- Add support for Update the uptime with a button
- Fix a bug where the client wouldn't update the uptime at the server - Languages updates
This commit is contained in:
parent
5b2431be5f
commit
11b7e2e339
8 changed files with 185 additions and 96 deletions
|
@ -1,8 +1,9 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="org.r3pek.droiduptime"
|
||||
android:versionCode="8" android:versionName="1.3.2">
|
||||
<application android:icon="@drawable/icon" android:label="@string/app_name" android:debuggable="false">
|
||||
package="org.r3pek.droiduptime" android:versionCode="8"
|
||||
android:versionName="1.3.2">
|
||||
<application android:icon="@drawable/icon" android:label="@string/app_name"
|
||||
android:debuggable="false">
|
||||
|
||||
|
||||
<service android:name="DroidUptimeService"></service>
|
||||
|
@ -11,7 +12,9 @@
|
|||
<action android:name="android.intent.action.BOOT_COMPLETED"></action>
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
<activity android:name="Main" android:label="@string/app_name"><intent-filter><action android:name="android.intent.action.MAIN"></action>
|
||||
<activity android:name="Main" android:label="@string/app_name">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN"></action>
|
||||
<category android:name="android.intent.category.LAUNCHER"></category>
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
@ -20,12 +23,19 @@
|
|||
</application>
|
||||
<uses-sdk android:minSdkVersion="3" />
|
||||
|
||||
<supports-screens android:resizeable="true" android:largeScreens="true" android:anyDensity="false" android:normalScreens="true" android:smallScreens="true"></supports-screens>
|
||||
<supports-screens android:resizeable="true"
|
||||
android:largeScreens="true" android:anyDensity="false"
|
||||
android:normalScreens="true" android:smallScreens="true"></supports-screens>
|
||||
|
||||
|
||||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"></uses-permission><uses-permission android:name="android.permission.ACCESS_WIFI_STATE"></uses-permission>
|
||||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"></uses-permission>
|
||||
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"></uses-permission>
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
|
||||
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>
|
||||
<permission android:name="org.r3pek.droiduptime.permission.FORCE_UPDATE"
|
||||
android:protectionLevel="normal" android:label="@string/perm_allow_update_label"
|
||||
android:description="@string/perm_allow_update_desc"></permission>
|
||||
<uses-permission android:name="org.r3pek.droiduptime.permission.FORCE_UPDATE"></uses-permission>
|
||||
</manifest>
|
|
@ -1,38 +1,83 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<ScrollView
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:myapp="http://schemas.android.com/apk/res/org.r3pek.droiduptime"
|
||||
android:id="@+id/ScrollView01"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent">
|
||||
<LinearLayout
|
||||
android:orientation="vertical"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent">
|
||||
android:layout_width="fill_parent" android:layout_height="fill_parent">
|
||||
<ScrollView android:id="@+id/ScrollView01"
|
||||
android:layout_width="fill_parent" android:layout_height="fill_parent">
|
||||
<LinearLayout android:orientation="vertical"
|
||||
android:layout_width="fill_parent" android:layout_height="fill_parent">
|
||||
|
||||
|
||||
|
||||
<com.admob.android.ads.AdView android:layout_gravity="bottom" android:id="@+id/ad" android:layout_width="fill_parent" android:layout_alignParentBottom="true" myapp:backgroundColor="#000000" myapp:primaryTextColor="#FFFFFF" myapp:secondaryTextColor="#CCCCCC" android:layout_height="wrap_content" />
|
||||
<ImageView android:id="@+id/ImageView01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/droiduptime" android:layout_gravity="center_horizontal" android:layout_marginTop="20dip"></ImageView>
|
||||
<ImageView android:id="@+id/ImageView01"
|
||||
android:layout_width="wrap_content" android:layout_height="wrap_content"
|
||||
android:src="@drawable/droiduptime" android:layout_gravity="center_horizontal"
|
||||
android:layout_marginTop="20dip"></ImageView>
|
||||
|
||||
<TableLayout android:id="@+id/TableLayout01" android:layout_height="wrap_content" android:layout_width="fill_parent" android:stretchColumns="1" android:paddingTop="20dip">
|
||||
<TableRow android:id="@+id/TableRow01" android:layout_width="wrap_content" android:layout_height="wrap_content">
|
||||
<LinearLayout android:id="@+id/LinearLayout01" android:layout_height="wrap_content" android:orientation="horizontal" android:layout_width="fill_parent">
|
||||
<TextView android:id="@+id/TextView01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textStyle="bold" android:layout_marginTop="15dip" android:text="@string/servicestatus"></TextView>
|
||||
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="20dip" android:id="@+id/tvStatus" android:layout_marginTop="15dip"></TextView>
|
||||
<TableLayout android:id="@+id/TableLayout01"
|
||||
android:layout_height="wrap_content" android:layout_width="fill_parent"
|
||||
android:stretchColumns="1" android:paddingTop="20dip">
|
||||
<TableRow android:id="@+id/TableRow01"
|
||||
android:layout_width="wrap_content" android:layout_height="wrap_content">
|
||||
<LinearLayout android:id="@+id/LinearLayout01"
|
||||
android:layout_height="wrap_content" android:orientation="horizontal"
|
||||
android:layout_width="fill_parent">
|
||||
<TextView android:id="@+id/TextView01"
|
||||
android:layout_width="wrap_content" android:layout_height="wrap_content"
|
||||
android:textStyle="bold" android:layout_marginTop="15dip"
|
||||
android:text="@string/servicestatus"></TextView>
|
||||
<TextView android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" android:layout_marginLeft="20dip"
|
||||
android:id="@+id/tvStatus" android:layout_marginTop="15dip"></TextView>
|
||||
</LinearLayout>
|
||||
<Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/btnStartStopService" android:layout_gravity="right"></Button>
|
||||
<Button android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" android:id="@+id/btnStartStopService"
|
||||
android:layout_gravity="right"></Button>
|
||||
</TableRow>
|
||||
</TableLayout>
|
||||
|
||||
|
||||
<LinearLayout android:id="@+id/LinearLayout02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" android:paddingTop="10dip"><TextView android:id="@+id/TextView02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textStyle="bold" android:text="@string/uptime"></TextView>
|
||||
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="20dip" android:id="@+id/tvUptime"></TextView>
|
||||
<LinearLayout android:id="@+id/LinearLayout02"
|
||||
android:layout_width="wrap_content" android:layout_height="wrap_content"
|
||||
android:orientation="horizontal" android:paddingTop="10dip">
|
||||
<TextView android:id="@+id/TextView02"
|
||||
android:layout_width="wrap_content" android:layout_height="wrap_content"
|
||||
android:textStyle="bold" android:text="@string/uptime"></TextView>
|
||||
<TextView android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" android:layout_marginLeft="20dip"
|
||||
android:id="@+id/tvUptime"></TextView>
|
||||
</LinearLayout>
|
||||
<LinearLayout android:id="@+id/LinearLayout05" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" android:layout_marginTop="15dip"><TextView android:id="@+id/TextView06" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textStyle="bold" android:text="@string/lastupdate"></TextView>
|
||||
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="20dip" android:id="@+id/tvLastUpdate"></TextView>
|
||||
</LinearLayout><TextView android:id="@+id/TextView03" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="15dip" android:linksClickable="true" android:autoLink="web" android:text="@string/message"></TextView>
|
||||
|
||||
<TableLayout android:id="@+id/TableLayout02"
|
||||
android:layout_height="wrap_content" android:layout_width="fill_parent"
|
||||
android:stretchColumns="1" android:paddingTop="20dip">
|
||||
<TableRow android:id="@+id/TableRow02"
|
||||
android:layout_width="wrap_content" android:layout_height="wrap_content">
|
||||
<LinearLayout android:id="@+id/LinearLayout05"
|
||||
android:layout_width="wrap_content" android:layout_height="wrap_content"
|
||||
android:orientation="horizontal" android:layout_marginTop="15dip">
|
||||
<TextView android:id="@+id/TextView06"
|
||||
android:layout_width="wrap_content" android:layout_height="wrap_content"
|
||||
android:textStyle="bold" android:text="@string/lastupdate"></TextView>
|
||||
<TextView android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" android:layout_marginLeft="20dip"
|
||||
android:id="@+id/tvLastUpdate"></TextView>
|
||||
</LinearLayout>
|
||||
<Button android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" android:id="@+id/btnUpdate"
|
||||
android:text="@string/update" android:layout_gravity="right"></Button>
|
||||
</TableRow>
|
||||
</TableLayout>
|
||||
<TextView android:id="@+id/TextView03" android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" android:layout_marginTop="15dip"
|
||||
android:linksClickable="true" android:autoLink="web" android:text="@string/message"></TextView>
|
||||
|
||||
|
||||
</LinearLayout>
|
||||
</ScrollView>
|
||||
<com.admob.android.ads.AdView
|
||||
android:layout_gravity="bottom" android:id="@+id/ad"
|
||||
android:layout_width="fill_parent" android:layout_alignParentBottom="true"
|
||||
myapp:backgroundColor="#000000" myapp:primaryTextColor="#FFFFFF"
|
||||
myapp:secondaryTextColor="#CCCCCC" android:layout_height="wrap_content" />
|
||||
</RelativeLayout>
|
|
@ -41,6 +41,9 @@
|
|||
<item>7200</item>
|
||||
</string-array>
|
||||
<string name="no_user_pass">Insira o utilizador e a senha no menu configuração</string>
|
||||
<string name="pref_gen_hostname">Hostname</string>
|
||||
<string name="pref_gen_hostname_desc">Hostname a reportar para o Uptime Project</string>
|
||||
<string name="pref_gen_hostname">Nome do telefone</string>
|
||||
<string name="pref_gen_hostname_desc">Nome do telefone a reportar para o Uptime Project</string>
|
||||
<string name="perm_allow_update_label">Força uma actualização do Uptime no site</string>
|
||||
<string name="perm_allow_update_desc">Permite que uma aplicação submita o uptime corrente para o site uptimeprj.com</string>
|
||||
<string name="update">Actualizar</string>
|
||||
</resources>
|
||||
|
|
|
@ -41,6 +41,9 @@
|
|||
<item>7200</item>
|
||||
</string-array>
|
||||
<string name="no_user_pass">请设定用户名和密码</string>
|
||||
<string name="pref_gen_hostname">主机名</string>
|
||||
<string name="pref_gen_hostname_desc">主机名发送到 Uptime 项目</string>
|
||||
<string name="pref_gen_hostname">电话名称</string>
|
||||
<string name="pref_gen_hostname_desc">手机名称发送到系统正常运行时间</string>
|
||||
<string name="perm_allow_update_label">强制提交系统正常运行时间</string>
|
||||
<string name="perm_allow_update_desc">允许任何应用程序强制提交系统正常运行时间执行时间到 uptimeprj.com 网站</string>
|
||||
<string name="update">更新</string>
|
||||
</resources>
|
||||
|
|
|
@ -41,6 +41,9 @@
|
|||
<item>7200</item>
|
||||
</string-array>
|
||||
<string name="no_user_pass">請設定使用者名稱和密碼</string>
|
||||
<string name="pref_gen_hostname">主機名</string>
|
||||
<string name="pref_gen_hostname_desc">主機名發送到 Uptime 項目</string>
|
||||
<string name="pref_gen_hostname">電話名稱</string>
|
||||
<string name="pref_gen_hostname_desc">手機名稱發送到系統正常執行時間</string>
|
||||
<string name="perm_allow_update_label">強制提交系統正常執行時間</string>
|
||||
<string name="perm_allow_update_desc">允許任何套用程式強制提交系統正常執行時間執行時間到 uptimeprj.com 網站</string>
|
||||
<string name="update">更新</string>
|
||||
</resources>
|
||||
|
|
|
@ -41,6 +41,9 @@
|
|||
<item>7200</item>
|
||||
</string-array>
|
||||
<string name="no_user_pass">Please setup Username and Password</string>
|
||||
<string name="pref_gen_hostname">Hostname</string>
|
||||
<string name="pref_gen_hostname_desc">Hostname to send to the Uptime Project</string>
|
||||
<string name="pref_gen_hostname">Phone Name</string>
|
||||
<string name="pref_gen_hostname_desc">Phone Name to send to the Uptime Project</string>
|
||||
<string name="perm_allow_update_label">Force an uptime submission</string>
|
||||
<string name="perm_allow_update_desc">Allows any application to force the current uptime to be submitted to the uptimeprj.com site</string>
|
||||
<string name="update">Update</string>
|
||||
</resources>
|
||||
|
|
|
@ -1,5 +1,24 @@
|
|||
package org.r3pek.droiduptime;
|
||||
|
||||
import org.apache.http.NameValuePair;
|
||||
import org.apache.http.client.entity.UrlEncodedFormEntity;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.impl.client.DefaultHttpClient;
|
||||
import org.apache.http.message.BasicNameValuePair;
|
||||
import org.apache.http.protocol.HTTP;
|
||||
|
||||
import android.app.Service;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.wifi.WifiInfo;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.os.IBinder;
|
||||
import android.os.SystemClock;
|
||||
import android.util.Log;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
|
@ -10,22 +29,6 @@ import java.util.TimerTask;
|
|||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.apache.http.NameValuePair;
|
||||
import org.apache.http.client.entity.UrlEncodedFormEntity;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.impl.client.DefaultHttpClient;
|
||||
import org.apache.http.message.BasicNameValuePair;
|
||||
import org.apache.http.protocol.HTTP;
|
||||
|
||||
import android.app.Service;
|
||||
import android.content.Intent;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.wifi.WifiInfo;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.os.IBinder;
|
||||
import android.os.SystemClock;
|
||||
import android.util.Log;
|
||||
|
||||
public class DroidUptimeService extends Service {
|
||||
private Timer timer;
|
||||
private ConfigValues cv;
|
||||
|
@ -38,15 +41,23 @@ public class DroidUptimeService extends Service {
|
|||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
cv = new ConfigValues(getApplicationContext());
|
||||
cv = new ConfigValues(this);
|
||||
timer = new Timer();
|
||||
timer.scheduleAtFixedRate(new TimerTask() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
sendUptime();
|
||||
}
|
||||
}, 60000, cv.getUpdateInterval() * 1000);
|
||||
|
||||
BroadcastReceiver receiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
sendUptime();
|
||||
}
|
||||
};
|
||||
IntentFilter filter = new IntentFilter("org.r3pek.droiduptime.FORCE_UPDATE");
|
||||
registerReceiver(receiver, filter, "org.r3pek.droiduptime.permission.FORCE_UPDATE", null);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -55,14 +66,15 @@ public class DroidUptimeService extends Service {
|
|||
if (timer != null) timer.cancel();
|
||||
}
|
||||
|
||||
@SuppressWarnings("static-access")
|
||||
private String getMACAddrMD5() {
|
||||
WifiManager manager = (WifiManager)getApplicationContext().getSystemService(getApplicationContext().WIFI_SERVICE);
|
||||
WifiManager manager = (WifiManager)getSystemService(Context.WIFI_SERVICE);
|
||||
WifiInfo info = manager.getConnectionInfo();
|
||||
|
||||
try {
|
||||
return MD5.calculateMD5(info.getMacAddress().toLowerCase().replaceAll(":", ""));
|
||||
} catch (Exception e) { }
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
|
@ -115,17 +127,16 @@ public class DroidUptimeService extends Service {
|
|||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("static-access")
|
||||
public void sendUptime() {
|
||||
if (cv.getUsername().equals("") || cv.getPassword().equals(""))
|
||||
return;
|
||||
ConnectivityManager conMngr = (ConnectivityManager)getSystemService(getApplicationContext().CONNECTIVITY_SERVICE);
|
||||
ConnectivityManager conMngr = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
boolean isConnected = false || conMngr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).isConnected();
|
||||
isConnected |= conMngr.getNetworkInfo(ConnectivityManager.TYPE_WIFI).isConnected();
|
||||
if (!isConnected) return;
|
||||
|
||||
long uptime = SystemClock.elapsedRealtime() / 1000;
|
||||
String agent = "DroidUptime-v1.3";
|
||||
String agent = "DroidUptime-v1.4";
|
||||
String cnb = "1";
|
||||
String mac = getMACAddrMD5();
|
||||
String hostname = cv.getHostname();
|
||||
|
@ -134,16 +145,15 @@ public class DroidUptimeService extends Service {
|
|||
String distrib = "Android";
|
||||
String distribContent = "SDK " + android.os.Build.VERSION.RELEASE;
|
||||
distribContent = Base64.encodeToString(distribContent.getBytes(), false);
|
||||
Log.d("DroidUptime", agent);
|
||||
Log.d("DroidUptime", cnb);
|
||||
Log.d("DroidUptime", mac);
|
||||
Log.d("DroidUptime", machine);
|
||||
Log.d("DroidUptime", os);
|
||||
Log.d("DroidUptime", distrib);
|
||||
Log.d("DroidUptime", distribContent);
|
||||
Log.d("DroidUptime", cv.getUsername());
|
||||
Log.d("DroidUptime", cv.getPassword());
|
||||
|
||||
/*Log.d("DroidUptime", URLEncoder.encode("http://update.uptimeprj.com/update.php?username=" + cv.getUsername() +
|
||||
"&pass=" + cv.getPassword() +
|
||||
"&cnb=" + cnb +
|
||||
"&mac=" + mac +
|
||||
"&machine=" + machine +
|
||||
"&os="+ os +
|
||||
"&uptime=" +String.valueOf(uptime) +
|
||||
"&distrib=" + distrib +
|
||||
"&distribcontent=" +distribContent));*/
|
||||
try {
|
||||
DefaultHttpClient httpclient = new DefaultHttpClient();
|
||||
HttpPost post = new HttpPost("http://update.uptimeprj.com/update.php?username=" + cv.getUsername());
|
||||
|
@ -161,7 +171,9 @@ public class DroidUptimeService extends Service {
|
|||
data.add(new BasicNameValuePair("distribcontent", distribContent));
|
||||
post.setEntity(new UrlEncodedFormEntity(data, HTTP.UTF_8));
|
||||
|
||||
Log.d("DroidUptime", "Updating uptime");
|
||||
httpclient.execute(post);
|
||||
Log.d("DroidUptime", "Done with updating");
|
||||
|
||||
cv.setLastUpdate(System.currentTimeMillis());
|
||||
} catch (Exception e) { e.printStackTrace(); }
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package org.r3pek.droiduptime;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.ActivityManager;
|
||||
import android.app.AlertDialog;
|
||||
|
@ -22,12 +20,15 @@ import android.widget.Button;
|
|||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Main extends Activity {
|
||||
private static final int MENU_ABOUT = 0;
|
||||
private static final int MENU_SETUP = 1;
|
||||
private static final int DIALOG_ABOUT = 0;
|
||||
|
||||
private Button btnStartStopService;
|
||||
private Button btnUpdate;
|
||||
private TextView tvStatus;
|
||||
private TextView tvUptime;
|
||||
private TextView tvLastUpdate;
|
||||
|
@ -49,6 +50,7 @@ public class Main extends Activity {
|
|||
cv = new ConfigValues(getApplicationContext());
|
||||
|
||||
btnStartStopService = (Button)findViewById(R.id.btnStartStopService);
|
||||
btnUpdate = (Button)findViewById(R.id.btnUpdate);
|
||||
tvStatus = (TextView)findViewById(R.id.tvStatus);
|
||||
tvUptime = (TextView)findViewById(R.id.tvUptime);
|
||||
tvLastUpdate = (TextView)findViewById(R.id.tvLastUpdate);
|
||||
|
@ -65,6 +67,14 @@ public class Main extends Activity {
|
|||
updateStatus();
|
||||
}
|
||||
});
|
||||
|
||||
btnUpdate.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent i = new Intent("org.r3pek.droiduptime.FORCE_UPDATE");
|
||||
sendBroadcast(i);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void startThread() {
|
||||
|
|
Loading…
Reference in a new issue