Search in sources :

Example 1 with FavoritesActivity

use of net.osmand.plus.myplaces.FavoritesActivity in project Osmand by osmandapp.

the class FavoritesTreeFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.favorites_tree, container, false);
    ExpandableListView listView = (ExpandableListView) view.findViewById(android.R.id.list);
    favouritesAdapter.synchronizeGroups();
    if (!favouritesAdapter.isEmpty()) {
        boolean light = getMyApplication().getSettings().isLightContent();
        View searchView = inflater.inflate(R.layout.search_fav_list_item, null);
        searchView.setBackgroundResource(light ? R.color.bg_color_light : R.color.bg_color_dark);
        TextView title = (TextView) searchView.findViewById(R.id.title);
        title.setCompoundDrawablesWithIntrinsicBounds(getMyApplication().getIconsCache().getThemedIcon(R.drawable.ic_action_search_dark), null, null, null);
        title.setHint(R.string.shared_string_search);
        searchView.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                FavoritesSearchFragment.showInstance(getActivity(), "");
            }
        });
        listView.addHeaderView(searchView);
        listView.addHeaderView(inflater.inflate(R.layout.list_item_divider, null, false));
        footerView = inflater.inflate(R.layout.list_shadow_footer, null, false);
        listView.addFooterView(footerView);
    }
    View emptyView = view.findViewById(android.R.id.empty);
    ImageView emptyImageView = (ImageView) emptyView.findViewById(R.id.empty_state_image_view);
    if (Build.VERSION.SDK_INT >= 18) {
        emptyImageView.setImageResource(app.getSettings().isLightContent() ? R.drawable.ic_empty_state_favorites_day : R.drawable.ic_empty_state_favorites_night);
    } else {
        emptyImageView.setVisibility(View.INVISIBLE);
    }
    Button importButton = (Button) emptyView.findViewById(R.id.import_button);
    importButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            importFavourites();
        }
    });
    listView.setEmptyView(emptyView);
    listView.setAdapter(favouritesAdapter);
    setListView(listView);
    setHasOptionsMenu(true);
    listView.setOnGroupCollapseListener(new ExpandableListView.OnGroupCollapseListener() {

        @Override
        public void onGroupCollapse(int groupPosition) {
            String groupName = favouritesAdapter.getGroup(groupPosition).name;
            getGroupExpandedPreference(groupName).set(false);
        }
    });
    listView.setOnGroupExpandListener(new ExpandableListView.OnGroupExpandListener() {

        @Override
        public void onGroupExpand(int groupPosition) {
            String groupName = favouritesAdapter.getGroup(groupPosition).name;
            getGroupExpandedPreference(groupName).set(true);
        }
    });
    String groupNameToShow = ((FavoritesActivity) getActivity()).getGroupNameToShow();
    if (groupNameToShow != null) {
        int groupPos = favouritesAdapter.getGroupPosition(groupNameToShow);
        if (groupPos != -1) {
            listView.expandGroup(groupPos);
            int selection = listView.getHeaderViewsCount();
            for (int i = 0; i < groupPos; i++) {
                // because of group header
                selection++;
                if (getGroupExpandedPreference(favouritesAdapter.getGroup(i).name).get()) {
                    selection += favouritesAdapter.getChildrenCount(i);
                }
            }
            listView.setSelection(selection);
        }
    }
    return view;
}
Also used : ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) ExpandableListView(android.widget.ExpandableListView) FavouritePoint(net.osmand.data.FavouritePoint) Button(android.widget.Button) TextView(android.widget.TextView) ImageView(android.widget.ImageView) ExpandableListView(android.widget.ExpandableListView) FavoritesActivity(net.osmand.plus.myplaces.FavoritesActivity)

Example 2 with FavoritesActivity

use of net.osmand.plus.myplaces.FavoritesActivity in project Osmand by osmandapp.

the class FavoritesTreeFragment method onCreateOptionsMenu.

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    menu.clear();
    MenuItem mi = createMenuItem(menu, SEARCH_ID, R.string.search_poi_filter, R.drawable.ic_action_search_dark, R.drawable.ic_action_search_dark, MenuItemCompat.SHOW_AS_ACTION_ALWAYS | MenuItemCompat.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
    mi.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(MenuItem item) {
            FavoritesSearchFragment.showInstance(getActivity(), "");
            return true;
        }
    });
    if (AndroidUiHelper.isOrientationPortrait(getActivity())) {
        menu = ((FavoritesActivity) getActivity()).getClearToolbar(true).getMenu();
    } else {
        ((FavoritesActivity) getActivity()).getClearToolbar(false);
    }
    ((FavoritesActivity) getActivity()).updateListViewFooter(footerView);
    if (!MenuItemCompat.isActionViewExpanded(mi)) {
        createMenuItem(menu, IMPORT_FAVOURITES_ID, R.string.shared_string_add_to_favorites, R.drawable.ic_action_plus, R.drawable.ic_action_plus, MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
        createMenuItem(menu, SHARE_ID, R.string.shared_string_share, R.drawable.ic_action_gshare_dark, R.drawable.ic_action_gshare_dark, MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
        createMenuItem(menu, SELECT_MAP_MARKERS_ID, R.string.select_map_markers, R.drawable.ic_action_flag_dark, R.drawable.ic_action_flag_dark, MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
        createMenuItem(menu, DELETE_ID, R.string.shared_string_delete, R.drawable.ic_action_delete_dark, R.drawable.ic_action_delete_dark, MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
    // createMenuItem(menu, EXPORT_ID, R.string.shared_string_export, R.drawable.ic_action_gsave_light,
    // R.drawable.ic_action_gsave_dark, MenuItem.SHOW_AS_ACTION_IF_ROOM);
    }
}
Also used : MenuItem(android.view.MenuItem) FavoritesActivity(net.osmand.plus.myplaces.FavoritesActivity)

Aggregations

FavoritesActivity (net.osmand.plus.myplaces.FavoritesActivity)2 MenuItem (android.view.MenuItem)1 View (android.view.View)1 Button (android.widget.Button)1 ExpandableListView (android.widget.ExpandableListView)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 FavouritePoint (net.osmand.data.FavouritePoint)1