16b19fa9017800b94c75238339a337fd8f6c3e808Maurice Lam/* 26b19fa9017800b94c75238339a337fd8f6c3e808Maurice Lam * Copyright (C) 2014 The Android Open Source Project 36b19fa9017800b94c75238339a337fd8f6c3e808Maurice Lam * 46b19fa9017800b94c75238339a337fd8f6c3e808Maurice Lam * Licensed under the Apache License, Version 2.0 (the "License"); 56b19fa9017800b94c75238339a337fd8f6c3e808Maurice Lam * you may not use this file except in compliance with the License. 66b19fa9017800b94c75238339a337fd8f6c3e808Maurice Lam * You may obtain a copy of the License at 76b19fa9017800b94c75238339a337fd8f6c3e808Maurice Lam * 86b19fa9017800b94c75238339a337fd8f6c3e808Maurice Lam * http://www.apache.org/licenses/LICENSE-2.0 96b19fa9017800b94c75238339a337fd8f6c3e808Maurice Lam * 106b19fa9017800b94c75238339a337fd8f6c3e808Maurice Lam * Unless required by applicable law or agreed to in writing, software 116b19fa9017800b94c75238339a337fd8f6c3e808Maurice Lam * distributed under the License is distributed on an "AS IS" BASIS, 126b19fa9017800b94c75238339a337fd8f6c3e808Maurice Lam * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 136b19fa9017800b94c75238339a337fd8f6c3e808Maurice Lam * See the License for the specific language governing permissions and 146b19fa9017800b94c75238339a337fd8f6c3e808Maurice Lam * limitations under the License. 156b19fa9017800b94c75238339a337fd8f6c3e808Maurice Lam */ 166b19fa9017800b94c75238339a337fd8f6c3e808Maurice Lam 172eb170cd6ff43db01dc0ff3c1fcac5ebba4489deMaurice Lampackage com.android.settings.password; 186b19fa9017800b94c75238339a337fd8f6c3e808Maurice Lam 19edb39449842dd1360fa5f92c990785bf7c8dcdcdMaurice Lamimport android.app.Activity; 206b19fa9017800b94c75238339a337fd8f6c3e808Maurice Lamimport android.app.Fragment; 2117d66bea42fc377a29fe4547f78dc17454f0f49fAjay Nadathurimport android.app.admin.DevicePolicyManager; 226b19fa9017800b94c75238339a337fd8f6c3e808Maurice Lamimport android.content.Context; 236b19fa9017800b94c75238339a337fd8f6c3e808Maurice Lamimport android.content.Intent; 246b19fa9017800b94c75238339a337fd8f6c3e808Maurice Lamimport android.os.Bundle; 2562c0c3c324aca7eaf78d7d5e0c8a6ae0213e1f80Maurice Lamimport android.support.annotation.Nullable; 2617d66bea42fc377a29fe4547f78dc17454f0f49fAjay Nadathurimport android.util.Log; 27edb39449842dd1360fa5f92c990785bf7c8dcdcdMaurice Lamimport android.view.View; 28edb39449842dd1360fa5f92c990785bf7c8dcdcdMaurice Lamimport android.widget.Button; 2971fde52ae36f134e93835bee53bc4bfe5481bba0Udam Sainiimport android.widget.LinearLayout; 306b19fa9017800b94c75238339a337fd8f6c3e808Maurice Lam 312eb170cd6ff43db01dc0ff3c1fcac5ebba4489deMaurice Lamimport com.android.settings.R; 322eb170cd6ff43db01dc0ff3c1fcac5ebba4489deMaurice Lamimport com.android.settings.SetupRedactionInterstitial; 33edb39449842dd1360fa5f92c990785bf7c8dcdcdMaurice Lamimport com.android.settings.password.ChooseLockTypeDialogFragment.OnLockTypeSelectedListener; 342eb170cd6ff43db01dc0ff3c1fcac5ebba4489deMaurice Lam 35ecd2b7b81fd2faa2f2f3dbe5a169c749321f3d89Maurice Lam/** 36ecd2b7b81fd2faa2f2f3dbe5a169c749321f3d89Maurice Lam * Setup Wizard's version of ChooseLockPassword screen. It inherits the logic and basic structure 37ecd2b7b81fd2faa2f2f3dbe5a169c749321f3d89Maurice Lam * from ChooseLockPassword class, and should remain similar to that behaviorally. This class should 38ecd2b7b81fd2faa2f2f3dbe5a169c749321f3d89Maurice Lam * only overload base methods for minor theme and behavior differences specific to Setup Wizard. 39ecd2b7b81fd2faa2f2f3dbe5a169c749321f3d89Maurice Lam * Other changes should be done to ChooseLockPassword class instead and let this class inherit 40ecd2b7b81fd2faa2f2f3dbe5a169c749321f3d89Maurice Lam * those changes. 41ecd2b7b81fd2faa2f2f3dbe5a169c749321f3d89Maurice Lam */ 4283301b5256e3fd930d620e8e9ad5f43cd388ba09Maurice Lampublic class SetupChooseLockPassword extends ChooseLockPassword { 436b19fa9017800b94c75238339a337fd8f6c3e808Maurice Lam 4417d66bea42fc377a29fe4547f78dc17454f0f49fAjay Nadathur private static final String TAG = "SetupChooseLockPassword"; 4517d66bea42fc377a29fe4547f78dc17454f0f49fAjay Nadathur 462eb170cd6ff43db01dc0ff3c1fcac5ebba4489deMaurice Lam public static Intent modifyIntentForSetup( 472eb170cd6ff43db01dc0ff3c1fcac5ebba4489deMaurice Lam Context context, 482eb170cd6ff43db01dc0ff3c1fcac5ebba4489deMaurice Lam Intent chooseLockPasswordIntent) { 492eb170cd6ff43db01dc0ff3c1fcac5ebba4489deMaurice Lam chooseLockPasswordIntent.setClass(context, SetupChooseLockPassword.class); 502eb170cd6ff43db01dc0ff3c1fcac5ebba4489deMaurice Lam chooseLockPasswordIntent.putExtra(EXTRA_PREFS_SHOW_BUTTON_BAR, false); 512eb170cd6ff43db01dc0ff3c1fcac5ebba4489deMaurice Lam return chooseLockPasswordIntent; 526b19fa9017800b94c75238339a337fd8f6c3e808Maurice Lam } 536b19fa9017800b94c75238339a337fd8f6c3e808Maurice Lam 546b19fa9017800b94c75238339a337fd8f6c3e808Maurice Lam @Override 556b19fa9017800b94c75238339a337fd8f6c3e808Maurice Lam protected boolean isValidFragment(String fragmentName) { 566b19fa9017800b94c75238339a337fd8f6c3e808Maurice Lam return SetupChooseLockPasswordFragment.class.getName().equals(fragmentName); 576b19fa9017800b94c75238339a337fd8f6c3e808Maurice Lam } 586b19fa9017800b94c75238339a337fd8f6c3e808Maurice Lam 596b19fa9017800b94c75238339a337fd8f6c3e808Maurice Lam @Override 606b19fa9017800b94c75238339a337fd8f6c3e808Maurice Lam /* package */ Class<? extends Fragment> getFragmentClass() { 616b19fa9017800b94c75238339a337fd8f6c3e808Maurice Lam return SetupChooseLockPasswordFragment.class; 626b19fa9017800b94c75238339a337fd8f6c3e808Maurice Lam } 636b19fa9017800b94c75238339a337fd8f6c3e808Maurice Lam 646b19fa9017800b94c75238339a337fd8f6c3e808Maurice Lam @Override 6571fde52ae36f134e93835bee53bc4bfe5481bba0Udam Saini protected void onCreate(Bundle savedInstance) { 6671fde52ae36f134e93835bee53bc4bfe5481bba0Udam Saini super.onCreate(savedInstance); 6771fde52ae36f134e93835bee53bc4bfe5481bba0Udam Saini LinearLayout layout = (LinearLayout) findViewById(R.id.content_parent); 6871fde52ae36f134e93835bee53bc4bfe5481bba0Udam Saini layout.setFitsSystemWindows(false); 6971fde52ae36f134e93835bee53bc4bfe5481bba0Udam Saini } 7071fde52ae36f134e93835bee53bc4bfe5481bba0Udam Saini 71edb39449842dd1360fa5f92c990785bf7c8dcdcdMaurice Lam public static class SetupChooseLockPasswordFragment extends ChooseLockPasswordFragment 72edb39449842dd1360fa5f92c990785bf7c8dcdcdMaurice Lam implements OnLockTypeSelectedListener { 73edb39449842dd1360fa5f92c990785bf7c8dcdcdMaurice Lam 7462c0c3c324aca7eaf78d7d5e0c8a6ae0213e1f80Maurice Lam @Nullable 7562c0c3c324aca7eaf78d7d5e0c8a6ae0213e1f80Maurice Lam private Button mOptionsButton; 7662c0c3c324aca7eaf78d7d5e0c8a6ae0213e1f80Maurice Lam 77edb39449842dd1360fa5f92c990785bf7c8dcdcdMaurice Lam @Override 78edb39449842dd1360fa5f92c990785bf7c8dcdcdMaurice Lam public void onViewCreated(View view, Bundle savedInstanceState) { 79edb39449842dd1360fa5f92c990785bf7c8dcdcdMaurice Lam super.onViewCreated(view, savedInstanceState); 8017d66bea42fc377a29fe4547f78dc17454f0f49fAjay Nadathur final Activity activity = getActivity(); 8117d66bea42fc377a29fe4547f78dc17454f0f49fAjay Nadathur ChooseLockGenericController chooseLockGenericController = 8217d66bea42fc377a29fe4547f78dc17454f0f49fAjay Nadathur new ChooseLockGenericController(activity, mUserId); 8317d66bea42fc377a29fe4547f78dc17454f0f49fAjay Nadathur boolean anyOptionsShown = chooseLockGenericController.getVisibleScreenLockTypes( 8417d66bea42fc377a29fe4547f78dc17454f0f49fAjay Nadathur DevicePolicyManager.PASSWORD_QUALITY_SOMETHING, false).size() > 0; 8517d66bea42fc377a29fe4547f78dc17454f0f49fAjay Nadathur boolean showOptionsButton = activity.getIntent().getBooleanExtra( 86a1314df69c193063cd2dfc0b84f0936855ac85abAjay Nadathur ChooseLockGeneric.ChooseLockGenericFragment.EXTRA_SHOW_OPTIONS_BUTTON, false); 8717d66bea42fc377a29fe4547f78dc17454f0f49fAjay Nadathur if (!anyOptionsShown) { 8817d66bea42fc377a29fe4547f78dc17454f0f49fAjay Nadathur Log.w(TAG, "Visible screen lock types is empty!"); 8917d66bea42fc377a29fe4547f78dc17454f0f49fAjay Nadathur } 9017d66bea42fc377a29fe4547f78dc17454f0f49fAjay Nadathur 9117d66bea42fc377a29fe4547f78dc17454f0f49fAjay Nadathur if (showOptionsButton && anyOptionsShown) { 9262c0c3c324aca7eaf78d7d5e0c8a6ae0213e1f80Maurice Lam mOptionsButton = view.findViewById(R.id.screen_lock_options); 9362c0c3c324aca7eaf78d7d5e0c8a6ae0213e1f80Maurice Lam mOptionsButton.setVisibility(View.VISIBLE); 9462c0c3c324aca7eaf78d7d5e0c8a6ae0213e1f80Maurice Lam mOptionsButton.setOnClickListener(this); 95edb39449842dd1360fa5f92c990785bf7c8dcdcdMaurice Lam } 96edb39449842dd1360fa5f92c990785bf7c8dcdcdMaurice Lam } 97edb39449842dd1360fa5f92c990785bf7c8dcdcdMaurice Lam 98edb39449842dd1360fa5f92c990785bf7c8dcdcdMaurice Lam @Override 99edb39449842dd1360fa5f92c990785bf7c8dcdcdMaurice Lam public void onClick(View v) { 100edb39449842dd1360fa5f92c990785bf7c8dcdcdMaurice Lam switch (v.getId()) { 101edb39449842dd1360fa5f92c990785bf7c8dcdcdMaurice Lam case R.id.screen_lock_options: 102a1314df69c193063cd2dfc0b84f0936855ac85abAjay Nadathur ChooseLockTypeDialogFragment.newInstance(mUserId) 103a1314df69c193063cd2dfc0b84f0936855ac85abAjay Nadathur .show(getChildFragmentManager(), null); 104edb39449842dd1360fa5f92c990785bf7c8dcdcdMaurice Lam break; 105a1314df69c193063cd2dfc0b84f0936855ac85abAjay Nadathur case R.id.skip_button: 1064c930fc2d5bf3a3ea3caf5df6e5eddb6c9a90a60Maurice Lam SetupSkipDialog dialog = SetupSkipDialog.newInstance( 1074c930fc2d5bf3a3ea3caf5df6e5eddb6c9a90a60Maurice Lam getActivity().getIntent() 1084c930fc2d5bf3a3ea3caf5df6e5eddb6c9a90a60Maurice Lam .getBooleanExtra(SetupSkipDialog.EXTRA_FRP_SUPPORTED, false)); 1094c930fc2d5bf3a3ea3caf5df6e5eddb6c9a90a60Maurice Lam dialog.show(getFragmentManager()); 1104c930fc2d5bf3a3ea3caf5df6e5eddb6c9a90a60Maurice Lam break; 111edb39449842dd1360fa5f92c990785bf7c8dcdcdMaurice Lam default: 112edb39449842dd1360fa5f92c990785bf7c8dcdcdMaurice Lam super.onClick(v); 113edb39449842dd1360fa5f92c990785bf7c8dcdcdMaurice Lam } 114edb39449842dd1360fa5f92c990785bf7c8dcdcdMaurice Lam } 115edb39449842dd1360fa5f92c990785bf7c8dcdcdMaurice Lam 116ecd2b7b81fd2faa2f2f3dbe5a169c749321f3d89Maurice Lam @Override 117ecd2b7b81fd2faa2f2f3dbe5a169c749321f3d89Maurice Lam protected Intent getRedactionInterstitialIntent(Context context) { 118957fc67af21b87c01e2c5939f0611021d8fe6c31Maurice Lam // Setup wizard's redaction interstitial is deferred to optional step. Enable that 119957fc67af21b87c01e2c5939f0611021d8fe6c31Maurice Lam // optional step if the lock screen was set up. 120957fc67af21b87c01e2c5939f0611021d8fe6c31Maurice Lam SetupRedactionInterstitial.setEnabled(context, true); 121dd05ab7600f79a6e77b6b5ed3916823d5985df72Udam Saini return null; 122ecd2b7b81fd2faa2f2f3dbe5a169c749321f3d89Maurice Lam } 123edb39449842dd1360fa5f92c990785bf7c8dcdcdMaurice Lam 124edb39449842dd1360fa5f92c990785bf7c8dcdcdMaurice Lam @Override 125edb39449842dd1360fa5f92c990785bf7c8dcdcdMaurice Lam public void onLockTypeSelected(ScreenLockType lock) { 126a5f7392d511ebe7eab69b959e8e6a103bbba1f84Ajay Nadathur ScreenLockType currentLockType = mIsAlphaMode ? 127a5f7392d511ebe7eab69b959e8e6a103bbba1f84Ajay Nadathur ScreenLockType.PASSWORD : ScreenLockType.PIN; 128a1314df69c193063cd2dfc0b84f0936855ac85abAjay Nadathur if (lock == currentLockType) { 129a5f7392d511ebe7eab69b959e8e6a103bbba1f84Ajay Nadathur return; 130a5f7392d511ebe7eab69b959e8e6a103bbba1f84Ajay Nadathur } 131a1314df69c193063cd2dfc0b84f0936855ac85abAjay Nadathur startChooseLockActivity(lock, getActivity()); 132edb39449842dd1360fa5f92c990785bf7c8dcdcdMaurice Lam } 13362c0c3c324aca7eaf78d7d5e0c8a6ae0213e1f80Maurice Lam 13462c0c3c324aca7eaf78d7d5e0c8a6ae0213e1f80Maurice Lam @Override 13562c0c3c324aca7eaf78d7d5e0c8a6ae0213e1f80Maurice Lam protected void updateUi() { 13662c0c3c324aca7eaf78d7d5e0c8a6ae0213e1f80Maurice Lam super.updateUi(); 137a1314df69c193063cd2dfc0b84f0936855ac85abAjay Nadathur mSkipButton.setVisibility(mForFingerprint ? View.GONE : View.VISIBLE); 138be2246bee734263970b4f6a5c393b72fccbdea2aAjay Nadathur 13962c0c3c324aca7eaf78d7d5e0c8a6ae0213e1f80Maurice Lam if (mOptionsButton != null) { 14062c0c3c324aca7eaf78d7d5e0c8a6ae0213e1f80Maurice Lam mOptionsButton.setVisibility( 14162c0c3c324aca7eaf78d7d5e0c8a6ae0213e1f80Maurice Lam mUiStage == Stage.Introduction ? View.VISIBLE : View.GONE); 14262c0c3c324aca7eaf78d7d5e0c8a6ae0213e1f80Maurice Lam } 14362c0c3c324aca7eaf78d7d5e0c8a6ae0213e1f80Maurice Lam } 1446b19fa9017800b94c75238339a337fd8f6c3e808Maurice Lam } 1456b19fa9017800b94c75238339a337fd8f6c3e808Maurice Lam} 146