The Android Open Source Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2008 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.settings; |
| 18 | |
| 19 | import android.app.Activity; |
| 20 | import android.content.Intent; |
| 21 | import android.graphics.drawable.AnimationDrawable; |
| 22 | import android.os.Bundle; |
| 23 | import android.os.Handler; |
| 24 | import android.view.View; |
| 25 | import android.widget.ImageView; |
| 26 | |
| 27 | public class ChooseLockPatternExample extends Activity implements View.OnClickListener { |
| 28 | private static final long START_DELAY = 1000; |
| 29 | protected static final String TAG = "Settings"; |
| 30 | private View mNextButton; |
| 31 | private View mSkipButton; |
| 32 | private View mImageView; |
| 33 | private AnimationDrawable mAnimation; |
| 34 | private Handler mHandler = new Handler(); |
| 35 | private Runnable mRunnable = new Runnable() { |
| 36 | public void run() { |
| 37 | startAnimation(mAnimation); |
| 38 | } |
| 39 | }; |
| 40 | |
| 41 | @Override |
| 42 | protected void onCreate(Bundle savedInstanceState) { |
| 43 | super.onCreate(savedInstanceState); |
| 44 | setContentView(R.layout.choose_lock_pattern_example); |
| 45 | initViews(); |
| 46 | } |
| 47 | |
| 48 | @Override |
| 49 | protected void onResume() { |
| 50 | super.onResume(); |
| 51 | mHandler.postDelayed(mRunnable, START_DELAY); |
| 52 | } |
| 53 | |
| 54 | @Override |
| 55 | protected void onPause() { |
| 56 | super.onPause(); |
| 57 | stopAnimation(mAnimation); |
| 58 | } |
| 59 | |
| 60 | public void onClick(View v) { |
| 61 | if (v == mSkipButton) { |
| 62 | finish(); |
| 63 | } else if (v == mNextButton) { |
| 64 | stopAnimation(mAnimation); |
| 65 | Intent intent = new Intent(this, ChooseLockPattern.class); |
| 66 | startActivity(intent); |
| 67 | finish(); |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | private void initViews() { |
| 72 | mNextButton = findViewById(R.id.next_button); |
| 73 | mNextButton.setOnClickListener(this); |
| 74 | |
| 75 | mSkipButton = findViewById(R.id.skip_button); |
| 76 | mSkipButton.setOnClickListener(this); |
| 77 | |
| 78 | mImageView = (ImageView) findViewById(R.id.lock_anim); |
| 79 | mImageView.setBackgroundResource(R.drawable.lock_anim); |
| 80 | mImageView.setOnClickListener(this); |
| 81 | mAnimation = (AnimationDrawable) mImageView.getBackground(); |
| 82 | } |
| 83 | |
| 84 | protected void startAnimation(final AnimationDrawable animation) { |
| 85 | if (animation != null && !animation.isRunning()) { |
| 86 | animation.run(); |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | protected void stopAnimation(final AnimationDrawable animation) { |
| 91 | if (animation != null && animation.isRunning()) animation.stop(); |
| 92 | } |
| 93 | } |
| 94 | |