use of android.graphics.drawable.NinePatchDrawable in project CoCoin by Nightonke.
the class TagSettingActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_tag_setting);
mContext = this;
int currentapiVersion = android.os.Build.VERSION.SDK_INT;
if (currentapiVersion >= Build.VERSION_CODES.LOLLIPOP) {
// Do something for lollipop and above versions
Window window = this.getWindow();
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(ContextCompat.getColor(mContext, R.color.statusBarColor));
} else {
// do something for phones running an SDK before lollipop
}
//noinspection ConstantConditions
mRecyclerView = (RecyclerView) findViewById(R.id.recyclerView);
mLayoutManager = new GridLayoutManager(this, 3, GridLayoutManager.VERTICAL, false);
// drag & drop manager
mRecyclerViewDragDropManager = new RecyclerViewDragDropManager();
mRecyclerViewDragDropManager.setDraggingItemShadowDrawable((NinePatchDrawable) ContextCompat.getDrawable(this, R.drawable.material_shadow_z3));
// Start dragging after long press
mRecyclerViewDragDropManager.setInitiateOnLongPress(true);
mRecyclerViewDragDropManager.setInitiateOnMove(false);
mRecyclerViewDragDropManager.setLongPressTimeout(750);
//adapter
myItemAdapter = new TagDraggableItemAdapter();
mAdapter = myItemAdapter;
// wrap for dragging
mWrappedAdapter = mRecyclerViewDragDropManager.createWrappedAdapter(myItemAdapter);
final GeneralItemAnimator animator = new RefactoredDefaultItemAnimator();
mRecyclerView.setLayoutManager(mLayoutManager);
// requires *wrapped* adapter
mRecyclerView.setAdapter(mWrappedAdapter);
mRecyclerView.setItemAnimator(animator);
mRecyclerView.addItemDecoration(new ItemShadowDecorator((NinePatchDrawable) ContextCompat.getDrawable(this, R.drawable.material_shadow_z1)));
mRecyclerViewDragDropManager.attachRecyclerView(mRecyclerView);
back = (MaterialIconView) findViewById(R.id.icon_left);
check = (MaterialIconView) findViewById(R.id.check);
title = (TextView) findViewById(R.id.title);
title.setText((RecordManager.TAGS.size() - 2) + mContext.getResources().getString(R.string.tag_number));
back.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
check.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
saveChanges(true);
}
});
}
use of android.graphics.drawable.NinePatchDrawable in project robolectric by robolectric.
the class ShadowDrawable method createFromResourceStream.
// todo: this sucks, it's all just so we can detect 9-patches
@Implementation
public static Drawable createFromResourceStream(Resources res, TypedValue value, InputStream is, String srcName, BitmapFactory.Options opts) {
if (is == null) {
return null;
}
Rect pad = new Rect();
if (opts == null)
opts = new BitmapFactory.Options();
opts.inScreenDensity = DisplayMetrics.DENSITY_DEFAULT;
Bitmap bm = BitmapFactory.decodeResourceStream(res, value, is, pad, opts);
if (bm != null) {
boolean isNinePatch = srcName != null && srcName.contains(".9.");
if (isNinePatch) {
ReflectionHelpers.callInstanceMethod(bm, "setNinePatchChunk", ClassParameter.from(byte[].class, new byte[0]));
}
byte[] np = bm.getNinePatchChunk();
if (np == null || !NinePatch.isNinePatchChunk(np)) {
np = null;
pad = null;
}
if (np != null) {
// todo: wrong
return new NinePatchDrawable(res, bm, np, pad, srcName);
}
return new BitmapDrawable(res, bm);
}
return null;
}
use of android.graphics.drawable.NinePatchDrawable in project Toasty by GrenderG.
the class ToastyUtils method tint9PatchDrawableFrame.
static Drawable tint9PatchDrawableFrame(@NonNull Context context, @ColorInt int tintColor) {
final NinePatchDrawable toastDrawable = (NinePatchDrawable) getDrawable(context, R.drawable.toast_frame);
toastDrawable.setColorFilter(new PorterDuffColorFilter(tintColor, PorterDuff.Mode.SRC_IN));
return toastDrawable;
}
use of android.graphics.drawable.NinePatchDrawable in project android_frameworks_base by crdroidandroid.
the class ResourceHelper method getNinePatchDrawable.
private static Drawable getNinePatchDrawable(InputStream inputStream, Density density, boolean isFramework, String cacheKey, BridgeContext context) throws IOException {
// see if we still have both the chunk and the bitmap in the caches
NinePatchChunk chunk = Bridge.getCached9Patch(cacheKey, isFramework ? null : context.getProjectKey());
Bitmap bitmap = Bridge.getCachedBitmap(cacheKey, isFramework ? null : context.getProjectKey());
// if either chunk or bitmap is null, then we reload the 9-patch file.
if (chunk == null || bitmap == null) {
try {
NinePatch ninePatch = NinePatch.load(inputStream, true, /*is9Patch*/
false);
if (ninePatch != null) {
if (chunk == null) {
chunk = ninePatch.getChunk();
Bridge.setCached9Patch(cacheKey, chunk, isFramework ? null : context.getProjectKey());
}
if (bitmap == null) {
bitmap = Bitmap_Delegate.createBitmap(ninePatch.getImage(), false, /*isMutable*/
density);
Bridge.setCachedBitmap(cacheKey, bitmap, isFramework ? null : context.getProjectKey());
}
}
} catch (MalformedURLException e) {
// URL is wrong, we'll return null below
}
}
if (chunk != null && bitmap != null) {
int[] padding = chunk.getPadding();
Rect paddingRect = new Rect(padding[0], padding[1], padding[2], padding[3]);
return new NinePatchDrawable(context.getResources(), bitmap, NinePatch_Delegate.serialize(chunk), paddingRect, null);
}
return null;
}
Aggregations