Exemplo n.º 1
0
 private void startPlayVideoActivity() {
     IImage image = mAllImages.getImageAt(mCurrentPosition);
     Intent intent = new Intent(
             Intent.ACTION_VIEW, image.fullSizeImageUri());
     try {
         startActivity(intent);
     } catch (android.content.ActivityNotFoundException ex) {
         Log.e(TAG, "Couldn't view video " + image.fullSizeImageUri(), ex);
     }
 }
Exemplo n.º 2
0
  /**
   * handles an image report item and returns an image URL
   *
   * @param image represents the image design information
   * @param context context information
   * @param prefix image prefix in URL
   * @param needMap whether image map is needed
   * @return URL for the image
   */
  protected String handleImage(IImage image, Object context, String prefix, boolean needMap) {
    String mapID = null;
    if (needMap) {
      mapID = getImageMapID(image);
      if (map.containsKey(mapID)) {
        synchronized (map) {
          return (String) map.get(mapID);
        }
      }
    }
    String ret = null;
    if (context != null && (context instanceof HTMLRenderContext)) {
      HTMLRenderContext myContext = (HTMLRenderContext) context;
      String imageURL = myContext.getBaseImageURL();
      String imageDir = myContext.getImageDirectory();
      if (imageURL == null
          || imageURL.length() == 0
          || imageDir == null
          || imageDir.length() == 0) {
        log.log(Level.SEVERE, "imageURL or ImageDIR is not set!"); // $NON-NLS-1$
        return null;
      }

      String extension = image.getExtension();
      String fileName = createUniqueFileName(imageDir, prefix, extension);
      File file = new File(imageDir, fileName); // $NON-NLS-1$
      try {
        image.writeImage(file);
      } catch (IOException e) {
        log.log(Level.SEVERE, e.getMessage(), e);
      }
      // servlet mode
      if (imageURL.indexOf("?") > 0) // $NON-NLS-1$
      {
        ret = imageURL + fileName;
      } else if (imageURL.endsWith("/")) // $NON-NLS-1$
      {
        ret = imageURL + fileName;
      } else {
        ret = imageURL + "/" + fileName; // $NON-NLS-1$
      }

      if (needMap) {
        synchronized (map) {
          map.put(mapID, ret);
        }
      }

    } else {
      ret = handleTempImage(image, prefix, needMap);
    }

    return ret;
  }
Exemplo n.º 3
0
 private void startShareMediaActivity(IImage image) {
     boolean isVideo = image instanceof VideoObject;
     Intent intent = new Intent();
     intent.setAction(Intent.ACTION_SEND);
     intent.setType(image.getMimeType());
     intent.putExtra(Intent.EXTRA_STREAM, image.fullSizeImageUri());
     try {
         startActivity(Intent.createChooser(intent, getText(
                 isVideo ? R.string.sendVideo : R.string.sendImage)));
     } catch (android.content.ActivityNotFoundException ex) {
         Toast.makeText(this, isVideo
                 ? R.string.no_way_to_share_image
                 : R.string.no_way_to_share_video,
                 Toast.LENGTH_SHORT).show();
     }
 }
Exemplo n.º 4
0
 /**
  * (non-Javadoc)
  *
  * @deprecated
  * @see
  *     org.eclipse.birt.report.engine.api2.IHTMLImageHandler#onURLImage(org.eclipse.birt.report.engine.api2.IImage,
  *     java.lang.Object)
  */
 public String onURLImage(IImage image, Object context) {
   assert (image != null);
   String uri = image.getID();
   if (uri.startsWith("http:") || uri.startsWith("https:")) {
     return uri;
   }
   return handleImage(image, context, "uri", true); // $NON-NLS-1$
 }
Exemplo n.º 5
0
 public boolean removeImage(IImage image) {
   // TODO: need to delete the thumbnails as well
   if (mContentResolver.delete(image.fullSizeImageUri(), null, null) > 0) {
     ((BaseImage) image).onRemove();
     invalidateCursor();
     invalidateCache();
     return true;
   } else {
     return false;
   }
 }
Exemplo n.º 6
0
 public void onClick(View v) {
     switch (v.getId()) {
         case R.id.btn_delete:
             MenuHelper.deleteImage(this, mDeletePhotoRunnable,
                     mAllImages.getImageAt(mCurrentPosition));
             break;
         case R.id.btn_play:
             startPlayVideoActivity();
             break;
         case R.id.btn_share: {
             IImage image = mAllImages.getImageAt(mCurrentPosition);
             if (!MenuHelper.isWhiteListUri(image.fullSizeImageUri())) {
                 return;
             }
             startShareMediaActivity(image);
             break;
         }
         case R.id.btn_set_as: {
             IImage image = mAllImages.getImageAt(mCurrentPosition);
             Intent intent = Util.createSetAsIntent(image);
             try {
                 startActivity(Intent.createChooser(
                         intent, getText(R.string.setImage)));
             } catch (android.content.ActivityNotFoundException ex) {
                 Toast.makeText(this, R.string.no_way_to_share_video,
                         Toast.LENGTH_SHORT).show();
             }
             break;
         }
         case R.id.btn_done:
             finish();
             break;
         case R.id.next_image:
             moveNextOrPrevious(1);
             break;
         case R.id.prev_image:
             moveNextOrPrevious(-1);
             break;
     }
 }
Exemplo n.º 7
0
 /**
  * returns the unique identifier for the image
  *
  * @param image the image object
  * @return the image id
  */
 protected String getImageMapID(IImage image) {
   if (image.getReportRunnable() != null) {
     return image.getReportRunnable().hashCode() + image.getID();
   }
   return image.getID();
 }
Exemplo n.º 8
0
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (mViewImage.mPaused) return false;

        // Don't respond to arrow keys if trackball scrolling is not enabled
        if (!mEnableTrackballScroll) {
            if ((keyCode >= KeyEvent.KEYCODE_DPAD_UP)
                    && (keyCode <= KeyEvent.KEYCODE_DPAD_RIGHT)) {
                return super.onKeyDown(keyCode, event);
            }
        }

        int current = mViewImage.mCurrentPosition;

        int nextImagePos = -2; // default no next image
        try {
            switch (keyCode) {
                case KeyEvent.KEYCODE_DPAD_CENTER: {
                    if (mViewImage.isPickIntent()) {
                        IImage img = mViewImage.mAllImages
                                .getImageAt(mViewImage.mCurrentPosition);
                        mViewImage.setResult(ReviewImage.RESULT_OK,
                                 new Intent().setData(img.fullSizeImageUri()));
                        mViewImage.finish();
                    }
                    break;
                }
                case KeyEvent.KEYCODE_DPAD_LEFT: {
                    if (getScale() <= 1F && event.getEventTime()
                            >= mNextChangePositionTime) {
                        nextImagePos = current - 1;
                        mNextChangePositionTime = event.getEventTime() + 500;
                    } else {
                        panBy(PAN_RATE, 0);
                        center(true, false);
                    }
                    return true;
                }
                case KeyEvent.KEYCODE_DPAD_RIGHT: {
                    if (getScale() <= 1F && event.getEventTime()
                            >= mNextChangePositionTime) {
                        nextImagePos = current + 1;
                        mNextChangePositionTime = event.getEventTime() + 500;
                    } else {
                        panBy(-PAN_RATE, 0);
                        center(true, false);
                    }
                    return true;
                }
                case KeyEvent.KEYCODE_DPAD_UP: {
                    panBy(0, PAN_RATE);
                    center(false, true);
                    return true;
                }
                case KeyEvent.KEYCODE_DPAD_DOWN: {
                    panBy(0, -PAN_RATE);
                    center(false, true);
                    return true;
                }
                case KeyEvent.KEYCODE_DEL:
                    MenuHelper.deletePhoto(
                            mViewImage, mViewImage.mDeletePhotoRunnable);
                    break;
            }
        } finally {
            if (nextImagePos >= 0
                    && nextImagePos < mViewImage.mAllImages.getCount()) {
                synchronized (mViewImage) {
                    mViewImage.setImage(nextImagePos, true);
                }
           } else if (nextImagePos != -2) {
               center(true, true);
           }
        }

        return super.onKeyDown(keyCode, event);
    }
Exemplo n.º 9
0
 private Uri getCurrentUri() {
     if (mAllImages.getCount() == 0) return null;
     IImage image = mAllImages.getImageAt(mCurrentPosition);
     return image.fullSizeImageUri();
 }
Exemplo n.º 10
0
    void setImage(int pos, boolean showControls) {
        mCurrentPosition = pos;

        Bitmap b = mCache.getBitmap(pos);
        if (b != null) {
            IImage image = mAllImages.getImageAt(pos);
            mImageView.setImageRotateBitmapResetBase(
                    new RotateBitmap(b, image.getDegreesRotated()), true);
            updateZoomButtonsEnabled();
        }

        ImageGetterCallback cb = new ImageGetterCallback() {
            public void completed() {
            }

            public boolean wantsThumbnail(int pos, int offset) {
                return !mCache.hasBitmap(pos + offset);
            }

            public boolean wantsFullImage(int pos, int offset) {
                return offset == 0;
            }

            public int fullImageSizeToUse(int pos, int offset) {
                // this number should be bigger so that we can zoom.  we may
                // need to get fancier and read in the fuller size image as the
                // user starts to zoom.
                // Originally the value is set to 480 in order to avoid OOM.
                // Now we set it to 2048 because of using
                // native memory allocation for Bitmaps.
                final int imageViewSize = 2048;
                return imageViewSize;
            }

            public int [] loadOrder() {
                return sOrderAdjacents;
            }

            public void imageLoaded(int pos, int offset, RotateBitmap bitmap,
                                    boolean isThumb) {
                // shouldn't get here after onPause()

                // We may get a result from a previous request. Ignore it.
                if (pos != mCurrentPosition) {
                    bitmap.recycle();
                    return;
                }

                if (isThumb) {
                    mCache.put(pos + offset, bitmap.getBitmap());
                }
                if (offset == 0) {
                    // isThumb: We always load thumb bitmap first, so we will
                    // reset the supp matrix for then thumb bitmap, and keep
                    // the supp matrix when the full bitmap is loaded.
                    mImageView.setImageRotateBitmapResetBase(bitmap, isThumb);
                    updateZoomButtonsEnabled();
                }
            }
        };

        // Could be null if we're stopping a slide show in the course of pausing
        if (mGetter != null) {
            mGetter.setPosition(pos, cb, mAllImages, mHandler);
        }
        updateActionIcons();
        if (showControls) showOnScreenControls();
        scheduleDismissOnScreenControls();
    }