Search in sources :

Example 11 with Uri

use of android.net.Uri in project cw-omnibus by commonsguy.

the class SuggestionsAdapter method getSuggestions.

public Cursor getSuggestions(String query, int limit) {
    if (mSearchable == null) {
        return null;
    }
    String authority = mSearchable.getSuggestAuthority();
    if (authority == null) {
        return null;
    }
    Uri.Builder uriBuilder = new Uri.Builder().scheme(ContentResolver.SCHEME_CONTENT).authority(authority).query(// TODO: Remove, workaround for a bug in Uri.writeToParcel()
    "").fragment(// TODO: Remove, workaround for a bug in Uri.writeToParcel()
    "");
    // if content path provided, insert it now
    final String contentPath = mSearchable.getSuggestPath();
    if (contentPath != null) {
        uriBuilder.appendEncodedPath(contentPath);
    }
    // append standard suggestion query path
    uriBuilder.appendPath(SearchManager.SUGGEST_URI_PATH_QUERY);
    // get the query selection, may be null
    String selection = mSearchable.getSuggestSelection();
    // inject query, either as selection args or inline
    String[] selArgs = null;
    if (selection != null) {
        // use selection if provided
        selArgs = new String[] { query };
    } else {
        // no selection, use REST pattern
        uriBuilder.appendPath(query);
    }
    if (limit > 0) {
        uriBuilder.appendQueryParameter("limit", String.valueOf(limit));
    }
    Uri uri = uriBuilder.build();
    // finally, make the query
    return mContext.getContentResolver().query(uri, null, selection, selArgs, null);
}
Also used : SpannableString(android.text.SpannableString) Uri(android.net.Uri)

Example 12 with Uri

use of android.net.Uri in project cw-omnibus by commonsguy.

the class SuggestionsAdapter method getDrawableFromResourceValue.

/**
     * Gets a drawable given a value provided by a suggestion provider.
     *
     * This value could be just the string value of a resource id
     * (e.g., "2130837524"), in which case we will try to retrieve a drawable from
     * the provider's resources. If the value is not an integer, it is
     * treated as a Uri and opened with
     * {@link ContentResolver#openOutputStream(android.net.Uri, String)}.
     *
     * All resources and URIs are read using the suggestion provider's context.
     *
     * If the string is not formatted as expected, or no drawable can be found for
     * the provided value, this method returns null.
     *
     * @param drawableId a string like "2130837524",
     *        "android.resource://com.android.alarmclock/2130837524",
     *        or "content://contacts/photos/253".
     * @return a Drawable, or null if none found
     */
private Drawable getDrawableFromResourceValue(String drawableId) {
    if (drawableId == null || drawableId.length() == 0 || "0".equals(drawableId)) {
        return null;
    }
    try {
        // First, see if it's just an integer
        int resourceId = Integer.parseInt(drawableId);
        // It's an int, look for it in the cache
        String drawableUri = ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + mProviderContext.getPackageName() + "/" + resourceId;
        // Must use URI as cache key, since ints are app-specific
        Drawable drawable = checkIconCache(drawableUri);
        if (drawable != null) {
            return drawable;
        }
        // Not cached, find it by resource ID
        drawable = mProviderContext.getResources().getDrawable(resourceId);
        // Stick it in the cache, using the URI as key
        storeInIconCache(drawableUri, drawable);
        return drawable;
    } catch (NumberFormatException nfe) {
        // It's not an integer, use it as a URI
        Drawable drawable = checkIconCache(drawableId);
        if (drawable != null) {
            return drawable;
        }
        Uri uri = Uri.parse(drawableId);
        drawable = getDrawable(uri);
        storeInIconCache(drawableId, drawable);
        return drawable;
    } catch (Resources.NotFoundException nfe) {
        // It was an integer, but it couldn't be found, bail out
        Log.w(LOG_TAG, "Icon resource not found: " + drawableId);
        return null;
    }
}
Also used : Drawable(android.graphics.drawable.Drawable) SpannableString(android.text.SpannableString) Resources(android.content.res.Resources) Uri(android.net.Uri)

Example 13 with Uri

use of android.net.Uri in project cw-omnibus by commonsguy.

the class PopupAdapter method getInfoContents.

@SuppressLint("InflateParams")
@Override
public View getInfoContents(Marker marker) {
    if (popup == null) {
        popup = inflater.inflate(R.layout.popup, null);
    }
    if (lastMarker == null || !lastMarker.getId().equals(marker.getId())) {
        lastMarker = marker;
        TextView tv = (TextView) popup.findViewById(R.id.title);
        tv.setText(marker.getTitle());
        tv = (TextView) popup.findViewById(R.id.snippet);
        tv.setText(marker.getSnippet());
        Uri image = images.get(marker.getId());
        ImageView icon = (ImageView) popup.findViewById(R.id.icon);
        if (image == null) {
            icon.setVisibility(View.GONE);
        } else {
            Picasso.with(ctxt).load(image).resize(iconWidth, iconHeight).centerCrop().noFade().placeholder(R.drawable.placeholder).into(icon, new MarkerCallback(marker));
        }
    }
    return (popup);
}
Also used : TextView(android.widget.TextView) ImageView(android.widget.ImageView) Uri(android.net.Uri) SuppressLint(android.annotation.SuppressLint)

Example 14 with Uri

use of android.net.Uri in project cw-omnibus by commonsguy.

the class VideoPresenter method onBindViewHolder.

@Override
public void onBindViewHolder(Presenter.ViewHolder viewHolder, Object item) {
    Video video = (Video) item;
    Holder h = (Holder) viewHolder;
    Resources res = ctxt.getResources();
    h.cardView.setTitleText(video.toString());
    h.cardView.setMainImageDimensions((int) res.getDimension(R.dimen.card_width), (int) res.getDimension(R.dimen.card_height));
    Uri thumbnailUri = ContentUris.withAppendedId(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, video.id);
    h.updateCardViewImage(thumbnailUri);
}
Also used : Resources(android.content.res.Resources) Uri(android.net.Uri)

Example 15 with Uri

use of android.net.Uri in project TakePhoto by crazycodeboy.

the class CustomHelper method onClick.

public void onClick(View view, TakePhoto takePhoto) {
    File file = new File(Environment.getExternalStorageDirectory(), "/temp/" + System.currentTimeMillis() + ".jpg");
    if (!file.getParentFile().exists())
        file.getParentFile().mkdirs();
    Uri imageUri = Uri.fromFile(file);
    configCompress(takePhoto);
    configTakePhotoOption(takePhoto);
    switch(view.getId()) {
        case R.id.btnPickBySelect:
            int limit = Integer.parseInt(etLimit.getText().toString());
            if (limit > 1) {
                if (rgCrop.getCheckedRadioButtonId() == R.id.rbCropYes) {
                    takePhoto.onPickMultipleWithCrop(limit, getCropOptions());
                } else {
                    takePhoto.onPickMultiple(limit);
                }
                return;
            }
            if (rgFrom.getCheckedRadioButtonId() == R.id.rbFile) {
                if (rgCrop.getCheckedRadioButtonId() == R.id.rbCropYes) {
                    takePhoto.onPickFromDocumentsWithCrop(imageUri, getCropOptions());
                } else {
                    takePhoto.onPickFromDocuments();
                }
                return;
            } else {
                if (rgCrop.getCheckedRadioButtonId() == R.id.rbCropYes) {
                    takePhoto.onPickFromGalleryWithCrop(imageUri, getCropOptions());
                } else {
                    takePhoto.onPickFromGallery();
                }
            }
            break;
        case R.id.btnPickByTake:
            if (rgCrop.getCheckedRadioButtonId() == R.id.rbCropYes) {
                takePhoto.onPickFromCaptureWithCrop(imageUri, getCropOptions());
            } else {
                takePhoto.onPickFromCapture(imageUri);
            }
            break;
        default:
            break;
    }
}
Also used : File(java.io.File) Uri(android.net.Uri)

Aggregations

Uri (android.net.Uri)6747 Intent (android.content.Intent)1547 Cursor (android.database.Cursor)894 File (java.io.File)744 Test (org.junit.Test)632 ContentValues (android.content.ContentValues)614 IOException (java.io.IOException)571 ContentResolver (android.content.ContentResolver)449 ArrayList (java.util.ArrayList)446 Bundle (android.os.Bundle)289 Context (android.content.Context)276 Bitmap (android.graphics.Bitmap)273 InputStream (java.io.InputStream)257 View (android.view.View)251 RemoteException (android.os.RemoteException)228 PendingIntent (android.app.PendingIntent)209 SuppressLint (android.annotation.SuppressLint)180 FileNotFoundException (java.io.FileNotFoundException)177 TextView (android.widget.TextView)175 ActivityNotFoundException (android.content.ActivityNotFoundException)169