package com.testy;
import java.util.Vector;
import com.testy.R;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Point;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.Typeface;
import android.graphics.Bitmap.Config;
import android.graphics.Paint.FontMetrics;
import android.os.Bundle;
import android.widget.ImageView;
public class main extends Activity {
// these_labela has elemnes[label,maxX,maxY]
static int draw_only_this_idx = -1;
static int[] drawSizes;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.testy);
setTitle("Quick XY Plot");
ImageView image = (ImageView) findViewById(R.id.testy_img);
Bitmap emptyBmap = Bitmap.createBitmap(250,
200, Config.ARGB_8888);
int width = emptyBmap.getWidth();
int height = emptyBmap.getHeight();
Bitmap charty = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
charty = quicky_XY(emptyBmap);
image.setImageBitmap(charty);
}
public static Bitmap quicky_XY(Bitmap bitmap)
{
// xode to get bitmap onto screen
Bitmap output = Bitmap.createBitmap(bitmap.getWidth(),
bitmap.getHeight(), Config.ARGB_8888);
Canvas canvas = new Canvas(output);
final int color = 0xff0B0B61;
final Paint paint = new Paint();
final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
final RectF rectF = new RectF(rect);
final float roundPx = 12;
// get the little rounded cornered outside
paint.setAntiAlias(true);
canvas.drawARGB(0, 0, 0, 0);
paint.setColor(color);
canvas.drawRoundRect(rectF, roundPx, roundPx, paint);
// ---- NOw just draw on this bitmap
// Set the labels info manually
String[] cur_elt_array = new String[4];
cur_elt_array[0]="Voltage";
cur_elt_array[1]="volts";
cur_elt_array[2]="93"; // max
cur_elt_array[3]="0"; //min
Vector labels = new Vector();
labels.add(cur_elt_array);
draw_the_grid(canvas,labels);
// se the data to be plotted and we should on our way
Vector data_2_plot = new Vector();
data_2_plot.add("0.2") ;
data_2_plot.add("1.2") ;
data_2_plot.add("9.6") ;
data_2_plot.add("83.2") ;
data_2_plot.add("44.2") ;
data_2_plot.add("20.2") ;
data_2_plot.add("16.2") ;
plot_array_list(canvas , data_2_plot , labels , "the title" , 0 );
canvas.drawBitmap(bitmap, rect, rect, paint);
return output;
}
// these_labels is vector of [label,units,max.min]
public static void draw_the_grid(Canvas this_g, Vector these_labels)
{
double rounded_max = 0.0;
double rounded_min = 0.0;
double rounded_max_temp;
Object curElt;
String[] cur_elt_array;
int left_margin_d, right_margin_d;
if( draw_only_this_idx == -1)
curElt = these_labels.elementAt(0); // default it to 1st one if non set
else
curElt = these_labels.elementAt(draw_only_this_idx); // now just the 1st elt
cur_elt_array = (String[])curElt;
rounded_max = get_ceiling_or_floor (Double.parseDouble(cur_elt_array[2]) , true);
rounded_min = get_ceiling_or_floor (Double.parseDouble(cur_elt_array[3]) , false);
// ok so now we have the max value of the set just get a cool ceiling and we go on
final Paint paint = new Paint();
paint.setTextSize(15);
left_margin_d = getCurTextLengthInPixels(paint, Double.toString(rounded_max));
//keep the position for later drawing -- leave space for the legend
int p_height = 170;
int p_width = 220;
int[] tmp_draw_sizes = {2 + left_margin_d, 25,p_width - 2 - left_margin_d ,p_height - 25 -5};
drawSizes = tmp_draw_sizes; //keep it for later processing
//with the mzrgins worked out draw the plotting grid
paint.setStyle(Paint.Style.FILL);
paint.setColor(Color.WHITE );
// Android does by coords
this_g.drawRect(drawSizes[0], drawSizes[1],drawSizes[0]+ drawSizes[2], drawSizes[1]+ drawSizes[3] , paint);
paint.setColor(Color.GRAY );
// finally draw the grid
paint.setStyle(Paint.Style.STROKE);
this_g.drawRect(drawSizes[0], drawSizes[1],drawSizes[0]+ drawSizes[2], drawSizes[1]+ drawSizes[3] , paint);
for(int i=1; i < 5 ; i++)
{
this_g.drawLine(drawSizes[0], drawSizes[1] + (i * drawSizes[3] / 5), drawSizes[0] + drawSizes[2], drawSizes[1] + (i * drawSizes[3] / 5), paint);
this_g.drawLine(drawSizes[0]+ (i * drawSizes[2] / 5), drawSizes[1], drawSizes[0] + (i * drawSizes[2] / 5), drawSizes[1] + drawSizes[3], paint);
}
// good for one value
print_axis_values_4_grid(this_g, cur_elt_array[1] , Double.toString(rounded_max) , Double.toString(rounded_min), cur_elt_array[0] , 2 ,0 );
} // --- end of draw_grid ---
// provate void print_axis_values_4_grid(Graphics thisDrawingArea, string cur_units , string cur_max , string cur_min , string cur_label , ByVal x_guide As Integer, ByVal this_idx As Integer)
public static void print_axis_values_4_grid(Canvas thisDrawingArea, String cur_units , String cur_max , String cur_min , String cur_label , int x_guide , int this_idx )
{
String this_str;
double delta = ( Double.valueOf(cur_max).doubleValue() - Double.valueOf(cur_min).doubleValue() ) / 5;
final Paint paint = new Paint();
paint.setColor( Color.WHITE );
paint.setTypeface( Typeface.SANS_SERIF );
//Font smallyFont = Font.getDefault().derive(Font.PLAIN, 12);
// thisDrawingArea.setFont(smallyFont);
paint.setTextSize(8);
for(int i = 0; i<6 ; i++)
{
// 'work our the values so is proper
this_str =Double.toString( (Double.valueOf(cur_min).doubleValue() + delta * i) );
final int point = this_str.indexOf('.');
if (point > 0) {
// If has a decimal point, may need to clip off after or force 2 decimal places
this_str = this_str + "00";
this_str = this_str.substring(0,point+3);
} else {
this_str = this_str + ".00";
}
if (i == 5)
// thisDrawingArea.drawText(this_str, x_guide - 2, drawSizes[1] + drawSizes[3] - (i *drawSizes[3] / 5) );
thisDrawingArea.drawText(this_str, x_guide - 2, drawSizes[1] + drawSizes[3] - (i *drawSizes[3] / 5) , paint );
else
thisDrawingArea.drawText(this_str, x_guide- 2, drawSizes[1] + drawSizes[3] - (i * drawSizes[3] / 5) -3, paint);
}
// smallyFont = Font.getDefault().derive(Font.BOLD, 12);
// thisDrawingArea.setFont(smallyFont);
paint.setTextSize(10);
switch(this_idx )
{
case 0:
thisDrawingArea.drawText(" " + cur_label +" - " +cur_units,
小程序 XY图表.rar
版权申诉
56 浏览量
2023-02-03
11:41:47
上传
评论
收藏 73KB RAR 举报
大富大贵7
- 粉丝: 317
- 资源: 8869
最新资源
- vscode配置c/c 环境教程
- vscode配置c/c 环境教程
- 基于matlab实现电磁优化计算功能,进行线型规划优化电磁设计.rar
- 基于matlab实现带精英策略的非支配排序遗传算法matlab 源码.rar
- 基于matlab实现差分进化算法,最新的用于替代遗传算法,是以后的主要发展方法.rar
- VSCode配置c/c++环境教程.md
- 基于matlab实现标准合作型协同进化遗传算法matlab源程序
- 七下人教.zip
- 基于matlab实现本份代码能对图像进行gabor滤波处理,结合指纹方向图以及指纹沟壑频率特性,对指纹图像进行增强.rar
- 基于matlab实现RBM神经网络实现了手写数字体识别的GUI程序.rar
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈