2 * Copyright (C) 2015 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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
17 package com.android.settings;
19 import android.app.Fragment;
20 import android.app.KeyguardManager;
21 import android.os.Bundle;
22 import android.os.UserManager;
23 import android.view.MenuItem;
24 import android.view.WindowManager;
26 public abstract class ConfirmDeviceCredentialBaseActivity extends SettingsActivity {
28 private static final String STATE_IS_KEYGUARD_LOCKED = "STATE_IS_KEYGUARD_LOCKED";
30 private boolean mRestoring;
31 private boolean mDark;
32 private boolean mEnterAnimationPending;
33 private boolean mFirstTimeVisible = true;
34 private boolean mIsKeyguardLocked = false;
37 protected void onCreate(Bundle savedState) {
38 int credentialOwnerUserId = Utils.getCredentialOwnerUserId(this,
39 Utils.getUserIdFromBundle(this, getIntent().getExtras()));
40 if (Utils.isManagedProfile(UserManager.get(this), credentialOwnerUserId)) {
41 setTheme(R.style.Theme_ConfirmDeviceCredentialsWork);
42 } else if (getIntent().getBooleanExtra(
43 ConfirmDeviceCredentialBaseFragment.DARK_THEME, false)) {
44 setTheme(R.style.Theme_ConfirmDeviceCredentialsDark);
47 super.onCreate(savedState);
48 mIsKeyguardLocked = savedState == null
49 ? getSystemService(KeyguardManager.class).isKeyguardLocked()
50 : savedState.getBoolean(STATE_IS_KEYGUARD_LOCKED, false);
51 // If the activity is launched, not due to config change, when keyguard is locked and the
52 // flag is set, assume it's launched on top of keyguard on purpose.
53 // TODO: Don't abuse SHOW_WHEN_LOCKED and don't check isKeyguardLocked.
54 // Set extra SHOW_WHEN_LOCKED and WindowManager FLAG_SHOW_WHEN_LOCKED only if it's
55 // truly on top of keyguard on purpose
56 if (mIsKeyguardLocked && getIntent().getBooleanExtra(
57 ConfirmDeviceCredentialBaseFragment.SHOW_WHEN_LOCKED, false)) {
58 getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
60 CharSequence msg = getIntent().getStringExtra(
61 ConfirmDeviceCredentialBaseFragment.TITLE_TEXT);
63 if (getActionBar() != null) {
64 getActionBar().setDisplayHomeAsUpEnabled(true);
65 getActionBar().setHomeButtonEnabled(true);
67 mRestoring = savedState != null;
71 public void onSaveInstanceState(Bundle outState) {
72 super.onSaveInstanceState(outState);
73 outState.putBoolean(STATE_IS_KEYGUARD_LOCKED, mIsKeyguardLocked);
77 public boolean onOptionsItemSelected(MenuItem item) {
78 if (item.getItemId() == android.R.id.home) {
82 return super.onOptionsItemSelected(item);
86 public void onResume() {
88 if (!isChangingConfigurations() && !mRestoring && mDark && mFirstTimeVisible) {
89 mFirstTimeVisible = false;
90 prepareEnterAnimation();
91 mEnterAnimationPending = true;
95 private ConfirmDeviceCredentialBaseFragment getFragment() {
96 Fragment fragment = getFragmentManager().findFragmentById(R.id.main_content);
97 if (fragment != null && fragment instanceof ConfirmDeviceCredentialBaseFragment) {
98 return (ConfirmDeviceCredentialBaseFragment) fragment;
104 public void onEnterAnimationComplete() {
105 super.onEnterAnimationComplete();
106 if (mEnterAnimationPending) {
107 startEnterAnimation();
108 mEnterAnimationPending = false;
112 public void prepareEnterAnimation() {
113 getFragment().prepareEnterAnimation();
116 public void startEnterAnimation() {
117 getFragment().startEnterAnimation();