Fixed UI for map language setting

This commit is contained in:
Alexey Kulish 2016-10-13 19:18:09 +03:00
parent deab76be09
commit 0a610fc07e
4 changed files with 108 additions and 88 deletions

View file

@ -1,56 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:osmand="http://schemas.android.com/apk/res-auto"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="26dp"
android:paddingRight="16dp"
android:paddingTop="18dp"
android:paddingBottom="16dp"
android:orientation="vertical">
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="?android:attr/textColorPrimary"
android:textSize="@dimen/dialog_header_text_size"
osmand:typeface="@string/font_roboto_medium"
android:text="@string/map_locale"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColor="?android:attr/textColorPrimary"
android:textSize="@dimen/default_list_text_size"
android:text="@string/translit_names"/>
<android.support.v7.widget.SwitchCompat
android:id="@+id/check"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
</LinearLayout>
<View
android:id="@+id/divider"
android:layout_width="wrap_content"
android:layout_height="1dp"
android:background="?attr/dashboard_divider"/>
</LinearLayout>

View file

@ -0,0 +1,58 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:orientation="vertical">
<View
android:background="?attr/dashboard_divider"
android:id="@+id/topDivider"
android:layout_height="1dp"
android:layout_width="wrap_content"/>
<android.support.v7.widget.AppCompatCheckedTextView
android:checkMark="?android:attr/listChoiceIndicatorSingle"
android:gravity="center_vertical"
android:id="@+id/text1"
android:layout_height="?android:attr/listPreferredItemHeightSmall"
android:layout_width="match_parent"
android:paddingLeft="26dp"
android:paddingRight="@dimen/list_content_padding"
android:textColor="?android:attr/textColorPrimary"
android:textSize="@dimen/default_list_text_size"/>
<LinearLayout
android:gravity="center_vertical"
android:id="@+id/switchLayout"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_width="match_parent"
android:orientation="horizontal"
android:paddingLeft="26dp"
android:paddingRight="@dimen/list_content_padding">
<TextView
android:id="@+id/switchText"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_width="0dp"
android:paddingRight="@dimen/list_content_padding"
android:textColor="?android:attr/textColorPrimary"
android:textSize="@dimen/default_sub_text_size"/>
<android.support.v7.widget.SwitchCompat
android:id="@+id/check"
android:layout_height="wrap_content"
android:layout_width="wrap_content"/>
</LinearLayout>
<View
android:background="?attr/dashboard_divider"
android:id="@+id/bottomDivider"
android:layout_height="1dp"
android:layout_marginTop="@dimen/list_header_padding"
android:layout_width="wrap_content"/>
</LinearLayout>

View file

@ -9,6 +9,7 @@
3. All your modified/created strings are in the top of the file (to make easier find what\'s translated).
PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy
-->
<string name="translit_name_if_miss">Transliterate if %1$s name is missing</string>
<string name="translit_names">Transliterate names</string>
<string name="edit_filter">Edit filter</string>
<string name="subcategories">Subcategories</string>

View file

@ -5,9 +5,11 @@ import android.content.DialogInterface;
import android.content.DialogInterface.OnMultiChoiceClickListener;
import android.content.Intent;
import android.support.annotation.DrawableRes;
import android.support.annotation.NonNull;
import android.support.annotation.StringRes;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.AppCompatCheckedTextView;
import android.support.v7.widget.SwitchCompat;
import android.view.LayoutInflater;
import android.view.View;
@ -15,7 +17,7 @@ import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
@ -68,6 +70,8 @@ public class ConfigureMapMenu {
private static final Log LOG = PlatformUtil.getLog(ConfigureMapMenu.class);
private static final String HIKING_ROUTES_OSMC_ATTR = "hikingRoutesOSMC";
private int hikingRouteOSMCValue;
private int selectedLanguageIndex;
private boolean transliterateNames;
public interface OnClickListener {
void onClick();
@ -483,19 +487,8 @@ public class ConfigureMapMenu {
final int pos, boolean isChecked) {
final OsmandMapTileView view = activity.getMapView();
final AlertDialog.Builder b = new AlertDialog.Builder(view.getContext());
final AlertDialog alertDialog;
View titleView = LayoutInflater.from(activity)
.inflate(R.layout.language_dialog_title, null);
final SwitchCompat check = (SwitchCompat) titleView.findViewById(R.id.check);
check.setChecked(view.getSettings().MAP_TRANSLITERATE_NAMES.get());
b.setCustomTitle(titleView);
check.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
view.getSettings().MAP_TRANSLITERATE_NAMES.set(isChecked);
}
});
b.setTitle(activity.getString(R.string.map_locale));
final String[] txtIds = getSortedMapNamesIds(activity, mapNamesIds,
getMapNamesValues(activity, mapNamesIds));
@ -507,20 +500,57 @@ public class ConfigureMapMenu {
break;
}
}
selectedLanguageIndex = selected;
transliterateNames = view.getSettings().MAP_TRANSLITERATE_NAMES.get();
final OnCheckedChangeListener translitChangdListener = new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
transliterateNames = isChecked;
}
};
final ArrayAdapter<CharSequence> singleChoiceAdapter = new ArrayAdapter<CharSequence>(activity, R.layout.single_choice_switch_item, R.id.text1, txtValues) {
@NonNull
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = super.getView(position, convertView, parent);
AppCompatCheckedTextView checkedTextView = (AppCompatCheckedTextView) v.findViewById(R.id.text1);
if (position == selectedLanguageIndex && position > 0) {
checkedTextView.setChecked(true);
v.findViewById(R.id.topDivider).setVisibility(View.VISIBLE);
v.findViewById(R.id.bottomDivider).setVisibility(View.VISIBLE);
v.findViewById(R.id.switchLayout).setVisibility(View.VISIBLE);
TextView switchText = (TextView) v.findViewById(R.id.switchText);
switchText.setText(activity.getString(R.string.translit_name_if_miss, txtValues[position]));
SwitchCompat check = (SwitchCompat) v.findViewById(R.id.check);
check.setChecked(transliterateNames);
check.setOnCheckedChangeListener(translitChangdListener);
} else {
checkedTextView.setChecked(position == selectedLanguageIndex);
v.findViewById(R.id.topDivider).setVisibility(View.GONE);
v.findViewById(R.id.bottomDivider).setVisibility(View.GONE);
v.findViewById(R.id.switchLayout).setVisibility(View.GONE);
}
return v;
}
};
b.setAdapter(singleChoiceAdapter, null);
b.setSingleChoiceItems(txtValues, selected, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (which != 1 && check.isChecked()) {
check.setTag(false);
check.setChecked(false);
}
selectedLanguageIndex = which;
((AlertDialog) dialog).getListView().setSelection(which);
singleChoiceAdapter.notifyDataSetChanged();
}
});
b.setNegativeButton(R.string.shared_string_cancel, null);
b.setPositiveButton(R.string.shared_string_apply, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
view.getSettings().MAP_TRANSLITERATE_NAMES.set(check.isChecked());
view.getSettings().MAP_TRANSLITERATE_NAMES.set(transliterateNames);
AlertDialog dlg = (AlertDialog) dialog;
int index = dlg.getListView().getCheckedItemPosition();
view.getSettings().MAP_PREFERRED_LOCALE.set(
@ -533,20 +563,7 @@ public class ConfigureMapMenu {
ad.notifyDataSetInvalidated();
}
});
alertDialog = b.show();
check.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
int index = alertDialog.getListView().getCheckedItemPosition();
if (index != 1) {
if (check.getTag() == null) {
alertDialog.getListView().setItemChecked(1, true);
} else {
check.setTag(null);
}
}
}
});
b.show();
return false;
}
}).createItem());