コード例 #1
0
  public void draw(Canvas canvas) {
    super.draw(canvas);
    float scale = getResources().getDisplayMetrics().density;
    int paddSize = (int) (GAPPING * scale + 0.5f);
    int bmWidth = bg.getBitmap().getWidth();
    Rect rect = new Rect(0, 0, getWidth(), getHeight());
    for (int x = 0; x < rect.width(); x += bmWidth) {
      RectF dstRect = new RectF(x, paddSize, getWidth() + x, getHeight() - paddSize);
      canvas.drawBitmap(bg.getBitmap(), null, dstRect, null);
    }
    bmWidth = midBg.getIntrinsicWidth();
    for (int x = 0; x < rect.width(); x += bmWidth) {
      Rect dstRectMid =
          new Rect(
              x,
              getHeight() - midBg.getIntrinsicHeight() - paddSize,
              midBg.getIntrinsicWidth() + x,
              getHeight() - paddSize);
      canvas.drawBitmap(midBg.getBitmap(), null, dstRectMid, null);
    }

    bmWidth = forBg.getIntrinsicWidth();
    for (int x = 0; x < rect.width(); x += bmWidth) {
      Rect dstRectMid =
          new Rect(
              x,
              getHeight() - forBg.getIntrinsicHeight() - paddSize,
              forBg.getIntrinsicWidth() + x,
              getHeight() - paddSize);
      canvas.drawBitmap(forBg.getBitmap(), null, dstRectMid, null);
    }
  }
コード例 #2
0
ファイル: ImageTextView.java プロジェクト: yezesong/Albums
 private Bitmap drawableToBitamp(Drawable drawable) {
   if (drawable == null) {
     return ((BitmapDrawable) getResources().getDrawable(R.drawable.image_text_icon)).getBitmap();
   }
   BitmapDrawable bd = (BitmapDrawable) drawable;
   return bd.getBitmap();
 }
コード例 #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
  private void setImageBitmap(Bitmap bt, boolean withAnim) {
    if (bt == null) {
      this.setImageDrawable(mDefaultSrc);
      return;
    }

    Drawable preDrawable = getDrawable();
    BitmapDrawable btDrawable = null;
    if (preDrawable instanceof BitmapDrawable) {
      btDrawable = (BitmapDrawable) preDrawable;
    }

    RoundRectDrawable rDrawable = new RoundRectDrawable(getResources(), bt);
    rDrawable.setConerRadius(mCornerRadius);
    rDrawable.setUseCanvasClip(this.getScaleType() == ScaleType.CENTER_CROP);
    if (DEBUG) {
      System.out.println(
          "[[WebImageView::setImageBitmap]] drawable obj = "
              + rDrawable
              + " corner = "
              + mCornerRadius
              + " >>>");
    }
    super.setImageDrawable(rDrawable);
    if (mHasAnimation) {
      this.clearAnimation();
      if ((Build.VERSION.SDK_INT >= 14)
          && withAnim
          && ((bt != null && btDrawable == null)
              || (bt != null && btDrawable != null && btDrawable.getBitmap() != bt))) {
        this.startAnimation(mAnimation);
      }
    }
  }
コード例 #5
0
ファイル: Upload.java プロジェクト: NightRaver/foond
  public static Bitmap drawableToBitmap(Drawable drawable) {
    Bitmap bitmap = null;

    if (drawable instanceof BitmapDrawable) {
      BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
      if (bitmapDrawable.getBitmap() != null) {
        return bitmapDrawable.getBitmap();
      }
    }

    if (drawable.getIntrinsicWidth() <= 0 || drawable.getIntrinsicHeight() <= 0) {
      bitmap =
          Bitmap.createBitmap(
              1, 1, Bitmap.Config.ARGB_8888); // Single color bitmap will be created of 1x1 pixel
    } else {
      bitmap =
          Bitmap.createBitmap(
              drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
    }

    Canvas canvas = new Canvas(bitmap);
    drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
    drawable.draw(canvas);
    return bitmap;
  }
コード例 #6
0
 /**
  * 获取关闭高光图标的副本
  *
  * @return
  */
 public BitmapDrawable getColseLightIconCopy() {
   try {
     if (mCloseLightIcon == null) {
       if (mThemeController == null) {
         mThemeController = AppFuncFrame.getThemeController();
       }
       BitmapDrawable origImg =
           (BitmapDrawable)
               mThemeController.getDrawable(
                   mThemeController.getThemeBean().mAppIconBean.mKillAppLight);
       if (origImg != null) {
         Bitmap copy = origImg.getBitmap().copy(Bitmap.Config.ARGB_8888, true);
         if (copy != null) {
           mCloseLightIcon = new BitmapDrawable(mContext.getResources(), copy);
         }
       }
     }
   } catch (OutOfMemoryError e) {
     e.printStackTrace();
     OutOfMemoryHandler.handle();
   } catch (Exception e) {
     e.printStackTrace();
   }
   return mCloseLightIcon;
 }
コード例 #7
0
ファイル: MainPage.java プロジェクト: Tacus/eigthtegame
 private void bindData2(List<SingleGameItem> list) {
   for (int i = 0; i < holders.size(); i++) {
     SingleGameItem gameItem = list.get(i);
     Holder holder = holders.get(i);
     if (i >= 12) {
       MyUtils.setImage(holder.game_logo, gameItem.getGame_icon_url(), 2);
       BitmapDrawable drawable = (BitmapDrawable) holder.game_logo.getDrawable();
       Bitmap srcBitmap = drawable.getBitmap();
       holder.game_reflect.setVisibility(View.VISIBLE);
       holder.game_reflect.setImageBitmap(MyUtils.createReflectedImage(srcBitmap));
     } else {
       holder.game_reflect.setVisibility(View.GONE);
       MyUtils.setImage(holder.game_logo, gameItem.getGame_icon_url(), 2);
     }
     holder.game_name.setText(gameItem.getGame_name());
     DownloadApk downloadApk = MainActivity.map.get(gameItem.getGame_id());
     if (downloadApk != null) {
       holder.game_progress.setVisibility(View.VISIBLE);
       downloadApk.addloadPercentageTextView(holder.game_progress);
     } else {
       holder.game_progress.setVisibility(View.GONE);
     }
     holder.game_logo.setTag(gameItem);
   }
 }
コード例 #8
0
 @Override
 protected void onLayout(boolean changed, int l, int t, int r, int b) {
   View view = resolveView();
   if (view != null) {
     int width = getMeasuredWidth();
     int height = getMeasuredHeight();
     @Px
     int leftLineWidth = leftBorder == BorderMode.LINE ? 1 : leftPageBorder.getIntrinsicWidth();
     @Px
     int rightLineWidth =
         rightBorder == BorderMode.HIDDEN ? 0 : rightPageBorder.getIntrinsicWidth();
     int headerFooterHeight = 0;
     view.layout(
         leftLineWidth, headerFooterHeight, width - rightLineWidth, height - headerFooterHeight);
     if (errorLayout != null) {
       int errorLayoutWidth = errorLayout.getMeasuredWidth();
       int errorLayoutHeight = errorLayout.getMeasuredHeight();
       int leftRightOffset = ((width - (leftLineWidth + rightLineWidth)) - errorLayoutWidth) / 2;
       int topBottomOffset = ((height - 2 * headerFooterHeight) - errorLayoutHeight) / 2;
       errorLayout.layout(
           leftLineWidth + leftRightOffset,
           headerFooterHeight + topBottomOffset,
           leftLineWidth + leftRightOffset + errorLayoutWidth,
           headerFooterHeight + topBottomOffset + errorLayoutHeight);
     }
   }
 }
コード例 #9
0
  private void init(Context context, AttributeSet attrs, int defStyle) {
    TypedArray a =
        context.obtainStyledAttributes(attrs, R.styleable.ToggleImageButton, defStyle, 0);
    boolean checked = a.getBoolean(R.styleable.ToggleImageButton_android_checked, false);
    setChecked(checked);
    mSrcDrawable = a.getDrawable(R.styleable.ToggleImageButton_android_src);
    mTintColor = a.getColor(R.styleable.ToggleImageButton_android_tint, 0);
    mCheckedDrawable = a.getDrawable(R.styleable.ToggleImageButton_checkedSrc);
    mCheckedTintColor = a.getColor(R.styleable.ToggleImageButton_checkedTint, 0);
    mBlurRadius = a.getFloat(R.styleable.ToggleImageButton_checkedBlurRadius, 0);
    a.recycle();

    super.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View view) {
            setChecked(!isChecked(), true);
          }
        });

    if (mBlurRadius != 0.0f) {
      Drawable drawable = resolveCheckedDrawable();
      if (BuildConfig.DEBUG) Log.d(LOG_TAG, "Checked drawable is a " + drawable.toString());
      if (drawable instanceof BitmapDrawable) {
        BitmapDrawable bd = (BitmapDrawable) drawable;
        Paint paint = new Paint();
        paint.setMaskFilter(new BlurMaskFilter(mBlurRadius, BlurMaskFilter.Blur.SOLID));
        Bitmap bitmap = bd.getBitmap().extractAlpha(paint, null);
        mCheckedDrawable = new BitmapDrawable(getContext().getResources(), bitmap);
      }
    }
  }
コード例 #10
0
ファイル: PicassoDrawable.java プロジェクト: sheytoon/Syna
 public void draw(Canvas canvas) {
   if (this.animating) {
     float uptimeMillis =
         ((float) (SystemClock.uptimeMillis() - this.startTimeMillis)) / FADE_DURATION;
     if (uptimeMillis >= 1.0f) {
       this.animating = false;
       this.placeholder = null;
       super.draw(canvas);
     } else {
       if (this.placeholder != null) {
         this.placeholder.draw(canvas);
       }
       super.setAlpha((int) (uptimeMillis * ((float) this.alpha)));
       super.draw(canvas);
       super.setAlpha(this.alpha);
       if (VERSION.SDK_INT <= 10) {
         invalidateSelf();
       }
     }
   } else {
     super.draw(canvas);
   }
   if (this.debugging) {
     drawDebugIndicator(canvas);
   }
 }
コード例 #11
0
  @Override
  public Drawable getDrawable(final String source) {
    try {
      Drawable repositoryImage = requestRepositoryImage(source);
      if (repositoryImage != null) return repositoryImage;
    } catch (Exception e) {
      // Ignore and attempt request over regular HTTP request
    }

    try {
      String logMessage = "Loading image: " + source;
      Log.d(getClass().getSimpleName(), logMessage);
      Bugsnag.leaveBreadcrumb(logMessage);

      Request request = new Request.Builder().get().url(source).build();

      com.squareup.okhttp.Response response = okHttpClient.newCall(request).execute();

      if (!response.isSuccessful())
        throw new IOException("Unexpected response code: " + response.code());

      Bitmap bitmap = BitmapFactory.decodeStream(response.body().byteStream());

      if (bitmap == null) return loading.getDrawable(source);

      BitmapDrawable drawable = new BitmapDrawable(context.getResources(), bitmap);
      drawable.setBounds(0, 0, bitmap.getWidth(), bitmap.getHeight());
      return drawable;
    } catch (IOException e) {
      Log.e(getClass().getSimpleName(), "Error loading image", e);
      Bugsnag.notify(e);
      return loading.getDrawable(source);
    }
  }
コード例 #12
0
ファイル: Theme.java プロジェクト: shlusiak/Freebloks-Android
  private BitmapDrawable getDrawable(Resources resources) {
    BitmapDrawable background = (BitmapDrawable) resources.getDrawable(drawable);

    background.setTileModeXY(TileMode.REPEAT, isPreview ? TileMode.MIRROR : TileMode.REPEAT);
    background.setFilterBitmap(true);
    return background;
  }
コード例 #13
0
  @Override
  public void draw(Canvas canvas) {
    if (!animating) {
      image.draw(canvas);
    } else {
      float normalized = (SystemClock.uptimeMillis() - startTimeMillis) / FADE_DURATION;
      if (normalized >= 1f) {
        animating = false;
        placeholder = null;
        image.draw(canvas);
      } else {
        if (placeholder != null) {
          placeholder.draw(canvas);
        }

        int alpha = (int) (0xFF * normalized);
        image.setAlpha(alpha);
        image.draw(canvas);
        image.setAlpha(0xFF);
        invalidateSelf();
      }
    }

    if (debugging) {
      drawDebugIndicator(canvas);
    }
  }
コード例 #14
0
  public void shareWebMessage(
      String shareUrl, String title, String description, Drawable mDrawable) {
    WeiboMultiMessage weiboMessage = new WeiboMultiMessage();
    if (mDrawable == null) mDrawable = context.getResources().getDrawable(R.drawable.ic_launcher);
    BitmapDrawable bitmapDrawable = (BitmapDrawable) mDrawable;
    Bitmap shareBitmap = null;
    try {
      shareBitmap = bitmapDrawable.getBitmap();
      if (shareBitmap == null)
        shareBitmap =
            ((BitmapDrawable) context.getResources().getDrawable(R.drawable.ic_launcher))
                .getBitmap();
      else shareBitmap = zoomImg(shareBitmap, 100);
      weiboMessage.mediaObject = getWebpageObj(shareUrl, title, description, shareBitmap);
      weiboMessage.textObject = getTextObj(title);
      SendMultiMessageToWeiboRequest request = new SendMultiMessageToWeiboRequest();
      request.transaction = String.valueOf(System.currentTimeMillis());
      request.multiMessage = weiboMessage;
      mWeiboShareAPI.sendRequest(request);
    } catch (Exception e) {

    } finally {
      if (shareBitmap != null) {
        // shareBitmap.recycle();
        shareBitmap = null;
      }
    }
  }
コード例 #15
0
ファイル: ImageLoader.java プロジェクト: Nairou/Subsonic
 private void createLargeUnknownImage(Context context) {
   BitmapDrawable drawable =
       (BitmapDrawable) context.getResources().getDrawable(R.drawable.unknown_album_large);
   Bitmap bitmap =
       Bitmap.createScaledBitmap(drawable.getBitmap(), imageSizeLarge, imageSizeLarge, true);
   largeUnknownImage = Util.createDrawableFromBitmap(context, bitmap);
 }
コード例 #16
0
  public static BitmapDrawable createCheckerBoard(Resources res, int size) {
    size *= res.getDisplayMetrics().density;

    BitmapShader shader =
        new BitmapShader(
            Bitmap.createBitmap(
                new int[] {0xFFFFFFFF, 0xFFCCCCCC, 0xFFCCCCCC, 0xFFFFFFFF},
                2,
                2,
                Bitmap.Config.RGB_565),
            BitmapShader.TileMode.REPEAT,
            BitmapShader.TileMode.REPEAT);
    Matrix matrix = new Matrix();
    matrix.setScale(size, size);
    shader.setLocalMatrix(matrix);

    Paint paint = new Paint();
    paint.setStyle(Paint.Style.FILL);
    paint.setShader(shader);

    Bitmap bm2 = Bitmap.createBitmap(size * 2, size * 2, Bitmap.Config.RGB_565);
    new Canvas(bm2).drawPaint(paint);

    BitmapDrawable drawable = new BitmapDrawable(res, bm2);
    drawable.setTileModeXY(BitmapShader.TileMode.REPEAT, BitmapShader.TileMode.REPEAT);

    return drawable;
  }
コード例 #17
0
 /**
  * 获取卸载图标的副本
  *
  * @return
  */
 public BitmapDrawable getKillIconCopy() {
   try {
     if (mKillImg == null) {
       // BitmapDrawable origImg = (BitmapDrawable) mActivity
       // .getResources().getDrawable(R.drawable.kill);
       if (mThemeController == null) {
         mThemeController = AppFuncFrame.getThemeController();
       }
       BitmapDrawable origImg =
           (BitmapDrawable)
               mThemeController.getDrawable(
                   mThemeController.getThemeBean().mAppIconBean.mDeletApp);
       if (origImg != null) {
         Bitmap copy = origImg.getBitmap().copy(Bitmap.Config.ARGB_8888, true);
         if (copy != null) {
           mKillImg = new BitmapDrawable(mContext.getResources(), copy);
         }
       }
     }
   } catch (OutOfMemoryError e) {
     e.printStackTrace();
     OutOfMemoryHandler.handle();
   } catch (Exception e) {
     e.printStackTrace();
   }
   return mKillImg;
 }
コード例 #18
0
ファイル: MapsActivity.java プロジェクト: gabrielsson/Clac
  @Override
  public void onMapReady(GoogleMap googleMap) {
    mMap = googleMap;
    mMap.setMyLocationEnabled(true);

    Bundle extras = getIntent().getExtras();
    float[] lats = {}, lngs = {};
    String[] titles = {}, snippets = {};
    int[] beers = {};

    if (null != extras) {
      lats = extras.getFloatArray("Latitudes");
      lngs = extras.getFloatArray("Longitudes");
      titles = extras.getStringArray("Titles");
      snippets = extras.getStringArray("Snippets");
      beers = extras.getIntArray("Beers");
    }
    googleMap.setInfoWindowAdapter(new CustomInfoWindowAdapter());

    LatLng ll = null;
    for (int i = 0; i < titles.length; i++) {
      ll = new LatLng(lats[i], lngs[i]);

      MarkerOptions mark = new MarkerOptions().position(ll).title(titles[i]).snippet(snippets[i]);

      // Other color if beer has been drunk.
      // The argument to defaultMarker() takes a float between 0-360.0,
      // check BitmapDescriptorFactory.HUE_*.
      // It is possible to create a BitmapDescriptor from drawables etc.
      BitmapDescriptor icon;
      if (i < beers.length && 0 < beers[i]) {
        icon = BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_GREEN);
      } else {
        icon = BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED);
      }
      mark.icon(icon);

      // Add a marker and set the number of beers drunk
      Marker marker = mMap.addMarker(mark);
      beerMap.put(marker, (beers.length > i ? beers[i] : 0));
    }

    /* Add propellern */
    BitmapDrawable bd = (BitmapDrawable) getResources().getDrawable(R.drawable.proppeller);
    Bitmap b = bd.getBitmap();
    Bitmap bhalfsize = Bitmap.createScaledBitmap(b, b.getWidth() / 2, b.getHeight() / 2, false);
    MarkerOptions propellern =
        new MarkerOptions()
            .position(PROPELLERN)
            .icon(BitmapDescriptorFactory.fromBitmap(bhalfsize));
    mMap.addMarker(propellern);

    /* See zoom */
    if (null == ll || 1 < titles.length) {
      // Zoom from far 2.0 (zoomed out) to close 21.0 (zoomed in)
      mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(PROPELLERN, 12.2f));
    } else {
      mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(ll, 12.2f));
    }
  }
コード例 #19
0
 /**
  * 获取编辑文件夹高光图标的副本
  *
  * @return
  */
 public BitmapDrawable getEditLightIconCopy() {
   try {
     if (mEditLightIcon == null) {
       // BitmapDrawable origImg = (BitmapDrawable) mActivity
       // .getResources().getDrawable(
       // R.drawable.eidt_folder_light);
       if (mThemeController == null) {
         mThemeController = AppFuncFrame.getThemeController();
       }
       BitmapDrawable origImg =
           (BitmapDrawable)
               mThemeController.getDrawable(
                   mThemeController.getThemeBean().mAppIconBean.mEditHighlightFolder);
       if (origImg != null) {
         Bitmap copy = origImg.getBitmap().copy(Bitmap.Config.ARGB_8888, true);
         if (copy != null) {
           mEditLightIcon = new BitmapDrawable(mContext.getResources(), copy);
         }
       }
     }
   } catch (OutOfMemoryError e) {
     e.printStackTrace();
     OutOfMemoryHandler.handle();
   } catch (Exception e) {
     e.printStackTrace();
   }
   return mEditLightIcon;
 }
コード例 #20
0
  /**
   * 加载网络图片到ImageView上(当然也可以重写{@link ImageWorker#processBitmap(Object)}来实现图片获取过程)<br>
   * 如果图片在内存和本地缓存ImageWorker中存在,则直接 <br>
   * 否则将开启{@link AsyncTask} 下载图片
   *
   * @param data 图片下载链接
   * @param imageView 图片显示组件
   */
  public void loadImage(Object data, ImageView imageView) {
    if (data == null) {
      return;
    }

    if (data.toString().indexOf("?") != -1) {
      data = data + "&w=" + getW() + "&h=" + getH();
    } else {
      data = data + "?w=" + getW() + "&h=" + getH();
    }
    BitmapDrawable value = null;
    mImageCache = ImageLoadManager.instance().getmImageCache();
    if (mImageCache != null) {
      value = mImageCache.getBitmapFromMemCache(String.valueOf(data));
    }
    // 如果图片为空
    if (value != null) {
      // 如果图片不为空 则直接设置
      if (value.getBitmap() != null) {
        finish(value.getBitmap(), imageView, lister);
      }
      imageView.setImageDrawable(value);
    } else if (cancelPotentialWork(data, imageView)) {
      final BitmapWorkerTask task = new BitmapWorkerTask(data, imageView, lister);
      final AsyncDrawable asyncDrawable = new AsyncDrawable(mResources, mLoadingBitmap, task);
      imageView.setImageDrawable(asyncDrawable);
      // 通过线程池执行下载进程
      task.executeOnExecutor(AsyncTask.DUAL_THREAD_EXECUTOR);
    }
  }
コード例 #21
0
ファイル: PicassoDrawable.java プロジェクト: arok/picasso
  @Override
  public void draw(Canvas canvas) {
    if (!animating) {
      super.draw(canvas);
    } else {
      float normalized = (SystemClock.uptimeMillis() - startTimeMillis) / FADE_DURATION;
      if (normalized >= 1f) {
        animating = false;
        placeholder = null;
        super.draw(canvas);
      } else {
        if (placeholder != null) {
          placeholder.draw(canvas);
        }

        int partialAlpha = (int) (alpha * normalized);
        super.setAlpha(partialAlpha);
        super.draw(canvas);
        super.setAlpha(alpha);
        if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD_MR1) {
          invalidateSelf();
        }
      }
    }

    if (debugging) {
      drawDebugIndicator(canvas);
    }
  }
コード例 #22
0
 private void startDragAtPosition(int position) {
   if (position != -1) {
     clickPosition = position;
     originPosition = position;
   }
   clickView =
       getChildAt(
           position
               - getFirstVisiblePosition()); // 任何情况下,getChildAt(int
                                             // position)返回的item都是指的可视区域内的第position个元素
   if (clickView != null) {
     mMobileItemId = getAdapter().getItemId(position);
     int w = clickView.getWidth() + 100;
     int h = clickView.getHeight() + 100;
     int left = clickView.getLeft() - 50;
     int top = clickView.getTop() - 50;
     Bitmap bitmap = getBitmapFromView(clickView);
     bitmapDrawable = new BitmapDrawable(getResources(), bitmap);
     bitmapDrawable.setAlpha(150);
     originRect = new Rect(left, top, left + w, top + h);
     currentRect = new Rect(originRect);
     bitmapDrawable.setBounds(originRect);
     clickView.setVisibility(View.INVISIBLE);
     isEditMode = true;
   }
 }
コード例 #23
0
  @Override
  protected void onDetachedFromWindow() {
    super.onDetachedFromWindow();
    if (videoPlayerInterface != null) {
      videoPlayerInterface.onDestroy();
    }
    videoPlayerInterface = null;
    if (controlsHandler != null) {
      controlsHandler.removeCallbacksAndMessages(null);
    }
    controlsHandler = null;
    appOffer = null;

    Drawable drawable = ctaImage.getDrawable();
    if (drawable instanceof BitmapDrawable) {
      BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
      Bitmap bitmap = bitmapDrawable.getBitmap();
      bitmap.recycle();
    }
    ctaImage.setImageDrawable(null);
    ctaImage.destroyDrawingCache();
    ctaImage = null;
    ingamewallVideoLayout.removeAllViews();
    ingamewallVideoLayout = null;
    System.gc();
  }
コード例 #24
0
  private Bitmap mask(Bitmap image, Bitmap mask) {
    // todo: image wiederholen und skalierung richtig
    Bitmap bitmapOut =
        Bitmap.createBitmap(mask.getWidth(), mask.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmapOut);

    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);

    if (tileImage) {
      BitmapDrawable background = new BitmapDrawable(image);
      // in this case, you want to tile the entire view
      background.setBounds(0, 0, mask.getWidth(), mask.getHeight());
      background.setTileModeXY(Shader.TileMode.REPEAT, Shader.TileMode.REPEAT);
      background.draw(canvas);
    } else {
      canvas.drawBitmap(image, (int) (mask.getWidth() * 0.5 - image.getWidth() * 0.5), 0, paint);
    }

    Paint xferPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    xferPaint.setXfermode(new PorterDuffXfermode(Mode.DST_IN));

    canvas.drawBitmap(mask, 0, 0, xferPaint);
    xferPaint.setXfermode(null);
    return bitmapOut;
  }
コード例 #25
0
 /** 设置开机图片 */
 public void initImgView() {
   imageview = (ImageView) this.findViewById(R.id.cp1);
   File sdcardDir = Environment.getExternalStorageDirectory();
   String path = sdcardDir.getParent() + "/" + sdcardDir.getName();
   // 得到开机图片
   Bitmap bitmap = BitmapFactory.decodeFile(path + DownLoadImg.LOCAL_DIR + DownLoadImg.IMG_NAME);
   String errorCode = shellRW.getStringValue("errorCode");
   if (bitmap == null || errorCode.equals("") || errorCode.equals("false")) {
     Resources r = this.getResources();
     InputStream is = r.openRawResource(R.drawable.cp1);
     BitmapDrawable bmpDraw = new BitmapDrawable(is);
     bitmap = bmpDraw.getBitmap();
   }
   // 缩放开机图片
   Matrix matrix = new Matrix();
   float iScreenWidth = PublicMethod.getDisplayWidth(this);
   float iScreenHeight = PublicMethod.getDisplayHeight(this);
   float w = iScreenWidth / bitmap.getWidth();
   float h = iScreenHeight / bitmap.getHeight();
   if (w != 1 || h != 1) {
     matrix.postScale(w, h);
     bitmap =
         Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
   }
   imageview.setImageBitmap(bitmap);
 }
コード例 #26
0
 private void applyRenderers() {
   if (renderers != null) {
     Spannable spannableString = new SpannableString(view.getText());
     Set<String> spanPatterns = renderers.keySet();
     for (String spanPattern : spanPatterns) {
       Pattern pattern = Pattern.compile(spanPattern);
       Matcher matcher = pattern.matcher(spannableString);
       while (matcher.find()) {
         int end = matcher.end();
         int start = matcher.start();
         ViewSpanRenderer renderer = renderers.get(spanPattern);
         String text = matcher.group(0);
         View view = renderer.getView(text, context);
         BitmapDrawable bitmpaDrawable = (BitmapDrawable) ViewUtils.convertViewToDrawable(view);
         bitmpaDrawable.setBounds(
             UPPER_LEFT_X,
             UPPER_LEFT_Y,
             bitmpaDrawable.getIntrinsicWidth(),
             bitmpaDrawable.getIntrinsicHeight());
         spannableString.setSpan(
             new ImageSpan(bitmpaDrawable), start, end, DEFAULT_RENDER_APPLY_MODE);
         if (renderer instanceof ViewSpanClickListener) {
           enableClickEvents();
           ClickableSpan clickableSpan = getClickableSpan(text, (ViewSpanClickListener) renderer);
           spannableString.setSpan(clickableSpan, start, end, DEFAULT_RENDER_APPLY_MODE);
         }
       }
     }
     view.setText(spannableString);
   }
 }
コード例 #27
0
  /**
   * 获取自定义属性
   *
   * @param attrs
   */
  private void obtainStyledAttributes(AttributeSet attrs) {
    metrics = getContext().getResources().getDisplayMetrics();
    framePadding =
        (int)
            TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, DEFAULT_FRAME_PADDING, metrics);
    frameWidth =
        (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, DEFAULT_FRAME_WIDTH, metrics);

    TypedArray mTypedArray = getContext().obtainStyledAttributes(attrs, R.styleable.WaterMarkView);

    Drawable srcDrawble = mTypedArray.getDrawable(R.styleable.WaterMarkView_src);
    if (srcDrawble instanceof BitmapDrawable) {
      BitmapDrawable bd = (BitmapDrawable) srcDrawble;
      this.mWaterMarkBitmap = bd.getBitmap();
    }

    framePadding =
        mTypedArray.getDimensionPixelSize(R.styleable.WaterMarkView_framePadding, framePadding);
    frameWidth =
        mTypedArray.getDimensionPixelSize(R.styleable.WaterMarkView_frameWidth, frameWidth);
    frameColor = mTypedArray.getColor(R.styleable.WaterMarkView_frameColor, DEFAULT_FRAME_COLOR);
    mScale = mTypedArray.getFloat(R.styleable.WaterMarkView_scale, DEFAULT_SCALE);
    mDegree = mTypedArray.getFloat(R.styleable.WaterMarkView_degree, DEFAULT_DEGREE);
    controlDrawable = mTypedArray.getDrawable(R.styleable.WaterMarkView_controlDrawable);
    controlLocation =
        mTypedArray.getInt(R.styleable.WaterMarkView_controlLocation, DEFAULT_CONTROL_LOCATION);
    isEditable = mTypedArray.getBoolean(R.styleable.WaterMarkView_editable, DEFAULT_EDITABLE);

    mTypedArray.recycle();
  }
コード例 #28
0
    @TestTargetNew(
        level = TestLevel.COMPLETE,
        notes = "Test {@link ImageView#setImageURI(Uri)}",
        method = "setImageURI",
        args = {android.net.Uri.class}
    )
    @UiThreadTest
    public void testSetImageURI() {
        mImageView = findImageViewById(R.id.imageview);
        mImageView.setImageURI(null);
        assertNull(mImageView.getDrawable());

        File dbDir = getInstrumentation().getTargetContext().getDir("tests",
                Context.MODE_PRIVATE);
        File imagefile = new File(dbDir, "tempimage.jpg");
        if (imagefile.exists()) {
            imagefile.delete();
        }
        createSampleImage(imagefile, R.raw.testimage);
        final String path = imagefile.getPath();
        mImageView.setImageURI(Uri.parse(path));
        assertTrue(mImageView.isLayoutRequested());
        assertNotNull(mImageView.getDrawable());

        Drawable imageViewDrawable = mImageView.getDrawable();
        BitmapDrawable imageViewBitmap = (BitmapDrawable) imageViewDrawable;
        Bitmap.Config viewConfig = imageViewBitmap.getBitmap().getConfig();
        Bitmap testimageBitmap = WidgetTestUtils.getUnscaledAndDitheredBitmap(
                mActivity.getResources(), R.raw.testimage, viewConfig);

        WidgetTestUtils.assertEquals(testimageBitmap, imageViewBitmap.getBitmap());
    }
コード例 #29
0
 public void init() {
   vWidth = getWidth() - getPaddingLeft() - getPaddingRight();
   vHeight = getHeight() - getPaddingTop() - getPaddingBottom();
   Drawable drawable = getDrawable();
   BitmapDrawable bd = (BitmapDrawable) drawable;
   bd.setAntiAlias(true);
 }
コード例 #30
0
 public Drawable getDrawable(String source) {
   File output = null;
   if (destroyed) {
     return loading.getDrawable(source);
   }
   try {
     output = File.createTempFile("image", ".jpg", dir);
     InputStream is = fetch(source);
     if (is != null) {
       boolean success = FileUtils.save(output, is);
       if (success) {
         Bitmap bitmap = ImageUtils.getBitmap(output, width, Integer.MAX_VALUE);
         if (bitmap == null) {
           return loading.getDrawable(source);
         }
         loadedBitmaps.add(new WeakReference<Bitmap>(bitmap));
         BitmapDrawable drawable = new BitmapDrawable(context.getResources(), bitmap);
         drawable.setBounds(0, 0, bitmap.getWidth(), bitmap.getHeight());
         return drawable;
       } else {
         return loading.getDrawable(source);
       }
     } else {
       return loading.getDrawable(source);
     }
   } catch (IOException e) {
     return loading.getDrawable(source);
   } finally {
     if (output != null) output.delete();
   }
 }