Example #1
0
    @Override
    public void onStop() {
        super.onStop();
        mPaused = true;

        // mGetter could be null if we call finish() and leave early in
        // onStart().
        if (mGetter != null) {
            mGetter.cancelCurrent();
            mGetter.stop();
            mGetter = null;
        }

        // removing all callback in the message queue
        mHandler.removeAllGetterCallbacks();

        if (mAllImages != null) {
            mSavedUri = getCurrentUri();
            mAllImages.close();
            mAllImages = null;
        }

        hideOnScreenControls();
        mImageView.clear();
        mCache.clear();

        for (ImageViewTouchBase iv : mSlideShowImageViews) {
            iv.clear();
        }
    }
Example #2
0
  @Override
  protected Bitmap doInBackground(String... arg0) {
    // TODO Auto-generated method stub
    if (bitmapReference != null) {}

    Bitmap bm = BitmapCache.getInstance().getBitmap(cookie, url);
    bitmapReference = new WeakReference<Bitmap>(bm);
    return bm;
  }
Example #3
0
 public Bitmap getPicture() {
   // mPicture is not null only if passed through
   // the ctor which is deprecated by now.
   if (mPicture == null) {
     BitmapCache cache = BitmapCache.getInstance();
     Bitmap picture = cache.getBitmapFromMemCache(mLocation);
     if (picture == null) {
       /* Not in memcache:
        * serving the file from the database and
        * adding it to the memcache for later use.
        */
       Context c = VLCApplication.getAppContext();
       picture = DatabaseManager.getInstance(c).getPicture(c, mLocation);
       cache.addBitmapToMemCache(mLocation, picture);
     }
     return picture;
   } else {
     return mPicture;
   }
 }
Example #4
0
    public void run() {
      Message msg = new Message();
      msg.arg2 = REQUEST_FRIENDS_TIMELINE;
      try {
        TwitterResponse statuses = twitter.getFriendsTimeline();

        // Load and cache all profile bitmaps
        BitmapCache cache = BitmapCache.getInstance();
        for (int i = 0; i < statuses.getNumberOfItems(); i++)
          cache.load(statuses.getItemAt(i).getUser().getProfileImageURL());

        msg.arg1 = RESPONSE_OK;
        msg.obj = statuses;
      } catch (TwitterConnectionException e) {
        msg.arg1 = RESPONSE_CONN_KO;
        msg.obj = e;
      } catch (Exception e) {
        msg.arg1 = RESPONSE_KO;
        msg.obj = e;
      }
      handler.sendMessage(msg);
    }
Example #5
0
 public void run() {
     mAllImages.removeImageAt(mCurrentPosition);
     if (mAllImages.getCount() == 0) {
         finish();
         return;
     } else {
         if (mCurrentPosition == mAllImages.getCount()) {
             mCurrentPosition -= 1;
         }
     }
     mImageView.clear();
     mCache.clear();  // Because the position number is changed.
     setImage(mCurrentPosition, true);
 }
  private void initialize() {
    if (!Preferences.loaded) loadPreferences(this);

    PreferenceManager.getDefaultSharedPreferences(context)
        .registerOnSharedPreferenceChangeListener(prefChangeListener);

    createNotification();

    connectionState = ConnectionState.CONNECTING;
    watchState = WatchStates.OFF;
    watchType = WatchType.DIGITAL;

    if (bluetoothAdapter == null) bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();

    powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
    wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "MetaWatch");

    Monitors.start(this /*, telephonyManager*/);

    // Initialise theme
    BitmapCache.getBitmap(context, "");

    start();
  }
  static Bitmap[] smartNotify(Context context, Bitmap icon, String header, String body) {

    Properties props = BitmapCache.getProperties(context, "notification_sticky.xml");

    final int textTop = Integer.parseInt(props.getProperty("textTop", "24"));
    final int textLeft = Integer.parseInt(props.getProperty("textLeft", "3"));
    final int textWidth = Integer.parseInt(props.getProperty("textWidth", "85"));
    final int textHeight = Integer.parseInt(props.getProperty("textHeight", "69"));

    final int iconTop = Integer.parseInt(props.getProperty("iconTop", "0"));
    final int iconLeft = Integer.parseInt(props.getProperty("iconLeft", "0"));

    final int headerLeft = Integer.parseInt(props.getProperty("headerLeft", "20"));
    final int headerBaseline = Integer.parseInt(props.getProperty("headerBaseline", "15"));

    final int headerColor =
        props.getProperty("headerColor", "white").equalsIgnoreCase("black")
            ? Color.BLACK
            : Color.WHITE;
    final int textColor =
        props.getProperty("textColor", "black").equalsIgnoreCase("black")
            ? Color.BLACK
            : Color.WHITE;

    final int arrowUpLeft = Integer.parseInt(props.getProperty("arrowUpLeft", "91"));
    final int arrowUpTop = Integer.parseInt(props.getProperty("arrowUpTop", "23"));

    final int arrowDownLeft = Integer.parseInt(props.getProperty("arrowDownLeft", "91"));
    final int arrowDownTop = Integer.parseInt(props.getProperty("arrowDownTop", "56"));

    final int closeLeft = Integer.parseInt(props.getProperty("closeLeft", "91"));
    final int closeTop = Integer.parseInt(props.getProperty("closeTop", "89"));

    FontInfo font = FontCache.instance(context).Get();

    List<Bitmap> bitmaps = new ArrayList<Bitmap>();

    Paint paintHead = new Paint();
    paintHead.setColor(headerColor);
    paintHead.setTextSize(FontCache.instance(context).Large.size);
    paintHead.setTypeface(FontCache.instance(context).Large.face);

    Paint paint = new Paint();
    paint.setColor(textColor);
    paint.setTextSize(font.size);
    paint.setTypeface(font.face);

    Paint whitePaint = new Paint();
    whitePaint.setColor(Color.WHITE);

    TextPaint textPaint = new TextPaint(paint);
    StaticLayout staticLayout =
        new StaticLayout(
            body, textPaint, textWidth, android.text.Layout.Alignment.ALIGN_NORMAL, 1.0f, 0, false);

    int iconHeight = 16;
    int iconOffset = 0;
    if (icon != null) {
      iconHeight = Math.max(16, icon.getHeight());
      iconOffset = iconHeight - icon.getHeight(); // align icon to bottom of text
    }

    int h = staticLayout.getHeight();
    int y = 0;
    int displayHeight = textHeight + 3;

    int scroll = textHeight - font.size;
    boolean more = true;

    int pages = 0;

    while (more) {
      more = false;
      Bitmap bitmap = Bitmap.createBitmap(96, 96, Bitmap.Config.RGB_565);
      Canvas canvas = new Canvas(bitmap);

      canvas.drawColor(Color.WHITE);

      canvas.drawBitmap(Utils.getBitmap(context, "notify_background_sticky.png"), 0, 0, null);

      canvas.save();
      canvas.translate(textLeft, textTop - y); // position the text
      canvas.clipRect(0, y, textWidth, textHeight + y);
      staticLayout.draw(canvas);
      canvas.restore();

      // Draw header
      if (icon != null) canvas.drawBitmap(icon, iconLeft, iconOffset + iconTop, paint);
      canvas.drawText(header, headerLeft, headerBaseline, paintHead);

      if (y > 0)
        canvas.drawBitmap(Utils.getBitmap(context, "arrow_up.bmp"), arrowUpLeft, arrowUpTop, null);

      if ((h - y) > (displayHeight) && pages < 10) {
        more = true;
        pages++;
        canvas.drawBitmap(
            Utils.getBitmap(context, "arrow_down.bmp"), arrowDownLeft, arrowDownTop, null);
      }

      canvas.drawBitmap(Utils.getBitmap(context, "close.bmp"), closeLeft, closeTop, null);

      y += scroll;
      bitmaps.add(bitmap);
    }

    Bitmap[] bitmapArray = new Bitmap[bitmaps.size()];
    bitmaps.toArray(bitmapArray);
    return bitmapArray;
  }
  static Bitmap smartLines(
      Context context, Bitmap icon, String header, String[] lines, FontCache.FontSize size) {

    Properties props = BitmapCache.getProperties(context, "notification.xml");

    final int textTop = Integer.parseInt(props.getProperty("textTop", "24"));
    final int textLeft = Integer.parseInt(props.getProperty("textLeft", "3"));
    final int textWidth = Integer.parseInt(props.getProperty("textWidth", "90"));
    final int textHeight = Integer.parseInt(props.getProperty("textHeight", "69"));

    final int iconTop = Integer.parseInt(props.getProperty("iconTop", "0"));
    final int iconLeft = Integer.parseInt(props.getProperty("iconLeft", "0"));

    final int headerLeft = Integer.parseInt(props.getProperty("headerLeft", "20"));
    final int headerBaseline = Integer.parseInt(props.getProperty("headerBaseline", "15"));

    final int headerColor =
        props.getProperty("headerColor", "white").equalsIgnoreCase("black")
            ? Color.BLACK
            : Color.WHITE;
    final int textColor =
        props.getProperty("textColor", "black").equalsIgnoreCase("black")
            ? Color.BLACK
            : Color.WHITE;

    FontInfo font = FontCache.instance(context).Get(size);

    Bitmap bitmap = Bitmap.createBitmap(96, 96, Bitmap.Config.RGB_565);
    Canvas canvas = new Canvas(bitmap);

    Paint paintHead = new Paint();
    paintHead.setColor(headerColor);
    paintHead.setTextSize(FontCache.instance(context).Large.size);
    paintHead.setTypeface(FontCache.instance(context).Large.face);

    Paint paint = new Paint();
    paint.setColor(textColor);
    paint.setTextSize(font.size);
    paint.setTypeface(font.face);

    canvas.drawColor(Color.WHITE);

    canvas.drawBitmap(Utils.getBitmap(context, "notify_background.png"), 0, 0, null);

    int iconHeight = 16;
    if (icon != null) {
      iconHeight = Math.max(16, icon.getHeight()); // make sure the text fits

      // align icon to bottom of text
      canvas.drawBitmap(icon, iconLeft, iconTop + iconHeight - icon.getHeight(), paint);
    }

    canvas.drawText(header, headerLeft, headerBaseline, paintHead);

    String body = "";
    for (String line : lines) {
      if (body.length() > 0) body += "\n\n";
      body += line;
    }

    TextPaint textPaint = new TextPaint(paint);
    StaticLayout staticLayout =
        new StaticLayout(
            body, textPaint, textWidth, android.text.Layout.Alignment.ALIGN_CENTER, 1.3f, 0, false);

    int layoutHeight = staticLayout.getHeight();
    int textY = textTop + (textHeight / 2) - (layoutHeight / 2);
    if (textY < textTop) textY = textTop;

    canvas.translate(textLeft, textY); // position the text
    staticLayout.draw(canvas);

    return bitmap;
  }
 /** {@inheritDoc} */
 public SimpleImageLoader(RequestQueue queue) {
   this(queue, BitmapCache.getInstance(null));
 }
Example #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();
    }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    setContentView(R.layout.main);
    super.onCreate(savedInstanceState);

    final BitmapCache ic = BitmapCache.initInstance(this);
    ic.readDir();

    final ImageView imageView1 = (ImageView) findViewById(R.id.imageView1);
    final ImageView imageView2 = (ImageView) findViewById(R.id.imageView2);
    final ImageView imageView3 = (ImageView) findViewById(R.id.imageView3);

    Button buttonLoad = (Button) findViewById(R.id.button1);
    Button buttonClear = (Button) findViewById(R.id.button2);

    Button buttonReset = (Button) findViewById(R.id.button3);

    buttonLoad.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View v) {
            ic.getImageForView(
                "http://cdn1.iconfinder.com/data/icons/gestureworks_gesture_glyphs/128/stroke_number_one_gestureworks.png",
                new OnBitmapReadyListener() {
                  @Override
                  public void onBitmapReady(Bitmap bitmap) {
                    imageView1.setImageBitmap(bitmap);
                  }
                });

            ic.getImageForView(
                "http://cdn1.iconfinder.com/data/icons/gestureworks_gesture_glyphs/128/stroke_number_two_gestureworks.png",
                new OnBitmapReadyListener() {
                  @Override
                  public void onBitmapReady(Bitmap bitmap) {
                    imageView2.setImageBitmap(bitmap);
                  }
                });

            ic.getImageForView(
                "http://cdn1.iconfinder.com/data/icons/gestureworks_gesture_glyphs/128/stroke_number_three_gestureworks.png",
                new OnBitmapReadyListener() {
                  @Override
                  public void onBitmapReady(Bitmap bitmap) {
                    imageView3.setImageBitmap(bitmap);
                  }
                });
          }
        });

    buttonClear.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View v) {
            ic.clearCache();
          }
        });

    buttonReset.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View v) {
            imageView1.setImageResource(R.drawable.ic_launcher);
            imageView2.setImageResource(R.drawable.ic_launcher);
            imageView3.setImageResource(R.drawable.ic_launcher);
          }
        });
  }
Example #12
0
  public void getPhoto(ImageView img) {
    final TL.Object location = getPhotoLocation();
    img.setTag(location);

    if (location == null) {
      img.setImageResource(getDefPhoto());
      return;
    }

    String path = FileQuery.exists(location);
    if (path != null) {
      Bitmap bmp = BitmapCache.get(path);
      if (bmp != null) {
        img.setImageBitmap(bmp);
        return;
      }
    }

    final WeakReference<ImageView> ref = new WeakReference<ImageView>(img);

    try {
      new FileQuery(
          location,
          null,
          new FileQuery.OnResultListener() {
            @Override
            public void onResult(TL.Object result) {
              ImageView img = ref.get();
              if (img == null || img.getTag() != location) return;

              final Bitmap bmp =
                  result != null
                      ? BitmapCache.loadBitmap(
                          result.getString("fileName"),
                          Main.SIZE_THUMB_USER,
                          Main.SIZE_THUMB_USER,
                          true,
                          false,
                          true)
                      : BitmapFactory.decodeResource(Main.main.getResources(), getDefPhoto());

              try {
                img.post(
                    new Runnable() {
                      @Override
                      public void run() {
                        ImageView img = ref.get();
                        if (img == null || img.getTag() != location) return;
                        img.setImageBitmap(bmp);
                      }
                    });
              } catch (Exception e) {
                Common.logError("error loading bitmap");
                e.printStackTrace();
              }
            }

            @Override
            public void onProgress(float progress) {}
          });
    } catch (Exception e) {
      Common.logError("error query file");
      e.printStackTrace();
    }
  }