private void importData() throws ClientProtocolException, JSONException, IOException { String sendReadRequest = sendReadRequest(); JSONObject result = new JSONObject(sendReadRequest); // Je�eli co� poszlo nie tak to konczymy import if (!"OK".equals(result.getString("response"))) return; JSONObject data = result.getJSONObject("data"); JSONArray tasks = data.getJSONArray("tasks"); TaskQueries.deleteTasks(TaskDb.getWritableDatabase()); for (int i = 0; i < tasks.length(); i++) { JSONObject task = tasks.getJSONObject(i); ContentValues vals = new ContentValues(); vals.put(Task._ID, task.getLong(Task._ID)); vals.put(Task.C_NAME, task.getString(Task.C_NAME)); vals.put(Task.C_DESCR, task.getString(Task.C_DESCR)); // Dodajemy rekordy do bazy TaskQueries.insertTask(TaskDb.getWritableDatabase(), vals); } Toast.makeText(this, "Zaladowalem " + tasks.length() + " zada�.", Toast.LENGTH_SHORT).show(); }
@Override public boolean onContextItemSelected(MenuItem item) { ContextMenuInfo menuInfo = item.getMenuInfo(); AdapterContextMenuInfo aMenuInfo = (AdapterContextMenuInfo) menuInfo; TaskQueries.deleteTask(TaskDb.getWritableDatabase(), aMenuInfo.id); reloadList(); /* AlertDialog.Builder adb=new AlertDialog.Builder(TaskListActivity.this); adb.setTitle("Usuna�?"); adb.setMessage("Czy jeste� pewien, �e chesz usuna� pozycje " + aMenuInfo.id); adb.setNegativeButton("Anuluj", null); adb.setPositiveButton("Usu�", new AlertDialog.OnClickListener() { @Override public void onClick(DialogInterface arg0, int arg1) { //Toast.makeText(TaskListActivity.this, "menu ctx id = ", Toast.LENGTH_SHORT).show(); //TaskQueries.deleteTask(TaskDb.getWritableDatabase(), aMenuInfo.id); } }); adb.show(); */ return true; }
private JSONArray readTaskList() throws JSONException { Cursor cursor = null; JSONArray retult = new JSONArray(); try { cursor = TaskQueries.selectTasks(TaskDb.getReadableDatabase()); if (cursor.moveToFirst()) { do { JSONObject taskObject = new JSONObject(); taskObject.put(Task._ID, cursor.getLong(cursor.getColumnIndex(Task._ID))); taskObject.put(Task.C_NAME, cursor.getString(cursor.getColumnIndex(Task.C_NAME))); taskObject.put(Task.C_DESCR, cursor.getString(cursor.getColumnIndex(Task.C_DESCR))); retult.put(taskObject); } while (cursor.moveToNext()); } } catch (Exception e) { Log.d("BUBA", e.getMessage()); } finally { if (cursor != null) cursor.close(); } return retult; }
@Override protected Cursor doInBackground(szkolenie.tasklist.TaskDb... params) { return TaskQueries.selectTasks(params[0].getReadableDatabase()); }