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