blob: 77517b9d3d4841f7676ebb3b28ce144d3b294cb9 [file] [log] [blame]
The Android Open Source Projectde2d9f52008-10-21 07:00:00 -07001/*
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
17package com.android.settings;
18
19import android.app.Activity;
20import android.content.Intent;
21import android.graphics.drawable.AnimationDrawable;
22import android.os.Bundle;
23import android.os.Handler;
24import android.view.View;
25import android.widget.ImageView;
26
27public class ChooseLockPatternExample extends Activity implements View.OnClickListener {
The Android Open Source Projectabc48f82008-12-17 18:06:01 -080028 private static final int REQUESTCODE_CHOOSE = 1;
The Android Open Source Projectde2d9f52008-10-21 07:00:00 -070029 private static final long START_DELAY = 1000;
30 protected static final String TAG = "Settings";
31 private View mNextButton;
32 private View mSkipButton;
33 private View mImageView;
34 private AnimationDrawable mAnimation;
35 private Handler mHandler = new Handler();
36 private Runnable mRunnable = new Runnable() {
37 public void run() {
38 startAnimation(mAnimation);
39 }
40 };
41
42 @Override
43 protected void onCreate(Bundle savedInstanceState) {
44 super.onCreate(savedInstanceState);
45 setContentView(R.layout.choose_lock_pattern_example);
46 initViews();
47 }
48
49 @Override
50 protected void onResume() {
51 super.onResume();
52 mHandler.postDelayed(mRunnable, START_DELAY);
53 }
54
55 @Override
56 protected void onPause() {
57 super.onPause();
58 stopAnimation(mAnimation);
59 }
60
61 public void onClick(View v) {
62 if (v == mSkipButton) {
The Android Open Source Projectabc48f82008-12-17 18:06:01 -080063 // Canceling, so finish all
64 setResult(ChooseLockPattern.RESULT_FINISHED);
The Android Open Source Projectde2d9f52008-10-21 07:00:00 -070065 finish();
66 } else if (v == mNextButton) {
67 stopAnimation(mAnimation);
68 Intent intent = new Intent(this, ChooseLockPattern.class);
The Android Open Source Projectabc48f82008-12-17 18:06:01 -080069 startActivityForResult(intent, REQUESTCODE_CHOOSE);
70 }
71 }
72
73 @Override
74 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
75 if (requestCode == REQUESTCODE_CHOOSE && resultCode == ChooseLockPattern.RESULT_FINISHED) {
76 setResult(resultCode);
The Android Open Source Projectde2d9f52008-10-21 07:00:00 -070077 finish();
78 }
79 }
The Android Open Source Projectabc48f82008-12-17 18:06:01 -080080
The Android Open Source Projectde2d9f52008-10-21 07:00:00 -070081 private void initViews() {
82 mNextButton = findViewById(R.id.next_button);
83 mNextButton.setOnClickListener(this);
84
85 mSkipButton = findViewById(R.id.skip_button);
86 mSkipButton.setOnClickListener(this);
87
88 mImageView = (ImageView) findViewById(R.id.lock_anim);
89 mImageView.setBackgroundResource(R.drawable.lock_anim);
90 mImageView.setOnClickListener(this);
91 mAnimation = (AnimationDrawable) mImageView.getBackground();
92 }
93
94 protected void startAnimation(final AnimationDrawable animation) {
95 if (animation != null && !animation.isRunning()) {
96 animation.run();
97 }
98 }
99
100 protected void stopAnimation(final AnimationDrawable animation) {
101 if (animation != null && animation.isRunning()) animation.stop();
102 }
103}
104