Add theming for AlertDialogBuilder

This commit is contained in:
d8ahazard
2016-09-25 10:11:57 -05:00
committed by topjohnwu
parent 859a984ec8
commit 7b8237afae
8 changed files with 117 additions and 20 deletions

View File

@ -4,18 +4,21 @@ import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.annotation.Nullable;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.text.Html;
import android.text.Spanned;
import android.text.TextUtils;
import android.text.method.LinkMovementMethod;
import android.view.View;
import android.view.WindowManager;
import android.widget.TextView;
import com.topjohnwu.magisk.utils.Logger;
import com.topjohnwu.magisk.utils.RowItem;
import java.io.IOException;
@ -28,7 +31,7 @@ public class AboutActivity extends AppCompatActivity {
private static final String SOURCE_CODE_URL = "https://github.com/topjohnwu/MagiskManager";
private static final String XDA_THREAD = "http://forum.xda-developers.com/android/software/mod-magisk-v1-universal-systemless-t3432382";
private AlertDialog.Builder builder;
@BindView(R.id.toolbar) Toolbar toolbar;
@BindView(R.id.app_version_info) RowItem appVersionInfo;
@ -41,6 +44,11 @@ public class AboutActivity extends AppCompatActivity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String theme = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getString("theme", "");
Logger.dh("AboutActivity: Theme is " + theme);
if (theme.equals("Dark")) {
setTheme(R.style.AppTheme_dh);
}
setContentView(R.layout.activity_about);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
@ -72,14 +80,24 @@ public class AboutActivity extends AppCompatActivity {
}
appChangelog.removeSummary();
if (theme.equals("Dark")) {
builder = new AlertDialog.Builder(this,R.style.AlertDialog_dh);
} else {
builder = new AlertDialog.Builder(this);
}
if (changes == null) {
appChangelog.setVisibility(View.GONE);
} else {
final String finalChanges = changes;
Spanned result;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
result = Html.fromHtml(changes,Html.TO_HTML_PARAGRAPH_LINES_CONSECUTIVE);
} else {
result = Html.fromHtml(changes);
}
appChangelog.setOnClickListener(v -> {
AlertDialog d = new AlertDialog.Builder(AboutActivity.this)
AlertDialog d = builder
.setTitle(R.string.app_changelog)
.setMessage(Html.fromHtml(finalChanges))
.setMessage(result)
.setPositiveButton(android.R.string.ok, null)
.create();
@ -92,9 +110,15 @@ public class AboutActivity extends AppCompatActivity {
appDevelopers.removeSummary();
appDevelopers.setOnClickListener(view -> {
AlertDialog d = new AlertDialog.Builder(AboutActivity.this)
Spanned result;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
result = Html.fromHtml(getString(R.string.app_developers_),Html.TO_HTML_PARAGRAPH_LINES_CONSECUTIVE);
} else {
result = Html.fromHtml(getString(R.string.app_developers_));
}
AlertDialog d = builder
.setTitle(R.string.app_developers)
.setMessage(Html.fromHtml(getString(R.string.app_developers_)))
.setMessage(result)
.setPositiveButton(android.R.string.ok, null)
.create();
@ -142,6 +166,5 @@ public class AboutActivity extends AppCompatActivity {
setTitle("About");
getWindow().setStatusBarColor(getResources().getColor(R.color.primary_dark));
}
}
}

View File

@ -6,6 +6,7 @@ import android.content.res.TypedArray;
import android.graphics.Color;
import android.os.AsyncTask;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.annotation.Nullable;
import android.support.v4.content.FileProvider;
@ -52,6 +53,7 @@ public class MagiskFragment extends Fragment {
private int colorOK, colorWarn, colorNeutral;
int statusOK = R.drawable.ic_check_circle;
int statusUnknown = R.drawable.ic_help;
private AlertDialog.Builder builder;
@Nullable
@Override
@ -91,6 +93,12 @@ public class MagiskFragment extends Fragment {
@Override
protected void onPostExecute(Void v) {
super.onPostExecute(v);
String theme = PreferenceManager.getDefaultSharedPreferences(getActivity()).getString("theme", "");
if (theme.equals("Dark")) {
builder = new AlertDialog.Builder(getActivity(),R.style.AlertDialog_dh);
} else {
builder = new AlertDialog.Builder(getActivity());
}
if (Utils.magiskVersion == -1) {
magiskStatusContainer.setBackgroundColor(grey500);
@ -123,7 +131,7 @@ public class MagiskFragment extends Fragment {
magiskCheckUpdatesIcon.setImageResource(R.drawable.ic_file_download);
magiskCheckUpdatesStatus.setText(getString(R.string.magisk_update_available, String.valueOf(Utils.remoteMagiskVersion)));
magiskCheckUpdatesStatus.setTextColor(colorNeutral);
magiskUpdateView.setOnClickListener(view -> new AlertDialog.Builder(getActivity())
magiskUpdateView.setOnClickListener(view -> builder
.setTitle(getString(R.string.update_title, getString(R.string.magisk)))
.setMessage(getString(R.string.update_msg, getString(R.string.magisk), String.valueOf(Utils.remoteMagiskVersion), Utils.magiskChangelog))
.setCancelable(true)
@ -150,7 +158,7 @@ public class MagiskFragment extends Fragment {
appCheckUpdatesIcon.setImageResource(R.drawable.ic_file_download);
appCheckUpdatesStatus.setText(getString(R.string.app_update_available, String.valueOf(Utils.remoteAppVersion)));
appCheckUpdatesStatus.setTextColor(colorNeutral);
appUpdateView.setOnClickListener(view -> new AlertDialog.Builder(getActivity())
appUpdateView.setOnClickListener(view -> builder
.setTitle(getString(R.string.update_title, getString(R.string.app_name)))
.setMessage(getString(R.string.update_msg, getString(R.string.app_name), String.valueOf(Utils.remoteAppVersion), Utils.appChangelog))
.setCancelable(true)

View File

@ -127,8 +127,13 @@ public class ModulesAdapter extends RecyclerView.Adapter<ModulesAdapter.ViewHold
break;
}
};
AlertDialog.Builder builder = new AlertDialog.Builder(context);
AlertDialog.Builder builder;
String theme = PreferenceManager.getDefaultSharedPreferences(context).getString("theme", "");
if (theme.equals("Dark")) {
builder = new AlertDialog.Builder(context,R.style.AlertDialog_dh);
} else {
builder = new AlertDialog.Builder(context);
}
builder.setMessage("An update is available for " + mModule.getName() + ". Would you like to install it?").setPositiveButton("Yes", dialogClickListener)
.setNegativeButton("No", dialogClickListener).show();
mListToUpdate.remove(mModule);

View File

@ -4,6 +4,7 @@ import android.app.Fragment;
import android.content.DialogInterface;
import android.os.AsyncTask;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.annotation.Nullable;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.AlertDialog;
@ -17,6 +18,7 @@ import android.widget.TextView;
import com.topjohnwu.magisk.module.Repo;
import com.topjohnwu.magisk.module.RepoHelper;
import com.topjohnwu.magisk.utils.Async;
import com.topjohnwu.magisk.utils.Logger;
import com.topjohnwu.magisk.utils.Utils;
import java.io.File;
@ -42,6 +44,7 @@ public class ReposFragment extends Fragment {
private boolean alertUpdate;
private boolean ignoreAlertUpdate;
private String alertPackage;
private AlertDialog.Builder builder;
// private SharedPreferences prefs;
@Nullable
@ -132,10 +135,17 @@ public class ReposFragment extends Fragment {
}
};
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setMessage("An update is available for " + repo.getName() + ". Would you like to install it?").setPositiveButton("Yes", dialogClickListener)
.setNegativeButton("No", dialogClickListener).show();
iterRepo.remove();
String theme = PreferenceManager.getDefaultSharedPreferences(getActivity()).getString("theme", "");
Logger.dh("ReposFragment: Theme is " + theme);
if (theme.equals("Dark")) {
builder = new AlertDialog.Builder(getActivity(),R.style.AlertDialog_dh);
} else {
builder = new AlertDialog.Builder(getActivity());
}
builder.setMessage("An update is available for " + repo.getName() + ". Would you like to install it?").setPositiveButton("Yes", dialogClickListener)
.setNegativeButton("No", dialogClickListener).show();
iterRepo.remove();
}
}

View File

@ -5,6 +5,7 @@ import android.content.ContentResolver;
import android.content.Context;
import android.net.Uri;
import android.os.AsyncTask;
import android.preference.PreferenceManager;
import android.support.v7.app.AlertDialog;
import android.util.Log;
import android.widget.Toast;
@ -388,7 +389,14 @@ public class Async {
}
protected void done() {
new AlertDialog.Builder(mContext)
AlertDialog.Builder builder;
String theme = PreferenceManager.getDefaultSharedPreferences(mContext).getString("theme", "");
if (theme.equals("Dark")) {
builder = new AlertDialog.Builder(mContext,R.style.AlertDialog_dh);
} else {
builder = new AlertDialog.Builder(mContext);
}
builder
.setTitle(R.string.reboot_title)
.setMessage(R.string.reboot_msg)
.setPositiveButton(R.string.reboot, (dialogInterface1, i) -> Shell.su("reboot"))

View File

@ -1,16 +1,24 @@
package com.topjohnwu.magisk.utils;
import android.content.Context;
import android.preference.PreferenceManager;
import android.support.v7.app.AlertDialog;
import android.webkit.WebResourceRequest;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import com.topjohnwu.magisk.R;
public class WebWindow {
public WebWindow(String title, String url, Context context) {
AlertDialog.Builder alert = new AlertDialog.Builder(context);
AlertDialog.Builder alert;
String theme = PreferenceManager.getDefaultSharedPreferences(context).getString("theme", "");
if (theme.equals("Dark")) {
alert = new AlertDialog.Builder(context, R.style.AlertDialog_dh);
} else {
alert = new AlertDialog.Builder(context);
}
alert.setTitle(title);
WebView wv = new WebView(context);