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.app.Activity;
20import android.content.Context;
21import android.content.Intent;
22import android.content.res.Resources;
23import android.os.Bundle;
24import android.view.LayoutInflater;
25import android.view.View;
26import android.view.ViewGroup;
27
28import com.android.settings.notification.RedactionInterstitial;
29import com.android.setupwizardlib.SetupWizardLayout;
30import com.android.setupwizardlib.view.NavigationBar;
31
32/**
33 * Setup Wizard's version of RedactionInterstitial screen. It inherits the logic and basic structure
34 * from RedactionInterstitial class, and should remain similar to that behaviorally. This class
35 * should only overload base methods for minor theme and behavior differences specific to Setup
36 * Wizard. Other changes should be done to RedactionInterstitial class instead and let this class
37 * inherit those changes.
38 */
39public class SetupRedactionInterstitial extends RedactionInterstitial {
40
41    public static Intent createStartIntent(Context ctx) {
42        Intent startIntent = RedactionInterstitial.createStartIntent(ctx);
43        if (startIntent != null) {
44            startIntent.setClass(ctx, SetupRedactionInterstitial.class);
45            startIntent.putExtra(EXTRA_PREFS_SHOW_BUTTON_BAR, false)
46                    .putExtra(EXTRA_SHOW_FRAGMENT_TITLE_RESID, -1);
47        }
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    public static class SetupEncryptionInterstitialFragment extends RedactionInterstitialFragment
71            implements NavigationBar.NavigationBarListener {
72
73        @Override
74        public View onCreateView(LayoutInflater inflater, ViewGroup container,
75                Bundle savedInstanceState) {
76            return inflater.inflate(R.layout.setup_redaction_interstitial, container, false);
77        }
78
79        @Override
80        public void onViewCreated(View view, Bundle savedInstanceState) {
81            super.onViewCreated(view, savedInstanceState);
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            navigationBar.getBackButton().setVisibility(View.GONE);
88            SetupWizardUtils.setImmersiveMode(getActivity());
89        }
90
91        @Override
92        public void onNavigateBack() {
93            final Activity activity = getActivity();
94            if (activity != null) {
95                activity.onBackPressed();
96            }
97        }
98
99        @Override
100        public void onNavigateNext() {
101            final SetupRedactionInterstitial activity = (SetupRedactionInterstitial) getActivity();
102            if (activity != null) {
103                activity.setResult(RESULT_OK, activity.getResultIntentData());
104                finish();
105            }
106        }
107    }
108}
109