android - 获取 SmartWatch 1 和 2 的显示尺寸或区分两者

标签 android sony sony-smartwatch

如果我完全忽略了这里的明显之处,请原谅我,但我似乎无法从代码中找出如何区分 smartWatch 1 和 smartWatch 2 的方法。硬件和显示尺寸似乎存在一些差异我想解释一下。太好了...如果有人知道如何获取当前 watch 的显示尺寸,或者确定当前 watch 是 SmartWatch 1 还是 2,我将不胜感激!!!

这是我试过的方法,但对于这两款 watch ,它似乎总是返回 220x176

public static int getSupportedControlWidth(Context context) {
    return context.getResources().getDimensionPixelSize(R.dimen.smart_watch_2_control_width);
}

public static int getSupportedControlHeight(Context context) {
    return context.getResources().getDimensionPixelSize(R.dimen.smart_watch_2_control_height);
}

最佳答案

查看SampleControlExtension项目,看看它是如何使用的:

DeviceInfoHelper.isSmartWatch2ApiAndScreenDetected()

但是如果你愿意,你可以从任何地方调用它。

这就是 SampleExtensionService 决定 SW1 或 SW2 的方式:

@Override
public ControlExtension createControlExtension(String hostAppPackageName) {
    // First we check if the API level and screen size required for
    // SampleControlSmartWatch2 is supported
    boolean advancedFeaturesSupported = DeviceInfoHelper.isSmartWatch2ApiAndScreenDetected(
            this, hostAppPackageName);
    if (advancedFeaturesSupported) {
        return new SampleControlSmartWatch2(hostAppPackageName, this, new Handler());
    } else {
        // If not we return an API level 1 control based on screen size
        final int controlSWWidth = SampleControlSmartWatch.getSupportedControlWidth(this);
        final int controlSWHeight = SampleControlSmartWatch.getSupportedControlHeight(this);
        final int controlSWHPWidth = SampleControlSmartWirelessHeadsetPro
                .getSupportedControlWidth(this);
        final int controlSWHPHeight = SampleControlSmartWirelessHeadsetPro
                .getSupportedControlHeight(this);

        for (DeviceInfo device : RegistrationAdapter.getHostApplication(this,
                hostAppPackageName)
                .getDevices()) {
            for (DisplayInfo display : device.getDisplays()) {
                if (display.sizeEquals(controlSWWidth, controlSWHeight)) {
                    return new SampleControlSmartWatch(hostAppPackageName, this, new Handler());
                } else if (display.sizeEquals(controlSWHPWidth, controlSWHPHeight)) {
                    return new SampleControlSmartWirelessHeadsetPro(hostAppPackageName, this,
                            new Handler());
                }
            }
        }
        throw new IllegalArgumentException("No control for: " + hostAppPackageName);
    }
}

就我个人而言,我觉得没有必要使用资源,所以这就是我选择的方式。我定义了一个 enum,我使用与上述查询类似的代码 isSmartWatch2ApiAndScreenDetected 然后传递正确的枚举值。

import android.graphics.Bitmap.Config;

public enum ScreenConfiguration {

    SMARTWATCH1(128, 128, Config.RGB_565), SMARTWATCH2(220, 176, Config.RGB_565);

    private final int mWidth;
    private final int mHeight;
    private final Config mBitmapConfig;

    private ScreenConfiguration(int width, int height, Config bitmapConfig) {
        mWidth = width;
        mHeight = height;
        mBitmapConfig = bitmapConfig;
    }

    public int getWidth() {
        return mWidth;
    }

    public int getHeight() {
        return mHeight;
    }

    public Config getBitmapConfig() {
        return mBitmapConfig;
    }

}

编辑您必须告诉系统您希望支持智能 watch 2。

在您的 RegistrationInformation 类中:

@Override
public int getTargetControlApiVersion() {
    return 2;
}

如果那是 1,您只会在 isSmartWatch2ApiAndScreenDetected 时得到 false。

编辑第 2 部分如何使用枚举

@Override
public ControlExtension createControlExtension(String hostAppPackageName) {
    // First we check if the API level and screen size required for
    // SampleControlSmartWatch2 is supported
    boolean advancedFeaturesSupported = DeviceInfoHelper.isSmartWatch2ApiAndScreenDetected(
            this, hostAppPackageName);
    if (advancedFeaturesSupported) {
        return new SampleControlSmartWatch(ScreenConfiguration.SMARTWATCH2, hostAppPackageName, this, new Handler());
    } else {
        // If not we return an API level 1 control based on screen size
        final int controlSWWidth = SampleControlSmartWatch.getSupportedControlWidth(this);
        final int controlSWHeight = SampleControlSmartWatch.getSupportedControlHeight(this);
        final int controlSWHPWidth = SampleControlSmartWirelessHeadsetPro
                .getSupportedControlWidth(this);
        final int controlSWHPHeight = SampleControlSmartWirelessHeadsetPro
                .getSupportedControlHeight(this);

        for (DeviceInfo device : RegistrationAdapter.getHostApplication(this,
                hostAppPackageName)
                .getDevices()) {
            for (DisplayInfo display : device.getDisplays()) {
                if (display.sizeEquals(controlSWWidth, controlSWHeight)) {
                    return new SampleControlSmartWatch(ScreenConfiguration.SMARTWATCH1, hostAppPackageName, this, new Handler());
                } else if (display.sizeEquals(controlSWHPWidth, controlSWHPHeight)) {
                    return new SampleControlSmartWirelessHeadsetPro(hostAppPackageName, this,
                            new Handler());
                }
            }
        }
        throw new IllegalArgumentException("No control for: " + hostAppPackageName);
    }
}

与第一个示例基本相同,但看看我如何使用相同的控件类 SampleControlSmartWatch 并将 ScreenConfiguration enum 传递给它,所以它可以知道宽度和高度。

关于android - 获取 SmartWatch 1 和 2 的显示尺寸或区分两者,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19484575/

相关文章:

text-to-speech - Smartband Talk - 通过它的音频

java - Android 上停止 for 循环的按钮

android - 优步服务器 token

AndroidHttpClient Nullpointerexception 调用 android.net.http.AndroidHttpClient.isMmsRequest

android - 将 Smartwatch Java 扩展添加到 Phonegap 应用程序?

android - 是否可以通过 android 从智能 watch 获取 PPG(光体积描记图)数据?

sony-smartwatch - 智能 watch 2 屏幕截图

更新后 Android gradle 'installDebug' 任务停止工作

android - 如何获取所选字符或字符串在 EditText 中的位置

debugging - 使用索尼爱立信 Cedar (J108i) 进行设备上调试