下面列出了怎么用android.graphics.drawable.NinePatchDrawable的API类实例代码及写法,或者点击链接到github查看源代码。
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);
}
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;
}
/**
* 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;
}
}
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);
}
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);
}
/**
* 获取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;
}
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;
}
}
/**
* 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;
}
}
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);
}
/**
* 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;
}
}
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;
}
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();
}
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();
}
@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();
}
/**
* @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);
}
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();
}
/**
* 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);
}
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;
}
}
}
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;
}
}
}
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;
}
}
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);
}
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();
}
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();
}
/**
*
* @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);
}
@Override
public void showDevices(List<LightsNSwitchesDevice> devices) {
logger.debug("Received {} lights & switches devices.", devices.size());
List<LightsNSwitchesDevice> userOrderedDeviceList = LightsNSwitchesPreferenceDelegate.loadLightsAndSwitchesDeviceOrder(devices);
Activity activity = getActivity();
if(activity == null){
return;
}
deviceListAdapter = new LightsNSwitchesDeviceControlAdapter(activity, userOrderedDeviceList);
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(activity);
linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
mRecyclerViewDragDropManager = new RecyclerViewDragDropManager();
NinePatchDrawable ninePatchDrawable = (NinePatchDrawable) ContextCompat.getDrawable(activity, R.drawable.material_shadow_z3);
if(ninePatchDrawable != null){
mRecyclerViewDragDropManager.setDraggingItemShadowDrawable(ninePatchDrawable);
}
wrappedDeviceListAdapter = mRecyclerViewDragDropManager.createWrappedAdapter(deviceListAdapter);
deviceList.setLayoutManager(linearLayoutManager);
deviceList.setAdapter(wrappedDeviceListAdapter);
deviceList.setItemAnimator(new RefactoredDefaultItemAnimator());
mRecyclerViewDragDropManager.attachRecyclerView(deviceList);
}
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = super.onCreateView(inflater, container, savedInstanceState);
RecyclerView mRecyclerView = (RecyclerView) view.findViewById(R.id.fragment_alarm_call_list);
RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getActivity());
alarmTitle = (Version1TextView) view.findViewById(R.id.fragment_alarm_call_list_title);
alarmSubTitle = (Version1TextView) view.findViewById(R.id.fragment_alarm_call_list_subtitle);
callTreeSubText = view.findViewById(R.id.call_tree_sub_text);
if(SUBSYSTEM_SAFETY.equals(mSubsystem)) {
alarmTitle.setText(getString(R.string.safety_alarm_premium_title));
}
else if (SUBSYSTEM_CARE.equals(mSubsystem)) {
alarmTitle.setText(getString(R.string.care_alarm_premium_title));
if (callTreeSubText != null) {
callTreeSubText.setVisibility(View.VISIBLE);
}
}else{
alarmTitle.setText(getString(R.string.security_alarm_premium_title));
}
alarmSubTitle.setText(getString(R.string.safety_alarm_premium_sub_title));
// drag & drop manager
RecyclerViewDragDropManager mRecyclerViewDragDropManager = new RecyclerViewDragDropManager();
mRecyclerViewDragDropManager.setDraggingItemShadowDrawable((NinePatchDrawable) ContextCompat.getDrawable(getActivity(), R.drawable.material_shadow_z3));
mAdapter = new CallListEntryAdapter();
RecyclerView.Adapter mWrappedAdapter = mRecyclerViewDragDropManager.createWrappedAdapter(mAdapter);
final GeneralItemAnimator animator = new RefactoredDefaultItemAnimator();
mRecyclerView.setLayoutManager(mLayoutManager);
mRecyclerView.setAdapter(mWrappedAdapter); // requires *wrapped* adapter
//mRecyclerView.setItemAnimator(animator);
mRecyclerViewDragDropManager.attachRecyclerView(mRecyclerView);
return view;
}
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = super.onCreateView(inflater, container, savedInstanceState);
RecyclerView mRecyclerView = (RecyclerView) view.findViewById(R.id.fragment_alarm_call_list);
RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getActivity());
alarmTitle = (Version1TextView) view.findViewById(R.id.fragment_alarm_call_list_title);
alarmSubTitle = (Version1TextView) view.findViewById(R.id.fragment_alarm_call_list_subtitle);
addPeopleText = (Version1TextView) view.findViewById(R.id.call_tree_sub_text);
alarmTitle.setText(getString(R.string.doors_and_locks_access_title));
alarmSubTitle.setText(getString(R.string.doors_and_locks_access_des));
addPeopleText.setText(R.string.doors_and_locks_access_no_people);
addPeopleText.setVisibility(View.VISIBLE);
// drag & drop manager
RecyclerViewDragDropManager mRecyclerViewDragDropManager = new RecyclerViewDragDropManager();
mRecyclerViewDragDropManager.setDraggingItemShadowDrawable((NinePatchDrawable) ContextCompat.getDrawable(getActivity(), R.drawable.material_shadow_z3));
mAdapter = new AccessStateAdapter();
mRecyclerView.setLayoutManager(mLayoutManager);
mRecyclerView.setAdapter(mRecyclerViewDragDropManager.createWrappedAdapter(mAdapter));
//mRecyclerView.setItemAnimator(new RefactoredDefaultItemAnimator());
mRecyclerViewDragDropManager.attachRecyclerView(mRecyclerView);
return view;
}
@SuppressWarnings("deprecation")
@Nullable
@Override
public View onCreateView3(LayoutInflater inflater,
@Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.scene_label_list, container, false);
mRecyclerView = (EasyRecyclerView) ViewUtils.$$(view, R.id.recycler_view);
TextView tip = (TextView) ViewUtils.$$(view, R.id.tip);
mViewTransition = new ViewTransition(mRecyclerView, tip);
Context context = getContext2();
AssertUtils.assertNotNull(context);
Drawable drawable = DrawableManager.getVectorDrawable(context, R.drawable.big_search);
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
tip.setCompoundDrawables(null, drawable, null, null);
tip.setText(R.string.no_quick_search);
// drag & drop manager
RecyclerViewDragDropManager dragDropManager = new RecyclerViewDragDropManager();
dragDropManager.setDraggingItemShadowDrawable(
(NinePatchDrawable) context.getResources().getDrawable(R.drawable.shadow_8dp));
RecyclerView.Adapter adapter = new QuickSearchAdapter();
adapter.setHasStableIds(true);
adapter = dragDropManager.createWrappedAdapter(adapter); // wrap for dragging
mAdapter = adapter;
final GeneralItemAnimator animator = new DraggableItemAnimator();
mRecyclerView.setLayoutManager(new LinearLayoutManager(context));
mRecyclerView.setAdapter(adapter);
mRecyclerView.setItemAnimator(animator);
dragDropManager.attachRecyclerView(mRecyclerView);
updateView();
return view;
}
@SuppressWarnings("deprecation")
@Nullable
@Override
public View onCreateView3(LayoutInflater inflater,
@Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.scene_label_list, container, false);
mRecyclerView = (EasyRecyclerView) ViewUtils.$$(view, R.id.recycler_view);
TextView tip = (TextView) ViewUtils.$$(view, R.id.tip);
mViewTransition = new ViewTransition(mRecyclerView, tip);
Context context = getContext2();
AssertUtils.assertNotNull(context);
Drawable drawable = DrawableManager.getVectorDrawable(context, R.drawable.big_label);
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
tip.setCompoundDrawables(null, drawable, null, null);
tip.setText(R.string.no_download_label);
// drag & drop manager
RecyclerViewDragDropManager dragDropManager = new RecyclerViewDragDropManager();
dragDropManager.setDraggingItemShadowDrawable(
(NinePatchDrawable) context.getResources().getDrawable(R.drawable.shadow_8dp));
RecyclerView.Adapter adapter = new LabelAdapter();
adapter.setHasStableIds(true);
adapter = dragDropManager.createWrappedAdapter(adapter); // wrap for dragging
mAdapter = adapter;
final GeneralItemAnimator animator = new SwipeDismissItemAnimator();
mRecyclerView.setLayoutManager(new LinearLayoutManager(context));
mRecyclerView.setAdapter(adapter);
mRecyclerView.setItemAnimator(animator);
dragDropManager.attachRecyclerView(mRecyclerView);
updateView();
return view;
}
private void init(Context context) {
// TODO not only 2dp
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
setOutlineProvider(ViewOutlineProvider.BOUNDS);
setElevation(LayoutUtils.dp2pix(context, 2));
} else {
setShadow((NinePatchDrawable) context.getResources().getDrawable(R.drawable.shadow_2dp)); // TODO draktheme
}
}