1 /* 2 * Copyright (C) 2016 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License 15 */ 16 17 package com.android.incallui.answer.impl.classifier; 18 19 import java.util.ArrayList; 20 21 /** 22 * Contains data about a stroke (a single trace, all the events from a given id from the 23 * DOWN/POINTER_DOWN event till the UP/POINTER_UP/CANCEL event.) 24 */ 25 class Stroke { 26 27 private static final float NANOS_TO_SECONDS = 1e9f; 28 29 private ArrayList<Point> mPoints = new ArrayList<>(); 30 private long mStartTimeNano; 31 private long mEndTimeNano; 32 private float mLength; 33 private final float mDpi; 34 Stroke(long eventTimeNano, float dpi)35 public Stroke(long eventTimeNano, float dpi) { 36 mDpi = dpi; 37 mStartTimeNano = mEndTimeNano = eventTimeNano; 38 } 39 addPoint(float x, float y, long eventTimeNano)40 public void addPoint(float x, float y, long eventTimeNano) { 41 mEndTimeNano = eventTimeNano; 42 Point point = new Point(x / mDpi, y / mDpi, eventTimeNano - mStartTimeNano); 43 if (!mPoints.isEmpty()) { 44 mLength += mPoints.get(mPoints.size() - 1).dist(point); 45 } 46 mPoints.add(point); 47 } 48 getCount()49 public int getCount() { 50 return mPoints.size(); 51 } 52 getTotalLength()53 public float getTotalLength() { 54 return mLength; 55 } 56 getEndPointLength()57 public float getEndPointLength() { 58 return mPoints.get(0).dist(mPoints.get(mPoints.size() - 1)); 59 } 60 getDurationNanos()61 public long getDurationNanos() { 62 return mEndTimeNano - mStartTimeNano; 63 } 64 getDurationSeconds()65 public float getDurationSeconds() { 66 return (float) getDurationNanos() / NANOS_TO_SECONDS; 67 } 68 getPoints()69 public ArrayList<Point> getPoints() { 70 return mPoints; 71 } 72 } 73