RTL - Step 4
This commit is contained in:
parent
e6d26f5c19
commit
f3f94a6a48
5 changed files with 134 additions and 89 deletions
|
@ -700,6 +700,13 @@ public class AndroidUtils {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void setTextDirection(@NonNull TextView tv, boolean rtl) {
|
||||||
|
if (isSupportRTL()) {
|
||||||
|
int textDirection = rtl ? View.TEXT_DIRECTION_RTL : View.TEXT_DIRECTION_LTR;
|
||||||
|
tv.setTextDirection(textDirection);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static int getLayoutDirection(@NonNull Context ctx) {
|
public static int getLayoutDirection(@NonNull Context ctx) {
|
||||||
Locale currentLocale = ctx.getResources().getConfiguration().locale;
|
Locale currentLocale = ctx.getResources().getConfiguration().locale;
|
||||||
return TextUtilsCompat.getLayoutDirectionFromLocale(currentLocale);
|
return TextUtilsCompat.getLayoutDirectionFromLocale(currentLocale);
|
||||||
|
|
|
@ -63,12 +63,18 @@ public class SimplePopUpMenuItemAdapter
|
||||||
public static class SimplePopUpMenuItem {
|
public static class SimplePopUpMenuItem {
|
||||||
private CharSequence title;
|
private CharSequence title;
|
||||||
private Drawable icon;
|
private Drawable icon;
|
||||||
|
private View.OnClickListener onClickListener;
|
||||||
|
|
||||||
public SimplePopUpMenuItem(CharSequence title, Drawable icon) {
|
public SimplePopUpMenuItem(CharSequence title, Drawable icon) {
|
||||||
this.title = title;
|
this.title = title;
|
||||||
this.icon = icon;
|
this.icon = icon;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public SimplePopUpMenuItem(CharSequence title, Drawable icon, View.OnClickListener onClickListener) {
|
||||||
|
this(title, icon);
|
||||||
|
this.onClickListener = onClickListener;
|
||||||
|
}
|
||||||
|
|
||||||
public CharSequence getTitle() {
|
public CharSequence getTitle() {
|
||||||
return title;
|
return title;
|
||||||
}
|
}
|
||||||
|
@ -76,5 +82,9 @@ public class SimplePopUpMenuItemAdapter
|
||||||
public Drawable getIcon() {
|
public Drawable getIcon() {
|
||||||
return icon;
|
return icon;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public View.OnClickListener getOnClickListener() {
|
||||||
|
return onClickListener;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -717,18 +717,23 @@ public class UiUtilities {
|
||||||
int contentPadding = themedCtx.getResources().getDimensionPixelSize(R.dimen.content_padding);
|
int contentPadding = themedCtx.getResources().getDimensionPixelSize(R.dimen.content_padding);
|
||||||
int contentPaddingHalf = themedCtx.getResources().getDimensionPixelSize(R.dimen.content_padding_half);
|
int contentPaddingHalf = themedCtx.getResources().getDimensionPixelSize(R.dimen.content_padding_half);
|
||||||
int defaultListTextSize = themedCtx.getResources().getDimensionPixelSize(R.dimen.default_list_text_size);
|
int defaultListTextSize = themedCtx.getResources().getDimensionPixelSize(R.dimen.default_list_text_size);
|
||||||
|
int standardIconSize = themedCtx.getResources().getDimensionPixelSize(R.dimen.standard_icon_size);
|
||||||
|
boolean hasIcon = false;
|
||||||
|
|
||||||
List<String> titles = new ArrayList<>();
|
List<String> titles = new ArrayList<>();
|
||||||
for (SimplePopUpMenuItem item : items) {
|
for (SimplePopUpMenuItem item : items) {
|
||||||
titles.add(String.valueOf(item.getTitle()));
|
titles.add(String.valueOf(item.getTitle()));
|
||||||
|
hasIcon = hasIcon || item.getIcon() != null;
|
||||||
}
|
}
|
||||||
float itemWidth = AndroidUtils.getTextMaxWidth(defaultListTextSize, titles) + contentPadding;
|
float itemWidth = AndroidUtils.getTextMaxWidth(defaultListTextSize, titles) + contentPadding;
|
||||||
|
float iconPartWidth = hasIcon ? standardIconSize + contentPaddingHalf : 0;
|
||||||
|
int totalWidth = (int) (Math.max(itemWidth, minWidth) + iconPartWidth);
|
||||||
|
|
||||||
SimplePopUpMenuItemAdapter adapter =
|
SimplePopUpMenuItemAdapter adapter =
|
||||||
new SimplePopUpMenuItemAdapter(themedCtx, R.layout.popup_menu_item, items);
|
new SimplePopUpMenuItemAdapter(themedCtx, R.layout.popup_menu_item, items);
|
||||||
final ListPopupWindow listPopupWindow = new ListPopupWindow(themedCtx);
|
final ListPopupWindow listPopupWindow = new ListPopupWindow(themedCtx);
|
||||||
listPopupWindow.setAnchorView(v);
|
listPopupWindow.setAnchorView(v);
|
||||||
listPopupWindow.setContentWidth((int) (Math.max(itemWidth, minWidth)));
|
listPopupWindow.setContentWidth((int) (totalWidth));
|
||||||
listPopupWindow.setDropDownGravity(Gravity.END | Gravity.TOP);
|
listPopupWindow.setDropDownGravity(Gravity.END | Gravity.TOP);
|
||||||
listPopupWindow.setVerticalOffset(-v.getHeight() + contentPaddingHalf);
|
listPopupWindow.setVerticalOffset(-v.getHeight() + contentPaddingHalf);
|
||||||
listPopupWindow.setModal(true);
|
listPopupWindow.setModal(true);
|
||||||
|
|
|
@ -23,6 +23,7 @@ import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.view.inputmethod.InputMethodManager;
|
import android.view.inputmethod.InputMethodManager;
|
||||||
import android.widget.AbsListView;
|
import android.widget.AbsListView;
|
||||||
|
import android.widget.AdapterView;
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.CheckBox;
|
import android.widget.CheckBox;
|
||||||
|
@ -40,7 +41,6 @@ import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.appcompat.app.AlertDialog;
|
import androidx.appcompat.app.AlertDialog;
|
||||||
import androidx.appcompat.view.ActionMode;
|
import androidx.appcompat.view.ActionMode;
|
||||||
import androidx.appcompat.widget.PopupMenu;
|
|
||||||
import androidx.appcompat.widget.SearchView;
|
import androidx.appcompat.widget.SearchView;
|
||||||
import androidx.core.content.ContextCompat;
|
import androidx.core.content.ContextCompat;
|
||||||
import androidx.core.view.MenuItemCompat;
|
import androidx.core.view.MenuItemCompat;
|
||||||
|
@ -69,13 +69,13 @@ import net.osmand.plus.OsmAndFormatter;
|
||||||
import net.osmand.plus.OsmandApplication;
|
import net.osmand.plus.OsmandApplication;
|
||||||
import net.osmand.plus.OsmandPlugin;
|
import net.osmand.plus.OsmandPlugin;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
|
import net.osmand.plus.SimplePopUpMenuItemAdapter;
|
||||||
import net.osmand.plus.UiUtilities;
|
import net.osmand.plus.UiUtilities;
|
||||||
import net.osmand.plus.activities.MapActivity;
|
import net.osmand.plus.activities.MapActivity;
|
||||||
import net.osmand.plus.activities.OsmandBaseExpandableListAdapter;
|
import net.osmand.plus.activities.OsmandBaseExpandableListAdapter;
|
||||||
import net.osmand.plus.activities.SavingTrackHelper;
|
import net.osmand.plus.activities.SavingTrackHelper;
|
||||||
import net.osmand.plus.activities.TrackActivity;
|
import net.osmand.plus.activities.TrackActivity;
|
||||||
import net.osmand.plus.base.OsmandExpandableListFragment;
|
import net.osmand.plus.base.OsmandExpandableListFragment;
|
||||||
import net.osmand.plus.dialogs.DirectionsDialogs;
|
|
||||||
import net.osmand.plus.helpers.AndroidUiHelper;
|
import net.osmand.plus.helpers.AndroidUiHelper;
|
||||||
import net.osmand.plus.helpers.GpxUiHelper.GPXDataSetType;
|
import net.osmand.plus.helpers.GpxUiHelper.GPXDataSetType;
|
||||||
import net.osmand.plus.mapmarkers.CoordinateInputDialogFragment;
|
import net.osmand.plus.mapmarkers.CoordinateInputDialogFragment;
|
||||||
|
@ -1454,112 +1454,133 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment implement
|
||||||
}
|
}
|
||||||
|
|
||||||
private void openPopUpMenu(View v, final GpxInfo gpxInfo) {
|
private void openPopUpMenu(View v, final GpxInfo gpxInfo) {
|
||||||
|
final List<SimplePopUpMenuItemAdapter.SimplePopUpMenuItem> items = new ArrayList<>();
|
||||||
UiUtilities iconsCache = getMyApplication().getUIUtilities();
|
UiUtilities iconsCache = getMyApplication().getUIUtilities();
|
||||||
final PopupMenu optionsMenu = new PopupMenu(getActivity(), v);
|
|
||||||
DirectionsDialogs.setupPopUpMenuIcon(optionsMenu);
|
|
||||||
|
|
||||||
MenuItem item = optionsMenu.getMenu().add(R.string.shared_string_show_on_map).setIcon(iconsCache.getThemedIcon(R.drawable.ic_show_on_map));
|
items.add(new SimplePopUpMenuItemAdapter.SimplePopUpMenuItem(
|
||||||
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
|
getString(R.string.shared_string_show_on_map),
|
||||||
@Override
|
iconsCache.getThemedIcon(R.drawable.ic_show_on_map),
|
||||||
public boolean onMenuItemClick(MenuItem item) {
|
new View.OnClickListener() {
|
||||||
showGpxOnMap(gpxInfo);
|
@Override
|
||||||
return true;
|
public void onClick(View v) {
|
||||||
}
|
showGpxOnMap(gpxInfo);
|
||||||
});
|
}
|
||||||
|
}
|
||||||
|
));
|
||||||
|
|
||||||
GPXTrackAnalysis analysis;
|
GPXTrackAnalysis analysis;
|
||||||
if ((analysis = getGpxTrackAnalysis(gpxInfo, app, null)) != null) {
|
if ((analysis = getGpxTrackAnalysis(gpxInfo, app, null)) != null) {
|
||||||
if (analysis.totalDistance != 0 && !gpxInfo.currentlyRecordingTrack) {
|
if (analysis.totalDistance != 0 && !gpxInfo.currentlyRecordingTrack) {
|
||||||
item = optionsMenu.getMenu().add(R.string.analyze_on_map).setIcon(iconsCache.getThemedIcon(R.drawable.ic_action_info_dark));
|
items.add(new SimplePopUpMenuItemAdapter.SimplePopUpMenuItem(
|
||||||
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
|
getString(R.string.analyze_on_map),
|
||||||
@Override
|
iconsCache.getThemedIcon(R.drawable.ic_action_info_dark),
|
||||||
public boolean onMenuItemClick(MenuItem item) {
|
new View.OnClickListener() {
|
||||||
new OpenGpxDetailsTask(gpxInfo).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
@Override
|
||||||
return true;
|
public void onClick(View v) {
|
||||||
}
|
new OpenGpxDetailsTask(gpxInfo).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||||
});
|
}
|
||||||
|
}
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
item = optionsMenu.getMenu().add(R.string.shared_string_move).setIcon(iconsCache.getThemedIcon(R.drawable.ic_action_folder_stroke));
|
items.add(new SimplePopUpMenuItemAdapter.SimplePopUpMenuItem(
|
||||||
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
|
getString(R.string.shared_string_move),
|
||||||
@Override
|
iconsCache.getThemedIcon(R.drawable.ic_action_folder_stroke),
|
||||||
public boolean onMenuItemClick(MenuItem item) {
|
new View.OnClickListener() {
|
||||||
moveGpx(gpxInfo);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
item = optionsMenu.getMenu().add(R.string.shared_string_rename)
|
|
||||||
.setIcon(iconsCache.getThemedIcon(R.drawable.ic_action_edit_dark));
|
|
||||||
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
|
|
||||||
@Override
|
|
||||||
public boolean onMenuItemClick(MenuItem item) {
|
|
||||||
final SelectedGpxFile selectedGpxFile = selectedGpxHelper.getSelectedFileByPath(gpxInfo.file.getPath());
|
|
||||||
FileUtils.renameFile(getActivity(), gpxInfo.file, new RenameCallback() {
|
|
||||||
@Override
|
@Override
|
||||||
public void renamedTo(File file) {
|
public void onClick(View v) {
|
||||||
asyncLoader = new LoadGpxTask();
|
moveGpx(gpxInfo);
|
||||||
asyncLoader.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, getActivity());
|
|
||||||
if (selectedGpxFile != null && selectedGpxFile.getGpxFile() != null) {
|
|
||||||
selectedGpxFile.getGpxFile().path = file.getPath();
|
|
||||||
selectedGpxHelper.updateSelectedGpxFile(selectedGpxFile);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
return true;
|
));
|
||||||
}
|
|
||||||
});
|
items.add(new SimplePopUpMenuItemAdapter.SimplePopUpMenuItem(
|
||||||
|
getString(R.string.shared_string_rename),
|
||||||
|
iconsCache.getThemedIcon(R.drawable.ic_action_edit_dark),
|
||||||
|
new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
final SelectedGpxFile selectedGpxFile = selectedGpxHelper.getSelectedFileByPath(gpxInfo.file.getPath());
|
||||||
|
FileUtils.renameFile(getActivity(), gpxInfo.file, new RenameCallback() {
|
||||||
|
@Override
|
||||||
|
public void renamedTo(File file) {
|
||||||
|
asyncLoader = new LoadGpxTask();
|
||||||
|
asyncLoader.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, getActivity());
|
||||||
|
if (selectedGpxFile != null && selectedGpxFile.getGpxFile() != null) {
|
||||||
|
selectedGpxFile.getGpxFile().path = file.getPath();
|
||||||
|
selectedGpxHelper.updateSelectedGpxFile(selectedGpxFile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
));
|
||||||
|
|
||||||
Drawable shareIcon = iconsCache.getThemedIcon((R.drawable.ic_action_gshare_dark));
|
Drawable shareIcon = iconsCache.getThemedIcon((R.drawable.ic_action_gshare_dark));
|
||||||
item = optionsMenu.getMenu().add(R.string.shared_string_share)
|
items.add(new SimplePopUpMenuItemAdapter.SimplePopUpMenuItem(
|
||||||
.setIcon(AndroidUtils.getDrawableForDirection(app, shareIcon));
|
getString(R.string.shared_string_share),
|
||||||
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
|
AndroidUtils.getDrawableForDirection(app, shareIcon),
|
||||||
@Override
|
new View.OnClickListener() {
|
||||||
public boolean onMenuItemClick(MenuItem item) {
|
@Override
|
||||||
final Uri fileUri = AndroidUtils.getUriForFile(getMyApplication(), gpxInfo.file);
|
public void onClick(View v) {
|
||||||
final Intent sendIntent = new Intent(Intent.ACTION_SEND);
|
final Uri fileUri = AndroidUtils.getUriForFile(getMyApplication(), gpxInfo.file);
|
||||||
sendIntent.putExtra(Intent.EXTRA_STREAM, fileUri);
|
final Intent sendIntent = new Intent(Intent.ACTION_SEND);
|
||||||
sendIntent.setType("text/plain");
|
sendIntent.putExtra(Intent.EXTRA_STREAM, fileUri);
|
||||||
sendIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
sendIntent.setType("text/plain");
|
||||||
startActivity(sendIntent);
|
sendIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
||||||
return true;
|
startActivity(sendIntent);
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
));
|
||||||
|
|
||||||
final OsmEditingPlugin osmEditingPlugin = OsmandPlugin.getEnabledPlugin(OsmEditingPlugin.class);
|
final OsmEditingPlugin osmEditingPlugin = OsmandPlugin.getEnabledPlugin(OsmEditingPlugin.class);
|
||||||
if (osmEditingPlugin != null && osmEditingPlugin.isActive()) {
|
if (osmEditingPlugin != null && osmEditingPlugin.isActive()) {
|
||||||
item = optionsMenu.getMenu().add(R.string.shared_string_export).setIcon(iconsCache.getThemedIcon(R.drawable.ic_action_export));
|
items.add(new SimplePopUpMenuItemAdapter.SimplePopUpMenuItem(
|
||||||
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
|
getString(R.string.shared_string_export),
|
||||||
@Override
|
iconsCache.getThemedIcon(R.drawable.ic_action_export),
|
||||||
public boolean onMenuItemClick(MenuItem item) {
|
new View.OnClickListener() {
|
||||||
osmEditingPlugin.sendGPXFiles(getActivity(), AvailableGPXFragment.this, gpxInfo);
|
@Override
|
||||||
return true;
|
public void onClick(View v) {
|
||||||
}
|
osmEditingPlugin.sendGPXFiles(getActivity(), AvailableGPXFragment.this, gpxInfo);
|
||||||
});
|
}
|
||||||
|
}
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
item = optionsMenu.getMenu().add(R.string.shared_string_delete)
|
items.add(new SimplePopUpMenuItemAdapter.SimplePopUpMenuItem(
|
||||||
.setIcon(iconsCache.getThemedIcon(R.drawable.ic_action_delete_dark));
|
getString(R.string.shared_string_delete),
|
||||||
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
|
iconsCache.getThemedIcon(R.drawable.ic_action_delete_dark),
|
||||||
@Override
|
new View.OnClickListener() {
|
||||||
public boolean onMenuItemClick(MenuItem item) {
|
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
|
||||||
builder.setMessage(R.string.recording_delete_confirm);
|
|
||||||
builder.setPositiveButton(R.string.shared_string_yes, new DialogInterface.OnClickListener() {
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(View v) {
|
||||||
operationTask = new DeleteGpxTask();
|
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||||
operationTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, gpxInfo);
|
builder.setMessage(R.string.recording_delete_confirm);
|
||||||
|
builder.setPositiveButton(R.string.shared_string_yes, new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
operationTask = new DeleteGpxTask();
|
||||||
|
operationTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, gpxInfo);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
builder.setNegativeButton(R.string.shared_string_cancel, null);
|
||||||
|
builder.show();
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
builder.setNegativeButton(R.string.shared_string_cancel, null);
|
));
|
||||||
builder.show();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
optionsMenu.show();
|
|
||||||
|
|
||||||
|
UiUtilities.createListPopupWindow(
|
||||||
|
getContext(), v, v.getWidth(), items, new AdapterView.OnItemClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||||
|
if (position < items.size()) {
|
||||||
|
View.OnClickListener listener = items.get(position).getOnClickListener();
|
||||||
|
if (listener != null) {
|
||||||
|
listener.onClick(view);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}).show();
|
||||||
}
|
}
|
||||||
|
|
||||||
public class DeleteGpxTask extends AsyncTask<GpxInfo, GpxInfo, String> {
|
public class DeleteGpxTask extends AsyncTask<GpxInfo, GpxInfo, String> {
|
||||||
|
|
|
@ -1223,6 +1223,8 @@ public class MapInfoWidgetsFactory {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
AndroidUtils.setTextDirection(latitudeText, false);
|
||||||
|
AndroidUtils.setTextDirection(longitudeText, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("SetTextI18n")
|
@SuppressLint("SetTextI18n")
|
||||||
|
|
Loading…
Reference in a new issue