Added new profile selection dialog to navigational settings menu

ui tweaks
This commit is contained in:
madwasp79 2019-05-29 15:30:41 +03:00
parent 60cee6a86a
commit 07db107b7a
8 changed files with 163 additions and 69 deletions

View file

@ -44,7 +44,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="1"
android:maxLines="2"
android:textAppearance="@style/TextAppearance.ListItemTitle"
android:textColor="?attr/main_font_color_basic"
tools:text="Item Title"/>

View file

@ -38,6 +38,8 @@
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="2"
android:ellipsize="end"
android:textColor="@color/main_font_dark"
android:textSize="@dimen/default_list_text_size"
tools:text="Bicycle"/>

View file

@ -43,7 +43,7 @@ public class ApplicationMode {
icon(R.drawable.map_action_car_dark, R.drawable.ic_action_car_dark, "ic_action_car_dark").setRoutingProfile("car").reg();
public static final ApplicationMode BICYCLE = create(R.string.app_mode_bicycle, "bicycle").speed(5.5f, 15).arrivalDistance(60).offRouteDistance(50).bicycleLocation().
icon(R.drawable.map_action_bicycle_dark, R.drawable.ic_action_bicycle_dark, "").setRoutingProfile("bicycle").reg();
icon(R.drawable.map_action_bicycle_dark, R.drawable.ic_action_bicycle_dark, "ic_action_bicycle_dark").setRoutingProfile("bicycle").reg();
public static final ApplicationMode PEDESTRIAN = create(R.string.app_mode_pedestrian, "pedestrian").speed(1.5f, 5).arrivalDistance(45).offRouteDistance(20).
icon(R.drawable.map_action_pedestrian_dark, R.drawable.ic_action_pedestrian_dark, "ic_action_pedestrian_dark").setRoutingProfile("pedestrian").reg();

View file

@ -18,9 +18,6 @@ import android.support.v7.app.AlertDialog;
import android.support.v7.app.AlertDialog.Builder;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Toast;
import net.osmand.plus.ApplicationMode;
@ -29,17 +26,16 @@ import net.osmand.plus.OsmandSettings;
import net.osmand.plus.OsmandSettings.CommonPreference;
import net.osmand.plus.OsmandSettings.OsmandPreference;
import net.osmand.plus.R;
import net.osmand.plus.activities.actions.AppModeDialog;
import net.osmand.plus.profiles.AppProfileArrayAdapter;
import net.osmand.plus.profiles.ProfileDataObject;
import net.osmand.plus.views.SeekBarPreference;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import net.osmand.util.Algorithms;
@ -60,12 +56,13 @@ public abstract class SettingsBaseActivity extends ActionBarPreferenceActivity
private Map<String, OsmandPreference<Integer>> seekBarPreferences = new LinkedHashMap<String, OsmandPreference<Integer>>();
private Map<String, Map<String, ?>> listPrefValues = new LinkedHashMap<String, Map<String, ?>>();
private AlertDialog profileDialog;
public SettingsBaseActivity() {
this(false);
}
private boolean isModeSelected = false;
public SettingsBaseActivity(boolean profile) {
profileSettings = profile;
}
@ -343,29 +340,7 @@ public abstract class SettingsBaseActivity extends ActionBarPreferenceActivity
getTypeButton().setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
AlertDialog.Builder singleSelectDialogBuilder = new Builder(SettingsBaseActivity.this);
singleSelectDialogBuilder.setTitle("Select App Profile");
final ArrayAdapter<String> modeNames = new ArrayAdapter<>(
SettingsBaseActivity.this, android.R.layout.select_dialog_singlechoice);
for (ApplicationMode am : modes) {
modeNames.add(am.toHumanString(SettingsBaseActivity.this));
}
singleSelectDialogBuilder.setNegativeButton(R.string.shared_string_cancel,
new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
singleSelectDialogBuilder.setAdapter(modeNames, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
settings.APPLICATION_MODE.set(modes.get(which));
updateModeButton(modes.get(which));
updateAllSettings();
}
});
singleSelectDialogBuilder.show();
selectAppModeDialog().show();
}
});
@ -373,6 +348,60 @@ public abstract class SettingsBaseActivity extends ActionBarPreferenceActivity
setPreferenceScreen(getPreferenceManager().createPreferenceScreen(this));
}
protected AlertDialog.Builder selectAppModeDialog() {
AlertDialog.Builder singleSelectDialogBuilder = new Builder(SettingsBaseActivity.this);
singleSelectDialogBuilder.setTitle(R.string.profile_settings);
final List<ProfileDataObject> activeModes = new ArrayList<>();
for (ApplicationMode am : ApplicationMode.values(getMyApplication())) {
boolean isSelected = false;
if (previousAppMode != null && previousAppMode == am) {
isSelected = true;
}
if (am != ApplicationMode.DEFAULT) {
activeModes.add(new ProfileDataObject(
am.toHumanString(getMyApplication()),
am.getParent() == null
? getString(R.string.profile_type_base_string)
: String.format(getString(R.string.profile_type_descr_string),
am.getParent().toHumanString(getMyApplication())),
am.getStringKey(),
ApplicationMode.getIconResFromName(getMyApplication(), am.getIconName(), getApplication().getPackageName()),
isSelected
));
}
}
final AppProfileArrayAdapter modeNames = new AppProfileArrayAdapter(
SettingsBaseActivity.this, R.layout.bottom_sheet_item_with_descr_and_radio_btn, activeModes);
singleSelectDialogBuilder.setNegativeButton(R.string.shared_string_cancel,
new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
singleSelectDialogBuilder.setOnDismissListener(new OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
if (!isModeSelected) {
List<ApplicationMode> m = ApplicationMode.values(getMyApplication());
setSelectedAppMode(m.get(m.size() > 1 ? 1 : 0));
}
}
});
singleSelectDialogBuilder.setAdapter(modeNames, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
settings.APPLICATION_MODE.set(modes.get(which));
updateModeButton(modes.get(which));
updateAllSettings();
}
});
return singleSelectDialogBuilder;
}
void updateModeButton(ApplicationMode mode) {
String title = Algorithms.isEmpty(mode.getUserProfileName())
? mode.toHumanString(SettingsBaseActivity.this)
@ -393,6 +422,7 @@ public abstract class SettingsBaseActivity extends ActionBarPreferenceActivity
? R.color.active_buttons_and_links_light
: R.color.active_buttons_and_links_dark));
settings.APPLICATION_MODE.set(mode);
isModeSelected = true;
updateAllSettings();
}
@ -416,39 +446,8 @@ public abstract class SettingsBaseActivity extends ActionBarPreferenceActivity
updateAllSettings();
}
}
protected void profileDialog() {
AlertDialog.Builder b = new AlertDialog.Builder(this);
final Set<ApplicationMode> selected = new LinkedHashSet<ApplicationMode>();
View v = AppModeDialog.prepareAppModeView(this, selected, false, null, true, true, false,
new View.OnClickListener() {
@Override
public void onClick(View v) {
if(selected.size() > 0) {
// test
setSelectedAppMode(selected.iterator().next());
}
if(profileDialog != null && profileDialog.isShowing()) {
profileDialog.dismiss();
}
profileDialog = null;
}
});
b.setOnDismissListener(new OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
if (selected.size() == 0) {
setSelectedAppMode(ApplicationMode.CAR);
}
}
});
b.setTitle(R.string.profile_settings);
b.setView(v);
profileDialog = b.show();
}
protected boolean setSelectedAppMode(ApplicationMode am) {
int ind = 0;
boolean found = false;
for (ApplicationMode a : modes) {
if (am == a) {
@ -456,7 +455,6 @@ public abstract class SettingsBaseActivity extends ActionBarPreferenceActivity
found = true;
break;
}
ind++;
}
return found;
}

View file

@ -180,7 +180,7 @@ public class SettingsNavigationActivity extends SettingsBaseActivity {
if(getIntent() != null && getIntent().hasExtra(INTENT_SKIP_DIALOG)) {
setSelectedAppMode(settings.getApplicationMode());
} else {
profileDialog();
selectAppModeDialog().show();
}
addVoicePrefs((PreferenceGroup) screen.findPreference("voice"));

View file

@ -43,7 +43,7 @@ public class SettingsMonitoringActivity extends SettingsBaseActivity {
createLoggingSection(grp);
createLiveSection(grp);
createNotificationSection(grp);
profileDialog();
selectAppModeDialog().show();
}

View file

@ -103,7 +103,6 @@ public class AppModesBottomSheetDialogFragment extends MenuBottomSheetDialogFrag
adapter.updateItemsList(allModes,
new LinkedHashSet<>(ApplicationMode.values(getMyApplication())));
setupHeightAndBackground(getView());
}
private void getData() {

View file

@ -0,0 +1,95 @@
package net.osmand.plus.profiles;
import android.app.Activity;
import android.app.Application;
import android.graphics.drawable.Drawable;
import android.support.annotation.NonNull;
import android.system.Os;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.TextView;
import java.util.List;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
public class AppProfileArrayAdapter extends ArrayAdapter<ProfileDataObject> {
private Activity context;
private List<ProfileDataObject> modes;
private int layout;
private int colorRes;
public AppProfileArrayAdapter(@NonNull Activity context, int resource, @NonNull List<ProfileDataObject> objects) {
super(context, resource, objects);
this.context = context;
this.modes = objects;
this.layout = resource;
}
public long getItemId(int position) {
return position;
}
static class ViewHolder {
public TextView title;
public TextView description;
public ImageView icon;
public CompoundButton compoundButton;
}
@Override
public @NonNull View getView(int position, View convertView, @NonNull ViewGroup parent) {
ViewHolder viewHolder;
View rowView = convertView;
if (rowView == null) {
LayoutInflater layoutInflater = context.getLayoutInflater();
rowView = layoutInflater.inflate(layout, null, true);
viewHolder = new ViewHolder();
viewHolder.title = (TextView) rowView.findViewById(R.id.title);
viewHolder.description = (TextView) rowView.findViewById(R.id.description);
viewHolder.icon = (ImageView) rowView.findViewById(R.id.icon);
viewHolder.compoundButton = (CompoundButton) rowView.findViewById(R.id.compound_button);
rowView.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) rowView.getTag();
}
ProfileDataObject mode = modes.get(position);
Drawable iconDrawable;
if (getMyApp(context) != null) {
if (mode.isSelected()) {
iconDrawable = getMyApp(context).getUIUtilities().getIcon(mode.getIconRes(),
getMyApp(context).getSettings().isLightContent()
? R.color.active_buttons_and_links_dark
: R.color.active_buttons_and_links_light
);
} else {
iconDrawable = getMyApp(context).getUIUtilities()
.getIcon(mode.getIconRes(), R.color.icon_color);
}
} else {
iconDrawable = context.getDrawable(mode.getIconRes());
}
viewHolder.title.setText(mode.getName());
viewHolder.description.setText(mode.getDescription());
viewHolder.icon.setImageDrawable(iconDrawable);
viewHolder.compoundButton.setChecked(mode.isSelected());
return rowView;
}
private OsmandApplication getMyApp(Activity context) {
Application app = context.getApplication();
if (app instanceof OsmandApplication) {
return (OsmandApplication) app;
} else {
return null;
}
}
}