Skip to content

Commit

Permalink
feat(android): use material themed dialogs
Browse files Browse the repository at this point in the history
Fixes TIMOB-28299
  • Loading branch information
jquick-axway authored and sgtcoolguy committed Mar 5, 2021
1 parent 86a704f commit ed22a7d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package ti.modules.titanium.android.quicksettings;

import android.annotation.TargetApi;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.graphics.drawable.Icon;
import android.service.quicksettings.TileService;

import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import org.appcelerator.kroll.KrollDict;
import org.appcelerator.kroll.KrollRuntime;
import org.appcelerator.kroll.annotations.Kroll;
Expand All @@ -27,7 +26,7 @@ public class QuickSettingsServiceProxy extends ServiceProxy
private TileService tileService;
//workaround for dealing with Icon class
private Object pathObject = null;
private AlertDialog.Builder builder;
private MaterialAlertDialogBuilder builder;

public QuickSettingsServiceProxy(TileService serviceInstance)
{
Expand Down Expand Up @@ -134,7 +133,7 @@ public void run()

private Dialog createDialogFromDictionary(KrollDict krollDict)
{
builder = new AlertDialog.Builder(tileService.getApplicationContext());
builder = new MaterialAlertDialogBuilder(tileService.getApplicationContext());
String[] buttonText = null;
if (krollDict.containsKey(TiC.PROPERTY_TITLE)) {
builder.setTitle(krollDict.getString(TiC.PROPERTY_TITLE));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,19 @@

import android.app.Activity;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AlertDialog.Builder;
import android.content.DialogInterface;
import android.content.DialogInterface.OnCancelListener;
import androidx.core.view.ViewCompat;
import android.view.ViewParent;
import android.widget.ListView;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;

public class TiUIDialog extends TiUIView
{
private static final String TAG = "TiUIDialog";
private static final int BUTTON_MASK = 0x10000000;

protected Builder builder;
protected MaterialAlertDialogBuilder builder;
protected TiUIView view;
private DialogWrapper dialogWrapper;

Expand Down Expand Up @@ -68,7 +68,7 @@ private Activity getCurrentActivity()
return currentActivity;
}

private Builder getBuilder()
private MaterialAlertDialogBuilder getBuilder()
{
if (builder == null) {
createBuilder();
Expand All @@ -81,13 +81,13 @@ public void processProperties(KrollDict d)
{
String[] buttonText = null;
if (d.containsKey(TiC.PROPERTY_TITLE)) {
Builder builder = getBuilder();
MaterialAlertDialogBuilder builder = getBuilder();
if (builder != null) {
builder.setTitle(d.getString(TiC.PROPERTY_TITLE));
}
}
if (d.containsKey(TiC.PROPERTY_MESSAGE)) {
Builder builder = getBuilder();
MaterialAlertDialogBuilder builder = getBuilder();
if (builder != null) {
builder.setMessage(d.getString(TiC.PROPERTY_MESSAGE));
}
Expand Down Expand Up @@ -124,7 +124,7 @@ public void processProperties(KrollDict d)

private void processOptions(String[] optionText, int selectedIndex)
{
Builder builder = getBuilder();
MaterialAlertDialogBuilder builder = getBuilder();
if (builder == null) {
return;
}
Expand Down Expand Up @@ -152,7 +152,7 @@ public void onClick(DialogInterface dialog, int which)

private void processButtons(String[] buttonText)
{
Builder builder = getBuilder();
MaterialAlertDialogBuilder builder = getBuilder();
if (builder == null) {
return;
}
Expand Down Expand Up @@ -203,7 +203,7 @@ private void processView(TiViewProxy proxy)
view = proxy.getOrCreateView();

// Handle view border.
Builder builder = getBuilder();
MaterialAlertDialogBuilder builder = getBuilder();
if ((builder != null) && (view != null)) {
ViewParent viewParent = view.getNativeView().getParent();
if (viewParent != null) {
Expand Down Expand Up @@ -244,7 +244,7 @@ public void propertyChanged(String key, Object oldValue, Object newValue, KrollP
processButtons(new String[] { TiConvert.toString(newValue) });
} else if (key.equals(TiC.PROPERTY_OPTIONS)) {
dismissDialog();
Builder builder = getBuilder();
MaterialAlertDialogBuilder builder = getBuilder();
if (builder != null) {
builder.setView(null);
}
Expand All @@ -255,7 +255,7 @@ public void propertyChanged(String key, Object oldValue, Object newValue, KrollP
processOptions(TiConvert.toStringArray((Object[]) newValue), selectedIndex);
} else if (key.equals(TiC.PROPERTY_SELECTED_INDEX)) {
dismissDialog();
Builder builder = getBuilder();
MaterialAlertDialogBuilder builder = getBuilder();
if (builder != null) {
builder.setView(null);
}
Expand Down Expand Up @@ -302,7 +302,7 @@ public void show(KrollDict options)
return;
}

Builder builder = getBuilder();
MaterialAlertDialogBuilder builder = getBuilder();
if (builder == null) {
return;
}
Expand Down Expand Up @@ -427,7 +427,7 @@ private void createBuilder()
{
Activity currentActivity = getCurrentActivity();
if (currentActivity != null) {
this.builder = new AlertDialog.Builder(currentActivity);
this.builder = new MaterialAlertDialogBuilder(currentActivity);
this.builder.setCancelable(true);

//Native dialogs are persistent by default.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
import android.view.View.MeasureSpec;
import android.view.inputmethod.InputMethodManager;
import android.widget.TextView;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;

/**
* A set of utility methods focused on UI and View operations.
Expand Down Expand Up @@ -141,7 +142,7 @@ public static void doKillOrContinueDialog(Context context, String title, String
negativeListener = createKillListener();
}

new AlertDialog.Builder(context)
new MaterialAlertDialogBuilder(context)
.setTitle(title)
.setMessage(message)
.setPositiveButton("Continue", positiveListener)
Expand Down Expand Up @@ -222,7 +223,7 @@ public void onCurrentActivityReady(Activity activity)
{
//add dialog to activity for cleaning up purposes
if (!activity.isFinishing()) {
AlertDialog dialog = new AlertDialog.Builder(activity)
AlertDialog dialog = new MaterialAlertDialogBuilder(activity)
.setTitle(title)
.setMessage(message)
.setPositiveButton(android.R.string.ok, fListener)
Expand Down

0 comments on commit ed22a7d

Please sign in to comment.