Example usage for android.graphics.drawable.shapes RoundRectShape RoundRectShape

List of usage examples for android.graphics.drawable.shapes RoundRectShape RoundRectShape

Introduction

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

Prototype

public RoundRectShape(@Nullable float[] outerRadii, @Nullable RectF inset, @Nullable float[] innerRadii) 

Source Link

Document

RoundRectShape constructor.

Usage

From source file:Main.java

public static ShapeDrawable getShapeDrawable(int color, int radius) {
    RoundRectShape roundRectShape = new RoundRectShape(
            new float[] { radius, radius, radius, radius, radius, radius, radius, radius }, null, null);
    ShapeDrawable shapeDrawable = new ShapeDrawable(roundRectShape);
    shapeDrawable.getPaint().setColor(color);
    return shapeDrawable;
}

From source file:Main.java

@NonNull
private static Drawable getRippleMask(int color) {
    float[] outerRadii = new float[8];
    // 3 is radius of final ripple,
    // instead of 3 you can give required final radius
    Arrays.fill(outerRadii, 3);//from w  w  w  . j  ava 2s . c  o m

    RoundRectShape r = new RoundRectShape(outerRadii, null, null);
    ShapeDrawable shapeDrawable = new ShapeDrawable(r);
    shapeDrawable.getPaint().setColor(color);

    return shapeDrawable;
}

From source file:Main.java

public static synchronized ShapeDrawable getRoundedRect(final int color) {
    if (color == Color.TRANSPARENT) {
        return null;
    }/*from   www.ja v  a 2 s .c  o  m*/
    int r = 3;
    float[] outerR = new float[] { r, r, r, r, r, r, r, r };
    RoundRectShape rr = new RoundRectShape(outerR, null, null);

    final ShapeDrawable d = new ShapeDrawable(rr);
    d.getPaint().setColor(color);

    return d;
}

From source file:com.ashlikun.badgeview.BadgeView.java

public void setBackground(int radius, int badgeColor) {

    if (radius <= 0 || (this.radius == radius && bvColor == badgeColor)) {
        return;//from  w w w .  j a  va2  s  .c  o m
    }
    bvColor = badgeColor;
    this.radius = radius;
    float[] radiusArray = new float[] { radius, radius, radius, radius, radius, radius, radius, radius };
    RoundRectShape roundRect = new RoundRectShape(radiusArray, null, null);
    ShapeDrawable bgDrawable = new ShapeDrawable(roundRect);
    bgDrawable.getPaint().setColor(badgeColor);
    setBackgroundDrawable(bgDrawable);
}

From source file:android.support.v7.internal.widget.TintRatingBar.java

private Shape getDrawableShape() {
    final float[] roundedCorners = new float[] { 5, 5, 5, 5, 5, 5, 5, 5 };
    return new RoundRectShape(roundedCorners, null, null);
}

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  ava  2s  .  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.flexible.flexibleadapter.utils.DrawableUtils.java

private static Drawable getRippleMask(@ColorInt int color) {
    float[] outerRadii = new float[8];
    // 3 is the radius of final ripple, instead of 3 we can give required final radius
    Arrays.fill(outerRadii, 3);//from w w  w .j a v  a  2  s .  co m
    RoundRectShape r = new RoundRectShape(outerRadii, null, null);
    ShapeDrawable shapeDrawable = new ShapeDrawable(r);
    shapeDrawable.getPaint().setColor(color);
    return shapeDrawable;
}

From source file:io.puzzlebox.orbit.ui.OrbitFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    // Inflate the layout for this fragment
    View v = inflater.inflate(R.layout.fragment_orbit, container, false);

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

    buttonConnectOrbit = (Button) v.findViewById(R.id.buttonConnectOrbit);
    buttonConnectOrbit.setOnClickListener(new View.OnClickListener() {
        @Override//from   w ww  . j  a v a2 s. co  m
        public void onClick(View v) {
            setOrbitActivate();
        }
    });

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

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

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

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

    textViewLabelScores = (TextView) v.findViewById(R.id.textViewLabelScores);
    textViewLabelScore = (TextView) v.findViewById(R.id.textViewLabelScore);
    textViewLabelLastScore = (TextView) v.findViewById(R.id.textViewLabelLastScore);
    textViewLabelHighScore = (TextView) v.findViewById(R.id.textViewLabelHighScore);

    viewSpaceScore = (View) v.findViewById(R.id.viewSpaceScore);
    viewSpaceScoreLast = (View) v.findViewById(R.id.viewSpaceScoreLast);
    viewSpaceScoreHigh = (View) v.findViewById(R.id.viewSpaceScoreHigh);

    textViewScore = (TextView) v.findViewById(R.id.textViewScore);
    textViewLastScore = (TextView) v.findViewById(R.id.textViewLastScore);
    textViewHighScore = (TextView) v.findViewById(R.id.textViewHighScore);

    // Hide the "Scores" label by default
    textViewLabelScores.setVisibility(View.GONE);
    viewSpaceScore.setVisibility(View.GONE);

    /**
     * AudioHandler
     */

    if (!OrbitSingleton.getInstance().audioHandler.isAlive()) {

        /**
         * Prepare audio stream
         */

        maximizeAudioVolume(); // Automatically set media volume to maximum

        /** Set the hardware buttons to control the audio output */
        getActivity().setVolumeControlStream(AudioManager.STREAM_MUSIC);

        /** Preload the flight control WAV file into memory */
        OrbitSingleton.getInstance().soundPool = new SoundPool(10, AudioManager.STREAM_MUSIC, 0);
        OrbitSingleton.getInstance().soundPool
                .setOnLoadCompleteListener(new SoundPool.OnLoadCompleteListener() {
                    public void onLoadComplete(SoundPool soundPool, int sampleId, int status) {
                        OrbitSingleton.getInstance().loaded = true;
                    }
                });
        OrbitSingleton.getInstance().soundID = OrbitSingleton.getInstance().soundPool
                .load(getActivity().getApplicationContext(), OrbitSingleton.getInstance().audioFile, 1);

        OrbitSingleton.getInstance().audioHandler.start();

    }

    if (OrbitSingleton.getInstance().flightActive)
        buttonTestFlight.setText(getResources().getString(R.string.button_stop_test));

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

    updateScreenLayout();

    updatePowerThresholds();
    //      updatePower();

    return v;

}

From source file:io.puzzlebox.bloom.ui.BloomFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Inflate the layout for this fragment

    View v = inflater.inflate(R.layout.fragment_bloom, 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 av a 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));

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

    //      progressBarBloom = (ProgressBar) v.findViewById(R.id.progressBarBloom);
    //      ShapeDrawable progressBarBloomDrawable = new ShapeDrawable(new RoundRectShape(roundedCorners, null,null));
    //      String progressBarBloomColor = "#7F0000";
    //      progressBarBloomDrawable.getPaint().setColor(Color.parseColor(progressBarBloomColor));
    //      ClipDrawable progressBloom = new ClipDrawable(progressBarBloomDrawable, Gravity.LEFT, ClipDrawable.HORIZONTAL);
    //      progressBarBloom.setProgressDrawable(progressBloom);
    //      progressBarBloom.setBackgroundDrawable(getResources().getDrawable(android.R.drawable.progress_horizontal));

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

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

    servoSeekBar = (SeekBar) v.findViewById(R.id.ServoSeekBar);
    servoSeekBar.setEnabled(false);
    //      servoSeekBar.setMax(180);
    servoSeekBar.setMax(100);
    servoSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {

        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {

        }

        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {

            byte[] buf = new byte[] { (byte) 0x03, (byte) 0x00, (byte) 0x00 };

            buf[1] = (byte) servoSeekBar.getProgress();

            BloomSingleton.getInstance().characteristicTx.setValue(buf);
            BloomSingleton.getInstance().mBluetoothLeService
                    .writeCharacteristic(BloomSingleton.getInstance().characteristicTx);
        }
    });

    //      rssiValue = (TextView) v.findViewById(R.id.rssiValue);

    connectBloom = (Button) v.findViewById(R.id.connectBloom);

    connectBloom.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            try {
                if (!BloomSingleton.getInstance().scanFlag) {
                    scanLeDevice();

                    Timer mTimer = new Timer();
                    mTimer.schedule(new TimerTask() {

                        @Override
                        public void run() {
                            if ((BloomSingleton.getInstance().mDevice != null)
                                    && (BloomSingleton.getInstance().mDevice.getAddress() != null)
                                    && (BloomSingleton.getInstance().mBluetoothLeService != null)) {
                                BloomSingleton
                                        .getInstance().mDeviceAddress = BloomSingleton.getInstance().mDevice
                                                .getAddress();
                                if (BloomSingleton.getInstance().mDeviceAddress != null)
                                    BloomSingleton.getInstance().mBluetoothLeService
                                            .connect(BloomSingleton.getInstance().mDeviceAddress);
                                else {
                                    Toast toast = Toast.makeText(getActivity(),
                                            "Error connecting to Puzzlebox Bloom", Toast.LENGTH_SHORT);
                                    toast.setGravity(0, 0, Gravity.CENTER | Gravity.BOTTOM);
                                    toast.show();
                                }
                                BloomSingleton.getInstance().scanFlag = true;
                            } else {
                                getActivity().runOnUiThread(new Runnable() {
                                    public void run() {
                                        Toast toast = Toast.makeText(getActivity(),
                                                "Error connecting to Puzzlebox Bloom", Toast.LENGTH_SHORT);
                                        toast.setGravity(0, 0, Gravity.CENTER | Gravity.BOTTOM);
                                        toast.show();
                                    }
                                });
                            }
                        }
                    }, BloomSingleton.getInstance().SCAN_PERIOD);
                }
            } catch (Exception e) {
                Log.e(TAG, "Exception connecting to Bloom: " + e);
                Toast toast = Toast.makeText(getActivity(), "Exception connecting to Puzzlebox Bloom",
                        Toast.LENGTH_SHORT);
                toast.setGravity(0, 0, Gravity.CENTER | Gravity.BOTTOM);
                toast.show();
            }

            System.out.println(BloomSingleton.getInstance().connState);
            //            Log.e(TAG, connState);
            //            if (connState == false) {
            if (!BloomSingleton.getInstance().connState
                    && BloomSingleton.getInstance().mDeviceAddress != null) {
                BloomSingleton.getInstance().mBluetoothLeService
                        .connect(BloomSingleton.getInstance().mDeviceAddress);
            } else {
                if (BloomSingleton.getInstance().mBluetoothLeService != null) {
                    setBloomRGBOff();
                    BloomSingleton.getInstance().mBluetoothLeService.disconnect();
                    BloomSingleton.getInstance().mBluetoothLeService.close();
                    setButtonDisable();
                }
            }
        }
    });

    //      Button buttonOpen = (Button) v.findViewById(R.id.buttonOpen);
    //      buttonOpen.setOnClickListener(new View.OnClickListener() {
    //         @Override
    //         public void onClick(View v) {
    //            byte[] buf = new byte[] { (byte) 0x01, (byte) 0x00, (byte) 0x00 };
    //            BloomSingleton.getInstance().characteristicTx.setValue(buf);
    //            BloomSingleton.getInstance().mBluetoothLeService.writeCharacteristic(BloomSingleton.getInstance().characteristicTx);
    //         }
    //      });
    //      buttonOpen.setVisibility(View.GONE);
    //
    //      Button buttonClose = (Button) v.findViewById(R.id.buttonClose);
    //      buttonClose.setOnClickListener(new View.OnClickListener() {
    //         @Override
    //         public void onClick(View v) {
    //            byte[] buf = new byte[] { (byte) 0x00, (byte) 0x00, (byte) 0x00 };
    //            BloomSingleton.getInstance().characteristicTx.setValue(buf);
    //            BloomSingleton.getInstance().mBluetoothLeService.writeCharacteristic(BloomSingleton.getInstance().characteristicTx);
    //         }
    //      });
    //      buttonClose.setVisibility(View.GONE);

    //      buttonDemo = (Button) v.findViewById(R.id.buttonDemo);
    //      buttonDemo.setOnClickListener(new View.OnClickListener() {
    //         @Override
    //         public void onClick(View v) {
    //            byte[] buf;
    ////            if (! BloomSingleton.getInstance().demoActive) {
    //            BloomSingleton.getInstance().demoActive = true;
    //
    //            // bloomOpen()
    ////            buf = new byte[]{(byte) 0x01, (byte) 0x00, (byte) 0x00};
    ////            BloomSingleton.getInstance().characteristicTx.setValue(buf);
    ////            BloomSingleton.getInstance().mBluetoothLeService.writeCharacteristic(BloomSingleton.getInstance().characteristicTx);
    //
    //            // loopRGB()
    //            buf = new byte[]{(byte) 0x06, (byte) 0x00, (byte) 0x00};
    //            BloomSingleton.getInstance().characteristicTx.setValue(buf);
    //            BloomSingleton.getInstance().mBluetoothLeService.writeCharacteristic(BloomSingleton.getInstance().characteristicTx);
    //
    //            // Set Red to 0
    //            buf = new byte[]{(byte) 0x0A, (byte) 0x00, (byte) 0x00}; // R = 0
    //            BloomSingleton.getInstance().characteristicTx.setValue(buf);
    //            BloomSingleton.getInstance().mBluetoothLeService.writeCharacteristic(BloomSingleton.getInstance().characteristicTx);
    //
    //            // bloomClose()
    ////            buf = new byte[]{(byte) 0x00, (byte) 0x00, (byte) 0x00};
    ////            BloomSingleton.getInstance().characteristicTx.setValue(buf);
    ////            BloomSingleton.getInstance().mBluetoothLeService.writeCharacteristic(BloomSingleton.getInstance().characteristicTx);
    //
    //
    ////            } else {
    ////               BloomSingleton.getInstance().demoActive = false;
    //////               buf = new byte[]{(byte) 0x00, (byte) 0x00, (byte) 0x00};
    //////               BloomSingleton.getInstance().characteristicTx.setValue(buf);
    //////               BloomSingleton.getInstance().mBluetoothLeService.writeCharacteristic(BloomSingleton.getInstance().characteristicTx);
    ////               buf = new byte[]{(byte) 0x0A, (byte) 0x00, (byte) 0x00}; // R = 0
    ////               BloomSingleton.getInstance().characteristicTx.setValue(buf);
    ////               BloomSingleton.getInstance().mBluetoothLeService.writeCharacteristic(BloomSingleton.getInstance().characteristicTx);
    //////               buf = new byte[]{(byte) 0x0A, (byte) 0x01, (byte) 0x00}; // G = 0
    //////               BloomSingleton.getInstance().characteristicTx.setValue(buf);
    //////               BloomSingleton.getInstance().mBluetoothLeService.writeCharacteristic(BloomSingleton.getInstance().characteristicTx);
    //////               buf = new byte[]{(byte) 0x0A, (byte) 0x02, (byte) 0x00}; // B = 0
    //////               BloomSingleton.getInstance().characteristicTx.setValue(buf);
    //////               BloomSingleton.getInstance().mBluetoothLeService.writeCharacteristic(BloomSingleton.getInstance().characteristicTx);
    ////            }
    //         }
    //      });

    if (!getActivity().getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) {
        Toast.makeText(getActivity(), "Bluetooth LE not supported", Toast.LENGTH_SHORT).show();
        getActivity().finish();
    }

    final BluetoothManager mBluetoothManager = (BluetoothManager) getActivity()
            .getSystemService(Context.BLUETOOTH_SERVICE);
    BloomSingleton.getInstance().mBluetoothAdapter = mBluetoothManager.getAdapter();
    if (BloomSingleton.getInstance().mBluetoothAdapter == null) {
        Toast.makeText(getActivity(), "Bluetooth LE not supported", Toast.LENGTH_SHORT).show();
        getActivity().finish();
        return v;
    }

    Intent gattServiceIntent = new Intent(getActivity(), RBLService.class);
    //      bindService(gattServiceIntent, mServiceConnection, BIND_AUTO_CREATE);
    getActivity().bindService(gattServiceIntent, mServiceConnection, getActivity().BIND_AUTO_CREATE);

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

    updateScreenLayout();

    //      updatePowerThresholds();
    //      updatePower();

    if (BloomSingleton.getInstance().connState)
        setButtonEnable();

    return v;

}

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

private static Drawable createButtonShape(Context context, int color) {
    // Translation of Lollipop's xml button-bg definition to Java
    int paddingH = context.getResources().getDimensionPixelSize(R.dimen.button_padding_horizontal_material);
    int paddingV = context.getResources().getDimensionPixelSize(R.dimen.button_padding_vertical_material);
    int insetH = context.getResources().getDimensionPixelSize(R.dimen.button_inset_horizontal_material);
    int insetV = context.getResources().getDimensionPixelSize(R.dimen.button_inset_vertical_material);

    float[] outerRadii = new float[8];
    Arrays.fill(outerRadii, CORNER_RADIUS);

    RoundRectShape r = new RoundRectShape(outerRadii, null, null);

    ShapeDrawable shapeDrawable = new ShapeDrawable(r);
    shapeDrawable.getPaint().setColor(color);
    shapeDrawable.setPadding(paddingH, paddingV, paddingH, paddingV);

    return new InsetDrawable(shapeDrawable, insetH, insetV, insetH, insetV);
}