Created card to choose between dashboard and drawer

This commit is contained in:
GaidamakUA 2015-11-16 17:50:50 +02:00
parent c3bd59ebf7
commit 1c9b7a71c7
6 changed files with 70 additions and 146 deletions

View file

@ -1,39 +1,56 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout android:id="@+id/main_fav"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:osmand="http://schemas.android.com/apk/res-auto"
android:id="@+id/main_fav"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="?attr/bg_card"
android:layout_marginTop="@dimen/dash_margin"
android:layout_marginBottom="@dimen/dash_margin"
android:layout_marginLeft="@dimen/dash_margin_h"
android:layout_marginRight="@dimen/dash_margin_h"
android:orientation="vertical" >
android:layout_marginTop="@dimen/dash_margin"
android:background="?attr/bg_card"
android:orientation="vertical">
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="10dp"
android:paddingLeft="@dimen/list_content_padding"
android:paddingRight="@dimen/list_content_padding"
android:paddingTop="8dp"
android:text="@string/dashboard_or_drawer_title"
android:textColor="?android:textColorPrimary"
android:textSize="20sp"
osmand:typeface="@string/font_roboto_medium"/>
<TextView
android:id="@+id/subheader"
style="@style/DashboardSubHeader"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="@dimen/list_content_padding"
android:text="@string/dashboard_or_drawer_description"/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="@dimen/list_header_height"
android:orientation="horizontal" >
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/fav_text"
style="@style/DashboardSubHeader"
android:text="@string/shared_string_my_favorites"
osmand:typeface="@string/font_roboto_medium" />
android:gravity="right"
android:orientation="horizontal">
<net.osmand.plus.widgets.ButtonEx
android:id="@+id/show_all"
android:id="@+id/useDashboardButton"
style="@style/DashboardGeneralButton"
android:text="@string/shared_string_show_all"
android:text="@string/use_dashboard"
osmand:textAllCapsCompat="true"
osmand:typeface="@string/font_roboto_medium" />
osmand:typeface="@string/font_roboto_medium"/>
<net.osmand.plus.widgets.ButtonEx
android:id="@+id/useDrawerButton"
style="@style/DashboardGeneralButton"
android:text="@string/use_drawer"
osmand:textAllCapsCompat="true"
osmand:typeface="@string/font_roboto_medium"/>
</LinearLayout>
<LinearLayout
android:id="@+id/items"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" />
</LinearLayout>

View file

@ -2086,5 +2086,9 @@ Afghanistan, Albania, Algeria, Andorra, Angola, Anguilla, Antigua and Barbuda, A
<string name="map_legend">Map legend</string>
<string name="save_poi_without_poi_type_message">Do you really want to save poi without POI type?</string>
<string name="poi_context_menu_modify_osm_change">Modify OSM change</string>
<string name="use_dashboard">Use dashboard</string>
<string name="use_drawer">Use drawer</string>
<string name="dashboard_or_drawer_title">New menu</string>
<string name="dashboard_or_drawer_description">You can choose what to use, Dashboard or Drawer menu. You can change this later in settings.</string>
<!-- string name="map_legend_item_description">Legend for OsmAnd default map style, Internet connectivity needed to display</string -->
</resources>

View file

@ -635,9 +635,9 @@ public class OsmandSettings {
}
public final CommonPreference<Boolean> USE_FAST_RECALCULATION = new BooleanPreference("use_fast_recalculation", true).makeGlobal().cache();
public final CommonPreference<Boolean> SHOW_CARD_TO_CHOOSE_DRAWER = new BooleanPreference("show_card_to_choose_drawer", false).makeGlobal();
public final CommonPreference<Boolean> SHOW_DASHBOARD_ON_START = new BooleanPreference("should_show_dashboard_on_start", false).makeGlobal();
public final CommonPreference<Boolean> SHOW_DASHBOARD_ON_MAP_SCREEN = new BooleanPreference("show_dashboard_on_map_screen", false).makeGlobal();
public final CommonPreference<Boolean> SHOW_CARD_TO_CHOOSE_DRAWER = new BooleanPreference("show_card_to_choose_drawer", true).makeGlobal();
public final CommonPreference<Boolean> SHOW_DASHBOARD_ON_START = new BooleanPreference("should_show_dashboard_on_start", true).makeGlobal();
public final CommonPreference<Boolean> 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<Boolean> USE_INTERNET_TO_DOWNLOAD_TILES = new BooleanPreference("use_internet_to_download_tiles", true).makeGlobal().cache();

View file

@ -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);
}
}
}

View file

@ -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";

View file

@ -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,