aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSamuel Tardieu <sam@rfc1149.net>2014-07-24 22:16:03 +0200
committerSamuel Tardieu <sam@rfc1149.net>2014-07-24 22:16:03 +0200
commitdec5f91c0ec5059877b313fdd984c25b052f6f9a (patch)
treed0655f4d857c67a94e2e18cd79ba7eef5ba96b62
parent9f90071b676caa441b8e63713dc2eb6010772ca0 (diff)
downloadcgeo-dec5f91c0ec5059877b313fdd984c25b052f6f9a.zip
cgeo-dec5f91c0ec5059877b313fdd984c25b052f6f9a.tar.gz
cgeo-dec5f91c0ec5059877b313fdd984c25b052f6f9a.tar.bz2
Simplify CustomProgressDialog implementation
-rw-r--r--main/src/cgeo/geocaching/ui/dialog/CustomProgressDialog.java27
1 files changed, 7 insertions, 20 deletions
diff --git a/main/src/cgeo/geocaching/ui/dialog/CustomProgressDialog.java b/main/src/cgeo/geocaching/ui/dialog/CustomProgressDialog.java
index 229150e..db21f70 100644
--- a/main/src/cgeo/geocaching/ui/dialog/CustomProgressDialog.java
+++ b/main/src/cgeo/geocaching/ui/dialog/CustomProgressDialog.java
@@ -7,14 +7,11 @@ 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
+ * Modified progress dialog class which allows hiding the absolute numbers.
*
*/
public class CustomProgressDialog extends ProgressDialog {
@@ -26,23 +23,13 @@ public class CustomProgressDialog extends ProgressDialog {
@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);
+ // Field is private, make it accessible through reflection before hiding it.
+ final Field field = getClass().getSuperclass().getDeclaredField("mProgressNumber");
+ field.setAccessible(true);
+ ((View) field.get(this)).setVisibility(View.GONE);
+ } catch (NoSuchFieldException | IllegalAccessException e) {
+ Log.e("Failed to find the progressDialog field 'mProgressNumber'", e);
}
}
} \ No newline at end of file