2 * Copyright (C) 2009 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.content.ContentUris;
20 import android.content.Context;
21 import android.content.Intent;
22 import android.net.Uri;
23 import android.preference.Preference;
24 import android.provider.Telephony;
25 import android.util.AttributeSet;
26 import android.util.Log;
27 import android.view.View;
28 import android.view.ViewGroup;
29 import android.view.View.OnClickListener;
30 import android.widget.CompoundButton;
31 import android.widget.RadioButton;
32 import android.widget.RelativeLayout;
34 public class ApnPreference extends Preference implements
35 CompoundButton.OnCheckedChangeListener, OnClickListener {
36 final static String TAG = "ApnPreference";
38 public ApnPreference(Context context, AttributeSet attrs, int defStyle) {
39 super(context, attrs, defStyle);
42 public ApnPreference(Context context, AttributeSet attrs) {
43 this(context, attrs, R.attr.apnPreferenceStyle);
46 public ApnPreference(Context context) {
50 private static String mSelectedKey = null;
51 private static CompoundButton mCurrentChecked = null;
52 private boolean mProtectFromCheckedChange = false;
53 private boolean mSelectable = true;
54 private boolean mApnReadOnly = false;
57 public View getView(View convertView, ViewGroup parent) {
58 View view = super.getView(convertView, parent);
60 View widget = view.findViewById(R.id.apn_radiobutton);
61 if ((widget != null) && widget instanceof RadioButton) {
62 RadioButton rb = (RadioButton) widget;
64 rb.setOnCheckedChangeListener(this);
66 boolean isChecked = getKey().equals(mSelectedKey);
69 mSelectedKey = getKey();
72 mProtectFromCheckedChange = true;
73 rb.setChecked(isChecked);
74 mProtectFromCheckedChange = false;
75 rb.setVisibility(View.VISIBLE);
77 rb.setVisibility(View.GONE);
81 View textLayout = view.findViewById(R.id.text_layout);
82 if ((textLayout != null) && textLayout instanceof RelativeLayout) {
83 textLayout.setOnClickListener(this);
89 public boolean isChecked() {
90 return getKey().equals(mSelectedKey);
93 public void setChecked() {
94 mSelectedKey = getKey();
97 public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
98 Log.i(TAG, "ID: " + getKey() + " :" + isChecked);
99 if (mProtectFromCheckedChange) {
104 if (mCurrentChecked != null) {
105 mCurrentChecked.setChecked(false);
107 mCurrentChecked = buttonView;
108 mSelectedKey = getKey();
109 callChangeListener(mSelectedKey);
111 mCurrentChecked = null;
116 public void onClick(android.view.View v) {
117 if ((v != null) && (R.id.text_layout == v.getId())) {
118 Context context = getContext();
119 if (context != null) {
120 int pos = Integer.parseInt(getKey());
121 Uri url = ContentUris.withAppendedId(Telephony.Carriers.CONTENT_URI, pos);
122 Intent intent = new Intent(Intent.ACTION_EDIT, url);
123 intent.putExtra("DISABLE_EDITOR", mApnReadOnly);
124 context.startActivity(intent);
129 public void setSelectable(boolean selectable) {
130 mSelectable = selectable;
133 public boolean getSelectable() {
137 public void setApnReadOnly(boolean apnReadOnly) {
138 mApnReadOnly = apnReadOnly;