diff options
Diffstat (limited to 'main/src/cgeo/geocaching/ui')
8 files changed, 121 insertions, 80 deletions
diff --git a/main/src/cgeo/geocaching/ui/AbstractCachingPageViewCreator.java b/main/src/cgeo/geocaching/ui/AbstractCachingPageViewCreator.java index ed5d182..0c67384 100644 --- a/main/src/cgeo/geocaching/ui/AbstractCachingPageViewCreator.java +++ b/main/src/cgeo/geocaching/ui/AbstractCachingPageViewCreator.java @@ -3,7 +3,6 @@ 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; diff --git a/main/src/cgeo/geocaching/ui/AnchorAwareLinkMovementMethod.java b/main/src/cgeo/geocaching/ui/AnchorAwareLinkMovementMethod.java index db82e5c..d4c2e10 100644 --- a/main/src/cgeo/geocaching/ui/AnchorAwareLinkMovementMethod.java +++ b/main/src/cgeo/geocaching/ui/AnchorAwareLinkMovementMethod.java @@ -8,7 +8,7 @@ import android.widget.TextView; /** * <code>LinkMovementMethod</code> with built-in suppression of errors for links, where the URL cannot be handled * correctly by Android. - * + * */ public class AnchorAwareLinkMovementMethod extends LinkMovementMethod { diff --git a/main/src/cgeo/geocaching/ui/CacheDetailsCreator.java b/main/src/cgeo/geocaching/ui/CacheDetailsCreator.java index 7fe77c4..5d8ebef 100644 --- a/main/src/cgeo/geocaching/ui/CacheDetailsCreator.java +++ b/main/src/cgeo/geocaching/ui/CacheDetailsCreator.java @@ -39,6 +39,11 @@ public final class CacheDetailsCreator { parentView.removeAllViews(); } + /** + * @param nameId + * @param value + * @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 TextView nameView = (TextView) layout.findViewById(R.id.name); @@ -188,14 +193,24 @@ public final class CacheDetailsCreator { if (!cache.isEventCache()) { return; } + addHiddenDate(cache); + } + + public TextView addHiddenDate(final @NonNull Geocache cache) { final Date hiddenDate = cache.getHiddenDate(); if (hiddenDate == null) { - return; + return null; } final long time = hiddenDate.getTime(); if (time > 0) { - final String dateString = DateUtils.formatDateTime(CgeoApplication.getInstance().getBaseContext(), time, DateUtils.FORMAT_SHOW_WEEKDAY) + ", " + Formatter.formatFullDate(time); - add(R.string.cache_event, dateString); + String dateString = Formatter.formatFullDate(time); + if (cache.isEventCache()) { + dateString = DateUtils.formatDateTime(CgeoApplication.getInstance().getBaseContext(), time, DateUtils.FORMAT_SHOW_WEEKDAY) + ", " + dateString; + } + final TextView view = add(cache.isEventCache() ? R.string.cache_event : R.string.cache_hidden, dateString); + view.setId(R.id.date); + return view; } + return null; } } diff --git a/main/src/cgeo/geocaching/ui/EditNoteDialog.java b/main/src/cgeo/geocaching/ui/EditNoteDialog.java index 2af1cb8..63f06fc 100644 --- a/main/src/cgeo/geocaching/ui/EditNoteDialog.java +++ b/main/src/cgeo/geocaching/ui/EditNoteDialog.java @@ -1,12 +1,17 @@ package cgeo.geocaching.ui; import cgeo.geocaching.R; +import cgeo.geocaching.activity.Keyboard; +import cgeo.geocaching.ui.dialog.Dialogs; + +import org.eclipse.jdt.annotation.NonNull; import android.app.AlertDialog; import android.app.Dialog; import android.content.DialogInterface; import android.os.Bundle; import android.support.v4.app.DialogFragment; +import android.support.v4.app.FragmentActivity; import android.view.ContextThemeWrapper; import android.view.View; import android.widget.EditText; @@ -35,15 +40,17 @@ public class EditNoteDialog extends DialogFragment { @Override public Dialog onCreateDialog(Bundle savedInstanceState) { - View view = View.inflate(new ContextThemeWrapper(getActivity(), R.style.dark), R.layout.fragment_edit_note, null); + 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); if (initialNote != null) { mEditText.setText(initialNote); + Dialogs.moveCursorToEnd(mEditText); getArguments().remove(ARGUMENT_INITIAL_NOTE); } - AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); + AlertDialog.Builder builder = new AlertDialog.Builder(activity); builder.setTitle(R.string.cache_personal_note); builder.setView(view); builder.setPositiveButton(android.R.string.ok, @@ -61,6 +68,8 @@ public class EditNoteDialog extends DialogFragment { dialog.dismiss(); } }); - return builder.create(); + final AlertDialog dialog = builder.create(); + new Keyboard(activity).showDelayed(mEditText); + return dialog; } } diff --git a/main/src/cgeo/geocaching/ui/ImagesList.java b/main/src/cgeo/geocaching/ui/ImagesList.java index 4eaf06d..dcce969 100644 --- a/main/src/cgeo/geocaching/ui/ImagesList.java +++ b/main/src/cgeo/geocaching/ui/ImagesList.java @@ -9,6 +9,12 @@ 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; +import rx.functions.Action1; +import rx.subscriptions.CompositeSubscription; +import rx.subscriptions.Subscriptions; import android.app.Activity; import android.content.Intent; @@ -18,14 +24,12 @@ import android.graphics.Bitmap.CompressFormat; import android.graphics.Rect; import android.graphics.drawable.BitmapDrawable; import android.net.Uri; -import android.os.AsyncTask; import android.text.Html; import android.util.SparseArray; import android.view.ContextMenu; import android.view.LayoutInflater; import android.view.MenuItem; import android.view.View; -import android.view.ViewGroup.LayoutParams; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; @@ -44,8 +48,7 @@ public class ImagesList { public enum ImageType { LogImages(R.string.cache_log_images_title), - SpoilerImages(R.string.cache_spoiler_images_title), - AllImages(R.string.cache_images_title); + SpoilerImages(R.string.cache_spoiler_images_title); private final int titleResId; @@ -75,12 +78,31 @@ public class ImagesList { inflater = activity.getLayoutInflater(); } - public void loadImages(final View parentView, final List<Image> images, final boolean offline) { + /** + * Load images into a view. + * + * @param parentView a view to load the images into + * @param images the images to load + * @param offline <tt>true</tt> if the images must be stored for offline use + * @return a subscription which, when unsubscribed, interrupts the loading and clears up resources + */ + public Subscription loadImages(final View parentView, final List<Image> images, final boolean offline) { + // Start with a fresh subscription because of this method can be called several times if the + // englobing activity is stopped/restarted. + final CompositeSubscription subscriptions = new CompositeSubscription(Subscriptions.create(new Action0() { + @Override + public void call() { + removeAllViews(); + } + })); imagesView = (LinearLayout) parentView.findViewById(R.id.spoiler_list); + final HtmlImage imgGetter = new HtmlImage(geocode, true, offline ? StoredList.STANDARD_LIST_ID : StoredList.TEMPORARY_LIST_ID, false); + for (final Image img : images) { - LinearLayout rowView = (LinearLayout) inflater.inflate(R.layout.cache_image_item, null); + final LinearLayout rowView = (LinearLayout) inflater.inflate(R.layout.cache_image_item, null); + assert(rowView != null); if (StringUtils.isNotBlank(img.getTitle())) { ((TextView) rowView.findViewById(R.id.title)).setText(Html.fromHtml(img.getTitle())); @@ -93,66 +115,58 @@ public class ImagesList { descView.setVisibility(View.VISIBLE); } - new AsyncImgLoader(rowView, img, offline).execute(); + final ImageView imageView = (ImageView) inflater.inflate(R.layout.image_item, null); + assert(imageView != null); + subscriptions.add(AndroidObservable.fromActivity(activity, imgGetter.fetchDrawable(img.getUrl())) + .subscribe(new Action1<BitmapDrawable>() { + @Override + public void call(final BitmapDrawable image) { + display(imageView, image, img, rowView); + } + })); + rowView.addView(imageView); imagesView.addView(rowView); } + + return subscriptions; } - private class AsyncImgLoader extends AsyncTask<Void, Void, BitmapDrawable> { + private void display(final ImageView imageView, final BitmapDrawable image, final Image img, final LinearLayout view) { + if (image != null) { + bitmaps.add(image.getBitmap()); - final private LinearLayout view; - final private Image img; - final boolean offline; + final Rect bounds = image.getBounds(); - public AsyncImgLoader(final LinearLayout view, final Image img, final boolean offline) { - this.view = view; - this.img = img; - this.offline = offline; - } + imageView.setImageResource(R.drawable.image_not_loaded); + imageView.setClickable(true); + imageView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View arg0) { + viewImageInStandardApp(image); + } + }); + activity.registerForContextMenu(imageView); + imageView.setImageDrawable(image); + imageView.setScaleType(ImageView.ScaleType.CENTER_CROP); + imageView.setLayoutParams(new LinearLayout.LayoutParams(bounds.width(), bounds.height())); - @Override - protected BitmapDrawable doInBackground(Void... params) { - final HtmlImage imgGetter = new HtmlImage(geocode, true, offline ? StoredList.STANDARD_LIST_ID : StoredList.TEMPORARY_LIST_ID, false); - return imgGetter.getDrawable(img.getUrl()); - } + view.findViewById(R.id.progress_bar).setVisibility(View.GONE); - @Override - protected void onPostExecute(final BitmapDrawable image) { - if (image != null) { - bitmaps.add(image.getBitmap()); - final ImageView imageView = (ImageView) inflater.inflate(R.layout.image_item, null); - - final Rect bounds = image.getBounds(); - - imageView.setImageResource(R.drawable.image_not_loaded); - imageView.setClickable(true); - imageView.setOnClickListener(new View.OnClickListener() { - - @Override - public void onClick(View arg0) { - viewImageInStandardApp(image); - } - }); - activity.registerForContextMenu(imageView); - imageView.setImageDrawable(image); - imageView.setScaleType(ImageView.ScaleType.CENTER_CROP); - imageView.setLayoutParams(new LayoutParams(bounds.width(), bounds.height())); - - view.findViewById(R.id.progress_bar).setVisibility(View.GONE); - view.addView(imageView); - - imageView.setId(image.hashCode()); - images.put(imageView.getId(), img); - } + imageView.setId(image.hashCode()); + images.put(imageView.getId(), img); + + view.invalidate(); } } - public void removeAllViews() { - imagesView.removeAllViews(); + private void removeAllViews() { for (final Bitmap b : bitmaps) { b.recycle(); } bitmaps.clear(); + images.clear(); + + imagesView.removeAllViews(); } public void onCreateContextMenu(ContextMenu menu, View v) { diff --git a/main/src/cgeo/geocaching/ui/dialog/CoordinatesInputDialog.java b/main/src/cgeo/geocaching/ui/dialog/CoordinatesInputDialog.java index 93f50e1..651ff6e 100644 --- a/main/src/cgeo/geocaching/ui/dialog/CoordinatesInputDialog.java +++ b/main/src/cgeo/geocaching/ui/dialog/CoordinatesInputDialog.java @@ -54,7 +54,7 @@ public class CoordinatesInputDialog extends NoTitleDialog { } else if (geo != null && geo.getCoords() != null) { this.gp = geo.getCoords(); } else { - this.gp = new Geopoint(0.0, 0.0); + this.gp = Geopoint.ZERO; } } @@ -396,7 +396,7 @@ public class CoordinatesInputDialog extends NoTitleDialog { if (geo != null && geo.getCoords() != null) { gp = geo.getCoords(); } else { - gp = new Geopoint(0.0, 0.0); + gp = Geopoint.ZERO; } } } diff --git a/main/src/cgeo/geocaching/ui/dialog/Dialogs.java b/main/src/cgeo/geocaching/ui/dialog/Dialogs.java index 865ba70..cb8926a 100644 --- a/main/src/cgeo/geocaching/ui/dialog/Dialogs.java +++ b/main/src/cgeo/geocaching/ui/dialog/Dialogs.java @@ -1,20 +1,24 @@ package cgeo.geocaching.ui.dialog; import cgeo.geocaching.CgeoApplication; -import cgeo.geocaching.utils.RunnableWithArgument; +import cgeo.geocaching.R; import org.apache.commons.lang3.StringUtils; import org.eclipse.jdt.annotation.Nullable; +import rx.functions.Action1; + import android.app.Activity; import android.app.AlertDialog; import android.app.AlertDialog.Builder; +import android.content.Context; import android.content.DialogInterface; import android.content.DialogInterface.OnClickListener; import android.graphics.drawable.Drawable; import android.text.Editable; import android.text.InputType; import android.text.TextWatcher; +import android.view.ContextThemeWrapper; import android.view.WindowManager; import android.widget.EditText; @@ -298,7 +302,7 @@ public final class Dialogs { /** * Show a message dialog for input from the user. The okay button is only enabled on non empty input. - * + * * @param context * activity owning the dialog * @param title @@ -310,19 +314,20 @@ public final class Dialogs { * @param okayListener * listener to be run on okay */ - public static void input(final Activity context, final int title, final String defaultValue, final int buttonTitle, final RunnableWithArgument<String> okayListener) { - final EditText input = new EditText(context); + public static void input(final Activity context, final int title, final String defaultValue, final int buttonTitle, final Action1<String> okayListener) { + final Context themedContext = new ContextThemeWrapper(context, R.style.dark); + final EditText input = new EditText(themedContext); input.setInputType(InputType.TYPE_TEXT_FLAG_CAP_SENTENCES | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS | InputType.TYPE_CLASS_TEXT); input.setText(defaultValue); - final AlertDialog.Builder builder = new AlertDialog.Builder(context); + final AlertDialog.Builder builder = new AlertDialog.Builder(themedContext); builder.setTitle(title); builder.setView(input); builder.setPositiveButton(buttonTitle, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { - okayListener.run(input.getText().toString()); + okayListener.call(input.getText().toString()); } }); builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @@ -357,8 +362,16 @@ public final class Dialogs { dialog.show(); enableDialogButtonIfNotEmpty(dialog, defaultValue); - // position cursor after text - input.setSelection(input.getText().length()); + moveCursorToEnd(input); + } + + /** + * 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()); } private static void enableDialogButtonIfNotEmpty(final AlertDialog dialog, final String input) { diff --git a/main/src/cgeo/geocaching/ui/dialog/LiveMapInfoDialogBuilder.java b/main/src/cgeo/geocaching/ui/dialog/LiveMapInfoDialogBuilder.java index 6ad59ec..c29f549 100644 --- a/main/src/cgeo/geocaching/ui/dialog/LiveMapInfoDialogBuilder.java +++ b/main/src/cgeo/geocaching/ui/dialog/LiveMapInfoDialogBuilder.java @@ -1,15 +1,14 @@ package cgeo.geocaching.ui.dialog; +import cgeo.geocaching.CgeoApplication; import cgeo.geocaching.R; import cgeo.geocaching.settings.Settings; -import cgeo.geocaching.CgeoApplication; import android.app.Activity; import android.app.AlertDialog; import android.content.DialogInterface; import android.view.ContextThemeWrapper; import android.view.View; -import android.widget.CheckBox; public class LiveMapInfoDialogBuilder { @@ -20,12 +19,7 @@ public class LiveMapInfoDialogBuilder { final View layout = View.inflate(new ContextThemeWrapper(activity, R.style.dark), R.layout.livemapinfo, null); builder.setView(layout); - final CheckBox checkBoxHide = (CheckBox) layout.findViewById(R.id.live_map_hint_hide); - final int showCount = Settings.getLiveMapHintShowCount(); - if (showCount > 2) { - checkBoxHide.setVisibility(View.VISIBLE); - } Settings.setLiveMapHintShowCount(showCount + 1); builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @@ -33,10 +27,7 @@ public class LiveMapInfoDialogBuilder { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); - CgeoApplication.getInstance().setLiveMapHintShown(); - if (checkBoxHide.getVisibility() == View.VISIBLE && checkBoxHide.isChecked()) { - Settings.setHideLiveHint(true); - } + CgeoApplication.getInstance().setLiveMapHintShownInThisSession(); } }); return builder.create(); |
