Android copy of QQ nickname Effect 2

Keywords: Android Java github xml

This paper is synchronized from http://javaexception.com/archives/77

Background:

stay Last article In, we give a scheme to copy QQ effect. Today we will talk about another way to realize it. Mainly relying on an open source project https://github.com/shangmingchao/PopupList.

terms of settlement:

PopupList.java code encapsulation is relatively perfect, using pure java code to achieve the view effect, do not need to use pictures, xml resource files, if introduced, only copy PopupList.java code into the project project.

All that's left is the call. Here we do not analyze the source code. The source code is relatively simple. We only talk about how to use it.

PopupList popupList = new PopupList(this);
List<String> popupMenuItemList = new ArrayList<>(Arrays.asList("copy QQ Number"));
popupList.bind(tvQQNum, popupMenuItemList, new PopupList.PopupListListener() {
    @Override
    public boolean showPopupList(View adapterView, View contextView, int contextPosition) {
        return true;
    }
 
    @Override
    public void onPopupListClick(View contextView, int contextPosition, int position) {
        ClipboardManager cm = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
        ClipData clipData = ClipData.newPlainText("Label", "10001");
        cm.setPrimaryClip(clipData);
    }
});
PopupList popupList = new PopupList(this);
List<String> popupMenuItemList = new ArrayList<>(Arrays.asList("copy"));
popupList.bind(tvUserName, popupMenuItemList, new PopupList.PopupListListener() {
    @Override
    public boolean showPopupList(View adapterView, View contextView, int contextPosition) {
        return true;
    }
 
    @Override
    public void onPopupListClick(View contextView, int contextPosition, int position) {
        ClipboardManager cm = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
        ClipData clipData = ClipData.newPlainText("Label", "every day");
        cm.setPrimaryClip(clipData);
    }
});

It's easy to use. PopupList supports both single and array structures, such as the effect of friends' likes.

reference material:

https://github.com/shangmingchao/PopupList

Posted by yogibear333 on Tue, 19 Nov 2019 07:42:49 -0800