List of usage examples for android.support.v4.content ContextCompat getDrawable
public static final Drawable getDrawable(Context context, int i)
From source file:com.h6ah4i.android.example.advrecyclerview.demo_eds.RecyclerListViewFragment.java
@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()); final Parcelable eimSavedState = (savedInstanceState != null) ? savedInstanceState.getParcelable(SAVED_STATE_EXPANDABLE_ITEM_MANAGER) : null;// w ww . j a va 2 s. co m mRecyclerViewExpandableItemManager = new RecyclerViewExpandableItemManager(eimSavedState); mRecyclerViewExpandableItemManager.setOnGroupExpandListener(this); mRecyclerViewExpandableItemManager.setOnGroupCollapseListener(this); // 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); // drag & drop manager mRecyclerViewDragDropManager = new RecyclerViewDragDropManager(); mRecyclerViewDragDropManager.setDraggingItemShadowDrawable( (NinePatchDrawable) ContextCompat.getDrawable(getContext(), R.drawable.material_shadow_z3)); // swipe manager mRecyclerViewSwipeManager = new RecyclerViewSwipeManager(); //adapter final MyExpandableDraggableSwipeableItemAdapter myItemAdapter = new MyExpandableDraggableSwipeableItemAdapter( mRecyclerViewExpandableItemManager, getDataProvider()); myItemAdapter.setEventListener(new MyExpandableDraggableSwipeableItemAdapter.EventListener() { @Override public void onGroupItemRemoved(int groupPosition) { ((ExpandableDraggableSwipeableExampleActivity) getActivity()).onGroupItemRemoved(groupPosition); } @Override public void onChildItemRemoved(int groupPosition, int childPosition) { ((ExpandableDraggableSwipeableExampleActivity) getActivity()).onChildItemRemoved(groupPosition, childPosition); } @Override public void onGroupItemPinned(int groupPosition) { ((ExpandableDraggableSwipeableExampleActivity) getActivity()).onGroupItemPinned(groupPosition); } @Override public void onChildItemPinned(int groupPosition, int childPosition) { ((ExpandableDraggableSwipeableExampleActivity) getActivity()).onChildItemPinned(groupPosition, childPosition); } @Override public void onItemViewClicked(View v, boolean pinned) { onItemViewClick(v, pinned); } }); mAdapter = myItemAdapter; mWrappedAdapter = mRecyclerViewExpandableItemManager.createWrappedAdapter(myItemAdapter); // wrap for expanding mWrappedAdapter = mRecyclerViewDragDropManager.createWrappedAdapter(mWrappedAdapter); // wrap for dragging mWrappedAdapter = mRecyclerViewSwipeManager.createWrappedAdapter(mWrappedAdapter); // wrap for swiping 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. // Also need to disable them when using animation indicator. animator.setSupportsChangeAnimations(false); mRecyclerView.setLayoutManager(mLayoutManager); mRecyclerView.setAdapter(mWrappedAdapter); // requires *wrapped* adapter mRecyclerView.setItemAnimator(animator); mRecyclerView.setHasFixedSize(false); // additional decorations //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 > ExpandableItem mRecyclerViewTouchActionGuardManager.attachRecyclerView(mRecyclerView); mRecyclerViewSwipeManager.attachRecyclerView(mRecyclerView); mRecyclerViewDragDropManager.attachRecyclerView(mRecyclerView); mRecyclerViewExpandableItemManager.attachRecyclerView(mRecyclerView); }
From source file:com.esri.arcgisruntime.sample.picturemarkersymbols.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // inflate MapView from layout mMapView = (MapView) findViewById(R.id.mapView); // create a map with the imagery basemap ArcGISMap map = new ArcGISMap(Basemap.createTopographic()); // set the map to be displayed in the mapview mMapView.setMap(map);//from ww w . ja v a 2 s.com // create an initial viewpoint using an envelope (of two points, bottom left and top right) Envelope envelope = new Envelope(new Point(-228835, 6550763, SpatialReferences.getWebMercator()), new Point(-223560, 6552021, SpatialReferences.getWebMercator())); //set viewpoint on mapview mMapView.setViewpointGeometryAsync(envelope, 100.0); // create a new graphics overlay and add it to the mapview mGraphicsOverlay = new GraphicsOverlay(); mMapView.getGraphicsOverlays().add(mGraphicsOverlay); //[DocRef: Name=Picture Marker Symbol URL, Category=Fundamentals, Topic=Symbols and Renderers] //Create a picture marker symbol from a URL resource //When using a URL, you need to call load to fetch the remote resource final PictureMarkerSymbol campsiteSymbol = new PictureMarkerSymbol( "http://sampleserver6.arcgisonline.com/arcgis/rest/services/Recreation/FeatureServer/0/images/e82f744ebb069bb35b234b3fea46deae"); //Optionally set the size, if not set the image will be auto sized based on its size in pixels, //its appearance would then differ across devices with different resolutions. campsiteSymbol.setHeight(18); campsiteSymbol.setWidth(18); campsiteSymbol.loadAsync(); //[DocRef: END] campsiteSymbol.addDoneLoadingListener(new Runnable() { @Override public void run() { //Once the symbol has loaded, add a new graphic to the graphic overlay Point campsitePoint = new Point(-223560, 6552021, SpatialReferences.getWebMercator()); Graphic campsiteGraphic = new Graphic(campsitePoint, campsiteSymbol); mGraphicsOverlay.getGraphics().add(campsiteGraphic); } }); //[DocRef: Name=Picture Marker Symbol Drawable-android, Category=Fundamentals, Topic=Symbols and Renderers] //Create a picture marker symbol from an app resource BitmapDrawable pinStarBlueDrawable = (BitmapDrawable) ContextCompat.getDrawable(this, R.drawable.pin_star_blue); final PictureMarkerSymbol pinStarBlueSymbol = new PictureMarkerSymbol(pinStarBlueDrawable); //Optionally set the size, if not set the image will be auto sized based on its size in pixels, //its appearance would then differ across devices with different resolutions. pinStarBlueSymbol.setHeight(40); pinStarBlueSymbol.setWidth(40); //Optionally set the offset, to align the base of the symbol aligns with the point geometry pinStarBlueSymbol.setOffsetY(11); //The image used for the symbol has a transparent buffer around it, so the offset is not simply height/2 pinStarBlueSymbol.loadAsync(); //[DocRef: END] pinStarBlueSymbol.addDoneLoadingListener(new Runnable() { @Override public void run() { //add a new graphic with the same location as the initial viewpoint Point pinStarBluePoint = new Point(-226773, 6550477, SpatialReferences.getWebMercator()); Graphic pinStarBlueGraphic = new Graphic(pinStarBluePoint, pinStarBlueSymbol); mGraphicsOverlay.getGraphics().add(pinStarBlueGraphic); } }); //see createPictureMarkerSymbolFromFile() method for implementation //first run checks for external storage and permissions, checkSaveResourceToExternalStorage(); }
From source file:com.h6ah4i.android.example.advrecyclerview.demo_eds.ExpandableDraggableSwipeableExampleFragment.java
@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()); final Parcelable eimSavedState = (savedInstanceState != null) ? savedInstanceState.getParcelable(SAVED_STATE_EXPANDABLE_ITEM_MANAGER) : null;//from w ww . ja v a2 s . co m mRecyclerViewExpandableItemManager = new RecyclerViewExpandableItemManager(eimSavedState); mRecyclerViewExpandableItemManager.setOnGroupExpandListener(this); mRecyclerViewExpandableItemManager.setOnGroupCollapseListener(this); // 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); // drag & drop manager mRecyclerViewDragDropManager = new RecyclerViewDragDropManager(); mRecyclerViewDragDropManager.setDraggingItemShadowDrawable( (NinePatchDrawable) ContextCompat.getDrawable(getContext(), R.drawable.material_shadow_z3)); // swipe manager mRecyclerViewSwipeManager = new RecyclerViewSwipeManager(); //adapter final ExpandableDraggableSwipeableExampleAdapter myItemAdapter = new ExpandableDraggableSwipeableExampleAdapter( mRecyclerViewExpandableItemManager, getDataProvider()); myItemAdapter.setEventListener(new ExpandableDraggableSwipeableExampleAdapter.EventListener() { @Override public void onGroupItemRemoved(int groupPosition) { ((ExpandableDraggableSwipeableExampleActivity) getActivity()).onGroupItemRemoved(groupPosition); } @Override public void onChildItemRemoved(int groupPosition, int childPosition) { ((ExpandableDraggableSwipeableExampleActivity) getActivity()).onChildItemRemoved(groupPosition, childPosition); } @Override public void onGroupItemPinned(int groupPosition) { ((ExpandableDraggableSwipeableExampleActivity) getActivity()).onGroupItemPinned(groupPosition); } @Override public void onChildItemPinned(int groupPosition, int childPosition) { ((ExpandableDraggableSwipeableExampleActivity) getActivity()).onChildItemPinned(groupPosition, childPosition); } @Override public void onItemViewClicked(View v, boolean pinned) { onItemViewClick(v, pinned); } }); mAdapter = myItemAdapter; mWrappedAdapter = mRecyclerViewExpandableItemManager.createWrappedAdapter(myItemAdapter); // wrap for expanding mWrappedAdapter = mRecyclerViewDragDropManager.createWrappedAdapter(mWrappedAdapter); // wrap for dragging mWrappedAdapter = mRecyclerViewSwipeManager.createWrappedAdapter(mWrappedAdapter); // wrap for swiping 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. // Also need to disable them when using animation indicator. animator.setSupportsChangeAnimations(false); mRecyclerView.setLayoutManager(mLayoutManager); mRecyclerView.setAdapter(mWrappedAdapter); // requires *wrapped* adapter mRecyclerView.setItemAnimator(animator); mRecyclerView.setHasFixedSize(false); // additional decorations //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 > ExpandableItem mRecyclerViewTouchActionGuardManager.attachRecyclerView(mRecyclerView); mRecyclerViewSwipeManager.attachRecyclerView(mRecyclerView); mRecyclerViewDragDropManager.attachRecyclerView(mRecyclerView); mRecyclerViewExpandableItemManager.attachRecyclerView(mRecyclerView); }
From source file:android.support.v7.internal.widget.TintManager.java
/** * A helper method to instantiate a {@link TintManager} and then call {@link #getDrawable(int)}. * This method should not be used routinely. *///ww w. ja v a 2s . c om public static Drawable getDrawable(Context context, int resId) { if (isInTintList(resId)) { final TintManager tm = (context instanceof TintContextWrapper) ? ((TintContextWrapper) context).getTintManager() : new TintManager(context); return tm.getDrawable(resId); } else { return ContextCompat.getDrawable(context, resId); } }
From source file:com.appyvet.materialrangebar.PinView.java
/** * The view is created empty with a default constructor. Use init to set all the initial * variables for the pin/*www .jav a 2s . co m*/ * * @param ctx Context * @param y The y coordinate to raw the pin (i.e. the bar location) * @param pinRadiusDP the initial size of the pin * @param pinColor the color of the pin * @param textColor the color of the value text in the pin * @param circleRadius the radius of the selector circle * @param circleColor the color of the selector circle * @param circleBoundaryColor The color of the selector circle boundary * @param circleBoundarySize The size of the selector circle boundary line * @param minFont the minimum font size for the pin text * @param maxFont the maximum font size for the pin text * @param pinsAreTemporary whether to show the pin initially or just the circle */ public void init(Context ctx, float y, float pinRadiusDP, int pinColor, int textColor, float circleRadius, int circleColor, int circleBoundaryColor, float circleBoundarySize, float minFont, float maxFont, boolean pinsAreTemporary) { mRes = ctx.getResources(); mPin = ContextCompat.getDrawable(ctx, R.drawable.rotate); mDensity = getResources().getDisplayMetrics().density; mMinPinFont = minFont / mDensity; mMaxPinFont = maxFont / mDensity; mPinsAreTemporary = pinsAreTemporary; mPinPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 15, mRes.getDisplayMetrics()); mCircleRadiusPx = circleRadius; mTextYPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 3.5f, mRes.getDisplayMetrics()); // If one of the attributes are set, but the others aren't, set the // attributes to default if (pinRadiusDP == -1) { mPinRadiusPx = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, DEFAULT_THUMB_RADIUS_DP, mRes.getDisplayMetrics()); } else { mPinRadiusPx = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, pinRadiusDP, mRes.getDisplayMetrics()); } //Set text size in px from dp int textSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 15, mRes.getDisplayMetrics()); // Creates the paint and sets the Paint values mTextPaint = new Paint(); mTextPaint.setColor(textColor); mTextPaint.setAntiAlias(true); mTextPaint.setTextSize(textSize); // Creates the paint and sets the Paint values mCirclePaint = new Paint(); mCirclePaint.setColor(circleColor); mCirclePaint.setAntiAlias(true); if (circleBoundarySize != 0) { mCircleBoundaryPaint = new Paint(); mCircleBoundaryPaint.setStyle(Paint.Style.STROKE); mCircleBoundaryPaint.setColor(circleBoundaryColor); mCircleBoundaryPaint.setStrokeWidth(circleBoundarySize); mCircleBoundaryPaint.setAntiAlias(true); } this.pinColor = pinColor; // Sets the minimum touchable area, but allows it to expand based on // image size int targetRadius = (int) Math.max(MINIMUM_TARGET_RADIUS_DP, mPinRadiusPx); mTargetRadiusPx = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, targetRadius, mRes.getDisplayMetrics()); mY = y; }
From source file:com.h6ah4i.android.example.advrecyclerview.demo_ed_with_section.ExpandableDraggableWithSectionExampleFragment.java
@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()); final Parcelable eimSavedState = (savedInstanceState != null) ? savedInstanceState.getParcelable(SAVED_STATE_EXPANDABLE_ITEM_MANAGER) : null;/*from w ww . j a va2 s .c o m*/ mRecyclerViewExpandableItemManager = new RecyclerViewExpandableItemManager(eimSavedState); mRecyclerViewExpandableItemManager.setOnGroupExpandListener(this); mRecyclerViewExpandableItemManager.setOnGroupCollapseListener(this); // 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); // drag & drop manager mRecyclerViewDragDropManager = new RecyclerViewDragDropManager(); mRecyclerViewDragDropManager.setDraggingItemShadowDrawable( (NinePatchDrawable) ContextCompat.getDrawable(getContext(), R.drawable.material_shadow_z3)); // swipe manager mRecyclerViewSwipeManager = new RecyclerViewSwipeManager(); //adapter final ExpandableDraggableWithSectionExampleAdapter myItemAdapter = new ExpandableDraggableWithSectionExampleAdapter( getDataProvider()); mAdapter = myItemAdapter; mWrappedAdapter = mRecyclerViewExpandableItemManager.createWrappedAdapter(myItemAdapter); // wrap for expanding mWrappedAdapter = mRecyclerViewDragDropManager.createWrappedAdapter(mWrappedAdapter); // wrap for dragging mWrappedAdapter = mRecyclerViewSwipeManager.createWrappedAdapter(mWrappedAdapter); // wrap for swiping mRecyclerViewDragDropManager.setCheckCanDropEnabled(ALLOW_ITEMS_MOVE_ACROSS_SECTIONS); myItemAdapter.setAllowItemsMoveAcrossSections(ALLOW_ITEMS_MOVE_ACROSS_SECTIONS); final GeneralItemAnimator animator = new SwipeDismissItemAnimator(); // Change animations are enabled by default since support-v7-recyclerview v22. // Need to disable them when using animation indicator. animator.setSupportsChangeAnimations(false); mRecyclerView.setLayoutManager(mLayoutManager); mRecyclerView.setAdapter(mWrappedAdapter); // requires *wrapped* adapter mRecyclerView.setItemAnimator(animator); mRecyclerView.setHasFixedSize(false); // additional decorations //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 > ExpandableItem mRecyclerViewTouchActionGuardManager.attachRecyclerView(mRecyclerView); mRecyclerViewSwipeManager.attachRecyclerView(mRecyclerView); mRecyclerViewDragDropManager.attachRecyclerView(mRecyclerView); mRecyclerViewExpandableItemManager.attachRecyclerView(mRecyclerView); }
From source file:com.h6ah4i.android.example.advrecyclerview.demo_e_already_expanded.AlreadyExpandedGroupsExpandableExampleFragment.java
@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()); final Parcelable eimSavedState = (savedInstanceState != null) ? savedInstanceState.getParcelable(SAVED_STATE_EXPANDABLE_ITEM_MANAGER) : null;/* w w w . j av a2 s.c o m*/ mRecyclerViewExpandableItemManager = new RecyclerViewExpandableItemManager(eimSavedState); // Expand all group items by default. This method must be called before creating a wrapper adapter. mRecyclerViewExpandableItemManager.setDefaultGroupsExpandedState(true); //adapter final AlreadyExpandedGroupsExpandableExampleAdapter myItemAdapter = new AlreadyExpandedGroupsExpandableExampleAdapter( mRecyclerViewExpandableItemManager, getDataProvider()); mAdapter = myItemAdapter; mWrappedAdapter = mRecyclerViewExpandableItemManager.createWrappedAdapter(myItemAdapter); // wrap for expanding final GeneralItemAnimator animator = new RefactoredDefaultItemAnimator(); // Change animations are enabled by default since support-v7-recyclerview v22. // Need to disable them when using animation indicator. animator.setSupportsChangeAnimations(false); mRecyclerView.setLayoutManager(mLayoutManager); mRecyclerView.setAdapter(mWrappedAdapter); // requires *wrapped* adapter mRecyclerView.setItemAnimator(animator); mRecyclerView.setHasFixedSize(false); // additional decorations //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)); mRecyclerViewExpandableItemManager.attachRecyclerView(mRecyclerView); }
From source file:com.dm.material.dashboard.candybar.helpers.DrawableHelper.java
public static Drawable getAppIcon(@NonNull Context context, ResolveInfo info) { try {//w w w.j ava2 s. c om return info.activityInfo.loadIcon(context.getPackageManager()); } catch (OutOfMemoryError | Exception e) { return ContextCompat.getDrawable(context, R.drawable.ic_app_default); } }
From source file:com.h6ah4i.android.example.advrecyclerview.demo_e_add_remove.RecyclerListViewFragment.java
@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()); final Parcelable eimSavedState = (savedInstanceState != null) ? savedInstanceState.getParcelable(SAVED_STATE_EXPANDABLE_ITEM_MANAGER) : null;// ww w. j ava 2s . co m mRecyclerViewExpandableItemManager = new RecyclerViewExpandableItemManager(eimSavedState); mRecyclerViewExpandableItemManager.setOnGroupExpandListener(this); mRecyclerViewExpandableItemManager.setOnGroupCollapseListener(this); //adapter final MyAddRemoveExpandableItemAdapter myItemAdapter = new MyAddRemoveExpandableItemAdapter( mRecyclerViewExpandableItemManager, getDataProvider()); mAdapter = myItemAdapter; mWrappedAdapter = mRecyclerViewExpandableItemManager.createWrappedAdapter(myItemAdapter); // wrap for expanding final GeneralItemAnimator animator = new RefactoredDefaultItemAnimator(); // Change animations are enabled by default since support-v7-recyclerview v22. // Need to disable them when using animation indicator. animator.setSupportsChangeAnimations(false); mRecyclerView.setLayoutManager(mLayoutManager); mRecyclerView.setAdapter(mWrappedAdapter); // requires *wrapped* adapter mRecyclerView.setItemAnimator(animator); mRecyclerView.setHasFixedSize(false); // additional decorations //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)); mRecyclerViewExpandableItemManager.attachRecyclerView(mRecyclerView); }
From source file:com.h6ah4i.android.example.advrecyclerview.demo_e_already_expanded.RecyclerListViewFragment.java
@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()); final Parcelable eimSavedState = (savedInstanceState != null) ? savedInstanceState.getParcelable(SAVED_STATE_EXPANDABLE_ITEM_MANAGER) : null;/* w w w . j a v a2s. c o m*/ mRecyclerViewExpandableItemManager = new RecyclerViewExpandableItemManager(eimSavedState); //adapter final MyExpandableItemAdapter myItemAdapter = new MyExpandableItemAdapter( mRecyclerViewExpandableItemManager, getDataProvider()); mAdapter = myItemAdapter; mWrappedAdapter = mRecyclerViewExpandableItemManager.createWrappedAdapter(myItemAdapter); // wrap for expanding // Expand all group items if no saved state exists. // The expandAll() method should be called here (before attaching the RecyclerView instance), // because it can reduce overheads of updating item views. if (eimSavedState == null) { mRecyclerViewExpandableItemManager.expandAll(); } final GeneralItemAnimator animator = new RefactoredDefaultItemAnimator(); // Change animations are enabled by default since support-v7-recyclerview v22. // Need to disable them when using animation indicator. animator.setSupportsChangeAnimations(false); mRecyclerView.setLayoutManager(mLayoutManager); mRecyclerView.setAdapter(mWrappedAdapter); // requires *wrapped* adapter mRecyclerView.setItemAnimator(animator); mRecyclerView.setHasFixedSize(false); // additional decorations //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)); mRecyclerViewExpandableItemManager.attachRecyclerView(mRecyclerView); }