Example usage for android.graphics.drawable ShapeDrawable ShapeDrawable

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

Introduction

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

Prototype

public ShapeDrawable() 

Source Link

Document

ShapeDrawable constructor.

Usage

From source file:Main.java

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private static Drawable getRippleDrawable(int pressedColor, Integer normalColor) {
    ColorStateList colorStateList = getPressedColorSelector(pressedColor);
    Drawable mask, content = null;/*from www .  j  a v  a2 s  . c  o m*/

    if (null == normalColor) {
        mask = new ShapeDrawable();
    } else {
        content = new ColorDrawable(normalColor);
        mask = getRippleMask(Color.WHITE);
    }
    return new RippleDrawable(colorStateList, content, mask);
}

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

public MaterialTabHost(Context context, AttributeSet attrs) {
    super(context, attrs);

    inflater = LayoutInflater.from(context);

    TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.MaterialTabHost, 0, 0);
    int indicatorColor = a.getColor(R.styleable.MaterialTabHost_colorTabIndicator, Color.YELLOW);
    colorControlActivated = a.getColor(R.styleable.MaterialTabHost_colorBackground, Color.WHITE);

    setBackgroundColor(colorControlActivated);
    a.recycle();//  www.  jav  a 2s. co m

    // ColorDrawable on 2.x does not use getBounds() so use ShapeDrawable
    indicator = new ShapeDrawable();
    indicator.setColorFilter(indicatorColor, PorterDuff.Mode.SRC_ATOP);

    Resources res = context.getResources();
    indicatorHeight = res.getDimensionPixelSize(R.dimen.mth_tab_indicator_height);
    leftOffset = res.getDimensionPixelSize(R.dimen.mth_tab_left_offset);
    int tabHeight = res.getDimensionPixelSize(R.dimen.mth_tab_height);

    tabWidget = new TabWidget(context);
    tabWidget.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, tabHeight));
    tabWidget.setId(android.R.id.tabs);
    tabWidget.setStripEnabled(false);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        tabWidget.setShowDividers(LinearLayout.SHOW_DIVIDER_NONE);
    }
    addView(tabWidget);

    FrameLayout fl = new FrameLayout(context);
    fl.setLayoutParams(new LayoutParams(0, 0));
    fl.setId(android.R.id.tabcontent);
    addView(fl);

    setup();

    setOnTabChangedListener(new TabHost.OnTabChangeListener() {
        @Override
        public void onTabChanged(String tabId) {
            if (listener != null) {
                listener.onTabSelected(Integer.valueOf(tabId));
            }
        }
    });

    float density = getResources().getDisplayMetrics().density;

    // set elevation for App bar
    // http://www.google.com/design/spec/what-is-material/objects-in-3d-space.html#objects-in-3d-space-elevation
    ViewCompat.setElevation(this, APP_TAB_ELEVATION * density);
}

From source file:org.de.jmg.learn.SettingsActivity.java

public void init(boolean blnRestart) throws Exception {
    if (_Intent == null || _main == null || SettingsView == null || _blnInitialized) {
        return;//from  w  w  w. j a v a  2 s .  c o m
    }
    try {
        //lib.ShowToast(_main, "Settings Start");

        RelativeLayout layout = (RelativeLayout) findViewById(R.id.layoutSettings); // id fetch from xml
        ShapeDrawable rectShapeDrawable = new ShapeDrawable(); // pre defined class
        int pxPadding = lib.dpToPx(10);
        rectShapeDrawable.setPadding(pxPadding, pxPadding, pxPadding,
                pxPadding * ((lib.NookSimpleTouch()) ? 2 : 1));
        Paint paint = rectShapeDrawable.getPaint();
        paint.setColor(Color.BLACK);
        paint.setStyle(Style.STROKE);
        paint.setStrokeWidth(5); // you can change the value of 5
        lib.setBg(layout, rectShapeDrawable);

        mainView = _main.findViewById(Window.ID_ANDROID_CONTENT);
        //Thread.setDefaultUncaughtExceptionHandler(ErrorHandler);
        prefs = _main.getPreferences(Context.MODE_PRIVATE);

        TextView txtSettings = (TextView) findViewById(R.id.txtSettings);
        SpannableString Settings = new SpannableString(txtSettings.getText());
        Settings.setSpan(new UnderlineSpan(), 0, Settings.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        txtSettings.setText(Settings);
        initCheckBoxes();
        initSpinners(blnRestart);
        initButtons();
        initHelp();
        edDataDir = (EditText) findViewById(R.id.edDataDir);
        edDataDir.setSingleLine(true);
        edDataDir.setText(_main.JMGDataDirectory);
        edDataDir.setImeOptions(EditorInfo.IME_ACTION_DONE);
        edDataDir.setOnEditorActionListener(new TextView.OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                if (actionId == EditorInfo.IME_ACTION_DONE) {
                    String strDataDir = edDataDir.getText().toString();
                    File fileSelected = new File(strDataDir);
                    if (fileSelected.isDirectory() && fileSelected.exists()) {
                        _main.setJMGDataDirectory(fileSelected.getPath());
                        edDataDir.setText(_main.JMGDataDirectory);
                        Editor editor = prefs.edit();
                        editor.putString("JMGDataDirectory", fileSelected.getPath());
                        editor.commit();
                    }
                }
                return true;
            }
        });
        edDataDir.setOnLongClickListener(new OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                ShowDataDirDialog();
                return true;
            }
        });
        if (!(lib.NookSimpleTouch()) && !_main.isSmallDevice) {
            SettingsView.getViewTreeObserver()
                    .addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {

                        @Override
                        public void onGlobalLayout() {
                            // Ensure you call it only once :
                            lib.removeLayoutListener(SettingsView.getViewTreeObserver(), this);

                            // Here you can get the size :)
                            resize(0);
                            //lib.ShowToast(_main, "Resize End");
                        }
                    });

        } else {
            //resize(1.8f);
            mScale = 1.0f;
        }
        _blnInitialized = true;
    } catch (Exception ex) {
        lib.ShowException(_main, ex);
    }

}

From source file:com.nile.kmooc.view.custom.popup.menu.MenuPopupHelper.java

public boolean tryShow() {
    mPopup = new ListPopupWindow(mContext, null, mPopupStyleAttr, mPopupStyleRes);
    mPopup.setOnDismissListener(this);
    mPopup.setOnItemClickListener(this);
    mPopup.setAdapter(mAdapter);//  w  w  w.j a  v  a2 s.  c  om
    mPopup.setModal(true);

    View anchor = mAnchorView;
    if (anchor != null) {
        final boolean addGlobalListener = mTreeObserver == null;
        mTreeObserver = anchor.getViewTreeObserver(); // Refresh to latest
        if (addGlobalListener)
            mTreeObserver.addOnGlobalLayoutListener(this);
        anchor.addOnAttachStateChangeListener(this);
        mPopup.setAnchorView(anchor);
        mPopup.setDropDownGravity(mDropDownGravity);
    } else {
        return false;
    }

    if (mContentWidth == Integer.MIN_VALUE) {
        mContentWidth = measureContentWidth();
    }
    mPopup.setContentWidth(mContentWidth);
    // Invert the horizontal offset in RTL mode.
    if (ViewCompat.getLayoutDirection(mAnchorView) == ViewCompat.LAYOUT_DIRECTION_RTL) {
        mPopup.setHorizontalOffset(-mPopup.getHorizontalOffset());
    }
    // Implement right gravity manually through horizontal offset pre-KitKat.
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT
            && (Gravity.getAbsoluteGravity(mDropDownGravity, ViewCompat.getLayoutDirection(anchor))
                    & Gravity.HORIZONTAL_GRAVITY_MASK) == Gravity.RIGHT) {
        mPopup.setHorizontalOffset(mPopup.getHorizontalOffset() + (mAnchorView.getWidth() - mPopup.getWidth()));
    }
    // If vertical offset is defined as 0, then ListPopupWindow infers
    // it as the negative of the top padding of the background, in
    // order to anchor the content area. Since that is not the effect
    // we want, we'll force it to use only the explicitly defined
    // offset by explicitly setting it dynamically as well, and thus
    // forcing it to discard it's 'unset' flag.
    mPopup.setVerticalOffset(mPopup.getVerticalOffset());
    // Top/bottom padding will be applied on the background drawable,
    // as the ListView is both initialized and set up only after show()
    // is called on the ListPopupWindow. Left/right padding will be
    // set up on the list items from the adapter, to keep the correct
    // item boundaries for the selector.
    ShapeDrawable paddedDrawable = new ShapeDrawable();
    paddedDrawable.setAlpha(0);
    // Don't apply top padding if the first item is a header, to
    // comply with the design.
    paddedDrawable.setPadding(0, mAdapter.hasHeader() ? 0 : (mPopupPaddingTop - mPopupItemVerticalPadding), 0,
            mPopupPaddingBottom - mPopupItemVerticalPadding);
    Drawable background = mPopup.getBackground();
    mPopup.setBackgroundDrawable(background == null ? paddedDrawable
            : new LayerDrawable(new Drawable[] { background, paddedDrawable }));
    mPopup.setInputMethodMode(PopupWindow.INPUT_METHOD_NOT_NEEDED);
    mPopup.show();
    mPopup.getListView().setOnKeyListener(this);
    return true;
}

From source file:com.saulmm.cui.OrderDialogFragment.java

private Drawable createProductImageDrawable(Product product) {
    final ShapeDrawable background = new ShapeDrawable();
    background.setShape(new OvalShape());
    background.getPaint().setColor(ContextCompat.getColor(getContext(), product.color));

    final BitmapDrawable bitmapDrawable = new BitmapDrawable(getResources(),
            BitmapFactory.decodeResource(getResources(), product.image));

    final LayerDrawable layerDrawable = new LayerDrawable(new Drawable[] { background, bitmapDrawable });

    final int padding = (int) getResources().getDimension(R.dimen.spacing_huge);
    layerDrawable.setLayerInset(1, padding, padding, padding, padding);

    return layerDrawable;
}

From source file:ticwear.design.widget.FloatingActionButton.java

Drawable createShapeDrawable() {
    ShapeDrawable d = new ShapeDrawable();
    d.setShape(new OvalShape());
    d.getPaint().setColor(Color.WHITE);
    return d;
}

From source file:com.ksharkapps.musicnow.ui.activities.AudioPlayerActivity.java

public static Drawable createDrawable(Context context, int color) {

    ShapeDrawable shape = new ShapeDrawable();
    shape.getPaint().setStyle(Style.FILL);
    shape.setIntrinsicHeight(1);/*from www .  j a v  a  2 s.  c  om*/
    shape.getPaint().setColor(context.getResources().getColor(R.color.transparent));

    shape.getPaint().setStyle(Style.STROKE);
    shape.getPaint().setStrokeWidth(4);
    shape.getPaint().setColor(color);

    ShapeDrawable shapeD = new ShapeDrawable();
    shapeD.getPaint().setStyle(Style.FILL);
    shapeD.getPaint().setColor(color);
    ClipDrawable clipDrawable = new ClipDrawable(shapeD, Gravity.LEFT, ClipDrawable.HORIZONTAL);

    LayerDrawable layerDrawable = new LayerDrawable(new Drawable[] { clipDrawable, shape });
    return layerDrawable;
}

From source file:com.ksharkapps.musicnow.ui.activities.AudioPlayerActivity.java

private void updateSeekbartheme(int color) {

    /*/*  w  w  w  . jav a  2s  . c  o  m*/
     * ShapeDrawable pgDrawable = new ShapeDrawable(new RectShape());
     * 
     * // Sets the progressBar color pgDrawable.getPaint().setColor(color);
     * 
     * // Adds the drawable to your progressBar ClipDrawable progress = new
     * ClipDrawable(pgDrawable, Gravity.LEFT, ClipDrawable.HORIZONTAL);
     * mProgress.setProgressDrawable(progress);
     * mProgress.setBackgroundDrawable
     * (getResources().getDrawable(R.drawable.progress_shape));
     */

    ShapeDrawable shape = new ShapeDrawable();
    shape.getPaint().setStyle(Style.FILL);
    shape.getPaint().setColor(getResources().getColor(R.color.transparent_black));

    ShapeDrawable shapeD = new ShapeDrawable();
    shapeD.getPaint().setStyle(Style.FILL);
    shapeD.getPaint().setColor(getResources().getColor(R.color.white));
    ClipDrawable clipDrawable = new ClipDrawable(shapeD, Gravity.LEFT, ClipDrawable.HORIZONTAL);

    LayerDrawable layerDrawable = new LayerDrawable(new Drawable[] { shape, clipDrawable });
    mProgress.setProgressDrawable(layerDrawable);

}