Search in sources :

Example 31 with PopupMenu

use of androidx.appcompat.widget.PopupMenu in project Rocket by mozilla-tw.

the class HistoryItemAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
    if (holder instanceof SiteItemViewHolder) {
        final Site item = (Site) mItems.get(position);
        if (item != null) {
            final SiteItemViewHolder siteVH = (SiteItemViewHolder) holder;
            siteVH.rootView.setOnClickListener(this);
            siteVH.textMain.setText(item.getTitle());
            siteVH.textSecondary.setText(item.getUrl());
            String favIconUri = item.getFavIconUri();
            if (favIconUri != null) {
                Glide.with(siteVH.imgFav.getContext()).asBitmap().load(favIconUri).into(new SimpleTarget<Bitmap>() {

                    @Override
                    public void onResourceReady(Bitmap resource, Transition<? super Bitmap> transition) {
                        if (DimenUtils.iconTooBlurry(siteVH.imgFav.getResources(), resource.getWidth())) {
                            setImageViewWithDefaultBitmap(siteVH.imgFav, item.getUrl());
                        } else {
                            siteVH.imgFav.setImageBitmap(resource);
                        }
                    }
                });
            } else {
                setImageViewWithDefaultBitmap(siteVH.imgFav, item.getUrl());
            }
            final PopupMenu popupMenu = new PopupMenu(mContext, siteVH.btnMore);
            popupMenu.setOnMenuItemClickListener(menuItem -> {
                if (menuItem.getItemId() == R.id.browsing_history_menu_delete) {
                    BrowsingHistoryManager.getInstance().delete(item.getId(), HistoryItemAdapter.this);
                    TelemetryWrapper.historyRemoveLink();
                    // Delete favicon
                    String uriString = item.getFavIconUri();
                    if (uriString == null) {
                        return false;
                    }
                    final URI fileUri;
                    try {
                        fileUri = new URI(uriString);
                    } catch (URISyntaxException e) {
                        e.printStackTrace();
                        return false;
                    }
                    final Runnable runnable = new FileUtils.DeleteFileRunnable(new File(fileUri));
                    ThreadUtils.postToBackgroundThread(runnable);
                }
                return false;
            });
            popupMenu.inflate(R.menu.menu_browsing_history_option);
            siteVH.btnMore.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    popupMenu.show();
                    TelemetryWrapper.showHistoryContextMenu();
                }
            });
        }
    } else if (holder instanceof DateItemViewHolder) {
        final DateSection item = (DateSection) mItems.get(position);
        if (item != null) {
            final DateItemViewHolder dateVH = (DateItemViewHolder) holder;
            dateVH.textDate.setText(DateUtils.getRelativeTimeSpanString(item.getTimestamp(), System.currentTimeMillis(), DateUtils.DAY_IN_MILLIS));
        }
    }
}
Also used : Site(org.mozilla.focus.history.model.Site) DateSection(org.mozilla.focus.history.model.DateSection) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) SiteItemViewHolder(org.mozilla.focus.site.SiteItemViewHolder) Bitmap(android.graphics.Bitmap) File(java.io.File) PopupMenu(androidx.appcompat.widget.PopupMenu)

Example 32 with PopupMenu

use of androidx.appcompat.widget.PopupMenu in project Rocket by mozilla-tw.

the class BookmarkAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(@NonNull SiteItemViewHolder holder, int position) {
    final BookmarkModel item = getItem(position);
    if (item == null) {
        return;
    }
    holder.rootView.setTag(item.getId());
    holder.textMain.setText(item.getTitle());
    holder.textSecondary.setText(item.getUrl());
    holder.rootView.setOnClickListener(v -> {
        listener.onItemClicked(item.getUrl());
    });
    final PopupMenu popupMenu = new PopupMenu(holder.btnMore.getContext(), holder.btnMore);
    popupMenu.setOnMenuItemClickListener(menuItem -> {
        if (menuItem.getItemId() == R.id.remove) {
            listener.onItemDeleted(item);
        }
        if (menuItem.getItemId() == R.id.edit) {
            listener.onItemEdited(item);
        }
        return false;
    });
    popupMenu.inflate(R.menu.menu_bookmarks);
    holder.btnMore.setOnClickListener(v -> {
        popupMenu.show();
        TelemetryWrapper.showBookmarkContextMenu();
    });
}
Also used : BookmarkModel(org.mozilla.focus.persistence.BookmarkModel) PopupMenu(androidx.appcompat.widget.PopupMenu)

Example 33 with PopupMenu

use of androidx.appcompat.widget.PopupMenu in project AnyMemo by helloworld1.

the class CardListActivity method showListItemLongClickPopup.

private void showListItemLongClickPopup(final View childView, final Card card) {
    View view = childView.findViewById(R.id.item_question);
    PopupMenu popup = new PopupMenu(this, view);
    MenuInflater inflater = popup.getMenuInflater();
    inflater.inflate(R.menu.card_list_long_click_popup_menu, popup.getMenu());
    popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(MenuItem menuItem) {
            switch(menuItem.getItemId()) {
                case R.id.edit:
                    gotoCardEditorActivity(card);
                    break;
                case R.id.detail:
                    gotoDetailActivity(card);
                    break;
                case R.id.preview_edit:
                    gotoPreviewEditActivity(card);
                    break;
            }
            return true;
        }
    });
    popup.show();
}
Also used : MenuInflater(android.view.MenuInflater) MenuItem(android.view.MenuItem) View(android.view.View) AdapterView(android.widget.AdapterView) SearchView(androidx.appcompat.widget.SearchView) TextView(android.widget.TextView) ListView(android.widget.ListView) PopupMenu(androidx.appcompat.widget.PopupMenu)

Example 34 with PopupMenu

use of androidx.appcompat.widget.PopupMenu in project AnyMemo by helloworld1.

the class CardListActivity method showListItemPopup.

private void showListItemPopup(final View childView, final Card card) {
    View view = childView.findViewById(R.id.item_question);
    PopupMenu popup = new PopupMenu(this, view);
    MenuInflater inflater = popup.getMenuInflater();
    inflater.inflate(R.menu.card_list_popup_menu, popup.getMenu());
    popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(MenuItem menuItem) {
            switch(menuItem.getItemId()) {
                case R.id.mark_as_learned_menu:
                    markAsLearned(card);
                    break;
                case R.id.mark_as_forgotten_menu:
                    markAsForgotten(card);
                    break;
                case R.id.mark_as_new_menu:
                    markAsNew(card);
                    break;
                case R.id.mark_as_learned_forever_menu:
                    markAsLearnedForever(card);
                    break;
            }
            return true;
        }
    });
    popup.show();
}
Also used : MenuInflater(android.view.MenuInflater) MenuItem(android.view.MenuItem) View(android.view.View) AdapterView(android.widget.AdapterView) SearchView(androidx.appcompat.widget.SearchView) TextView(android.widget.TextView) ListView(android.widget.ListView) PopupMenu(androidx.appcompat.widget.PopupMenu)

Aggregations

PopupMenu (androidx.appcompat.widget.PopupMenu)34 MenuItem (android.view.MenuItem)20 TextView (android.widget.TextView)12 Spannable (android.text.Spannable)8 View (android.view.View)8 Menu (android.view.Menu)7 SwitchCompat (androidx.appcompat.widget.SwitchCompat)5 MenuInflater (android.view.MenuInflater)4 LinearLayout (android.widget.LinearLayout)4 RelativeLayout (android.widget.RelativeLayout)4 Intent (android.content.Intent)3 AdapterView (android.widget.AdapterView)3 ListView (android.widget.ListView)3 SuppressLint (android.annotation.SuppressLint)2 Activity (android.app.Activity)2 Resources (android.content.res.Resources)2 TypedArray (android.content.res.TypedArray)2 Drawable (android.graphics.drawable.Drawable)2 CompoundButton (android.widget.CompoundButton)2 SearchView (androidx.appcompat.widget.SearchView)2