List of usage examples for android.content ContentValues ContentValues
public ContentValues()
From source file:org.tomahawk.libtomahawk.database.DatabaseHelper.java
/** * Store the given {@link Playlist}/*from ww w . j a va 2 s .c o m*/ * * @param playlist the given {@link Playlist} * @param reverseEntries set to true, if the order of the entries should be reversed before * storing in the database */ public void storePlaylist(final Playlist playlist, final boolean reverseEntries) { new Thread(new Runnable() { @Override public void run() { synchronized (this) { ContentValues values = new ContentValues(); values.put(TomahawkSQLiteHelper.PLAYLISTS_COLUMN_NAME, playlist.getName()); values.put(TomahawkSQLiteHelper.PLAYLISTS_COLUMN_CURRENTREVISION, playlist.getCurrentRevision()); values.put(TomahawkSQLiteHelper.PLAYLISTS_COLUMN_ID, playlist.getId()); values.put(TomahawkSQLiteHelper.PLAYLISTS_COLUMN_HATCHETID, playlist.getHatchetId()); mDatabase.beginTransaction(); mDatabase.insertWithOnConflict(TomahawkSQLiteHelper.TABLE_PLAYLISTS, null, values, SQLiteDatabase.CONFLICT_REPLACE); // Delete every already associated Track entry mDatabase.delete(TomahawkSQLiteHelper.TABLE_TRACKS, TomahawkSQLiteHelper.TRACKS_COLUMN_PLAYLISTID + " = ?", new String[] { playlist.getId() }); // Store every single Track in the database and store the relationship // by storing the playlists's id with it ArrayList<PlaylistEntry> entries = playlist.getEntries(); for (int i = 0; i < entries.size(); i++) { PlaylistEntry entry; if (reverseEntries) { entry = entries.get(entries.size() - 1 - i); } else { entry = entries.get(i); } values.clear(); values.put(TomahawkSQLiteHelper.TRACKS_COLUMN_PLAYLISTID, playlist.getId()); values.put(TomahawkSQLiteHelper.TRACKS_COLUMN_TRACKNAME, entry.getQuery().getBasicTrack().getName()); values.put(TomahawkSQLiteHelper.TRACKS_COLUMN_ARTISTNAME, entry.getQuery().getBasicTrack().getArtist().getName()); values.put(TomahawkSQLiteHelper.TRACKS_COLUMN_ALBUMNAME, entry.getQuery().getBasicTrack().getAlbum().getName()); values.put(TomahawkSQLiteHelper.TRACKS_COLUMN_RESULTHINT, entry.getQuery().getTopTrackResultKey()); values.put(TomahawkSQLiteHelper.TRACKS_COLUMN_PLAYLISTENTRYINDEX, i); if (entry.getQuery().isFetchedViaHatchet()) { values.put(TomahawkSQLiteHelper.TRACKS_COLUMN_ISFETCHEDVIAHATCHET, TRUE); } else { values.put(TomahawkSQLiteHelper.TRACKS_COLUMN_ISFETCHEDVIAHATCHET, FALSE); } values.put(TomahawkSQLiteHelper.TRACKS_COLUMN_PLAYLISTENTRYID, entry.getId()); mDatabase.insert(TomahawkSQLiteHelper.TABLE_TRACKS, null, values); } mDatabase.setTransactionSuccessful(); mDatabase.endTransaction(); sendReportResultsBroadcast(playlist.getId()); } } }).start(); }
From source file:com.nicolacimmino.expensestracker.tracker.data_sync.ExpenseDataSyncAdapter.java
public void onPerformSync(Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) {/*from w w w . jav a2s .c om*/ // Get expenses that are not yet synced with the server. Cursor expenses = getContext().getContentResolver().query( ExpensesDataContentProvider.Contract.Expense.CONTENT_URI, ExpensesDataContentProvider.Contract.Expense.COLUMN_NAME_ALL, ExpensesDataContentProvider.Contract.Expense.COLUMN_NAME_SYNC + "=?", new String[] { "0" }, null); while (expenses.moveToNext()) { HttpURLConnection connection = null; try { JSONObject expense = new JSONObject(); expense.put(ExpensesApiContract.Expense.NOTES, expenses.getString(expenses .getColumnIndex(ExpensesDataContentProvider.Contract.Expense.COLUMN_NAME_DESCRIPTION))); expense.put(ExpensesApiContract.Expense.CURRENCY, expenses.getString(expenses .getColumnIndex(ExpensesDataContentProvider.Contract.Expense.COLUMN_NAME_CURRENCY))); expense.put(ExpensesApiContract.Expense.AMOUNT, expenses.getString( expenses.getColumnIndex(ExpensesDataContentProvider.Contract.Expense.COLUMN_NAME_AMOUNT))); expense.put(ExpensesApiContract.Expense.DESTINATION, expenses.getString(expenses .getColumnIndex(ExpensesDataContentProvider.Contract.Expense.COLUMN_NAME_DESTINATION))); expense.put(ExpensesApiContract.Expense.SOURCE, expenses.getString( expenses.getColumnIndex(ExpensesDataContentProvider.Contract.Expense.COLUMN_NAME_SOURCE))); expense.put(ExpensesApiContract.Expense.TIMESTAMP, expenses.getString(expenses .getColumnIndex(ExpensesDataContentProvider.Contract.Expense.COLUMN_NAME_TIMESTAMP))); expense.put(ExpensesApiContract.Expense.REPORTER_GCM_REG_ID, GcmRegistration.getRegistration_id()); ExpensesApiNewExpenseRequest request = new ExpensesApiNewExpenseRequest(expense); if (request.performRequest()) { syncResult.stats.numEntries++; ContentValues values = new ContentValues(); values.put(ExpensesDataContentProvider.Contract.Expense.COLUMN_NAME_SYNC, "1"); getContext().getContentResolver().update( ExpensesDataContentProvider.Contract.Expense.CONTENT_URI, values, ExpensesDataContentProvider.Contract.Expense.COLUMN_NAME_ID + "=?", new String[] { expenses.getString(expenses.getColumnIndex( ExpensesDataContentProvider.Contract.Expense.COLUMN_NAME_ID)) }); } else { syncResult.stats.numIoExceptions++; } } catch (JSONException e) { Log.e(TAG, "Error building json doc: " + e.toString()); syncResult.stats.numIoExceptions++; return; } finally { if (connection != null) { connection.disconnect(); } } } expenses.close(); fetchExpensesFromServer(); Log.i(TAG, "Sync done"); }
From source file:com.taxicop.sync.SyncAdapter.java
@Override public void onPerformSync(Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) {/*from w w w. jav a 2 s . c o m*/ USER = queryUser(provider); Log.i(TAG, "onPerformSync: Start"); NetworkUtilities.reset(); FROM = queryLastId(provider); Log.d(TAG, "data from= " + FROM); ArrayList<Complaint> queries = query(provider, FROM); NetworkUtilities.add(USER); for (Complaint c : queries) { NetworkUtilities.add(c.RANKING, c.CAR_PLATE, c.DESCRIPTION, c.USER, c.DATE); } Log.d(TAG, "from= " + FROM + " size del query= " + queries.size()); String response = null; if (NetworkUtilities.adapter.size() > 0) { response = ":" + NetworkUtilities.process_upload(); Log.i(TAG, "response: " + response); } else Log.i(TAG, "no data"); if (USER != null) { NetworkUtilities.reset(); NetworkUtilities.add(USER); NetworkUtilities.add(FROM); response = null; if (NetworkUtilities.adapter.size() > 0) { response = NetworkUtilities.process_download(); Log.d(TAG, "" + response); } else Log.e(TAG, "no data"); try { if (response != null) { final JSONArray cars = new JSONArray(response); provider.delete(PlateContentProvider.URI_REPORT, null, null); Log.i(TAG, "" + response); for (int i = 0; i < cars.length(); i++) { JSONObject COMPLETE = cars.getJSONObject(i); JSONObject e1 = COMPLETE.getJSONObject("fields"); float rank = (float) e1.getDouble(Fields.RANKING); String car = e1.getString(Fields.CAR_PLATE); String desc = e1.getString(Fields.DESCRIPTION); String date = e1.getString(Fields.DATE_REPORT); ContentValues in = new ContentValues(); in.put(Fields.ID_KEY, i); in.put(Fields.CAR_PLATE, car); in.put(Fields.RANKING, rank); in.put(Fields.DATE_REPORT, date); in.put(Fields.DESCRIPTION, desc); insert.add(in); } Log.d(TAG, "current ammount to insert= " + insert.size() + ", FROM=" + FROM); ContentValues upd = new ContentValues(); upd.put(Fields.ITH, insert.size()); upd.put(Fields.ID_USR, USER); provider.update(PlateContentProvider.URI_USERS, upd, "" + Fields.ID_USR + " = '" + USER + "'", null); //if(insert.size()>FROM) provider.applyBatch(insertData()); insert.clear(); } else { Log.e(TAG, "null response"); } } catch (Exception e) { Log.e(TAG, "inserting .... fucked => message: " + e.getMessage()); } } }
From source file:com.aware.ui.ESM_UI.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { // getActivity().getWindow().setType(WindowManager.LayoutParams.TYPE_PRIORITY_PHONE); // getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); // getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED); // getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON); builder = new AlertDialog.Builder(getActivity()); inflater = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE); inputManager = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); TAG = Aware.getSetting(getActivity().getApplicationContext(), Aware_Preferences.DEBUG_TAG).length() > 0 ? Aware.getSetting(getActivity().getApplicationContext(), Aware_Preferences.DEBUG_TAG) : TAG;/*from w w w . jav a 2s. co m*/ Cursor visible_esm = getActivity().getContentResolver().query(ESM_Data.CONTENT_URI, null, ESM_Data.STATUS + "=" + ESM.STATUS_NEW, null, ESM_Data.TIMESTAMP + " ASC LIMIT 1"); if (visible_esm != null && visible_esm.moveToFirst()) { esm_id = visible_esm.getInt(visible_esm.getColumnIndex(ESM_Data._ID)); //Fixed: set the esm as not new anymore, to avoid displaying the same ESM twice due to changes in orientation ContentValues update_state = new ContentValues(); update_state.put(ESM_Data.STATUS, ESM.STATUS_VISIBLE); getActivity().getContentResolver().update(ESM_Data.CONTENT_URI, update_state, ESM_Data._ID + "=" + esm_id, null); esm_type = visible_esm.getInt(visible_esm.getColumnIndex(ESM_Data.TYPE)); expires_seconds = visible_esm.getInt(visible_esm.getColumnIndex(ESM_Data.EXPIRATION_THREASHOLD)); builder.setTitle(visible_esm.getString(visible_esm.getColumnIndex(ESM_Data.TITLE))); View ui = null; switch (esm_type) { case ESM.TYPE_ESM_TEXT: ui = inflater.inflate(R.layout.esm_text, null); break; case ESM.TYPE_ESM_RADIO: ui = inflater.inflate(R.layout.esm_radio, null); break; case ESM.TYPE_ESM_CHECKBOX: ui = inflater.inflate(R.layout.esm_checkbox, null); break; case ESM.TYPE_ESM_LIKERT: ui = inflater.inflate(R.layout.esm_likert, null); break; case ESM.TYPE_ESM_QUICK_ANSWERS: ui = inflater.inflate(R.layout.esm_quick, null); break; } final View layout = ui; builder.setView(layout); current_dialog = builder.create(); sContext = current_dialog.getContext(); TextView esm_instructions = (TextView) layout.findViewById(R.id.esm_instructions); esm_instructions.setText(visible_esm.getString(visible_esm.getColumnIndex(ESM_Data.INSTRUCTIONS))); switch (esm_type) { case ESM.TYPE_ESM_TEXT: final EditText feedback = (EditText) layout.findViewById(R.id.esm_feedback); Button cancel_text = (Button) layout.findViewById(R.id.esm_cancel); cancel_text.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { inputManager.hideSoftInputFromWindow(feedback.getWindowToken(), 0); current_dialog.cancel(); } }); Button submit_text = (Button) layout.findViewById(R.id.esm_submit); submit_text.setText(visible_esm.getString(visible_esm.getColumnIndex(ESM_Data.SUBMIT))); submit_text.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { inputManager.hideSoftInputFromWindow(feedback.getWindowToken(), 0); if (expires_seconds > 0 && expire_monitor != null) expire_monitor.cancel(true); ContentValues rowData = new ContentValues(); rowData.put(ESM_Data.ANSWER_TIMESTAMP, System.currentTimeMillis()); rowData.put(ESM_Data.ANSWER, feedback.getText().toString()); rowData.put(ESM_Data.STATUS, ESM.STATUS_ANSWERED); sContext.getContentResolver().update(ESM_Data.CONTENT_URI, rowData, ESM_Data._ID + "=" + esm_id, null); Intent answer = new Intent(ESM.ACTION_AWARE_ESM_ANSWERED); getActivity().sendBroadcast(answer); if (Aware.DEBUG) Log.d(TAG, "Answer:" + rowData.toString()); current_dialog.dismiss(); } }); break; case ESM.TYPE_ESM_RADIO: try { final RadioGroup radioOptions = (RadioGroup) layout.findViewById(R.id.esm_radio); final JSONArray radios = new JSONArray( visible_esm.getString(visible_esm.getColumnIndex(ESM_Data.RADIOS))); for (int i = 0; i < radios.length(); i++) { final RadioButton radioOption = new RadioButton(getActivity()); radioOption.setId(i); radioOption.setText(radios.getString(i)); radioOptions.addView(radioOption); if (radios.getString(i).equals("Other")) { radioOption.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { final Dialog editOther = new Dialog(getActivity()); editOther.setTitle("Can you be more specific, please?"); editOther.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT); editOther.getWindow().setGravity(Gravity.TOP); editOther.getWindow().setLayout(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); LinearLayout editor = new LinearLayout(getActivity()); editor.setOrientation(LinearLayout.VERTICAL); editOther.setContentView(editor); editOther.show(); final EditText otherText = new EditText(getActivity()); editor.addView(otherText); Button confirm = new Button(getActivity()); confirm.setText("OK"); confirm.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (otherText.length() > 0) radioOption.setText(otherText.getText()); inputManager.hideSoftInputFromWindow(otherText.getWindowToken(), 0); editOther.dismiss(); } }); editor.addView(confirm); } }); } } Button cancel_radio = (Button) layout.findViewById(R.id.esm_cancel); cancel_radio.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { current_dialog.cancel(); } }); Button submit_radio = (Button) layout.findViewById(R.id.esm_submit); submit_radio.setText(visible_esm.getString(visible_esm.getColumnIndex(ESM_Data.SUBMIT))); submit_radio.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (expires_seconds > 0 && expire_monitor != null) expire_monitor.cancel(true); ContentValues rowData = new ContentValues(); rowData.put(ESM_Data.ANSWER_TIMESTAMP, System.currentTimeMillis()); RadioGroup radioOptions = (RadioGroup) layout.findViewById(R.id.esm_radio); if (radioOptions.getCheckedRadioButtonId() != -1) { RadioButton selected = (RadioButton) radioOptions .getChildAt(radioOptions.getCheckedRadioButtonId()); rowData.put(ESM_Data.ANSWER, selected.getText().toString()); } rowData.put(ESM_Data.STATUS, ESM.STATUS_ANSWERED); sContext.getContentResolver().update(ESM_Data.CONTENT_URI, rowData, ESM_Data._ID + "=" + esm_id, null); Intent answer = new Intent(ESM.ACTION_AWARE_ESM_ANSWERED); getActivity().sendBroadcast(answer); if (Aware.DEBUG) Log.d(TAG, "Answer:" + rowData.toString()); current_dialog.dismiss(); } }); } catch (JSONException e) { e.printStackTrace(); } break; case ESM.TYPE_ESM_CHECKBOX: try { final LinearLayout checkboxes = (LinearLayout) layout.findViewById(R.id.esm_checkboxes); final JSONArray checks = new JSONArray( visible_esm.getString(visible_esm.getColumnIndex(ESM_Data.CHECKBOXES))); for (int i = 0; i < checks.length(); i++) { final CheckBox checked = new CheckBox(getActivity()); checked.setText(checks.getString(i)); checked.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(final CompoundButton buttonView, boolean isChecked) { if (isChecked) { if (buttonView.getText().equals("Other")) { checked.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { final Dialog editOther = new Dialog(getActivity()); editOther.setTitle("Can you be more specific, please?"); editOther.getWindow() .setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT); editOther.getWindow().setGravity(Gravity.TOP); editOther.getWindow().setLayout(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); LinearLayout editor = new LinearLayout(getActivity()); editor.setOrientation(LinearLayout.VERTICAL); editOther.setContentView(editor); editOther.show(); final EditText otherText = new EditText(getActivity()); editor.addView(otherText); Button confirm = new Button(getActivity()); confirm.setText("OK"); confirm.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (otherText.length() > 0) { inputManager.hideSoftInputFromWindow( otherText.getWindowToken(), 0); selected_options .remove(buttonView.getText().toString()); checked.setText(otherText.getText()); selected_options.add(otherText.getText().toString()); } editOther.dismiss(); } }); editor.addView(confirm); } }); } else { selected_options.add(buttonView.getText().toString()); } } else { selected_options.remove(buttonView.getText().toString()); } } }); checkboxes.addView(checked); } Button cancel_checkbox = (Button) layout.findViewById(R.id.esm_cancel); cancel_checkbox.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { current_dialog.cancel(); } }); Button submit_checkbox = (Button) layout.findViewById(R.id.esm_submit); submit_checkbox.setText(visible_esm.getString(visible_esm.getColumnIndex(ESM_Data.SUBMIT))); submit_checkbox.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (expires_seconds > 0 && expire_monitor != null) expire_monitor.cancel(true); ContentValues rowData = new ContentValues(); rowData.put(ESM_Data.ANSWER_TIMESTAMP, System.currentTimeMillis()); if (selected_options.size() > 0) { rowData.put(ESM_Data.ANSWER, selected_options.toString()); } rowData.put(ESM_Data.STATUS, ESM.STATUS_ANSWERED); sContext.getContentResolver().update(ESM_Data.CONTENT_URI, rowData, ESM_Data._ID + "=" + esm_id, null); Intent answer = new Intent(ESM.ACTION_AWARE_ESM_ANSWERED); getActivity().sendBroadcast(answer); if (Aware.DEBUG) Log.d(TAG, "Answer:" + rowData.toString()); current_dialog.dismiss(); } }); } catch (JSONException e) { e.printStackTrace(); } break; case ESM.TYPE_ESM_LIKERT: final RatingBar ratingBar = (RatingBar) layout.findViewById(R.id.esm_likert); ratingBar.setMax(visible_esm.getInt(visible_esm.getColumnIndex(ESM_Data.LIKERT_MAX))); ratingBar.setStepSize( (float) visible_esm.getDouble(visible_esm.getColumnIndex(ESM_Data.LIKERT_STEP))); ratingBar.setNumStars(visible_esm.getInt(visible_esm.getColumnIndex(ESM_Data.LIKERT_MAX))); TextView min_label = (TextView) layout.findViewById(R.id.esm_min); min_label.setText(visible_esm.getString(visible_esm.getColumnIndex(ESM_Data.LIKERT_MIN_LABEL))); TextView max_label = (TextView) layout.findViewById(R.id.esm_max); max_label.setText(visible_esm.getString(visible_esm.getColumnIndex(ESM_Data.LIKERT_MAX_LABEL))); Button cancel = (Button) layout.findViewById(R.id.esm_cancel); cancel.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { current_dialog.cancel(); } }); Button submit = (Button) layout.findViewById(R.id.esm_submit); submit.setText(visible_esm.getString(visible_esm.getColumnIndex(ESM_Data.SUBMIT))); submit.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (expires_seconds > 0 && expire_monitor != null) expire_monitor.cancel(true); ContentValues rowData = new ContentValues(); rowData.put(ESM_Data.ANSWER_TIMESTAMP, System.currentTimeMillis()); rowData.put(ESM_Data.ANSWER, ratingBar.getRating()); rowData.put(ESM_Data.STATUS, ESM.STATUS_ANSWERED); sContext.getContentResolver().update(ESM_Data.CONTENT_URI, rowData, ESM_Data._ID + "=" + esm_id, null); Intent answer = new Intent(ESM.ACTION_AWARE_ESM_ANSWERED); getActivity().sendBroadcast(answer); if (Aware.DEBUG) Log.d(TAG, "Answer:" + rowData.toString()); current_dialog.dismiss(); } }); break; case ESM.TYPE_ESM_QUICK_ANSWERS: try { final JSONArray answers = new JSONArray( visible_esm.getString(visible_esm.getColumnIndex(ESM_Data.QUICK_ANSWERS))); final LinearLayout answersHolder = (LinearLayout) layout.findViewById(R.id.esm_answers); //If we have more than 3 possibilities, better that the UI is vertical for UX if (answers.length() > 3) { answersHolder.setOrientation(LinearLayout.VERTICAL); } for (int i = 0; i < answers.length(); i++) { final Button answer = new Button(getActivity()); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, 1.0f); answer.setLayoutParams(params); answer.setText(answers.getString(i)); answer.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (expires_seconds > 0 && expire_monitor != null) expire_monitor.cancel(true); ContentValues rowData = new ContentValues(); rowData.put(ESM_Data.ANSWER_TIMESTAMP, System.currentTimeMillis()); rowData.put(ESM_Data.STATUS, ESM.STATUS_ANSWERED); rowData.put(ESM_Data.ANSWER, (String) answer.getText()); sContext.getContentResolver().update(ESM_Data.CONTENT_URI, rowData, ESM_Data._ID + "=" + esm_id, null); Intent answer = new Intent(ESM.ACTION_AWARE_ESM_ANSWERED); getActivity().sendBroadcast(answer); if (Aware.DEBUG) Log.d(TAG, "Answer:" + rowData.toString()); current_dialog.dismiss(); } }); answersHolder.addView(answer); } } catch (JSONException e) { e.printStackTrace(); } break; } } if (visible_esm != null && !visible_esm.isClosed()) visible_esm.close(); //Start dialog visibility threshold if (expires_seconds > 0) { expire_monitor = new ESMExpireMonitor(System.currentTimeMillis(), expires_seconds, esm_id); expire_monitor.execute(); } //Fixed: doesn't dismiss the dialog if touched outside or ghost touches current_dialog.setCanceledOnTouchOutside(false); return current_dialog; }
From source file:cn.code.notes.gtask.data.SqlNote.java
public SqlNote(Context context, Cursor c) { mContext = context;/* ww w .j a v a 2s. c o m*/ mContentResolver = context.getContentResolver(); mIsCreate = false; loadFromCursor(c); mDataList = new ArrayList<SqlData>(); if (mType == Notes.TYPE_NOTE) loadDataContent(); mDiffNoteValues = new ContentValues(); }
From source file:com.procasy.dubarah_nocker.gcm.MyGcmPushReceiver.java
/** * Called when message is received.//ww w .j a va 2 s . co m * * @param from SenderID of the sender. * @param bundle Data bundle containing message data as key/value pairs. * For Set of keys use data.keySet(). */ @Override public void onMessageReceived(String from, Bundle bundle) { MainActivity.getInstance().updateNotification(); try { Log.e("notify_gcm", "success , type = " + bundle.toString()); switch (bundle.getString(GCM_TAG)) { case "GENERAL": { NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.hourly_logo).setContentTitle(bundle.getString(TITLE_TAG)) .setContentText(bundle.getString(DESC_TAG)); Intent resultIntent = new Intent(this, MainActivity.class); TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addParentStack(MainActivity.class); stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); mBuilder.setDefaults( Notification.DEFAULT_SOUND | Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE); NotificationManager mNotificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); mNotificationManager.notify(12, mBuilder.build()); mNotification = new com.procasy.dubarah_nocker.Helper.Notification(getApplicationContext()); mNotification.open(); try { ContentValues contentValues = new ContentValues(); contentValues.put(mNotification.COL_notification_type, GENERAL_TAG); contentValues.put(mNotification.COL_notfication_status, 0); contentValues.put(mNotification.COL_notfication_title, bundle.getString(TITLE_TAG)); contentValues.put(mNotification.COL_notfication_desc, bundle.getString(DESC_TAG)); contentValues.put(mNotification.COL_notfication_content, bundle.getString(CONTENT_TAG)); mNotification.insertEntry(contentValues); } catch (Exception e) { e.printStackTrace(); } finally { mNotification.close(); } break; } case "HELP": { NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.hourly_logo).setContentTitle(bundle.getString(TITLE_TAG)) .setContentText(bundle.getString(DESC_TAG)); Intent resultIntent = new Intent(this, MainActivity.class); TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addParentStack(MainActivity.class); stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); mBuilder.setDefaults( Notification.DEFAULT_SOUND | Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE); NotificationManager mNotificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); mNotificationManager.notify(12, mBuilder.build()); mNotification = new com.procasy.dubarah_nocker.Helper.Notification(getApplicationContext()); mNotification.open(); try { ContentValues contentValues = new ContentValues(); contentValues.put(mNotification.COL_notification_type, HELP_TAG); contentValues.put(mNotification.COL_notfication_status, 0); contentValues.put(mNotification.COL_notfication_title, bundle.getString(TITLE_TAG)); contentValues.put(mNotification.COL_notfication_desc, bundle.getString(DESC_TAG)); contentValues.put(mNotification.COL_notfication_content, bundle.getString(CONTENT_TAG)); mNotification.insertEntry(contentValues); } catch (Exception e) { e.printStackTrace(); } finally { mNotification.close(); } JSONObject content = new JSONObject(bundle.getString("content")); JSONObject hr = content.getJSONObject("hr"); JSONArray album = content.getJSONArray("album"); System.out.println(content.getInt("hr_id")); System.out.println(content.toString()); Bundle bundle1 = new Bundle(); bundle1.putString("hr_id", hr.getString("hr_id")); bundle1.putString("hr_user_id", hr.getString("hr_user_id")); bundle1.putString("hr_description", hr.getString("hr_description")); bundle1.putString("hr_est_date", hr.getString("hr_est_date")); bundle1.putString("hr_est_time", hr.getString("hr_est_time")); bundle1.putString("hr_skill_id", hr.getString("hr_skill_id")); bundle1.putString("hr_ua_id", hr.getString("hr_ua_id")); bundle1.putString("hr_voice_record", hr.getString("hr_voice_record")); bundle1.putString("hr_language", hr.getString("hr_language")); bundle1.putString("hr_lat", hr.getString("hr_lat")); bundle1.putString("hr_lon", hr.getString("hr_lon")); bundle1.putString("hr_address", hr.getString("hr_address")); ArrayList<String> array = new ArrayList<>(); for (int i = 0; i < album.length(); i++) { JSONObject object = album.getJSONObject(i); array.add(object.getString("ahr_img")); } bundle1.putStringArrayList("album", array); Intent intent = (new Intent(getApplicationContext(), JobRequestActivity.class)); intent.putExtras(bundle1); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); getApplicationContext().startActivity(intent); break; } case "APPOINTEMENT": { NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.hourly_logo).setContentTitle(bundle.getString(TITLE_TAG)) .setContentText(bundle.getString(DESC_TAG)); Intent resultIntent = new Intent(this, MainActivity.class); TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addParentStack(MainActivity.class); stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); mBuilder.setDefaults( Notification.DEFAULT_SOUND | Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE); NotificationManager mNotificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); mNotificationManager.notify(12, mBuilder.build()); mNotification = new com.procasy.dubarah_nocker.Helper.Notification(getApplicationContext()); mNotification.open(); try { ContentValues contentValues = new ContentValues(); contentValues.put(mNotification.COL_notification_type, APPOINTEMENT_TAG); contentValues.put(mNotification.COL_notfication_status, 0); contentValues.put(mNotification.COL_notfication_title, bundle.getString(TITLE_TAG)); contentValues.put(mNotification.COL_notfication_desc, bundle.getString(DESC_TAG)); contentValues.put(mNotification.COL_notfication_content, bundle.getString(CONTENT_TAG)); mNotification.insertEntry(contentValues); } catch (Exception e) { e.printStackTrace(); } finally { mNotification.close(); } break; } case "QOUTA_USER": { NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.hourly_logo).setContentTitle(bundle.getString(TITLE_TAG)) .setContentText(bundle.getString(DESC_TAG)); Intent resultIntent = new Intent(this, MainActivity.class); TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addParentStack(MainActivity.class); stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); mBuilder.setDefaults( Notification.DEFAULT_SOUND | Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE); NotificationManager mNotificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); mNotificationManager.notify(12, mBuilder.build()); mNotification = new com.procasy.dubarah_nocker.Helper.Notification(getApplicationContext()); mNotification.open(); try { ContentValues contentValues = new ContentValues(); contentValues.put(mNotification.COL_notification_type, USER_Qouta_TAG); contentValues.put(mNotification.COL_notfication_status, 0); contentValues.put(mNotification.COL_notfication_title, bundle.getString(TITLE_TAG)); contentValues.put(mNotification.COL_notfication_desc, bundle.getString(DESC_TAG)); contentValues.put(mNotification.COL_notfication_content, bundle.getString(CONTENT_TAG)); mNotification.insertEntry(contentValues); } catch (Exception e) { e.printStackTrace(); } finally { mNotification.close(); } break; } case "QOUTA_NOCKER": { NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.hourly_logo).setContentTitle(bundle.getString(TITLE_TAG)) .setContentText(bundle.getString(DESC_TAG)); Intent resultIntent = new Intent(this, MainActivity.class); TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addParentStack(MainActivity.class); stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); mBuilder.setDefaults( Notification.DEFAULT_SOUND | Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE); NotificationManager mNotificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); mNotificationManager.notify(12, mBuilder.build()); mNotification = new com.procasy.dubarah_nocker.Helper.Notification(getApplicationContext()); mNotification.open(); try { ContentValues contentValues = new ContentValues(); contentValues.put(mNotification.COL_notification_type, Nocker_Qouta_TAG); contentValues.put(mNotification.COL_notfication_status, 0); contentValues.put(mNotification.COL_notfication_title, bundle.getString(TITLE_TAG)); contentValues.put(mNotification.COL_notfication_desc, bundle.getString(DESC_TAG)); contentValues.put(mNotification.COL_notfication_content, bundle.getString(CONTENT_TAG)); mNotification.insertEntry(contentValues); } catch (Exception e) { e.printStackTrace(); } finally { mNotification.close(); } break; } } } catch (Exception e) { e.printStackTrace(); } }
From source file:com.samknows.measurement.storage.TestResultDataSource.java
public void insert(String type_name, long dtime, long success, double result, String location, long test_batch_id) { ContentValues values = new ContentValues(); values.put(SKSQLiteHelper.TR_COLUMN_DTIME, dtime); values.put(SKSQLiteHelper.TR_COLUMN_TYPE, type_name); values.put(SKSQLiteHelper.TR_COLUMN_LOCATION, location); values.put(SKSQLiteHelper.TR_COLUMN_SUCCESS, success); values.put(SKSQLiteHelper.TR_COLUMN_RESULT, result); values.put(SKSQLiteHelper.TR_COLUMN_BATCH_ID, test_batch_id); database.insert(SKSQLiteHelper.TABLE_TESTRESULT, null, values); }
From source file:net.kourlas.voipms_sms.Database.java
/** * Adds a message to the database. If a record with the message's database ID or VoIP.ms ID already exists, that * record is replaced. Otherwise, a new record is created. * * @param message The message to be added to the database. * @return The database ID of the newly added message. *//*from ww w .ja v a 2 s . c o m*/ public synchronized long insertMessage(Message message) { ContentValues values = new ContentValues(); if (message.getDatabaseId() != null) { values.put(COLUMN_DATABASE_ID, message.getDatabaseId()); } else if (message.getVoipId() != null) { Long databaseId = getDatabaseIdForVoipId(message.getDid(), message.getVoipId()); if (databaseId != null) { values.put(COLUMN_DATABASE_ID, databaseId); } } values.put(COLUMN_VOIP_ID, message.getVoipId()); values.put(COLUMN_DATE, message.getDateInDatabaseFormat()); values.put(COLUMN_TYPE, message.getTypeInDatabaseFormat()); values.put(COLUMN_DID, message.getDid()); values.put(COLUMN_CONTACT, message.getContact()); values.put(COLUMN_MESSAGE, message.getText()); values.put(COLUMN_UNREAD, message.isUnreadInDatabaseFormat()); values.put(COLUMN_DELETED, message.isDeletedInDatabaseFormat()); values.put(COLUMN_DELIVERED, message.isDeliveredInDatabaseFormat()); values.put(COLUMN_DELIVERY_IN_PROGRESS, message.isDeliveryInProgressInDatabaseFormat()); if (values.getAsLong(COLUMN_DATABASE_ID) != null) { return database.replace(TABLE_MESSAGE, null, values); } else { return database.insert(TABLE_MESSAGE, null, values); } }
From source file:com.zapto.park.ParkActivity.java
public void employeeCheck(String idValue, boolean checkType) { EmployeeDB edb = new EmployeeDB(context); Date date = new Date(); //String timeStamp = Util.dateTimestamp(date); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Calendar c = Calendar.getInstance(); c.setTime(date);/* w w w .ja v a2s.c om*/ String timeStamp = sdf.format(c.getTime()); int id = 0; try { id = new Integer(idValue); } catch (Exception e) { return; } /* String dir = Environment.getExternalStorageDirectory()+"/.id/"+idValue; boolean success = new File(dir).mkdirs(); String filename; filename = timeStamp.replace(':', 'p'); File oldname= new File(Environment.getExternalStorageDirectory(), "photo.jpg"); File newname = new File(dir, idValue.concat("_").concat(filename+".jpg")); oldname.renameTo(newname); */ Log.i("TIME", timeStamp); String checkStatus = ""; String employee_name = ""; int sent = 0; ContentValues cv = new ContentValues(); cv.put("totable_license", Globals.LICENSE_KEY); cv.put("totable_id", idValue); cv.put("totable_date", timeStamp); cv.put("totable_inout", checkType == true ? "1" : "1"); // Send request. try { //String response = SendPost.sendPostRequest("app/clockuser.php", cv); employee_name = edb.getName(id); checkStatus = ""; //if (response.equals("1")) { //sent = 1; checkStatus = "Punch Successful"; Sound.play(R.raw.success); if (employee_name.length() > 0) { checkStatus += ": " + employee_name; } /*} else if (response.equals("0")) { // Request failed. sent = 0; Sound.play(R.raw.fail); checkStatus = "No ID exists."; */ if (edb.hasEmployee(id)) { checkStatus = "ID saved. Punch Successful"; Sound.play(R.raw.success); if (employee_name.length() > 0) { checkStatus += ": " + employee_name; } } else { // This is currently not a valid ID. Sound.play(R.raw.fail); checkStatus = "ID saved. Please Update List."; } Log.i(LOG_TAG, "Response: try done"); } catch (Exception e) { // Unable to send request. Log.i(LOG_TAG, "Error clocking request."); sent = 0; // Is the employee is currently in the database. We're good. } // Log request in database. ContentValues cv2 = new ContentValues(); cv2.put("license", Globals.LICENSE_KEY); cv2.put("employee_id", idValue); cv2.put("date", timeStamp); cv2.put("inout", checkType == true ? "1" : "1"); cv2.put("sent", "" + sent); // Query database. edb.clockEmployee(cv2); // Close our database. edb.close(); Toast.makeText(cActivity, checkStatus, Toast.LENGTH_LONG).show(); }
From source file:com.getmarco.weatherstationviewer.gcm.StationGcmListenerService.java
/** * Called when message is received.// w ww . java2 s . com * * @param from SenderID of the sender. * @param data Data bundle containing message data as key/value pairs. * For Set of keys use data.keySet(). */ // [START receive_message] @Override public void onMessageReceived(String from, Bundle data) { String message = data.getString("message"); Log.d(LOG_TAG, "From: " + from); Log.d(LOG_TAG, "Message: " + message); SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); boolean enableTempNotifications = sharedPreferences .getBoolean(getString(R.string.pref_enable_temp_notifications_key), Boolean.parseBoolean("true")); boolean enableHumidityNotifications = sharedPreferences.getBoolean( getString(R.string.pref_enable_humidity_notifications_key), Boolean.parseBoolean("true")); boolean notifyUser = false; String tag = null; double temp = 0; double humidity = 0; double latitude = 0; double longitude = 0; String dateString = null; StringBuilder msg = new StringBuilder(); try { JSONObject json = new JSONObject(message); if (!json.isNull(STATION_TAG)) { tag = json.getString(STATION_TAG); msg.append(tag); } else throw new IllegalArgumentException("station tag is required"); if (!json.isNull(CONDITION_DATE)) dateString = json.getString(CONDITION_DATE); else throw new IllegalArgumentException("date is required"); if (msg.length() > 0) msg.append(" -"); if (!json.isNull(CONDITION_TEMP)) { notifyUser |= enableTempNotifications; temp = json.getDouble(CONDITION_TEMP); msg.append(" temp: " + getString(R.string.format_temperature, temp)); } if (!json.isNull(CONDITION_HUMIDITY)) { notifyUser |= enableHumidityNotifications; humidity = json.getDouble(CONDITION_HUMIDITY); msg.append(" humidity: " + getString(R.string.format_humidity, humidity)); } if (!json.isNull(CONDITION_LAT)) { latitude = json.getDouble(CONDITION_LAT); } if (!json.isNull(CONDITION_LONG)) { longitude = json.getDouble(CONDITION_LONG); } } catch (JSONException e) { Log.e(LOG_TAG, "error parsing GCM message JSON", e); } long stationId = addStation(tag); Date date = Utility.parseDateDb(dateString); ContentValues conditionValues = new ContentValues(); conditionValues.put(StationContract.ConditionEntry.COLUMN_STATION_KEY, stationId); conditionValues.put(StationContract.ConditionEntry.COLUMN_TEMP, temp); conditionValues.put(StationContract.ConditionEntry.COLUMN_HUMIDITY, humidity); conditionValues.put(StationContract.ConditionEntry.COLUMN_LATITUDE, latitude); conditionValues.put(StationContract.ConditionEntry.COLUMN_LONGITUDE, longitude); conditionValues.put(StationContract.ConditionEntry.COLUMN_DATE, date != null ? date.getTime() : 0); getContentResolver().insert(StationContract.ConditionEntry.CONTENT_URI, conditionValues); /** * show a notification indicating to the user that a message was received. */ if (notifyUser) sendNotification(msg.toString()); }