SetupEncryptionInterstitial.java revision 190ec1c14acbe305ac38d7d584a66ea57b7392fa
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
17package com.android.settings;
18
19import android.content.Context;
20import android.content.Intent;
21import android.content.res.Resources;
22import android.os.Bundle;
23import android.support.v7.widget.RecyclerView;
24import android.view.LayoutInflater;
25import android.view.View;
26import android.view.ViewGroup;
27import android.widget.LinearLayout;
28import android.widget.TextView;
29
30import com.android.setupwizardlib.GlifPreferenceLayout;
31
32/**
33 * Setup Wizard's version of EncryptionInterstitial screen. It inherits the logic and basic
34 * structure from EncryptionInterstitial class, and should remain similar to that behaviorally. This
35 * class should only overload base methods for minor theme and behavior differences specific to
36 * Setup Wizard. Other changes should be done to EncryptionInterstitial class instead and let this
37 * class inherit those changes.
38 */
39public class SetupEncryptionInterstitial extends EncryptionInterstitial {
40
41    public static Intent createStartIntent(Context ctx, int quality,
42            boolean requirePasswordDefault, Intent unlockMethodIntent) {
43        Intent startIntent = EncryptionInterstitial.createStartIntent(ctx, quality,
44                requirePasswordDefault, unlockMethodIntent);
45        startIntent.setClass(ctx, SetupEncryptionInterstitial.class);
46        startIntent.putExtra(EXTRA_PREFS_SHOW_BUTTON_BAR, false)
47                .putExtra(EXTRA_SHOW_FRAGMENT_TITLE_RESID, -1);
48        return startIntent;
49    }
50
51    @Override
52    public Intent getIntent() {
53        Intent modIntent = new Intent(super.getIntent());
54        modIntent.putExtra(EXTRA_SHOW_FRAGMENT,
55                SetupEncryptionInterstitialFragment.class.getName());
56        return modIntent;
57    }
58
59    @Override
60    protected boolean isValidFragment(String fragmentName) {
61        return SetupEncryptionInterstitialFragment.class.getName().equals(fragmentName);
62    }
63
64    @Override
65    protected void onApplyThemeResource(Resources.Theme theme, int resid, boolean first) {
66        resid = SetupWizardUtils.getTheme(getIntent());
67        super.onApplyThemeResource(theme, resid, first);
68    }
69
70    @Override
71    protected void onCreate(Bundle savedInstance) {
72        super.onCreate(savedInstance);
73        LinearLayout layout = (LinearLayout) findViewById(R.id.content_parent);
74        layout.setFitsSystemWindows(false);
75    }
76
77    public static class SetupEncryptionInterstitialFragment extends EncryptionInterstitialFragment {
78
79        @Override
80        public void onViewCreated(View view, Bundle savedInstanceState) {
81            super.onViewCreated(view, savedInstanceState);
82
83            final GlifPreferenceLayout layout = (GlifPreferenceLayout) view;
84            layout.setDividerInset(getContext().getResources().getDimensionPixelSize(
85                    R.dimen.suw_items_glif_icon_divider_inset));
86            layout.setIcon(getContext().getDrawable(R.drawable.ic_lock));
87
88            layout.setHeaderText(R.string.encryption_interstitial_header);
89
90            // Use the dividers in SetupWizardRecyclerLayout. Suppress the dividers in
91            // PreferenceFragment.
92            setDivider(null);
93        }
94
95        @Override
96        protected TextView createHeaderView() {
97            TextView message = (TextView) LayoutInflater.from(getActivity()).inflate(
98                    R.layout.setup_encryption_interstitial_header, null, false);
99            return message;
100        }
101
102        @Override
103        public RecyclerView onCreateRecyclerView(LayoutInflater inflater, ViewGroup parent,
104                                                 Bundle savedInstanceState) {
105            GlifPreferenceLayout layout = (GlifPreferenceLayout) parent;
106            return layout.onCreateRecyclerView(inflater, parent, savedInstanceState);
107        }
108    }
109}
110