OSDN Git Service

[automerger] DO NOT MERGE Fix unexpected behavior in Bluetooth pairing am: 4f58c19afa...
[android-x86/packages-apps-Settings.git] / src / com / android / settings / OwnerInfoSettings.java
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;
18
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;
30
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;
35
36 public class OwnerInfoSettings extends InstrumentedDialogFragment implements OnClickListener {
37
38     private static final String TAG_OWNER_INFO = "ownerInfo";
39
40     private View mView;
41     private int mUserId;
42     private LockPatternUtils mLockPatternUtils;
43     private EditText mOwnerInfo;
44
45     @Override
46     public void onCreate(Bundle savedInstanceState) {
47         super.onCreate(savedInstanceState);
48         mUserId = UserHandle.myUserId();
49         mLockPatternUtils = new LockPatternUtils(getActivity());
50     }
51
52     @Override
53     public Dialog onCreateDialog(Bundle savedInstanceState) {
54         mView = LayoutInflater.from(getActivity()).inflate(R.layout.ownerinfo, null);
55         initView();
56         return new AlertDialog.Builder(getActivity())
57                 .setTitle(R.string.owner_info_settings_title)
58                 .setView(mView)
59                 .setPositiveButton(R.string.save, this)
60                 .setNegativeButton(R.string.cancel, this)
61                 .show();
62     }
63
64     private void initView() {
65         String info = mLockPatternUtils.getOwnerInfo(mUserId);
66
67         mOwnerInfo = (EditText) mView.findViewById(R.id.owner_info_edit_text);
68         if (!TextUtils.isEmpty(info)) {
69             mOwnerInfo.setText(info);
70         }
71     }
72
73     @Override
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);
79
80             if (getTargetFragment() instanceof OwnerInfoCallback) {
81                 ((OwnerInfoCallback) getTargetFragment()).onOwnerInfoUpdated();
82             }
83         }
84     }
85
86     public static void show(Fragment parent) {
87         if (!parent.isAdded()) return;
88
89         final OwnerInfoSettings dialog = new OwnerInfoSettings();
90         dialog.setTargetFragment(parent, 0);
91         dialog.show(parent.getFragmentManager(), TAG_OWNER_INFO);
92     }
93
94     @Override
95     public int getMetricsCategory() {
96         return MetricsProto.MetricsEvent.DIALOG_OWNER_INFO_SETTINGS;
97     }
98 }