OKDialog layout
This commit is contained in:
parent
06d2a2cfc5
commit
9042957585
4 changed files with 90 additions and 40 deletions
|
@ -1,47 +1,41 @@
|
|||
package info.nightscout.androidaps.utils;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Handler;
|
||||
import android.os.SystemClock;
|
||||
import android.text.Spanned;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.appcompat.view.ContextThemeWrapper;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
|
||||
/**
|
||||
* Created by mike on 31.03.2017.
|
||||
*/
|
||||
|
||||
public class OKDialog {
|
||||
private static Logger log = LoggerFactory.getLogger(OKDialog.class);
|
||||
|
||||
public static void show(final Context context, String title, String message, final Runnable runnable) {
|
||||
try {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(context, R.style.AppTheme));
|
||||
builder.setTitle(title);
|
||||
builder.setMessage(message);
|
||||
builder.setPositiveButton(MainApp.gs(R.string.ok), new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
if (title.isEmpty()) title = MainApp.gs(R.string.message);
|
||||
View titleLayout = LayoutInflater.from(context).inflate(R.layout.dialog_alert_custom, null);
|
||||
((TextView)titleLayout.findViewById(R.id.alertdialog_title)).setText(title);
|
||||
((ImageView)titleLayout.findViewById(R.id.alertdialog_icon)).setImageResource(R.drawable.ic_check_while_48dp);
|
||||
|
||||
new AlertDialog.Builder(new ContextThemeWrapper(context, R.style.AppTheme))
|
||||
.setCustomTitle(titleLayout)
|
||||
.setMessage(message)
|
||||
.setPositiveButton(MainApp.gs(R.string.ok), (dialog, which) -> {
|
||||
dialog.dismiss();
|
||||
if (runnable != null) {
|
||||
SystemClock.sleep(100);
|
||||
runOnUiThread(runnable);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
builder.create().show();
|
||||
} catch (Exception e) {
|
||||
log.debug("show_dialog exception: ", e);
|
||||
}
|
||||
})
|
||||
.show()
|
||||
.setCanceledOnTouchOutside(false);
|
||||
}
|
||||
|
||||
public static boolean runOnUiThread(Runnable theRunnable) {
|
||||
|
@ -50,24 +44,23 @@ public class OKDialog {
|
|||
}
|
||||
|
||||
public static void show(final Activity activity, String title, Spanned message, final Runnable runnable) {
|
||||
try {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(activity, R.style.AppTheme));
|
||||
builder.setTitle(title);
|
||||
builder.setMessage(message);
|
||||
builder.setPositiveButton(MainApp.gs(R.string.ok), new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
if (title.isEmpty()) title = MainApp.gs(R.string.message);
|
||||
View titleLayout = activity.getLayoutInflater().inflate(R.layout.dialog_alert_custom, null);
|
||||
((TextView)titleLayout.findViewById(R.id.alertdialog_title)).setText(title);
|
||||
((ImageView)titleLayout.findViewById(R.id.alertdialog_icon)).setImageResource(R.drawable.ic_check_while_48dp);
|
||||
|
||||
new AlertDialog.Builder(new ContextThemeWrapper(activity, R.style.AppTheme))
|
||||
.setCustomTitle(titleLayout)
|
||||
.setMessage(message)
|
||||
.setPositiveButton(MainApp.gs(R.string.ok), (dialog, which) -> {
|
||||
dialog.dismiss();
|
||||
if (runnable != null) {
|
||||
SystemClock.sleep(100);
|
||||
activity.runOnUiThread(runnable);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
builder.create().show();
|
||||
} catch (Exception e) {
|
||||
log.debug("show_dialog exception: " + e);
|
||||
}
|
||||
})
|
||||
.show()
|
||||
.setCanceledOnTouchOutside(false);
|
||||
}
|
||||
|
||||
public static void showConfirmation(final Activity activity, String message, final Runnable ok) {
|
||||
|
@ -79,9 +72,13 @@ public class OKDialog {
|
|||
}
|
||||
|
||||
public static void showConfirmation(final Activity activity, Spanned message, final Runnable ok, final Runnable cancel) {
|
||||
View titleLayout = activity.getLayoutInflater().inflate(R.layout.dialog_alert_custom, null);
|
||||
((TextView)titleLayout.findViewById(R.id.alertdialog_title)).setText(R.string.confirmation);
|
||||
((ImageView)titleLayout.findViewById(R.id.alertdialog_icon)).setImageResource(R.drawable.ic_check_while_48dp);
|
||||
|
||||
new AlertDialog.Builder(new ContextThemeWrapper(activity, R.style.AppTheme))
|
||||
.setMessage(message)
|
||||
.setTitle(MainApp.gs(R.string.confirmation))
|
||||
.setCustomTitle(titleLayout)
|
||||
.setPositiveButton(android.R.string.ok, (dialog, which) -> {
|
||||
dialog.dismiss();
|
||||
if (ok != null) {
|
||||
|
@ -97,13 +94,19 @@ public class OKDialog {
|
|||
}
|
||||
})
|
||||
.setNegativeButton(android.R.string.cancel, null)
|
||||
.show();
|
||||
.show()
|
||||
.setCanceledOnTouchOutside(false);
|
||||
}
|
||||
|
||||
public static void showConfirmation(final Activity activity, String message, final Runnable ok, final Runnable cancel) {
|
||||
View titleLayout = activity.getLayoutInflater().inflate(R.layout.dialog_alert_custom, null);
|
||||
((TextView)titleLayout.findViewById(R.id.alertdialog_title)).setText(R.string.confirmation);
|
||||
((ImageView)titleLayout.findViewById(R.id.alertdialog_icon)).setImageResource(R.drawable.ic_check_while_48dp);
|
||||
|
||||
new AlertDialog.Builder(new ContextThemeWrapper(activity, R.style.AppTheme))
|
||||
.setMessage(message)
|
||||
.setTitle(MainApp.gs(R.string.confirmation))
|
||||
.setCustomTitle(titleLayout)
|
||||
.setView(R.layout.dialog_alert_custom)
|
||||
.setPositiveButton(android.R.string.ok, (dialog, which) -> {
|
||||
dialog.dismiss();
|
||||
if (ok != null) {
|
||||
|
@ -118,7 +121,8 @@ public class OKDialog {
|
|||
activity.runOnUiThread(cancel);
|
||||
}
|
||||
})
|
||||
.show();
|
||||
.show()
|
||||
.setCanceledOnTouchOutside(false);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
5
app/src/main/res/drawable/ic_check_while_48dp.xml
Normal file
5
app/src/main/res/drawable/ic_check_while_48dp.xml
Normal file
|
@ -0,0 +1,5 @@
|
|||
<vector android:height="48dp" android:tint="#FFFFFF"
|
||||
android:viewportHeight="24.0" android:viewportWidth="24.0"
|
||||
android:width="48dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="#FF000000" android:pathData="M9,16.17L4.83,12l-1.42,1.41L9,19 21,7l-1.41,-1.41z"/>
|
||||
</vector>
|
40
app/src/main/res/layout/dialog_alert_custom.xml
Normal file
40
app/src/main/res/layout/dialog_alert_custom.xml
Normal file
|
@ -0,0 +1,40 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:background="@color/dialog_title_background"
|
||||
android:orientation="horizontal"
|
||||
android:padding="5dp">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/alertdialog_icon"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/alertdialog_title"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerInParent="true"
|
||||
android:layout_gravity="center"
|
||||
android:layout_marginLeft="10dp"
|
||||
android:layout_marginRight="10dp"
|
||||
android:textAlignment="center"
|
||||
android:textAppearance="?android:attr/textAppearanceLarge" />
|
||||
</RelativeLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/spacer"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:padding="5dp" />
|
||||
|
||||
|
||||
</LinearLayout>
|
|
@ -1691,5 +1691,6 @@
|
|||
<string name="timeformat24h">24h</string>
|
||||
<string name="automation_event">Automation event</string>
|
||||
<string name="alreadyset">Already set</string>
|
||||
<string name="message">Message</string>
|
||||
|
||||
</resources>
|
||||
|
|
Loading…
Reference in a new issue