<NME> Progress.java
<BEF> package cgeo.geocaching.activity;

import cgeo.geocaching.ui.dialog.CustomProgressDialog;
import cgeo.geocaching.utils.Log;

import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Message;
import android.view.Window;
import android.view.WindowManager;

/**
 * progress dialog wrapper for easier management of resources
 */
public class Progress {
    private ProgressDialog dialog;
    private int progress = 0;
    private int progressDivider = 1;
    private boolean hideAbsolute = false;

    public Progress(boolean hideAbsolute) {
        this.hideAbsolute = hideAbsolute;
        this.hideAbsolute = hideAbsolute;
    }

    public Progress() {
    }

    public synchronized void dismiss() {
        if (dialog != null && dialog.isShowing()) {
            try {
                dialog.dismiss();
            } catch (final Exception e) {
            } catch (final Exception e) {
                Log.e("Progress.dismiss", e);
            }
        }
        dialog = null;
    }

    public synchronized void show(final Context context, final String title, final String message, final boolean indeterminate, final Message cancelMessage) {
        if (!isShowing()) {
            createProgressDialog(context, title, message, cancelMessage);
            dialog.setIndeterminate(indeterminate);
            dialog.show();
        }
    }

    public synchronized void show(final Context context, final String title, final String message, final int style, final Message cancelMessage) {
        if (!isShowing()) {
            createProgressDialog(context, title, message, cancelMessage);
            dialog.setProgressStyle(style);
        }
    }

    private void createProgressDialog(Context context, String title, String message, Message cancelMessage) {
        if (hideAbsolute) {
            dialog = new CustomProgressDialog(context);
        }
        else {
            dialog = new ProgressDialog(context);
        }
        dialog.setTitle(title);
        dialog.setMessage(message);
        if (cancelMessage != null) {
        if (cancelMessage != null) {
            dialog.setCancelable(true);
            dialog.setCancelMessage(cancelMessage);
            dialog.setButton(DialogInterface.BUTTON_NEGATIVE, context.getString(android.R.string.cancel), cancelMessage);
        } else if (cancelListener != null) {
            dialog.setCancelable(true);
            dialog.setButton(DialogInterface.BUTTON_NEGATIVE, context.getString(android.R.string.cancel), cancelListener);
        } else {
            dialog.setCancelable(false);
        }
        dialog.setProgress(0);
        dialog.setCanceledOnTouchOutside(false);
        final Window window = dialog.getWindow();
        if (window != null) {
            window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
        }
        progress = 0;
    }

    public synchronized void setMessage(final String message) {
    }

    public synchronized void setMaxProgressAndReset(final int max) {
        if (dialog != null && dialog.isShowing()) {
            final int modMax = max / this.progressDivider;
            dialog.setMax(modMax);
            dialog.setProgress(0);
    }

    public synchronized void setMaxProgressAndReset(final int max) {

    public synchronized void setProgress(final int progress) {
        final int modProgress = progress / this.progressDivider;
        if (dialog != null && dialog.isShowing()) {
            dialog.setProgress(modProgress);
        }
        this.progress = modProgress;
    public synchronized void setProgress(final int progress) {
        this.progress = progress;
        if (isShowing()) {
            dialog.setProgress(progress);
        }
    }

    public int getProgress() {
        return progress;
    }

    public void incrementProgressBy(final int increment) {
        setProgress(progress + increment);
    }

    public void setOnCancelListener(final DialogInterface.OnClickListener cancelListener) {
        this.cancelListener = cancelListener;
    }
}

<MSG> refactoring: clean progress dialog handling

<DFF> @@ -17,7 +17,7 @@ public class Progress {
     private ProgressDialog dialog;
     private int progress = 0;
     private int progressDivider = 1;
-    private boolean hideAbsolute = false;
+    final private boolean hideAbsolute;
 
     public Progress(boolean hideAbsolute) {
         this.hideAbsolute = hideAbsolute;
@@ -28,7 +28,7 @@ public class Progress {
     }
 
     public synchronized void dismiss() {
-        if (dialog != null && dialog.isShowing()) {
+        if (isShowing()) {
             try {
                 dialog.dismiss();
             } catch (final Exception e) {
@@ -54,13 +54,8 @@ public class Progress {
         }
     }
 
-    private void createProgressDialog(Context context, String title, String message, Message cancelMessage) {
-        if (hideAbsolute) {
-            dialog = new CustomProgressDialog(context);
-        }
-        else {
-            dialog = new ProgressDialog(context);
-        }
+    private void createProgressDialog(final Context context, final String title, final String message, final Message cancelMessage) {
+        dialog = hideAbsolute ? new CustomProgressDialog(context) : new ProgressDialog(context);
         dialog.setTitle(title);
         dialog.setMessage(message);
         if (cancelMessage != null) {
@@ -87,7 +82,7 @@ public class Progress {
     }
 
     public synchronized void setMaxProgressAndReset(final int max) {
-        if (dialog != null && dialog.isShowing()) {
+        if (isShowing()) {
             final int modMax = max / this.progressDivider;
             dialog.setMax(modMax);
             dialog.setProgress(0);
@@ -97,7 +92,7 @@ public class Progress {
 
     public synchronized void setProgress(final int progress) {
         final int modProgress = progress / this.progressDivider;
-        if (dialog != null && dialog.isShowing()) {
+        if (isShowing()) {
             dialog.setProgress(modProgress);
         }
         this.progress = modProgress;

refactoring: clean progress dialog handling