diff options
Diffstat (limited to 'main/src/cgeo/geocaching/ui')
8 files changed, 62 insertions, 58 deletions
diff --git a/main/src/cgeo/geocaching/ui/AbstractCachingPageViewCreator.java b/main/src/cgeo/geocaching/ui/AbstractCachingPageViewCreator.java index 71cd3b4..306c686 100644 --- a/main/src/cgeo/geocaching/ui/AbstractCachingPageViewCreator.java +++ b/main/src/cgeo/geocaching/ui/AbstractCachingPageViewCreator.java @@ -3,11 +3,13 @@ package cgeo.geocaching.ui; import cgeo.geocaching.activity.AbstractViewPagerActivity.PageViewCreator; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; + import org.eclipse.jdt.annotation.NonNull; import org.eclipse.jdt.annotation.Nullable; import android.os.Bundle; import android.view.View; +import android.view.ViewGroup; /** * View creator which destroys the created view on every {@link #notifyDataSetChanged()}. @@ -24,9 +26,9 @@ public abstract class AbstractCachingPageViewCreator<ViewClass extends View> imp } @Override - public final View getView() { + public final View getView(final ViewGroup parentView) { if (view == null) { - view = getDispatchedView(); + view = getDispatchedView(parentView); } return view; @@ -34,7 +36,7 @@ public abstract class AbstractCachingPageViewCreator<ViewClass extends View> imp @Override @SuppressFBWarnings("USM_USELESS_ABSTRACT_METHOD") - public abstract ViewClass getDispatchedView(); + public abstract ViewClass getDispatchedView(final ViewGroup parentView); /** * Gets the state of the view but returns an empty state if not overridden @@ -51,6 +53,6 @@ public abstract class AbstractCachingPageViewCreator<ViewClass extends View> imp * Restores the state of the view but just returns if not overridden. */ @Override - public void setViewState(@NonNull Bundle state) { + public void setViewState(@NonNull final Bundle state) { } } diff --git a/main/src/cgeo/geocaching/ui/AddressListAdapter.java b/main/src/cgeo/geocaching/ui/AddressListAdapter.java index 8134235..5d16df5 100644 --- a/main/src/cgeo/geocaching/ui/AddressListAdapter.java +++ b/main/src/cgeo/geocaching/ui/AddressListAdapter.java @@ -29,7 +29,7 @@ public class AddressListAdapter extends ArrayAdapter<Address> { @InjectView(R.id.label) protected TextView label; @InjectView(R.id.distance) protected TextView distance; - public ViewHolder(View view) { + public ViewHolder(final View view) { super(view); } } @@ -49,7 +49,7 @@ public class AddressListAdapter extends ArrayAdapter<Address> { // holder pattern implementation final ViewHolder holder; if (view == null) { - view = inflater.inflate(R.layout.addresslist_item, null); + view = inflater.inflate(R.layout.addresslist_item, parent, false); holder = new ViewHolder(view); } else { holder = (ViewHolder) view.getTag(); diff --git a/main/src/cgeo/geocaching/ui/CacheDetailsCreator.java b/main/src/cgeo/geocaching/ui/CacheDetailsCreator.java index 5d8ebef..6d44554 100644 --- a/main/src/cgeo/geocaching/ui/CacheDetailsCreator.java +++ b/main/src/cgeo/geocaching/ui/CacheDetailsCreator.java @@ -45,7 +45,7 @@ public final class CacheDetailsCreator { * @return the view containing the displayed string (i.e. the right side one from the pair of "label": "value") */ public TextView add(final int nameId, final CharSequence value) { - final RelativeLayout layout = (RelativeLayout) activity.getLayoutInflater().inflate(R.layout.cache_information_item, null); + final RelativeLayout layout = (RelativeLayout) activity.getLayoutInflater().inflate(R.layout.cache_information_item, parentView, false); final TextView nameView = (TextView) layout.findViewById(R.id.name); nameView.setText(res.getString(nameId)); lastValueView = (TextView) layout.findViewById(R.id.value); @@ -63,7 +63,7 @@ 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); + final RelativeLayout layout = (RelativeLayout) activity.getLayoutInflater().inflate(R.layout.cache_information_item, parentView, 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); @@ -81,7 +81,7 @@ public final class CacheDetailsCreator { final LayoutInflater inflater = LayoutInflater.from(activity); for (int i = 0; i < max; i++) { - ImageView star = (ImageView) inflater.inflate(R.layout.star_image, null); + final ImageView star = (ImageView) inflater.inflate(R.layout.star_image, starsContainer, false); if (value - i >= 0.75) { star.setImageResource(R.drawable.star_on); } else if (value - i >= 0.25) { @@ -93,7 +93,7 @@ public final class CacheDetailsCreator { } } - public void addCacheState(Geocache cache) { + public void addCacheState(final Geocache cache) { if (cache.isLogOffline() || cache.isArchived() || cache.isDisabled() || cache.isPremiumMembersOnly() || cache.isFound()) { final List<String> states = new ArrayList<String>(5); if (cache.isLogOffline()) { @@ -115,7 +115,7 @@ public final class CacheDetailsCreator { } } - public void addRating(Geocache cache) { + public void addRating(final Geocache cache) { if (cache.getRating() > 0) { final RelativeLayout itemLayout = addStars(R.string.cache_rating, cache.getRating()); if (cache.getVotes() > 0) { @@ -126,19 +126,19 @@ public final class CacheDetailsCreator { } } - public void addSize(Geocache cache) { + public void addSize(final Geocache cache) { if (null != cache.getSize() && cache.showSize()) { add(R.string.cache_size, cache.getSize().getL10n()); } } - public void addDifficulty(Geocache cache) { + public void addDifficulty(final Geocache cache) { if (cache.getDifficulty() > 0) { addStars(R.string.cache_difficulty, cache.getDifficulty()); } } - public void addTerrain(Geocache cache) { + public void addTerrain(final Geocache cache) { if (cache.getTerrain() > 0) { addStars(R.string.cache_terrain, cache.getTerrain(), ConnectorFactory.getConnector(cache).getMaxTerrain()); } @@ -189,7 +189,7 @@ public final class CacheDetailsCreator { add(R.string.cache_distance, text); } - public void addEventDate(@NonNull Geocache cache) { + public void addEventDate(@NonNull final Geocache cache) { if (!cache.isEventCache()) { return; } diff --git a/main/src/cgeo/geocaching/ui/CacheListAdapter.java b/main/src/cgeo/geocaching/ui/CacheListAdapter.java index 3a451a5..2de1140 100644 --- a/main/src/cgeo/geocaching/ui/CacheListAdapter.java +++ b/main/src/cgeo/geocaching/ui/CacheListAdapter.java @@ -63,7 +63,7 @@ public class CacheListAdapter extends ArrayAdapter<Geocache> { private boolean selectMode = false; private IFilter currentFilter = null; private List<Geocache> originalList = null; - private boolean isLiveList = Settings.isLiveList(); + private final boolean isLiveList = Settings.isLiveList(); final private Set<CompassMiniView> compasses = new LinkedHashSet<CompassMiniView>(); final private Set<DistanceView> distances = new LinkedHashSet<DistanceView>(); @@ -110,12 +110,12 @@ public class CacheListAdapter extends ArrayAdapter<Geocache> { @InjectView(R.id.direction) protected CompassMiniView direction; @InjectView(R.id.dirimg) protected ImageView dirImg; - public ViewHolder(View view) { + public ViewHolder(final View view) { super(view); } } - public CacheListAdapter(final Activity activity, final List<Geocache> list, CacheListType cacheListType) { + public CacheListAdapter(final Activity activity, final List<Geocache> list, final CacheListType cacheListType) { super(activity, 0, list); final IGeoData currentGeo = CgeoApplication.getInstance().currentGeo(); if (currentGeo != null) { @@ -133,10 +133,10 @@ public class CacheListAdapter extends ArrayAdapter<Geocache> { gcIconDrawables.put(hashCode, activity.getResources().getDrawable(cacheType.markerId)); // icon with flag for user modified coordinates hashCode = getIconHashCode(cacheType, true); - Drawable[] layers = new Drawable[2]; + final Drawable[] layers = new Drawable[2]; layers[0] = activity.getResources().getDrawable(cacheType.markerId); layers[1] = modifiedCoordinatesMarker; - LayerDrawable ld = new LayerDrawable(layers); + final LayerDrawable ld = new LayerDrawable(layers); ld.setLayerInset(1, layers[0].getIntrinsicWidth() - layers[1].getIntrinsicWidth(), layers[0].getIntrinsicHeight() - layers[1].getIntrinsicHeight(), @@ -184,7 +184,7 @@ public class CacheListAdapter extends ArrayAdapter<Geocache> { return cacheListType == CacheListType.HISTORY; } - public Geocache findCacheByGeocode(String geocode) { + public Geocache findCacheByGeocode(final String geocode) { for (int i = 0; i < getCount(); i++) { if (getItem(i).getGeocode().equalsIgnoreCase(geocode)) { return getItem(i); @@ -240,7 +240,7 @@ public class CacheListAdapter extends ArrayAdapter<Geocache> { public int getCheckedCount() { int checked = 0; - for (Geocache cache : list) { + for (final Geocache cache : list) { if (cache.isStatusChecked()) { checked++; } @@ -268,7 +268,7 @@ public class CacheListAdapter extends ArrayAdapter<Geocache> { } public void invertSelection() { - for (Geocache cache : list) { + for (final Geocache cache : list) { cache.setStatusChecked(!cache.isStatusChecked()); } notifyDataSetChanged(); @@ -369,7 +369,7 @@ public class CacheListAdapter extends ArrayAdapter<Geocache> { final ViewHolder holder; if (v == null) { - v = inflater.inflate(R.layout.cacheslist_item, null); + v = inflater.inflate(R.layout.cacheslist_item, parent, false); holder = new ViewHolder(v); } else { @@ -502,7 +502,7 @@ public class CacheListAdapter extends ArrayAdapter<Geocache> { return v; } - private static Drawable getCacheIcon(Geocache cache) { + private static Drawable getCacheIcon(final Geocache cache) { int hashCode = getIconHashCode(cache.getType(), cache.hasUserModifiedCoords() || cache.hasFinalDefined()); final Drawable drawable = gcIconDrawables.get(hashCode); if (drawable != null) { @@ -525,12 +525,12 @@ public class CacheListAdapter extends ArrayAdapter<Geocache> { private final Geocache cache; - public SelectionCheckBoxListener(Geocache cache) { + public SelectionCheckBoxListener(final Geocache cache) { this.cache = cache; } @Override - public void onClick(View view) { + public void onClick(final View view) { assert view instanceof CheckBox; final boolean checkNow = ((CheckBox) view).isChecked(); cache.setStatusChecked(checkNow); @@ -590,7 +590,7 @@ public class CacheListAdapter extends ArrayAdapter<Geocache> { } @Override - public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { + public boolean onFling(final MotionEvent e1, final MotionEvent e2, final float velocityX, final float velocityY) { try { if (Math.abs(e1.getY() - e2.getY()) > SWIPE_MAX_OFF_PATH) { return false; @@ -616,7 +616,7 @@ public class CacheListAdapter extends ArrayAdapter<Geocache> { } return true; } - } catch (Exception e) { + } catch (final Exception e) { Log.w("CacheListAdapter.FlingGesture.onFling", e); } @@ -630,7 +630,7 @@ public class CacheListAdapter extends ArrayAdapter<Geocache> { public List<Geocache> getCheckedCaches() { final ArrayList<Geocache> result = new ArrayList<Geocache>(); - for (Geocache cache : list) { + for (final Geocache cache : list) { if (cache.isStatusChecked()) { result.add(cache); } diff --git a/main/src/cgeo/geocaching/ui/FileSelectionListAdapter.java b/main/src/cgeo/geocaching/ui/FileSelectionListAdapter.java index c325f50..e07bbc3 100644 --- a/main/src/cgeo/geocaching/ui/FileSelectionListAdapter.java +++ b/main/src/cgeo/geocaching/ui/FileSelectionListAdapter.java @@ -22,7 +22,7 @@ public class FileSelectionListAdapter extends ArrayAdapter<File> { private final IFileSelectionView parentView; private final LayoutInflater inflater; - public FileSelectionListAdapter(IFileSelectionView parentIn, List<File> listIn) { + public FileSelectionListAdapter(final IFileSelectionView parentIn, final List<File> listIn) { super(parentIn.getContext(), 0, listIn); parentView = parentIn; @@ -36,19 +36,19 @@ public class FileSelectionListAdapter extends ArrayAdapter<File> { return null; } - File file = getItem(position); + final File file = getItem(position); View v = rowView; ViewHolder holder; if (v == null) { - v = inflater.inflate(R.layout.mapfile_item, null); + v = inflater.inflate(R.layout.mapfile_item, parent, false); holder = new ViewHolder(v); } else { holder = (ViewHolder) v.getTag(); } - String currentFile = parentView.getCurrentFile(); + final String currentFile = parentView.getCurrentFile(); if (currentFile != null && file.equals(new File(currentFile))) { holder.filename.setTypeface(holder.filename.getTypeface(), Typeface.BOLD); } else { @@ -67,13 +67,13 @@ public class FileSelectionListAdapter extends ArrayAdapter<File> { private class TouchListener implements View.OnClickListener { private File file = null; - public TouchListener(File fileIn) { + public TouchListener(final File fileIn) { file = fileIn; } // tap on item @Override - public void onClick(View view) { + public void onClick(final View view) { parentView.setCurrentFile(file.toString()); parentView.close(); } @@ -83,7 +83,7 @@ public class FileSelectionListAdapter extends ArrayAdapter<File> { @InjectView(R.id.mapfilepath) protected TextView filepath; @InjectView(R.id.mapfilename) protected TextView filename; - public ViewHolder(View view) { + public ViewHolder(final View view) { super(view); } } diff --git a/main/src/cgeo/geocaching/ui/GPXListAdapter.java b/main/src/cgeo/geocaching/ui/GPXListAdapter.java index ae18ab4..5db103b 100644 --- a/main/src/cgeo/geocaching/ui/GPXListAdapter.java +++ b/main/src/cgeo/geocaching/ui/GPXListAdapter.java @@ -28,12 +28,12 @@ public class GPXListAdapter extends ArrayAdapter<File> { @InjectView(R.id.filepath) protected TextView filepath; @InjectView(R.id.filename) protected TextView filename; - public ViewHolder(View view) { + public ViewHolder(final View view) { super(view); } } - public GPXListAdapter(GpxFileListActivity parentIn, List<File> listIn) { + public GPXListAdapter(final GpxFileListActivity parentIn, final List<File> listIn) { super(parentIn, 0, listIn); activity = parentIn; @@ -53,7 +53,7 @@ public class GPXListAdapter extends ArrayAdapter<File> { final ViewHolder holder; if (view == null) { - view = inflater.inflate(R.layout.gpx_item, null); + view = inflater.inflate(R.layout.gpx_item, parent, false); holder = new ViewHolder(view); } else { holder = (ViewHolder) view.getTag(); @@ -62,7 +62,7 @@ public class GPXListAdapter extends ArrayAdapter<File> { view.setOnClickListener(new View.OnClickListener() { @Override - public void onClick(View v) { + public void onClick(final View v) { (new GPXImporter(activity, activity.getListId(), null)).importGPX(file); } }); @@ -73,10 +73,10 @@ public class GPXListAdapter extends ArrayAdapter<File> { view.setOnLongClickListener(new View.OnLongClickListener() { @Override - public boolean onLongClick(View v) { + public boolean onLongClick(final View v) { Dialogs.confirmYesNo(activity, R.string.gpx_import_delete_title, activity.getString(R.string.gpx_import_delete_message, file.getName()), new DialogInterface.OnClickListener() { @Override - public void onClick(DialogInterface dialog, int id) { + public void onClick(final DialogInterface dialog, final int id) { FileUtils.deleteIgnoringFailure(file); GPXListAdapter.this.remove(file); } diff --git a/main/src/cgeo/geocaching/ui/ImagesList.java b/main/src/cgeo/geocaching/ui/ImagesList.java index 5727971..bf53725 100644 --- a/main/src/cgeo/geocaching/ui/ImagesList.java +++ b/main/src/cgeo/geocaching/ui/ImagesList.java @@ -9,6 +9,7 @@ import cgeo.geocaching.utils.Log; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; + import rx.Subscription; import rx.android.observables.AndroidObservable; import rx.functions.Action0; @@ -102,7 +103,7 @@ public class ImagesList { final HtmlImage imgGetter = new HtmlImage(geocode, true, offline ? StoredList.STANDARD_LIST_ID : StoredList.TEMPORARY_LIST_ID, false); for (final Image img : images) { - final LinearLayout rowView = (LinearLayout) inflater.inflate(R.layout.cache_image_item, null); + final LinearLayout rowView = (LinearLayout) inflater.inflate(R.layout.cache_image_item, imagesView, false); assert(rowView != null); if (StringUtils.isNotBlank(img.getTitle())) { @@ -116,7 +117,7 @@ public class ImagesList { descView.setVisibility(View.VISIBLE); } - final ImageView imageView = (ImageView) inflater.inflate(R.layout.image_item, null); + final ImageView imageView = (ImageView) inflater.inflate(R.layout.image_item, rowView, false); assert(imageView != null); subscriptions.add(AndroidObservable.bindActivity(activity, imgGetter.fetchDrawable(img.getUrl())).subscribe(new Action1<BitmapDrawable>() { @Override @@ -141,7 +142,7 @@ public class ImagesList { imageView.setClickable(true); imageView.setOnClickListener(new View.OnClickListener() { @Override - public void onClick(View arg0) { + public void onClick(final View arg0) { viewImageInStandardApp(img, image); } }); @@ -169,7 +170,7 @@ public class ImagesList { imagesView.removeAllViews(); } - public void onCreateContextMenu(ContextMenu menu, View v) { + public void onCreateContextMenu(final ContextMenu menu, final View v) { assert v instanceof ImageView; activity.getMenuInflater().inflate(R.menu.images_list_context, menu); final Resources res = activity.getResources(); @@ -179,7 +180,7 @@ public class ImagesList { currentImage = images.get(view.getId()); } - public boolean onContextItemSelected(MenuItem item) { + public boolean onContextItemSelected(final MenuItem item) { switch (item.getItemId()) { case R.id.image_open_file: viewImageInStandardApp(currentImage, currentDrawable); @@ -221,7 +222,7 @@ public class ImagesList { intent.setDataAndType(Uri.fromFile(saveToTemporaryJPGFile(image)), "image/jpeg"); } activity.startActivity(intent); - } catch (Exception e) { + } catch (final Exception e) { Log.e("ImagesList.viewImageInStandardApp", e); } } diff --git a/main/src/cgeo/geocaching/ui/logs/LogsViewCreator.java b/main/src/cgeo/geocaching/ui/logs/LogsViewCreator.java index 6590d22..1f6706c 100644 --- a/main/src/cgeo/geocaching/ui/logs/LogsViewCreator.java +++ b/main/src/cgeo/geocaching/ui/logs/LogsViewCreator.java @@ -23,6 +23,7 @@ import android.os.AsyncTask; import android.text.Html; import android.text.Spanned; import android.view.View; +import android.view.ViewGroup; import android.widget.ArrayAdapter; import android.widget.ListView; import android.widget.TextView; @@ -34,19 +35,19 @@ public abstract class LogsViewCreator extends AbstractCachingListViewPageViewCre protected final AbstractActivity activity; - public LogsViewCreator(AbstractActivity activity) { + public LogsViewCreator(final AbstractActivity activity) { this.activity = activity; } @Override - public ListView getDispatchedView() { + public ListView getDispatchedView(final ViewGroup parentView) { if (!isValid()) { return null; } final List<LogEntry> logs = getLogs(); - view = (ListView) activity.getLayoutInflater().inflate(R.layout.logs_page, null); + view = (ListView) activity.getLayoutInflater().inflate(R.layout.logs_page, parentView, false); addHeaderView(); view.setAdapter(new ArrayAdapter<LogEntry>(activity, R.layout.logs_item, logs) { @@ -54,7 +55,7 @@ public abstract class LogsViewCreator extends AbstractCachingListViewPageViewCre public View getView(final int position, final View convertView, final android.view.ViewGroup parent) { View rowView = convertView; if (null == rowView) { - rowView = activity.getLayoutInflater().inflate(R.layout.logs_item, null); + rowView = activity.getLayoutInflater().inflate(R.layout.logs_item, parent, false); } LogViewHolder holder = (LogViewHolder) rowView.getTag(); if (null == holder) { @@ -71,7 +72,7 @@ public abstract class LogsViewCreator extends AbstractCachingListViewPageViewCre return view; } - protected void fillViewHolder(final View convertView, LogViewHolder holder, final LogEntry log) { + protected void fillViewHolder(final View convertView, final LogViewHolder holder, final LogEntry log) { if (log.date > 0) { holder.date.setText(Formatter.formatShortDateVerbally(log.date)); holder.date.setVisibility(View.VISIBLE); @@ -108,7 +109,7 @@ public abstract class LogsViewCreator extends AbstractCachingListViewPageViewCre holder.images.setVisibility(View.VISIBLE); holder.images.setOnClickListener(new View.OnClickListener() { @Override - public void onClick(View v) { + public void onClick(final View v) { ImagesActivity.startActivityLogImages(activity, getGeocode(), new ArrayList<Image>(log.getLogImages())); } }); @@ -152,18 +153,18 @@ public abstract class LogsViewCreator extends AbstractCachingListViewPageViewCre final private LogViewHolder holder; final private int position; - public LogImageLoader(LogViewHolder holder) { + public LogImageLoader(final LogViewHolder holder) { this.holder = holder; this.position = holder.getPosition(); } @Override - protected Spanned doInBackground(String... logtext) { + protected Spanned doInBackground(final String... logtext) { return Html.fromHtml(logtext[0], new HtmlImage(getGeocode(), false, StoredList.STANDARD_LIST_ID, false), null); //, TextView.BufferType.SPANNABLE) } @Override - protected void onPostExecute(Spanned result) { + protected void onPostExecute(final Spanned result) { // Ensure that this holder and its view still references the right item before updating the text. if (position == holder.getPosition()) { holder.text.setText(result); |
