1 /* 2 * Copyright (C) 2011 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 package com.android.settings.wifi; 17 18 import com.android.settings.ButtonBarHandler; 19 import com.android.settings.ChooseLockGeneric.ChooseLockGenericFragment; 20 import com.android.settings.wifi.p2p.WifiP2pSettings; 21 22 import android.app.Fragment; 23 import android.content.Intent; 24 import android.os.Bundle; 25 import android.preference.PreferenceActivity; 26 import android.widget.Button; 27 28 public class WifiPickerActivity extends PreferenceActivity implements ButtonBarHandler { 29 30 // Same as what are in PreferenceActivity as private. 31 private static final String EXTRA_PREFS_SHOW_BUTTON_BAR = "extra_prefs_show_button_bar"; 32 private static final String EXTRA_PREFS_SET_NEXT_TEXT = "extra_prefs_set_next_text"; 33 private static final String EXTRA_PREFS_SET_BACK_TEXT = "extra_prefs_set_back_text"; 34 private static final String EXTRA_WIFI_SHOW_ACTION_BAR = "wifi_show_action_bar"; 35 private static final String EXTRA_WIFI_SHOW_MENUS = "wifi_show_menus"; 36 37 @Override 38 public Intent getIntent() { 39 Intent modIntent = new Intent(super.getIntent()); 40 if (!modIntent.hasExtra(EXTRA_SHOW_FRAGMENT)) { 41 modIntent.putExtra(EXTRA_SHOW_FRAGMENT, WifiSettings.class.getName()); 42 } 43 modIntent.putExtra(EXTRA_NO_HEADERS, true); 44 return modIntent; 45 } 46 47 @Override 48 protected boolean isValidFragment(String fragmentName) { 49 if (WifiSettings.class.getName().equals(fragmentName) 50 || WifiP2pSettings.class.getName().equals(fragmentName) 51 || AdvancedWifiSettings.class.getName().equals(fragmentName)) return true; 52 return false; 53 } 54 55 /** 56 * Almost dead copy of 57 * {@link PreferenceActivity#startWithFragment(String, Bundle, Fragment, int)}, except 58 * this has additional codes for button bar handling. 59 */ 60 @Override 61 public void startWithFragment(String fragmentName, Bundle args, 62 Fragment resultTo, int resultRequestCode) { 63 Intent intent = new Intent(Intent.ACTION_MAIN); 64 intent.setClass(this, getClass()); 65 intent.putExtra(EXTRA_SHOW_FRAGMENT, fragmentName); 66 intent.putExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS, args); 67 intent.putExtra(EXTRA_NO_HEADERS, true); 68 69 final Intent orgIntent = getIntent(); 70 if (orgIntent.hasExtra(EXTRA_PREFS_SHOW_BUTTON_BAR)) { 71 intent.putExtra(EXTRA_PREFS_SHOW_BUTTON_BAR, 72 orgIntent.getBooleanExtra(EXTRA_PREFS_SHOW_BUTTON_BAR, false)); 73 } 74 if (orgIntent.hasExtra(EXTRA_PREFS_SET_NEXT_TEXT)) { 75 intent.putExtra(EXTRA_PREFS_SET_NEXT_TEXT, 76 orgIntent.getStringExtra(EXTRA_PREFS_SET_NEXT_TEXT)); 77 } 78 if (orgIntent.hasExtra(EXTRA_PREFS_SET_BACK_TEXT)) { 79 intent.putExtra(EXTRA_PREFS_SET_BACK_TEXT, 80 orgIntent.getStringExtra(EXTRA_PREFS_SET_BACK_TEXT)); 81 } 82 if (orgIntent.hasExtra(EXTRA_WIFI_SHOW_ACTION_BAR)) { 83 intent.putExtra(EXTRA_WIFI_SHOW_ACTION_BAR, 84 orgIntent.getBooleanExtra(EXTRA_WIFI_SHOW_ACTION_BAR, true)); 85 } 86 if (orgIntent.hasExtra(EXTRA_WIFI_SHOW_MENUS)) { 87 intent.putExtra(EXTRA_WIFI_SHOW_MENUS, 88 orgIntent.getBooleanExtra(EXTRA_WIFI_SHOW_MENUS, true)); 89 } 90 91 if (resultTo == null) { 92 startActivity(intent); 93 } else { 94 resultTo.startActivityForResult(intent, resultRequestCode); 95 } 96 } 97 98 @Override 99 public boolean hasNextButton() { 100 // PreferenceActivity#hasNextButton() is protected, so we need to expose it here. 101 return super.hasNextButton(); 102 } 103 104 @Override 105 public Button getNextButton() { 106 // PreferenceActivity#getNextButton() is protected, so we need to expose it here. 107 return super.getNextButton(); 108 } 109 }