Example usage for android.support.v4.content ContextCompat getDrawable

List of usage examples for android.support.v4.content ContextCompat getDrawable

Introduction

In this page you can find the example usage for android.support.v4.content ContextCompat getDrawable.

Prototype

public static final Drawable getDrawable(Context context, int i) 

Source Link

Usage

From source file:com.bilibili.magicasakura.widgets.AppCompatCompoundDrawableHelper.java

private Drawable getCompoundDrawableByPosition(int i) {
    PorterDuff.Mode tintMode = mCompoundDrawableTintModes[i];
    int tintResId = mCompoundDrawableTintResIds[i];
    int resId = mCompoundDrawableResIds[i];
    if (tintResId != 0) {
        setSupportCompoundDrawableTintModeByPosition(i, tintMode);
        return setSupportCompoundDrawableByPosition(i, tintResId);
    } else {//from  ww  w  .j  a va 2 s  .c  o  m
        Drawable drawable = mTintManager.getDrawable(resId);
        if (drawable == null) {
            return resId == 0 ? null : ContextCompat.getDrawable(mView.getContext(), resId);
        }
        return drawable;
    }
}

From source file:com.belatrixsf.allstars.ui.contacts.ContactFragment.java

private void initViews() {
    employeeListAdapter = new EmployeeListAdapter(this);
    employeeRecyclerView.setAdapter(employeeListAdapter);
    employeeRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
    employeeRecyclerView.addItemDecoration(new DividerItemDecoration(
            ContextCompat.getDrawable(getActivity(), android.R.drawable.divider_horizontal_bright)));
}

From source file:com.github.colorchief.colorchief.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);

    final TabHost tabHost = (TabHost) findViewById(R.id.tabHost);
    tabHost.setup();//from   w  w w .  java  2 s . c  om

    final TabHost.TabSpec tabImageView = tabHost.newTabSpec("Image View");
    final TabHost.TabSpec tabSettings = tabHost.newTabSpec("Settings");
    final TabHost.TabSpec tabAbout = tabHost.newTabSpec("About");

    tabImageView.setIndicator("", ContextCompat.getDrawable(this, R.drawable.ic_action_picture));
    tabImageView.setContent(R.id.tabImageView);

    tabSettings.setIndicator("", ContextCompat.getDrawable(this, R.drawable.ic_action_gear));
    tabSettings.setContent(R.id.tabSettings);

    tabAbout.setIndicator("", ContextCompat.getDrawable(this, R.drawable.ic_action_help));
    tabAbout.setContent(R.id.tabAbout);

    /** Add the tabs  to the TabHost to display. */
    tabHost.addTab(tabImageView);
    tabHost.addTab(tabSettings);
    tabHost.addTab(tabAbout);

    colorLUT.initLUT(LUT_SIZE, LUT_SIZE, LUT_SIZE);

    //check savedInstance
    // for Tab state and set active tab accordingly
    // for LUT values and update (restore) accordingly
    if (savedInstanceState != null) {
        tabHost.setCurrentTab(savedInstanceState.getInt("Active Tab"));
        colorLUT.setColorLutArray(savedInstanceState.getIntArray("Color LUT"));
    }

    ((SeekBar) findViewById(R.id.seekBarChromaPowerFactor)).setMax(POWER_FACTOR_SEEK_BAR_MAX);
    ((SeekBar) findViewById(R.id.seekBarChromaPowerFactor)).setProgress(getSeekPosition(powerFactor));

    if (Lselect == LutCalculate.L_SELECT_IN) {
        ((RadioButton) findViewById(R.id.radioButtonLin)).setChecked(true);
        ((RadioButton) findViewById(R.id.radioButtonLout)).setChecked(false);
    } else if (Lselect == LutCalculate.L_SELECT_OUT) {
        ((RadioButton) findViewById(R.id.radioButtonLin)).setChecked(false);
        ((RadioButton) findViewById(R.id.radioButtonLout)).setChecked(true);
    }
    if (Cselect == LutCalculate.C_SELECT_ABSOLUTE) {
        ((RadioButton) findViewById(R.id.radioButtonCin)).setChecked(true);
        ((RadioButton) findViewById(R.id.radioButtonCrelative)).setChecked(false);
        ((SeekBar) findViewById(R.id.seekBarChromaPowerFactor)).setEnabled(false);

    } else if (Cselect == LutCalculate.C_SELECT_RELATIVE) {
        ((RadioButton) findViewById(R.id.radioButtonCin)).setChecked(false);
        ((RadioButton) findViewById(R.id.radioButtonCrelative)).setChecked(true);
        ((SeekBar) findViewById(R.id.seekBarChromaPowerFactor)).setEnabled(true);
    }

    if (uriIccProfileIn != null)
        iccProfileIn.loadFromFile(uriIccProfileIn);
    if (uriIccProfileOut != null)
        iccProfileOut.loadFromFile(uriIccProfileOut);

    if (bitmapLoaded) {

        transformImage();
        updateImageViewer();

    } else {
        ((ImageView) findViewById(R.id.imageView)).setImageBitmap(
                BitmapFactory.decodeResource(getResources(), R.drawable.ic_action_folder_open_blue));

    }

    ((ImageView) findViewById(R.id.imageView)).addOnLayoutChangeListener(new View.OnLayoutChangeListener() {

        @Override
        public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop,
                int oldRight, int oldBottom) {
            // if layout is not complete we will get all zero values for the positions, so ignore the event
            if (left == 0 && top == 0 && right == 0 && bottom == 0) {
                return;
            } else {
                if (bitmapLoaded) {
                    try {
                        decodeImageUri(uriBitmapOriginal, (ImageView) findViewById(R.id.imageView));
                    } catch (FileNotFoundException e) {
                        Log.e(TAG, "Failed to grab Bitmap: " + e);
                    }
                    //if (iccProfileOut.isValidProfile() && iccProfileIn.isValidProfile())
                    transformImage();
                    updateImageViewer();

                }
            }

        }
    });

    ((SeekBar) findViewById(R.id.seekBarChromaPowerFactor))
            .setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
                @Override
                public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {

                }

                @Override
                public void onStartTrackingTouch(SeekBar seekBar) {

                }

                @Override
                public void onStopTrackingTouch(SeekBar seekBar) {
                    powerFactor = getPowerFactor(seekBar.getProgress());
                    //convertImage(seekBar);
                    //updateImageViewer();
                }
            });

    //when switching tabs, make sure:
    //a: update the image when switching to the imageview tab in case any settings changes were made
    //b: hide the color controls overlay if we are not on the imageview tab
    tabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener() {
        @Override
        public void onTabChanged(String tabId) {
            if (tabId.equals(tabImageView.getTag())) {
                //Log.d(TAG,"Tab changed to image view");

                if (iccProfileIn.isValidProfile() && iccProfileOut.isValidProfile() && bitmapLoaded) {
                    recalculateTransform();
                    transformImage();
                    updateImageViewer();
                }
            } else if (tabId.equals(tabAbout.getTag())) {
                ((LinearLayout) findViewById(R.id.overlayColorControl)).setVisibility(View.INVISIBLE);
                InputStream inputStream = getResources().openRawResource(R.raw.about);
                ByteArrayOutputStream byteArrayStream = new ByteArrayOutputStream();
                try {
                    int bytesRead = inputStream.read();
                    while (bytesRead != -1) {
                        byteArrayStream.write(bytesRead);
                        bytesRead = inputStream.read();
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                }

                //TextView textViewAbout = (TextView) findViewById(R.id.textViewAbout);
                //textViewAbout.setText(Html.fromHtml(byteArrayStream.toString()));
                WebView webViewAbout = (WebView) findViewById(R.id.webViewAbout);
                webViewAbout.loadDataWithBaseURL(null, byteArrayStream.toString(), "text/html", "utf-8", null);
            } else {
                ((LinearLayout) findViewById(R.id.overlayColorControl)).setVisibility(View.INVISIBLE);
            }
        }
    });

}

From source file:com.h6ah4i.android.example.advrecyclerview.demo_s_viewpager.RecyclerListViewPageFragment.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  va 2s  .c o m
    final MyViewPagerSwipeableItemAdapter myItemAdapter = new MyViewPagerSwipeableItemAdapter(getDataProvider(),
            mCanSwipeLeft);

    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_viewpager.ViewPagerSwipeableExampleFragment.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  om
    final ViewPagerSwipeableExampleAdapter myItemAdapter = new ViewPagerSwipeableExampleAdapter(
            getDataProvider(), mCanSwipeLeft);

    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.joaquimley.faboptions.FabOptions.java

private void setBackgroundColor(Context context, @ColorInt int backgroundColor) {
    Drawable backgroundShape = ContextCompat.getDrawable(context, R.drawable.faboptions_background);
    backgroundShape.setColorFilter(backgroundColor, PorterDuff.Mode.ADD);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        mBackground.setBackground(backgroundShape);
    } else {//from w w  w  . j a va2s  .  c  o m
        mBackground.setBackgroundDrawable(backgroundShape);
    }
}

From source file:com.adkdevelopment.earthquakesurvival.utils.Utilities.java

/**
 * Creates Bitmap for a Map marker depending on the magnitude of an earthquake
 * @param context from which call is being made
 * @param magnitude from 0 to 10 scale earthquake intensity
 * @return colorful oval of size depending on magnitude
 *//*from   w w  w. jav a 2  s.com*/
public static Bitmap getEarthquakeMarker(Context context, Double magnitude) {

    if (magnitude < 1) {
        magnitude = 1.0;
    }

    GradientDrawable oval;
    oval = (GradientDrawable) ContextCompat.getDrawable(context, R.drawable.marker);

    if (oval != null) {

        int STROKE_SIZE = 5;
        float DASH_WIDTH = 9f;
        float DASH_GAP = 3f;

        if (magnitude >= 3 && magnitude <= 5) {
            oval.setColors(new int[] { Color.TRANSPARENT, Color.BLUE });
            oval.setStroke(STROKE_SIZE, Color.BLUE, DASH_WIDTH, DASH_GAP);
        } else if (magnitude > 5 && magnitude < 7) {
            oval.setColors(new int[] { Color.TRANSPARENT, Color.YELLOW });
            oval.setStroke(STROKE_SIZE, Color.YELLOW, DASH_WIDTH, DASH_GAP);
        } else if (magnitude >= 7) {
            oval.setColors(new int[] { Color.TRANSPARENT, Color.RED });
            oval.setStroke(STROKE_SIZE, Color.RED, DASH_WIDTH, DASH_GAP);
        } else {
            oval.setColors(new int[] { Color.TRANSPARENT, Color.GREEN });
            oval.setStroke(STROKE_SIZE, Color.GREEN, DASH_WIDTH, DASH_GAP);
        }

        int diameter = (int) (oval.getIntrinsicWidth() * magnitude / 4);

        Canvas canvas = new Canvas();
        Bitmap icon = Bitmap.createBitmap(diameter, diameter, Bitmap.Config.ARGB_8888);

        canvas.setBitmap(icon);
        oval.setBounds(0, 0, diameter, diameter);
        oval.draw(canvas);

        return icon;
    } else {
        return null;
    }
}

From source file:com.jaredrummler.materialspinner.MaterialSpinner.java

private void init(Context context, AttributeSet attrs) {
    TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.MaterialSpinner);
    int defaultColor = getTextColors().getDefaultColor();
    backgroundColor = typedArray.getColor(R.styleable.MaterialSpinner_ms_background_color, Color.WHITE);
    textColor = typedArray.getColor(R.styleable.MaterialSpinner_ms_text_color, defaultColor);
    arrowColor = typedArray.getColor(R.styleable.MaterialSpinner_ms_arrow_tint, textColor);
    hideArrow = typedArray.getBoolean(R.styleable.MaterialSpinner_ms_hide_arrow, false);
    typedArray.recycle();//from  w  w  w . j av  a 2  s .  c o  m

    setGravity(Gravity.CENTER_VERTICAL | Gravity.START);

    boolean rtl = false;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        Configuration config = getResources().getConfiguration();
        rtl = config.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL;
        if (rtl) {
            setLayoutDirection(View.LAYOUT_DIRECTION_RTL);
            setTextDirection(View.TEXT_DIRECTION_RTL);
        }
    }

    Resources resources = getResources();
    int left, right, bottom, top;
    left = right = bottom = top = resources.getDimensionPixelSize(R.dimen.ms__padding_top);
    if (rtl) {
        right = resources.getDimensionPixelSize(R.dimen.ms__padding_left);
    } else {
        left = resources.getDimensionPixelSize(R.dimen.ms__padding_left);
    }

    setClickable(true);
    setPadding(left, top, right, bottom);
    setBackgroundResource(R.drawable.ms__selector);

    if (!hideArrow) {
        arrowDrawable = DrawableCompat.wrap(ContextCompat.getDrawable(context, R.drawable.ms__arrow));
        DrawableCompat.setTint(arrowDrawable, arrowColor);
        if (rtl) {
            setCompoundDrawablesWithIntrinsicBounds(arrowDrawable, null, null, null);
        } else {
            setCompoundDrawablesWithIntrinsicBounds(null, null, arrowDrawable, null);
        }
    }

    listView = new ListView(context);
    listView.setId(getId());
    listView.setDivider(null);
    listView.setItemsCanFocus(true);
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            if (position >= selectedIndex && position < adapter.getCount()) {
                position++;
            }
            selectedIndex = position;
            nothingSelected = false;
            Object item = adapter.get(position);
            adapter.notifyItemSelected(position);
            setText(item.toString());
            collapse();
            if (onItemSelectedListener != null) {
                //noinspection unchecked
                onItemSelectedListener.onItemSelected(MaterialSpinner.this, position, id, item);
            }
        }
    });

    popupWindow = new PopupWindow(context);
    popupWindow.setContentView(listView);
    popupWindow.setOutsideTouchable(true);
    popupWindow.setFocusable(true);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        popupWindow.setElevation(16);
        popupWindow.setBackgroundDrawable(ContextCompat.getDrawable(context, R.drawable.ms__drawable));
    } else {
        popupWindow.setBackgroundDrawable(ContextCompat.getDrawable(context, R.drawable.ms__drop_down_shadow));
    }

    if (backgroundColor != Color.WHITE) { // default color is white
        setBackgroundColor(backgroundColor);
    }
    if (textColor != defaultColor) {
        setTextColor(textColor);
    }

    popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {

        @Override
        public void onDismiss() {
            if (nothingSelected && onNothingSelectedListener != null) {
                onNothingSelectedListener.onNothingSelected(MaterialSpinner.this);
            }
            if (!hideArrow) {
                animateArrow(false);
            }
        }
    });
}

From source file:com.h6ah4i.android.example.advrecyclerview.demo_eds_vp_sec_long.RecyclerListViewPageFragment.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);

    final Parcelable eimSavedState = (savedInstanceState != null)
            ? savedInstanceState.getParcelable(SAVED_STATE_EXPANDABLE_ITEM_MANAGER)
            : null;/*  w  ww .  j  a v  a2s  .c om*/
    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 MyExpandableDraggableSwipeableSectionAdapter myItemAdapter = new MyExpandableDraggableSwipeableSectionAdapter(
            mRecyclerViewExpandableItemManager, getDataProvider());

    myItemAdapter.setEventListener(new MyExpandableDraggableSwipeableSectionAdapter.EventListener() {
        @Override
        public void onGroupItemRemoved(int groupPosition) {
            Snackbar snackbar = Snackbar.make(getActivity().findViewById(R.id.container),
                    R.string.snack_bar_text_group_item_removed, Snackbar.LENGTH_LONG);

            snackbar.setAction(R.string.snack_bar_action_undo, new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    onItemUndoActionClicked();
                }
            });
            snackbar.setActionTextColor(
                    ContextCompat.getColor(getActivity(), R.color.snackbar_action_color_done));
            snackbar.show();
        }

        @Override
        public void onChildItemRemoved(int groupPosition, int childPosition) {
            Snackbar snackbar = Snackbar.make(getActivity().findViewById(R.id.container),
                    R.string.snack_bar_text_child_item_removed, Snackbar.LENGTH_LONG);

            snackbar.setAction(R.string.snack_bar_action_undo, new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    onItemUndoActionClicked();
                }
            });
            snackbar.setActionTextColor(
                    ContextCompat.getColor(getActivity(), R.color.snackbar_action_color_done));
            snackbar.show();
        }

        @Override
        public void onGroupItemPinned(int groupPosition) {
        }

        @Override
        public void onChildItemPinned(int groupPosition, int childPosition) {
        }

        @Override
        public void onItemViewClicked(View v, boolean pinned) {
            final int flatPosition = mRecyclerView.getChildAdapterPosition(v);

            if (flatPosition == RecyclerView.NO_POSITION) {
                return;
            }

            final long expandablePosition = mRecyclerViewExpandableItemManager
                    .getExpandablePosition(flatPosition);
            final int groupPosition = RecyclerViewExpandableItemManager
                    .getPackedPositionGroup(expandablePosition);
            final int childPosition = RecyclerViewExpandableItemManager
                    .getPackedPositionChild(expandablePosition);

            if (childPosition == RecyclerView.NO_POSITION) {
                //Group
                AbstractExpandableDataProvider.GroupData data = getDataProvider().getGroupItem(groupPosition);
                if (data.isPinned()) {
                    // unpin if tapped the pinned item
                    data.setPinned(false);
                    notifyGroupItemChanged(groupPosition);
                }

            } else {

                AbstractExpandableDataProvider.ChildData data = getDataProvider().getChildItem(groupPosition,
                        childPosition);

                if (data.isPinned()) {
                    // unpin if tapped the pinned item
                    data.setPinned(false);
                    notifyChildItemChanged(groupPosition, childPosition);
                }

            }

        }
    });

    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.
    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);

    // for debugging
    //        animator.setDebug(true);
    //        animator.setMoveDuration(2000);
    //        animator.setRemoveDuration(2000);
    //        mRecyclerViewSwipeManager.setMoveToOutsideWindowAnimationDuration(2000);
    //        mRecyclerViewSwipeManager.setReturnToDefaultPositionAnimationDuration(2000);
}

From source file:com.github.chrisbanes.photoview.sample.SimpleSampleActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbar.setTitle("Simple Sample");
    toolbar.setNavigationIcon(R.drawable.ic_arrow_back_white_24dp);
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {
        @Override/*from ww w  .j  ava 2 s.c  o  m*/
        public void onClick(View v) {
            onBackPressed();
        }
    });
    toolbar.inflateMenu(R.menu.main_menu);
    toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            switch (item.getItemId()) {
            case R.id.menu_zoom_toggle:
                mPhotoView.setZoomable(!mPhotoView.isZoomEnabled());
                item.setTitle(
                        mPhotoView.isZoomEnabled() ? R.string.menu_zoom_disable : R.string.menu_zoom_enable);
                return true;

            case R.id.menu_scale_fit_center:
                mPhotoView.setScaleType(ImageView.ScaleType.CENTER);
                return true;

            case R.id.menu_scale_fit_start:
                mPhotoView.setScaleType(ImageView.ScaleType.FIT_START);
                return true;

            case R.id.menu_scale_fit_end:
                mPhotoView.setScaleType(ImageView.ScaleType.FIT_END);
                return true;

            case R.id.menu_scale_fit_xy:
                mPhotoView.setScaleType(ImageView.ScaleType.FIT_XY);
                return true;

            case R.id.menu_scale_scale_center:
                mPhotoView.setScaleType(ImageView.ScaleType.CENTER);
                return true;

            case R.id.menu_scale_scale_center_crop:
                mPhotoView.setScaleType(ImageView.ScaleType.CENTER_CROP);
                return true;

            case R.id.menu_scale_scale_center_inside:
                mPhotoView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
                return true;

            case R.id.menu_scale_random_animate:
            case R.id.menu_scale_random:
                Random r = new Random();

                float minScale = mPhotoView.getMinimumScale();
                float maxScale = mPhotoView.getMaximumScale();
                float randomScale = minScale + (r.nextFloat() * (maxScale - minScale));
                mPhotoView.setScale(randomScale, item.getItemId() == R.id.menu_scale_random_animate);

                showToast(String.format(SCALE_TOAST_STRING, randomScale));

                return true;
            case R.id.menu_matrix_restore:
                if (mCurrentDisplayMatrix == null)
                    showToast("You need to capture display matrix first");
                else
                    mPhotoView.setDisplayMatrix(mCurrentDisplayMatrix);
                return true;
            case R.id.menu_matrix_capture:
                mCurrentDisplayMatrix = new Matrix();
                mPhotoView.getDisplayMatrix(mCurrentDisplayMatrix);
                return true;
            }
            return false;
        }
    });
    mPhotoView = (PhotoView) findViewById(R.id.iv_photo);
    mCurrMatrixTv = (TextView) findViewById(R.id.tv_current_matrix);

    Drawable bitmap = ContextCompat.getDrawable(this, R.drawable.wallpaper);
    mPhotoView.setImageDrawable(bitmap);

    // Lets attach some listeners, not required though!
    mPhotoView.setOnMatrixChangeListener(new MatrixChangeListener());
    mPhotoView.setOnPhotoTapListener(new PhotoTapListener());
    mPhotoView.setOnSingleFlingListener(new SingleFlingListener());
}