aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching/ui
diff options
context:
space:
mode:
Diffstat (limited to 'main/src/cgeo/geocaching/ui')
-rw-r--r--main/src/cgeo/geocaching/ui/CacheDetailsCreator.java14
-rw-r--r--main/src/cgeo/geocaching/ui/CompassView.java19
-rw-r--r--main/src/cgeo/geocaching/ui/EditNoteDialog.java22
-rw-r--r--main/src/cgeo/geocaching/ui/ImagesList.java9
-rw-r--r--main/src/cgeo/geocaching/ui/dialog/CoordinatesInputDialog.java48
-rw-r--r--main/src/cgeo/geocaching/ui/dialog/CustomProgressDialog.java19
-rw-r--r--main/src/cgeo/geocaching/ui/dialog/DateDialog.java16
7 files changed, 77 insertions, 70 deletions
diff --git a/main/src/cgeo/geocaching/ui/CacheDetailsCreator.java b/main/src/cgeo/geocaching/ui/CacheDetailsCreator.java
index e4b5f54..afd3666 100644
--- a/main/src/cgeo/geocaching/ui/CacheDetailsCreator.java
+++ b/main/src/cgeo/geocaching/ui/CacheDetailsCreator.java
@@ -1,5 +1,7 @@
package cgeo.geocaching.ui;
+import butterknife.ButterKnife;
+
import cgeo.geocaching.CgeoApplication;
import cgeo.geocaching.Geocache;
import cgeo.geocaching.R;
@@ -50,9 +52,9 @@ public final class CacheDetailsCreator {
*/
public TextView add(final int nameId, final CharSequence value) {
final RelativeLayout layout = (RelativeLayout) activity.getLayoutInflater().inflate(R.layout.cache_information_item, null, false);
- final TextView nameView = (TextView) layout.findViewById(R.id.name);
+ final TextView nameView = ButterKnife.findById(layout, R.id.name);
nameView.setText(res.getString(nameId));
- lastValueView = (TextView) layout.findViewById(R.id.value);
+ lastValueView = ButterKnife.findById(layout, R.id.value);
lastValueView.setText(value);
parentView.addView(layout);
return lastValueView;
@@ -68,9 +70,9 @@ public final class CacheDetailsCreator {
public RelativeLayout addStars(final int nameId, final float value, final int max) {
final RelativeLayout layout = (RelativeLayout) activity.getLayoutInflater().inflate(R.layout.cache_information_item, null, false);
- final TextView nameView = (TextView) layout.findViewById(R.id.name);
- lastValueView = (TextView) layout.findViewById(R.id.value);
- final LinearLayout layoutStars = (LinearLayout) layout.findViewById(R.id.stars);
+ final TextView nameView = ButterKnife.findById(layout, R.id.name);
+ lastValueView = ButterKnife.findById(layout, R.id.value);
+ final LinearLayout layoutStars = ButterKnife.findById(layout, R.id.stars);
nameView.setText(activity.getResources().getString(nameId));
lastValueView.setText(String.format("%.1f", value) + ' ' + activity.getResources().getString(R.string.cache_rating_of) + " " + String.format("%d", max));
@@ -123,7 +125,7 @@ public final class CacheDetailsCreator {
if (cache.getRating() > 0) {
final RelativeLayout itemLayout = addStars(R.string.cache_rating, cache.getRating());
if (cache.getVotes() > 0) {
- final TextView itemAddition = (TextView) itemLayout.findViewById(R.id.addition);
+ final TextView itemAddition = ButterKnife.findById(itemLayout, R.id.addition);
itemAddition.setText("(" + cache.getVotes() + ")");
itemAddition.setVisibility(View.VISIBLE);
}
diff --git a/main/src/cgeo/geocaching/ui/CompassView.java b/main/src/cgeo/geocaching/ui/CompassView.java
index 60982a9..b503d6c 100644
--- a/main/src/cgeo/geocaching/ui/CompassView.java
+++ b/main/src/cgeo/geocaching/ui/CompassView.java
@@ -6,6 +6,7 @@ import cgeo.geocaching.utils.AngleUtils;
import rx.Subscription;
import rx.android.schedulers.AndroidSchedulers;
import rx.functions.Action0;
+import rx.subscriptions.Subscriptions;
import android.content.Context;
import android.content.res.Resources;
@@ -54,13 +55,13 @@ public class CompassView extends View {
private int compassOverlayWidth = 0;
private int compassOverlayHeight = 0;
private boolean initialDisplay;
- private Subscription periodicUpdate;
+ private Subscription periodicUpdate = Subscriptions.empty();
private static final class UpdateAction implements Action0 {
private final WeakReference<CompassView> compassViewRef;
- private UpdateAction(CompassView view) {
+ private UpdateAction(final CompassView view) {
this.compassViewRef = new WeakReference<CompassView>(view);
}
@@ -74,7 +75,7 @@ public class CompassView extends View {
}
}
- public CompassView(Context contextIn) {
+ public CompassView(final Context contextIn) {
super(contextIn);
context = contextIn;
}
@@ -90,7 +91,7 @@ public class CompassView extends View {
}
}
- public CompassView(Context contextIn, AttributeSet attrs) {
+ public CompassView(final Context contextIn, final AttributeSet attrs) {
super(contextIn, attrs);
context = contextIn;
}
@@ -174,7 +175,7 @@ public class CompassView extends View {
* the actual value
* @return the new value
*/
- static protected float smoothUpdate(float goal, float actual) {
+ static protected float smoothUpdate(final float goal, final float actual) {
final double diff = AngleUtils.difference(actual, goal);
double offset = 0;
@@ -191,7 +192,7 @@ public class CompassView extends View {
}
@Override
- protected void onDraw(Canvas canvas) {
+ protected void onDraw(final Canvas canvas) {
final float azimuthTemp = azimuthShown;
final float azimuthRelative = AngleUtils.normalize(azimuthTemp - cacheHeadingShown);
@@ -236,11 +237,11 @@ public class CompassView extends View {
}
@Override
- protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
+ protected void onMeasure(final int widthMeasureSpec, final int heightMeasureSpec) {
setMeasuredDimension(measureWidth(widthMeasureSpec), measureHeight(heightMeasureSpec));
}
- private int measureWidth(int measureSpec) {
+ private int measureWidth(final int measureSpec) {
final int specMode = MeasureSpec.getMode(measureSpec);
final int specSize = MeasureSpec.getSize(measureSpec);
@@ -256,7 +257,7 @@ public class CompassView extends View {
return desired;
}
- private int measureHeight(int measureSpec) {
+ private int measureHeight(final int measureSpec) {
// The duplicated code in measureHeight and measureWidth cannot be avoided.
// Those methods must be efficient, therefore we cannot extract the code differences and unify the remainder.
final int specMode = MeasureSpec.getMode(measureSpec);
diff --git a/main/src/cgeo/geocaching/ui/EditNoteDialog.java b/main/src/cgeo/geocaching/ui/EditNoteDialog.java
index 63f06fc..cb1b11d 100644
--- a/main/src/cgeo/geocaching/ui/EditNoteDialog.java
+++ b/main/src/cgeo/geocaching/ui/EditNoteDialog.java
@@ -1,5 +1,7 @@
package cgeo.geocaching.ui;
+import butterknife.ButterKnife;
+
import cgeo.geocaching.R;
import cgeo.geocaching.activity.Keyboard;
import cgeo.geocaching.ui.dialog.Dialogs;
@@ -27,10 +29,10 @@ public class EditNoteDialog extends DialogFragment {
private EditText mEditText;
private EditNoteDialogListener listener;
- public static EditNoteDialog newInstance(final String initialNote, EditNoteDialogListener listener) {
- EditNoteDialog dialog = new EditNoteDialog();
+ public static EditNoteDialog newInstance(final String initialNote, final EditNoteDialogListener listener) {
+ final EditNoteDialog dialog = new EditNoteDialog();
- Bundle arguments = new Bundle();
+ final Bundle arguments = new Bundle();
arguments.putString(EditNoteDialog.ARGUMENT_INITIAL_NOTE, initialNote);
dialog.setArguments(arguments);
dialog.listener = listener;
@@ -39,24 +41,24 @@ public class EditNoteDialog extends DialogFragment {
}
@Override
- public Dialog onCreateDialog(Bundle savedInstanceState) {
+ public Dialog onCreateDialog(final Bundle savedInstanceState) {
final @NonNull FragmentActivity activity = getActivity();
- View view = View.inflate(new ContextThemeWrapper(activity, R.style.dark), R.layout.fragment_edit_note, null);
- mEditText = (EditText) view.findViewById(R.id.note);
- String initialNote = getArguments().getString(ARGUMENT_INITIAL_NOTE);
+ final View view = View.inflate(new ContextThemeWrapper(activity, R.style.dark), R.layout.fragment_edit_note, null);
+ mEditText = ButterKnife.findById(view, R.id.note);
+ final String initialNote = getArguments().getString(ARGUMENT_INITIAL_NOTE);
if (initialNote != null) {
mEditText.setText(initialNote);
Dialogs.moveCursorToEnd(mEditText);
getArguments().remove(ARGUMENT_INITIAL_NOTE);
}
- AlertDialog.Builder builder = new AlertDialog.Builder(activity);
+ final AlertDialog.Builder builder = new AlertDialog.Builder(activity);
builder.setTitle(R.string.cache_personal_note);
builder.setView(view);
builder.setPositiveButton(android.R.string.ok,
new DialogInterface.OnClickListener() {
@Override
- public void onClick(DialogInterface dialog, int whichButton) {
+ public void onClick(final DialogInterface dialog, final int whichButton) {
listener.onFinishEditNoteDialog(mEditText.getText().toString());
dialog.dismiss();
}
@@ -64,7 +66,7 @@ public class EditNoteDialog extends DialogFragment {
builder.setNegativeButton(android.R.string.cancel,
new DialogInterface.OnClickListener() {
@Override
- public void onClick(DialogInterface dialog, int whichButton) {
+ public void onClick(final DialogInterface dialog, final int whichButton) {
dialog.dismiss();
}
});
diff --git a/main/src/cgeo/geocaching/ui/ImagesList.java b/main/src/cgeo/geocaching/ui/ImagesList.java
index bf53725..fbf6f8b 100644
--- a/main/src/cgeo/geocaching/ui/ImagesList.java
+++ b/main/src/cgeo/geocaching/ui/ImagesList.java
@@ -1,5 +1,7 @@
package cgeo.geocaching.ui;
+import butterknife.ButterKnife;
+
import cgeo.geocaching.Image;
import cgeo.geocaching.R;
import cgeo.geocaching.files.LocalStorage;
@@ -98,7 +100,7 @@ public class ImagesList {
}
}));
- imagesView = (LinearLayout) parentView.findViewById(R.id.spoiler_list);
+ imagesView = ButterKnife.findById(parentView, R.id.spoiler_list);
final HtmlImage imgGetter = new HtmlImage(geocode, true, offline ? StoredList.STANDARD_LIST_ID : StoredList.TEMPORARY_LIST_ID, false);
@@ -107,12 +109,13 @@ public class ImagesList {
assert(rowView != null);
if (StringUtils.isNotBlank(img.getTitle())) {
- ((TextView) rowView.findViewById(R.id.title)).setText(Html.fromHtml(img.getTitle()));
+ final TextView titleView = ButterKnife.findById(rowView, R.id.title);
+ titleView.setText(Html.fromHtml(img.getTitle()));
rowView.findViewById(R.id.titleLayout).setVisibility(View.VISIBLE);
}
if (StringUtils.isNotBlank(img.getDescription())) {
- final TextView descView = (TextView) rowView.findViewById(R.id.description);
+ final TextView descView = ButterKnife.findById(rowView, R.id.description);
descView.setText(Html.fromHtml(img.getDescription()), TextView.BufferType.SPANNABLE);
descView.setVisibility(View.VISIBLE);
}
diff --git a/main/src/cgeo/geocaching/ui/dialog/CoordinatesInputDialog.java b/main/src/cgeo/geocaching/ui/dialog/CoordinatesInputDialog.java
index 06943f0..ca3e3a4 100644
--- a/main/src/cgeo/geocaching/ui/dialog/CoordinatesInputDialog.java
+++ b/main/src/cgeo/geocaching/ui/dialog/CoordinatesInputDialog.java
@@ -1,5 +1,7 @@
package cgeo.geocaching.ui.dialog;
+import butterknife.ButterKnife;
+
import cgeo.geocaching.Geocache;
import cgeo.geocaching.R;
import cgeo.geocaching.activity.AbstractActivity;
@@ -103,7 +105,7 @@ public class CoordinatesInputDialog extends DialogFragment {
getDialog().setTitle(R.string.cache_coordinates);
final View v = inflater.inflate(R.layout.coordinatesinput_dialog, container, false);
- final Spinner spinner = (Spinner) v.findViewById(R.id.spinnerCoordinateFormats);
+ final Spinner spinner = ButterKnife.findById(v, R.id.spinnerCoordinateFormats);
final ArrayAdapter<CharSequence> adapter =
ArrayAdapter.createFromResource(getActivity(),
R.array.waypoint_coordinate_formats,
@@ -113,25 +115,25 @@ public class CoordinatesInputDialog extends DialogFragment {
spinner.setSelection(Settings.getCoordInputFormat().ordinal());
spinner.setOnItemSelectedListener(new CoordinateFormatListener());
- bLat = (Button) v.findViewById(R.id.ButtonLat);
- eLat = (EditText) v.findViewById(R.id.latitude);
- eLatDeg = (EditText) v.findViewById(R.id.EditTextLatDeg);
- eLatMin = (EditText) v.findViewById(R.id.EditTextLatMin);
- eLatSec = (EditText) v.findViewById(R.id.EditTextLatSec);
- eLatSub = (EditText) v.findViewById(R.id.EditTextLatSecFrac);
- tLatSep1 = (TextView) v.findViewById(R.id.LatSeparator1);
- tLatSep2 = (TextView) v.findViewById(R.id.LatSeparator2);
- tLatSep3 = (TextView) v.findViewById(R.id.LatSeparator3);
-
- bLon = (Button) v.findViewById(R.id.ButtonLon);
- eLon = (EditText) v.findViewById(R.id.longitude);
- eLonDeg = (EditText) v.findViewById(R.id.EditTextLonDeg);
- eLonMin = (EditText) v.findViewById(R.id.EditTextLonMin);
- eLonSec = (EditText) v.findViewById(R.id.EditTextLonSec);
- eLonSub = (EditText) v.findViewById(R.id.EditTextLonSecFrac);
- tLonSep1 = (TextView) v.findViewById(R.id.LonSeparator1);
- tLonSep2 = (TextView) v.findViewById(R.id.LonSeparator2);
- tLonSep3 = (TextView) v.findViewById(R.id.LonSeparator3);
+ bLat = ButterKnife.findById(v, R.id.ButtonLat);
+ eLat = ButterKnife.findById(v, R.id.latitude);
+ eLatDeg = ButterKnife.findById(v, R.id.EditTextLatDeg);
+ eLatMin = ButterKnife.findById(v, R.id.EditTextLatMin);
+ eLatSec = ButterKnife.findById(v, R.id.EditTextLatSec);
+ eLatSub = ButterKnife.findById(v, R.id.EditTextLatSecFrac);
+ tLatSep1 = ButterKnife.findById(v, R.id.LatSeparator1);
+ tLatSep2 = ButterKnife.findById(v, R.id.LatSeparator2);
+ tLatSep3 = ButterKnife.findById(v, R.id.LatSeparator3);
+
+ bLon = ButterKnife.findById(v, R.id.ButtonLon);
+ eLon = ButterKnife.findById(v, R.id.longitude);
+ eLonDeg = ButterKnife.findById(v, R.id.EditTextLonDeg);
+ eLonMin = ButterKnife.findById(v, R.id.EditTextLonMin);
+ eLonSec = ButterKnife.findById(v, R.id.EditTextLonSec);
+ eLonSub = ButterKnife.findById(v, R.id.EditTextLonSecFrac);
+ tLonSep1 = ButterKnife.findById(v, R.id.LonSeparator1);
+ tLonSep2 = ButterKnife.findById(v, R.id.LonSeparator2);
+ tLonSep3 = ButterKnife.findById(v, R.id.LonSeparator3);
eLatDeg.addTextChangedListener(new TextChanged(eLatDeg));
eLatMin.addTextChangedListener(new TextChanged(eLatMin));
@@ -154,9 +156,9 @@ public class CoordinatesInputDialog extends DialogFragment {
bLat.setOnClickListener(new ButtonClickListener());
bLon.setOnClickListener(new ButtonClickListener());
- final Button buttonCurrent = (Button) v.findViewById(R.id.current);
+ final Button buttonCurrent = ButterKnife.findById(v, R.id.current);
buttonCurrent.setOnClickListener(new CurrentListener());
- final Button buttonCache = (Button) v.findViewById(R.id.cache);
+ final Button buttonCache = ButterKnife.findById(v, R.id.cache);
if (cacheCoords != null) {
buttonCache.setOnClickListener(new CacheListener());
@@ -164,7 +166,7 @@ public class CoordinatesInputDialog extends DialogFragment {
buttonCache.setVisibility(View.GONE);
}
- final Button buttonDone = (Button) v.findViewById(R.id.done);
+ final Button buttonDone = ButterKnife.findById(v, R.id.done);
buttonDone.setOnClickListener(new InputDoneListener());
return v;
diff --git a/main/src/cgeo/geocaching/ui/dialog/CustomProgressDialog.java b/main/src/cgeo/geocaching/ui/dialog/CustomProgressDialog.java
index 97c5c29..74f568f 100644
--- a/main/src/cgeo/geocaching/ui/dialog/CustomProgressDialog.java
+++ b/main/src/cgeo/geocaching/ui/dialog/CustomProgressDialog.java
@@ -10,7 +10,6 @@ import android.view.View;
import android.widget.TextView;
import java.lang.reflect.Field;
-import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
/**
@@ -19,31 +18,27 @@ import java.lang.reflect.Method;
*/
public class CustomProgressDialog extends ProgressDialog {
- public CustomProgressDialog(Context context) {
+ public CustomProgressDialog(final Context context) {
super(context, ActivityMixin.getDialogTheme());
}
@Override
- protected void onCreate(Bundle savedInstanceState) {
+ protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
try {
- Method method = TextView.class.getMethod("setVisibility", Integer.TYPE);
+ final Method method = TextView.class.getMethod("setVisibility", Integer.TYPE);
- Field[] fields = this.getClass().getSuperclass().getDeclaredFields();
+ final Field[] fields = this.getClass().getSuperclass().getDeclaredFields();
- for (Field field : fields) {
+ for (final Field field : fields) {
if (field.getName().equalsIgnoreCase("mProgressNumber")) {
field.setAccessible(true);
- TextView textView = (TextView) field.get(this);
+ final TextView textView = (TextView) field.get(this);
method.invoke(textView, View.GONE);
}
}
- } catch (NoSuchMethodException e) {
- Log.e("Failed to invoke the progressDialog method 'setVisibility' and set 'mProgressNumber' to GONE.", e);
- } catch (IllegalAccessException e) {
- Log.e("Failed to invoke the progressDialog method 'setVisibility' and set 'mProgressNumber' to GONE.", e);
- } catch (InvocationTargetException e) {
+ } catch (final ReflectiveOperationException e) {
Log.e("Failed to invoke the progressDialog method 'setVisibility' and set 'mProgressNumber' to GONE.", e);
}
}
diff --git a/main/src/cgeo/geocaching/ui/dialog/DateDialog.java b/main/src/cgeo/geocaching/ui/dialog/DateDialog.java
index fc69f44..1046f81 100644
--- a/main/src/cgeo/geocaching/ui/dialog/DateDialog.java
+++ b/main/src/cgeo/geocaching/ui/dialog/DateDialog.java
@@ -1,5 +1,7 @@
package cgeo.geocaching.ui.dialog;
+import butterknife.ButterKnife;
+
import cgeo.geocaching.R;
import android.os.Bundle;
@@ -19,9 +21,9 @@ public class DateDialog extends DialogFragment {
private Calendar date;
- public static DateDialog getInstance(Calendar date) {
- DateDialog dd = new DateDialog();
- Bundle args = new Bundle();
+ public static DateDialog getInstance(final Calendar date) {
+ final DateDialog dd = new DateDialog();
+ final Bundle args = new Bundle();
args.putSerializable("date", date);
dd.setArguments(args);
return dd;
@@ -31,15 +33,15 @@ public class DateDialog extends DialogFragment {
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setStyle(DialogFragment.STYLE_NO_TITLE, 0);
- Bundle args = getArguments();
+ final Bundle args = getArguments();
date = (Calendar) args.getSerializable("date");
}
@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) {
- View v = inflater.inflate(R.layout.date, container, false);
+ final View v = inflater.inflate(R.layout.date, container, false);
- final DatePicker picker = (DatePicker) v.findViewById(R.id.picker);
+ final DatePicker picker = ButterKnife.findById(v, R.id.picker);
picker.init(date.get(Calendar.YEAR), date.get(Calendar.MONTH), date.get(Calendar.DATE), new DatePickerListener());
return v;
}
@@ -47,7 +49,7 @@ public class DateDialog extends DialogFragment {
private class DatePickerListener implements DatePicker.OnDateChangedListener {
@Override
- public void onDateChanged(DatePicker picker, int year, int month, int day) {
+ public void onDateChanged(final DatePicker picker, final int year, final int month, final int day) {
date.set(year, month, day);
((DateDialogParent) getActivity()).setDate(date);