Add profile dialog to settings

This commit is contained in:
Victor Shcherb 2013-07-16 01:43:40 +02:00
parent f7aa832c9e
commit 812d010b13
8 changed files with 49 additions and 14 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.4 KiB

View file

@ -2,7 +2,7 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="vertical" > android:orientation="horizontal" >
<ToggleButton <ToggleButton
android:id="@+id/DefaultButton" android:id="@+id/DefaultButton"

View file

@ -465,13 +465,17 @@ public class MapActivityActions implements DialogProvider {
} }
public static View showActivityActionsDialog(Activity a, AlertDialog.Builder builder, final Set<ApplicationMode> selected) { public static View showActivityActionsDialog(Activity a, final Set<ApplicationMode> selected, boolean showDefault) {
View view = a.getLayoutInflater().inflate(R.layout.mode_toggles, null); View view = a.getLayoutInflater().inflate(R.layout.mode_toggles, null);
OsmandSettings settings = ((OsmandApplication) a.getApplication()).getSettings(); OsmandSettings settings = ((OsmandApplication) a.getApplication()).getSettings();
boolean lc = settings.isLightContentMenu(); boolean lc = settings.isLightContentMenu();
final ToggleButton[] buttons = new ToggleButton[ApplicationMode.values().length]; final ToggleButton[] buttons = new ToggleButton[ApplicationMode.values().length];
buttons[ApplicationMode.DEFAULT.ordinal()] = (ToggleButton) view.findViewById(R.id.DefaultButton); if(showDefault) {
buttons[ApplicationMode.DEFAULT.ordinal()].setButtonDrawable(R.drawable.ic_action_globus_light ); buttons[ApplicationMode.DEFAULT.ordinal()] = (ToggleButton) view.findViewById(R.id.DefaultButton);
buttons[ApplicationMode.DEFAULT.ordinal()].setButtonDrawable(R.drawable.ic_browse_map );
} else {
view.findViewById(R.id.DefaultButton).setVisibility(View.GONE);
}
buttons[ApplicationMode.CAR.ordinal()] = (ToggleButton) view.findViewById(R.id.CarButton); buttons[ApplicationMode.CAR.ordinal()] = (ToggleButton) view.findViewById(R.id.CarButton);
buttons[ApplicationMode.CAR.ordinal()].setButtonDrawable(R.drawable.ic_car ); buttons[ApplicationMode.CAR.ordinal()].setButtonDrawable(R.drawable.ic_car );
buttons[ApplicationMode.BICYCLE.ordinal()] = (ToggleButton) view.findViewById(R.id.BicycleButton); buttons[ApplicationMode.BICYCLE.ordinal()] = (ToggleButton) view.findViewById(R.id.BicycleButton);

View file

@ -3,9 +3,11 @@ package net.osmand.plus.activities;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Set;
import net.osmand.access.AccessibleToast; import net.osmand.access.AccessibleToast;
import net.osmand.plus.ApplicationMode; import net.osmand.plus.ApplicationMode;
@ -19,6 +21,7 @@ import android.app.AlertDialog;
import android.app.AlertDialog.Builder; import android.app.AlertDialog.Builder;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.DialogInterface.OnMultiChoiceClickListener; import android.content.DialogInterface.OnMultiChoiceClickListener;
import android.os.Bundle; import android.os.Bundle;
import android.preference.CheckBoxPreference; import android.preference.CheckBoxPreference;
@ -28,6 +31,7 @@ import android.preference.Preference;
import android.preference.Preference.OnPreferenceChangeListener; import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.Preference.OnPreferenceClickListener; import android.preference.Preference.OnPreferenceClickListener;
import android.preference.PreferenceScreen; import android.preference.PreferenceScreen;
import android.view.View;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import android.widget.Toast; import android.widget.Toast;
@ -289,16 +293,7 @@ public abstract class SettingsBaseActivity extends SherlockPreferenceActivity im
super.onResume(); super.onResume();
if (profileSettings) { if (profileSettings) {
previousAppMode = settings.getApplicationMode(); previousAppMode = settings.getApplicationMode();
int ind = 0; boolean found = setSelectedAppMode(previousAppMode);
boolean found = false;
for (ApplicationMode a : modes) {
if (previousAppMode == a) {
getSupportActionBar().setSelectedNavigationItem(ind);
found = true;
break;
}
ind++;
}
if (!found) { if (!found) {
getSupportActionBar().setSelectedNavigationItem(0); getSupportActionBar().setSelectedNavigationItem(0);
} }
@ -307,6 +302,37 @@ public abstract class SettingsBaseActivity extends SherlockPreferenceActivity im
} }
} }
protected void profileDialog() {
Builder b = new AlertDialog.Builder(this);
final Set<ApplicationMode> selected = new LinkedHashSet<ApplicationMode>();
View v = MapActivityActions.showActivityActionsDialog(this, selected, false);
b.setView(v);
b.setPositiveButton(R.string.default_buttons_ok, new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if(selected.size() > 0) {
setSelectedAppMode(selected.iterator().next());
}
}
});
b.show();
}
protected boolean setSelectedAppMode(ApplicationMode am) {
int ind = 0;
boolean found = false;
for (ApplicationMode a : modes) {
if (am == a) {
getSupportActionBar().setSelectedNavigationItem(ind);
found = true;
break;
}
ind++;
}
return found;
}
@Override @Override
protected void onPause() { protected void onPause() {
super.onPause(); super.onPause();

View file

@ -95,11 +95,15 @@ public class SettingsNavigationActivity extends SettingsBaseActivity {
speakAlarms = (Preference) screen.findPreference("speak_routing_alarms"); speakAlarms = (Preference) screen.findPreference("speak_routing_alarms");
speakAlarms.setOnPreferenceClickListener(this); speakAlarms.setOnPreferenceClickListener(this);
profileDialog();
} }
private void reloadVoiceListPreference(PreferenceScreen screen) { private void reloadVoiceListPreference(PreferenceScreen screen) {
String[] entries; String[] entries;
String[] entrieValues; String[] entrieValues;

View file

@ -49,6 +49,7 @@ public class SettingsMonitoringActivity extends SettingsBaseActivity {
if(REGISTER_BG_SETTINGS) { if(REGISTER_BG_SETTINGS) {
registerBackgroundSettings(); registerBackgroundSettings();
} }
profileDialog();
} }