• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 java.util.ArrayList;
20 
21 import com.android.internal.widget.LockPatternUtils;
22 import com.android.internal.widget.LockPatternView;
23 
24 import android.app.Fragment;
25 import android.content.Intent;
26 import android.os.Bundle;
27 import android.preference.PreferenceActivity;
28 import android.view.LayoutInflater;
29 import android.view.View;
30 import android.view.ViewGroup;
31 
32 public class ChooseLockPatternTutorial extends PreferenceActivity {
33 
34     // required constructor for fragments
ChooseLockPatternTutorial()35     public ChooseLockPatternTutorial() {
36 
37     }
38 
39     @Override
getIntent()40     public Intent getIntent() {
41         Intent modIntent = new Intent(super.getIntent());
42         modIntent.putExtra(EXTRA_SHOW_FRAGMENT, ChooseLockPatternTutorialFragment.class.getName());
43         modIntent.putExtra(EXTRA_NO_HEADERS, true);
44         return modIntent;
45     }
46 
47     @Override
onCreate(Bundle savedInstanceState)48     public void onCreate(Bundle savedInstanceState) {
49         super.onCreate(savedInstanceState);
50         CharSequence msg = getText(R.string.lockpassword_choose_your_pattern_header);
51         showBreadCrumbs(msg, msg);
52     }
53 
54     public static class ChooseLockPatternTutorialFragment extends Fragment
55             implements View.OnClickListener {
56         private View mNextButton;
57         private View mSkipButton;
58         private LockPatternView mPatternView;
59 
60         @Override
onCreate(Bundle savedInstanceState)61         public void onCreate(Bundle savedInstanceState) {
62             super.onCreate(savedInstanceState);
63             // Don't show the tutorial if the user has seen it before.
64             LockPatternUtils lockPatternUtils = new LockPatternUtils(getActivity());
65             if (savedInstanceState == null && lockPatternUtils.isPatternEverChosen()) {
66                 Intent intent = new Intent(getActivity(), ChooseLockPattern.class);
67                 intent.setFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT);
68                 intent.putExtra("confirm_credentials", false);
69                 final boolean isFallback = getActivity().getIntent()
70                     .getBooleanExtra(LockPatternUtils.LOCKSCREEN_BIOMETRIC_WEAK_FALLBACK, false);
71                 intent.putExtra(LockPatternUtils.LOCKSCREEN_BIOMETRIC_WEAK_FALLBACK,
72                                 isFallback);
73                 startActivity(intent);
74                 getActivity().finish();
75             }
76         }
77 
78         @Override
onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)79         public View onCreateView(LayoutInflater inflater, ViewGroup container,
80                 Bundle savedInstanceState) {
81             View view = inflater.inflate(R.layout.choose_lock_pattern_tutorial, null);
82             mNextButton = view.findViewById(R.id.next_button);
83             mNextButton.setOnClickListener(this);
84             mSkipButton = view.findViewById(R.id.skip_button);
85             mSkipButton.setOnClickListener(this);
86 
87             // Set up LockPatternView to be a non-interactive demo animation
88             mPatternView = (LockPatternView) view.findViewById(R.id.lockPattern);
89             ArrayList<LockPatternView.Cell> demoPattern = new ArrayList<LockPatternView.Cell>();
90             demoPattern.add(LockPatternView.Cell.of(0,0));
91             demoPattern.add(LockPatternView.Cell.of(0,1));
92             demoPattern.add(LockPatternView.Cell.of(1,1));
93             demoPattern.add(LockPatternView.Cell.of(2,1));
94             mPatternView.setPattern(LockPatternView.DisplayMode.Animate, demoPattern);
95             mPatternView.disableInput();
96 
97             return view;
98         }
99 
onClick(View v)100         public void onClick(View v) {
101             if (v == mSkipButton) {
102                 // Canceling, so finish all
103                 getActivity().setResult(ChooseLockPattern.RESULT_FINISHED);
104                 getActivity().finish();
105             } else if (v == mNextButton) {
106                 final boolean isFallback = getActivity().getIntent()
107                     .getBooleanExtra(LockPatternUtils.LOCKSCREEN_BIOMETRIC_WEAK_FALLBACK, false);
108                 Intent intent = new Intent(getActivity(), ChooseLockPattern.class);
109                 intent.addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT);
110                 intent.putExtra(LockPatternUtils.LOCKSCREEN_BIOMETRIC_WEAK_FALLBACK,
111                                 isFallback);
112                 startActivity(intent);
113                 getActivity().overridePendingTransition(0, 0); // no animation
114                 getActivity().finish();
115             }
116         }
117     }
118 }
119