Follow up for bug ##16703191 APN settings shows back button even when you intent into it

- create the OnPreferenceClickListener() only when needed
- imports cleaning

Change-Id: I61838403683ca68f5ab51ecf24d739bdf9a9a501
diff --git a/src/com/android/phone/GsmUmtsOptions.java b/src/com/android/phone/GsmUmtsOptions.java
index 5e0c324..8964cb5 100644
--- a/src/com/android/phone/GsmUmtsOptions.java
+++ b/src/com/android/phone/GsmUmtsOptions.java
@@ -22,7 +22,7 @@
 import android.preference.PreferenceScreen;
 import android.content.res.Resources;
 
-import com.android.internal.telephony.Phone;
+import android.provider.Settings;
 import com.android.internal.telephony.PhoneConstants;
 import com.android.internal.telephony.PhoneFactory;
 
@@ -50,18 +50,7 @@
     protected void create() {
         mPrefActivity.addPreferencesFromResource(R.xml.gsm_umts_options);
         mButtonAPNExpand = (PreferenceScreen) mPrefScreen.findPreference(BUTTON_APN_EXPAND_KEY);
-        mButtonAPNExpand.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
-            @Override
-            public boolean onPreferenceClick(Preference preference) {
-                // We need to build the Intent by hand as the Preference Framework does not allow
-                // to add an Intent with some extras into a Preference XML file
-                final Intent intent = new Intent("android.settings.APN_SETTINGS");
-                // This will setup the Home and Search affordance
-                intent.putExtra(":settings:show_fragment_as_subsetting", true);
-                mPrefActivity.startActivity(intent);
-                return true;
-            }
-        });
+        boolean removedAPNExpand = false;
         mButtonOperatorSelectionExpand =
                 (PreferenceScreen) mPrefScreen.findPreference(BUTTON_OPERATOR_SELECTION_EXPAND_KEY);
         if (PhoneFactory.getDefaultPhone().getPhoneType() != PhoneConstants.PHONE_TYPE_GSM) {
@@ -78,6 +67,7 @@
             // specific resources or device specific overlays.
             if (!res.getBoolean(R.bool.config_apn_expand) && mButtonAPNExpand != null) {
                 mPrefScreen.removePreference(mButtonAPNExpand);
+                removedAPNExpand = true;
             }
             if (!res.getBoolean(R.bool.config_operator_selection_expand)) {
                 mPrefScreen.removePreference(mPrefScreen
@@ -105,6 +95,22 @@
                 }
             }
         }
+        if (!removedAPNExpand) {
+            mButtonAPNExpand.setOnPreferenceClickListener(
+                    new Preference.OnPreferenceClickListener() {
+                        @Override
+                        public boolean onPreferenceClick(Preference preference) {
+                            // We need to build the Intent by hand as the Preference Framework
+                            // does not allow to add an Intent with some extras into a Preference
+                            // XML file
+                            final Intent intent = new Intent(Settings.ACTION_APN_SETTINGS);
+                            // This will setup the Home and Search affordance
+                            intent.putExtra(":settings:show_fragment_as_subsetting", true);
+                            mPrefActivity.startActivity(intent);
+                            return true;
+                        }
+            });
+        }
     }
 
     public boolean preferenceTreeClick(Preference preference) {