Example usage for android.graphics.drawable GradientDrawable GradientDrawable

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

Introduction

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

Prototype

private GradientDrawable(@NonNull GradientState state, @Nullable Resources res) 

Source Link

Document

Creates a new themed GradientDrawable based on the specified constant state.

Usage

From source file:Main.java

public static Drawable paintGradient(Context c, int mainColor, String gColor, String g) {
    GradientDrawable gd = null;// w  w  w. j a  v  a  2  s .co  m
    int[] a = { mainColor, getIntPref(c, gColor) };
    int gType = Integer.parseInt(c.getSharedPreferences(THEME_PREFS, 0).getString(g, "0"));
    if (gType == 2)
        gd = new GradientDrawable(GradientDrawable.Orientation.LEFT_RIGHT, a);
    if (gType == 1)
        gd = new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM, a);
    return gd;
}

From source file:Main.java

public static void setGradientForPreferenceView(View v) {

    int[] colorsForGradient = new int[2];
    colorsForGradient[0] = Color.argb(0, 0, 0, 0);
    colorsForGradient[1] = Color.argb(64, 255, 255, 255);
    GradientDrawable d = new GradientDrawable(GradientDrawable.Orientation.LEFT_RIGHT, colorsForGradient);
    d.setGradientType(GradientDrawable.LINEAR_GRADIENT);
    d.setShape(GradientDrawable.RECTANGLE);
    // doesn't help d.setUseLevel(true);
    d.setDither(true);/* w w w . j  a v a 2  s .c o m*/
    v.setBackgroundDrawable(d);
}

From source file:Main.java

public static synchronized GradientDrawable getHorizontalGradiant(final int color, final int backgroundColor) {
    final int[] colors = new int[2];
    colors[0] = backgroundColor;/* w ww .j av  a2s. c om*/
    colors[1] = color;

    final GradientDrawable d = new GradientDrawable(GradientDrawable.Orientation.BOTTOM_TOP, colors);
    d.setDither(true);

    return d;
}

From source file:Main.java

public static synchronized GradientDrawable getGradiant(final int color) {
    int[] colors;
    int darkerColor;
    // Get darker color
    final float[] hsv = new float[3];
    Color.colorToHSV(color, hsv);
    hsv[2] *= 0.9f; // value component
    darkerColor = Color.HSVToColor(hsv);

    colors = new int[2];
    colors[0] = darkerColor;//ww w .java 2 s  .co m
    colors[1] = color;

    final GradientDrawable d = new GradientDrawable(GradientDrawable.Orientation.BOTTOM_TOP, colors);
    d.setDither(true);

    return d;
}

From source file:com.waz.zclient.ui.utils.ColorUtils.java

public static Drawable getButtonBackground(int borderColor, int fillColor, int strokeWidth, int cornerRadius) {
    int fillColorPressed = getPressColor(PRESSED_ALPHA, fillColor);
    int borderColorPressed = getPressColor(PRESSED_ALPHA, borderColor);

    GradientDrawable gradientDrawablePressed = new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM,
            new int[] { fillColorPressed, fillColorPressed });
    gradientDrawablePressed.setStroke(strokeWidth, borderColorPressed);
    gradientDrawablePressed.setCornerRadius(cornerRadius);

    GradientDrawable gradientDrawable = new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM,
            new int[] { fillColor, fillColor });
    gradientDrawable.setStroke(strokeWidth, borderColor);
    gradientDrawable.setCornerRadius(cornerRadius);

    StateListDrawable states = new StateListDrawable();
    states.addState(new int[] { android.R.attr.state_pressed }, gradientDrawablePressed);
    states.addState(new int[] { android.R.attr.state_focused }, gradientDrawablePressed);
    states.addState(new int[] {}, gradientDrawable);

    return states;
}

From source file:siminov.connect.sample.fragments.MenuSlider.java

public void onResume() {
    super.onResume();

    int[] colors = { 0, Color.LTGRAY, 0 };
    getListView().setDivider(new GradientDrawable(Orientation.RIGHT_LEFT, colors));
    getListView().setDividerHeight(1);//from   w  w w . j  a  v a 2s  .com
    getListView().setCacheColorHint(Color.TRANSPARENT);

    getListView().setOnItemClickListener(this);
}

From source file:eu.geopaparazzi.library.forms.FormListFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    List<String> fragmentTitles = mFragmentListSupporter.getListTitles();

    ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(),
            android.R.layout.simple_list_item_activated_1,
            fragmentTitles.toArray(new String[fragmentTitles.size()]));

    int color = Compat.getColor(getActivity(), R.color.formcolor);
    int[] colors = { 0, color, 0 };
    ListView listView = getListView();
    listView.setDivider(new GradientDrawable(Orientation.RIGHT_LEFT, colors));
    listView.setDividerHeight(2);/*from  w  w  w  . j  a v a2  s  .  co m*/

    listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
    listView.setFocusableInTouchMode(true);
    StateListDrawable selector = new StateListDrawable();
    selector.addState(new int[] { -android.R.attr.state_pressed },
            new ColorDrawable(Compat.getColor(getContext(), R.color.main_selection)));
    listView.setSelector(selector);

    setListAdapter(adapter);

    if (fragmentTitles.size() > 0)
        listView.setItemChecked(0, true);
}

From source file:net.pocketmagic.android.carousel.MainActivity.java

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

    //no keyboard unless requested by user
    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

    // compute screen size and scaling
    Singleton.getInstance().InitGUIFrame(this);

    int padding = m_Inst.Scale(10);
    // create the interface : full screen container
    RelativeLayout panel = new RelativeLayout(this);
    panel.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
    panel.setPadding(padding, padding, padding, padding);
    panel.setBackgroundDrawable(new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM,
            new int[] { Color.WHITE, Color.GRAY }));
    setContentView(panel);//from w  w  w  .  j  ava  2s  . co m

    // copy images from assets to sdcard
    AppUtils.AssetFileCopy(this, "/mnt/sdcard/plasma1.png", "plasma1.png", false);
    AppUtils.AssetFileCopy(this, "/mnt/sdcard/plasma2.png", "plasma2.png", false);
    AppUtils.AssetFileCopy(this, "/mnt/sdcard/plasma3.png", "plasma3.png", false);
    AppUtils.AssetFileCopy(this, "/mnt/sdcard/plasma4.png", "plasma4.png", false);

    //Create carousel view documents
    ArrayList<CarouselDataItem> Docus = new ArrayList<CarouselDataItem>();
    for (int i = 0; i < 1000; i++) {
        CarouselDataItem docu;
        if (i % 4 == 0)
            docu = new CarouselDataItem("/mnt/sdcard/plasma1.png", 0, "First Image " + i);
        else if (i % 4 == 1)
            docu = new CarouselDataItem("/mnt/sdcard/plasma2.png", 0, "Second Image " + i);
        else if (i % 4 == 2)
            docu = new CarouselDataItem("/mnt/sdcard/plasma3.png", 0, "Third Image " + i);
        else
            docu = new CarouselDataItem("/mnt/sdcard/plasma4.png", 0, "4th Image " + i);
        Docus.add(docu);
    }

    // add the serach filter
    EditText etSearch = new EditText(this);
    etSearch.setHint("Search your documents");
    etSearch.setSingleLine();
    etSearch.setTextColor(Color.BLACK);
    etSearch.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_menu_search, 0, 0, 0);
    AppUtils.AddView(panel, etSearch, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, new int[][] {
            new int[] { RelativeLayout.CENTER_HORIZONTAL }, new int[] { RelativeLayout.ALIGN_PARENT_TOP } }, -1,
            -1);
    etSearch.addTextChangedListener((TextWatcher) this);

    // add logo
    TextView tv = new TextView(this);
    tv.setTextColor(Color.BLACK);
    tv.setText("www.pocketmagic.net");
    AppUtils.AddView(panel, tv, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, new int[][] {
            new int[] { RelativeLayout.CENTER_HORIZONTAL }, new int[] { RelativeLayout.ALIGN_PARENT_BOTTOM } },
            -1, -1);

    // create the carousel
    CarouselView coverFlow = new CarouselView(this);

    // create adapter and specify device independent items size (scaling)
    // for more details see: http://www.pocketmagic.net/2013/04/how-to-scale-an-android-ui-on-multiple-screens/
    m_carouselAdapter = new CarouselViewAdapter(this, Docus, m_Inst.Scale(400), m_Inst.Scale(300));
    coverFlow.setAdapter(m_carouselAdapter);
    coverFlow.setSpacing(-1 * m_Inst.Scale(150));
    coverFlow.setSelection(Integer.MAX_VALUE / 2, true);
    coverFlow.setAnimationDuration(1000);
    coverFlow.setOnItemSelectedListener((OnItemSelectedListener) this);

    AppUtils.AddView(panel, coverFlow, LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT,
            new int[][] { new int[] { RelativeLayout.CENTER_IN_PARENT } }, -1, -1);
}

From source file:com.yahala.ui.Views.StickersView.java

private void init() {
    setOrientation(LinearLayout.VERTICAL);
    loadRecents();//from  www .j  a  v  a 2s  .  c o m
    setBackgroundDrawable(new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM, new int[] {
            Color.parseColor("#FF373737"), Color.parseColor("#FF575757"), Color.parseColor("#FF666666") }));

    emojiPagerAdapter = new EmojiPagerAdapter(getContext(), EmojiManager.getInstance().stickersCategories);
    pager = new ViewPager(getContext());
    pager.setAdapter(emojiPagerAdapter);
    FileLog.e("EmojiManager.stickersCategories", "" + EmojiManager.getInstance().stickersCategories.size());
    PagerSlidingTabStripEmoji tabs = new PagerSlidingTabStripEmoji(getContext());
    tabs.setViewPager(pager);
    tabs.setShouldExpand(false);
    tabs.setMinimumWidth(OSUtilities.dp(50));
    tabs.setTabPaddingLeftRight(OSUtilities.dp(10));
    tabs.setIndicatorHeight(3);
    //tabs.setTabBackground(Color.parseColor("#FF3f9fe0"));
    tabs.setTabBackground(R.drawable.bar_selector_main);

    tabs.setIndicatorColor(Color.parseColor("#FFffffff"));
    tabs.setDividerColor(Color.parseColor("#ff222222"));
    tabs.setUnderlineHeight(2);
    tabs.setUnderlineColor(Color.parseColor("#ff373737"));

    //tabs.setTabBackground(0);
    LinearLayout localLinearLayout = new LinearLayout(getContext());
    localLinearLayout.setOrientation(LinearLayout.HORIZONTAL);
    localLinearLayout.addView(tabs,
            new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT, 1.0f));
    ImageView localImageView = new ImageView(getContext());
    localImageView.setImageResource(R.drawable.ic_emoji_backspace);
    localImageView.setScaleType(ImageView.ScaleType.CENTER);
    localImageView.setBackgroundResource(R.drawable.bg_emoji_bs);
    localImageView.setOnClickListener(new OnClickListener() {
        public void onClick(View view) {
            if (StickersView.this.listener != null) {
                StickersView.this.listener.onBackspace();
            }
        }
    });
    localLinearLayout.addView(localImageView,
            new LayoutParams(OSUtilities.dpf(61.0f), LayoutParams.MATCH_PARENT));
    /* recentsWrap = new FrameLayout(getContext());
     recentsWrap.addView(views.get(0));
     TextView localTextView = new TextView(getContext());
     localTextView.setText(LocaleController.getString("NoRecent", R.string.NoRecent));
     localTextView.setTextSize(18.0f);
     localTextView.setTextColor(-7829368);
     localTextView.setGravity(17);
     recentsWrap.addView(localTextView);
     views.get(0).setEmptyView(localTextView);*/
    addView(localLinearLayout, new LayoutParams(-1, OSUtilities.dpf(48.0f)));

    addView(pager);

    if (!EmojiManager.getInstance().stickersCategoriesDict.containsKey("recents")
            || EmojiManager.getInstance().stickersCategoriesDict.get("recents").stickers.size() == 0) {
        pager.setCurrentItem(1);
    }
}

From source file:com.yahala.ui.Views.EmojiViewExtra.java

private void init() {
    setOrientation(LinearLayout.VERTICAL);
    loadRecents();/*from w  w  w  .j  av  a2 s.c o m*/
    setBackgroundDrawable(new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM, new int[] {
            Color.parseColor("#FF373737"), Color.parseColor("#FF575757"), Color.parseColor("#FF666666") }));

    emojiPagerAdapter = new EmojiPagerAdapter(getContext(), EmojiManager.getInstance().categories);
    pager = new ViewPager(getContext());
    pager.setOffscreenPageLimit(5);
    pager.setAdapter(emojiPagerAdapter);
    FileLog.e("EmojiManager.emojiGroups", "" + EmojiManager.getInstance().categories.size());
    PagerSlidingTabStripEmoji tabs = new PagerSlidingTabStripEmoji(getContext());
    tabs.setViewPager(pager);
    tabs.setShouldExpand(false);
    tabs.setMinimumWidth(OSUtilities.dp(50));
    tabs.setTabPaddingLeftRight(OSUtilities.dp(10));
    tabs.setIndicatorHeight(3);
    //tabs.setTabBackground(Color.parseColor("#FF3f9fe0"));
    tabs.setTabBackground(R.drawable.bar_selector_main);

    tabs.setIndicatorColor(Color.parseColor("#FFffffff"));
    tabs.setDividerColor(Color.parseColor("#ff222222"));
    tabs.setUnderlineHeight(2);
    tabs.setUnderlineColor(Color.parseColor("#ff373737"));

    //tabs.setTabBackground(0);
    LinearLayout localLinearLayout = new LinearLayout(getContext());
    localLinearLayout.setOrientation(LinearLayout.HORIZONTAL);
    localLinearLayout.addView(tabs,
            new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT, 1.0f));
    ImageView localImageView = new ImageView(getContext());
    localImageView.setImageResource(R.drawable.ic_emoji_backspace);
    localImageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
    localImageView.setBackgroundResource(R.drawable.bg_emoji_bs);
    localImageView.setOnClickListener(new OnClickListener() {
        public void onClick(View view) {
            if (EmojiViewExtra.this.listener != null) {
                EmojiViewExtra.this.listener.onBackspace();
            }
        }
    });
    localLinearLayout.addView(localImageView,
            new LayoutParams(OSUtilities.dpf(61.0f), LayoutParams.MATCH_PARENT));
    /* recentsWrap = new FrameLayout(getContext());
     recentsWrap.addView(views.get(0));
     TextView localTextView = new TextView(getContext());
     localTextView.setText(LocaleController.getString("NoRecent", R.string.NoRecent));
     localTextView.setTextSize(18.0f);
     localTextView.setTextColor(-7829368);
     localTextView.setGravity(17);
     recentsWrap.addView(localTextView);
     views.get(0).setEmptyView(localTextView);*/
    addView(localLinearLayout, new LayoutParams(-1, OSUtilities.dpf(48.0f)));

    addView(pager);

    if (!EmojiManager.getInstance().categoriesDict.containsKey("recents")
            || EmojiManager.getInstance().categoriesDict.get("recents").emojis.size() == 0) {
        pager.setCurrentItem(1);
    }
}