Example usage for android.graphics.drawable StateListDrawable StateListDrawable

List of usage examples for android.graphics.drawable StateListDrawable StateListDrawable

Introduction

In this page you can find the example usage for android.graphics.drawable StateListDrawable StateListDrawable.

Prototype

public StateListDrawable() 

Source Link

Usage

From source file:com.lambdasoup.quickfit.ui.WorkoutListActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Timber.d("onCreate before inflate");
    setContentView(R.layout.activity_workout_list);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);//  w w  w.j  a  v  a  2  s . co  m
    //noinspection ConstantConditions
    toolbar.setTitle(getTitle());

    fabAnimationDuration = getResources().getInteger(R.integer.fab_animation_duration);

    fab = (FloatingActionButton) findViewById(R.id.fab);
    //noinspection ConstantConditions
    fab.setOnClickListener(view -> addNewWorkout());

    // need to set statelistdrawable referencing vector drawables programmatically, because
    // support library vector drawable support in 23.3.0 does not allow vector drawable
    // references in xml statelistdrawables
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        VectorDrawableCompat drawableAdd = VectorDrawableCompat.create(getResources(),
                R.drawable.ic_add_white_fat_24dp, getTheme());
        VectorDrawableCompat drawableExpandLess = VectorDrawableCompat.create(getResources(),
                R.drawable.ic_expand_less_white_fat_24dp, getTheme());

        StateListDrawable stateListDrawable = new StateListDrawable();
        stateListDrawable.addState(new int[] { android.R.attr.state_activated }, drawableExpandLess);
        stateListDrawable.addState(new int[] {}, drawableAdd);

        fab.setImageDrawable(stateListDrawable);
    }

    fabBackgroundToActivated = BackgroundTintListAnimator.create(this, fab, R.color.colorAccent,
            R.color.colorPrimaryMediumLight, fabAnimationDuration);
    fabBackgroundToNotActivated = BackgroundTintListAnimator.create(this, fab, R.color.colorPrimaryMediumLight,
            R.color.colorAccent, fabAnimationDuration);

    masterDetailView = (MasterDetailLayout) findViewById(R.id.two_panes);
    if (masterDetailView != null) {
        // The detail container view will be present only in the
        // large-screen layouts (res/values-w900dp).
        // If this view is present, then the
        // activity should be in two-pane mode.
        isTwoPane = true;

        fabAddSchedule = findViewById(R.id.fab_add_schedule);
        //noinspection ConstantConditions
        fabAddSchedule.setOnClickListener(view -> addNewSchedule());
        fabAddWorkout = findViewById(R.id.fab_add_workout);
        //noinspection ConstantConditions
        fabAddWorkout.setOnClickListener(view -> addNewWorkout());
        setMiniFabOffsets();

        masterDetailView.setAfterCollapse(() -> {
            CoordinatorLayout.LayoutParams fabLayoutParams = (CoordinatorLayout.LayoutParams) fab
                    .getLayoutParams();
            fabLayoutParams.setAnchorId(View.NO_ID);
            fabLayoutParams.gravity = Gravity.BOTTOM | Gravity.END;
            fab.setLayoutParams(fabLayoutParams);

            Fragment schedulesFragment = getSupportFragmentManager().findFragmentById(R.id.schedules_container);
            getSupportFragmentManager().beginTransaction().remove(schedulesFragment).commit();
        });
    }

    workoutsRecyclerView = (EmptyRecyclerView) findViewById(R.id.workout_list);
    workoutsAdapter = new WorkoutItemRecyclerViewAdapter(this, isTwoPane);
    workoutsAdapter.setOnWorkoutInteractionListener(this);

    workoutsRecyclerView.setAdapter(workoutsAdapter);
    workoutsRecyclerView.addItemDecoration(new DividerItemDecoration(this, false));

    readIntentExtras();

    if (savedInstanceState != null) {
        idToSelect = savedInstanceState.getLong(KEY_SHOW_WORKOUT_ID, NO_ID);
        if (idToSelect == NO_ID) {
            idToSelect = savedInstanceState.getLong(KEY_SELECTED_ITEM_ID, NO_ID);
        }
    } else {
        idToSelect = FIRST_ITEM_IF_EXISTS;
    }

    getLoaderManager().initLoader(0, null, this);
    Timber.d("onCreate finished");
}

From source file:com.esri.android.ecologicalmarineunitexplorer.watercolumn.WaterColumnFragment.java

private StateListDrawable buildStateList(int emuName) {
    StateListDrawable stateListDrawable = new StateListDrawable();

    GradientDrawable defaultShape = new GradientDrawable();
    int color = Color.parseColor(EmuHelper.getColorForEMUCluster(getContext(), emuName));
    defaultShape.setColor(color);//from   www  . ja v a 2s. c  om

    GradientDrawable selectedPressShape = new GradientDrawable();
    selectedPressShape.setColor(color);
    selectedPressShape.setStroke(5, Color.parseColor("#f4f442"));

    stateListDrawable.addState(new int[] { android.R.attr.state_pressed }, selectedPressShape);
    stateListDrawable.addState(new int[] { android.R.attr.state_selected }, selectedPressShape);
    stateListDrawable.addState(new int[] { android.R.attr.state_enabled }, defaultShape);

    return stateListDrawable;
}

From source file:org.opensilk.common.ui.widget.FloatingActionButton.java

/**
 * <= api 19//from   ww  w. ja  v a 2  s . c  o  m
 */
protected Drawable createSelectableDrawable() {

    ShapeDrawable drawableNormal = new ShapeDrawable(new OvalShape());
    drawableNormal.getPaint().setColor(mColorNormal);

    StateListDrawable stateDrawable = new StateListDrawable();

    ShapeDrawable drawableHighlight = new ShapeDrawable(new OvalShape());
    drawableHighlight.getPaint().setColor(mColorPressed);

    stateDrawable.addState(new int[] { android.R.attr.state_pressed }, drawableHighlight);
    stateDrawable.addState(new int[0], null);

    LayerDrawable layerDrawable = new LayerDrawable(new Drawable[] { drawableNormal, stateDrawable });

    return layerDrawable;
}

From source file:net.yanzm.mth.MaterialTabHost.java

/**
 * add new tab with title text/*from   w  w w .  ja v a  2  s .co m*/
 *
 * @param title title text
 */
public void addTab(CharSequence title) {
    int layoutId = getLayoutId(type);
    TextView tv = (TextView) inflater.inflate(layoutId, tabWidget, false);
    tv.setText(title);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        tv.setBackgroundResource(R.drawable.mth_tab_widget_background_ripple);

    } else {
        // create background using colorControlActivated
        StateListDrawable d = new StateListDrawable();
        d.addState(new int[] { android.R.attr.state_pressed }, new ColorDrawable(colorControlActivated));
        d.setAlpha(180);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            tv.setBackground(d);
        } else {
            tv.setBackgroundDrawable(d);
        }
    }

    int tabId = tabWidget.getTabCount();

    addTab(newTabSpec(String.valueOf(tabId)).setIndicator(tv).setContent(android.R.id.tabcontent));
}

From source file:com.nihaskalam.progressbuttonlibrary.CircularProgressButton.java

private void initErrorStateDrawable() {
    int colorPressed = getPressedColor(mErrorColorState);

    StrokeGradientDrawable drawablePressed = createDrawable(colorPressed);
    mErrorStateDrawable = new StateListDrawable();

    mErrorStateDrawable.addState(new int[] { android.R.attr.state_pressed },
            drawablePressed.getGradientDrawable());
    mErrorStateDrawable.addState(StateSet.WILD_CARD, background.getGradientDrawable());
}

From source file:android.support.design.internal.NavigationMenuItemView.java

private StateListDrawable createDefaultBackground() {
    TypedValue value = new TypedValue();
    if (getContext().getTheme().resolveAttribute(android.support.v7.appcompat.R.attr.colorControlHighlight,
            value, true)) {//from ww w  . j av a  2  s  . c o  m
        StateListDrawable drawable = new StateListDrawable();
        drawable.addState(CHECKED_STATE_SET, new ColorDrawable(value.data));
        drawable.addState(EMPTY_STATE_SET, new ColorDrawable(Color.TRANSPARENT));
        return drawable;
    }
    return null;
}

From source file:cn.finalteam.galleryfinal.widget.FloatingActionButton.java

private StateListDrawable createFillDrawable(RectF circleRect) {
    StateListDrawable drawable = new StateListDrawable();
    drawable.addState(new int[] { android.R.attr.state_pressed },
            createCircleDrawable(circleRect, mColorPressed));
    drawable.addState(new int[] {}, createCircleDrawable(circleRect, mColorNormal));
    return drawable;
}

From source file:com.gudong.appkit.ui.fragment.ColorChooseDialog.java

private Drawable createSelector(int color) {
    ShapeDrawable coloredCircle = new ShapeDrawable(new OvalShape());
    coloredCircle.getPaint().setColor(color);
    ShapeDrawable darkerCircle = new ShapeDrawable(new OvalShape());
    darkerCircle.getPaint().setColor(shiftColor(color));

    StateListDrawable stateListDrawable = new StateListDrawable();
    stateListDrawable.addState(new int[] { -android.R.attr.state_pressed }, coloredCircle);
    stateListDrawable.addState(new int[] { android.R.attr.state_pressed }, darkerCircle);
    return stateListDrawable;
}

From source file:com.nihaskalam.progressbuttonlibrary.CircularProgressButton.java

private void initCompleteStateDrawable() {
    int colorPressed = getPressedColor(mCompleteColorState);

    StrokeGradientDrawable drawablePressed = createDrawable(colorPressed);
    mCompleteStateDrawable = new StateListDrawable();

    mCompleteStateDrawable.addState(new int[] { android.R.attr.state_pressed },
            drawablePressed.getGradientDrawable());
    mCompleteStateDrawable.addState(StateSet.WILD_CARD, background.getGradientDrawable());
}

From source file:com.appeaser.sublimepickerlibrary.utilities.SUtils.java

private static Drawable createButtonNormalBg(Context context, int colorControlHighlight) {
    StateListDrawable sld = new StateListDrawable();
    sld.addState(new int[] { android.R.attr.state_pressed }, createButtonShape(context, colorControlHighlight));
    sld.addState(new int[] {}, new ColorDrawable(Color.TRANSPARENT));
    return sld;//from  w w  w .  j  a v  a2s  .co  m
}