WifiPickerActivity.java revision 18d271c73b17c9eb5570689247415a1d70583894
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 */ 16package com.android.settings.wifi; 17 18import com.android.settings.ButtonBarHandler; 19import com.android.settings.SettingsActivity; 20import com.android.settings.wifi.p2p.WifiP2pSettings; 21 22import android.app.Fragment; 23import android.content.Intent; 24import android.os.Bundle; 25import android.preference.PreferenceActivity; 26import android.widget.Button; 27 28public class WifiPickerActivity extends SettingsActivity 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 return modIntent; 44 } 45 46 @Override 47 protected boolean isValidFragment(String fragmentName) { 48 if (WifiSettings.class.getName().equals(fragmentName) 49 || WifiP2pSettings.class.getName().equals(fragmentName) 50 || AdvancedWifiSettings.class.getName().equals(fragmentName)) return true; 51 return false; 52 } 53 54 /** 55 * Add additional codes for button bar handling. 56 */ 57 public void startPreferencePanel(String fragmentClass, Bundle args, int titleRes, 58 CharSequence titleText, Fragment resultTo, int resultRequestCode) { 59 Intent intent = new Intent(Intent.ACTION_MAIN); 60 intent.setClass(this, getClass()); 61 intent.putExtra(EXTRA_SHOW_FRAGMENT, fragmentClass); 62 intent.putExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS, args); 63 64 final Intent orgIntent = getIntent(); 65 if (orgIntent.hasExtra(EXTRA_PREFS_SHOW_BUTTON_BAR)) { 66 intent.putExtra(EXTRA_PREFS_SHOW_BUTTON_BAR, 67 orgIntent.getBooleanExtra(EXTRA_PREFS_SHOW_BUTTON_BAR, false)); 68 } 69 if (orgIntent.hasExtra(EXTRA_PREFS_SET_NEXT_TEXT)) { 70 intent.putExtra(EXTRA_PREFS_SET_NEXT_TEXT, 71 orgIntent.getStringExtra(EXTRA_PREFS_SET_NEXT_TEXT)); 72 } 73 if (orgIntent.hasExtra(EXTRA_PREFS_SET_BACK_TEXT)) { 74 intent.putExtra(EXTRA_PREFS_SET_BACK_TEXT, 75 orgIntent.getStringExtra(EXTRA_PREFS_SET_BACK_TEXT)); 76 } 77 if (orgIntent.hasExtra(EXTRA_WIFI_SHOW_ACTION_BAR)) { 78 intent.putExtra(EXTRA_WIFI_SHOW_ACTION_BAR, 79 orgIntent.getBooleanExtra(EXTRA_WIFI_SHOW_ACTION_BAR, true)); 80 } 81 if (orgIntent.hasExtra(EXTRA_WIFI_SHOW_MENUS)) { 82 intent.putExtra(EXTRA_WIFI_SHOW_MENUS, 83 orgIntent.getBooleanExtra(EXTRA_WIFI_SHOW_MENUS, true)); 84 } 85 86 super.startPreferencePanel(fragmentClass, args, titleRes, titleText, resultTo, 87 resultRequestCode); 88 } 89 90 @Override 91 public boolean hasNextButton() { 92 // PreferenceActivity#hasNextButton() is protected, so we need to expose it here. 93 return super.hasNextButton(); 94 } 95 96 @Override 97 public Button getNextButton() { 98 // PreferenceActivity#getNextButton() is protected, so we need to expose it here. 99 return super.getNextButton(); 100 } 101}