2014-10-04 57 views
1

我有一個活動,爲ExampleActivityAndroid Wear,錶盤類型檢測 - 圓形或方形

<activity android:name="com.android.ExampleActivity" 
     android:label="@string/app_name" 
     android:allowEmbedded="true"> 

     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 
      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 

    </activity> 

有了這個定義manifiest,全面佈局是檢測沒有問題。

但是,與此顯示相同的是,同樣的活動,相同的代碼不起作用。

<activity android:name="com.android.ExampleActivity" 
     android:label="@string/app_name" 
     android:allowEmbedded="true"> 

     <meta-data android:name="com.google.android.clockwork.home.preview" android:resource="@drawable/example_watch_background" /> 

     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 
      <category android:name="com.google.android.clockwork.home.category.HOME_BACKGROUND" /> 
     </intent-filter> 

    </activity> 

對於檢測圓形佈局,摩托360設備,使用onApplyWindowInsets或onReadyForContent,但是同樣的問題。

任何想法,因爲當我使用這個類,com.google.android.clockwork.home.category.HOME_BACKGROUND,不工作?

感謝

+0

你可以發佈整個清單嗎? – kentarosu 2014-10-06 19:56:37

回答

-1

,直到新的andrioid智能手錶的SDK realeased,您不能使用setOnApplyWindowInsetsListener/onApplyWindowInsets定製手錶表面。此功能僅適用於智能手錶應用程序(無需添加清單)。

要知道,如果鐘面是圓的,你可以使用:

public static boolean heightSameAsWidth(Context context) { 
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); 
    Display display = wm.getDefaultDisplay(); 

    DisplayMetrics metrics = new DisplayMetrics(); 
    display.getMetrics(metrics); 

    int width = metrics.widthPixels; 
    int height = metrics.heightPixels; 

    return height == width; 
} 

private void checkIfWatchIsRound() { 
    if (heightSameAsWidth(getApplicationContext())) { 
     isRound = false; 
    } else { 
     isRound = true; 
    } 
} 
+0

這對華爲手錶無效,因爲華爲的高度=寬度 – Raffaeu 2015-12-02 14:35:57

1

有了新的SDK,你需要做的是像它的上Android Wear for Developers

private class Engine extends CanvasWatchFaceService.Engine { 
    boolean mIsRound; 
    int mChinSize; 

    @Override 
    public void onApplyWindowInsets(WindowInsets insets) { 
     super.onApplyWindowInsets(insets); 
     mIsRound = insets.isRound(); 
     mChinSize = insets.getSystemWindowInsetBottom(); 
    } 
    ... 
} 

出在這裏,因爲你可以看到,你也可以獲得底部屏幕間隙的值(例如Moto 360)。