Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 24a133a0 authored by Willi Ye's avatar Willi Ye Committed by Jorge Ruesga
Browse files

wifi: Add a filter

* Based on this concept: https://plus.google.com/+MiroslavVitula/posts/ibm6CmBnBvc

Change-Id: Ia8cb2996ae37b61e257538dcc89eff3da87e7498
parent 58c9d696
Loading
Loading
Loading
Loading
+31 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
/*
** Copyright 2014, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
**     http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*/
-->

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/text1"
    style="?android:attr/spinnerDropDownItemStyle"
    android:singleLine="true"
    android:layout_width="match_parent"
    android:layout_height="?android:attr/listPreferredItemHeightSmall"
    android:ellipsize="marquee"
    android:gravity="center_vertical"
    android:textAppearance="@style/TextAppearance.Switch"
    android:textColor="@color/switchbar_text_color"
    android:textAlignment="viewStart" />
+18 −8
Original line number Diff line number Diff line
@@ -19,15 +19,25 @@

<merge xmlns:android="http://schemas.android.com/apk/res/android" >

    <FrameLayout android:layout_height="wrap_content"
                 android:layout_width="wrap_content"
                 android:layout_weight="1"
                 android:layout_gravity="center_vertical" >

        <TextView android:id="@+id/switch_text"
                  android:layout_height="wrap_content"
              android:layout_width="0dp"
              android:layout_weight="1"
              android:layout_gravity="center_vertical"
                  android:layout_width="wrap_content"
                  android:textAppearance="@style/TextAppearance.Switch"
                  android:textColor="@color/switchbar_text_color"
                  android:textAlignment="viewStart" />

        <Spinner android:id="@+id/switch_spinner"
                 android:layout_height="wrap_content"
                 android:layout_width="wrap_content"
                 android:visibility="gone" />

    </FrameLayout>

    <com.android.settings.widget.ToggleSwitch android:id="@+id/switch_widget"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
+8 −1
Original line number Diff line number Diff line
@@ -498,7 +498,14 @@
        <item>2</item>
    </string-array>

    <!-- Wi-Fi settings. Presented as a list dialog to the user to choose the Wi-Fi region code. -->
    <!-- Wi-Fi settings -->
    <string-array name="wifi_filter_entries" translatable="false">
        <item>@string/wifi_show_all</item>
        <item>@string/wifi_show_protected</item>
        <item>@string/wifi_show_open</item>
    </string-array>

    <!-- Presented as a list dialog to the user to choose the Wi-Fi region code. -->
    <string-array name="wifi_countrycode_entries" translatable="false">
        <item>@string/wifi_countrycode_entries_us</item>
        <item>@string/wifi_countrycode_entries_ca</item>
+7 −0
Original line number Diff line number Diff line
@@ -1260,6 +1260,13 @@
    <string name="factory_reset_warning_text_reset_now">RESET NOW</string>
    <string name="factory_reset_warning_text_message">All your accounts, apps, app data, and system settings will be removed from this device. This cannot be reversed.</string>

    <!-- Wi-Fi filters -->
    <string name="wifi_show_all">Show all</string>
    <string name="wifi_show_protected">Show protected networks</string>
    <string name="wifi_show_open">Show open networks</string>
    <string name="wifi_empty_list_protected">No protected Wi\u2011Fi networks</string>
    <string name="wifi_empty_list_open">No open Wi\u2011Fi networks</string>

    <!-- Wi-Fi region code -->
    <string name="wifi_setting_countrycode_title">Wi\u2011Fi region code</string>
    <!-- Wi-Fi settings screen, setting summary for setting the wifi frequency band [CHAR LIMIT=50]-->
+92 −1
Original line number Diff line number Diff line
@@ -28,6 +28,9 @@ import android.view.ViewGroup;
import android.widget.CompoundButton;
import android.widget.LinearLayout;

import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.Switch;
import android.widget.TextView;
import com.android.settings.R;
@@ -35,7 +38,7 @@ import com.android.settings.R;
import java.util.ArrayList;

public class SwitchBar extends LinearLayout implements CompoundButton.OnCheckedChangeListener,
        View.OnClickListener {
        View.OnClickListener, AdapterView.OnItemSelectedListener {

    public static interface OnSwitchChangeListener {
        /**
@@ -47,8 +50,13 @@ public class SwitchBar extends LinearLayout implements CompoundButton.OnCheckedC
        void onSwitchChanged(Switch switchView, boolean isChecked);
    }

    public static interface OnItemSelectedListener {
        void onItemSelected(Switch switchView, int position);
    }

    private ToggleSwitch mSwitch;
    private TextView mTextView;
    private Spinner mSpinner;

    private int mStateOnLabel = R.string.switch_on_text;
    private int mStateOffLabel = R.string.switch_off_text;
@@ -56,6 +64,9 @@ public class SwitchBar extends LinearLayout implements CompoundButton.OnCheckedC
    private ArrayList<OnSwitchChangeListener> mSwitchChangeListeners =
            new ArrayList<OnSwitchChangeListener>();

    private ArrayList<OnItemSelectedListener> mItemSelectedListeners =
            new ArrayList<OnItemSelectedListener>();

    private static int[] MARGIN_ATTRIBUTES = {
            R.attr.switchBarMarginStart, R.attr.switchBarMarginEnd};

@@ -86,6 +97,11 @@ public class SwitchBar extends LinearLayout implements CompoundButton.OnCheckedC
        ViewGroup.MarginLayoutParams lp = (MarginLayoutParams) mTextView.getLayoutParams();
        lp.setMarginStart(switchBarMarginStart);

        mSpinner = (Spinner) findViewById(R.id.switch_spinner);
        mSpinner.setOnItemSelectedListener(this);
        lp = (MarginLayoutParams) mSpinner.getLayoutParams();
        lp.setMarginStart(switchBarMarginStart);

        mSwitch = (ToggleSwitch) findViewById(R.id.switch_widget);
        // Prevent onSaveInstanceState() to be called as we are managing the state of the Switch
        // on our own
@@ -135,9 +151,23 @@ public class SwitchBar extends LinearLayout implements CompoundButton.OnCheckedC
    public void setEnabled(boolean enabled) {
        super.setEnabled(enabled);
        mTextView.setEnabled(enabled);
        mSpinner.setEnabled(enabled);
        mSwitch.setEnabled(enabled);
    }

    public void showSpinner(boolean visible) {
        mTextView.setVisibility(visible ? View.GONE : View.VISIBLE);
        mSpinner.setVisibility(visible ? View.VISIBLE : View.GONE);
    }

    public void setSpinnerEntries(String[] entries) {
        mSpinner.setAdapter(new SpinnerAdapter(getContext(), entries));
    }

    public final Spinner getSpinner() {
        return mSpinner;
    }

    public final ToggleSwitch getSwitch() {
        return mSwitch;
    }
@@ -178,6 +208,17 @@ public class SwitchBar extends LinearLayout implements CompoundButton.OnCheckedC
        propagateChecked(isChecked);
    }

    @Override
    public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
        for (OnItemSelectedListener mItemSelectedListener : mItemSelectedListeners) {
            mItemSelectedListener.onItemSelected(mSwitch, position);
        }
    }

    @Override
    public void onNothingSelected(AdapterView<?> parent) {
    }

    public void addOnSwitchChangeListener(OnSwitchChangeListener listener) {
        if (mSwitchChangeListeners.contains(listener)) {
            throw new IllegalStateException("Cannot add twice the same OnSwitchChangeListener");
@@ -192,6 +233,56 @@ public class SwitchBar extends LinearLayout implements CompoundButton.OnCheckedC
        mSwitchChangeListeners.remove(listener);
    }

    public void addOnItemSelectedListener(OnItemSelectedListener listener) {
        if (mItemSelectedListeners.contains(listener)) {
            throw new IllegalStateException("Cannot add twice the same OnItemSelectedListener");
        }
        mItemSelectedListeners.add(listener);
    }

    public void removeOnItemSelectedListener(OnItemSelectedListener listener) {
        if (!mItemSelectedListeners.contains(listener)) {
            throw new IllegalStateException("Cannot remove OnItemSelectedListener");
        }
        mItemSelectedListeners.remove(listener);
    }

    private class SpinnerAdapter<T> extends ArrayAdapter<T> {

        private final T[] entries;

        public SpinnerAdapter(Context context, T[] entries) {
            super(context, R.layout.spinner_item, entries);
            this.entries = entries;
        }

        private View createView(LayoutInflater inflater, ViewGroup parent,
                int position, boolean dropDown) {
            TextView textView = (TextView) inflater.inflate(R.layout.spinner_item, parent, false)
                    .findViewById(android.R.id.text1);
            textView.setText(entries[position].toString());
            if (!dropDown) {
                textView.setPadding(0, textView.getPaddingTop(),
                        textView.getPaddingRight(), textView.getPaddingBottom());
            } else {
                textView.setBackground(getContext().getDrawable(R.drawable.switchbar_background));
            }
            return textView;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            return createView(LayoutInflater.from(getContext()), parent,
                    mSpinner.getSelectedItemPosition(), false);
        }

        @Override
        public View getDropDownView(int position, View convertView, ViewGroup parent) {
            return createView(LayoutInflater.from(getContext()), parent, position, true);
        }

    }

    static class SavedState extends BaseSavedState {
        boolean checked;
        boolean visible;
Loading