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