Loading res/layout/wifi_button_preference_widget.xml 0 → 100644 +25 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <!-- Copyright (C) 2018 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. --> <ImageButton xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/button_icon" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:background="@null" android:visibility="gone" android:contentDescription="@string/wifi_add_network" /> res/layout/wifi_dialog.xml +41 −10 Original line number Diff line number Diff line Loading @@ -50,6 +50,9 @@ android:text="@string/wifi_ssid" android:textDirection="locale" /> <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content" > <EditText android:id="@+id/ssid" android:layout_width="match_parent" android:layout_height="wrap_content" Loading @@ -57,6 +60,18 @@ android:hint="@string/wifi_ssid_hint" android:singleLine="true" android:inputType="textNoSuggestions" /> <ImageButton android:id="@+id/ssid_scanner_button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_centerVertical="true" android:layout_margin="5dp" android:background="@null" android:src="@drawable/ic_qrcode_24dp" android:visibility="gone" android:contentDescription="@string/wifi_add_network" /> </RelativeLayout> <LinearLayout android:id="@+id/ssid_too_long_warning" android:layout_width="match_parent" Loading Loading @@ -270,12 +285,28 @@ style="@style/wifi_item_label" android:text="@string/wifi_password" /> <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content" > <EditText android:id="@+id/password" android:layout_width="match_parent" android:layout_height="wrap_content" style="@style/wifi_item_edit_content" android:singleLine="true" android:password="true" /> <ImageButton android:id="@+id/password_scanner_button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_centerVertical="true" android:layout_margin="5dp" android:background="@null" android:src="@drawable/ic_qrcode_24dp" android:visibility="gone" android:contentDescription="@string/wifi_add_network" /> </RelativeLayout> </LinearLayout> <LinearLayout android:id="@+id/show_password_layout" Loading src/com/android/settings/wifi/AddNetworkFragment.java +14 −0 Original line number Diff line number Diff line Loading @@ -23,12 +23,14 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Button; import android.widget.ImageButton; import androidx.annotation.VisibleForTesting; import com.android.internal.logging.nano.MetricsProto.MetricsEvent; import com.android.settings.R; import com.android.settings.core.InstrumentedFragment; import com.android.settings.wifi.dpp.WifiDppUtils; public class AddNetworkFragment extends InstrumentedFragment implements WifiConfigUiBase, View.OnClickListener { Loading Loading @@ -64,6 +66,18 @@ public class AddNetworkFragment extends InstrumentedFragment implements WifiConf mCancelBtn.setOnClickListener(this); mUIController = new WifiConfigController(this, rootView, null, getMode()); if (WifiDppUtils.isSharingNetworkEnabled(getContext())) { final ImageButton scannerButton = rootView.findViewById(R.id.ssid_scanner_button); if (scannerButton != null) { scannerButton.setVisibility(View.VISIBLE); scannerButton.setOnClickListener((View v) -> { // Launch QR code scanner to join a network. getContext().startActivity( WifiDppUtils.getConfiguratorQRCodeScannerIntent(/* ssid */ null)); }); } } return rootView; } Loading src/com/android/settings/wifi/ButtonPreference.java 0 → 100644 +123 −0 Original line number Diff line number Diff line /* * Copyright (C) 2018 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 */ package com.android.settings.wifi; import android.content.Context; import android.content.res.Resources; import android.graphics.drawable.Drawable; import android.util.AttributeSet; import android.util.Log; import android.view.View; import android.widget.ImageButton; import com.android.settings.R; import androidx.annotation.VisibleForTesting; import androidx.annotation.DrawableRes; import androidx.preference.Preference; import androidx.preference.PreferenceViewHolder; /** * This preference provides one button layout with Settings style. * It looks like below * * -------------------------------------------------------------- * | icon | title | button | * -------------------------------------------------------------- * * User can set icon / click listener for button. * By default, the button is invisible. */ public class ButtonPreference extends Preference { private static final String TAG = "ButtonPreference"; private ImageButton mImageButton; private Drawable mButtonIcon; private View.OnClickListener mClickListener; // Used for dummy pref. public ButtonPreference(Context context, AttributeSet attrs) { super(context, attrs); setWidgetLayoutResource(R.layout.wifi_button_preference_widget); mImageButton = null; mButtonIcon = null; mClickListener = null; } public ButtonPreference(Context context) { this(context, /* attrs */ null); } @Override public void onBindViewHolder(final PreferenceViewHolder view) { super.onBindViewHolder(view); initButton(view); } @Override public void setOrder(int order) { super.setOrder(order); setButtonVisibility(); } @VisibleForTesting protected void initButton(final PreferenceViewHolder view) { if (mImageButton == null) { mImageButton = (ImageButton) view.findViewById(R.id.button_icon); } if (mImageButton != null) { mImageButton.setImageDrawable(mButtonIcon); mImageButton.setOnClickListener(mClickListener); } setButtonVisibility(); } private void setButtonVisibility() { if(mImageButton != null) { mImageButton.setVisibility(mButtonIcon == null ? View.GONE : View.VISIBLE); } } /** * Sets the drawable to be displayed in button. */ public ButtonPreference setButtonIcon(@DrawableRes int iconResId) { if (iconResId == 0) { return this; } try { mButtonIcon = getContext().getDrawable(iconResId); notifyChanged(); } catch (Resources.NotFoundException exception) { Log.e(TAG, "Resource does not exist: " + iconResId); } return this; } /** * Register a callback to be invoked when button is clicked. */ public ButtonPreference setButtonOnClickListener(View.OnClickListener listener) { if (listener != mClickListener) { mClickListener = listener; notifyChanged(); } return this; } } src/com/android/settings/wifi/WifiDialog.java +15 −1 Original line number Diff line number Diff line Loading @@ -21,10 +21,13 @@ import android.content.DialogInterface; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.ImageButton; import androidx.appcompat.app.AlertDialog; import com.android.settings.R; import com.android.settings.wifi.dpp.WifiDppUtils; import com.android.settingslib.RestrictedLockUtils; import com.android.settingslib.RestrictedLockUtilsInternal; import com.android.settingslib.wifi.AccessPoint; Loading Loading @@ -77,7 +80,18 @@ public class WifiDialog extends AlertDialog implements WifiConfigUiBase, @Override protected void onCreate(Bundle savedInstanceState) { mView = getLayoutInflater().inflate(R.layout.wifi_dialog, null); mView = getLayoutInflater().inflate(R.layout.wifi_dialog, /* root */ null); if (WifiDppUtils.isSharingNetworkEnabled(getContext())) { final ImageButton scannerButton = mView.findViewById(R.id.password_scanner_button); if (scannerButton != null) { scannerButton.setVisibility(View.VISIBLE); scannerButton.setOnClickListener((View v) -> { // Launch QR code scanner to join a network. getContext().startActivity( WifiDppUtils.getConfiguratorQRCodeScannerIntent(/* ssid */ null)); }); } } setView(mView); mController = new WifiConfigController(this, mView, mAccessPoint, mMode); super.onCreate(savedInstanceState); Loading Loading
res/layout/wifi_button_preference_widget.xml 0 → 100644 +25 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <!-- Copyright (C) 2018 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. --> <ImageButton xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/button_icon" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:background="@null" android:visibility="gone" android:contentDescription="@string/wifi_add_network" />
res/layout/wifi_dialog.xml +41 −10 Original line number Diff line number Diff line Loading @@ -50,6 +50,9 @@ android:text="@string/wifi_ssid" android:textDirection="locale" /> <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content" > <EditText android:id="@+id/ssid" android:layout_width="match_parent" android:layout_height="wrap_content" Loading @@ -57,6 +60,18 @@ android:hint="@string/wifi_ssid_hint" android:singleLine="true" android:inputType="textNoSuggestions" /> <ImageButton android:id="@+id/ssid_scanner_button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_centerVertical="true" android:layout_margin="5dp" android:background="@null" android:src="@drawable/ic_qrcode_24dp" android:visibility="gone" android:contentDescription="@string/wifi_add_network" /> </RelativeLayout> <LinearLayout android:id="@+id/ssid_too_long_warning" android:layout_width="match_parent" Loading Loading @@ -270,12 +285,28 @@ style="@style/wifi_item_label" android:text="@string/wifi_password" /> <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content" > <EditText android:id="@+id/password" android:layout_width="match_parent" android:layout_height="wrap_content" style="@style/wifi_item_edit_content" android:singleLine="true" android:password="true" /> <ImageButton android:id="@+id/password_scanner_button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_centerVertical="true" android:layout_margin="5dp" android:background="@null" android:src="@drawable/ic_qrcode_24dp" android:visibility="gone" android:contentDescription="@string/wifi_add_network" /> </RelativeLayout> </LinearLayout> <LinearLayout android:id="@+id/show_password_layout" Loading
src/com/android/settings/wifi/AddNetworkFragment.java +14 −0 Original line number Diff line number Diff line Loading @@ -23,12 +23,14 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Button; import android.widget.ImageButton; import androidx.annotation.VisibleForTesting; import com.android.internal.logging.nano.MetricsProto.MetricsEvent; import com.android.settings.R; import com.android.settings.core.InstrumentedFragment; import com.android.settings.wifi.dpp.WifiDppUtils; public class AddNetworkFragment extends InstrumentedFragment implements WifiConfigUiBase, View.OnClickListener { Loading Loading @@ -64,6 +66,18 @@ public class AddNetworkFragment extends InstrumentedFragment implements WifiConf mCancelBtn.setOnClickListener(this); mUIController = new WifiConfigController(this, rootView, null, getMode()); if (WifiDppUtils.isSharingNetworkEnabled(getContext())) { final ImageButton scannerButton = rootView.findViewById(R.id.ssid_scanner_button); if (scannerButton != null) { scannerButton.setVisibility(View.VISIBLE); scannerButton.setOnClickListener((View v) -> { // Launch QR code scanner to join a network. getContext().startActivity( WifiDppUtils.getConfiguratorQRCodeScannerIntent(/* ssid */ null)); }); } } return rootView; } Loading
src/com/android/settings/wifi/ButtonPreference.java 0 → 100644 +123 −0 Original line number Diff line number Diff line /* * Copyright (C) 2018 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 */ package com.android.settings.wifi; import android.content.Context; import android.content.res.Resources; import android.graphics.drawable.Drawable; import android.util.AttributeSet; import android.util.Log; import android.view.View; import android.widget.ImageButton; import com.android.settings.R; import androidx.annotation.VisibleForTesting; import androidx.annotation.DrawableRes; import androidx.preference.Preference; import androidx.preference.PreferenceViewHolder; /** * This preference provides one button layout with Settings style. * It looks like below * * -------------------------------------------------------------- * | icon | title | button | * -------------------------------------------------------------- * * User can set icon / click listener for button. * By default, the button is invisible. */ public class ButtonPreference extends Preference { private static final String TAG = "ButtonPreference"; private ImageButton mImageButton; private Drawable mButtonIcon; private View.OnClickListener mClickListener; // Used for dummy pref. public ButtonPreference(Context context, AttributeSet attrs) { super(context, attrs); setWidgetLayoutResource(R.layout.wifi_button_preference_widget); mImageButton = null; mButtonIcon = null; mClickListener = null; } public ButtonPreference(Context context) { this(context, /* attrs */ null); } @Override public void onBindViewHolder(final PreferenceViewHolder view) { super.onBindViewHolder(view); initButton(view); } @Override public void setOrder(int order) { super.setOrder(order); setButtonVisibility(); } @VisibleForTesting protected void initButton(final PreferenceViewHolder view) { if (mImageButton == null) { mImageButton = (ImageButton) view.findViewById(R.id.button_icon); } if (mImageButton != null) { mImageButton.setImageDrawable(mButtonIcon); mImageButton.setOnClickListener(mClickListener); } setButtonVisibility(); } private void setButtonVisibility() { if(mImageButton != null) { mImageButton.setVisibility(mButtonIcon == null ? View.GONE : View.VISIBLE); } } /** * Sets the drawable to be displayed in button. */ public ButtonPreference setButtonIcon(@DrawableRes int iconResId) { if (iconResId == 0) { return this; } try { mButtonIcon = getContext().getDrawable(iconResId); notifyChanged(); } catch (Resources.NotFoundException exception) { Log.e(TAG, "Resource does not exist: " + iconResId); } return this; } /** * Register a callback to be invoked when button is clicked. */ public ButtonPreference setButtonOnClickListener(View.OnClickListener listener) { if (listener != mClickListener) { mClickListener = listener; notifyChanged(); } return this; } }
src/com/android/settings/wifi/WifiDialog.java +15 −1 Original line number Diff line number Diff line Loading @@ -21,10 +21,13 @@ import android.content.DialogInterface; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.ImageButton; import androidx.appcompat.app.AlertDialog; import com.android.settings.R; import com.android.settings.wifi.dpp.WifiDppUtils; import com.android.settingslib.RestrictedLockUtils; import com.android.settingslib.RestrictedLockUtilsInternal; import com.android.settingslib.wifi.AccessPoint; Loading Loading @@ -77,7 +80,18 @@ public class WifiDialog extends AlertDialog implements WifiConfigUiBase, @Override protected void onCreate(Bundle savedInstanceState) { mView = getLayoutInflater().inflate(R.layout.wifi_dialog, null); mView = getLayoutInflater().inflate(R.layout.wifi_dialog, /* root */ null); if (WifiDppUtils.isSharingNetworkEnabled(getContext())) { final ImageButton scannerButton = mView.findViewById(R.id.password_scanner_button); if (scannerButton != null) { scannerButton.setVisibility(View.VISIBLE); scannerButton.setOnClickListener((View v) -> { // Launch QR code scanner to join a network. getContext().startActivity( WifiDppUtils.getConfiguratorQRCodeScannerIntent(/* ssid */ null)); }); } } setView(mView); mController = new WifiConfigController(this, mView, mAccessPoint, mMode); super.onCreate(savedInstanceState); Loading