OSDN Git Service

Added tabs for Multi-SIM SIM Lock.
authorPauloftheWest <paulofthewest@google.com>
Tue, 11 Nov 2014 14:42:54 +0000 (06:42 -0800)
committerPauloftheWest <paulofthewest@google.com>
Fri, 14 Nov 2014 18:38:43 +0000 (10:38 -0800)
Bug: 18147652
Change-Id: I89d3ffb0b1451d263d7c913ac210d52d5308f3c0

res/layout/icc_lock_tabs.xml [new file with mode: 0644]
src/com/android/settings/IccLockSettings.java

diff --git a/res/layout/icc_lock_tabs.xml b/res/layout/icc_lock_tabs.xml
new file mode 100644 (file)
index 0000000..d2a4acc
--- /dev/null
@@ -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>
index b988572..d8744cc 100644 (file)
@@ -29,13 +29,26 @@ import android.preference.CheckBoxPreference;
 import android.preference.Preference;
 import android.preference.PreferenceActivity;
 import android.preference.PreferenceScreen;
+import android.telephony.SubscriptionInfo;
+import android.telephony.SubscriptionManager;
+import android.telephony.TelephonyManager;
 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 com.android.internal.telephony.Phone;
 import com.android.internal.telephony.PhoneFactory;
 import com.android.internal.telephony.TelephonyIntents;
 
+import java.util.ArrayList;
+import java.util.List;
+
 /**
  * Implements the preference screen to enable/disable ICC lock and
  * 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?
     private boolean mToState;
 
+    private TabHost mTabHost;
+    private TabWidget mTabWidget;
+    private ListView mListView;
+
     private Phone mPhone;
 
     private EditPinPreference mPinDialog;
@@ -143,6 +160,10 @@ public class IccLockSettings extends PreferenceActivity
     @Override
     protected void onCreate(Bundle 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()) {
             finish();
@@ -182,13 +203,38 @@ public class IccLockSettings extends PreferenceActivity
         // Don't need any changes to be remembered
         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();
         mRes = getResources();
         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
@@ -418,4 +464,30 @@ public class IccLockSettings extends PreferenceActivity
         setDialogValues();
         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);
+    }
 }