Example usage for android.graphics Color rgb

List of usage examples for android.graphics Color rgb

Introduction

In this page you can find the example usage for android.graphics Color rgb.

Prototype

@ColorInt
public static int rgb(float red, float green, float blue) 

Source Link

Document

Return a color-int from red, green, blue float components in the range \([0..1]\).

Usage

From source file:project.pamela.slambench.fragments.PowerPlot.java

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

    // Replace LinearLayout by the type of the root element of the layout you're trying to load
    LinearLayout llLayout = (LinearLayout) inflater.inflate(R.layout.fragment_plot, container, false);

    // Retrieve bench number
    Intent mIntent = super.getActivity().getIntent();
    final int intValue = mIntent.getIntExtra(ResultActivity.SELECTED_TEST_TAG, 0);
    SLAMResult value = SLAMBenchApplication.getResults().get(intValue);

    if (!value.isFinished()) {
        Log.e(SLAMBenchApplication.LOG_TAG,
                this.getResources().getString(R.string.debug_proposed_value_not_valid));
        return llLayout;
    }/*from www.  ja  v a  2s .  c o  m*/

    // initialize our XYPlot reference:
    XYPlot plot = (XYPlot) llLayout.findViewById(R.id.mySimpleXYPlot);

    plot.setTitle(value.test.name);
    plot.setDomainLabel(this.getResources().getString(R.string.legend_frame_number));
    plot.setRangeLabel(this.getResources().getString(R.string.legend_power));
    plot.setBackgroundColor(Color.WHITE);
    plot.getBorderPaint().setColor(Color.WHITE);

    plot.getGraphWidget().getBackgroundPaint().setColor(Color.WHITE);
    plot.getGraphWidget().getGridBackgroundPaint().setColor(Color.WHITE);

    plot.getGraphWidget().getDomainLabelPaint().setColor(Color.BLACK);
    plot.getGraphWidget().getRangeLabelPaint().setColor(Color.BLACK);

    plot.getGraphWidget().getDomainOriginLabelPaint().setColor(Color.BLACK);
    plot.getGraphWidget().getDomainOriginLinePaint().setColor(Color.BLACK);
    plot.getGraphWidget().getRangeOriginLinePaint().setColor(Color.BLACK);

    plot.getGraphWidget().setRangeValueFormat(new DecimalFormat("#####.##"));

    int border = 60;
    int legendsize = 110;

    plot.getGraphWidget().position(border, XLayoutStyle.ABSOLUTE_FROM_LEFT, border,
            YLayoutStyle.ABSOLUTE_FROM_BOTTOM, AnchorPosition.LEFT_BOTTOM);
    plot.getGraphWidget()
            .setSize(new SizeMetrics(border + legendsize, SizeLayoutType.FILL, border, SizeLayoutType.FILL));

    // reduce the number of range labels
    plot.setDomainStep(XYStepMode.INCREMENT_BY_VAL, 10);
    plot.setDomainValueFormat(new DecimalFormat("#"));
    plot.setRangeStep(XYStepMode.SUBDIVIDE, 10);

    //Remove legend
    //plot.getLayoutManager().remove(plot.getLegendWidget());
    //plot.getLayoutManager().remove(plot.getDomainLabelWidget());
    //plot.getLayoutManager().remove(plot.getRangeLabelWidget());
    plot.getLayoutManager().remove(plot.getTitleWidget());

    // Set legend
    plot.getLegendWidget().setTableModel(new DynamicTableModel(4, 2));

    Paint bgPaint = new Paint();
    bgPaint.setColor(Color.BLACK);
    bgPaint.setStyle(Paint.Style.FILL);
    bgPaint.setAlpha(140);

    plot.getLegendWidget().setBackgroundPaint(bgPaint);

    plot.getLegendWidget()
            .setSize(new SizeMetrics(legendsize, SizeLayoutType.ABSOLUTE, 0, SizeLayoutType.FILL));

    plot.getLegendWidget().position(0, XLayoutStyle.ABSOLUTE_FROM_RIGHT, 0, YLayoutStyle.ABSOLUTE_FROM_TOP,
            AnchorPosition.RIGHT_TOP);

    plot.getDomainLabelWidget().position(0, XLayoutStyle.ABSOLUTE_FROM_CENTER, 0,
            YLayoutStyle.RELATIVE_TO_BOTTOM, AnchorPosition.BOTTOM_MIDDLE);

    int strokecolor = Color.rgb(91, 255, 159);
    int fillcolor = Color.rgb(91, 255, 184);

    Double powerNumbers[] = value.getPowerList();
    for (int i = 0; i < value.test.dataset.getFrameCount(); i++) {
        powerNumbers[i] = powerNumbers[i] / -1000;
    }
    XYSeries series = new SimpleXYSeries(Arrays.asList(powerNumbers), SimpleXYSeries.ArrayFormat.Y_VALS_ONLY,
            this.getResources().getString(R.string.legend_power));
    LineAndPointFormatter seriesFormat = new LineAndPointFormatter(strokecolor, strokecolor, null, null);

    Paint lineFill = new Paint();
    lineFill.setAlpha(200);
    DisplayMetrics metrics = new DisplayMetrics();
    super.getActivity().getWindowManager().getDefaultDisplay().getMetrics(metrics);
    lineFill.setShader(
            new LinearGradient(0, 0, 0, metrics.heightPixels, Color.WHITE, fillcolor, Shader.TileMode.MIRROR));
    seriesFormat.setPointLabeler(new PointLabeler() {
        @Override
        public String getLabel(XYSeries series, int index) {
            return "o";
        }
    });
    seriesFormat.setFillPaint(lineFill);
    plot.addSeries(series, seriesFormat);

    // same as above
    LineAndPointFormatter lineFormat = new LineAndPointFormatter(Color.BLACK, null, null, null);
    //change the line width
    Paint paint = lineFormat.getLinePaint();
    paint.setStrokeWidth(5);
    lineFormat.setLinePaint(paint);

    Number[] line = { 0, 3, value.test.dataset.getFrameCount() - 1, 3 };
    XYSeries expected = new SimpleXYSeries(Arrays.asList(line), SimpleXYSeries.ArrayFormat.XY_VALS_INTERLEAVED,
            getResources().getString(R.string.legend_power_limit));
    plot.addSeries(expected, lineFormat);

    plot.redraw();

    plot.calculateMinMaxVals();
    PointF minXY = new PointF(plot.getCalculatedMinX().floatValue(), plot.getCalculatedMinY().floatValue());
    PointF maxXY = new PointF(plot.getCalculatedMaxX().floatValue(), plot.getCalculatedMaxY().floatValue());

    plot.setDomainBoundaries(0, value.test.dataset.getFrameCount() - 1, BoundaryMode.FIXED);
    plot.setRangeBoundaries(Math.min(0, minXY.y), maxXY.y * 1.2f, BoundaryMode.FIXED);

    plot.redraw();

    return llLayout;
}

From source file:project.pamela.slambench.fragments.FrequencyPlot.java

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

    // Replace LinearLayout by the type of the root element of the layout you're trying to load
    LinearLayout llLayout = (LinearLayout) inflater.inflate(R.layout.fragment_plot, container, false);

    // Retrieve bench number
    Intent mIntent = super.getActivity().getIntent();
    final int intValue = mIntent.getIntExtra(ResultActivity.SELECTED_TEST_TAG, 0);
    SLAMResult value = SLAMBenchApplication.getResults().get(intValue);

    if (!value.isFinished()) {
        Log.e(SLAMBenchApplication.LOG_TAG,
                this.getResources().getString(R.string.debug_proposed_value_not_valid));
        return llLayout;
    }/*from w  w w  .j  ava  2 s.c o m*/

    // initialize our XYPlot reference:
    XYPlot plot = (XYPlot) llLayout.findViewById(R.id.mySimpleXYPlot);

    plot.setBackgroundColor(Color.WHITE);
    plot.setTitle(value.test.name);
    plot.setDomainLabel(this.getResources().getString(R.string.legend_frame_number));
    plot.setRangeLabel(this.getResources().getString(R.string.frequency_domain));
    plot.setBackgroundColor(Color.WHITE);
    plot.getGraphWidget().getBackgroundPaint().setColor(Color.WHITE);
    plot.getGraphWidget().getGridBackgroundPaint().setColor(Color.WHITE);

    plot.getGraphWidget().getDomainLabelPaint().setColor(Color.BLACK);
    plot.getGraphWidget().getRangeLabelPaint().setColor(Color.BLACK);

    plot.getGraphWidget().getDomainOriginLabelPaint().setColor(Color.BLACK);
    plot.getGraphWidget().getDomainOriginLinePaint().setColor(Color.BLACK);
    plot.getGraphWidget().getRangeOriginLinePaint().setColor(Color.BLACK);

    plot.getGraphWidget().setRangeValueFormat(new DecimalFormat("#####.##"));

    int border = 60;
    int legendsize = 110;

    plot.getGraphWidget().position(border, XLayoutStyle.ABSOLUTE_FROM_LEFT, border,
            YLayoutStyle.ABSOLUTE_FROM_BOTTOM, AnchorPosition.LEFT_BOTTOM);
    plot.getGraphWidget()
            .setSize(new SizeMetrics(border + legendsize, SizeLayoutType.FILL, border, SizeLayoutType.FILL));

    // reduce the number of range labels
    plot.setDomainStep(XYStepMode.INCREMENT_BY_VAL, 10);
    plot.setDomainValueFormat(new DecimalFormat("#"));
    plot.setRangeStep(XYStepMode.SUBDIVIDE, 10);

    //Remove legend
    //plot.getLayoutManager().remove(plot.getLegendWidget());
    //plot.getLayoutManager().remove(plot.getDomainLabelWidget());
    //plot.getLayoutManager().remove(plot.getRangeLabelWidget());
    plot.getLayoutManager().remove(plot.getTitleWidget());

    // Set legend
    plot.getLegendWidget().setTableModel(new DynamicTableModel(4, 2));

    Paint bgPaint = new Paint();
    bgPaint.setColor(Color.BLACK);
    bgPaint.setStyle(Paint.Style.FILL);
    bgPaint.setAlpha(140);

    plot.getLegendWidget().setBackgroundPaint(bgPaint);

    plot.getLegendWidget()
            .setSize(new SizeMetrics(legendsize, SizeLayoutType.ABSOLUTE, 0, SizeLayoutType.FILL));

    plot.getLegendWidget().position(0, XLayoutStyle.ABSOLUTE_FROM_RIGHT, 0, YLayoutStyle.ABSOLUTE_FROM_TOP,
            AnchorPosition.RIGHT_TOP);

    plot.getDomainLabelWidget().position(0, XLayoutStyle.ABSOLUTE_FROM_CENTER, 0,
            YLayoutStyle.RELATIVE_TO_BOTTOM, AnchorPosition.BOTTOM_MIDDLE);

    for (int i = 0; i < value.getCPUCount(); i++) {

        int strokecolor = Color.rgb(i * (255 / value.getCPUCount()), 137, 192);
        int fillcolor = Color.rgb(i * (255 / value.getCPUCount()), 229, 255);

        Double frequencyNumbers[] = value.getfrequencyList(i);
        XYSeries series = new SimpleXYSeries(Arrays.asList(frequencyNumbers),
                SimpleXYSeries.ArrayFormat.Y_VALS_ONLY,
                this.getResources().getString(R.string.frequency_legend, i));
        LineAndPointFormatter seriesFormat = new LineAndPointFormatter(strokecolor, strokecolor, null, null);

        seriesFormat.setPointLabeler(new PointLabeler() {
            @Override
            public String getLabel(XYSeries series, int index) {
                return "o";
            }
        });

        Paint lineFill = new Paint();
        lineFill.setAlpha(150);
        DisplayMetrics metrics = new DisplayMetrics();
        super.getActivity().getWindowManager().getDefaultDisplay().getMetrics(metrics);
        lineFill.setShader(new LinearGradient(0, 0, 0, metrics.heightPixels, Color.WHITE, fillcolor,
                Shader.TileMode.MIRROR));
        seriesFormat.setFillPaint(lineFill);

        plot.addSeries(series, seriesFormat);
    }

    plot.redraw();

    plot.calculateMinMaxVals();
    PointF minXY = new PointF(plot.getCalculatedMinX().floatValue(), plot.getCalculatedMinY().floatValue());
    PointF maxXY = new PointF(plot.getCalculatedMaxX().floatValue(), plot.getCalculatedMaxY().floatValue());

    plot.setDomainBoundaries(0, value.test.dataset.getFrameCount() - 1, BoundaryMode.FIXED);
    plot.setRangeBoundaries(Math.min(0, minXY.y), maxXY.y * 1.2f, BoundaryMode.FIXED);

    plot.redraw();

    return llLayout;
}

From source file:com.rowland.hashtrace.ui.fragments.SearchFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // The CursorAdapter will take data from a source and use it to populate the ListView it's attached to.
    mTweetListAdapter = new TweetListAdapter(getActivity(), null, 0);
    creator = new SwipeMenuCreator() {

        @Override/*from  w  w w . j  av a 2 s.c o  m*/
        public void create(SwipeMenu menu) {
            // create "share" item
            SwipeMenuItem shareItem = new SwipeMenuItem(getActivity().getApplicationContext());
            // set item background
            shareItem.setBackground(new ColorDrawable(Color.rgb(211, 214, 219)));
            // set item width
            shareItem.setWidth(Utility.convertDpToPixel(100, getResources().getDisplayMetrics()));
            // set icon resource
            shareItem.setIcon(R.drawable.selector_swipemenuitem_share);
            // set item title
            shareItem.setTitle("Share");
            // set item title fontsize
            shareItem.setTitleSize(18);
            // set item title font color
            shareItem.setTitleColor(Color.WHITE);
            // add to menu
            menu.addMenuItem(shareItem);

            // create "favour" item
            SwipeMenuItem favourItem = new SwipeMenuItem(getActivity().getApplicationContext());
            // set item background
            favourItem.setBackground(new ColorDrawable(Color.rgb(211, 214, 219)));
            // set item width
            favourItem.setWidth(Utility.convertDpToPixel(100, getResources().getDisplayMetrics()));
            // set icon resource
            favourItem.setIcon(R.drawable.selector_swipemenuitem_favorite);
            // set item title
            favourItem.setTitle("Like");
            // set item title fontsize
            favourItem.setTitleSize(18);
            // set item title font color
            favourItem.setTitleColor(Color.WHITE);
            // add to menu
            menu.addMenuItem(favourItem);
        }
    };

    View rootView = inflater.inflate(R.layout.fragment_search, container, false);

    //txtQuery = (TextView) rootView.findViewById(R.id.listview_tweet_empty);
    mListView = (SwipeMenuListView) rootView.findViewById(android.R.id.list);
    mListView.setAdapter(mTweetListAdapter);
    mListView.setMenuCreator(creator);
    mListView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {

        @Override
        public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
            // Do the onItemLongClick action
            mListView.smoothOpenMenu(position);

            return true;
        }
    });
    mListView.setOnMenuItemClickListener(new SwipeMenuListView.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(int position, SwipeMenu menu, int index) {
            switch (index) {
            case 0:
                // Share
                shareTweet();
                break;
            case 1:
                // Favourite
                favouriteTweet();
                break;
            }
            // false : close the menu; true : not close the menu
            return false;
        }
    });
    mListView.setCloseInterpolator(new BounceInterpolator());

    // If there's instance state, mine it for useful information.
    // The end-goal here is that the user never knows that turning their
    // device sideways does crazy lifecycle related things. It should
    // feel like some stuff stretched out, or magically appeared to take
    // advantage of room, but data or place in the app was never actually *lost*.
    if (savedInstanceState != null && savedInstanceState.containsKey(SELECTED_KEY)) {
        // The listview probably hasn't even been populated yet. Actually
        // perform the
        // swapout in onLoadFinished.
        mPosition = savedInstanceState.getInt(SELECTED_KEY);
    }

    return rootView;
}

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

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

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

    editTextSessionProfile = (EditText) v.findViewById(R.id.editTextSessionProfile);

    if (SessionSingleton.getInstance().getSessionName() == null)
        SessionSingleton.getInstance().setSessionName(getString(R.string.session_profile));

    editTextSessionProfile.setText(SessionSingleton.getInstance().getSessionName());

    editTextSessionProfile.addTextChangedListener(new TextWatcher() {
        @Override//from  w  w  w .ja v a  2 s.c  om
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            SessionSingleton.getInstance().setSessionName(editTextSessionProfile.getText().toString());
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void afterTextChanged(Editable s) {
        }
    });

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

    //      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");
    //            SessionSingleton.getInstance().exportDataToCSV(null, null);
    //         }
    //      });

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

            resetSession();

        }
    });

    // setup the Session History plot
    sessionPlot1 = (XYPlot) v.findViewById(R.id.sessionPlot1);
    sessionPlotSeries1 = new SimpleXYSeries("Session Plot");

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

    if (sessionPlot1 != null) {

        sessionPlot1.setDomainBoundaries(0, 30, BoundaryMode.FIXED);
        //         sessionPlot1.setRangeBoundaries(0, 100, BoundaryMode.GROW);
        sessionPlot1.setRangeBoundaries(0, 100, BoundaryMode.FIXED);

        //         sessionPlot1.addSeries(sessionPlotSeries1, new LineAndPointFormatter(Color.rgb(200, 100, 100), Color.BLACK, null, null));
        sessionPlot1.addSeries(sessionPlotSeries1,
                new LineAndPointFormatter(Color.rgb(200, 100, 100), Color.RED, null, null));

        // Thin out domain and range tick values so they don't overlap
        sessionPlot1.setDomainStepValue(1);
        sessionPlot1.setTicksPerRangeLabel(10);

        //         sessionPlot1.setRangeLabel("Attention");
        sessionPlot1.setRangeLabel("");

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

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

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

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

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

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

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

    }

    // setup the Session History plot
    sessionPlot2 = (XYPlot) v.findViewById(R.id.sessionPlot2);
    sessionPlotSeries2 = new SimpleXYSeries("Session Plot");

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

    if (sessionPlot2 != null) {

        sessionPlot2.setDomainBoundaries(0, 30, BoundaryMode.FIXED);
        //         sessionPlot2.setRangeBoundaries(0, 100, BoundaryMode.GROW);
        sessionPlot2.setRangeBoundaries(0, 100, BoundaryMode.FIXED);

        //         sessionPlot2.addSeries(sessionPlotSeries2, new LineAndPointFormatter(Color.rgb(200, 100, 100), Color.BLACK, null, null));
        sessionPlot2.addSeries(sessionPlotSeries2,
                new LineAndPointFormatter(Color.rgb(200, 100, 100), Color.RED, null, null));

        // Thin out domain and range tick values so they don't overlap
        sessionPlot2.setDomainStepValue(1);
        sessionPlot2.setTicksPerRangeLabel(10);

        //         sessionPlot2.setRangeLabel("Meditation");
        sessionPlot2.setRangeLabel("");

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

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

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

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

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

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

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

    }

    return v;

}

From source file:fi.tuukka.weather.utils.Utils.java

public static int getTempColor(int tempValue) {
    int r = 255;/*  w w w. j  a  v a2  s.c o m*/
    int g = 255;
    int b = 255;
    if (tempValue <= -30) {
        r = 0;
        g = 0;
        b = 255;
    } else if (tempValue > -30 && tempValue <= -15) {
        double c1 = 17.;
        double c2 = 510.;
        r = 0;
        g = (int) (c1 * tempValue + c2);
        b = 255;
    } else if (tempValue > -15 && tempValue <= -0) {
        double c1 = 15.;
        double c2 = 225.;
        r = (int) (c1 * tempValue + c2);
        g = 255;
        b = 255;
    } else if (tempValue >= 0 && tempValue < 15) {
        double c1 = -14.;
        double c2 = 210.0;
        r = 255;
        g = 255;
        b = (int) (c1 * tempValue + c2);
    } else if (tempValue >= 15 && tempValue < 30) {
        double c1 = -17.;
        double c2 = 510.;
        r = 255;
        g = (int) (c1 * tempValue + c2);
        b = 0;
    }
    if (tempValue >= 30) {
        r = 255;
        g = 0;
        b = 0;
    }
    return Color.rgb(r, g, b);
}

From source file:de.uni_weimar.benike.misex3.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // register for accelerometer events:
    mSensorManager = (SensorManager) getApplicationContext().getSystemService(Context.SENSOR_SERVICE);
    for (Sensor sensor : mSensorManager.getSensorList(Sensor.TYPE_ACCELEROMETER)) {
        if (sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
            mAccelerometerSensor = sensor;
        }/*  w w  w.jav a 2 s .  co m*/
    }

    // if we can't access the accelerometer sensor then exit:
    if (mAccelerometerSensor == null) {
        Log.e(TAG, "Failed to attach to Accelerator Sensor.");
        Toast.makeText(this, "Error! Failed to create accelerometer sensor!", Toast.LENGTH_LONG).show();
        cleanup();
    }

    mSensorManager.registerListener(this, mAccelerometerSensor, SensorManager.SENSOR_DELAY_UI);

    // setup the Accelerometer History plot:
    mAccelerometerPlot = (XYPlot) findViewById(R.id.accelerometerPlot);
    mFftPlot = (XYPlot) findViewById(R.id.fftPlot);

    mAccelerometerPlot.setRangeBoundaries(-25, 25, BoundaryMode.FIXED);
    mAccelerometerPlot.setDomainBoundaries(0, mWindowSize - 1, BoundaryMode.FIXED);

    mFftPlot.setRangeBoundaries(0, 250, BoundaryMode.FIXED);
    mFftPlot.setDomainBoundaries(0, mWindowSize / 2, BoundaryMode.AUTO);
    mFftPlot.setDomainStep(XYStepMode.SUBDIVIDE, 10);
    //mFftPlot.setRangeStep(XYStepMode.INCREMENT_BY_VAL, 50);

    mAccelerometerXSeries = new SimpleXYSeries("X");
    mAccelerometerXSeries.useImplicitXVals();
    mAccelerometerYSeries = new SimpleXYSeries("Y");
    mAccelerometerYSeries.useImplicitXVals();
    mAccelerometerZSeries = new SimpleXYSeries("Z");
    mAccelerometerZSeries.useImplicitXVals();
    mAccelerometerMSeries = new SimpleXYSeries("magnitude");
    mAccelerometerMSeries.useImplicitXVals();

    mFftSeries = new SimpleXYSeries("FFT");
    mFftSeries.useImplicitXVals();

    mFftPlot.addSeries(mFftSeries, new LineAndPointFormatter(Color.rgb(0, 0, 0), null, null, null));

    mAccelerometerPlot.addSeries(mAccelerometerXSeries,
            new LineAndPointFormatter(Color.rgb(100, 100, 200), null, null, null));
    mAccelerometerPlot.addSeries(mAccelerometerYSeries,
            new LineAndPointFormatter(Color.rgb(100, 200, 100), null, null, null));
    mAccelerometerPlot.addSeries(mAccelerometerZSeries,
            new LineAndPointFormatter(Color.rgb(200, 100, 100), null, null, null));
    mAccelerometerPlot.addSeries(mAccelerometerMSeries,
            new LineAndPointFormatter(Color.rgb(0, 0, 0), null, null, null));
    mAccelerometerPlot.setDomainStepValue(5);
    mAccelerometerPlot.setTicksPerRangeLabel(3);
    mAccelerometerPlot.setDomainLabel("Sample Index");
    mAccelerometerPlot.getDomainLabelWidget().pack();
    mAccelerometerPlot.setRangeLabel("m/s^2");
    mAccelerometerPlot.getRangeLabelWidget().pack();

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

    // perform hardware accelerated rendering of the plots
    mAccelerometerPlot.setLayerType(View.LAYER_TYPE_NONE, null);
    mFftPlot.setLayerType(View.LAYER_TYPE_NONE, null);

    mFftPlot.setTicksPerRangeLabel(5);
    mFftPlot.setTicksPerDomainLabel(1);

    mSampleRateSeekBar = (SeekBar) findViewById(R.id.sampleRateSeekBar);
    mSampleRateSeekBar.setMax((SAMPLE_MAX_VALUE - SAMPLE_MIN_VALUE) / SAMPLE_STEP);
    mSampleRateSeekBar.setOnSeekBarChangeListener(this);

    mFftWindowSeekBar = (SeekBar) findViewById(R.id.fftWindowSeekBar);
    mFftWindowSeekBar.setMax((WINDOW_MAX_VALUE - WINDOW_MIN_VALUE) / WINDOW_STEP);
    mFftWindowSeekBar.setOnSeekBarChangeListener(this);

    mWindowSizeTextView = (TextView) findViewById(R.id.windowSizeTextView);

    // Perform FFT calculations in background thread
    mFft = new FFT(mWindowSize);
    Runnable r = new PerformFft();
    mFftThread = new Thread(r);
    mFftThread.start();

    mNotificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_help_outline_black_24dp).setContentTitle("MIS Ex3 Activity Recognizer")
            .setContentText("Trying to guess your activity").setOngoing(true);

    Intent resultIntent = new Intent(this, MainActivity.class);

    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    stackBuilder.addParentStack(MainActivity.class);
    stackBuilder.addNextIntent(resultIntent);
    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    mNotificationBuilder.setContentIntent(resultPendingIntent);

    mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    mNotificationManager.notify(mNotificationId, mNotificationBuilder.build());

    Runnable detectActivity = new DetectActivity();
    mDetectActivityThread = new Thread(detectActivity);
    mDetectActivityThread.start();
}

From source file:com.example.jit.home.SlidingTabStrip.java

/**
 * Blend {@code color1} and {@code color2} using the given ratio.
 *
 * @param ratio of which to blend. 1.0 will return {@code color1}, 0.5 will give an even blend,
 *              0.0 will return {@code color2}.
 *//*from   w  ww.j a v  a 2 s  . c o m*/
private static int blendColors(int color1, int color2, float ratio) {
    final float inverseRation = 1f - ratio;
    float r = (Color.red(color1) * ratio) + (Color.red(color2) * inverseRation);
    float g = (Color.green(color1) * ratio) + (Color.green(color2) * inverseRation);
    float b = (Color.blue(color1) * ratio) + (Color.blue(color2) * inverseRation);
    return Color.rgb((int) r, (int) g, (int) b);
}

From source file:mobile.tiis.appv2.fragments.MonthlyPerformanceFragment.java

public void renderChartData() {

    List<ChartDataModel> listItems = mydb.getMonthlyPerformance(app);
    ArrayList<String> xVals = new ArrayList<String>();

    ArrayList<BarEntry> noVals = new ArrayList<BarEntry>();
    ArrayList<BarEntry> cummNoVals = new ArrayList<BarEntry>();
    for (int i = 0; i < listItems.size(); i++) {
        ChartDataModel item = listItems.get(i);
        xVals.add(item.getLabel());/*from   w w w  .j  a v a  2 s. co m*/

        noVals.add(new BarEntry((float) item.getValue(), i));

        cummNoVals.add(new BarEntry((float) summPreviousEntries(listItems, i), i));
    }

    // create 2 datasets with different types
    BarDataSet set1 = new BarDataSet(noVals, app.getString(R.string.no_of_children_immunized));
    // set1.setColors(ColorTemplate.createColors(getApplicationContext(),
    // ColorTemplate.FRESH_COLORS));
    set1.setColor(Color.rgb(109, 164, 213));
    BarDataSet set2 = new BarDataSet(cummNoVals, app.getString(R.string.cumm_no_children_immunized));
    set2.setColor(Color.rgb(235, 139, 75));

    ArrayList<IBarDataSet> dataSets = new ArrayList<IBarDataSet>();
    dataSets.add(set1);
    dataSets.add(set2);

    BarData data = new BarData(xVals, dataSets);
    data.setValueFormatter(new LargeValueFormatter());

    mChart.setData(data);
    mChart.invalidate();
}

From source file:info.rti.tabsswipe.AltitudeFragment.java

@Override
public void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mItems = new ArrayList<String>();
    mSeries = new HashMap<String, TimeSeries>();
    mDataset = new XYMultipleSeriesDataset();
    mRenderer = new XYMultipleSeriesRenderer();

    mRenderer.setAxisTitleTextSize(24);//from w ww. ja  v  a  2s.c o m
    mRenderer.setChartTitleTextSize(28);
    mRenderer.setLabelsTextSize(22);
    mRenderer.setLegendTextSize(22);
    mRenderer.setPointSize(8f);
    mRenderer.setXLabelsAlign(Align.CENTER);
    mRenderer.setYLabelsAlign(Align.CENTER);

    mRenderer.setChartTitle("Live Altitude from RaspberryPi (" + BMP_pressureSubscriber.mId
            + ") Barometric Sensor (BMP085) " + "\nat Temperature " + BMP_pressureSubscriber.mTemperature
            + " Celsius and Pressure " + BMP_pressureSubscriber.mPressure + " kPa");

    mRenderer.setXTitle("In Real Time...");
    mRenderer.setYTitle("Altitude (meters)");
    mRenderer.setLabelsColor(Color.LTGRAY);
    mRenderer.setAxesColor(Color.LTGRAY);
    mRenderer.setGridColor(Color.rgb(136, 136, 136));
    mRenderer.setBackgroundColor(Color.BLACK);

    mRenderer.setApplyBackgroundColor(true);

    mRenderer.setMargins(new int[] { 60, 60, 60, 60 });

    mRenderer.setFitLegend(true);
    mRenderer.setShowGrid(true);

    mRenderer.setZoomButtonsVisible(false);
    mRenderer.setZoomEnabled(true);
    mRenderer.setExternalZoomEnabled(true);

    mRenderer.setAntialiasing(true);
    mRenderer.setInScroll(true);

    mLastItemChange = new Date().getTime();
    mItemIndex = 5;// Math.abs(RAND.nextInt(ITEMS.length));

    mThresholds = new TimeSeries[3];
    mThresholdRenderers = new XYSeriesRenderer[3];

    for (int i = 0; i < THRESHOLD_COLORS.length; i++) {
        mThresholdRenderers[i] = new XYSeriesRenderer();
        mThresholdRenderers[i].setColor(THRESHOLD_COLORS[i]);
        mThresholdRenderers[i].setLineWidth(3);

        mThresholds[i] = new TimeSeries(THRESHOLD_LABELS[i]);
        final long now = new Date().getTime();
        mThresholds[i].add(new Date(now - 1000 * 60 * 10), THRESHOLD_VALUES[i]);
        mThresholds[i].add(new Date(now + 1000 * 60 * 10), THRESHOLD_VALUES[i]);

        mDataset.addSeries(mThresholds[i]);
        mRenderer.addSeriesRenderer(mThresholdRenderers[i]);
    }

}

From source file:com.mchp.android.PIC32_BTSK.ColorFragment.java

public void onProgressChanged(SeekBar seekBar, int progress, boolean fromTouch) {
    if (!fromTouch) {
        return;//  w  w w .j  a  va  2 s  . c om
    }

    getSeekBarProgress();

    mColor = Color.rgb(r, g, b);
    setProgressText();
    mColorPicker.setColor(mColor);
    mNewColor.setColor(mColor);

    sendLedCmd(r, g, b);
}