mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-19 00:19:25 +01:00
Asynchronously load and render all widgets
This commit is contained in:
parent
3621377d91
commit
1d5ccde5b1
@ -16,6 +16,7 @@
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
package nodomain.freeyourgadget.gadgetbridge.activities.dashboard;
|
||||
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
@ -77,13 +78,35 @@ public class DashboardActiveTimeWidget extends AbstractDashboardWidget {
|
||||
|
||||
@Override
|
||||
protected void fillData() {
|
||||
// Update text representation
|
||||
long totalActiveMinutes = dashboardData.getActiveMinutesTotal();
|
||||
String activeHours = String.format("%d", (int) Math.floor(totalActiveMinutes / 60f));
|
||||
String activeMinutes = String.format("%02d", (int) (totalActiveMinutes % 60f));
|
||||
activeTime.setText(activeHours + ":" + activeMinutes);
|
||||
activeTimeGauge.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
FillDataAsyncTask myAsyncTask = new FillDataAsyncTask();
|
||||
myAsyncTask.execute();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Draw gauge
|
||||
activeTimeGauge.setImageBitmap(drawGauge(200, 15, color_active_time, dashboardData.getActiveMinutesGoalFactor()));
|
||||
private class FillDataAsyncTask extends AsyncTask<Void, Void, Void> {
|
||||
@Override
|
||||
protected Void doInBackground(Void... params) {
|
||||
dashboardData.getActiveMinutesTotal();
|
||||
dashboardData.getActiveMinutesGoalFactor();
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Void unused) {
|
||||
super.onPostExecute(unused);
|
||||
|
||||
// Update text representation
|
||||
long totalActiveMinutes = dashboardData.getActiveMinutesTotal();
|
||||
String activeHours = String.format("%d", (int) Math.floor(totalActiveMinutes / 60f));
|
||||
String activeMinutes = String.format("%02d", (int) (totalActiveMinutes % 60f));
|
||||
activeTime.setText(activeHours + ":" + activeMinutes);
|
||||
|
||||
// Draw gauge
|
||||
activeTimeGauge.setImageBitmap(drawGauge(200, 15, color_active_time, dashboardData.getActiveMinutesGoalFactor()));
|
||||
}
|
||||
}
|
||||
}
|
@ -16,6 +16,7 @@
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
package nodomain.freeyourgadget.gadgetbridge.activities.dashboard;
|
||||
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
@ -78,11 +79,34 @@ public class DashboardDistanceWidget extends AbstractDashboardWidget {
|
||||
|
||||
@Override
|
||||
protected void fillData() {
|
||||
// Update text representation
|
||||
String distanceFormatted = FormatUtils.getFormattedDistanceLabel(dashboardData.getDistanceTotal());
|
||||
distanceText.setText(distanceFormatted);
|
||||
distanceGauge.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
FillDataAsyncTask myAsyncTask = new FillDataAsyncTask();
|
||||
myAsyncTask.execute();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Draw gauge
|
||||
distanceGauge.setImageBitmap(drawGauge(200, 15, color_distance, dashboardData.getDistanceGoalFactor()));
|
||||
private class FillDataAsyncTask extends AsyncTask<Void, Void, Void> {
|
||||
@Override
|
||||
protected Void doInBackground(Void... params) {
|
||||
dashboardData.getDistanceTotal();
|
||||
dashboardData.getDistanceGoalFactor();
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Void unused) {
|
||||
super.onPostExecute(unused);
|
||||
|
||||
// Update text representation
|
||||
String distanceFormatted = FormatUtils.getFormattedDistanceLabel(dashboardData.getDistanceTotal());
|
||||
distanceText.setText(distanceFormatted);
|
||||
|
||||
// Draw gauge
|
||||
distanceGauge.setImageBitmap(drawGauge(200, 15, color_distance, dashboardData.getDistanceGoalFactor()));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -95,6 +95,7 @@ public class DashboardGoalsWidget extends AbstractDashboardWidget {
|
||||
if (goalsChart != null) fillData();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void fillData() {
|
||||
goalsView.post(new Runnable() {
|
||||
@Override
|
||||
@ -107,18 +108,11 @@ public class DashboardGoalsWidget extends AbstractDashboardWidget {
|
||||
|
||||
private class FillDataAsyncTask extends AsyncTask<Void, Void, Void> {
|
||||
private Bitmap goalsBitmap;
|
||||
int width = 500;
|
||||
int height = 500;
|
||||
|
||||
@Override
|
||||
protected void onPreExecute() {
|
||||
super.onPreExecute();
|
||||
goalsBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
|
||||
goalsChart.setImageBitmap(goalsBitmap);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(Void... params) {
|
||||
int width = 500;
|
||||
int height = 500;
|
||||
int barWidth = 20;
|
||||
int barMargin = (int) Math.ceil(barWidth / 2f);
|
||||
|
||||
|
@ -16,6 +16,7 @@
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
package nodomain.freeyourgadget.gadgetbridge.activities.dashboard;
|
||||
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
@ -77,13 +78,35 @@ public class DashboardSleepWidget extends AbstractDashboardWidget {
|
||||
|
||||
@Override
|
||||
protected void fillData() {
|
||||
// Update text representation
|
||||
long totalSleepMinutes = dashboardData.getSleepMinutesTotal();
|
||||
String sleepHours = String.format("%d", (int) Math.floor(totalSleepMinutes / 60f));
|
||||
String sleepMinutes = String.format("%02d", (int) (totalSleepMinutes % 60f));
|
||||
sleepAmount.setText(sleepHours + ":" + sleepMinutes);
|
||||
sleepGauge.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
FillDataAsyncTask myAsyncTask = new FillDataAsyncTask();
|
||||
myAsyncTask.execute();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Draw gauge
|
||||
sleepGauge.setImageBitmap(drawGauge(200, 15, color_light_sleep, dashboardData.getSleepMinutesGoalFactor()));
|
||||
private class FillDataAsyncTask extends AsyncTask<Void, Void, Void> {
|
||||
@Override
|
||||
protected Void doInBackground(Void... params) {
|
||||
dashboardData.getSleepMinutesTotal();
|
||||
dashboardData.getSleepMinutesGoalFactor();
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Void unused) {
|
||||
super.onPostExecute(unused);
|
||||
|
||||
// Update text representation
|
||||
long totalSleepMinutes = dashboardData.getSleepMinutesTotal();
|
||||
String sleepHours = String.format("%d", (int) Math.floor(totalSleepMinutes / 60f));
|
||||
String sleepMinutes = String.format("%02d", (int) (totalSleepMinutes % 60f));
|
||||
sleepAmount.setText(sleepHours + ":" + sleepMinutes);
|
||||
|
||||
// Draw gauge
|
||||
sleepGauge.setImageBitmap(drawGauge(200, 15, color_light_sleep, dashboardData.getSleepMinutesGoalFactor()));
|
||||
}
|
||||
}
|
||||
}
|
@ -16,6 +16,7 @@
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
package nodomain.freeyourgadget.gadgetbridge.activities.dashboard;
|
||||
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
@ -73,11 +74,35 @@ public class DashboardStepsWidget extends AbstractDashboardWidget {
|
||||
if (stepsCount != null && stepsGauge != null) fillData();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void fillData() {
|
||||
// Update text representation
|
||||
stepsCount.setText(String.valueOf(dashboardData.getStepsTotal()));
|
||||
stepsGauge.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
FillDataAsyncTask myAsyncTask = new FillDataAsyncTask();
|
||||
myAsyncTask.execute();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Draw gauge
|
||||
stepsGauge.setImageBitmap(drawGauge(200, 15, color_activity, dashboardData.getStepsGoalFactor()));
|
||||
private class FillDataAsyncTask extends AsyncTask<Void, Void, Void> {
|
||||
@Override
|
||||
protected Void doInBackground(Void... params) {
|
||||
dashboardData.getStepsTotal();
|
||||
dashboardData.getStepsGoalFactor();
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Void unused) {
|
||||
super.onPostExecute(unused);
|
||||
|
||||
// Update text representation
|
||||
stepsCount.setText(String.valueOf(dashboardData.getStepsTotal()));
|
||||
|
||||
// Draw gauge
|
||||
stepsGauge.setImageBitmap(drawGauge(200, 15, color_activity, dashboardData.getStepsGoalFactor()));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user