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);
}
}
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;
}
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) {
}
}
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);
}
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);
}
Aggregations