DelayedConfirmationView is empty on Android Wear

I am trying to use Andoird Wear DelayedConfirmationView from the support library by running an action.

Activity has this in OnCreate:

setContentView(R.layout.delayed_main); mDelayed = (DelayedConfirmationView) findViewById(R.id.delay); mDelayed.setTotalTimeMs(4000); //mDelayed.setImageDrawable(getResources().getDrawable(R.drawable.close_button)); mDelayed.setListener(new DelayedConfirmationView.DelayedConfirmationListener() { ... 

My delayed_main has the following:

 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" xmlns:app="http://schemas.android.com/apk/android.support.wearable.view" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".DelayedConfirmActivity"> <android.support.wearable.view.DelayedConfirmationView android:id="@+id/delay" app:circle_border_color="#2299ee" app:circle_border_width="5sp" app:circle_color="#222222" app:circle_padding="5sp" app:circle_radius="80sp" app:update_interval="100" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" /> </RelativeLayout> 

I don't get an exception in my OnCreate, but all I get is a blank white screen. I tried setImageDrawable. Also tried passing setContentView (View) to a new instance of DelayedConfirmationView. Also tried to remove all the app: attributes in the XML above (hoping some reasonable default values ​​are applicable). The docs give no example of what to expect or how to use.

Any ideas?

0
source share
1 answer

There is an example DelayedConfirmation project in DelayedConfirmation . If you have samples uploaded to your SDK manager, you can find here: sdk\samples\android-20\wearable\DelayedConfirmation

Part of main_activity.xml :

  <android.support.wearable.view.DelayedConfirmationView android:id="@+id/delayed_confirmation" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:src="@drawable/ic_launcher" app:circle_color="@color/blue" app:circle_radius="@dimen/circle_radius" app:circle_radius_pressed="@dimen/circle_radius_pressed" app:circle_padding="@dimen/circle_padding" app:circle_border_width="@dimen/circle_border_normal_width" app:circle_border_color="@color/white"/> 

therefore the only additional attribute here:

  app:circle_radius_pressed="@dimen/circle_radius_pressed" 

there are almost the same lines in the MainActivity.java class as you:

  delayedConfirmationView = (DelayedConfirmationView) findViewById(R.id.delayed_confirmation); delayedConfirmationView.setTotalTimeMs(NUM_SECONDS * 1000); ... delayedConfirmationView.setListener(this); 

But in addition, they also call the .start() method:

  delayedConfirmationView.start(); 


EDIT:

I only tested DelayedConfirmationView with FrameLayout and it works great, so BoxInsetLayout has nothing to do here.
Even after copying and pasting your DelayedConfirmationView xml code, DelayedConfirmationView still works fine, a gray button appears on the screen. So I was a little surprised :)
enter image description here
After playing with this code, I realized that you have the wrong xmlns:app :

 xmlns:app="http://schemas.android.com/apk/android.support.wearable.view" 

You cannot specify the library package in which the attributes are located (just like you cannot use the android.support.wearable.R class). You must use the class R from your own package. You need to use:

 xmlns:app="http://schemas.android.com/apk/res-auto" 

and then everything works fine in your code. That's why after replacing the root view with the copied BoxInsetLayout code (with the correct xmlns ), the button the code started working with :)

+1
source

Source: https://habr.com/ru/post/1207556/


All Articles