mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-04 09:17:29 +01:00
Add Activity info into Device Card: add charts, split widths evenly
This commit is contained in:
parent
b24da9a409
commit
8caa529fbb
@ -22,6 +22,7 @@ import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.drawable.GradientDrawable;
|
||||
import android.text.InputType;
|
||||
import android.transition.TransitionManager;
|
||||
@ -44,6 +45,12 @@ import androidx.cardview.widget.CardView;
|
||||
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.github.mikephil.charting.animation.Easing;
|
||||
import com.github.mikephil.charting.charts.PieChart;
|
||||
import com.github.mikephil.charting.data.PieData;
|
||||
import com.github.mikephil.charting.data.PieDataSet;
|
||||
import com.github.mikephil.charting.data.PieEntry;
|
||||
import com.github.mikephil.charting.utils.MPPointF;
|
||||
import com.google.android.material.snackbar.Snackbar;
|
||||
import com.jaredrummler.android.colorpicker.ColorPickerDialog;
|
||||
import com.jaredrummler.android.colorpicker.ColorPickerDialogListener;
|
||||
@ -52,6 +59,7 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
@ -677,6 +685,7 @@ public class GBDeviceAdapterv2 extends RecyclerView.Adapter<GBDeviceAdapterv2.Vi
|
||||
TextView fmFrequencyLabel;
|
||||
ImageView ledColor;
|
||||
|
||||
//activity card
|
||||
LinearLayout cardViewActivityCardLayout;
|
||||
LinearLayout cardViewActivityCardStepsLayout;
|
||||
LinearLayout cardViewActivityCardSleepLayout;
|
||||
@ -687,6 +696,9 @@ public class GBDeviceAdapterv2 extends RecyclerView.Adapter<GBDeviceAdapterv2.Vi
|
||||
ProgressBar cardViewActivityCardStepsProgress;
|
||||
ProgressBar cardViewActivityCardDistanceProgress;
|
||||
ProgressBar cardViewActivityCardSleepProgress;
|
||||
PieChart TotalStepsChart;
|
||||
PieChart TotalDistanceChart;
|
||||
PieChart SleepTimeChart;
|
||||
|
||||
ViewHolder(View view) {
|
||||
super(view);
|
||||
@ -747,6 +759,9 @@ public class GBDeviceAdapterv2 extends RecyclerView.Adapter<GBDeviceAdapterv2.Vi
|
||||
cardViewActivityCardDistanceProgress = view.findViewById(R.id.card_view_activity_card_distance_progress);
|
||||
cardViewActivityCardSleepProgress = view.findViewById(R.id.card_view_activity_card_sleep_progress);
|
||||
|
||||
TotalStepsChart = view.findViewById(R.id.activity_dashboard_piechart1);
|
||||
TotalDistanceChart = view.findViewById(R.id.activity_dashboard_piechart2);
|
||||
SleepTimeChart = view.findViewById(R.id.activity_dashboard_piechart3);
|
||||
}
|
||||
|
||||
}
|
||||
@ -856,21 +871,95 @@ public class GBDeviceAdapterv2 extends RecyclerView.Adapter<GBDeviceAdapterv2.Vi
|
||||
holder.cardViewActivityCardDistanceProgress.setMax(distanceGoal);
|
||||
holder.cardViewActivityCardDistanceProgress.setProgress(steps * stepLength);
|
||||
|
||||
setUpChart(holder.TotalStepsChart);
|
||||
setChartsData(holder.TotalStepsChart, steps, stepGoal, context.getString(R.string.live_activity_total_steps), context);
|
||||
|
||||
setUpChart(holder.TotalDistanceChart);
|
||||
setChartsData(holder.TotalDistanceChart, steps * stepLength, distanceGoal, context.getString(R.string.live_activity_total_distance), context);
|
||||
|
||||
setUpChart(holder.SleepTimeChart);
|
||||
setChartsData(holder.SleepTimeChart, sleep, sleepGoalMinutes, context.getString(R.string.live_activity_sleep_duration), context);
|
||||
|
||||
boolean showActivityCard = GBApplication.getDeviceSpecificSharedPrefs(device.getAddress()).getBoolean(DeviceSettingsPreferenceConst.PREFS_ACTIVITY_IN_DEVICE_CARD, true);
|
||||
holder.cardViewActivityCardLayout.setVisibility(showActivityCard ? View.VISIBLE : View.GONE);
|
||||
|
||||
boolean showActivitySteps = GBApplication.getDeviceSpecificSharedPrefs(device.getAddress()).getBoolean(DeviceSettingsPreferenceConst.PREFS_ACTIVITY_IN_DEVICE_CARD_STEPS, true);
|
||||
holder.cardViewActivityCardStepsLayout.setVisibility(showActivitySteps ? View.VISIBLE : View.GONE);
|
||||
holder.TotalStepsChart.setVisibility(showActivitySteps ? View.VISIBLE : View.GONE);
|
||||
|
||||
boolean showActivitySleep = GBApplication.getDeviceSpecificSharedPrefs(device.getAddress()).getBoolean(DeviceSettingsPreferenceConst.PREFS_ACTIVITY_IN_DEVICE_CARD_SLEEP, true);
|
||||
holder.cardViewActivityCardSleepLayout.setVisibility(showActivitySleep ? View.VISIBLE : View.GONE);
|
||||
holder.SleepTimeChart.setVisibility(showActivitySleep ? View.VISIBLE : View.GONE);
|
||||
|
||||
boolean showActivityDistance = GBApplication.getDeviceSpecificSharedPrefs(device.getAddress()).getBoolean(DeviceSettingsPreferenceConst.PREFS_ACTIVITY_IN_DEVICE_CARD_DISTANCE, true);
|
||||
holder.cardViewActivityCardDistanceLayout.setVisibility(showActivityDistance ? View.VISIBLE : View.GONE);
|
||||
|
||||
holder.TotalDistanceChart.setVisibility(showActivityDistance ? View.VISIBLE : View.GONE);
|
||||
}
|
||||
|
||||
private String getHM(long value) {
|
||||
return DateTimeUtils.formatDurationHoursMinutes(value, TimeUnit.MINUTES);
|
||||
}
|
||||
private void setUpChart(PieChart DashboardChart) {
|
||||
DashboardChart.setNoDataText("");
|
||||
DashboardChart.getLegend().setEnabled(false);
|
||||
DashboardChart.setDrawHoleEnabled(true);
|
||||
DashboardChart.setHoleColor(Color.WHITE);
|
||||
DashboardChart.getDescription().setText("");
|
||||
DashboardChart.setTransparentCircleColor(Color.WHITE);
|
||||
DashboardChart.setTransparentCircleAlpha(110);
|
||||
DashboardChart.setHoleRadius(70f);
|
||||
DashboardChart.setTransparentCircleRadius(75f);
|
||||
DashboardChart.setDrawCenterText(true);
|
||||
DashboardChart.setRotationEnabled(true);
|
||||
DashboardChart.setHighlightPerTapEnabled(true);
|
||||
DashboardChart.setCenterTextOffset(0, 0);
|
||||
}
|
||||
private void setChartsData(PieChart pieChart, float value, float target, String label, Context context) {
|
||||
final String CHART_COLOR_START = "#e74c3c";
|
||||
final String CHART_COLOR_END = "#2ecc71";
|
||||
|
||||
ArrayList<PieEntry> entries = new ArrayList<>();
|
||||
entries.add(new PieEntry((float) value, context.getResources().getDrawable(R.drawable.ic_star_gold)));
|
||||
|
||||
if (value < target) {
|
||||
entries.add(new PieEntry((float) (target - value)));
|
||||
}
|
||||
|
||||
pieChart.setCenterText(String.format("%d%%\n%s", (int) (value * 100 / target), label));
|
||||
float colorValue = Math.max(0, Math.min(1, value / target));
|
||||
int chartColor = interpolateColor(Color.parseColor(CHART_COLOR_START), Color.parseColor(CHART_COLOR_END), colorValue);
|
||||
|
||||
PieDataSet dataSet = new PieDataSet(entries, "");
|
||||
dataSet.setDrawIcons(false);
|
||||
dataSet.setIconsOffset(new MPPointF(0, -66));
|
||||
|
||||
if (colorValue == 1) {
|
||||
dataSet.setDrawIcons(true);
|
||||
}
|
||||
dataSet.setSliceSpace(0f);
|
||||
dataSet.setSelectionShift(5f);
|
||||
dataSet.setColors(chartColor, Color.LTGRAY);
|
||||
|
||||
PieData data = new PieData(dataSet);
|
||||
data.setValueTextSize(0f);
|
||||
data.setValueTextColor(Color.WHITE);
|
||||
|
||||
pieChart.setData(data);
|
||||
pieChart.invalidate();
|
||||
}
|
||||
private float interpolate(float a, float b, float proportion) {
|
||||
return (a + ((b - a) * proportion));
|
||||
}
|
||||
|
||||
private int interpolateColor(int a, int b, float proportion) {
|
||||
float[] hsva = new float[3];
|
||||
float[] hsvb = new float[3];
|
||||
Color.colorToHSV(a, hsva);
|
||||
Color.colorToHSV(b, hsvb);
|
||||
for (int i = 0; i < 3; i++) {
|
||||
hsvb[i] = interpolate(hsva[i], hsvb[i], proportion);
|
||||
}
|
||||
return Color.HSVToColor(hsvb);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -463,135 +463,182 @@
|
||||
|
||||
|
||||
</com.google.android.flexbox.FlexboxLayout>
|
||||
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/card_view_activity_card_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/device_info_icons"
|
||||
android:gravity="center_horizontal"
|
||||
android:orientation="horizontal"
|
||||
android:paddingLeft="3dp"
|
||||
android:paddingRight="3dp"
|
||||
android:paddingBottom="5dp">
|
||||
android:layout_marginBottom="10dp"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/card_view_activity_card_steps_layout"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/card_view_activity_card_steps_icon"
|
||||
android:layout_width="20dp"
|
||||
android:layout_height="20dp"
|
||||
android:layout_gravity="start|center_vertical"
|
||||
android:background="@drawable/ic_shoe_prints_many"
|
||||
android:contentDescription="@string/icon_placeholder"
|
||||
android:padding="0dp" />
|
||||
android:gravity="center_horizontal"
|
||||
android:orientation="horizontal"
|
||||
android:paddingLeft="3dp"
|
||||
android:paddingRight="3dp"
|
||||
android:paddingBottom="15dp">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:id="@+id/card_view_activity_card_steps_layout"
|
||||
android:layout_width="110dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:paddingStart="10dp"
|
||||
android:paddingEnd="10dp">
|
||||
android:layout_gravity="bottom|center"
|
||||
android:layout_marginBottom="0dp"
|
||||
android:layout_weight="1"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/card_view_activity_card_steps"
|
||||
<ImageView
|
||||
android:id="@+id/card_view_activity_card_steps_icon"
|
||||
android:layout_width="20dp"
|
||||
android:layout_height="20dp"
|
||||
android:layout_gravity="start|bottom"
|
||||
android:background="@drawable/ic_shoe_prints_many"
|
||||
android:contentDescription="@string/icon_placeholder"
|
||||
android:padding="0dp" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_vertical|center_horizontal"
|
||||
android:text=""
|
||||
android:textSize="18sp" />
|
||||
android:orientation="vertical"
|
||||
android:paddingStart="10dp"
|
||||
android:paddingEnd="10dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/card_view_activity_card_steps"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_vertical|center_horizontal"
|
||||
android:text=""
|
||||
android:textSize="18sp" />
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/card_view_activity_card_steps_progress"
|
||||
style="?android:attr/progressBarStyleHorizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="3dp"
|
||||
android:background="#FFFFFF" />
|
||||
</LinearLayout>
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/card_view_activity_card_steps_progress"
|
||||
style="?android:attr/progressBarStyleHorizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="3dp"
|
||||
android:background="#FFFFFF" />
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/card_view_activity_card_distance_layout"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/card_view_activity_card_distance_icon"
|
||||
android:layout_width="20dp"
|
||||
android:layout_height="20dp"
|
||||
android:layout_gravity="start|center_vertical"
|
||||
android:background="@drawable/ic_distance_total"
|
||||
android:contentDescription="@string/icon_placeholder"
|
||||
android:padding="0dp" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:id="@+id/card_view_activity_card_distance_layout"
|
||||
android:layout_width="110dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:paddingStart="10dp"
|
||||
android:paddingEnd="10dp">
|
||||
android:layout_gravity="bottom|center"
|
||||
android:layout_marginBottom="0dp"
|
||||
android:layout_weight="1"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/card_view_activity_card_distance"
|
||||
<ImageView
|
||||
android:id="@+id/card_view_activity_card_distance_icon"
|
||||
android:layout_width="20dp"
|
||||
android:layout_height="20dp"
|
||||
android:layout_gravity="start|bottom"
|
||||
android:background="@drawable/ic_distance_total"
|
||||
android:contentDescription="@string/icon_placeholder"
|
||||
android:padding="0dp" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_vertical|center_horizontal"
|
||||
android:text=""
|
||||
android:textSize="18sp" />
|
||||
android:orientation="vertical"
|
||||
android:paddingStart="10dp"
|
||||
android:paddingEnd="10dp">
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/card_view_activity_card_distance_progress"
|
||||
style="?android:attr/progressBarStyleHorizontal"
|
||||
<TextView
|
||||
android:id="@+id/card_view_activity_card_distance"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_vertical|center_horizontal"
|
||||
android:text=""
|
||||
android:textSize="18sp" />
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/card_view_activity_card_distance_progress"
|
||||
style="?android:attr/progressBarStyleHorizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="3dp"
|
||||
android:layout_weight="1"
|
||||
android:background="#FFFFFF" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/card_view_activity_card_sleep_layout"
|
||||
android:layout_width="110dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="bottom|center"
|
||||
android:layout_marginBottom="0dp"
|
||||
android:layout_weight="1"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/card_view_activity_card_sleep_icon"
|
||||
android:layout_width="20dp"
|
||||
android:layout_height="20dp"
|
||||
android:layout_gravity="start|bottom"
|
||||
android:background="@drawable/ic_activity_sleep"
|
||||
android:contentDescription="@string/icon_placeholder" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="3dp"
|
||||
android:layout_weight="1"
|
||||
android:background="#FFFFFF" />
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:paddingStart="10dp"
|
||||
android:paddingEnd="10dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/card_view_activity_card_sleep"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_vertical|center_horizontal"
|
||||
android:text=""
|
||||
android:textSize="18sp" />
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/card_view_activity_card_sleep_progress"
|
||||
style="?android:attr/progressBarStyleHorizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="3dp"
|
||||
android:layout_weight="1"
|
||||
android:background="#FFFFFF" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/card_view_activity_card_sleep_layout"
|
||||
android:gravity="center"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/card_view_activity_card_sleep_icon"
|
||||
android:layout_width="20dp"
|
||||
android:layout_height="20dp"
|
||||
android:layout_gravity="start|center_vertical"
|
||||
android:background="@drawable/ic_activity_sleep"
|
||||
android:contentDescription="@string/icon_placeholder" />
|
||||
<com.github.mikephil.charting.charts.PieChart
|
||||
android:id="@+id/activity_dashboard_piechart1"
|
||||
android:layout_width="110dp"
|
||||
android:layout_height="110dp"
|
||||
android:layout_gravity="bottom|center"
|
||||
android:layout_marginBottom="0dp"
|
||||
android:layout_weight="1" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:paddingStart="10dp"
|
||||
android:paddingEnd="10dp">
|
||||
<com.github.mikephil.charting.charts.PieChart
|
||||
android:id="@+id/activity_dashboard_piechart2"
|
||||
android:layout_width="110dp"
|
||||
android:layout_height="110dp"
|
||||
android:layout_gravity="bottom|center"
|
||||
android:layout_marginBottom="0dp"
|
||||
android:layout_weight="1" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/card_view_activity_card_sleep"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_vertical|center_horizontal"
|
||||
android:text=""
|
||||
android:textSize="18sp" />
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/card_view_activity_card_sleep_progress"
|
||||
style="?android:attr/progressBarStyleHorizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="3dp"
|
||||
android:layout_weight="1"
|
||||
android:background="#FFFFFF" />
|
||||
</LinearLayout>
|
||||
<com.github.mikephil.charting.charts.PieChart
|
||||
android:id="@+id/activity_dashboard_piechart3"
|
||||
android:layout_width="110dp"
|
||||
android:layout_height="110dp"
|
||||
android:layout_gravity="bottom|center"
|
||||
android:layout_marginBottom="0dp"
|
||||
android:layout_weight="1" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
</RelativeLayout>
|
||||
|
@ -561,6 +561,8 @@
|
||||
<string name="live_activity_steps_history">Steps history</string>
|
||||
<string name="live_activity_current_steps_per_minute">Current steps/min</string>
|
||||
<string name="live_activity_total_steps">Total steps</string>
|
||||
<string name="live_activity_total_distance">Total distance</string>
|
||||
<string name="live_activity_sleep_duration">Sleep time</string>
|
||||
<string name="live_activity_steps_per_minute_history">Steps per minute history</string>
|
||||
<string name="live_activity_start_your_activity">Start your activity</string>
|
||||
<string name="live_activity_max_heart_rate">Current / Max heart rate: %1$d / %2$d</string>
|
||||
|
Loading…
Reference in New Issue
Block a user