use of android.support.v7.view.ContextThemeWrapper in project Osmand by osmandapp.
the class PlanRouteFragment method onCreateView.
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
final MapActivity mapActivity = getMapActivity();
markersHelper = mapActivity.getMyApplication().getMapMarkersHelper();
planRouteContext = markersHelper.getPlanRouteContext();
planRouteContext.setListener(new MarkersPlanRouteContext.PlanRouteProgressListener() {
@Override
public void showProgressBar() {
PlanRouteFragment.this.showProgressBar();
}
@Override
public void updateProgress(int progress) {
((ProgressBar) mainView.findViewById(R.id.snap_to_road_progress_bar)).setProgress(progress);
}
@Override
public void hideProgressBar(boolean canceled) {
mainView.findViewById(R.id.snap_to_road_progress_bar).setVisibility(View.GONE);
planRouteContext.setProgressBarVisible(false);
if (!canceled && portrait && planRouteContext.isMarkersListOpened()) {
Snackbar.make(mainView, getString(R.string.route_is_calculated) + ":", Snackbar.LENGTH_LONG).setAction(R.string.show_map, new View.OnClickListener() {
@Override
public void onClick(View view) {
showHideMarkersList();
}
}).show();
}
}
@Override
public void refresh() {
adapter.notifyDataSetChanged();
mapActivity.refreshMap();
}
@Override
public void updateText() {
PlanRouteFragment.this.updateText();
}
@Override
public void showMarkersRouteOnMap(boolean adjustMap) {
PlanRouteFragment.this.showMarkersRouteOnMap(adjustMap);
}
});
// Handling screen rotation
FragmentManager fragmentManager = mapActivity.getSupportFragmentManager();
Fragment snapToRoadFragment = fragmentManager.findFragmentByTag(SnapToRoadBottomSheetDialogFragment.TAG);
if (snapToRoadFragment != null) {
((SnapToRoadBottomSheetDialogFragment) snapToRoadFragment).setListener(createSnapToRoadFragmentListener());
}
Fragment optionsFragment = fragmentManager.findFragmentByTag(PlanRouteOptionsBottomSheetDialogFragment.TAG);
if (optionsFragment != null) {
((PlanRouteOptionsBottomSheetDialogFragment) optionsFragment).setListener(createOptionsFragmentListener());
}
toolbarHeight = mapActivity.getResources().getDimensionPixelSize(R.dimen.dashboard_map_toolbar);
nightMode = mapActivity.getMyApplication().getDaynightHelper().isNightModeForMapControls();
final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme;
final int backgroundColor = ContextCompat.getColor(mapActivity, nightMode ? R.color.ctx_menu_info_view_bg_dark : R.color.ctx_menu_info_view_bg_light);
portrait = AndroidUiHelper.isOrientationPortrait(mapActivity);
fullScreen = portrait && planRouteContext.isMarkersListOpened();
int layoutRes = fullScreen ? R.layout.fragment_plan_route_full_screen : R.layout.fragment_plan_route_half_screen;
View view = View.inflate(new ContextThemeWrapper(getContext(), themeRes), layoutRes, null);
mainView = fullScreen ? view : view.findViewById(R.id.main_view);
enterPlanRouteMode();
View markersListContainer = mainView.findViewById(R.id.markers_list_container);
if (markersListContainer != null) {
markersListContainer.setBackgroundColor(backgroundColor);
}
if (portrait) {
mainView.findViewById(R.id.toolbar_divider).setBackgroundColor(ContextCompat.getColor(mapActivity, nightMode ? R.color.actionbar_dark_color : R.color.dashboard_divider_light));
Drawable arrow = getContentIcon(fullScreen ? R.drawable.ic_action_arrow_down : R.drawable.ic_action_arrow_up);
((ImageView) mainView.findViewById(R.id.up_down_icon)).setImageDrawable(arrow);
mainView.findViewById(R.id.up_down_row).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
showHideMarkersList();
}
});
mainView.findViewById(R.id.select_all_button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
selectAllOnClick();
updateSelectButton();
}
});
toolbarController = new PlanRouteToolbarController();
toolbarController.setBackBtnIconIds(R.drawable.ic_action_mode_back, R.drawable.ic_action_mode_back);
toolbarController.setTitle(getString(R.string.plan_route));
toolbarController.setOnBackButtonClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (quit(false)) {
MapMarkersDialogFragment.showInstance(mapActivity);
}
}
});
toolbarController.setSaveViewTextId(R.string.shared_string_options);
toolbarController.setOnSaveViewClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
optionsOnClick();
}
});
mapActivity.showTopToolbar(toolbarController);
if (fullScreen) {
mapActivity.findViewById(R.id.bottom_controls_container).setVisibility(View.GONE);
mainView.findViewById(R.id.plan_route_toolbar).setVisibility(View.VISIBLE);
mainView.findViewById(R.id.toolbar_divider).setVisibility(View.VISIBLE);
} else {
final int screenH = AndroidUtils.getScreenHeight(mapActivity);
final int statusBarH = AndroidUtils.getStatusBarHeight(mapActivity);
final int navBarH = AndroidUtils.getNavBarHeight(mapActivity);
final int availableHeight = (screenH - statusBarH - navBarH) / 2;
mainView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
int upDownRowH = mainView.findViewById(R.id.up_down_row).getHeight();
closedListContainerHeight = availableHeight - upDownRowH;
View listContainer = mainView.findViewById(R.id.markers_list_container);
listContainer.getLayoutParams().height = closedListContainerHeight;
listContainer.requestLayout();
ViewTreeObserver obs = mainView.getViewTreeObserver();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
obs.removeOnGlobalLayoutListener(this);
} else {
obs.removeGlobalOnLayoutListener(this);
}
}
});
}
}
Toolbar toolbar = (Toolbar) mainView.findViewById(R.id.plan_route_toolbar);
toolbar.setNavigationIcon(getContentIcon(R.drawable.ic_arrow_back));
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (quit(false)) {
MapMarkersDialogFragment.showInstance(mapActivity);
}
}
});
mainView.findViewById(R.id.options_button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
optionsOnClick();
}
});
markersRv = mainView.findViewById(R.id.markers_recycler_view);
adapter = new MapMarkersListAdapter(mapActivity);
adapter.setHasStableIds(true);
adapter.setSnappedToRoadPoints(planRouteContext.getSnappedToRoadPoints());
final ItemTouchHelper touchHelper = new ItemTouchHelper(new MapMarkersItemTouchHelperCallback(adapter));
touchHelper.attachToRecyclerView(markersRv);
adapter.setAdapterListener(new MapMarkersListAdapter.MapMarkersListAdapterListener() {
private int fromPosition;
private int toPosition;
@Override
public void onDisableRoundTripClick() {
roundTripOnClick();
}
@Override
public void onCheckBoxClick(View view) {
int pos = markersRv.getChildAdapterPosition(view);
if (pos == RecyclerView.NO_POSITION) {
return;
}
Object item = adapter.getItem(pos);
if (item instanceof Location) {
markersHelper.setStartFromMyLocation(!mapActivity.getMyApplication().getSettings().ROUTE_MAP_MARKERS_START_MY_LOC.get());
} else if (item instanceof MapMarker) {
MapMarker marker = (MapMarker) item;
selectedCount = marker.selected ? selectedCount - 1 : selectedCount + 1;
marker.selected = !marker.selected;
markersHelper.updateMapMarker(marker, false);
}
adapter.reloadData();
adapter.notifyDataSetChanged();
updateSelectButton();
planRouteContext.recreateSnapTrkSegment(false);
}
@Override
public void onItemClick(View v) {
int pos = markersRv.getChildAdapterPosition(v);
if (pos == RecyclerView.NO_POSITION) {
return;
}
Object item = adapter.getItem(pos);
if (item instanceof Location) {
Location loc = (Location) item;
moveMapToPosition(loc.getLatitude(), loc.getLongitude());
} else if (item instanceof MapMarker) {
MapMarker marker = (MapMarker) item;
moveMapToPosition(marker.getLatitude(), marker.getLongitude());
}
}
@Override
public void onDragStarted(RecyclerView.ViewHolder holder) {
fromPosition = holder.getAdapterPosition();
touchHelper.startDrag(holder);
}
@Override
public void onDragEnded(RecyclerView.ViewHolder holder) {
toPosition = holder.getAdapterPosition();
if (toPosition >= 0 && fromPosition >= 0) {
mapActivity.getMyApplication().getMapMarkersHelper().reorderActiveMarkersIfNeeded();
mapActivity.refreshMap();
adapter.reloadData();
try {
adapter.notifyDataSetChanged();
} catch (Exception e) {
// to avoid crash because of:
// java.lang.IllegalStateException: Cannot call this method while RecyclerView is computing a layout or scrolling
}
planRouteContext.recreateSnapTrkSegment(false);
}
}
});
markersRv.setPadding(0, (int) mapActivity.getResources().getDimension(R.dimen.map_markers_recycler_view_padding_top), 0, (int) mapActivity.getResources().getDimension(R.dimen.map_markers_recycler_view_padding_bottom));
markersRv.setClipToPadding(false);
markersRv.setLayoutManager(new LinearLayoutManager(getContext()));
markersRv.setAdapter(adapter);
if (planRouteContext.isProgressBarVisible()) {
showProgressBar();
}
return view;
}
use of android.support.v7.view.ContextThemeWrapper in project Osmand by osmandapp.
the class FavouritesBottomSheetMenuFragment method createMenuItems.
@Override
public void createMenuItems(final Bundle savedInstanceState) {
Bundle args = getArguments();
if (args != null) {
target = args.getBoolean(TARGET);
intermediate = args.getBoolean(INTERMEDIATE);
}
if (savedInstanceState != null && savedInstanceState.getBoolean(IS_SORTED)) {
sortByDist = savedInstanceState.getBoolean(SORTED_BY_TYPE);
}
favouritePoints = getMyApplication().getFavorites().getVisibleFavouritePoints();
recyclerView = new RecyclerView(getContext());
final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme;
recyclerView = (RecyclerView) View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.recyclerview, null);
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
location = getMyApplication().getLocationProvider().getLastKnownLocation();
if (location != null) {
latLon = new LatLon(location.getLatitude(), location.getLongitude());
}
adapter = new FavouritesAdapter(getContext(), favouritePoints);
sortFavourites();
final BottomSheetItemTitleWithDescrAndButton[] title = new BottomSheetItemTitleWithDescrAndButton[1];
title[0] = (BottomSheetItemTitleWithDescrAndButton) new BottomSheetItemTitleWithDescrAndButton.Builder().setButtonIcons(null, getIconForButton()).setButtonTitle(getTextForButton(sortByDist)).setonButtonClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
sortFavourites();
title[0].setButtonIcons(null, getIconForButton());
title[0].setButtonText(getTextForButton(sortByDist));
title[0].setDescription(getTextForButton(!sortByDist));
}
}).setDescription(getTextForButton(!sortByDist)).setTitle(getString(R.string.favourites)).setLayoutId(R.layout.bottom_sheet_item_title_with_descr_and_button).create();
items.add(title[0]);
adapter.setItemClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int position = recyclerView.getChildAdapterPosition(v);
if (position == RecyclerView.NO_POSITION) {
return;
}
selectFavorite(favouritePoints.get(position));
}
});
recyclerView.setAdapter(adapter);
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
super.onScrollStateChanged(recyclerView, newState);
compassUpdateAllowed = newState == RecyclerView.SCROLL_STATE_IDLE;
}
});
items.add(new BaseBottomSheetItem.Builder().setCustomView(recyclerView).create());
}
use of android.support.v7.view.ContextThemeWrapper in project Osmand by osmandapp.
the class CreateEditActionDialog method onCreateDialog.
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
OsmandApplication application = (OsmandApplication) getActivity().getApplication();
boolean light = application.getSettings().isLightContent() && !application.getDaynightHelper().isNightMode();
Dialog dialog = new Dialog(new ContextThemeWrapper(getActivity(), light ? R.style.Dialog90Light : R.style.Dialog90Dark), getTheme());
dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
dialog.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
return dialog;
}
use of android.support.v7.view.ContextThemeWrapper in project Osmand by osmandapp.
the class AddQuickActionDialog method onCreateDialog.
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
OsmandApplication application = (OsmandApplication) getActivity().getApplication();
boolean light = application.getSettings().isLightContent() && !application.getDaynightHelper().isNightMode();
return new Dialog(new ContextThemeWrapper(getActivity(), light ? R.style.Dialog90Light : R.style.Dialog90Dark), getTheme());
}
use of android.support.v7.view.ContextThemeWrapper in project Osmand by osmandapp.
the class QuickActionListFragment method createAndShowDeleteDialog.
void createAndShowDeleteDialog(final int itemPosition, final String itemName) {
AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(getContext(), R.style.OsmandLightTheme));
builder.setTitle(R.string.quick_actions_delete);
builder.setMessage(getResources().getString(R.string.quick_actions_delete_text, itemName));
builder.setIcon(getMyApplication().getIconsCache().getThemedIcon(R.drawable.ic_action_delete_dark));
builder.setPositiveButton(R.string.shared_string_yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
adapter.deleteItem(itemPosition);
dialog.dismiss();
}
});
builder.setNegativeButton(R.string.shared_string_no, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.dismiss();
}
});
AlertDialog dialog = builder.show();
dialog.getButton(DialogInterface.BUTTON_NEGATIVE).setTextColor(ContextCompat.getColor(getContext(), R.color.dashboard_blue));
dialog.getButton(DialogInterface.BUTTON_POSITIVE).setTextColor(ContextCompat.getColor(getContext(), R.color.dashboard_blue));
}
Aggregations