Skip to content

Commit

Permalink
rename data service to app service
Browse files Browse the repository at this point in the history
  • Loading branch information
wuan committed Apr 14, 2014
1 parent b546170 commit ab47088
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 100 deletions.
2 changes: 1 addition & 1 deletion AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<service android:name=".DataService"/>
<service android:name=".AppService"/>
<activity
android:name=".Preferences"
android:label="@string/preferences"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import java.util.HashSet;
import java.util.Set;

public class DataService extends Service implements Runnable, SharedPreferences.OnSharedPreferenceChangeListener {
public class AppService extends Service implements Runnable, SharedPreferences.OnSharedPreferenceChangeListener {

public static final String RETRIEVE_DATA_ACTION = "retrieveData";

Expand Down Expand Up @@ -57,13 +57,13 @@ public class DataService extends Service implements Runnable, SharedPreferences.
private PowerManager.WakeLock wakeLock;

@SuppressWarnings("UnusedDeclaration")
public DataService() {
public AppService() {
this(new Handler(), new Period());
Log.d(Main.LOG_TAG, "DataService() created with new handler");
Log.d(Main.LOG_TAG, "AppService() created with new handler");
}

protected DataService(Handler handler, Period updatePeriod) {
Log.d(Main.LOG_TAG, "DataService() create");
protected AppService(Handler handler, Period updatePeriod) {
Log.d(Main.LOG_TAG, "AppService() create");
this.handler = handler;
this.updatePeriod = updatePeriod;
}
Expand Down Expand Up @@ -99,9 +99,9 @@ public DataHandler getDataHandler() {
}

public class DataServiceBinder extends Binder {
DataService getService() {
Log.d(Main.LOG_TAG, "DataServiceBinder.getService() " + DataService.this);
return DataService.this;
AppService getService() {
Log.d(Main.LOG_TAG, "DataServiceBinder.getService() " + AppService.this);
return AppService.this;
}
}

Expand All @@ -111,7 +111,7 @@ public interface DataServiceStatusListener {

@Override
public void onCreate() {
Log.i(Main.LOG_TAG, "DataService.onCreate()");
Log.i(Main.LOG_TAG, "AppService.onCreate()");
super.onCreate();

SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
Expand All @@ -131,21 +131,21 @@ public void onCreate() {

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Log.i(Main.LOG_TAG, "DataService.onStartCommand() startId: " + startId + " " + intent);
Log.i(Main.LOG_TAG, "AppService.onStartCommand() startId: " + startId + " " + intent);

if (intent != null && RETRIEVE_DATA_ACTION.equals(intent.getAction())) {
if (!backgroundOperation) {
Log.i(Main.LOG_TAG, "DataService.onStartCommand() discard alarm");
Log.i(Main.LOG_TAG, "AppService.onStartCommand() discard alarm");
discardAlarm();
} else {
releaseWakeLock();
Log.i(Main.LOG_TAG, "DataService.onStartCommand() wakeLock released");
Log.i(Main.LOG_TAG, "AppService.onStartCommand() wakeLock released");

PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, WAKE_LOCK_TAG);
wakeLock.acquire();

Log.v(Main.LOG_TAG, "DataService.onStartCommand() acquire wake lock " + wakeLock);
Log.v(Main.LOG_TAG, "AppService.onStartCommand() acquire wake lock " + wakeLock);

handler.removeCallbacks(this);
handler.post(this);
Expand All @@ -157,27 +157,27 @@ public int onStartCommand(Intent intent, int flags, int startId) {

public void releaseWakeLock() {
if (wakeLock != null && wakeLock.isHeld()) {
Log.v(Main.LOG_TAG, "DataService.releaseWakeLock() " + wakeLock);
Log.v(Main.LOG_TAG, "AppService.releaseWakeLock() " + wakeLock);
try {
wakeLock.release();
} catch (RuntimeException e) {
Log.v(Main.LOG_TAG, "DataService.releaseWakeLock() failed: " + e.toString());
Log.v(Main.LOG_TAG, "AppService.releaseWakeLock() failed: " + e.toString());
}
}
wakeLock = null;
}

@Override
public IBinder onBind(Intent intent) {
Log.i(Main.LOG_TAG, "DataService.onBind() " + intent);
Log.i(Main.LOG_TAG, "AppService.onBind() " + intent);
return binder;
}

@Override
public void run() {

if (backgroundOperation) {
Log.v(Main.LOG_TAG, "DataService.run() in background");
Log.v(Main.LOG_TAG, "AppService.run() in background");

dataHandler.updateDatainBackground();
} else {
Expand Down Expand Up @@ -223,18 +223,18 @@ public void onResume() {
discardAlarm();

if (dataHandler.isRealtime()) {
Log.v(Main.LOG_TAG, "DataService.onResume() enable");
Log.v(Main.LOG_TAG, "AppService.onResume() enable");
enable();
} else {
Log.v(Main.LOG_TAG, "DataService.onResume() do not enable");
Log.v(Main.LOG_TAG, "AppService.onResume() do not enable");
}
}

public boolean onPause() {
backgroundOperation = true;

handler.removeCallbacks(this);
Log.v(Main.LOG_TAG, "DataService.onPause() remove callback");
Log.v(Main.LOG_TAG, "AppService.onPause() remove callback");

if (alarmEnabled && backgroundPeriod != 0) {
createAlarm();
Expand Down Expand Up @@ -279,7 +279,7 @@ private void onSharedPreferenceChanged(SharedPreferences sharedPreferences, Pref

case BACKGROUND_QUERY_PERIOD:
backgroundPeriod = Integer.parseInt(sharedPreferences.getString(key.toString(), "0"));
Log.v(Main.LOG_TAG, String.format("DataService.onSharedPreferenceChanged() backgroundPeriod=%d", backgroundPeriod));
Log.v(Main.LOG_TAG, String.format("AppService.onSharedPreferenceChanged() backgroundPeriod=%d", backgroundPeriod));
break;

case SHOW_PARTICIPANTS:
Expand All @@ -295,23 +295,23 @@ private void onSharedPreferenceChanged(SharedPreferences sharedPreferences, Pref
private void createAlarm() {
discardAlarm();

Log.v(Main.LOG_TAG, String.format("DataService.createAlarm() %d", backgroundPeriod));
Intent intent = new Intent(this, DataService.class);
Log.v(Main.LOG_TAG, String.format("AppService.createAlarm() %d", backgroundPeriod));
Intent intent = new Intent(this, AppService.class);
intent.setAction(RETRIEVE_DATA_ACTION);
pendingIntent = PendingIntent.getService(this, 0, intent, 0);
alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
if (alarmManager != null) {
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, 0, backgroundPeriod * 1000, pendingIntent);
} else {
Log.e(Main.LOG_TAG, "DataService.createAlarm() failed");
Log.e(Main.LOG_TAG, "AppService.createAlarm() failed");
}
}

private void discardAlarm() {
releaseWakeLock();

if (alarmManager != null) {
Log.v(Main.LOG_TAG, "DataService.discardAlarm()");
Log.v(Main.LOG_TAG, "AppService.discardAlarm()");
alarmManager.cancel(pendingIntent);
pendingIntent.cancel();

Expand Down
38 changes: 19 additions & 19 deletions src/main/java/org/blitzortung/android/app/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
import java.util.HashSet;
import java.util.Set;

public class Main extends OwnMapActivity implements DataListener, OnSharedPreferenceChangeListener, DataService.DataServiceStatusListener,
public class Main extends OwnMapActivity implements DataListener, OnSharedPreferenceChangeListener, AppService.DataServiceStatusListener,
AlarmManager.AlarmListener {

public static final String LOG_TAG = "BO_ANDROID";
Expand Down Expand Up @@ -78,7 +78,7 @@ public class Main extends OwnMapActivity implements DataListener, OnSharedPrefer
private ButtonColumnHandler<ImageButton> buttonColumnHandler;

private HistoryController historyController;
private DataService dataService;
private AppService appService;
private ServiceConnection serviceConnection;
private LegendView legendView;
private AlarmView alarmView;
Expand Down Expand Up @@ -185,23 +185,23 @@ public void onClick(View v) {
}

private void createAndBindToDataService() {
final Intent serviceIntent = new Intent(this, DataService.class);
final Intent serviceIntent = new Intent(this, AppService.class);

startService(serviceIntent);

serviceConnection = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
dataService = ((DataService.DataServiceBinder) iBinder).getService();
Log.i(Main.LOG_TAG, "Main.ServiceConnection.onServiceConnected() " + dataService);
dataService.setStatusListener(Main.this);
dataService.getDataHandler().setDataListener(Main.this);
strokesOverlay.setIntervalDuration(dataService.getDataHandler().getIntervalDuration());
appService = ((AppService.DataServiceBinder) iBinder).getService();
Log.i(Main.LOG_TAG, "Main.ServiceConnection.onServiceConnected() " + appService);
appService.setStatusListener(Main.this);
appService.getDataHandler().setDataListener(Main.this);
strokesOverlay.setIntervalDuration(appService.getDataHandler().getIntervalDuration());
if (!persistor.hasCurrentResult()) {
dataService.restart();
appService.restart();
}
dataService.onResume();
historyController.setDataService(dataService);
appService.onResume();
historyController.setAppService(appService);
}

@Override
Expand All @@ -224,7 +224,7 @@ private void setupDebugModeButton() {
rasterToggle.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
buttonColumnHandler.disableButtonColumn();
dataService.getDataHandler().toggleExtendedMode();
appService.getDataHandler().toggleExtendedMode();
onDataReset();
}
});
Expand Down Expand Up @@ -389,8 +389,8 @@ public void onResume() {

Log.d(Main.LOG_TAG, "Main.onResume()");

if (dataService != null) {
dataService.onResume();
if (appService != null) {
appService.onResume();
}
locationHandler.onResume();

Expand All @@ -404,7 +404,7 @@ public void onResume() {
public void onPause() {
super.onPause();

if (dataService == null || dataService.onPause()) {
if (appService == null || appService.onPause()) {
Log.d(Main.LOG_TAG, "Main.onPause() disable location handler");
locationHandler.onPause();
} else {
Expand Down Expand Up @@ -474,7 +474,7 @@ public void onDataUpdate(DataResult result) {
}

if (!result.containsRealtimeData()) {
dataService.disable();
appService.disable();
setHistoricStatusString();
}

Expand All @@ -494,8 +494,8 @@ public void onDataUpdate(DataResult result) {
legendView.invalidate();
}

if (dataService != null) {
dataService.releaseWakeLock();
if (appService != null) {
appService.releaseWakeLock();
}
}

Expand All @@ -513,7 +513,7 @@ private void clearDataIfRequested() {

@Override
public void onDataReset() {
dataService.reloadData();
appService.reloadData();
clearData = true;

for (DataListener listener : dataListeners) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
import android.view.View;
import android.widget.ImageButton;
import android.widget.Toast;
import org.blitzortung.android.app.AppService;
import org.blitzortung.android.app.R;
import org.blitzortung.android.app.DataService;
import org.blitzortung.android.data.DataChannel;
import org.blitzortung.android.data.DataHandler;

import java.util.ArrayList;
import java.util.Collection;
Expand All @@ -21,7 +20,7 @@ public class HistoryController {
private ImageButton historyForward;
private ImageButton goRealtime;
private final Collection<ImageButton> buttons;
private DataService dataService;
private AppService appService;

private ButtonColumnHandler buttonHandler;

Expand All @@ -40,7 +39,7 @@ public void setButtonHandler(ButtonColumnHandler buttonColumnHandler) {
}

public void setRealtimeData(boolean realtimeData) {
if (dataService != null && dataService.getDataHandler().isCapableOfHistoricalData()) {
if (appService != null && appService.getDataHandler().isCapableOfHistoricalData()) {
historyRewind.setVisibility(View.VISIBLE);
int historyButtonsVisibility = realtimeData ? View.INVISIBLE : View.VISIBLE;
historyForward.setVisibility(historyButtonsVisibility);
Expand All @@ -58,7 +57,7 @@ private void setupHistoryRewindButton(final Activity activity) {
buttons.add(historyRewind);
historyRewind.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if (dataService.getDataHandler().rewInterval()) {
if (appService.getDataHandler().rewInterval()) {
disableButtonColumn();
historyForward.setVisibility(View.VISIBLE);
goRealtime.setVisibility(View.VISIBLE);
Expand All @@ -78,8 +77,8 @@ private void setupHistoryForwardButton(Activity activity) {
historyForward.setVisibility(View.INVISIBLE);
historyForward.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if (dataService.getDataHandler().ffwdInterval()) {
if (dataService.getDataHandler().isRealtime()) {
if (appService.getDataHandler().ffwdInterval()) {
if (appService.getDataHandler().isRealtime()) {
configureForRealtimeOperation();
} else {
updateData();
Expand All @@ -95,7 +94,7 @@ private void setupGoRealtimeButton(Activity activity) {
goRealtime.setVisibility(View.INVISIBLE);
goRealtime.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if (dataService.getDataHandler().goRealtime()) {
if (appService.getDataHandler().goRealtime()) {
configureForRealtimeOperation();
}
}
Expand All @@ -107,8 +106,8 @@ private void configureForRealtimeOperation() {
historyForward.setVisibility(View.INVISIBLE);
goRealtime.setVisibility(View.INVISIBLE);
updateButtonColumn();
dataService.restart();
dataService.enable();
appService.restart();
appService.enable();
}

private void updateButtonColumn() {
Expand All @@ -128,10 +127,10 @@ private void disableButtonColumn() {
private void updateData() {
Set<DataChannel> dataChannels = new HashSet<DataChannel>();
dataChannels.add(DataChannel.STROKES);
dataService.getDataHandler().updateData(dataChannels);
appService.getDataHandler().updateData(dataChannels);
}

public void setDataService(DataService dataService) {
this.dataService = dataService;
public void setAppService(AppService appService) {
this.appService = appService;
}
}
Loading

0 comments on commit ab47088

Please sign in to comment.