Switch customize

This commit is contained in:
androiddevkkotlin 2020-11-07 15:39:50 +02:00
parent c3d88ab231
commit 7ba46570a0
7 changed files with 154 additions and 100 deletions

View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<stroke android:width="1dp" android:color="#2F3030" />
<corners android:radius="6dp"/>
<padding android:left="0dp" android:top="0dp" android:right="0dp" android:bottom="0dp" />
</shape>

View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#2F3030"/>
<corners android:radius="6dp"/>
<padding android:left="0dp" android:top="0dp" android:right="0dp" android:bottom="0dp" />
</shape>

View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#F0F0F0"/>
<corners android:radius="6dp"/>
<padding android:left="0dp" android:top="0dp" android:right="0dp" android:bottom="0dp" />
</shape>

View file

@ -21,8 +21,10 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginBottom="16dp" android:layout_marginBottom="16dp"
android:textSize="@dimen/default_desc_text_size" android:textSize="@dimen/default_list_text_size"
android:text = "@string/osm_notes" /> osmand:typeface="@string/font_roboto_medium"
android:text = "@string/osm_notes"
android:letterSpacing="@dimen/text_button_letter_spacing"/>
<com.google.android.material.textfield.TextInputLayout <com.google.android.material.textfield.TextInputLayout
android:id="@+id/message_label" android:id="@+id/message_label"
@ -41,12 +43,16 @@
<com.google.android.material.switchmaterial.SwitchMaterial <com.google.android.material.switchmaterial.SwitchMaterial
android:id="@+id/upload_anonymously_switch" android:id="@+id/upload_anonymously_switch"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="match_parent"
android:minHeight="@dimen/context_menu_buttons_bottom_height" android:minHeight="@dimen/context_menu_buttons_bottom_height"
android:text="@string/upload_anonymously"
android:layout_marginBottom="@dimen/bottom_sheet_content_margin" android:layout_marginBottom="@dimen/bottom_sheet_content_margin"
android:paddingLeft="@dimen/context_menu_padding_margin_medium" android:paddingBottom="@dimen/content_padding_small"
android:background="@drawable/layout_bg"/> android:paddingTop="@dimen/content_padding_small"
android:text="@string/upload_anonymously"
android:textColor="?android:textColorPrimary"
android:textSize="@dimen/default_list_text_size"
android:letterSpacing="@dimen/text_button_letter_spacing"
osmand:typeface="@string/font_roboto_regular"/>
</LinearLayout> </LinearLayout>

View file

@ -22,7 +22,9 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginBottom="16dp" android:layout_marginBottom="16dp"
android:text="@string/upload_poi" android:text="@string/upload_poi"
android:textSize="@dimen/default_desc_text_size" /> android:textSize="@dimen/default_list_text_size"
osmand:typeface="@string/font_roboto_medium"
android:letterSpacing="@dimen/text_button_letter_spacing"/>
<com.google.android.material.textfield.TextInputLayout <com.google.android.material.textfield.TextInputLayout
@ -46,8 +48,11 @@
android:layout_marginBottom="@dimen/content_padding" android:layout_marginBottom="@dimen/content_padding"
android:minHeight="@dimen/context_menu_buttons_bottom_height" android:minHeight="@dimen/context_menu_buttons_bottom_height"
android:text="@string/close_changset" android:text="@string/close_changset"
android:paddingLeft="@dimen/context_menu_padding_margin_medium" android:paddingLeft="50dp"
android:background="@drawable/layout_bg"/> android:textColor="?android:textColorPrimary"
android:textSize="@dimen/default_list_text_size"
osmand:typeface="@string/font_roboto_regular"
android:letterSpacing="@dimen/text_button_letter_spacing"/>
</LinearLayout> </LinearLayout>

View file

@ -1,5 +1,6 @@
package net.osmand.plus.osmedit.dialogs; package net.osmand.plus.osmedit.dialogs;
import android.content.Context;
import android.os.Bundle; import android.os.Bundle;
import android.view.View; import android.view.View;
import android.widget.CompoundButton; import android.widget.CompoundButton;
@ -22,100 +23,108 @@ import net.osmand.plus.settings.backend.OsmandSettings;
public class SendOsmNoteBottomSheetFragment extends MenuBottomSheetDialogFragment { public class SendOsmNoteBottomSheetFragment extends MenuBottomSheetDialogFragment {
public static final String TAG = "SendPoiBottomSheetFragment"; public static final String TAG = "SendPoiBottomSheetFragment";
public static final String OPENSTREETMAP_POINT = "openstreetmap_point"; public static final String OPENSTREETMAP_POINT = "openstreetmap_point";
public static final String POI_UPLOADER_TYPE = "poi_uploader_type"; public static final String POI_UPLOADER_TYPE = "poi_uploader_type";
private OsmPoint[] poi; private OsmPoint[] poi;
protected OsmandSettings settings; protected OsmandSettings settings;
public enum PoiUploaderType { public enum PoiUploaderType {
SIMPLE, SIMPLE,
FRAGMENT FRAGMENT
} }
protected OsmandApplication getMyApplication() { protected OsmandApplication getMyApplication() {
return (OsmandApplication) getActivity().getApplication(); return (OsmandApplication) getActivity().getApplication();
} }
@Override @Override
public void createMenuItems(Bundle savedInstanceState) { public void createMenuItems(Bundle savedInstanceState) {
String userName = getMyApplication().getSettings().USER_DISPLAY_NAME.get(); final boolean isNightMode = !getMyApplication().getSettings().isLightContent();
final View sendOsmNoteView = View.inflate(getContext(), R.layout.send_osm_note_fragment, null); final View sendOsmNoteView = View.inflate(getContext(), R.layout.send_osm_note_fragment, null);
final LinearLayout accountBlockView = (LinearLayout) sendOsmNoteView.findViewById(R.id.account_block); final LinearLayout accountBlockView = sendOsmNoteView.findViewById(R.id.account_block);
final SwitchCompat uploadAnonymously = (SwitchCompat) sendOsmNoteView.findViewById(R.id.upload_anonymously_switch); final SwitchCompat uploadAnonymously = sendOsmNoteView.findViewById(R.id.upload_anonymously_switch);
final TextView accountName = (TextView) sendOsmNoteView.findViewById(R.id.user_name); final TextView accountName = sendOsmNoteView.findViewById(R.id.user_name);
accountName.setText(userName); String userName = getMyApplication().getSettings().USER_DISPLAY_NAME.get();
accountBlockView.setVisibility(View.VISIBLE); accountName.setText(userName);
uploadAnonymously.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { accountBlockView.setVisibility(View.VISIBLE);
@Override uploadAnonymously.setBackgroundResource(isNightMode ? R.drawable.layout_bg_dark : R.drawable.layout_bg);
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { uploadAnonymously.setPadding(30, 0, 0, 0);
accountBlockView.setVisibility(isChecked ? View.GONE : View.VISIBLE); uploadAnonymously.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
} @Override
}); public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
final SimpleBottomSheetItem titleItem = (SimpleBottomSheetItem) new SimpleBottomSheetItem.Builder() accountBlockView.setVisibility(isChecked ? View.GONE : View.VISIBLE);
.setCustomView(sendOsmNoteView) if (isNightMode) {
.create(); uploadAnonymously.setBackgroundResource(isChecked ? R.drawable.layout_bg_dark_solid : R.drawable.layout_bg_dark);
items.add(titleItem); } else {
} uploadAnonymously.setBackgroundResource(isChecked ? R.drawable.layout_bg_solid : R.drawable.layout_bg);
}
uploadAnonymously.setPadding(30, 0, 0, 0);
}
});
final SimpleBottomSheetItem titleItem = (SimpleBottomSheetItem) new SimpleBottomSheetItem.Builder()
.setCustomView(sendOsmNoteView)
.create();
items.add(titleItem);
}
public static SendOsmNoteBottomSheetFragment showInstance(@NonNull OsmPoint[] points, @NonNull PoiUploaderType uploaderType) { public static SendOsmNoteBottomSheetFragment showInstance(@NonNull OsmPoint[] points, @NonNull PoiUploaderType uploaderType) {
SendOsmNoteBottomSheetFragment fragment = new SendOsmNoteBottomSheetFragment(); SendOsmNoteBottomSheetFragment fragment = new SendOsmNoteBottomSheetFragment();
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putSerializable(OPENSTREETMAP_POINT, points); bundle.putSerializable(OPENSTREETMAP_POINT, points);
bundle.putString(POI_UPLOADER_TYPE, uploaderType.name()); bundle.putString(POI_UPLOADER_TYPE, uploaderType.name());
fragment.setArguments(bundle); fragment.setArguments(bundle);
return fragment; return fragment;
} }
@Override @Override
protected UiUtilities.DialogButtonType getRightBottomButtonType() { protected UiUtilities.DialogButtonType getRightBottomButtonType() {
return (UiUtilities.DialogButtonType.PRIMARY); return (UiUtilities.DialogButtonType.PRIMARY);
} }
@Override @Override
protected void onRightBottomButtonClick() { protected void onRightBottomButtonClick() {
View view = getView(); View view = getView();
poi = (OsmPoint[]) getArguments().getSerializable(OPENSTREETMAP_POINT); poi = (OsmPoint[]) getArguments().getSerializable(OPENSTREETMAP_POINT);
boolean hasPoiGroup = false; boolean hasPoiGroup = false;
assert poi != null; assert poi != null;
for (OsmPoint p : poi) { for (OsmPoint p : poi) {
if (p.getGroup() == OsmPoint.Group.POI) { if (p.getGroup() == OsmPoint.Group.POI) {
hasPoiGroup = true; hasPoiGroup = true;
break; break;
} }
} }
final boolean hasPOI = hasPoiGroup; final boolean hasPOI = hasPoiGroup;
final SwitchCompat uploadAnonymously = (SwitchCompat) view.findViewById(R.id.upload_anonymously_switch); final SwitchCompat uploadAnonymously = (SwitchCompat) view.findViewById(R.id.upload_anonymously_switch);
final EditText messageEditText = (EditText) view.findViewById(R.id.message_field); final EditText messageEditText = (EditText) view.findViewById(R.id.message_field);
final SendPoiDialogFragment.PoiUploaderType poiUploaderType = SendPoiDialogFragment.PoiUploaderType.valueOf(getArguments().getString(POI_UPLOADER_TYPE, SendPoiDialogFragment.PoiUploaderType.SIMPLE.name())); final SendPoiDialogFragment.PoiUploaderType poiUploaderType = SendPoiDialogFragment.PoiUploaderType.valueOf(getArguments().getString(POI_UPLOADER_TYPE, SendPoiDialogFragment.PoiUploaderType.SIMPLE.name()));
final SendPoiDialogFragment.ProgressDialogPoiUploader progressDialogPoiUploader; final SendPoiDialogFragment.ProgressDialogPoiUploader progressDialogPoiUploader;
if (poiUploaderType == SendPoiDialogFragment.PoiUploaderType.SIMPLE && getActivity() instanceof MapActivity) { if (poiUploaderType == SendPoiDialogFragment.PoiUploaderType.SIMPLE && getActivity() instanceof MapActivity) {
progressDialogPoiUploader = progressDialogPoiUploader =
new SendPoiDialogFragment.SimpleProgressDialogPoiUploader((MapActivity) getActivity()); new SendPoiDialogFragment.SimpleProgressDialogPoiUploader((MapActivity) getActivity());
} else { } else {
progressDialogPoiUploader = (SendPoiDialogFragment.ProgressDialogPoiUploader) getParentFragment(); progressDialogPoiUploader = (SendPoiDialogFragment.ProgressDialogPoiUploader) getParentFragment();
} }
if (progressDialogPoiUploader != null) { if (progressDialogPoiUploader != null) {
String comment = messageEditText.getText().toString(); String comment = messageEditText.getText().toString();
if (comment.length() > 0) { if (comment.length() > 0) {
for (OsmPoint osmPoint : poi) { for (OsmPoint osmPoint : poi) {
if (osmPoint.getGroup() == OsmPoint.Group.POI) { if (osmPoint.getGroup() == OsmPoint.Group.POI) {
((OpenstreetmapPoint) osmPoint).setComment(comment); ((OpenstreetmapPoint) osmPoint).setComment(comment);
break; break;
} }
} }
} }
progressDialogPoiUploader.showProgressDialog(poi, progressDialogPoiUploader.showProgressDialog(poi,
false, false,
!hasPOI && uploadAnonymously.isChecked()); !hasPOI && uploadAnonymously.isChecked());
} }
dismiss(); dismiss();
} }
@Override
protected int getRightBottomButtonTextId() {
return R.string.shared_string_upload;
}
@Override
protected int getRightBottomButtonTextId() {
return R.string.shared_string_upload;
}
} }

View file

@ -2,6 +2,7 @@ package net.osmand.plus.osmedit.dialogs;
import android.os.Bundle; import android.os.Bundle;
import android.view.View; import android.view.View;
import android.widget.CompoundButton;
import android.widget.EditText; import android.widget.EditText;
import android.widget.TextView; import android.widget.TextView;
@ -35,12 +36,27 @@ public class SendPoiBottomSheetFragment extends MenuBottomSheetDialogFragment {
@Override @Override
public void createMenuItems(Bundle savedInstanceState) { public void createMenuItems(Bundle savedInstanceState) {
final boolean isNightMode = getMyApplication().getDaynightHelper().isNightModeForMapControls();
final View sendOsmPoiView = View.inflate(getContext(), R.layout.send_poi_fragment, null);
final SwitchCompat closeChangset = sendOsmPoiView.findViewById(R.id.close_change_set_checkbox);
final TextView accountName = (TextView) sendOsmPoiView.findViewById(R.id.user_name);
String userName = getMyApplication().getSettings().USER_DISPLAY_NAME.get(); String userName = getMyApplication().getSettings().USER_DISPLAY_NAME.get();
final View sendOsmNoteView = View.inflate(getContext(), R.layout.send_poi_fragment, null);
final TextView accountName = (TextView) sendOsmNoteView.findViewById(R.id.user_name);
accountName.setText(userName); accountName.setText(userName);
closeChangset.setBackgroundResource(isNightMode ? R.drawable.layout_bg_dark : R.drawable.layout_bg);
closeChangset.setPadding(30, 0, 0, 0);
closeChangset.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isNightMode) {
closeChangset.setBackgroundResource(isChecked ? R.drawable.layout_bg_dark_solid : R.drawable.layout_bg_dark);
} else {
closeChangset.setBackgroundResource(isChecked ? R.drawable.layout_bg_solid : R.drawable.layout_bg);
}
closeChangset.setPadding(30, 0, 0, 0);
}
});
final SimpleBottomSheetItem titleItem = (SimpleBottomSheetItem) new SimpleBottomSheetItem.Builder() final SimpleBottomSheetItem titleItem = (SimpleBottomSheetItem) new SimpleBottomSheetItem.Builder()
.setCustomView(sendOsmNoteView) .setCustomView(sendOsmPoiView)
.create(); .create();
items.add(titleItem); items.add(titleItem);
} }