Sono curioso di sapere sul tipo di usura, se è rotondo o quadrato, perché sulla base del tipo di dispositivo voglio rendere diverse viste per tondo e quadrato. Da This Post ho avuto modo di sapere che in SDK-20 la classe android.view.View
ha un nuovo listener per rilevare il tipo di dispositivo, usando questo sto cercando di ottenere il tipo di dispositivo, ma niente sta stampando su logcat. Di seguito è riportato il codice che ho provato.Rilevamento del tipo di usura Android - Rotondo o quadrato
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;
}
}
file xml.
<?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>
rotonda:
<?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>
Sono nuovo di portare lo sviluppo, farmi sapere dove sto andando male. Le mani d'aiuto saranno molto apprezzate.
Non sono sicuro che questo è il problema, non ho provato con l'usura sia, ma quando ho cercato di attuare il 'OnApplyWindowInsetsListener' in studio Android, ha ottenuto compilato automaticamente come 'View.OnApplyWindowInsetsListener'. Quindi, per favore, prova 'public class WearSplash estende Activity implementa View.OnApplyWindowInsetsListener' invece di' class WearSplash estende l'attività implementa OnApplyWindowInsetsListener'. –
Già provato, non funzionante – Dev
In realtà ricevo un errore quando tento di implementare 'OnApplyWindowInsetsListener' senza la parte' View'. –