Example usage for android.graphics.drawable ClipDrawable ClipDrawable

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

Introduction

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

Prototype

public ClipDrawable(Drawable drawable, int gravity, int orientation) 

Source Link

Document

Creates a new clip drawable with the specified gravity and orientation.

Usage

From source file:Main.java

@SuppressWarnings("deprecation")
public static void clipDrawable(final View image, Drawable drawable, boolean isActivated) {
    if (drawable == null) {
        return;//from   www  .  j  a v  a2s . c om
    }
    if (isActivated) {
        final ClipDrawable scaleDrawable = new ClipDrawable(drawable, Gravity.CENTER,
                ClipDrawable.HORIZONTAL | ClipDrawable.VERTICAL);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            image.setBackground(scaleDrawable);
        } else {
            image.setBackgroundDrawable(scaleDrawable);
        }
        image.setBackgroundDrawable(scaleDrawable);
        ValueAnimator animator = ValueAnimator.ofInt(0, 10000);
        animator.setDuration(200);
        animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                scaleDrawable.setLevel((Integer) animation.getAnimatedValue());
            }
        });
        animator.start();
    } else {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            image.setBackground(null);
        } else {
            image.setBackgroundDrawable(null);
        }
    }
}

From source file:org.chromium.chrome.browser.widget.ClipDrawableProgressBar.java

/**
 * Constructor for inflating from XML.//w  w  w  . ja va  2s  . co  m
 */
public ClipDrawableProgressBar(Context context, AttributeSet attrs) {
    super(context, attrs);
    mDesiredVisibility = getVisibility();

    assert attrs != null;
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ClipDrawableProgressBar, 0, 0);

    int foregroundColor = a.getColor(R.styleable.ClipDrawableProgressBar_progressBarColor, Color.TRANSPARENT);
    mBackgroundColor = a.getColor(R.styleable.ClipDrawableProgressBar_backgroundColor, Color.TRANSPARENT);
    assert foregroundColor != Color.TRANSPARENT;
    assert Color.alpha(
            foregroundColor) == 255 : "Currently ClipDrawableProgressBar only supports opaque progress bar color.";

    a.recycle();

    mForegroundDrawable = new ColorDrawable(foregroundColor);
    setImageDrawable(new ClipDrawable(mForegroundDrawable, Gravity.START, ClipDrawable.HORIZONTAL));
    setBackgroundColor(mBackgroundColor);
}

From source file:android.support.v7.widget.AppCompatProgressBarHelper.java

/**
 * Converts a drawable to a tiled version of itself. It will recursively
 * traverse layer and state list drawables.
 *//*ww  w. j  av a2 s . co  m*/
private Drawable tileify(Drawable drawable, boolean clip) {
    if (drawable instanceof DrawableWrapper) {
        Drawable inner = ((DrawableWrapper) drawable).getWrappedDrawable();
        if (inner != null) {
            inner = tileify(inner, clip);
            ((DrawableWrapper) drawable).setWrappedDrawable(inner);
        }
    } else 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 BitmapDrawable) {
        final BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
        final Bitmap tileBitmap = bitmapDrawable.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);
        shapeDrawable.getPaint().setColorFilter(bitmapDrawable.getPaint().getColorFilter());
        return (clip) ? new ClipDrawable(shapeDrawable, Gravity.LEFT, ClipDrawable.HORIZONTAL) : shapeDrawable;
    }

    return drawable;
}

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

/**
 * Converts a drawable to a tiled version of itself. It will recursively
 * traverse layer and state list drawables.
 *//* ww  w.  jav  a 2  s.com*/
private Drawable tileify(Drawable drawable, boolean clip) {
    if (drawable instanceof DrawableWrapper) {
        Drawable inner = ((DrawableWrapper) drawable).getWrappedDrawable();
        if (inner != null) {
            inner = tileify(inner, clip);
            ((DrawableWrapper) drawable).setWrappedDrawable(inner);
        }
    } else 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 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;
}

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

    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: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 ww w  . jav a 2  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 ww  . j  a  va2s .  co 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:uk.co.brightec.ratetheapp.RateTheApp.java

/**
 * Converts a drawable to a tiled version of itself. It will recursively traverse layer and state list drawables.
 * This method was copied from android.widget.ProgressBar, however it was highlighted in their code that this may be sub optimal.
 *
 * @param drawable The drawable to tileify
 * @param clip     Whether to clip drawable
 * @return The tiled drawable//  w  w  w. j a  v a 2 s .c o  m
 */
private Drawable tileify(Drawable drawable, boolean clip) {
    if (drawable instanceof LayerDrawable) {
        final LayerDrawable orig = (LayerDrawable) drawable;
        final int N = orig.getNumberOfLayers();
        final Drawable[] outDrawables = new Drawable[N];

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

        final LayerDrawable clone = new LayerDrawable(outDrawables);
        for (int i = 0; i < N; i++) {
            clone.setId(i, orig.getId(i));
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                clone.setLayerGravity(i, orig.getLayerGravity(i));
                clone.setLayerWidth(i, orig.getLayerWidth(i));
                clone.setLayerHeight(i, orig.getLayerHeight(i));
                clone.setLayerInsetLeft(i, orig.getLayerInsetLeft(i));
                clone.setLayerInsetRight(i, orig.getLayerInsetRight(i));
                clone.setLayerInsetTop(i, orig.getLayerInsetTop(i));
                clone.setLayerInsetBottom(i, orig.getLayerInsetBottom(i));
                clone.setLayerInsetStart(i, orig.getLayerInsetStart(i));
                clone.setLayerInsetEnd(i, orig.getLayerInsetEnd(i));
            }
        }

        return clone;
    }

    if (drawable instanceof BitmapDrawable) {
        final BitmapDrawable bitmap = (BitmapDrawable) drawable;

        final BitmapDrawable clone = (BitmapDrawable) bitmap.getConstantState().newDrawable();
        clone.setTileModeXY(Shader.TileMode.REPEAT, Shader.TileMode.CLAMP);

        if (clip) {
            return new ClipDrawable(clone, Gravity.LEFT, ClipDrawable.HORIZONTAL);
        } else {
            return clone;
        }
    }

    return drawable;
}

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 .ja  v a 2 s.  co  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;
}

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 w w w  . java2s.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;
}