1
0
Fork 0

- 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:
Carlos Mogas da Silva 2010-10-07 18:53:59 +01:00
parent 5b2431be5f
commit 11b7e2e339
8 changed files with 185 additions and 96 deletions

View file

@ -1,31 +1,41 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.r3pek.droiduptime" package="org.r3pek.droiduptime" android:versionCode="8"
android:versionCode="8" android:versionName="1.3.2"> android:versionName="1.3.2">
<application android:icon="@drawable/icon" android:label="@string/app_name" android:debuggable="false"> <application android:icon="@drawable/icon" android:label="@string/app_name"
android:debuggable="false">
<service android:name="DroidUptimeService"></service> <service android:name="DroidUptimeService"></service>
<receiver android:name="DroidUptimeServiceManager"> <receiver android:name="DroidUptimeServiceManager">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"></action> <action android:name="android.intent.action.BOOT_COMPLETED"></action>
</intent-filter> </intent-filter>
</receiver> </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">
<category android:name="android.intent.category.LAUNCHER"></category> <intent-filter>
</intent-filter> <action android:name="android.intent.action.MAIN"></action>
</activity> <category android:name="android.intent.category.LAUNCHER"></category>
</intent-filter>
</activity>
<meta-data android:value="a14bad01161834d" android:name="ADMOB_PUBLISHER_ID" /> <meta-data android:value="a14bad01161834d" android:name="ADMOB_PUBLISHER_ID" />
<activity android:name="MyPreferences"></activity> <activity android:name="MyPreferences"></activity>
</application> </application>
<uses-sdk android:minSdkVersion="3"/> <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.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></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> </manifest>

View file

@ -1,38 +1,83 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<ScrollView <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:myapp="http://schemas.android.com/apk/res/org.r3pek.droiduptime" 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">
android:layout_width="fill_parent" <ScrollView android:id="@+id/ScrollView01"
android:layout_height="fill_parent"> android:layout_width="fill_parent" android:layout_height="fill_parent">
<LinearLayout <LinearLayout android:orientation="vertical"
android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent">
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"
<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> 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"> <TableLayout android:id="@+id/TableLayout01"
<TableRow android:id="@+id/TableRow01" android:layout_width="wrap_content" android:layout_height="wrap_content"> android:layout_height="wrap_content" android:layout_width="fill_parent"
<LinearLayout android:id="@+id/LinearLayout01" android:layout_height="wrap_content" android:orientation="horizontal" android:layout_width="fill_parent"> android:stretchColumns="1" android:paddingTop="20dip">
<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> <TableRow android:id="@+id/TableRow01"
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="20dip" android:id="@+id/tvStatus" android:layout_marginTop="15dip"></TextView> 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> </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> </TableRow>
</TableLayout> </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> <LinearLayout android:id="@+id/LinearLayout02"
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="20dip" android:id="@+id/tvUptime"></TextView> android:layout_width="wrap_content" android:layout_height="wrap_content"
</LinearLayout> android:orientation="horizontal" android:paddingTop="10dip">
<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:id="@+id/TextView02"
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="20dip" android:id="@+id/tvLastUpdate"></TextView> android:layout_width="wrap_content" android:layout_height="wrap_content"
</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> 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>
<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> </LinearLayout>
</ScrollView> </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>

View file

@ -41,6 +41,9 @@
<item>7200</item> <item>7200</item>
</string-array> </string-array>
<string name="no_user_pass">Insira o utilizador e a senha no menu configuração</string> <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">Nome do telefone</string>
<string name="pref_gen_hostname_desc">Hostname a reportar para o Uptime Project</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> </resources>

View file

@ -41,6 +41,9 @@
<item>7200</item> <item>7200</item>
</string-array> </string-array>
<string name="no_user_pass">请设定用户名和密码</string> <string name="no_user_pass">请设定用户名和密码</string>
<string name="pref_gen_hostname">主机名</string> <string name="pref_gen_hostname">电话名称</string>
<string name="pref_gen_hostname_desc">主机名发送到 Uptime 项目</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> </resources>

View file

@ -41,6 +41,9 @@
<item>7200</item> <item>7200</item>
</string-array> </string-array>
<string name="no_user_pass">請設定使用者名稱和密碼</string> <string name="no_user_pass">請設定使用者名稱和密碼</string>
<string name="pref_gen_hostname">主機名</string> <string name="pref_gen_hostname">電話名稱</string>
<string name="pref_gen_hostname_desc">主機名發送到 Uptime 項目</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> </resources>

View file

@ -41,6 +41,9 @@
<item>7200</item> <item>7200</item>
</string-array> </string-array>
<string name="no_user_pass">Please setup Username and Password</string> <string name="no_user_pass">Please setup Username and Password</string>
<string name="pref_gen_hostname">Hostname</string> <string name="pref_gen_hostname">Phone Name</string>
<string name="pref_gen_hostname_desc">Hostname to send to the Uptime Project</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> </resources>

View file

@ -1,5 +1,24 @@
package org.r3pek.droiduptime; 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.BufferedReader;
import java.io.FileReader; import java.io.FileReader;
import java.io.IOException; import java.io.IOException;
@ -10,22 +29,6 @@ import java.util.TimerTask;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; 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 { public class DroidUptimeService extends Service {
private Timer timer; private Timer timer;
private ConfigValues cv; private ConfigValues cv;
@ -38,15 +41,23 @@ public class DroidUptimeService extends Service {
@Override @Override
public void onCreate() { public void onCreate() {
super.onCreate(); super.onCreate();
cv = new ConfigValues(getApplicationContext()); cv = new ConfigValues(this);
timer = new Timer(); timer = new Timer();
timer.scheduleAtFixedRate(new TimerTask() { timer.scheduleAtFixedRate(new TimerTask() {
@Override @Override
public void run() { public void run() {
sendUptime(); sendUptime();
} }
}, 60000, cv.getUpdateInterval() * 1000); }, 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 @Override
@ -55,14 +66,15 @@ public class DroidUptimeService extends Service {
if (timer != null) timer.cancel(); if (timer != null) timer.cancel();
} }
@SuppressWarnings("static-access")
private String getMACAddrMD5() { private String getMACAddrMD5() {
WifiManager manager = (WifiManager)getApplicationContext().getSystemService(getApplicationContext().WIFI_SERVICE); WifiManager manager = (WifiManager)getSystemService(Context.WIFI_SERVICE);
WifiInfo info = manager.getConnectionInfo(); WifiInfo info = manager.getConnectionInfo();
try { try {
return MD5.calculateMD5(info.getMacAddress().toLowerCase().replaceAll(":", "")); return MD5.calculateMD5(info.getMacAddress().toLowerCase().replaceAll(":", ""));
} catch (Exception e) { } } catch (Exception e) {
e.printStackTrace();
}
return ""; return "";
} }
@ -115,17 +127,16 @@ public class DroidUptimeService extends Service {
} }
} }
@SuppressWarnings("static-access")
public void sendUptime() { public void sendUptime() {
if (cv.getUsername().equals("") || cv.getPassword().equals("")) if (cv.getUsername().equals("") || cv.getPassword().equals(""))
return; return;
ConnectivityManager conMngr = (ConnectivityManager)getSystemService(getApplicationContext().CONNECTIVITY_SERVICE); ConnectivityManager conMngr = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
boolean isConnected = false || conMngr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).isConnected(); boolean isConnected = false || conMngr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).isConnected();
isConnected |= conMngr.getNetworkInfo(ConnectivityManager.TYPE_WIFI).isConnected(); isConnected |= conMngr.getNetworkInfo(ConnectivityManager.TYPE_WIFI).isConnected();
if (!isConnected) return; if (!isConnected) return;
long uptime = SystemClock.elapsedRealtime() / 1000; long uptime = SystemClock.elapsedRealtime() / 1000;
String agent = "DroidUptime-v1.3"; String agent = "DroidUptime-v1.4";
String cnb = "1"; String cnb = "1";
String mac = getMACAddrMD5(); String mac = getMACAddrMD5();
String hostname = cv.getHostname(); String hostname = cv.getHostname();
@ -134,16 +145,15 @@ public class DroidUptimeService extends Service {
String distrib = "Android"; String distrib = "Android";
String distribContent = "SDK " + android.os.Build.VERSION.RELEASE; String distribContent = "SDK " + android.os.Build.VERSION.RELEASE;
distribContent = Base64.encodeToString(distribContent.getBytes(), false); distribContent = Base64.encodeToString(distribContent.getBytes(), false);
Log.d("DroidUptime", agent); /*Log.d("DroidUptime", URLEncoder.encode("http://update.uptimeprj.com/update.php?username=" + cv.getUsername() +
Log.d("DroidUptime", cnb); "&pass=" + cv.getPassword() +
Log.d("DroidUptime", mac); "&cnb=" + cnb +
Log.d("DroidUptime", machine); "&mac=" + mac +
Log.d("DroidUptime", os); "&machine=" + machine +
Log.d("DroidUptime", distrib); "&os="+ os +
Log.d("DroidUptime", distribContent); "&uptime=" +String.valueOf(uptime) +
Log.d("DroidUptime", cv.getUsername()); "&distrib=" + distrib +
Log.d("DroidUptime", cv.getPassword()); "&distribcontent=" +distribContent));*/
try { try {
DefaultHttpClient httpclient = new DefaultHttpClient(); DefaultHttpClient httpclient = new DefaultHttpClient();
HttpPost post = new HttpPost("http://update.uptimeprj.com/update.php?username=" + cv.getUsername()); 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)); data.add(new BasicNameValuePair("distribcontent", distribContent));
post.setEntity(new UrlEncodedFormEntity(data, HTTP.UTF_8)); post.setEntity(new UrlEncodedFormEntity(data, HTTP.UTF_8));
Log.d("DroidUptime", "Updating uptime");
httpclient.execute(post); httpclient.execute(post);
Log.d("DroidUptime", "Done with updating");
cv.setLastUpdate(System.currentTimeMillis()); cv.setLastUpdate(System.currentTimeMillis());
} catch (Exception e) { e.printStackTrace(); } } catch (Exception e) { e.printStackTrace(); }

View file

@ -1,7 +1,5 @@
package org.r3pek.droiduptime; package org.r3pek.droiduptime;
import java.util.List;
import android.app.Activity; import android.app.Activity;
import android.app.ActivityManager; import android.app.ActivityManager;
import android.app.AlertDialog; import android.app.AlertDialog;
@ -22,12 +20,15 @@ import android.widget.Button;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
import java.util.List;
public class Main extends Activity { public class Main extends Activity {
private static final int MENU_ABOUT = 0; private static final int MENU_ABOUT = 0;
private static final int MENU_SETUP = 1; private static final int MENU_SETUP = 1;
private static final int DIALOG_ABOUT = 0; private static final int DIALOG_ABOUT = 0;
private Button btnStartStopService; private Button btnStartStopService;
private Button btnUpdate;
private TextView tvStatus; private TextView tvStatus;
private TextView tvUptime; private TextView tvUptime;
private TextView tvLastUpdate; private TextView tvLastUpdate;
@ -49,6 +50,7 @@ public class Main extends Activity {
cv = new ConfigValues(getApplicationContext()); cv = new ConfigValues(getApplicationContext());
btnStartStopService = (Button)findViewById(R.id.btnStartStopService); btnStartStopService = (Button)findViewById(R.id.btnStartStopService);
btnUpdate = (Button)findViewById(R.id.btnUpdate);
tvStatus = (TextView)findViewById(R.id.tvStatus); tvStatus = (TextView)findViewById(R.id.tvStatus);
tvUptime = (TextView)findViewById(R.id.tvUptime); tvUptime = (TextView)findViewById(R.id.tvUptime);
tvLastUpdate = (TextView)findViewById(R.id.tvLastUpdate); tvLastUpdate = (TextView)findViewById(R.id.tvLastUpdate);
@ -65,6 +67,14 @@ public class Main extends Activity {
updateStatus(); 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() { private void startThread() {