Skip to content

Commit 551ca4e

Browse files
committed
make sure that device is a watch when installing a watch face
1 parent c4d4f64 commit 551ca4e

File tree

4 files changed

+29
-9
lines changed

4 files changed

+29
-9
lines changed

src/processing/mode/android/AndroidBuild.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import processing.app.Library;
3232
import processing.app.Messages;
3333
import processing.app.Platform;
34-
import processing.app.Preferences;
3534
import processing.app.Sketch;
3635
import processing.app.SketchException;
3736
import processing.app.Util;
@@ -71,7 +70,7 @@ class AndroidBuild extends JavaBuild {
7170
static public final String target_api_level = "22";
7271
static public final String target_platform = "android-" + target_api_level;
7372

74-
static int appComponent = FRAGMENT;
73+
static public int appComponent = FRAGMENT;
7574
static boolean forceNewManifest = false;
7675

7776
private final AndroidSDK sdk;
@@ -204,11 +203,6 @@ public File createProject() throws IOException, SketchException {
204203
// object returned by initSketchSize()
205204
writeMainClass(srcFolder, preproc.getRenderer(sketch.getMainProgram()));
206205

207-
// new location for SDK Tools 17: /opt/android/tools/proguard/proguard-android.txt
208-
// File proguardSrc = new File(sdk.getSdkFolder(), "tools/lib/proguard.cfg");
209-
// File proguardDst = new File(tmpFolder, "proguard.cfg");
210-
// Base.copyFile(proguardSrc, proguardDst);
211-
212206
final File libsFolder = mkdirs(tmpFolder, "libs");
213207
final File assetsFolder = mkdirs(tmpFolder, "assets");
214208

src/processing/mode/android/AndroidMode.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ public void handleRunDevice(Sketch sketch, RunnerListener listener)
300300

301301
public void showSelectComponentMessage() {
302302
if (showBluetoothDebugMessage && AndroidBuild.appComponent == AndroidBuild.WATCHFACE) {
303-
Messages.showMessage("Enable bluetooth debugging!",
303+
Messages.showMessage("Is Debugging over Bluetooth enabled?",
304304
"Processing will access the wearable through the handheld paired to it.\n" +
305305
"Make sure to enable \"Debugging over Bluetooth\" for this to work:\n" +
306306
"http://developer.android.com/training/wearables/apps/bt-debugging.html");
@@ -310,7 +310,7 @@ public void showSelectComponentMessage() {
310310

311311
public void showPostBuildMessage() {
312312
if (showWallpaperSelectMessage && AndroidBuild.appComponent == AndroidBuild.WALLPAPER) {
313-
Messages.showMessage("Now select the wallpaper!",
313+
Messages.showMessage("Now select the wallpaper...",
314314
"Processing built and installed your sketch\n" +
315315
"as a live wallpaper on the selected device.\n" +
316316
"You need to open the wallpaper selector\n" +

src/processing/mode/android/AndroidRunner.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import java.util.regex.Pattern;
3131

3232
import processing.app.ui.Editor;
33+
import processing.app.Messages;
3334
import processing.app.RunnerListener;
3435
import processing.app.SketchException;
3536
import processing.mode.java.runner.Runner;
@@ -76,6 +77,15 @@ public void launch(Future<Device> deviceFuture) {
7677
Devices.killAdbServer();
7778
return;
7879
}
80+
81+
if (AndroidBuild.appComponent == AndroidBuild.WATCHFACE && !device.hasFeature("watch")) {
82+
Messages.showWarning("Device is not a watch!",
83+
"Processing built your sketch as a watch face, but\n" +
84+
"you selected a non-watch device to install it on.\n" +
85+
"Please select a watch device instead.");
86+
listener.statusError("Trying to install a watch face on a non-watch device. Select correct device.");
87+
return;
88+
}
7989

8090
device.addListener(this);
8191

src/processing/mode/android/Device.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
class Device {
4040
private final Devices env;
4141
private final String id;
42+
private final String features;
4243
private final Set<Integer> activeProcesses = new HashSet<Integer>();
4344
private final Set<DeviceListener> listeners =
4445
Collections.synchronizedSet(new HashSet<DeviceListener>());
@@ -52,6 +53,17 @@ class Device {
5253
public Device(final Devices env, final String id) {
5354
this.env = env;
5455
this.id = id;
56+
57+
// http://android.stackexchange.com/questions/82169/howto-get-devices-features-with-adb
58+
String concat = "";
59+
try {
60+
final ProcessResult res = adb("shell", "getprop", "ro.build.characteristics");
61+
for (String line : res) {
62+
concat += "," + line.toLowerCase();
63+
}
64+
} catch (final Exception e) {
65+
}
66+
this.features = concat;
5567
}
5668

5769
public void bringLauncherToFront() {
@@ -64,6 +76,10 @@ public void bringLauncherToFront() {
6476
}
6577
}
6678

79+
public boolean hasFeature(String feature) {
80+
return -1 < features.indexOf(feature);
81+
}
82+
6783
public String getName() {
6884
String name = "";
6985

0 commit comments

Comments
 (0)