Skip to content

Commit c03567f

Browse files
committed
adding service
1 parent 677ae63 commit c03567f

File tree

5 files changed

+97
-9
lines changed

5 files changed

+97
-9
lines changed

AndroidManifest.xml

+9-3
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,27 @@
88
android:minSdkVersion="14"
99
android:targetSdkVersion="19" />
1010

11+
<uses-permission android:name="android.permission.INTERNET" />
12+
<uses-permission android:name="android.permission.WAKE_LOCK" />
13+
1114
<application
1215
android:allowBackup="true"
1316
android:icon="@drawable/ic_launcher"
1417
android:label="@string/app_name"
1518
android:theme="@style/AppTheme" >
1619
<activity
1720
android:name=".TaskerActivity"
18-
android:label="@string/app_name" android:theme="@style/AppTheme.Translucent">
21+
android:label="@string/app_name"
22+
android:theme="@style/AppTheme.Translucent" >
1923
<intent-filter>
2024
<action android:name="android.intent.action.MAIN" />
2125

2226
<category android:name="android.intent.category.LAUNCHER" />
2327
</intent-filter>
2428
</activity>
25-
<service android:name="TaskerService"></service>
29+
30+
<service android:name="TaskerService" >
31+
</service>
2632
</application>
2733

28-
</manifest>
34+
</manifest>

libs/jsoup-1.8.1.jar

294 KB
Binary file not shown.

lint.xml

+1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
<lint>
33
<issue id="InlinedApi" severity="ignore" />
44
<issue id="NewApi" severity="ignore" />
5+
<issue id="Wakelock" severity="ignore" />
56
</lint>

src/com/BBsRs/HSPAP/Tweaker/TaskerActivity.java

+16-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33

44

55
import android.app.Activity;
6+
import android.app.ActivityManager;
7+
import android.app.ActivityManager.RunningServiceInfo;
68
import android.content.Context;
9+
import android.content.Intent;
710
import android.os.Bundle;
811
import android.util.DisplayMetrics;
912
import android.view.Display;
@@ -26,8 +29,6 @@ public class TaskerActivity extends Activity {
2629
private ImageView mBackgroundShape;
2730
private TextView mLightbulb;
2831

29-
private boolean isRunning = false;
30-
3132
@Override
3233
protected void onCreate(Bundle savedInstanceState) {
3334
super.onCreate(savedInstanceState);
@@ -43,16 +44,16 @@ protected void onCreate(Bundle savedInstanceState) {
4344
mLightbulb.setOnClickListener(new OnClickListener() {
4445
@Override
4546
public void onClick(View v) {
46-
if (isRunning)
47+
if (isMyServiceRunning(TaskerService.class))
4748
onServiceOff();
4849
else
4950
onServiceOn();
50-
isRunning = !isRunning;
5151
}
5252
});
5353
}
5454

5555
private void onServiceOn() {
56+
startService(new Intent(getApplicationContext(), TaskerService.class));
5657
if (mBackgroundShape == null) {
5758
return;
5859
}
@@ -68,6 +69,7 @@ private void onServiceOn() {
6869
}
6970

7071
private void onServiceOff() {
72+
stopService(new Intent(getApplicationContext(), TaskerService.class));
7173
if (mBackgroundShape == null) {
7274
return;
7375
}
@@ -96,4 +98,14 @@ public void onAttachedToWindow() {
9698
super.onAttachedToWindow();
9799
mFullScreenScale = getMeasureScale();
98100
}
101+
102+
private boolean isMyServiceRunning(Class<?> serviceClass) { //returns true is service running
103+
ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
104+
for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
105+
if (serviceClass.getName().equals(service.service.getClassName())) {
106+
return true;
107+
}
108+
}
109+
return false;
110+
}
99111
}
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,84 @@
11
package com.BBsRs.HSPAP.Tweaker;
22

3+
import java.io.IOException;
4+
5+
import org.jsoup.Jsoup;
6+
import org.jsoup.nodes.Document;
7+
38
import android.app.Service;
9+
import android.content.Context;
410
import android.content.Intent;
11+
import android.os.CountDownTimer;
512
import android.os.IBinder;
13+
import android.os.PowerManager;
14+
import android.util.Log;
615

716
public class TaskerService extends Service {
17+
18+
boolean isNeedToStop = false;
19+
20+
PowerManager pm;
21+
PowerManager.WakeLock wl;
22+
23+
public void onCreate() {
24+
super.onCreate();
25+
}
26+
27+
public int onStartCommand(Intent intent, int flags, int startId) {
28+
pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
29+
wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "My Tag");
30+
wl.acquire();
31+
startMission();
32+
return super.onStartCommand(intent, flags, startId);
33+
}
34+
35+
public void onDestroy() {
36+
super.onDestroy();
37+
wl.release();
38+
isNeedToStop = true;
39+
}
840

9-
@Override
1041
public IBinder onBind(Intent intent) {
11-
// TODO Auto-generated method stub
1242
return null;
1343
}
1444

45+
public void startMission() {
46+
if (!isNeedToStop) {
47+
CountDownTimer = new timer(1000, 1000);
48+
49+
CountDownTimer.start();
50+
}
51+
}
52+
53+
private timer CountDownTimer;
54+
55+
public class timer extends CountDownTimer {
56+
57+
public timer(long millisInFuture, long countDownInterval) {
58+
super(millisInFuture, countDownInterval);
59+
}
60+
61+
@Override
62+
public void onFinish() {
63+
Thread thr = new Thread(new Runnable() {
64+
public void run() {
65+
try {
66+
Document doc = Jsoup.connect("http://brothers-rovers.3dn.ru/HPlusTweaker/1.txt").get();
67+
Log.i("23", doc.text());
68+
} catch (IOException e) {
69+
// TODO Auto-generated catch block
70+
e.printStackTrace();
71+
}
72+
}
73+
});
74+
thr.start();
75+
startMission();
76+
}
77+
78+
@Override
79+
public void onTick(long arg0) {
80+
}
81+
}
82+
83+
1584
}

0 commit comments

Comments
 (0)