From 1c9b7a71c73975851b6a651b3b0258bfd17f556c Mon Sep 17 00:00:00 2001 From: GaidamakUA Date: Mon, 16 Nov 2015 17:50:50 +0200 Subject: [PATCH] Created card to choose between dashboard and drawer --- .../dash_dashboard_or_drawer_fragment.xml | 71 ++++++---- OsmAnd/res/values/strings.xml | 4 + .../src/net/osmand/plus/OsmandSettings.java | 6 +- .../DashDashboardOrDrawerFragment.java | 129 +++--------------- .../plus/dashboard/DashErrorFragment.java | 4 - .../osmand/plus/dashboard/DashboardOnMap.java | 2 + 6 files changed, 70 insertions(+), 146 deletions(-) diff --git a/OsmAnd/res/layout/dash_dashboard_or_drawer_fragment.xml b/OsmAnd/res/layout/dash_dashboard_or_drawer_fragment.xml index d74c1feffa..65f6cadc7c 100644 --- a/OsmAnd/res/layout/dash_dashboard_or_drawer_fragment.xml +++ b/OsmAnd/res/layout/dash_dashboard_or_drawer_fragment.xml @@ -1,39 +1,56 @@ - + + + + + - - + android:gravity="right" + android:orientation="horizontal"> + osmand:typeface="@string/font_roboto_medium"/> + + - - \ No newline at end of file diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 9d2c152a99..dcb5d5c10c 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -2086,5 +2086,9 @@ Afghanistan, Albania, Algeria, Andorra, Angola, Anguilla, Antigua and Barbuda, A Map legend Do you really want to save poi without POI type? Modify OSM change + Use dashboard + Use drawer + New menu + You can choose what to use, Dashboard or Drawer menu. You can change this later in settings. diff --git a/OsmAnd/src/net/osmand/plus/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/OsmandSettings.java index d58a653779..b2d3750705 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/plus/OsmandSettings.java @@ -635,9 +635,9 @@ public class OsmandSettings { } public final CommonPreference USE_FAST_RECALCULATION = new BooleanPreference("use_fast_recalculation", true).makeGlobal().cache(); - public final CommonPreference SHOW_CARD_TO_CHOOSE_DRAWER = new BooleanPreference("show_card_to_choose_drawer", false).makeGlobal(); - public final CommonPreference SHOW_DASHBOARD_ON_START = new BooleanPreference("should_show_dashboard_on_start", false).makeGlobal(); - public final CommonPreference SHOW_DASHBOARD_ON_MAP_SCREEN = new BooleanPreference("show_dashboard_on_map_screen", false).makeGlobal(); + public final CommonPreference SHOW_CARD_TO_CHOOSE_DRAWER = new BooleanPreference("show_card_to_choose_drawer", true).makeGlobal(); + public final CommonPreference SHOW_DASHBOARD_ON_START = new BooleanPreference("should_show_dashboard_on_start", true).makeGlobal(); + public final CommonPreference SHOW_DASHBOARD_ON_MAP_SCREEN = new BooleanPreference("show_dashboard_on_map_screen", true).makeGlobal(); // this value string is synchronized with settings_pref.xml preference name public final CommonPreference USE_INTERNET_TO_DOWNLOAD_TILES = new BooleanPreference("use_internet_to_download_tiles", true).makeGlobal().cache(); diff --git a/OsmAnd/src/net/osmand/plus/dashboard/DashDashboardOrDrawerFragment.java b/OsmAnd/src/net/osmand/plus/dashboard/DashDashboardOrDrawerFragment.java index 09961f3e3d..b2e3b33475 100644 --- a/OsmAnd/src/net/osmand/plus/dashboard/DashDashboardOrDrawerFragment.java +++ b/OsmAnd/src/net/osmand/plus/dashboard/DashDashboardOrDrawerFragment.java @@ -1,150 +1,55 @@ package net.osmand.plus.dashboard; -import android.content.Intent; -import android.content.pm.PackageInfo; -import android.content.pm.PackageManager; -import android.graphics.Typeface; -import android.net.Uri; -import android.os.Build; import android.os.Bundle; -import android.support.design.widget.Snackbar; -import android.support.v4.view.ViewCompat; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.Button; -import android.widget.ImageView; -import android.widget.TextView; -import net.osmand.PlatformUtil; -import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandSettings; import net.osmand.plus.R; -import net.osmand.plus.Version; import net.osmand.plus.activities.MapActivity; -import net.osmand.plus.activities.OsmandActionBarActivity; import net.osmand.plus.dashboard.tools.DashFragmentData; -import net.osmand.plus.dialogs.ErrorBottomSheetDialog; -import net.osmand.plus.helpers.FontCache; - -import java.io.File; -import java.text.MessageFormat; public class DashDashboardOrDrawerFragment extends DashBaseFragment { - public static final String TAG = "DASH_ERROR_FRAGMENT"; + public static final String TAG = "DASH_DASHBOARD_OR_DRAWER_FRAGMENT"; public static final DashFragmentData.ShouldShowFunction SHOULD_SHOW_FUNCTION = new DashFragmentData.ShouldShowFunction() { // If settings null. No changes in setting will be made. @Override public boolean shouldShow(OsmandSettings settings, MapActivity activity, String tag) { - return ErrorBottomSheetDialog.shouldShow(settings, activity); + return settings.SHOW_CARD_TO_CHOOSE_DRAWER.get(); } }; private DismissListener dismissCallback; @Override public View initView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - View view = getActivity().getLayoutInflater().inflate(R.layout.dash_error_fragment, container, false); - String msg = MessageFormat.format(getString(R.string.previous_run_crashed), OsmandApplication.EXCEPTION_PATH); - Typeface typeface = FontCache.getRobotoMedium(getActivity()); - ImageView iv = ((ImageView) view.findViewById(R.id.error_icon)); - iv.setImageDrawable(getMyApplication().getIconsCache().getContentIcon(R.drawable.ic_crashlog)); - TextView message = ((TextView) view.findViewById(R.id.error_header)); - message.setTypeface(typeface); - message.setText(msg); - Button errorBtn = ((Button) view.findViewById(R.id.error_btn)); - errorBtn.setTypeface(typeface); - errorBtn.setOnClickListener(new View.OnClickListener() { + View view = getActivity().getLayoutInflater().inflate(R.layout.dash_dashboard_or_drawer_fragment, container, false); + view.findViewById(R.id.useDashboardButton).setOnClickListener(new View.OnClickListener() { @Override - public void onClick(View view) { - Intent intent = new Intent(Intent.ACTION_SEND); - intent.putExtra(Intent.EXTRA_EMAIL, new String[]{"crash@osmand.net"}); //$NON-NLS-1$ - File file = getMyApplication().getAppPath(OsmandApplication.EXCEPTION_PATH); - intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file)); - intent.setType("vnd.android.cursor.dir/email"); //$NON-NLS-1$ - intent.putExtra(Intent.EXTRA_SUBJECT, "OsmAnd bug"); //$NON-NLS-1$ - StringBuilder text = new StringBuilder(); - text.append("\nDevice : ").append(Build.DEVICE); //$NON-NLS-1$ - text.append("\nBrand : ").append(Build.BRAND); //$NON-NLS-1$ - text.append("\nModel : ").append(Build.MODEL); //$NON-NLS-1$ - text.append("\nProduct : ").append(Build.PRODUCT); //$NON-NLS-1$ - text.append("\nBuild : ").append(Build.DISPLAY); //$NON-NLS-1$ - text.append("\nVersion : ").append(Build.VERSION.RELEASE); //$NON-NLS-1$ - text.append("\nApp Version : ").append(Version.getAppName(getMyApplication())); //$NON-NLS-1$ - try { - PackageInfo info = getActivity().getPackageManager().getPackageInfo(getActivity().getPackageName(), - 0); - if (info != null) { - text.append("\nApk Version : ").append(info.versionName).append(" ").append(info.versionCode); //$NON-NLS-1$ //$NON-NLS-2$ - } - } catch (PackageManager.NameNotFoundException e) { - PlatformUtil.getLog(DashDashboardOrDrawerFragment.class).error("", e); - } - intent.putExtra(Intent.EXTRA_TEXT, text.toString()); - startActivity(Intent.createChooser(intent, getString(R.string.send_report))); + public void onClick(View v) { + final OsmandSettings settings = getMyApplication().getSettings(); + settings.SHOW_DASHBOARD_ON_START.set(true); + settings.SHOW_DASHBOARD_ON_MAP_SCREEN.set(true); + settings.SHOW_CARD_TO_CHOOSE_DRAWER.set(false); + dashboard.hideFragmentByTag(TAG); } }); - - Button cancelBtn = ((Button) view.findViewById(R.id.error_cancel)); - cancelBtn.setTypeface(typeface); - cancelBtn.setOnClickListener(new View.OnClickListener() { + view.findViewById(R.id.useDrawerButton).setOnClickListener(new View.OnClickListener() { @Override - public void onClick(View view) { - OsmandActionBarActivity dashboardActivity = ((OsmandActionBarActivity) getActivity()); - if (dashboardActivity != null) { - dashboardActivity.getSupportFragmentManager().beginTransaction().remove(DashDashboardOrDrawerFragment.this) - .commit(); - } + public void onClick(View v) { + final OsmandSettings settings = getMyApplication().getSettings(); + settings.SHOW_DASHBOARD_ON_START.set(false); + settings.SHOW_DASHBOARD_ON_MAP_SCREEN.set(false); + settings.SHOW_CARD_TO_CHOOSE_DRAWER.set(false); + dashboard.hideFragmentByTag(TAG); } }); - dismissCallback = new ErrorDismissListener(getParentView(), dashboard, TAG, view); return view; } @Override public void onOpenDash() { } - - @Override - public DismissListener getDismissCallback() { - return dismissCallback; - } - - private static class ErrorDismissListener implements DismissListener { - private View parentView; - private DashboardOnMap dashboardOnMap; - private String fragmentTag; - private View fragmentView; - - public ErrorDismissListener(View parentView, DashboardOnMap dashboardOnMap, - String fragmentTag, View fragmentView) { - this.parentView = parentView; - this.dashboardOnMap = dashboardOnMap; - this.fragmentTag = fragmentTag; - this.fragmentView = fragmentView; - } - - @Override - public void onDismiss() { - dashboardOnMap.hideFragmentByTag(fragmentTag); - ViewCompat.setTranslationX(fragmentView, 0); - ViewCompat.setAlpha(fragmentView, 1); - Snackbar.make(parentView, dashboardOnMap.getMyApplication().getResources() - .getString(R.string.shared_string_card_was_hidden), Snackbar.LENGTH_LONG) - .setAction(R.string.shared_string_undo, new View.OnClickListener() { - @Override - public void onClick(View view) { - ErrorDismissListener.this.onUndo(); - } - }) - .show(); - } - - public void onUndo() { - dashboardOnMap.unhideFragmentByTag(fragmentTag); - ViewCompat.setTranslationX(fragmentView, 0); - ViewCompat.setAlpha(fragmentView, 1); - } - } } diff --git a/OsmAnd/src/net/osmand/plus/dashboard/DashErrorFragment.java b/OsmAnd/src/net/osmand/plus/dashboard/DashErrorFragment.java index 71a239076c..c8a5cfe1f5 100644 --- a/OsmAnd/src/net/osmand/plus/dashboard/DashErrorFragment.java +++ b/OsmAnd/src/net/osmand/plus/dashboard/DashErrorFragment.java @@ -30,10 +30,6 @@ import net.osmand.plus.helpers.FontCache; import java.io.File; import java.text.MessageFormat; -/** - * Created by Denis - * on 02.12.14. - */ public class DashErrorFragment extends DashBaseFragment { public static final String TAG = "DASH_ERROR_FRAGMENT"; diff --git a/OsmAnd/src/net/osmand/plus/dashboard/DashboardOnMap.java b/OsmAnd/src/net/osmand/plus/dashboard/DashboardOnMap.java index f0e4fd5452..3f07f54dbe 100644 --- a/OsmAnd/src/net/osmand/plus/dashboard/DashboardOnMap.java +++ b/OsmAnd/src/net/osmand/plus/dashboard/DashboardOnMap.java @@ -75,6 +75,8 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks { private final DashFragmentData[] fragmentsData = new DashFragmentData[]{ new DashFragmentData(DashRateUsFragment.TAG, DashRateUsFragment.class, DashRateUsFragment.SHOULD_SHOW_FUNCTION, 0, null), + new DashFragmentData(DashDashboardOrDrawerFragment.TAG, DashDashboardOrDrawerFragment.class, + DashDashboardOrDrawerFragment.SHOULD_SHOW_FUNCTION, 5, null), new DashFragmentData(DashErrorFragment.TAG, DashErrorFragment.class, DashErrorFragment.SHOULD_SHOW_FUNCTION, 30, null), new DashFragmentData(DashNavigationFragment.TAG, DashNavigationFragment.class,