Merge pull request #512 from PoweRGbg/patch-3

ProfileSwitch on graph depending on ScreenSize
This commit is contained in:
Milos Kozak 2017-12-04 12:49:01 +01:00 committed by GitHub
commit 812583059a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 41 additions and 30 deletions

View file

@ -54,7 +54,7 @@ public class Constants {
//Screen: Threshold for width/height to go into small width/height layout //Screen: Threshold for width/height to go into small width/height layout
public static final int SMALL_WIDTH = 320; public static final int SMALL_WIDTH = 320;
public static final int SMALL_HEIGHT = 320; public static final int SMALL_HEIGHT = 480;
//Autosens //Autosens
public static final double DEVIATION_TO_BE_EQUAL = 2.0; public static final double DEVIATION_TO_BE_EQUAL = 2.0;

View file

@ -192,8 +192,8 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm); getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm);
int screen_width = dm.widthPixels; int screen_width = dm.widthPixels;
int screen_height = dm.heightPixels; int screen_height = dm.heightPixels;
smallWidth = screen_width < Constants.SMALL_WIDTH; smallWidth = screen_width <= Constants.SMALL_WIDTH;
smallHeight = screen_height < Constants.SMALL_HEIGHT; smallHeight = screen_height <= Constants.SMALL_HEIGHT;
boolean landscape = screen_height < screen_width; boolean landscape = screen_height < screen_width;
View view; View view;

View file

@ -194,7 +194,7 @@ public class GraphData {
basalsLineSeries = new LineGraphSeries<>(basalLine); basalsLineSeries = new LineGraphSeries<>(basalLine);
Paint paint = new Paint(); Paint paint = new Paint();
paint.setStyle(Paint.Style.STROKE); paint.setStyle(Paint.Style.STROKE);
paint.setStrokeWidth(2); paint.setStrokeWidth(MainApp.instance().getApplicationContext().getResources().getDisplayMetrics().scaledDensity*2);
paint.setPathEffect(new DashPathEffect(new float[]{2, 4}, 0)); paint.setPathEffect(new DashPathEffect(new float[]{2, 4}, 0));
paint.setColor(MainApp.sResources.getColor(R.color.basal)); paint.setColor(MainApp.sResources.getColor(R.color.basal));
basalsLineSeries.setCustomPaint(paint); basalsLineSeries.setCustomPaint(paint);
@ -204,7 +204,7 @@ public class GraphData {
absoluteBasalsLineSeries = new LineGraphSeries<>(absoluteBasalLine); absoluteBasalsLineSeries = new LineGraphSeries<>(absoluteBasalLine);
Paint absolutePaint = new Paint(); Paint absolutePaint = new Paint();
absolutePaint.setStyle(Paint.Style.STROKE); absolutePaint.setStyle(Paint.Style.STROKE);
absolutePaint.setStrokeWidth(4); absolutePaint.setStrokeWidth(MainApp.instance().getApplicationContext().getResources().getDisplayMetrics().scaledDensity*2);
absolutePaint.setColor(MainApp.sResources.getColor(R.color.basal)); absolutePaint.setColor(MainApp.sResources.getColor(R.color.basal));
absoluteBasalsLineSeries.setCustomPaint(absolutePaint); absoluteBasalsLineSeries.setCustomPaint(absolutePaint);

View file

@ -30,7 +30,10 @@ import android.graphics.Path;
import android.graphics.Point; import android.graphics.Point;
import android.graphics.Rect; import android.graphics.Rect;
import android.graphics.Typeface; import android.graphics.Typeface;
import android.util.TypedValue;
// Added by Rumen for scalable text
import android.content.Context;
import info.nightscout.androidaps.MainApp;
import com.jjoe64.graphview.GraphView; import com.jjoe64.graphview.GraphView;
import com.jjoe64.graphview.series.BaseSeries; import com.jjoe64.graphview.series.BaseSeries;
@ -44,6 +47,13 @@ import java.util.Iterator;
* @author jjoe64 * @author jjoe64
*/ */
public class PointsWithLabelGraphSeries<E extends DataPointWithLabelInterface> extends BaseSeries<E> { public class PointsWithLabelGraphSeries<E extends DataPointWithLabelInterface> extends BaseSeries<E> {
// Default spSize
int spSize = 12;
// Convert the sp to pixels
Context context = MainApp.instance().getApplicationContext();
float scaledTextSize = spSize * context.getResources().getDisplayMetrics().scaledDensity;
float scaledPxSize = context.getResources().getDisplayMetrics().scaledDensity * 1.5f;
/** /**
* choose a predefined shape to render for * choose a predefined shape to render for
* each data point. * each data point.
@ -193,22 +203,22 @@ public class PointsWithLabelGraphSeries<E extends DataPointWithLabelInterface> e
if (!overdraw) { if (!overdraw) {
if (value.getShape() == Shape.POINT) { if (value.getShape() == Shape.POINT) {
mPaint.setStrokeWidth(0); mPaint.setStrokeWidth(0);
canvas.drawCircle(endX, endY, value.getSize(), mPaint); canvas.drawCircle(endX, endY, scaledPxSize, mPaint);
} else if (value.getShape() == Shape.RECTANGLE) { } else if (value.getShape() == Shape.RECTANGLE) {
canvas.drawRect(endX-value.getSize(), endY-value.getSize(), endX+value.getSize(), endY+value.getSize(), mPaint); canvas.drawRect(endX-scaledPxSize, endY-scaledPxSize, endX+scaledPxSize, endY+scaledPxSize, mPaint);
} else if (value.getShape() == Shape.TRIANGLE) { } else if (value.getShape() == Shape.TRIANGLE) {
mPaint.setStrokeWidth(0); mPaint.setStrokeWidth(0);
Point[] points = new Point[3]; Point[] points = new Point[3];
points[0] = new Point((int)endX, (int)(endY-value.getSize())); points[0] = new Point((int)endX, (int)(endY-scaledPxSize));
points[1] = new Point((int)(endX+value.getSize()), (int)(endY+value.getSize()*0.67)); points[1] = new Point((int)(endX+scaledPxSize), (int)(endY+scaledPxSize*0.67));
points[2] = new Point((int)(endX-value.getSize()), (int)(endY+value.getSize()*0.67)); points[2] = new Point((int)(endX-scaledPxSize), (int)(endY+scaledPxSize*0.67));
drawArrows(points, canvas, mPaint); drawArrows(points, canvas, mPaint);
} else if (value.getShape() == Shape.BOLUS) { } else if (value.getShape() == Shape.BOLUS) {
mPaint.setStrokeWidth(0); mPaint.setStrokeWidth(0);
Point[] points = new Point[3]; Point[] points = new Point[3];
points[0] = new Point((int)endX, (int)(endY-value.getSize())); points[0] = new Point((int)endX, (int)(endY-scaledPxSize));
points[1] = new Point((int)(endX+value.getSize()), (int)(endY+value.getSize()*0.67)); points[1] = new Point((int)(endX+scaledPxSize), (int)(endY+scaledPxSize*0.67));
points[2] = new Point((int)(endX-value.getSize()), (int)(endY+value.getSize()*0.67)); points[2] = new Point((int)(endX-scaledPxSize), (int)(endY+scaledPxSize*0.67));
mPaint.setStyle(Paint.Style.FILL_AND_STROKE); mPaint.setStyle(Paint.Style.FILL_AND_STROKE);
drawArrows(points, canvas, mPaint); drawArrows(points, canvas, mPaint);
if (value.getLabel() != null) { if (value.getLabel() != null) {
@ -220,7 +230,7 @@ public class PointsWithLabelGraphSeries<E extends DataPointWithLabelInterface> e
Rect bounds = new Rect((int)endX, (int)endY + 3, (int) (xpluslength), (int) endY + 8); Rect bounds = new Rect((int)endX, (int)endY + 3, (int) (xpluslength), (int) endY + 8);
mPaint.setStyle(Paint.Style.FILL_AND_STROKE); mPaint.setStyle(Paint.Style.FILL_AND_STROKE);
canvas.drawRect(bounds, mPaint); canvas.drawRect(bounds, mPaint);
mPaint.setTextSize((int) (value.getSize() * 2.5)); mPaint.setTextSize((int) (scaledTextSize * 2.5));
mPaint.setTypeface(Typeface.create(Typeface.DEFAULT, Typeface.NORMAL)); mPaint.setTypeface(Typeface.create(Typeface.DEFAULT, Typeface.NORMAL));
mPaint.setFakeBoldText(true); mPaint.setFakeBoldText(true);
canvas.drawText(value.getLabel(), endX, endY, mPaint); canvas.drawText(value.getLabel(), endX, endY, mPaint);
@ -228,7 +238,8 @@ public class PointsWithLabelGraphSeries<E extends DataPointWithLabelInterface> e
} else if (value.getShape() == Shape.PROFILE) { } else if (value.getShape() == Shape.PROFILE) {
mPaint.setStrokeWidth(0); mPaint.setStrokeWidth(0);
if (value.getLabel() != null) { if (value.getLabel() != null) {
mPaint.setTextSize((int) (value.getSize() * 3)); //mPaint.setTextSize((int) (scaledPxSize * 3));
mPaint.setTextSize((float) (scaledTextSize*1.2));
mPaint.setTypeface(Typeface.create(Typeface.DEFAULT, Typeface.BOLD)); mPaint.setTypeface(Typeface.create(Typeface.DEFAULT, Typeface.BOLD));
Rect bounds = new Rect(); Rect bounds = new Rect();
mPaint.getTextBounds(value.getLabel(), 0, value.getLabel().length(), bounds); mPaint.getTextBounds(value.getLabel(), 0, value.getLabel().length(), bounds);
@ -245,25 +256,25 @@ public class PointsWithLabelGraphSeries<E extends DataPointWithLabelInterface> e
mPaint.setStyle(Paint.Style.STROKE); mPaint.setStyle(Paint.Style.STROKE);
mPaint.setStrokeWidth(5); mPaint.setStrokeWidth(5);
float w = mPaint.getStrokeWidth(); float w = mPaint.getStrokeWidth();
canvas.drawCircle(endX, endY, value.getSize(), mPaint); canvas.drawCircle(endX, endY, scaledPxSize, mPaint);
} else if (value.getShape() == Shape.BGCHECK) { } else if (value.getShape() == Shape.BGCHECK) {
mPaint.setStyle(Paint.Style.FILL_AND_STROKE); mPaint.setStyle(Paint.Style.FILL_AND_STROKE);
mPaint.setStrokeWidth(0); mPaint.setStrokeWidth(0);
canvas.drawCircle(endX, endY, value.getSize(), mPaint); canvas.drawCircle(endX, endY, scaledPxSize, mPaint);
if (value.getLabel() != null) { if (value.getLabel() != null) {
drawLabel45(endX, endY, value, canvas); drawLabel45(endX, endY, value, canvas);
} }
} else if (value.getShape() == Shape.ANNOUNCEMENT) { } else if (value.getShape() == Shape.ANNOUNCEMENT) {
mPaint.setStyle(Paint.Style.FILL_AND_STROKE); mPaint.setStyle(Paint.Style.FILL_AND_STROKE);
mPaint.setStrokeWidth(0); mPaint.setStrokeWidth(0);
canvas.drawCircle(endX, endY, value.getSize(), mPaint); canvas.drawCircle(endX, endY, scaledPxSize, mPaint);
if (value.getLabel() != null) { if (value.getLabel() != null) {
drawLabel45(endX, endY, value, canvas); drawLabel45(endX, endY, value, canvas);
} }
} else if (value.getShape() == Shape.GENERAL) { } else if (value.getShape() == Shape.GENERAL) {
mPaint.setStyle(Paint.Style.FILL_AND_STROKE); mPaint.setStyle(Paint.Style.FILL_AND_STROKE);
mPaint.setStrokeWidth(0); mPaint.setStrokeWidth(0);
canvas.drawCircle(endX, endY, value.getSize(), mPaint); canvas.drawCircle(endX, endY, scaledPxSize, mPaint);
if (value.getLabel() != null) { if (value.getLabel() != null) {
drawLabel45(endX, endY, value, canvas); drawLabel45(endX, endY, value, canvas);
} }
@ -271,7 +282,7 @@ public class PointsWithLabelGraphSeries<E extends DataPointWithLabelInterface> e
mPaint.setStrokeWidth(0); mPaint.setStrokeWidth(0);
if (value.getLabel() != null) { if (value.getLabel() != null) {
mPaint.setStrokeWidth(0); mPaint.setStrokeWidth(0);
mPaint.setTextSize((int) (value.getSize() * 3)); mPaint.setTextSize((int) (scaledTextSize * 3));
mPaint.setTypeface(Typeface.create(Typeface.DEFAULT, Typeface.BOLD)); mPaint.setTypeface(Typeface.create(Typeface.DEFAULT, Typeface.BOLD));
Rect bounds = new Rect(); Rect bounds = new Rect();
mPaint.getTextBounds(value.getLabel(), 0, value.getLabel().length(), bounds); mPaint.getTextBounds(value.getLabel(), 0, value.getLabel().length(), bounds);
@ -286,7 +297,7 @@ public class PointsWithLabelGraphSeries<E extends DataPointWithLabelInterface> e
mPaint.setStrokeWidth(0); mPaint.setStrokeWidth(0);
if (value.getLabel() != null) { if (value.getLabel() != null) {
mPaint.setStrokeWidth(0); mPaint.setStrokeWidth(0);
mPaint.setTextSize((int) (value.getSize() * 3)); mPaint.setTextSize(scaledTextSize);
mPaint.setTypeface(Typeface.create(Typeface.DEFAULT, Typeface.BOLD)); mPaint.setTypeface(Typeface.create(Typeface.DEFAULT, Typeface.BOLD));
Rect bounds = new Rect(); Rect bounds = new Rect();
mPaint.getTextBounds(value.getLabel(), 0, value.getLabel().length(), bounds); mPaint.getTextBounds(value.getLabel(), 0, value.getLabel().length(), bounds);
@ -301,7 +312,7 @@ public class PointsWithLabelGraphSeries<E extends DataPointWithLabelInterface> e
mPaint.setStrokeWidth(0); mPaint.setStrokeWidth(0);
if (value.getLabel() != null) { if (value.getLabel() != null) {
mPaint.setStrokeWidth(0); mPaint.setStrokeWidth(0);
mPaint.setTextSize((int) (value.getSize() * 3)); mPaint.setTextSize(scaledTextSize * 3);
mPaint.setTypeface(Typeface.create(Typeface.DEFAULT, Typeface.BOLD)); mPaint.setTypeface(Typeface.create(Typeface.DEFAULT, Typeface.BOLD));
Rect bounds = new Rect(); Rect bounds = new Rect();
mPaint.getTextBounds(value.getLabel(), 0, value.getLabel().length(), bounds); mPaint.getTextBounds(value.getLabel(), 0, value.getLabel().length(), bounds);
@ -352,26 +363,26 @@ public class PointsWithLabelGraphSeries<E extends DataPointWithLabelInterface> e
void drawLabel45(float endX, float endY, E value, Canvas canvas) { void drawLabel45(float endX, float endY, E value, Canvas canvas) {
if (value.getLabel().startsWith("~")) { if (value.getLabel().startsWith("~")) {
float px = endX; float px = endX;
float py = endY + value.getSize(); float py = endY + scaledPxSize;
canvas.save(); canvas.save();
canvas.rotate(-45, px, py); canvas.rotate(-45, px, py);
mPaint.setTextSize((int) (value.getSize() * 2.5)); mPaint.setTextSize((float) (scaledTextSize*0.8));
mPaint.setTypeface(Typeface.create(Typeface.DEFAULT, Typeface.NORMAL)); mPaint.setTypeface(Typeface.create(Typeface.DEFAULT, Typeface.NORMAL));
mPaint.setFakeBoldText(true); mPaint.setFakeBoldText(true);
mPaint.setTextAlign(Paint.Align.RIGHT); mPaint.setTextAlign(Paint.Align.RIGHT);
canvas.drawText(value.getLabel().substring(1), px - value.getSize(), py, mPaint); canvas.drawText(value.getLabel().substring(1), px - scaledPxSize, py, mPaint);
mPaint.setTextAlign(Paint.Align.LEFT); mPaint.setTextAlign(Paint.Align.LEFT);
canvas.restore(); canvas.restore();
} else { } else {
float px = endX; float px = endX;
float py = endY - value.getSize(); float py = endY - scaledPxSize;
canvas.save(); canvas.save();
canvas.rotate(-45, px, py); canvas.rotate(-45, px, py);
mPaint.setTextSize((int) (value.getSize() * 2.5)); mPaint.setTextSize((float) (scaledTextSize*0.8));
mPaint.setTypeface(Typeface.create(Typeface.DEFAULT, Typeface.NORMAL)); mPaint.setTypeface(Typeface.create(Typeface.DEFAULT, Typeface.NORMAL));
mPaint.setFakeBoldText(true); mPaint.setFakeBoldText(true);
canvas.drawText(value.getLabel(), px + value.getSize(), py, mPaint); canvas.drawText(value.getLabel(), px + scaledPxSize, py, mPaint);
canvas.restore(); canvas.restore();
} }
} }
} }