Back to project page frc-notebook.
The source code is released under:
GNU General Public License
If you think the Android project frc-notebook listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.plnyyanks.frcnotebook.background; /*from w w w . j a v a 2 s .co m*/ import android.app.Activity; import android.content.DialogInterface; import android.os.AsyncTask; import android.util.Log; import android.util.SparseArray; import android.view.ActionMode; import android.view.MenuItem; import android.view.View; import android.widget.ExpandableListView; import android.widget.ProgressBar; import android.widget.Toast; import com.plnyyanks.frcnotebook.Constants; import com.plnyyanks.frcnotebook.R; import com.plnyyanks.frcnotebook.activities.StartActivity; import com.plnyyanks.frcnotebook.adapters.ActionBarCallback; import com.plnyyanks.frcnotebook.adapters.NotesExpandableListAdapter; import com.plnyyanks.frcnotebook.datatypes.ListGroup; import com.plnyyanks.frcnotebook.datatypes.Note; import com.plnyyanks.frcnotebook.dialogs.DeleteDialog; import java.util.ArrayList; /** * File created by phil on 3/1/14. * Copyright 2014, Phil Lopreiato * This file is part of FRC Notebook. * FRC Notebook is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * FRC Notebook is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. * You should have received a copy of the GNU General Public License along with FRC Notebook. If not, see http://www.gnu.org/licenses/. */ public class GetNotesForTeam extends AsyncTask<String,String,String> { private static Activity activity; private static String teamKey,teamNumber,eventKey, eventTitle; private static SparseArray<ListGroup> groups = new SparseArray<ListGroup>(); private static NotesExpandableListAdapter adapter; private static ExpandableListView noteList; public static Object mActionMode; public static String selectedNote=""; public GetNotesForTeam(Activity activity) { super(); GetNotesForTeam.activity = activity; } @Override protected String doInBackground(String... strings) { teamKey = strings[0]; eventKey = strings[1]; teamNumber = teamKey.substring(3); eventTitle = strings[2]; selectedNote = ""; createData(); activity.runOnUiThread(new Runnable() { @Override public void run() { noteList = (ExpandableListView) activity.findViewById(R.id.note_list); if(noteList!=null) { adapter = new NotesExpandableListAdapter(activity, groups); noteList.setAdapter(adapter); //hide the progress bar ProgressBar prog = (ProgressBar) activity.findViewById(R.id.notes_loading_progress); prog.setVisibility(View.GONE); } } }); return null; } private void createData() { final ArrayList<Note> generalNotes = StartActivity.db.getAllNotes(teamKey,eventKey,"all"); final ArrayList<Note> matchNotes = StartActivity.db.getAllMatchNotes(teamKey,eventKey); ListGroup generalNoteGroup = new ListGroup("General Notes ("+generalNotes.size()+")"); for (Note n : generalNotes) { generalNoteGroup.children.add(Note.buildGeneralNoteTitle(n, eventTitle.equals("all"),teamKey.equals("all"))); generalNoteGroup.children_keys.add(Integer.toString(n.getId())); } groups.append(0,generalNoteGroup); ListGroup matchNoteGroup = new ListGroup(("Match Notes ("+matchNotes.size()+")")); for (Note n : matchNotes) { matchNoteGroup.children.add(Note.buildMatchNoteTitle(n, eventKey.equals("all"),true,teamKey.equals("all"))); matchNoteGroup.children_keys.add(Integer.toString(n.getId())); } groups.append(1,matchNoteGroup); } public static void updateListData(){ adapter.notifyDataSetChanged(); } public static SparseArray<ListGroup> getListData() { return groups; } public static String getTeamKey() { return teamKey; } public static String getTeamNumber() { return teamNumber; } public static String getEventKey() { return eventKey; } public static NotesExpandableListAdapter getAdapter(){ return adapter; } public static ActionMode.Callback mActionModeCallback = new ActionBarCallback() { @Override public boolean onActionItemClicked(ActionMode mode, MenuItem item) { switch (item.getItemId()) { case R.id.action_delete: confirmAndDelete(selectedNote); // the Action was executed, close the CAB selectedNote = ""; mode.finish(); return true; default: return false; } } @Override public void onDestroyActionMode(ActionMode actionMode) { Log.d(Constants.LOG_TAG, "Destroy CAB"); mActionMode = null; noteList.requestFocusFromTouch(); noteList.clearChoices(); adapter.notifyDataSetChanged(); } private void confirmAndDelete(final String noteId){ DialogInterface.OnClickListener deleter = new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { //delete the event now StartActivity.db.deleteNote(noteId); adapter.removeNote(Short.parseShort(noteId)); adapter.notifyDataSetChanged(); Toast.makeText(activity, "Deleted note from database", Toast.LENGTH_SHORT).show(); dialog.cancel(); } }; new DeleteDialog(activity.getString(R.string.note_deletion_message),deleter) .show(activity.getFragmentManager(),"delete_note"); } }; }