I am drawing a line segment with the specified start and stop x,y coordinates, using the specified paint on the following Bitmap image for each day dynamically -
chart_by_rule (Unexpected in >= 4.4) -
chart_by_rule (Expected) -
The following code should draw the line in the above bitmap. The lines are only drawn in Android versions < 4.4.
This is the code -
@Override
public View onCreateView(LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState)
{
getActivity().runOnUiThread(new Runnable()
{
@Override
public void run()
{
getChartLoaded();
}
});
}
public void getChartLoaded()
{
if(dates_array.indexOf(today) == -1 || (redrawChart != null && redrawChart.equals("popback")) || (getSetting("ZoneIDChanged","0").equals("1")))
{
redrawChartView(scal, zeroPadding, zeroPaddingDate);
setSetting("ZoneIDChanged","0");
}
else
{
addChartViews(scal, zeroPadding, zeroPaddingDate);
}
}
public void redrawChartView(Calendar scal,
String zeroPadding, String zeroPaddingDate)
{
Calendar cal = Calendar.getInstance(TimeZone.getTimeZone(driverTimeZone));
while (scal.compareTo(cal) < 0) {
cv = new ChartView();
LinearLayout layout = cv.getChartView(i);
i++;
linearLayoutMap.put(date, layout);
views.add(layout);
}
}
public class ChartView
{
private Paint cPaint;
float startHours = 0, endHours = 0,
startHeight = 0, endHeight = 0,
scale = 0;
public LinearLayout getChartView(final int number)
{
getActivity().runOnUiThread(new Runnable()
{
@Override
public void run() {
cPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
cPaint.setStyle(Paint.Style.STROKE);
cPaint.setColor(Color.BLACK);
cPaint.setStrokeWidth(3);
scale = getActivity().getBaseContext().getResources()
.getDisplayMetrics().density;
linearlayout = new LinearLayout(getActivity());
final ImageView img = new ImageView(getActivity());
BitmapFactory.Options options = new BitmapFactory.Options();
options.inPurgeable = true;
newBitmap = BitmapFactory.decodeResource(getResources(),
chart_by_rule).copy(Bitmap.Config.ARGB_4444, true);
canvas = new Canvas(newBitmap);
img.setImageBitmap(newBitmap);
img.setScaleType(ScaleType.FIT_XY);
img.setTag(number);
float wFactor = (15 * scale);
float hFactor = (float) ((19.35) * scale);
float x1 = startHours * wFactor;
float x2 = endHours * wFactor;
float y1 = (2 * startHeight - 1) * hFactor;
float y2 = (2 * endHeight - 1) * hFactor;
canvas.drawLine(x1, y1, x2, y2, cPaint);
canvas.save(Canvas.ALL_SAVE_FLAG);
linearlayout.addView(img);
}
});
return linearlayout;
}
}
This code is working fine in all the android versions smaller then 4.4.
In Android OS >= 4.4
, I am getting no line drawn with the canvas on my linear layout that contains the image view.
Is there any change in these later OS versions regarding Canvas OR the problem can be somewhere else ?
More: I have different layout files for all the screen layouts.
This was checked with Motorola XT907
.
This is the phone specification - http://wiki.cyanogenmod.org/w/Xt907_Info.