Updated functionality of select modes button
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.3 KiB |
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.3 KiB |
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.3 KiB |
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.3 KiB |
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.5 KiB |
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.5 KiB |
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 1.4 KiB |
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 1.4 KiB |
Before Width: | Height: | Size: 1.7 KiB After Width: | Height: | Size: 1.7 KiB |
Before Width: | Height: | Size: 1.7 KiB After Width: | Height: | Size: 1.7 KiB |
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 1.6 KiB |
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 1.6 KiB |
|
@ -1,6 +1,7 @@
|
|||
package net.osmand.plus;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.widget.*;
|
||||
import gnu.trove.list.array.TIntArrayList;
|
||||
|
||||
|
@ -20,18 +21,6 @@ import net.osmand.plus.activities.actions.AppModeDialog;
|
|||
|
||||
public class ContextMenuAdapter {
|
||||
|
||||
public void clearAll() {
|
||||
items.clear();
|
||||
isCategory.clear();
|
||||
itemNames.clear();
|
||||
checkListeners.clear();
|
||||
selectedList.clear();
|
||||
layoutIds.clear();
|
||||
iconList.clear();
|
||||
iconListLight.clear();
|
||||
itemDescription.clear();
|
||||
}
|
||||
|
||||
public interface OnContextMenuClick {
|
||||
//boolean return type needed to desribe if drawer needed to be close or not
|
||||
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked);
|
||||
|
@ -283,6 +272,25 @@ public class ContextMenuAdapter {
|
|||
notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
}, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialogInterface, int i) {
|
||||
//if user selects modes and none of them is set to current
|
||||
// - need to set one of them as current
|
||||
OsmandSettings settings = ((OsmandApplication) activity.getApplication()).getSettings();
|
||||
ApplicationMode currentMode = settings.APPLICATION_MODE.get();
|
||||
boolean selected = false;
|
||||
for (ApplicationMode mode : visibleModes) {
|
||||
if (mode.equals(currentMode)){
|
||||
selected = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!selected) {
|
||||
settings.APPLICATION_MODE.set(visibleModes.get(0));
|
||||
}
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
});
|
||||
}
|
||||
if (v == null || (v.getTag() != lid)) {
|
||||
|
@ -349,6 +357,4 @@ public class ContextMenuAdapter {
|
|||
return listAdapter;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -778,7 +778,7 @@ public class MapActivityActions implements DialogProvider {
|
|||
.listen(new OnContextMenuClick() {
|
||||
@Override
|
||||
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) {
|
||||
ContextMenuAdapter cm = mapActivity.getMapLayers().getMapInfoLayer().openViewConfigureDrawer();
|
||||
ContextMenuAdapter cm = mapActivity.getMapLayers().getMapInfoLayer().getViewConfigureMenuAdapter();
|
||||
prepareOptionsMenu(cm);
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -37,29 +37,33 @@ public class AppModeDialog {
|
|||
return prepareAppModeView(a, values, selected, parent, singleSelection, onClickListener);
|
||||
}
|
||||
|
||||
//special method for drawer menu
|
||||
// needed because if there's more than 4 items - the don't fit in drawer
|
||||
public static View prepareAppModeDrawerView(Activity a, List<ApplicationMode> visible, final Set<ApplicationMode> selected,
|
||||
final View.OnClickListener onClickListener) {
|
||||
final View.OnClickListener onClickListener, DialogInterface.OnClickListener onDialogOk) {
|
||||
OsmandSettings settings = ((OsmandApplication) a.getApplication()).getSettings();
|
||||
final List<ApplicationMode> values = new ArrayList<ApplicationMode>(ApplicationMode.values(settings));
|
||||
selected.add(settings.getApplicationMode());
|
||||
if (values.size() > 4) {
|
||||
return prepareAppModeDrawerView(a, visible, values, selected, onClickListener);
|
||||
return prepareAppModeDrawerView(a, visible, values, selected, onClickListener, onDialogOk);
|
||||
} else {
|
||||
return prepareAppModeView(a, values, selected, null, true, onClickListener);
|
||||
}
|
||||
}
|
||||
|
||||
private static View prepareAppModeDrawerView(Activity a, List<ApplicationMode> visible, final List<ApplicationMode> values, final Set<ApplicationMode> selected,
|
||||
final View.OnClickListener onClickListener){
|
||||
private static View prepareAppModeDrawerView(Activity a,final List<ApplicationMode> visible, final List<ApplicationMode> values,
|
||||
final Set<ApplicationMode> selected,
|
||||
final View.OnClickListener onClickListener,
|
||||
DialogInterface.OnClickListener onDialogOk){
|
||||
getVisibleModes(values, selected, visible);
|
||||
LinearLayout ll = (LinearLayout) a.getLayoutInflater().inflate(R.layout.mode_toggles, null);
|
||||
final ToggleButton[] buttons = createDrawerToggles(visible, values, a, ll);
|
||||
final ToggleButton[] buttons = createDrawerToggles(visible, values, a, ll, onDialogOk);
|
||||
final boolean[] selectionChangeLoop = new boolean[] {false};
|
||||
for (int i = 0; i < buttons.length - 1; i++) {
|
||||
if (buttons[i] != null) {
|
||||
final int ind = i;
|
||||
ToggleButton b = buttons[i];
|
||||
final ApplicationMode buttonAppMode = values.get(i);
|
||||
final ApplicationMode buttonAppMode = visible.get(i);
|
||||
b.setChecked(selected.contains(buttonAppMode));
|
||||
b.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
|
@ -69,7 +73,7 @@ public class AppModeDialog {
|
|||
}
|
||||
selectionChangeLoop[0] = true;
|
||||
try {
|
||||
handleSelection(values, selected, true, buttons, ind, buttonAppMode, isChecked);
|
||||
handleSelection(visible, selected, true, buttons, ind, buttonAppMode, isChecked);
|
||||
if (onClickListener != null) {
|
||||
onClickListener.onClick(null);
|
||||
}
|
||||
|
@ -85,7 +89,8 @@ public class AppModeDialog {
|
|||
return ll;
|
||||
}
|
||||
|
||||
private static ToggleButton[] createDrawerToggles(final List<ApplicationMode> visible, final List<ApplicationMode> modes, final Activity a, LinearLayout ll) {
|
||||
private static ToggleButton[] createDrawerToggles(final List<ApplicationMode> visible, final List<ApplicationMode> modes,
|
||||
final Activity a, LinearLayout ll, final DialogInterface.OnClickListener onDialogOk) {
|
||||
ToggleButton[] buttons = createToggles(visible, ll, a);
|
||||
ToggleButton[] newButtons = new ToggleButton[buttons.length + 1];
|
||||
for (int i = 0; i< buttons.length; i++){
|
||||
|
@ -106,24 +111,34 @@ public class AppModeDialog {
|
|||
public void onClick(View view) {
|
||||
CompoundButton compoundButton = (CompoundButton) view;
|
||||
compoundButton.setChecked(false);
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(a);
|
||||
final AlertDialog.Builder builder = new AlertDialog.Builder(a);
|
||||
|
||||
final Set<ApplicationMode> selected = new LinkedHashSet<ApplicationMode>(visible);
|
||||
builder.setTitle(R.string.profile_settings);
|
||||
builder.setPositiveButton(R.string.default_buttons_ok, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialogInterface, int i) {
|
||||
visible.clear();
|
||||
visible.addAll(selected);
|
||||
if(onDialogOk != null){
|
||||
onDialogOk.onClick(dialogInterface, i);
|
||||
}
|
||||
}
|
||||
});
|
||||
final AlertDialog dialog = builder.create();
|
||||
View v = AppModeDialog.prepareAppModeView(a, modes, selected, null, false,
|
||||
new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
StringBuilder vls = new StringBuilder(ApplicationMode.DEFAULT.getStringKey()+",");
|
||||
for(ApplicationMode mode : modes) {
|
||||
if(selected.contains(mode)) {
|
||||
vls.append(mode.getStringKey()+",");
|
||||
}
|
||||
if (selected.size() == 3){
|
||||
dialog.getButton(DialogInterface.BUTTON_POSITIVE).setEnabled(true);
|
||||
} else {
|
||||
dialog.getButton(DialogInterface.BUTTON_POSITIVE).setEnabled(false);
|
||||
}
|
||||
}
|
||||
});
|
||||
builder.setTitle(R.string.profile_settings);
|
||||
builder.setPositiveButton(R.string.default_buttons_ok, null);
|
||||
builder.setView(v);
|
||||
builder.show();
|
||||
dialog.setView(v);
|
||||
dialog.show();
|
||||
}
|
||||
});
|
||||
ll.addView(tb, lp);
|
||||
|
@ -145,7 +160,6 @@ public class AppModeDialog {
|
|||
for (int i =0; i< values.size(); i++){
|
||||
if (mode.equals(values.get(i))){
|
||||
positions.add(i);
|
||||
visible.add(values.get(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -154,22 +168,31 @@ public class AppModeDialog {
|
|||
int pos = positions.get(0);
|
||||
if (pos < values.size() - 2 && pos > 0){
|
||||
visible.add(values.get(pos - 1));
|
||||
visible.add(values.get(pos));
|
||||
visible.add(values.get(pos + 1));
|
||||
} else if (pos == 0) {
|
||||
visible.add(values.get(pos));
|
||||
visible.add(values.get(1));
|
||||
visible.add(values.get(2));
|
||||
} else if (pos == values.size() -1) {
|
||||
visible.add(values.get(pos - 1));
|
||||
visible.add(values.get(pos - 2));
|
||||
visible.add(values.get(pos));
|
||||
}
|
||||
} else if (positions.size() == 2) {
|
||||
int pos1 = positions.get(0);
|
||||
int pos2 = positions.get(1);
|
||||
if (pos1 + 1 != pos2){
|
||||
visible.add(values.get(pos1));
|
||||
visible.add(values.get(pos1 + 1));
|
||||
visible.add(values.get(pos2));
|
||||
} else if (pos1 > 0 && pos1 + 1 == pos2) {
|
||||
visible.add(values.get(pos1 - 1));
|
||||
visible.add(values.get(pos1));
|
||||
visible.add(values.get(pos2));
|
||||
} else if (pos1 == 0 && pos1 + 1 == pos2) {
|
||||
visible.add(values.get(pos1));
|
||||
visible.add(values.get(pos2));
|
||||
visible.add(values.get(pos2 + 1));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,6 +41,7 @@ public class ConfigureMapMenu {
|
|||
return false;
|
||||
}
|
||||
}).reg();
|
||||
adapter.item(R.string.app_modes_choose).layout(R.layout.mode_toggles).reg();
|
||||
|
||||
createLayersItems(adapter, ma);
|
||||
createRenderingAttributeItems(adapter, ma);
|
||||
|
|
|
@ -289,7 +289,7 @@ public class MapInfoLayer extends OsmandMapLayer {
|
|||
recreateControls();
|
||||
}
|
||||
|
||||
public ContextMenuAdapter openViewConfigureDrawer() {
|
||||
public ContextMenuAdapter getViewConfigureMenuAdapter() {
|
||||
final OsmandSettings settings = view.getSettings();
|
||||
ContextMenuAdapter cm = new ContextMenuAdapter(view.getContext());
|
||||
cm.setDefaultLayoutId(R.layout.drawer_list_item);
|
||||
|
@ -302,7 +302,7 @@ public class MapInfoLayer extends OsmandMapLayer {
|
|||
return false;
|
||||
}
|
||||
}).reg();
|
||||
|
||||
cm.item(R.string.app_modes_choose).layout(R.layout.mode_toggles).reg();
|
||||
cm.item(R.string.map_widget_reset)
|
||||
.icons(R.drawable.widget_reset_to_default_dark, R.drawable.widget_reset_to_default_light).listen(new OnContextMenuClick() {
|
||||
|
||||
|
@ -324,7 +324,8 @@ public class MapInfoLayer extends OsmandMapLayer {
|
|||
|
||||
cm.item(R.string.map_widget_appearance_rem).setCategory(true).layout(R.layout.drawer_list_sub_header).reg();
|
||||
addControls(cm, mapInfoControls.getAppearanceWidgets(), mode);
|
||||
final Set<ApplicationMode> selected = new LinkedHashSet<ApplicationMode>();
|
||||
|
||||
|
||||
|
||||
// TODO add profiles
|
||||
// View confirmDialog = View.inflate(view.getContext(), R.layout.configuration_dialog, null);
|
||||
|
|