Beispiel #1
0
 protected void recycle() {
   if (_thumb != null) {
     _thumb.recycle();
     _thumb = null;
     MLog.i(TAG, "PhotoChoosingActivity.recycle() _thumb was recycled");
   }
   if (_pic != null) {
     _pic.recycle();
     _pic = null;
     MLog.i(TAG, "PhotoChoosingActivity.recycle() _pic was recycled");
   }
 }
Beispiel #2
0
  /**
   * go grab the remote emoticons
   *
   * @param delay - start grabbing after this many milliseconds
   */
  public void fetchEmoticons(
      final int delay, final boolean forceFetch, final DisplayMetrics displayMetrics) {

    _dm = displayMetrics;

    if (!forceFetch) {
      synchronized (this) {
        if (_isRunning) {
          MLog.d(TAG, "RemoteEmoticonMgr.fetchEmoticons()  already issued fetch");
          return;
        }
        _isRunning = true;
      }
    }
    _isReady = false;
    try {
      Thread.sleep(delay);
    } catch (final InterruptedException e) {
    }

    new Thread() {
      public void run() {
        initBlocking();
      }
    }.start();
  }
Beispiel #3
0
  private void createThumb(final Bitmap pic) {
    if (_thumb != null) {
      _thumb.recycle();
    }

    MLog.i(TAG, "PhotoChoosingActivity createThumb() before creating thumb..");

    _thumb =
        Bitmap.createScaledBitmap(pic, GmobApp.SCALED_THUMB_SIZE, GmobApp.SCALED_THUMB_SIZE, true);

    MLog.i(TAG, "PhotoChoosingActivity createThumb() created _thumb");

    try {
      ImageUtils.writeBitmapToFile(_thumb, TEMP_THUMB_PATH_ON_DISK);
    } catch (final Exception e) {
      MLog.i(TAG, "", e);
    }
  }
Beispiel #4
0
        @Override
        public void handleMessage(final Message msg) {

          dismissProgressDialog();

          MLog.i(TAG, "PhotoChoosingActivity _photoDoneHandler msg.arg1 = " + msg.arg1);

          if (msg.arg1 == EVENT_PHOTO_PROC_SUCCESS) {

            handleThumbAndPicReady(_thumbFile, _picFile);

          } else {
            Toast.makeText(_this, R.string.error, Toast.LENGTH_SHORT).show();
          }
        }
Beispiel #5
0
  @Override
  public void onCreate(final Bundle savedInstanceState) {

    MLog.i(TAG, "PhotoChoosingActivity.onCreate()");
    super.onCreate(savedInstanceState);

    ThreadWrapper.executeInWorkerThread(
        new Task() {
          @Override
          public void execute() {
            TEMP_PIC_PATH_ON_DISK = CacheUtils.getExternalCacheDir(_this).getPath() + "/photo.jpg";
            TEMP_THUMB_PATH_ON_DISK =
                CacheUtils.getExternalCacheDir(_this).getPath() + "/thumb.jpg";
            _thumbFile = new File(TEMP_THUMB_PATH_ON_DISK);
            _picFile = new File(TEMP_PIC_PATH_ON_DISK);
          }
        });
  }
Beispiel #6
0
  @Override
  public void onActivityResult(final int requestCode, final int resultCode, final Intent intent) {

    MLog.i(
        TAG,
        "PhotoChoosingActivity.onActivityResult() resultCode="
            + (resultCode == Activity.RESULT_OK)
            + " requestCode == "
            + requestCode);

    super.onActivityResult(requestCode, resultCode, intent);

    if (requestCode == REQUEST_SELECT_PHOTO && resultCode == Activity.RESULT_OK) {
      final Uri uri = intent.getData();
      preProcessPhoto(uri);
    } else if (requestCode == REQUEST_SNAP_A_PHOTO && resultCode == Activity.RESULT_OK) {
      capturedPhoto = true;
      final Uri uri = Uri.fromFile(_picFile);
      preProcessPhoto(uri);
    }
  }
Beispiel #7
0
 @Override
 public void onDestroy() {
   MLog.i(TAG, "PhotoChoosingActivity.onDestroy()");
   recycle();
   super.onDestroy();
 }
Beispiel #8
0
  /** call this within a thread */
  private void createFinalPic() {

    MLog.i(TAG, "PhotoChoosingActivity createFinalPic() ..");

    final Bitmap picToBeRecycled = _pic;

    int newWidth = 0, newHeight = 0;

    int shorter, longer;

    if (GmobApp.DISPLAY_METRICS.widthPixels > GmobApp.DISPLAY_METRICS.heightPixels) {
      longer = GmobApp.DISPLAY_METRICS.widthPixels;
      shorter = GmobApp.DISPLAY_METRICS.heightPixels;
    } else {
      longer = GmobApp.DISPLAY_METRICS.heightPixels;
      shorter = GmobApp.DISPLAY_METRICS.widthPixels;
    }

    /*
     * If it's a portrait mode oriented photo, then don't allow the height
     * to be longer than the longest length of the phone
     *
     * If it's a landscape mode oriented photo, then don't allow the width
     * to be longer than the longest length of the phone
     *
     * Lastly, we can't keep the original dimensions of the photo, because
     * it's just too big for mobile viewing.
     */
    if (_pic.getHeight() > _pic.getWidth()) { // it's a portrait mode
      // picture
      newWidth = shorter;
      newHeight = longer;
    } else { // it's a landscape mode picture
      newWidth = longer;
      newHeight = shorter;
    }

    /*
     * lastly, if the photo is actually smaller than the dimensions of the
     * phone, then just use those dimensions
     */
    if (_pic.getWidth() < newWidth) {
      newWidth = _pic.getWidth();
    }

    if (_pic.getHeight() < newHeight) {
      newHeight = _pic.getHeight();
    }

    _pic = ImageUtils.scale(_pic, newWidth, newHeight);

    if (picToBeRecycled != null && !picToBeRecycled.isRecycled()) {
      picToBeRecycled.recycle();
    }
    MLog.i(
        TAG,
        "PhotoChoosingActivity createFinalPicAndThumb() was successful, pic width="
            + _pic.getWidth()
            + " pic Height="
            + _pic.getHeight());
  }
Beispiel #9
0
  private void initBlocking() {
    try {
      final HashMap<String, String> code2Id = new HashMap<String, String>(20);
      final HashMap<Integer, Drawable> id2File = new HashMap<Integer, Drawable>(20);

      MLog.d(TAG, "RemoteEmoticonMgr.initBlocking()..");
      final JSONArray emoticons = WebService.instance.getEmoticons();
      for (int i = 0; i < emoticons.length(); i++) {
        final JSONObject emo = emoticons.getJSONObject(i);
        final String code = emo.getString("code");
        final String link = emo.getString("link");
        final String descr = emo.optString("descr", "");
        final int id = emo.getInt("id");

        final File localImage =
            new File(GmobApp.DIR_EXTRA_PICS + '/' + StringUtils.getImageFilenameFromURL(link));
        if (descr.contains("remove from cache") && localImage.exists()) {
          localImage.delete();
        }
        /*
         * we chose Globals.DIR_EXTRA_PICS because its cached files
         * last 12 days as opposed to DIR_MEDIA which lasts only 12 hours
         * false param = don't return the drawable object, we just
         * want to know by it finishing that it exists on the file system
         */
        MLog.d(TAG, "RemoteEmoticonMgr.initBlocking() about to grab " + emo.toString());
        if (!localImage.exists()) {
          HttpUtils.saveHttpFile(link, localImage.getPath());
        }

        final BitmapFactory.Options opts = new BitmapFactory.Options();
        opts.inDither = false;
        opts.inDensity =
            DisplayMetrics.DENSITY_MEDIUM; // this can be dangerous to assume but watever
        opts.inScaled = true;
        opts.inTargetDensity = _dm.densityDpi;

        final Bitmap b = BitmapFactory.decodeFile(localImage.getPath(), opts);
        // final Bitmap b2 = ImageUtils.scale(b, (int)(b.getWidth() * 1.5f)+10, (int)(b.getHeight()
        // * 1.5f)+10);
        // b.recycle();

        final Drawable d = new BitmapDrawable(b);
        d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
        code2Id.put(code, "<img src=\"" + (256 + id) + "\" />");
        id2File.put(256 + id, d);
      }
      final String[] codes = new String[code2Id.size()];
      int j = 0;
      for (final String c : code2Id.keySet()) {
        codes[j++] = c;
      }
      _id2File = id2File;
      _code2Id = code2Id;
      _codes = codes;
      _isReady = true;
      _isRunning = false;
    } catch (final Exception e) {
      MLog.d(TAG, "", e);
      _failedToLoad = true;
      _isRunning = false;
    }
  }