am de16eb6e: am acb160ba: Merge "Added tabs for Multi-SIM SIM Lock." into lmp-mr1-dev

* commit 'de16eb6e5346714a57973095f4d1854aa13f54bd':
  Added tabs for Multi-SIM SIM Lock.
This commit is contained in:
PauloftheWest
2014-11-17 16:20:14 +00:00
committed by Android Git Automerger
2 changed files with 133 additions and 1 deletions

View File

@@ -0,0 +1,60 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2014 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/tabs_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="none"
android:fillViewport="true">
<TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
style="?android:attr/tabWidgetStyle" />
</HorizontalScrollView>
<!-- give an empty content area to make tabhost happy -->
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="0dip"
android:layout_height="0dip" />
<ListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:clipChildren="false"
android:clipToPadding="false"
android:smoothScrollbar="false" />
</LinearLayout>
</TabHost>

View File

@@ -29,13 +29,26 @@ import android.preference.CheckBoxPreference;
import android.preference.Preference; import android.preference.Preference;
import android.preference.PreferenceActivity; import android.preference.PreferenceActivity;
import android.preference.PreferenceScreen; import android.preference.PreferenceScreen;
import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.util.Log; import android.util.Log;
import android.view.View;
import android.widget.ListView;
import android.widget.TabHost;
import android.widget.TabHost.OnTabChangeListener;
import android.widget.TabHost.TabContentFactory;
import android.widget.TabHost.TabSpec;
import android.widget.TabWidget;
import android.widget.Toast; import android.widget.Toast;
import com.android.internal.telephony.Phone; import com.android.internal.telephony.Phone;
import com.android.internal.telephony.PhoneFactory; import com.android.internal.telephony.PhoneFactory;
import com.android.internal.telephony.TelephonyIntents; import com.android.internal.telephony.TelephonyIntents;
import java.util.ArrayList;
import java.util.List;
/** /**
* Implements the preference screen to enable/disable ICC lock and * Implements the preference screen to enable/disable ICC lock and
* also the dialogs to change the ICC PIN. In the former case, enabling/disabling * also the dialogs to change the ICC PIN. In the former case, enabling/disabling
@@ -86,6 +99,10 @@ public class IccLockSettings extends PreferenceActivity
// Are we trying to enable or disable ICC lock? // Are we trying to enable or disable ICC lock?
private boolean mToState; private boolean mToState;
private TabHost mTabHost;
private TabWidget mTabWidget;
private ListView mListView;
private Phone mPhone; private Phone mPhone;
private EditPinPreference mPinDialog; private EditPinPreference mPinDialog;
@@ -143,6 +160,10 @@ public class IccLockSettings extends PreferenceActivity
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
final Context context = getApplicationContext();
final TelephonyManager tm =
(TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
final int numSims = tm.getSimCount();
if (Utils.isMonkeyRunning()) { if (Utils.isMonkeyRunning()) {
finish(); finish();
@@ -182,13 +203,38 @@ public class IccLockSettings extends PreferenceActivity
// Don't need any changes to be remembered // Don't need any changes to be remembered
getPreferenceScreen().setPersistent(false); getPreferenceScreen().setPersistent(false);
if (numSims > 1) {
setContentView(R.layout.icc_lock_tabs);
mTabHost = (TabHost) findViewById(android.R.id.tabhost);
mTabWidget = (TabWidget) findViewById(android.R.id.tabs);
mListView = (ListView) findViewById(android.R.id.list);
mTabHost.setup();
mTabHost.setOnTabChangedListener(mTabListener);
mTabHost.clearAllTabs();
for (int i = 0; i < numSims; ++i) {
final SubscriptionInfo subInfo = Utils.findRecordBySlotId(i);
mTabHost.addTab(buildTabSpec(String.valueOf(i),
String.valueOf(subInfo == null
? context.getString(R.string.sim_editor_title, i + 1)
: subInfo.getDisplayName())));
}
}
mPhone = PhoneFactory.getDefaultPhone(); mPhone = PhoneFactory.getDefaultPhone();
mRes = getResources(); mRes = getResources();
updatePreferences(); updatePreferences();
} }
private void updatePreferences() { private void updatePreferences() {
mPinToggle.setChecked(mPhone.getIccCard().getIccLockEnabled()); mPinDialog.setEnabled(mPhone != null);
mPinToggle.setEnabled(mPhone != null);
if (mPhone != null) {
mPinToggle.setChecked(mPhone.getIccCard().getIccLockEnabled());
}
} }
@Override @Override
@@ -418,4 +464,30 @@ public class IccLockSettings extends PreferenceActivity
setDialogValues(); setDialogValues();
mDialogState = OFF_MODE; mDialogState = OFF_MODE;
} }
private OnTabChangeListener mTabListener = new OnTabChangeListener() {
@Override
public void onTabChanged(String tabId) {
final int slotId = Integer.parseInt(tabId);
final SubscriptionInfo sir = Utils.findRecordBySlotId(slotId);
mPhone = (sir == null) ? null
: PhoneFactory.getPhone(SubscriptionManager.getPhoneId(sir.getSubscriptionId()));
// The User has changed tab; update the body.
updatePreferences();
}
};
private TabContentFactory mEmptyTabContent = new TabContentFactory() {
@Override
public View createTabContent(String tag) {
return new View(mTabHost.getContext());
}
};
private TabSpec buildTabSpec(String tag, String title) {
return mTabHost.newTabSpec(tag).setIndicator(title).setContent(
mEmptyTabContent);
}
} }