コード例 #1
0
  public void onResume() {
    super.onResume();
    Log.d(TAG, "onResume()");

    Intent startingIntent = this.getIntent();
    selectedImage = startingIntent.getStringExtra("selected");
    Log.d(TAG, "selectedImage: " + selectedImage);
    oriTitle = startingIntent.getStringExtra("oriTitle");
    croppedTitle = startingIntent.getStringExtra("croppedTitle");
    annotated = startingIntent.getBooleanExtra("annotated", false);
    timestamps = startingIntent.getBundleExtra("timestamps");
    imageType = startingIntent.getStringExtra("img_type");
    Log.d(TAG, "annotated: " + annotated);
    Log.d(TAG, "nTs: " + timestamps.getLong("tsNot") + ", ts: " + timestamps.getLong("ts"));
    if (annotated) {
      this.bubbleTexts = startingIntent.getStringArrayListExtra("texts");
      this.bubbleTypes = startingIntent.getIntegerArrayListExtra("types");
      Log.d(TAG, "bubbleTexts: " + bubbleTexts.size());
      imageType = "annotated";
    }

    if (yourSelectedImage != null)
      if (yourSelectedImage.isRecycled()) yourSelectedImage.prepareToDraw();
    if (imageWithBubbles != null)
      if (imageWithBubbles.isRecycled()) imageWithBubbles.prepareToDraw();

    new WorkerTask().execute(Uri.parse(selectedImage));
  }
コード例 #2
0
  /** Takes a screenshot of the current display and shows an animation. */
  void takeScreenshot(Runnable finisher, boolean statusBarVisible, boolean navBarVisible) {
    // We need to orient the screenshot correctly (and the Surface api seems to take screenshots
    // only in the natural orientation of the device :!)
    mDisplay.getRealMetrics(mDisplayMetrics);
    float[] dims = {mDisplayMetrics.widthPixels, mDisplayMetrics.heightPixels};
    // float degrees = getDegreesForRotation(mDisplay.getRotation());
    int value = mDisplay.getRotation();
    String hwRotation = SystemProperties.get("ro.sf.hwrotation", "0");
    if (hwRotation.equals("270") || hwRotation.equals("90")) {
      value = (value + 3) % 4;
    }
    float degrees = getDegreesForRotation(value);
    boolean requiresRotation = (degrees > 0);
    if (requiresRotation) {
      // Get the dimensions of the device in its native orientation
      mDisplayMatrix.reset();
      mDisplayMatrix.preRotate(-degrees);
      mDisplayMatrix.mapPoints(dims);
      dims[0] = Math.abs(dims[0]);
      dims[1] = Math.abs(dims[1]);
    }

    // Take the screenshot
    mScreenBitmap = Surface.screenshot((int) dims[0], (int) dims[1]);
    if (mScreenBitmap == null) {
      notifyScreenshotError(mContext, mNotificationManager);
      finisher.run();
      return;
    }

    if (requiresRotation) {
      // Rotate the screenshot to the current orientation
      Bitmap ss =
          Bitmap.createBitmap(
              mDisplayMetrics.widthPixels, mDisplayMetrics.heightPixels, Bitmap.Config.ARGB_8888);
      Canvas c = new Canvas(ss);
      c.translate(ss.getWidth() / 2, ss.getHeight() / 2);
      c.rotate(degrees);
      c.translate(-dims[0] / 2, -dims[1] / 2);
      c.drawBitmap(mScreenBitmap, 0, 0, null);
      c.setBitmap(null);
      mScreenBitmap = ss;
    }

    // Optimizations
    mScreenBitmap.setHasAlpha(false);
    mScreenBitmap.prepareToDraw();

    // Start the post-screenshot animation
    startAnimation(
        finisher,
        mDisplayMetrics.widthPixels,
        mDisplayMetrics.heightPixels,
        statusBarVisible,
        navBarVisible);
  }