Presentation from GDG DevFest - the biggest Google related event in Ukraine. October 24-25, Lviv. Learn more at http://devfest.gdg.org.ua/
Android Wear Views#AndroidWearMichał TajchertPolidea, Software Engineer
View Slide
Wear history
#dfua~2012
#dfua
What is Android Wear?
#dfuaAndroid WearSimplicityContextExtension
View
#dfuaThis class represents the basic building block for user interface components.
WearViewStubGolden View of Wear?
Problem?
#dfuaWearViewStubxmlns: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_activity_stub"app:roundLayout="@layout/round_activity_stub"tools:context=".StubActivity"tools:deviceIds="wear">
WearViewStub
#dfuaWearViewStubIs it perfect?
BoxInsetLayoutMind your corners!
BoxInsetLayout
#dfuaBoxInsetLayoutxmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"android:layout_height="match_parent"android:layout_width="match_parent">android:layout_width="match_parent"android:layout_height="match_parent"android:layout_alignParentTop="true"android:layout_centerHorizontal="true"android:orientation="horizontal"app:layout_box="all" >android:layout_width="match_parent"android:layout_height="match_parent"android:text="@string/text_long"/>
CircledImageViewCircle-shape all the things!
#dfuaCircledImageViewxmlns:app="http://schemas.android.com/apk/res-auto"android:layout_width="match_parent"android:layout_height="match_parent"android:background="@color/white">android:layout_width="100dp"android:layout_height="100dp"android:layout_gravity="center"android:src="@drawable/ic_launcher"app:circle_border_color="#999999"app:circle_border_width="1dp"app:circle_color="#000"app:circle_radius="50dp"/>
CircledImageView
DismissOverlayViewKeep on dismissing!
#dfuaWindowSwipeToDismiss = false<br/><item name="android:windowSwipeToDismiss"<br/>>false</item><br/>
#dfuaDismissOverlayViewdismissOverlayView = (DismissOverlayView) findViewById(R.id.dismiss_plain);gestureDetector = new GestureDetector(this, new GestureDetector.SimpleOnGestureListener(){@Overridepublic void onLongPress(MotionEvent e) {dismissOverlayView.show();}});android:id="@+id/dismiss_plain"android:layout_width="fill_parent"android:layout_height="fill_parent"/>
DismissOverlayView
DelayedConfirmationViewNot so fast!
DelayedConfirmationView
DelayedConfirmationViewandroid:id="@+id/delayed_confirmation"android:layout_width="fill_parent"android:layout_height="fill_parent"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"/>
#dfuaDelayedConfirmationViewdelayedConfirmationView = (DelayedConfirmationView) findViewById(R.id.delayed_confirmation);delayedConfirmationView.setTotalTimeMs(2000);delayedConfirmationView.setListener(ConfirmationOverlayActivity.this);... implements DelayedConfirmationView.DelayedConfirmationListener{...}@Overridepublic void onTimerFinished(View view) {view.setPressed(false);}@Overridepublic void onTimerSelected(View view) {view.setPressed(true);delayedConfirmationView.start();}
GridViewPagerOwn card structure!
#dfuaGridViewPagerfinal Resources res = getResources();final GridViewPager pager = (GridViewPager) findViewById(R.id.pager);pager.setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() {@Overridepublic WindowInsets onApplyWindowInsets(View v, WindowInsets insets) {final boolean round = insets.isRound();int rowMargin = res.getDimensionPixelOffset(R.dimen.card_margin);int colMargin = res.getDimensionPixelOffset(round ? R.dimen.padding_round : R.dimen.padding_rect);pager.setPageMargins(rowMargin, colMargin);return insets;}});pager.setAdapter(new GridViewPagerCustomAdapter(this, getFragmentManager()));
#dfuaGridViewPagerxmlns:android="http://schemas.android.com/apk/res/android"android:id="@+id/pager"android:layout_width="match_parent"android:layout_height="match_parent" />
GridViewPager
CardFragmentFill our card structure!
#dfuaCardFragmentxmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"android:background="@drawable/robot_background"android:layout_height="match_parent"android:layout_width="match_parent">android:id="@+id/frame_layout"android:layout_width="match_parent"android:layout_height="match_parent"app:layout_box="bottom">
#dfuaCardFragmentprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_wear_activity2);FragmentManager fragmentManager = getFragmentManager();FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();CardFragment cardFragment = CardFragment.create(getString(R.string.cftitle),getString(R.string.cfdesc),R.drawable.p);fragmentTransaction.add(R.id.frame_layout, cardFragment);fragmentTransaction.commit();}
CardFragment
App that rocks!
Thank you@tajchertgoogle.com/+MichalTajchertgithub.com/tajcherttajchert.pltwitterg+githubwww