Profile settings fifth part

This commit is contained in:
Chumva 2019-09-05 18:50:37 +03:00
parent 3f12808b76
commit efeaa0f63a
20 changed files with 490 additions and 517 deletions

View file

@ -4,7 +4,7 @@
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:minHeight="72dp"> android:minHeight="52dp">
<ImageView <ImageView
android:id="@android:id/icon" android:id="@android:id/icon"

View file

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:osmand="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<net.osmand.plus.widgets.TextViewEx
android:id="@android:id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/content_padding"
android:layout_marginRight="@dimen/content_padding"
android:textColor="?android:textColorSecondary"
android:textSize="@dimen/default_desc_text_size"
osmand:typeface="@string/font_roboto_regular" />
</LinearLayout>

View file

@ -6,22 +6,47 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="?android:attr/selectableItemBackground" android:background="?android:attr/selectableItemBackground"
android:gravity="center_vertical" android:gravity="center_vertical"
android:minHeight="36dp"> android:minHeight="72dp">
<ImageView
android:id="@android:id/icon"
android:layout_width="@dimen/standard_icon_size"
android:layout_height="@dimen/standard_icon_size"
android:layout_gravity="center"
android:layout_marginStart="@dimen/content_padding"
android:layout_marginLeft="@dimen/content_padding"
android:layout_marginEnd="@dimen/content_padding_half"
android:layout_marginRight="@dimen/content_padding_half" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
android:paddingLeft="@dimen/content_padding"
android:paddingRight="@dimen/content_padding">
<net.osmand.plus.widgets.TextViewEx <net.osmand.plus.widgets.TextViewEx
android:id="@android:id/title" android:id="@android:id/title"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_marginStart="@dimen/empty_state_text_button_padding_left"
android:layout_marginLeft="@dimen/empty_state_text_button_padding_left"
android:ellipsize="marquee" android:ellipsize="marquee"
android:gravity="center_vertical" android:gravity="center_vertical"
android:paddingLeft="@dimen/content_padding"
android:paddingRight="@dimen/content_padding"
android:singleLine="true" android:singleLine="true"
android:textColor="@color/preference_category_title" android:textColor="@color/preference_category_title"
android:textSize="@dimen/default_desc_text_size" android:textSize="@dimen/default_desc_text_size"
osmand:typeface="@string/font_roboto_medium" osmand:typeface="@string/font_roboto_medium"
tools:text="@string/shared_string_other" /> tools:text="@string/shared_string_other" />
<net.osmand.plus.widgets.TextViewEx
android:id="@android:id/summary"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="4"
android:textColor="?android:textColorSecondary"
android:textSize="@dimen/default_list_text_size"
osmand:typeface="@string/font_roboto_regular" />
</LinearLayout>
</LinearLayout> </LinearLayout>

View file

@ -5,7 +5,7 @@
<Preference <Preference
android:key="configure_profile_info" android:key="configure_profile_info"
android:layout="@layout/preference_info" android:layout="@layout/preference_info_descr"
android:persistent="false" android:persistent="false"
android:selectable="false" android:selectable="false"
android:title="@string/configure_profile_info" /> android:title="@string/configure_profile_info" />
@ -38,7 +38,7 @@
<PreferenceCategory <PreferenceCategory
android:key="plugin_settings" android:key="plugin_settings"
android:layout="@layout/preference_with_descr" android:layout="@layout/simple_preference_category"
android:summary="@string/list_of_installed_plugins" android:summary="@string/list_of_installed_plugins"
android:title="@string/plugin_settings" /> android:title="@string/plugin_settings" />

View file

@ -31,6 +31,7 @@
android:icon="@drawable/ic_action_privacy_and_security" android:icon="@drawable/ic_action_privacy_and_security"
android:key="send_anonymous_data" android:key="send_anonymous_data"
android:layout="@layout/preference_dialog_and_switch" android:layout="@layout/preference_dialog_and_switch"
android:persistent="false"
android:summaryOff="@string/shared_string_off" android:summaryOff="@string/shared_string_off"
android:summaryOn="@string/shared_string_on" android:summaryOn="@string/shared_string_on"
android:title="@string/analytics_pref_title" /> android:title="@string/analytics_pref_title" />

View file

@ -924,7 +924,12 @@ public class OsmandSettings {
@Override @Override
protected boolean setValue(Object prefs, ApplicationMode val) { protected boolean setValue(Object prefs, ApplicationMode val) {
return settingsAPI.edit(prefs).putString(getId(), val.getStringKey()).commit(); boolean valueSaved = settingsAPI.edit(prefs).putString(getId(), val.getStringKey()).commit();
if (valueSaved) {
APPLICATION_MODE.set(val);
}
return valueSaved;
} }
}; };
@ -1102,7 +1107,6 @@ public class OsmandSettings {
public final OsmandPreference<Boolean> DO_NOT_SHOW_STARTUP_MESSAGES = new BooleanPreference("do_not_show_startup_messages", false).makeGlobal().cache(); public final OsmandPreference<Boolean> DO_NOT_SHOW_STARTUP_MESSAGES = new BooleanPreference("do_not_show_startup_messages", false).makeGlobal().cache();
public final OsmandPreference<Boolean> DO_NOT_USE_ANIMATIONS = new BooleanPreference("do_not_use_animations", false).makeProfile().cache(); public final OsmandPreference<Boolean> DO_NOT_USE_ANIMATIONS = new BooleanPreference("do_not_use_animations", false).makeProfile().cache();
public final OsmandPreference<Boolean> SEND_ANONYMOUS_DATA = new BooleanPreference("send_anonymous_data", false).makeGlobal().cache();
public final OsmandPreference<Boolean> SEND_ANONYMOUS_MAP_DOWNLOADS_DATA = new BooleanPreference("send_anonymous_map_downloads_data", false).makeGlobal().cache(); public final OsmandPreference<Boolean> SEND_ANONYMOUS_MAP_DOWNLOADS_DATA = new BooleanPreference("send_anonymous_map_downloads_data", false).makeGlobal().cache();
public final OsmandPreference<Boolean> SEND_ANONYMOUS_APP_USAGE_DATA = new BooleanPreference("send_anonymous_app_usage_data", false).makeGlobal().cache(); public final OsmandPreference<Boolean> SEND_ANONYMOUS_APP_USAGE_DATA = new BooleanPreference("send_anonymous_app_usage_data", false).makeGlobal().cache();
public final OsmandPreference<Boolean> SEND_ANONYMOUS_DATA_REQUEST_PROCESSED = new BooleanPreference("send_anonymous_data_request_processed", false).makeGlobal().cache(); public final OsmandPreference<Boolean> SEND_ANONYMOUS_DATA_REQUEST_PROCESSED = new BooleanPreference("send_anonymous_data_request_processed", false).makeGlobal().cache();

View file

@ -879,7 +879,7 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
} else if (!isFirstScreenShowing() && OsmLiveCancelledDialog.shouldShowDialog(app)) { } else if (!isFirstScreenShowing() && OsmLiveCancelledDialog.shouldShowDialog(app)) {
OsmLiveCancelledDialog.showInstance(getSupportFragmentManager()); OsmLiveCancelledDialog.showInstance(getSupportFragmentManager());
} else if (SendAnalyticsBottomSheetDialogFragment.shouldShowDialog(app)) { } else if (SendAnalyticsBottomSheetDialogFragment.shouldShowDialog(app)) {
SendAnalyticsBottomSheetDialogFragment.showInstance(app, getSupportFragmentManager()); SendAnalyticsBottomSheetDialogFragment.showInstance(app, getSupportFragmentManager(), null);
} }
FirstUsageWelcomeFragment.SHOW = false; FirstUsageWelcomeFragment.SHOW = false;
if (isFirstScreenShowing() && (!settings.SHOW_OSMAND_WELCOME_SCREEN.get() || !showOsmAndWelcomeScreen)) { if (isFirstScreenShowing() && (!settings.SHOW_OSMAND_WELCOME_SCREEN.get() || !showOsmAndWelcomeScreen)) {

View file

@ -841,13 +841,13 @@ public class MapActivityActions implements DialogProvider {
} }
}).createItem()); }).createItem());
optionsMenuHelper.addItem(new ItemBuilder().setTitleId(R.string.shared_string_settings, mapActivity) optionsMenuHelper.addItem(new ItemBuilder().setTitle(getString(R.string.shared_string_settings) + " (Alpha)")
.setId(DRAWER_SETTINGS_ID) .setId(DRAWER_SETTINGS_ID + ".new")
.setIcon(R.drawable.ic_action_compass) .setIcon(R.drawable.ic_action_settings)
.setListener(new ItemClickListener() { .setListener(new ItemClickListener() {
@Override @Override
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int pos, boolean isChecked, int[] viewCoordinates) { public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int pos, boolean isChecked, int[] viewCoordinates) {
app.logEvent("drawer_settings_open"); app.logEvent("drawer_settings_new_open");
mapActivity.showSettings(); mapActivity.showSettings();
return true; return true;
} }

View file

@ -590,7 +590,7 @@ public abstract class SettingsBaseActivity extends ActionBarPreferenceActivity
return (OsmandApplication) getApplication(); return (OsmandApplication) getApplication();
} }
protected void showWarnings(List<String> warnings) { public static void showWarnings(final OsmandApplication app, List<String> warnings) {
if (!warnings.isEmpty()) { if (!warnings.isEmpty()) {
final StringBuilder b = new StringBuilder(); final StringBuilder b = new StringBuilder();
boolean f = true; boolean f = true;
@ -602,11 +602,10 @@ public abstract class SettingsBaseActivity extends ActionBarPreferenceActivity
} }
b.append(w); b.append(w);
} }
runOnUiThread(new Runnable() { app.runInUIThread(new Runnable() {
@Override @Override
public void run() { public void run() {
Toast.makeText(SettingsBaseActivity.this, b.toString(), Toast.LENGTH_LONG).show(); Toast.makeText(app, b.toString(), Toast.LENGTH_LONG).show();
} }
}); });
} }

View file

@ -1,7 +1,9 @@
package net.osmand.plus.activities; package net.osmand.plus.activities;
import android.app.Activity;
import android.app.Dialog; import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener; import android.content.DialogInterface.OnClickListener;
import android.content.pm.ActivityInfo; import android.content.pm.ActivityInfo;
@ -22,6 +24,7 @@ import android.support.annotation.NonNull;
import android.support.v4.app.ActivityCompat.OnRequestPermissionsResultCallback; import android.support.v4.app.ActivityCompat.OnRequestPermissionsResultCallback;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
import android.support.v7.widget.AppCompatCheckedTextView; import android.support.v7.widget.AppCompatCheckedTextView;
import android.util.Pair;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -69,7 +72,6 @@ public class SettingsGeneralActivity extends SettingsBaseActivity implements OnR
private Preference applicationDir; private Preference applicationDir;
private ListPreference applicationModePreference; private ListPreference applicationModePreference;
private Preference drivingRegionPreference; private Preference drivingRegionPreference;
private ChooseAppDirFragment chooseAppDirFragment;
private boolean permissionRequested; private boolean permissionRequested;
private boolean permissionGranted; private boolean permissionGranted;
@ -223,17 +225,35 @@ public class SettingsGeneralActivity extends SettingsBaseActivity implements OnR
} }
registerListPreference(settings.ANGULAR_UNITS, screen, entries, ac); registerListPreference(settings.ANGULAR_UNITS, screen, entries, ac);
Pair<String[], String[]> preferredLocaleInfo = getPreferredLocaleIdsAndValues(this);
if (preferredLocaleInfo != null) {
registerListPreference(settings.PREFERRED_LOCALE, screen, preferredLocaleInfo.first, preferredLocaleInfo.second);
}
// Add " (Display language)" to menu title in Latin letters for all non-en languages
if (!getResources().getString(R.string.preferred_locale).equals(getResources().getString(R.string.preferred_locale_no_translate))) {
((ListPreference) screen.findPreference(settings.PREFERRED_LOCALE.getId())).setTitle(getString(R.string.preferred_locale) + " (" + getString(R.string.preferred_locale_no_translate) + ")");
}
// This setting now only in "Confgure map" menu
//String[] values = ConfigureMapMenu.getMapNamesValues(this, ConfigureMapMenu.mapNamesIds);
//String[] ids = ConfigureMapMenu.getSortedMapNamesIds(this, ConfigureMapMenu.mapNamesIds, values);
//registerListPreference(settings.MAP_PREFERRED_LOCALE, screen, ConfigureMapMenu.getMapNamesValues(this, ids), ids);
}
public static Pair<String[], String[]> getPreferredLocaleIdsAndValues(Context ctx) {
// See language list and statistics at: https://hosted.weblate.org/projects/osmand/main/ // See language list and statistics at: https://hosted.weblate.org/projects/osmand/main/
// Hardy maintenance 2016-05-29: // Hardy maintenance 2016-05-29:
// - Include languages if their translation is >= ~10% (but any language will be visible if it is the device's system locale) // - Include languages if their translation is >= ~10% (but any language will be visible if it is the device's system locale)
// - Mark as "incomplete" if < ~80% // - Mark as "incomplete" if < ~80%
String incompleteSuffix = " (" + getString(R.string.incomplete_locale) + ")"; String incompleteSuffix = " (" + ctx.getString(R.string.incomplete_locale) + ")";
// Add " (Device language)" to system default entry in Latin letters, so it can be more easily identified if a foreign language has been selected by mistake // Add " (Device language)" to system default entry in Latin letters, so it can be more easily identified if a foreign language has been selected by mistake
String latinSystemDefaultSuffix = " (" + getString(R.string.system_locale_no_translate) + ")"; String latinSystemDefaultSuffix = " (" + ctx.getString(R.string.system_locale_no_translate) + ")";
//getResources().getAssets().getLocales(); //getResources().getAssets().getLocales();
entrieValues = new String[]{"", String[] entryValues = new String[] {
"",
"en", "en",
"af", "af",
"ar", "ar",
@ -294,83 +314,76 @@ public class SettingsGeneralActivity extends SettingsBaseActivity implements OnR
"vi", "vi",
"zh_CN", "zh_CN",
"zh_TW"}; "zh_TW"};
entries = new String[]{getString(R.string.system_locale) + latinSystemDefaultSuffix,
getString(R.string.lang_en), String[] entries = new String[] {
getString(R.string.lang_af) + incompleteSuffix, ctx.getString(R.string.system_locale) + latinSystemDefaultSuffix,
getString(R.string.lang_ar), ctx.getString(R.string.lang_en),
getString(R.string.lang_ast) + incompleteSuffix, ctx.getString(R.string.lang_af) + incompleteSuffix,
getString(R.string.lang_az), ctx.getString(R.string.lang_ar),
getString(R.string.lang_be), ctx.getString(R.string.lang_ast) + incompleteSuffix,
ctx.getString(R.string.lang_az),
ctx.getString(R.string.lang_be),
// getString(R.string.lang_be_by), // getString(R.string.lang_be_by),
getString(R.string.lang_bg), ctx.getString(R.string.lang_bg),
getString(R.string.lang_ca), ctx.getString(R.string.lang_ca),
getString(R.string.lang_cs), ctx.getString(R.string.lang_cs),
getString(R.string.lang_cy) + incompleteSuffix, ctx.getString(R.string.lang_cy) + incompleteSuffix,
getString(R.string.lang_da), ctx.getString(R.string.lang_da),
getString(R.string.lang_de), ctx.getString(R.string.lang_de),
getString(R.string.lang_el) + incompleteSuffix, ctx.getString(R.string.lang_el) + incompleteSuffix,
getString(R.string.lang_en_gb), ctx.getString(R.string.lang_en_gb),
getString(R.string.lang_eo), ctx.getString(R.string.lang_eo),
getString(R.string.lang_es), ctx.getString(R.string.lang_es),
getString(R.string.lang_es_ar), ctx.getString(R.string.lang_es_ar),
getString(R.string.lang_es_us), ctx.getString(R.string.lang_es_us),
getString(R.string.lang_eu), ctx.getString(R.string.lang_eu),
getString(R.string.lang_fa), ctx.getString(R.string.lang_fa),
getString(R.string.lang_fi) + incompleteSuffix, ctx.getString(R.string.lang_fi) + incompleteSuffix,
getString(R.string.lang_fr), ctx.getString(R.string.lang_fr),
getString(R.string.lang_gl), ctx.getString(R.string.lang_gl),
getString(R.string.lang_he) + incompleteSuffix, ctx.getString(R.string.lang_he) + incompleteSuffix,
getString(R.string.lang_hr) + incompleteSuffix, ctx.getString(R.string.lang_hr) + incompleteSuffix,
getString(R.string.lang_hsb) + incompleteSuffix, ctx.getString(R.string.lang_hsb) + incompleteSuffix,
getString(R.string.lang_hu), ctx.getString(R.string.lang_hu),
getString(R.string.lang_hy), ctx.getString(R.string.lang_hy),
getString(R.string.lang_is), ctx.getString(R.string.lang_is),
getString(R.string.lang_it), ctx.getString(R.string.lang_it),
getString(R.string.lang_ja), ctx.getString(R.string.lang_ja),
getString(R.string.lang_ka) + incompleteSuffix, ctx.getString(R.string.lang_ka) + incompleteSuffix,
getString(R.string.lang_kab) + incompleteSuffix, ctx.getString(R.string.lang_kab) + incompleteSuffix,
getString(R.string.lang_kn) + incompleteSuffix, ctx.getString(R.string.lang_kn) + incompleteSuffix,
getString(R.string.lang_ko), ctx.getString(R.string.lang_ko),
getString(R.string.lang_lt), ctx.getString(R.string.lang_lt),
getString(R.string.lang_lv), ctx.getString(R.string.lang_lv),
getString(R.string.lang_ml) + incompleteSuffix, ctx.getString(R.string.lang_ml) + incompleteSuffix,
getString(R.string.lang_mr) + incompleteSuffix, ctx.getString(R.string.lang_mr) + incompleteSuffix,
getString(R.string.lang_nb), ctx.getString(R.string.lang_nb),
getString(R.string.lang_nl), ctx.getString(R.string.lang_nl),
getString(R.string.lang_nn) + incompleteSuffix, ctx.getString(R.string.lang_nn) + incompleteSuffix,
getString(R.string.lang_oc) + incompleteSuffix, ctx.getString(R.string.lang_oc) + incompleteSuffix,
getString(R.string.lang_pl), ctx.getString(R.string.lang_pl),
getString(R.string.lang_pt), ctx.getString(R.string.lang_pt),
getString(R.string.lang_pt_br), ctx.getString(R.string.lang_pt_br),
getString(R.string.lang_ro) + incompleteSuffix, ctx.getString(R.string.lang_ro) + incompleteSuffix,
getString(R.string.lang_ru), ctx.getString(R.string.lang_ru),
getString(R.string.lang_sc), ctx.getString(R.string.lang_sc),
getString(R.string.lang_sk), ctx.getString(R.string.lang_sk),
getString(R.string.lang_sl), ctx.getString(R.string.lang_sl),
getString(R.string.lang_sr) + incompleteSuffix, ctx.getString(R.string.lang_sr) + incompleteSuffix,
getString(R.string.lang_sr_latn) + incompleteSuffix, ctx.getString(R.string.lang_sr_latn) + incompleteSuffix,
getString(R.string.lang_sv), ctx.getString(R.string.lang_sv),
getString(R.string.lang_tr), ctx.getString(R.string.lang_tr),
getString(R.string.lang_uk), ctx.getString(R.string.lang_uk),
getString(R.string.lang_vi) + incompleteSuffix, ctx.getString(R.string.lang_vi) + incompleteSuffix,
getString(R.string.lang_zh_cn) + incompleteSuffix, ctx.getString(R.string.lang_zh_cn) + incompleteSuffix,
getString(R.string.lang_zh_tw)}; ctx.getString(R.string.lang_zh_tw)};
String[] valuesPl = ConfigureMapMenu.getSortedMapNamesIds(this, entries, entries);
String[] idsPl = ConfigureMapMenu.getSortedMapNamesIds(this, entrieValues, entries);
registerListPreference(settings.PREFERRED_LOCALE, screen, valuesPl, idsPl);
// Add " (Display language)" to menu title in Latin letters for all non-en languages String[] valuesPl = ConfigureMapMenu.getSortedMapNamesIds(ctx, entries, entries);
if (!getResources().getString(R.string.preferred_locale).equals(getResources().getString(R.string.preferred_locale_no_translate))) { String[] idsPl = ConfigureMapMenu.getSortedMapNamesIds(ctx, entryValues, entries);
((ListPreference) screen.findPreference(settings.PREFERRED_LOCALE.getId())).setTitle(getString(R.string.preferred_locale) + " (" + getString(R.string.preferred_locale_no_translate) + ")");
return Pair.create(valuesPl, idsPl);
} }
// This setting now only in "Confgure map" menu
//String[] values = ConfigureMapMenu.getMapNamesValues(this, ConfigureMapMenu.mapNamesIds);
//String[] ids = ConfigureMapMenu.getSortedMapNamesIds(this, ConfigureMapMenu.mapNamesIds, values);
//registerListPreference(settings.MAP_PREFERRED_LOCALE, screen, ConfigureMapMenu.getMapNamesValues(this, ids), ids);
}
protected void enableProxy(boolean enable) { protected void enableProxy(boolean enable) {
settings.ENABLE_PROXY.set(enable); settings.ENABLE_PROXY.set(enable);
if (enable) { if (enable) {
@ -425,14 +438,14 @@ public class SettingsGeneralActivity extends SettingsBaseActivity implements OnR
} }
public void showAppDirDialog() { public static void showAppDirDialog(final OsmandSettings settings, final ActionBarPreferenceActivity ctx, boolean permissionRequested, boolean permissionGranted) {
if (Build.VERSION.SDK_INT >= 19) { if (Build.VERSION.SDK_INT >= 19) {
showAppDirDialogV19(); showAppDirDialogV19(ctx,permissionRequested,permissionGranted);
return; return;
} }
AlertDialog.Builder editalert = new AlertDialog.Builder(SettingsGeneralActivity.this); AlertDialog.Builder editalert = new AlertDialog.Builder(ctx);
editalert.setTitle(R.string.application_dir); editalert.setTitle(R.string.application_dir);
final EditText input = new EditText(SettingsGeneralActivity.this); final EditText input = new EditText(ctx);
input.setText(settings.getExternalStorageDirectory().getAbsolutePath()); input.setText(settings.getExternalStorageDirectory().getAbsolutePath());
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams( LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT,
@ -445,25 +458,27 @@ public class SettingsGeneralActivity extends SettingsBaseActivity implements OnR
editalert.setNegativeButton(R.string.shared_string_cancel, null); editalert.setNegativeButton(R.string.shared_string_cancel, null);
editalert.setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() { editalert.setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) { public void onClick(DialogInterface dialog, int whichButton) {
warnAboutChangingStorage(input.getText().toString()); warnAboutChangingStorage(settings,ctx,input.getText().toString());
} }
}); });
editalert.show(); editalert.show();
} }
private void showAppDirDialogV19() { private static void showAppDirDialogV19(final Activity activity, boolean permissionRequested, boolean permissionGranted) {
AlertDialog.Builder bld = new AlertDialog.Builder(this); AlertDialog.Builder bld = new AlertDialog.Builder(activity);
chooseAppDirFragment = new DashChooseAppDirFragment.ChooseAppDirFragment(this, (Dialog) null) { ChooseAppDirFragment chooseAppDirFragment = new DashChooseAppDirFragment.ChooseAppDirFragment(activity, (Dialog) null) {
@Override @Override
protected void successCallback() { protected void successCallback() {
updateApplicationDirTextAndSummary(); if (activity instanceof SettingsGeneralActivity) {
((SettingsGeneralActivity) activity).updateApplicationDirTextAndSummary();
}
} }
}; };
if (permissionRequested && !permissionGranted) { if (permissionRequested && !permissionGranted) {
chooseAppDirFragment.setPermissionDenied(); chooseAppDirFragment.setPermissionDenied();
} }
bld.setView(chooseAppDirFragment.initView(getLayoutInflater(), null, null)); bld.setView(chooseAppDirFragment.initView(activity.getLayoutInflater(), null, null));
AlertDialog dlg = bld.show(); AlertDialog dlg = bld.show();
chooseAppDirFragment.setDialog(dlg); chooseAppDirFragment.setDialog(dlg);
} }
@ -473,12 +488,12 @@ public class SettingsGeneralActivity extends SettingsBaseActivity implements OnR
if (!Version.isBlackberry(getMyApplication())) { if (!Version.isBlackberry(getMyApplication())) {
applicationDir = new Preference(this); applicationDir = new Preference(this);
applicationDir.setTitle(R.string.application_dir); applicationDir.setTitle(R.string.application_dir);
applicationDir.setKey("external_storage_dir"); applicationDir.setKey(OsmandSettings.EXTERNAL_STORAGE_DIR);
applicationDir.setOnPreferenceClickListener(new OnPreferenceClickListener() { applicationDir.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override @Override
public boolean onPreferenceClick(Preference preference) { public boolean onPreferenceClick(Preference preference) {
showAppDirDialog(); showAppDirDialog(settings, SettingsGeneralActivity.this, permissionRequested, permissionGranted);
return false; return false;
} }
}); });
@ -569,7 +584,7 @@ public class SettingsGeneralActivity extends SettingsBaseActivity implements OnR
private void warnAboutChangingStorage(final String newValue) { private static void warnAboutChangingStorage(final OsmandSettings settings, final ActionBarPreferenceActivity activity, String newValue) {
String newDir = newValue != null ? newValue.trim() : newValue; String newDir = newValue != null ? newValue.trim() : newValue;
if (!newDir.replace('/', ' ').trim(). if (!newDir.replace('/', ' ').trim().
toLowerCase().endsWith(IndexConstants.APP_DIR.replace('/', ' ').trim())) { toLowerCase().endsWith(IndexConstants.APP_DIR.replace('/', ' ').trim())) {
@ -578,21 +593,21 @@ public class SettingsGeneralActivity extends SettingsBaseActivity implements OnR
final File path = new File(newDir); final File path = new File(newDir);
path.mkdirs(); path.mkdirs();
if (!path.canRead() || !path.exists()) { if (!path.canRead() || !path.exists()) {
Toast.makeText(this, R.string.specified_dir_doesnt_exist, Toast.LENGTH_LONG).show(); Toast.makeText(activity, R.string.specified_dir_doesnt_exist, Toast.LENGTH_LONG).show();
return; return;
} }
AlertDialog.Builder builder = new AlertDialog.Builder(this); AlertDialog.Builder builder = new AlertDialog.Builder(activity);
builder.setMessage(getString(R.string.application_dir_change_warning3)); builder.setMessage(activity.getString(R.string.application_dir_change_warning3));
builder.setPositiveButton(R.string.shared_string_yes, new OnClickListener() { builder.setPositiveButton(R.string.shared_string_yes, new OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
MoveFilesToDifferentDirectory task = MoveFilesToDifferentDirectory task =
new MoveFilesToDifferentDirectory(SettingsGeneralActivity.this, new MoveFilesToDifferentDirectory(activity,
settings.getExternalStorageDirectory(), path); settings.getExternalStorageDirectory(), path);
task.setRunOnSuccess(new Runnable() { task.setRunOnSuccess(new Runnable() {
@Override @Override
public void run() { public void run() {
updateSettingsToNewDir(path.getParentFile().getAbsolutePath()); updateSettingsToNewDir(settings,activity,path.getParentFile().getAbsolutePath());
} }
}); });
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
@ -602,39 +617,41 @@ public class SettingsGeneralActivity extends SettingsBaseActivity implements OnR
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
updateSettingsToNewDir(path.getParentFile().getAbsolutePath()); updateSettingsToNewDir(settings,activity,path.getParentFile().getAbsolutePath());
} }
}); });
builder.setNegativeButton(R.string.shared_string_cancel, null); builder.setNegativeButton(R.string.shared_string_cancel, null);
builder.show(); builder.show();
} }
private void updateSettingsToNewDir(final String newDir) { private static void updateSettingsToNewDir(OsmandSettings settings, ActionBarPreferenceActivity activity, String newDir) {
// edit the preference // edit the preference
settings.setExternalStorageDirectoryPre19(newDir); settings.setExternalStorageDirectoryPre19(newDir);
getMyApplication().getResourceManager().resetStoreDirectory(); ((OsmandApplication) activity.getApplication()).getResourceManager().resetStoreDirectory();
reloadIndexes(); reloadIndexes(activity);
updateApplicationDirTextAndSummary(); if (activity instanceof SettingsGeneralActivity) {
((SettingsGeneralActivity) activity).updateApplicationDirTextAndSummary();
}
} }
public void reloadIndexes() { public static void reloadIndexes(final ActionBarPreferenceActivity activity) {
setProgressVisibility(true); activity.setProgressVisibility(true);
final CharSequence oldTitle = getToolbar().getTitle(); final CharSequence oldTitle = activity.getToolbar().getTitle();
getToolbar().setTitle(getString(R.string.loading_data)); activity.getToolbar().setTitle(activity.getString(R.string.loading_data));
getToolbar().setSubtitle(getString(R.string.reading_indexes)); activity.getToolbar().setSubtitle(activity.getString(R.string.reading_indexes));
new AsyncTask<Void, Void, List<String>>() { new AsyncTask<Void, Void, List<String>>() {
@Override @Override
protected List<String> doInBackground(Void... params) { protected List<String> doInBackground(Void... params) {
return getMyApplication().getResourceManager().reloadIndexes(IProgress.EMPTY_PROGRESS, return ((OsmandApplication) activity.getApplication()).getResourceManager().reloadIndexes(IProgress.EMPTY_PROGRESS,
new ArrayList<String>()); new ArrayList<String>());
} }
protected void onPostExecute(List<String> result) { protected void onPostExecute(List<String> result) {
showWarnings(result); showWarnings(((OsmandApplication)activity.getApplication()),result);
getToolbar().setTitle(oldTitle); activity.getToolbar().setTitle(oldTitle);
getToolbar().setSubtitle(""); activity.getToolbar().setSubtitle("");
setProgressVisibility(false); activity.setProgressVisibility(false);
} }
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
@ -667,34 +684,11 @@ public class SettingsGeneralActivity extends SettingsBaseActivity implements OnR
} }
} }
protected void showWarnings(List<String> warnings) {
if (!warnings.isEmpty()) {
final StringBuilder b = new StringBuilder();
boolean f = true;
for (String w : warnings) {
if (f) {
f = false;
} else {
b.append('\n');
}
b.append(w);
}
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(SettingsGeneralActivity.this, b.toString(), Toast.LENGTH_LONG).show();
}
});
}
}
@Override @Override
protected void onResume() { protected void onResume() {
super.onResume(); super.onResume();
if (permissionRequested) { if (permissionRequested) {
showAppDirDialogV19(); showAppDirDialogV19(this, permissionRequested, permissionGranted);
permissionRequested = false; permissionRequested = false;
} }
} }

View file

@ -3,6 +3,8 @@ package net.osmand.plus.dialogs;
import android.content.Context; import android.content.Context;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentManager;
import android.support.v4.content.ContextCompat; import android.support.v4.content.ContextCompat;
import android.text.Spannable; import android.text.Spannable;
@ -25,7 +27,6 @@ import net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerItem;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.LongDescriptionItem; import net.osmand.plus.base.bottomsheetmenu.simpleitems.LongDescriptionItem;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.SubtitleDividerItem; import net.osmand.plus.base.bottomsheetmenu.simpleitems.SubtitleDividerItem;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.SubtitmeListDividerItem; import net.osmand.plus.base.bottomsheetmenu.simpleitems.SubtitmeListDividerItem;
import net.osmand.plus.chooseplan.OsmLiveCancelledDialog;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
@ -142,6 +143,7 @@ public class SendAnalyticsBottomSheetDialogFragment extends MenuBottomSheetDialo
settings.SEND_ANONYMOUS_MAP_DOWNLOADS_DATA.set(false); settings.SEND_ANONYMOUS_MAP_DOWNLOADS_DATA.set(false);
settings.SEND_ANONYMOUS_APP_USAGE_DATA.set(false); settings.SEND_ANONYMOUS_APP_USAGE_DATA.set(false);
settings.SEND_ANONYMOUS_DATA_REQUEST_PROCESSED.set(true); settings.SEND_ANONYMOUS_DATA_REQUEST_PROCESSED.set(true);
informAnalyticsPrefsUpdate();
} }
@Override @Override
@ -151,9 +153,17 @@ public class SendAnalyticsBottomSheetDialogFragment extends MenuBottomSheetDialo
settings.SEND_ANONYMOUS_MAP_DOWNLOADS_DATA.set(sendAnonymousMapDownloadsData); settings.SEND_ANONYMOUS_MAP_DOWNLOADS_DATA.set(sendAnonymousMapDownloadsData);
settings.SEND_ANONYMOUS_APP_USAGE_DATA.set(sendAnonymousAppUsageData); settings.SEND_ANONYMOUS_APP_USAGE_DATA.set(sendAnonymousAppUsageData);
settings.SEND_ANONYMOUS_DATA_REQUEST_PROCESSED.set(true); settings.SEND_ANONYMOUS_DATA_REQUEST_PROCESSED.set(true);
informAnalyticsPrefsUpdate();
dismiss(); dismiss();
} }
private void informAnalyticsPrefsUpdate() {
Fragment target = getTargetFragment();
if (target instanceof OnSendAnalyticsPrefsUpdate) {
((OnSendAnalyticsPrefsUpdate) target).onAnalyticsPrefsUpdate();
}
}
public static boolean shouldShowDialog(@NonNull OsmandApplication app) { public static boolean shouldShowDialog(@NonNull OsmandApplication app) {
OsmandSettings settings = app.getSettings(); OsmandSettings settings = app.getSettings();
int requestsCount = settings.SEND_ANONYMOUS_DATA_REQUESTS_COUNT.get(); int requestsCount = settings.SEND_ANONYMOUS_DATA_REQUESTS_COUNT.get();
@ -171,10 +181,11 @@ public class SendAnalyticsBottomSheetDialogFragment extends MenuBottomSheetDialo
return false; return false;
} }
public static void showInstance(@NonNull OsmandApplication app, @NonNull FragmentManager fm) { public static void showInstance(@NonNull OsmandApplication app, @NonNull FragmentManager fm, @Nullable Fragment target) {
try { try {
if (fm.findFragmentByTag(SendAnalyticsBottomSheetDialogFragment.TAG) == null) { if (fm.findFragmentByTag(SendAnalyticsBottomSheetDialogFragment.TAG) == null) {
SendAnalyticsBottomSheetDialogFragment fragment = new SendAnalyticsBottomSheetDialogFragment(); SendAnalyticsBottomSheetDialogFragment fragment = new SendAnalyticsBottomSheetDialogFragment();
fragment.setTargetFragment(target, 0);
fragment.show(fm, SendAnalyticsBottomSheetDialogFragment.TAG); fragment.show(fm, SendAnalyticsBottomSheetDialogFragment.TAG);
OsmandSettings settings = app.getSettings(); OsmandSettings settings = app.getSettings();
@ -190,4 +201,10 @@ public class SendAnalyticsBottomSheetDialogFragment extends MenuBottomSheetDialo
LOG.error("showInstance", e); LOG.error("showInstance", e);
} }
} }
public interface OnSendAnalyticsPrefsUpdate {
void onAnalyticsPrefsUpdate();
}
} }

View file

@ -73,6 +73,7 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl
if (view != null) { if (view != null) {
AndroidUtils.addStatusBarPadding21v(getContext(), view); AndroidUtils.addStatusBarPadding21v(getContext(), view);
createToolbar(inflater, view); createToolbar(inflater, view);
setDivider(null);
} }
return view; return view;
@ -110,7 +111,10 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl
view.findViewById(R.id.close_button).setOnClickListener(new View.OnClickListener() { view.findViewById(R.id.close_button).setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
getActivity().getSupportFragmentManager().popBackStack(); MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
mapActivity.onBackPressed();
}
} }
}); });
View switchProfile = view.findViewById(R.id.switch_profile_button); View switchProfile = view.findViewById(R.id.switch_profile_button);
@ -244,11 +248,9 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl
} }
public void updateAllSettings() { public void updateAllSettings() {
String sharedPreferencesName = OsmandSettings.getSharedPreferencesName(getSelectedAppMode());
getPreferenceManager().setSharedPreferencesName(sharedPreferencesName);
updateToolbar(getView());
getPreferenceScreen().removeAll(); getPreferenceScreen().removeAll();
updatePreferencesScreen(); updatePreferencesScreen();
updateToolbar(getView());
} }
@XmlRes @XmlRes
@ -277,6 +279,11 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl
return -1; return -1;
} }
@ColorRes
protected int getActiveProfileColor() {
return getSelectedAppMode().getIconColorInfo().getColor(isNightMode());
}
protected void registerPreference(Preference preference) { protected void registerPreference(Preference preference) {
if (preference != null) { if (preference != null) {
preference.setOnPreferenceChangeListener(this); preference.setOnPreferenceChangeListener(this);
@ -352,16 +359,21 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl
return iconsCache; return iconsCache;
} }
protected Drawable getIcon(@DrawableRes int id, @ColorRes int colorId) {
UiUtilities cache = getIconsCache();
return cache != null ? cache.getIcon(id, colorId) : null;
}
protected Drawable getIcon(@DrawableRes int id) { protected Drawable getIcon(@DrawableRes int id) {
UiUtilities cache = getIconsCache(); UiUtilities cache = getIconsCache();
return cache != null ? cache.getIcon(id) : null; return cache != null ? cache.getIcon(id) : null;
} }
protected Drawable getActiveIcon(@DrawableRes int id) {
UiUtilities cache = getIconsCache();
return cache != null ? cache.getIcon(id, getActiveProfileColor()) : null;
}
protected Drawable getIcon(@DrawableRes int id, @ColorRes int colorId) {
UiUtilities cache = getIconsCache();
return cache != null ? cache.getIcon(id, colorId) : null;
}
protected Drawable getContentIcon(@DrawableRes int id) { protected Drawable getContentIcon(@DrawableRes int id) {
UiUtilities cache = getIconsCache(); UiUtilities cache = getIconsCache();
return cache != null ? cache.getThemedIcon(id) : null; return cache != null ? cache.getThemedIcon(id) : null;

View file

@ -1,11 +1,15 @@
package net.osmand.plus.settings; package net.osmand.plus.settings;
import android.app.Activity;
import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.support.v14.preference.SwitchPreference; import android.support.v14.preference.SwitchPreference;
import android.support.v7.preference.Preference; import android.support.v7.preference.Preference;
import android.widget.Toast;
import net.osmand.aidl.OsmandAidlApi;
import net.osmand.aidl.OsmandAidlApi.ConnectedApp; import net.osmand.aidl.OsmandAidlApi.ConnectedApp;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
@ -32,6 +36,7 @@ public class ConfigureProfileFragment extends BaseSettingsFragment {
return R.layout.profile_preference_toolbar_big; return R.layout.profile_preference_toolbar_big;
} }
@Override
protected String getToolbarTitle() { protected String getToolbarTitle() {
return getString(R.string.configure_profile); return getString(R.string.configure_profile);
} }
@ -50,69 +55,99 @@ public class ConfigureProfileFragment extends BaseSettingsFragment {
setupOsmandPluginsPref(); setupOsmandPluginsPref();
} }
private void setupConfigureMapPref() {
Context ctx = getContext();
if (ctx == null) {
return;
}
Preference configureMap = findPreference("configure_map");
configureMap.setIcon(getContentIcon(R.drawable.ic_action_layers_dark));
Intent intent = new Intent(ctx, MapActivity.class);
intent.putExtra(OPEN_CONFIG_ON_MAP, MAP_CONFIG);
intent.putExtra(SELECTED_ITEM, getSelectedAppMode().getStringKey());
configureMap.setIntent(intent);
}
private void setupConnectedAppsPref() { private void setupConnectedAppsPref() {
List<ConnectedApp> connectedApps = getMyApplication().getAidlApi().getConnectedApps(); OsmandApplication app = getMyApplication();
if (app == null) {
return;
}
List<ConnectedApp> connectedApps = app.getAidlApi().getConnectedApps();
for (ConnectedApp connectedApp : connectedApps) { for (ConnectedApp connectedApp : connectedApps) {
SwitchPreference preference = new SwitchPreference(getContext()); SwitchPreference preference = new SwitchPreference(app);
preference.setPersistent(false);
preference.setKey(connectedApp.getPack()); preference.setKey(connectedApp.getPack());
preference.setTitle(connectedApp.getName()); preference.setTitle(connectedApp.getName());
preference.setIcon(connectedApp.getIcon()); preference.setIcon(connectedApp.getIcon());
preference.setChecked(connectedApp.isEnabled()); preference.setChecked(connectedApp.isEnabled());
preference.setLayoutResource(R.layout.preference_dialog_and_switch); preference.setLayoutResource(R.layout.preference_switch);
getPreferenceScreen().addPreference(preference); getPreferenceScreen().addPreference(preference);
} }
} }
private void setupOsmandPluginsPref() { private void setupOsmandPluginsPref() {
Context ctx = getContext();
if (ctx == null) {
return;
}
List<OsmandPlugin> plugins = OsmandPlugin.getVisiblePlugins(); List<OsmandPlugin> plugins = OsmandPlugin.getVisiblePlugins();
for (OsmandPlugin plugin : plugins) { for (OsmandPlugin plugin : plugins) {
SwitchPreferenceEx preference = new SwitchPreferenceEx(getContext()); SwitchPreferenceEx preference = new SwitchPreferenceEx(ctx);
preference.setPersistent(false);
preference.setKey(plugin.getId()); preference.setKey(plugin.getId());
preference.setTitle(plugin.getName()); preference.setTitle(plugin.getName());
preference.setIcon(getContentIcon(plugin.getLogoResourceId())); preference.setIcon(getPluginIcon(plugin));
preference.setChecked(plugin.isActive()); preference.setChecked(plugin.isActive());
preference.setLayoutResource(R.layout.preference_dialog_and_switch); preference.setLayoutResource(R.layout.preference_dialog_and_switch);
preference.setIntent(getPluginIntent(plugin));
Intent intent = new Intent(getContext(), PluginActivity.class);
intent.putExtra(PluginActivity.EXTRA_PLUGIN_ID, plugin.getId());
preference.setIntent(intent);
getPreferenceScreen().addPreference(preference); getPreferenceScreen().addPreference(preference);
} }
} }
private void setupConfigureMapPref() { private Drawable getPluginIcon(OsmandPlugin plugin) {
Preference configureMap = findPreference("configure_map"); int iconResId = plugin.getLogoResourceId();
configureMap.setIcon(getContentIcon(R.drawable.ic_action_layers_dark)); return plugin.isActive() ? getActiveIcon(iconResId) : getContentIcon(iconResId);
Intent intent = new Intent(getActivity(), MapActivity.class);
intent.putExtra(OPEN_CONFIG_ON_MAP, MAP_CONFIG);
intent.putExtra(SELECTED_ITEM, getSelectedAppMode().getStringKey());
configureMap.setIntent(intent);
} }
@Override private Intent getPluginIntent(OsmandPlugin plugin) {
public boolean onPreferenceClick(Preference preference) { Intent intent;
if (preference.getKey().equals("configure_map")) { final Class<? extends Activity> settingsActivity = plugin.getSettingsActivity();
getActivity().getSupportFragmentManager().beginTransaction().remove(this).commit(); if (settingsActivity != null && !plugin.needsInstallation()) {
return false; intent = new Intent(getContext(), settingsActivity);
} else {
intent = new Intent(getContext(), PluginActivity.class);
intent.putExtra(PluginActivity.EXTRA_PLUGIN_ID, plugin.getId());
} }
return intent;
return super.onPreferenceClick(preference);
} }
@Override @Override
public boolean onPreferenceChange(Preference preference, Object newValue) { public boolean onPreferenceChange(Preference preference, Object newValue) {
String key = preference.getKey(); String key = preference.getKey();
OsmandPlugin plugin = OsmandPlugin.getPlugin(key); OsmandPlugin plugin = OsmandPlugin.getPlugin(key);
if (plugin != null) { if (plugin != null) {
Toast.makeText(getActivity(), "Change " + plugin.getId(), Toast.LENGTH_LONG).show(); if (newValue instanceof Boolean) {
return OsmandPlugin.enablePlugin(getActivity(), app, plugin, (Boolean) newValue); if ((plugin.isActive() || !plugin.needsInstallation())) {
if (OsmandPlugin.enablePlugin(getActivity(), app, plugin, (Boolean) newValue)) {
updateAllSettings();
return true;
} }
ConnectedApp connectedApp = getMyApplication().getAidlApi().getConnectedApp(key); } else if (plugin.needsInstallation() && preference.getIntent() != null) {
startActivity(preference.getIntent());
}
}
return false;
}
OsmandAidlApi aidlApi = app.getAidlApi();
ConnectedApp connectedApp = aidlApi.getConnectedApp(key);
if (connectedApp != null) { if (connectedApp != null) {
return getMyApplication().getAidlApi().switchEnabled(connectedApp); return aidlApi.switchEnabled(connectedApp);
} }
return super.onPreferenceChange(preference, newValue); return super.onPreferenceChange(preference, newValue);

View file

@ -2,38 +2,36 @@ package net.osmand.plus.settings;
import android.app.Activity; import android.app.Activity;
import android.app.Dialog; import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Build; import android.os.Build;
import android.os.Bundle;
import android.os.StatFs; import android.os.StatFs;
import android.support.v14.preference.SwitchPreference; import android.support.v14.preference.SwitchPreference;
import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentManager;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
import android.support.v7.preference.Preference; import android.support.v7.preference.Preference;
import android.support.v7.widget.Toolbar; import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater; import android.util.Pair;
import android.view.View; import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText; import android.widget.EditText;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.Toast; import android.widget.Toast;
import net.osmand.IProgress; import net.osmand.IProgress;
import net.osmand.IndexConstants; import net.osmand.IndexConstants;
import net.osmand.StateChangedListener;
import net.osmand.ValueHolder; import net.osmand.ValueHolder;
import net.osmand.plus.ApplicationMode; import net.osmand.plus.ApplicationMode;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.Version; import net.osmand.plus.Version;
import net.osmand.plus.activities.SettingsBaseActivity;
import net.osmand.plus.activities.SettingsGeneralActivity;
import net.osmand.plus.dashboard.DashChooseAppDirFragment; import net.osmand.plus.dashboard.DashChooseAppDirFragment;
import net.osmand.plus.dialogs.ConfigureMapMenu;
import net.osmand.plus.dialogs.SendAnalyticsBottomSheetDialogFragment; import net.osmand.plus.dialogs.SendAnalyticsBottomSheetDialogFragment;
import net.osmand.plus.download.DownloadActivity; import net.osmand.plus.download.DownloadActivity;
import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.settings.preferences.ListPreferenceEx; import net.osmand.plus.settings.preferences.ListPreferenceEx;
import net.osmand.plus.settings.preferences.SwitchPreferenceEx; import net.osmand.plus.settings.preferences.SwitchPreferenceEx;
@ -41,13 +39,11 @@ import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
public class GlobalSettingsFragment extends BaseSettingsFragment { public class GlobalSettingsFragment extends BaseSettingsFragment implements SendAnalyticsBottomSheetDialogFragment.OnSendAnalyticsPrefsUpdate, OnPreferenceChanged {
public static final String TAG = "GlobalSettingsFragment"; public static final String TAG = "GlobalSettingsFragment";
private Preference applicationDir; private static final String SEND_ANONYMOUS_DATA_PREF_ID = "send_anonymous_data";
private boolean permissionRequested;
private boolean permissionGranted;
@Override @Override
protected int getPreferencesResId() { protected int getPreferencesResId() {
@ -71,195 +67,64 @@ public class GlobalSettingsFragment extends BaseSettingsFragment {
setupExternalStorageDirPref(); setupExternalStorageDirPref();
setupSendAnonymousDataPref(); setupSendAnonymousDataPref();
setupDoNotShowStartupMessagesPref();
setupEnableProxyPref(); setupEnableProxyPref();
} }
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { public boolean onPreferenceChange(Preference preference, Object newValue) {
View view = super.onCreateView(inflater, container, savedInstanceState); String prefId = preference.getKey();
AndroidUiHelper.updateVisibility(view.findViewById(R.id.ProgressBar), false); if (prefId.equals(SEND_ANONYMOUS_DATA_PREF_ID)) {
if (newValue instanceof Boolean) {
return view; boolean enabled = (Boolean) newValue;
if (enabled) {
FragmentManager fragmentManager = getFragmentManager();
if (fragmentManager != null) {
SendAnalyticsBottomSheetDialogFragment.showInstance(app, fragmentManager, this);
}
} else {
settings.SEND_ANONYMOUS_MAP_DOWNLOADS_DATA.set(false);
settings.SEND_ANONYMOUS_APP_USAGE_DATA.set(false);
return true;
}
}
return false;
} }
private void setupDefaultAppModePref() { return super.onPreferenceChange(preference, newValue);
ApplicationMode selectedMode = settings.DEFAULT_APPLICATION_MODE.get();
int iconRes = selectedMode.getIconRes();
String title = selectedMode.toHumanString(getContext());
ApplicationMode[] appModes = ApplicationMode.values(app).toArray(new ApplicationMode[0]);
String[] entries = new String[appModes.length];
for (int i = 0; i < entries.length; i++) {
entries[i] = appModes[i].toHumanString(app);
} }
final ListPreferenceEx defaultApplicationMode = (ListPreferenceEx) findPreference(settings.DEFAULT_APPLICATION_MODE.getId());
defaultApplicationMode.setIcon(getContentIcon(iconRes));
defaultApplicationMode.setSummary(title);
defaultApplicationMode.setEntries(entries);
defaultApplicationMode.setEntryValues(appModes);
}
private void setupPreferredLocalePref() {
// See language list and statistics at: https://hosted.weblate.org/projects/osmand/main/
// Hardy maintenance 2016-05-29:
// - Include languages if their translation is >= ~10% (but any language will be visible if it is the device's system locale)
// - Mark as "incomplete" if < ~80%
String incompleteSuffix = " (" + getString(R.string.incomplete_locale) + ")";
// Add " (Device language)" to system default entry in Latin letters, so it can be more easily identified if a foreign language has been selected by mistake
String latinSystemDefaultSuffix = " (" + getString(R.string.system_locale_no_translate) + ")";
//getResources().getAssets().getLocales();
String[] entrieValues = new String[] {"",
"en",
"af",
"ar",
"ast",
"az",
"be",
//"be_BY",
"bg",
"ca",
"cs",
"cy",
"da",
"de",
"el",
"en_GB",
"eo",
"es",
"es_AR",
"es_US",
"eu",
"fa",
"fi",
"fr",
"gl",
"he",
"hr",
"hsb",
"hu",
"hy",
"is",
"it",
"ja",
"ka",
"kab",
"kn",
"ko",
"lt",
"lv",
"ml",
"mr",
"nb",
"nl",
"nn",
"oc",
"pl",
"pt",
"pt_BR",
"ro",
"ru",
"sc",
"sk",
"sl",
"sr",
"sr+Latn",
"sv",
"tr",
"uk",
"vi",
"zh_CN",
"zh_TW"};
String[] entries = new String[] {getString(R.string.system_locale) + latinSystemDefaultSuffix,
getString(R.string.lang_en),
getString(R.string.lang_af) + incompleteSuffix,
getString(R.string.lang_ar),
getString(R.string.lang_ast) + incompleteSuffix,
getString(R.string.lang_az),
getString(R.string.lang_be),
// getString(R.string.lang_be_by),
getString(R.string.lang_bg),
getString(R.string.lang_ca),
getString(R.string.lang_cs),
getString(R.string.lang_cy) + incompleteSuffix,
getString(R.string.lang_da),
getString(R.string.lang_de),
getString(R.string.lang_el) + incompleteSuffix,
getString(R.string.lang_en_gb),
getString(R.string.lang_eo),
getString(R.string.lang_es),
getString(R.string.lang_es_ar),
getString(R.string.lang_es_us),
getString(R.string.lang_eu),
getString(R.string.lang_fa),
getString(R.string.lang_fi) + incompleteSuffix,
getString(R.string.lang_fr),
getString(R.string.lang_gl),
getString(R.string.lang_he) + incompleteSuffix,
getString(R.string.lang_hr) + incompleteSuffix,
getString(R.string.lang_hsb) + incompleteSuffix,
getString(R.string.lang_hu),
getString(R.string.lang_hy),
getString(R.string.lang_is),
getString(R.string.lang_it),
getString(R.string.lang_ja),
getString(R.string.lang_ka) + incompleteSuffix,
getString(R.string.lang_kab) + incompleteSuffix,
getString(R.string.lang_kn) + incompleteSuffix,
getString(R.string.lang_ko),
getString(R.string.lang_lt),
getString(R.string.lang_lv),
getString(R.string.lang_ml) + incompleteSuffix,
getString(R.string.lang_mr) + incompleteSuffix,
getString(R.string.lang_nb),
getString(R.string.lang_nl),
getString(R.string.lang_nn) + incompleteSuffix,
getString(R.string.lang_oc) + incompleteSuffix,
getString(R.string.lang_pl),
getString(R.string.lang_pt),
getString(R.string.lang_pt_br),
getString(R.string.lang_ro) + incompleteSuffix,
getString(R.string.lang_ru),
getString(R.string.lang_sc),
getString(R.string.lang_sk),
getString(R.string.lang_sl),
getString(R.string.lang_sr) + incompleteSuffix,
getString(R.string.lang_sr_latn) + incompleteSuffix,
getString(R.string.lang_sv),
getString(R.string.lang_tr),
getString(R.string.lang_uk),
getString(R.string.lang_vi) + incompleteSuffix,
getString(R.string.lang_zh_cn) + incompleteSuffix,
getString(R.string.lang_zh_tw)};
String[] valuesPl = ConfigureMapMenu.getSortedMapNamesIds(getContext(), entries, entries);
String[] idsPl = ConfigureMapMenu.getSortedMapNamesIds(getContext(), entrieValues, entries);
ListPreferenceEx preferredLocale = (ListPreferenceEx) findPreference(settings.PREFERRED_LOCALE.getId());
preferredLocale.setIcon(getContentIcon(R.drawable.ic_action_map_language));
preferredLocale.setSummary(settings.PREFERRED_LOCALE.get());
preferredLocale.setEntries(valuesPl);
preferredLocale.setEntryValues(idsPl);
// Add " (Display language)" to menu title in Latin letters for all non-en languages
if (!getResources().getString(R.string.preferred_locale).equals(getResources().getString(R.string.preferred_locale_no_translate))) {
preferredLocale.setTitle(getString(R.string.preferred_locale) + " (" + getString(R.string.preferred_locale_no_translate) + ")");
}
// This setting now only in "Confgure map" menu
//String[] values = ConfigureMapMenu.getMapNamesValues(this, ConfigureMapMenu.mapNamesIds);
//String[] ids = ConfigureMapMenu.getSortedMapNamesIds(this, ConfigureMapMenu.mapNamesIds, values);
//registerListPreference(settings.MAP_PREFERRED_LOCALE, screen, ConfigureMapMenu.getMapNamesValues(this, ids), ids);
settings.PREFERRED_LOCALE.addListener(new StateChangedListener<String>() {
@Override @Override
public void stateChanged(String change) { public boolean onPreferenceClick(Preference preference) {
String prefId = preference.getKey();
if (prefId.equals(OsmandSettings.EXTERNAL_STORAGE_DIR)) {
showAppDirDialog();
return true;
}
return super.onPreferenceClick(preference);
}
@Override
public void onDisplayPreferenceDialog(Preference preference) {
String prefId = preference.getKey();
if (prefId.equals(SEND_ANONYMOUS_DATA_PREF_ID)) {
FragmentManager fragmentManager = getFragmentManager();
if (fragmentManager != null) {
SendAnalyticsBottomSheetDialogFragment.showInstance(app, fragmentManager, this);
}
} else {
super.onDisplayPreferenceDialog(preference);
}
}
@Override
public void onPreferenceChanged(String prefId) {
if (prefId.equals(settings.DEFAULT_APPLICATION_MODE.getId())) {
setupDefaultAppModePref();
} else if (prefId.equals(settings.PREFERRED_LOCALE.getId())) {
// recreate activity to update locale // recreate activity to update locale
Activity activity = getActivity(); Activity activity = getActivity();
OsmandApplication app = getMyApplication(); OsmandApplication app = getMyApplication();
@ -268,7 +133,97 @@ public class GlobalSettingsFragment extends BaseSettingsFragment {
activity.recreate(); activity.recreate();
} }
} }
}); }
@Override
public void onAnalyticsPrefsUpdate() {
setupSendAnonymousDataPref();
}
private void setupDefaultAppModePref() {
OsmandApplication app = getMyApplication();
if (app == null) {
return;
}
ApplicationMode selectedMode = settings.DEFAULT_APPLICATION_MODE.get();
ApplicationMode[] appModes = ApplicationMode.values(app).toArray(new ApplicationMode[0]);
String[] entries = new String[appModes.length];
String[] entryValues = new String[appModes.length];
for (int i = 0; i < entries.length; i++) {
entries[i] = appModes[i].toHumanString(app);
entryValues[i] = appModes[i].getStringKey();
}
ListPreferenceEx defaultApplicationMode = (ListPreferenceEx) findPreference(settings.DEFAULT_APPLICATION_MODE.getId());
defaultApplicationMode.setIcon(getContentIcon(selectedMode.getIconRes()));
defaultApplicationMode.setEntries(entries);
defaultApplicationMode.setEntryValues(entryValues);
}
private void setupPreferredLocalePref() {
Context ctx = getContext();
if (ctx == null) {
return;
}
ListPreferenceEx preferredLocale = (ListPreferenceEx) findPreference(settings.PREFERRED_LOCALE.getId());
preferredLocale.setIcon(getContentIcon(R.drawable.ic_action_map_language));
preferredLocale.setSummary(settings.PREFERRED_LOCALE.get());
Pair<String[], String[]> preferredLocaleInfo = SettingsGeneralActivity.getPreferredLocaleIdsAndValues(ctx);
if (preferredLocaleInfo != null) {
preferredLocale.setEntries(preferredLocaleInfo.first);
preferredLocale.setEntryValues(preferredLocaleInfo.second);
}
// Add " (Display language)" to menu title in Latin letters for all non-en languages
if (!getResources().getString(R.string.preferred_locale).equals(getResources().getString(R.string.preferred_locale_no_translate))) {
preferredLocale.setTitle(getString(R.string.preferred_locale) + " (" + getString(R.string.preferred_locale_no_translate) + ")");
}
}
private void setupSendAnonymousDataPref() {
boolean enabled = settings.SEND_ANONYMOUS_MAP_DOWNLOADS_DATA.get() || settings.SEND_ANONYMOUS_APP_USAGE_DATA.get();
SwitchPreference sendAnonymousData = (SwitchPreference) findPreference(SEND_ANONYMOUS_DATA_PREF_ID);
sendAnonymousData.setChecked(enabled);
}
private void setupEnableProxyPref() {
SwitchPreferenceEx enableProxy = (SwitchPreferenceEx) findPreference(settings.ENABLE_PROXY.getId());
enableProxy.setIcon(getContentIcon(R.drawable.ic_action_proxy));
}
// -------------------------- APP DIR PREF --------------------------------------------------------
private Preference applicationDir;
private boolean permissionRequested;
private boolean permissionGranted;
@Override
public void onResume() {
super.onResume();
if (permissionRequested) {
showAppDirDialogV19();
permissionRequested = false;
}
}
@Override
public void onRequestPermissionsResult(int requestCode,
String permissions[], int[] grantResults) {
permissionRequested = requestCode == DownloadActivity.PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE;
if (permissionRequested
&& grantResults.length > 0
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
permissionGranted = true;
} else {
permissionGranted = false;
Toast.makeText(getContext(),
R.string.missing_write_external_storage_permission,
Toast.LENGTH_LONG).show();
}
} }
private void setupExternalStorageDirPref() { private void setupExternalStorageDirPref() {
@ -317,55 +272,6 @@ public class GlobalSettingsFragment extends BaseSettingsFragment {
return ""; return "";
} }
private void setupSendAnonymousDataPref() {
SwitchPreferenceEx sendAnonymousData = (SwitchPreferenceEx) findPreference(settings.SEND_ANONYMOUS_DATA.getId());
}
private void setupDoNotShowStartupMessagesPref() {
SwitchPreference doNotShowStartupMessages = (SwitchPreference) findPreference(settings.DO_NOT_SHOW_STARTUP_MESSAGES.getId());
}
private void setupEnableProxyPref() {
SwitchPreferenceEx enableProxy = (SwitchPreferenceEx) findPreference(settings.ENABLE_PROXY.getId());
enableProxy.setIcon(getContentIcon(R.drawable.ic_action_proxy));
}
@Override
public void onDisplayPreferenceDialog(Preference preference) {
if (preference.getKey().equals(settings.SEND_ANONYMOUS_DATA.getId())) {
FragmentManager fragmentManager = getFragmentManager();
if (fragmentManager != null) {
SendAnalyticsBottomSheetDialogFragment.showInstance(app, fragmentManager);
}
} else {
super.onDisplayPreferenceDialog(preference);
}
}
@Override
public boolean onPreferenceClick(Preference preference) {
String prefId = preference.getKey();
if (prefId.equals(OsmandSettings.EXTERNAL_STORAGE_DIR)) {
showAppDirDialog();
return true;
}
return super.onPreferenceClick(preference);
}
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
String prefId = preference.getKey();
if (prefId.equals(settings.DEFAULT_APPLICATION_MODE.getId()) && newValue instanceof ApplicationMode) {
preference.setIcon(getContentIcon(((ApplicationMode) newValue).getIconRes()));
settings.APPLICATION_MODE.set((ApplicationMode) newValue);
}
return super.onPreferenceChange(preference, newValue);
}
public void showAppDirDialog() { public void showAppDirDialog() {
if (Build.VERSION.SDK_INT >= 19) { if (Build.VERSION.SDK_INT >= 19) {
showAppDirDialogV19(); showAppDirDialogV19();
@ -478,7 +384,7 @@ public class GlobalSettingsFragment extends BaseSettingsFragment {
} }
protected void onPostExecute(List<String> result) { protected void onPostExecute(List<String> result) {
showWarnings(result); SettingsBaseActivity.showWarnings(getMyApplication(), result);
toolbar.setTitle(oldTitle); toolbar.setTitle(oldTitle);
toolbar.setSubtitle(""); toolbar.setSubtitle("");
setProgressVisibility(false); setProgressVisibility(false);
@ -494,50 +400,4 @@ public class GlobalSettingsFragment extends BaseSettingsFragment {
getView().findViewById(R.id.ProgressBar).setVisibility(View.GONE); getView().findViewById(R.id.ProgressBar).setVisibility(View.GONE);
} }
} }
protected void showWarnings(List<String> warnings) {
if (!warnings.isEmpty()) {
final StringBuilder b = new StringBuilder();
boolean f = true;
for (String w : warnings) {
if (f) {
f = false;
} else {
b.append('\n');
}
b.append(w);
}
app.runInUIThread(new Runnable() {
@Override
public void run() {
Toast.makeText(getContext(), b.toString(), Toast.LENGTH_LONG).show();
}
});
}
}
@Override
public void onResume() {
super.onResume();
if (permissionRequested) {
showAppDirDialogV19();
permissionRequested = false;
}
}
@Override
public void onRequestPermissionsResult(int requestCode,
String permissions[], int[] grantResults) {
permissionRequested = requestCode == DownloadActivity.PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE;
if (permissionRequested
&& grantResults.length > 0
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
permissionGranted = true;
} else {
permissionGranted = false;
Toast.makeText(getContext(),
R.string.missing_write_external_storage_permission,
Toast.LENGTH_LONG).show();
}
}
} }

View file

@ -53,7 +53,7 @@ public class MainSettingsFragment extends BaseSettingsFragment {
ApplicationMode selectedMode = getSelectedAppMode(); ApplicationMode selectedMode = getSelectedAppMode();
int iconRes = selectedMode.getIconRes(); int iconRes = selectedMode.getIconRes();
int iconColor = selectedMode.getIconColorInfo().getColor(isNightMode()); int iconColor = getActiveProfileColor();
String title = selectedMode.toHumanString(getContext()); String title = selectedMode.toHumanString(getContext());
String profileType; String profileType;
@ -73,7 +73,7 @@ public class MainSettingsFragment extends BaseSettingsFragment {
ApplicationMode selectedMode = getSelectedAppMode(); ApplicationMode selectedMode = getSelectedAppMode();
int iconRes = selectedMode.getIconRes(); int iconRes = selectedMode.getIconRes();
int iconColor = selectedMode.getIconColorInfo().getColor(isNightMode()); int iconColor = getActiveProfileColor();
String title = selectedMode.toHumanString(getContext()); String title = selectedMode.toHumanString(getContext());
String profileType; String profileType;

View file

@ -0,0 +1,7 @@
package net.osmand.plus.settings;
public interface OnPreferenceChanged {
void onPreferenceChanged(String prefId);
}

View file

@ -34,15 +34,10 @@ public class ProxySettingsFragment extends BaseSettingsFragment {
Preference mapDuringNavigationInfo = findPreference("proxy_preferences_info"); Preference mapDuringNavigationInfo = findPreference("proxy_preferences_info");
mapDuringNavigationInfo.setIcon(getContentIcon(R.drawable.ic_action_info_dark)); mapDuringNavigationInfo.setIcon(getContentIcon(R.drawable.ic_action_info_dark));
setupEnableProxyPref();
setupProxyHostPref(); setupProxyHostPref();
setupProxyPortPref(); setupProxyPortPref();
} }
private void setupEnableProxyPref() {
SwitchPreference enableProxyPref = (SwitchPreference) findPreference(settings.ENABLE_PROXY.getId());
}
private void setupProxyHostPref() { private void setupProxyHostPref() {
EditTextPreferenceEx hostPref = (EditTextPreferenceEx) findPreference(settings.PROXY_HOST.getId()); EditTextPreferenceEx hostPref = (EditTextPreferenceEx) findPreference(settings.PROXY_HOST.getId());
hostPref.setPersistent(false); hostPref.setPersistent(false);

View file

@ -135,6 +135,10 @@ public class SingleSelectPreferenceBottomSheet extends MenuBottomSheetDialogFrag
listPreference.setValue(value); listPreference.setValue(value);
} }
} }
Fragment target = getTargetFragment();
if (target instanceof OnPreferenceChanged) {
((OnPreferenceChanged) target).onPreferenceChanged(listPreference.getKey());
}
dismiss(); dismiss();
} }

View file

@ -6,6 +6,7 @@ import android.support.v7.preference.DialogPreference;
import android.support.v7.preference.PreferenceDataStore; import android.support.v7.preference.PreferenceDataStore;
import android.util.AttributeSet; import android.util.AttributeSet;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.OsmandSettings.PreferencesDataStore; import net.osmand.plus.OsmandSettings.PreferencesDataStore;
public class ListPreferenceEx extends DialogPreference { public class ListPreferenceEx extends DialogPreference {
@ -128,6 +129,8 @@ public class ListPreferenceEx extends DialogPreference {
Object value = ((PreferencesDataStore) dataStore).getValue(getKey(), defaultValue); Object value = ((PreferencesDataStore) dataStore).getValue(getKey(), defaultValue);
if (value instanceof Enum) { if (value instanceof Enum) {
return ((Enum) value).ordinal(); return ((Enum) value).ordinal();
} else if (value instanceof ApplicationMode) {
return ((ApplicationMode) value).getStringKey();
} else { } else {
return value; return value;
} }

View file

@ -34,7 +34,7 @@ public class SwitchPreferenceEx extends SwitchPreference {
@Override @Override
protected void onClick() { protected void onClick() {
if (getFragment() == null) { if (getFragment() == null && getIntent() == null) {
getPreferenceManager().showDialog(this); getPreferenceManager().showDialog(this);
} }
} }