Browse Source

Working on an update service that check the latest version.

pull/11/head
Eric Kok 13 years ago
parent
commit
508ba39c1e
  1. 4
      android/AndroidManifest.xml
  2. 4
      android/res/values/strings.xml
  3. 15
      android/src/org/transdroid/gui/TorrentsFragment.java
  4. 41
      android/src/org/transdroid/service/BootReceiver.java

4
android/AndroidManifest.xml

@ -201,5 +201,9 @@
</intent-filter> </intent-filter>
</service> </service>
<!-- App and search module update service -->
<service android:name="org.transdroid.service.UpdateService" />
<receiver android:name="org.transdroid.service.UpdateReceiver" />
</application> </application>
</manifest> </manifest>

4
android/res/values/strings.xml

@ -331,6 +331,10 @@
<string name="dialog_color_picker">Color Picker</string> <string name="dialog_color_picker">Color Picker</string>
<string name="press_color_to_apply">Press on Color to apply</string> <string name="press_color_to_apply">Press on Color to apply</string>
<string name="update_app_newversion">New Transdroid version available</string>
<string name="update_search_newversion">New Transdroid search module available</string>
<string name="update_updateto">You can now update to %1$s</string>
<string name="error_httperror">Error during communication with server</string> <string name="error_httperror">Error during communication with server</string>
<string name="error_jsonrequesterror">Error building request</string> <string name="error_jsonrequesterror">Error building request</string>
<string name="error_jsonresponseerror">Error parsing of server response (please check your settings)</string> <string name="error_jsonresponseerror">Error parsing of server response (please check your settings)</string>

15
android/src/org/transdroid/gui/TorrentsFragment.java

@ -86,26 +86,24 @@ import android.content.SharedPreferences.Editor;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.support.v4.app.ActionBar.OnNavigationListener;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction; import android.support.v4.app.FragmentTransaction;
import android.support.v4.app.ActionBar.OnNavigationListener;
import android.support.v4.view.Menu; import android.support.v4.view.Menu;
import android.support.v4.view.MenuItem; import android.support.v4.view.MenuItem;
import android.support.v4.view.SubMenu; import android.support.v4.view.SubMenu;
import android.view.ContextMenu; import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.GestureDetector; import android.view.GestureDetector;
import android.view.GestureDetector.SimpleOnGestureListener;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.MenuInflater; import android.view.MenuInflater;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.view.View; import android.view.View;
import android.view.ViewGroup;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.GestureDetector.SimpleOnGestureListener;
import android.view.View.OnClickListener; import android.view.View.OnClickListener;
import android.view.View.OnTouchListener; import android.view.View.OnTouchListener;
import android.view.ViewGroup;
import android.widget.AdapterView; import android.widget.AdapterView;
import android.widget.AdapterView.AdapterContextMenuInfo;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import android.widget.Button; import android.widget.Button;
import android.widget.EditText; import android.widget.EditText;
@ -116,6 +114,8 @@ import android.widget.SpinnerAdapter;
import android.widget.TableLayout; import android.widget.TableLayout;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import android.widget.AdapterView.AdapterContextMenuInfo;
import android.widget.AdapterView.OnItemClickListener;
/** /**
* The main screen for the Transdroid application and provides most on-the-surface functionality * The main screen for the Transdroid application and provides most on-the-surface functionality
@ -335,6 +335,9 @@ public class TorrentsFragment extends Fragment implements IDaemonCallback, OnTou
// Start the alarm service, if needed // Start the alarm service, if needed
BootReceiver.startAlarm(getActivity().getApplicationContext()); BootReceiver.startAlarm(getActivity().getApplicationContext());
// Check for new app version, if needed
BootReceiver.startUpdateCheck(getActivity().getApplicationContext());
handleIntent(getActivity().getIntent()); handleIntent(getActivity().getIntent());
} }

41
android/src/org/transdroid/service/BootReceiver.java

@ -29,42 +29,59 @@ import android.os.SystemClock;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
/** /**
* Receives a broadcast message when the device has started and * Receives a broadcast message when the device has started and is used to manually start/stop the alarm
* is used to manually start/stop the alarm service. * service.
* *
* @author erickok * @author erickok
* *
*/ */
public class BootReceiver extends BroadcastReceiver { public class BootReceiver extends BroadcastReceiver {
private static final String LOG_NAME = "Boot receiver"; private static final String LOG_NAME = "Boot receiver";
private static AlarmManager mgr; private static AlarmManager mgr = null;
private static PendingIntent pi = null; private static PendingIntent pi = null;
private static PendingIntent pui = null;
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
TLog.d(LOG_NAME, "Received fresh boot broadcast; start alarm service"); TLog.d(LOG_NAME, "Received fresh boot broadcast; start alarm service");
startAlarm(context); startAlarm(context);
startUpdateCheck(context);
} }
public static void cancelAlarm(){ public static void cancelAlarm() {
if (mgr != null) { if (mgr != null) {
mgr.cancel(pi); mgr.cancel(pi);
} }
} }
public static void startAlarm(Context context){ public static void startAlarm(Context context) {
AlarmSettings settings = Preferences.readAlarmSettings(PreferenceManager.getDefaultSharedPreferences(context)); AlarmSettings settings = Preferences.readAlarmSettings(PreferenceManager.getDefaultSharedPreferences(context));
if (settings.isAlarmEnabled()) { if (settings.isAlarmEnabled()) {
// Set up PendingIntent for the alarm service // Set up PendingIntent for the alarm service
mgr = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE); if (mgr == null)
mgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
Intent i = new Intent(context, AlarmReceiver.class); Intent i = new Intent(context, AlarmReceiver.class);
pi = PendingIntent.getBroadcast(context, 0, i, 0); pi = PendingIntent.getBroadcast(context, 0, i, 0);
// First intent after a small (2 second) delay and repeat at the user-set intervals // First intent after a small (2 second) delay and repeat at the user-set intervals
mgr.setRepeating(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + 2000, settings.getAlarmIntervalInMilliseconds(), pi); mgr.setRepeating(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + 2000, settings
.getAlarmIntervalInMilliseconds(), pi);
} }
} }
public static void startUpdateCheck(Context context) {
// Set up PendingIntent for the alarm service
if (mgr == null)
mgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
mgr.cancel(pui);
Intent i = new Intent(context, UpdateReceiver.class);
pui = PendingIntent.getBroadcast(context, 0, i, 0);
// First intent after a small (2 second) delay and repeat every day
mgr.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + 2000,
AlarmManager.INTERVAL_DAY, pui);
}
} }

Loading…
Cancel
Save