From 3bcd76ce63c77b229e2d25a0191ccb568824f5c4 Mon Sep 17 00:00:00 2001 From: Jason Monk Date: Tue, 21 Apr 2015 11:20:20 -0400 Subject: Change owner info to be a dialog rather than screen Bug: 15937670 Change-Id: I8d8609ff165c4a76e318a80a62fb1dc9effbc82a --- res/layout/ownerinfo.xml | 79 ++++--------- res/values/strings.xml | 12 +- res/xml/security_settings_chooser.xml | 3 +- res/xml/security_settings_lockscreen.xml | 3 +- res/xml/security_settings_password.xml | 3 +- res/xml/security_settings_pattern.xml | 3 +- res/xml/security_settings_pin.xml | 3 +- src/com/android/settings/OwnerInfoSettings.java | 125 ++++++++++----------- src/com/android/settings/SecuritySettings.java | 44 +++++--- .../settings/SingleLineSummaryPreference.java | 41 +++++++ src/com/android/settings/users/UserSettings.java | 11 +- 11 files changed, 159 insertions(+), 168 deletions(-) create mode 100644 src/com/android/settings/SingleLineSummaryPreference.java diff --git a/res/layout/ownerinfo.xml b/res/layout/ownerinfo.xml index 6adec7d..80f0192 100644 --- a/res/layout/ownerinfo.xml +++ b/res/layout/ownerinfo.xml @@ -16,70 +16,29 @@ - - - - - - - - - - - - - - - - - + android:layout_height="wrap_content" + android:gravity="top" + android:hint="@string/owner_info_settings_edit_text_hint" + android:maxLength="100" + android:inputType="textMultiLine|textCapSentences" + /> + + diff --git a/res/values/strings.xml b/res/values/strings.xml index 153492b..7e7026d 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -700,17 +700,17 @@ Show owner info on lock screen - Owner info + Lock screen message Enable widgets Disabled by administrator - - + + None + + %1$d / %2$d - Type text to display on the lock screen - - Show user info on lock screen + E.g., Joe\'s Android. User info diff --git a/res/xml/security_settings_chooser.xml b/res/xml/security_settings_chooser.xml index 4c1d809..af7bfeb 100644 --- a/res/xml/security_settings_chooser.xml +++ b/res/xml/security_settings_chooser.xml @@ -27,9 +27,8 @@ android:summary="@string/unlock_set_unlock_mode_none" android:persistent="false"/> - diff --git a/res/xml/security_settings_lockscreen.xml b/res/xml/security_settings_lockscreen.xml index 88df74b..480d6ee 100644 --- a/res/xml/security_settings_lockscreen.xml +++ b/res/xml/security_settings_lockscreen.xml @@ -29,9 +29,8 @@ settings:keywords="@string/keywords_lockscreen" android:persistent="false"/> - diff --git a/res/xml/security_settings_password.xml b/res/xml/security_settings_password.xml index 9f1092a..b610562 100644 --- a/res/xml/security_settings_password.xml +++ b/res/xml/security_settings_password.xml @@ -41,9 +41,8 @@ android:key="power_button_instantly_locks" android:title="@string/lockpattern_settings_enable_power_button_instantly_locks"/> - diff --git a/res/xml/security_settings_pattern.xml b/res/xml/security_settings_pattern.xml index ceb749c..867bed4 100644 --- a/res/xml/security_settings_pattern.xml +++ b/res/xml/security_settings_pattern.xml @@ -45,8 +45,7 @@ android:key="power_button_instantly_locks" android:title="@string/lockpattern_settings_enable_power_button_instantly_locks"/> - diff --git a/res/xml/security_settings_pin.xml b/res/xml/security_settings_pin.xml index 4470b1d..ac09a2c 100644 --- a/res/xml/security_settings_pin.xml +++ b/res/xml/security_settings_pin.xml @@ -41,9 +41,8 @@ android:key="power_button_instantly_locks" android:title="@string/lockpattern_settings_enable_power_button_instantly_locks"/> - diff --git a/src/com/android/settings/OwnerInfoSettings.java b/src/com/android/settings/OwnerInfoSettings.java index 54b7cab..56da637 100644 --- a/src/com/android/settings/OwnerInfoSettings.java +++ b/src/com/android/settings/OwnerInfoSettings.java @@ -16,110 +16,105 @@ package com.android.settings; +import android.app.AlertDialog; +import android.app.Dialog; +import android.app.DialogFragment; import android.app.Fragment; +import android.content.DialogInterface; +import android.content.DialogInterface.OnClickListener; import android.os.Bundle; import android.os.UserHandle; -import android.os.UserManager; +import android.text.Editable; import android.text.TextUtils; +import android.text.TextWatcher; import android.view.LayoutInflater; import android.view.View; -import android.view.ViewGroup; -import android.widget.CheckBox; -import android.widget.CompoundButton; import android.widget.EditText; -import android.widget.CompoundButton.OnCheckedChangeListener; +import android.widget.TextView; -import com.android.internal.logging.MetricsLogger; import com.android.internal.widget.LockPatternUtils; -public class OwnerInfoSettings extends InstrumentedFragment { +public class OwnerInfoSettings extends DialogFragment implements OnClickListener { - public static final String EXTRA_SHOW_NICKNAME = "show_nickname"; + private static final String TAG_OWNER_INFO = "ownerInfo"; + + private static final int MAX_CHARS = 100; private View mView; - private CheckBox mCheckbox; private int mUserId; private LockPatternUtils mLockPatternUtils; private EditText mOwnerInfo; - private EditText mNickname; - private boolean mShowNickname; + private TextView mOwnerInfoStatus; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - Bundle args = getArguments(); - if (args != null && args.containsKey(EXTRA_SHOW_NICKNAME)) { - mShowNickname = args.getBoolean(EXTRA_SHOW_NICKNAME); - } + mUserId = UserHandle.myUserId(); + mLockPatternUtils = new LockPatternUtils(getActivity()); } @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { - mView = inflater.inflate(R.layout.ownerinfo, container, false); - mUserId = UserHandle.myUserId(); - mLockPatternUtils = new LockPatternUtils(getActivity()); + public Dialog onCreateDialog(Bundle savedInstanceState) { + mView = LayoutInflater.from(getActivity()).inflate(R.layout.ownerinfo, null); initView(); - return mView; + return new AlertDialog.Builder(getActivity()) + .setTitle(R.string.owner_info_settings_title) + .setView(mView) + .setPositiveButton(R.string.save, this) + .setNegativeButton(R.string.cancel, this) + .show(); } private void initView() { - mNickname = (EditText) mView.findViewById(R.id.owner_info_nickname); - if (!mShowNickname) { - mNickname.setVisibility(View.GONE); - } else { - mNickname.setText(UserManager.get(getActivity()).getUserName()); - mNickname.setSelected(true); - } - - final boolean enabled = mLockPatternUtils.isOwnerInfoEnabled(); - - mCheckbox = (CheckBox) mView.findViewById(R.id.show_owner_info_on_lockscreen_checkbox); - mCheckbox.setChecked(enabled); - if (UserHandle.myUserId() != UserHandle.USER_OWNER) { - if (UserManager.get(getActivity()).isLinkedUser()) { - mCheckbox.setText(R.string.show_profile_info_on_lockscreen_label); - } else { - mCheckbox.setText(R.string.show_user_info_on_lockscreen_label); - } - } - mCheckbox.setOnCheckedChangeListener(new OnCheckedChangeListener() { - public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - mLockPatternUtils.setOwnerInfoEnabled(isChecked); - mOwnerInfo.setEnabled(isChecked); // disable text field if not enabled - } - }); - String info = mLockPatternUtils.getOwnerInfo(mUserId); mOwnerInfo = (EditText) mView.findViewById(R.id.owner_info_edit_text); - mOwnerInfo.setEnabled(enabled); if (!TextUtils.isEmpty(info)) { mOwnerInfo.setText(info); } - } + mOwnerInfoStatus = (TextView) mView.findViewById(R.id.owner_info_status); + updateOwnerInfoStatus(); - @Override - protected int getMetricsCategory() { - return MetricsLogger.OWNER_INFO; + mOwnerInfo.addTextChangedListener(new TextWatcher() { + @Override + public void onTextChanged(CharSequence s, int start, int before, int count) { + } + + @Override + public void beforeTextChanged(CharSequence s, int start, int count, int after) { + } + + @Override + public void afterTextChanged(Editable s) { + updateOwnerInfoStatus(); + } + }); } - @Override - public void onPause() { - super.onPause(); - saveChanges(); + private void updateOwnerInfoStatus() { + String status = getString(R.string.owner_info_settings_status, + mOwnerInfo.getText().toString().length(), MAX_CHARS); + mOwnerInfoStatus.setText(status); } - void saveChanges() { - String info = mOwnerInfo.getText().toString(); - mLockPatternUtils.setOwnerInfo(info, mUserId); - if (mShowNickname) { - String oldName = UserManager.get(getActivity()).getUserName(); - CharSequence newName = mNickname.getText(); - if (!TextUtils.isEmpty(newName) && !newName.equals(oldName)) { - UserManager.get(getActivity()).setUserName(UserHandle.myUserId(), - newName.toString()); + @Override + public void onClick(DialogInterface dialog, int which) { + if (which == AlertDialog.BUTTON_POSITIVE) { + String info = mOwnerInfo.getText().toString(); + mLockPatternUtils.setOwnerInfoEnabled(!TextUtils.isEmpty(info)); + mLockPatternUtils.setOwnerInfo(info, mUserId); + + if (getTargetFragment() instanceof SecuritySettings) { + ((SecuritySettings) getTargetFragment()).updateOwnerInfo(); } } } + + public static void show(Fragment parent) { + if (!parent.isAdded()) return; + + final OwnerInfoSettings dialog = new OwnerInfoSettings(); + dialog.setTargetFragment(parent, 0); + dialog.show(parent.getFragmentManager(), TAG_OWNER_INFO); + } } diff --git a/src/com/android/settings/SecuritySettings.java b/src/com/android/settings/SecuritySettings.java index 30b7590..59816ac 100644 --- a/src/com/android/settings/SecuritySettings.java +++ b/src/com/android/settings/SecuritySettings.java @@ -17,6 +17,8 @@ package com.android.settings; +import static android.provider.Settings.System.SCREEN_OFF_TIMEOUT; + import android.app.Activity; import android.app.AlertDialog; import android.app.admin.DevicePolicyManager; @@ -26,26 +28,26 @@ import android.content.DialogInterface; import android.content.Intent; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; -import android.content.pm.UserInfo; import android.content.res.Resources; +import android.hardware.fingerprint.Fingerprint; +import android.hardware.fingerprint.FingerprintManager; import android.os.Bundle; import android.os.UserHandle; import android.os.UserManager; -import android.preference.SwitchPreference; import android.preference.ListPreference; import android.preference.Preference; import android.preference.Preference.OnPreferenceChangeListener; +import android.preference.Preference.OnPreferenceClickListener; import android.preference.PreferenceGroup; import android.preference.PreferenceScreen; +import android.preference.SwitchPreference; import android.provider.SearchIndexableResource; import android.provider.Settings; import android.security.KeyStore; -import android.hardware.fingerprint.Fingerprint; -import android.hardware.fingerprint.FingerprintManager; import android.service.trust.TrustAgentService; -import android.telephony.TelephonyManager; -import android.telephony.SubscriptionManager; import android.telephony.SubscriptionInfo; +import android.telephony.SubscriptionManager; +import android.telephony.TelephonyManager; import android.text.TextUtils; import android.util.Log; @@ -60,8 +62,6 @@ import com.android.settings.search.SearchIndexableRaw; import java.util.ArrayList; import java.util.List; -import static android.provider.Settings.System.SCREEN_OFF_TIMEOUT; - /** * Gesture lock pattern settings. */ @@ -129,6 +129,7 @@ public class SecuritySettings extends SettingsPreferenceFragment private boolean mIsPrimary; private Intent mTrustAgentClickIntent; + private Preference mOwnerInfoPref; @Override protected int getMetricsCategory() { @@ -202,16 +203,15 @@ public class SecuritySettings extends SettingsPreferenceFragment // Add options for device encryption mIsPrimary = UserHandle.myUserId() == UserHandle.USER_OWNER; - if (!mIsPrimary) { - // Rename owner info settings - Preference ownerInfoPref = findPreference(KEY_OWNER_INFO_SETTINGS); - if (ownerInfoPref != null) { - if (UserManager.get(getActivity()).isLinkedUser()) { - ownerInfoPref.setTitle(R.string.profile_info_settings_title); - } else { - ownerInfoPref.setTitle(R.string.user_info_settings_title); + mOwnerInfoPref = findPreference(KEY_OWNER_INFO_SETTINGS); + if (mOwnerInfoPref != null) { + mOwnerInfoPref.setOnPreferenceClickListener(new OnPreferenceClickListener() { + @Override + public boolean onPreferenceClick(Preference preference) { + OwnerInfoSettings.show(SecuritySettings.this); + return true; } - } + }); } if (mIsPrimary) { @@ -603,6 +603,16 @@ public class SecuritySettings extends SettingsPreferenceFragment if (mResetCredentials != null) { mResetCredentials.setEnabled(!mKeyStore.isEmpty()); } + + updateOwnerInfo(); + } + + public void updateOwnerInfo() { + if (mOwnerInfoPref != null) { + mOwnerInfoPref.setSummary(mLockPatternUtils.isOwnerInfoEnabled() + ? mLockPatternUtils.getOwnerInfo(UserHandle.myUserId()) + : getString(R.string.owner_info_settings_summary)); + } } @Override diff --git a/src/com/android/settings/SingleLineSummaryPreference.java b/src/com/android/settings/SingleLineSummaryPreference.java new file mode 100644 index 0000000..420fe08 --- /dev/null +++ b/src/com/android/settings/SingleLineSummaryPreference.java @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.android.settings; + +import android.content.Context; +import android.preference.Preference; +import android.text.TextUtils.TruncateAt; +import android.util.AttributeSet; +import android.view.View; +import android.widget.TextView; + +public class SingleLineSummaryPreference extends Preference { + + public SingleLineSummaryPreference(Context context, AttributeSet attrs) { + super(context, attrs); + } + + @Override + protected void onBindView(View view) { + super.onBindView(view); + + final TextView summaryView = (TextView) view.findViewById( + com.android.internal.R.id.summary); + summaryView.setSingleLine(); + summaryView.setEllipsize(TruncateAt.END); + } + +} diff --git a/src/com/android/settings/users/UserSettings.java b/src/com/android/settings/users/UserSettings.java index 6d0cc5a..f3b60fc 100644 --- a/src/com/android/settings/users/UserSettings.java +++ b/src/com/android/settings/users/UserSettings.java @@ -461,16 +461,7 @@ public class UserSettings extends SettingsPreferenceFragment null, 0); } else if (info.id == UserHandle.myUserId()) { // Jump to owner info panel - Bundle extras = new Bundle(); - if (!info.isRestricted()) { - extras.putBoolean(OwnerInfoSettings.EXTRA_SHOW_NICKNAME, true); - } - int titleResId = info.id == UserHandle.USER_OWNER ? R.string.owner_info_settings_title - : (info.isRestricted() ? R.string.profile_info_settings_title - : R.string.user_info_settings_title); - ((SettingsActivity) getActivity()).startPreferencePanel( - OwnerInfoSettings.class.getName(), - extras, titleResId, null, null, 0); + OwnerInfoSettings.show(this); } else if (mIsOwner) { Bundle extras = new Bundle(); extras.putInt(UserDetailsSettings.EXTRA_USER_ID, userId); -- cgit v1.1