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