android.graphics.drawable.NinePatchDrawable Java Examples
The following examples show how to use
android.graphics.drawable.NinePatchDrawable.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FloatingDrawerView.java From FastAccess with GNU General Public License v3.0 | 6 votes |
@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(); }
Example #2
Source File: CropView.java From imageCrop with MIT License | 6 votes |
private void setup(Context context) { setLayerType(View.LAYER_TYPE_SOFTWARE, null); Resources rsc = context.getResources(); mShadow = (NinePatchDrawable) rsc.getDrawable(R.drawable.geometry_shadow); mCropIndicator = rsc.getDrawable(R.drawable.camera_crop); mIndicatorSize = (int) rsc.getDimension(R.dimen.crop_indicator_size); mShadowMargin = (int) rsc.getDimension(R.dimen.shadow_margin); mMargin = (int) rsc.getDimension(R.dimen.preview_margin); mMinSideSize = (int) rsc.getDimension(R.dimen.crop_min_side); mTouchTolerance = (int) rsc.getDimension(R.dimen.crop_touch_tolerance); mOverlayShadowColor = (int) rsc.getColor(R.color.crop_shadow_color); mOverlayWPShadowColor = (int) rsc.getColor(R.color.crop_shadow_wp_color); mWPMarkerColor = (int) rsc.getColor(R.color.crop_wp_markers); mDashOnLength = rsc.getDimension(R.dimen.wp_selector_dash_length); mDashOffLength = rsc.getDimension(R.dimen.wp_selector_off_length); }
Example #3
Source File: ImageUtils.java From Android-UtilCode with Apache License 2.0 | 6 votes |
/** * drawable转bitmap * * @param drawable drawable对象 * @return bitmap */ 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; } }
Example #4
Source File: ThemeUtils.java From timecat with Apache License 2.0 | 6 votes |
public static boolean containsNinePatch(Drawable drawable) { drawable = getWrapperDrawable(drawable); if (drawable instanceof NinePatchDrawable || drawable instanceof InsetDrawable || drawable instanceof LayerDrawable) { return true; } else if (drawable instanceof StateListDrawable) { final DrawableContainer.DrawableContainerState containerState = ((DrawableContainer.DrawableContainerState) drawable.getConstantState()); //can't get containState from drawable which is containing DrawableWrapperDonut //https://code.google.com/p/android/issues/detail?id=169920 if (containerState == null) { return true; } for (Drawable dr : containerState.getChildren()) { dr = getWrapperDrawable(dr); if (dr instanceof NinePatchDrawable || dr instanceof InsetDrawable || dr instanceof LayerDrawable) { return true; } } } return false; }
Example #5
Source File: DepthContainerManager.java From Android-3D-Layout with MIT License | 6 votes |
public void setup() { view.setLayerType(View.LAYER_TYPE_HARDWARE, null); view.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() { @Override public boolean onPreDraw() { for (int i = 0; i < view.getChildCount(); i++) { final View child = view.getChildAt(i); if (child instanceof DepthLayout) { boolean hasChangedBounds = ((DepthLayout) child).getDepthManager().calculateBounds(); if (hasChangedBounds) view.invalidate(); } } return true; } }); shadowPaint.setColor(Color.BLACK); shadowPaint.setAntiAlias(true); softShadow = (NinePatchDrawable) ContextCompat.getDrawable(view.getContext(), R.drawable.shadow); roundSoftShadow = ContextCompat.getDrawable(view.getContext(), R.drawable.round_soft_shadow); }
Example #6
Source File: DrawShadowFrameLayout.java From v2ex with Apache License 2.0 | 6 votes |
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(); }
Example #7
Source File: DepthRelativeLayoutContainer.java From Depth with MIT License | 6 votes |
void setup() { setLayerType(LAYER_TYPE_HARDWARE, null); getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() { @Override public boolean onPreDraw() { for (int i = 0; i < getChildCount(); i++) { View child = getChildAt(i); if (child instanceof DepthRelativeLayout) { boolean hasChangedBounds = ((DepthRelativeLayout) child).calculateBounds(); if (hasChangedBounds) invalidate(); } } return true; } }); shadowPaint.setColor(Color.BLACK); shadowPaint.setAntiAlias(true); softShadow = (NinePatchDrawable) getResources().getDrawable(R.drawable.shadow, null); roundSoftShadow = getResources().getDrawable(R.drawable.round_soft_shadow, null); }
Example #8
Source File: DrawShadowFrameLayout.java From hacker-news-android with Apache License 2.0 | 6 votes |
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(); }
Example #9
Source File: DepthRendrer.java From Android-Plugin-Framework with MIT License | 6 votes |
void setup() { getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() { @Override public boolean onPreDraw() { for (int i = 0; i < getChildCount(); i++) { View child = getChildAt(i); if (child instanceof DepthLayout) { boolean hasChangedBounds = ((DepthLayout) child).calculateBounds(); if (hasChangedBounds) invalidate(); } } return true; } }); shadowPaint.setColor(Color.BLACK); shadowPaint.setAntiAlias(true); softShadow = (NinePatchDrawable) getResources().getDrawable(R.drawable.shadow, null); roundSoftShadow = getResources().getDrawable(R.drawable.round_soft_shadow, null); }
Example #10
Source File: Utils.java From MaterialQQLite with Apache License 2.0 | 6 votes |
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; } }
Example #11
Source File: BackGroudSeletor.java From FloatBall with Apache License 2.0 | 6 votes |
/** * 获取asset下面的.9 png * * @param imagename 图片名 * @param context 上下文对象 */ public static NinePatchDrawable get9png(String imagename, Context context) { Bitmap toast_bitmap; try { toast_bitmap = BitmapFactory.decodeStream(context.getAssets().open("image/" + imagename + ".9.png")); byte[] temp = toast_bitmap.getNinePatchChunk(); boolean is_nine = NinePatch.isNinePatchChunk(temp); if (is_nine) { NinePatchDrawable nine_draw = new NinePatchDrawable(context.getResources(), toast_bitmap, temp, new Rect(), null); return nine_draw; } } catch (IOException e) { e.printStackTrace(); } return null; }
Example #12
Source File: BitmapUtil.java From Android-Application-ZJB with Apache License 2.0 | 6 votes |
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; } }
Example #13
Source File: DepthRendrer.java From HaiNaBaiChuan with Apache License 2.0 | 6 votes |
void setup() { getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() { @Override public boolean onPreDraw() { for (int i = 0; i < getChildCount(); i++) { View child = getChildAt(i); if (child instanceof DepthLayout) { boolean hasChangedBounds = ((DepthLayout) child).calculateBounds(); if (hasChangedBounds) invalidate(); } } return true; } }); shadowPaint.setColor(Color.BLACK); shadowPaint.setAntiAlias(true); softShadow = (NinePatchDrawable) getResources().getDrawable(R.drawable.shadow, null); roundSoftShadow = getResources().getDrawable(R.drawable.round_soft_shadow, null); }
Example #14
Source File: LineView.java From SimplePomodoro-android with MIT License | 6 votes |
/** * * @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 ↓ * 3 * 2 * 1 * 0 1 2 3 4 5 */ private void drawPopup(Canvas canvas,String num, Point point){ boolean singularNum = (num.length() == 1); int sidePadding = MyUtils.dip2px(getContext(),singularNum? 8:5); int x = point.x; int y = point.y-MyUtils.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(R.drawable.popup_red); popup.setBounds(r); popup.draw(canvas); canvas.drawText(num, x, y-bottomTriangleHeight-popupBottomMargin, popupTextPaint); }
Example #15
Source File: LineView.java From AndroidCharts with MIT License | 6 votes |
/** * @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 * * 3 * 2 * 1 * 0 1 2 3 4 5 */ private void drawPopup(Canvas canvas, float num, Point point, int PopupColor) { String numStr = showFloatNumInPopup ? String.valueOf(num) : String.valueOf(Math.round(num)); boolean singularNum = (numStr.length() == 1); int sidePadding = MyUtils.dip2px(getContext(), singularNum ? 8 : 5); int x = point.x; int y = point.y - MyUtils.dip2px(getContext(), 5); Rect popupTextRect = new Rect(); popupTextPaint.getTextBounds(numStr, 0, numStr.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 + popupBottomPadding); NinePatchDrawable popup = (NinePatchDrawable) getResources().getDrawable(R.drawable.popup_white); popup.setColorFilter(new PorterDuffColorFilter(PopupColor, PorterDuff.Mode.MULTIPLY)); popup.setBounds(r); popup.draw(canvas); canvas.drawText(numStr, x, y - bottomTriangleHeight - popupBottomMargin, popupTextPaint); }
Example #16
Source File: DrawShadowFrameLayout.java From Lollipop-AppCompat-Widgets-Skeleton with Apache License 2.0 | 6 votes |
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(); }
Example #17
Source File: ImageDrawing.java From actor-platform with GNU Affero General Public License v3.0 | 6 votes |
/** * 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); }
Example #18
Source File: ForegroundRelativeLayout.java From Android-nRF-Toolbox with BSD 3-Clause "New" or "Revised" License | 6 votes |
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(); rectPadding = new Rect(); if (npd.getPadding(rectPadding)) { useBackgroundPadding = true; } } }
Example #19
Source File: DrawShadowFrameLayout.java From RetailStore with Apache License 2.0 | 6 votes |
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(); }
Example #20
Source File: ForegroundLinearLayout.java From Android-nRF-Toolbox with BSD 3-Clause "New" or "Revised" License | 6 votes |
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(); rectPadding = new Rect(); if (npd.getPadding(rectPadding)) { useBackgroundPadding = true; } } }
Example #21
Source File: DrawShadowFrameLayout.java From gank with GNU General Public License v3.0 | 6 votes |
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(); }
Example #22
Source File: ThemeUtils.java From MagicaSakura with Apache License 2.0 | 6 votes |
public static boolean containsNinePatch(Drawable drawable) { drawable = getWrapperDrawable(drawable); if (drawable instanceof NinePatchDrawable || drawable instanceof InsetDrawable || drawable instanceof LayerDrawable) { return true; } else if (drawable instanceof StateListDrawable) { final DrawableContainer.DrawableContainerState containerState = ((DrawableContainer.DrawableContainerState) drawable.getConstantState()); //can't get containState from drawable which is containing DrawableWrapperDonut //https://code.google.com/p/android/issues/detail?id=169920 if (containerState == null) { return true; } for (Drawable dr : containerState.getChildren()) { dr = getWrapperDrawable(dr); if (dr instanceof NinePatchDrawable || dr instanceof InsetDrawable || dr instanceof LayerDrawable) { return true; } } } return false; }
Example #23
Source File: DanMuHelper.java From LLApp with Apache License 2.0 | 6 votes |
/** * Drawable转换成Bitmap * * @param drawable * @return */ public Bitmap drawable2Bitmap(Drawable drawable) { if (drawable instanceof BitmapDrawable) { // 转换成Bitmap return ((BitmapDrawable) drawable).getBitmap(); } else if (drawable instanceof NinePatchDrawable) { // .9图片转换成Bitmap 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; } }
Example #24
Source File: CanViewPagerActivity.java From CanPhotos with Apache License 2.0 | 6 votes |
/** * Drawable 转 bitmap * * @param drawable * @return */ public 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; } }
Example #25
Source File: ImageLoadingResult.java From NinePatchChunk with Apache License 2.0 | 5 votes |
/** * Method creates NinePatchDrawable according to the current object state. * @param resources uses to get some information about system, get access to resources cache. * @param strName if not null it will be cached with this name inside resource manager. * @return 9 patch drawable instance or null if bitmap was null. */ public NinePatchDrawable getNinePatchDrawable(Resources resources, String strName){ if(bitmap == null) return null; if(chunk == null) return new NinePatchDrawable(resources, bitmap, null, new Rect(), strName); return new NinePatchDrawable(resources, bitmap, chunk.toBytes(), chunk.padding, strName); }
Example #26
Source File: ForegroundRelativeLayout.java From ForegroundViews with Apache License 2.0 | 5 votes |
public ForegroundRelativeLayout(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ForegroundLayout, defStyle, 0); final Drawable d = a.getDrawable(R.styleable.ForegroundLayout_foreground); foregroundPadding = a.getBoolean(R.styleable.ForegroundLayout_foregroundInsidePadding, false); backgroundAsForeground = a.getBoolean(R.styleable.ForegroundLayout_backgroundAsForeground, false); // Apply foreground padding for ninepatches automatically if (!foregroundPadding && getBackground() instanceof NinePatchDrawable) { final NinePatchDrawable npd = (NinePatchDrawable) getBackground(); if (npd != null && npd.getPadding(rectPadding)) { foregroundPadding = true; } } final Drawable b = getBackground(); if (backgroundAsForeground && b != null) { setForeground(b); } else if (d != null) { setForeground(d); } a.recycle(); }
Example #27
Source File: ForegroundTextView.java From ForegroundViews with Apache License 2.0 | 5 votes |
public ForegroundTextView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ForegroundLayout, defStyle, 0); final Drawable d = a.getDrawable(R.styleable.ForegroundLayout_foreground); foregroundPadding = a.getBoolean(R.styleable.ForegroundLayout_foregroundInsidePadding, false); backgroundAsForeground = a.getBoolean(R.styleable.ForegroundLayout_backgroundAsForeground, false); // Apply foreground padding for ninepatches automatically if (!foregroundPadding && getBackground() instanceof NinePatchDrawable) { final NinePatchDrawable npd = (NinePatchDrawable) getBackground(); if (npd != null && npd.getPadding(rectPadding)) { foregroundPadding = true; } } final Drawable b = getBackground(); if (backgroundAsForeground && b != null) { setForeground(b); } else if (d != null) { setForeground(d); } a.recycle(); }
Example #28
Source File: ForegroundLinearLayout.java From ForegroundViews with Apache License 2.0 | 5 votes |
public ForegroundLinearLayout(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ForegroundLayout, defStyle, 0); final Drawable d = a.getDrawable(R.styleable.ForegroundLayout_foreground); foregroundPadding = a.getBoolean(R.styleable.ForegroundLayout_foregroundInsidePadding, false); backgroundAsForeground = a.getBoolean(R.styleable.ForegroundLayout_backgroundAsForeground, false); // Apply foreground padding for ninepatches automatically if (!foregroundPadding && getBackground() instanceof NinePatchDrawable) { final NinePatchDrawable npd = (NinePatchDrawable) getBackground(); if (npd != null && npd.getPadding(rectPadding)) { foregroundPadding = true; } } final Drawable b = getBackground(); if (backgroundAsForeground && b != null) { setForeground(b); } else if (d != null) { setForeground(d); } a.recycle(); }
Example #29
Source File: MaterialShadowContainerView.java From android-materialshadowninepatch with Apache License 2.0 | 5 votes |
private NinePatchDrawable getNinePatchDrawableFromResource(int resId) { final Drawable drawable = (resId != 0) ? getResources().getDrawable(resId) : null; if (drawable instanceof NinePatchDrawable) { return (NinePatchDrawable) drawable; } else { return null; } }
Example #30
Source File: ChatImageView.java From ChatImageView with MIT License | 5 votes |
private void init() { mMatrix = new Matrix(); mPaint = new Paint(Paint.ANTI_ALIAS_FLAG); if (mMaskResId <= 0) { return; } mMaskBmp = BitmapFactory.decodeResource(getResources(), mMaskResId); byte[] ninePatchChunk = mMaskBmp.getNinePatchChunk(); if (ninePatchChunk != null && NinePatch.isNinePatchChunk(ninePatchChunk)) { mMaskDrawable = new NinePatchDrawable(getResources(), mMaskBmp, ninePatchChunk, new Rect(), null); } internalSetImage(); }