Example usage for android.content ContentValues toString

List of usage examples for android.content ContentValues toString

Introduction

In this page you can find the example usage for android.content ContentValues toString.

Prototype

@Override
public String toString() 

Source Link

Document

Returns a string containing a concise, human-readable description of this object.

Usage

From source file:com.money.manager.ex.MmxContentProvider.java

private void logUpdate(Dataset dataset, ContentValues values, String whereClause, String[] whereArgs) {
    String log = "UPDATE " + dataset.getSource();
    // compose log verbose
    if (values != null) {
        log += " SET " + values.toString();
    }/*from  w w w.  j  av  a 2s . c  o  m*/
    if (!TextUtils.isEmpty(whereClause)) {
        log += " WHERE " + whereClause;
    }
    if (whereArgs != null) {
        log += "; ARGS=" + Arrays.asList(whereArgs).toString();
    }

    // open transaction
    //database.beginTransaction();
    //        if (BuildConfig.DEBUG) Log.d(LOGCAT, "database begin transaction");

    Timber.d(log);
}

From source file:org.hfoss.posit.android.sync.Communicator.java

/**
 * //  w w  w .ja  v  a  2  s.  co  m
 * Retrieve finds from the server using a Communicator.
 * 
 * @param serverGuids
 * @return
 */
public static boolean getFindsFromServer(Context context, String authKey, String serverGuids) {
    String guid;
    int rows = 0;
    StringTokenizer st = new StringTokenizer(serverGuids, ",");

    while (st.hasMoreElements()) {
        guid = st.nextElement().toString();
        ContentValues cv = getRemoteFindById(context, authKey, guid);

        if (cv == null) {
            return false; // Shouldn't be null--we know its ID
        } else {
            Log.i(TAG, cv.toString());
            try {

                // Find out what Find class POSIT is configured for
                Class<? extends Find> findClass = FindPluginManager.mFindPlugin.getmFindClass();

                Log.i(TAG, "Find class = " + findClass.getSimpleName());

                // Update the DB
                Find find = DbHelper.getDbManager(context).getFindByGuid(guid);
                if (find != null) {
                    Log.i(TAG, "Updating existing find: " + find.getId());
                    Find updatedFind = findClass.newInstance();
                    updatedFind.updateObject(cv);

                    //                  Find updatedFind = (OutsideInFind)find;
                    //                  ((OutsideInFind) updatedFind).updateObject(cv);
                    updatedFind.setId(find.getId());
                    rows = DbHelper.getDbManager(context).updateWithoutHistory(updatedFind);
                } else {
                    //   find = new OutsideInFind();
                    find = findClass.newInstance();
                    Log.i(TAG, "Inserting new find: " + find.getId());
                    find.updateObject(cv);
                    //                  ((OutsideInFind) find).updateObject(cv);
                    Log.i(TAG, "Adding a new find " + find);
                    rows = DbHelper.getDbManager(context).insertWithoutHistory(find);
                }
            } catch (IllegalAccessException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (InstantiationException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }
    DbHelper.releaseDbManager();
    return rows > 0;
}

From source file:com.money.manager.ex.database.MmxOpenHelper.java

private void initCategories(SQLiteDatabase database) {
    try {/*from  w w  w. ja v  a2 s.  c  o m*/
        Cursor countCategories = database.rawQuery("SELECT * FROM CATEGORY_V1", null);
        if (countCategories == null || countCategories.getCount() > 0)
            return;

        int keyCategory = 0;
        String[] categories = new String[] { "1;1", "2;1", "3;1", "4;1", "5;1", "6;1", "7;1", "8;2", "9;2",
                "10;3", "11;3", "12;3", "13;4", "14;4", "15;4", "16;4", "17;5", "18;5", "19;5", "20;6", "21;6",
                "22;6", "23;7", "24;7", "25;7", "26;7", "27;7", "28;8", "29;8", "30;8", "31;8", "32;9", "33;9",
                "34;9", "35;10", "36;10", "37;10", "38;10", "39;13", "40;13", "41;13" };

        for (String item : categories) {
            int subCategoryId = Integer.parseInt(item.substring(0, item.indexOf(";")));
            int categoryId = Integer.parseInt(item.substring(item.indexOf(";") + 1));

            if (categoryId != keyCategory) {
                keyCategory = categoryId;
                int idStringCategory = mContext.getResources().getIdentifier(
                        "category_" + Integer.toString(categoryId), "string", mContext.getPackageName());

                if (idStringCategory > 0) {
                    ContentValues contentValues = new ContentValues();
                    contentValues.put(Category.CATEGID, categoryId);
                    contentValues.put(Category.CATEGNAME, mContext.getString(idStringCategory));

                    // Update existing records, inserted via the db creation script.
                    int updated = database.update(CategoryRepository.tableName, contentValues,
                            Category.CATEGID + "=?", new String[] { Integer.toString(categoryId) });
                    if (updated <= 0) {
                        Timber.w("updating %s for category %s", contentValues.toString(),
                                Integer.toString(categoryId));
                    }
                }
            }

            int idStringSubcategory = mContext.getResources().getIdentifier(
                    "subcategory_" + Integer.toString(subCategoryId), "string", mContext.getPackageName());
            if (idStringSubcategory > 0) {
                ContentValues contentValues = new ContentValues();
                contentValues.put(Subcategory.SUBCATEGID, subCategoryId);
                contentValues.put(Subcategory.CATEGID, categoryId);
                contentValues.put(Subcategory.SUBCATEGNAME, mContext.getString(idStringSubcategory));

                int updated = database.update(SubcategoryRepository.tableName, contentValues,
                        Subcategory.SUBCATEGID + "=?", new String[] { Integer.toString(subCategoryId) });
                if (updated <= 0) {
                    Timber.w("update failed, %s for subcategory %s", contentValues.toString(),
                            Integer.toString(subCategoryId));
                }
            }
        }

        countCategories.close();
    } catch (Exception e) {
        Timber.e(e, "init database, categories");
    }
}

From source file:at.bitfire.davdroid.mirakel.resource.LocalCalendar.java

@SuppressLint("InlinedApi")
public static void create(Account account, ContentResolver resolver, ServerInfo.ResourceInfo info)
        throws LocalStorageException {
    ContentProviderClient client = resolver.acquireContentProviderClient(CalendarContract.AUTHORITY);
    if (client == null)
        throw new LocalStorageException("No Calendar Provider found (Calendar app disabled?)");

    int color = 0xFFC3EA6E; // fallback: "DAVdroid green"
    if (info.getColor() != null) {
        Pattern p = Pattern.compile("#(\\p{XDigit}{6})(\\p{XDigit}{2})?");
        Matcher m = p.matcher(info.getColor());
        if (m.find()) {
            int color_rgb = Integer.parseInt(m.group(1), 16);
            int color_alpha = m.group(2) != null ? (Integer.parseInt(m.group(2), 16) & 0xFF) : 0xFF;
            color = (color_alpha << 24) | color_rgb;
        }/*from w  ww. j  a va 2  s. co  m*/
    }

    ContentValues values = new ContentValues();
    values.put(Calendars.ACCOUNT_NAME, account.name);
    values.put(Calendars.ACCOUNT_TYPE, account.type);
    values.put(Calendars.NAME, info.getURL());
    values.put(Calendars.CALENDAR_DISPLAY_NAME, info.getTitle());
    values.put(Calendars.CALENDAR_COLOR, color);
    values.put(Calendars.OWNER_ACCOUNT, account.name);
    values.put(Calendars.SYNC_EVENTS, 1);
    values.put(Calendars.VISIBLE, 1);
    values.put(Calendars.ALLOWED_REMINDERS, Reminders.METHOD_ALERT);

    if (info.isReadOnly())
        values.put(Calendars.CALENDAR_ACCESS_LEVEL, Calendars.CAL_ACCESS_READ);
    else {
        values.put(Calendars.CALENDAR_ACCESS_LEVEL, Calendars.CAL_ACCESS_OWNER);
        values.put(Calendars.CAN_ORGANIZER_RESPOND, 1);
        values.put(Calendars.CAN_MODIFY_TIME_ZONE, 1);
    }

    if (android.os.Build.VERSION.SDK_INT >= 15) {
        values.put(Calendars.ALLOWED_AVAILABILITY, Events.AVAILABILITY_BUSY + "," + Events.AVAILABILITY_FREE
                + "," + Events.AVAILABILITY_TENTATIVE);
        values.put(Calendars.ALLOWED_ATTENDEE_TYPES, Attendees.TYPE_NONE + "," + Attendees.TYPE_OPTIONAL + ","
                + Attendees.TYPE_REQUIRED + "," + Attendees.TYPE_RESOURCE);
    }

    if (info.getTimezone() != null)
        values.put(Calendars.CALENDAR_TIME_ZONE, info.getTimezone());

    Log.i(TAG, "Inserting calendar: " + values.toString() + " -> " + calendarsURI(account).toString());
    try {
        client.insert(calendarsURI(account), values);
    } catch (RemoteException e) {
        throw new LocalStorageException(e);
    }
}

From source file:com.granita.icloudcalsync.resource.LocalCalendar.java

@SuppressLint("InlinedApi")
public static Uri create(Account account, ContentResolver resolver, ServerInfo.ResourceInfo info)
        throws LocalStorageException {
    final ContentProviderClient client = resolver.acquireContentProviderClient(CalendarContract.AUTHORITY);
    if (client == null)
        throw new LocalStorageException("No Calendar Provider found (Calendar app disabled?)");

    ContentValues values = new ContentValues();
    values.put(Calendars.ACCOUNT_NAME, account.name);
    values.put(Calendars.ACCOUNT_TYPE, account.type);
    values.put(Calendars.NAME, info.getURL());
    values.put(Calendars.CALENDAR_DISPLAY_NAME, info.getTitle());
    values.put(Calendars.CALENDAR_COLOR, DAVUtils.CalDAVtoARGBColor(info.getColor()));
    values.put(Calendars.OWNER_ACCOUNT, account.name);
    values.put(Calendars.SYNC_EVENTS, 1);
    values.put(Calendars.VISIBLE, 1);//from  ww w  .  ja v  a2  s . c om
    values.put(Calendars.ALLOWED_REMINDERS, Reminders.METHOD_ALERT);

    if (info.isReadOnly())
        values.put(Calendars.CALENDAR_ACCESS_LEVEL, Calendars.CAL_ACCESS_READ);
    else {
        values.put(Calendars.CALENDAR_ACCESS_LEVEL, Calendars.CAL_ACCESS_OWNER);
        values.put(Calendars.CAN_ORGANIZER_RESPOND, 1);
        values.put(Calendars.CAN_MODIFY_TIME_ZONE, 1);
    }

    if (android.os.Build.VERSION.SDK_INT >= 15) {
        values.put(Calendars.ALLOWED_AVAILABILITY, Events.AVAILABILITY_BUSY + "," + Events.AVAILABILITY_FREE
                + "," + Events.AVAILABILITY_TENTATIVE);
        values.put(Calendars.ALLOWED_ATTENDEE_TYPES, Attendees.TYPE_NONE + "," + Attendees.TYPE_OPTIONAL + ","
                + Attendees.TYPE_REQUIRED + "," + Attendees.TYPE_RESOURCE);
    }

    if (info.getTimezone() != null)
        values.put(Calendars.CALENDAR_TIME_ZONE, info.getTimezone());

    Log.i(TAG, "Inserting calendar: " + values.toString());
    try {
        return client.insert(calendarsURI(account), values);
    } catch (RemoteException e) {
        throw new LocalStorageException(e);
    }
}

From source file:at.bitfire.davdroid.resource.LocalCalendar.java

@SuppressLint("InlinedApi")
public static Uri create(Account account, ContentResolver resolver, ServerInfo.ResourceInfo info)
        throws LocalStorageException {
    @Cleanup("release")
    final ContentProviderClient client = resolver.acquireContentProviderClient(CalendarContract.AUTHORITY);
    if (client == null)
        throw new LocalStorageException("No Calendar Provider found (Calendar app disabled?)");

    ContentValues values = new ContentValues();
    values.put(Calendars.ACCOUNT_NAME, account.name);
    values.put(Calendars.ACCOUNT_TYPE, account.type);
    values.put(Calendars.NAME, info.getURL());
    values.put(Calendars.CALENDAR_DISPLAY_NAME, info.getTitle());
    values.put(Calendars.CALENDAR_COLOR, info.getColor() != null ? info.getColor() : DAVUtils.calendarGreen);
    values.put(Calendars.OWNER_ACCOUNT, account.name);
    values.put(Calendars.SYNC_EVENTS, 1);
    values.put(Calendars.VISIBLE, 1);/*from  ww w.  ja  v  a 2 s.co m*/
    values.put(Calendars.ALLOWED_REMINDERS, Reminders.METHOD_ALERT);

    if (info.isReadOnly())
        values.put(Calendars.CALENDAR_ACCESS_LEVEL, Calendars.CAL_ACCESS_READ);
    else {
        values.put(Calendars.CALENDAR_ACCESS_LEVEL, Calendars.CAL_ACCESS_OWNER);
        values.put(Calendars.CAN_ORGANIZER_RESPOND, 1);
        values.put(Calendars.CAN_MODIFY_TIME_ZONE, 1);
    }

    if (android.os.Build.VERSION.SDK_INT >= 15) {
        values.put(Calendars.ALLOWED_AVAILABILITY, Events.AVAILABILITY_BUSY + "," + Events.AVAILABILITY_FREE
                + "," + Events.AVAILABILITY_TENTATIVE);
        values.put(Calendars.ALLOWED_ATTENDEE_TYPES, Attendees.TYPE_NONE + "," + Attendees.TYPE_OPTIONAL + ","
                + Attendees.TYPE_REQUIRED + "," + Attendees.TYPE_RESOURCE);
    }

    if (info.getTimezone() != null)
        values.put(Calendars.CALENDAR_TIME_ZONE, DateUtils.findAndroidTimezoneID(info.getTimezone()));

    Log.i(TAG, "Inserting calendar: " + values.toString());
    try {
        return client.insert(calendarsURI(account), values);
    } catch (RemoteException e) {
        throw new LocalStorageException(e);
    }
}

From source file:org.exfio.csyncdroid.resource.LocalCalendar.java

@SuppressLint("InlinedApi")
public static void create(Account account, ContentResolver resolver, ServerInfo.ResourceInfo info)
        throws RemoteException {
    ContentProviderClient client = resolver.acquireContentProviderClient(CalendarContract.AUTHORITY);

    //FIXME - change default colour
    int color = 0xFFC3EA6E; // fallback: "DAVdroid green"
    if (info.getColor() != null) {
        Pattern p = Pattern.compile("#(\\p{XDigit}{6})(\\p{XDigit}{2})?");
        Matcher m = p.matcher(info.getColor());
        if (m.find()) {
            int color_rgb = Integer.parseInt(m.group(1), 16);
            int color_alpha = m.group(2) != null ? (Integer.parseInt(m.group(2), 16) & 0xFF) : 0xFF;
            color = (color_alpha << 24) | color_rgb;
        }//from w ww . j av a 2 s .co  m
    }

    ContentValues values = new ContentValues();
    values.put(Calendars.ACCOUNT_NAME, account.name);
    values.put(Calendars.ACCOUNT_TYPE, account.type);
    values.put(Calendars.NAME, info.getCollection());
    values.put(Calendars.CALENDAR_DISPLAY_NAME, info.getTitle());
    values.put(Calendars.CALENDAR_COLOR, color);
    values.put(Calendars.OWNER_ACCOUNT, account.name);
    values.put(Calendars.SYNC_EVENTS, 1);
    values.put(Calendars.VISIBLE, 1);
    values.put(Calendars.ALLOWED_REMINDERS, Reminders.METHOD_ALERT);

    if (info.isReadOnly())
        values.put(Calendars.CALENDAR_ACCESS_LEVEL, Calendars.CAL_ACCESS_READ);
    else {
        values.put(Calendars.CALENDAR_ACCESS_LEVEL, Calendars.CAL_ACCESS_OWNER);
        values.put(Calendars.CAN_ORGANIZER_RESPOND, 1);
        values.put(Calendars.CAN_MODIFY_TIME_ZONE, 1);
    }

    if (android.os.Build.VERSION.SDK_INT >= 15) {
        values.put(Calendars.ALLOWED_AVAILABILITY, Events.AVAILABILITY_BUSY + "," + Events.AVAILABILITY_FREE
                + "," + Events.AVAILABILITY_TENTATIVE);
        values.put(Calendars.ALLOWED_ATTENDEE_TYPES, Attendees.TYPE_NONE + "," + Attendees.TYPE_OPTIONAL + ","
                + Attendees.TYPE_REQUIRED + "," + Attendees.TYPE_RESOURCE);
    }

    if (info.getTimezone() != null)
        values.put(Calendars.CALENDAR_TIME_ZONE, info.getTimezone());

    Log.i(TAG, "Inserting calendar: " + values.toString() + " -> " + calendarsURI(account).toString());
    client.insert(calendarsURI(account), values);
}

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;//  ww  w  .j a v a 2s.c  o  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:org.opensilk.video.data.VideosProviderClient.java

public boolean insertMedia(MediaBrowser.MediaItem mediaItem) {
    ContentValues cv = new ContentValues(10);
    MediaDescription description = mediaItem.getDescription();
    MediaMetaExtras metaExtras = MediaMetaExtras.from(description.getExtras());
    Uri mediaUri = MediaDescriptionUtil.getMediaUri(description);
    cv.put("_display_name", metaExtras.getMediaTitle());
    String descriptionTitle = description.getTitle() != null ? description.getTitle().toString() : null;
    cv.put("_title", descriptionTitle);
    String descriptionSubtitle = description.getSubtitle() != null ? description.getSubtitle().toString()
            : null;//  w w  w . ja  v a 2s . c o  m
    cv.put("_subtitle", descriptionSubtitle);

    cv.put("parent_media_uri", metaExtras.getParentUri().toString());
    cv.put("server_id", metaExtras.getServerId());
    cv.put("media_category", metaExtras.getMediaType());
    if (description.getIconUri() != null) {
        cv.put("artwork_uri", description.getIconUri().toString());
    }
    cv.put("is_indexed", metaExtras.isIndexed() ? 1 : 0);
    //Not setting last_played or duration service does that

    if (metaExtras.isTvEpisode()) {
        tvdb().onInsertMedia(mediaItem, cv);
    } else if (metaExtras.isMovie()) {
        moviedb().onInsertMedia(mediaItem, cv);
    }

    try {
        int num = mResolver.update(mUris.media(), cv, "media_uri=?", new String[] { mediaUri.toString() });
        if (num > 0) {
            Timber.d("Updated %d rows for %s", num, metaExtras.getMediaTitle());
            return true;
        }
        cv.put("media_uri", mediaUri.toString());
        cv.put("date_added", System.currentTimeMillis());
        return mResolver.insert(mUris.media(), cv) != null;
    } catch (SQLiteException e) {
        Timber.w(e, "Failed updating %s values=%s", metaExtras.getMediaTitle(), cv.toString());
        return false;
    }
}

From source file:com.aware.Aware.java

private void get_device_info() {
    Cursor awareContextDevice = awareContext.getContentResolver().query(Aware_Device.CONTENT_URI, null, null,
            null, null);//from w  w  w . j  a  v a 2  s . c  o m
    if (awareContextDevice == null || !awareContextDevice.moveToFirst()) {
        ContentValues rowData = new ContentValues();
        rowData.put("timestamp", System.currentTimeMillis());
        rowData.put("device_id", Aware.getSetting(awareContext, Aware_Preferences.DEVICE_ID));
        rowData.put("board", Build.BOARD);
        rowData.put("brand", Build.BRAND);
        rowData.put("device", Build.DEVICE);
        rowData.put("build_id", Build.DISPLAY);
        rowData.put("hardware", Build.HARDWARE);
        rowData.put("manufacturer", Build.MANUFACTURER);
        rowData.put("model", Build.MODEL);
        rowData.put("product", Build.PRODUCT);
        rowData.put("serial", Build.SERIAL);
        rowData.put("release", Build.VERSION.RELEASE);
        rowData.put("release_type", Build.TYPE);
        rowData.put("sdk", Build.VERSION.SDK_INT);

        try {
            awareContext.getContentResolver().insert(Aware_Device.CONTENT_URI, rowData);

            Intent deviceData = new Intent(ACTION_AWARE_DEVICE_INFORMATION);
            sendBroadcast(deviceData);

            if (Aware.DEBUG)
                Log.d(TAG, "Device information:" + rowData.toString());

        } catch (SQLiteException e) {
            if (Aware.DEBUG)
                Log.d(TAG, e.getMessage());
        } catch (SQLException e) {
            if (Aware.DEBUG)
                Log.d(TAG, e.getMessage());
        }
    }
    if (awareContextDevice != null && !awareContextDevice.isClosed())
        awareContextDevice.close();
}