Back to project page AndroidWearable-Samples.
The source code is released under:
Apache License
If you think the Android project AndroidWearable-Samples listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.example.android.google.wearable.watchviewstub; /* www. j av a2 s . c o m*/ import android.app.Activity; import android.os.Bundle; import android.support.v4.view.GestureDetectorCompat; import android.support.wearable.view.DismissOverlayView; import android.support.wearable.view.WatchViewStub; import android.view.GestureDetector; import android.view.MotionEvent; import android.view.View; import android.view.animation.Animation; import android.view.animation.ScaleAnimation; import android.widget.RelativeLayout; public class MainActivity extends Activity { private RelativeLayout mRectBackground; private RelativeLayout mRoundBackground; private GestureDetectorCompat mGestureDetector; private DismissOverlayView mDismissOverlayView; @Override public void onCreate(Bundle b) { super.onCreate(b); setContentView(R.layout.main_activity); WatchViewStub stub = (WatchViewStub) findViewById(R.id.stub); stub.setOnLayoutInflatedListener(new WatchViewStub.OnLayoutInflatedListener() { @Override public void onLayoutInflated(WatchViewStub stub) { mRectBackground = (RelativeLayout) findViewById(R.id.rect_layout); mRoundBackground = (RelativeLayout) findViewById(R.id.round_layout); } }); mDismissOverlayView = (DismissOverlayView) findViewById(R.id.dismiss_overlay); mGestureDetector = new GestureDetectorCompat(this, new LongPressListener()); } /** * Animates the layout when clicked. The animation used depends on whether the * device is round or rectangular. */ public void onLayoutClicked(View view) { if (mRectBackground != null) { ScaleAnimation scaleAnimation = new ScaleAnimation(1.0f, 0.7f, 1.0f, 0.7f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); scaleAnimation.setDuration(300); scaleAnimation.setRepeatCount(1); scaleAnimation.setRepeatMode(Animation.REVERSE); mRectBackground.startAnimation(scaleAnimation); } if (mRoundBackground != null) { mRoundBackground.animate().rotationBy(360).setDuration(300).start(); } } @Override public boolean dispatchTouchEvent(MotionEvent event) { return mGestureDetector.onTouchEvent(event) || super.dispatchTouchEvent(event); } private class LongPressListener extends GestureDetector.SimpleOnGestureListener { @Override public void onLongPress(MotionEvent event) { mDismissOverlayView.show(); } } }