예제 #1
0
  public Bitmap loadImage(String path) throws OutOfMemoryError {
    Bitmap bitsat;

    try {
      BitmapFactory.Options options = new BitmapFactory.Options();
      options.inPreferredConfig = Bitmap.Config.ARGB_8888;
      options.inJustDecodeBounds = true;
      Bitmap b = BitmapFactory.decodeFile(path, options);

      options.inSampleSize = Futils.calculateInSampleSize(options, px, px);

      // Decode bitmap with inSampleSize set
      options.inJustDecodeBounds = false;

      Bitmap bit;
      if (path.startsWith("smb:/")) bit = BitmapFactory.decodeStream(new SmbFileInputStream(path));
      else bit = BitmapFactory.decodeFile(path, options);

      bitsat =
          bit; // decodeFile(path);//.createScaledBitmap(bits,imageViewReference.get().getHeight(),imageViewReference.get().getWidth(),true);
    } catch (Exception e) {
      Drawable img = ContextCompat.getDrawable(mContext, R.drawable.ic_doc_image);
      Bitmap img1 = ((BitmapDrawable) img).getBitmap();
      bitsat = img1;
    }
    return bitsat;
  }
 static void calculateInSampleSize(
     int paramInt1,
     int paramInt2,
     int paramInt3,
     int paramInt4,
     BitmapFactory.Options paramOptions,
     Request paramRequest) {
   int i = 1;
   if ((paramInt4 > paramInt2) || (paramInt3 > paramInt1)) {
     if (paramInt2 != 0) {
       break label43;
     }
   }
   for (i = (int) Math.floor(paramInt3 / paramInt1);
       ;
       i = (int) Math.floor(paramInt4 / paramInt2)) {
     paramOptions.inSampleSize = i;
     paramOptions.inJustDecodeBounds = false;
     return;
     label43:
     if (paramInt1 != 0) {
       break;
     }
   }
   paramInt2 = (int) Math.floor(paramInt4 / paramInt2);
   paramInt1 = (int) Math.floor(paramInt3 / paramInt1);
   if (paramRequest.centerInside) {}
   for (i = Math.max(paramInt2, paramInt1); ; i = Math.min(paramInt2, paramInt1)) {
     break;
   }
 }
예제 #3
0
  public DessertCaseView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    final Resources res = getResources();

    mStarted = false;

    mCellSize = res.getDimensionPixelSize(R.dimen.dessert_case_cell_size);
    final BitmapFactory.Options opts = new BitmapFactory.Options();
    if (mCellSize < 512) { // assuming 512x512 images
      opts.inSampleSize = 2;
    }
    opts.inMutable = true;
    Bitmap loaded = null;
    for (int[] list : new int[][] {PASTRIES, RARE_PASTRIES, XRARE_PASTRIES, XXRARE_PASTRIES}) {
      for (int resid : list) {
        opts.inBitmap = loaded;
        loaded = BitmapFactory.decodeResource(res, resid, opts);
        final BitmapDrawable d = new BitmapDrawable(res, convertToAlphaMask(loaded));
        d.setColorFilter(new ColorMatrixColorFilter(ALPHA_MASK));
        d.setBounds(0, 0, mCellSize, mCellSize);
        mDrawables.append(resid, d);
      }
    }
    loaded = null;
    if (DEBUG) setWillNotDraw(false);
  }
예제 #4
0
 public static Bitmap getSmallBitmap(String filePath, int reqWidth, int reqHeight) {
   BitmapFactory.Options options = new BitmapFactory.Options();
   options.inJustDecodeBounds = true;
   BitmapFactory.decodeFile(filePath, options);
   options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);
   options.inJustDecodeBounds = false;
   return BitmapFactory.decodeFile(filePath, options);
 }
 public Bitmap run(ThreadPool.JobContext paramJobContext) {
   ImageCacheService localImageCacheService = this.mApplication.getImageCacheService();
   BytesBufferPool.BytesBuffer localBytesBuffer = MediaItem.getBytesBufferPool().get();
   Bitmap localBitmap1;
   try {
     boolean bool1 = localImageCacheService.getImageData(this.mPath, this.mType, localBytesBuffer);
     boolean bool2 = paramJobContext.isCancelled();
     if (bool2) return null;
     if (bool1) {
       BitmapFactory.Options localOptions = new BitmapFactory.Options();
       localOptions.inPreferredConfig = Bitmap.Config.ARGB_8888;
       if (this.mType == 2) ;
       Bitmap localBitmap3;
       for (Object localObject2 =
               DecodeUtils.decode(
                   paramJobContext,
                   localBytesBuffer.data,
                   localBytesBuffer.offset,
                   localBytesBuffer.length,
                   localOptions,
                   MediaItem.getMicroThumbPool());
           ;
           localObject2 = localBitmap3) {
         if ((localObject2 == null) && (!paramJobContext.isCancelled()))
           Log.w("ImageCacheRequest", "decode cached failed " + debugTag());
         return localObject2;
         localBitmap3 =
             DecodeUtils.decode(
                 paramJobContext,
                 localBytesBuffer.data,
                 localBytesBuffer.offset,
                 localBytesBuffer.length,
                 localOptions,
                 MediaItem.getThumbPool());
       }
     }
     MediaItem.getBytesBufferPool().recycle(localBytesBuffer);
     localBitmap1 = onDecodeOriginal(paramJobContext, this.mType);
     return null;
   } finally {
     MediaItem.getBytesBufferPool().recycle(localBytesBuffer);
   }
   if (localBitmap1 == null) {
     Log.w("ImageCacheRequest", "decode orig failed " + debugTag());
     return null;
   }
   if (this.mType == 2) ;
   for (Bitmap localBitmap2 =
           BitmapUtils.resizeAndCropCenter(localBitmap1, this.mTargetSize, true);
       paramJobContext.isCancelled();
       localBitmap2 = BitmapUtils.resizeDownBySideLength(localBitmap1, this.mTargetSize, true))
     return null;
   byte[] arrayOfByte = BitmapUtils.compressToBytes(localBitmap2);
   if (paramJobContext.isCancelled()) return null;
   localImageCacheService.putImageData(this.mPath, this.mType, arrayOfByte);
   return (Bitmap) localBitmap2;
 }
예제 #6
0
  private void loadTilesBitmap() {
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inPreferredConfig = Bitmap.Config.ARGB_8888;

    this.tilesBitmap = new Bitmap[SLICE_COUNT];
    for (int i = 0; i < tilesBitmap.length; i++) {
      String s = String.format("tiles%d_%02d", tileSize, i);
      int rid = getResources().getIdentifier(s, "drawable", "micropolis.android");
      tilesBitmap[i] = BitmapFactory.decodeResource(getResources(), rid, options);
    }
  }
예제 #7
0
  /**
   * Stores a bitmap for use by a game tile in a level.
   *
   * @param int resourceId - The bitmap resource ID.
   * @return Bitmap - The Bitmap instance for the given resource ID.
   */
  private Bitmap setAndGetGameTileBitmap(int resourceId) {
    if (!mGameTileBitmaps.containsKey(resourceId)) {
      BitmapFactory.Options opts = new BitmapFactory.Options();
      opts.inJustDecodeBounds = true;
      Bitmap bitmap = BitmapFactory.decodeResource(mGameContext.getResources(), resourceId);

      if (bitmap != null) {
        mGameTileBitmaps.put(resourceId, bitmap);
      }
    }

    return mGameTileBitmaps.get(resourceId);
  }
 static BitmapFactory.Options createBitmapOptions(Request paramRequest) {
   boolean bool = paramRequest.hasSize();
   if (paramRequest.config != null) {}
   for (int i = 1; ; i = 0) {
     Object localObject = null;
     if ((bool) || (i != 0)) {
       BitmapFactory.Options localOptions = new BitmapFactory.Options();
       localOptions.inJustDecodeBounds = bool;
       localObject = localOptions;
       if (i != 0) {
         localOptions.inPreferredConfig = paramRequest.config;
         localObject = localOptions;
       }
     }
     return (BitmapFactory.Options) localObject;
   }
 }
 /**
  * @Method: decodeBitmap @Description: ���ļ��ж�ȡͼƬ
  *
  * @param path ͼƬ��·��
  * @return
  */
 Bitmap decodeBitmap(String path) {
   BitmapFactory.Options op = new BitmapFactory.Options();
   op.inJustDecodeBounds = true;
   Bitmap bmp = BitmapFactory.decodeFile(path, op);
   int wRatio = (int) Math.ceil(op.outWidth / 100); // ��ȡ�����С
   int hRatio = (int) Math.ceil(op.outHeight / 100);
   if (wRatio > 1 && hRatio > 1) { // ����ָ����С������С��Ӧ�ı���
     if (wRatio > hRatio) {
       op.inSampleSize = wRatio;
     } else {
       op.inSampleSize = hRatio;
     }
   }
   op.inJustDecodeBounds = false;
   bmp = BitmapFactory.decodeFile(path, op);
   return bmp;
 }
예제 #10
0
  /**
   * @Method: decodeBitmap @Description: ��ȡpath·���µ�ͼƬ��������
   *
   * @param path
   * @param rect
   * @return
   */
  Bitmap decodeBitmap(String path, int rect) {
    BitmapFactory.Options op = new BitmapFactory.Options();
    op.inJustDecodeBounds = true;
    op.inPreferredConfig = Bitmap.Config.ALPHA_8;
    Bitmap bmp = BitmapFactory.decodeFile(path, op);
    // ��ȡ�����С
    int wRatio = (int) Math.ceil(op.outWidth / rect);
    int hRatio = (int) Math.ceil(op.outHeight / rect);

    // ����ָ����С������С��Ӧ�ı���
    if (wRatio > 1 && hRatio > 1) {
      if (wRatio > hRatio) {
        op.inSampleSize = wRatio;
      } else {
        op.inSampleSize = hRatio;
      }
    }
    op.inPreferredConfig = Bitmap.Config.ALPHA_8;
    op.inJustDecodeBounds = false;
    bmp = BitmapFactory.decodeFile(path, op);
    return bmp;
  }
예제 #11
0
  @Override
  public int onStartCommand(Intent intent, int flags, int startId) {

    // GET SETTINGS FROM SHARED PREFERENCES
    SharedPreferences settingsF = getSharedPreferences(FUZZY_STUFF, 0);
    int backgroundColorF =
        settingsF.getInt("BackgroundColorF", this.getResources().getColor(R.color.palesky));
    int textColorF = settingsF.getInt("TextColorF", this.getResources().getColor(R.color.night));
    String packageName = settingsF.getString("PackageName", "com.android.alarmclock");
    String className = settingsF.getString("ClassName", "com.android.alarmclock.AlarmClock");

    // CALCULATE ALL THE TIME DEPENDENT VARIABLES

    // reset the time dependent addition
    long alarmAddMillis = 0;

    // get time instance and values
    Calendar rightNow = Calendar.getInstance();
    int thisMin = rightNow.get(Calendar.MINUTE);
    int thisHour = rightNow.get(Calendar.HOUR);

    // set correct hour values
    nextHour = thisHour + 1;
    if (thisHour == 0) {
      thisHour = 12;
    }
    if (nextHour == 13) {
      nextHour = 1;
    }

    // set text values based on minutes
    if (thisMin >= 0 && thisMin <= 7) {
      wordA = "its";
      wordB = "about";
      wordA_B = "its_about";
      clockH = thisHour;
      nextAlarmMin = 8;
      alarmAddMillis = 0;
    }
    if (thisMin >= 8 && thisMin <= 22) {
      wordA = "quarter";
      wordB = "past";
      wordA_B = "quarter_past";
      clockH = thisHour;
      nextAlarmMin = 23;
      alarmAddMillis = 0;
    }
    if (thisMin >= 23 && thisMin <= 37) {
      wordA = "half";
      wordB = "past";
      wordA_B = "half_past";
      clockH = thisHour;
      nextAlarmMin = 38;
      alarmAddMillis = 0;
    }
    if (thisMin >= 38 && thisMin <= 52) {
      wordA = "quarter";
      wordB = "to";
      wordA_B = "quarter_to";
      clockH = nextHour;
      nextAlarmMin = 53;
      alarmAddMillis = 0;
    }
    if (thisMin >= 53 && thisMin <= 59) {
      wordA = "its";
      wordB = "about";
      wordA_B = "its_about";
      clockH = nextHour;
      nextAlarmMin = 8;
      alarmAddMillis = 3600000;
    }

    // CANCEL ANY UNSENT ALARM
    if (alarmManager != null) {
      alarmManager.cancel(pendingIntent);
    }

    // SET UP THE NEXT ALARM

    // set the time
    Calendar nextAlarm = Calendar.getInstance();
    // add one hour of millis if its for the next hour
    nextAlarm.setTimeInMillis(System.currentTimeMillis() + alarmAddMillis);
    // set the correct minute
    nextAlarm.set(Calendar.MINUTE, nextAlarmMin);
    nextAlarm.set(Calendar.SECOND, 15);
    nextAlarm.set(Calendar.MILLISECOND, 0);

    // request the alarm
    alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    Intent usIntent = new Intent(this, AlarmReceiver.class);
    pendingIntent = PendingIntent.getBroadcast(this, 0, usIntent, 0);
    // use onExact for API19+
    int currentApiVersion = android.os.Build.VERSION.SDK_INT;
    if (currentApiVersion <= 18) {
      alarmManager.set(AlarmManager.RTC, nextAlarm.getTimeInMillis(), pendingIntent);
    } else {
      alarmManager.setExact(AlarmManager.RTC, nextAlarm.getTimeInMillis(), pendingIntent);
    }

    // SET UP THE IMAGES

    // get the resource id ints for images to send by remoteviews
    int timePhraseA =
        this.getResources().getIdentifier("phr_" + wordA, "drawable", this.getPackageName());
    int timePhraseB =
        this.getResources().getIdentifier("phr_" + wordB, "drawable", this.getPackageName());
    int timePhraseA_B =
        this.getResources().getIdentifier("phr_" + wordA_B, "drawable", this.getPackageName());
    int hourWordImageCrop =
        this.getResources().getIdentifier("num_" + clockH, "drawable", this.getPackageName());
    int hourWordImageWide =
        this.getResources()
            .getIdentifier("num_" + clockH + "_w", "drawable", this.getPackageName());

    // SET THE BITMAP COLOR AND OTHER VALUES
    fillPaintF = new Paint(Paint.FILTER_BITMAP_FLAG);
    fillPaintF.setColor(textColorF);
    fillPaintF.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_ATOP));

    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inPurgeable = true;
    options.inPreferredConfig = Bitmap.Config.ARGB_8888;

    // ASSEMBLE THE PENDING INTENTS

    // create the open configuration pending intent
    Intent openAWC = new Intent(this, AppWidgetConfigure.class);
    openAWC.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    PendingIntent openAwcPi =
        PendingIntent.getActivity(this, 0, openAWC, PendingIntent.FLAG_UPDATE_CURRENT);

    // create the open alarms pending intent - done here because it couldnt be saved in prefs
    // set up open Alarms Intent
    PendingIntent alarmPI = null;
    PackageManager packageManager = this.getPackageManager();
    Intent alarmClockIntent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER);
    // get the activity info and attach to the intent
    try {
      ComponentName cn = new ComponentName(packageName, className);
      packageManager.getActivityInfo(cn, PackageManager.GET_META_DATA);
      alarmClockIntent.setComponent(cn);
    } catch (PackageManager.NameNotFoundException e) {
      stopSelf();
    }
    // finalize the pending intent
    alarmPI = PendingIntent.getActivity(this, 0, alarmClockIntent, 0);

    // create the refresh widget pending intent
    Intent startUpdateF = new Intent(this, UpdateService.class);
    startUpdateF.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    pendingStartUpdateF =
        PendingIntent.getService(this, 0, startUpdateF, PendingIntent.FLAG_UPDATE_CURRENT);

    // **** BACKGROUND IMAGE PREPARATION ****

    // draw an empty image
    bitmapBackgroundF = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
    // paint in the color
    Canvas canvasBackgroundF = new Canvas(bitmapBackgroundF);
    fillPaintBackgroundF = new Paint();
    fillPaintBackgroundF.setColor(backgroundColorF);
    canvasBackgroundF.drawPaint(fillPaintBackgroundF);

    // SEND ALL THE STUFF TO THE PLACED WIDGETS

    // get appwidgetmanager instance for all widgets
    AppWidgetManager localAppWidgetManager = AppWidgetManager.getInstance(this);

    // update all 4x1 widget instances
    ComponentName thisWidget4x1 = new ComponentName(getBaseContext(), WidgetProvider4x1.class);
    int[] allWidgetIds4x1 = localAppWidgetManager.getAppWidgetIds(thisWidget4x1);
    if (allWidgetIds4x1 != null) {

      // join the images together into one strip
      Bitmap bitmap4x1partA = BitmapFactory.decodeResource(getResources(), timePhraseA, options);
      Bitmap bitmap4x1partB = BitmapFactory.decodeResource(getResources(), timePhraseB, options);
      Bitmap bitmap4x1partC =
          BitmapFactory.decodeResource(getResources(), hourWordImageCrop, options);

      Bitmap bitmap4x1strip =
          Bitmap.createBitmap(
              bitmap4x1partA.getWidth() + bitmap4x1partB.getWidth() + bitmap4x1partC.getWidth(),
              bitmap4x1partA.getHeight(),
              Bitmap.Config.ARGB_8888);
      Canvas canvas4x1strip = new Canvas(bitmap4x1strip);
      canvas4x1strip.drawBitmap(bitmap4x1partA, 0, 0, null);
      canvas4x1strip.drawBitmap(bitmap4x1partB, bitmap4x1partA.getWidth(), 0, null);
      canvas4x1strip.drawBitmap(
          bitmap4x1partC, bitmap4x1partA.getWidth() + bitmap4x1partB.getWidth(), 0, null);

      // generate adjusted images if color theme isnt default

      // strip
      Bitmap bitmap4x1strip2 = bitmap4x1strip.copy(Bitmap.Config.ARGB_8888, true);
      Canvas canvas4x1strip2 = new Canvas(bitmap4x1strip2);
      canvas4x1strip2.drawPaint(fillPaintF);

      for (int widgetId : allWidgetIds4x1) {
        RemoteViews remoteViews = new RemoteViews(getPackageName(), R.layout.widget_layout_4x1);
        remoteViews.setImageViewBitmap(R.id.imageviewBG, bitmapBackgroundF);
        remoteViews.setImageViewBitmap(R.id.imageviewABC, bitmap4x1strip2);
        remoteViews.setOnClickPendingIntent(R.id.topclickLeft, alarmPI);
        remoteViews.setOnClickPendingIntent(R.id.topclickRight, openAwcPi);
        localAppWidgetManager.updateAppWidget(widgetId, remoteViews);
      }
      bitmap4x1strip2 = null;
      canvas4x1strip2 = null;
      bitmap4x1strip = null;
      canvas4x1strip = null;
    }

    // update all 3x2 widget instances
    ComponentName thisWidget3x2 = new ComponentName(getBaseContext(), WidgetProvider3x2.class);
    int[] allWidgetIds3x2 = localAppWidgetManager.getAppWidgetIds(thisWidget3x2);
    if (allWidgetIds3x2 != null) {
      // generate adjusted images if color theme isnt default
      // time phrase
      if (bitmapTimePhraseA_B == null) {
        bitmapTimePhraseA_B1 = BitmapFactory.decodeResource(getResources(), timePhraseA_B, options);
        bitmapTimePhraseA_B = bitmapTimePhraseA_B1.copy(Bitmap.Config.ARGB_8888, true);
        canvasPhrase = new Canvas(bitmapTimePhraseA_B);
        canvasPhrase.drawPaint(fillPaintF);
      }
      // hour word
      if (bitmapHourWordImage == null) {
        bitmapHourWordImage1 =
            BitmapFactory.decodeResource(getResources(), hourWordImageWide, options);
        bitmapHourWordImage = bitmapHourWordImage1.copy(Bitmap.Config.ARGB_8888, true);
        canvasHour = new Canvas(bitmapHourWordImage);
        canvasHour.drawPaint(fillPaintF);
      }
      for (int widgetId : allWidgetIds3x2) {
        RemoteViews remoteViews = new RemoteViews(getPackageName(), R.layout.widget_layout_3x2);
        remoteViews.setImageViewBitmap(R.id.imageviewA_B, bitmapTimePhraseA_B);
        remoteViews.setImageViewBitmap(R.id.imageviewC, bitmapHourWordImage);
        remoteViews.setImageViewBitmap(R.id.imageviewBG, bitmapBackgroundF);
        remoteViews.setOnClickPendingIntent(R.id.topclickLeft, alarmPI);
        remoteViews.setOnClickPendingIntent(R.id.topclickRight, openAwcPi);
        localAppWidgetManager.updateAppWidget(widgetId, remoteViews);
      }
    }

    // CLEAR ALL THE BITMAPS
    bitmapTimePhraseA_B = null;
    bitmapTimePhraseA_B1 = null;
    bitmapHourWordImageCrop = null;
    bitmapHourWordImageCrop1 = null;
    bitmapHourWordImage = null;
    bitmapHourWordImage1 = null;
    canvasPhrase = null;
    canvasHour = null;
    bitmapBackgroundF = null;

    stopSelf();
    return super.onStartCommand(intent, flags, startId);
  }