diff options
author | 2023-04-04 22:44:51 +0000 | |
---|---|---|
committer | 2023-04-04 22:44:51 +0000 | |
commit | 265fd03b33094530c14d903853393bb70f20ab58 (patch) | |
tree | ffdcc515eb2f540ef46abdba0b3f0a4b2c8c9edc | |
parent | fc3926683b26c077ca05906ffe6685e092667ccf (diff) | |
parent | eaf9301379ab5d435858021e36af52d987e40158 (diff) |
Merge "Fix WifiDialog app showing a solid background on U-on-T" into udc-dev
-rw-r--r-- | WifiDialog/Android.bp | 1 | ||||
-rw-r--r-- | WifiDialog/AndroidManifest.xml | 6 | ||||
-rw-r--r-- | WifiDialog/res/values/styles.xml | 25 | ||||
-rw-r--r-- | WifiDialog/src/com/android/wifi/dialog/WifiDialogActivity.java | 125 | ||||
-rw-r--r-- | service/ServiceWifiResources/res/values-night/styles.xml | 26 | ||||
-rw-r--r-- | service/ServiceWifiResources/res/values/styles.xml | 5 |
6 files changed, 115 insertions, 73 deletions
diff --git a/WifiDialog/Android.bp b/WifiDialog/Android.bp index 1941294fa8..75bb3cc2cf 100644 --- a/WifiDialog/Android.bp +++ b/WifiDialog/Android.bp @@ -28,7 +28,6 @@ android_app { static_libs: [ "androidx.appcompat_appcompat", ], - resource_dirs: [], srcs: ["src/**/*.java"], sdk_version: "module_current", diff --git a/WifiDialog/AndroidManifest.xml b/WifiDialog/AndroidManifest.xml index e9bb936840..cc6b44b7e3 100644 --- a/WifiDialog/AndroidManifest.xml +++ b/WifiDialog/AndroidManifest.xml @@ -29,7 +29,8 @@ <application android:enabled="true" android:configChanges="keyboardHidden|orientation|screenSize" - android:supportsRtl="true"> + android:supportsRtl="true" + android:theme="@style/WifiDialogTheme"> <!-- This is only used to identify this app by resolving the action. The activity is never actually triggered. --> @@ -43,7 +44,6 @@ android:configChanges="keyboardHidden|screenSize" android:hardwareAccelerated="true" android:launchMode="singleInstance" - android:excludeFromRecents="true" - android:theme="@*android:style/Theme.DeviceDefault.Dialog.Alert.DayNight" /> + android:excludeFromRecents="true"/> </application> </manifest> diff --git a/WifiDialog/res/values/styles.xml b/WifiDialog/res/values/styles.xml new file mode 100644 index 0000000000..b21e8d3590 --- /dev/null +++ b/WifiDialog/res/values/styles.xml @@ -0,0 +1,25 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + ~ Copyright (C) 2023 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. + --> +<resources> + <style name="WifiDialogTheme"> + <item name="android:windowNoTitle">true</item> + <item name="android:windowIsTranslucent">true</item> + <item name="android:windowBackground">@android:color/transparent</item> + <item name="android:windowContentOverlay">@null</item> + <item name="android:windowIsFloating">true</item> + </style> +</resources> diff --git a/WifiDialog/src/com/android/wifi/dialog/WifiDialogActivity.java b/WifiDialog/src/com/android/wifi/dialog/WifiDialogActivity.java index 2275dd7e78..34fc8e3d28 100644 --- a/WifiDialog/src/com/android/wifi/dialog/WifiDialogActivity.java +++ b/WifiDialog/src/com/android/wifi/dialog/WifiDialogActivity.java @@ -24,7 +24,6 @@ import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.content.res.Configuration; -import android.content.res.Resources; import android.icu.text.MessageFormat; import android.media.AudioManager; import android.media.Ringtone; @@ -97,50 +96,45 @@ public class WifiDialogActivity extends Activity { return mWifiContext; } - /** - * Override the default Resources with the Resources from the active ServiceWifiResources APK. - */ - @Override - public Resources getResources() { - return getWifiContext().getResources(); + private int getWifiResourceId(@NonNull String name, @NonNull String type) { + return getWifiContext().getResources().getIdentifier( + name, type, getWifiContext().getWifiOverlayApkPkgName()); + } + + private String getWifiString(@NonNull String name) { + return getWifiContext().getString(getWifiResourceId(name, "string")); } - // TODO(b/215605937): Remove these getXxxId() methods with the actual resource ID references - // once the build system is fixed to allow importing ServiceWifiResources. - private int getStringId(@NonNull String name) { - Resources res = getResources(); - return res.getIdentifier( - name, "string", getWifiContext().getWifiOverlayApkPkgName()); + private int getWifiInteger(@NonNull String name) { + return getWifiContext().getResources().getInteger(getWifiResourceId(name, "integer")); } - private int getIntegerId(@NonNull String name) { - Resources res = getResources(); - return res.getIdentifier( - name, "integer", getWifiContext().getWifiOverlayApkPkgName()); + private boolean getWifiBoolean(@NonNull String name) { + return getWifiContext().getResources().getBoolean(getWifiResourceId(name, "bool")); } - private int getBooleanId(@NonNull String name) { - Resources res = getResources(); - return res.getIdentifier( - name, "bool", getWifiContext().getWifiOverlayApkPkgName()); + private int getWifiLayoutId(@NonNull String name) { + return getWifiResourceId(name, "layout"); } - private int getLayoutId(@NonNull String name) { - Resources res = getResources(); - return res.getIdentifier( - name, "layout", getWifiContext().getWifiOverlayApkPkgName()); + private int getWifiViewId(@NonNull String name) { + return getWifiResourceId(name, "id"); } - private int getViewId(@NonNull String name) { - Resources res = getResources(); - return res.getIdentifier( - name, "id", getWifiContext().getWifiOverlayApkPkgName()); + private int getWifiStyleId(@NonNull String name) { + return getWifiResourceId(name, "style"); } - private int getStyleId(@NonNull String name) { - Resources res = getResources(); - return res.getIdentifier( - name, "style", getWifiContext().getWifiOverlayApkPkgName()); + private LayoutInflater getWifiLayoutInflater() { + return getLayoutInflater().cloneInContext(getWifiContext()); + } + + /** + * Returns an AlertDialog builder with the specified ServiceWifiResources theme applied. + */ + private AlertDialog.Builder getWifiAlertDialogBuilder(@NonNull String styleName) { + return new AlertDialog.Builder( + new ContextThemeWrapper(getWifiContext(), getWifiStyleId(styleName))); } private WifiManager getWifiManager() { @@ -182,7 +176,7 @@ public class WifiDialogActivity extends Activity { if (mIsVerboseLoggingEnabled) { Log.v(TAG, "Creating WifiDialogActivity."); } - mGravity = getResources().getInteger(getIntegerId("config_wifiDialogGravity")); + mGravity = getWifiInteger("config_wifiDialogGravity"); List<Intent> receivedIntents = new ArrayList<>(); if (savedInstanceState != null) { if (mIsVerboseLoggingEnabled) { @@ -381,8 +375,7 @@ public class WifiDialogActivity extends Activity { } removeIntentAndPossiblyFinish(dialogId); }); - dialog.setCanceledOnTouchOutside(getResources().getBoolean( - getBooleanId("config_wifiDialogCanceledOnTouchOutside"))); + dialog.setCanceledOnTouchOutside(getWifiBoolean("config_wifiDialogCanceledOnTouchOutside")); if (mGravity != Gravity.NO_GRAVITY) { dialog.getWindow().setGravity(mGravity); } @@ -414,7 +407,7 @@ public class WifiDialogActivity extends Activity { secondsRemaining++; } dialog.setMessage(MessageFormat.format( - getString(getStringId("wifi_p2p_invitation_seconds_remaining")), + getWifiString("wifi_p2p_invitation_seconds_remaining"), secondsRemaining)); } } @@ -445,8 +438,7 @@ public class WifiDialogActivity extends Activity { // sound/vibration for the specific dialog type. if (!mSavedStateIntents.contains(intent) && dialogType == WifiManager.DIALOG_TYPE_P2P_INVITATION_RECEIVED - && getResources().getBoolean( - getBooleanId("config_p2pInvitationReceivedDialogNotificationSound"))) { + && getWifiBoolean("config_p2pInvitationReceivedDialogNotificationSound")) { Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); Ringtone r = RingtoneManager.getRingtone(this, notification); r.play(); @@ -494,8 +486,7 @@ public class WifiDialogActivity extends Activity { } } } - AlertDialog dialog = new AlertDialog.Builder( - new ContextThemeWrapper(this, getStyleId("wifi_dialog"))) + AlertDialog dialog = getWifiAlertDialogBuilder("wifi_dialog") .setTitle(title) .setMessage(spannableMessage) .setPositiveButton(positiveButtonText, (dialogPositive, which) -> { @@ -551,26 +542,26 @@ public class WifiDialogActivity extends Activity { final int dialogId, @Nullable final String deviceName, @Nullable final String displayPin) { - final View textEntryView = LayoutInflater.from(this) - .inflate(getLayoutId("wifi_p2p_dialog"), null); - ViewGroup group = textEntryView.findViewById(getViewId("info")); + final View textEntryView = getWifiLayoutInflater() + .inflate(getWifiLayoutId("wifi_p2p_dialog"), null); + ViewGroup group = textEntryView.findViewById(getWifiViewId("info")); if (TextUtils.isEmpty(deviceName)) { Log.w(TAG, "P2P Invitation Sent dialog device name is null or empty." + " id=" + dialogId + " deviceName=" + deviceName + " displayPin=" + displayPin); } - addRowToP2pDialog(group, getStringId("wifi_p2p_to_message"), deviceName); + addRowToP2pDialog(group, getWifiString("wifi_p2p_to_message"), deviceName); if (displayPin != null) { - addRowToP2pDialog(group, getStringId("wifi_p2p_show_pin_message"), displayPin); + addRowToP2pDialog(group, getWifiString("wifi_p2p_show_pin_message"), displayPin); } - AlertDialog dialog = new AlertDialog.Builder( - new ContextThemeWrapper(this, getStyleId("wifi_dialog"))) - .setTitle(getString(getStringId("wifi_p2p_invitation_sent_title"))) + AlertDialog dialog = getWifiAlertDialogBuilder("wifi_dialog") + .setTitle(getWifiString("wifi_p2p_invitation_sent_title")) .setView(textEntryView) - .setPositiveButton(getStringId("ok"), (dialogPositive, which) -> { + .setPositiveButton(getWifiString("ok"), + (dialogPositive, which) -> { // No-op if (mIsVerboseLoggingEnabled) { Log.v(TAG, "P2P Invitation Sent Dialog id=" + dialogId @@ -595,36 +586,36 @@ public class WifiDialogActivity extends Activity { @Nullable final String deviceName, final boolean isPinRequested, @Nullable final String displayPin) { - final View textEntryView = LayoutInflater.from(this) - .inflate(getLayoutId("wifi_p2p_dialog"), null); - ViewGroup group = textEntryView.findViewById(getViewId("info")); + final View textEntryView = getWifiLayoutInflater() + .inflate(getWifiLayoutId("wifi_p2p_dialog"), null); + ViewGroup group = textEntryView.findViewById(getWifiViewId("info")); if (TextUtils.isEmpty(deviceName)) { Log.w(TAG, "P2P Invitation Received dialog device name is null or empty." + " id=" + dialogId + " deviceName=" + deviceName + " displayPin=" + displayPin); } - addRowToP2pDialog(group, getStringId("wifi_p2p_from_message"), deviceName); + addRowToP2pDialog(group, getWifiString("wifi_p2p_from_message"), deviceName); final EditText pinEditText; if (isPinRequested) { - textEntryView.findViewById(getViewId("enter_pin_section")).setVisibility(View.VISIBLE); - pinEditText = textEntryView.findViewById(getViewId("wifi_p2p_wps_pin")); + textEntryView.findViewById(getWifiViewId("enter_pin_section")) + .setVisibility(View.VISIBLE); + pinEditText = textEntryView.findViewById(getWifiViewId("wifi_p2p_wps_pin")); pinEditText.setVisibility(View.VISIBLE); } else { pinEditText = null; } if (displayPin != null) { - addRowToP2pDialog(group, getStringId("wifi_p2p_show_pin_message"), displayPin); + addRowToP2pDialog(group, getWifiString("wifi_p2p_show_pin_message"), displayPin); } - AlertDialog dialog = new AlertDialog.Builder( - new ContextThemeWrapper(this, getStyleId("wifi_p2p_invitation_received_dialog"))) - .setTitle(getString(getStringId("wifi_p2p_invitation_to_connect_title"))) + AlertDialog dialog = getWifiAlertDialogBuilder("wifi_p2p_invitation_received_dialog") + .setTitle(getWifiString("wifi_p2p_invitation_to_connect_title")) // Set the message to "" to allow us to modify it after building (b/36913966). .setMessage("") .setView(textEntryView) - .setPositiveButton(getStringId("accept"), (dialogPositive, which) -> { + .setPositiveButton(getWifiString("accept"), (dialogPositive, which) -> { String pin = null; if (pinEditText != null) { pin = pinEditText.getText().toString(); @@ -635,7 +626,7 @@ public class WifiDialogActivity extends Activity { } getWifiManager().replyToP2pInvitationReceivedDialog(dialogId, true, pin); }) - .setNegativeButton(getStringId("decline"), (dialogNegative, which) -> { + .setNegativeButton(getWifiString("decline"), (dialogNegative, which) -> { if (mIsVerboseLoggingEnabled) { Log.v(TAG, "P2P Invitation Received dialog id=" + dialogId + " declined."); @@ -730,11 +721,11 @@ public class WifiDialogActivity extends Activity { /** * Helper method to add a row to a ViewGroup for a P2P Invitation Received/Sent Dialog. */ - private void addRowToP2pDialog(ViewGroup group, int stringId, String value) { - View row = LayoutInflater.from(this) - .inflate(getLayoutId("wifi_p2p_dialog_row"), group, false); - ((TextView) row.findViewById(getViewId("name"))).setText(getString(stringId)); - ((TextView) row.findViewById(getViewId("value"))).setText(value); + private void addRowToP2pDialog(ViewGroup group, String name, String value) { + View row = getWifiLayoutInflater() + .inflate(getWifiLayoutId("wifi_p2p_dialog_row"), group, false); + ((TextView) row.findViewById(getWifiViewId("name"))).setText(name); + ((TextView) row.findViewById(getWifiViewId("value"))).setText(value); group.addView(row); } } diff --git a/service/ServiceWifiResources/res/values-night/styles.xml b/service/ServiceWifiResources/res/values-night/styles.xml new file mode 100644 index 0000000000..9279ee3780 --- /dev/null +++ b/service/ServiceWifiResources/res/values-night/styles.xml @@ -0,0 +1,26 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + ~ Copyright (C) 2023 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. + --> +<resources> + <style name="wifi_dialog" parent="@android:style/Theme.DeviceDefault.Dialog.Alert" /> + <style name="wifi_p2p_invitation_received_dialog" parent="@android:style/Theme.DeviceDefault.Dialog.Alert" /> + <style name="wifi_p2p_dialog_pin_input" parent="@style/wifi_item_content"> + <item name="android:singleLine">true</item> + <item name="android:maxLength">8</item> + <item name="android:inputType">number</item> + <item name="android:textColor">@android:color/primary_text_dark</item> + </style> +</resources> diff --git a/service/ServiceWifiResources/res/values/styles.xml b/service/ServiceWifiResources/res/values/styles.xml index f995441a9f..e3ad1619a5 100644 --- a/service/ServiceWifiResources/res/values/styles.xml +++ b/service/ServiceWifiResources/res/values/styles.xml @@ -43,8 +43,8 @@ <item name="android:orientation">vertical</item> </style> - <style name="wifi_dialog" /> - <style name="wifi_p2p_invitation_received_dialog" /> + <style name="wifi_dialog" parent="@android:style/Theme.DeviceDefault.Light.Dialog.Alert" /> + <style name="wifi_p2p_invitation_received_dialog" parent="@android:style/Theme.DeviceDefault.Light.Dialog.Alert" /> <style name="wifi_p2p_dialog_row_label" parent="@style/wifi_item_label" /> @@ -59,5 +59,6 @@ <item name="android:singleLine">true</item> <item name="android:maxLength">8</item> <item name="android:inputType">number</item> + <item name="android:textColor">@android:color/primary_text_light</item> </style> </resources> |