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.h6ah4i.android.example.advrecyclerview.demo_d_on_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());

    // drag & drop manager
    mRecyclerViewDragDropManager = new RecyclerViewDragDropManager();
    mRecyclerViewDragDropManager.setDraggingItemShadowDrawable(
            (NinePatchDrawable) ContextCompat.getDrawable(getContext(), R.drawable.material_shadow_z3));
    // Start dragging after long press
    mRecyclerViewDragDropManager.setInitiateOnLongPress(true);
    mRecyclerViewDragDropManager.setInitiateOnMove(false);

    //adapter//from   w  w w.  j  ava 2 s .com
    final MyDraggableItemAdapter myItemAdapter = new MyDraggableItemAdapter(getDataProvider());
    mAdapter = myItemAdapter;

    mWrappedAdapter = mRecyclerViewDragDropManager.createWrappedAdapter(myItemAdapter); // wrap for dragging

    final GeneralItemAnimator animator = new RefactoredDefaultItemAnimator();

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

    mRecyclerViewDragDropManager.attachRecyclerView(mRecyclerView);

    // for debugging
    //        animator.setDebug(true);
    //        animator.setMoveDuration(2000);
}

From source file:com.angelatech.yeyelive.view.PeriscopeLayout.java

private void init(Context mContext) {
    //?//from  w  w w  .ja  va2  s .  c  o  m
    drawables = new Drawable[7];
    Drawable love_0 = ContextCompat.getDrawable(mContext, R.drawable.love_heart1);
    Drawable love_1 = ContextCompat.getDrawable(mContext, R.drawable.love_heart2);
    Drawable love_2 = ContextCompat.getDrawable(mContext, R.drawable.love_heart3);
    Drawable love_3 = ContextCompat.getDrawable(mContext, R.drawable.love_heart4);
    Drawable love_4 = ContextCompat.getDrawable(mContext, R.drawable.love_heart5);
    Drawable love_5 = ContextCompat.getDrawable(mContext, R.drawable.love_heart6);
    Drawable love_6 = ContextCompat.getDrawable(mContext, R.drawable.love_heart7);

    drawables[0] = love_0;
    drawables[1] = love_1;
    drawables[2] = love_2;
    drawables[3] = love_3;
    drawables[4] = love_4;
    drawables[5] = love_5;
    drawables[6] = love_6;
    //? ??
    //? 3?,??
    dHeight = love_0.getIntrinsicHeight();
    dWidth = love_0.getIntrinsicWidth();

    //  
    lp = new LayoutParams(dWidth, dHeight);
    lp.addRule(CENTER_HORIZONTAL, TRUE);//TRUE ?? ?true
    lp.addRule(ALIGN_PARENT_BOTTOM, TRUE);

    // ??
    interpolators = new Interpolator[4];
    interpolators[0] = line;
    interpolators[1] = acc;
    interpolators[2] = dce;
    interpolators[3] = accdec;
}

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

    // drag & drop manager
    mRecyclerViewDragDropManager = new RecyclerViewDragDropManager();
    mRecyclerViewDragDropManager.setDraggingItemShadowDrawable(
            (NinePatchDrawable) ContextCompat.getDrawable(getContext(), R.drawable.material_shadow_z3));
    // Start dragging after long press
    mRecyclerViewDragDropManager.setInitiateOnLongPress(true);
    mRecyclerViewDragDropManager.setInitiateOnMove(false);

    //adapter//from  w w w.  j  a  v a2  s .co m
    final DragOnLongPressExampleAdapter myItemAdapter = new DragOnLongPressExampleAdapter(getDataProvider());
    mAdapter = myItemAdapter;

    mWrappedAdapter = mRecyclerViewDragDropManager.createWrappedAdapter(myItemAdapter); // wrap for dragging

    final GeneralItemAnimator animator = new RefactoredDefaultItemAnimator();

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

    mRecyclerViewDragDropManager.attachRecyclerView(mRecyclerView);

    // for debugging
    //        animator.setDebug(true);
    //        animator.setMoveDuration(2000);
}

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

    // drag & drop manager
    mRecyclerViewDragDropManager = new RecyclerViewDragDropManager();
    mRecyclerViewDragDropManager.setDraggingItemShadowDrawable(
            (NinePatchDrawable) ContextCompat.getDrawable(getContext(), R.drawable.material_shadow_z3));

    //adapter//from   w  w  w.ja va 2 s .c  om
    final MyDraggableItemAdapter myItemAdapter = new MyDraggableItemAdapter(getDataProvider());
    mAdapter = myItemAdapter;

    mWrappedAdapter = mRecyclerViewDragDropManager.createWrappedAdapter(myItemAdapter); // wrap for dragging

    final GeneralItemAnimator animator = new RefactoredDefaultItemAnimator();

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

    mRecyclerViewDragDropManager.attachRecyclerView(mRecyclerView);

    // for debugging
    //        animator.setDebug(true);
    //        animator.setMoveDuration(2000);
}

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

    // drag & drop manager
    mRecyclerViewDragDropManager = new RecyclerViewDragDropManager();
    mRecyclerViewDragDropManager.setDraggingItemShadowDrawable(
            (NinePatchDrawable) ContextCompat.getDrawable(getContext(), R.drawable.material_shadow_z3));

    //adapter//w  w  w. jav a2 s .c om
    final DraggableWithSectionExampleAdapter myItemAdapter = new DraggableWithSectionExampleAdapter(
            getDataProvider());
    mAdapter = myItemAdapter;

    mWrappedAdapter = mRecyclerViewDragDropManager.createWrappedAdapter(myItemAdapter); // wrap for dragging

    final GeneralItemAnimator animator = new RefactoredDefaultItemAnimator();

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

    mRecyclerViewDragDropManager.attachRecyclerView(mRecyclerView);

    // for debugging
    //        animator.setDebug(true);
    //        animator.setMoveDuration(2000);
}

From source file:com.filemanager.free.activities.Preferences.java

@Override
public void onCreate(Bundle savedInstanceState) {
    SharedPreferences Sp = PreferenceManager.getDefaultSharedPreferences(this);

    super.onCreate(savedInstanceState);
    setContentView(R.layout.prefsfrag);/*from  ww  w  . j  a va2s.  co m*/
    mHandler = new Handler();

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    skin = PreferenceUtils.getSkinColor(Sp.getInt("skin_color_position", 9));
    if (Build.VERSION.SDK_INT >= 21) {
        ActivityManager.TaskDescription taskDescription = new ActivityManager.TaskDescription("File Manager",
                ((BitmapDrawable) ContextCompat.getDrawable(getBaseContext(), R.mipmap.ic_launcher))
                        .getBitmap(),
                Color.parseColor(skin));
        setTaskDescription(taskDescription);
    }
    skinStatusBar = PreferenceUtils.getStatusColor(skin);
    setSupportActionBar(toolbar);
    assert (getSupportActionBar()) != null;
    getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_HOME_AS_UP | ActionBar.DISPLAY_SHOW_TITLE);
    getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor(skin)));
    int sdk = Build.VERSION.SDK_INT;

    if (sdk == 20 || sdk == 19) {
        SystemBarTintManager tintManager = new SystemBarTintManager(this);
        tintManager.setStatusBarTintEnabled(true);
        tintManager.setStatusBarTintColor(Color.parseColor(skin));

        FrameLayout.MarginLayoutParams p = (ViewGroup.MarginLayoutParams) findViewById(R.id.preferences)
                .getLayoutParams();
        SystemBarTintManager.SystemBarConfig config = tintManager.getConfig();
        p.setMargins(0, config.getStatusBarHeight(), 0, 0);
    } else if (Build.VERSION.SDK_INT >= 21) {
        boolean colourednavigation = Sp.getBoolean("colorednavigation", true);
        Window window = getWindow();
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        window.setStatusBarColor((PreferenceUtils.getStatusColor(skin)));
        if (colourednavigation)
            window.setNavigationBarColor((PreferenceUtils.getStatusColor(skin)));

    }
    selectItem(0);
}

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

    // drag & drop manager
    mRecyclerViewDragDropManager = new RecyclerViewDragDropManager();
    mRecyclerViewDragDropManager.setDraggingItemShadowDrawable(
            (NinePatchDrawable) ContextCompat.getDrawable(getContext(), R.drawable.material_shadow_z3));

    //adapter/* www.  j a  v  a 2 s. co  m*/
    final DraggableExampleItemAdapter myItemAdapter = new DraggableExampleItemAdapter(getDataProvider());
    mAdapter = myItemAdapter;

    mWrappedAdapter = mRecyclerViewDragDropManager.createWrappedAdapter(myItemAdapter); // wrap for dragging

    final GeneralItemAnimator animator = new RefactoredDefaultItemAnimator();

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

    mRecyclerViewDragDropManager.attachRecyclerView(mRecyclerView);

    // for debugging
    //        animator.setDebug(true);
    //        animator.setMoveDuration(2000);
}

From source file:com.apptentive.android.sdk.module.engagement.interaction.fragment.UpgradeMessageFragment.java

private Drawable getIconDrawableResourceId() {
    try {/*from  w w w.ja  v a  2 s .co m*/
        Context context = getContext();
        PackageManager pm = context.getPackageManager();
        PackageInfo pi = pm.getPackageInfo(context.getPackageName(), 0);
        return ContextCompat.getDrawable(getContext(), pi.applicationInfo.icon);
    } catch (Exception e) {
        ApptentiveLog.e("Error loading app icon.", e);
    }
    return null;
}

From source file:com.einzig.ipst2.util.ThemeHelper.java

public static void styleRadioButton(CompoundButton rb, Context context, boolean isChecked) {
    if (isDarkTheme(context)) {
        if (isChecked) {
            rb.setBackground(ContextCompat.getDrawable(context, R.drawable.button_bg_dark));
            rb.setTextColor(ContextCompat.getColor(context, R.color.white));
        } else {/* w  w w.  java2s  .  c  o m*/
            rb.setBackground(null);
            rb.setTextColor(ContextCompat.getColor(context, R.color.white));
        }
    } else {
        Logger.d("BUTTON: " + rb.getText().toString() + " " + isChecked);
        if (isChecked) {
            rb.setBackground(ContextCompat.getDrawable(context, R.drawable.button_bg));
            rb.setTextColor(ContextCompat.getColor(context, R.color.white));
        } else {
            rb.setBackground(null);
            rb.setTextColor(ContextCompat.getColor(context, R.color.colorPrimary));
        }
    }
}

From source file:com.jun.jokedaquan.widget.divider.DividerItemDecoration.java

/**
 * Construct a decoration with a specified resId,the default orientation is {@link #VERTICAL_LIST}
 *
 * @param context Context// ww  w .ja  v  a  2s.c  om
 * @param resId   id of divider
 */
public DividerItemDecoration(Context context, @DrawableRes int resId) {
    mDivider = ContextCompat.getDrawable(context, resId);
    setOrientation(VERTICAL_LIST);
}