I am curious to know about the wear type, whether it's round or square, because on the basis of device type I want to make different views for round and square. From This Post I got to know that in SDK-20 android.view.View
class has a new listener to detect device type, using this I am trying to get the device type but nothing is printing on logcat. Below is the code I tried.
public class WearSplash extends Activity implements OnApplyWindowInsetsListener {
private WatchViewStub _stub = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_wear_splash);
_stub = (WatchViewStub) findViewById(R.id.watch_view_stub);
_stub.setOnApplyWindowInsetsListener(this);
_stub.setOnLayoutInflatedListener(new WatchViewStub.OnLayoutInflatedListener() {
@Override
public void onLayoutInflated(WatchViewStub mStub) {
// here on the basis of device type i want to inflate views.
}
});
}
@Override
public WindowInsets onApplyWindowInsets(View v, WindowInsets insets) {
System.out.println(" in testing phase");
if (insets.isRound())
System.out.println("in round");
else
System.out.println("in square");
return null;
}
}
xml files.
<?xml version="1.0" encoding="utf-8"?>
<android.support.wearable.view.WatchViewStub xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/watch_view_stub"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:rectLayout="@layout/rect"
app:roundLayout="@layout/round"
tools:context="com.app.WearSplash"
tools:deviceIds="wear" >
</android.support.wearable.view.WatchViewStub>
Round:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.app.WearSplash"
tools:deviceIds="wear_round" >
<TextView
android:id="@+id/text"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:contentDescription="@string/hello_world" />
</RelativeLayout>
Square:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.app.WearSplash"
tools:deviceIds="wear_square" >
<ImageView
android:id="@+id/image"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:contentDescription="@string/hello_world"
android:background="@drawable/ic_launcher"/>
</LinearLayout>
I am new to wear development, let me know where I am going wrong. Helping hands will be highly appreciated.