aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBananeweizen <bananeweizen@gmx.de>2013-05-31 13:02:56 +0200
committerBananeweizen <bananeweizen@gmx.de>2013-05-31 13:02:56 +0200
commit7179671a5f0428cbeab5a687c7866d81cf50cef0 (patch)
tree1a8e8c373da3052e0bb409c46e44dc326f4739ba
parent1bed89fad9e1cc8d7c5435aa17324d9122b69481 (diff)
downloadcgeo-7179671a5f0428cbeab5a687c7866d81cf50cef0.zip
cgeo-7179671a5f0428cbeab5a687c7866d81cf50cef0.tar.gz
cgeo-7179671a5f0428cbeab5a687c7866d81cf50cef0.tar.bz2
#2684: Use view injection instead of view.findById()
-rw-r--r--main/src/cgeo/geocaching/CompassActivity.java40
-rw-r--r--main/src/cgeo/geocaching/ImageSelectActivity.java26
-rw-r--r--main/src/cgeo/geocaching/LogTrackableActivity.java43
-rw-r--r--main/src/cgeo/geocaching/NavigateAnyPointActivity.java61
-rw-r--r--main/src/cgeo/geocaching/SearchActivity.java79
-rw-r--r--main/src/cgeo/geocaching/TrackableActivity.java66
-rw-r--r--main/src/cgeo/geocaching/WaypointPopup.java20
-rw-r--r--main/src/cgeo/geocaching/cgeocaches.java2
-rw-r--r--main/src/cgeo/geocaching/ui/CacheListAdapter.java41
9 files changed, 180 insertions, 198 deletions
diff --git a/main/src/cgeo/geocaching/CompassActivity.java b/main/src/cgeo/geocaching/CompassActivity.java
index 0e850ee..73db653 100644
--- a/main/src/cgeo/geocaching/CompassActivity.java
+++ b/main/src/cgeo/geocaching/CompassActivity.java
@@ -1,5 +1,8 @@
package cgeo.geocaching;
+import butterknife.InjectView;
+import butterknife.Views;
+
import cgeo.geocaching.activity.AbstractActivity;
import cgeo.geocaching.geopoint.Geopoint;
import cgeo.geocaching.geopoint.Units;
@@ -29,6 +32,16 @@ import java.util.List;
public class CompassActivity extends AbstractActivity {
+ @InjectView(R.id.nav_type) protected TextView navType;
+ @InjectView(R.id.nav_accuracy) protected TextView navAccuracy;
+ @InjectView(R.id.nav_satellites) protected TextView navSatellites;
+ @InjectView(R.id.nav_location) protected TextView navLocation;
+ @InjectView(R.id.distance) protected TextView distanceView;
+ @InjectView(R.id.heading) protected TextView headingView;
+ @InjectView(R.id.rose) protected CompassView compassView;
+ @InjectView(R.id.destination) protected TextView destinationTextView;
+ @InjectView(R.id.cacheinfo) protected TextView cacheInfoView;
+
private static final String EXTRAS_COORDS = "coords";
private static final String EXTRAS_NAME = "name";
private static final String EXTRAS_GEOCODE = "geocode";
@@ -40,13 +53,6 @@ public class CompassActivity extends AbstractActivity {
private float cacheHeading = 0;
private String title = null;
private String info = null;
- private TextView navType = null;
- private TextView navAccuracy = null;
- private TextView navSatellites = null;
- private TextView navLocation = null;
- private TextView distanceView = null;
- private TextView headingView = null;
- private CompassView compassView = null;
private boolean hasMagneticFieldSensor;
@Override
@@ -87,8 +93,7 @@ public class CompassActivity extends AbstractActivity {
setDestCoords();
setCacheInfo();
- // get textviews once
- compassView = (CompassView) findViewById(R.id.rose);
+ Views.inject(this);
}
@Override
@@ -214,11 +219,10 @@ public class CompassActivity extends AbstractActivity {
return;
}
- ((TextView) findViewById(R.id.destination)).setText(dstCoords.toString());
+ destinationTextView.setText(dstCoords.toString());
}
private void setCacheInfo() {
- final TextView cacheInfoView = (TextView) findViewById(R.id.cacheinfo);
if (info == null) {
cacheInfoView.setVisibility(View.GONE);
return;
@@ -232,13 +236,6 @@ public class CompassActivity extends AbstractActivity {
return;
}
- if (distanceView == null) {
- distanceView = (TextView) findViewById(R.id.distance);
- }
- if (headingView == null) {
- headingView = (TextView) findViewById(R.id.heading);
- }
-
cacheHeading = geo.getCoords().bearingTo(dstCoords);
distanceView.setText(Units.getDistanceFromKilometers(geo.getCoords().distanceTo(dstCoords)));
headingView.setText(Math.round(cacheHeading) + "°");
@@ -248,13 +245,6 @@ public class CompassActivity extends AbstractActivity {
@Override
public void updateGeoData(final IGeoData geo) {
try {
- if (navType == null || navLocation == null || navAccuracy == null) {
- navType = (TextView) findViewById(R.id.nav_type);
- navAccuracy = (TextView) findViewById(R.id.nav_accuracy);
- navSatellites = (TextView) findViewById(R.id.nav_satellites);
- navLocation = (TextView) findViewById(R.id.nav_location);
- }
-
if (geo.getCoords() != null) {
if (geo.getSatellitesVisible() >= 0) {
navSatellites.setText(res.getString(R.string.loc_sat) + ": " + geo.getSatellitesFixed() + "/" + geo.getSatellitesVisible());
diff --git a/main/src/cgeo/geocaching/ImageSelectActivity.java b/main/src/cgeo/geocaching/ImageSelectActivity.java
index 4329686..f442a51 100644
--- a/main/src/cgeo/geocaching/ImageSelectActivity.java
+++ b/main/src/cgeo/geocaching/ImageSelectActivity.java
@@ -1,5 +1,8 @@
package cgeo.geocaching;
+import butterknife.InjectView;
+import butterknife.Views;
+
import cgeo.geocaching.activity.AbstractActivity;
import cgeo.geocaching.compatibility.Compatibility;
import cgeo.geocaching.utils.ImageHelper;
@@ -30,6 +33,16 @@ import java.util.Date;
import java.util.Locale;
public class ImageSelectActivity extends AbstractActivity {
+
+ @InjectView(R.id.caption) protected EditText captionView;
+ @InjectView(R.id.description) protected EditText descriptionView;
+ @InjectView(R.id.logImageScale) protected Spinner scaleView;
+ @InjectView(R.id.camera) protected Button cameraButton;
+ @InjectView(R.id.stored) protected Button storedButton;
+ @InjectView(R.id.save) protected Button saveButton;
+ @InjectView(R.id.cancel) protected Button clearButton;
+ @InjectView(R.id.image_preview) protected ImageView imagePreview;
+
static final String EXTRAS_CAPTION = "caption";
static final String EXTRAS_DESCRIPTION = "description";
static final String EXTRAS_URI_AS_STRING = "uri";
@@ -43,10 +56,6 @@ public class ImageSelectActivity extends AbstractActivity {
private static final int SELECT_NEW_IMAGE = 1;
private static final int SELECT_STORED_IMAGE = 2;
- private EditText captionView;
- private EditText descriptionView;
- private Spinner scaleView;
-
// Data to be saved while reconfiguring
private String imageCaption;
private String imageDescription;
@@ -56,6 +65,7 @@ public class ImageSelectActivity extends AbstractActivity {
@Override
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState, R.layout.visit_image);
+ Views.inject(this);
scaleChoiceIndex = Settings.getLogImageScale();
imageCaption = "";
@@ -79,7 +89,6 @@ public class ImageSelectActivity extends AbstractActivity {
scaleChoiceIndex = savedInstanceState.getInt(SAVED_STATE_IMAGE_SCALE);
}
- final Button cameraButton = (Button) findViewById(R.id.camera);
cameraButton.setOnClickListener(new View.OnClickListener() {
@Override
@@ -88,7 +97,6 @@ public class ImageSelectActivity extends AbstractActivity {
}
});
- final Button storedButton = (Button) findViewById(R.id.stored);
storedButton.setOnClickListener(new View.OnClickListener() {
@Override
@@ -97,17 +105,14 @@ public class ImageSelectActivity extends AbstractActivity {
}
});
- captionView = (EditText) findViewById(R.id.caption);
if (StringUtils.isNotBlank(imageCaption)) {
captionView.setText(imageCaption);
}
- descriptionView = (EditText) findViewById(R.id.description);
if (StringUtils.isNotBlank(imageDescription)) {
descriptionView.setText(imageDescription);
}
- scaleView = (Spinner) findViewById(R.id.logImageScale);
scaleView.setSelection(scaleChoiceIndex);
scaleView.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
@@ -121,7 +126,6 @@ public class ImageSelectActivity extends AbstractActivity {
}
});
- final Button saveButton = (Button) findViewById(R.id.save);
saveButton.setOnClickListener(new View.OnClickListener() {
@Override
@@ -130,7 +134,6 @@ public class ImageSelectActivity extends AbstractActivity {
}
});
- final Button clearButton = (Button) findViewById(R.id.cancel);
clearButton.setOnClickListener(new View.OnClickListener() {
@Override
@@ -299,7 +302,6 @@ public class ImageSelectActivity extends AbstractActivity {
return;
}
- final ImageView imagePreview = (ImageView) findViewById(R.id.image_preview);
BitmapFactory.Options bitmapOptions = new BitmapFactory.Options();
bitmapOptions.inSampleSize = 8;
final Bitmap bitmap = BitmapFactory.decodeFile(imageUri.getPath(), bitmapOptions);
diff --git a/main/src/cgeo/geocaching/LogTrackableActivity.java b/main/src/cgeo/geocaching/LogTrackableActivity.java
index 7aee6ae..7d8575b 100644
--- a/main/src/cgeo/geocaching/LogTrackableActivity.java
+++ b/main/src/cgeo/geocaching/LogTrackableActivity.java
@@ -1,5 +1,8 @@
package cgeo.geocaching;
+import butterknife.InjectView;
+import butterknife.Views;
+
import cgeo.geocaching.connector.gc.GCParser;
import cgeo.geocaching.connector.gc.Login;
import cgeo.geocaching.enumerations.LogType;
@@ -36,6 +39,14 @@ import java.util.Calendar;
import java.util.List;
public class LogTrackableActivity extends AbstractLoggingActivity implements DateDialog.DateDialogParent {
+
+ @InjectView(R.id.post) protected Button buttonPost;
+ @InjectView(R.id.type) protected Button typeButton;
+ @InjectView(R.id.date) protected Button dateButton;
+ @InjectView(R.id.tracking) protected EditText trackingEditText;
+ @InjectView(R.id.tweet) protected CheckBox tweetCheck;
+ @InjectView(R.id.tweet_box) protected LinearLayout tweetBox;
+
private List<LogType> possibleLogTypes = new ArrayList<LogType>();
private ProgressDialog waitDialog = null;
private String guid = null;
@@ -45,8 +56,6 @@ public class LogTrackableActivity extends AbstractLoggingActivity implements Dat
private Calendar date = Calendar.getInstance();
private LogType typeSelected = LogType.getById(Settings.getTrackableAction());
private int attempts = 0;
- private CheckBox tweetCheck = null;
- private LinearLayout tweetBox = null;
private Trackable trackable;
private Handler showProgressHandler = new Handler() {
@@ -57,6 +66,7 @@ public class LogTrackableActivity extends AbstractLoggingActivity implements Dat
};
private Handler loadDataHandler = new Handler() {
+
@Override
public void handleMessage(final Message msg) {
if (!possibleLogTypes.contains(typeSelected)) {
@@ -78,7 +88,6 @@ public class LogTrackableActivity extends AbstractLoggingActivity implements Dat
gettingViewstate = false; // we're done, user can post log
- final Button buttonPost = (Button) findViewById(R.id.post);
buttonPost.setEnabled(true);
buttonPost.setOnClickListener(new PostListener());
@@ -107,6 +116,7 @@ public class LogTrackableActivity extends AbstractLoggingActivity implements Dat
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState, R.layout.touch);
+ Views.inject(this);
// get parameters
final Bundle extras = getIntent().getExtras();
@@ -115,7 +125,7 @@ public class LogTrackableActivity extends AbstractLoggingActivity implements Dat
guid = extras.getString(Intents.EXTRA_GUID);
if (StringUtils.isNotBlank(extras.getString(Intents.EXTRA_TRACKING_CODE))) {
- ((EditText) findViewById(R.id.tracking)).setText(extras.getString(Intents.EXTRA_TRACKING_CODE));
+ trackingEditText.setText(extras.getString(Intents.EXTRA_TRACKING_CODE));
}
}
@@ -138,11 +148,6 @@ public class LogTrackableActivity extends AbstractLoggingActivity implements Dat
}
@Override
- public void onResume() {
- super.onResume();
- }
-
- @Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
@@ -176,7 +181,6 @@ public class LogTrackableActivity extends AbstractLoggingActivity implements Dat
}
public void init() {
- final Button typeButton = (Button) findViewById(R.id.type);
registerForContextMenu(typeButton);
typeButton.setText(typeSelected.getL10n());
typeButton.setOnClickListener(new View.OnClickListener() {
@@ -186,23 +190,15 @@ public class LogTrackableActivity extends AbstractLoggingActivity implements Dat
}
});
- final Button dateButton = (Button) findViewById(R.id.date);
dateButton.setOnClickListener(new DateListener());
setDate(date);
- if (tweetBox == null) {
- tweetBox = (LinearLayout) findViewById(R.id.tweet_box);
- }
- if (tweetCheck == null) {
- tweetCheck = (CheckBox) findViewById(R.id.tweet);
- }
tweetCheck.setChecked(true);
if (CollectionUtils.isEmpty(possibleLogTypes)) {
possibleLogTypes = Trackable.getPossibleLogTypes();
}
- final Button buttonPost = (Button) findViewById(R.id.post);
if (Login.isEmpty(viewstates)) {
buttonPost.setEnabled(false);
buttonPost.setOnTouchListener(null);
@@ -213,20 +209,17 @@ public class LogTrackableActivity extends AbstractLoggingActivity implements Dat
buttonPost.setEnabled(true);
buttonPost.setOnClickListener(new PostListener());
}
- disableSuggestions((EditText) findViewById(R.id.tracking));
+ disableSuggestions(trackingEditText);
}
@Override
public void setDate(Calendar dateIn) {
date = dateIn;
- final Button dateButton = (Button) findViewById(R.id.date);
dateButton.setText(Formatter.formatShortDateVerbally(date.getTime().getTime()));
}
public void setType(LogType type) {
- final Button typeButton = (Button) findViewById(R.id.type);
-
typeSelected = type;
typeButton.setText(typeSelected.getL10n());
@@ -249,6 +242,8 @@ public class LogTrackableActivity extends AbstractLoggingActivity implements Dat
private class PostListener implements View.OnClickListener {
+ protected EditText logEditText = (EditText) findViewById(R.id.log);
+
@Override
public void onClick(View arg0) {
if (!gettingViewstate) {
@@ -257,8 +252,8 @@ public class LogTrackableActivity extends AbstractLoggingActivity implements Dat
Settings.setTrackableAction(typeSelected.id);
- final String tracking = ((EditText) findViewById(R.id.tracking)).getText().toString();
- final String log = ((EditText) findViewById(R.id.log)).getText().toString();
+ final String tracking = trackingEditText.getText().toString();
+ final String log = logEditText.getText().toString();
new PostLogThread(postLogHandler, tracking, log).start();
} else {
showToast(res.getString(R.string.err_log_load_data_still));
diff --git a/main/src/cgeo/geocaching/NavigateAnyPointActivity.java b/main/src/cgeo/geocaching/NavigateAnyPointActivity.java
index 4e17caa..61ba0e5 100644
--- a/main/src/cgeo/geocaching/NavigateAnyPointActivity.java
+++ b/main/src/cgeo/geocaching/NavigateAnyPointActivity.java
@@ -41,6 +41,27 @@ import java.util.List;
public class NavigateAnyPointActivity extends AbstractActivity {
+ @InjectView(R.id.buttonLatitude) protected Button latButton;
+ @InjectView(R.id.buttonLongitude) protected Button lonButton;
+ @InjectView(R.id.current) protected Button buttonCurrent;
+ @InjectView(R.id.historyList) protected ListView historyListView;
+ @InjectView(R.id.distanceUnit) protected Spinner distanceUnitSelector;
+ @InjectView(R.id.bearing) protected EditText bearingEditText;
+ @InjectView(R.id.distance) protected EditText distanceEditText;
+
+ private boolean changed = false;
+ private List<Destination> historyOfSearchedLocations;
+ private DestinationHistoryAdapter destinationHistoryAdapter;
+ private TextView historyFooter;
+
+ private static final int CONTEXT_MENU_NAVIGATE = 1;
+ private static final int CONTEXT_MENU_DELETE_WAYPOINT = 2;
+ private static final int CONTEXT_MENU_EDIT_WAYPOINT = 3;
+
+ private int contextMenuItemPosition;
+
+ private String distanceUnit = "";
+
protected static class ViewHolder {
@InjectView(R.id.simple_way_point_longitude) protected TextView longitude;
@InjectView(R.id.simple_way_point_latitude) protected TextView latitude;
@@ -96,38 +117,22 @@ public class NavigateAnyPointActivity extends AbstractActivity {
}
}
- private Button latButton = null;
- private Button lonButton = null;
- private boolean changed = false;
- private List<Destination> historyOfSearchedLocations;
- private DestinationHistoryAdapter destinationHistoryAdapter;
- private ListView historyListView;
- private TextView historyFooter;
-
- private static final int CONTEXT_MENU_NAVIGATE = 1;
- private static final int CONTEXT_MENU_DELETE_WAYPOINT = 2;
- private static final int CONTEXT_MENU_EDIT_WAYPOINT = 3;
-
- private int contextMenuItemPosition;
-
- private String distanceUnit = "";
-
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState, R.layout.point);
+ Views.inject(this);
createHistoryView();
-
init();
}
private void createHistoryView() {
- historyListView = (ListView) findViewById(R.id.historyList);
-
- final View pointControls = getLayoutInflater().inflate(
- R.layout.point_controls, null);
+ final View pointControls = getLayoutInflater().inflate(R.layout.point_controls, null);
historyListView.addHeaderView(pointControls, null, false);
+ // inject a second time to also find the dynamically expanded views above
+ Views.inject(this);
+
if (getHistoryOfSearchedLocations().isEmpty()) {
historyListView.addFooterView(getEmptyHistoryFooter(), null, false);
}
@@ -235,9 +240,6 @@ public class NavigateAnyPointActivity extends AbstractActivity {
}
private void init() {
- latButton = (Button) findViewById(R.id.buttonLatitude);
- lonButton = (Button) findViewById(R.id.buttonLongitude);
-
latButton.setOnClickListener(new CoordDialogListener());
lonButton.setOnClickListener(new CoordDialogListener());
@@ -247,19 +249,15 @@ public class NavigateAnyPointActivity extends AbstractActivity {
lonButton.setText(coords.format(GeopointFormatter.Format.LON_DECMINUTE));
}
- Button buttonCurrent = (Button) findViewById(R.id.current);
buttonCurrent.setOnClickListener(new CurrentListener());
getDestionationHistoryAdapter().notifyDataSetChanged();
- disableSuggestions((EditText) findViewById(R.id.distance));
+ disableSuggestions(distanceEditText);
initializeDistanceUnitSelector();
}
private void initializeDistanceUnitSelector() {
-
- Spinner distanceUnitSelector = (Spinner) findViewById(R.id.distanceUnit);
-
if (StringUtils.isBlank(distanceUnit)) {
if (Settings.isUseMetricUnits()) {
distanceUnitSelector.setSelection(0); // m
@@ -479,10 +477,9 @@ public class NavigateAnyPointActivity extends AbstractActivity {
}
private Geopoint getDestination() {
-
- String bearingText = ((EditText) findViewById(R.id.bearing)).getText().toString();
+ String bearingText = bearingEditText.getText().toString();
// combine distance from EditText and distanceUnit saved from Spinner
- String distanceText = ((EditText) findViewById(R.id.distance)).getText().toString() + distanceUnit;
+ String distanceText = distanceEditText.getText().toString() + distanceUnit;
String latText = latButton.getText().toString();
String lonText = lonButton.getText().toString();
diff --git a/main/src/cgeo/geocaching/SearchActivity.java b/main/src/cgeo/geocaching/SearchActivity.java
index cfd6ea9..946724f 100644
--- a/main/src/cgeo/geocaching/SearchActivity.java
+++ b/main/src/cgeo/geocaching/SearchActivity.java
@@ -1,5 +1,8 @@
package cgeo.geocaching;
+import butterknife.InjectView;
+import butterknife.Views;
+
import cgeo.geocaching.activity.AbstractActivity;
import cgeo.geocaching.connector.ConnectorFactory;
import cgeo.geocaching.connector.IConnector;
@@ -33,8 +36,25 @@ import java.util.Locale;
public class SearchActivity extends AbstractActivity {
- private EditText latEdit = null;
- private EditText lonEdit = null;
+ @InjectView(R.id.buttonLatitude) protected Button buttonLatitude;
+ @InjectView(R.id.buttonLongitude) protected Button buttonLongitude;
+ @InjectView(R.id.search_coordinates) protected Button findByCoords;
+ @InjectView(R.id.search_address) protected Button findByAddress;
+ @InjectView(R.id.geocode) protected AutoCompleteTextView geocodeEdit;
+ @InjectView(R.id.display_geocode) protected Button displayByGeocode;
+ @InjectView(R.id.search_keyword) protected Button findByKeyword;
+ @InjectView(R.id.search_username) protected Button findByUserName;
+ @InjectView(R.id.search_owner) protected Button findByOwner;
+ @InjectView(R.id.trackable) protected AutoCompleteTextView trackable;
+ @InjectView(R.id.display_trackable) protected Button displayTrackable;
+ @InjectView(R.id.latitude) protected EditText latEdit;
+ @InjectView(R.id.longitude) protected EditText lonEdit;
+ @InjectView(R.id.keyword) protected EditText keywordEditText;
+ @InjectView(R.id.address) protected EditText addressEditText;
+ @InjectView(R.id.username) protected EditText userNameEditText;
+ @InjectView(R.id.owner) protected EditText ownerNameEditText;
+ @InjectView(R.id.geocode) protected EditText geocodeEditText;
+ @InjectView(R.id.trackable) protected EditText trackableEditText;
@Override
public void onCreate(Bundle savedInstanceState) {
@@ -63,6 +83,7 @@ public class SearchActivity extends AbstractActivity {
// set title in code, as the activity needs a hard coded title due to the intent filters
setTitle(res.getString(R.string.search));
+ Views.inject(this);
init();
}
@@ -132,10 +153,8 @@ public class SearchActivity extends AbstractActivity {
private void init() {
Settings.getLogin();
- findViewById(R.id.buttonLatitude).setOnClickListener(new FindByCoordsAction());
- findViewById(R.id.buttonLongitude).setOnClickListener(new FindByCoordsAction());
-
- final Button findByCoords = (Button) findViewById(R.id.search_coordinates);
+ buttonLatitude.setOnClickListener(new FindByCoordsAction());
+ buttonLongitude.setOnClickListener(new FindByCoordsAction());
findByCoords.setOnClickListener(new FindByCoordsListener());
EditUtils.setActionListener((EditText) findViewById(R.id.address), new Runnable() {
@@ -145,11 +164,8 @@ public class SearchActivity extends AbstractActivity {
findByAddressFn();
}
});
-
- final Button findByAddress = (Button) findViewById(R.id.search_address);
findByAddress.setOnClickListener(new FindByAddressListener());
- final AutoCompleteTextView geocodeEdit = (AutoCompleteTextView) findViewById(R.id.geocode);
EditUtils.setActionListener(geocodeEdit, new Runnable() {
@Override
@@ -158,8 +174,6 @@ public class SearchActivity extends AbstractActivity {
}
});
addHistoryEntries(geocodeEdit, cgData.getRecentGeocodesForSearch());
-
- final Button displayByGeocode = (Button) findViewById(R.id.display_geocode);
displayByGeocode.setOnClickListener(new FindByGeocodeListener());
EditUtils.setActionListener((EditText) findViewById(R.id.keyword), new Runnable() {
@@ -169,8 +183,6 @@ public class SearchActivity extends AbstractActivity {
findByKeywordFn();
}
});
-
- final Button findByKeyword = (Button) findViewById(R.id.search_keyword);
findByKeyword.setOnClickListener(new FindByKeywordListener());
EditUtils.setActionListener((EditText) findViewById(R.id.username), new Runnable() {
@@ -180,8 +192,6 @@ public class SearchActivity extends AbstractActivity {
findByUsernameFn();
}
});
-
- final Button findByUserName = (Button) findViewById(R.id.search_username);
findByUserName.setOnClickListener(new FindByUsernameListener());
EditUtils.setActionListener((EditText) findViewById(R.id.owner), new Runnable() {
@@ -191,8 +201,6 @@ public class SearchActivity extends AbstractActivity {
findByOwnerFn();
}
});
-
- final Button findByOwner = (Button) findViewById(R.id.search_owner);
findByOwner.setOnClickListener(new OnClickListener() {
@Override
@@ -201,7 +209,6 @@ public class SearchActivity extends AbstractActivity {
}
});
- AutoCompleteTextView trackable = (AutoCompleteTextView) findViewById(R.id.trackable);
EditUtils.setActionListener(trackable, new Runnable() {
@Override
@@ -210,10 +217,7 @@ public class SearchActivity extends AbstractActivity {
}
});
addHistoryEntries(trackable, cgData.getTrackableCodes());
-
disableSuggestions(trackable);
-
- final Button displayTrackable = (Button) findViewById(R.id.display_trackable);
displayTrackable.setOnClickListener(new FindTrackableListener());
}
@@ -228,13 +232,6 @@ public class SearchActivity extends AbstractActivity {
@Override
public void updateGeoData(final IGeoData geo) {
try {
- if (latEdit == null) {
- latEdit = (EditText) findViewById(R.id.latitude);
- }
- if (lonEdit == null) {
- lonEdit = (EditText) findViewById(R.id.longitude);
- }
-
if (geo.getCoords() != null) {
if (latEdit != null) {
latEdit.setHint(geo.getCoords().format(GeopointFormatter.Format.LAT_DECMINUTE_RAW));
@@ -258,8 +255,8 @@ public class SearchActivity extends AbstractActivity {
coordsDialog.setOnCoordinateUpdate(new CoordinatesInputDialog.CoordinateUpdate() {
@Override
public void update(Geopoint gp) {
- ((Button) findViewById(R.id.buttonLatitude)).setText(gp.format(GeopointFormatter.Format.LAT_DECMINUTE));
- ((Button) findViewById(R.id.buttonLongitude)).setText(gp.format(GeopointFormatter.Format.LON_DECMINUTE));
+ buttonLatitude.setText(gp.format(GeopointFormatter.Format.LAT_DECMINUTE));
+ buttonLongitude.setText(gp.format(GeopointFormatter.Format.LON_DECMINUTE));
}
});
coordsDialog.show();
@@ -275,16 +272,14 @@ public class SearchActivity extends AbstractActivity {
}
private void findByCoordsFn() {
- final Button latView = (Button) findViewById(R.id.buttonLatitude);
- final Button lonView = (Button) findViewById(R.id.buttonLongitude);
- final String latText = latView.getText().toString();
- final String lonText = lonView.getText().toString();
+ final String latText = buttonLatitude.getText().toString();
+ final String lonText = buttonLongitude.getText().toString();
if (StringUtils.isEmpty(latText) || StringUtils.isEmpty(lonText)) {
final IGeoData geo = app.currentGeo();
if (geo.getCoords() != null) {
- latView.setText(geo.getCoords().format(GeopointFormatter.Format.LAT_DECMINUTE));
- lonView.setText(geo.getCoords().format(GeopointFormatter.Format.LON_DECMINUTE));
+ buttonLatitude.setText(geo.getCoords().format(GeopointFormatter.Format.LAT_DECMINUTE));
+ buttonLongitude.setText(geo.getCoords().format(GeopointFormatter.Format.LON_DECMINUTE));
}
} else {
try {
@@ -305,7 +300,7 @@ public class SearchActivity extends AbstractActivity {
private void findByKeywordFn() {
// find caches by coordinates
- String keyText = ((EditText) findViewById(R.id.keyword)).getText().toString();
+ String keyText = keywordEditText.getText().toString();
if (StringUtils.isBlank(keyText)) {
helpDialog(res.getString(R.string.warn_search_help_title), res.getString(R.string.warn_search_help_keyword));
@@ -323,7 +318,7 @@ public class SearchActivity extends AbstractActivity {
}
private void findByAddressFn() {
- final String addText = ((EditText) findViewById(R.id.address)).getText().toString();
+ final String addText = addressEditText.getText().toString();
if (StringUtils.isBlank(addText)) {
helpDialog(res.getString(R.string.warn_search_help_title), res.getString(R.string.warn_search_help_address));
@@ -344,7 +339,7 @@ public class SearchActivity extends AbstractActivity {
}
public void findByUsernameFn() {
- final String usernameText = ((EditText) findViewById(R.id.username)).getText().toString();
+ final String usernameText = userNameEditText.getText().toString();
if (StringUtils.isBlank(usernameText)) {
helpDialog(res.getString(R.string.warn_search_help_title), res.getString(R.string.warn_search_help_user));
@@ -355,7 +350,7 @@ public class SearchActivity extends AbstractActivity {
}
private void findByOwnerFn() {
- findByOwnerFn(((EditText) findViewById(R.id.owner)).getText().toString());
+ findByOwnerFn(ownerNameEditText.getText().toString());
}
private void findByOwnerFn(String userName) {
@@ -378,7 +373,7 @@ public class SearchActivity extends AbstractActivity {
}
private void findByGeocodeFn() {
- final String geocodeText = ((EditText) findViewById(R.id.geocode)).getText().toString();
+ final String geocodeText = geocodeEditText.getText().toString();
if (StringUtils.isBlank(geocodeText) || geocodeText.equalsIgnoreCase("GC")) {
helpDialog(res.getString(R.string.warn_search_help_title), res.getString(R.string.warn_search_help_gccode));
@@ -397,7 +392,7 @@ public class SearchActivity extends AbstractActivity {
}
private void findTrackableFn() {
- final String trackableText = ((EditText) findViewById(R.id.trackable)).getText().toString();
+ final String trackableText = trackableEditText.getText().toString();
if (StringUtils.isBlank(trackableText) || trackableText.equalsIgnoreCase("TB")) {
helpDialog(res.getString(R.string.warn_search_help_title), res.getString(R.string.warn_search_help_tb));
diff --git a/main/src/cgeo/geocaching/TrackableActivity.java b/main/src/cgeo/geocaching/TrackableActivity.java
index 55d693e..80ffc09 100644
--- a/main/src/cgeo/geocaching/TrackableActivity.java
+++ b/main/src/cgeo/geocaching/TrackableActivity.java
@@ -1,5 +1,8 @@
package cgeo.geocaching;
+import butterknife.InjectView;
+import butterknife.Views;
+
import cgeo.geocaching.activity.AbstractActivity;
import cgeo.geocaching.activity.AbstractViewPagerActivity;
import cgeo.geocaching.connector.gc.GCParser;
@@ -384,24 +387,18 @@ public class TrackableActivity extends AbstractViewPagerActivity<TrackableActivi
public class LogsViewCreator extends AbstractCachingPageViewCreator<ListView> {
- private class LogViewHolder {
-
- private final TextView added;
- private final TextView type;
- private final TextView author;
- private final TextView location;
- private final TextView text;
- private final TextView images;
- private final ImageView marker;
+ protected class LogViewHolder {
+ @InjectView(R.id.added) protected TextView added ;
+ @InjectView(R.id.type) protected TextView type;
+ @InjectView(R.id.author) protected TextView author;
+ @InjectView(R.id.location) protected TextView location;
+ @InjectView(R.id.log) protected TextView text;
+ @InjectView(R.id.log_images) protected TextView images;
+ @InjectView(R.id.log_mark) protected ImageView marker;
public LogViewHolder(View rowView) {
- added = ((TextView) rowView.findViewById(R.id.added));
- type = ((TextView) rowView.findViewById(R.id.type));
- author = ((TextView) rowView.findViewById(R.id.author));
- location = ((TextView) rowView.findViewById(R.id.location));
- text = (TextView) rowView.findViewById(R.id.log);
- images = (TextView) rowView.findViewById(R.id.log_images);
- marker = (ImageView) rowView.findViewById(R.id.log_mark);
+ Views.inject(this, rowView);
+ rowView.setTag(this);
}
}
@@ -420,7 +417,6 @@ public class TrackableActivity extends AbstractViewPagerActivity<TrackableActivi
LogViewHolder holder = (LogViewHolder) rowView.getTag();
if (null == holder) {
holder = new LogViewHolder(rowView);
- rowView.setTag(holder);
}
final LogEntry log = getItem(position);
@@ -498,10 +494,20 @@ public class TrackableActivity extends AbstractViewPagerActivity<TrackableActivi
public class DetailsViewCreator extends AbstractCachingPageViewCreator<ScrollView> {
+ @InjectView(R.id.goal_box) protected View goalBox;
+ @InjectView(R.id.goal) protected TextView goalTextView;
+ @InjectView(R.id.details_box) protected View detailsBox;
+ @InjectView(R.id.details) protected TextView detailsTextView;
+ @InjectView(R.id.image_box) protected View imageBox;
+ @InjectView(R.id.details_list) protected LinearLayout detailsList;
+ @InjectView(R.id.image) protected LinearLayout imageView;
+
@Override
public ScrollView getDispatchedView() {
view = (ScrollView) getLayoutInflater().inflate(R.layout.trackable_details_view, null);
- final CacheDetailsCreator details = new CacheDetailsCreator(TrackableActivity.this, (LinearLayout) view.findViewById(R.id.details_list));
+ Views.inject(this, view);
+
+ final CacheDetailsCreator details = new CacheDetailsCreator(TrackableActivity.this, detailsList);
// action bar icon
if (StringUtils.isNotBlank(trackable.getIconUrl())) {
@@ -595,27 +601,23 @@ public class TrackableActivity extends AbstractViewPagerActivity<TrackableActivi
// trackable goal
if (StringUtils.isNotBlank(trackable.getGoal())) {
- view.findViewById(R.id.goal_box).setVisibility(View.VISIBLE);
- TextView descView = (TextView) view.findViewById(R.id.goal);
- descView.setVisibility(View.VISIBLE);
- descView.setText(Html.fromHtml(trackable.getGoal(), new HtmlImage(geocode, true, 0, false), null), TextView.BufferType.SPANNABLE);
- descView.setMovementMethod(AnchorAwareLinkMovementMethod.getInstance());
+ goalBox.setVisibility(View.VISIBLE);
+ goalTextView.setVisibility(View.VISIBLE);
+ goalTextView.setText(Html.fromHtml(trackable.getGoal(), new HtmlImage(geocode, true, 0, false), null), TextView.BufferType.SPANNABLE);
+ goalTextView.setMovementMethod(AnchorAwareLinkMovementMethod.getInstance());
}
// trackable details
if (StringUtils.isNotBlank(trackable.getDetails())) {
- view.findViewById(R.id.details_box).setVisibility(View.VISIBLE);
- TextView descView = (TextView) view.findViewById(R.id.details);
- descView.setVisibility(View.VISIBLE);
- descView.setText(Html.fromHtml(trackable.getDetails(), new HtmlImage(geocode, true, 0, false), new UnknownTagsHandler()), TextView.BufferType.SPANNABLE);
- descView.setMovementMethod(AnchorAwareLinkMovementMethod.getInstance());
+ detailsBox.setVisibility(View.VISIBLE);
+ detailsTextView.setVisibility(View.VISIBLE);
+ detailsTextView.setText(Html.fromHtml(trackable.getDetails(), new HtmlImage(geocode, true, 0, false), new UnknownTagsHandler()), TextView.BufferType.SPANNABLE);
+ detailsTextView.setMovementMethod(AnchorAwareLinkMovementMethod.getInstance());
}
// trackable image
if (StringUtils.isNotBlank(trackable.getImage())) {
- view.findViewById(R.id.image_box).setVisibility(View.VISIBLE);
- LinearLayout imgView = (LinearLayout) view.findViewById(R.id.image);
-
+ imageBox.setVisibility(View.VISIBLE);
final ImageView trackableImage = (ImageView) inflater.inflate(R.layout.trackable_image, null);
trackableImage.setImageResource(R.drawable.image_not_loaded);
@@ -656,7 +658,7 @@ public class TrackableActivity extends AbstractViewPagerActivity<TrackableActivi
}
}.start();
- imgView.addView(trackableImage);
+ imageView.addView(trackableImage);
}
return view;
}
diff --git a/main/src/cgeo/geocaching/WaypointPopup.java b/main/src/cgeo/geocaching/WaypointPopup.java
index ad1d981..b77fc0c 100644
--- a/main/src/cgeo/geocaching/WaypointPopup.java
+++ b/main/src/cgeo/geocaching/WaypointPopup.java
@@ -1,5 +1,8 @@
package cgeo.geocaching;
+import butterknife.InjectView;
+import butterknife.Views;
+
import cgeo.geocaching.apps.cache.navi.NavigationAppFactory;
import cgeo.geocaching.geopoint.Geopoint;
import cgeo.geocaching.geopoint.Units;
@@ -18,6 +21,11 @@ import android.widget.LinearLayout;
import android.widget.TextView;
public class WaypointPopup extends AbstractPopupActivity {
+ @InjectView(R.id.actionbar_title) protected TextView actionBarTitle;
+ @InjectView(R.id.waypoint_details_list) protected LinearLayout waypointDetailsLayout;
+ @InjectView(R.id.edit) protected Button buttonEdit;
+ @InjectView(R.id.details_list) protected LinearLayout cacheDetailsLayout;
+
private int waypointId = 0;
private Waypoint waypoint = null;
private TextView waypointDistance = null;
@@ -29,6 +37,7 @@ public class WaypointPopup extends AbstractPopupActivity {
@Override
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
+ Views.inject(this);
// get parameters
final Bundle extras = getIntent().getExtras();
if (extras != null) {
@@ -55,11 +64,9 @@ public class WaypointPopup extends AbstractPopupActivity {
setTitle(waypoint.getGeocode());
}
- // actionbar icon
- ((TextView) findViewById(R.id.actionbar_title)).setCompoundDrawablesWithIntrinsicBounds(getResources().getDrawable(waypoint.getWaypointType().markerId), null, null, null);
+ actionBarTitle.setCompoundDrawablesWithIntrinsicBounds(getResources().getDrawable(waypoint.getWaypointType().markerId), null, null, null);
- //Start filling waypoint details
- details = new CacheDetailsCreator(this, (LinearLayout) findViewById(R.id.waypoint_details_list));
+ details = new CacheDetailsCreator(this, waypointDetailsLayout);
//Waypoint geocode
details.add(R.string.cache_geocode, waypoint.getPrefix() + waypoint.getGeocode().substring(2));
@@ -67,8 +74,6 @@ public class WaypointPopup extends AbstractPopupActivity {
waypointDistance = details.getValueView();
details.add(R.string.waypoint_note, waypoint.getNote());
- // Edit Button
- final Button buttonEdit = (Button) findViewById(R.id.edit);
buttonEdit.setOnClickListener(new OnClickListener() {
@Override
@@ -78,8 +83,7 @@ public class WaypointPopup extends AbstractPopupActivity {
}
});
- //Start filling cache details
- details = new CacheDetailsCreator(this, (LinearLayout) findViewById(R.id.details_list));
+ details = new CacheDetailsCreator(this, cacheDetailsLayout);
details.add(R.string.cache_name, cache.getName());
addCacheDetails();
diff --git a/main/src/cgeo/geocaching/cgeocaches.java b/main/src/cgeo/geocaching/cgeocaches.java
index a7a8f7e..6dad510 100644
--- a/main/src/cgeo/geocaching/cgeocaches.java
+++ b/main/src/cgeo/geocaching/cgeocaches.java
@@ -427,7 +427,7 @@ public class cgeocaches extends AbstractListActivity implements FilteredActivity
}
}
- // Add the list selection in code. This way we can leave the XML layout the same as for other activities.
+ // Add the list selection in code. This way we can leave the XML layout of the action bar the same as for other activities.
final View titleBar = findViewById(R.id.actionbar_title);
titleBar.setClickable(true);
titleBar.setOnClickListener(new View.OnClickListener() {
diff --git a/main/src/cgeo/geocaching/ui/CacheListAdapter.java b/main/src/cgeo/geocaching/ui/CacheListAdapter.java
index 7f4ceaa..c27c387 100644
--- a/main/src/cgeo/geocaching/ui/CacheListAdapter.java
+++ b/main/src/cgeo/geocaching/ui/CacheListAdapter.java
@@ -1,5 +1,8 @@
package cgeo.geocaching.ui;
+import butterknife.InjectView;
+import butterknife.Views;
+
import cgeo.geocaching.CacheDetailActivity;
import cgeo.geocaching.Geocache;
import cgeo.geocaching.IGeoData;
@@ -91,16 +94,21 @@ public class CacheListAdapter extends ArrayAdapter<Geocache> {
* view holder for the cache list adapter
*
*/
- private static class ViewHolder {
- CheckBox checkbox;
- ImageView logStatusMark;
- TextView text;
- TextView favorite;
- TextView info;
- ImageView inventory;
- DistanceView distance;
- CompassMiniView direction;
- ImageView dirImg;
+ protected static class ViewHolder {
+ @InjectView(R.id.checkbox) protected CheckBox checkbox;
+ @InjectView(R.id.log_status_mark) protected ImageView logStatusMark;
+ @InjectView(R.id.text) protected TextView text;
+ @InjectView(R.id.distance) protected DistanceView distance;
+ @InjectView(R.id.favorite) protected TextView favorite;
+ @InjectView(R.id.info) protected TextView info;
+ @InjectView(R.id.inventory) protected ImageView inventory;
+ @InjectView(R.id.direction) protected CompassMiniView direction;
+ @InjectView(R.id.dirimg) protected ImageView dirImg;
+
+ public ViewHolder(View view) {
+ Views.inject(this, view);
+ view.setTag(this);
+ }
}
public CacheListAdapter(final Activity activity, final List<Geocache> list, CacheListType cacheListType) {
@@ -350,18 +358,7 @@ public class CacheListAdapter extends ArrayAdapter<Geocache> {
if (v == null) {
v = inflater.inflate(R.layout.caches_item, null);
- holder = new ViewHolder();
- holder.checkbox = (CheckBox) v.findViewById(R.id.checkbox);
- holder.logStatusMark = (ImageView) v.findViewById(R.id.log_status_mark);
- holder.text = (TextView) v.findViewById(R.id.text);
- holder.distance = (DistanceView) v.findViewById(R.id.distance);
- holder.direction = (CompassMiniView) v.findViewById(R.id.direction);
- holder.dirImg = (ImageView) v.findViewById(R.id.dirimg);
- holder.inventory = (ImageView) v.findViewById(R.id.inventory);
- holder.favorite = (TextView) v.findViewById(R.id.favorite);
- holder.info = (TextView) v.findViewById(R.id.info);
-
- v.setTag(holder);
+ holder = new ViewHolder(v);
} else {
holder = (ViewHolder) v.getTag();
}