1 /* 2 * Copyright (C) 2010 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.users; 18 19 import android.app.Dialog; 20 import android.app.settings.SettingsEnums; 21 import android.content.DialogInterface; 22 import android.content.DialogInterface.OnClickListener; 23 import android.os.Bundle; 24 import android.os.UserHandle; 25 import android.text.TextUtils; 26 import android.view.LayoutInflater; 27 import android.view.View; 28 import android.widget.EditText; 29 30 import androidx.appcompat.app.AlertDialog; 31 import androidx.fragment.app.Fragment; 32 33 import com.android.internal.widget.LockPatternUtils; 34 import com.android.settings.R; 35 import com.android.settings.core.instrumentation.InstrumentedDialogFragment; 36 import com.android.settings.security.OwnerInfoPreferenceController.OwnerInfoCallback; 37 38 public class OwnerInfoSettings extends InstrumentedDialogFragment implements OnClickListener { 39 40 private static final String TAG_OWNER_INFO = "ownerInfo"; 41 42 private View mView; 43 private int mUserId; 44 private LockPatternUtils mLockPatternUtils; 45 private EditText mOwnerInfo; 46 47 @Override onCreate(Bundle savedInstanceState)48 public void onCreate(Bundle savedInstanceState) { 49 super.onCreate(savedInstanceState); 50 mUserId = UserHandle.myUserId(); 51 mLockPatternUtils = new LockPatternUtils(getActivity()); 52 } 53 54 @Override onCreateDialog(Bundle savedInstanceState)55 public Dialog onCreateDialog(Bundle savedInstanceState) { 56 mView = LayoutInflater.from(getActivity()).inflate(R.layout.ownerinfo, null); 57 initView(); 58 return new AlertDialog.Builder(getActivity()) 59 .setTitle(R.string.owner_info_settings_title) 60 .setView(mView) 61 .setPositiveButton(R.string.save, this) 62 .setNegativeButton(R.string.cancel, this) 63 .show(); 64 } 65 initView()66 private void initView() { 67 String info = mLockPatternUtils.getOwnerInfo(mUserId); 68 69 mOwnerInfo = (EditText) mView.findViewById(R.id.owner_info_edit_text); 70 if (!TextUtils.isEmpty(info)) { 71 mOwnerInfo.setText(info); 72 mOwnerInfo.setSelection(info.length()); 73 } 74 } 75 76 @Override onClick(DialogInterface dialog, int which)77 public void onClick(DialogInterface dialog, int which) { 78 if (which == AlertDialog.BUTTON_POSITIVE) { 79 String info = mOwnerInfo.getText().toString(); 80 mLockPatternUtils.setOwnerInfoEnabled(!TextUtils.isEmpty(info), mUserId); 81 mLockPatternUtils.setOwnerInfo(info, mUserId); 82 83 if (getTargetFragment() instanceof OwnerInfoCallback) { 84 ((OwnerInfoCallback) getTargetFragment()).onOwnerInfoUpdated(); 85 } 86 } 87 } 88 show(Fragment parent)89 public static void show(Fragment parent) { 90 if (!parent.isAdded()) return; 91 92 final OwnerInfoSettings dialog = new OwnerInfoSettings(); 93 dialog.setTargetFragment(parent, 0); 94 dialog.show(parent.getFragmentManager(), TAG_OWNER_INFO); 95 } 96 97 @Override getMetricsCategory()98 public int getMetricsCategory() { 99 return SettingsEnums.DIALOG_OWNER_INFO_SETTINGS; 100 } 101 } 102