From 4d5f6fd24315638185398325b470cba096985615 Mon Sep 17 00:00:00 2001 From: GaidamakUA Date: Fri, 13 Nov 2015 17:42:01 +0200 Subject: [PATCH] Error dialog added --- .../osmand/plus/activities/MapActivity.java | 8 +- .../osmand/plus/dashboard/DashboardOnMap.java | 3 +- .../plus/dialogs/ErrorBottomSheetDialog.java | 97 +++++++++++++++++++ 3 files changed, 105 insertions(+), 3 deletions(-) create mode 100644 OsmAnd/src/net/osmand/plus/dialogs/ErrorBottomSheetDialog.java diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java index 2369158095..1907276871 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java @@ -62,6 +62,7 @@ import net.osmand.plus.activities.search.SearchActivity; import net.osmand.plus.base.FailSafeFuntions; import net.osmand.plus.base.MapViewTrackingUtilities; import net.osmand.plus.dashboard.DashboardOnMap; +import net.osmand.plus.dialogs.ErrorBottomSheetDialog; import net.osmand.plus.dialogs.WhatsNewDialogFragment; import net.osmand.plus.download.DownloadIndexesThread.DownloadEvents; import net.osmand.plus.helpers.GpxImportHelper; @@ -394,8 +395,13 @@ public class MapActivity extends AccessibleActivity implements DownloadEvents { if (!dashboardOnMap.isVisible()) { final OsmandSettings.CommonPreference shouldShowDashboardOnStart = settings.registerBooleanPreference(MapActivity.SHOULD_SHOW_DASHBOARD_ON_START, true); - if (shouldShowDashboardOnStart.get() || dashboardOnMap.hasCriticalMessages()) + if (shouldShowDashboardOnStart.get() || dashboardOnMap.hasCriticalMessages()) { dashboardOnMap.setDashboardVisibility(true, DashboardOnMap.staticVisibleType); + } else { + if (ErrorBottomSheetDialog.shouldShow(settings, this)) { + new ErrorBottomSheetDialog().show(getFragmentManager(), "dialog"); + } + } } } dashboardOnMap.updateLocation(true, true, false); diff --git a/OsmAnd/src/net/osmand/plus/dashboard/DashboardOnMap.java b/OsmAnd/src/net/osmand/plus/dashboard/DashboardOnMap.java index 2c5c907eeb..12f710c438 100644 --- a/OsmAnd/src/net/osmand/plus/dashboard/DashboardOnMap.java +++ b/OsmAnd/src/net/osmand/plus/dashboard/DashboardOnMap.java @@ -907,8 +907,7 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks { // TODO: 11/13/15 Remove public boolean hasCriticalMessages() { final OsmandSettings settings = getMyApplication().getSettings(); - return rateUsShouldShow.shouldShow(settings, mapActivity, DashRateUsFragment.TAG) - || errorShouldShow.shouldShow(null, mapActivity, null); + return rateUsShouldShow.shouldShow(settings, mapActivity, DashRateUsFragment.TAG); } View getParentView() { diff --git a/OsmAnd/src/net/osmand/plus/dialogs/ErrorBottomSheetDialog.java b/OsmAnd/src/net/osmand/plus/dialogs/ErrorBottomSheetDialog.java new file mode 100644 index 0000000000..4e08aa029c --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/dialogs/ErrorBottomSheetDialog.java @@ -0,0 +1,97 @@ +package net.osmand.plus.dialogs; + +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.annotation.Nullable; +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.base.BottomSheetDialogFragment; +import net.osmand.plus.helpers.FontCache; + +import java.io.File; +import java.text.MessageFormat; + +/** + * Created by GaidamakUA on 11/13/15. + */ +public class ErrorBottomSheetDialog extends BottomSheetDialogFragment { + @Nullable + @Override + public View onCreateView(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() { + @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(ErrorBottomSheetDialog.class).error("", e); + } + intent.putExtra(Intent.EXTRA_TEXT, text.toString()); + startActivity(Intent.createChooser(intent, getString(R.string.send_report))); + } + }); + + Button cancelBtn = ((Button) view.findViewById(R.id.error_cancel)); + cancelBtn.setTypeface(typeface); + cancelBtn.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + OsmandActionBarActivity dashboardActivity = ((OsmandActionBarActivity) getActivity()); + if (dashboardActivity != null) { + dismiss(); + } + } + }); + return view; + } + + public static boolean shouldShow(OsmandSettings settings, MapActivity activity) { + return activity.getMyApplication().getAppInitializer() + .checkPreviousRunsForExceptions(activity, settings != null); + } +}