我正致力于信道,并能够完成二分之一的图形部分,并在二字(如旧电话)上放置一些 app,现在我想确定用户已经触及哪些问题。 我已在感动的听众中执行这一守则:
public class CanvasDemActivity extends Activity {
Bitmap mLight,mDial,mBrowser,mCamera,mMessage,mDialer,mHome,mLock;
float angle;
ArrayList<Double> mCurrentAngleArray;
ArrayList<PointF> mArray;
ArrayList<Bitmap> mBitmapArray;
PointF p1,p2,p3,p4,p5;
String mTIme;
Date date;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
// making it full screen
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
Dialer view = new Dialer(this);
setContentView(view);
view.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
int action = event.getAction();
if(action == MotionEvent.ACTION_DOWN) {
PointF p = new PointF();
p.x = event.getX(); p.y = event.getY();
for(int i=0;i<5;i++) {
if (p.x >= mArray.get(i).x && p.x < (mArray.get(i).x + mBitmapArray.get(i).getWidth())
&& p.y >= mArray.get(i).y && p.y < (mArray.get(i).y + mBitmapArray.get(i).getHeight())) {
System.out.println("presssed on icon " + i);
break;
iii
iii
return true;
iii
iii
public class Dialer extends View{
Context mcontext;
public Dialer(Context context) {
super(context);
mcontext = context;
mLight = BitmapFactory.decodeResource(mcontext.getResources(), R.drawable.light);
mDial = BitmapFactory.decodeResource(mcontext.getResources(), R.drawable.dial);
mBrowser = BitmapFactory.decodeResource(mcontext.getResources(), R.drawable.browser);
mCamera = BitmapFactory.decodeResource(mcontext.getResources(), R.drawable.camera);
mMessage = BitmapFactory.decodeResource(mcontext.getResources(), R.drawable.message);
mDialer = BitmapFactory.decodeResource(mcontext.getResources(), R.drawable.dialer);
mHome = BitmapFactory.decodeResource(mcontext.getResources(), R.drawable.home);
mLock = BitmapFactory.decodeResource(mcontext.getResources(), R.drawable.lock);
mArray = new ArrayList<PointF>();
mBitmapArray = new ArrayList<Bitmap>();
mCurrentAngleArray = new ArrayList<Double>();
mBitmapArray.add(mBrowser);
mBitmapArray.add(mCamera);
mBitmapArray.add(mMessage);
mBitmapArray.add(mDialer);
mBitmapArray.add(mHome);
date = new Date();
p1 = new PointF();
p1.x = 80.0f ; p1.y = 475;
mArray.add(p1);
p2 = new PointF();
p2.x = 120.0f ; p2.y = 320.0f;
mArray.add(p2);
p3 = new PointF();
p3.x = 260 ; p3.y = 275;
mArray.add(p3);
p4 = new PointF();
p4.x = 315 ; p4.y = 390;
mArray.add(p4);
p5 = new PointF();
p5.x = 330 ; p5.y = 460;
mArray.add(p5);
float delta_x,delta_y;
double mCurrentAngle;
for(int i=0; i<5 ; i++) {
delta_x = mArray.get(i).x - 248;
delta_y = mArray.get(i).y - 430;
mCurrentAngle = Math.atan2(delta_y, delta_x);
mCurrentAngleArray.add(mCurrentAngle);
iii
iii
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
Paint paint = new Paint();
canvas.drawPaint(paint);
paint.setStyle(Paint.Style.FILL);
paint.setColor(Color.WHITE);
paint.setTextSize(75);
if(date.getMinutes() > 9)
mTIme = date.getHours() + ":" + date.getMinutes();
else
mTIme = date.getHours() + ":0" + date.getMinutes();
canvas.drawText(mTIme, 140,125, paint);
String dayNames[] = new DateFormatSymbols().getWeekdays();
Calendar date2 = Calendar.getInstance();
String day = dayNames[date2.get(Calendar.DAY_OF_WEEK)];
java.util.Date d = new java.util.Date(Calendar.getInstance().getTimeInMillis());
String properformat = day+", "+ date.getDate() + " " +new SimpleDateFormat("MMMM").format(d);
paint.setTextSize(25);
canvas.drawText(properformat, 125, 175, paint);
TelephonyManager telephonyManager =((TelephonyManager) mcontext.getSystemService(Context.TELEPHONY_SERVICE));
String operatorName = telephonyManager.getNetworkOperatorName();
if(operatorName.length() == 0 )
operatorName = "Insert Sim Card";
paint.setTextSize(20);
canvas.drawText(operatorName, 175, 210, paint);
canvas.drawBitmap(mDial, canvas.getWidth()/10, canvas.getHeight()/4, null);
canvas.drawBitmap(mLock, canvas.getWidth()/10, canvas.getHeight()/4, null);
for(int i=0;i<5;i++) {
double X = 120 * Math.cos(mCurrentAngleArray.get(i) + angle);
double Y = 120 * Math.sin(mCurrentAngleArray.get(i) + angle);
canvas.drawBitmap(mBitmapArray.get(i),210 + (float) X, 395+ (float)Y, null);
iii
angle = angle + 0.01f;
canvas.drawBitmap(mLight, canvas.getWidth()/9,canvas.getHeight()/4f, null);
invalidate();
iii
iii
iii
当p.x和p.y是用户触动的坐标,而mArray是我放置轨道图的坐标,而mBitmapArray是我储存的轨道图的阵列。
The problem is that even though I have written the code correctly, I am unable to get into the "if" condition when I am pressing browser and dialer icons.
I have tested the same code in a sample app and it works fine.
Can you please tell me what s the problem?