Search in sources :

Example 1 with SwipeMenuCreator

use of com.baoyz.swipemenulistview.SwipeMenuCreator in project samourai-wallet-android by Samourai-Wallet.

the class BIP47Activity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.bip47_list);
    setTitle(R.string.paynyms);
    ActionBar actionBar = getActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);
    ibBIP47Menu = (FloatingActionsMenu) findViewById(R.id.bip47_menu);
    actionAdd = (FloatingActionButton) findViewById(R.id.bip47_add);
    actionAdd.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View arg0) {
            doAdd();
        }
    });
    actionSign = (FloatingActionButton) findViewById(R.id.bip47_sign);
    actionSign.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View arg0) {
            doSign();
        }
    });
    if (meta == null) {
        meta = new HashMap<String, String>();
    }
    if (bitmaps == null) {
        bitmaps = new HashMap<String, Bitmap>();
    }
    listView = (SwipeMenuListView) findViewById(R.id.list);
    handler = new Handler();
    refreshList();
    adapter = new BIP47EntryAdapter();
    listView.setAdapter(adapter);
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            final String itemValue = (String) listView.getItemAtPosition(position);
            String msg = "";
            if (BIP47Meta.getInstance().getLabel(itemValue) != null && BIP47Meta.getInstance().getLabel(itemValue).length() > 0) {
                msg = BIP47Meta.getInstance().getLabel(itemValue) + ":";
            }
            if (BIP47Meta.getInstance().getOutgoingStatus(itemValue) == BIP47Meta.STATUS_NOT_SENT) {
                doNotifTx(itemValue);
            } else if (BIP47Meta.getInstance().getOutgoingStatus(itemValue) == BIP47Meta.STATUS_SENT_NO_CFM) {
                // Toast.makeText(BIP47Activity.this, R.string.bip47_wait_for_confirmation, Toast.LENGTH_SHORT).show();
                AlertDialog.Builder dlg = new AlertDialog.Builder(BIP47Activity.this).setTitle(R.string.app_name).setMessage(R.string.bip47_wait_for_confirmation_or_retry).setCancelable(false).setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {

                    public void onClick(DialogInterface dialog, int whichButton) {
                        doNotifTx(itemValue);
                    }
                }).setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {

                    public void onClick(DialogInterface dialog, int whichButton) {
                        ;
                    }
                });
                if (!isFinishing()) {
                    dlg.show();
                }
            } else {
                AlertDialog.Builder dlg = new AlertDialog.Builder(BIP47Activity.this).setTitle(R.string.app_name).setMessage(R.string.bip47_spend_to_pcode).setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {

                    public void onClick(DialogInterface dialog, int whichButton) {
                        AppUtil.getInstance(BIP47Activity.this).restartApp("pcode", itemValue);
                    }
                }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {

                    public void onClick(DialogInterface dialog, int whichButton) {
                        ;
                    }
                });
                dlg.show();
            }
        }
    });
    listView.setOnMenuItemClickListener(new SwipeMenuListView.OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(final int position, SwipeMenu menu, int index) {
            switch(index) {
                case 0:
                    {
                        Intent intent = new Intent(BIP47Activity.this, BIP47Add.class);
                        intent.putExtra("label", BIP47Meta.getInstance().getLabel(pcodes[position]));
                        intent.putExtra("pcode", pcodes[position]);
                        startActivityForResult(intent, EDIT_PCODE);
                    }
                    break;
                case 1:
                    doSync(pcodes[position]);
                    break;
                case 2:
                    {
                        Intent intent = new Intent(BIP47Activity.this, BIP47ShowQR.class);
                        intent.putExtra("label", BIP47Meta.getInstance().getLabel(pcodes[position]));
                        intent.putExtra("pcode", pcodes[position]);
                        startActivity(intent);
                    }
                    break;
                case 3:
                    // archive
                    BIP47Meta.getInstance().setArchived(pcodes[position], true);
                    refreshList();
                    adapter.notifyDataSetChanged();
                    break;
            }
            return false;
        }
    });
    listView.setLongClickable(true);
    listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {

        public boolean onItemLongClick(AdapterView<?> parent, View v, int position, long id) {
            int outgoing = BIP47Meta.getInstance().getOutgoingIdx(pcodes[position]);
            int incoming = BIP47Meta.getInstance().getIncomingIdx(pcodes[position]);
            // Toast.makeText(BIP47Activity.this, pcodes[position], Toast.LENGTH_SHORT).show();
            Toast.makeText(BIP47Activity.this, "Incoming index:" + incoming + ", Outgoing index:" + outgoing, Toast.LENGTH_SHORT).show();
            return true;
        }
    });
    SwipeMenuCreator creator = new SwipeMenuCreator() {

        @Override
        public void create(SwipeMenu menu) {
            // create "edit" item
            SwipeMenuItem openItem = new SwipeMenuItem(getApplicationContext());
            // set item background
            openItem.setBackground(new ColorDrawable(Color.rgb(0x17, 0x1B, 0x24)));
            // set item width
            openItem.setWidth(180);
            // set a icon
            openItem.setIcon(R.drawable.ic_edit_white_24dp);
            // add to menu
            menu.addMenuItem(openItem);
            // create "sync" item
            SwipeMenuItem syncItem = new SwipeMenuItem(getApplicationContext());
            // set item background
            syncItem.setBackground(new ColorDrawable(Color.rgb(0x17, 0x1B, 0x24)));
            // set item width
            syncItem.setWidth(180);
            // set a icon
            syncItem.setIcon(android.R.drawable.ic_popup_sync);
            // add to menu
            menu.addMenuItem(syncItem);
            // create "qr" item
            SwipeMenuItem qrItem = new SwipeMenuItem(getApplicationContext());
            // set item background
            qrItem.setBackground(new ColorDrawable(Color.rgb(0x17, 0x1B, 0x24)));
            // set item width
            qrItem.setWidth(180);
            // set a icon
            qrItem.setIcon(R.drawable.ic_receive_qr);
            // add to menu
            menu.addMenuItem(qrItem);
            // create "qr" item
            SwipeMenuItem archiveItem = new SwipeMenuItem(getApplicationContext());
            // set item background
            archiveItem.setBackground(new ColorDrawable(Color.rgb(0x17, 0x1B, 0x24)));
            // set item width
            archiveItem.setWidth(180);
            // set a icon
            archiveItem.setIcon(android.R.drawable.ic_media_pause);
            // add to menu
            menu.addMenuItem(archiveItem);
        }
    };
    listView.setMenuCreator(creator);
    listView.setSwipeDirection(SwipeMenuListView.DIRECTION_LEFT);
    doTimer();
    Bundle extras = getIntent().getExtras();
    if (extras != null && extras.containsKey("pcode")) {
        String pcode = extras.getString("pcode");
        String meta = null;
        if (extras.containsKey("meta")) {
            meta = extras.getString("meta");
        }
        String _meta = null;
        try {
            Map<String, String> map = new HashMap<String, String>();
            if (meta != null && meta.length() > 0) {
                _meta = URLDecoder.decode(meta, "UTF-8");
                map = Splitter.on('&').trimResults().withKeyValueSeparator("=").split(_meta);
            }
            Intent intent = new Intent(BIP47Activity.this, BIP47Add.class);
            intent.putExtra("pcode", pcode);
            intent.putExtra("label", map.containsKey("title") ? map.get("title").trim() : "");
            startActivityForResult(intent, EDIT_PCODE);
        } catch (UnsupportedEncodingException uee) {
            ;
        } catch (Exception e) {
            ;
        }
    }
}
Also used : AlertDialog(android.app.AlertDialog) DialogInterface(android.content.DialogInterface) SwipeMenu(com.baoyz.swipemenulistview.SwipeMenu) HashMap(java.util.HashMap) Bitmap(android.graphics.Bitmap) SwipeMenuCreator(com.baoyz.swipemenulistview.SwipeMenuCreator) SwipeMenuItem(com.baoyz.swipemenulistview.SwipeMenuItem) ActionBar(android.app.ActionBar) Bundle(android.os.Bundle) Handler(android.os.Handler) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Intent(android.content.Intent) SwipeMenuListView(com.baoyz.swipemenulistview.SwipeMenuListView) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) MyTransactionOutPoint(com.samourai.wallet.send.MyTransactionOutPoint) SecretPoint(com.samourai.wallet.bip47.rpc.SecretPoint) Point(android.graphics.Point) NotSecp256k1Exception(com.samourai.wallet.bip47.rpc.NotSecp256k1Exception) JSONException(org.json.JSONException) AddressFormatException(org.bitcoinj.core.AddressFormatException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InvalidKeyException(java.security.InvalidKeyException) InvalidKeySpecException(java.security.spec.InvalidKeySpecException) DecryptionException(com.samourai.wallet.crypto.DecryptionException) IOException(java.io.IOException) DecoderException(org.bouncycastle.util.encoders.DecoderException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) MnemonicException(org.bitcoinj.crypto.MnemonicException) NoSuchProviderException(java.security.NoSuchProviderException) SwipeMenuListView(com.baoyz.swipemenulistview.SwipeMenuListView) ColorDrawable(android.graphics.drawable.ColorDrawable) AdapterView(android.widget.AdapterView)

Example 2 with SwipeMenuCreator

use of com.baoyz.swipemenulistview.SwipeMenuCreator in project JustAndroid by chinaltz.

the class MvvmGreenDaoActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_note);
    ButterKnife.bind(this);
    noteDao = MyApplication.getInstance().getDaoSession().getNoteDao();
    navBack.setVisibility(View.VISIBLE);
    navTitle.setText("简单笔记本");
    navRight.setVisibility(View.VISIBLE);
    navRightText.setText("添加");
    noteList = new ArrayList<>();
    adapter = new MvvmNoteAdapter(mContext, noteList);
    navBack.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            finish();
        }
    });
    navRight.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            View view = LayoutInflater.from(mContext).inflate(R.layout.view_add_note, null);
            final EditText titleText = (EditText) view.findViewById(R.id.titleText);
            final EditText contentText = (EditText) view.findViewById(R.id.contentText);
            Button commitButton = (Button) view.findViewById(R.id.commitButton);
            AbDialogUtil.showDialog(view, Gravity.CENTER);
            commitButton.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    String title = titleText.getText().toString();
                    String content = contentText.getText().toString();
                    if (AbStrUtil.isEmpty(title)) {
                        AbDialogUtil.removeDialog(mContext);
                        return;
                    }
                    if (AbStrUtil.isEmpty(content)) {
                        AbDialogUtil.removeDialog(mContext);
                        return;
                    }
                    Note note = new Note();
                    note.setCreatDate(new Date());
                    note.setNoteTitle(title);
                    note.setFavFlag(0);
                    note.setNoteContent(content);
                    noteDao.insert(note);
                    AbDialogUtil.removeDialog(mContext);
                    refreshNoteList();
                }
            });
        }
    });
    listView.setAdapter(adapter);
    refreshNoteList();
    // 1.创建侧滑按钮菜单
    SwipeMenuCreator creator = new SwipeMenuCreator() {

        @Override
        public void create(SwipeMenu menu) {
            // create "open" item
            // create "delete" item
            SwipeMenuItem deleteItem = new SwipeMenuItem(getApplicationContext());
            // set item background
            deleteItem.setBackground(new ColorDrawable(Color.rgb(0xF9, 0x3F, 0x25)));
            // set item width
            deleteItem.setWidth(150);
            // set a icon
            deleteItem.setIcon(R.drawable.ic_delete);
            // add to menu
            menu.addMenuItem(deleteItem);
        }
    };
    // 设置 MenuCreator
    listView.setMenuCreator(creator);
    // 2. 设置侧滑按钮 监听事件
    listView.setOnMenuItemClickListener(new SwipeMenuListView.OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(int position, SwipeMenu menu, int index) {
            switch(index) {
                case 0:
                    // delete
                    noteDao.delete(noteList.get(position));
                    refreshNoteList();
                    break;
            }
            return false;
        }
    });
}
Also used : EditText(android.widget.EditText) SwipeMenu(com.baoyz.swipemenulistview.SwipeMenu) SwipeMenuListView(com.baoyz.swipemenulistview.SwipeMenuListView) ImageView(android.widget.ImageView) BindView(butterknife.BindView) View(android.view.View) TextView(android.widget.TextView) Date(java.util.Date) ColorDrawable(android.graphics.drawable.ColorDrawable) SwipeMenuListView(com.baoyz.swipemenulistview.SwipeMenuListView) Button(android.widget.Button) SwipeMenuCreator(com.baoyz.swipemenulistview.SwipeMenuCreator) Note(com.litingzhe.justandroid.netdb.db.model.Note) MvvmNoteAdapter(com.litingzhe.justandroid.designMode.mvvm.adapter.MvvmNoteAdapter) SwipeMenuItem(com.baoyz.swipemenulistview.SwipeMenuItem)

Example 3 with SwipeMenuCreator

use of com.baoyz.swipemenulistview.SwipeMenuCreator in project SwipeMenuListView by baoyongzhang.

the class SimpleActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_list);
    mAppList = getPackageManager().getInstalledApplications(0);
    mListView = (SwipeMenuListView) findViewById(R.id.listView);
    mAdapter = new AppAdapter();
    mListView.setAdapter(mAdapter);
    // step 1. create a MenuCreator
    SwipeMenuCreator creator = new SwipeMenuCreator() {

        @Override
        public void create(SwipeMenu menu) {
            // create "open" item
            SwipeMenuItem openItem = new SwipeMenuItem(getApplicationContext());
            // set item background
            openItem.setBackground(new ColorDrawable(Color.rgb(0xC9, 0xC9, 0xCE)));
            // set item width
            openItem.setWidth(dp2px(90));
            // set item title
            openItem.setTitle("Open");
            // set item title fontsize
            openItem.setTitleSize(18);
            // set item title font color
            openItem.setTitleColor(Color.WHITE);
            // add to menu
            menu.addMenuItem(openItem);
            // create "delete" item
            SwipeMenuItem deleteItem = new SwipeMenuItem(getApplicationContext());
            // set item background
            deleteItem.setBackground(new ColorDrawable(Color.rgb(0xF9, 0x3F, 0x25)));
            // set item width
            deleteItem.setWidth(dp2px(90));
            // set a icon
            deleteItem.setIcon(R.drawable.ic_delete);
            // add to menu
            menu.addMenuItem(deleteItem);
        }
    };
    // set creator
    mListView.setMenuCreator(creator);
    // step 2. listener item click event
    mListView.setOnMenuItemClickListener(new SwipeMenuListView.OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(int position, SwipeMenu menu, int index) {
            ApplicationInfo item = mAppList.get(position);
            switch(index) {
                case 0:
                    // open
                    open(item);
                    break;
                case 1:
                    // delete
                    // delete(item);
                    mAppList.remove(position);
                    mAdapter.notifyDataSetChanged();
                    break;
            }
            return false;
        }
    });
    // set SwipeListener
    mListView.setOnSwipeListener(new SwipeMenuListView.OnSwipeListener() {

        @Override
        public void onSwipeStart(int position) {
        // swipe start
        }

        @Override
        public void onSwipeEnd(int position) {
        // swipe end
        }
    });
    // set MenuStateChangeListener
    mListView.setOnMenuStateChangeListener(new SwipeMenuListView.OnMenuStateChangeListener() {

        @Override
        public void onMenuOpen(int position) {
        }

        @Override
        public void onMenuClose(int position) {
        }
    });
    // other setting
    // listView.setCloseInterpolator(new BounceInterpolator());
    // test item long click
    mListView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {

        @Override
        public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
            Toast.makeText(getApplicationContext(), position + " long click", Toast.LENGTH_SHORT).show();
            return false;
        }
    });
}
Also used : SwipeMenu(com.baoyz.swipemenulistview.SwipeMenu) ApplicationInfo(android.content.pm.ApplicationInfo) SwipeMenuListView(com.baoyz.swipemenulistview.SwipeMenuListView) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ColorDrawable(android.graphics.drawable.ColorDrawable) SwipeMenuListView(com.baoyz.swipemenulistview.SwipeMenuListView) SwipeMenuCreator(com.baoyz.swipemenulistview.SwipeMenuCreator) SwipeMenuItem(com.baoyz.swipemenulistview.SwipeMenuItem) AdapterView(android.widget.AdapterView)

Example 4 with SwipeMenuCreator

use of com.baoyz.swipemenulistview.SwipeMenuCreator in project sentinel-android by Samourai-Wallet.

the class XPUBListActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_list);
    xpubs = getXPUBS();
    if (xpubs.size() == 0) {
        PrefsUtil.getInstance(XPUBListActivity.this).setValue(PrefsUtil.XPUB, "");
        AppUtil.getInstance(XPUBListActivity.this).restartApp();
    }
    xpubList = (SwipeMenuListView) findViewById(R.id.xpubList);
    xpubAdapter = new XPUBAdapter();
    xpubList.setAdapter(xpubAdapter);
    xpubList.setOnMenuItemClickListener(new SwipeMenuListView.OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(final int position, SwipeMenu menu, int index) {
            switch(index) {
                case 0:
                    new AlertDialog.Builder(XPUBListActivity.this).setTitle(R.string.app_name).setMessage(R.string.sure_to_delete).setCancelable(false).setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {

                        public void onClick(DialogInterface dialog, int whichButton) {
                            dialog.dismiss();
                            String xpub = xpubs.get(position).second;
                            updateXPUBs(xpub, null, true, false);
                            xpubs = getXPUBS();
                            if (xpubs.size() == 0) {
                                PrefsUtil.getInstance(XPUBListActivity.this).setValue(PrefsUtil.XPUB, "");
                                AppUtil.getInstance(XPUBListActivity.this).restartApp();
                            }
                            xpubAdapter.notifyDataSetChanged();
                        }
                    }).setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {

                        public void onClick(DialogInterface dialog, int whichButton) {
                            ;
                        }
                    }).show();
                    break;
                case 1:
                    {
                        Intent intent = new Intent(XPUBListActivity.this, ShowQRActivity.class);
                        intent.putExtra("label", xpubs.get(position).first);
                        intent.putExtra("xpub", xpubs.get(position).second);
                        startActivity(intent);
                    }
                    break;
                case 2:
                    final EditText etLabel = new EditText(XPUBListActivity.this);
                    etLabel.setSingleLine(true);
                    etLabel.setHint(getText(R.string.xpub_label));
                    etLabel.setText(xpubs.get(position).first);
                    new AlertDialog.Builder(XPUBListActivity.this).setTitle(R.string.app_name).setView(etLabel).setCancelable(false).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {

                        public void onClick(DialogInterface dialog, int whichButton) {
                            dialog.dismiss();
                            String label = etLabel.getText().toString().trim();
                            String xpub = xpubs.get(position).second;
                            boolean isBIP49 = false;
                            if (SamouraiSentinel.getInstance(XPUBListActivity.this).getBIP49().keySet().contains(xpub)) {
                                isBIP49 = true;
                            }
                            updateXPUBs(xpub, label, false, isBIP49);
                            xpubs = getXPUBS();
                            xpubAdapter.notifyDataSetChanged();
                        }
                    }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {

                        public void onClick(DialogInterface dialog, int whichButton) {
                            ;
                        }
                    }).show();
                    break;
            }
            return false;
        }
    });
    SwipeMenuCreator creator = new SwipeMenuCreator() {

        @Override
        public void create(SwipeMenu menu) {
            // create "delete" item
            SwipeMenuItem deleteItem = new SwipeMenuItem(getApplicationContext());
            // set item background
            deleteItem.setBackground(new ColorDrawable(Color.rgb(0x17, 0x1B, 0x24)));
            // set item width
            // deleteItem.setWidth(dp2px(90));
            deleteItem.setWidth(180);
            // set a icon
            deleteItem.setIcon(R.drawable.ic_close_white_24dp);
            // add to menu
            menu.addMenuItem(deleteItem);
            // create "qr" item
            SwipeMenuItem qrItem = new SwipeMenuItem(getApplicationContext());
            // set item background
            qrItem.setBackground(new ColorDrawable(Color.rgb(0x17, 0x1B, 0x24)));
            // set item width
            qrItem.setWidth(180);
            // set a icon
            qrItem.setIcon(R.drawable.ic_receive_qr);
            // add to menu
            menu.addMenuItem(qrItem);
            // create "edit" item
            SwipeMenuItem openItem = new SwipeMenuItem(getApplicationContext());
            // set item background
            openItem.setBackground(new ColorDrawable(Color.rgb(0x17, 0x1B, 0x24)));
            // set item width
            openItem.setWidth(180);
            // set a icon
            openItem.setIcon(R.drawable.ic_edit_white_24dp);
            // add to menu
            menu.addMenuItem(openItem);
        }
    };
    xpubList.setMenuCreator(creator);
    xpubList.setSwipeDirection(SwipeMenuListView.DIRECTION_LEFT);
    actionXPUB = (FloatingActionButton) findViewById(R.id.xpub);
    actionXPUB.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View arg0) {
            Intent intent = new Intent(XPUBListActivity.this, InsertActivity.class);
            startActivity(intent);
        }
    });
}
Also used : AlertDialog(android.app.AlertDialog) EditText(android.widget.EditText) SwipeMenu(com.baoyz.swipemenulistview.SwipeMenu) DialogInterface(android.content.DialogInterface) Intent(android.content.Intent) SwipeMenuListView(com.baoyz.swipemenulistview.SwipeMenuListView) View(android.view.View) TextView(android.widget.TextView) SwipeMenuListView(com.baoyz.swipemenulistview.SwipeMenuListView) ColorDrawable(android.graphics.drawable.ColorDrawable) SwipeMenuCreator(com.baoyz.swipemenulistview.SwipeMenuCreator) SwipeMenuItem(com.baoyz.swipemenulistview.SwipeMenuItem)

Example 5 with SwipeMenuCreator

use of com.baoyz.swipemenulistview.SwipeMenuCreator in project SwipeMenuListView by baoyongzhang.

the class DifferentMenuActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_list);
    mAppList = getPackageManager().getInstalledApplications(0);
    SwipeMenuListView listView = (SwipeMenuListView) findViewById(R.id.listView);
    mAdapter = new AppAdapter();
    listView.setAdapter(mAdapter);
    // step 1. create a MenuCreator
    SwipeMenuCreator creator = new SwipeMenuCreator() {

        @Override
        public void create(SwipeMenu menu) {
            // Create different menus depending on the view type
            switch(menu.getViewType()) {
                case 0:
                    createMenu1(menu);
                    break;
                case 1:
                    createMenu2(menu);
                    break;
                case 2:
                    createMenu3(menu);
                    break;
            }
        }

        private void createMenu1(SwipeMenu menu) {
            SwipeMenuItem item1 = new SwipeMenuItem(getApplicationContext());
            item1.setBackground(new ColorDrawable(Color.rgb(0xE5, 0x18, 0x5E)));
            item1.setWidth(dp2px(90));
            item1.setIcon(R.drawable.ic_action_favorite);
            menu.addMenuItem(item1);
            SwipeMenuItem item2 = new SwipeMenuItem(getApplicationContext());
            item2.setBackground(new ColorDrawable(Color.rgb(0xC9, 0xC9, 0xCE)));
            item2.setWidth(dp2px(90));
            item2.setIcon(R.drawable.ic_action_good);
            menu.addMenuItem(item2);
        }

        private void createMenu2(SwipeMenu menu) {
            SwipeMenuItem item1 = new SwipeMenuItem(getApplicationContext());
            item1.setBackground(new ColorDrawable(Color.rgb(0xE5, 0xE0, 0x3F)));
            item1.setWidth(dp2px(90));
            item1.setIcon(R.drawable.ic_action_important);
            menu.addMenuItem(item1);
            SwipeMenuItem item2 = new SwipeMenuItem(getApplicationContext());
            item2.setBackground(new ColorDrawable(Color.rgb(0xF9, 0x3F, 0x25)));
            item2.setWidth(dp2px(90));
            item2.setIcon(R.drawable.ic_action_discard);
            menu.addMenuItem(item2);
        }

        private void createMenu3(SwipeMenu menu) {
            SwipeMenuItem item1 = new SwipeMenuItem(getApplicationContext());
            item1.setBackground(new ColorDrawable(Color.rgb(0x30, 0xB1, 0xF5)));
            item1.setWidth(dp2px(90));
            item1.setIcon(R.drawable.ic_action_about);
            menu.addMenuItem(item1);
            SwipeMenuItem item2 = new SwipeMenuItem(getApplicationContext());
            item2.setBackground(new ColorDrawable(Color.rgb(0xC9, 0xC9, 0xCE)));
            item2.setWidth(dp2px(90));
            item2.setIcon(R.drawable.ic_action_share);
            menu.addMenuItem(item2);
        }
    };
    // set creator
    listView.setMenuCreator(creator);
    // step 2. listener item click event
    listView.setOnMenuItemClickListener(new SwipeMenuListView.OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(int position, SwipeMenu menu, int index) {
            ApplicationInfo item = mAppList.get(position);
            switch(index) {
                case 0:
                    // open
                    break;
                case 1:
                    // delete
                    // delete(item);
                    mAppList.remove(position);
                    mAdapter.notifyDataSetChanged();
                    break;
            }
            return false;
        }
    });
}
Also used : SwipeMenuListView(com.baoyz.swipemenulistview.SwipeMenuListView) ColorDrawable(android.graphics.drawable.ColorDrawable) SwipeMenu(com.baoyz.swipemenulistview.SwipeMenu) SwipeMenuCreator(com.baoyz.swipemenulistview.SwipeMenuCreator) ApplicationInfo(android.content.pm.ApplicationInfo) SwipeMenuItem(com.baoyz.swipemenulistview.SwipeMenuItem)

Aggregations

ColorDrawable (android.graphics.drawable.ColorDrawable)8 SwipeMenu (com.baoyz.swipemenulistview.SwipeMenu)8 SwipeMenuCreator (com.baoyz.swipemenulistview.SwipeMenuCreator)8 SwipeMenuItem (com.baoyz.swipemenulistview.SwipeMenuItem)8 SwipeMenuListView (com.baoyz.swipemenulistview.SwipeMenuListView)8 View (android.view.View)7 TextView (android.widget.TextView)7 ImageView (android.widget.ImageView)6 BindView (butterknife.BindView)4 ApplicationInfo (android.content.pm.ApplicationInfo)3 EditText (android.widget.EditText)3 AlertDialog (android.app.AlertDialog)2 DialogInterface (android.content.DialogInterface)2 Intent (android.content.Intent)2 AdapterView (android.widget.AdapterView)2 Button (android.widget.Button)2 NoteAdapter (com.litingzhe.justandroid.netdb.db.adapter.NoteAdapter)2 Note (com.litingzhe.justandroid.netdb.db.model.Note)2 Date (java.util.Date)2 ActionBar (android.app.ActionBar)1