From 173b4fbbe60074cdb592b0eab7e92637d2900620 Mon Sep 17 00:00:00 2001 From: Andreas Shimokawa Date: Fri, 31 Mar 2017 23:42:25 +0200 Subject: [PATCH 001/131] Add legend ans labels to weekly sleep charts Also remove the "missing sleep" gray entry to avoid confusion --- .../charts/AbstractWeekChartFragment.java | 38 +++++++++---------- .../charts/WeekSleepChartFragment.java | 27 +++++++++++++ .../charts/WeekStepsChartFragment.java | 12 ++++++ 3 files changed, 56 insertions(+), 21 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/AbstractWeekChartFragment.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/AbstractWeekChartFragment.java index b43816372..ea55e740e 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/AbstractWeekChartFragment.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/AbstractWeekChartFragment.java @@ -25,7 +25,6 @@ import android.view.View; import android.view.ViewGroup; import com.github.mikephil.charting.charts.BarChart; -import com.github.mikephil.charting.charts.Chart; import com.github.mikephil.charting.charts.PieChart; import com.github.mikephil.charting.components.LimitLine; import com.github.mikephil.charting.components.XAxis; @@ -81,13 +80,12 @@ public abstract class AbstractWeekChartFragment extends AbstractChartFragment { protected void updateChartsnUIThread(ChartsData chartsData) { MyChartsData mcd = (MyChartsData) chartsData; -// setupLegend(mWeekChart); + setupLegend(mWeekChart); mTodayPieChart.setCenterText(mcd.getDayData().centerText); mTodayPieChart.setData(mcd.getDayData().data); mWeekChart.setData(null); // workaround for https://github.com/PhilJay/MPAndroidChart/issues/2317 mWeekChart.setData(mcd.getWeekBeforeData().getData()); - mWeekChart.getLegend().setEnabled(false); mWeekChart.getXAxis().setValueFormatter(mcd.getWeekBeforeData().getXValueFormatter()); } @@ -133,23 +131,30 @@ public abstract class AbstractWeekChartFragment extends AbstractChartFragment { ActivityAmounts amounts = getActivityAmountsForDay(db, day, device); float totalValues[] = getTotalsForActivityAmounts(amounts); + String[] pieLabels = getPieLabels(); float totalValue = 0; - for (float value : totalValues) { + for (int i = 0; i < totalValues.length; i++) { + float value = totalValues[i]; totalValue += value; - entries.add(new PieEntry(value)); + entries.add(new PieEntry(value, pieLabels[i])); } set.setValueFormatter(getPieValueFormatter()); set.setColors(getColors()); - if (totalValue < mTargetValue) { - entries.add(new PieEntry((mTargetValue - totalValue))); - set.addColor(Color.GRAY); + //this hides the values (numeric) added to the set. These would be shown aside the strings set with addXValue above + if (totalValues.length < 2) { + if (totalValue < mTargetValue) { + entries.add(new PieEntry((mTargetValue - totalValue))); + set.addColor(Color.GRAY); + } } data.setDataSet(set); - //this hides the values (numeric) added to the set. These would be shown aside the strings set with addXValue above - data.setDrawValues(false); + + if (totalValues.length < 2) { + data.setDrawValues(false); + } return new DayData(data, formatPieValue((int) totalValue)); } @@ -185,7 +190,6 @@ public abstract class AbstractWeekChartFragment extends AbstractChartFragment { // mTodayPieChart.setNoDataTextDescription(""); mTodayPieChart.setNoDataText(""); mTodayPieChart.getLegend().setEnabled(false); -// setupLegend(mTodayPieChart); } private void setupWeekChart() { @@ -222,16 +226,6 @@ public abstract class AbstractWeekChartFragment extends AbstractChartFragment { yAxisRight.setTextColor(CHART_TEXT_COLOR); } - @Override - protected void setupLegend(Chart chart) { -// List legendColors = new ArrayList<>(1); -// List legendLabels = new ArrayList<>(1); -// legendColors.add(akActivity.color); -// legendLabels.add(getContext().getString(R.string.chart_steps)); -// chart.getLegend().setCustom(legendColors, legendLabels); -// chart.getLegend().setTextColor(LEGEND_TEXT_COLOR); - } - private List getSamplesOfDay(DBHandler db, Calendar day, int offsetHours, GBDevice device) { int startTs; int endTs; @@ -312,6 +306,8 @@ public abstract class AbstractWeekChartFragment extends AbstractChartFragment { abstract String formatPieValue(int value); + abstract String[] getPieLabels(); + abstract IValueFormatter getPieValueFormatter(); abstract IValueFormatter getBarValueFormatter(); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/WeekSleepChartFragment.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/WeekSleepChartFragment.java index 8e6e5623d..29ef5a969 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/WeekSleepChartFragment.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/WeekSleepChartFragment.java @@ -16,12 +16,16 @@ along with this program. If not, see . */ package nodomain.freeyourgadget.gadgetbridge.activities.charts; +import com.github.mikephil.charting.charts.Chart; import com.github.mikephil.charting.components.AxisBase; +import com.github.mikephil.charting.components.LegendEntry; import com.github.mikephil.charting.data.Entry; import com.github.mikephil.charting.formatter.IAxisValueFormatter; import com.github.mikephil.charting.formatter.IValueFormatter; import com.github.mikephil.charting.utils.ViewPortHandler; +import java.util.ArrayList; +import java.util.List; import java.util.concurrent.TimeUnit; import nodomain.freeyourgadget.gadgetbridge.GBApplication; @@ -72,6 +76,11 @@ public class WeekSleepChartFragment extends AbstractWeekChartFragment { return DateTimeUtils.formatDurationHoursMinutes((long) value, TimeUnit.MINUTES); } + @Override + String[] getPieLabels() { + return new String[]{getString(R.string.abstract_chart_fragment_kind_deep_sleep), getString(R.string.abstract_chart_fragment_kind_light_sleep)}; + } + @Override IValueFormatter getPieValueFormatter() { return new IValueFormatter() { @@ -106,4 +115,22 @@ public class WeekSleepChartFragment extends AbstractWeekChartFragment { int[] getColors() { return new int[]{akDeepSleep.color, akLightSleep.color}; } + + @Override + protected void setupLegend(Chart chart) { + List legendEntries = new ArrayList<>(2); + + LegendEntry lightSleepEntry = new LegendEntry(); + lightSleepEntry.label = akLightSleep.label; + lightSleepEntry.formColor = akLightSleep.color; + legendEntries.add(lightSleepEntry); + + LegendEntry deepSleepEntry = new LegendEntry(); + deepSleepEntry.label = akDeepSleep.label; + deepSleepEntry.formColor = akDeepSleep.color; + legendEntries.add(deepSleepEntry); + + chart.getLegend().setCustom(legendEntries); + chart.getLegend().setTextColor(LEGEND_TEXT_COLOR); + } } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/WeekStepsChartFragment.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/WeekStepsChartFragment.java index 143ad9cfa..86cc382c6 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/WeekStepsChartFragment.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/WeekStepsChartFragment.java @@ -17,6 +17,7 @@ along with this program. If not, see . */ package nodomain.freeyourgadget.gadgetbridge.activities.charts; +import com.github.mikephil.charting.charts.Chart; import com.github.mikephil.charting.formatter.IAxisValueFormatter; import com.github.mikephil.charting.formatter.IValueFormatter; @@ -62,6 +63,11 @@ public class WeekStepsChartFragment extends AbstractWeekChartFragment { return String.valueOf(value); } + @Override + String[] getPieLabels() { + return new String[]{""}; + } + @Override IValueFormatter getPieValueFormatter() { return null; @@ -81,4 +87,10 @@ public class WeekStepsChartFragment extends AbstractWeekChartFragment { int[] getColors() { return new int[]{akActivity.color}; } + + @Override + protected void setupLegend(Chart chart) { + // no legend here, it is all about the steps here + chart.getLegend().setEnabled(false); + } } From db4e37d08b984cd2c49c935239729b52f75e1eb4 Mon Sep 17 00:00:00 2001 From: Daniele Gobbetti Date: Sat, 1 Apr 2017 15:45:30 +0200 Subject: [PATCH 002/131] Make the drag handle less prominent (grey) --- app/src/main/res/layout/item_with_details_and_drag_handle.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/res/layout/item_with_details_and_drag_handle.xml b/app/src/main/res/layout/item_with_details_and_drag_handle.xml index 58943cb68..98d39a23f 100644 --- a/app/src/main/res/layout/item_with_details_and_drag_handle.xml +++ b/app/src/main/res/layout/item_with_details_and_drag_handle.xml @@ -43,6 +43,7 @@ Date: Sat, 1 Apr 2017 17:06:38 +0200 Subject: [PATCH 003/131] Apply some Material design guidelines to the app management - replace the PagerTabStrip with a TabLayout (moved to top) - change the row element to adhere to the guidelines wrt spacing - move the FAB a bit and hide it when scrolling down, scroll up to reveal it again --- .../AbstractAppManagerFragment.java | 13 +++++++ .../main/res/layout/activity_appmanager.xml | 9 +++-- .../layout/activity_fragmentappmanager.xml | 12 +++---- .../item_with_details_and_drag_handle.xml | 36 ++++++++++++------- 4 files changed, 46 insertions(+), 24 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/appmanager/AbstractAppManagerFragment.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/appmanager/AbstractAppManagerFragment.java index c9ebb69af..e2ad884f6 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/appmanager/AbstractAppManagerFragment.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/appmanager/AbstractAppManagerFragment.java @@ -24,6 +24,7 @@ import android.content.IntentFilter; import android.content.pm.PackageManager; import android.net.Uri; import android.os.Bundle; +import android.support.design.widget.FloatingActionButton; import android.support.v4.app.Fragment; import android.support.v4.content.LocalBroadcastManager; import android.support.v7.widget.LinearLayoutManager; @@ -259,9 +260,21 @@ public abstract class AbstractAppManagerFragment extends Fragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + final FloatingActionButton appListFab = ((FloatingActionButton) getActivity().findViewById(R.id.fab)); View rootView = inflater.inflate(R.layout.activity_appmanager, container, false); RecyclerView appListView = (RecyclerView) (rootView.findViewById(R.id.appListView)); + + appListView.addOnScrollListener(new RecyclerView.OnScrollListener() { + @Override + public void onScrolled(RecyclerView recyclerView, int dx, int dy) { + if (dy > 0) { + appListFab.hide(); + } else if (dy < 0) { + appListFab.show(); + } + } + }); appListView.setLayoutManager(new LinearLayoutManager(getActivity())); mGBDeviceAppAdapter = new GBDeviceAppAdapter(appList, R.layout.item_with_details_and_drag_handle, this); appListView.setAdapter(mGBDeviceAppAdapter); diff --git a/app/src/main/res/layout/activity_appmanager.xml b/app/src/main/res/layout/activity_appmanager.xml index ed6a70f38..943de9d83 100644 --- a/app/src/main/res/layout/activity_appmanager.xml +++ b/app/src/main/res/layout/activity_appmanager.xml @@ -5,7 +5,10 @@ tools:context="nodomain.freeyourgadget.gadgetbridge.activities.appmanager.AbstractAppManagerFragment"> + android:id="@+id/appListView" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:layout_alignParentTop="true" + android:layout_centerHorizontal="true" + android:divider="@null" /> diff --git a/app/src/main/res/layout/activity_fragmentappmanager.xml b/app/src/main/res/layout/activity_fragmentappmanager.xml index d32ada664..95915b0a6 100644 --- a/app/src/main/res/layout/activity_fragmentappmanager.xml +++ b/app/src/main/res/layout/activity_fragmentappmanager.xml @@ -3,10 +3,6 @@ android:layout_width="match_parent" android:layout_height="match_parent" xmlns:app="http://schemas.android.com/apk/res-auto" - android:paddingBottom="0px" - android:paddingLeft="0px" - android:paddingRight="0px" - android:paddingTop="0px" tools:context=".activities.appmanager.AppManagerActivity"> - + android:layout_gravity="top" /> @@ -39,7 +35,7 @@ android:src="@drawable/ic_add_white" app:elevation="6dp" app:pressedTranslationZ="12dp" - android:layout_marginBottom="10dp" - android:layout_marginRight="10dp" /> + android:layout_marginBottom="30dp" + android:layout_marginEnd="10dp" /> diff --git a/app/src/main/res/layout/item_with_details_and_drag_handle.xml b/app/src/main/res/layout/item_with_details_and_drag_handle.xml index 98d39a23f..316fc03a6 100644 --- a/app/src/main/res/layout/item_with_details_and_drag_handle.xml +++ b/app/src/main/res/layout/item_with_details_and_drag_handle.xml @@ -4,50 +4,60 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:background="?android:attr/activatedBackgroundIndicator" - android:padding="8dp"> + android:minHeight="60dp"> + android:paddingBottom="8dp" + android:paddingTop="8dp"> + android:textAppearance="@style/TextAppearance.AppCompat.Subhead" /> + android:text="Item Description" + android:textAppearance="@style/TextAppearance.AppCompat.Body1" /> \ No newline at end of file From e89ba529c301bc653151b6f86e94c0a1c1926e3a Mon Sep 17 00:00:00 2001 From: Daniele Gobbetti Date: Sat, 1 Apr 2017 17:47:54 +0200 Subject: [PATCH 004/131] Apply some Material design guidelines to the charts - replace the PagerTabStrip with a TabLayout (moved to top and scrollable) - move the date selection to the bottom - do not update the activity title as the tab name is much more visible now --- CHANGELOG.md | 3 + .../activities/AbstractGBFragment.java | 11 --- .../activities/charts/ChartsActivity.java | 3 - app/src/main/res/layout/activity_charts.xml | 89 ++++++++++--------- app/src/main/res/xml/changelog_master.xml | 5 ++ 5 files changed, 54 insertions(+), 57 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ef8dbf97c..d9bdad8a2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ ###Changelog +###Version next +* Applied some material design guidelines to Charts and (pebble) app management + ###Version 0.18.4 * Mi Band 2: Display realtime steps in Live Activity * Mi Band: Attempt to recognize Mi Band model with hwVersion = 8 diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/AbstractGBFragment.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/AbstractGBFragment.java index 66858bf1b..d9939ba07 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/AbstractGBFragment.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/AbstractGBFragment.java @@ -18,7 +18,6 @@ package nodomain.freeyourgadget.gadgetbridge.activities; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; -import android.support.v4.app.FragmentActivity; /** * Abstract base class for fragments. Provides hooks that are called when @@ -37,7 +36,6 @@ public abstract class AbstractGBFragment extends Fragment { * @see #onMadeInvisibleInActivity() */ protected void onMadeVisibleInActivity() { - updateActivityTitle(); } /** @@ -58,15 +56,6 @@ public abstract class AbstractGBFragment extends Fragment { return mVisibleInactivity; } - protected void updateActivityTitle() { - FragmentActivity activity = getActivity(); - if (activity != null && !activity.isFinishing() && !activity.isDestroyed()) { - if (getTitle() != null) { - activity.setTitle(getTitle()); - } - } - } - @Nullable protected abstract CharSequence getTitle(); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/ChartsActivity.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/ChartsActivity.java index d5dedfc24..2b73b1923 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/ChartsActivity.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/ChartsActivity.java @@ -27,7 +27,6 @@ import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentStatePagerAdapter; import android.support.v4.content.LocalBroadcastManager; -import android.support.v4.view.PagerTabStrip; import android.support.v4.view.ViewPager; import android.support.v4.widget.SwipeRefreshLayout; import android.view.Menu; @@ -67,7 +66,6 @@ public class ChartsActivity extends AbstractGBFragmentActivity implements Charts private Date mStartDate; private Date mEndDate; private SwipeRefreshLayout swipeLayout; - private PagerTabStrip mPagerTabStrip; private ViewPager viewPager; LimitedQueue mActivityAmountCache = new LimitedQueue(60); @@ -200,7 +198,6 @@ public class ChartsActivity extends AbstractGBFragmentActivity implements Charts handleNextButtonClicked(); } }); - mPagerTabStrip = (PagerTabStrip) findViewById(R.id.charts_pagerTabStrip); LinearLayout mainLayout = (LinearLayout) findViewById(R.id.charts_main_layout); } diff --git a/app/src/main/res/layout/activity_charts.xml b/app/src/main/res/layout/activity_charts.xml index bce480827..6321f441e 100644 --- a/app/src/main/res/layout/activity_charts.xml +++ b/app/src/main/res/layout/activity_charts.xml @@ -1,56 +1,59 @@ - - + android:layout_height="match_parent" + tools:context="nodomain.freeyourgadget.gadgetbridge.activities.charts.ChartsActivity"> -