Advertisement
Guest User

Untitled

a guest
Oct 24th, 2014
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.21 KB | None | 0 0
  1. import android.content.BroadcastReceiver;
  2. import android.content.Context;
  3. import android.content.Intent;
  4. import android.content.IntentFilter;
  5. import android.os.Bundle;
  6. import android.view.animation.Animation;
  7. import android.view.animation.LinearInterpolator;
  8. import android.view.animation.RotateAnimation;
  9. import android.widget.ImageView;
  10.  
  11. import java.util.Calendar;
  12.  
  13. public class ClockActivity extends WatchFaceActivity {
  14.  
  15.     private ImageView img;
  16.  
  17.     private final static IntentFilter INTENT_FILTER;
  18.     static {
  19.         INTENT_FILTER = new IntentFilter();
  20.         INTENT_FILTER.addAction(Intent.ACTION_TIME_TICK);
  21.         INTENT_FILTER.addAction(Intent.ACTION_TIMEZONE_CHANGED);
  22.         INTENT_FILTER.addAction(Intent.ACTION_TIME_CHANGED);
  23.     }
  24.  
  25.  
  26.     private BroadcastReceiver mTimeInfoReceiver = new BroadcastReceiver(){
  27.         @Override
  28.         public void onReceive(Context arg0, Intent intent) {
  29.             updateUI();
  30.         }
  31.     };
  32.  
  33.  
  34.     @Override
  35.     public void onScreenDim() {
  36.         updateUI();
  37.     }
  38.  
  39.     @Override
  40.     public void onScreenAwake() {
  41.         updateUI();
  42.     }
  43.  
  44.     @Override
  45.     protected void onDestroy() {
  46.         super.onDestroy();
  47.     }
  48.  
  49.     @Override
  50.     protected void onCreate(Bundle savedInstanceState) {
  51.         super.onCreate(savedInstanceState);
  52.         setContentView(R.layout.activity_clock);
  53.         updateUI();
  54.  
  55.         mTimeInfoReceiver.onReceive(ClockActivity.this, null);
  56.         registerReceiver(mTimeInfoReceiver, INTENT_FILTER);
  57.  
  58.     }
  59.  
  60.     private void updateUI() {
  61.         Calendar calendar = Calendar.getInstance();
  62.         int seconds = calendar.get(Calendar.SECOND);
  63.  
  64.         img = (ImageView)findViewById(R.id.hand_second);
  65.  
  66. //        img.animate().setDuration(1000).rotation((360f/60f) * seconds).setInterpolator(new LinearInterpolator());
  67.  
  68.  
  69.         RotateAnimation rotateAnimation = new RotateAnimation((seconds-1)*6, seconds*6, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
  70.  
  71.         rotateAnimation.setInterpolator(new LinearInterpolator());
  72.         rotateAnimation.setDuration(1000);
  73.         rotateAnimation.setFillAfter(true);
  74.  
  75.         img.startAnimation(rotateAnimation);
  76.     }
  77.  
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement