2 * Copyright (C) 2010 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.AlertDialog;
20 import android.app.Dialog;
21 import android.app.Fragment;
22 import android.content.DialogInterface;
23 import android.content.DialogInterface.OnClickListener;
24 import android.os.Bundle;
25 import android.os.UserHandle;
26 import android.text.TextUtils;
27 import android.view.LayoutInflater;
28 import android.view.View;
29 import android.widget.EditText;
31 import com.android.internal.logging.nano.MetricsProto;
32 import com.android.internal.widget.LockPatternUtils;
33 import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
34 import com.android.settings.security.OwnerInfoPreferenceController.OwnerInfoCallback;
36 public class OwnerInfoSettings extends InstrumentedDialogFragment implements OnClickListener {
38 private static final String TAG_OWNER_INFO = "ownerInfo";
42 private LockPatternUtils mLockPatternUtils;
43 private EditText mOwnerInfo;
46 public void onCreate(Bundle savedInstanceState) {
47 super.onCreate(savedInstanceState);
48 mUserId = UserHandle.myUserId();
49 mLockPatternUtils = new LockPatternUtils(getActivity());
53 public Dialog onCreateDialog(Bundle savedInstanceState) {
54 mView = LayoutInflater.from(getActivity()).inflate(R.layout.ownerinfo, null);
56 return new AlertDialog.Builder(getActivity())
57 .setTitle(R.string.owner_info_settings_title)
59 .setPositiveButton(R.string.save, this)
60 .setNegativeButton(R.string.cancel, this)
64 private void initView() {
65 String info = mLockPatternUtils.getOwnerInfo(mUserId);
67 mOwnerInfo = (EditText) mView.findViewById(R.id.owner_info_edit_text);
68 if (!TextUtils.isEmpty(info)) {
69 mOwnerInfo.setText(info);
74 public void onClick(DialogInterface dialog, int which) {
75 if (which == AlertDialog.BUTTON_POSITIVE) {
76 String info = mOwnerInfo.getText().toString();
77 mLockPatternUtils.setOwnerInfoEnabled(!TextUtils.isEmpty(info), mUserId);
78 mLockPatternUtils.setOwnerInfo(info, mUserId);
80 if (getTargetFragment() instanceof OwnerInfoCallback) {
81 ((OwnerInfoCallback) getTargetFragment()).onOwnerInfoUpdated();
86 public static void show(Fragment parent) {
87 if (!parent.isAdded()) return;
89 final OwnerInfoSettings dialog = new OwnerInfoSettings();
90 dialog.setTargetFragment(parent, 0);
91 dialog.show(parent.getFragmentManager(), TAG_OWNER_INFO);
95 public int getMetricsCategory() {
96 return MetricsProto.MetricsEvent.DIALOG_OWNER_INFO_SETTINGS;