OwnerInfoSettings.java revision bd8e69733821d6761a7c8946cd8cebb15a44babd
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;
18
19import android.app.Fragment;
20import android.content.ContentResolver;
21import android.os.Bundle;
22import android.provider.Settings;
23import android.text.Editable;
24import android.text.TextWatcher;
25import android.view.LayoutInflater;
26import android.view.View;
27import android.view.ViewGroup;
28import android.widget.CheckBox;
29import android.widget.CompoundButton;
30import android.widget.EditText;
31import android.widget.CompoundButton.OnCheckedChangeListener;
32
33public class OwnerInfoSettings extends Fragment {
34    private View mView;
35    private CheckBox mCheckbox;
36    private EditText mEditText;
37
38    @Override
39    public View onCreateView(LayoutInflater inflater, ViewGroup container,
40            Bundle savedInstanceState) {
41        mView = inflater.inflate(R.layout.ownerinfo, container, false);
42        initView(mView);
43        return mView;
44    }
45
46    private void initView(View view) {
47        final ContentResolver res = getActivity().getContentResolver();
48        String info = Settings.Secure.getString(res, Settings.Secure.LOCK_SCREEN_OWNER_INFO);
49        int enabled = Settings.Secure.getInt(res,
50                Settings.Secure.LOCK_SCREEN_OWNER_INFO_ENABLED, 1);
51        mCheckbox = (CheckBox) mView.findViewById(R.id.show_owner_info_on_lockscreen_checkbox);
52        mEditText = (EditText) mView.findViewById(R.id.owner_info_edit_text);
53        mEditText.setText(info);
54        mEditText.setEnabled(enabled != 0);
55        mCheckbox.setChecked(enabled != 0);
56        mCheckbox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
57            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
58                Settings.Secure.putInt(res, Settings.Secure.LOCK_SCREEN_OWNER_INFO_ENABLED,
59                        isChecked ? 1 : 0);
60                mEditText.setEnabled(isChecked); // disable text field if not enabled
61            }
62        });
63    }
64
65    @Override
66    public void onPause() {
67        super.onPause();
68        saveToDb();
69    }
70
71    void saveToDb() {
72        ContentResolver res = getActivity().getContentResolver();
73        String info = mEditText.getText().toString();
74        Settings.Secure.putString(res, Settings.Secure.LOCK_SCREEN_OWNER_INFO, info);
75    }
76
77}
78