java类android.graphics.drawable.NinePatchDrawable的实例源码

FloatingDrawerView.java 文件源码 项目:FastAccess 阅读 29 收藏 0 点赞 0 评论 0
@SuppressLint("InflateParams")
@Override public void onShow(@NonNull WindowManager windowManager, @NonNull View view, @NonNull FolderModel folder) {
    this.windowManager = windowManager;
    Context context = view.getContext();
    drawerHolder = new AppDrawerHolder(LayoutInflater.from(view.getContext()).inflate(R.layout.floating_folder_layout, null, false), this);
    adapter = new FloatingFolderAppsAdapter(new ArrayList<AppsModel>(), getPresenter(), false);
    drawerHolder.recycler.setAdapter(adapter);
    drawerHolder.emptyText.setText(R.string.no_apps);
    drawerHolder.recycler.setEmptyView(drawerHolder.emptyText);
    drawerHolder.folderName.setText(folder.getFolderName());
    NinePatchDrawable drawable = (NinePatchDrawable) drawerHolder.appDrawer.getBackground();
    drawable.setColorFilter(new PorterDuffColorFilter(folder.getColor(),
            PorterDuff.Mode.MULTIPLY));
    setupParams(windowManager);
    appsLoader = new SelectedAppsLoader(context, folder.getId());
    appsLoader.registerListener(folder.hashCode(), getPresenter());
    appsLoader.startLoading();
}
LineView.java 文件源码 项目:soulissapp 阅读 26 收藏 0 点赞 0 评论 0
/**
 * @param canvas The canvas you need to draw on.
 * @param point  The Point consists of the x y coordinates from left bottom to right top.
 *               Like is
 *               <p/>
 *               3
 *               2
 *               1
 *               0 1 2 3 4 5
 */
private void drawPopup(Canvas canvas, String num, Point point, int PopupColor) {
    boolean singularNum = (num.length() == 1);
    int sidePadding = ChartUtils.dip2px(getContext(), singularNum ? 8 : 5);
    int x = point.x;
    int y = point.y - ChartUtils.dip2px(getContext(), 5);
    Rect popupTextRect = new Rect();
    popupTextPaint.getTextBounds(num, 0, num.length(), popupTextRect);
    Rect r = new Rect(x - popupTextRect.width() / 2 - sidePadding,
            y - popupTextRect.height() - bottomTriangleHeight - popupTopPadding * 2 - popupBottomMargin,
            x + popupTextRect.width() / 2 + sidePadding,
            y + popupTopPadding - popupBottomMargin);

    NinePatchDrawable popup = (NinePatchDrawable) getResources().getDrawable(PopupColor);
    popup.setBounds(r);
    popup.draw(canvas);
    canvas.drawText(num, x, y - bottomTriangleHeight - popupBottomMargin, popupTextPaint);
}
BubbleRessources.java 文件源码 项目:sonarflow-android 阅读 18 收藏 0 点赞 0 评论 0
public BubbleRessources(Context context) {
    backgroundColor = Color.argb(255, 0, 0, 0);
    textPaint = new Paint(Paint.LINEAR_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG);
    textPaint.setColor(Color.WHITE);
    final int LABEL_TEXT_SIZE_DP = 13; // DP
    textPaint.setTextSize(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
            LABEL_TEXT_SIZE_DP, context.getResources().getDisplayMetrics()));
    textPaint.setShadowLayer(2, 1, 1, Color.BLACK);
    labelBackground = (NinePatchDrawable) context.getResources().getDrawable(R.drawable.bubble_text_background);
    labelPadding = new Rect();
    labelBackground.getPadding(labelPadding);
    bubbleGlow = context.getResources().getDrawable(R.drawable.bubble_glow_256);
    bubbleImages = new Drawable[4];
    bubbleImages[0] = context.getResources().getDrawable(R.drawable.bubble_32);
    bubbleImages[1] = context.getResources().getDrawable(R.drawable.bubble_64);
    bubbleImages[2] = context.getResources().getDrawable(R.drawable.bubble_128);
    bubbleImages[3] = context.getResources().getDrawable(R.drawable.bubble_256);
    discoveryBubble = context.getResources().getDrawable(R.drawable.similar_bubble);
    colorFilters = new ColorFilters(Mode.MULTIPLY);
}
ImageShow.java 文件源码 项目:nexus-gallery 阅读 17 收藏 0 点赞 0 评论 0
private void setupImageShow(Context context) {
    Resources res = context.getResources();
    mTextSize = res.getDimensionPixelSize(R.dimen.photoeditor_text_size);
    mTextPadding = res.getDimensionPixelSize(R.dimen.photoeditor_text_padding);
    mOriginalTextMargin = res.getDimensionPixelSize(R.dimen.photoeditor_original_text_margin);
    mOriginalTextSize = res.getDimensionPixelSize(R.dimen.photoeditor_original_text_size);
    mBackgroundColor = res.getColor(R.color.background_screen);
    mOriginalText = res.getString(R.string.original_picture_text);
    mShadow = (NinePatchDrawable) res.getDrawable(R.drawable.geometry_shadow);
    setupGestureDetector(context);
    mActivity = (FilterShowActivity) context;
    if (sMask == null) {
        Bitmap mask = BitmapFactory.decodeResource(res, R.drawable.spot_mask);
        sMask = convertToAlphaMask(mask);
    }
    mEdgeEffect = new EdgeEffectCompat(context);
    mEdgeSize = res.getDimensionPixelSize(R.dimen.edge_glow_size);
}
ImageDraw.java 文件源码 项目:nexus-gallery 阅读 23 收藏 0 点赞 0 评论 0
private void setupConstants(Context context){
    Resources res = context.getResources();
    mDisplayRound = res.getDimensionPixelSize(R.dimen.draw_rect_round);
    mDisplayBorder = res.getDimensionPixelSize(R.dimen.draw_rect_border);
    mBorderShadowSize = res.getDimensionPixelSize(R.dimen.draw_rect_shadow);
    float edge = res.getDimensionPixelSize(R.dimen.draw_rect_border_edge);

    mBorderColor = res.getColor(R.color.draw_rect_border);
    mBorderPaint.setColor(mBorderColor);
    mBorderPaint.setStyle(Paint.Style.STROKE);
    mBorderPaint.setStrokeWidth(edge);
    mShadowPaint.setStyle(Paint.Style.FILL);
    mShadowPaint.setColor(Color.BLACK);
    mShadowPaint.setShadowLayer(mBorderShadowSize,mBorderShadowSize,
            mBorderShadowSize,Color.BLACK);
    mShadow = (NinePatchDrawable) res.getDrawable(R.drawable.geometry_shadow);
}
DrawUtils.java 文件源码 项目:Android-SmartChart 阅读 21 收藏 0 点赞 0 评论 0
/**
 * Drawable ת bitmap
 * 
 * @param drawable
 * @return
 */
public static Bitmap drawable2Bitmap(Drawable drawable)
{
    if (drawable instanceof BitmapDrawable)
    {
        return ((BitmapDrawable) drawable).getBitmap();
    }
    else if (drawable instanceof NinePatchDrawable)
    {
        Bitmap bitmap =
                    Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), drawable
                                .getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888
                                : Bitmap.Config.RGB_565);
        Canvas canvas = new Canvas(bitmap);
        drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
        drawable.draw(canvas);
        return bitmap;
    }
    else
    {
        return null;
    }
}
DrawShadowFrameLayout.java 文件源码 项目:Lollipop-AppCompat-Widgets-Skeleton 阅读 18 收藏 0 点赞 0 评论 0
public DrawShadowFrameLayout(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    final TypedArray a = context.obtainStyledAttributes(attrs,
            R.styleable.DrawShadowFrameLayout, 0, 0);

    mShadowDrawable = a.getDrawable(R.styleable.DrawShadowFrameLayout_shadowDrawable);
    if (mShadowDrawable != null) {
        mShadowDrawable.setCallback(this);
        if (mShadowDrawable instanceof NinePatchDrawable) {
            mShadowNinePatchDrawable = (NinePatchDrawable) mShadowDrawable;
        }
    }

    mShadowVisible = a.getBoolean(R.styleable.DrawShadowFrameLayout_shadowVisible, true);
    setWillNotDraw(!mShadowVisible || mShadowDrawable == null);

    a.recycle();
}
ImageDrawing.java 文件源码 项目:actor-platform 阅读 16 收藏 0 点赞 0 评论 0
/**
 * Drawing src bitmap to dest bitmap with applied mask.
 *
 * @param src        source bitmap
 * @param mask       bitmap mask
 * @param dest       destination bitmap
 * @param clearColor clear color
 */
public static void drawMasked(Bitmap src, Drawable mask, Bitmap dest, int clearColor) {
    clearBitmap(dest, clearColor);
    Canvas canvas = new Canvas(dest);

    canvas.drawBitmap(src,
            new Rect(0, 0, src.getWidth(), src.getHeight()),
            new Rect(0, 0, dest.getWidth(), dest.getHeight()),
            new Paint(Paint.FILTER_BITMAP_FLAG));

    if (mask instanceof BitmapDrawable) {
        ((BitmapDrawable) mask).getPaint().setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));
    } else if (mask instanceof NinePatchDrawable) {
        ((NinePatchDrawable) mask).getPaint().setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));
    } else {
        throw new RuntimeException("Supported only BitmapDrawable or NinePatchDrawable");
    }
    mask.setBounds(0, 0, mask.getIntrinsicWidth(), mask.getIntrinsicHeight());
    mask.draw(canvas);
    canvas.setBitmap(null);
}
ForegroundRelativeLayout.java 文件源码 项目:Android-nRF-Toolbox 阅读 20 收藏 0 点赞 0 评论 0
public ForegroundRelativeLayout(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ForegroundRelativeLayout,
            defStyle, 0);

    final Drawable d = a.getDrawable(R.styleable.ForegroundRelativeLayout_foreground);
    if (d != null) {
        setForeground(d);
    }

    a.recycle();

    if (this.getBackground() instanceof NinePatchDrawable) {
        final NinePatchDrawable npd = (NinePatchDrawable) this.getBackground();
        mRectPadding = new Rect();
        if (npd.getPadding(mRectPadding)) {
         mUseBackgroundPadding = true;
        }
    }
}
ForegroundLinearLayout.java 文件源码 项目:Android-nRF-Toolbox 阅读 24 收藏 0 点赞 0 评论 0
public ForegroundLinearLayout(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ForegroundLinearLayout,
            defStyle, 0);

    final Drawable d = a.getDrawable(R.styleable.ForegroundRelativeLayout_foreground);
    if (d != null) {
        setForeground(d);
    }

    a.recycle();

    if (this.getBackground() instanceof NinePatchDrawable) {
        final NinePatchDrawable npd = (NinePatchDrawable) this.getBackground();
        mRectPadding = new Rect();
        if (npd.getPadding(mRectPadding)) {
         mUseBackgroundPadding = true;
        }
    }
}


问题


面经


文章

微信
公众号

扫码关注公众号