Example usage for android.net Uri withAppendedPath

List of usage examples for android.net Uri withAppendedPath

Introduction

In this page you can find the example usage for android.net Uri withAppendedPath.

Prototype

public static Uri withAppendedPath(Uri baseUri, String pathSegment) 

Source Link

Document

Creates a new Uri by appending an already-encoded path segment to a base Uri.

Usage

From source file:nl.sogeti.android.gpstracker.viewer.LoggerMap.java

private void updateDataOverlays() {
    ContentResolver resolver = this.getContentResolver();
    Uri segmentsUri = Uri.withAppendedPath(Tracks.CONTENT_URI, this.mTrackId + "/segments");
    Cursor segmentsCursor = null;
    List<?> overlays = this.mMapView.getOverlays();
    int segmentOverlaysCount = 0;

    for (Object overlay : overlays) {
        if (overlay instanceof SegmentOverlay) {
            segmentOverlaysCount++;//  ww w.  ja  va 2 s . com
        }
    }
    try {
        segmentsCursor = resolver.query(segmentsUri, new String[] { Segments._ID }, null, null, null);
        if (segmentsCursor != null && segmentsCursor.getCount() == segmentOverlaysCount) {
            //            Log.d( TAG, "Alignment of segments" );
        } else {
            createDataOverlays();
        }
    } finally {
        if (segmentsCursor != null) {
            segmentsCursor.close();
        }
    }
}

From source file:org.opendatakit.survey.android.activities.MainMenuActivity.java

@Override
public void initializationCompleted(String fragmentToShowNext) {
    // whether we have can cancelled or completed update,
    // remember to not do the expansion files check next time through
    ScreenList newFragment = ScreenList.valueOf(fragmentToShowNext);
    if (newFragment == ScreenList.WEBKIT && getCurrentForm() == null) {
        // we were sent off to the initialization dialog to try to
        // discover the form. We need to inquire about the form again
        // and, if we cannot find it, report an error to the user.
        final Uri uriFormsProvider = FormsProviderAPI.CONTENT_URI;
        Uri uri = getIntent().getData();
        Uri formUri = null;/*from   w  w  w.j a  va2 s . com*/

        if (uri.getScheme().equalsIgnoreCase(uriFormsProvider.getScheme())
                && uri.getAuthority().equalsIgnoreCase(uriFormsProvider.getAuthority())) {
            List<String> segments = uri.getPathSegments();
            if (segments != null && segments.size() >= 2) {
                String appName = segments.get(0);
                setAppName(appName);
                formUri = Uri.withAppendedPath(Uri.withAppendedPath(uriFormsProvider, appName),
                        segments.get(1));
            } else {
                swapToFragmentView(ScreenList.FORM_CHOOSER);
                createErrorDialog(getString(R.string.invalid_uri_expecting_n_segments, uri.toString(), 2),
                        EXIT);
                return;
            }
            // request specifies a specific formUri -- try to open that
            FormIdStruct newForm = FormIdStruct.retrieveFormIdStruct(getContentResolver(), formUri);
            if (newForm == null) {
                // error
                swapToFragmentView(ScreenList.FORM_CHOOSER);
                createErrorDialog(getString(R.string.form_not_found, segments.get(1)), EXIT);
                return;
            } else {
                transitionToFormHelper(uri, newForm);
                swapToFragmentView(newFragment);
            }
        }
    } else {
        WebLogger.getLogger(getAppName()).i(t, "initializationCompleted: swapping to " + newFragment.name());
        swapToFragmentView(newFragment);
    }
}

From source file:com.phonegap.ContactAccessorSdk3_4.java

/**
 * This method will save a contact object into the devices contacts database.
 * /*w  ww. j  av a2  s  .  com*/
 * @param contact the contact to be saved.
 * @returns true if the contact is successfully saved, false otherwise.
 */
@Override
public boolean save(JSONObject contact) {
    ContentValues personValues = new ContentValues();

    String id = getJsonString(contact, "id");

    String name = getJsonString(contact, "displayName");
    if (name != null) {
        personValues.put(Contacts.People.NAME, name);
    }
    String note = getJsonString(contact, "note");
    if (note != null) {
        personValues.put(Contacts.People.NOTES, note);
    }

    /* STARRED 0 = Contacts, 1 = Favorites */
    personValues.put(Contacts.People.STARRED, 0);

    Uri newPersonUri;
    // Add new contact
    if (id == null) {
        newPersonUri = Contacts.People.createPersonInMyContactsGroup(mApp.getContentResolver(), personValues);
    }
    // modify existing contact
    else {
        newPersonUri = Uri.withAppendedPath(Contacts.People.CONTENT_URI, id);
        mApp.getContentResolver().update(newPersonUri, personValues, PEOPLE_ID_EQUALS, new String[] { id });
    }

    if (newPersonUri != null) {
        // phoneNumbers
        savePhoneNumbers(contact, newPersonUri);
        // emails
        saveEntries(contact, newPersonUri, "emails", Contacts.KIND_EMAIL);
        // addresses
        saveAddresses(contact, newPersonUri);
        // organizations
        saveOrganizations(contact, newPersonUri);
        // ims
        saveEntries(contact, newPersonUri, "ims", Contacts.KIND_IM);

        // Successfully create a Contact
        return true;
    }
    return false;
}

From source file:cz.maresmar.sfm.view.credential.CredentialDetailFragment.java

@Nullable
@Override// ww  w.j  av a  2  s.  com
public Uri saveData() {
    Timber.i("Saving credential data");

    // Defines an object to contain the new values to insert
    ContentValues values = new ContentValues();

    /*
     * Sets the values of each column and inserts the word. The arguments to the "put"
     * method are "column name" and "value"
     */
    values.put(ProviderContract.Credentials.CREDENTIALS_GROUP_ID, mCredentialGroupSpinner.getSelectedItemId());
    values.put(ProviderContract.Credentials.PORTAL_GROUP_ID, mPortalGroupId);
    // User will be added from user prefix
    values.put(ProviderContract.Credentials.USER_NAME, mNameText.getText().toString());
    values.put(ProviderContract.Credentials.USER_PASS, mPasswordText.getText().toString());
    values.put(ProviderContract.Credentials.EXTRA, getExtraData());
    // Notifications
    @ProviderContract.CredentialFlags
    int flags = 0;
    if (!mCreditIncreaseNotificationCheckBox.isChecked()) {
        flags |= ProviderContract.CREDENTIAL_FLAG_DISABLE_CREDIT_INCREASE_NOTIFICATION;
    }
    if (!mLowCreditNotificationCheckBox.isChecked()) {
        flags |= ProviderContract.CREDENTIAL_FLAG_DISABLE_LOW_CREDIT_NOTIFICATION;
    }
    values.put(ProviderContract.Credentials.FLAGS, flags);
    values.put(ProviderContract.Credentials.LOW_CREDIT_THRESHOLD, mLowCreditText.getText().toString());

    //noinspection ConstantConditions
    ContentResolver contentResolver = getContext().getContentResolver();
    if (mCredentialUri == null) {
        Uri credentialUri = Uri.withAppendedPath(mUserPrefixUri, ProviderContract.CREDENTIALS_PATH);
        mCredentialTempUri = contentResolver.insert(credentialUri, values);
        mCredentialUri = mCredentialTempUri;
    } else {
        int updatedRows = contentResolver.update(mCredentialUri, values, null, null);
        if (BuildConfig.DEBUG) {
            Assert.isOne(updatedRows);
        }
    }
    return mCredentialUri;
}

From source file:com.google.android.apps.paco.NotificationCreator.java

private void createAlarmForSnooze(Context context, NotificationHolder notificationHolder) {
    DateTime alarmTime = new DateTime(notificationHolder.getAlarmTime());
    Experiment experiment = experimentProviderUtil.getExperiment(notificationHolder.getExperimentId());
    Integer snoozeTime = experiment.getSignalingMechanisms().get(0).getSnoozeTime();
    int snoozeMinutes = snoozeTime / MILLIS_IN_MINUTE;
    DateTime timeoutMinutes = new DateTime(alarmTime).plusMinutes(snoozeMinutes);
    long snoozeDurationInMillis = timeoutMinutes.getMillis();

    Log.i(PacoConstants.TAG,//from  w w  w.j  a  v a  2 s .c  o  m
            "Creating snooze alarm to resound notification for holder: " + notificationHolder.getId()
                    + ". experiment = " + notificationHolder.getExperimentId() + ". alarmtime = "
                    + new DateTime(alarmTime).toString() + " waking up from snooze in " + timeoutMinutes
                    + " minutes");

    Intent ultimateIntent = new Intent(context, AlarmReceiver.class);
    Uri uri = Uri.withAppendedPath(NotificationHolderColumns.CONTENT_URI,
            notificationHolder.getId().toString());
    ultimateIntent.setData(uri);
    ultimateIntent.putExtra(NOTIFICATION_ID, notificationHolder.getId().longValue());
    ultimateIntent.putExtra(SNOOZE_REPEATER_EXTRA_KEY, true);

    PendingIntent intent = PendingIntent.getBroadcast(context.getApplicationContext(), 3, ultimateIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    alarmManager.cancel(intent);
    alarmManager.set(AlarmManager.RTC_WAKEUP, snoozeDurationInMillis, intent);
}

From source file:org.opendatakit.survey.android.tasks.InitializationTask.java

/**
 * Scan the given formDir and update the Forms database. If it is the
 * formsFolder, then any 'framework' forms should be forbidden. If it is not
 * the formsFolder, only 'framework' forms should be allowed
 *
 * @param mediaPath// ww w  . ja v  a2s. c  o  m
 *          -- full formDir
 * @param isFormsFolder
 * @param baseStaleMediaPath
 *          -- path prefix to the stale forms/framework directory.
 */
private final void updateFormDir(File formDir, boolean isFormsFolder, String baseStaleMediaPath) {
    Uri formsProviderContentUri = Uri.parse("content://" + FormsProviderAPI.AUTHORITY);
    String formDirectoryPath = formDir.getAbsolutePath();
    WebLogger.getLogger(appName).i(t, "updateFormDir: " + formDirectoryPath);

    boolean needUpdate = true;
    FormInfo fi = null;
    Uri uri = null;
    Cursor c = null;
    try {
        File formDef = new File(formDir, ODKFileUtils.FORMDEF_JSON_FILENAME);

        String selection = FormsColumns.APP_RELATIVE_FORM_MEDIA_PATH + "=?";
        String[] selectionArgs = { ODKFileUtils.asRelativePath(appName, formDir) };
        c = appContext.getContentResolver().query(Uri.withAppendedPath(formsProviderContentUri, appName), null,
                selection, selectionArgs, null);

        if (c == null) {
            WebLogger.getLogger(appName).w(t,
                    "updateFormDir: " + formDirectoryPath + " null cursor -- cannot update!");
            return;
        }

        if (c.getCount() > 1) {
            c.close();
            WebLogger.getLogger(appName).w(t, "updateFormDir: " + formDirectoryPath
                    + " multiple records from cursor -- delete all and restore!");
            // we have multiple records for this one directory.
            // Rename the directory. Delete the records, and move the
            // directory back.
            File tempMediaPath = moveToStaleDirectory(formDir, baseStaleMediaPath);
            appContext.getContentResolver().delete(Uri.withAppendedPath(formsProviderContentUri, appName),
                    selection, selectionArgs);
            FileUtils.moveDirectory(tempMediaPath, formDir);
            // we don't know which of the above records was correct, so
            // reparse this to get ground truth...
            fi = new FormInfo(appContext, appName, formDef);
        } else if (c.getCount() == 1) {
            c.moveToFirst();
            String id = ODKDatabaseUtils.get().getIndexAsString(c, c.getColumnIndex(FormsColumns.FORM_ID));
            uri = Uri.withAppendedPath(Uri.withAppendedPath(formsProviderContentUri, appName), id);
            Long lastModificationDate = ODKDatabaseUtils.get().getIndexAsType(c, Long.class,
                    c.getColumnIndex(FormsColumns.DATE));
            Long formDefModified = ODKFileUtils.getMostRecentlyModifiedDate(formDir);
            if (lastModificationDate.compareTo(formDefModified) == 0) {
                WebLogger.getLogger(appName).i(t, "updateFormDir: " + formDirectoryPath + " formDef unchanged");
                fi = new FormInfo(appName, c, false);
                needUpdate = false;
            } else {
                WebLogger.getLogger(appName).i(t, "updateFormDir: " + formDirectoryPath + " formDef revised");
                fi = new FormInfo(appContext, appName, formDef);
                needUpdate = true;
            }
        } else if (c.getCount() == 0) {
            // it should be new, try to parse it...
            fi = new FormInfo(appContext, appName, formDef);
        }

        // Enforce that a formId == FormsColumns.COMMON_BASE_FORM_ID can only be
        // in the Framework directory
        // and that no other formIds can be in that directory. If this is not the
        // case, ensure that
        // this record is moved to the stale directory.

        if (fi.formId.equals(FormsColumns.COMMON_BASE_FORM_ID)) {
            if (isFormsFolder) {
                // we have a 'framework' form in the forms directory.
                // Move it to the stale directory.
                // Delete all records referring to this directory.
                moveToStaleDirectory(formDir, baseStaleMediaPath);
                appContext.getContentResolver().delete(Uri.withAppendedPath(formsProviderContentUri, appName),
                        selection, selectionArgs);
                return;
            }
        } else {
            if (!isFormsFolder) {
                // we have a non-'framework' form in the framework directory.
                // Move it to the stale directory.
                // Delete all records referring to this directory.
                moveToStaleDirectory(formDir, baseStaleMediaPath);
                appContext.getContentResolver().delete(Uri.withAppendedPath(formsProviderContentUri, appName),
                        selection, selectionArgs);
                return;
            }
        }
    } catch (SQLiteException e) {
        WebLogger.getLogger(appName).printStackTrace(e);
        WebLogger.getLogger(appName).e(t,
                "updateFormDir: " + formDirectoryPath + " exception: " + e.toString());
        return;
    } catch (IOException e) {
        WebLogger.getLogger(appName).printStackTrace(e);
        WebLogger.getLogger(appName).e(t,
                "updateFormDir: " + formDirectoryPath + " exception: " + e.toString());
        return;
    } catch (IllegalArgumentException e) {
        WebLogger.getLogger(appName).printStackTrace(e);
        WebLogger.getLogger(appName).e(t,
                "updateFormDir: " + formDirectoryPath + " exception: " + e.toString());
        try {
            FileUtils.deleteDirectory(formDir);
            WebLogger.getLogger(appName).i(t, "updateFormDir: " + formDirectoryPath
                    + " Removing -- unable to parse formDef file: " + e.toString());
        } catch (IOException e1) {
            WebLogger.getLogger(appName).printStackTrace(e1);
            WebLogger.getLogger(appName)
                    .i(t, "updateFormDir: " + formDirectoryPath
                            + " Removing -- unable to delete form directory: " + formDir.getName() + " error: "
                            + e.toString());
        }
        return;
    } finally {
        if (c != null && !c.isClosed()) {
            c.close();
        }
    }

    // Delete any entries matching this FORM_ID, but not the same directory and
    // which have a version that is equal to or older than this version.
    String selection;
    String[] selectionArgs;
    if (fi.formVersion == null) {
        selection = FormsColumns.APP_RELATIVE_FORM_MEDIA_PATH + "!=? AND " + FormsColumns.FORM_ID + "=? AND "
                + FormsColumns.FORM_VERSION + " IS NULL";
        String[] temp = { ODKFileUtils.asRelativePath(appName, formDir), fi.formId };
        selectionArgs = temp;
    } else {
        selection = FormsColumns.APP_RELATIVE_FORM_MEDIA_PATH + "!=? AND " + FormsColumns.FORM_ID + "=? AND "
                + "( " + FormsColumns.FORM_VERSION + " IS NULL" + " OR " + FormsColumns.FORM_VERSION + " <=?"
                + " )";
        String[] temp = { ODKFileUtils.asRelativePath(appName, formDir), fi.formId, fi.formVersion };
        selectionArgs = temp;
    }

    try {
        appContext.getContentResolver().delete(Uri.withAppendedPath(formsProviderContentUri, appName),
                selection, selectionArgs);
    } catch (SQLiteException e) {
        WebLogger.getLogger(appName).printStackTrace(e);
        WebLogger.getLogger(appName).e(t,
                "updateFormDir: " + formDirectoryPath + " exception: " + e.toString());
        return;
    } catch (Exception e) {
        WebLogger.getLogger(appName).printStackTrace(e);
        WebLogger.getLogger(appName).e(t,
                "updateFormDir: " + formDirectoryPath + " exception: " + e.toString());
        return;
    }

    // See if we have any newer versions already present...
    if (fi.formVersion == null) {
        selection = FormsColumns.APP_RELATIVE_FORM_MEDIA_PATH + "!=? AND " + FormsColumns.FORM_ID + "=? AND "
                + FormsColumns.FORM_VERSION + " IS NOT NULL";
        String[] temp = { ODKFileUtils.asRelativePath(appName, formDir), fi.formId };
        selectionArgs = temp;
    } else {
        selection = FormsColumns.APP_RELATIVE_FORM_MEDIA_PATH + "!=? AND " + FormsColumns.FORM_ID + "=? AND "
                + FormsColumns.FORM_VERSION + " >?";
        String[] temp = { ODKFileUtils.asRelativePath(appName, formDir), fi.formId, fi.formVersion };
        selectionArgs = temp;
    }

    try {
        Uri uriApp = Uri.withAppendedPath(formsProviderContentUri, appName);
        c = appContext.getContentResolver().query(uriApp, null, selection, selectionArgs, null);

        if (c == null) {
            WebLogger.getLogger(appName).w(t,
                    "updateFormDir: " + uriApp.toString() + " null cursor -- cannot update!");
            return;
        }

        if (c.moveToFirst()) {
            // the directory we are processing is stale -- move it to stale
            // directory
            moveToStaleDirectory(formDir, baseStaleMediaPath);
            return;
        }
    } catch (SQLiteException e) {
        WebLogger.getLogger(appName).printStackTrace(e);
        WebLogger.getLogger(appName).e(t,
                "updateFormDir: " + formDirectoryPath + " exception: " + e.toString());
        return;
    } catch (IOException e) {
        WebLogger.getLogger(appName).printStackTrace(e);
        WebLogger.getLogger(appName).e(t,
                "updateFormDir: " + formDirectoryPath + " exception: " + e.toString());
        return;
    } finally {
        if (c != null && !c.isClosed()) {
            c.close();
        }
    }

    if (!needUpdate) {
        // no change...
        return;
    }

    try {
        // Now insert or update the record...
        ContentValues v = new ContentValues();
        String[] values = fi.asRowValues(FormsColumns.formsDataColumnNames);
        for (int i = 0; i < values.length; ++i) {
            v.put(FormsColumns.formsDataColumnNames[i], values[i]);
        }

        if (uri != null) {
            int count = appContext.getContentResolver().update(uri, v, null, null);
            WebLogger.getLogger(appName).i(t,
                    "updateFormDir: " + formDirectoryPath + " " + count + " records successfully updated");
        } else {
            appContext.getContentResolver().insert(Uri.withAppendedPath(formsProviderContentUri, appName), v);
            WebLogger.getLogger(appName).i(t,
                    "updateFormDir: " + formDirectoryPath + " one record successfully inserted");
        }

    } catch (SQLiteException ex) {
        WebLogger.getLogger(appName).printStackTrace(ex);
        WebLogger.getLogger(appName).e(t,
                "updateFormDir: " + formDirectoryPath + " exception: " + ex.toString());
        return;
    }
}

From source file:fr.shywim.antoinedaniel.ui.fragment.VideoDetailsFragment.java

private void bindSound(View view, Cursor cursor) {
    AppState appState = AppState.getInstance();

    final View card = view;
    final View downloadFrame = view.findViewById(R.id.sound_download_frame);
    final TextView tv = (TextView) view.findViewById(R.id.grid_text);
    final SquareImageView siv = (SquareImageView) view.findViewById(R.id.grid_image);
    final ImageView star = (ImageView) view.findViewById(R.id.ic_sound_fav);
    final ImageView menu = (ImageView) view.findViewById(R.id.ic_sound_menu);

    final String soundName = cursor
            .getString(cursor.getColumnIndex(ProviderContract.SoundEntry.COLUMN_SOUND_NAME));
    String imgId = cursor.getString(cursor.getColumnIndex(ProviderContract.SoundEntry.COLUMN_IMAGE_NAME));
    final String description = cursor.getString(cursor.getColumnIndex(ProviderContract.SoundEntry.COLUMN_DESC));
    final boolean favorite = appState.favSounds.contains(soundName)
            || cursor.getInt(cursor.getColumnIndex(ProviderContract.SoundEntry.COLUMN_FAVORITE)) == 1;
    final boolean widget = appState.widgetSounds.contains(soundName)
            || cursor.getInt(cursor.getColumnIndex(ProviderContract.SoundEntry.COLUMN_WIDGET)) == 1;
    final boolean downloaded = cursor
            .getInt(cursor.getColumnIndex(ProviderContract.SoundEntry.COLUMN_DOWNLOADED)) != 0;

    new Handler().post(new Runnable() {
        @Override/*from   w  ww .  j  a  v  a 2 s.c  om*/
        public void run() {
            ContentValues cv = new ContentValues();
            File sndFile = new File(mContext.getExternalFilesDir(null) + "/snd/" + soundName + ".ogg");

            if (downloaded && !sndFile.exists()) {
                cv.put(ProviderContract.SoundEntry.COLUMN_DOWNLOADED, 0);
                mContext.getContentResolver().update(
                        Uri.withAppendedPath(ProviderConstants.SOUND_DOWNLOAD_NOTIFY_URI, soundName), cv, null,
                        null);
            }
        }
    });

    final View.OnClickListener playSound = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            String category = mContext.getString(R.string.ana_cat_sound);
            String action = mContext.getString(R.string.ana_act_play);

            Bundle extras = new Bundle();
            extras.putString(SoundFragment.SOUND_TO_PLAY, soundName);
            extras.putBoolean(SoundFragment.LOOP, SoundUtils.isLoopingSet());
            Intent intent = new Intent(mContext, SoundService.class);
            intent.putExtras(extras);

            mContext.startService(intent);
            AnalyticsUtils.sendEvent(category, action, soundName);
        }
    };

    final View.OnClickListener downloadSound = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            card.setOnClickListener(null);
            RotateAnimation animation = new RotateAnimation(0, 360, Animation.RELATIVE_TO_SELF, 0.5f,
                    Animation.RELATIVE_TO_SELF, 0.5f);
            animation.setInterpolator(new BounceInterpolator());
            animation.setFillAfter(true);
            animation.setFillEnabled(true);
            animation.setDuration(1000);
            animation.setRepeatCount(Animation.INFINITE);
            animation.setRepeatMode(Animation.RESTART);
            downloadFrame.findViewById(R.id.sound_download_icon).startAnimation(animation);

            DownloadService.startActionDownloadSound(mContext, soundName,
                    new SoundUtils.DownloadResultReceiver(new Handler(), downloadFrame, playSound, this));
        }
    };

    if (downloaded) {
        downloadFrame.setVisibility(View.GONE);
        downloadFrame.findViewById(R.id.sound_download_icon).clearAnimation();
        card.setOnClickListener(playSound);
    } else {
        downloadFrame.setAlpha(1);
        downloadFrame.findViewById(R.id.sound_download_icon).setScaleX(1);
        downloadFrame.findViewById(R.id.sound_download_icon).setScaleY(1);
        downloadFrame.setVisibility(View.VISIBLE);
        card.setOnClickListener(downloadSound);
    }

    menu.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            final ImageView menuIc = (ImageView) v;
            PopupMenu popup = new PopupMenu(mContext, menuIc);
            Menu menu = popup.getMenu();
            popup.getMenuInflater().inflate(R.menu.sound_menu, menu);

            if (favorite)
                menu.findItem(R.id.action_sound_fav).setTitle("Retirer des favoris");
            if (widget)
                menu.findItem(R.id.action_sound_wid).setTitle("Retirer du widget");

            popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
                @Override
                public boolean onMenuItemClick(MenuItem item) {
                    switch (item.getItemId()) {
                    case R.id.action_sound_fav:
                        SoundUtils.addRemoveFavorite(mContext, soundName);
                        return true;
                    case R.id.action_sound_wid:
                        SoundUtils.addRemoveWidget(mContext, soundName);
                        return true;
                    /*case R.id.action_sound_add:
                       return true;*/
                    case R.id.action_sound_ring:
                        SoundUtils.addRingtone(mContext, soundName, description);
                        return true;
                    case R.id.action_sound_share:
                        AnalyticsUtils.sendEvent(mContext.getString(R.string.ana_cat_soundcontext),
                                mContext.getString(R.string.ana_act_weblink), soundName);
                        ClipboardManager clipboard = (ClipboardManager) mContext
                                .getSystemService(Context.CLIPBOARD_SERVICE);
                        ClipData clip = ClipData.newPlainText("BAD link", "http://bad.shywim.fr/" + soundName);
                        clipboard.setPrimaryClip(clip);
                        Toast.makeText(mContext, R.string.toast_link_copied, Toast.LENGTH_LONG).show();
                        return true;
                    case R.id.action_sound_delete:
                        SoundUtils.delete(mContext, soundName);
                        return true;
                    default:
                        return false;
                    }
                }
            });

            popup.setOnDismissListener(new PopupMenu.OnDismissListener() {
                @Override
                public void onDismiss(PopupMenu menu) {
                    menuIc.setColorFilter(mContext.getResources().getColor(R.color.text_caption_dark));
                }
            });
            menuIc.setColorFilter(mContext.getResources().getColor(R.color.black));

            popup.show();
        }
    });

    tv.setText(description);
    siv.setTag(imgId);

    if (appState.favSounds.contains(soundName)) {
        star.setVisibility(View.VISIBLE);
    } else if (favorite) {
        star.setVisibility(View.VISIBLE);
        appState.favSounds.add(soundName);
    } else {
        star.setVisibility(View.INVISIBLE);
    }

    File file = new File(mContext.getExternalFilesDir(null) + "/img/" + imgId + ".jpg");
    Picasso.with(mContext).load(file).placeholder(R.drawable.noimg).fit().into(siv);
}

From source file:com.ute.bihapi.wydarzeniatekstowe.thirdScreenActivities.ContactsListFragment.java

@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
    // This swaps the new cursor into the adapter.
    if (loader.getId() == ContactsQuery.QUERY_ID) {
        mAdapter.swapCursor(data);/*  w  w  w .j av a 2  s. c o m*/

        // If this is a two-pane layout and there is a search query then
        // there is some additional work to do around default selected
        // search item.
        if (!TextUtils.isEmpty(mSearchTerm) && mSearchQueryChanged) {
            // Selects the first item in results, unless this fragment has
            // been restored from a saved state (like orientation change)
            // in which case it selects the previously selected search item.
            if (data != null && data.moveToPosition(mPreviouslySelectedSearchItem)) {
                // Creates the content Uri for the previously selected contact by appending the
                // contact's ID to the Contacts table content Uri
                final Uri uri = Uri.withAppendedPath(Contacts.CONTENT_URI,
                        String.valueOf(data.getLong(ContactsQuery.ID)));
                mOnContactSelectedListener.onContactSelected(uri);
                getListView().setItemChecked(mPreviouslySelectedSearchItem, true);
            } else {
                // No results, clear selection.
                onSelectionCleared();
            }
            // Only restore from saved state one time. Next time fall back
            // to selecting first item. If the fragment state is saved again
            // then the currently selected item will once again be saved.
            mPreviouslySelectedSearchItem = 0;
            mSearchQueryChanged = false;
        }
    }
}

From source file:com.phonegap.ContactAccessorSdk3_4.java

/** 
 * Takes a JSON contact object and loops through the available organizations.  If the  
 * organization has an id that is not equal to null the organization will be updated in the database.
 * If the id is null then we treat it as a new organization.
 * // w w w .  j av a 2  s. co  m
 * @param contact the contact to extract the organizations from
 * @param uri the base URI for this contact.
 */
private void saveOrganizations(JSONObject contact, Uri newPersonUri) {
    ContentValues values = new ContentValues();
    Uri orgUri = Uri.withAppendedPath(newPersonUri, Contacts.Organizations.CONTENT_DIRECTORY);
    String id = null;
    try {
        JSONArray orgs = contact.getJSONArray("organizations");
        if (orgs != null && orgs.length() > 0) {
            JSONObject org;
            for (int i = 0; i < orgs.length(); i++) {
                org = orgs.getJSONObject(i);
                id = getJsonString(org, "id");
                values.put(Contacts.Organizations.COMPANY, getJsonString(org, "name"));
                values.put(Contacts.Organizations.TITLE, getJsonString(org, "title"));
                if (id == null) {
                    Uri contactUpdate = mApp.getContentResolver().insert(orgUri, values);
                } else {
                    Uri tempUri = Uri.withAppendedPath(orgUri, id);
                    mApp.getContentResolver().update(tempUri, values, null, null);
                }
            }
        }
    } catch (JSONException e) {
        Log.d(LOG_TAG, "Could not save organizations = " + e.getMessage());
    }
}

From source file:com.android.mms.ui.SelectRecipientsList.java

private Uri getSelectedAsVcard(PhoneNumber number) {
    if (mMode == MODE_VCARD && !TextUtils.isEmpty(number.getLookupKey())) {
        return Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_VCARD_URI, number.getLookupKey());
    }/* www . j  ava 2  s  . c o m*/
    return null;
}