Navigational settings UI (profile selection) change.

This commit is contained in:
madwasp79 2019-05-06 18:19:18 +03:00
parent 15703a4c90
commit 2e1817d210
6 changed files with 154 additions and 44 deletions

View file

@ -35,6 +35,80 @@
</android.support.design.widget.AppBarLayout>
<LinearLayout
android:id="@+id/type_selection_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="?attr/selectableItemBackground"
android:clickable="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="64dp"
android:paddingStart="@dimen/content_padding"
android:paddingEnd="@dimen/content_padding_small"
android:paddingLeft="@dimen/content_padding"
android:paddingRight="@dimen/content_padding_small"
android:orientation="horizontal">
<ImageView
android:id="@+id/mode_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/bottom_sheet_icon_margin"
android:layout_marginRight="@dimen/bottom_sheet_icon_margin"
android:layout_gravity="center_vertical"
android:tint="?attr/primary_icon_color"
tools:src="@drawable/ic_action_coordinates_latitude"/>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginEnd="@dimen/content_padding"
android:layout_marginRight="@dimen/content_padding"
android:layout_gravity="center_vertical"
android:gravity="center_vertical"
android:orientation="vertical">
<TextView
android:id="@+id/mode_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="1"
android:textAppearance="@style/TextAppearance.ListItemTitle"
android:textColor="?attr/main_font_color_basic"
tools:text="Item Title"/>
<TextView
android:id="@+id/mode_subtitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="1"
tools:text="Item additional desription"/>
</LinearLayout>
<ImageView
android:id="@+id/type_down_arrow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0"
android:layout_gravity="center_vertical"
android:src="@drawable/ic_action_arrow_drop_down"/>
</LinearLayout>
<ImageView
android:id="@+id/bottom_shadow2"
android:layout_width="match_parent"
android:layout_height="5dp"
android:scaleType="fitXY"
android:src="@drawable/bg_shadow_list_bottom"/>
</LinearLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >

View file

@ -470,10 +470,6 @@ public class ApplicationMode {
return routingProfile;
}
public int getMapIconsSetId() {
return mapIconsSetId;
}
public String getUserProfileName() {
return userProfileName;
}

View file

@ -482,6 +482,7 @@ public class GpxSelectionHelper {
public void loadGPXTracks(IProgress p) {
String load = app.getSettings().SELECTED_GPX.get();
LOG.debug("Saved selection:" + load);
if (!Algorithms.isEmpty(load)) {
try {
JSONArray ar = new JSONArray(load);

View file

@ -9,8 +9,11 @@ import android.support.v7.widget.Toolbar;
import android.util.TypedValue;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Spinner;
import android.widget.TextView;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
@ -56,6 +59,7 @@ public abstract class ActionBarPreferenceActivity extends AppCompatPreferenceAct
});
getSpinner().setVisibility(View.GONE);
getTypeButton().setVisibility(View.GONE);
setProgressVisibility(false);
}
@ -81,6 +85,25 @@ public abstract class ActionBarPreferenceActivity extends AppCompatPreferenceAct
return (Spinner) findViewById(R.id.spinner_nav);
}
protected LinearLayout getTypeButton() {
return (LinearLayout) findViewById(R.id.type_selection_button);
}
protected TextView getModeTitleTV() {
return (TextView) findViewById(R.id.mode_title);
}
protected TextView getModeSubTitleTV() {
return (TextView) findViewById(R.id.mode_subtitle);
}
protected ImageView getModeIconIV() {
return (ImageView) findViewById(R.id.mode_icon);
}
protected ImageView getDropDownArrow() {
return (ImageView) findViewById(R.id.type_down_arrow);
}
protected void setProgressVisibility(boolean visibility) {
if (visibility) {
findViewById(R.id.ProgressBar).setVisibility(View.VISIBLE);

View file

@ -14,6 +14,7 @@
* limitations under the License.
*/
package net.osmand.plus.activities;
import android.app.FragmentManager;
import android.content.res.Configuration;
import android.os.Bundle;
import android.preference.PreferenceActivity;

View file

@ -2,6 +2,7 @@ package net.osmand.plus.activities;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.DialogInterface.OnMultiChoiceClickListener;
import android.os.Bundle;
import android.preference.CheckBoxPreference;
@ -13,6 +14,7 @@ import android.preference.Preference.OnPreferenceClickListener;
import android.preference.PreferenceGroup;
import android.preference.PreferenceScreen;
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;
@ -28,6 +30,7 @@ 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.BaseProfile;
import net.osmand.plus.views.SeekBarPreference;
import java.lang.reflect.Field;
@ -38,6 +41,7 @@ import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import net.osmand.util.Algorithms;
public abstract class SettingsBaseActivity extends ActionBarPreferenceActivity
@ -48,6 +52,7 @@ public abstract class SettingsBaseActivity extends ActionBarPreferenceActivity
protected OsmandSettings settings;
protected final boolean profileSettings;
protected List<ApplicationMode> modes = new ArrayList<ApplicationMode>();
protected final ArrayList<BaseProfile> appModes = new ArrayList<>();
private ApplicationMode previousAppMode;
private Map<String, Preference> screenPreferences = new LinkedHashMap<String, Preference>();
@ -328,7 +333,6 @@ public abstract class SettingsBaseActivity extends ActionBarPreferenceActivity
settings = app.getSettings();
getToolbar().setTitle(R.string.shared_string_settings);
if (profileSettings) {
modes.clear();
for (ApplicationMode a : ApplicationMode.values(app)) {
@ -336,52 +340,63 @@ public abstract class SettingsBaseActivity extends ActionBarPreferenceActivity
modes.add(a);
}
}
List<String> s = new ArrayList<String>();
for (ApplicationMode a : modes) {
s.add(a.toHumanString(app));
}
SpinnerAdapter spinnerAdapter = new SpinnerAdapter(this,
R.layout.spinner_item, s);
// android.R.layout.simple_spinner_dropdown_item
spinnerAdapter.setDropDownViewResource(R.layout.spinner_dropdown_item);
getSpinner().setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
settings.APPLICATION_MODE.set(modes.get(position));
updateAllSettings();
}
updateModeButton(settings.APPLICATION_MODE.get());
//--------------------------
getTypeButton().setVisibility(View.VISIBLE);
getTypeButton().setOnClickListener(new View.OnClickListener() {
@Override
public void onNothingSelected(AdapterView<?> parent) {
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();
}
});
getSpinner().setAdapter(spinnerAdapter);
getSpinner().setVisibility(View.VISIBLE);
}
setPreferenceScreen(getPreferenceManager().createPreferenceScreen(this));
}
void updateModeButton(ApplicationMode mode) {
String title = Algorithms.isEmpty(mode.getUserProfileName())
? mode.toHumanString(SettingsBaseActivity.this)
: mode.getUserProfileName();
String subtitle = mode.getParent() == null
? "Mode: " + Algorithms.capitalizeFirstLetterAndLowercase(mode.getStringKey().replace("_", ""))
: "User Mode, derived from: " + Algorithms
.capitalizeFirstLetterAndLowercase(mode.getParent().getStringKey());
getModeTitleTV().setText(title);
getModeSubTitleTV().setText(subtitle);
getModeIconIV().setImageDrawable(getMyApplication().getUIUtilities().getIcon(mode.getSmallIconDark(),
getMyApplication().getSettings().isLightContent()
? R.color.active_buttons_and_links_light
: R.color.active_buttons_and_links_dark));
getDropDownArrow().setImageDrawable(getMyApplication().getUIUtilities().getIcon(R.drawable.ic_action_arrow_drop_down,
getMyApplication().getSettings().isLightContent()
? R.color.active_buttons_and_links_light
: R.color.active_buttons_and_links_dark));
class SpinnerAdapter extends ArrayAdapter<String>{
public SpinnerAdapter(Context context, int resource, List<String> objects) {
super(context, resource, objects);
}
@Override
public View getDropDownView(int position, View convertView, ViewGroup parent) {
View view = super.getDropDownView(position, convertView, parent);
if (!settings.isLightActionBar()){
TextView textView = (TextView) view.findViewById(android.R.id.text1);
textView.setBackgroundColor(getResources().getColor(R.color.actionbar_dark_color));
}
return view;
}
}
}
@Override
protected void onResume() {
@ -431,7 +446,7 @@ public abstract class SettingsBaseActivity extends ActionBarPreferenceActivity
boolean found = false;
for (ApplicationMode a : modes) {
if (am == a) {
getSpinner().setSelection(ind);
updateModeButton(a);
found = true;
break;
}
@ -541,7 +556,7 @@ public abstract class SettingsBaseActivity extends ActionBarPreferenceActivity
}
public void showBooleanSettings(String[] vals, final OsmandPreference<Boolean>[] prefs) {
AlertDialog.Builder bld = new AlertDialog.Builder(this);