Application Profiles. Settings menu. Almost done.

This commit is contained in:
madwasp79 2019-03-26 16:28:14 +02:00
parent 8dfe6930b7
commit b7e080ac1c
10 changed files with 138 additions and 84 deletions

View file

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="24dp" />
<solid android:color="@color/map_widget_blue"/>
</shape>

View file

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="24dp" />
<solid android:color="@color/map_widget_blue_pressed"/>
</shape>

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/fab_extended_blue_pressed" android:state_pressed="true"/> <item android:drawable="@drawable/bg_shadow_fab_normal" android:state_pressed="true"/>
<item android:drawable="@drawable/fab_extended_blue_idle"/> <item android:drawable="@drawable/bg_shadow_fab_normal"/>
</selector> </selector>

View file

@ -1,9 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
</LinearLayout>

View file

@ -32,7 +32,7 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:gravity="center" android:gravity="center"
android:orientation="vertical" android:orientation="vertical"
android:layout_weight="4"> android:layout_weight="5">
<TextView <TextView
android:id="@+id/profile_title" android:id="@+id/profile_title"
@ -52,9 +52,9 @@
</LinearLayout> </LinearLayout>
<LinearLayout <LinearLayout
android:layout_width="0dp" android:layout_width="wrap_content"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_weight="2"
android:orientation="horizontal"> android:orientation="horizontal">
<ImageView <ImageView
@ -71,6 +71,10 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center_vertical|end" android:layout_gravity="center_vertical|end"
android:paddingRight="16dp"
android:paddingEnd="16dp"
android:paddingLeft="4dp"
android:paddingStart="4dp"
android:background="@null" android:background="@null"
android:clickable="false" android:clickable="false"
android:focusable="false" android:focusable="false"

View file

@ -28,18 +28,37 @@
android:layout_below="@id/top_divider" android:layout_below="@id/top_divider"
android:clipToPadding="false"/> android:clipToPadding="false"/>
<android.support.v7.widget.AppCompatButton <LinearLayout
android:id="@+id/add_profile_btn" android:id="@+id/add_profile_btn"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="48dp" android:layout_height="wrap_content"
android:layout_alignParentBottom="true" android:layout_alignParentBottom="true"
android:layout_alignParentRight="true" android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:clickable="true"
android:focusable="true"
android:layout_gravity="bottom|center_horizontal" android:layout_gravity="bottom|center_horizontal"
android:background="@drawable/fab_extended_drawable" android:background="@drawable/fab_extended_drawable"
android:drawableLeft="@drawable/ic_action_plus" android:orientation="horizontal"
android:drawableStart="@drawable/ic_action_plus" android:gravity="center_vertical">
<android.support.v7.widget.AppCompatImageView
android:layout_gravity="center_vertical"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginLeft="14dp"
android:layout_marginStart="14dp"
android:src="@drawable/ic_action_plus"/>
<android.support.v7.widget.AppCompatTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/shared_string_add" android:text="@string/shared_string_add"
android:layout_margin="16dp" android:textColor="@color/color_white"
android:textColor="@color/color_white"/> android:layout_marginRight="20dp"
android:layout_marginEnd="20dp"
/>
</LinearLayout>
</RelativeLayout> </RelativeLayout>

View file

@ -14,7 +14,8 @@ import java.util.List;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.profiles.ProfileMenuAdapter.ProfileViewHolder; import net.osmand.plus.profiles.ProfileMenuAdapter.ProfileViewHolder;
import net.osmand.plus.profiles.SettingsProfileActivity.ProfileItem; import net.osmand.plus.profiles.SettingsProfileFragment.ProfileItem;
public class ProfileMenuAdapter extends RecyclerView.Adapter<ProfileViewHolder> { public class ProfileMenuAdapter extends RecyclerView.Adapter<ProfileViewHolder> {
@ -47,10 +48,12 @@ public class ProfileMenuAdapter extends RecyclerView.Adapter<ProfileViewHolder>
public void onBindViewHolder(@NonNull ProfileViewHolder holder, int position) { public void onBindViewHolder(@NonNull ProfileViewHolder holder, int position) {
ProfileItem item = items.get(position); ProfileItem item = items.get(position);
holder.title.setText(item.getTitle()); holder.title.setText(item.getTitle());
holder.descr.setText(item.getDescr()); holder.title.setTextColor(app.getResources().getColor(isNightMode(app) ? R.color.main_font_dark : R.color.main_font_light));
holder.descr.setText(String.format("Type: %s", item.getDescr()));
Drawable drawable = app.getUIUtilities().getThemedIcon(item.getIconRes()); Drawable drawable = app.getUIUtilities().getThemedIcon(item.getIconRes());
holder.icon.setImageDrawable(drawable); holder.icon.setImageDrawable(drawable);
holder.aSwitch.setChecked(item.getState()); holder.icon.setImageDrawable(app.getUIUtilities().getIcon(item.getIconRes(), isNightMode(app) ? R.color.active_buttons_and_links_dark : R.color.active_buttons_and_links_light));
holder.aSwitch.setChecked(item.isSelected());
holder.aSwitch.setOnClickListener(new OnClickListener() { holder.aSwitch.setOnClickListener(new OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
@ -70,6 +73,10 @@ public class ProfileMenuAdapter extends RecyclerView.Adapter<ProfileViewHolder>
return items.size(); return items.size();
} }
private static boolean isNightMode(OsmandApplication ctx) {
return !ctx.getSettings().isLightContent();
}
class ProfileViewHolder extends RecyclerView.ViewHolder { class ProfileViewHolder extends RecyclerView.ViewHolder {
TextView title, descr; TextView title, descr;
SwitchCompat aSwitch; SwitchCompat aSwitch;

View file

@ -42,49 +42,5 @@ public class SettingsProfileActivity extends OsmandActionBarActivity {
super.onResume(); super.onResume();
} }
public class ProfileItem {
private int iconRes;
private String title;
private String descr;
private boolean state;
public ProfileItem(int iconRes, String title, String descr, boolean state) {
this.iconRes = iconRes;
this.title = title;
this.descr = descr;
this.state = state;
}
public int getIconRes() {
return iconRes;
}
public void setIconRes(int iconRes) {
this.iconRes = iconRes;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getDescr() {
return descr;
}
public void setDescr(String descr) {
this.descr = descr;
}
public boolean getState() {
return state;
}
public void setState(boolean state) {
this.state = state;
}
}
} }

View file

@ -3,13 +3,17 @@ package net.osmand.plus.profiles;
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.annotation.Nullable;
import android.support.v7.widget.AppCompatButton; import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.View.OnClickListener; import android.view.View.OnClickListener;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.LinearLayout;
import java.util.ArrayList;
import java.util.List;
import net.osmand.PlatformUtil; import net.osmand.PlatformUtil;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.base.BaseOsmAndFragment; import net.osmand.plus.base.BaseOsmAndFragment;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
@ -20,14 +24,40 @@ public class SettingsProfileFragment extends BaseOsmAndFragment {
private ProfileMenuAdapter adapter; private ProfileMenuAdapter adapter;
private RecyclerView recyclerView; private RecyclerView recyclerView;
private AppCompatButton btn; private LinearLayout btn;
private List<ApplicationMode> allDefaultModes;
private List<ApplicationMode> selectedDefaultModes;
private List<ProfileItem> profilesList;
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
profilesList = new ArrayList<>();
allDefaultModes = ApplicationMode.allPossibleValues();
allDefaultModes.remove(ApplicationMode.DEFAULT);
selectedDefaultModes = new ArrayList<>(ApplicationMode.values(getMyApplication()));
selectedDefaultModes.remove(ApplicationMode.DEFAULT);
for (ApplicationMode am : allDefaultModes) {
ProfileItem profileItem = new ProfileItem(
am.getSmallIconDark(),
am.toHumanStringCtx(getMyApplication().getApplicationContext()),
am.toHumanStringCtx(getMyApplication().getApplicationContext()),
true);
if (selectedDefaultModes.contains(am)) {
profileItem.setSelected(true);
}
profilesList.add(profileItem);
}
}
@Nullable @Nullable
@Override @Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) { @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.profiles_list_fragment, container, false); View view = inflater.inflate(R.layout.profiles_list_fragment, container, false);
recyclerView = view.findViewById(R.id.profiles_list); recyclerView = view.findViewById(R.id.profiles_list);
btn = view.findViewById(R.id.add_profile_btn); btn = view.findViewById(R.id.add_profile_btn);
btn.setOnClickListener(new OnClickListener() { btn.setOnClickListener(new OnClickListener() {
@ -36,7 +66,66 @@ public class SettingsProfileFragment extends BaseOsmAndFragment {
//todo add new profile; //todo add new profile;
} }
}); });
adapter = new ProfileMenuAdapter(profilesList, getMyApplication());
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
recyclerView.setAdapter(adapter);
return view; return view;
} }
public class ProfileItem {
private int iconRes;
private String title;
private String descr;
private boolean isSelected;
private boolean isAppDefault;
public ProfileItem(int iconRes, String title, String descr, boolean isAppDefault) {
this.iconRes = iconRes;
this.title = title;
this.descr = descr;
this.isAppDefault = isAppDefault;
}
public int getIconRes() {
return iconRes;
}
public void setIconRes(int iconRes) {
this.iconRes = iconRes;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getDescr() {
return descr;
}
public void setDescr(String descr) {
this.descr = descr;
}
public boolean isSelected() {
return isSelected;
}
public void setSelected(boolean isSelected) {
this.isSelected = isSelected;
}
public boolean isAppDefault() {
return isAppDefault;
}
public void setAppDefault(boolean appDefault) {
isAppDefault = appDefault;
}
}
} }

View file

@ -66,7 +66,7 @@ Functionality
* Add POIs and directly upload them to OSM (or later if offline) * Add POIs and directly upload them to OSM (or later if offline)
* Optional trip recording also in background mode (while device is in sleep mode) * Optional trip recording also in background mode (while device is in sleep mode)
OsmAnd is open source and actively being developed. Everyone can contribute to the application by reporting bugs, [improving translations](https://hosted.weblate.org/projects/osmand/), or coding new features. The project is in a lively state of continuous improvement by all these forms of developer and user interaction. The project progress also relies on financial contributions to fund the development, coding, and testing of new functionality. By buying OsmAnd+ and subscribing to OsmAnd Live you help the application to be even more awesome! It is also possible to make a general donation, see http://osmand.net/help-online#buy_app. OsmAnd is open source and actively being developed. Everyone can contribute to the application by reporting bugs, [improving translations](https://hosted.weblate.org/projects/osmand/), or coding new features. The project is in a lively selected of continuous improvement by all these forms of developer and user interaction. The project progress also relies on financial contributions to fund the development, coding, and testing of new functionality. By buying OsmAnd+ and subscribing to OsmAnd Live you help the application to be even more awesome! It is also possible to make a general donation, see http://osmand.net/help-online#buy_app.
#### Approximate map coverage and quality: #### Approximate map coverage and quality: