Skip to content

Commit 01530b6

Browse files
author
rjmatthews62
committed
5x22 - setFullTitle, and fix to NPE in receive broadcast events.
1 parent 3743659 commit 01530b6

File tree

5 files changed

+56
-7
lines changed

5 files changed

+56
-7
lines changed

android/Common/src/com/googlecode/android_scripting/facade/EventFacade.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,12 +360,16 @@ public BroadcastListener(EventFacade parent, boolean enqueue) {
360360

361361
@Override
362362
public void onReceive(Context context, Intent intent) {
363-
Bundle data = (Bundle) intent.getExtras().clone();
363+
Bundle data;
364+
if (intent.getExtras() != null) {
365+
data = (Bundle) intent.getExtras().clone();
366+
} else {
367+
data = new Bundle();
368+
}
364369
data.putString("action", intent.getAction());
365370
try {
366371
mParent.eventPost("sl4a", JsonBuilder.build(data).toString(), mEnQueue);
367372
} catch (JSONException e) {
368-
// TODO Auto-generated catch block
369373
e.printStackTrace();
370374
}
371375
}

android/Common/src/com/googlecode/android_scripting/facade/ui/FullScreenTask.java

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,16 @@ public class FullScreenTask extends FutureActivityTask<Object> implements OnClic
3535
protected final CountDownLatch mShowLatch = new CountDownLatch(1);
3636
protected Handler mHandler = null;
3737
private List<Integer> mOverrideKeys;
38+
protected String mTitle;
3839

39-
public FullScreenTask(String layout) {
40+
public FullScreenTask(String layout, String title) {
4041
super();
4142
mLayout = layout;
43+
if (title != null) {
44+
mTitle = title;
45+
} else {
46+
mTitle = "SL4a";
47+
}
4248
}
4349

4450
@Override
@@ -60,7 +66,7 @@ public void onCreate() {
6066
mInflater.setIdList(R.id.class);
6167
}
6268
getActivity().setContentView(mView);
63-
getActivity().setTitle("SL4A Title");
69+
getActivity().setTitle(mTitle);
6470
mInflater.setClickListener(mView, this, this);
6571
mShowLatch.countDown();
6672
}
@@ -240,6 +246,22 @@ public void run() {
240246
}
241247
}
242248

249+
private class SetTitle implements Runnable {
250+
String mSetTitle;
251+
CountDownLatch mLatch = new CountDownLatch(1);
252+
253+
SetTitle(String title) {
254+
mSetTitle = title;
255+
}
256+
257+
@Override
258+
public void run() {
259+
mTitle = mSetTitle;
260+
getActivity().setTitle(mSetTitle);
261+
mLatch.countDown();
262+
}
263+
}
264+
243265
@Override
244266
public boolean onKeyDown(int keyCode, KeyEvent event) {
245267
Map<String, String> data = new HashMap<String, String>();
@@ -279,4 +301,14 @@ public void setLayout(String layout) {
279301
}
280302
}
281303

304+
public void setTitle(String title) {
305+
SetTitle p = new SetTitle(title);
306+
mHandler.post(p);
307+
try {
308+
p.mLatch.await();
309+
} catch (InterruptedException e) {
310+
mInflater.getErrors().add(e.toString());
311+
}
312+
}
313+
282314
}

android/Common/src/com/googlecode/android_scripting/facade/ui/UiFacade.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -549,13 +549,17 @@ public boolean onPrepareOptionsMenu(Menu menu) {
549549
*/
550550
@Rpc(description = "Show Full Screen.")
551551
public List<String> fullShow(
552-
@RpcParameter(name = "layout", description = "String containing View layout") String layout)
552+
@RpcParameter(name = "layout", description = "String containing View layout") String layout,
553+
@RpcParameter(name = "title", description = "Activity Title") @RpcOptional String title)
553554
throws InterruptedException {
554555
if (mFullScreenTask != null) {
555556
// fullDismiss();
556557
mFullScreenTask.setLayout(layout);
558+
if (title != null) {
559+
mFullScreenTask.setTitle(title);
560+
}
557561
} else {
558-
mFullScreenTask = new FullScreenTask(layout);
562+
mFullScreenTask = new FullScreenTask(layout, title);
559563
mFullScreenTask.setEventFacade(mEventFacade);
560564
mFullScreenTask.setUiFacade(this);
561565
mFullScreenTask.setOverrideKeys(mOverrideKeys);
@@ -611,6 +615,15 @@ public String fullSetList(
611615
return mFullScreenTask.setList(id, items);
612616
}
613617

618+
@Rpc(description = "Set the Full Screen Activity Title")
619+
public void fullSetTitle(
620+
@RpcParameter(name = "title", description = "Activity Title") String title) {
621+
if (mFullScreenTask == null) {
622+
throw new RuntimeException("No screen displayed.");
623+
}
624+
mFullScreenTask.setTitle(title);
625+
}
626+
614627
/**
615628
* This will override the default behaviour of keys while in the fullscreen mode. ie:
616629
*

android/ScriptingLayerForAndroid/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
33
package="com.googlecode.android_scripting" android:installLocation="auto"
4-
android:versionCode="521" android:versionName="5x21">
4+
android:versionCode="522" android:versionName="5x22">
55
<uses-permission android:name="android.permission.RECEIVE_SMS" />
66
<uses-permission android:name="net.dinglisch.android.tasker.PERMISSION_RUN_TASKS" />
77
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
Binary file not shown.

0 commit comments

Comments
 (0)