Search in sources :

Example 31 with NinePatchDrawable

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);
        }
    });
}
Also used : Window(android.view.Window) RefactoredDefaultItemAnimator(com.h6ah4i.android.widget.advrecyclerview.animator.RefactoredDefaultItemAnimator) GridLayoutManager(android.support.v7.widget.GridLayoutManager) ItemShadowDecorator(com.h6ah4i.android.widget.advrecyclerview.decoration.ItemShadowDecorator) TagDraggableItemAdapter(com.nightonke.saver.adapter.TagDraggableItemAdapter) GeneralItemAnimator(com.h6ah4i.android.widget.advrecyclerview.animator.GeneralItemAnimator) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) MaterialIconView(net.steamcrafted.materialiconlib.MaterialIconView) RecyclerViewDragDropManager(com.h6ah4i.android.widget.advrecyclerview.draggable.RecyclerViewDragDropManager) NinePatchDrawable(android.graphics.drawable.NinePatchDrawable)

Example 32 with NinePatchDrawable

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;
}
Also used : Rect(android.graphics.Rect) Bitmap(android.graphics.Bitmap) BitmapDrawable(android.graphics.drawable.BitmapDrawable) NinePatchDrawable(android.graphics.drawable.NinePatchDrawable) Implementation(org.robolectric.annotation.Implementation)

Example 33 with NinePatchDrawable

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;
}
Also used : PorterDuffColorFilter(android.graphics.PorterDuffColorFilter) NinePatchDrawable(android.graphics.drawable.NinePatchDrawable)

Example 34 with NinePatchDrawable

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;
}
Also used : Bitmap(android.graphics.Bitmap) MalformedURLException(java.net.MalformedURLException) Rect(android.graphics.Rect) NinePatch(com.android.ninepatch.NinePatch) NinePatchChunk(com.android.ninepatch.NinePatchChunk) NinePatchDrawable(android.graphics.drawable.NinePatchDrawable)

Aggregations

NinePatchDrawable (android.graphics.drawable.NinePatchDrawable)34 GeneralItemAnimator (com.h6ah4i.android.widget.advrecyclerview.animator.GeneralItemAnimator)19 ItemShadowDecorator (com.h6ah4i.android.widget.advrecyclerview.decoration.ItemShadowDecorator)19 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)16 SimpleListDividerDecorator (com.h6ah4i.android.widget.advrecyclerview.decoration.SimpleListDividerDecorator)16 RecyclerViewDragDropManager (com.h6ah4i.android.widget.advrecyclerview.draggable.RecyclerViewDragDropManager)10 RecyclerView (android.support.v7.widget.RecyclerView)9 View (android.view.View)9 RecyclerViewSwipeManager (com.h6ah4i.android.widget.advrecyclerview.swipeable.RecyclerViewSwipeManager)9 RecyclerViewTouchActionGuardManager (com.h6ah4i.android.widget.advrecyclerview.touchguard.RecyclerViewTouchActionGuardManager)9 Bitmap (android.graphics.Bitmap)8 DraggableItemAnimator (com.h6ah4i.android.widget.advrecyclerview.animator.DraggableItemAnimator)8 Rect (android.graphics.Rect)7 SwipeDismissItemAnimator (com.h6ah4i.android.widget.advrecyclerview.animator.SwipeDismissItemAnimator)7 NinePatch (com.android.ninepatch.NinePatch)6 NinePatchChunk (com.android.ninepatch.NinePatchChunk)6 MalformedURLException (java.net.MalformedURLException)6 Parcelable (android.os.Parcelable)5 RecyclerViewExpandableItemManager (com.h6ah4i.android.widget.advrecyclerview.expandable.RecyclerViewExpandableItemManager)5 ImageView (android.widget.ImageView)4