Search in sources :

Example 11 with Bitmap

use of android.graphics.Bitmap in project AndroidSyncProviderDemo by c99koder.

the class ContactsSyncAdapterService method performSync.

private static void performSync(Context context, Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) throws OperationCanceledException {
    HashMap<String, SyncEntry> localContacts = new HashMap<String, SyncEntry>();
    mContentResolver = context.getContentResolver();
    Log.i(TAG, "performSync: " + account.toString());
    // Load the local contacts
    Uri rawContactUri = RawContacts.CONTENT_URI.buildUpon().appendQueryParameter(RawContacts.ACCOUNT_NAME, account.name).appendQueryParameter(RawContacts.ACCOUNT_TYPE, account.type).build();
    Cursor c1 = mContentResolver.query(rawContactUri, new String[] { BaseColumns._ID, UsernameColumn, PhotoTimestampColumn }, null, null, null);
    while (c1.moveToNext()) {
        SyncEntry entry = new SyncEntry();
        entry.raw_id = c1.getLong(c1.getColumnIndex(BaseColumns._ID));
        entry.photo_timestamp = c1.getLong(c1.getColumnIndex(PhotoTimestampColumn));
        localContacts.put(c1.getString(1), entry);
    }
    ArrayList<ContentProviderOperation> operationList = new ArrayList<ContentProviderOperation>();
    try {
        // status message
        if (localContacts.get("efudd") == null) {
            addContact(account, "Elmer Fudd", "efudd");
        } else {
            if (localContacts.get("efudd").photo_timestamp == null || System.currentTimeMillis() > (localContacts.get("efudd").photo_timestamp + 604800000L)) {
                //You would probably download an image file and just pass the bytes, but this sample doesn't use network so we'll decode and re-compress the icon resource to get the bytes
                ByteArrayOutputStream stream = new ByteArrayOutputStream();
                Bitmap icon = BitmapFactory.decodeResource(context.getResources(), R.drawable.icon);
                icon.compress(CompressFormat.PNG, 0, stream);
                updateContactPhoto(operationList, localContacts.get("efudd").raw_id, stream.toByteArray());
            }
            updateContactStatus(operationList, localContacts.get("efudd").raw_id, "hunting wabbits");
        }
        if (operationList.size() > 0)
            mContentResolver.applyBatch(ContactsContract.AUTHORITY, operationList);
    } catch (Exception e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
}
Also used : ContentProviderOperation(android.content.ContentProviderOperation) Bitmap(android.graphics.Bitmap) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Cursor(android.database.Cursor) Uri(android.net.Uri) OperationCanceledException(android.accounts.OperationCanceledException)

Example 12 with Bitmap

use of android.graphics.Bitmap in project glide by bumptech.

the class GifDecoderTest method testFirstFrameMustClearBeforeDrawingWhenLastFrameIsDisposalNone.

@Test
@Config(shadows = { CustomShadowBitmap.class })
public void testFirstFrameMustClearBeforeDrawingWhenLastFrameIsDisposalNone() throws IOException {
    byte[] data = TestUtil.resourceToBytes(getClass(), "transparent_disposal_none.gif");
    GifHeaderParser headerParser = new GifHeaderParser();
    headerParser.setData(data);
    GifHeader header = headerParser.parseHeader();
    GifDecoder decoder = new StandardGifDecoder(provider);
    decoder.setData(header, data);
    decoder.advance();
    Bitmap firstFrame = decoder.getNextFrame();
    decoder.advance();
    decoder.getNextFrame();
    decoder.advance();
    Bitmap firstFrameTwice = decoder.getNextFrame();
    assertTrue(Arrays.equals((((CustomShadowBitmap) shadowOf(firstFrame))).getPixels(), (((CustomShadowBitmap) shadowOf(firstFrameTwice))).getPixels()));
}
Also used : ShadowBitmap(org.robolectric.shadows.ShadowBitmap) Bitmap(android.graphics.Bitmap) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Example 13 with Bitmap

use of android.graphics.Bitmap in project photo-picker-plus-android by chute.

the class ServicesRecyclerAdapter method setupLocalService.

private void setupLocalService(ListItemViewHolder holder, LocalServiceType type) {
    Uri lastVideoThumbFromAllVideos = MediaDAO.getLastVideoThumbnailFromAllVideos(context.getApplicationContext());
    Uri lastVideoThumbFromCameraVideos = MediaDAO.getLastVideoThumbnailFromCameraVideos(context.getApplicationContext());
    Uri lastImageFromAllPhotos = MediaDAO.getLastPhotoFromAllPhotos(context.getApplicationContext());
    Uri lastImageFromCameraPhotos = MediaDAO.getLastPhotoFromCameraPhotos(context.getApplicationContext());
    switch(type) {
        case TAKE_PHOTO:
            holder.imageViewService.setBackgroundResource(R.drawable.take_photo);
            holder.textViewServiceTitle.setText(R.string.take_photos);
            break;
        case CAMERA_MEDIA:
            Uri uriCameraMedia = null;
            if (supportsImages) {
                uriCameraMedia = lastImageFromAllPhotos;
            } else {
                uriCameraMedia = lastVideoThumbFromCameraVideos;
            }
            Picasso.with(context).load(uriCameraMedia).fit().centerCrop().into(holder.imageViewService);
            holder.textViewServiceTitle.setText(R.string.camera_media);
            break;
        case LAST_PHOTO_TAKEN:
            Picasso.with(context).load(lastImageFromAllPhotos).fit().centerCrop().into(holder.imageViewService);
            holder.textViewServiceTitle.setText(context.getResources().getString(R.string.last_photo));
            break;
        case ALL_MEDIA:
            Uri uriAllMedia = null;
            if (supportsImages) {
                uriAllMedia = lastImageFromAllPhotos;
            } else {
                uriAllMedia = lastVideoThumbFromAllVideos;
            }
            Picasso.with(context).load(uriAllMedia).fit().centerCrop().into(holder.imageViewService);
            holder.textViewServiceTitle.setText(context.getResources().getString(R.string.all_media));
            break;
        case LAST_VIDEO_CAPTURED:
            String thumbnail = MediaDAO.getLastVideoThumbnailFromCurosr(context);
            Bitmap bitmap = ThumbnailUtils.createVideoThumbnail(thumbnail, MediaStore.Images.Thumbnails.MINI_KIND);
            holder.imageViewService.setImageBitmap(bitmap);
            holder.textViewServiceTitle.setText(context.getResources().getString(R.string.last_video_captured));
            break;
        case RECORD_VIDEO:
            holder.imageViewService.setBackgroundResource(R.drawable.take_photo);
            holder.textViewServiceTitle.setText(R.string.record_video);
            break;
    }
    /* Click listeners */
    switch(type) {
        case ALL_MEDIA:
            holder.imageViewService.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    serviceClickedListener.photoStream();
                }
            });
            break;
        case CAMERA_MEDIA:
            holder.imageViewService.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    serviceClickedListener.cameraRoll();
                }
            });
            break;
        case TAKE_PHOTO:
            holder.imageViewService.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    serviceClickedListener.takePhoto();
                }
            });
            break;
        case LAST_PHOTO_TAKEN:
            holder.imageViewService.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    serviceClickedListener.lastPhoto();
                }
            });
            break;
        case LAST_VIDEO_CAPTURED:
            holder.imageViewService.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    serviceClickedListener.lastVideo();
                }
            });
            break;
        case RECORD_VIDEO:
            holder.imageViewService.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    serviceClickedListener.recordVideo();
                }
            });
            break;
    }
}
Also used : Bitmap(android.graphics.Bitmap) OnClickListener(android.view.View.OnClickListener) Uri(android.net.Uri) ImageView(android.widget.ImageView) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) View(android.view.View)

Example 14 with Bitmap

use of android.graphics.Bitmap in project photo-picker-plus-android by chute.

the class MediaScannerWrapper method onScanCompleted.

public void onScanCompleted(String path, Uri uri) {
    File file = new File(path);
    Uri uriFromFile = Uri.fromFile(file);
    String imagePath = "";
    if (mMimeType == MediaType.IMAGE) {
        if (AppUtil.hasImageCaptureBug() == false) {
            imagePath = uriFromFile.toString();
        } else {
            imagePath = Uri.fromFile(new File(AppUtil.getPath(context, intent.getData()))).toString();
        }
    } else if (mMimeType == MediaType.VIDEO) {
        imagePath = uriFromFile.toString();
    }
    final AssetModel model = new AssetModel();
    if (uri != null) {
        model.setId(uri.toString());
    }
    if (mMimeType == MediaType.VIDEO) {
        Bitmap thumbnail = ThumbnailUtils.createVideoThumbnail(file.getAbsolutePath(), MediaStore.Images.Thumbnails.MINI_KIND);
        model.setThumbnail(thumbnail != null ? (AppUtil.getImagePath(context.getApplicationContext(), thumbnail)) : null);
        model.setVideoUrl(imagePath);
    } else {
        model.setThumbnail(imagePath);
    }
    model.setUrl(imagePath);
    model.setType(mMimeType.name().toLowerCase());
    IntentUtil.deliverDataToInitialActivity((ServicesActivity) context, model, null);
}
Also used : Bitmap(android.graphics.Bitmap) AssetModel(com.chute.sdk.v2.model.AssetModel) File(java.io.File) Uri(android.net.Uri)

Example 15 with Bitmap

use of android.graphics.Bitmap in project photo-picker-plus-android by chute.

the class RippleView method getCircleBitmap.

private Bitmap getCircleBitmap(final int radius) {
    final Bitmap output = Bitmap.createBitmap(originBitmap.getWidth(), originBitmap.getHeight(), Bitmap.Config.ARGB_8888);
    final Canvas canvas = new Canvas(output);
    final Paint paint = new Paint();
    final Rect rect = new Rect((int) (x - radius), (int) (y - radius), (int) (x + radius), (int) (y + radius));
    paint.setAntiAlias(true);
    canvas.drawARGB(0, 0, 0, 0);
    canvas.drawCircle(x, y, radius, paint);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(originBitmap, rect, rect, paint);
    return output;
}
Also used : Bitmap(android.graphics.Bitmap) Rect(android.graphics.Rect) PorterDuffXfermode(android.graphics.PorterDuffXfermode) Canvas(android.graphics.Canvas) Paint(android.graphics.Paint)

Aggregations

Bitmap (android.graphics.Bitmap)3662 Canvas (android.graphics.Canvas)875 Paint (android.graphics.Paint)697 BitmapDrawable (android.graphics.drawable.BitmapDrawable)447 IOException (java.io.IOException)384 Rect (android.graphics.Rect)338 Test (org.junit.Test)255 File (java.io.File)253 Matrix (android.graphics.Matrix)250 Drawable (android.graphics.drawable.Drawable)241 BitmapFactory (android.graphics.BitmapFactory)236 View (android.view.View)220 ImageView (android.widget.ImageView)205 FileOutputStream (java.io.FileOutputStream)182 Intent (android.content.Intent)177 InputStream (java.io.InputStream)165 FileNotFoundException (java.io.FileNotFoundException)150 RectF (android.graphics.RectF)148 Point (android.graphics.Point)146 Uri (android.net.Uri)117