Merge "Fix Wi-Fi QR code scanning icon disappears problem" into qt-dev
This commit is contained in:
@@ -36,7 +36,7 @@ public class AddWifiNetworkPreference extends Preference {
|
||||
|
||||
private static final String TAG = "AddWifiNetworkPreference";
|
||||
|
||||
private boolean mInitialized;
|
||||
private final Drawable mScanIconDrawable;
|
||||
|
||||
public AddWifiNetworkPreference(Context context) {
|
||||
super(context);
|
||||
@@ -45,24 +45,22 @@ public class AddWifiNetworkPreference extends Preference {
|
||||
setWidgetLayoutResource(R.layout.wifi_button_preference_widget);
|
||||
setIcon(R.drawable.ic_menu_add);
|
||||
setTitle(R.string.wifi_add_network);
|
||||
|
||||
mScanIconDrawable = getDrawable(R.drawable.ic_scan_24dp);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(PreferenceViewHolder holder) {
|
||||
super.onBindViewHolder(holder);
|
||||
|
||||
if (!mInitialized) {
|
||||
mInitialized = true;
|
||||
|
||||
final ImageButton imageButton = (ImageButton) holder.findViewById(R.id.button_icon);
|
||||
imageButton.setImageDrawable(getDrawable(R.drawable.ic_scan_24dp));
|
||||
imageButton.setContentDescription(
|
||||
getContext().getString(R.string.wifi_dpp_scan_qr_code));
|
||||
imageButton.setOnClickListener(view -> {
|
||||
getContext().startActivity(
|
||||
WifiDppUtils.getEnrolleeQrCodeScannerIntent(/* ssid */ null));
|
||||
});
|
||||
}
|
||||
final ImageButton scanButton = (ImageButton) holder.findViewById(R.id.button_icon);
|
||||
scanButton.setImageDrawable(mScanIconDrawable);
|
||||
scanButton.setContentDescription(
|
||||
getContext().getString(R.string.wifi_dpp_scan_qr_code));
|
||||
scanButton.setOnClickListener(view -> {
|
||||
getContext().startActivity(
|
||||
WifiDppUtils.getEnrolleeQrCodeScannerIntent(/* ssid */ null));
|
||||
});
|
||||
}
|
||||
|
||||
private Drawable getDrawable(@DrawableRes int iconResId) {
|
||||
|
@@ -37,9 +37,7 @@ import com.android.settings.widget.ValidatedEditTextPreference;
|
||||
public class WifiTetherSsidPreference extends ValidatedEditTextPreference {
|
||||
private static final String TAG = "WifiTetherSsidPreference";
|
||||
|
||||
private ImageButton mImageButton;
|
||||
private Drawable mButtonIcon;
|
||||
private View mDivider;
|
||||
private Drawable mShareIconDrawable;
|
||||
private View.OnClickListener mClickListener;
|
||||
private boolean mVisible;
|
||||
|
||||
@@ -72,30 +70,29 @@ public class WifiTetherSsidPreference extends ValidatedEditTextPreference {
|
||||
// TODO(b/129019971): use methods of divider line in parent object
|
||||
setLayoutResource(com.android.settingslib.R.layout.preference_two_target);
|
||||
setWidgetLayoutResource(R.layout.wifi_button_preference_widget);
|
||||
|
||||
mShareIconDrawable = getDrawable(R.drawable.ic_qrcode_24dp);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(PreferenceViewHolder holder) {
|
||||
super.onBindViewHolder(holder);
|
||||
|
||||
if (mImageButton == null) {
|
||||
mImageButton = (ImageButton) holder.findViewById(R.id.button_icon);
|
||||
|
||||
mImageButton.setContentDescription(
|
||||
getContext().getString(R.string.wifi_dpp_share_hotspot));
|
||||
setButtonIcon(R.drawable.ic_qrcode_24dp);
|
||||
mImageButton.setImageDrawable(mButtonIcon);
|
||||
|
||||
mDivider = holder.findViewById(R.id.two_target_divider);
|
||||
}
|
||||
final ImageButton shareButton = (ImageButton) holder.findViewById(R.id.button_icon);
|
||||
final View dividerView = holder.findViewById(R.id.two_target_divider);
|
||||
|
||||
if (mVisible) {
|
||||
mImageButton.setOnClickListener(mClickListener);
|
||||
mImageButton.setVisibility(View.VISIBLE);
|
||||
mDivider.setVisibility(View.VISIBLE);
|
||||
shareButton.setOnClickListener(mClickListener);
|
||||
shareButton.setVisibility(View.VISIBLE);
|
||||
shareButton.setContentDescription(
|
||||
getContext().getString(R.string.wifi_dpp_share_hotspot));
|
||||
shareButton.setImageDrawable(mShareIconDrawable);
|
||||
|
||||
dividerView.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
mImageButton.setVisibility(View.GONE);
|
||||
mDivider.setVisibility(View.GONE);
|
||||
shareButton.setVisibility(View.GONE);
|
||||
|
||||
dividerView.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,12 +104,15 @@ public class WifiTetherSsidPreference extends ValidatedEditTextPreference {
|
||||
mVisible = visible;
|
||||
}
|
||||
|
||||
private void setButtonIcon(@DrawableRes int iconResId) {
|
||||
private Drawable getDrawable(@DrawableRes int iconResId) {
|
||||
Drawable buttonIcon = null;
|
||||
|
||||
try {
|
||||
mButtonIcon = getContext().getDrawable(iconResId);
|
||||
buttonIcon = getContext().getDrawable(iconResId);
|
||||
} catch (Resources.NotFoundException exception) {
|
||||
Log.e(TAG, "Resource does not exist: " + iconResId);
|
||||
}
|
||||
return buttonIcon;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
|
Reference in New Issue
Block a user