mirror of
https://codeberg.org/OpenTracksApp/OpenTracks.git
synced 2026-10-07 20:03:06 +02:00
Set dialog title divider for preference dialogs
This commit is contained in:
@@ -46,15 +46,22 @@ public class DialogUtils {
|
||||
* @param okListener the listener when OK is clicked
|
||||
*/
|
||||
public static Dialog createConfirmationDialog(
|
||||
Context context, int titleId, String message, DialogInterface.OnClickListener okListener) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(context)
|
||||
final Context context, int titleId, String message, DialogInterface.OnClickListener okListener) {
|
||||
final AlertDialog alertDialog = new AlertDialog.Builder(context)
|
||||
.setCancelable(true)
|
||||
.setIcon(android.R.drawable.ic_dialog_alert)
|
||||
.setMessage(message)
|
||||
.setNegativeButton(R.string.generic_no, null)
|
||||
.setPositiveButton(R.string.generic_yes, okListener)
|
||||
.setTitle(titleId);
|
||||
return builder.create();
|
||||
.setTitle(titleId).create();
|
||||
alertDialog.setOnShowListener(new DialogInterface.OnShowListener() {
|
||||
|
||||
@Override
|
||||
public void onShow(DialogInterface dialog) {
|
||||
setDialogTitleDivider(context, alertDialog);
|
||||
}
|
||||
});
|
||||
return alertDialog;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -91,9 +98,9 @@ public class DialogUtils {
|
||||
* @param onCancelListener the cancel listener
|
||||
* @param formatArgs the format arguments for the message id
|
||||
*/
|
||||
private static ProgressDialog createProgressDialog(boolean spinner, Context context,
|
||||
private static ProgressDialog createProgressDialog(boolean spinner, final Context context,
|
||||
int messageId, DialogInterface.OnCancelListener onCancelListener, Object... formatArgs) {
|
||||
ProgressDialog progressDialog = new ProgressDialog(context);
|
||||
final ProgressDialog progressDialog = new ProgressDialog(context);
|
||||
progressDialog.setCancelable(true);
|
||||
progressDialog.setCanceledOnTouchOutside(false);
|
||||
progressDialog.setIcon(android.R.drawable.ic_dialog_info);
|
||||
@@ -103,18 +110,49 @@ public class DialogUtils {
|
||||
progressDialog.setProgressStyle(spinner ? ProgressDialog.STYLE_SPINNER
|
||||
: ProgressDialog.STYLE_HORIZONTAL);
|
||||
progressDialog.setTitle(R.string.generic_progress_title);
|
||||
progressDialog.setOnShowListener(new DialogInterface.OnShowListener() {
|
||||
|
||||
@Override
|
||||
public void onShow(DialogInterface dialog) {
|
||||
setDialogTitleDivider(context, progressDialog);
|
||||
}
|
||||
});
|
||||
return progressDialog;
|
||||
}
|
||||
|
||||
public static void setTitleDivier(Context context, Dialog dialog) {
|
||||
/**
|
||||
* Sets the dialog title divider.
|
||||
*
|
||||
* @param context the context
|
||||
* @param dialog the dialog
|
||||
*/
|
||||
public static void setDialogTitleDivider(Context context, Dialog dialog) {
|
||||
if (ApiAdapterFactory.getApiAdapter().hasDialogTitleDivider()) {
|
||||
try {
|
||||
ViewGroup decorView = (ViewGroup) dialog.getWindow().getDecorView();
|
||||
if (decorView == null) {
|
||||
return;
|
||||
}
|
||||
FrameLayout windowContentView = (FrameLayout) decorView.getChildAt(0);
|
||||
if (windowContentView == null) {
|
||||
return;
|
||||
}
|
||||
FrameLayout contentView = (FrameLayout) windowContentView.getChildAt(0);
|
||||
if (contentView == null) {
|
||||
return;
|
||||
}
|
||||
LinearLayout parentPanel = (LinearLayout) contentView.getChildAt(0);
|
||||
if (parentPanel == null) {
|
||||
return;
|
||||
}
|
||||
LinearLayout topPanel = (LinearLayout) parentPanel.getChildAt(0);
|
||||
if (topPanel == null) {
|
||||
return;
|
||||
}
|
||||
View titleDivider = topPanel.getChildAt(2);
|
||||
if (titleDivider == null) {
|
||||
return;
|
||||
}
|
||||
titleDivider.setBackgroundColor(context.getResources().getColor(R.color.holo_orange_dark));
|
||||
} catch (Exception e) {
|
||||
// Can safely ignore
|
||||
|
||||
Reference in New Issue
Block a user