Home | History | Annotate | Download | only in password
      1 /*
      2  * Copyright (C) 2014 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.password;
     18 
     19 import android.app.Activity;
     20 import android.app.Fragment;
     21 import android.app.admin.DevicePolicyManager;
     22 import android.content.Context;
     23 import android.content.Intent;
     24 import android.os.Bundle;
     25 import android.support.annotation.Nullable;
     26 import android.util.Log;
     27 import android.view.View;
     28 import android.widget.Button;
     29 import android.widget.LinearLayout;
     30 
     31 import com.android.settings.R;
     32 import com.android.settings.SetupRedactionInterstitial;
     33 import com.android.settings.password.ChooseLockTypeDialogFragment.OnLockTypeSelectedListener;
     34 
     35 /**
     36  * Setup Wizard's version of ChooseLockPassword screen. It inherits the logic and basic structure
     37  * from ChooseLockPassword class, and should remain similar to that behaviorally. This class should
     38  * only overload base methods for minor theme and behavior differences specific to Setup Wizard.
     39  * Other changes should be done to ChooseLockPassword class instead and let this class inherit
     40  * those changes.
     41  */
     42 public class SetupChooseLockPassword extends ChooseLockPassword {
     43 
     44     private static final String TAG = "SetupChooseLockPassword";
     45 
     46     public static Intent modifyIntentForSetup(
     47             Context context,
     48             Intent chooseLockPasswordIntent) {
     49         chooseLockPasswordIntent.setClass(context, SetupChooseLockPassword.class);
     50         chooseLockPasswordIntent.putExtra(EXTRA_PREFS_SHOW_BUTTON_BAR, false);
     51         return chooseLockPasswordIntent;
     52     }
     53 
     54     @Override
     55     protected boolean isValidFragment(String fragmentName) {
     56         return SetupChooseLockPasswordFragment.class.getName().equals(fragmentName);
     57     }
     58 
     59     @Override
     60     /* package */ Class<? extends Fragment> getFragmentClass() {
     61         return SetupChooseLockPasswordFragment.class;
     62     }
     63 
     64     @Override
     65     protected void onCreate(Bundle savedInstance) {
     66         super.onCreate(savedInstance);
     67         LinearLayout layout = (LinearLayout) findViewById(R.id.content_parent);
     68         layout.setFitsSystemWindows(false);
     69     }
     70 
     71     public static class SetupChooseLockPasswordFragment extends ChooseLockPasswordFragment
     72             implements OnLockTypeSelectedListener {
     73 
     74         @Nullable
     75         private Button mOptionsButton;
     76 
     77         @Override
     78         public void onViewCreated(View view, Bundle savedInstanceState) {
     79             super.onViewCreated(view, savedInstanceState);
     80             final Activity activity = getActivity();
     81             ChooseLockGenericController chooseLockGenericController =
     82                     new ChooseLockGenericController(activity, mUserId);
     83             boolean anyOptionsShown = chooseLockGenericController.getVisibleScreenLockTypes(
     84                     DevicePolicyManager.PASSWORD_QUALITY_SOMETHING, false).size() > 0;
     85             boolean showOptionsButton = activity.getIntent().getBooleanExtra(
     86                     ChooseLockGeneric.ChooseLockGenericFragment.EXTRA_SHOW_OPTIONS_BUTTON, false);
     87             if (!anyOptionsShown) {
     88                 Log.w(TAG, "Visible screen lock types is empty!");
     89             }
     90 
     91             if (showOptionsButton && anyOptionsShown) {
     92                 mOptionsButton = view.findViewById(R.id.screen_lock_options);
     93                 mOptionsButton.setVisibility(View.VISIBLE);
     94                 mOptionsButton.setOnClickListener(this);
     95             }
     96         }
     97 
     98         @Override
     99         public void onClick(View v) {
    100             switch (v.getId()) {
    101                 case R.id.screen_lock_options:
    102                     ChooseLockTypeDialogFragment.newInstance(mUserId)
    103                             .show(getChildFragmentManager(), null);
    104                     break;
    105                 case R.id.skip_button:
    106                     SetupSkipDialog dialog = SetupSkipDialog.newInstance(
    107                             getActivity().getIntent()
    108                                     .getBooleanExtra(SetupSkipDialog.EXTRA_FRP_SUPPORTED, false));
    109                     dialog.show(getFragmentManager());
    110                     break;
    111                 default:
    112                     super.onClick(v);
    113             }
    114         }
    115 
    116         @Override
    117         protected Intent getRedactionInterstitialIntent(Context context) {
    118             // Setup wizard's redaction interstitial is deferred to optional step. Enable that
    119             // optional step if the lock screen was set up.
    120             SetupRedactionInterstitial.setEnabled(context, true);
    121             return null;
    122         }
    123 
    124         @Override
    125         public void onLockTypeSelected(ScreenLockType lock) {
    126             ScreenLockType currentLockType = mIsAlphaMode ?
    127                     ScreenLockType.PASSWORD : ScreenLockType.PIN;
    128             if (lock == currentLockType) {
    129                 return;
    130             }
    131             startChooseLockActivity(lock, getActivity());
    132         }
    133 
    134         @Override
    135         protected void updateUi() {
    136             super.updateUi();
    137             mSkipButton.setVisibility(mForFingerprint ? View.GONE : View.VISIBLE);
    138 
    139             if (mOptionsButton != null) {
    140                 mOptionsButton.setVisibility(
    141                         mUiStage == Stage.Introduction ? View.VISIBLE : View.GONE);
    142             }
    143         }
    144     }
    145 }
    146