1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197
| package com.co.and.xxxxx.atcs;
import android.app.Dialog;
import android.content.Context;
//import android.content.Intent;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.LinearGradient;
import android.graphics.Paint;
import android.graphics.RectF;
import android.graphics.Shader;
import android.support.annotation.NonNull;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.MotionEvent;
//import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import android.view.View;
import android.app.AlertDialog;
//import android.view.ActionMode;
/**
* Created by xxxxxx on 08/12/15.
*/
public class ResultView extends ImageView {
private Paint monPaint, monPaint2, monPaint3;
private RectF rect;
private String txt;
public int[] notesType = new int[6];
public String[] tTypes = {"PNF", "PNR", "ADU", "EAS", "EAR", "ESP"};
public String txt2;
private View maVue;
private int l, h;
private int contentView;
private final static int ID_PNF = 0;
private final static int ID_PNR = 1;
public ResultActivity monAct = null;
TextView pTitre, pTexte = null;
public Dialog box = null;
private static final String TAG = ResultView.class.getSimpleName();
public ResultView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init();
}
public ResultView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public ResultView(Context context) {
super(context);
init();
}
private void init() {
monPaint = new Paint();
monPaint2 = new Paint();
monPaint3 = new Paint();
monPaint.setAntiAlias(true);
monPaint.setDither(true);
monPaint.setStyle(Paint.Style.STROKE);
monPaint.setStrokeJoin(Paint.Join.ROUND);
monPaint.setStrokeCap(Paint.Cap.ROUND);
monPaint.setStrokeWidth(2);
monPaint.setShader(new LinearGradient(0.40f, 0.0f, 100.60f, 100.0f,
Color.BLUE,
Color.BLUE,
Shader.TileMode.MIRROR));
monPaint2.setAntiAlias(true);
monPaint2.setDither(true);
monPaint2.setStrokeJoin(Paint.Join.ROUND);
monPaint2.setStrokeCap(Paint.Cap.ROUND);
monPaint2.setStrokeWidth(2);
monPaint2.setShader(new LinearGradient(0.40f, 0.0f, 100.60f, 100.0f,
Color.RED,
Color.RED,
Shader.TileMode.CLAMP));
monPaint2.setStyle(Paint.Style.FILL_AND_STROKE);
/* monPaint3.setAntiAlias(true);
monPaint3.setDither(true);
monPaint3.setStrokeJoin(Paint.Join.ROUND);
monPaint3.setStrokeCap(Paint.Cap.ROUND);*/
monPaint3.setStrokeWidth(12);
monPaint3.setShader(new LinearGradient(0.40f, 0.0f, 100.60f, 100.0f,
Color.BLUE,
Color.BLUE,
Shader.TileMode.CLAMP));
monPaint3.setStyle(Paint.Style.FILL);
maVue = findViewById(R.id.maVue);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
l = getWidth() - 5;
h = getHeight() - 5;
//
// Affichage des axes
//
drawAxes(canvas, l, h);
//
// Affichages des barres de catégories.
//
canvas.drawRect(5 * l / 26, 7 * h / 8 - notesType[0] * 3 * h / 120, 7 * l / 26, 7 * h / 8, monPaint2);
canvas.drawRect(8 * l / 26, 7 * h / 8 - notesType[1] * 3 * h / 120, 10 * l / 26, 7 * h / 8, monPaint2);
canvas.drawRect(11 * l / 26, 7 * h / 8 - notesType[2] * 3 * h / 120, 13 * l / 26, 7 * h / 8, monPaint2);
canvas.drawRect(14 * l / 26, 7 * h / 8 - notesType[3] * 3 * h / 120, 16 * l / 26, 7 * h / 8, monPaint2);
canvas.drawRect(17 * l / 26, 7 * h / 8 - notesType[4] * 3 * h / 120, 19 * l / 26, 7 * h / 8, monPaint2);
canvas.drawRect(20 * l / 26, 7 * h / 8 - notesType[5] * 3 * h / 120, 22 * l / 26, 7 * h / 8, monPaint2);
//
// Affichage des valeurs des catégories au sommet des barres
//
for (int i = 0; i <= 5; i++) {
txt = String.format("%d", notesType[i]);
monPaint3.setTextSize(l * h / 14000);
canvas.drawText(txt, (5 + (i * 3)) * l / 26, 7 * h / 8 - notesType[i] * 3 * h / 120 - l / 52, monPaint3);
monPaint3.setTextSize(l * h / 18000);
canvas.drawText(tTypes[i], (5 + (i * 3)) * l / 26, 7 * h / 8 + l * h / 15000, monPaint3);
}
}
public int[] getNotes() {
return notesType;
}
public void setNotes(int pnotes[]) {
this.notesType = pnotes;
}
public void drawAxes(Canvas canvas, int l, int h) {
monPaint3.setTextSize(l * h / 18000);
canvas.drawLine(2 * l / 13 - 5, 7 * h / 8, 12 * l / 13, 7 * h / 8, monPaint);
canvas.drawLine(2 * l / 13, 7 * h / 8 + 5, 2 * l / 13, h / 8, monPaint);
canvas.drawLine(2 * l / 13, (h / 8) + ((12 * h) / 120), 2 * l / 13 + 5, (h / 8) + ((12 * h) / 120), monPaint);
for (int i = 0; i <= 30; i++) {
canvas.drawLine(2 * l / 13, h / 8 + i * 3 * h / 120, 2 * l / 13 + 5, h / 8 + i * 3 * h / 120, monPaint);
}
for (int i = 5; i <= 30; i = i + 5) {
canvas.drawLine(2 * l / 13, h / 8 + i * 3 * h / 120, 2 * l / 13 + 10, h / 8 + i * 3 * h / 120, monPaint);
txt = String.format("%d", 30 - i + 5);
canvas.drawText(txt, 2 * l / 13 - l * h / 12000, h / 8 + (i - 5) * 3 * h / 120, monPaint3);
}
}
@Override
public boolean onTouchEvent(@NonNull MotionEvent event)
{
float x = event.getX();
float y = event.getY();
switch (event.getAction())
{
case MotionEvent.ACTION_DOWN:
if ( x >= 5*l/26 && x <= 8*l/26 && y>= 7 * h / 8 - notesType[0] * 3 * h / 120 && y<= 7*h/8) {
//maVue.setBackgroundColor(Color.YELLOW);
Log.d(TAG, "1");
box = new Dialog(super.getContext());
Log.d(TAG, "2");
pTitre = (TextView)findViewById(R.id.profil_titre);
pTexte = (TextView)findViewById(R.id.profil_contenu);
Log.d(TAG, "3");
txt2 = getResources().getString(R.string.pnf_titre);
Log.d(TAG, "4");
pTitre.setText(txt2);
Log.d(TAG, "5");
txt2 = getResources().getString(R.string.pnf_texte);
pTexte.setText(txt2);
Log.d(TAG, "6");
box.setContentView(R.layout.profils_info);
}
invalidate();
break;
default:
break;
}
return true;
}
} |
Partager