Skip to content

Commit 1d135bf

Browse files
authored
Merge pull request #318 from processing/wearapi
merge changes in Services API and permission handling
2 parents 33fc9e4 + 842cbf3 commit 1d135bf

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+1327
-1286
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ release
1111

1212
build/**
1313
.gradle
14+
/processing-core.zip

README.md

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
Processing for Android
22
======================
33

4-
#New architecture branch
5-
6-
This branch is meant to test the new architecture that will allow different app publishing options (fragment-based apps, wallpaper, watchfaces, etc)
7-
8-
It is highly experimental and very likely will break your code, don't use it unless you want to help us with debugging.
4+
This is the main repository for Processing for Android. It includes the core library inside the core folder, and the mode itself in the root. See the [wiki](https://github.com/processing/processing-android/wiki) for build instructions.

build.gradle

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ allprojects {
1414
apply plugin: 'java'
1515

1616
ext.android_platform = "$sdkdir/platforms/android-$sdkver"
17-
ext.core_jar_path = "$rootDir/android-core.zip"
17+
ext.core_jar_path = "$rootDir/processing-core.zip"
1818

1919
repositories {
2020
jcenter()
@@ -66,8 +66,8 @@ task dist {
6666
Files.copy(file("$buildDir/libs/processing-android.jar").toPath(),
6767
file("mode/AndroidMode.jar").toPath(), REPLACE_EXISTING);
6868

69-
Files.copy(file("core/build/libs/android-core.zip").toPath(),
70-
file("$root/android-core.zip").toPath(), REPLACE_EXISTING);
69+
Files.copy(file("core/build/libs/processing-core.zip").toPath(),
70+
file("$root/processing-core.zip").toPath(), REPLACE_EXISTING);
7171

7272
Files.copy(file("mode.properties").toPath(),
7373
file("$root/mode.properties").toPath(), REPLACE_EXISTING);

build.xml

+5-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<!-- path to the main processing repo -->
66
<property name="processing.dir" value="../processing" />
77

8-
<property name="core.jar.path" value="android-core.zip" />
8+
<property name="core.jar.path" value="processing-core.zip" />
99
<property name="mode.jar.path" value="mode/AndroidMode.jar" />
1010
<property name="mode.dist.path" value="release/AndroidMode.zip" />
1111
<property name="tools.jar.path" value="mode/tools.jar" />
@@ -58,15 +58,15 @@
5858
<!--
5959
<target name="android-dist-check">
6060
-->
61-
<!-- ensure that the android-core.zip file has been built -->
61+
<!-- ensure that the processing-core.zip file has been built -->
6262
<!--
6363
<available file="${core.jar.path}"
6464
property="android-core-present" />
6565
-->
66-
<!--<echo message="${target.path}/modes/android/android-core.zip" />-->
66+
<!--<echo message="${target.path}/modes/android/processing-core.zip" />-->
6767
<!--
6868
<fail unless="android-core-present"
69-
message="android-core.zip was not built, but is required for dist. Install the Android tools, set ANDROID_SDK, and try again." />
69+
message="processing-core.zip was not built, but is required for dist. Install the Android tools, set ANDROID_SDK, and try again." />
7070
</target>
7171
-->
7272

@@ -85,7 +85,7 @@
8585

8686
<zip destfile="${mode.dist.path}">
8787
<zipfileset dir="." prefix="AndroidMode">
88-
<include name="android-core.zip" />
88+
<include name="processing-core.zip" />
8989
<include name="mode.properties" />
9090
<include name="mode/**" />
9191
<include name="templates/**" />

core/.classpath

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
<classpath>
33
<classpathentry kind="src" path="src"/>
44
<classpathentry kind="var" path="ANDROID_LIB"/>
5-
<classpathentry kind="lib" path="library/android-support-v4.jar"/>
65
<classpathentry kind="lib" path="library/wearable-2.0.0.jar"/>
6+
<classpathentry kind="lib" path="library/support-annotations-25.2.0.jar"/>
7+
<classpathentry kind="lib" path="library/support-compat-25.2.0.jar"/>
8+
<classpathentry kind="lib" path="library/support-fragment-25.2.0.jar"/>
79
<classpathentry kind="output" path="bin"/>
810
</classpath>

core/build.gradle

+4-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ buildscript {
1010

1111
dependencies {
1212
compile name: 'android'
13-
compile name: 'android-support-v4'
13+
compile name: 'support-compat-25.2.0'
14+
compile name: 'support-fragment-25.2.0'
15+
compile name: 'support-annotations-25.2.0'
1416
compile name: 'wearable-2.0.0'
1517
}
1618

@@ -46,7 +48,7 @@ task dist {
4648
doLast {
4749
// make copy of jar file as zip
4850
Files.copy(file("$buildDir/libs/core.jar").toPath(),
49-
file("$buildDir/libs/android-core.zip").toPath(), REPLACE_EXISTING);
51+
file("$buildDir/libs/processing-core.zip").toPath(), REPLACE_EXISTING);
5052

5153
// and copy it to root
5254
Files.copy(file("$buildDir/libs/core.jar").toPath(),

core/build.xml

+8-3
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,22 @@
77
<property name="processing.dir" value="../../processing" />
88

99
<!-- path to the core library -->
10-
<property name="core.jar.path" value="../android-core.zip" />
10+
<property name="core.jar.path" value="../processing-core.zip" />
1111

1212
<!-- Android platform to build the core library -->
1313
<property name="android.platform" value="android-25" />
1414

1515
<!-- Wear version to build the core library -->
1616
<property name="wear.version" value="2.0.0" />
1717

18+
<!-- Support version to build the core library -->
19+
<property name="support.version" value="25.2.0" />
20+
1821
<!-- oh ant, you're so cute and convoluted -->
1922
<target name="build" depends="sdk_chatter,actual_build" />
2023

2124
<target name="sdk_chatter" unless="env.ANDROID_SDK">
22-
<echo message="ANDROID_SDK not set, skipping build of android-core.zip" />
25+
<echo message="ANDROID_SDK not set, skipping build of processing-core.zip" />
2326
</target>
2427

2528
<target name="sdk_whining">
@@ -41,7 +44,9 @@
4144
encoding="UTF-8"
4245
includeAntRuntime="false"
4346
bootclasspath="${env.ANDROID_SDK}/platforms/${android.platform}/android.jar;
44-
library/android-support-v4.jar;
47+
library/support-compat-${support.version}.jar;
48+
library/support-fragment-${support.version}.jar;
49+
library/support-annotations-${support.version}.jar;
4550
library/wearable-${wear.version}.jar"
4651
srcdir="src" destdir="bin" />
4752

core/library/android-support-v4.jar

-1.36 MB
Binary file not shown.
22.4 KB
Binary file not shown.
751 KB
Binary file not shown.
163 KB
Binary file not shown.

core/src/processing/a2d/PGraphicsAndroid2D.java

+13-32
Original file line numberDiff line numberDiff line change
@@ -135,34 +135,6 @@ public PGraphicsAndroid2D() {
135135
//public void setPath(String path)
136136

137137

138-
/**
139-
* Called in response to a resize event, handles setting the
140-
* new width and height internally, as well as re-allocating
141-
* the pixel buffer for the new size.
142-
*
143-
* Note that this will nuke any cameraMode() settings.
144-
*/
145-
// @Override
146-
// public void setSize(int iwidth, int iheight) { // ignore
147-
// width = iwidth;
148-
// height = iheight;
149-
// width1 = width - 1;
150-
// height1 = height - 1;
151-
//
152-
// allocate();
153-
// reapplySettings();
154-
// }
155-
156-
157-
@Override
158-
protected void allocate() {
159-
if (useBitmap) {
160-
if (bitmap != null) bitmap.recycle();
161-
bitmap = Bitmap.createBitmap(width, height, Config.ARGB_8888);
162-
canvas = new Canvas(bitmap);
163-
}
164-
}
165-
166138

167139
@Override
168140
public void dispose() {
@@ -197,8 +169,20 @@ public void requestDraw() {
197169
// }
198170

199171

172+
protected Canvas checkCanvas() {
173+
if (canvas == null && (useBitmap || !primaryGraphics)) {
174+
if (bitmap != null) bitmap.recycle();
175+
bitmap = Bitmap.createBitmap(width, height, Config.ARGB_8888);
176+
canvas = new Canvas(bitmap);
177+
}
178+
return canvas;
179+
}
180+
181+
200182
@Override
201183
public void beginDraw() {
184+
canvas = checkCanvas();
185+
202186
// if (primaryGraphics) {
203187
// canvas = parent.getSurfaceHolder().lockCanvas(null);
204188
// if (canvas == null) {
@@ -232,7 +216,7 @@ public void endDraw() {
232216
// }
233217

234218
if (primaryGraphics) {
235-
SurfaceHolder holder = parent.surface.getSurfaceHolder();
219+
SurfaceHolder holder = parent.getSurface().getSurfaceHolder();
236220
if (holder != null) {
237221
Canvas screen = null;
238222
try {
@@ -473,7 +457,6 @@ public void breakShape() {
473457
@Override
474458
public void endShape(int mode) {
475459
if (shape == POINTS && stroke && vertexCount > 0) {
476-
// Matrix m = canvas.getMatrix();
477460
Matrix m = getMatrixImp();
478461
if (strokeWeight == 1 && m.isIdentity()) {
479462
if (screenPoint == null) {
@@ -519,15 +502,13 @@ public void endShape(int mode) {
519502

520503
@Override
521504
protected void clipImpl(float x1, float y1, float x2, float y2) {
522-
// canvas.save(Canvas.CLIP_SAVE_FLAG);
523505
canvas.clipRect(x1, y1, x2, y2);
524506
}
525507

526508

527509
@Override
528510
public void noClip() {
529511
canvas.clipRect(0, 0, width, height, Region.Op.REPLACE);
530-
// canvas.restore();
531512
}
532513

533514

core/src/processing/android/AppComponent.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/*
44
Part of the Processing project - http://processing.org
55
6-
Copyright (c) 2016 The Processing Foundation
6+
Copyright (c) 2016-17 The Processing Foundation
77
88
This library is free software; you can redistribute it and/or
99
modify it under the terms of the GNU Lesser General Public
@@ -38,12 +38,12 @@ abstract public interface AppComponent extends PConstants {
3838
public int getKind();
3939
public void setSketch(PApplet sketch);
4040
public PApplet getSketch();
41+
public ServiceEngine getEngine();
4142

4243
public void startActivity(Intent intent);
4344

4445
public void requestDraw();
4546
public boolean canDraw();
4647

4748
public void dispose();
48-
public void onPermissionsGranted();
4949
}

core/src/processing/android/PFragment.java

+42-18
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,13 @@
2222

2323
package processing.android;
2424

25+
import android.support.annotation.IdRes;
26+
import android.support.annotation.LayoutRes;
2527
import android.support.v4.app.Fragment;
2628
import android.support.v4.app.FragmentManager;
2729
import android.support.v4.app.FragmentTransaction;
2830
import android.util.DisplayMetrics;
31+
2932
import android.content.pm.ActivityInfo;
3033
import android.content.res.Configuration;
3134
import android.graphics.Point;
@@ -41,17 +44,21 @@
4144

4245
public class PFragment extends Fragment implements AppComponent {
4346
private DisplayMetrics metrics;
44-
protected Point size;
45-
protected PApplet sketch;
47+
private Point size;
48+
private PApplet sketch;
4649

4750
public PFragment() {
4851
}
4952

50-
public void init(int layout, FragmentManager fragmentManager) {
51-
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
52-
fragmentTransaction.add(layout, this);
53-
fragmentTransaction.commit();
54-
}
53+
// public void setLayout(int layout, FragmentManager manager) {
54+
// this.layout = layout;
55+
// if (sketch != null) {
56+
// sketch.parentLayout = layout;
57+
// }
58+
// FragmentTransaction transaction = manager.beginTransaction();
59+
// transaction.add(layout, this);
60+
// transaction.commit();
61+
// }
5562

5663
public void initDimensions() {
5764
WindowManager wm = getActivity().getWindowManager();
@@ -98,19 +105,40 @@ public void setSketch(PApplet sketch) {
98105
this.sketch = sketch;
99106
}
100107

108+
public void setSketch(PApplet sketch, @IdRes int id, @LayoutRes int layout,
109+
FragmentManager manager) {
110+
this.sketch = sketch;
111+
sketch.parentLayout = layout;
112+
FragmentTransaction transaction = manager.beginTransaction();
113+
transaction.add(id, this);
114+
transaction.commit();
115+
}
116+
117+
public void setSketch(PApplet sketch, View view, FragmentManager manager) {
118+
this.sketch = sketch;
119+
FragmentTransaction transaction = manager.beginTransaction();
120+
transaction.add(view.getId(), this);
121+
transaction.commit();
122+
}
123+
101124
public PApplet getSketch() {
102125
return sketch;
103126
}
104127

128+
public ServiceEngine getEngine() {
129+
return null;
130+
}
131+
105132
public void dispose() {
106133
}
107134

135+
108136
@Override
109137
public View onCreateView(LayoutInflater inflater, ViewGroup container,
110138
Bundle savedInstanceState) {
111139
if (sketch != null) {
112140
sketch.initSurface(inflater, container, savedInstanceState, this, null);
113-
return sketch.surface.getRootView();
141+
return sketch.getSurface().getRootView();
114142
} else {
115143
return null;
116144
}
@@ -158,16 +186,6 @@ public void onConfigurationChanged(Configuration newConfig) {
158186
}
159187

160188

161-
// public void onBackPressed() {
162-
// sketch.exit();
163-
// }
164-
165-
166-
public void onPermissionsGranted() {
167-
if (sketch != null) sketch.onPermissionsGranted();
168-
}
169-
170-
171189
public void setOrientation(int which) {
172190
if (which == PORTRAIT) {
173191
getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
@@ -180,8 +198,14 @@ public void setOrientation(int which) {
180198
public void requestDraw() {
181199
}
182200

201+
183202
public boolean canDraw() {
184203
if (sketch == null) return false;
185204
return sketch.isLooping();
186205
}
206+
207+
208+
//public void onBackPressed() {
209+
// sketch.exit();
210+
//}
187211
}

0 commit comments

Comments
 (0)