OSDN Git Service

[ScreenLock] Style encryption interstitial in SUW
[android-x86/packages-apps-Settings.git] / src / com / android / settings / SetupEncryptionInterstitial.java
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;
18
19 import com.android.setupwizardlib.SetupWizardLayout;
20 import com.android.setupwizardlib.view.NavigationBar;
21
22 import android.app.Activity;
23 import android.content.Context;
24 import android.content.Intent;
25 import android.content.res.Resources;
26 import android.os.Bundle;
27 import android.view.LayoutInflater;
28 import android.view.View;
29 import android.view.ViewGroup;
30
31 /**
32  * Setup Wizard's version of EncryptionInterstitial screen. It inherits the logic and basic
33  * structure from EncryptionInterstitial class, and should remain similar to that behaviorally. This
34  * class should only overload base methods for minor theme and behavior differences specific to
35  * Setup Wizard. Other changes should be done to EncryptionInterstitial class instead and let this
36  * class inherit those changes.
37  */
38 public class SetupEncryptionInterstitial extends EncryptionInterstitial {
39
40     public static Intent createStartIntent(Context ctx, int quality,
41             boolean requirePasswordDefault) {
42         Intent startIntent = EncryptionInterstitial.createStartIntent(ctx, quality,
43                 requirePasswordDefault);
44         startIntent.setClass(ctx, SetupEncryptionInterstitial.class);
45         startIntent.putExtra(EXTRA_PREFS_SHOW_BUTTON_BAR, false)
46                 .putExtra(EXTRA_SHOW_FRAGMENT_TITLE_RESID, -1);
47         return startIntent;
48     }
49
50     @Override
51     public Intent getIntent() {
52         Intent modIntent = new Intent(super.getIntent());
53         modIntent.putExtra(EXTRA_SHOW_FRAGMENT,
54                 SetupEncryptionInterstitialFragment.class.getName());
55         return modIntent;
56     }
57
58     @Override
59     protected boolean isValidFragment(String fragmentName) {
60         return SetupEncryptionInterstitialFragment.class.getName().equals(fragmentName);
61     }
62
63     @Override
64     protected void onApplyThemeResource(Resources.Theme theme, int resid, boolean first) {
65         resid = SetupWizardUtils.getTheme(getIntent());
66         super.onApplyThemeResource(theme, resid, first);
67     }
68
69     public static class SetupEncryptionInterstitialFragment extends EncryptionInterstitialFragment
70             implements NavigationBar.NavigationBarListener {
71
72         @Override
73         public View onCreateView(LayoutInflater inflater, ViewGroup container,
74                 Bundle savedInstanceState) {
75             return inflater.inflate(R.layout.setup_encryption_interstitial, container, false);
76         }
77
78         @Override
79         public void onViewCreated(View view, Bundle savedInstanceState) {
80             super.onViewCreated(view, savedInstanceState);
81
82             final SetupWizardLayout layout =
83                     (SetupWizardLayout) view.findViewById(R.id.setup_wizard_layout);
84
85             final NavigationBar navigationBar = layout.getNavigationBar();
86             navigationBar.setNavigationBarListener(this);
87
88             Activity activity = getActivity();
89             if (activity != null) {
90                 activity.setTitle(R.string.encryption_interstitial_header);
91                 SetupWizardUtils.setImmersiveMode(activity);
92             }
93         }
94
95         @Override
96         public void onNavigateBack() {
97             final Activity activity = getActivity();
98             if (activity != null) {
99                 activity.onBackPressed();
100             }
101         }
102
103         @Override
104         public void onNavigateNext() {
105             final SetupEncryptionInterstitial activity =
106                     (SetupEncryptionInterstitial) getActivity();
107             if (activity != null) {
108                 activity.setResult(RESULT_OK, activity.getResultIntentData());
109                 finish();
110             }
111         }
112     }
113 }