Search in sources :

Example 26 with ContextThemeWrapper

use of android.support.v7.view.ContextThemeWrapper in project material-about-library by daniel-stoneuk.

the class MaterialAboutFragment method onCreateView.

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    int style = getTheme();
    // create ContextThemeWrapper from the original Activity Context with the custom theme
    final Context contextThemeWrapper = new android.view.ContextThemeWrapper(getActivity(), style);
    LayoutInflater localInflater = inflater.cloneInContext(contextThemeWrapper);
    View rootView = localInflater.inflate(R.layout.mal_material_about_fragment, container, false);
    recyclerView = (RecyclerView) rootView.findViewById(R.id.mal_recyclerview);
    adapter = new MaterialAboutListAdapter(getViewTypeManager());
    recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
    recyclerView.setAdapter(adapter);
    RecyclerView.ItemAnimator animator = recyclerView.getItemAnimator();
    if (animator instanceof SimpleItemAnimator) {
        ((SimpleItemAnimator) animator).setSupportsChangeAnimations(false);
    }
    recyclerView.setAlpha(0f);
    recyclerView.setTranslationY(20);
    ListTask task = new ListTask(getActivity());
    task.execute();
    return rootView;
}
Also used : Context(android.content.Context) MaterialAboutListAdapter(com.danielstone.materialaboutlibrary.adapters.MaterialAboutListAdapter) SimpleItemAnimator(android.support.v7.widget.SimpleItemAnimator) LayoutInflater(android.view.LayoutInflater) RecyclerView(android.support.v7.widget.RecyclerView) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View) Nullable(android.support.annotation.Nullable)

Example 27 with ContextThemeWrapper

use of android.support.v7.view.ContextThemeWrapper in project Osmand by osmandapp.

the class EditFavoriteGroupDialogFragment method createMenuItems.

@Override
public void createMenuItems(Bundle savedInstanceState) {
    final OsmandApplication app = getMyApplication();
    FavouritesDbHelper helper = app.getFavorites();
    Bundle args = getArguments();
    if (args != null) {
        String groupName = args.getString(GROUP_NAME_KEY);
        if (groupName != null) {
            group = helper.getGroup(groupName);
        }
    }
    if (group == null) {
        return;
    }
    items.add(new TitleItem(Algorithms.isEmpty(group.name) ? app.getString(R.string.shared_string_favorites) : group.name));
    BaseBottomSheetItem editNameItem = new SimpleBottomSheetItem.Builder().setIcon(getContentIcon(R.drawable.ic_action_edit_dark)).setTitle(getString(R.string.edit_name)).setLayoutId(R.layout.bottom_sheet_item_simple).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            AlertDialog.Builder b = new AlertDialog.Builder(getContext());
            b.setTitle(R.string.favorite_group_name);
            final EditText nameEditText = new EditText(getContext());
            nameEditText.setText(group.name);
            b.setView(nameEditText);
            b.setNegativeButton(R.string.shared_string_cancel, null);
            b.setPositiveButton(R.string.shared_string_save, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    String name = nameEditText.getText().toString();
                    boolean nameChanged = !Algorithms.objectEquals(group.name, name);
                    if (nameChanged) {
                        app.getFavorites().editFavouriteGroup(group, name, group.color, group.visible);
                        updateParentFragment();
                    }
                    dismiss();
                }
            });
            b.show();
        }
    }).create();
    items.add(editNameItem);
    final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme;
    final View changeColorView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.change_fav_color, null);
    ((ImageView) changeColorView.findViewById(R.id.change_color_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_appearance));
    updateColorView((ImageView) changeColorView.findViewById(R.id.colorImage));
    BaseBottomSheetItem changeColorItem = new BaseBottomSheetItem.Builder().setCustomView(changeColorView).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            final ListPopupWindow popup = new ListPopupWindow(getActivity());
            popup.setAnchorView(changeColorView);
            popup.setContentWidth(AndroidUtils.dpToPx(app, 200f));
            popup.setModal(true);
            popup.setDropDownGravity(Gravity.END | Gravity.TOP);
            if (AndroidUiHelper.isOrientationPortrait(getActivity())) {
                popup.setVerticalOffset(AndroidUtils.dpToPx(app, 48f));
            } else {
                popup.setVerticalOffset(AndroidUtils.dpToPx(app, -48f));
            }
            popup.setHorizontalOffset(AndroidUtils.dpToPx(app, -6f));
            final FavoriteColorAdapter colorAdapter = new FavoriteColorAdapter(getActivity());
            popup.setAdapter(colorAdapter);
            popup.setOnItemClickListener(new AdapterView.OnItemClickListener() {

                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                    Integer color = colorAdapter.getItem(position);
                    if (color != null) {
                        if (color != group.color) {
                            app.getFavorites().editFavouriteGroup(group, group.name, color, group.visible);
                            updateParentFragment();
                        }
                    }
                    popup.dismiss();
                    dismiss();
                }
            });
            popup.show();
        }
    }).create();
    items.add(changeColorItem);
    BaseBottomSheetItem showOnMapItem = new BottomSheetItemWithCompoundButton.Builder().setChecked(group.visible).setIcon(getContentIcon(R.drawable.ic_map)).setTitle(getString(R.string.shared_string_show_on_map)).setLayoutId(R.layout.bottom_sheet_item_with_switch).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            boolean visible = !group.visible;
            app.getFavorites().editFavouriteGroup(group, group.name, group.color, visible);
            updateParentFragment();
            dismiss();
        }
    }).create();
    items.add(showOnMapItem);
    if (group.points.size() > 0) {
        items.add(new DividerHalfItem(getContext()));
        final MapMarkersHelper markersHelper = app.getMapMarkersHelper();
        final MapMarkersGroup markersGr = markersHelper.getOrCreateGroup(this.group);
        final boolean synced = markersHelper.isGroupSynced(markersGr.getId());
        BaseBottomSheetItem markersGroupItem = new SimpleBottomSheetItem.Builder().setIcon(getContentIcon(synced ? R.drawable.ic_action_delete_dark : R.drawable.ic_action_flag_dark)).setTitle(getString(synced ? R.string.remove_from_map_markers : R.string.shared_string_add_to_map_markers)).setLayoutId(R.layout.bottom_sheet_item_simple).setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                if (synced) {
                    markersHelper.removeMarkersGroup(markersGr);
                } else {
                    markersHelper.addOrEnableGroup(markersGr);
                }
                dismiss();
                MapActivity.launchMapActivityMoveToTop(getActivity());
            }
        }).create();
        items.add(markersGroupItem);
        BaseBottomSheetItem shareItem = new SimpleBottomSheetItem.Builder().setIcon(getContentIcon(R.drawable.ic_action_gshare_dark)).setTitle(getString(R.string.shared_string_share)).setLayoutId(R.layout.bottom_sheet_item_simple).setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                FavoritesTreeFragment fragment = getFavoritesTreeFragment();
                if (fragment != null) {
                    fragment.shareFavorites(EditFavoriteGroupDialogFragment.this.group);
                }
                dismiss();
            }
        }).create();
        items.add(shareItem);
    }
}
Also used : BaseBottomSheetItem(net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem) AlertDialog(android.support.v7.app.AlertDialog) SimpleBottomSheetItem(net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem) OsmandApplication(net.osmand.plus.OsmandApplication) DialogInterface(android.content.DialogInterface) TitleItem(net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem) ListPopupWindow(android.support.v7.widget.ListPopupWindow) DividerHalfItem(net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerHalfItem) MapMarkersGroup(net.osmand.plus.MapMarkersHelper.MapMarkersGroup) ImageView(android.widget.ImageView) EditText(android.widget.EditText) Bundle(android.os.Bundle) FavouritesDbHelper(net.osmand.plus.FavouritesDbHelper) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ContextThemeWrapper(android.view.ContextThemeWrapper) MapMarkersHelper(net.osmand.plus.MapMarkersHelper) AdapterView(android.widget.AdapterView)

Example 28 with ContextThemeWrapper

use of android.support.v7.view.ContextThemeWrapper in project Osmand by osmandapp.

the class AmenityMenuBuilder method buildRow.

protected void buildRow(final View view, Drawable icon, final String text, final String textPrefix, boolean collapsable, final CollapsableView collapsableView, int textColor, boolean isWiki, boolean isText, boolean needLinks, boolean isPhoneNumber, boolean isUrl, boolean matchWidthDivider, int textLinesLimit) {
    if (!isFirstRow()) {
        buildRowDivider(view);
    }
    final String txt = text;
    LinearLayout baseView = new LinearLayout(view.getContext());
    baseView.setOrientation(LinearLayout.VERTICAL);
    LinearLayout.LayoutParams llBaseViewParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    baseView.setLayoutParams(llBaseViewParams);
    LinearLayout ll = new LinearLayout(view.getContext());
    ll.setOrientation(LinearLayout.HORIZONTAL);
    LinearLayout.LayoutParams llParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    ll.setLayoutParams(llParams);
    ll.setBackgroundResource(AndroidUtils.resolveAttribute(view.getContext(), android.R.attr.selectableItemBackground));
    ll.setOnLongClickListener(new View.OnLongClickListener() {

        @Override
        public boolean onLongClick(View v) {
            String textToCopy = !Algorithms.isEmpty(textPrefix) ? textPrefix + ": " + txt : txt;
            copyToClipboard(textToCopy, view.getContext());
            return true;
        }
    });
    baseView.addView(ll);
    // Icon
    if (icon != null) {
        LinearLayout llIcon = new LinearLayout(view.getContext());
        llIcon.setOrientation(LinearLayout.HORIZONTAL);
        llIcon.setLayoutParams(new LinearLayout.LayoutParams(dpToPx(64f), dpToPx(48f)));
        llIcon.setGravity(Gravity.CENTER_VERTICAL);
        ll.addView(llIcon);
        ImageView iconView = new ImageView(view.getContext());
        LinearLayout.LayoutParams llIconParams = new LinearLayout.LayoutParams(dpToPx(24f), dpToPx(24f));
        llIconParams.setMargins(dpToPx(16f), dpToPx(12f), dpToPx(24f), dpToPx(12f));
        llIconParams.gravity = Gravity.CENTER_VERTICAL;
        iconView.setLayoutParams(llIconParams);
        iconView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
        iconView.setImageDrawable(icon);
        llIcon.addView(iconView);
    }
    // Text
    LinearLayout llText = new LinearLayout(view.getContext());
    llText.setOrientation(LinearLayout.VERTICAL);
    ll.addView(llText);
    TextView textPrefixView = null;
    if (!Algorithms.isEmpty(textPrefix)) {
        textPrefixView = new TextView(view.getContext());
        LinearLayout.LayoutParams llTextParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        llTextParams.setMargins(icon == null ? dpToPx(16f) : 0, dpToPx(8f), 0, 0);
        textPrefixView.setLayoutParams(llTextParams);
        textPrefixView.setTextSize(12);
        textPrefixView.setTextColor(app.getResources().getColor(R.color.ctx_menu_buttons_text_color));
        textPrefixView.setEllipsize(TextUtils.TruncateAt.END);
        textPrefixView.setMinLines(1);
        textPrefixView.setMaxLines(1);
        textPrefixView.setText(textPrefix);
    }
    TextView textView = new TextView(view.getContext());
    LinearLayout.LayoutParams llTextParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    llTextParams.setMargins(icon == null ? dpToPx(16f) : 0, textPrefixView == null ? (collapsable ? dpToPx(13f) : dpToPx(8f)) : dpToPx(2f), 0, collapsable && textPrefixView == null ? dpToPx(13f) : dpToPx(8f));
    textView.setLayoutParams(llTextParams);
    textView.setTextSize(16);
    textView.setTextColor(app.getResources().getColor(light ? R.color.ctx_menu_bottom_view_text_color_light : R.color.ctx_menu_bottom_view_text_color_dark));
    int linkTextColor = ContextCompat.getColor(view.getContext(), light ? R.color.ctx_menu_bottom_view_url_color_light : R.color.ctx_menu_bottom_view_url_color_dark);
    if (isPhoneNumber || isUrl) {
        textView.setTextColor(linkTextColor);
        needLinks = false;
    }
    textView.setText(txt);
    if (needLinks) {
        Linkify.addLinks(textView, Linkify.ALL);
        textView.setLinksClickable(true);
        textView.setLinkTextColor(linkTextColor);
        AndroidUtils.removeLinkUnderline(textView);
    }
    textView.setEllipsize(TextUtils.TruncateAt.END);
    if (textLinesLimit > 0) {
        textView.setMinLines(1);
        textView.setMaxLines(textLinesLimit);
    } else if (isWiki) {
        textView.setMinLines(1);
        textView.setMaxLines(15);
    } else if (isText) {
        textView.setMinLines(1);
        textView.setMaxLines(10);
    }
    if (textColor > 0) {
        textView.setTextColor(view.getResources().getColor(textColor));
    }
    LinearLayout.LayoutParams llTextViewParams = new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.WRAP_CONTENT);
    llTextViewParams.weight = 1f;
    llTextViewParams.setMargins(0, 0, dpToPx(10f), 0);
    llTextViewParams.gravity = Gravity.CENTER_VERTICAL;
    llText.setLayoutParams(llTextViewParams);
    if (textPrefixView != null) {
        llText.addView(textPrefixView);
    }
    llText.addView(textView);
    final ImageView iconViewCollapse = new ImageView(view.getContext());
    if (collapsable && collapsableView != null) {
        // Icon
        LinearLayout llIconCollapse = new LinearLayout(view.getContext());
        llIconCollapse.setLayoutParams(new LinearLayout.LayoutParams(dpToPx(40f), ViewGroup.LayoutParams.MATCH_PARENT));
        llIconCollapse.setOrientation(LinearLayout.HORIZONTAL);
        llIconCollapse.setGravity(Gravity.CENTER_VERTICAL);
        ll.addView(llIconCollapse);
        LinearLayout.LayoutParams llIconCollapseParams = new LinearLayout.LayoutParams(dpToPx(24f), dpToPx(24f));
        llIconCollapseParams.setMargins(0, dpToPx(12f), dpToPx(24f), dpToPx(12f));
        llIconCollapseParams.gravity = Gravity.CENTER_VERTICAL;
        iconViewCollapse.setLayoutParams(llIconCollapseParams);
        iconViewCollapse.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
        iconViewCollapse.setImageDrawable(getCollapseIcon(collapsableView.getContenView().getVisibility() == View.GONE));
        llIconCollapse.addView(iconViewCollapse);
        ll.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                if (collapsableView.getContenView().getVisibility() == View.VISIBLE) {
                    collapsableView.getContenView().setVisibility(View.GONE);
                    iconViewCollapse.setImageDrawable(getCollapseIcon(true));
                    collapsableView.setCollapsed(true);
                } else {
                    collapsableView.getContenView().setVisibility(View.VISIBLE);
                    iconViewCollapse.setImageDrawable(getCollapseIcon(false));
                    collapsableView.setCollapsed(false);
                }
            }
        });
        if (collapsableView.isCollapsed()) {
            collapsableView.getContenView().setVisibility(View.GONE);
            iconViewCollapse.setImageDrawable(getCollapseIcon(true));
        }
        baseView.addView(collapsableView.getContenView());
    }
    if (isWiki) {
        TextViewEx button = new TextViewEx(new ContextThemeWrapper(view.getContext(), light ? R.style.OsmandLightTheme : R.style.OsmandDarkTheme));
        LinearLayout.LayoutParams llWikiButtonParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, dpToPx(36f));
        llWikiButtonParams.setMargins(dpToPx(16f), 0, 0, dpToPx(16f));
        button.setLayoutParams(llWikiButtonParams);
        button.setTypeface(FontCache.getRobotoMedium(app));
        button.setBackgroundResource(light ? R.drawable.context_menu_controller_bg_light : R.drawable.context_menu_controller_bg_dark);
        button.setTextSize(14);
        int paddingSides = dpToPx(10f);
        button.setPadding(paddingSides, 0, paddingSides, 0);
        ColorStateList buttonColorStateList = AndroidUtils.createColorStateList(view.getContext(), !light, R.color.ctx_menu_controller_button_text_color_light_n, R.color.ctx_menu_controller_button_text_color_light_p, R.color.ctx_menu_controller_button_text_color_dark_n, R.color.ctx_menu_controller_button_text_color_dark_p);
        button.setTextColor(buttonColorStateList);
        button.setGravity(Gravity.LEFT | Gravity.CENTER_VERTICAL);
        button.setSingleLine(true);
        button.setEllipsize(TextUtils.TruncateAt.END);
        button.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                WikipediaDialogFragment.showInstance(mapActivity, amenity);
            }
        });
        button.setAllCaps(true);
        button.setText(R.string.context_menu_read_full_article);
        Drawable normal = app.getIconsCache().getIcon(R.drawable.ic_action_read_text, light ? R.color.ctx_menu_controller_button_text_color_light_n : R.color.ctx_menu_controller_button_text_color_dark_n);
        Drawable pressed = app.getIconsCache().getIcon(R.drawable.ic_action_read_text, light ? R.color.ctx_menu_controller_button_text_color_light_p : R.color.ctx_menu_controller_button_text_color_dark_p);
        button.setCompoundDrawablesWithIntrinsicBounds(Build.VERSION.SDK_INT >= 21 ? AndroidUtils.createStateListDrawable(normal, pressed) : normal, null, null, null);
        button.setCompoundDrawablePadding(dpToPx(8f));
        llText.addView(button);
    }
    ((LinearLayout) view).addView(baseView);
    if (isPhoneNumber) {
        ll.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(final View v) {
                final String[] phones = text.split(",|;");
                if (phones.length > 1) {
                    AlertDialog.Builder dlg = new AlertDialog.Builder(v.getContext());
                    dlg.setNegativeButton(R.string.shared_string_cancel, null);
                    dlg.setItems(phones, new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            Intent intent = new Intent(Intent.ACTION_DIAL);
                            intent.setData(Uri.parse("tel:" + phones[which]));
                            v.getContext().startActivity(intent);
                        }
                    });
                    dlg.show();
                } else {
                    Intent intent = new Intent(Intent.ACTION_DIAL);
                    intent.setData(Uri.parse("tel:" + text));
                    v.getContext().startActivity(intent);
                }
            }
        });
    } else if (isUrl) {
        ll.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                if (text.contains(".wikipedia.org/w")) {
                    WikipediaDialogFragment.showFullArticle(v.getContext(), Uri.parse(text), !light);
                } else {
                    Intent intent = new Intent(Intent.ACTION_VIEW);
                    intent.setData(Uri.parse(text));
                    v.getContext().startActivity(intent);
                }
            }
        });
    } else if (isWiki) {
        ll.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                WikipediaDialogFragment.showInstance(mapActivity, amenity);
            }
        });
    } else if (isText && text.length() > 200) {
        ll.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                POIMapLayer.showDescriptionDialog(view.getContext(), app, text, textPrefix);
            }
        });
    }
    rowBuilt();
    setDividerWidth(matchWidthDivider);
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) DialogInterface(android.content.DialogInterface) MenuBuilder(net.osmand.plus.mapcontextmenu.MenuBuilder) Drawable(android.graphics.drawable.Drawable) ColorStateList(android.content.res.ColorStateList) Intent(android.content.Intent) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) ContextThemeWrapper(android.support.v7.view.ContextThemeWrapper) TextViewEx(net.osmand.plus.widgets.TextViewEx) TextView(android.widget.TextView) ImageView(android.widget.ImageView) LinearLayout(android.widget.LinearLayout)

Example 29 with ContextThemeWrapper

use of android.support.v7.view.ContextThemeWrapper in project Osmand by osmandapp.

the class AddGroupBottomSheetDialogFragment method createMenuItems.

@Override
public void createMenuItems(Bundle savedInstanceState) {
    final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme;
    mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.fragment_marker_add_group_bottom_sheet_dialog, null);
    final RecyclerView recyclerView = mainView.findViewById(R.id.groups_recycler_view);
    recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
    adapter = createAdapter();
    adapter.setAdapterListener(new GroupsAdapter.GroupsAdapterListener() {

        @Override
        public void onItemClick(View view) {
            int position = recyclerView.getChildAdapterPosition(view);
            if (position != RecyclerView.NO_POSITION) {
                AddGroupBottomSheetDialogFragment.this.onItemClick(position);
            }
        }
    });
    recyclerView.setAdapter(adapter);
    items.add(new BaseBottomSheetItem.Builder().setCustomView(mainView).create());
}
Also used : BaseBottomSheetItem(net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem) GroupsAdapter(net.osmand.plus.mapmarkers.adapters.GroupsAdapter) ContextThemeWrapper(android.view.ContextThemeWrapper) RecyclerView(android.support.v7.widget.RecyclerView) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View)

Example 30 with ContextThemeWrapper

use of android.support.v7.view.ContextThemeWrapper in project Osmand by osmandapp.

the class MapillaryFiltersFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final MapActivity mapActivity = (MapActivity) getActivity();
    final OsmandSettings settings = getSettings();
    final MapillaryPlugin plugin = OsmandPlugin.getPlugin(MapillaryPlugin.class);
    final boolean nightMode = getMyApplication().getDaynightHelper().isNightModeForMapControls();
    final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme;
    final int backgroundColor = ContextCompat.getColor(getActivity(), nightMode ? R.color.ctx_menu_info_view_bg_dark : R.color.ctx_menu_info_view_bg_light);
    final DateFormat dateFormat = SimpleDateFormat.getDateInstance(DateFormat.MEDIUM);
    final View view = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.fragment_mapillary_filters, null);
    view.findViewById(R.id.mapillary_filters_linear_layout).setBackgroundColor(backgroundColor);
    final View toggleRow = view.findViewById(R.id.toggle_row);
    final boolean selected = settings.SHOW_MAPILLARY.get();
    final int toggleActionStringId = selected ? R.string.shared_string_enabled : R.string.shared_string_disabled;
    int toggleIconColorId;
    int toggleIconId;
    if (selected) {
        toggleIconId = R.drawable.ic_action_view;
        toggleIconColorId = nightMode ? R.color.color_dialog_buttons_dark : R.color.color_dialog_buttons_light;
    } else {
        toggleIconId = R.drawable.ic_action_hide;
        toggleIconColorId = nightMode ? 0 : R.color.icon_color;
    }
    ((AppCompatTextView) toggleRow.findViewById(R.id.toggle_row_title)).setText(toggleActionStringId);
    final Drawable drawable = getIcon(toggleIconId, toggleIconColorId);
    ((AppCompatImageView) toggleRow.findViewById(R.id.toggle_row_icon)).setImageDrawable(drawable);
    final CompoundButton toggle = (CompoundButton) toggleRow.findViewById(R.id.toggle_row_toggle);
    toggle.setOnCheckedChangeListener(null);
    toggle.setChecked(selected);
    toggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
            settings.SHOW_MAPILLARY.set(!settings.SHOW_MAPILLARY.get());
            plugin.updateLayers(mapActivity.getMapView(), mapActivity);
            mapActivity.getDashboard().refreshContent(true);
        }
    });
    toggleRow.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            toggle.setChecked(!toggle.isChecked());
        }
    });
    final Button reloadTile = (Button) view.findViewById(R.id.button_reload_tile);
    reloadTile.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            ResourceManager manager = getMyApplication().getResourceManager();
            manager.clearCacheAndTiles(TileSourceManager.getMapillaryVectorSource());
            manager.clearCacheAndTiles(TileSourceManager.getMapillaryRasterSource());
            mapActivity.refreshMap();
        }
    });
    final int colorRes = nightMode ? R.color.color_white : R.color.icon_color;
    ((AppCompatImageView) view.findViewById(R.id.mapillary_filters_user_icon)).setImageDrawable(getIcon(R.drawable.ic_action_user, colorRes));
    ((AppCompatImageView) view.findViewById(R.id.mapillary_filters_date_icon)).setImageDrawable(getIcon(R.drawable.ic_action_data, colorRes));
    ((AppCompatImageView) view.findViewById(R.id.mapillary_filters_tile_cache_icon)).setImageDrawable(getIcon(R.drawable.ic_layer_top_dark, colorRes));
    final DelayAutoCompleteTextView textView = (DelayAutoCompleteTextView) view.findViewById(R.id.auto_complete_text_view);
    textView.setAdapter(new MapillaryAutoCompleteAdapter(getContext(), R.layout.auto_complete_suggestion, getMyApplication()));
    String selectedUsername = settings.MAPILLARY_FILTER_USERNAME.get();
    if (!selectedUsername.equals("") && settings.USE_MAPILLARY_FILTER.get()) {
        textView.setText(selectedUsername);
        textView.setSelection(selectedUsername.length());
    }
    textView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            hideKeyboard();
            mapActivity.getDashboard().refreshContent(true);
        }
    });
    textView.setOnEditorActionListener(new TextView.OnEditorActionListener() {

        @Override
        public boolean onEditorAction(TextView textView, int id, KeyEvent keyEvent) {
            if (id == EditorInfo.IME_ACTION_DONE) {
                hideKeyboard();
                mapActivity.getDashboard().refreshContent(true);
                return true;
            }
            return false;
        }
    });
    textView.addTextChangedListener(new TextWatcher() {

        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            view.findViewById(R.id.warning_linear_layout).setVisibility(View.GONE);
            if (!settings.MAPILLARY_FILTER_USERNAME.get().equals("") || settings.MAPILLARY_FILTER_TO_DATE.get() != 0 || settings.MAPILLARY_FILTER_FROM_DATE.get() != 0) {
                changeButtonState((Button) view.findViewById(R.id.button_apply), 1, true);
            } else {
                changeButtonState((Button) view.findViewById(R.id.button_apply), .5f, false);
            }
        }

        @Override
        public void afterTextChanged(Editable editable) {
        }
    });
    ImageView imageView = (ImageView) view.findViewById(R.id.warning_image_view);
    imageView.setImageDrawable(getPaintedContentIcon(R.drawable.ic_small_warning, getResources().getColor(R.color.color_warning)));
    final EditText dateFromEt = (EditText) view.findViewById(R.id.date_from_edit_text);
    final DatePickerDialog.OnDateSetListener dateFromDialog = new DatePickerDialog.OnDateSetListener() {

        @Override
        public void onDateSet(DatePicker v, int year, int monthOfYear, int dayOfMonth) {
            Calendar from = Calendar.getInstance();
            from.set(Calendar.YEAR, year);
            from.set(Calendar.MONTH, monthOfYear);
            from.set(Calendar.DAY_OF_MONTH, dayOfMonth);
            dateFromEt.setText(dateFormat.format(from.getTime()));
            settings.MAPILLARY_FILTER_FROM_DATE.set(from.getTimeInMillis());
            changeButtonState((Button) view.findViewById(R.id.button_apply), 1, true);
            mapActivity.getDashboard().refreshContent(true);
        }
    };
    dateFromEt.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            Calendar now = Calendar.getInstance();
            new DatePickerDialog(mapActivity, dateFromDialog, now.get(Calendar.YEAR), now.get(Calendar.MONTH), now.get(Calendar.DAY_OF_MONTH)).show();
        }
    });
    dateFromEt.setCompoundDrawablesWithIntrinsicBounds(null, null, getContentIcon(R.drawable.ic_action_arrow_drop_down), null);
    final EditText dateToEt = (EditText) view.findViewById(R.id.date_to_edit_text);
    final DatePickerDialog.OnDateSetListener dateToDialog = new DatePickerDialog.OnDateSetListener() {

        @Override
        public void onDateSet(DatePicker v, int year, int monthOfYear, int dayOfMonth) {
            Calendar to = Calendar.getInstance();
            to.set(Calendar.YEAR, year);
            to.set(Calendar.MONTH, monthOfYear);
            to.set(Calendar.DAY_OF_MONTH, dayOfMonth);
            dateToEt.setText(dateFormat.format(to.getTime()));
            settings.MAPILLARY_FILTER_TO_DATE.set(to.getTimeInMillis());
            changeButtonState((Button) view.findViewById(R.id.button_apply), 1, true);
            mapActivity.getDashboard().refreshContent(true);
        }
    };
    dateToEt.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            Calendar now = Calendar.getInstance();
            new DatePickerDialog(mapActivity, dateToDialog, now.get(Calendar.YEAR), now.get(Calendar.MONTH), now.get(Calendar.DAY_OF_MONTH)).show();
        }
    });
    dateToEt.setCompoundDrawablesWithIntrinsicBounds(null, null, getContentIcon(R.drawable.ic_action_arrow_drop_down), null);
    if (settings.USE_MAPILLARY_FILTER.get()) {
        long to = settings.MAPILLARY_FILTER_TO_DATE.get();
        if (to != 0) {
            dateToEt.setText(dateFormat.format(new Date(to)));
        }
        long from = settings.MAPILLARY_FILTER_FROM_DATE.get();
        if (from != 0) {
            dateFromEt.setText(dateFormat.format(new Date(from)));
        }
    }
    final Button apply = (Button) view.findViewById(R.id.button_apply);
    changeButtonState(apply, .5f, false);
    apply.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            String username = textView.getText().toString();
            String dateFrom = dateFromEt.getText().toString();
            String dateTo = dateToEt.getText().toString();
            if (!settings.MAPILLARY_FILTER_USERNAME.get().equals("") || !dateFrom.equals("") || !dateTo.equals("")) {
                settings.USE_MAPILLARY_FILTER.set(true);
            }
            if (dateFrom.equals("")) {
                settings.MAPILLARY_FILTER_FROM_DATE.set(0L);
            }
            if (dateTo.equals("")) {
                settings.MAPILLARY_FILTER_TO_DATE.set(0L);
            }
            if (!username.equals("") && settings.MAPILLARY_FILTER_USERNAME.get().equals("")) {
                view.findViewById(R.id.warning_linear_layout).setVisibility(View.VISIBLE);
            } else {
                mapActivity.getDashboard().hideDashboard();
            }
            changeButtonState(apply, .5f, false);
            plugin.updateLayers(mapActivity.getMapView(), mapActivity);
            hideKeyboard();
        }
    });
    final Button clear = (Button) view.findViewById(R.id.button_clear);
    clear.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            textView.setText("");
            dateFromEt.setText("");
            dateToEt.setText("");
            settings.USE_MAPILLARY_FILTER.set(false);
            settings.MAPILLARY_FILTER_USER_KEY.set("");
            settings.MAPILLARY_FILTER_USERNAME.set("");
            settings.MAPILLARY_FILTER_FROM_DATE.set(0L);
            settings.MAPILLARY_FILTER_TO_DATE.set(0L);
            plugin.updateLayers(mapActivity.getMapView(), mapActivity);
            hideKeyboard();
        }
    });
    return view;
}
Also used : DelayAutoCompleteTextView(net.osmand.plus.views.controls.DelayAutoCompleteTextView) KeyEvent(android.view.KeyEvent) Button(android.widget.Button) CompoundButton(android.widget.CompoundButton) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) AppCompatTextView(android.support.v7.widget.AppCompatTextView) TextView(android.widget.TextView) DelayAutoCompleteTextView(net.osmand.plus.views.controls.DelayAutoCompleteTextView) ImageView(android.widget.ImageView) AppCompatImageView(android.support.v7.widget.AppCompatImageView) MapActivity(net.osmand.plus.activities.MapActivity) EditText(android.widget.EditText) DatePickerDialog(android.app.DatePickerDialog) Calendar(java.util.Calendar) AppCompatTextView(android.support.v7.widget.AppCompatTextView) Drawable(android.graphics.drawable.Drawable) ResourceManager(net.osmand.plus.resources.ResourceManager) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) AppCompatImageView(android.support.v7.widget.AppCompatImageView) AppCompatTextView(android.support.v7.widget.AppCompatTextView) TextView(android.widget.TextView) DelayAutoCompleteTextView(net.osmand.plus.views.controls.DelayAutoCompleteTextView) AppCompatImageView(android.support.v7.widget.AppCompatImageView) OsmandSettings(net.osmand.plus.OsmandSettings) Date(java.util.Date) ContextThemeWrapper(android.view.ContextThemeWrapper) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) AdapterView(android.widget.AdapterView) DatePicker(android.widget.DatePicker) CompoundButton(android.widget.CompoundButton)

Aggregations

View (android.view.View)40 ContextThemeWrapper (android.support.v7.view.ContextThemeWrapper)38 ContextThemeWrapper (android.view.ContextThemeWrapper)31 Context (android.content.Context)25 DialogInterface (android.content.DialogInterface)24 TextView (android.widget.TextView)22 RecyclerView (android.support.v7.widget.RecyclerView)21 ImageView (android.widget.ImageView)21 AlertDialog (android.support.v7.app.AlertDialog)20 LayoutInflater (android.view.LayoutInflater)18 Intent (android.content.Intent)13 Nullable (android.support.annotation.Nullable)10 ColorPreferences (me.ccrama.redditslide.ColorPreferences)10 Drawable (android.graphics.drawable.Drawable)9 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)9 EditText (android.widget.EditText)8 Bundle (android.os.Bundle)7 ArrayList (java.util.ArrayList)7 SuppressLint (android.annotation.SuppressLint)6 Dialog (android.app.Dialog)6