Skip to content

Commit e21fb5b

Browse files
authored
Merge pull request #764 from processing/main
Latest changes from main
2 parents d8b4677 + 9e8c066 commit e21fb5b

File tree

35 files changed

+578
-136
lines changed

35 files changed

+578
-136
lines changed

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ mode/libraries/ar/library
1313
mode/tools/SDKUpdater/tool
1414
mode/tools/SDKUpdater/lib
1515

16-
debug/.gradle
17-
debug/.idea
16+
.gradle
17+
.idea
1818

1919
**/examples/**/AndroidManifest.xml
2020

app/armarkers/build.gradle

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
apply plugin: 'com.android.application'
2+
3+
android {
4+
compileSdkVersion 33
5+
defaultConfig {
6+
applicationId "processing.tests.armarkers"
7+
minSdkVersion 23
8+
targetSdkVersion 33
9+
versionCode 1
10+
versionName "1.0"
11+
}
12+
buildTypes {
13+
release {
14+
minifyEnabled false
15+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
16+
}
17+
}
18+
productFlavors {
19+
}
20+
compileOptions {
21+
sourceCompatibility JavaVersion.VERSION_1_8
22+
targetCompatibility JavaVersion.VERSION_1_8
23+
}
24+
namespace 'armarkers'
25+
}
26+
27+
dependencies {
28+
implementation fileTree(include: ['*.jar'], dir: 'libs')
29+
testImplementation 'junit:junit:4.13.2'
30+
implementation project(':library:processing-core')
31+
implementation project(':library:processing-ar')
32+
implementation 'androidx.appcompat:appcompat:1.6.0'
33+
implementation 'com.google.ar:core:1.35.0'
34+
}

app/armarkers/gradle.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
android.enableJetifier=true
2+
android.useAndroidX=true
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:tools="http://schemas.android.com/tools"
4+
android:versionCode="1"
5+
android:versionName="1.0">
6+
<uses-permission android:name="android.permission.CAMERA"/>
7+
<uses-feature android:name="android.hardware.camera.ar" android:required="true"/>
8+
<uses-feature android:glEsVersion="0x00020000" android:required="true"/>
9+
<application android:icon="@mipmap/ic_launcher"
10+
android:label="@string/app_name"
11+
android:theme="@style/ArActivityTheme"
12+
android:allowBackup="false"
13+
android:usesCleartextTraffic="false"
14+
tools:ignore="GoogleAppIndexingWarning">
15+
<activity android:configChanges="orientation|screenSize"
16+
android:exported="true"
17+
android:name=".MainActivity"
18+
android:screenOrientation="locked"
19+
android:theme="@style/Theme.AppCompat.NoActionBar">
20+
<intent-filter>
21+
<action android:name="android.intent.action.MAIN"/>
22+
<category android:name="android.intent.category.LAUNCHER"/>
23+
</intent-filter>
24+
</activity>
25+
<meta-data android:name="com.google.ar.core" android:value="required"/>
26+
</application>
27+
</manifest>
230 KB
Loading
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
package armarkers;
2+
3+
import android.Manifest;
4+
import android.content.pm.PackageManager;
5+
import android.net.Uri;
6+
import android.os.Bundle;
7+
import android.content.Intent;
8+
import android.provider.Settings;
9+
import android.view.ViewGroup;
10+
import android.widget.FrameLayout;
11+
import android.widget.Toast;
12+
13+
import androidx.appcompat.app.AppCompatActivity;
14+
import androidx.core.app.ActivityCompat;
15+
import androidx.core.content.ContextCompat;
16+
17+
import processing.android.PFragment;
18+
import processing.android.CompatUtils;
19+
import processing.core.PApplet;
20+
21+
public class MainActivity extends AppCompatActivity {
22+
private static final int CAMERA_PERMISSION_CODE = 0;
23+
private static boolean CAMERA_PERMISSION_REQUESTED = false;
24+
private static final String CAMERA_PERMISSION = Manifest.permission.CAMERA;
25+
private static final String CAMERA_PERMISSION_MESSAGE = "Camera permission is needed to use AR";
26+
27+
private PApplet sketch;
28+
29+
@Override
30+
protected void onCreate(Bundle savedInstanceState) {
31+
super.onCreate(savedInstanceState);
32+
FrameLayout frame = new FrameLayout(this);
33+
frame.setId(CompatUtils.getUniqueViewId());
34+
setContentView(frame, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
35+
ViewGroup.LayoutParams.MATCH_PARENT));
36+
37+
sketch = new Sketch();
38+
PFragment fragment = new PFragment(sketch);
39+
fragment.setView(frame, this);
40+
}
41+
42+
@Override
43+
protected void onResume() {
44+
super.onResume();
45+
if (!hasCameraPermission()) requestCameraPermission();
46+
}
47+
48+
@Override
49+
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
50+
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
51+
if (!hasCameraPermission()) {
52+
Toast.makeText(this, CAMERA_PERMISSION_MESSAGE, Toast.LENGTH_LONG).show();
53+
if (!shouldShowRequestPermissionRationale()) {
54+
launchPermissionSettings();
55+
}
56+
finish();
57+
}
58+
59+
if (sketch != null) {
60+
sketch.onRequestPermissionsResult(requestCode, permissions, grantResults);
61+
}
62+
63+
CAMERA_PERMISSION_REQUESTED = false;
64+
}
65+
66+
@Override
67+
public void onNewIntent(Intent intent) {
68+
super.onNewIntent(intent);
69+
if (sketch != null) {
70+
sketch.onNewIntent(intent);
71+
}
72+
}
73+
74+
@Override
75+
public void onActivityResult(int requestCode, int resultCode, Intent data) {
76+
super.onActivityResult(requestCode, resultCode, data);
77+
if (sketch != null) {
78+
sketch.onActivityResult(requestCode, resultCode, data);
79+
}
80+
}
81+
82+
@Override
83+
public void onBackPressed() {
84+
if (sketch != null) {
85+
sketch.onBackPressed();
86+
}
87+
}
88+
89+
private boolean hasCameraPermission() {
90+
int res = ContextCompat.checkSelfPermission(this, CAMERA_PERMISSION);
91+
return res == PackageManager.PERMISSION_GRANTED;
92+
}
93+
94+
private void requestCameraPermission() {
95+
if (!CAMERA_PERMISSION_REQUESTED) {
96+
CAMERA_PERMISSION_REQUESTED = true;
97+
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.CAMERA}, CAMERA_PERMISSION_CODE);
98+
}
99+
}
100+
101+
private boolean shouldShowRequestPermissionRationale() {
102+
return ActivityCompat.shouldShowRequestPermissionRationale(this, CAMERA_PERMISSION);
103+
}
104+
105+
private void launchPermissionSettings() {
106+
Intent intent = new Intent();
107+
intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
108+
intent.setData(Uri.fromParts("package", this.getPackageName(), null));
109+
this.startActivity(intent);
110+
}
111+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package armarkers;
2+
3+
import java.util.ArrayList;
4+
5+
import processing.ar.*;
6+
import processing.core.PApplet;
7+
import processing.core.PImage;
8+
import processing.core.PShape;
9+
10+
public class Sketch extends PApplet {
11+
ARTracker tracker;
12+
ARAnchor anchor;
13+
PShape earth;
14+
15+
public void settings() {
16+
fullScreen(AR);
17+
}
18+
19+
public void setup() {
20+
fullScreen(AR);
21+
22+
tracker = new ARTracker(this);
23+
24+
PImage earthImg = loadImage("earth.jpg");
25+
tracker.start();
26+
tracker.addImage("earth", earthImg);
27+
28+
earth = createShape(SPHERE, 0.15f);
29+
}
30+
31+
public void draw() {
32+
lights();
33+
34+
if (mousePressed) {
35+
// Create new anchor at the current touch point
36+
if (anchor != null) anchor.dispose();
37+
ARTrackable hit = tracker.get(mouseX, mouseY);
38+
if (hit != null && hit.isImage() && hit.getName().equals("earth")) {
39+
anchor = new ARAnchor(hit);
40+
}
41+
else anchor = null;
42+
}
43+
44+
if (anchor != null) {
45+
anchor.attach();
46+
shape(earth);
47+
anchor.detach();
48+
}
49+
}
50+
51+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
2+
xmlns:tools="http://schemas.android.com/tools"
3+
android:id="@+id/fragment"
4+
android:name=".Cube"
5+
tools:layout="@layout/fragment_main"
6+
android:layout_width="match_parent"
7+
android:layout_height="match_parent" />
3.34 KB
Loading
2.15 KB
Loading

0 commit comments

Comments
 (0)