Skip to content

Commit

Permalink
Adjusting the dialog style & better RTL support (LSPosed#1838)
Browse files Browse the repository at this point in the history
* Adjusting the dialog style

* Fix alignment

* Separate appPackageName and appVersionName from appDescription
  • Loading branch information
Howard20181 authored Apr 13, 2022
1 parent 1e2973b commit abfac93
Show file tree
Hide file tree
Showing 51 changed files with 183 additions and 110 deletions.
30 changes: 17 additions & 13 deletions app/src/main/java/org/lsposed/manager/adapters/ScopeAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
import android.widget.ImageView;
import android.widget.Switch;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
Expand Down Expand Up @@ -257,7 +256,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
int itemId = item.getItemId();
if (itemId == R.id.use_recommended) {
if (!checkedList.isEmpty()) {
new BlurBehindDialogBuilder(activity)
new BlurBehindDialogBuilder(activity, R.style.ThemeOverlay_MaterialAlertDialog_Centered_FullWidthButtons)
.setMessage(R.string.use_recommended_message)
.setPositiveButton(android.R.string.ok, (dialog, which) -> checkRecommended())
.setNegativeButton(android.R.string.cancel, null)
Expand Down Expand Up @@ -328,7 +327,7 @@ public boolean onContextItemSelected(@NonNull MenuItem item) {
if (info.packageName.equals("android")) {
ConfigManager.reboot(false);
} else {
new BlurBehindDialogBuilder(activity)
new BlurBehindDialogBuilder(activity, R.style.ThemeOverlay_MaterialAlertDialog_Centered_FullWidthButtons)
.setTitle(R.string.force_stop_dlg_title)
.setMessage(R.string.force_stop_dlg_text)
.setPositiveButton(android.R.string.ok, (dialog, which) -> ConfigManager.forceStopPackage(info.packageName, info.uid / 100000))
Expand Down Expand Up @@ -416,12 +415,15 @@ public void onLoadFailed(@Nullable Drawable errorDrawable) {
holder.appIcon.setImageDrawable(pm.getDefaultActivityIcon());
}
});
SpannableStringBuilder sb = new SpannableStringBuilder(android ? "" : activity.getString(R.string.app_description, appInfo.packageName, appInfo.packageInfo.versionName));
if (android) holder.appDescription.setVisibility(View.GONE);
else {
holder.appDescription.setVisibility(View.VISIBLE);
holder.appDescription.setText(sb);
sb = new SpannableStringBuilder();
SpannableStringBuilder sb = new SpannableStringBuilder();
if (android) {
holder.appPackageName.setVisibility(View.GONE);
holder.appVersionName.setVisibility(View.GONE);
} else {
holder.appPackageName.setVisibility(View.VISIBLE);
holder.appVersionName.setVisibility(View.VISIBLE);
holder.appPackageName.setText(appInfo.packageName);
holder.appVersionName.setText(activity.getString(R.string.app_version, appInfo.packageInfo.versionName));
}
if (!recommendedList.isEmpty() && recommendedList.contains(appInfo.application)) {
String recommended = activity.getString(R.string.requested_by_module);
Expand Down Expand Up @@ -601,7 +603,8 @@ static class ViewHolder extends RecyclerView.ViewHolder {
ConstraintLayout root;
ImageView appIcon;
TextView appName;
TextView appDescription;
TextView appPackageName;
TextView appVersionName;
TextView hint;
MaterialCheckBox checkbox;

Expand All @@ -610,7 +613,8 @@ static class ViewHolder extends RecyclerView.ViewHolder {
root = binding.itemRoot;
appIcon = binding.appIcon;
appName = binding.appName;
appDescription = binding.description;
appPackageName = binding.appPackageName;
appVersionName = binding.appVersionName;
checkbox = binding.checkbox;
hint = binding.hint;
checkbox.setVisibility(View.VISIBLE);
Expand Down Expand Up @@ -665,7 +669,7 @@ public boolean onQueryTextChange(String query) {
public void onBackPressed() {
fragment.searchView.clearFocus();
if (isLoaded && enabled && checkedList.isEmpty()) {
var builder = new BlurBehindDialogBuilder(activity);
var builder = new BlurBehindDialogBuilder(activity, R.style.ThemeOverlay_MaterialAlertDialog_Centered_FullWidthButtons);
builder.setMessage(!recommendedList.isEmpty() ? R.string.no_scope_selected_has_recommended : R.string.no_scope_selected);
if (!recommendedList.isEmpty()) {
builder.setPositiveButton(android.R.string.ok, (dialog, which) -> checkRecommended());
Expand All @@ -674,7 +678,7 @@ public void onBackPressed() {
}
builder.setNegativeButton(!recommendedList.isEmpty() ? android.R.string.cancel : android.R.string.ok, (dialog, which) -> {
moduleUtil.setModuleEnabled(module.packageName, false);
Toast.makeText(activity, activity.getString(R.string.module_disabled_no_selection, module.getAppName()), Toast.LENGTH_LONG).show();
fragment.showHint(activity.getString(R.string.module_disabled_no_selection, module.getAppName()), true);
fragment.getNavController().navigateUp();
});
builder.show();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ public class BlurBehindDialogBuilder extends MaterialAlertDialogBuilder {
private static final boolean supportBlur = getSystemProperty("ro.surface_flinger.supports_background_blur", false) && !getSystemProperty("persist.sys.sf.disable_blurs", false);

public BlurBehindDialogBuilder(@NonNull Context context) {
super(context, com.google.android.material.R.style.ThemeOverlay_Material3_MaterialAlertDialog_Centered);
super(context);
}

public BlurBehindDialogBuilder(@NonNull Context context, int overrideThemeResId) {
super(context, overrideThemeResId);
}

@NonNull
Expand All @@ -57,16 +61,15 @@ public AlertDialog create() {

private void setBackgroundBlurRadius(AlertDialog dialog) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
ValueAnimator animator = ValueAnimator.ofInt(1, 150);
animator.setInterpolator(new DecelerateInterpolator());
animator.setDuration(150);
Window window = dialog.getWindow();
View view = window.getDecorView();
if (Build.VERSION.SDK_INT >= 31) {
window.addFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND);
window.getAttributes().setBlurBehindRadius(50);
window.getAttributes().setBlurBehindRadius(53); //android.R.styleable.Window_windowBlurBehindRadius
window.addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
} else if (supportBlur) {
View view = window.getDecorView();
ValueAnimator animator = ValueAnimator.ofInt(1, 153);
animator.setInterpolator(new DecelerateInterpolator());
try {
Object viewRootImpl = view.getClass().getMethod("getViewRootImpl").invoke(view);
if (viewRootImpl == null) {
Expand All @@ -87,19 +90,18 @@ private void setBackgroundBlurRadius(AlertDialog dialog) {
} catch (Throwable t) {
Log.e(App.TAG, "Blur behind dialog builder", t);
}
}
view.addOnAttachStateChangeListener(new View.OnAttachStateChangeListener() {
@Override
public void onViewAttachedToWindow(View v) {

}
view.addOnAttachStateChangeListener(new View.OnAttachStateChangeListener() {
@Override
public void onViewAttachedToWindow(View v) {
}

@Override
public void onViewDetachedFromWindow(View v) {
animator.cancel();
}
});
animator.start();
@Override
public void onViewDetachedFromWindow(View v) {
animator.cancel();
}
});
animator.start();
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class FlashDialogBuilder extends BlurBehindDialogBuilder {
private final BorderNestedScrollView rootView;

public FlashDialogBuilder(@NonNull Context context, DialogInterface.OnClickListener cancel) {
super(context);
super(context, R.style.ThemeOverlay_MaterialAlertDialog_Centered_FullWidthButtons);
var pref = App.getPreferences();
var notes = pref.getString("release_notes", "");
this.zipPath = pref.getString("zip_file", null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class ShortcutDialog extends DialogFragment {
@NonNull
@Override
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
return new BlurBehindDialogBuilder(requireContext())
return new BlurBehindDialogBuilder(requireContext(), R.style.ThemeOverlay_MaterialAlertDialog_Centered_FullWidthButtons)
.setTitle(R.string.parasitic_recommend)
.setMessage(R.string.parasitic_recommend_summary)
.setNegativeButton(R.string.never_show, (dialog, which) ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public Dialog onCreateDialog(Bundle savedInstanceState) {
FragmentCompileDialogBinding binding = FragmentCompileDialogBinding.inflate(LayoutInflater.from(requireActivity()), null, false);
final PackageManager pm = requireContext().getPackageManager();
var builder = new BlurBehindDialogBuilder(requireActivity())
.setIcon(appInfo.loadIcon(pm))
.setTitle(appInfo.loadLabel(pm))
.setView(binding.getRoot());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ private void updateModuleSummary() {
}

void installModuleToUser(ModuleUtil.InstalledModule module, UserInfo user) {
new BlurBehindDialogBuilder(requireActivity())
new BlurBehindDialogBuilder(requireActivity(), R.style.ThemeOverlay_MaterialAlertDialog_Centered_FullWidthButtons)
.setTitle(getString(R.string.install_to_user, user.name))
.setMessage(getString(R.string.install_to_user_message, module.getAppName(), user.name))
.setPositiveButton(android.R.string.ok, (dialog, which) ->
Expand Down Expand Up @@ -308,7 +308,8 @@ public boolean onContextItemSelected(@NonNull MenuItem item) {
ConfigManager.startActivityAsUserWithFeature(new Intent(ACTION_APPLICATION_DETAILS_SETTINGS, Uri.fromParts("package", selectedModule.packageName, null)), selectedModule.userId);
return true;
} else if (itemId == R.id.menu_uninstall) {
new BlurBehindDialogBuilder(requireActivity())
new BlurBehindDialogBuilder(requireActivity(), R.style.ThemeOverlay_MaterialAlertDialog_FullWidthButtons)
.setIcon(selectedModule.app.loadIcon(pm))
.setTitle(selectedModule.getAppName())
.setMessage(R.string.module_uninstall_message)
.setPositiveButton(android.R.string.ok, (dialog, which) ->
Expand Down Expand Up @@ -541,7 +542,7 @@ public void onLoadCleared(@Nullable Drawable placeholder) {
sb.append(getString(R.string.module_empty_description));
}
holder.appDescription.setText(sb);

holder.appDescription.setVisibility(View.VISIBLE);
sb = new SpannableStringBuilder();

int installXposedVersion = ConfigManager.getXposedApiVersion();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void onChanged() {
pickAdaptor.refresh();
var title = DialogTitleBinding.inflate(getLayoutInflater()).getRoot();
title.setText(getString(R.string.install_to_user, user.name));
var dialog = new BlurBehindDialogBuilder(requireActivity())
var dialog = new BlurBehindDialogBuilder(requireActivity(), R.style.ThemeOverlay_MaterialAlertDialog_FullWidthButtons)
.setCustomTitle(title)
.setView(binding.getRoot())
.setNegativeButton(android.R.string.cancel, null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,12 +282,12 @@ RepoLoader.ModuleVersion getUpgradableVer(OnlineModule module) {
public void onBindViewHolder(@NonNull RepoAdapter.ViewHolder holder, int position) {
OnlineModule module = showList.get(position);
holder.appName.setText(module.getDescription());
holder.appPackageName.setText(module.getName());

SpannableStringBuilder sb = new SpannableStringBuilder(module.getName());
SpannableStringBuilder sb = new SpannableStringBuilder();

String summary = module.getSummary();
if (summary != null) {
sb.append("\n");
sb.append(summary);
}
holder.appDescription.setVisibility(View.VISIBLE);
Expand Down Expand Up @@ -389,13 +389,15 @@ public boolean isLoaded() {
class ViewHolder extends RecyclerView.ViewHolder {
ConstraintLayout root;
TextView appName;
TextView appPackageName;
TextView appDescription;
TextView hint;

ViewHolder(ItemOnlinemoduleBinding binding) {
super(binding.getRoot());
root = binding.itemRoot;
appName = binding.appName;
appPackageName=binding.appPackageName;
appDescription = binding.description;
hint = binding.hint;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,11 @@ public static class DownloadDialog extends DialogFragment {
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
var args = getArguments();
if (args == null) throw new IllegalArgumentException();
return new BlurBehindDialogBuilder(requireActivity())
.setItems(args.getCharSequenceArray("names"), (dialog, which) -> NavUtil.startURL(requireActivity(), args.getStringArrayList("urls").get(which)))
return new BlurBehindDialogBuilder(requireActivity(), R.style.ThemeOverlay_MaterialAlertDialog_Centered_FullWidthButtons)
.setTitle(R.string.module_release_view_assets)
.setPositiveButton(android.R.string.cancel, null)
.setItems(args.getCharSequenceArray("names"),
(dialog, which) -> NavUtil.startURL(requireActivity(), args.getStringArrayList("urls").get(which)))
.create();
}

Expand Down
Loading

0 comments on commit abfac93

Please sign in to comment.