線をn個の図形で描くために一般的に使用されるアプリケーションを作成しました。正方形を作成したとします。これを保存したいので、アプリケーションを再起動すると、正方形を表示する必要があります。どうすれば可能でしょうか。これが私のコードです
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Set full screen view
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
requestWindowFeature(Window.FEATURE_NO_TITLE);
DrawView drawView = new DrawView(this, null);
setContentView(drawView);
drawView.requestFocus();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// TODO Auto-generated method stub
menu.add(0,1,1,"RED").setShortcut('3', 'C');
menu.add(0,2,2,"GREEN");
menu.add(0,3,3,"BLUE");
menu.add(0,4,4,"Erase");
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// TODO Auto-generated method stub
switch(item.getItemId())
{
case 1:
first(x,y,z);
break;
case 4:
DrawView.second();
break;
}
return super.onOptionsItemSelected(item);
}
public List<Integer> first(int x2, int y2, int z2) {
// TODO Auto-generated method stub
x2=100;y2=150;z2=200;
al.add(x2);al.add(y2);al.add(z2);
return al;
}
}
public DrawView(Context context, AttributeSet attrs) {
super(context, attrs);
list1 = d.first(a,b,c);
paint.setAntiAlias(true);
paint.setColor(Color.rgb(list1.get(0),list1.get(1),list1.get(2)));
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeJoin(Paint.Join.ROUND);
paint.setStrokeWidth(5f);
}
@Override
protected void onDraw(Canvas canvas) {
canvas.drawPath(path, paint);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
float eventX = event.getX();
float eventY = event.getY();
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
path.moveTo(eventX, eventY);
return true;
case MotionEvent.ACTION_MOVE:
case MotionEvent.ACTION_UP:
path.lineTo(eventX, eventY);
break;
default:
return false;
}
// Schedules a repaint.
invalidate();
return true;
}
static void second() {
// TODO Auto-generated method stub
erase(paint);
}
private static void erase(Paint paint2) {
// TODO Auto-generated method stub
paint2.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
}
}