package cgeo.geocaching.ui.dialog;

import cgeo.geocaching.activity.ActivityMixin;
import cgeo.geocaching.utils.Log;

import android.app.ProgressDialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * Modified progress dialog class which allows hiding the absolute numbers
 *
 */
public class CustomProgressDialog extends ProgressDialog {

    public CustomProgressDialog(final Context context) {
        super(context, ActivityMixin.getDialogTheme());
    }

    @Override
    protected void onCreate(final Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        try {
            final Method method = TextView.class.getMethod("setVisibility", Integer.TYPE);

            final Field[] fields = this.getClass().getSuperclass().getDeclaredFields();

            for (final Field field : fields) {
                if (field.getName().equalsIgnoreCase("mProgressNumber")) {
                    field.setAccessible(true);
                    final TextView textView = (TextView) field.get(this);
                    method.invoke(textView, View.GONE);
                }
            }
        } catch (final NoSuchMethodException e) {
            Log.e("Failed to find the progressDialog method 'setVisibility'.", e);
        } catch (final IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
            Log.e("Failed to invoke the progressDialog method 'setVisibility' and set 'mProgressNumber' to GONE.", e);
        }
    }
}
@@ -233,40 +233,8 @@
 iew;
-%0Aimport android.widget.TextView;
 %0A%0Aim
@@ -266,93 +266,8 @@
 eld;
-%0Aimport java.lang.reflect.InvocationTargetException;%0Aimport java.lang.reflect.Method;
 %0A%0A/*
@@ -342,16 +342,17 @@
  numbers
+.
 %0A *%0A */%0A
@@ -652,17 +652,16 @@
 State);%0A
-%0A
         
@@ -682,87 +682,84 @@
     
-final Method method = TextView.class.getMethod(%22setVisibility%22, Integer.TYPE);%0A
+// Field is private, make it accessible through reflection before hiding it.
 %0A   
@@ -782,25 +782,17 @@
 ield
-%5B%5D
  field
-s
  = 
-this.
 getC
@@ -834,113 +834,8 @@
 ield
-s();%0A%0A            for (final Field field : fields) %7B%0A                if (field.getName().equalsIgnoreCase
 (%22mP
@@ -849,28 +849,18 @@
 Number%22)
-) %7B%0A        
+;%0A
         
@@ -906,382 +906,112 @@
     
-   
-     final TextView textView = (TextView) field.get(this);%0A                    method.invoke(textView, View.GONE);%0A                %7D%0A            %7D%0A        %7D catch (final NoSuchMethodException e) %7B%0A            Log.e(%22Failed to find the progressDialog method 'setVisibility'.%22, e);%0A        %7D catch (final IllegalAccessException %7C IllegalArgumentException %7C InvocationTarget
+((View) field.get(this)).setVisibility(View.GONE);%0A        %7D catch (NoSuchFieldException %7C IllegalAccess
 Exce
@@ -1054,14 +1054,12 @@
  to 
+f
 in
-voke
+d
  the
@@ -1078,38 +1078,13 @@
 log 
-method 'setVisibility' and set
+field
  'mP
@@ -1101,17 +1101,8 @@
 ber'
- to GONE.
 %22, e

Simplify CustomProgressDialog implementation