Example usage for android.graphics.drawable ShapeDrawable getPaint

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

Introduction

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

Prototype

public Paint getPaint() 

Source Link

Document

Returns the Paint used to draw the shape.

Usage

From source file:de.mrapp.android.view.FloatingActionButton.java

/**
 * Creates and returns a drawable with a specific color, which can be used as the floating
 * action button's background.//from  w  ww  .j  a v a2s  . c om
 *
 * @param color
 *         The color of the background as an {@link Integer} value
 * @return The drawable, which has been created, as an instance of the class {@link Drawable}
 */
private Drawable createBackgroundDrawable(@ColorInt final int color) {
    OvalShape shape = new OvalShape();
    ShapeDrawable drawable = new ShapeDrawable(shape);
    drawable.getPaint().setColor(color);
    return drawable;
}

From source file:com.tiancaicc.springfloatingactionmenu.SpringFloatingActionMenu.java

private View generateRevealCircle() {
    int diameter = mFAB.getType() == FloatingActionButton.TYPE_NORMAL
            ? Utils.getDimension(mContext, R.dimen.fab_size_normal)
            : Utils.getDimension(mContext, R.dimen.fab_size_mini);
    View view = new View(mContext);
    OvalShape ovalShape = new OvalShape();
    ShapeDrawable shapeDrawable = new ShapeDrawable(ovalShape);
    shapeDrawable.getPaint().setColor(ContextCompat.getColor(mContext, mRevealColor));
    view.setBackgroundDrawable(shapeDrawable);
    LayoutParams lp = new LayoutParams(diameter, diameter);
    view.setLayoutParams(lp);//  www  .j  a  v  a2 s.  c o m

    // Make view clickable to avoid clicks on any view located behind the menu
    view.setClickable(true);

    // note it is invisible, but will be visible while  animating
    view.setVisibility(View.GONE);
    return view;
}

From source file:com.tiancaicc.springfloatingactionmenu.SpringFloatingActionMenu.java

private ArrayList<ImageButton> generateFollowCircles() {

    int diameter = mFAB.getType() == FloatingActionButton.TYPE_NORMAL
            ? Utils.getDimension(mContext, R.dimen.fab_size_normal) - 2
            : Utils.getDimension(mContext, R.dimen.fab_size_mini);

    ArrayList<ImageButton> circles = new ArrayList<>(mMenuItems.size());
    for (MenuItem item : mMenuItems) {
        ImageButton circle = new ImageButton(mContext);
        circle.setScaleType(ImageView.ScaleType.FIT_CENTER);
        OvalShape ovalShape = new OvalShape();
        ShapeDrawable shapeDrawable = new ShapeDrawable(ovalShape);
        shapeDrawable.getPaint().setColor(getResources().getColor(item.getBgColor()));
        circle.setBackgroundDrawable(shapeDrawable);

        if (TextUtils.isEmpty(item.getIconFilePath())) {
            circle.setImageResource(item.getIcon());
        } else {/*from  w  w  w . java  2s .  c o m*/
            circle.setImageURI(Uri.fromFile(new File(item.getIconFilePath())));
        }

        LayoutParams lp = new LayoutParams(diameter, diameter);
        circle.setLayoutParams(lp);
        circles.add(circle);
    }

    return circles;
}

From source file:com.google.maps.android.clustering.view.DefaultClusterRenderer.java

private LayerDrawable makeClusterBackground() {
    mColoredCircleBackground = new ShapeDrawable(new OvalShape());
    ShapeDrawable outline = new ShapeDrawable(new OvalShape());
    outline.getPaint().setColor(0x80ffffff); // Transparent white.
    LayerDrawable background = new LayerDrawable(new Drawable[] { outline, mColoredCircleBackground });
    int strokeWidth = (int) (mDensity * 3);
    background.setLayerInset(1, strokeWidth, strokeWidth, strokeWidth, strokeWidth);
    return background;
}

From source file:com.gm.grecyclerview.GmRecyclerView.java

private void addDividerItemDecoration(@ColorInt int color, int orientation, int paddingLeft, int paddingTop,
        int paddingRight, int paddingBottom) {
    DividerItemDecoration decor = new DividerItemDecoration(getContext(), orientation);
    if (color != 0) {
        ShapeDrawable shapeDrawable = new ShapeDrawable(new RectShape());
        shapeDrawable.setIntrinsicHeight(Utils.dpToPx(getContext(), 1));
        shapeDrawable.setIntrinsicWidth(Utils.dpToPx(getContext(), 1));
        shapeDrawable.getPaint().setColor(color);
        InsetDrawable insetDrawable = new InsetDrawable(shapeDrawable, paddingLeft, paddingTop, paddingRight,
                paddingBottom);/*from   ww  w  .  j  a  v  a 2 s.  c  o  m*/
        decor.setDrawable(insetDrawable);
    }
    decor.setShowLastDivider(showLastDivider);
    addItemDecoration(decor);
}

From source file:info.tellmetime.TellmetimeActivity.java

/**
 * Generates rainbow gradient and sets it as #mSeekBarHighlight progress drawable.
 *//*from  w ww. j a va2 s . co  m*/
private void drawRainbow() {
    float gradientWidth = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 256,
            getResources().getDisplayMetrics());
    int[] colors = { 0xFFFFFFFF, 0xFFFF0000, 0xFFFFFF00, 0xFF00FF00, 0xFF00FFFF, 0xFF0000FF, 0xFFFF00FF,
            0xFF888888, 0xFF000000 };
    LinearGradient rainbowGradient = new LinearGradient(0f, 0f, gradientWidth, 0f, colors, null,
            Shader.TileMode.CLAMP);
    float r = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 2, getResources().getDisplayMetrics());
    ShapeDrawable shape = new ShapeDrawable(
            new RoundRectShape(new float[] { r, r, r, r, r, r, r, r }, null, null));
    shape.getPaint().setShader(rainbowGradient);
    mSeekBarHighlight.setProgressDrawable(shape);

    // Generate bitmap with the same rainbow gradient and cache it for later use to retrieve color at given position.
    Bitmap bitmap = Bitmap.createBitmap((int) gradientWidth, 1, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setStyle(Paint.Style.FILL);
    paint.setShader(rainbowGradient);
    canvas.drawRect(0, 0, gradientWidth, 1, paint);
    mRainbow = bitmap;

    // Set max value to gradient's width and restore relative position.
    mSeekBarHighlight.setMax((int) (gradientWidth - 1));
    mSeekBarHighlight.setProgress((int) ((gradientWidth - 1) * mHighlightPosition));
}

From source file:com.vuze.android.remote.activity.LoginActivity.java

@SuppressWarnings("deprecation")
private void setBackgroundGradient() {

    ViewGroup mainLayout = (ViewGroup) findViewById(R.id.main_loginlayout);
    assert mainLayout != null;
    int h = mainLayout.getHeight();
    int w = mainLayout.getWidth();
    View viewCenterOn = findViewById(R.id.login_frog_logo);
    assert viewCenterOn != null;

    RectShape shape = new RectShape();
    ShapeDrawable mDrawable = new ShapeDrawable(shape);
    int color1 = AndroidUtilsUI.getStyleColor(this, R.attr.login_grad_color_1);
    int color2 = AndroidUtilsUI.getStyleColor(this, R.attr.login_grad_color_2);

    RadialGradient shader;/*from w  w  w  . j  a  va  2  s  .  c o  m*/
    if (w > h) {
        int left = viewCenterOn.getLeft() + (viewCenterOn.getWidth() / 2);
        int top = viewCenterOn.getTop() + (viewCenterOn.getHeight() / 2);
        int remaining = w - left;
        shader = new RadialGradient(left, top, remaining, new int[] { color1, color2 }, new float[] { 0, 1.0f },
                Shader.TileMode.CLAMP);
    } else {
        int top = viewCenterOn.getTop() + (viewCenterOn.getHeight() / 2);
        shader = new RadialGradient(w / 2, top, w * 2 / 3, color1, color2, Shader.TileMode.CLAMP);
    }
    mDrawable.setBounds(0, 0, w, h);
    mDrawable.getPaint().setShader(shader);
    mDrawable.getPaint().setDither(true);
    mDrawable.getPaint().setAntiAlias(true);
    mDrawable.setDither(true);

    mainLayout.setDrawingCacheEnabled(true);
    mainLayout.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH);
    mainLayout.setAnimationCacheEnabled(false);

    mainLayout.setBackgroundDrawable(mDrawable);
}

From source file:de.uni_weimar.mheinz.androidtouchscope.display.ScopeView.java

private void initDrawable(ShapeDrawable drawable, Path path, int color, int width, int height) {
    path.moveTo(0, 0);/*  w  ww.j a  v  a 2s . c  om*/
    drawable.setShape(new PathShape(path, width, height));
    drawable.getPaint().setStyle(Paint.Style.STROKE);
    drawable.getPaint().setColor(color);
    drawable.setBounds(0, 0, width, height);

    setLayerType(LAYER_TYPE_SOFTWARE, drawable.getPaint());
}

From source file:io.puzzlebox.jigsaw.ui.EEGFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    v = inflater.inflate(R.layout.fragment_eeg, container, false);

    //      requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
    //      setContentView(R.layout.main);
    //      getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title);

    progressBarAttention = (ProgressBar) v.findViewById(R.id.progressBarAttention);
    final float[] roundedCorners = new float[] { 5, 5, 5, 5, 5, 5, 5, 5 };
    ShapeDrawable progressBarAttentionDrawable = new ShapeDrawable(
            new RoundRectShape(roundedCorners, null, null));
    String progressBarAttentionColor = "#FF0000";
    progressBarAttentionDrawable.getPaint().setColor(Color.parseColor(progressBarAttentionColor));
    ClipDrawable progressAttention = new ClipDrawable(progressBarAttentionDrawable, Gravity.LEFT,
            ClipDrawable.HORIZONTAL);/*from w w w . j a va 2 s. c o  m*/
    progressBarAttention.setProgressDrawable(progressAttention);
    progressBarAttention
            .setBackgroundDrawable(getResources().getDrawable(android.R.drawable.progress_horizontal));

    progressBarMeditation = (ProgressBar) v.findViewById(R.id.progressBarMeditation);
    ShapeDrawable progressBarMeditationDrawable = new ShapeDrawable(
            new RoundRectShape(roundedCorners, null, null));
    String progressBarMeditationColor = "#0000FF";
    progressBarMeditationDrawable.getPaint().setColor(Color.parseColor(progressBarMeditationColor));
    ClipDrawable progressMeditation = new ClipDrawable(progressBarMeditationDrawable, Gravity.LEFT,
            ClipDrawable.HORIZONTAL);
    progressBarMeditation.setProgressDrawable(progressMeditation);
    progressBarMeditation
            .setBackgroundDrawable(getResources().getDrawable(android.R.drawable.progress_horizontal));

    progressBarSignal = (ProgressBar) v.findViewById(R.id.progressBarSignal);
    ShapeDrawable progressBarSignalDrawable = new ShapeDrawable(new RoundRectShape(roundedCorners, null, null));
    String progressBarSignalColor = "#00FF00";
    progressBarSignalDrawable.getPaint().setColor(Color.parseColor(progressBarSignalColor));
    ClipDrawable progressSignal = new ClipDrawable(progressBarSignalDrawable, Gravity.LEFT,
            ClipDrawable.HORIZONTAL);
    progressBarSignal.setProgressDrawable(progressSignal);
    progressBarSignal.setBackgroundDrawable(getResources().getDrawable(android.R.drawable.progress_horizontal));
    //      progressBarSignal.setProgress(tgSignal);

    progressBarPower = (ProgressBar) v.findViewById(R.id.progressBarPower);
    ShapeDrawable progressBarPowerDrawable = new ShapeDrawable(new RoundRectShape(roundedCorners, null, null));
    String progressBarPowerColor = "#FFFF00";
    progressBarPowerDrawable.getPaint().setColor(Color.parseColor(progressBarPowerColor));
    ClipDrawable progressPower = new ClipDrawable(progressBarPowerDrawable, Gravity.LEFT,
            ClipDrawable.HORIZONTAL);
    progressBarPower.setProgressDrawable(progressPower);
    progressBarPower.setBackgroundDrawable(getResources().getDrawable(android.R.drawable.progress_horizontal));

    progressBarBlink = (ProgressBar) v.findViewById(R.id.progressBarBlink);
    //      ShapeDrawable progressBarRangeDrawable = new ShapeDrawable(new RoundRectShape(roundedCorners, null,null));
    ShapeDrawable progressBarRangeDrawable = new ShapeDrawable();
    //      String progressBarRangeColor = "#FF00FF";
    //      String progressBarRangeColor = "#990099";
    String progressBarRangeColor = "#BBBBBB";
    progressBarRangeDrawable.getPaint().setColor(Color.parseColor(progressBarRangeColor));
    ClipDrawable progressRange = new ClipDrawable(progressBarRangeDrawable, Gravity.LEFT,
            ClipDrawable.HORIZONTAL);
    progressBarBlink.setProgressDrawable(progressRange);
    progressBarBlink.setBackgroundDrawable(getResources().getDrawable(android.R.drawable.progress_horizontal));

    progressBarBlink.setMax(ThinkGearService.blinkRangeMax);

    // setup the Raw EEG History plot
    eegRawHistoryPlot = (XYPlot) v.findViewById(R.id.eegRawHistoryPlot);
    //      eegRawHistorySeries = new SimpleXYSeries("Raw EEG");
    eegRawHistorySeries = new SimpleXYSeries("");

    // Use index value as xVal, instead of explicit, user provided xVals.
    //      eegRawHistorySeries.useImplicitXVals();

    // Setup the boundary mode, boundary values only applicable in FIXED mode.

    if (eegRawHistoryPlot != null) {

        //         eegRawHistoryPlot.setDomainBoundaries(0, EEG_RAW_HISTORY_SIZE, BoundaryMode.FIXED);
        //         eegRawHistoryPlot.setDomainBoundaries(0, ThinkGearService.EEG_RAW_HISTORY_SIZE, BoundaryMode.FIXED);
        //      eegRawHistoryPlot.setDomainBoundaries(0, EEG_RAW_HISTORY_SIZE, BoundaryMode.AUTO);
        //      eegRawHistoryPlot.setRangeBoundaries(-32767, 32767, BoundaryMode.FIXED);
        //      eegRawHistoryPlot.setRangeBoundaries(-32767, 32767, BoundaryMode.AUTO);
        //         eegRawHistoryPlot.setRangeBoundaries(-256, 256, BoundaryMode.GROW);
        eegRawHistoryPlot.setDomainBoundaries(0, ThinkGearService.EEG_RAW_FREQUENCY, BoundaryMode.FIXED);
        eegRawHistoryPlot.setRangeBoundaries(0, 1, BoundaryMode.GROW);

        eegRawHistoryPlot.addSeries(eegRawHistorySeries,
                new LineAndPointFormatter(Color.rgb(200, 100, 100), Color.BLACK, null, null));

        // Thin out domain and range tick values so they don't overlap
        eegRawHistoryPlot.setDomainStepValue(5);
        eegRawHistoryPlot.setTicksPerRangeLabel(3);

        //      eegRawHistoryPlot.setRangeLabel("Amplitude");

        // Sets the dimensions of the widget to exactly contain the text contents
        eegRawHistoryPlot.getDomainLabelWidget().pack();
        eegRawHistoryPlot.getRangeLabelWidget().pack();

        // Only display whole numbers in labels
        eegRawHistoryPlot.getGraphWidget().setDomainValueFormat(new DecimalFormat("0"));
        eegRawHistoryPlot.getGraphWidget().setRangeValueFormat(new DecimalFormat("0"));

        // Hide domain and range labels
        eegRawHistoryPlot.getGraphWidget().setDomainLabelWidth(0);
        eegRawHistoryPlot.getGraphWidget().setRangeLabelWidth(0);

        // Hide legend
        eegRawHistoryPlot.getLegendWidget().setVisible(false);

        // setGridPadding(float left, float top, float right, float bottom)
        eegRawHistoryPlot.getGraphWidget().setGridPadding(0, 0, 0, 0);

        //      eegRawHistoryPlot.getGraphWidget().setDrawMarkersEnabled(false);

        //      final PlotStatistics histStats = new PlotStatistics(1000, false);
        //      eegRawHistoryPlot.addListener(histStats);

    }

    seekBarAttention = (SeekBar) v.findViewById(R.id.seekBarAttention);
    seekBarAttention.setOnSeekBarChangeListener(this);
    seekBarMeditation = (SeekBar) v.findViewById(R.id.seekBarMeditation);
    seekBarMeditation.setOnSeekBarChangeListener(this);

    //      spinnerEEG = (Spinner) v.findViewById(R.id.spinnerEEG);

    String[] items = new String[] { "NeuroSky MindWave Mobile", "Emotiv Insight", "InteraXon Muse" };

    //      if (ThinkGearService.eegConnected || ThinkGearService.eegConnecting)
    //         items = new String[] {"NeuroSky MindWave Mobile", "Emotiv Insight", "InteraXon Muse"};
    if (MuseService.eegConnected || MuseService.eegConnecting)
        items = new String[] { "InteraXon Muse", "Emotiv Insight", "NeuroSky MindWave Mobile" };

    spinnerEEG = (Spinner) v.findViewById(R.id.spinnerEEG);

    //      ArrayAdapter<String> adapter = new ArrayAdapter<>(getActivity().getApplicationContext(),
    //              android.R.layout.simple_spinner_item, items);

    ArrayAdapter<String> adapter = new ArrayAdapter<>(getActivity().getApplicationContext(),
            R.layout.spinner_item, items);

    //      ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.spinner_item,list);

    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinnerEEG.setAdapter(adapter);

    if (android.os.Build.VERSION.SDK_INT >= 16)
        spinnerEEG.setPopupBackgroundDrawable(new ColorDrawable(Color.DKGRAY));

    //      imageViewStatus = (ImageView) v.findViewById(R.id.imageViewStatus);

    textViewSessionTime = (TextView) v.findViewById(R.id.textViewSessionTime);

    Button connectEEG = (Button) v.findViewById(R.id.buttonConnectEEG);
    connectEEG.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            connectHeadset();
        }
    });

    if (ThinkGearService.eegConnected) {
        connectEEG.setText("Disconnect EEG");
        spinnerEEG.setEnabled(false);
    }
    if (MuseService.eegConnected) {
        connectEEG.setText("Disconnect EEG");
        //         spinnerEEG.setSelection(spinnerEEG.getPosition(DEFAULT_CURRENCY_TYPE));
        //         spinnerEEG.setSelection(spinnerEEG.getAdapter(). .getPosition(DEFAULT_CURRENCY_TYPE));
        spinnerEEG.setEnabled(false);
    }

    //      Button saveSession = (Button) v.findViewById(R.id.buttonSaveSession);
    //      saveSession.setOnClickListener(new View.OnClickListener() {
    //         @Override
    //         public void onClick(View v) {
    //
    //            Intent intent = new Intent(getActivity(), CreateSessionFileInGoogleDrive.class);
    //            startActivity(intent);
    //
    ////            Toast.makeText((getActivity()),
    ////                    "Session data saved to Google Drive",
    ////                    Toast.LENGTH_SHORT).show();
    //         }
    //      });

    //      Button exportToCSV = (Button) v.findViewById(R.id.buttonExportCSV);
    //      exportToCSV.setOnClickListener(new View.OnClickListener() {
    //         @Override
    //         public void onClick(View v) {
    //            Log.d(TAG, "SessionSingleton.getInstance().exportDataToCSV");
    ////            String path = SessionSingleton.getInstance().getTimestampPS4();
    //            SessionSingleton.getInstance().exportDataToCSV(null, null);
    //
    //            Toast.makeText((getActivity()),
    //                    "Session data exported to:\n" + SessionSingleton.getInstance().getTimestampPS4() + ".csv",
    //                    Toast.LENGTH_LONG).show();
    //         }
    //      });

    Button resetSession = (Button) v.findViewById(R.id.buttonResetSession);
    resetSession.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            resetSession();

        }
    });

    intentThinkGear = new Intent(getActivity(), ThinkGearService.class);
    intentMuse = new Intent(getActivity(), MuseService.class);

    /**
     * Update settings according to default UI
     */

    updateScreenLayout();

    updatePowerThresholds();
    updatePower();

    return v;

}

From source file:com.actionbarsherlock.internal.widget.IcsProgressBar.java

/**
 * Converts a drawable to a tiled version of itself. It will recursively
 * traverse layer and state list drawables.
 *//*from w  w  w. j a v a 2 s .c  o m*/
private Drawable tileify(Drawable drawable, boolean clip) {

    if (drawable instanceof LayerDrawable) {
        LayerDrawable background = (LayerDrawable) drawable;
        final int N = background.getNumberOfLayers();
        Drawable[] outDrawables = new Drawable[N];

        for (int i = 0; i < N; i++) {
            int id = background.getId(i);
            outDrawables[i] = tileify(background.getDrawable(i),
                    (id == android.R.id.progress || id == android.R.id.secondaryProgress));
        }

        LayerDrawable newBg = new LayerDrawable(outDrawables);

        for (int i = 0; i < N; i++) {
            newBg.setId(i, background.getId(i));
        }

        return newBg;

    } /* else if (drawable instanceof StateListDrawable) {
      StateListDrawable in = (StateListDrawable) drawable;
      StateListDrawable out = new StateListDrawable();
      int numStates = in.getStateCount();
      for (int i = 0; i < numStates; i++) {
          out.addState(in.getStateSet(i), tileify(in.getStateDrawable(i), clip));
      }
      return out;
              
      }*/ else if (drawable instanceof BitmapDrawable) {
        final Bitmap tileBitmap = ((BitmapDrawable) drawable).getBitmap();
        if (mSampleTile == null) {
            mSampleTile = tileBitmap;
        }

        final ShapeDrawable shapeDrawable = new ShapeDrawable(getDrawableShape());

        final BitmapShader bitmapShader = new BitmapShader(tileBitmap, Shader.TileMode.REPEAT,
                Shader.TileMode.CLAMP);
        shapeDrawable.getPaint().setShader(bitmapShader);

        return (clip) ? new ClipDrawable(shapeDrawable, Gravity.LEFT, ClipDrawable.HORIZONTAL) : shapeDrawable;
    }

    return drawable;
}