Search in sources :

Example 6 with SwipeMenuCreator

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

the class SwipeLeftActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_swipeleftlist);
    ButterKnife.bind(this);
    navBack.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            finish();
        }
    });
    navTitle.setText("带侧滑的按钮(程序管理)");
    mAppList = getPackageManager().getInstalledApplications(0);
    mListView = (SwipeMenuListView) findViewById(R.id.listView);
    mAdapter = new AppAdapter();
    mListView.setAdapter(mAdapter);
    // 1.创建侧滑按钮菜单
    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);
        }
    };
    // 设置 MenuCreator
    mListView.setMenuCreator(creator);
    // 2. 设置侧滑按钮 监听事件
    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
        }
    });
}
Also used : SwipeMenu(com.baoyz.swipemenulistview.SwipeMenu) ApplicationInfo(android.content.pm.ApplicationInfo) SwipeMenuListView(com.baoyz.swipemenulistview.SwipeMenuListView) ImageView(android.widget.ImageView) BindView(butterknife.BindView) View(android.view.View) TextView(android.widget.TextView) ColorDrawable(android.graphics.drawable.ColorDrawable) SwipeMenuListView(com.baoyz.swipemenulistview.SwipeMenuListView) SwipeMenuCreator(com.baoyz.swipemenulistview.SwipeMenuCreator) SwipeMenuItem(com.baoyz.swipemenulistview.SwipeMenuItem)

Example 7 with SwipeMenuCreator

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

the class GreenDaoActivity 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 NoteAdapter(mContext, noteList);
    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) NoteAdapter(com.litingzhe.justandroid.netdb.db.adapter.NoteAdapter) SwipeMenuItem(com.baoyz.swipemenulistview.SwipeMenuItem)

Example 8 with SwipeMenuCreator

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

the class MvpGreenDaoActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_note);
    ButterKnife.bind(this);
    navBack.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            finish();
        }
    });
    presenter = new NotePresenter(this);
    noteDao = MyApplication.getInstance().getDaoSession().getNoteDao();
    navBack.setVisibility(View.VISIBLE);
    navTitle.setText("简单笔记本");
    navRight.setVisibility(View.VISIBLE);
    navRightText.setText("添加");
    noteList = new ArrayList<>();
    adapter = new NoteAdapter(mContext, noteList);
    navRight.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            showAddNoteDialog();
        }
    });
    refreshList();
    listView.setAdapter(adapter);
    // 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
                    presenter.deleteNote(noteList.get(position));
                    break;
            }
            return false;
        }
    });
}
Also used : SwipeMenu(com.baoyz.swipemenulistview.SwipeMenu) SwipeMenuListView(com.baoyz.swipemenulistview.SwipeMenuListView) NoteView(com.litingzhe.justandroid.designMode.mvp.view.NoteView) ImageView(android.widget.ImageView) BindView(butterknife.BindView) View(android.view.View) TextView(android.widget.TextView) ColorDrawable(android.graphics.drawable.ColorDrawable) SwipeMenuListView(com.baoyz.swipemenulistview.SwipeMenuListView) SwipeMenuCreator(com.baoyz.swipemenulistview.SwipeMenuCreator) NoteAdapter(com.litingzhe.justandroid.netdb.db.adapter.NoteAdapter) SwipeMenuItem(com.baoyz.swipemenulistview.SwipeMenuItem) NotePresenter(com.litingzhe.justandroid.designMode.mvp.presenter.NotePresenter)

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