Home | History | Annotate | Download | only in wifi
      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 
     20 import android.app.Fragment;
     21 import android.content.Intent;
     22 import android.os.Bundle;
     23 import android.preference.PreferenceActivity;
     24 import android.widget.Button;
     25 
     26 public class WifiPickerActivity extends PreferenceActivity implements ButtonBarHandler {
     27 
     28     // Same as what are in PreferenceActivity as private.
     29     private static final String EXTRA_PREFS_SHOW_BUTTON_BAR = "extra_prefs_show_button_bar";
     30     private static final String EXTRA_PREFS_SET_NEXT_TEXT = "extra_prefs_set_next_text";
     31     private static final String EXTRA_PREFS_SET_BACK_TEXT = "extra_prefs_set_back_text";
     32 
     33     @Override
     34     public Intent getIntent() {
     35         Intent modIntent = new Intent(super.getIntent());
     36         if (!modIntent.hasExtra(EXTRA_SHOW_FRAGMENT)) {
     37             modIntent.putExtra(EXTRA_SHOW_FRAGMENT, WifiSettings.class.getName());
     38         }
     39         modIntent.putExtra(EXTRA_NO_HEADERS, true);
     40         return modIntent;
     41     }
     42 
     43     /**
     44      * Almost dead copy of
     45      * {@link PreferenceActivity#startWithFragment(String, Bundle, Fragment, int)}, except
     46      * this has additional codes for button bar handling.
     47      */
     48     @Override
     49     public void startWithFragment(String fragmentName, Bundle args,
     50             Fragment resultTo, int resultRequestCode) {
     51         Intent intent = new Intent(Intent.ACTION_MAIN);
     52         intent.setClass(this, getClass());
     53         intent.putExtra(EXTRA_SHOW_FRAGMENT, fragmentName);
     54         intent.putExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS, args);
     55         intent.putExtra(EXTRA_NO_HEADERS, true);
     56 
     57         final Intent orgIntent = getIntent();
     58         if (orgIntent.hasExtra(EXTRA_PREFS_SHOW_BUTTON_BAR)) {
     59             intent.putExtra(EXTRA_PREFS_SHOW_BUTTON_BAR,
     60                     orgIntent.getBooleanExtra(EXTRA_PREFS_SHOW_BUTTON_BAR, false));
     61         }
     62         if (orgIntent.hasExtra(EXTRA_PREFS_SET_NEXT_TEXT)) {
     63             intent.putExtra(EXTRA_PREFS_SET_NEXT_TEXT,
     64                     orgIntent.getStringExtra(EXTRA_PREFS_SET_NEXT_TEXT));
     65         }
     66         if (orgIntent.hasExtra(EXTRA_PREFS_SET_BACK_TEXT)) {
     67             intent.putExtra(EXTRA_PREFS_SET_BACK_TEXT,
     68                     orgIntent.getStringExtra(EXTRA_PREFS_SET_BACK_TEXT));
     69         }
     70 
     71         if (resultTo == null) {
     72             startActivity(intent);
     73         } else {
     74             resultTo.startActivityForResult(intent, resultRequestCode);
     75         }
     76     }
     77 
     78     @Override
     79     public boolean hasNextButton() {
     80         // PreferenceActivity#hasNextButton() is protected, so we need to expose it here.
     81         return super.hasNextButton();
     82     }
     83 
     84     @Override
     85     public Button getNextButton() {
     86         // PreferenceActivity#getNextButton() is protected, so we need to expose it here.
     87         return super.getNextButton();
     88     }
     89 }