-
Notifications
You must be signed in to change notification settings - Fork 265
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change-Id: Ib3436f7fff8d3677458008793feb37dfa5e168db
- Loading branch information
Jeremy Walker
committed
Jul 30, 2019
1 parent
4d82755
commit a1a60cc
Showing
41 changed files
with
2,091 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
|
||
# GOOGLE SAMPLE PACKAGING DATA | ||
# | ||
# This file is used by Google as part of our samples packaging process. | ||
# End users may safely ignore this file. It has no relevance to other systems. | ||
--- | ||
status: PUBLISHED | ||
technologies: [Android] | ||
categories: [UI, Views, Input] | ||
languages: [Java] | ||
solutions: [Mobile] | ||
github: android/input | ||
level: INTERMEDIATE | ||
icon: screenshots/icon-web.png | ||
apiRefs: | ||
- android:android.view.MotionEvent | ||
license: apache2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
|
||
buildscript { | ||
repositories { | ||
google() | ||
jcenter() | ||
} | ||
|
||
dependencies { | ||
classpath 'com.android.tools.build:gradle:3.4.2' | ||
} | ||
} | ||
|
||
apply plugin: 'com.android.application' | ||
|
||
repositories { | ||
google() | ||
jcenter() | ||
} | ||
|
||
dependencies { | ||
|
||
|
||
implementation "com.android.support:support-v4:28.0.0" | ||
implementation "com.android.support:support-v13:28.0.0" | ||
implementation "com.android.support:cardview-v7:28.0.0" | ||
implementation "com.android.support:appcompat-v7:28.0.0" | ||
|
||
|
||
|
||
|
||
|
||
|
||
} | ||
|
||
// The sample build uses multiple directories to | ||
// keep boilerplate and common code separate from | ||
// the main sample code. | ||
List<String> dirs = [ | ||
'main', // main sample code; look here for the interesting stuff. | ||
'common', // components that are reused by multiple samples | ||
'template'] // boilerplate code that is generated by the sample template process | ||
|
||
android { | ||
compileSdkVersion 28 | ||
|
||
defaultConfig { | ||
minSdkVersion 14 | ||
targetSdkVersion 28 | ||
} | ||
|
||
compileOptions { | ||
sourceCompatibility JavaVersion.VERSION_1_7 | ||
targetCompatibility JavaVersion.VERSION_1_7 | ||
} | ||
|
||
sourceSets { | ||
main { | ||
dirs.each { dir -> | ||
java.srcDirs "src/${dir}/java" | ||
res.srcDirs "src/${dir}/res" | ||
} | ||
} | ||
androidTest.setRoot('tests') | ||
androidTest.java.srcDirs = ['tests/src'] | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- | ||
Copyright 2013 The Android Open Source Project | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
--> | ||
|
||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.example.android.basicmultitouch" | ||
android:versionCode="1" | ||
android:versionName="1.0" > | ||
|
||
<!-- Min/target SDK versions (<uses-sdk>) managed by build.gradle --> | ||
|
||
<application | ||
android:allowBackup="true" | ||
android:icon="@drawable/ic_launcher" | ||
android:label="@string/app_name" | ||
android:theme="@style/AppTheme" > | ||
<activity | ||
android:name=".MainActivity" | ||
android:label="@string/app_name" > | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
|
||
</manifest> |
43 changes: 43 additions & 0 deletions
43
...ultitouch/Application/src/main/java/com/example/android/basicmultitouch/MainActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Copyright (C) 2013 The Android Open Source Project | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.example.android.basicmultitouch; | ||
|
||
import android.app.Activity; | ||
import android.os.Bundle; | ||
|
||
/** | ||
* This is an example of keeping track of individual touches across multiple | ||
* {@link android.view.MotionEvent}s. | ||
* <p> | ||
* This is illustrated by a View ({@link TouchDisplayView}) that responds to | ||
* touch events and draws coloured circles for each pointer, stores the last | ||
* positions of this pointer and draws them. This example shows the relationship | ||
* between MotionEvent indices, pointer identifiers and actions. | ||
* | ||
* @see android.view.MotionEvent | ||
*/ | ||
public class MainActivity extends Activity { | ||
TouchDisplayView mView; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
|
||
setContentView(R.layout.layout_mainactivity); | ||
} | ||
|
||
} |
165 changes: 165 additions & 0 deletions
165
BasicMultitouch/Application/src/main/java/com/example/android/basicmultitouch/Pools.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
/* | ||
* Copyright (C) 2009 The Android Open Source Project | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.example.android.basicmultitouch; | ||
|
||
/** | ||
* Helper class for crating pools of objects. An example use looks like this: | ||
* <pre> | ||
* public class MyPooledClass { | ||
* | ||
* private static final SynchronizedPool<MyPooledClass> sPool = | ||
* new SynchronizedPool<MyPooledClass>(10); | ||
* | ||
* public static MyPooledClass obtain() { | ||
* MyPooledClass instance = sPool.acquire(); | ||
* return (instance != null) ? instance : new MyPooledClass(); | ||
* } | ||
* | ||
* public void recycle() { | ||
* // Clear state if needed. | ||
* sPool.release(this); | ||
* } | ||
* | ||
* . . . | ||
* } | ||
* </pre> | ||
* | ||
* @hide | ||
*/ | ||
public final class Pools { | ||
|
||
/** | ||
* Interface for managing a pool of objects. | ||
* | ||
* @param <T> The pooled type. | ||
*/ | ||
public static interface Pool<T> { | ||
|
||
/** | ||
* @return An instance from the pool if such, null otherwise. | ||
*/ | ||
public T acquire(); | ||
|
||
/** | ||
* Release an instance to the pool. | ||
* | ||
* @param instance The instance to release. | ||
* @return Whether the instance was put in the pool. | ||
* | ||
* @throws IllegalStateException If the instance is already in the pool. | ||
*/ | ||
public boolean release(T instance); | ||
} | ||
|
||
private Pools() { | ||
/* do nothing - hiding constructor */ | ||
} | ||
|
||
/** | ||
* Simple (non-synchronized) pool of objects. | ||
* | ||
* @param <T> The pooled type. | ||
*/ | ||
public static class SimplePool<T> implements Pool<T> { | ||
private final Object[] mPool; | ||
|
||
private int mPoolSize; | ||
|
||
/** | ||
* Creates a new instance. | ||
* | ||
* @param maxPoolSize The max pool size. | ||
* | ||
* @throws IllegalArgumentException If the max pool size is less than zero. | ||
*/ | ||
public SimplePool(int maxPoolSize) { | ||
if (maxPoolSize <= 0) { | ||
throw new IllegalArgumentException("The max pool size must be > 0"); | ||
} | ||
mPool = new Object[maxPoolSize]; | ||
} | ||
|
||
@Override | ||
@SuppressWarnings("unchecked") | ||
public T acquire() { | ||
if (mPoolSize > 0) { | ||
final int lastPooledIndex = mPoolSize - 1; | ||
T instance = (T) mPool[lastPooledIndex]; | ||
mPool[lastPooledIndex] = null; | ||
mPoolSize--; | ||
return instance; | ||
} | ||
return null; | ||
} | ||
|
||
@Override | ||
public boolean release(T instance) { | ||
if (isInPool(instance)) { | ||
throw new IllegalStateException("Already in the pool!"); | ||
} | ||
if (mPoolSize < mPool.length) { | ||
mPool[mPoolSize] = instance; | ||
mPoolSize++; | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
private boolean isInPool(T instance) { | ||
for (int i = 0; i < mPoolSize; i++) { | ||
if (mPool[i] == instance) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
} | ||
|
||
/** | ||
* Synchronized) pool of objects. | ||
* | ||
* @param <T> The pooled type. | ||
*/ | ||
public static class SynchronizedPool<T> extends SimplePool<T> { | ||
private final Object mLock = new Object(); | ||
|
||
/** | ||
* Creates a new instance. | ||
* | ||
* @param maxPoolSize The max pool size. | ||
* | ||
* @throws IllegalArgumentException If the max pool size is less than zero. | ||
*/ | ||
public SynchronizedPool(int maxPoolSize) { | ||
super(maxPoolSize); | ||
} | ||
|
||
@Override | ||
public T acquire() { | ||
synchronized (mLock) { | ||
return super.acquire(); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean release(T element) { | ||
synchronized (mLock) { | ||
return super.release(element); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.