如何制作测试触摸屏应用程序?

时间:2015-09-17 16:31:41

标签: android touch screen

我想制作三星设备诊断工具等测试触摸屏应用程序。谁能做到并向我发送源代码?

我想要喜欢它。 http://i.stack.imgur.com/7KgKW.jpg

2 个答案:

答案 0 :(得分:0)

这个应用程序的开发很容易。你需要明白:

如何获取点击的坐标。

import UIKit
import iAd

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        self.canDisplayBannerAds = true
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }
}

覆盖方法onDraw,绘制矩形。

iAd.framework

答案 1 :(得分:0)

最近,我还必须在我的应用中进行此屏幕测试。所以我想出了一个解决方案。我正在使用RectF的数组,即ArrayList<RectF> arr = new ArrayList<>()并按以下顺序绘制此Rects

  1. 左垂直线

    private void drawLeftLine(int width, int height) {
    int leftPoint = 0;
    int topPoint = 0;
    int rightPoint = 100;
    int bottomPoint = 100;
    
    int maxNoOfRect = height / 100;
    int lastRectHeight = height % 100;
    
    for (int i = 0; i < maxNoOfRect; i++) {
        arr.add(new RectF(leftPoint, topPoint, rightPoint, bottomPoint));
        topPoint = bottomPoint;
        bottomPoint = bottomPoint + 100;
    }
    

    }

  2. 顶部水平线

    private void drawTopLine(int w,int h){

    int leftPoint = 0;
    int topPoint = 0;
    int rightPoint = 100;
    int bottomPoint = 100;
    
    int maxNoOfRect = w / 100;
    int lastRectWidth = w % 100;
    
    for (int i = 0; i < maxNoOfRect; i++) {
        arr.add(new RectF(leftPoint, topPoint, rightPoint, bottomPoint));
        leftPoint = rightPoint;
        rightPoint = rightPoint + 100;
    }
    arr.add(new RectF(leftPoint, topPoint, rightPoint + lastRectWidth, bottomPoint));
    

    }

并类似地; 3.右垂直线4.底部水平线,借助于大小为100的RectF的集合。

因此,当用户触摸一个点时,检查该坐标是否位于任何RectF范围内?如果是,请从阵列中删除该RectF。 像:

     @Override
public boolean onTouchEvent(MotionEvent event) {
    float touchX = event.getX();
    float touchY = event.getY();

    switch (event.getAction()) {
        case MotionEvent.ACTION_DOWN:
            if (mOnViewTouchedListener != null)
                mOnViewTouchedListener.onViewTouched();
            Point point = new Point();
            point.x = (int) event.getX();
            point.y = (int) event.getY();
            Log.d("TAG", "point: " + point);

            for (int i = 0; i < arr.size(); i++) {
                if (arr.get(i).contains(point.x, point.y)) {
                    Log.d("TAG", "Touch IN");
                    arr.remove(i);
                    invalidate();
                    break;
                }
            }
            break;
        case MotionEvent.ACTION_MOVE:
            if (mOnViewTouchedListener != null)
                mOnViewTouchedListener.onViewTouched();
            Log.d("TAG", "ACTION_MOVE");
            Point point1 = new Point();
            point1.x = (int) event.getX();
            point1.y = (int) event.getY();
            Log.d("TAG", "point: " + point1);

            for (int i = 0; i < arr.size(); i++) {
                if (arr.get(i).contains(point1.x, point1.y)) {
                    Log.d("TAG", "Touch IN");
                    arr.remove(i);
                    invalidate();
                    break;
                }
            }
            break;
        default:
            return false;
    }
    return true;
}

因此,这是解决方案。用同样的方式绘制对角线。

从左上角到右下角的对角线:

 private void drawTBDiagonalLine(int w, int h) {

    float height = h;
    float width = w;
    float slope = (height / width);

    float left = 0;
    float top = 0;
    float bottom = 100;
    float right = bottom / slope;

    int maxNoOfRect = h / 100;

    for (int i = 0; i < maxNoOfRect; i++) {
        arr.add(new RectF(left, top, right, bottom));
        left = right;
        top = bottom;
        bottom = bottom + 100;
        right = bottom / slope;
    }
}

我很快就会在我的Github页面上发布完整的解决方案 shashankkapsime