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