Android notepad NoteBook and androidnotebook

Source: Internet
Author: User

Android notepad NoteBook and androidnotebook

It is also transplanted from the mtk sdk and can be used to classify events.

The specific code can be viewed on GitHub. The link is at the end of the article. Below is:

Main Activity, Note list:

package com.zms.notebook;import android.app.ActionBar;import android.app.AlertDialog;import android.app.ListActivity;import android.app.ProgressDialog;import android.content.ComponentName;import android.content.ContentUris;import android.content.DialogInterface;import android.content.Intent;import android.net.Uri;import android.os.Bundle;import android.util.Log;import android.view.ActionMode;import android.view.Gravity;import android.view.LayoutInflater;import android.view.Menu;import android.view.MenuInflater;import android.view.MenuItem;import android.view.View;import android.view.ViewGroup;import android.view.ViewGroup.LayoutParams;import android.widget.AdapterView;import android.widget.AdapterView.OnItemLongClickListener;import android.widget.Button;import android.widget.ListView;import android.widget.PopupMenu;import android.widget.ProgressBar;import android.widget.TextView;import android.widget.Toast;import com.zms.notebook.NoteAdapter.NoteItem;import com.zms.notebook.NotePad.Notes;import java.util.Locale;public class NotesList extends ListActivity implements OnItemLongClickListener {    private static final String TAG = "NotesList";    public TextView countView;    public NoteAdapter noteadapter;    private ProgressDialog mPdialogDeleting;    private ModeCallback mActionModeListener = new ModeCallback();    public ActionMode mActionMode;    private Button mSelectedItemsView;    private NoteWaitCursorView mWaitCursorView;    private TextView mLoadingNotes;    private View mLoadingContainer;    private ProgressBar mProgress;    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setDefaultKeyMode(DEFAULT_KEYS_SHORTCUT);        setContentView(R.layout.noteslist_item_main);        ActionBar actionBar = getActionBar();        actionBar.setHomeButtonEnabled(false);        ViewGroup view = (ViewGroup) LayoutInflater.from(this).inflate(                R.layout.notelist_action_bar, null);        actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM,                ActionBar.DISPLAY_SHOW_CUSTOM);        actionBar.setCustomView(view, new ActionBar.LayoutParams(                LayoutParams.WRAP_CONTENT,                LayoutParams.WRAP_CONTENT, Gravity.CENTER_VERTICAL                        | Gravity.RIGHT));        countView = (TextView) view.findViewById(R.id.note_count);        getListView().setOnItemLongClickListener(this);        mLoadingNotes = (TextView)findViewById(R.id.loading_notes);        mLoadingContainer = findViewById(R.id.loading_container);        mProgress = (ProgressBar)findViewById(R.id.progress_loading);        mProgress.setVisibility(View.GONE);        mWaitCursorView = new NoteWaitCursorView(this, mLoadingContainer,                mProgress, mLoadingNotes);    }    @Override    protected void onResume() {        super.onResume();        Log.i(TAG, "mActionMode = " + mActionMode + "\nsFlagNotesChanged"                + Notes.sFlagNotesChanged);        if (mActionMode == null && Notes.sFlagNotesChanged) {            queryUpdateData();            Notes.sFlagNotesChanged = false;        }        if (Notes.sSaveNoteFlag) {            Toast.makeText(this, R.string.note_saved, Toast.LENGTH_LONG).show();            Notes.sSaveNoteFlag = false;        } else if (Notes.sSaveNoNote) {            Toast.makeText(this, R.string.save_none, Toast.LENGTH_LONG).show();            Notes.sSaveNoNote = false;        }    }    @Override    protected void onDestroy() {        super.onDestroy();        noteadapter = null;        Notes.sFlagNotesChanged = true;    }    public void queryUpdateData() {        Log.i(TAG, "queryUpdateData");        mWaitCursorView.startWaitCursor();        invalidateOptionsMenu();        noteadapter = new NoteAdapter(this, null, 0);        QueryHandler qh = new QueryHandler(this.getContentResolver(), this);        qh.startQuery(0, mWaitCursorView, Notes.CONTENT_URI, Notes.PROJECTION,                null, null, Notes.sSortOrder);    }    @Override    public boolean onCreateOptionsMenu(Menu menu) {        MenuInflater inflater = getMenuInflater();        inflater.inflate(R.menu.list_options_menu, menu);        Intent intent = new Intent(null, Notes.CONTENT_URI);        intent.addCategory(Intent.CATEGORY_ALTERNATIVE);        menu.addIntentOptions(Menu.CATEGORY_ALTERNATIVE, 0, 0,                new ComponentName(this, NotesList.class), null, intent, 0, null);        return super.onCreateOptionsMenu(menu);    }    @Override    public boolean onPrepareOptionsMenu(Menu menu) {        super.onPrepareOptionsMenu(menu);        if (Notes.sNoteCount == 0 || mWaitCursorView.getQueryStatus()) {            menu.findItem(R.id.menu_muti_delete).setEnabled(false);            menu.findItem(R.id.menu_sort_by_modify).setEnabled(false);            menu.findItem(R.id.menu_sort_by_tab).setEnabled(false);        } else {            menu.findItem(R.id.menu_muti_delete).setEnabled(true);            menu.findItem(R.id.menu_sort_by_modify).setEnabled(true);            menu.findItem(R.id.menu_sort_by_tab).setEnabled(true);        }        return true;    }    @Override    public boolean onOptionsItemSelected(MenuItem item) {        Intent it;        switch (item.getItemId()) {        case R.id.menu_add:            it = new Intent(this, NoteEdit.class);            this.startActivity(it);            return true;        case R.id.menu_muti_delete:            deleteAllNotes();            return true;        case R.id.menu_sort_by_tab:            Notes.sSortOrder = "notegroup DESC, modified DESC";            queryUpdateData();            return true;        case R.id.menu_sort_by_modify:            Notes.sSortOrder = "modified DESC";            queryUpdateData();            return true;        default:            return super.onOptionsItemSelected(item);        }    }    @Override    protected void onListItemClick(ListView l, View v, int position, long id) {        NoteItem noteitem = (NoteItem) l.getAdapter().getItem(position);        Uri uri = ContentUris.withAppendedId(Notes.CONTENT_URI, noteitem.id);        if (mActionMode != null) {            noteadapter.checkboxClickAction(position);            mSelectedItemsView.setText(getString(R.string.selected_item_count,                    Notes.sDeleteNum));            if (Notes.sDeleteNum == 0) {                mActionMode.finish();            }        } else {            Intent it = new Intent(this, NoteReading.class);            it.setData(uri);            this.startActivity(it);        }    }    @Override    public boolean onItemLongClick(AdapterView parent, View view, int position,            long id) {        Notes.sDeleteNum = 1;        mActionMode = startActionMode(mActionModeListener);        noteadapter.checkboxClickAction(position);        return true;    }    private class ModeCallback implements ActionMode.Callback {        private View mMultiSelectActionBarView;        @Override        public boolean onCreateActionMode(ActionMode mode, Menu menu) {            MenuInflater inflater = getMenuInflater();            inflater.inflate(R.menu.list_delete_menu, menu);            if (mMultiSelectActionBarView == null) {                mMultiSelectActionBarView = LayoutInflater.from(NotesList.this)                        .inflate(R.layout.noteslist_item_delete_action_bar,                                null);            }            mode.setCustomView(mMultiSelectActionBarView);            ((TextView) mMultiSelectActionBarView                    .findViewById(R.id.select_items)).setText(getString(                    R.string.selected_item_count, Notes.sDeleteNum));            mMultiSelectActionBarView.setVisibility(View.VISIBLE);            mSelectedItemsView = (Button) mMultiSelectActionBarView                    .findViewById(R.id.select_items);            mSelectedItemsView.setOnClickListener(new View.OnClickListener() {                @Override                public void onClick(View v) {                    PopupMenu popup = new PopupMenu(NotesList.this, v);                    popup.getMenuInflater().inflate(                            R.menu.multi_delete_action_bar, popup.getMenu());                    popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {                        @Override                        public boolean onMenuItemClick(MenuItem item) {                            int id = item.getItemId();                            if (id == R.id.menu_all_select) {                                noteadapter.selectAllOrNoCheckbox(true);                                mSelectedItemsView.setText(getString(                                        R.string.selected_item_count,                                        Notes.sDeleteNum));                            } else if (id == R.id.menu_no_select) {                                mActionMode.finish();                            } else {                                return true;                            }                            return false;                        }                    });                    Menu popupMenu = popup.getMenu();                    MenuItem selectAllItem = popupMenu                            .findItem(R.id.menu_all_select);                    MenuItem unSelectAllItem = popupMenu                            .findItem(R.id.menu_no_select);                    if (Notes.sDeleteNum >= noteadapter.getCount()) {                        if (selectAllItem != null) {                            selectAllItem.setVisible(false);                        }                        if (unSelectAllItem != null) {                            unSelectAllItem.setVisible(true);                        }                    } else {                        if (selectAllItem != null) {                            selectAllItem.setVisible(true);                        }                        if (unSelectAllItem != null) {                            unSelectAllItem.setVisible(false);                        }                    }                    popup.show();                }            });                getListView().setLongClickable(false);            return true;        }        @Override        public boolean onPrepareActionMode(ActionMode mode, Menu menu) {            return true;        }        @Override        public void onDestroyActionMode(ActionMode mode) {            Log.i(TAG, "onDestroyActionMode");            mMultiSelectActionBarView.setVisibility(View.GONE);            invalidateOptionsMenu();            getListView().setLongClickable(true);            mActionMode = null;            noteadapter.selectAllOrNoCheckbox(false);        }        @Override        public boolean onActionItemClicked(final ActionMode mode, MenuItem item) {            switch (item.getItemId()) {            case R.id.menu_delete:                mutiDeleteSelectNotes();                break;            default:                break;            }            return true;        }    }    private void mutiDeleteSelectNotes() {        if (Notes.sDeleteNum > 0) {            AlertDialog.Builder bld = new AlertDialog.Builder(this);            bld.setPositiveButton(getString(R.string.delete_confirm_ok),                    new DialogInterface.OnClickListener() {                        @Override                        public void onClick(DialogInterface dialog, int which) {                            dialog.dismiss();                            beginDeleteNotes(Notes.NOTESLIST_DELETE_TOKEN);                        }                    });            bld.setNegativeButton(getString(R.string.delete_confirm_cancel),                    null);            bld.setCancelable(true);            bld.setMessage(getString(R.string.delete_confirm));            if (Notes.sDeleteNum > 1                    && Locale.getDefault().getLanguage().equals("en")) {                bld.setMessage(getString(R.string.delete_confirm));            } else {                bld.setMessage(getString(R.string.delete_confirm_one));            }            bld.setIconAttribute(android.R.attr.alertDialogIcon);            bld.setTitle(getString(R.string.delete_confirm_title));            AlertDialog dlg = bld.create();            dlg.show();        } else {            Toast.makeText(this, R.string.no_selected, Toast.LENGTH_LONG)                    .show();        }            }        public void beginDeleteNotes(int token) {        Log.i(TAG, "beginDeleteNotes");        mPdialogDeleting = ProgressDialog.show(this, "",                getString(R.string.delete_progress), true);        QueryHandler qh = new QueryHandler(this.getContentResolver(), this);        Log.i(TAG, "noteadapter.getFilter() =="+noteadapter.getFilter());        qh.startDelete(token, mPdialogDeleting, Notes.CONTENT_URI,                noteadapter.getFilter(), null);    }        private void deleteAllNotes() {        AlertDialog.Builder bld = new AlertDialog.Builder(this);        bld.setPositiveButton(getString(R.string.delete_confirm_ok),                new DialogInterface.OnClickListener() {                    @Override                    public void onClick(DialogInterface dialog, int which) {                        dialog.dismiss();                        for (int i = 0; i < noteadapter.list.size(); i++) {                            noteadapter.list.get(i).isselect = true;                        }                        beginDeleteNotes(Notes.NOTESLIST_DELETE_ALL_TOKEN);                    }                });        bld.setNegativeButton(getString(R.string.delete_confirm_cancel), null);        bld.setCancelable(true);        bld.setMessage(getString(R.string.delete_confirm));        bld.setMessage(getString(R.string.delete_all_notes_confirm));        bld.setIconAttribute(android.R.attr.alertDialogIcon);        bld.setTitle(getString(R.string.delete_confirm_title));        bld.create().show();    }}



Reprinted please indicate the source: Zhou mu Shui CSDN blog http://blog.csdn.net/zhoumushui
My GitHub: Zhou mu Shui's GitHub https://github.com/zhoumushui


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.