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:it.redturtle.mobile.apparpav.MeteogramAdapter.java

/**
 * DOUBLE IMAGE ROW/*from  ww w.  j av a2  s  .  c  o  m*/
 * @param att
 * @param linear
 * @return
 */
public LinearLayout getDoubleImageRow(Map<String, String> att, LinearLayout linear) {

    LinearLayout container_layout = new LinearLayout(context);
    container_layout.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.view_shape_meteo));
    container_layout.setMinimumHeight(46);
    container_layout.setVerticalGravity(Gravity.CENTER);

    LinearLayout.LayoutParams value_params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
            LayoutParams.WRAP_CONTENT, 0.3f);
    TextView tx = new TextView(context);
    tx.setText(att.get("title"));
    tx.setTextSize(11);
    tx.setTypeface(null, Typeface.BOLD);
    tx.setGravity(Gravity.LEFT);
    tx.setPadding(3, 0, 0, 2);
    tx.setTextColor(Color.rgb(66, 66, 66));
    container_layout.addView(tx, value_params);

    LinearLayout.LayoutParams value_one_params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, 46,
            0.35f);
    ImageView img1 = new ImageView(context);
    String path = "it.redturtle.mobile.apparpav:drawable/" + FilenameUtils.removeExtension(att.get("value1"));
    img1.setImageResource(context.getResources().getIdentifier(path, null, null));
    img1.setPadding(0, 3, 0, 3);
    container_layout.addView(img1, value_one_params);

    LinearLayout.LayoutParams value_two_params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, 46,
            0.35f);
    ImageView img2 = new ImageView(context);
    path = "it.redturtle.mobile.apparpav:drawable/" + FilenameUtils.removeExtension(att.get("value2"));
    img2.setImageResource(context.getResources().getIdentifier(path, null, null));
    img2.setPadding(0, 3, 0, 3);
    container_layout.addView(img2, value_two_params);

    linear.addView(container_layout);

    return linear;
}

From source file:com.todoroo.astrid.notes.EditNoteActivity.java

private void setUpInterface() {
    timerView = commentsBar.findViewById(R.id.timer_container);
    commentButton = commentsBar.findViewById(R.id.commentButton);
    commentField = (EditText) commentsBar.findViewById(R.id.commentField);

    final boolean showTimerShortcut = preferences.getBoolean(R.string.p_show_timer_shortcut, false);

    if (showTimerShortcut) {
        commentField.setOnFocusChangeListener(new OnFocusChangeListener() {
            @Override/* w ww.j a va  2s. c o m*/
            public void onFocusChange(View v, boolean hasFocus) {
                if (hasFocus) {
                    timerView.setVisibility(View.GONE);
                    commentButton.setVisibility(View.VISIBLE);
                } else {
                    timerView.setVisibility(View.VISIBLE);
                    commentButton.setVisibility(View.GONE);
                }
            }
        });
    }
    commentField.setHorizontallyScrolling(false);
    commentField.setMaxLines(Integer.MAX_VALUE);
    commentField.setOnKeyListener(new OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_ENTER) {
                AndroidUtilities.hideSoftInputForViews(activity, commentField);
                return true;
            }
            return false;
        }
    });
    commentField.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            commentField.setCursorVisible(true);
        }
    });

    commentField.addTextChangedListener(new TextWatcher() {
        @Override
        public void afterTextChanged(Editable s) {
            commentButton.setVisibility(
                    (s.length() > 0 || pendingCommentPicture != null) ? View.VISIBLE : View.GONE);
            if (showTimerShortcut) {
                timerView.setVisibility(
                        (s.length() > 0 || pendingCommentPicture != null) ? View.GONE : View.VISIBLE);
            }
        }

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

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            //
        }
    });

    commentField.setOnEditorActionListener(new OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView view, int actionId, KeyEvent event) {
            if (commentField.getText().length() > 0) {
                if (actionId == EditorInfo.IME_ACTION_DONE || actionId == EditorInfo.IME_NULL) {
                    //                        commentField.setCursorVisible(false);
                    addComment();
                }
            }
            return false;
        }
    });

    commentButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            addComment();
        }
    });

    final ClearImageCallback clearImage = new ClearImageCallback() {
        @Override
        public void clearImage() {
            pendingCommentPicture = null;
            pictureButton.setImageResource(cameraButton);
        }
    };
    pictureButton = (ImageButton) commentsBar.findViewById(R.id.picture);
    pictureButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (pendingCommentPicture != null) {
                actFmCameraModule.showPictureLauncher(clearImage);
            } else {
                actFmCameraModule.showPictureLauncher(null);
            }
            respondToPicture = true;
        }
    });
    if (!TextUtils.isEmpty(task.getNotes())) {
        TextView notes = new TextView(getContext());
        notes.setLinkTextColor(Color.rgb(100, 160, 255));
        notes.setTextSize(18);
        notes.setText(task.getNotes());
        notes.setPadding(5, 10, 5, 10);
        Linkify.addLinks(notes, Linkify.ALL);
    }

    if (activity != null) {
        String uri = activity.getIntent().getStringExtra(TaskEditFragment.TOKEN_PICTURE_IN_PROGRESS);
        if (uri != null) {
            pendingCommentPicture = Uri.parse(uri);
            setPictureButtonToPendingPicture();
        }
    }
}

From source file:de.tudarmstadt.informatik.secuso.phishedu2.MainActivity.java

@Override
public void displayToastScore(int score) {
    LayoutInflater inflater = getLayoutInflater();
    View layout = inflater.inflate(R.layout.fragment_toast_score,
            (ViewGroup) findViewById(R.id.toast_layout_root));

    String scoreString = Integer.toString(score);

    TextView text = (TextView) layout.findViewById(R.id.text);
    if (score < 0) {
        // red/*from w ww  .  j ava2 s.  c  o  m*/
        text.setTextColor(Color.rgb(135, 0, 0));
    } else {
        // green
        text.setTextColor(Color.rgb(0, 135, 0));
        scoreString = "+ " + score;
    }

    text.setText(getString(R.string.scoreString, scoreString)); // scoreString + " Punkte"
    text.setTypeface(Typeface.DEFAULT_BOLD);
    Toast toast = new Toast(getApplicationContext());
    toast.setDuration(Toast.LENGTH_SHORT);
    toast.setView(layout);
    toast.show();
}

From source file:com.android.gallery3d.data.UriImage.java

public Bitmap drawTextToBitmap(Context gContext, String gText, Bitmap bitmap) {
    Resources resources = gContext.getResources();
    float scale = resources.getDisplayMetrics().density;

    android.graphics.Bitmap.Config bitmapConfig = bitmap.getConfig();
    // set default bitmap config if none
    if (bitmapConfig == null) {
        bitmapConfig = android.graphics.Bitmap.Config.ARGB_8888;
    }//from w  ww .j  a v  a2 s.  c  om
    // resource bitmaps are imutable, 
    // so we need to convert it to mutable one
    bitmap = bitmap.copy(bitmapConfig, true);

    Canvas canvas = new Canvas(bitmap);
    // new antialised Paint
    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    // text color - #3D3D3D
    paint.setColor(Color.rgb(61, 61, 61));
    // text size in pixels
    paint.setTextSize((int) (25 * scale));
    // text shadow
    paint.setShadowLayer(1f, 0f, 1f, Color.WHITE);

    // draw text to the Canvas center
    Rect bounds = new Rect();
    paint.setTextAlign(Align.CENTER);

    paint.getTextBounds(gText, 0, gText.length(), bounds);
    int x = (bitmap.getWidth() - bounds.width()) / 2;
    int y = (bitmap.getHeight() + bounds.height()) / 2;

    canvas.drawText(gText, x * scale, y * scale, paint);

    return bitmap;
}

From source file:ln.paign10.arduinopixel.MainActivity.java

private void parseJsonData(String result) {
    try {/*from  w w w  .j a  va2s  .  co m*/
        JSONObject responseObject = (JSONObject) new JSONTokener(result).nextValue();

        String[] optNames = { "r", "g", "b" };
        for (int i = 0; i < 3; ++i)
            mColor[i] = responseObject.optInt(optNames[i]);

        mColorPicker.setColor(Color.rgb(mColor[0], mColor[1], mColor[2]));
        mColorPicker.postInvalidate();

    } catch (JSONException e) {
        e.printStackTrace();
    }

}

From source file:com.spoiledmilk.cykelsuperstier.navigation.SMRouteNavigationActivity.java

public void onMetroContainerClick(View v) {
    v.setBackgroundColor(isMetroSelected ? Color.rgb(255, 255, 255) : Color.rgb(236, 104, 0));
    ((ImageView) findViewById(R.id.imgCheckbox4))
            .setImageResource(isMetroSelected ? R.drawable.check_field : R.drawable.check_in_orange);
    ((ImageView) findViewById(R.id.imgMetro))
            .setImageResource(isMetroSelected ? R.drawable.metro_icon : R.drawable.metro_icon_white);
    textMetro.setTextColor(isMetroSelected ? getResources().getColor(R.color.DarkGrey) : Color.WHITE);
    if (isMetroSelected)
        getMapFragment().overlaysManager.removeMetroStations();
    else//from w  ww. jav a 2s .  c om
        getMapFragment().overlaysManager.drawMetroStations(this);
    isMetroSelected = !isMetroSelected;
}

From source file:com.google.android.apps.body.LayersLoader.java

private void loadTexture(Context context, Render.DrawGroup drawGroup) {
    if (drawGroup.texture != null) {
        int resource = TEXTURES.get(drawGroup.texture.toLowerCase());

        InputStream is = context.getResources().openRawResource(resource);
        try {//w ww  . j  a v  a 2s  . com
            ETC1Util.ETC1Texture tex = ETC1Util.createTexture(is);
            is.close();
            drawGroup.loadedCompressedDiffuseTexture = tex;
        } catch (IOException e) {
            Log.e("Body", "Loading texture: " + e);
        }
    } else {
        int[] color = { Color.rgb((int) (drawGroup.diffuseColor[0] * 255 + 0.5),
                (int) (drawGroup.diffuseColor[1] * 255 + 0.5), (int) (drawGroup.diffuseColor[2] * 255 + 0.5)) };
        Bitmap bitmap = Bitmap.createBitmap(color, 1, 1, Bitmap.Config.RGB_565);
        drawGroup.loadedDiffuseTexture = bitmap;
    }
}

From source file:com.nathanson.meterreader.fragment.BarChartFragment.java

private void setData(int count, float range) {

    // only using first meter for now.
    // TODO: graph multiple meters?
    Meter meter = mMeters.get(0);//  w  w w .  j a v a2s .  c  o m
    List<MeterReading> readings = meter.getReadings();

    ArrayList<Entry> averageEntries = new ArrayList<Entry>();

    // build up X-axis labels; e.g., dates.
    // build up Y-axis with values;
    // skip first date as we can't determine consumption.
    ArrayList<String> xVals = new ArrayList<String>();
    ArrayList<BarEntry> yVals1 = new ArrayList<BarEntry>();
    float runningTotal = 0;
    float dailyAverage;
    for (int lv = 1; lv < count; lv++) {
        MeterReading prevReading = readings.get(lv - 1);
        MeterReading currReading = readings.get(lv);

        xVals.add(removeYearFromDate(currReading.getTimeStamp()));
        float val = (currReading.getConsumption() - prevReading.getConsumption()) * 10;
        yVals1.add(new BarEntry(val, lv - 1));

        // calc & store daily average.
        runningTotal += val;
        dailyAverage = runningTotal / lv;
        averageEntries.add(new Entry(dailyAverage, lv - 1));
    }

    // TODO: allow name to be updated.
    BarDataSet set1 = new BarDataSet(yVals1, "mine");
    set1.setBarSpacePercent(35f);

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

    // bar chart data
    BarData barData = new BarData(xVals, dataSets);
    barData.setValueFormatter(new MyValueFormatter());
    barData.setValueTextSize(10f);

    // line chart data
    LineData lineData = new LineData();
    LineDataSet set = new LineDataSet(averageEntries, "average");
    int lineColor = Color.rgb(251, 169, 165);
    set.setColor(lineColor);
    set.setLineWidth(1.5f);
    set.setDrawCircles(false);
    set.setFillColor(lineColor);
    set.setDrawCubic(true);
    set.setDrawValues(false);
    set.setAxisDependency(YAxis.AxisDependency.LEFT);
    lineData.addDataSet(set);

    CombinedData combinedData = new CombinedData(getDates(meter.getReadings()));
    combinedData.setData(barData);
    combinedData.setData(lineData);

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

From source file:com.heneryh.aquanotes.ui.controllers.GraphsFragment.java

/**
 * Handle {@link VendorsQuery} {@link Cursor}.
 *//* w  ww  .j  a v a  2s  .c o m*/
private void onProbeDataQueryComplete(Cursor cursor) {
    if (mCursor != null) {
        // In case cancelOperation() doesn't work and we end up with consecutive calls to this
        // callback.
        getActivity().stopManagingCursor(mCursor);
        mCursor = null;
    }
    mySimpleXYPlot = (XYPlot) mRootView.findViewById(R.id.mySimpleXYPlot);
    mySimpleXYPlot.setOnTouchListener(this);
    mySimpleXYPlot.clear();

    //Creation of the series
    final Vector<Double> vector = new Vector<Double>();
    int numDataPoints = 0;
    String probeName = null;
    Long timestamp = (long) 0;
    String valueS = null;
    try {
        /** For each datapoint in the database, */
        while (cursor.moveToNext()) {
            probeName = cursor.getString(ProbeDataViewQuery.NAME);
            timestamp = cursor.getLong(ProbeDataViewQuery.TIMESTAMP);
            valueS = cursor.getString(ProbeDataViewQuery.VALUE);
            Double valueD = Double.valueOf(valueS);
            vector.add(timestamp.doubleValue());
            vector.add(valueD);
            numDataPoints++;
        } // end of while()
    } finally {
        cursor.close();
        if (numDataPoints < 2)
            return;
    }
    // create our series from our array of nums:
    mySeries = new SimpleXYSeries(vector, ArrayFormat.XY_VALS_INTERLEAVED, probeName);

    mySimpleXYPlot.getGraphWidget().getGridBackgroundPaint().setColor(Color.WHITE);
    mySimpleXYPlot.getGraphWidget().getGridLinePaint().setColor(Color.BLACK);
    mySimpleXYPlot.getGraphWidget().getGridLinePaint()
            .setPathEffect(new DashPathEffect(new float[] { 1, 1 }, 1));
    mySimpleXYPlot.getGraphWidget().getDomainOriginLinePaint().setColor(Color.BLACK);
    mySimpleXYPlot.getGraphWidget().getRangeOriginLinePaint().setColor(Color.BLACK);

    mySimpleXYPlot.setBorderStyle(Plot.BorderStyle.SQUARE, null, null);
    mySimpleXYPlot.getBorderPaint().setStrokeWidth(1);
    mySimpleXYPlot.getBorderPaint().setAntiAlias(false);
    mySimpleXYPlot.getBorderPaint().setColor(Color.WHITE);

    // Create a formatter to use for drawing a series using LineAndPointRenderer:
    LineAndPointFormatter series1Format = new LineAndPointFormatter(Color.rgb(0, 100, 0), // line color
            Color.rgb(0, 100, 0), // point color
            Color.rgb(100, 200, 0)); // fill color

    // setup our line fill paint to be a slightly transparent gradient:
    Paint lineFill = new Paint();
    lineFill.setAlpha(200);
    //lineFill.setShader(new LinearGradient(0, 0, 0, 250, Color.WHITE, Color.GREEN, Shader.TileMode.MIRROR));

    LineAndPointFormatter formatter = new LineAndPointFormatter(Color.rgb(0, 0, 0), Color.BLUE, Color.RED);
    //       formatter.setFillPaint(lineFill);
    formatter.setFillPaint(null);
    //       formatter.setVertexPaint(null);
    formatter.getLinePaint().setShadowLayer(0, 0, 0, 0);
    mySimpleXYPlot.getGraphWidget().setPaddingRight(2);
    mySimpleXYPlot.addSeries(mySeries, formatter);

    // draw a domain tick for each year:
    //mySimpleXYPlot.setDomainStep(XYStepMode.SUBDIVIDE, numDataPoints);

    // customize our domain/range labels
    mySimpleXYPlot.setDomainLabel("Time");
    mySimpleXYPlot.setRangeLabel(probeName);

    // get rid of decimal points in our range labels:
    mySimpleXYPlot.setRangeValueFormat(new DecimalFormat("#0.00"));

    mySimpleXYPlot.setDomainValueFormat(new MyDateFormat());

    // by default, AndroidPlot displays developer guides to aid in laying out your plot.
    // To get rid of them call disableAllMarkup():
    mySimpleXYPlot.disableAllMarkup();

    //Set of internal variables for keeping track of the boundaries
    mySimpleXYPlot.calculateMinMaxVals();
    minXY = new PointF(mySimpleXYPlot.getCalculatedMinX().floatValue(),
            mySimpleXYPlot.getCalculatedMinY().floatValue()); //initial minimum data point
    absMinX = minXY.x; //absolute minimum data point
    //absolute minimum value for the domain boundary maximum
    minNoError = Math.round(mySeries.getX(1).floatValue() + 2);
    maxXY = new PointF(mySimpleXYPlot.getCalculatedMaxX().floatValue(),
            mySimpleXYPlot.getCalculatedMaxY().floatValue()); //initial maximum data point
    absMaxX = maxXY.x; //absolute maximum data point
    //absolute maximum value for the domain boundary minimum
    maxNoError = (float) Math.round(mySeries.getX(mySeries.size() - 1).floatValue()) - 2;

    //Check x data to find the minimum difference between two neighboring domain values
    //Will use to prevent zooming further in than this distance
    double temp1 = mySeries.getX(0).doubleValue();
    double temp2 = mySeries.getX(1).doubleValue();
    double temp3;
    double thisDif;
    minDif = 100000000; //increase if necessary for domain values
    for (int i = 2; i < mySeries.size(); i++) {
        temp3 = mySeries.getX(i).doubleValue();
        thisDif = Math.abs(temp1 - temp3);
        if (thisDif < minDif)
            minDif = thisDif;
        temp1 = temp2;
        temp2 = temp3;
    }
    minDif = minDif + difPadding; //with padding, the minimum difference

    mySimpleXYPlot.redraw();

}

From source file:net.zorgblub.typhon.Configuration.java

public Configuration(Context context) {
    this.settings = PreferenceManager.getDefaultSharedPreferences(context);
    this.context = context;

    if (IS_NOOK_TOUCH) {
        defaultSerifFont = "serif";
        defaultSansFont = "sans";
    } else {/*from ww  w.ja  v a2 s .c  o m*/
        defaultSerifFont = "gen_book_bas";
        defaultSansFont = "sans";
    }

    // On Nook Touch, preset some different defaults on first load
    // (these values work better w/ e-ink)
    if (IS_NOOK_TOUCH && this.settings.getString(KEY_DEVICE_NAME, null) == null) {
        SharedPreferences.Editor editor = this.settings.edit();
        editor.putString(KEY_FONT_FACE, "sans");
        editor.putString(KEY_SERIF_FONT, "serif");

        editor.putInt(KEY_TEXT_SIZE, 32);
        editor.putString(KEY_SCROLL_STYLE, "timer"); // enum is ScrollStyle.PAGE_TIMER
        final String no_animation = AnimationStyle.NONE.name().toLowerCase(Locale.US);
        editor.putString(KEY_H_ANIMATION, no_animation);
        editor.putString(KEY_V_ANIMATION, no_animation);
        editor.putInt(PREFIX_DAY + "_" + KEY_LINK, Color.rgb(0x40, 0x40, 0x40));
        editor.putInt(PREFIX_NIGHT + "_" + KEY_TEXT, Color.WHITE);
        editor.putInt(PREFIX_NIGHT + "_" + KEY_LINK, Color.rgb(0xb0, 0xb0, 0xb0));
        editor.commit();
    }
}