aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching/CachePopupFragment.java
diff options
context:
space:
mode:
authorArne Schwabe <arne@rfc2549.org>2014-04-20 21:38:19 +0200
committerArne Schwabe <arne@rfc2549.org>2014-05-17 13:08:14 +0200
commitbe26c1845210a1c8824677ed6e2d093073ea5c84 (patch)
tree81d02773f4fd9edc5d05b44c770be89994a9c207 /main/src/cgeo/geocaching/CachePopupFragment.java
parent496878826d638367c129b02e66f992202e0d36c9 (diff)
downloadcgeo-be26c1845210a1c8824677ed6e2d093073ea5c84.zip
cgeo-be26c1845210a1c8824677ed6e2d093073ea5c84.tar.gz
cgeo-be26c1845210a1c8824677ed6e2d093073ea5c84.tar.bz2
Implement ActionBar using AppCompat in cgeo
This a first version of an ActionBar implementation with following properties: - The application should be usuable (there still might be bugs left from the conversation to Action) - Provides a more modern feeling on all devices - gets rid of the "dots of shame" on Android 3.0+ devices - The Maps classes MUST inherit from Activity instead of ActionBarActivity. There these classes use the old ActionBar on Android 2.3 devices and the real ActionBar on 3.0+ - This can be fixed when cgeo is ported to Google Maps API v2.0 API which usesFragment - The Dialog classes (CachePopup and WaypointPopup) have been converted to DialogFragments - The AppCombat themes provide no Theme.Dialog theme - this will later ease using these Fragment in other Activities - Use an almost empty activity which just shows the DialogFragment - Use the 'old' ActionBar but which overflow menu button to fit into Holo Design Style - Using a real ActionBar for Dialogs is not really support by Android and trying to force the frame into showing an Actionbar on a dialog leeds to strange bugs/effects - Most of the icon are still the Android 2.3 Menu Icon. These need to be replaced with Holo Style Icons - for most menu icon the ifRoom and/or withText attributes should be reviewed and set - The ActionBar of the main Activity is transparent. This is more or less by accident but looks good - Review Up Action of activities. Is going back to Main Activity always the semantically right thing to do? - Shortpress/Longpress on the Actionbars Compass Icon for primary/secondary Navigation clashes the normal ActionBar behaviour of long pressing to show the text of the action This commit contains many fixes and suggestions from rsudev
Diffstat (limited to 'main/src/cgeo/geocaching/CachePopupFragment.java')
-rw-r--r--main/src/cgeo/geocaching/CachePopupFragment.java229
1 files changed, 229 insertions, 0 deletions
diff --git a/main/src/cgeo/geocaching/CachePopupFragment.java b/main/src/cgeo/geocaching/CachePopupFragment.java
new file mode 100644
index 0000000..010d701
--- /dev/null
+++ b/main/src/cgeo/geocaching/CachePopupFragment.java
@@ -0,0 +1,229 @@
+package cgeo.geocaching;
+
+import cgeo.geocaching.activity.Progress;
+import cgeo.geocaching.apps.cache.navi.NavigationAppFactory;
+import cgeo.geocaching.geopoint.Geopoint;
+import cgeo.geocaching.list.StoredList;
+import cgeo.geocaching.network.Network;
+import cgeo.geocaching.settings.Settings;
+import cgeo.geocaching.ui.CacheDetailsCreator;
+import cgeo.geocaching.utils.CancellableHandler;
+import cgeo.geocaching.utils.Log;
+
+import org.apache.commons.lang3.StringUtils;
+
+import rx.functions.Action0;
+import rx.functions.Action1;
+import rx.schedulers.Schedulers;
+
+import android.content.Context;
+import android.content.Intent;
+import android.content.res.Configuration;
+import android.os.Bundle;
+import android.os.Handler;
+import android.os.Message;
+import android.support.v4.app.DialogFragment;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+
+public class CachePopupFragment extends AbstractDialogFragment {
+ private final Progress progress = new Progress();
+
+ public static DialogFragment newInstance(String geocode) {
+
+ Bundle args = new Bundle();
+ args.putString(GEOCODE_ARG,geocode);
+
+ DialogFragment f = new CachePopupFragment();
+ f.setStyle(DialogFragment.STYLE_NO_TITLE,0);
+ f.setArguments(args);
+
+ return f;
+ }
+
+ private class StoreCacheHandler extends CancellableHandler {
+ private final int progressMessage;
+
+ public StoreCacheHandler(final int progressMessage) {
+ this.progressMessage = progressMessage;
+ }
+
+ @Override
+ public void handleRegularMessage(Message msg) {
+ if (UPDATE_LOAD_PROGRESS_DETAIL == msg.what && msg.obj instanceof String) {
+ updateStatusMsg((String) msg.obj);
+ } else {
+ init();
+ }
+ }
+
+ private void updateStatusMsg(final String msg) {
+ progress.setMessage(res.getString(progressMessage)
+ + "\n\n"
+ + msg);
+ }
+ }
+
+ private class DropCacheHandler extends Handler {
+ @Override
+ public void handleMessage(Message msg) {
+ getActivity().finish();
+ }
+ }
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
+ View v = inflater.inflate(R.layout.popup, container, false);
+ initCustomActionBar(v);
+ return v;
+ }
+
+ @Override
+ protected void init() {
+ super.init();
+
+ try {
+ if (StringUtils.isNotBlank(cache.getName())) {
+ setTitle(cache.getName());
+ } else {
+ setTitle(geocode);
+ }
+
+ ((TextView) getView().findViewById(R.id.actionbar_title)).setCompoundDrawablesWithIntrinsicBounds(getResources().getDrawable(cache.getType().markerId), null, null, null);
+
+ details = new CacheDetailsCreator(getActivity(), (LinearLayout) getView().findViewById(R.id.details_list));
+
+ addCacheDetails();
+
+ // offline use
+ CacheDetailActivity.updateOfflineBox(getView(), cache, res, new RefreshCacheClickListener(), new DropCacheClickListener(), new StoreCacheClickListener());
+
+ } catch (Exception e) {
+ Log.e("CachePopupFragment.init", e);
+ }
+
+ // cache is loaded. remove progress-popup if any there
+ progress.dismiss();
+ }
+
+
+
+ @Override
+ public void onConfigurationChanged(Configuration newConfig) {
+ super.onConfigurationChanged(newConfig);
+
+ init();
+ }
+
+ private class StoreCacheClickListener implements View.OnClickListener {
+ @Override
+ public void onClick(View arg0) {
+ if (progress.isShowing()) {
+ showToast(res.getString(R.string.err_detail_still_working));
+ return;
+ }
+
+ if (Settings.getChooseList()) {
+ // let user select list to store cache in
+ new StoredList.UserInterface(getActivity()).promptForListSelection(R.string.list_title,
+ new Action1<Integer>() {
+ @Override
+ public void call(final Integer selectedListId) {
+ storeCache(selectedListId);
+ }
+ }, true, StoredList.TEMPORARY_LIST_ID);
+ } else {
+ storeCache(StoredList.TEMPORARY_LIST_ID);
+ }
+ }
+
+ protected void storeCache(final int listId) {
+ final StoreCacheHandler storeCacheHandler = new StoreCacheHandler(R.string.cache_dialog_offline_save_message);
+ progress.show(getActivity(), res.getString(R.string.cache_dialog_offline_save_title), res.getString(R.string.cache_dialog_offline_save_message), true, storeCacheHandler.cancelMessage());
+ Schedulers.io().createWorker().schedule(new Action0() {
+ @Override
+ public void call() {
+ cache.store(listId, storeCacheHandler);
+ getActivity().supportInvalidateOptionsMenu();
+ }
+ });
+ }
+ }
+
+ private class RefreshCacheClickListener implements View.OnClickListener {
+ @Override
+ public void onClick(View arg0) {
+ if (progress.isShowing()) {
+ showToast(res.getString(R.string.err_detail_still_working));
+ return;
+ }
+
+ if (!Network.isNetworkConnected(getActivity())) {
+ showToast(getString(R.string.err_server));
+ return;
+ }
+
+ final StoreCacheHandler refreshCacheHandler = new StoreCacheHandler(R.string.cache_dialog_offline_save_message);
+ progress.show(getActivity(), res.getString(R.string.cache_dialog_refresh_title), res.getString(R.string.cache_dialog_refresh_message), true, refreshCacheHandler.cancelMessage());
+ cache.refresh(refreshCacheHandler, Schedulers.io());
+ }
+ }
+
+ private class DropCacheClickListener implements View.OnClickListener {
+ @Override
+ public void onClick(View arg0) {
+ if (progress.isShowing()) {
+ showToast(res.getString(R.string.err_detail_still_working));
+ return;
+ }
+
+ final DropCacheHandler dropCacheHandler = new DropCacheHandler();
+ progress.show(getActivity(), res.getString(R.string.cache_dialog_offline_drop_title), res.getString(R.string.cache_dialog_offline_drop_message), true, null);
+ cache.drop(dropCacheHandler, Schedulers.io());
+ }
+ }
+
+
+ @Override
+ public void navigateTo() {
+ NavigationAppFactory.startDefaultNavigationApplication(1, getActivity(), cache);
+ }
+
+ @Override
+ public void showNavigationMenu() {
+ // TODO
+ }
+
+
+ /**
+ * Tries to navigate to the {@link cgeo.geocaching.Geocache} of this activity.
+ */
+ @Override
+ protected void startDefaultNavigation2() {
+ if (cache == null || cache.getCoords() == null) {
+ showToast(res.getString(R.string.cache_coordinates_no));
+ return;
+ }
+ NavigationAppFactory.startDefaultNavigationApplication(2, getActivity(), cache);
+ getActivity().finish();
+ }
+
+ public static void startActivity(final Context context, final String geocode) {
+ final Intent popupIntent = new Intent(context, CachePopup.class);
+ popupIntent.putExtra(Intents.EXTRA_GEOCODE, geocode);
+ context.startActivity(popupIntent);
+ }
+
+ @Override
+ protected Geopoint getCoordinates() {
+ if (cache == null) {
+ return null;
+ }
+ return cache.getCoords();
+ }
+
+
+}