diff options
Diffstat (limited to 'main/src/cgeo/geocaching/ui')
11 files changed, 111 insertions, 41 deletions
diff --git a/main/src/cgeo/geocaching/ui/AbstractCachingPageViewCreator.java b/main/src/cgeo/geocaching/ui/AbstractCachingPageViewCreator.java index 306c686..60e8b2d 100644 --- a/main/src/cgeo/geocaching/ui/AbstractCachingPageViewCreator.java +++ b/main/src/cgeo/geocaching/ui/AbstractCachingPageViewCreator.java @@ -14,7 +14,6 @@ import android.view.ViewGroup; /** * View creator which destroys the created view on every {@link #notifyDataSetChanged()}. * - * @param <ViewClass> */ public abstract class AbstractCachingPageViewCreator<ViewClass extends View> implements PageViewCreator { diff --git a/main/src/cgeo/geocaching/ui/AbstractMenuActionProvider.java b/main/src/cgeo/geocaching/ui/AbstractMenuActionProvider.java new file mode 100644 index 0000000..fbea675 --- /dev/null +++ b/main/src/cgeo/geocaching/ui/AbstractMenuActionProvider.java @@ -0,0 +1,24 @@ +package cgeo.geocaching.ui; + +import android.content.Context; +import android.support.v4.view.ActionProvider; +import android.view.View; + +public abstract class AbstractMenuActionProvider extends ActionProvider { + + public AbstractMenuActionProvider(final Context context) { + super(context); + } + + @Override + public boolean hasSubMenu() { + return true; + } + + @Override + public View onCreateActionView() { + // must return null, otherwise the menu will not work + return null; + } + +} diff --git a/main/src/cgeo/geocaching/ui/CacheListAdapter.java b/main/src/cgeo/geocaching/ui/CacheListAdapter.java index ebbe23f..d9daa1d 100644 --- a/main/src/cgeo/geocaching/ui/CacheListAdapter.java +++ b/main/src/cgeo/geocaching/ui/CacheListAdapter.java @@ -18,7 +18,7 @@ import cgeo.geocaching.sorting.EventDateComparator; import cgeo.geocaching.sorting.InverseComparator; import cgeo.geocaching.sorting.VisitComparator; import cgeo.geocaching.utils.AngleUtils; -import cgeo.geocaching.utils.DateUtils; +import cgeo.geocaching.utils.CalendarUtils; import cgeo.geocaching.utils.Formatter; import cgeo.geocaching.utils.Log; @@ -112,7 +112,7 @@ public class CacheListAdapter extends ArrayAdapter<Geocache> { @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.inventory) protected TextView inventory; @InjectView(R.id.direction) protected CompassMiniView direction; @InjectView(R.id.dirimg) protected ImageView dirImg; public Geocache cache = null; @@ -160,7 +160,6 @@ public class CacheListAdapter extends ArrayAdapter<Geocache> { /** * change the sort order * - * @param comparator */ public void setComparator(final CacheComparator comparator) { cacheComparator = comparator; @@ -415,7 +414,7 @@ public class CacheListAdapter extends ArrayAdapter<Geocache> { } Spannable spannable = null; - if (cache.isDisabled() || cache.isArchived() || DateUtils.isPastEvent(cache)) { // strike + if (cache.isDisabled() || cache.isArchived() || CalendarUtils.isPastEvent(cache)) { // strike spannable = Spannable.Factory.getInstance().newSpannable(cache.getName()); spannable.setSpan(new StrikethroughSpan(), 0, spannable.toString().length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } @@ -434,7 +433,9 @@ public class CacheListAdapter extends ArrayAdapter<Geocache> { } holder.text.setCompoundDrawablesWithIntrinsicBounds(getCacheIcon(cache), null, null, null); - if (cache.getInventoryItems() > 0) { + final int inventorySize = cache.getInventoryItems(); + if (inventorySize > 0) { + holder.inventory.setText(Integer.toString(inventorySize)); holder.inventory.setVisibility(View.VISIBLE); } else { holder.inventory.setVisibility(View.GONE); diff --git a/main/src/cgeo/geocaching/ui/CompassMiniView.java b/main/src/cgeo/geocaching/ui/CompassMiniView.java index a811fa0..d50d806 100644 --- a/main/src/cgeo/geocaching/ui/CompassMiniView.java +++ b/main/src/cgeo/geocaching/ui/CompassMiniView.java @@ -50,18 +50,19 @@ final public class CompassMiniView extends View { private static final float MINIMUM_ROTATION_DEGREES_FOR_REPAINT = 5; private float azimuthRelative; - public CompassMiniView(Context context) { + public CompassMiniView(final Context context) { super(context); } - public CompassMiniView(Context context, AttributeSet attrs) { + public CompassMiniView(final Context context, final AttributeSet attrs) { super(context, attrs); } @Override public void onAttachedToWindow() { if (instances++ == 0) { - compassArrow = BitmapFactory.decodeResource(getResources(), Settings.isLightSkin() ? R.drawable.compass_arrow_mini_black : R.drawable.compass_arrow_mini_white); + final int drawable = isInEditMode() || !Settings.isLightSkin() ? R.drawable.compass_arrow_mini_white : R.drawable.compass_arrow_mini_black; + compassArrow = BitmapFactory.decodeResource(getResources(), drawable); compassArrowWidth = compassArrow.getWidth(); compassArrowHeight = compassArrow.getWidth(); } @@ -79,12 +80,12 @@ final public class CompassMiniView extends View { targetCoords = point; } - public void updateAzimuth(float azimuth) { + public void updateAzimuth(final float azimuth) { this.azimuth = azimuth; updateDirection(); } - public void updateHeading(float heading) { + public void updateHeading(final float heading) { this.heading = heading; updateDirection(); } @@ -106,7 +107,7 @@ final public class CompassMiniView extends View { azimuthRelative = AngleUtils.normalize(azimuth - heading); // avoid updates on very small changes, which are not visible to the user - float change = Math.abs(azimuthRelative - lastDrawnAzimuth); + final float change = Math.abs(azimuthRelative - lastDrawnAzimuth); if (change < MINIMUM_ROTATION_DEGREES_FOR_REPAINT) { return; } @@ -119,7 +120,7 @@ final public class CompassMiniView extends View { } @Override - protected void onDraw(Canvas canvas) { + protected void onDraw(final Canvas canvas) { super.onDraw(canvas); lastDrawnAzimuth = azimuthRelative; @@ -137,11 +138,11 @@ final public class CompassMiniView 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); @@ -158,7 +159,7 @@ final public class CompassMiniView extends View { return result; } - private int measureHeight(int measureSpec) { + private int measureHeight(final int measureSpec) { final int specMode = MeasureSpec.getMode(measureSpec); final int specSize = MeasureSpec.getSize(measureSpec); diff --git a/main/src/cgeo/geocaching/ui/NavigationActionProvider.java b/main/src/cgeo/geocaching/ui/NavigationActionProvider.java index 5840e27..ed4455d 100644 --- a/main/src/cgeo/geocaching/ui/NavigationActionProvider.java +++ b/main/src/cgeo/geocaching/ui/NavigationActionProvider.java @@ -9,6 +9,10 @@ import android.support.v4.view.ActionProvider; import android.view.LayoutInflater; import android.view.View; +/** + * Action provider showing the compass icon, and reacting to normal click (primary navigation) and long click (secondary + * navigation). + */ public class NavigationActionProvider extends ActionProvider { private final Context context; diff --git a/main/src/cgeo/geocaching/ui/WeakReferenceHandler.java b/main/src/cgeo/geocaching/ui/WeakReferenceHandler.java index d51e697..aa75db7 100644 --- a/main/src/cgeo/geocaching/ui/WeakReferenceHandler.java +++ b/main/src/cgeo/geocaching/ui/WeakReferenceHandler.java @@ -11,7 +11,6 @@ import java.lang.ref.WeakReference; * * Create static private subclasses of this handler class in your activity. * - * @param <ActivityType> */ public abstract class WeakReferenceHandler<ActivityType extends Activity> extends Handler { diff --git a/main/src/cgeo/geocaching/ui/dialog/Dialogs.java b/main/src/cgeo/geocaching/ui/dialog/Dialogs.java index 47ce6e1..3729677 100644 --- a/main/src/cgeo/geocaching/ui/dialog/Dialogs.java +++ b/main/src/cgeo/geocaching/ui/dialog/Dialogs.java @@ -408,7 +408,6 @@ public final class Dialogs { /** * Move the cursor to the end of the input field. * - * @param input */ public static void moveCursorToEnd(final EditText input) { input.setSelection(input.getText().length(), input.getText().length()); diff --git a/main/src/cgeo/geocaching/ui/logs/CacheLogsViewCreator.java b/main/src/cgeo/geocaching/ui/logs/CacheLogsViewCreator.java index 7e49c97..076c412 100644 --- a/main/src/cgeo/geocaching/ui/logs/CacheLogsViewCreator.java +++ b/main/src/cgeo/geocaching/ui/logs/CacheLogsViewCreator.java @@ -2,6 +2,7 @@ package cgeo.geocaching.ui.logs; import cgeo.geocaching.CacheDetailActivity; import cgeo.geocaching.CgeoApplication; +import cgeo.geocaching.DataStore; import cgeo.geocaching.Geocache; import cgeo.geocaching.LogEntry; import cgeo.geocaching.R; @@ -24,28 +25,33 @@ import java.util.Map.Entry; public class CacheLogsViewCreator extends LogsViewCreator { private final boolean allLogs; private final Resources res = CgeoApplication.getInstance().getResources(); + private final CacheDetailActivity cacheDetailActivity; - public CacheLogsViewCreator(CacheDetailActivity cacheDetailActivity, boolean allLogs) { + public CacheLogsViewCreator(final CacheDetailActivity cacheDetailActivity, final boolean allLogs) { super(cacheDetailActivity); + this.cacheDetailActivity = cacheDetailActivity; this.allLogs = allLogs; } - /** - * May return null! - * - * @return - */ private Geocache getCache() { - if (this.activity instanceof CacheDetailActivity) { - CacheDetailActivity details = (CacheDetailActivity) this.activity; - return details.getCache(); - } - return null; + return cacheDetailActivity.getCache(); } @Override protected List<LogEntry> getLogs() { - return allLogs ? getCache().getLogs() : getCache().getFriendsLogs(); + final Geocache cache = getCache(); + final List<LogEntry> logs = allLogs ? cache.getLogs() : cache.getFriendsLogs(); + return addOwnOfflineLog(cache, logs); + } + + private List<LogEntry> addOwnOfflineLog(final Geocache cache, final List<LogEntry> logsIn) { + final LogEntry log = DataStore.loadLogOffline(cache.getGeocode()); + final ArrayList<LogEntry> logs = new ArrayList<>(logsIn); + if (log != null) { + log.author = res.getString(R.string.log_your_saved_log); + logs.add(0, log); + } + return logs; } @Override @@ -56,7 +62,7 @@ public class CacheLogsViewCreator extends LogsViewCreator { final List<Entry<LogType, Integer>> sortedLogCounts = new ArrayList<>(logCounts.size()); for (final Entry<LogType, Integer> entry : logCounts.entrySet()) { // it may happen that the label is unknown -> then avoid any output for this type - if (entry.getKey() != LogType.PUBLISH_LISTING && entry.getKey().getL10n() != null && entry.getValue() != 0) { + if (entry.getKey() != LogType.PUBLISH_LISTING && entry.getValue() != 0) { sortedLogCounts.add(entry); } } @@ -66,7 +72,7 @@ public class CacheLogsViewCreator extends LogsViewCreator { Collections.sort(sortedLogCounts, new Comparator<Entry<LogType, Integer>>() { @Override - public int compare(Entry<LogType, Integer> logCountItem1, Entry<LogType, Integer> logCountItem2) { + public int compare(final Entry<LogType, Integer> logCountItem1, final Entry<LogType, Integer> logCountItem2) { return logCountItem1.getKey().compareTo(logCountItem2.getKey()); } }); @@ -84,7 +90,7 @@ public class CacheLogsViewCreator extends LogsViewCreator { } @Override - protected void fillCountOrLocation(LogViewHolder holder, final LogEntry log) { + protected void fillCountOrLocation(final LogViewHolder holder, final LogEntry log) { // finds count if (log.found == -1) { holder.countOrLocation.setVisibility(View.GONE); @@ -95,6 +101,21 @@ public class CacheLogsViewCreator extends LogsViewCreator { } @Override + protected void fillViewHolder(final View convertView, final LogViewHolder holder, final LogEntry log) { + super.fillViewHolder(convertView, holder, log); + if (isOfflineLog(log)) { + holder.author.setOnClickListener(new EditOfflineLogListener(getCache(), cacheDetailActivity)); + holder.text.setOnClickListener(new EditOfflineLogListener(getCache(), cacheDetailActivity)); + holder.marker.setVisibility(View.VISIBLE); + holder.marker.setImageResource(R.drawable.mark_orange); + } + } + + private boolean isOfflineLog(final LogEntry log) { + return log.author.equals(activity.getString(R.string.log_your_saved_log)); + } + + @Override protected boolean isValid() { return getCache() != null; } diff --git a/main/src/cgeo/geocaching/ui/logs/EditOfflineLogListener.java b/main/src/cgeo/geocaching/ui/logs/EditOfflineLogListener.java new file mode 100644 index 0000000..2e0f154 --- /dev/null +++ b/main/src/cgeo/geocaching/ui/logs/EditOfflineLogListener.java @@ -0,0 +1,25 @@ +package cgeo.geocaching.ui.logs; + +import cgeo.geocaching.CacheDetailActivity; +import cgeo.geocaching.Geocache; + +import android.view.View; +import android.view.View.OnClickListener; + +class EditOfflineLogListener implements OnClickListener { + + private final Geocache cache; + private final CacheDetailActivity activity; + + public EditOfflineLogListener(final Geocache cache, final CacheDetailActivity activity) { + this.cache = cache; + this.activity = activity; + } + + @Override + public void onClick(final View v) { + activity.setNeedsRefresh(); + cache.logVisit(activity); + } + +} diff --git a/main/src/cgeo/geocaching/ui/logs/LogsViewCreator.java b/main/src/cgeo/geocaching/ui/logs/LogsViewCreator.java index 3aaeec1..a6fd5aa 100644 --- a/main/src/cgeo/geocaching/ui/logs/LogsViewCreator.java +++ b/main/src/cgeo/geocaching/ui/logs/LogsViewCreator.java @@ -68,7 +68,7 @@ public abstract class LogsViewCreator extends AbstractCachingListViewPageViewCre return view; } - protected void fillViewHolder(final View convertView, final LogViewHolder holder, final LogEntry log) { + protected void fillViewHolder(@SuppressWarnings("unused") 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); @@ -116,12 +116,10 @@ public abstract class LogsViewCreator extends AbstractCachingListViewPageViewCre holder.marker.setVisibility(View.GONE); } - if (null == convertView) { - holder.author.setOnClickListener(createUserActionsListener()); - holder.text.setMovementMethod(AnchorAwareLinkMovementMethod.getInstance()); - holder.text.setOnClickListener(new DecryptTextClickListener(holder.text)); - activity.registerForContextMenu(holder.text); - } + holder.author.setOnClickListener(createUserActionsListener()); + holder.text.setMovementMethod(AnchorAwareLinkMovementMethod.getInstance()); + holder.text.setOnClickListener(new DecryptTextClickListener(holder.text)); + activity.registerForContextMenu(holder.text); } abstract protected UserActionsClickListener createUserActionsListener(); diff --git a/main/src/cgeo/geocaching/ui/logs/TrackableLogsViewCreator.java b/main/src/cgeo/geocaching/ui/logs/TrackableLogsViewCreator.java index 24c8871..c120286 100644 --- a/main/src/cgeo/geocaching/ui/logs/TrackableLogsViewCreator.java +++ b/main/src/cgeo/geocaching/ui/logs/TrackableLogsViewCreator.java @@ -19,7 +19,6 @@ public class TrackableLogsViewCreator extends LogsViewCreator { private final TrackableActivity trackableActivity; /** - * @param trackableActivity */ public TrackableLogsViewCreator(final TrackableActivity trackableActivity) { super(trackableActivity); |
