List of usage examples for android.support.v4.content ContextCompat getDrawable
public static final Drawable getDrawable(Context context, int i)
From source file:cat.terrones.devops.radiofx.ui.FullScreenPlayerActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_full_player); initToolBar();/*w ww . ja v a 2 s . c om*/ if (getSupportActionBar() != null) { getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setTitle(""); } mBackgroundImage = (ImageView) findViewById(R.id.background_image); mPauseDrawable = ContextCompat.getDrawable(this, R.drawable.uamp_ic_pause_white_48dp); mPlayDrawable = ContextCompat.getDrawable(this, R.drawable.uamp_ic_play_arrow_white_48dp); mPlayPause = (ImageView) findViewById(R.id.play_pause); mSkipNext = (ImageView) findViewById(R.id.next); mSkipPrev = (ImageView) findViewById(R.id.prev); mStart = (TextView) findViewById(R.id.startText); mEnd = (TextView) findViewById(R.id.endText); mSeekbar = (SeekBar) findViewById(R.id.seekBar1); mLine1 = (TextView) findViewById(R.id.line1); mLine2 = (TextView) findViewById(R.id.line2); mLine3 = (TextView) findViewById(R.id.line3); mLoading = (ProgressBar) findViewById(R.id.progressBar1); mControllers = findViewById(R.id.controllers); mSkipNext.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { MediaControllerCompat.TransportControls controls = getSupportMediaController() .getTransportControls(); controls.skipToNext(); } }); mSkipPrev.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { MediaControllerCompat.TransportControls controls = getSupportMediaController() .getTransportControls(); controls.skipToPrevious(); } }); mPlayPause.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { PlaybackStateCompat state = getSupportMediaController().getPlaybackState(); if (state != null) { MediaControllerCompat.TransportControls controls = getSupportMediaController() .getTransportControls(); switch (state.getState()) { case PlaybackStateCompat.STATE_PLAYING: // fall through case PlaybackStateCompat.STATE_BUFFERING: controls.pause(); stopSeekbarUpdate(); break; case PlaybackStateCompat.STATE_PAUSED: case PlaybackStateCompat.STATE_STOPPED: controls.play(); scheduleSeekbarUpdate(); break; default: LogHelper.d(TAG, "onClick with state ", state.getState()); } } } }); mSeekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { mStart.setText(DateUtils.formatElapsedTime(progress / 1000)); } @Override public void onStartTrackingTouch(SeekBar seekBar) { stopSeekbarUpdate(); } @Override public void onStopTrackingTouch(SeekBar seekBar) { getSupportMediaController().getTransportControls().seekTo(seekBar.getProgress()); scheduleSeekbarUpdate(); } }); // Only update from the intent if we are not recreating from a config change: if (savedInstanceState == null) { updateFromParams(getIntent()); } mMediaBrowser = new MediaBrowserCompat(this, new ComponentName(this, MusicService.class), mConnectionCallback, null); }
From source file:com.h6ah4i.android.example.advrecyclerview.demo_s.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(), 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//from ww w.j a v a2 s.c om final MySwipeableItemAdapter myItemAdapter = new MySwipeableItemAdapter(getDataProvider()); myItemAdapter.setEventListener(new MySwipeableItemAdapter.EventListener() { @Override public void onItemRemoved(int position) { ((SwipeableExampleActivity) getActivity()).onItemRemoved(position); } @Override public void onItemPinned(int position) { ((SwipeableExampleActivity) getActivity()).onItemPinned(position); } @Override public void onItemViewClicked(View v, boolean pinned) { onItemViewClick(v, pinned); } }); mAdapter = myItemAdapter; mWrappedAdapter = mRecyclerViewSwipeManager.createWrappedAdapter(myItemAdapter); // 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. animator.setSupportsChangeAnimations(false); mRecyclerView.setLayoutManager(mLayoutManager); mRecyclerView.setAdapter(mWrappedAdapter); // requires *wrapped* adapter mRecyclerView.setItemAnimator(animator); // 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 mRecyclerViewTouchActionGuardManager.attachRecyclerView(mRecyclerView); mRecyclerViewSwipeManager.attachRecyclerView(mRecyclerView); // for debugging // animator.setDebug(true); // animator.setMoveDuration(2000); // animator.setRemoveDuration(2000); // mRecyclerViewSwipeManager.setMoveToOutsideWindowAnimationDuration(2000); // mRecyclerViewSwipeManager.setReturnToDefaultPositionAnimationDuration(2000); }
From source file:com.h6ah4i.android.example.advrecyclerview.demo_s_basic.SwipeableExampleFragment.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(), 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/*from w w w . j a v a 2s .c o m*/ final SwipeableExampleAdapter myItemAdapter = new SwipeableExampleAdapter(getDataProvider()); myItemAdapter.setEventListener(new SwipeableExampleAdapter.EventListener() { @Override public void onItemRemoved(int position) { ((SwipeableExampleActivity) getActivity()).onItemRemoved(position); } @Override public void onItemPinned(int position) { ((SwipeableExampleActivity) getActivity()).onItemPinned(position); } @Override public void onItemViewClicked(View v, boolean pinned) { onItemViewClick(v, pinned); } }); mAdapter = myItemAdapter; mWrappedAdapter = mRecyclerViewSwipeManager.createWrappedAdapter(myItemAdapter); // 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. animator.setSupportsChangeAnimations(false); mRecyclerView.setLayoutManager(mLayoutManager); mRecyclerView.setAdapter(mWrappedAdapter); // requires *wrapped* adapter mRecyclerView.setItemAnimator(animator); // 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 mRecyclerViewTouchActionGuardManager.attachRecyclerView(mRecyclerView); mRecyclerViewSwipeManager.attachRecyclerView(mRecyclerView); // for debugging // animator.setDebug(true); // animator.setMoveDuration(2000); // animator.setRemoveDuration(2000); // mRecyclerViewSwipeManager.setMoveToOutsideWindowAnimationDuration(2000); // mRecyclerViewSwipeManager.setReturnToDefaultPositionAnimationDuration(2000); }
From source file:com.h6ah4i.android.example.advrecyclerview.demo_s_longpress.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(), 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/* ww w .j a v a2 s . c o m*/ final MySwipeableItemAdapter myItemAdapter = new MySwipeableItemAdapter(getDataProvider()); myItemAdapter.setEventListener(new MySwipeableItemAdapter.EventListener() { @Override public void onItemRemoved(int position) { ((SwipeOnLongPressExampleActivity) getActivity()).onItemRemoved(position); } @Override public void onItemPinned(int position) { ((SwipeOnLongPressExampleActivity) getActivity()).onItemPinned(position); } @Override public void onItemViewClicked(View v, boolean pinned) { onItemViewClick(v, pinned); } }); mAdapter = myItemAdapter; mWrappedAdapter = mRecyclerViewSwipeManager.createWrappedAdapter(myItemAdapter); // 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. animator.setSupportsChangeAnimations(false); mRecyclerView.setLayoutManager(mLayoutManager); mRecyclerView.setAdapter(mWrappedAdapter); // requires *wrapped* adapter mRecyclerView.setItemAnimator(animator); // 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 mRecyclerViewTouchActionGuardManager.attachRecyclerView(mRecyclerView); mRecyclerViewSwipeManager.attachRecyclerView(mRecyclerView); // for debugging // animator.setDebug(true); // animator.setMoveDuration(2000); // animator.setRemoveDuration(2000); // mRecyclerViewSwipeManager.setMoveToOutsideWindowAnimationDuration(2000); // mRecyclerViewSwipeManager.setReturnToDefaultPositionAnimationDuration(2000); }
From source file:com.h6ah4i.android.example.advrecyclerview.demo_s_vertical.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(), LinearLayoutManager.HORIZONTAL, 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/*from w w w . j av a2 s. co m*/ final MySwipeableItemAdapter myItemAdapter = new MySwipeableItemAdapter(getDataProvider()); myItemAdapter.setEventListener(new MySwipeableItemAdapter.EventListener() { @Override public void onItemRemoved(int position) { ((VerticalSwipeableExampleActivity) getActivity()).onItemRemoved(position); } @Override public void onItemPinned(int position) { ((VerticalSwipeableExampleActivity) getActivity()).onItemPinned(position); } @Override public void onItemViewClicked(View v, boolean pinned) { onItemViewClick(v, pinned); } }); mAdapter = myItemAdapter; mWrappedAdapter = mRecyclerViewSwipeManager.createWrappedAdapter(myItemAdapter); // 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. animator.setSupportsChangeAnimations(false); mRecyclerView.setLayoutManager(mLayoutManager); mRecyclerView.setAdapter(mWrappedAdapter); // requires *wrapped* adapter mRecyclerView.setItemAnimator(animator); // 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(null, ContextCompat.getDrawable(getContext(), R.drawable.list_divider_v), 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); }
From source file:com.h6ah4i.android.example.advrecyclerview.demo_s_button.SwipeableWithButtonExampleFragment.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()); // 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//w ww . ja v a2 s .co m 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; mWrappedAdapter = mRecyclerViewSwipeManager.createWrappedAdapter(myItemAdapter); // 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. animator.setSupportsChangeAnimations(false); mRecyclerView.setLayoutManager(mLayoutManager); mRecyclerView.setAdapter(mWrappedAdapter); // requires *wrapped* adapter mRecyclerView.setItemAnimator(animator); // 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 mRecyclerViewTouchActionGuardManager.attachRecyclerView(mRecyclerView); mRecyclerViewSwipeManager.attachRecyclerView(mRecyclerView); // for debugging // animator.setDebug(true); // animator.setMoveDuration(2000); // mRecyclerViewSwipeManager.setMoveToOutsideWindowAnimationDuration(2000); // mRecyclerViewSwipeManager.setReturnToDefaultPositionAnimationDuration(2000); }
From source file:com.h6ah4i.android.example.advrecyclerview.demo_s_legacy.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(), 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/*from www . j a v a2 s .c o m*/ final MyLegacySwipeableItemAdapter myItemAdapter = new MyLegacySwipeableItemAdapter(getDataProvider()); myItemAdapter.setEventListener(new MyLegacySwipeableItemAdapter.EventListener() { @Override public void onItemRemoved(int position) { ((LegacySwipeableExampleActivity) getActivity()).onItemRemoved(position); } @Override public void onItemPinned(int position) { ((LegacySwipeableExampleActivity) getActivity()).onItemPinned(position); } @Override public void onItemViewClicked(View v, boolean pinned) { onItemViewClick(v, pinned); } }); mAdapter = myItemAdapter; mWrappedAdapter = mRecyclerViewSwipeManager.createWrappedAdapter(myItemAdapter); // 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. animator.setSupportsChangeAnimations(false); mRecyclerView.setLayoutManager(mLayoutManager); mRecyclerView.setAdapter(mWrappedAdapter); // requires *wrapped* adapter mRecyclerView.setItemAnimator(animator); // 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 mRecyclerViewTouchActionGuardManager.attachRecyclerView(mRecyclerView); mRecyclerViewSwipeManager.attachRecyclerView(mRecyclerView); // for debugging // animator.setDebug(true); // animator.setMoveDuration(2000); // animator.setRemoveDuration(2000); // mRecyclerViewSwipeManager.setMoveToOutsideWindowAnimationDuration(2000); // mRecyclerViewSwipeManager.setReturnToDefaultPositionAnimationDuration(2000); }
From source file:com.h6ah4i.android.example.advrecyclerview.demo_s_legacy.LegacySwipeableExampleFragment.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(), 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/*from w w w .j a va2s . c om*/ final LegacySwipeableExampleAdapter myItemAdapter = new LegacySwipeableExampleAdapter(getDataProvider()); myItemAdapter.setEventListener(new LegacySwipeableExampleAdapter.EventListener() { @Override public void onItemRemoved(int position) { ((LegacySwipeableExampleActivity) getActivity()).onItemRemoved(position); } @Override public void onItemPinned(int position) { ((LegacySwipeableExampleActivity) getActivity()).onItemPinned(position); } @Override public void onItemViewClicked(View v, boolean pinned) { onItemViewClick(v, pinned); } }); mAdapter = myItemAdapter; mWrappedAdapter = mRecyclerViewSwipeManager.createWrappedAdapter(myItemAdapter); // 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. animator.setSupportsChangeAnimations(false); mRecyclerView.setLayoutManager(mLayoutManager); mRecyclerView.setAdapter(mWrappedAdapter); // requires *wrapped* adapter mRecyclerView.setItemAnimator(animator); // 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 mRecyclerViewTouchActionGuardManager.attachRecyclerView(mRecyclerView); mRecyclerViewSwipeManager.attachRecyclerView(mRecyclerView); // for debugging // animator.setDebug(true); // animator.setMoveDuration(2000); // animator.setRemoveDuration(2000); // mRecyclerViewSwipeManager.setMoveToOutsideWindowAnimationDuration(2000); // mRecyclerViewSwipeManager.setReturnToDefaultPositionAnimationDuration(2000); }
From source file:com.h6ah4i.android.example.advrecyclerview.demo_s_longpress.SwipeOnLongPressExampleFragment.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(), 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/* w w w.j a v a 2 s. c o m*/ final SwipeOnLongPressExampleAdapter myItemAdapter = new SwipeOnLongPressExampleAdapter(getDataProvider()); myItemAdapter.setEventListener(new SwipeOnLongPressExampleAdapter.EventListener() { @Override public void onItemRemoved(int position) { ((SwipeOnLongPressExampleActivity) getActivity()).onItemRemoved(position); } @Override public void onItemPinned(int position) { ((SwipeOnLongPressExampleActivity) getActivity()).onItemPinned(position); } @Override public void onItemViewClicked(View v, boolean pinned) { onItemViewClick(v, pinned); } }); mAdapter = myItemAdapter; mWrappedAdapter = mRecyclerViewSwipeManager.createWrappedAdapter(myItemAdapter); // 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. animator.setSupportsChangeAnimations(false); mRecyclerView.setLayoutManager(mLayoutManager); mRecyclerView.setAdapter(mWrappedAdapter); // requires *wrapped* adapter mRecyclerView.setItemAnimator(animator); // 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 mRecyclerViewTouchActionGuardManager.attachRecyclerView(mRecyclerView); mRecyclerViewSwipeManager.attachRecyclerView(mRecyclerView); // for debugging // animator.setDebug(true); // animator.setMoveDuration(2000); // animator.setRemoveDuration(2000); // mRecyclerViewSwipeManager.setMoveToOutsideWindowAnimationDuration(2000); // mRecyclerViewSwipeManager.setReturnToDefaultPositionAnimationDuration(2000); }
From source file:alexander.martinz.libs.materialpreferences.MaterialPreference.java
public boolean init(Context context, AttributeSet attrs) { if (mInit) {//from w ww . j a va 2 s . co m return false; } mInit = true; if (attrs != null) { TypedArray typedArray = parseAttrs(context, attrs); recycleTypedArray(typedArray); } final int layoutResId = mPrefAsCard ? R.layout.material_prefs_card_preference : R.layout.material_prefs_preference; mView = getLayoutInflater().inflate(layoutResId, this, true); if (mPrefAsCard) { mCardView = (CardView) mView.findViewById(R.id.card_preference_root); } mIcon = (ImageView) mView.findViewById(android.R.id.icon); mTitle = (TextView) mView.findViewById(android.R.id.title); mSummary = (TextView) mView.findViewById(android.R.id.summary); mWidgetFrame = (LinearLayout) mView.findViewById(android.R.id.widget_frame); mWidgetFrameBottom = (LinearLayout) mView.findViewById(R.id.widget_frame_bottom); if (mResIdIcon != -1 && mIcon != null) { Drawable d = ContextCompat.getDrawable(context, mResIdIcon); if (d != null && mIconTintColor != Integer.MIN_VALUE) { d = d.mutate(); d.setColorFilter(new LightingColorFilter(Color.BLACK, mIconTintColor)); } mIcon.setImageDrawable(d); mIcon.setVisibility(View.VISIBLE); } if (mResIdTitle != -1) { mTitle.setText(mResIdTitle); } if (mResIdSummary != -1 && mSummary != null) { mSummary.setText(mResIdSummary); mSummary.setVisibility(View.VISIBLE); } if (mPrefAsCard && mCardBackgroundColor != Integer.MIN_VALUE) { setBackgroundColor(mCardBackgroundColor); } setSelectable(true); setOnClickListener(this); setOnTouchListener(this); setOrientation(LinearLayout.VERTICAL); return true; }