2024-09-15 22:47:45 -06:00
|
|
|
package com.ridgebotics.ridgescout.utility;
|
2024-07-24 15:27:13 -06:00
|
|
|
|
|
|
|
|
import android.app.Activity;
|
|
|
|
|
import android.app.AlertDialog;
|
|
|
|
|
import android.content.Context;
|
|
|
|
|
import android.widget.Toast;
|
|
|
|
|
|
|
|
|
|
import java.io.PrintWriter;
|
|
|
|
|
import java.io.StringWriter;
|
|
|
|
|
|
|
|
|
|
public class AlertManager {
|
2024-07-24 23:41:00 -06:00
|
|
|
public static Context context;
|
2024-07-24 15:27:13 -06:00
|
|
|
|
|
|
|
|
public static void init(Context c){
|
|
|
|
|
context = c;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void alert(String title, String content) {
|
|
|
|
|
((Activity) context).runOnUiThread(new Runnable() {
|
|
|
|
|
public void run() {
|
|
|
|
|
AlertDialog.Builder alert = new AlertDialog.Builder(context);
|
|
|
|
|
alert.setMessage(content);
|
|
|
|
|
alert.setTitle(title);
|
|
|
|
|
alert.setPositiveButton("OK", null);
|
|
|
|
|
alert.setCancelable(true);
|
|
|
|
|
|
|
|
|
|
alert.create().show();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void toast(String content) {
|
|
|
|
|
((Activity) context).runOnUiThread(new Runnable() {
|
|
|
|
|
public void run() {
|
|
|
|
|
Toast.makeText(context, content, Toast.LENGTH_LONG).show();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void error(String content) {
|
|
|
|
|
((Activity) context).runOnUiThread(new Runnable() {
|
|
|
|
|
public void run() {
|
|
|
|
|
AlertDialog.Builder alert = new AlertDialog.Builder(context);
|
|
|
|
|
alert.setMessage(content);
|
|
|
|
|
alert.setTitle("Error!");
|
|
|
|
|
alert.setPositiveButton("OK", null);
|
|
|
|
|
alert.setCancelable(true);
|
|
|
|
|
|
|
|
|
|
alert.create().show();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void error(Exception e) {
|
2024-07-24 23:41:00 -06:00
|
|
|
e.printStackTrace();
|
2025-02-20 12:57:14 -07:00
|
|
|
((Activity) context).runOnUiThread(() -> {
|
|
|
|
|
StringWriter sw = new StringWriter();
|
|
|
|
|
e.printStackTrace(new PrintWriter(sw));
|
2024-07-24 15:27:13 -06:00
|
|
|
|
2025-02-20 12:57:14 -07:00
|
|
|
AlertDialog.Builder alert = new AlertDialog.Builder(context);
|
|
|
|
|
alert.setMessage(sw.toString());
|
|
|
|
|
alert.setTitle(e.getMessage());
|
|
|
|
|
alert.setPositiveButton("OK", null);
|
|
|
|
|
alert.setCancelable(true);
|
2024-07-24 15:27:13 -06:00
|
|
|
|
2025-02-20 12:57:14 -07:00
|
|
|
alert.create().show();
|
2024-07-24 15:27:13 -06:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|