Update color programmatically - android

I draw lines in the Google Map and how can I update the color in the program?
map.addPolyline(new PolylineOptions()
.add(latlngArray)
.width(5)
.color(Color.CYAN)
.geodesic(true));
Color.CYAN is the line color. Under certain condition, I need to show the line with different colors. How can I change the Color.CYAN with another color on runtime?

You can try doing something like this:
map.addPolyline(new PolylineOptions()
.add(latlngArray)
.width(5)
.color( Color.parseColor( "#AARRGGBB" ) )
.geodesic(true));
Where A is alpha, and RGB is your typical red, green, blue color mapping. Then you can use any string color you want.

mGoogleMap.addPolyline(new PolylineOptions()
.add(latlngArray)
.width(5)
.color( getResources().getColor(R.color.colorPrimary) )
.geodesic(true));
It's for working me

Related

Draw a line on a map but the line not a road

How can I draw a line on a map to detect a live location on that line.
but the line won't be on a road (street), it is a well known line on the map
using google map API.
You can draw a line with
Polyline polyline1 = googleMap.addPolyline(new PolylineOptions()
.clickable(true)
.add(
new LatLng(-35.016, 143.321),
new LatLng(-34.747, 145.592),
new LatLng(-34.364, 147.891),
new LatLng(-33.501, 150.217),
new LatLng(-32.306, 149.248),
new LatLng(-32.491, 147.309)));
Check documentation

How to make 2 colored text in a line in a marker infowindow?

I would like to make a marker info window, which has 3 lines, and every singe line contains 2 colors.
I made the 3 lines with the help of
mMap.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter()
but i am stucked with the colors.
Please Help :)
You can use SpannableString to set multiple color in single string sentence in TextView or other text enabled component
String strMessage="I am android developer";
Spannable spannable = new SpannableString(strMessage);
//"I am android" red colored
spannable.setSpan(getTextAppearanceSpan(ContextCompat.getColor(mContext, android.R.color.RED)), 0, 12, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
textView.setText(spannable);
//"developer" blue colored
spannable.setSpan(getTextAppearanceSpan(ContextCompat.getColor(mContext, android.R.color.BLUE)), 14, strMessage.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
textView.setText(spannable);
TextAppearanceSpan method to customized text with color
/*
*get customized text with color, style
*/
private TextAppearanceSpan getTextAppearanceSpan(int color) {
ColorStateList blueColor1 = new ColorStateList(new int[][]{new int[]{}}, new int[]{color});
return new TextAppearanceSpan(null, Typeface.NORMAL, -1, blueColor1, null);
}

How do I achieve this Gradiant color if it possible at all?

I made this Icon in Photoshop, but now I want to make the gradiant in Android and use it as the Textcolor for a Textview
The colors and settings from Photoshop is:
Style: Linear
Angle: 90*
Colors: #00a8d9 (0%), #223595 (20%), #f1328f(40%), #ee3031(60%), #f9e63a(80%), #009958(100%)
The numbers in the parentes is the location value.
I have tried the following, but its only showing one color
LinearGradient linearGradient = new LinearGradient(20,30,40,50, new int[] {Color.parseColor("#00a8d9"), Color.parseColor("#223595"), Color.parseColor("#f1328f"), Color.parseColor("#ee3031"), Color.parseColor("#f9e63a"), Color.parseColor("#009958")},new float[]{0,0,0,0,0,0},
Shader.TileMode.REPEAT);
textView.getPaint().setShader(linearGradient);
I managed to replicate the gradient from the picture to the code with this solution:
textView = (TextView) v.findViewById(R.id.fontcolorwhite);
LinearGradient linearGradient = new LinearGradient(60,-70,60,70, new int[]{Color.parseColor("#00a8d9"), Color.parseColor("#4244b8"), Color.parseColor("#f1328f"), Color.parseColor("#ee3031"), Color.parseColor("#fde92d"), Color.parseColor("#009e54")},null,
Shader.TileMode.MIRROR);
textView.getPaint().setShader(linearGradient);
Another problem is that the gradient dosn't look the same with different screen sizes. This will be in a another question
You may Try this.
Try to set this as your view background colour and set colour as per your need.
GradientDrawable rainbow = new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM,
new int[] {Color.RED, Color.MAGENTA, Color.BLUE, Color.CYAN, Color.GREEN, Color.YELLOW, Color.RED});
textview.setBackground(rainbow);

Android achartengine FillOutsideLine with gradient color

Can we use a gradient style for FillOutsideLine of achartlibrary to color the below side of the line ?
so far I managed to use simple Color.argb(), but I can't use any xml to make it gradient or it will crash
can we fix this issue ?
code:
FillOutsideLine fill = new FillOutsideLine(FillOutsideLine.Type.BOUNDS_ALL);
fill.setColor(Color.argb(55, 62, 117, 163));
renderer.addFillOutsideLine(fill);
Well, it's bit tricky, but you can set FillOutsideLine ABOVE with your background color, make chart background transparent, and add gradient background to GraphicalView.
Upd
I'm using Xamarin for now, that's why C#. Anyway, hope it helps :)
XYSeriesRenderer renderer = new XYSeriesRenderer();
...
//Set up fill
XYSeriesRenderer.FillOutsideLine fill = new XYSeriesRenderer.FillOutsideLine(XYSeriesRenderer.FillOutsideLine.FillOutsideLineBehaviorType.Above);
fill.Color = Color.White.ToAndroid();
renderer.AddFillOutsideLine(fill);
XYMultipleSeriesRenderer mRenderer = new XYMultipleSeriesRenderer();
mRenderer.AddSeriesRenderer(renderer);
//Set chart background
mRenderer.BackgroundColor = Color.Transparent.ToAndroid();
...
chartView = ChartFactory.GetLineChartView(Forms.Context, dataset, mRenderer);
//Set gradient background
chartView.SetBackgroundResource(Droid.Resource.Drawable.chart_gradient);

Android plot removing the black border or change the color of border to white

I tried lot of methods to remove the black border in the android plot .. But none of them is working.
When I tried this method
dynamicPlot.getGraphWidget().getBorderPaint().setColor(Color.TRANSPARENT);
it is crashing..
this the code used for plotting
dynamicPlot = (MultitouchPlot) findViewById(R.id.dynamicPlot);
dynamicPlot.getGraphWidget().getBackgroundPaint().setColor(color.white);
createNewGraph(dynamicPlot, 150);
dynamicPlot.setDomainLabel("Sensor data logging");
dynamicPlot.setDomainBoundaries(0, 110, BoundaryMode.FIXED);
historyData = new SimpleXYSeries(" Reading");
historyData.useImplicitXVals();
dynamicPlot.addSeries(historyData,
new LineAndPointFormatter(Color.BLUE,
Color.BLACK, Color.WHITE , null));
dynamicPlot.setDomainStepValue(5);
//dynamicPlot.setBackgroundColor(Color.WHITE);
//dynamicPlot.setGridPadding(0,0 ,0,0);
dynamicPlot.setTicksPerRangeLabel(3);
dynamicPlot.setBackgroundColor(Color.WHITE);
//dynamicPlot.getLayoutManager().remove(dynamicPlot.removeXMarkers());
dynamicPlot.getDomainLabelWidget().pack();
dynamicPlot.setRangeLabel("Units");
dynamicPlot.getRangeLabelWidget().pack();
dynamicPlot.getGraphWidget()
.setRangeValueFormat(new DecimalFormat("0"));
dynamicPlot.getGraphWidget().setDomainValueFormat(
new DecimalFormat("0"));
dynamicPlot.getGraphWidget().getGridBackgroundPaint().setColor(Color.WHITE);
dynamicPlot.getGraphWidget().getRangeOriginLabelPaint().setColor(Color.WHITE);
dynamicPlot.getBackgroundPaint().setColor(Color.WHITE);
//dynamicPlot.getGraphWidget().getGridBackgroundPaint().setColor(Color.TRANSPARENT);
dynamicPlot.getGraphWidget().getDomainLabelPaint().setColor(Color.BLACK);
dynamicPlot.getGraphWidget().getRangeLabelPaint().setColor(Color.BLACK);
//dynamicPlot.getGraphWidget().getBackgroundPaint().setColor(Color.WHITE);
//dynamicPlot.getGraphWidget().getBorderPaint().setColor(Color.TRANSPARENT);
Help me to remove this black border
I got the same problem and this question solved it :
androidPlot black border
All you have to do is :
dynamicPlot.setPlotMargins(0, 0, 0, 0);
and there will be no more black border.
Hope it helps.
Check out if you have turned to null the GridBackgroundPaint before call the method
plot.getGraphWidget().setGridBackgroundPaint(null);
or something like that in the upper lines.

Categories

Resources