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) {
|
||||
Locale currentLocale = ctx.getResources().getConfiguration().locale;
|
||||
return TextUtilsCompat.getLayoutDirectionFromLocale(currentLocale);
|
||||
|
|
|
@ -63,12 +63,18 @@ public class SimplePopUpMenuItemAdapter
|
|||
public static class SimplePopUpMenuItem {
|
||||
private CharSequence title;
|
||||
private Drawable icon;
|
||||
private View.OnClickListener onClickListener;
|
||||
|
||||
public SimplePopUpMenuItem(CharSequence title, Drawable icon) {
|
||||
this.title = title;
|
||||
this.icon = icon;
|
||||
}
|
||||
|
||||
public SimplePopUpMenuItem(CharSequence title, Drawable icon, View.OnClickListener onClickListener) {
|
||||
this(title, icon);
|
||||
this.onClickListener = onClickListener;
|
||||
}
|
||||
|
||||
public CharSequence getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
@ -76,5 +82,9 @@ public class SimplePopUpMenuItemAdapter
|
|||
public Drawable getIcon() {
|
||||
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 contentPaddingHalf = themedCtx.getResources().getDimensionPixelSize(R.dimen.content_padding_half);
|
||||
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<>();
|
||||
for (SimplePopUpMenuItem item : items) {
|
||||
titles.add(String.valueOf(item.getTitle()));
|
||||
hasIcon = hasIcon || item.getIcon() != null;
|
||||
}
|
||||
float itemWidth = AndroidUtils.getTextMaxWidth(defaultListTextSize, titles) + contentPadding;
|
||||
float iconPartWidth = hasIcon ? standardIconSize + contentPaddingHalf : 0;
|
||||
int totalWidth = (int) (Math.max(itemWidth, minWidth) + iconPartWidth);
|
||||
|
||||
SimplePopUpMenuItemAdapter adapter =
|
||||
new SimplePopUpMenuItemAdapter(themedCtx, R.layout.popup_menu_item, items);
|
||||
final ListPopupWindow listPopupWindow = new ListPopupWindow(themedCtx);
|
||||
listPopupWindow.setAnchorView(v);
|
||||
listPopupWindow.setContentWidth((int) (Math.max(itemWidth, minWidth)));
|
||||
listPopupWindow.setContentWidth((int) (totalWidth));
|
||||
listPopupWindow.setDropDownGravity(Gravity.END | Gravity.TOP);
|
||||
listPopupWindow.setVerticalOffset(-v.getHeight() + contentPaddingHalf);
|
||||
listPopupWindow.setModal(true);
|
||||
|
|
|
@ -23,6 +23,7 @@ import android.view.View;
|
|||
import android.view.ViewGroup;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.AbsListView;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.Button;
|
||||
import android.widget.CheckBox;
|
||||
|
@ -40,7 +41,6 @@ import androidx.annotation.NonNull;
|
|||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.appcompat.view.ActionMode;
|
||||
import androidx.appcompat.widget.PopupMenu;
|
||||
import androidx.appcompat.widget.SearchView;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.core.view.MenuItemCompat;
|
||||
|
@ -69,13 +69,13 @@ import net.osmand.plus.OsmAndFormatter;
|
|||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.OsmandPlugin;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.SimplePopUpMenuItemAdapter;
|
||||
import net.osmand.plus.UiUtilities;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.activities.OsmandBaseExpandableListAdapter;
|
||||
import net.osmand.plus.activities.SavingTrackHelper;
|
||||
import net.osmand.plus.activities.TrackActivity;
|
||||
import net.osmand.plus.base.OsmandExpandableListFragment;
|
||||
import net.osmand.plus.dialogs.DirectionsDialogs;
|
||||
import net.osmand.plus.helpers.AndroidUiHelper;
|
||||
import net.osmand.plus.helpers.GpxUiHelper.GPXDataSetType;
|
||||
import net.osmand.plus.mapmarkers.CoordinateInputDialogFragment;
|
||||
|
@ -1454,112 +1454,133 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment implement
|
|||
}
|
||||
|
||||
private void openPopUpMenu(View v, final GpxInfo gpxInfo) {
|
||||
final List<SimplePopUpMenuItemAdapter.SimplePopUpMenuItem> items = new ArrayList<>();
|
||||
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));
|
||||
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
|
||||
@Override
|
||||
public boolean onMenuItemClick(MenuItem item) {
|
||||
showGpxOnMap(gpxInfo);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
items.add(new SimplePopUpMenuItemAdapter.SimplePopUpMenuItem(
|
||||
getString(R.string.shared_string_show_on_map),
|
||||
iconsCache.getThemedIcon(R.drawable.ic_show_on_map),
|
||||
new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
showGpxOnMap(gpxInfo);
|
||||
}
|
||||
}
|
||||
));
|
||||
|
||||
GPXTrackAnalysis analysis;
|
||||
if ((analysis = getGpxTrackAnalysis(gpxInfo, app, null)) != null) {
|
||||
if (analysis.totalDistance != 0 && !gpxInfo.currentlyRecordingTrack) {
|
||||
item = optionsMenu.getMenu().add(R.string.analyze_on_map).setIcon(iconsCache.getThemedIcon(R.drawable.ic_action_info_dark));
|
||||
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
|
||||
@Override
|
||||
public boolean onMenuItemClick(MenuItem item) {
|
||||
new OpenGpxDetailsTask(gpxInfo).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
items.add(new SimplePopUpMenuItemAdapter.SimplePopUpMenuItem(
|
||||
getString(R.string.analyze_on_map),
|
||||
iconsCache.getThemedIcon(R.drawable.ic_action_info_dark),
|
||||
new View.OnClickListener() {
|
||||
@Override
|
||||
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));
|
||||
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
|
||||
@Override
|
||||
public boolean onMenuItemClick(MenuItem item) {
|
||||
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() {
|
||||
items.add(new SimplePopUpMenuItemAdapter.SimplePopUpMenuItem(
|
||||
getString(R.string.shared_string_move),
|
||||
iconsCache.getThemedIcon(R.drawable.ic_action_folder_stroke),
|
||||
new View.OnClickListener() {
|
||||
@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);
|
||||
}
|
||||
public void onClick(View v) {
|
||||
moveGpx(gpxInfo);
|
||||
}
|
||||
});
|
||||
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));
|
||||
item = optionsMenu.getMenu().add(R.string.shared_string_share)
|
||||
.setIcon(AndroidUtils.getDrawableForDirection(app, shareIcon));
|
||||
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
|
||||
@Override
|
||||
public boolean onMenuItemClick(MenuItem item) {
|
||||
final Uri fileUri = AndroidUtils.getUriForFile(getMyApplication(), gpxInfo.file);
|
||||
final Intent sendIntent = new Intent(Intent.ACTION_SEND);
|
||||
sendIntent.putExtra(Intent.EXTRA_STREAM, fileUri);
|
||||
sendIntent.setType("text/plain");
|
||||
sendIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
||||
startActivity(sendIntent);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
items.add(new SimplePopUpMenuItemAdapter.SimplePopUpMenuItem(
|
||||
getString(R.string.shared_string_share),
|
||||
AndroidUtils.getDrawableForDirection(app, shareIcon),
|
||||
new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
final Uri fileUri = AndroidUtils.getUriForFile(getMyApplication(), gpxInfo.file);
|
||||
final Intent sendIntent = new Intent(Intent.ACTION_SEND);
|
||||
sendIntent.putExtra(Intent.EXTRA_STREAM, fileUri);
|
||||
sendIntent.setType("text/plain");
|
||||
sendIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
||||
startActivity(sendIntent);
|
||||
}
|
||||
}
|
||||
));
|
||||
|
||||
final OsmEditingPlugin osmEditingPlugin = OsmandPlugin.getEnabledPlugin(OsmEditingPlugin.class);
|
||||
if (osmEditingPlugin != null && osmEditingPlugin.isActive()) {
|
||||
item = optionsMenu.getMenu().add(R.string.shared_string_export).setIcon(iconsCache.getThemedIcon(R.drawable.ic_action_export));
|
||||
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
|
||||
@Override
|
||||
public boolean onMenuItemClick(MenuItem item) {
|
||||
osmEditingPlugin.sendGPXFiles(getActivity(), AvailableGPXFragment.this, gpxInfo);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
items.add(new SimplePopUpMenuItemAdapter.SimplePopUpMenuItem(
|
||||
getString(R.string.shared_string_export),
|
||||
iconsCache.getThemedIcon(R.drawable.ic_action_export),
|
||||
new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
osmEditingPlugin.sendGPXFiles(getActivity(), AvailableGPXFragment.this, gpxInfo);
|
||||
}
|
||||
}
|
||||
));
|
||||
}
|
||||
|
||||
item = optionsMenu.getMenu().add(R.string.shared_string_delete)
|
||||
.setIcon(iconsCache.getThemedIcon(R.drawable.ic_action_delete_dark));
|
||||
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
|
||||
@Override
|
||||
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() {
|
||||
items.add(new SimplePopUpMenuItemAdapter.SimplePopUpMenuItem(
|
||||
getString(R.string.shared_string_delete),
|
||||
iconsCache.getThemedIcon(R.drawable.ic_action_delete_dark),
|
||||
new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
operationTask = new DeleteGpxTask();
|
||||
operationTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, gpxInfo);
|
||||
public void onClick(View v) {
|
||||
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
|
||||
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> {
|
||||
|
|
|
@ -1223,6 +1223,8 @@ public class MapInfoWidgetsFactory {
|
|||
}
|
||||
}
|
||||
});
|
||||
AndroidUtils.setTextDirection(latitudeText, false);
|
||||
AndroidUtils.setTextDirection(longitudeText, false);
|
||||
}
|
||||
|
||||
@SuppressLint("SetTextI18n")
|
||||
|
|
Loading…
Reference in a new issue