use of net.osmand.plus.utils.UiUtilities in project Osmand by osmandapp.
the class QuickSearchListAdapter method bindIndexItem.
public static void bindIndexItem(@NonNull View view, @NonNull IndexItem indexItem, FragmentActivity activity, boolean nightMode) {
OsmandApplication app = (OsmandApplication) view.getContext().getApplicationContext();
UiUtilities iconsCache = app.getUIUtilities();
DownloadIndexesThread thread = app.getDownloadThread();
DateFormat dateFormat = android.text.format.DateFormat.getMediumDateFormat(app);
TextView tvName = (TextView) view.findViewById(R.id.title);
TextView tvDesc = (TextView) view.findViewById(R.id.description);
ImageView ivButton = (ImageView) view.findViewById(R.id.secondaryIcon);
ProgressBar pbProgress = (ProgressBar) view.findViewById(R.id.progressBar);
int activeColorId = ColorUtilities.getActiveColorId(nightMode);
int defaultIconColorId = ColorUtilities.getDefaultIconColorId(nightMode);
String name = indexItem.getVisibleName(app, app.getRegions(), false);
tvName.setText(name);
Drawable buttonDrawable = null;
boolean isDownloading = indexItem.isDownloading(thread);
if (!isDownloading) {
pbProgress.setVisibility(View.GONE);
tvDesc.setVisibility(View.VISIBLE);
String pattern = app.getString(R.string.ltr_or_rtl_combine_via_bold_point);
String size = indexItem.getSizeDescription(app);
String type = indexItem.getType().getString(app);
String date = indexItem.getDate(dateFormat, true);
String description = String.format(pattern, type, date);
description = String.format(pattern, size, description);
tvDesc.setText(description);
buttonDrawable = iconsCache.getIcon(R.drawable.ic_action_gsave_dark, activeColorId);
} else {
pbProgress.setVisibility(View.VISIBLE);
tvDesc.setVisibility(View.GONE);
int progress = -1;
if (thread.getCurrentDownloadingItem() == indexItem) {
progress = thread.getCurrentDownloadingItemProgress();
}
pbProgress.setIndeterminate(progress == -1);
pbProgress.setProgress(progress);
buttonDrawable = iconsCache.getIcon(R.drawable.ic_action_remove_dark, defaultIconColorId);
}
ivButton.setImageDrawable(buttonDrawable);
}
use of net.osmand.plus.utils.UiUtilities in project Osmand by osmandapp.
the class QuickSearchPoiFilterFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final OsmandApplication app = getMyApplication();
boolean nightMode = !app.getSettings().isLightContent();
if (getArguments() != null) {
filterId = getArguments().getString(QUICK_SEARCH_POI_FILTER_ID_KEY);
nameFilterText = getArguments().getString(QUICK_SEARCH_POI_FILTER_BY_NAME_KEY);
} else if (savedInstanceState != null) {
filterId = savedInstanceState.getString(QUICK_SEARCH_POI_FILTER_ID_KEY);
nameFilterText = savedInstanceState.getString(QUICK_SEARCH_POI_FILTER_BY_NAME_KEY);
ArrayList<String> selectedList = savedInstanceState.getStringArrayList(QUICK_SEARCH_POI_FILTER_SELECTED_ADDITIONALS);
if (selectedList != null) {
selectedPoiAdditionals.addAll(selectedList);
}
ArrayList<String> collapsedList = savedInstanceState.getStringArrayList(QUICK_SEARCH_POI_FILTER_COLLAPSED_CATEGORIES);
if (collapsedList != null) {
collapsedCategories.addAll(collapsedList);
}
ArrayList<String> showAllList = savedInstanceState.getStringArrayList(QUICK_SEARCH_POI_FILTER_SHOW_ALL_CATEGORIES);
if (showAllList != null) {
showAllCategories.addAll(showAllList);
}
}
nameFilterTextOrig = "" + nameFilterText;
if (filterId != null) {
filter = app.getPoiFilters().getFilterById(filterId);
}
if (filter == null) {
filter = app.getPoiFilters().getCustomPOIFilter();
filter.clearFilter();
}
if (selectedPoiAdditionals.size() == 0) {
processFilterFields();
initListItems();
}
selectedPoiAdditionalsOrig = new TreeSet<>(selectedPoiAdditionals);
view = inflater.inflate(R.layout.search_poi_filter, container, false);
TextView description = (TextView) view.findViewById(R.id.description);
description.setText(filter.getName());
Toolbar toolbar = (Toolbar) view.findViewById(R.id.toolbar);
int colorId = ColorUtilities.getActiveButtonsAndLinksTextColorId(!isLightTheme);
Drawable icClose = app.getUIUtilities().getIcon(R.drawable.ic_action_remove_dark, colorId);
toolbar.setNavigationIcon(icClose);
toolbar.setNavigationContentDescription(R.string.shared_string_close);
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dismiss();
}
});
toolbar.setBackgroundColor(ColorUtilities.getAppBarColor(app, !isLightTheme));
toolbar.setTitleTextColor(ColorUtilities.getActiveButtonsAndLinksTextColor(app, !isLightTheme));
ImageButton moreButton = (ImageButton) view.findViewById(R.id.moreButton);
moreButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
UiUtilities iconsCache = app.getUIUtilities();
final PopupMenu optionsMenu = new PopupMenu(getContext(), v);
DirectionsDialogs.setupPopUpMenuIcon(optionsMenu);
MenuItem item;
if (!filter.isStandardFilter()) {
item = optionsMenu.getMenu().add(R.string.edit_filter).setIcon(iconsCache.getThemedIcon(R.drawable.ic_action_edit_dark));
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
editFilter();
return true;
}
});
}
if (!filter.isStandardFilter()) {
item = optionsMenu.getMenu().add(R.string.edit_filter_save_as_menu_item).setIcon(iconsCache.getThemedIcon(R.drawable.ic_action_save));
} else {
item = optionsMenu.getMenu().add(R.string.save_filter).setIcon(iconsCache.getThemedIcon(R.drawable.ic_action_save));
}
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
saveFilter();
return true;
}
});
if (!filter.isStandardFilter()) {
item = optionsMenu.getMenu().add(R.string.delete_filter).setIcon(iconsCache.getThemedIcon(R.drawable.ic_action_delete_dark));
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
deleteFilter();
return true;
}
});
}
optionsMenu.show();
}
});
listView = (ListView) view.findViewById(android.R.id.list);
listView.setBackgroundColor(ColorUtilities.getActivityBgColor(app, nightMode));
View editTextView = inflater.inflate(R.layout.poi_filter_list_item, listView, false);
editText = (EditText) editTextView.findViewById(R.id.editText);
editTextView.findViewById(R.id.divider).setVisibility(View.GONE);
editText.setText(nameFilterText);
editText.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
nameFilterText = s.toString();
updateApplyButton();
}
});
editText.setVisibility(View.VISIBLE);
final ImageView textEditIcon = (ImageView) editTextView.findViewById(R.id.icon);
textEditIcon.setImageDrawable(app.getUIUtilities().getThemedIcon(R.drawable.ic_action_search_dark));
textEditIcon.setVisibility(View.VISIBLE);
editTextView.findViewById(R.id.titleBold).setVisibility(View.GONE);
editTextView.findViewById(R.id.titleButton).setVisibility(View.GONE);
editTextView.findViewById(R.id.expandItem).setVisibility(View.GONE);
editTextView.findViewById(R.id.titleRegular).setVisibility(View.GONE);
editTextView.findViewById(R.id.switchItem).setVisibility(View.GONE);
editTextView.findViewById(R.id.checkboxItem).setVisibility(View.GONE);
listView.addHeaderView(editTextView);
View bottomShadowView = inflater.inflate(R.layout.list_shadow_footer, listView, false);
listView.addFooterView(bottomShadowView, null, false);
adapter = new PoiFilterListAdapter(app, getListItems());
listView.setAdapter(adapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
PoiFilterListItem item = adapter.getItem(position - listView.getHeaderViewsCount());
if (item != null) {
switch(item.type) {
case GROUP_HEADER:
if (item.category != null) {
if (collapsedCategories.contains(item.category)) {
collapsedCategories.remove(item.category);
} else {
collapsedCategories.add(item.category);
}
updateListView();
}
break;
case CHECKBOX_ITEM:
CheckBox checkBox = (CheckBox) view.findViewById(R.id.checkboxItem);
adapter.toggleCheckbox(item, checkBox, !checkBox.isChecked());
break;
case BUTTON_ITEM:
if (item.category != null) {
showAllCategories.add(item.category);
updateListView();
}
break;
}
}
}
});
applyFilterButtonShadow = view.findViewById(R.id.bottomButtonShadow);
applyFilterButton = (TextView) view.findViewById(R.id.bottomButton);
applyFilterButton.setText(app.getString(R.string.apply_filters));
applyFilterButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
applyFilterFields();
if (!filter.isStandardFilter()) {
filter.setSavedFilterByName(filter.getFilterByName());
if (app.getPoiFilters().editPoiFilter(filter)) {
app.getSearchUICore().refreshCustomPoiFilters();
((QuickSearchDialogFragment) getParentFragment()).replaceQueryWithUiFilter(filter, "");
((QuickSearchDialogFragment) getParentFragment()).reloadCategories();
dismiss();
}
} else {
((QuickSearchDialogFragment) getParentFragment()).replaceQueryWithUiFilter(filter, nameFilterText.trim());
dismiss();
}
}
});
updateApplyButton();
return view;
}
use of net.osmand.plus.utils.UiUtilities in project Osmand by osmandapp.
the class LocalIndexesFragment method onCreateOptionsMenu.
@SuppressWarnings("deprecation")
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
if (!this.isAdded()) {
return;
}
// Next line throws NPE in some circumstances when called from dashboard and listAdpater=null is not checked for. (Checking !this.isAdded above is not sufficient!)
if (listAdapter != null && listAdapter.getGroupCount() == 0 && getDownloadActivity().getLocalIndexInfos().size() > 0) {
for (LocalIndexInfo info : getDownloadActivity().getLocalIndexInfos()) {
listAdapter.addLocalIndexInfo(info);
}
listAdapter.sortData();
getExpandableListView().setAdapter(listAdapter);
expandAllGroups();
}
ActionBar actionBar = getDownloadActivity().getSupportActionBar();
// hide action bar from downloadindexfragment
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
boolean nightMode = !getMyApplication().getSettings().isLightContent();
UiUtilities iconsCache = getMyApplication().getUIUtilities();
int iconColorResId = ColorUtilities.getActiveButtonsAndLinksTextColorId(nightMode);
optionsMenuAdapter = new ContextMenuAdapter(requireMyApplication());
ItemClickListener listener = new ContextMenuAdapter.ItemClickListener() {
@Override
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int pos, boolean isChecked, int[] viewCoordinates) {
localOptionsMenu(itemId);
return true;
}
};
optionsMenuAdapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.shared_string_refresh, getContext()).setIcon(R.drawable.ic_action_refresh_dark).setListener(listener).setColor(getContext(), iconColorResId).createItem());
optionsMenuAdapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.shared_string_delete, getContext()).setIcon(R.drawable.ic_action_delete_dark).setListener(listener).setColor(getContext(), iconColorResId).createItem());
optionsMenuAdapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.local_index_mi_backup, getContext()).setListener(listener).createItem());
optionsMenuAdapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.local_index_mi_restore, getContext()).setListener(listener).createItem());
// doesn't work correctly
// int max = getResources().getInteger(R.integer.abs__max_action_buttons);
int max = 3;
SubMenu split = null;
for (int j = 0; j < optionsMenuAdapter.length(); j++) {
MenuItem item;
ContextMenuItem contextMenuItem = optionsMenuAdapter.getItem(j);
if (j + 1 >= max && optionsMenuAdapter.length() > max) {
if (split == null) {
Drawable icOverflowMenu = iconsCache.getIcon(R.drawable.ic_overflow_menu_white, iconColorResId);
split = menu.addSubMenu(0, 1, j + 1, R.string.shared_string_more_actions);
split.setIcon(icOverflowMenu);
split.getItem();
MenuItemCompat.setShowAsAction(split.getItem(), MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
}
item = split.add(0, contextMenuItem.getTitleId(), j + 1, contextMenuItem.getTitle());
MenuItemCompat.setShowAsAction(item, MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
} else {
item = menu.add(0, contextMenuItem.getTitleId(), j + 1, contextMenuItem.getTitle());
MenuItemCompat.setShowAsAction(item, MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
}
if (contextMenuItem.getIcon() != -1) {
Drawable icMenuItem = getMyApplication().getUIUtilities().getPaintedIcon(contextMenuItem.getIcon(), contextMenuItem.getColor());
item.setIcon(icMenuItem);
}
}
if (operationTask == null || operationTask.getStatus() == AsyncTask.Status.FINISHED) {
menu.setGroupVisible(0, true);
} else {
menu.setGroupVisible(0, false);
}
}
use of net.osmand.plus.utils.UiUtilities in project Osmand by osmandapp.
the class LocalIndexesFragment method openPopUpMenu.
private void openPopUpMenu(View v, final LocalIndexInfo info) {
UiUtilities iconsCache = getMyApplication().getUIUtilities();
final PopupMenu optionsMenu = new PopupMenu(getActivity(), v);
DirectionsDialogs.setupPopUpMenuIcon(optionsMenu);
final boolean restore = info.isBackupedData();
MenuItem item;
if ((info.getType() == LocalIndexType.MAP_DATA) || (info.getType() == LocalIndexType.DEACTIVATED)) {
item = optionsMenu.getMenu().add(restore ? R.string.local_index_mi_restore : R.string.local_index_mi_backup).setIcon(iconsCache.getThemedIcon(R.drawable.ic_type_archive));
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
performBasicOperation(restore ? R.string.local_index_mi_restore : R.string.local_index_mi_backup, info);
return true;
}
});
}
if (info.getType() != LocalIndexType.TILES_DATA) {
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) {
performBasicOperation(R.string.shared_string_rename, info);
return true;
}
});
}
if (info.getType() == LocalIndexType.TILES_DATA && ((info.getAttachedObject() instanceof TileSourceManager.TileSourceTemplate) || ((info.getAttachedObject() instanceof SQLiteTileSource) && ((SQLiteTileSource) info.getAttachedObject()).couldBeDownloadedFromInternet()))) {
item = optionsMenu.getMenu().add(R.string.shared_string_edit).setIcon(iconsCache.getThemedIcon(R.drawable.ic_action_edit_dark));
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
performBasicOperation(R.string.shared_string_edit, info);
return true;
}
});
}
if (info.getType() == LocalIndexType.TILES_DATA && (info.getAttachedObject() instanceof ITileSource) && ((ITileSource) info.getAttachedObject()).couldBeDownloadedFromInternet()) {
item = optionsMenu.getMenu().add(R.string.clear_tile_data).setIcon(iconsCache.getThemedIcon(R.drawable.ic_action_remove_dark));
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
performBasicOperation(R.string.clear_tile_data, info);
return true;
}
});
}
final IndexItem update = filesToUpdate.get(info.getFileName());
if (update != null) {
item = optionsMenu.getMenu().add(R.string.update_tile).setIcon(iconsCache.getThemedIcon(R.drawable.ic_action_import));
item.setOnMenuItemClickListener(i -> {
DownloadActivity downloadActivity = getDownloadActivity();
if (downloadActivity != null) {
downloadActivity.startDownload(update);
}
return true;
});
}
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) {
performBasicOperation(R.string.shared_string_delete, info);
return true;
}
});
optionsMenu.show();
}
use of net.osmand.plus.utils.UiUtilities in project Osmand by osmandapp.
the class MapRouteInfoMenu method setupButtonIcon.
private void setupButtonIcon(ImageView imageView, @DrawableRes int iconId) {
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
UiUtilities uiUtilities = mapActivity.getMyApplication().getUIUtilities();
Drawable normal = uiUtilities.getIcon(iconId, nightMode ? R.color.route_info_control_icon_color_dark : R.color.route_info_control_icon_color_light);
if (Build.VERSION.SDK_INT >= 21) {
Drawable active = uiUtilities.getIcon(iconId, ColorUtilities.getActiveColorId(nightMode));
normal = AndroidUtils.createPressedStateListDrawable(normal, active);
}
imageView.setImageDrawable(normal);
}
}
Aggregations