Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import android.content.BroadcastReceiver;
- import android.content.Context;
- import android.content.Intent;
- import android.content.IntentFilter;
- import android.os.Bundle;
- import android.view.animation.Animation;
- import android.view.animation.LinearInterpolator;
- import android.view.animation.RotateAnimation;
- import android.widget.ImageView;
- import java.util.Calendar;
- public class ClockActivity extends WatchFaceActivity {
- private ImageView img;
- private final static IntentFilter INTENT_FILTER;
- static {
- INTENT_FILTER = new IntentFilter();
- INTENT_FILTER.addAction(Intent.ACTION_TIME_TICK);
- INTENT_FILTER.addAction(Intent.ACTION_TIMEZONE_CHANGED);
- INTENT_FILTER.addAction(Intent.ACTION_TIME_CHANGED);
- }
- private BroadcastReceiver mTimeInfoReceiver = new BroadcastReceiver(){
- @Override
- public void onReceive(Context arg0, Intent intent) {
- updateUI();
- }
- };
- @Override
- public void onScreenDim() {
- updateUI();
- }
- @Override
- public void onScreenAwake() {
- updateUI();
- }
- @Override
- protected void onDestroy() {
- super.onDestroy();
- }
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_clock);
- updateUI();
- mTimeInfoReceiver.onReceive(ClockActivity.this, null);
- registerReceiver(mTimeInfoReceiver, INTENT_FILTER);
- }
- private void updateUI() {
- Calendar calendar = Calendar.getInstance();
- int seconds = calendar.get(Calendar.SECOND);
- img = (ImageView)findViewById(R.id.hand_second);
- // img.animate().setDuration(1000).rotation((360f/60f) * seconds).setInterpolator(new LinearInterpolator());
- RotateAnimation rotateAnimation = new RotateAnimation((seconds-1)*6, seconds*6, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
- rotateAnimation.setInterpolator(new LinearInterpolator());
- rotateAnimation.setDuration(1000);
- rotateAnimation.setFillAfter(true);
- img.startAnimation(rotateAnimation);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement