Skip to content

Commit

Permalink
Merge pull request #2 from j4velin/master
Browse files Browse the repository at this point in the history
Update to latest version
  • Loading branch information
McGiverGim committed Jan 28, 2014
2 parents 7b0933b + 2487c8e commit f43fb47
Show file tree
Hide file tree
Showing 9 changed files with 133 additions and 49 deletions.
11 changes: 8 additions & 3 deletions res/menu/main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,21 @@
android:id="@+id/action_settings"
android:orderInCategory="100"
android:showAsAction="ifRoom"
android:title="Settings"/>
android:title="@string/settings"/>
<item
android:id="@+id/action_achievements"
android:orderInCategory="100"
android:showAsAction="never"
android:title="Achievements"/>
android:title="@string/achievements"/>
<item
android:id="@+id/action_leaderboard"
android:orderInCategory="100"
android:showAsAction="never"
android:title="Leaderboard"/>
android:title="@string/leaderboard"/>
<item
android:id="@+id/action_faq"
android:orderInCategory="100"
android:showAsAction="never"
android:title="@string/faq"/>

</menu>
39 changes: 39 additions & 0 deletions res/values-de/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>

<string name="app_name">Schrittzähler</string>
<string name="goal">Ziel</string>
<string name="step_size">Schrittweite</string>
<string name="about">Info</string>
<string name="account">Konto</string>
<string name="goal_summary">Aktuelles Ziel: %,d Schritte</string>
<string name="step_size_summary">Aktuelle Schrittweite: %1$.2f %2$s</string>
<string name="sign_in">Logge dich mit deinem Google Konto ein um Erfolge zu sammeln und die Bestenslisten zu nutzen</string>
<string name="signed_in">Eingeloggt als %s</string>
<string name="export_summary">Sichere deine Daten in einer .csv Datei</string>
<string name="export_title">Exportieren</string>
<string name="import_summary">Lade Daten aus einer .csv Datei</string>
<string name="import_title">Importieren</string>
<string name="notification">Zeige Benachrichtigung</string>
<string name="set_goal">Ziel setzen</string>
<string name="set_step_size">Schrittweite ändern</string>
<string name="about_text">Diese App wurde von Thomas Hoffmann (www.j4velin-development.de) geschrieben und verwendet \'HoloGraphLibrary\' von Daniel Nadeau und \'ColorPickerPreference\' von Sergey Margaritov.\n\nApp-Version: %s\n\nSchrittzähler ist ein Open-Source Projekt, der Quellcode kann unter https://github.com/j4velin/Pedometer abgerufen werden</string>
<string name="sign_out">Ausloggen</string>
<string name="file_cant_read">Fehler: %s kann nicht gelesen werden</string>
<string name="error_file">Fehler beim Zugriff auf die Datei: %s</string>
<string name="error_external_storage_not_available">Fehler: Externer Speicher ist momentan nicht verfügbar</string>
<string name="data_saved">Daten gespeichert in %s</string>
<string name="entries_imported">%d Einträge wurden importiert</string>
<string name="entries_ignored">%d Einträge wurden ignoriert, da diese in keinem gültigen Format vorlagen</string>
<string name="sign_in_necessary">Login erforderlich</string>
<string name="please_sign_in_with_your_google_account">Bitte logge dich mit deinem Google+ Konto ein um diese Funktion zu nutzen.</string>
<string name="steps">Schritte</string>
<string name="text_color">Text-Farbe:</string>
<string name="background_color">Hintergrund-Farbe:</string>
<string name="settings">Einstellungen</string>
<string name="achievements">Errungenschaften</string>
<string name="leaderboard">Bestenliste</string>
<string name="faq">FAQ</string>
<string name="goal_reached_notification">Ziel erreicht! Schon über %s Schritte</string>
<string name="notification_text">Ziel wird in %s Schritte erreicht</string>
</resources>
8 changes: 7 additions & 1 deletion res/values-sv/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,11 @@
<string name="steps">steg</string>
<string name="text_color">Textfärg:</string>
<string name="background_color">Bakgrundsfärg:</string>

<string name="settings">Inställningar</string>
<string name="achievements">Prestationer</string>
<string name="leaderboard">Topplistor</string>
<string name="faq">FAQ</string>
<string name="goal_reached_notification">Mål nått! %s steg hittills</string>
<string name="notification_text">%s steg kvar</string>

</resources>
6 changes: 6 additions & 0 deletions res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,11 @@
<string name="steps">steps</string>
<string name="text_color">Text color:</string>
<string name="background_color">Background color:</string>
<string name="settings">Settings</string>
<string name="achievements">Achievements</string>
<string name="leaderboard">Leaderboard</string>
<string name="faq">FAQ</string>
<string name="goal_reached_notification">Goal reached! %s steps and counting</string>
<string name="notification_text">%s steps to go</string>

</resources>
5 changes: 5 additions & 0 deletions src/de/j4velin/pedometer/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import de.j4velin.pedometer.background.SensorListener;

import android.net.Uri;
import android.os.Bundle;
import android.view.MenuItem;
import android.app.AlertDialog;
Expand Down Expand Up @@ -110,6 +111,10 @@ public void onClick(DialogInterface dialog, int which) {
builder2.create().show();
}
break;
case R.id.action_faq:
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://j4velin-systems.de/faq/index.php?app=pm"))
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
break;
}
return true;
}
Expand Down
32 changes: 18 additions & 14 deletions src/de/j4velin/pedometer/OverviewFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,12 @@ public void onServiceConnected(ComponentName name, IBinder service) {
final ServiceConnection conn = this;
Messenger incoming = new Messenger(new Handler() {
public void handleMessage(Message msg) {
if (Logger.LOG)
Logger.log("SensorListener.steps: " + msg.arg1);
since_boot = msg.arg1;
updateSteps();
if (msg != null) {
if (Logger.LOG)
Logger.log("SensorListener.steps: " + msg.arg1);
since_boot = msg.arg1;
updateSteps();
}
getActivity().unbindService(conn);
}
});
Expand Down Expand Up @@ -179,16 +181,18 @@ public void handleMessage(Message msg) {
yesterday.add(Calendar.DAY_OF_YEAR, -6);
int steps;
for (int i = 0; i < 7; i++) {
steps = Math.max(db.getSteps(yesterday.getTimeInMillis()), 0);
d = new Bar();
if (steps > goal)
d.setColor(Color.parseColor("#99CC00"));
else
d.setColor(Color.parseColor("#0099cc"));
d.setName(df.format(new Date(yesterday.getTimeInMillis())));
d.setValue(steps);
d.setValueString(formatter.format(d.getValue()));
points.add(d);
steps = db.getSteps(yesterday.getTimeInMillis());
if (steps > 0) {
d = new Bar();
if (steps > goal)
d.setColor(Color.parseColor("#99CC00"));
else
d.setColor(Color.parseColor("#0099cc"));
d.setName(df.format(new Date(yesterday.getTimeInMillis())));
d.setValue(steps);
d.setValueString(formatter.format(d.getValue()));
points.add(d);
}
yesterday.add(Calendar.DAY_OF_YEAR, 1);
}
db.close();
Expand Down
47 changes: 28 additions & 19 deletions src/de/j4velin/pedometer/background/NewDayReceiver.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,26 +32,34 @@ public class NewDayReceiver extends BroadcastReceiver {

@Override
public void onReceive(final Context context, final Intent intent) {

// Save the steps made yesterday and create a new
// row for today
if (Logger.LOG) {
Logger.log("date changed, today is: " + Util.getToday());
Logger.log("Steps: " + SensorListener.steps);
}
Database db = new Database(context);
db.open();
// start the new days step with the offset of the
// current step-value.
//
// insertNewDay also updates the step value for yesterday
db.insertNewDay(Util.getToday(), SensorListener.steps);
db.close();

// to update the notification
context.startService(new Intent(context, SensorListener.class).putExtra("updateNotificationState", true));
if (SensorListener.IS_RUNNING) {
// Save the steps made yesterday and create a new
// row for today
Database db = new Database(context);
db.open();
// start the new days step with the offset of the
// current step-value.
//
// insertNewDay also updates the step value for yesterday
db.insertNewDay(Util.getToday(), SensorListener.steps);
db.close();

sheduleAlarmForNextDay(context);

// to update the notification
context.startService(new Intent(context, SensorListener.class).putExtra("updateNotificationState", true));

sheduleAlarmForNextDay(context);
} else {
// start the SensorListener first. SensorListener will then start
// this Receiver again as it see that there is no entry for today
// yet
context.startService(new Intent(context, SensorListener.class));
}
}

/**
Expand All @@ -67,12 +75,13 @@ static void sheduleAlarmForNextDay(final Context context) {
tomorrow.setTimeInMillis(Util.getToday()); // today
tomorrow.add(Calendar.DAY_OF_YEAR, 1); // tomorrow
tomorrow.add(Calendar.SECOND, 1); // tomorrow at 0:00:01
((AlarmManager) context.getApplicationContext().getSystemService(Context.ALARM_SERVICE))
.setExact(AlarmManager.RTC_WAKEUP, tomorrow.getTimeInMillis(), PendingIntent.getBroadcast(
context.getApplicationContext(), 10, new Intent(context.getApplicationContext(), NewDayReceiver.class),
PendingIntent.FLAG_UPDATE_CURRENT));

PendingIntent pi = PendingIntent.getBroadcast(context.getApplicationContext(), 10,
new Intent(context.getApplicationContext(), NewDayReceiver.class), PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager am = ((AlarmManager) context.getApplicationContext().getSystemService(Context.ALARM_SERVICE));
am.cancel(pi);
am.setExact(AlarmManager.RTC_WAKEUP, tomorrow.getTimeInMillis(), pi);
if (Logger.LOG)
Logger.log("newDayAlarm sheduled for " + tomorrow.getTime().toLocaleString());
}

}
22 changes: 17 additions & 5 deletions src/de/j4velin/pedometer/background/SensorListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@
*/
public class SensorListener extends Service implements SensorEventListener {

static boolean IS_RUNNING;

/**
* The steps since boot as returned by the step-sensor
*/
Expand Down Expand Up @@ -98,10 +100,11 @@ public void onSensorChanged(final SensorEvent event) {
today_offset = -steps;
if (today_offset + steps < goal) {
notificationBuilder.setProgress(goal, today_offset + steps, false).setContentText(
NumberFormat.getInstance(Locale.getDefault()).format((goal - today_offset - steps)) + " steps to go");
getString(R.string.notification_text,
NumberFormat.getInstance(Locale.getDefault()).format((goal - today_offset - steps))));
} else {
notificationBuilder.setContentText("Goal reached! "
+ NumberFormat.getInstance(Locale.getDefault()).format((today_offset + steps)) + " steps and counting");
notificationBuilder.setContentText(getString(R.string.goal_reached_notification,
NumberFormat.getInstance(Locale.getDefault()).format((today_offset + steps))));
}
((NotificationManager) getSystemService(NOTIFICATION_SERVICE)).notify(1, notificationBuilder.build());
}
Expand All @@ -115,6 +118,8 @@ public IBinder onBind(final Intent intent) {

@Override
public int onStartCommand(final Intent intent, int flags, int startId) {
IS_RUNNING = true;

if (Logger.LOG)
Logger.log("service started. steps: " + steps + " intent=null? " + (intent == null) + " flags: " + flags
+ " startid: " + startId);
Expand All @@ -123,7 +128,7 @@ public int onStartCommand(final Intent intent, int flags, int startId) {
}

NewDayReceiver.sheduleAlarmForNextDay(this);

// check if NewDayReceiver was called for the current day
Database db = new Database(this);
db.open();
Expand All @@ -134,6 +139,13 @@ public int onStartCommand(final Intent intent, int flags, int startId) {
sendBroadcast(new Intent(this, NewDayReceiver.class));
}

// Workaround as on Android 4.4.2 START_STICKY has currently no
// effect
// -> restart service every hour
((AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE)).set(AlarmManager.RTC, System
.currentTimeMillis() + 1000 * 60 * 60, PendingIntent.getService(getApplicationContext(), 2, new Intent(this,
SensorListener.class), PendingIntent.FLAG_UPDATE_CURRENT));

return START_STICKY;
}

Expand Down Expand Up @@ -209,7 +221,7 @@ public void onDestroy() {
} catch (Exception e) {
e.printStackTrace();
}

IS_RUNNING = false;
stopForeground(true);
}
}
12 changes: 5 additions & 7 deletions src/de/j4velin/pedometer/widget/Widget.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,18 @@
import de.j4velin.pedometer.R;
import android.app.PendingIntent;
import android.appwidget.AppWidgetManager;
import android.content.BroadcastReceiver;
import android.appwidget.AppWidgetProvider;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.widget.RemoteViews;

public class Widget extends BroadcastReceiver {

public class Widget extends AppWidgetProvider {
@Override
public void onReceive(final Context context, final Intent intent) {
if (AppWidgetManager.ACTION_APPWIDGET_UPDATE.equals(intent.getAction())) {
context.startService(new Intent(context, WidgetUpdateService.class));
}
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
context.startService(new Intent(context, WidgetUpdateService.class));
}

static RemoteViews updateWidget(final int appWidgetId, final Context context, final int steps) {
Expand Down

0 comments on commit f43fb47

Please sign in to comment.