코스웨어/10년 스마트폰BSP
[BSP]업무일지 - 한경수 - 20100812
알 수 없는 사용자
2010. 8. 12. 17:43
package com.itisn.test;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.View;
public class SrView extends View {
private Drawable image;
public SrView(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
image = this.getResources().getDrawable(R.drawable.icon);
}
@Override
protected void onDraw(Canvas canvas) {
// TODO Auto-generated method stub
//화면 중앙으로 출력.
int viewWidth = this.getWidth();
int viewHeight = this.getHeight();
int imageWidth = image.getIntrinsicWidth();
int imageHeight = image.getIntrinsicHeight();
int x = viewWidth / 2 - imageWidth / 2;
int y = viewHeight / 2 - imageHeight / 2;
image.setBounds( x , y , x + imageWidth, y + imageHeight);
//image.setBounds(0, 0, 128, 128); //화면중앙출력
image.draw(canvas);
super.onDraw(canvas);
}
}
|
package com.itisn.test;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.View;
public class RobotView extends View {
private Drawable image;
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh)
{
// TODO Auto-generated method stub
viewWidth = this.getWidth();
viewHeight = this.getHeight();
imageWidth = image.getIntrinsicWidth();
imageHeight = image.getIntrinsicHeight();
x = viewWidth / 2 - imageWidth / 2;
y = viewHeight / 2 - imageHeight / 2;
super.onSizeChanged(w, h, oldw, oldh);
}
private int viewWidth,viewHeight;
private int imageWidth,imageHeight;
private int x,y;
public RobotView(Context context, AttributeSet attrs)
{
super(context, attrs);
// TODO Auto-generated constructor stub
image = this.getResources().getDrawable(R.drawable.sssss);
}
@Override
protected void onDraw(Canvas canvas)
{
image.setBounds( x , y , x + imageWidth, y + imageHeight);
//image.setBounds(0, 0, 128, 128); //화면중앙출력
image.draw(canvas);
super.onDraw(canvas);
}
}
|

package com.itisn.test;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
public class RobotView extends View implements Runnable
{
private final static int STEP = 10;
private Drawable image;
private int viewWidth,viewHeight;
private int imageWidth,imageHeight;
private int x,y;
public RobotView(Context context, AttributeSet attrs)
{
super(context, attrs);
// TODO Auto-generated constructor stub
image = this.getResources().getDrawable(R.drawable.sssss);
Thread thread = new Thread(this);
thread.start();
}
@Override
public boolean onTouchEvent(MotionEvent event)
{
x = (int)event.getX();
y = (int)event.getY();
this.invalidate();
return true;
// TODO Auto-generated method stub
//return super.onTouchEvent(event);
}
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh)
{
// TODO Auto-generated method stub
super.onSizeChanged(w, h, oldw, oldh);
viewWidth = this.getWidth();
viewHeight = this.getHeight();
imageWidth = image.getIntrinsicWidth();
imageHeight = image.getIntrinsicHeight();
imageWidth /=2; //그림크기 절반으로
imageHeight /=2; //그림크기 절반으로
x = viewWidth / 2 - imageWidth / 2;
y = viewHeight / 2 - imageHeight / 2;
}
@Override
public void run()
{
for(;;)
{
try
{
Thread.sleep(500);
y = Math.min(viewHeight - imageHeight,y + STEP);
this.postInvalidate();
}
catch (InterruptedException e)
{
//TODO Auto-generated catch block
e.printStackTrace();
}
}
}
@Override
protected void onDraw(Canvas canvas)
{
image.setBounds( x , y , x + imageWidth, y + imageHeight);
//image.setBounds(0, 0, 128, 128); //화면중앙출력
image.draw(canvas);
super.onDraw(canvas);
}
}

그림이 천천히 내려와 바닥에 닿으면 멈춘다. 마우스로 다시 위에 찍으로 다시 올라가서 천천히 내려온다.
|
class Car
{
String model;
String color;
public void carPrn()
{
System.out.print("모델명 : " +model+ "\t");
System.out.print("색상 : " +color+ "\n");
}
}
class Texi extends Car //Car를 수퍼 클래스로 하는 서브 클래스 Texi정의
{
Boolean texiMeter;
int texiFare = 2000;
public void power()
{
texiMeter =! texiMeter;
}
public void texiPrn()
{
if(texiMeter == true)
System.out.print("요금::"+texiFare+"\n");
else
System.out.print("미터기가 꺼져있습니다.");
}
}
class Kind extends Texi //포인트!! 앞클래스를 상속 받도록 Texi로 지정해준다.
{
Boolean PrivateTaxi;
String Brand;
public void KindPrn()
{
if(PrivateTaxi == true)
System.out.print("개인택시\n");
else
System.out.print("영업택시");
}
public void BrandPrn()
{
System.out.println("택시브랜드 : "+Brand);
}
}
public class TexiTest
{
public static void main(String[] args)
{
//Texi t = new Texi(); //서브클래스로 인스턴스 생성
Kind k = new Kind();
k.PrivateTaxi = true;
k.Brand = "등대콜";
k.KindPrn();
k.BrandPrn();
k.model = "렉서스"; //슈퍼클래스로부터 상속받은 필드
k.color = "실버"; //슈퍼클래스로부터 상속받은 필드
k.texiMeter = true; //자신의 필드
k.carPrn(); //슈퍼클래스로부터 상속받은 필드
k.texiPrn(); //자신의 메소드
}
}
|
개인택시
택시브랜드 : 등대콜
모델명 : 렉서스 색상 : 실버
요금::2000
|