• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Aucun tag

Frequently used words (click to add to your profile)

javac++androidlinuxc#objective-cqt誰得cocoawindowspythonphprubygameguibathyscaphec翻訳omegat計画中(planning stage)frameworktwittertestdombtronvb.netdirectxarduinopreviewerゲームエンジン

Keep an android app up for demo


Commit MetaInfo

Révisionebd8b52d67dd2a376c99520f13ae1ef021569d33 (tree)
l'heure2014-01-30 08:06:06
Auteurgull08 (HMML) <hmml3939@gmai...>
Commitergull08 (HMML)

Message de Log

Add setting UI, error toast.

Change Summary

Modification

--- a/.settings/org.eclipse.jdt.core.prefs
+++ b/.settings/org.eclipse.jdt.core.prefs
@@ -1,4 +1,11 @@
11 eclipse.preferences.version=1
2+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
23 org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
4+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
35 org.eclipse.jdt.core.compiler.compliance=1.6
6+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
7+org.eclipse.jdt.core.compiler.debug.localVariable=generate
8+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
9+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
10+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
411 org.eclipse.jdt.core.compiler.source=1.6
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -28,15 +28,10 @@
2828 <category android:name="android.intent.category.LAUNCHER" />
2929 </intent-filter>
3030 </activity>
31- <service android:name="WatchService"/><receiver android:name="StartReceiver">
31+ <service android:name="WatchService"/><receiver android:name="EventReceiver">
3232 <intent-filter>
3333 <action android:name="android.intent.action.BOOT_COMPLETED" />
3434 <action android:name="android.intent.action.ACTION_POWER_CONNECTED" />
35- </intent-filter>
36- </receiver>
37-
38- <receiver android:name="StopReceiver">
39- <intent-filter>
4035 <action android:name="android.intent.action.ACTION_POWER_DISCONNECTED"/>
4136 </intent-filter>
4237 </receiver>
--- a/res/layout/activity_main.xml
+++ b/res/layout/activity_main.xml
@@ -8,86 +8,161 @@
88 android:paddingTop="@dimen/activity_vertical_margin"
99 tools:context=".MainActivity" >
1010
11- <RadioGroup
12- android:id="@+id/radioGroupEnabled"
13- android:layout_width="wrap_content"
14- android:layout_height="wrap_content"
15- android:layout_alignLeft="@+id/textView1"
16- android:layout_below="@+id/textView1"
17- android:orientation="horizontal" >
18-
19- <RadioButton
20- android:id="@+id/radio_enabled"
21- android:layout_width="wrap_content"
22- android:layout_height="wrap_content"
23- android:checked="true"
24- android:text="Enabled" />
25-
26- <RadioButton
27- android:id="@+id/radio_disabled"
28- android:layout_width="wrap_content"
29- android:layout_height="wrap_content"
30- android:text="Disabled" />
31- </RadioGroup>
32-
33- <TextView
34- android:id="@+id/textView1"
35- android:layout_width="wrap_content"
36- android:layout_height="wrap_content"
37- android:layout_alignParentLeft="true"
38- android:layout_alignParentTop="true"
39- android:text="Enable"
40- android:textAppearance="?android:attr/textAppearanceLarge" />
41-
42- <EditText
43- android:id="@+id/text_interval"
44- android:layout_width="wrap_content"
45- android:layout_height="wrap_content"
46- android:layout_alignLeft="@+id/textView2"
47- android:layout_below="@+id/textView2"
48- android:ems="10"
49- android:inputType="numberDecimal"
50- android:text="30" >
51-
52- <requestFocus />
53- </EditText>
54-
55- <TextView
56- android:id="@+id/textView3"
57- android:layout_width="wrap_content"
58- android:layout_height="wrap_content"
59- android:layout_alignBaseline="@+id/text_interval"
60- android:layout_alignBottom="@+id/text_interval"
61- android:layout_toRightOf="@+id/text_interval"
62- android:text="sec" />
63-
64- <TextView
65- android:id="@+id/textView4"
66- android:layout_width="wrap_content"
67- android:layout_height="wrap_content"
68- android:layout_alignLeft="@+id/text_interval"
69- android:layout_below="@+id/text_interval"
70- android:layout_marginTop="16dp"
71- android:text="Trigger open URL"
72- android:textAppearance="?android:attr/textAppearanceLarge" />
73-
74- <TextView
75- android:id="@+id/textView2"
76- android:layout_width="wrap_content"
77- android:layout_height="wrap_content"
78- android:layout_alignLeft="@+id/radioGroupEnabled"
79- android:layout_below="@+id/radioGroupEnabled"
80- android:layout_marginTop="16dp"
81- android:text="Watch Interval"
82- android:textAppearance="?android:attr/textAppearanceLarge" />
83-
84- <EditText
85- android:id="@+id/text_open"
86- android:layout_width="wrap_content"
87- android:layout_height="wrap_content"
88- android:layout_alignLeft="@+id/textView4"
89- android:layout_alignParentRight="true"
90- android:layout_below="@+id/textView4"
91- android:ems="10" />
11+ <ScrollView
12+ android:id="@+id/scrollView1"
13+ android:layout_width="fill_parent"
14+ android:layout_height="fill_parent" >
15+
16+ <LinearLayout
17+ android:layout_width="fill_parent"
18+ android:layout_height="fill_parent"
19+ android:orientation="vertical"
20+ android:scrollbarStyle="insideOverlay" >
21+
22+ <TextView
23+ android:id="@+id/textView1"
24+ android:layout_width="wrap_content"
25+ android:layout_height="wrap_content"
26+ android:text="Watcher status"
27+ android:textAppearance="?android:attr/textAppearanceLarge" />
28+
29+ <RadioGroup
30+ android:id="@+id/radioGroupEnabled"
31+ android:layout_width="wrap_content"
32+ android:layout_height="wrap_content"
33+ android:orientation="horizontal" >
34+
35+ <RadioButton
36+ android:id="@+id/radio_enabled"
37+ android:layout_width="wrap_content"
38+ android:layout_height="wrap_content"
39+ android:checked="true"
40+ android:text="Enabled" />
41+
42+ <RadioButton
43+ android:id="@+id/radio_disabled"
44+ android:layout_width="wrap_content"
45+ android:layout_height="wrap_content"
46+ android:text="Disabled" />
47+ </RadioGroup>
48+
49+ <TextView
50+ android:id="@+id/textView2"
51+ android:layout_width="wrap_content"
52+ android:layout_height="wrap_content"
53+ android:layout_marginTop="16dp"
54+ android:text="Watch interval"
55+ android:textAppearance="?android:attr/textAppearanceLarge" />
56+
57+ <LinearLayout
58+ android:layout_width="wrap_content"
59+ android:layout_height="wrap_content" >
60+
61+ <EditText
62+ android:id="@+id/text_interval"
63+ android:layout_width="wrap_content"
64+ android:layout_height="wrap_content"
65+ android:layout_weight="1"
66+ android:ems="10"
67+ android:inputType="numberDecimal"
68+ android:maxLines="1"
69+ android:text="30" />
70+
71+ <TextView
72+ android:id="@+id/textView3"
73+ android:layout_width="wrap_content"
74+ android:layout_height="wrap_content"
75+ android:layout_weight="1"
76+ android:text="sec" />
77+ </LinearLayout>
78+
79+ <TextView
80+ android:id="@+id/textView6"
81+ android:layout_width="wrap_content"
82+ android:layout_height="wrap_content"
83+ android:layout_marginTop="16dp"
84+ android:text="Watch target package"
85+ android:textAppearance="?android:attr/textAppearanceLarge" />
86+
87+ <EditText
88+ android:id="@+id/text_watch"
89+ android:layout_width="fill_parent"
90+ android:layout_height="wrap_content"
91+ android:ems="10"
92+ android:minLines="1" />
93+
94+ <TextView
95+ android:id="@+id/textView5"
96+ android:layout_width="wrap_content"
97+ android:layout_height="wrap_content"
98+ android:layout_marginTop="18dp"
99+ android:text="Launch method"
100+ android:textAppearance="?android:attr/textAppearanceLarge" />
101+
102+ <RadioGroup
103+ android:id="@+id/radioGroupMethod"
104+ android:layout_width="wrap_content"
105+ android:layout_height="wrap_content"
106+ android:orientation="horizontal" >
107+
108+ <RadioButton
109+ android:id="@+id/radio_launch_package"
110+ android:layout_width="wrap_content"
111+ android:layout_height="wrap_content"
112+ android:checked="true"
113+ android:text="Run package" />
114+
115+ <RadioButton
116+ android:id="@+id/radio_launch_url"
117+ android:layout_width="wrap_content"
118+ android:layout_height="wrap_content"
119+ android:text="Open URL" />
120+ </RadioGroup>
121+
122+ <TextView
123+ android:id="@+id/textView4"
124+ android:layout_width="wrap_content"
125+ android:layout_height="wrap_content"
126+ android:layout_marginTop="16dp"
127+ android:text="Trigger open URL"
128+ android:textAppearance="?android:attr/textAppearanceLarge" />
129+
130+ <EditText
131+ android:id="@+id/text_open"
132+ android:layout_width="fill_parent"
133+ android:layout_height="wrap_content"
134+ android:ems="10"
135+ android:minLines="1" >
136+
137+ <requestFocus />
138+ </EditText>
139+
140+ <TextView
141+ android:id="@+id/textView7"
142+ android:layout_width="wrap_content"
143+ android:layout_height="wrap_content"
144+ android:text="Event handlers"
145+ android:textAppearance="?android:attr/textAppearanceLarge" />
146+
147+ <CheckBox
148+ android:id="@+id/check_boot"
149+ android:layout_width="wrap_content"
150+ android:layout_height="wrap_content"
151+ android:text="Enable on boot" />
152+
153+ <CheckBox
154+ android:id="@+id/check_power_connected"
155+ android:layout_width="wrap_content"
156+ android:layout_height="wrap_content"
157+ android:text="Enable on power connected" />
158+
159+ <CheckBox
160+ android:id="@+id/check_power_disconnected"
161+ android:layout_width="wrap_content"
162+ android:layout_height="wrap_content"
163+ android:text="Disable on power disconnected" />
164+ </LinearLayout>
165+
166+ </ScrollView>
92167
93168 </RelativeLayout>
\ No newline at end of file
--- /dev/null
+++ b/src/jp/nekoteki/android/demowatcher/EventReceiver.java
@@ -0,0 +1,27 @@
1+package jp.nekoteki.android.demowatcher;
2+
3+import android.content.BroadcastReceiver;
4+import android.content.Context;
5+import android.content.Intent;
6+import android.content.SharedPreferences;
7+import android.preference.PreferenceManager;
8+
9+public class EventReceiver extends BroadcastReceiver {
10+
11+ @Override
12+ public void onReceive(Context context, Intent intent) {
13+ String act = intent.getAction();
14+ SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
15+ if (act.equals(Intent.ACTION_BOOT_COMPLETED) &&
16+ prefs.getBoolean("handle_boot", true)) {
17+ new WatchService().schedule(context);
18+ } else if (act.equals(Intent.ACTION_POWER_CONNECTED) &&
19+ prefs.getBoolean("handle_power_connected", true)) {
20+ new WatchService().schedule(context);
21+ } else if (act.equals(Intent.ACTION_POWER_DISCONNECTED) &&
22+ prefs.getBoolean("handle_power_disconnected", true)) {
23+ new WatchService().cancelSchedule(context);
24+ }
25+
26+ }
27+}
--- a/src/jp/nekoteki/android/demowatcher/MainActivity.java
+++ b/src/jp/nekoteki/android/demowatcher/MainActivity.java
@@ -1,5 +1,6 @@
11 package jp.nekoteki.android.demowatcher;
22
3+import android.R.bool;
34 import android.os.Bundle;
45 import android.os.Environment;
56 import android.preference.PreferenceManager;
@@ -15,6 +16,9 @@ import android.text.Editable;
1516 import android.text.TextWatcher;
1617 import android.util.Log;
1718 import android.view.Menu;
19+import android.view.View;
20+import android.widget.CheckBox;
21+import android.widget.CompoundButton;
1822 import android.widget.EditText;
1923 import android.widget.RadioButton;
2024 import android.widget.RadioGroup;
@@ -34,10 +38,8 @@ public class MainActivity extends Activity {
3438
3539 RadioGroup enable_raidos = (RadioGroup) findViewById(R.id.radioGroupEnabled);
3640 enable_raidos.setOnCheckedChangeListener(new OnCheckedChangeListener() {
37-
3841 @Override
3942 public void onCheckedChanged(RadioGroup group, int checkedId) {
40- // TODO Auto-generated method stub
4143 if (checkedId == R.id.radio_disabled) {
4244 MainActivity.this.cancelSchedule();
4345 } else {
@@ -47,62 +49,125 @@ public class MainActivity extends Activity {
4749 }
4850 });
4951
52+ if (prefs.getString("method", "package").equals("url")) {
53+ ((RadioButton) findViewById(R.id.radio_launch_url)).setChecked(true);
54+ } else {
55+ ((RadioButton) findViewById(R.id.radio_launch_package)).setChecked(true);;
56+ }
57+ RadioGroup method_raidos = (RadioGroup) findViewById(R.id.radioGroupMethod);
58+ method_raidos.setOnCheckedChangeListener(new OnCheckedChangeListener() {
59+ @Override
60+ public void onCheckedChanged(RadioGroup group, int checkedId) {
61+ Editor peditor = MainActivity.this.prefs.edit();
62+ if (checkedId == R.id.radio_launch_url) {
63+ peditor.putString("method", "url");
64+ } else {
65+ peditor.putString("method", "package");
66+ }
67+ peditor.commit();
68+ MainActivity.this.reSchdule();
69+ }
70+ });
71+
5072 EditText interval = (EditText) findViewById(R.id.text_interval);
5173 interval.setText(String.valueOf(prefs.getInt("interval", WatchService.DEFAULT_INTERVAL)));
5274 interval.addTextChangedListener(new TextWatcher() {
53-
5475 @Override
55- public void onTextChanged(CharSequence s, int start, int before, int count) {
56- return;
57- }
76+ public void onTextChanged(CharSequence s, int start, int before, int count) {}
5877
5978 @Override
60- public void beforeTextChanged(CharSequence s, int start, int count, int after) {
61- return;
62- }
79+ public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
6380
6481 @Override
6582 public void afterTextChanged(Editable s) {
6683 Editor peditor = MainActivity.this.prefs.edit();
6784 peditor.putInt("interval", MainActivity.this.getInterval()/1000);
6885 peditor.commit();
86+ MainActivity.this.reSchdule();
6987 }
7088 });
7189
7290 EditText open = (EditText) findViewById(R.id.text_open);
7391 open.setText(prefs.getString("open", WatchService.DEFAULT_OPEN));
7492 open.addTextChangedListener(new TextWatcher() {
93+ @Override
94+ public void onTextChanged(CharSequence s, int start, int before, int count) {}
7595
7696 @Override
77- public void onTextChanged(CharSequence s, int start, int before, int count) {
78- return;
97+ public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
98+
99+ @Override
100+ public void afterTextChanged(Editable s) {
101+ Editor peditor = MainActivity.this.prefs.edit();
102+ peditor.putString("open", s.toString());
103+ peditor.commit();
104+ MainActivity.this.reSchdule();
79105 }
106+ });
107+
108+ EditText watch = (EditText) findViewById(R.id.text_watch);
109+ watch.setText(prefs.getString("watch", WatchService.DEFAULT_WATCH));
110+ watch.addTextChangedListener(new TextWatcher() {
111+ @Override
112+ public void onTextChanged(CharSequence s, int start, int before, int count) {}
113+
114+ @Override
115+ public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
80116
81117 @Override
82- public void beforeTextChanged(CharSequence s, int start, int count, int after) {
83- return;
84-
118+ public void afterTextChanged(Editable s) {
119+ Editor peditor = MainActivity.this.prefs.edit();
120+ peditor.putString("watch", s.toString());
121+ peditor.commit();
122+ MainActivity.this.reSchdule();
123+ }
124+ });
125+
126+ CheckBox check_boot = (CheckBox) findViewById(R.id.check_boot);
127+ check_boot.setChecked(prefs.getBoolean("handle_boot", true));
128+ check_boot.setOnClickListener(new View.OnClickListener() {
129+ @Override
130+ public void onClick(View v) {
131+ Editor peditor = MainActivity.this.prefs.edit();
132+ peditor.putBoolean("handle_boot", ((CheckBox) v).isChecked());
133+ peditor.commit();
85134 }
135+ });
86136
137+ CheckBox check_pc = (CheckBox) findViewById(R.id.check_power_connected);
138+ check_pc.setChecked(prefs.getBoolean("handle_boot", true));
139+ check_pc.setOnClickListener(new View.OnClickListener() {
87140 @Override
88- public void afterTextChanged(Editable s) {
141+ public void onClick(View v) {
89142 Editor peditor = MainActivity.this.prefs.edit();
90- peditor.putString("open", s.toString());
143+ peditor.putBoolean("handle_power_connected", ((CheckBox) v).isChecked());
144+ peditor.commit();
145+ }
146+ });
147+
148+ CheckBox check_pd = (CheckBox) findViewById(R.id.check_power_disconnected);
149+ check_pd.setChecked(prefs.getBoolean("handle_boot", true));
150+ check_pd.setOnClickListener(new View.OnClickListener() {
151+ @Override
152+ public void onClick(View v) {
153+ Editor peditor = MainActivity.this.prefs.edit();
154+ peditor.putBoolean("handle_power_disconnected", ((CheckBox) v).isChecked());
91155 peditor.commit();
92156 }
93157 });
158+
159+ if (prefs.getBoolean("enabled", false))
160+ schedule();
94161 }
95162
96163 @Override
97164 protected void onResume() {
98165 super.onResume();
99166
100- RadioButton radio_enabled = (RadioButton) findViewById(R.id.radio_enabled);
101- RadioButton radio_disabled = (RadioButton) findViewById(R.id.radio_disabled);
102167 if (this.prefs.getBoolean("enabled", false)) {
103- radio_enabled.setChecked(true);
168+ ((RadioButton) findViewById(R.id.radio_enabled)).setChecked(true);;
104169 } else {
105- radio_disabled.setChecked(true);
170+ ((RadioButton) findViewById(R.id.radio_disabled)).setChecked(true);
106171 }
107172 }
108173
@@ -113,16 +178,21 @@ public class MainActivity extends Activity {
113178 return true;
114179 }
115180
116- public void cancelSchedule() {
117- watcher.cancelSchedule(getApplicationContext());
181+ public void reSchdule() {
182+ if (cancelSchedule())
183+ schedule();
184+ }
185+
186+ public boolean cancelSchedule() {
187+ return watcher.cancelSchedule(getApplicationContext());
118188 }
119189
120- public void schedule() {
190+ public boolean schedule() {
121191 Log.d(this.getClass().getSimpleName(), "Enable watch schedule");
122192 Editor peditor = this.prefs.edit();
123193 peditor.putBoolean("enabled", true);
124194 peditor.commit();
125- watcher.schedule(getApplicationContext());
195+ return watcher.schedule(getApplicationContext());
126196 }
127197
128198 public int getInterval() {
--- a/src/jp/nekoteki/android/demowatcher/StartReceiver.java
+++ /dev/null
@@ -1,14 +0,0 @@
1-package jp.nekoteki.android.demowatcher;
2-
3-import android.content.BroadcastReceiver;
4-import android.content.Context;
5-import android.content.Intent;
6-import android.widget.Toast;
7-
8-public class StartReceiver extends BroadcastReceiver {
9-
10- @Override
11- public void onReceive(Context context, Intent intent) {
12- new WatchService().schedule(context);
13- }
14-}
--- a/src/jp/nekoteki/android/demowatcher/StopReceiver.java
+++ /dev/null
@@ -1,14 +0,0 @@
1-package jp.nekoteki.android.demowatcher;
2-
3-import android.content.BroadcastReceiver;
4-import android.content.Context;
5-import android.content.Intent;
6-import android.widget.Toast;
7-
8-public class StopReceiver extends BroadcastReceiver {
9-
10- @Override
11- public void onReceive(Context context, Intent intent) {
12- new WatchService().cancelSchedule(context);
13- }
14-}
--- a/src/jp/nekoteki/android/demowatcher/WatchService.java
+++ b/src/jp/nekoteki/android/demowatcher/WatchService.java
@@ -13,6 +13,7 @@ import android.content.Intent;
1313 import android.content.SharedPreferences;
1414 import android.content.SharedPreferences.Editor;
1515 import android.net.Uri;
16+import android.os.Handler;
1617 import android.os.PowerManager;
1718 import android.preference.PreferenceManager;
1819 import android.provider.BaseColumns;
@@ -27,13 +28,16 @@ public class WatchService extends IntentService {
2728 final public static String DEFAULT_WATCH = "com.mxtech.videoplayer.pro";
2829 final public static String DEFAULT_OPEN = "file:///sdcard/test/test.mp4";
2930 final public static int DEFAULT_INTERVAL = 30;
31+ public Handler handler;
3032
3133 public WatchService() {
3234 super(NAME);
35+ this.handler = new Handler();
3336 }
3437
3538 public WatchService(String name) {
3639 super(name);
40+ this.handler = new Handler();
3741 }
3842
3943 public PendingIntent getPendingIntent(Context context) {
@@ -50,6 +54,7 @@ public class WatchService extends IntentService {
5054 Intent intent = new Intent(context, WatchService.class);
5155 intent.putExtra("open", this.getOpenTarget(context));
5256 intent.putExtra("watch", this.getWatchTarget(context));
57+ intent.putExtra("method", this.getLaunchMethod(context));
5358 return PendingIntent.getService(context, 0, intent, flag);
5459 }
5560
@@ -65,36 +70,43 @@ public class WatchService extends IntentService {
6570 return getPrefs(c).getString("open", DEFAULT_OPEN);
6671 }
6772
73+ public String getLaunchMethod(Context c) {
74+ return getPrefs(c).getString("method", "package");
75+ }
76+
6877 public int getInterval(Context c) {
6978 return getPrefs(c).getInt("interval", DEFAULT_INTERVAL);
7079 }
7180
7281
73- public void cancelSchedule(Context context) {
82+ public boolean cancelSchedule(Context context) {
7483 Editor peditor = getPrefs(context).edit();
7584 peditor.putBoolean("enabled", false);
7685 peditor.commit();
7786
7887 PendingIntent intent = this.getPendingIntent(context);
79- if (intent == null) return;
88+ if (intent == null) return false;
8089 Log.d(this.getClass().getSimpleName(), "Disable watch schedule");
8190 AlarmManager manager = (AlarmManager) context.getSystemService(ALARM_SERVICE);
8291 manager.cancel(intent);
8392 intent.cancel();
8493
8594 killWatchTarget(context);
95+ return true;
8696 }
8797
88- public void schedule(Context context) {
98+ public boolean schedule(Context context) {
8999 Editor peditor = getPrefs(context).edit();
90100 peditor.putBoolean("enabled", true);
91101 peditor.commit();
92102
103+ if (this.getPendingIntent(context) != null)
104+ return false;
93105 AlarmManager manager = (AlarmManager) context.getSystemService(ALARM_SERVICE);
94106 manager.setInexactRepeating(AlarmManager.RTC_WAKEUP,
95107 System.currentTimeMillis(), this.getInterval(context) * 1000,
96108 this.getPendingIntent(context, true));
97-
109+ return true;
98110 }
99111
100112 @Override
@@ -102,24 +114,53 @@ public class WatchService extends IntentService {
102114 Log.d(NAME, "Run watch handle!");
103115
104116 this.forceWake();
117+ // TODO: unlock support.
105118
106119 if (checkTopActivity(intent.getStringExtra("watch")))
107120 return;
121+
122+ try {
123+ if (intent.getStringExtra("method").equals("url")) {
124+ launchWithURL(intent);
125+ } else {
126+ launchWithPackage(intent);
127+ }
128+ } catch (Exception e) {
129+ Log.d(NAME, "Faild to Start: "+e.getMessage());
130+ handler.post(new Runnable() {
131+ public String message = "";
132+ public Runnable setMessage(String message) {
133+ this.message = message;
134+ return this;
135+ }
136+ @Override
137+ public void run() {
138+ Toast.makeText(getApplicationContext(),
139+ "[DemoWatcher] Failed to start target!\n"+this.message,
140+ Toast.LENGTH_LONG).show();
141+ }
142+ }.setMessage(e.getMessage()));
143+ }
144+ }
145+
146+ protected void launchWithPackage(Intent intent) {
147+ String watch = intent.getStringExtra("watch");
148+ Intent openintent = getPackageManager().getLaunchIntentForPackage(watch);
149+ openintent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
150+
151+ Log.d(NAME, "Sending package "+watch);
108152
153+ startActivity(openintent);
154+ }
155+
156+ protected void launchWithURL(Intent intent) {
109157 String url = intent.getStringExtra("open");
110158 Intent openintent = new Intent(Intent.ACTION_VIEW);
111159 openintent.setData(Uri.parse(url));
112160 openintent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
113161
114162 Log.d(NAME, "Sending view intent with "+url);
115-
116- try {
117- startActivity(openintent);
118- } catch (Exception e) {
119- Log.d(NAME, "Faild to Start: "+e.getMessage());
120- }
121-
122- // TODO: unlock support.
163+ startActivity(openintent);
123164 }
124165
125166 public void killWatchTarget(Context context) {