Search in sources :

Example 1 with NinePatchDrawable

use of android.graphics.drawable.NinePatchDrawable in project Fairphone by Kwamecorp.

the class CellLayout method dispatchDraw.

@Override
protected void dispatchDraw(Canvas canvas) {
    super.dispatchDraw(canvas);
    if (mForegroundAlpha > 0) {
        mOverScrollForegroundDrawable.setBounds(mForegroundRect);
        Paint p = ((NinePatchDrawable) mOverScrollForegroundDrawable).getPaint();
        p.setXfermode(sAddBlendMode);
        mOverScrollForegroundDrawable.draw(canvas);
        p.setXfermode(null);
    }
}
Also used : Paint(android.graphics.Paint) NinePatchDrawable(android.graphics.drawable.NinePatchDrawable)

Example 2 with NinePatchDrawable

use of android.graphics.drawable.NinePatchDrawable in project platform_frameworks_base by android.

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)

Example 3 with NinePatchDrawable

use of android.graphics.drawable.NinePatchDrawable in project Shuttle by timusus.

the class ThemeUtils method themeSearchView.

@SuppressLint("InlinedApi")
public static void themeSearchView(Context context, SearchView searchView) {
    FilterableStateListDrawable stateListDrawable = new FilterableStateListDrawable();
    NinePatchDrawable disabledDrawable = (NinePatchDrawable) CompatUtils.getDrawableCompat(context, R.drawable.abc_textfield_search_default_mtrl_alpha);
    NinePatchDrawable otherDrawable = (NinePatchDrawable) CompatUtils.getDrawableCompat(context, R.drawable.abc_textfield_search_activated_mtrl_alpha);
    int accentColor = ColorUtils.getAccentColor();
    ColorFilter colorFilter = new PorterDuffColorFilter(accentColor, PorterDuff.Mode.SRC_ATOP);
    stateListDrawable.addState(new int[] { android.R.attr.state_enabled, android.R.attr.state_activated }, otherDrawable, colorFilter);
    stateListDrawable.addState(new int[] { android.R.attr.state_enabled, android.R.attr.state_focused }, otherDrawable, colorFilter);
    stateListDrawable.addState(StateSet.WILD_CARD, disabledDrawable);
    View searchPlate = searchView.findViewById(android.support.v7.appcompat.R.id.search_plate);
    searchPlate.setBackground(stateListDrawable);
    EditText searchTextView = (EditText) searchView.findViewById(android.support.v7.appcompat.R.id.search_src_text);
    try {
        Field mCursorDrawableRes = TextView.class.getDeclaredField("mCursorDrawableRes");
        mCursorDrawableRes.setAccessible(true);
        mCursorDrawableRes.set(searchTextView, 0);
    } catch (final Exception | NoClassDefFoundError ignored) {
    }
}
Also used : FilterableStateListDrawable(com.simplecity.amp_library.ui.views.FilterableStateListDrawable) AppCompatEditText(android.support.v7.widget.AppCompatEditText) EditText(android.widget.EditText) Field(java.lang.reflect.Field) PorterDuffColorFilter(android.graphics.PorterDuffColorFilter) ColorFilter(android.graphics.ColorFilter) LightingColorFilter(android.graphics.LightingColorFilter) PorterDuffColorFilter(android.graphics.PorterDuffColorFilter) SearchView(android.support.v7.widget.SearchView) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) HmsView(com.doomonafireball.betterpickers.hmspicker.HmsView) AbsListView(android.widget.AbsListView) RecyclerView(android.support.v7.widget.RecyclerView) ScrollView(android.widget.ScrollView) SuppressLint(android.annotation.SuppressLint) NinePatchDrawable(android.graphics.drawable.NinePatchDrawable) SuppressLint(android.annotation.SuppressLint)

Example 4 with NinePatchDrawable

use of android.graphics.drawable.NinePatchDrawable in project android-advancedrecyclerview by h6ah4i.

the class ViewPagerSwipeableExampleFragment method onViewCreated.

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    //noinspection ConstantConditions
    mRecyclerView = (RecyclerView) getView().findViewById(R.id.recycler_view);
    mLayoutManager = new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false);
    // touch guard manager  (this class is required to suppress scrolling while swipe-dismiss animation is running)
    mRecyclerViewTouchActionGuardManager = new RecyclerViewTouchActionGuardManager();
    mRecyclerViewTouchActionGuardManager.setInterceptVerticalScrollingWhileAnimationRunning(true);
    mRecyclerViewTouchActionGuardManager.setEnabled(true);
    // swipe manager
    mRecyclerViewSwipeManager = new RecyclerViewSwipeManager();
    //adapter
    final ViewPagerSwipeableExampleAdapter myItemAdapter = new ViewPagerSwipeableExampleAdapter(getDataProvider(), mCanSwipeLeft);
    mAdapter = myItemAdapter;
    // wrap for swiping
    mWrappedAdapter = mRecyclerViewSwipeManager.createWrappedAdapter(myItemAdapter);
    final GeneralItemAnimator animator = new SwipeDismissItemAnimator();
    // Change animations are enabled by default since support-v7-recyclerview v22.
    // Disable the change animation in order to make turning back animation of swiped item works properly.
    animator.setSupportsChangeAnimations(false);
    mRecyclerView.setLayoutManager(mLayoutManager);
    // requires *wrapped* adapter
    mRecyclerView.setAdapter(mWrappedAdapter);
    mRecyclerView.setItemAnimator(animator);
    //noinspection StatementWithEmptyBody
    if (supportsViewElevation()) {
    // Lollipop or later has native drop shadow feature. ItemShadowDecorator is not required.
    } else {
        mRecyclerView.addItemDecoration(new ItemShadowDecorator((NinePatchDrawable) ContextCompat.getDrawable(getContext(), R.drawable.material_shadow_z1)));
    }
    mRecyclerView.addItemDecoration(new SimpleListDividerDecorator(ContextCompat.getDrawable(getContext(), R.drawable.list_divider_h), true));
    // NOTE:
    // The initialization order is very important! This order determines the priority of touch event handling.
    //
    // priority: TouchActionGuard > Swipe > DragAndDrop
    mRecyclerViewTouchActionGuardManager.attachRecyclerView(mRecyclerView);
    mRecyclerViewSwipeManager.attachRecyclerView(mRecyclerView);
// for debugging
//        animator.setDebug(true);
//        animator.setMoveDuration(2000);
//        animator.setRemoveDuration(2000);
//        mRecyclerViewSwipeManager.setMoveToOutsideWindowAnimationDuration(2000);
//        mRecyclerViewSwipeManager.setReturnToDefaultPositionAnimationDuration(2000);
}
Also used : RecyclerViewSwipeManager(com.h6ah4i.android.widget.advrecyclerview.swipeable.RecyclerViewSwipeManager) RecyclerViewTouchActionGuardManager(com.h6ah4i.android.widget.advrecyclerview.touchguard.RecyclerViewTouchActionGuardManager) ItemShadowDecorator(com.h6ah4i.android.widget.advrecyclerview.decoration.ItemShadowDecorator) GeneralItemAnimator(com.h6ah4i.android.widget.advrecyclerview.animator.GeneralItemAnimator) SimpleListDividerDecorator(com.h6ah4i.android.widget.advrecyclerview.decoration.SimpleListDividerDecorator) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) SwipeDismissItemAnimator(com.h6ah4i.android.widget.advrecyclerview.animator.SwipeDismissItemAnimator) NinePatchDrawable(android.graphics.drawable.NinePatchDrawable)

Example 5 with NinePatchDrawable

use of android.graphics.drawable.NinePatchDrawable in project android-advancedrecyclerview by h6ah4i.

the class SwipeableWithButtonExampleFragment method onViewCreated.

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    //noinspection ConstantConditions
    mRecyclerView = (RecyclerView) getView().findViewById(R.id.recycler_view);
    mLayoutManager = new LinearLayoutManager(getContext());
    // touch guard manager  (this class is required to suppress scrolling while swipe-dismiss animation is running)
    mRecyclerViewTouchActionGuardManager = new RecyclerViewTouchActionGuardManager();
    mRecyclerViewTouchActionGuardManager.setInterceptVerticalScrollingWhileAnimationRunning(true);
    mRecyclerViewTouchActionGuardManager.setEnabled(true);
    // swipe manager
    mRecyclerViewSwipeManager = new RecyclerViewSwipeManager();
    //adapter
    final SwipeableWithButtonExampleAdapter myItemAdapter = new SwipeableWithButtonExampleAdapter(getDataProvider());
    myItemAdapter.setEventListener(new SwipeableWithButtonExampleAdapter.EventListener() {

        @Override
        public void onItemPinned(int position) {
            ((SwipeableWithButtonExampleActivity) getActivity()).onItemPinned(position);
        }

        @Override
        public void onItemViewClicked(View v) {
            handleOnItemViewClicked(v);
        }

        @Override
        public void onUnderSwipeableViewButtonClicked(View v) {
            handleOnUnderSwipeableViewButtonClicked(v);
        }
    });
    mAdapter = myItemAdapter;
    // wrap for swiping
    mWrappedAdapter = mRecyclerViewSwipeManager.createWrappedAdapter(myItemAdapter);
    final GeneralItemAnimator animator = new SwipeDismissItemAnimator();
    // Change animations are enabled by default since support-v7-recyclerview v22.
    // Disable the change animation in order to make turning back animation of swiped item works properly.
    animator.setSupportsChangeAnimations(false);
    mRecyclerView.setLayoutManager(mLayoutManager);
    // requires *wrapped* adapter
    mRecyclerView.setAdapter(mWrappedAdapter);
    mRecyclerView.setItemAnimator(animator);
    //noinspection StatementWithEmptyBody
    if (supportsViewElevation()) {
    // Lollipop or later has native drop shadow feature. ItemShadowDecorator is not required.
    } else {
        mRecyclerView.addItemDecoration(new ItemShadowDecorator((NinePatchDrawable) ContextCompat.getDrawable(getContext(), R.drawable.material_shadow_z1)));
    }
    mRecyclerView.addItemDecoration(new SimpleListDividerDecorator(ContextCompat.getDrawable(getContext(), R.drawable.list_divider_h), true));
    // NOTE:
    // The initialization order is very important! This order determines the priority of touch event handling.
    //
    // priority: TouchActionGuard > Swipe > DragAndDrop
    mRecyclerViewTouchActionGuardManager.attachRecyclerView(mRecyclerView);
    mRecyclerViewSwipeManager.attachRecyclerView(mRecyclerView);
// for debugging
//        animator.setDebug(true);
//        animator.setMoveDuration(2000);
//        mRecyclerViewSwipeManager.setMoveToOutsideWindowAnimationDuration(2000);
//        mRecyclerViewSwipeManager.setReturnToDefaultPositionAnimationDuration(2000);
}
Also used : RecyclerViewSwipeManager(com.h6ah4i.android.widget.advrecyclerview.swipeable.RecyclerViewSwipeManager) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) SwipeDismissItemAnimator(com.h6ah4i.android.widget.advrecyclerview.animator.SwipeDismissItemAnimator) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View) RecyclerViewTouchActionGuardManager(com.h6ah4i.android.widget.advrecyclerview.touchguard.RecyclerViewTouchActionGuardManager) ItemShadowDecorator(com.h6ah4i.android.widget.advrecyclerview.decoration.ItemShadowDecorator) GeneralItemAnimator(com.h6ah4i.android.widget.advrecyclerview.animator.GeneralItemAnimator) SimpleListDividerDecorator(com.h6ah4i.android.widget.advrecyclerview.decoration.SimpleListDividerDecorator) 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