예제 #1
0
  public void draw(Canvas canvas) {
    super.draw(canvas);
    float scale = getResources().getDisplayMetrics().density;
    int paddSize = (int) (GAPPING * scale + 0.5f);
    int bmWidth = bg.getBitmap().getWidth();
    Rect rect = new Rect(0, 0, getWidth(), getHeight());
    for (int x = 0; x < rect.width(); x += bmWidth) {
      RectF dstRect = new RectF(x, paddSize, getWidth() + x, getHeight() - paddSize);
      canvas.drawBitmap(bg.getBitmap(), null, dstRect, null);
    }
    bmWidth = midBg.getIntrinsicWidth();
    for (int x = 0; x < rect.width(); x += bmWidth) {
      Rect dstRectMid =
          new Rect(
              x,
              getHeight() - midBg.getIntrinsicHeight() - paddSize,
              midBg.getIntrinsicWidth() + x,
              getHeight() - paddSize);
      canvas.drawBitmap(midBg.getBitmap(), null, dstRectMid, null);
    }

    bmWidth = forBg.getIntrinsicWidth();
    for (int x = 0; x < rect.width(); x += bmWidth) {
      Rect dstRectMid =
          new Rect(
              x,
              getHeight() - forBg.getIntrinsicHeight() - paddSize,
              forBg.getIntrinsicWidth() + x,
              getHeight() - paddSize);
      canvas.drawBitmap(forBg.getBitmap(), null, dstRectMid, null);
    }
  }
예제 #2
0
 @Override
 protected void onLayout(boolean changed, int l, int t, int r, int b) {
   View view = resolveView();
   if (view != null) {
     int width = getMeasuredWidth();
     int height = getMeasuredHeight();
     @Px
     int leftLineWidth = leftBorder == BorderMode.LINE ? 1 : leftPageBorder.getIntrinsicWidth();
     @Px
     int rightLineWidth =
         rightBorder == BorderMode.HIDDEN ? 0 : rightPageBorder.getIntrinsicWidth();
     int headerFooterHeight = 0;
     view.layout(
         leftLineWidth, headerFooterHeight, width - rightLineWidth, height - headerFooterHeight);
     if (errorLayout != null) {
       int errorLayoutWidth = errorLayout.getMeasuredWidth();
       int errorLayoutHeight = errorLayout.getMeasuredHeight();
       int leftRightOffset = ((width - (leftLineWidth + rightLineWidth)) - errorLayoutWidth) / 2;
       int topBottomOffset = ((height - 2 * headerFooterHeight) - errorLayoutHeight) / 2;
       errorLayout.layout(
           leftLineWidth + leftRightOffset,
           headerFooterHeight + topBottomOffset,
           leftLineWidth + leftRightOffset + errorLayoutWidth,
           headerFooterHeight + topBottomOffset + errorLayoutHeight);
     }
   }
 }
 private void applyRenderers() {
   if (renderers != null) {
     Spannable spannableString = new SpannableString(view.getText());
     Set<String> spanPatterns = renderers.keySet();
     for (String spanPattern : spanPatterns) {
       Pattern pattern = Pattern.compile(spanPattern);
       Matcher matcher = pattern.matcher(spannableString);
       while (matcher.find()) {
         int end = matcher.end();
         int start = matcher.start();
         ViewSpanRenderer renderer = renderers.get(spanPattern);
         String text = matcher.group(0);
         View view = renderer.getView(text, context);
         BitmapDrawable bitmpaDrawable = (BitmapDrawable) ViewUtils.convertViewToDrawable(view);
         bitmpaDrawable.setBounds(
             UPPER_LEFT_X,
             UPPER_LEFT_Y,
             bitmpaDrawable.getIntrinsicWidth(),
             bitmpaDrawable.getIntrinsicHeight());
         spannableString.setSpan(
             new ImageSpan(bitmpaDrawable), start, end, DEFAULT_RENDER_APPLY_MODE);
         if (renderer instanceof ViewSpanClickListener) {
           enableClickEvents();
           ClickableSpan clickableSpan = getClickableSpan(text, (ViewSpanClickListener) renderer);
           spannableString.setSpan(clickableSpan, start, end, DEFAULT_RENDER_APPLY_MODE);
         }
       }
     }
     view.setText(spannableString);
   }
 }
  public void drawMarkerCentered(GeoPoint geoPoint, BitmapDrawable bitmap) {
    int width = bitmap.getIntrinsicWidth();
    int height = bitmap.getIntrinsicHeight();
    Point point = getPoint(geoPoint);

    mCanvas.drawBitmap(bitmap.getBitmap(), point.x - width / 2, point.y - height / 2, null);
  }
예제 #5
0
  /** Check weather this imageTask has cache Drawable data. */
  public boolean queryCache(ImageTask imageTask, CubeImageView imageView) {
    if (null == mImageProvider) {
      return false;
    }
    BitmapDrawable drawable = mImageProvider.getBitmapFromMemCache(imageTask);

    if (imageTask.getStatistics() != null) {
      imageTask.getStatistics().s0_afterCheckMemoryCache(drawable != null);
    }
    if (drawable == null) {
      return false;
    }

    if (DEBUG) {
      CLog.d(
          LOG_TAG,
          MSG_HIT_CACHE,
          imageTask,
          drawable.getIntrinsicWidth(),
          drawable.getIntrinsicHeight());
    }
    imageTask.addImageView(imageView);
    imageTask.onLoadTaskFinish(drawable, mImageLoadHandler);
    return true;
  }
        @Override
        public void onClick(View v) {

          try {
            BitmapDrawable bmp = null;
            int bmpW = 0, bmpH = 0;

            if (bmp != null) {
              bmp = null;
            }

            switch (mImageCounter) {
              case 0:
                bmp = (BitmapDrawable) getResources().getDrawable(R.drawable.img_big1);
                break;
              case 1:
                bmp = (BitmapDrawable) getResources().getDrawable(R.drawable.img_big3);
                break;
              case 2:
                bmp = (BitmapDrawable) getResources().getDrawable(R.drawable.img_big3);
                break;
              case 3:
                bmp = (BitmapDrawable) getResources().getDrawable(R.drawable.img_big4);
                break;
              case 4:
                bmp = (BitmapDrawable) getResources().getDrawable(R.drawable.img_big5);
                break;
              default:
                break;
            }

            // 불러온 이미지의 가로, 세로 너비를 구한다.
            bmpW = bmp.getIntrinsicWidth();
            bmpH = bmp.getIntrinsicHeight();

            mImageCounter++;

            if (mImageCounter > 4) {
              mImageCounter = 0;
            }

            mImgView.setImageDrawable(bmp);
            mImgView.getLayoutParams().width = bmpW;
            mImgView.getLayoutParams().height = bmpH;

          } catch (OutOfMemoryError error) {
            Log.e("TEST", error.toString());
          }
        }
예제 #7
0
  @Override
  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);

    View view = resolveView();
    if (view != null) {
      int width = MeasureSpec.getSize(widthMeasureSpec);
      int height = MeasureSpec.getSize(heightMeasureSpec);
      int leftLineWidth = leftBorder == BorderMode.LINE ? 1 : leftPageBorder.getIntrinsicWidth();
      int rightLineWidth =
          rightBorder == BorderMode.HIDDEN ? 0 : rightPageBorder.getIntrinsicWidth();
      int headerFooterHeight = 0;
      width = width - (leftLineWidth + rightLineWidth + viewPaddingSmall + viewPaddingLarge);
      height = height - 2 * headerFooterHeight;
      view.measure(
          MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY),
          MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY));
      if (errorLayout != null) {
        errorLayout.measure(
            MeasureSpec.makeMeasureSpec(width, MeasureSpec.AT_MOST),
            MeasureSpec.makeMeasureSpec(height, MeasureSpec.AT_MOST));
      }
    }
  }
예제 #8
0
  private void loadTask() {
    String dataString = "";
    if (task.repetition != null) dataString += "Repetitions: " + task.repetition + '\n';
    if (task.holdTime != null) dataString += "Hold Time: " + task.holdTime + '\n';

    data.setText(dataString);

    txt.setText(task.longName);
    des.setText(task.text);

    anima = new AnimationDrawable();
    Log.e("tag", "IdddddO Exception");
    try {
      Log.e("tag", "" + task.getFrames().get(0));
      still =
          new BitmapDrawable(
              MediaStore.Images.Media.getBitmap(getContentResolver(), task.getFrames().get(0)));
    } catch (FileNotFoundException e1) {
      Log.e("tag", "File Not Found");
    } catch (IOException e1) {
      Log.e("tag", "IO Exception");
    }
    Log.e("tag", "IdddddO Exception");
    int w = still.getIntrinsicWidth();
    int h = still.getIntrinsicHeight();
    img.setMinimumWidth(w * 2);
    img.setMinimumHeight(h * 2);
    Log.e("tag", "Safe ");
    for (int i = 0; i < task.getFrames().size(); i++) {
      Bitmap temp1;
      try {
        temp1 = MediaStore.Images.Media.getBitmap(getContentResolver(), task.getFrames().get(i));
        Log.i("tag", "hello1");
        BitmapDrawable drw = new BitmapDrawable(temp1);
        img.setBackgroundDrawable(drw);
        anima.addFrame(drw, task.frameTimes.get(i) * 1000);
      } catch (FileNotFoundException e) {
        e.printStackTrace();
      } catch (IOException e) {

        e.printStackTrace();
      }
    }
    Log.i("tag", "hello");
    img.setBackgroundDrawable(still);
  }
예제 #9
0
  /** 初始化各元素位置,大小 */
  protected void genRects() {
    Log.e("tttt", "view_height : " + view_height);

    /** 顶部logo大小,宽度是屏幕宽度三分之一 */
    int logo_width = image_logo.getIntrinsicWidth();
    int logo_height = image_logo.getIntrinsicHeight();
    int logo_target_width = view_width / 2;
    int logo_target_height = logo_height * logo_target_width / logo_width;

    /** 顶部logo位置,x轴是二分之一,y轴是三分之一 */
    rect_logo = new Rect();
    rect_logo.left = view_width / 2 - logo_target_width / 2;
    rect_logo.right = view_width / 2 + logo_target_width / 2;
    rect_logo.top = view_height / 2 - logo_target_height / 2;
    rect_logo.bottom = view_height / 2 + logo_target_height / 2;

    image_logo.setBounds(rect_logo);
  }
예제 #10
0
  /**
   * 功能简述: 功能详细描述: 注意:
   *
   * @param drawable
   * @param w
   * @param h
   * @param res
   * @return
   */
  public static BitmapDrawable clipDrawable(BitmapDrawable drawable, int w, int h, Resources res) {
    if (drawable != null) {
      int width = drawable.getIntrinsicWidth();
      int height = drawable.getIntrinsicHeight();
      if (width < w) {
        w = width;
      }
      if (height < h) {
        h = height;
      }
      int x = (width - w) >> 1;
      int y = (height - h) >> 1;
      Matrix matrix = new Matrix(); // 创建操作图片用的 Matrix 对象

      // 建立新的bitmap,其内容是对原bitmap的缩放后的图
      Bitmap newbmp = Bitmap.createBitmap(drawable.getBitmap(), x, y, w, h, matrix, true);
      matrix = null;
      // 把 bitmap 转换成 drawable 并返回
      return new BitmapDrawable(res, newbmp);
    }
    return null;
  }
예제 #11
0
 @Override
 public int getIntrinsicWidth() {
   return mDrawable.getIntrinsicWidth();
 }
  public Bitmap generateWidgetPreview(
      ComponentName provider,
      int previewImage,
      int iconId,
      int cellHSpan,
      int cellVSpan,
      int maxPreviewWidth,
      int maxPreviewHeight,
      Bitmap preview,
      int[] preScaledWidthOut) {
    // Load the preview image if possible
    String packageName = provider.getPackageName();
    if (maxPreviewWidth < 0) maxPreviewWidth = Integer.MAX_VALUE;
    if (maxPreviewHeight < 0) maxPreviewHeight = Integer.MAX_VALUE;

    Drawable drawable = null;
    if (previewImage != 0) {
      drawable = mPackageManager.getDrawable(packageName, previewImage, null);
      if (drawable == null) {
        Log.w(
            TAG,
            "Can't load widget preview drawable 0x"
                + Integer.toHexString(previewImage)
                + " for provider: "
                + provider);
      }
    }

    int previewWidth;
    int previewHeight;
    Bitmap defaultPreview = null;
    boolean widgetPreviewExists = (drawable != null);
    if (widgetPreviewExists) {
      previewWidth = drawable.getIntrinsicWidth();
      previewHeight = drawable.getIntrinsicHeight();
    } else {
      // Generate a preview image if we couldn't load one
      if (cellHSpan < 1) cellHSpan = 1;
      if (cellVSpan < 1) cellVSpan = 1;

      BitmapDrawable previewDrawable =
          (BitmapDrawable) mContext.getResources().getDrawable(R.drawable.widget_tile);
      final int previewDrawableWidth = previewDrawable.getIntrinsicWidth();
      final int previewDrawableHeight = previewDrawable.getIntrinsicHeight();
      previewWidth = previewDrawableWidth * cellHSpan;
      previewHeight = previewDrawableHeight * cellVSpan;

      defaultPreview = Bitmap.createBitmap(previewWidth, previewHeight, Config.ARGB_8888);
      final Canvas c = mCachedAppWidgetPreviewCanvas.get();
      c.setBitmap(defaultPreview);
      previewDrawable.setBounds(0, 0, previewWidth, previewHeight);
      previewDrawable.setTileModeXY(Shader.TileMode.REPEAT, Shader.TileMode.REPEAT);
      previewDrawable.draw(c);
      c.setBitmap(null);

      // Draw the icon in the top left corner
      int minOffset = (int) (mAppIconSize * sWidgetPreviewIconPaddingPercentage);
      int smallestSide = Math.min(previewWidth, previewHeight);
      float iconScale = Math.min((float) smallestSide / (mAppIconSize + 2 * minOffset), 1f);

      try {
        Drawable icon = null;
        int hoffset = (int) ((previewDrawableWidth - mAppIconSize * iconScale) / 2);
        int yoffset = (int) ((previewDrawableHeight - mAppIconSize * iconScale) / 2);
        if (iconId > 0) icon = mIconCache.getFullResIcon(packageName, iconId);
        if (icon != null) {
          renderDrawableToBitmap(
              icon,
              defaultPreview,
              hoffset,
              yoffset,
              (int) (mAppIconSize * iconScale),
              (int) (mAppIconSize * iconScale));
        }
      } catch (Resources.NotFoundException e) {
      }
    }

    // Scale to fit width only - let the widget preview be clipped in the
    // vertical dimension
    float scale = 1f;
    if (preScaledWidthOut != null) {
      preScaledWidthOut[0] = previewWidth;
    }
    if (previewWidth > maxPreviewWidth) {
      scale = maxPreviewWidth / (float) previewWidth;
    }
    if (scale != 1f) {
      previewWidth = (int) (scale * previewWidth);
      previewHeight = (int) (scale * previewHeight);
    }

    // If a bitmap is passed in, we use it; otherwise, we create a bitmap of the right size
    if (preview == null) {
      preview = Bitmap.createBitmap(previewWidth, previewHeight, Config.ARGB_8888);
    }

    // Draw the scaled preview into the final bitmap
    int x = (preview.getWidth() - previewWidth) / 2;
    if (widgetPreviewExists) {
      renderDrawableToBitmap(drawable, preview, x, 0, previewWidth, previewHeight);
    } else {
      final Canvas c = mCachedAppWidgetPreviewCanvas.get();
      final Rect src = mCachedAppWidgetPreviewSrcRect.get();
      final Rect dest = mCachedAppWidgetPreviewDestRect.get();
      c.setBitmap(preview);
      src.set(0, 0, defaultPreview.getWidth(), defaultPreview.getHeight());
      dest.set(x, 0, x + previewWidth, previewHeight);

      Paint p = mCachedAppWidgetPreviewPaint.get();
      if (p == null) {
        p = new Paint();
        p.setFilterBitmap(true);
        mCachedAppWidgetPreviewPaint.set(p);
      }
      c.drawBitmap(defaultPreview, src, dest, p);
      c.setBitmap(null);
    }
    return preview;
  }
예제 #13
0
  private void drawDrawable(Canvas canvas, Drawable drawable, int alpha) {
    if (drawable instanceof BitmapDrawable) {
      BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;

      Paint paint = bitmapDrawable.getPaint();
      boolean hasFilter = paint != null && paint.getColorFilter() != null;
      if (hasFilter && !isPressed) {
        bitmapDrawable.setColorFilter(null);
      } else if (!hasFilter && isPressed) {
        bitmapDrawable.setColorFilter(
            new PorterDuffColorFilter(0xffdddddd, PorterDuff.Mode.MULTIPLY));
      }
      if (colorFilter != null) {
        bitmapDrawable.setColorFilter(colorFilter);
      }
      if (bitmapShader != null) {
        drawRegion.set(imageX, imageY, imageX + imageW, imageY + imageH);
        if (isVisible) {
          roundRect.set(drawRegion);
          shaderMatrix.reset();
          shaderMatrix.setRectToRect(bitmapRect, roundRect, Matrix.ScaleToFit.FILL);
          bitmapShader.setLocalMatrix(shaderMatrix);
          roundPaint.setAlpha(alpha);
          canvas.drawRoundRect(roundRect, roundRadius, roundRadius, roundPaint);
        }
      } else {
        int bitmapW;
        int bitmapH;
        if (orientation == 90 || orientation == 270) {
          bitmapW = bitmapDrawable.getIntrinsicHeight();
          bitmapH = bitmapDrawable.getIntrinsicWidth();
        } else {
          bitmapW = bitmapDrawable.getIntrinsicWidth();
          bitmapH = bitmapDrawable.getIntrinsicHeight();
        }
        float scaleW = bitmapW / (float) imageW;
        float scaleH = bitmapH / (float) imageH;

        if (isAspectFit) {
          float scale = Math.max(scaleW, scaleH);
          canvas.save();
          bitmapW /= scale;
          bitmapH /= scale;
          drawRegion.set(
              imageX + (imageW - bitmapW) / 2,
              imageY + (imageH - bitmapH) / 2,
              imageX + (imageW + bitmapW) / 2,
              imageY + (imageH + bitmapH) / 2);
          bitmapDrawable.setBounds(drawRegion);
          try {
            bitmapDrawable.setAlpha(alpha);
            bitmapDrawable.draw(canvas);
          } catch (Exception e) {
            if (bitmapDrawable == currentImage && currentKey != null) {
              ImageLoader.getInstance().removeImage(currentKey);
              currentKey = null;
            } else if (bitmapDrawable == currentThumb && currentThumbKey != null) {
              ImageLoader.getInstance().removeImage(currentThumbKey);
              currentThumbKey = null;
            }
            setImage(
                currentImageLocation,
                currentHttpUrl,
                currentFilter,
                currentThumb,
                currentThumbLocation,
                currentThumbFilter,
                currentSize,
                currentExt,
                currentCacheOnly);
            FileLog.e("tmessages", e);
          }
          canvas.restore();
        } else {
          if (Math.abs(scaleW - scaleH) > 0.00001f) {
            canvas.save();
            canvas.clipRect(imageX, imageY, imageX + imageW, imageY + imageH);

            if (orientation != 0) {
              if (centerRotation) {
                canvas.rotate(orientation, imageW / 2, imageH / 2);
              } else {
                canvas.rotate(orientation, 0, 0);
              }
            }

            if (bitmapW / scaleH > imageW) {
              bitmapW /= scaleH;
              drawRegion.set(
                  imageX - (bitmapW - imageW) / 2,
                  imageY,
                  imageX + (bitmapW + imageW) / 2,
                  imageY + imageH);
            } else {
              bitmapH /= scaleW;
              drawRegion.set(
                  imageX,
                  imageY - (bitmapH - imageH) / 2,
                  imageX + imageW,
                  imageY + (bitmapH + imageH) / 2);
            }
            if (orientation == 90 || orientation == 270) {
              int width = (drawRegion.right - drawRegion.left) / 2;
              int height = (drawRegion.bottom - drawRegion.top) / 2;
              int centerX = (drawRegion.right + drawRegion.left) / 2;
              int centerY = (drawRegion.top + drawRegion.bottom) / 2;
              bitmapDrawable.setBounds(
                  centerX - height, centerY - width, centerX + height, centerY + width);
            } else {
              bitmapDrawable.setBounds(drawRegion);
            }
            if (isVisible) {
              try {
                bitmapDrawable.setAlpha(alpha);
                bitmapDrawable.draw(canvas);
              } catch (Exception e) {
                if (bitmapDrawable == currentImage && currentKey != null) {
                  ImageLoader.getInstance().removeImage(currentKey);
                  currentKey = null;
                } else if (bitmapDrawable == currentThumb && currentThumbKey != null) {
                  ImageLoader.getInstance().removeImage(currentThumbKey);
                  currentThumbKey = null;
                }
                setImage(
                    currentImageLocation,
                    currentHttpUrl,
                    currentFilter,
                    currentThumb,
                    currentThumbLocation,
                    currentThumbFilter,
                    currentSize,
                    currentExt,
                    currentCacheOnly);
                FileLog.e("tmessages", e);
              }
            }

            canvas.restore();
          } else {
            canvas.save();
            if (orientation != 0) {
              if (centerRotation) {
                canvas.rotate(orientation, imageW / 2, imageH / 2);
              } else {
                canvas.rotate(orientation, 0, 0);
              }
            }
            drawRegion.set(imageX, imageY, imageX + imageW, imageY + imageH);
            if (orientation == 90 || orientation == 270) {
              int width = (drawRegion.right - drawRegion.left) / 2;
              int height = (drawRegion.bottom - drawRegion.top) / 2;
              int centerX = (drawRegion.right + drawRegion.left) / 2;
              int centerY = (drawRegion.top + drawRegion.bottom) / 2;
              bitmapDrawable.setBounds(
                  centerX - height, centerY - width, centerX + height, centerY + width);
            } else {
              bitmapDrawable.setBounds(drawRegion);
            }
            if (isVisible) {
              try {
                bitmapDrawable.setAlpha(alpha);
                bitmapDrawable.draw(canvas);
              } catch (Exception e) {
                if (bitmapDrawable == currentImage && currentKey != null) {
                  ImageLoader.getInstance().removeImage(currentKey);
                  currentKey = null;
                } else if (bitmapDrawable == currentThumb && currentThumbKey != null) {
                  ImageLoader.getInstance().removeImage(currentThumbKey);
                  currentThumbKey = null;
                }
                setImage(
                    currentImageLocation,
                    currentHttpUrl,
                    currentFilter,
                    currentThumb,
                    currentThumbLocation,
                    currentThumbFilter,
                    currentSize,
                    currentExt,
                    currentCacheOnly);
                FileLog.e("tmessages", e);
              }
            }
            canvas.restore();
          }
        }
      }
    } else {
      drawRegion.set(imageX, imageY, imageX + imageW, imageY + imageH);
      drawable.setBounds(drawRegion);
      if (isVisible) {
        try {
          drawable.setAlpha(alpha);
          drawable.draw(canvas);
        } catch (Exception e) {
          FileLog.e("tmessages", e);
        }
      }
    }
  }
예제 #14
0
 @Override
 public int getIntrinsicWidth() {
   return image.getIntrinsicWidth();
 }
  /**
   * Test case for the behavior of the ContactsProvider's photos table It does not test any APIs in
   * android.provider.Contacts.java
   */
  @BrokenTest("Should not test EXISTS_ON_SERVER_INDEX?")
  public void testPhotosTable() {
    final String[] PHOTOS_PROJECTION =
        new String[] {
          Photos._ID,
          Photos.EXISTS_ON_SERVER,
          Photos.PERSON_ID,
          Photos.LOCAL_VERSION,
          Photos.DATA,
          Photos._SYNC_ACCOUNT,
          Photos._SYNC_ACCOUNT_TYPE,
          Photos._SYNC_ID,
          Photos._SYNC_TIME,
          Photos._SYNC_VERSION,
          Photos._SYNC_LOCAL_ID,
          Photos._SYNC_DIRTY,
          Photos.SYNC_ERROR
        };
    final int ID_INDEX = 0;
    final int EXISTS_ON_SERVER_INDEX = 1;
    final int PERSON_ID_INDEX = 2;
    final int LOCAL_VERSION_INDEX = 3;
    final int DATA_INDEX = 4;
    final int SYNC_ACCOUNT_NAME_INDEX = 5;
    final int SYNC_ACCOUNT_TYPE_INDEX = 6;
    final int SYNC_ID_INDEX = 7;
    final int SYNC_TIME_INDEX = 8;
    final int SYNC_VERSION_INDEX = 9;
    final int SYNC_LOCAL_ID_INDEX = 10;
    final int SYNC_DIRTY_INDEX = 11;
    final int SYNC_ERROR_INDEX = 12;

    String updatePhotosLocalVersion = "local_version1";

    try {
      Context context = getInstrumentation().getTargetContext();
      InputStream inputStream =
          context.getResources().openRawResource(com.android.cts.stub.R.drawable.testimage);
      int size = inputStream.available();
      byte[] data = new byte[size];
      inputStream.read(data);
      BitmapDrawable sourceDrawable =
          (BitmapDrawable)
              context.getResources().getDrawable(com.android.cts.stub.R.drawable.testimage);
      // Test: insert
      ContentValues value = new ContentValues();
      value.put(Photos.PERSON_ID, 1);
      value.put(Photos.LOCAL_VERSION, "local_version0");
      value.put(Photos.DATA, data);
      try {
        mProvider.insert(Photos.CONTENT_URI, value);
        fail("Should throw out UnsupportedOperationException.");
      } catch (UnsupportedOperationException e) {
        // Don't support direct insert operation to photos URI.
      }

      // Insert a people to insert a row in photos table.
      value.clear();
      value.put(PeopleColumns.NAME, "name_photos_test_stub");
      Uri peopleUri = mProvider.insert(People.CONTENT_URI, value);
      int peopleId = Integer.parseInt(peopleUri.getPathSegments().get(1));

      Cursor cursor =
          mProvider.query(
              Photos.CONTENT_URI,
              PHOTOS_PROJECTION,
              Photos.PERSON_ID + " = " + peopleId,
              null,
              null);
      assertTrue(cursor.moveToNext());
      assertEquals(0, cursor.getInt(EXISTS_ON_SERVER_INDEX));
      assertEquals(peopleId, cursor.getInt(PERSON_ID_INDEX));
      assertNull(cursor.getString(LOCAL_VERSION_INDEX));
      assertNull(cursor.getString(DATA_INDEX));
      // TODO: Figure out what can be tested for the SYNC_* columns
      int id = cursor.getInt(ID_INDEX);
      cursor.close();

      // Test: update
      value.clear();
      value.put(Photos.LOCAL_VERSION, updatePhotosLocalVersion);
      value.put(Photos.DATA, data);
      value.put(Photos.EXISTS_ON_SERVER, 1);

      Uri uri = ContentUris.withAppendedId(Photos.CONTENT_URI, id);
      mProvider.update(uri, value, null, null);
      cursor =
          mProvider.query(
              Photos.CONTENT_URI, PHOTOS_PROJECTION, Photos._ID + " = " + id, null, null);
      assertTrue(cursor.moveToNext());
      assertEquals(1, cursor.getInt(EXISTS_ON_SERVER_INDEX));
      assertEquals(peopleId, cursor.getInt(PERSON_ID_INDEX));
      assertEquals(updatePhotosLocalVersion, cursor.getString(LOCAL_VERSION_INDEX));
      byte resultData[] = cursor.getBlob(DATA_INDEX);
      InputStream resultInputStream = new ByteArrayInputStream(resultData);
      Bitmap bitmap = BitmapFactory.decodeStream(resultInputStream, null, null);
      assertEquals(sourceDrawable.getIntrinsicWidth(), bitmap.getWidth());
      assertEquals(sourceDrawable.getIntrinsicHeight(), bitmap.getHeight());
      // TODO: Figure out what can be tested for the SYNC_* columns
      cursor.close();

      // Test: delete
      mProvider.delete(peopleUri, null, null);
      cursor =
          mProvider.query(
              Photos.CONTENT_URI, PHOTOS_PROJECTION, Groups._ID + " = " + id, null, null);
      assertEquals(0, cursor.getCount());

      mProvider.delete(peopleUri, null, null);
    } catch (RemoteException e) {
      fail("Unexpected RemoteException");
    } catch (IOException e) {
      fail("Unexpected IOException");
    }
  }