From 29a05f1d8f8f2952688d7b60a748639c66793b77 Mon Sep 17 00:00:00 2001 From: Andreas Shimokawa Date: Sat, 31 Mar 2018 16:21:25 +0200 Subject: [PATCH] refactor onFetchActivityData() into onFetchRecordedData(dataTypes) to make it more generic This removes misuse of testNewFunctionality() and support fetching GPS data and debug logs Fetching debug logs (Amazfit Bip/Cor) is now accessible in the debug activity Fetching GPS data can be done by swiping in the list activity. TODO: actually refresh list when fetching data is done :P Also fix some android studio warnings on the go... --- .../activities/AbstractListActivity.java | 16 +---- .../activities/ActivitySummariesActivity.java | 30 +++++++++ .../activities/ControlCenterv2.java | 32 +++++---- .../activities/DebugActivity.java | 65 +++++++++---------- .../activities/charts/ChartsActivity.java | 31 ++++----- .../adapter/GBDeviceAdapterv2.java | 65 ++++++++++--------- .../gadgetbridge/devices/EventHandler.java | 2 +- .../gadgetbridge/impl/GBDeviceService.java | 5 +- .../gadgetbridge/model/DeviceService.java | 4 +- .../gadgetbridge/model/RecordedDataTypes.java | 28 ++++++++ .../service/DeviceCommunicationService.java | 8 ++- .../service/ServiceDeviceSupport.java | 4 +- .../devices/amazfitbip/AmazfitBipSupport.java | 21 ++++-- .../service/devices/hplus/HPlusSupport.java | 2 +- .../devices/jyou/TeclastH30Support.java | 2 +- .../service/devices/miband/MiBandSupport.java | 2 +- .../devices/miband2/MiBand2Support.java | 3 +- .../service/devices/no1f1/No1F1Support.java | 2 +- .../vibratissimo/VibratissimoSupport.java | 2 +- .../service/devices/xwatch/XWatchSupport.java | 34 +++++----- .../serial/AbstractSerialDeviceSupport.java | 2 +- .../freeyourgadget/gadgetbridge/util/GB.java | 2 +- app/src/main/res/layout/activity_debug.xml | 10 ++- app/src/main/res/layout/activity_list.xml | 12 ++-- app/src/main/res/layout/device_itemv2.xml | 30 ++++++--- .../service/TestDeviceSupport.java | 2 +- .../gadgetbridge/test/LoggingTest.java | 7 +- 27 files changed, 242 insertions(+), 181 deletions(-) create mode 100644 app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/RecordedDataTypes.java diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/AbstractListActivity.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/AbstractListActivity.java index bbdd11e2a..8a92de45e 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/AbstractListActivity.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/AbstractListActivity.java @@ -1,24 +1,10 @@ package nodomain.freeyourgadget.gadgetbridge.activities; import android.os.Bundle; -import android.support.v7.widget.Toolbar; import android.widget.ListView; -import android.widget.Toast; -import java.util.ArrayList; -import java.util.List; - -import nodomain.freeyourgadget.gadgetbridge.GBApplication; import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.adapter.AbstractItemAdapter; -import nodomain.freeyourgadget.gadgetbridge.adapter.ItemWithDetailsAdapter; -import nodomain.freeyourgadget.gadgetbridge.database.DBHandler; -import nodomain.freeyourgadget.gadgetbridge.entities.BaseActivitySummary; -import nodomain.freeyourgadget.gadgetbridge.entities.BaseActivitySummaryDao; -import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind; -import nodomain.freeyourgadget.gadgetbridge.model.GenericItem; -import nodomain.freeyourgadget.gadgetbridge.model.ItemWithDetails; -import nodomain.freeyourgadget.gadgetbridge.util.GB; public abstract class AbstractListActivity extends AbstractGBActivity { private AbstractItemAdapter itemAdapter; @@ -46,6 +32,6 @@ public abstract class AbstractListActivity extends AbstractGBActivity { super.onCreate(savedInstanceState); setContentView(R.layout.activity_list); - itemListView = (ListView) findViewById(R.id.itemListView); + itemListView = findViewById(R.id.itemListView); } } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ActivitySummariesActivity.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ActivitySummariesActivity.java index 209544e83..a9a0345c4 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ActivitySummariesActivity.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ActivitySummariesActivity.java @@ -2,6 +2,7 @@ package nodomain.freeyourgadget.gadgetbridge.activities; import android.content.Intent; import android.os.Bundle; +import android.support.v4.widget.SwipeRefreshLayout; import android.view.ContextMenu; import android.view.MenuItem; import android.view.View; @@ -10,9 +11,13 @@ import android.widget.Toast; import java.io.IOException; +import nodomain.freeyourgadget.gadgetbridge.GBApplication; +import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.adapter.ActivitySummariesAdapter; import nodomain.freeyourgadget.gadgetbridge.entities.BaseActivitySummary; +import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice; import nodomain.freeyourgadget.gadgetbridge.model.ActivitySummary; +import nodomain.freeyourgadget.gadgetbridge.model.RecordedDataTypes; import nodomain.freeyourgadget.gadgetbridge.util.AndroidUtils; import nodomain.freeyourgadget.gadgetbridge.util.GB; @@ -20,8 +25,18 @@ public class ActivitySummariesActivity extends AbstractListActivity deviceList; private GBDeviceAdapterv2 mGBDeviceAdapter; private RecyclerView deviceListView; @@ -84,7 +81,7 @@ public class ControlCenterv2 extends AppCompatActivity @Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); - switch (action) { + switch (Objects.requireNonNull(action)) { case GBApplication.ACTION_LANGUAGE_CHANGE: setLanguage(GBApplication.getLanguage(), true); break; @@ -104,10 +101,10 @@ public class ControlCenterv2 extends AppCompatActivity super.onCreate(savedInstanceState); setContentView(R.layout.activity_controlcenterv2); - Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); + Toolbar toolbar = findViewById(R.id.toolbar); setSupportActionBar(toolbar); - FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); + FloatingActionButton fab = findViewById(R.id.fab); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { @@ -115,28 +112,30 @@ public class ControlCenterv2 extends AppCompatActivity } }); - DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); + DrawerLayout drawer = findViewById(R.id.drawer_layout); ActionBarDrawerToggle toggle = new ActionBarDrawerToggle( this, drawer, toolbar, R.string.controlcenter_navigation_drawer_open, R.string.controlcenter_navigation_drawer_close); drawer.setDrawerListener(toggle); toggle.syncState(); - NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view); + NavigationView navigationView = findViewById(R.id.nav_view); navigationView.setNavigationItemSelectedListener(this); //end of material design boilerplate deviceManager = ((GBApplication) getApplication()).getDeviceManager(); - deviceListView = (RecyclerView) findViewById(R.id.deviceListView); + deviceListView = findViewById(R.id.deviceListView); deviceListView.setHasFixedSize(true); deviceListView.setLayoutManager(new LinearLayoutManager(this)); - background = (ImageView) findViewById(R.id.no_items_bg); + background = findViewById(R.id.no_items_bg); - deviceList = deviceManager.getDevices(); + List deviceList = deviceManager.getDevices(); mGBDeviceAdapter = new GBDeviceAdapterv2(this, deviceList); deviceListView.setAdapter(this.mGBDeviceAdapter); + /* uncomment to enable fixed-swipe to reveal more actions + ItemTouchHelper swipeToDismissTouchHelper = new ItemTouchHelper(new ItemTouchHelper.SimpleCallback( ItemTouchHelper.LEFT , ItemTouchHelper.RIGHT) { @Override @@ -167,9 +166,8 @@ public class ControlCenterv2 extends AppCompatActivity } }); - //uncomment to enable fixed-swipe to reveal more actions - //swipeToDismissTouchHelper.attachToRecyclerView(deviceListView); - + swipeToDismissTouchHelper.attachToRecyclerView(deviceListView); + */ registerForContextMenu(deviceListView); @@ -226,7 +224,7 @@ public class ControlCenterv2 extends AppCompatActivity @Override public void onBackPressed() { - DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); + DrawerLayout drawer = findViewById(R.id.drawer_layout); if (drawer.isDrawerOpen(GravityCompat.START)) { drawer.closeDrawer(GravityCompat.START); } else { @@ -237,7 +235,7 @@ public class ControlCenterv2 extends AppCompatActivity @Override public boolean onNavigationItemSelected(@NonNull MenuItem item) { - DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); + DrawerLayout drawer = findViewById(R.id.drawer_layout); drawer.closeDrawer(GravityCompat.START); switch (item.getItemId()) { diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/DebugActivity.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/DebugActivity.java index 33028e9db..3a1d8391b 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/DebugActivity.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/DebugActivity.java @@ -40,16 +40,17 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.util.ArrayList; +import java.util.Objects; import nodomain.freeyourgadget.gadgetbridge.GBApplication; import nodomain.freeyourgadget.gadgetbridge.R; -import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice; import nodomain.freeyourgadget.gadgetbridge.model.CallSpec; import nodomain.freeyourgadget.gadgetbridge.model.DeviceService; import nodomain.freeyourgadget.gadgetbridge.model.MusicSpec; import nodomain.freeyourgadget.gadgetbridge.model.MusicStateSpec; import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec; import nodomain.freeyourgadget.gadgetbridge.model.NotificationType; +import nodomain.freeyourgadget.gadgetbridge.model.RecordedDataTypes; import nodomain.freeyourgadget.gadgetbridge.util.GB; import static nodomain.freeyourgadget.gadgetbridge.util.GB.NOTIFICATION_CHANNEL_ID; @@ -63,23 +64,12 @@ public class DebugActivity extends AbstractGBActivity { = "nodomain.freeyourgadget.gadgetbridge.DebugActivity.action.reply"; private Spinner sendTypeSpinner; - private Button sendButton; - private Button incomingCallButton; - private Button outgoingCallButton; - private Button startCallButton; - private Button endCallButton; - private Button testNotificationButton; - private Button setMusicInfoButton; - private Button setTimeButton; - private Button rebootButton; - private Button HeartRateButton; - private Button testNewFunctionalityButton; private EditText editContent; private final BroadcastReceiver mReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { - switch (intent.getAction()) { + switch (Objects.requireNonNull(intent.getAction())) { case ACTION_REPLY: { Bundle remoteInput = RemoteInput.getResultsFromIntent(intent); CharSequence reply = remoteInput.getCharSequence(EXTRA_REPLY); @@ -87,11 +77,9 @@ public class DebugActivity extends AbstractGBActivity { GB.toast(context, "got wearable reply: " + reply, Toast.LENGTH_SHORT, GB.INFO); break; } - case DeviceService.ACTION_HEARTRATE_MEASUREMENT: { - int hrValue = intent.getIntExtra(DeviceService.EXTRA_HEART_RATE_VALUE, -1); - GB.toast(DebugActivity.this, "Heart Rate measured: " + hrValue, Toast.LENGTH_LONG, GB.INFO); + default: + LOG.info("ignoring intent action " + intent.getAction()); break; - } } } }; @@ -107,17 +95,17 @@ public class DebugActivity extends AbstractGBActivity { LocalBroadcastManager.getInstance(this).registerReceiver(mReceiver, filter); registerReceiver(mReceiver, filter); // for ACTION_REPLY - editContent = (EditText) findViewById(R.id.editContent); + editContent = findViewById(R.id.editContent); ArrayList spinnerArray = new ArrayList<>(); for (NotificationType notificationType : NotificationType.values()) { spinnerArray.add(notificationType.name()); } ArrayAdapter spinnerArrayAdapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_dropdown_item, spinnerArray); - sendTypeSpinner = (Spinner) findViewById(R.id.sendTypeSpinner); + sendTypeSpinner = findViewById(R.id.sendTypeSpinner); sendTypeSpinner.setAdapter(spinnerArrayAdapter); - sendButton = (Button) findViewById(R.id.sendButton); + Button sendButton = findViewById(R.id.sendButton); sendButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { @@ -134,7 +122,7 @@ public class DebugActivity extends AbstractGBActivity { } }); - incomingCallButton = (Button) findViewById(R.id.incomingCallButton); + Button incomingCallButton = findViewById(R.id.incomingCallButton); incomingCallButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { @@ -144,7 +132,7 @@ public class DebugActivity extends AbstractGBActivity { GBApplication.deviceService().onSetCallState(callSpec); } }); - outgoingCallButton = (Button) findViewById(R.id.outgoingCallButton); + Button outgoingCallButton = findViewById(R.id.outgoingCallButton); outgoingCallButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { @@ -155,7 +143,7 @@ public class DebugActivity extends AbstractGBActivity { } }); - startCallButton = (Button) findViewById(R.id.startCallButton); + Button startCallButton = findViewById(R.id.startCallButton); startCallButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { @@ -164,7 +152,7 @@ public class DebugActivity extends AbstractGBActivity { GBApplication.deviceService().onSetCallState(callSpec); } }); - endCallButton = (Button) findViewById(R.id.endCallButton); + Button endCallButton = findViewById(R.id.endCallButton); endCallButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { @@ -174,15 +162,15 @@ public class DebugActivity extends AbstractGBActivity { } }); - rebootButton = (Button) findViewById(R.id.rebootButton); + Button rebootButton = findViewById(R.id.rebootButton); rebootButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { GBApplication.deviceService().onReboot(); } }); - HeartRateButton = (Button) findViewById(R.id.HearRateButton); - HeartRateButton.setOnClickListener(new View.OnClickListener() { + Button heartRateButton = findViewById(R.id.HeartRateButton); + heartRateButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { GB.toast("Measuring heart rate, please wait...", Toast.LENGTH_LONG, GB.INFO); @@ -190,7 +178,7 @@ public class DebugActivity extends AbstractGBActivity { } }); - setMusicInfoButton = (Button) findViewById(R.id.setMusicInfoButton); + Button setMusicInfoButton = findViewById(R.id.setMusicInfoButton); setMusicInfoButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { @@ -216,7 +204,7 @@ public class DebugActivity extends AbstractGBActivity { } }); - setTimeButton = (Button) findViewById(R.id.setTimeButton); + Button setTimeButton = findViewById(R.id.setTimeButton); setTimeButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { @@ -224,7 +212,7 @@ public class DebugActivity extends AbstractGBActivity { } }); - testNotificationButton = (Button) findViewById(R.id.testNotificationButton); + Button testNotificationButton = findViewById(R.id.testNotificationButton); testNotificationButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { @@ -232,7 +220,15 @@ public class DebugActivity extends AbstractGBActivity { } }); - testNewFunctionalityButton = (Button) findViewById(R.id.testNewFunctionality); + Button fetchDebugLogsButton = findViewById(R.id.fetchDebugLogsButton); + fetchDebugLogsButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + GBApplication.deviceService().onFetchRecordedData(RecordedDataTypes.TYPE_DEBUGLOGS); + } + }); + + Button testNewFunctionalityButton = findViewById(R.id.testNewFunctionality); testNewFunctionalityButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { @@ -277,7 +273,9 @@ public class DebugActivity extends AbstractGBActivity { .setContentIntent(pendingIntent) .extend(wearableExtender); - nManager.notify((int) System.currentTimeMillis(), ncomp.build()); + if (nManager != null) { + nManager.notify((int) System.currentTimeMillis(), ncomp.build()); + } } @Override @@ -297,7 +295,4 @@ public class DebugActivity extends AbstractGBActivity { unregisterReceiver(mReceiver); } - public interface DeviceSelectionCallback { - void invoke(GBDevice device); - } } 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 fc6582e9e..778d83303 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 @@ -36,15 +36,12 @@ import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; import android.widget.Button; -import android.widget.LinearLayout; import android.widget.TextView; import android.widget.Toast; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import java.text.SimpleDateFormat; import java.util.Date; +import java.util.Objects; import nodomain.freeyourgadget.gadgetbridge.GBApplication; import nodomain.freeyourgadget.gadgetbridge.R; @@ -52,6 +49,7 @@ import nodomain.freeyourgadget.gadgetbridge.activities.AbstractFragmentPagerAdap import nodomain.freeyourgadget.gadgetbridge.activities.AbstractGBFragmentActivity; import nodomain.freeyourgadget.gadgetbridge.devices.DeviceCoordinator; import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice; +import nodomain.freeyourgadget.gadgetbridge.model.RecordedDataTypes; import nodomain.freeyourgadget.gadgetbridge.util.DateTimeUtils; import nodomain.freeyourgadget.gadgetbridge.util.DeviceHelper; import nodomain.freeyourgadget.gadgetbridge.util.GB; @@ -59,16 +57,11 @@ import nodomain.freeyourgadget.gadgetbridge.util.LimitedQueue; public class ChartsActivity extends AbstractGBFragmentActivity implements ChartsHost { - private static final Logger LOG = LoggerFactory.getLogger(ChartsActivity.class); - - private Button mPrevButton; - private Button mNextButton; private TextView mDateControl; private Date mStartDate; private Date mEndDate; private SwipeRefreshLayout swipeLayout; - private NonSwipeableViewPager viewPager; LimitedQueue mActivityAmountCache = new LimitedQueue(60); @@ -86,7 +79,7 @@ public class ChartsActivity extends AbstractGBFragmentActivity implements Charts super.onCreate(savedInstanceState); setContentView(R.layout.activity_charts_durationdialog); - durationLabel = (TextView) findViewById(R.id.charts_duration_label); + durationLabel = findViewById(R.id.charts_duration_label); setDuration(mDuration); } @@ -103,7 +96,7 @@ public class ChartsActivity extends AbstractGBFragmentActivity implements Charts @Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); - switch (action) { + switch (Objects.requireNonNull(action)) { case GBDevice.ACTION_DEVICE_CHANGED: GBDevice dev = intent.getParcelableExtra(GBDevice.EXTRA_DEVICE); refreshBusyState(dev); @@ -145,7 +138,7 @@ public class ChartsActivity extends AbstractGBFragmentActivity implements Charts throw new IllegalArgumentException("Must provide a device when invoking this activity"); } - swipeLayout = (SwipeRefreshLayout) findViewById(R.id.activity_swipe_layout); + swipeLayout = findViewById(R.id.activity_swipe_layout); swipeLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { @@ -155,7 +148,7 @@ public class ChartsActivity extends AbstractGBFragmentActivity implements Charts enableSwipeRefresh(true); // Set up the ViewPager with the sections adapter. - viewPager = (NonSwipeableViewPager) findViewById(R.id.charts_pager); + NonSwipeableViewPager viewPager = findViewById(R.id.charts_pager); viewPager.setAdapter(getPagerAdapter()); viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Override @@ -172,8 +165,8 @@ public class ChartsActivity extends AbstractGBFragmentActivity implements Charts } }); - dateBar = (ViewGroup) findViewById(R.id.charts_date_bar); - mDateControl = (TextView) findViewById(R.id.charts_text_date); + dateBar = findViewById(R.id.charts_date_bar); + mDateControl = findViewById(R.id.charts_text_date); mDateControl.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { @@ -182,22 +175,20 @@ public class ChartsActivity extends AbstractGBFragmentActivity implements Charts } }); - mPrevButton = (Button) findViewById(R.id.charts_previous); + Button mPrevButton = findViewById(R.id.charts_previous); mPrevButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { handlePrevButtonClicked(); } }); - mNextButton = (Button) findViewById(R.id.charts_next); + Button mNextButton = findViewById(R.id.charts_next); mNextButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { handleNextButtonClicked(); } }); - - LinearLayout mainLayout = (LinearLayout) findViewById(R.id.charts_main_layout); } private String formatDetailedDuration() { @@ -284,7 +275,7 @@ public class ChartsActivity extends AbstractGBFragmentActivity implements Charts private void fetchActivityData() { if (getDevice().isInitialized()) { - GBApplication.deviceService().onFetchActivityData(); + GBApplication.deviceService().onFetchRecordedData(RecordedDataTypes.TYPE_ACTIVITY); } else { swipeLayout.setRefreshing(false); GB.toast(this, getString(R.string.device_not_connected), Toast.LENGTH_SHORT, GB.ERROR); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/adapter/GBDeviceAdapterv2.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/adapter/GBDeviceAdapterv2.java index 84d7ea6f7..12087694e 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/adapter/GBDeviceAdapterv2.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/adapter/GBDeviceAdapterv2.java @@ -22,6 +22,7 @@ import android.app.AlertDialog; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; +import android.support.annotation.NonNull; import android.support.design.widget.Snackbar; import android.support.v4.content.LocalBroadcastManager; import android.support.v7.widget.CardView; @@ -52,6 +53,7 @@ import nodomain.freeyourgadget.gadgetbridge.devices.DeviceManager; import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice; import nodomain.freeyourgadget.gadgetbridge.model.BatteryState; import nodomain.freeyourgadget.gadgetbridge.model.DeviceType; +import nodomain.freeyourgadget.gadgetbridge.model.RecordedDataTypes; import nodomain.freeyourgadget.gadgetbridge.util.DeviceHelper; import nodomain.freeyourgadget.gadgetbridge.util.GB; @@ -70,16 +72,16 @@ public class GBDeviceAdapterv2 extends RecyclerView.Adapter. */ + +package nodomain.freeyourgadget.gadgetbridge.model; + +public class RecordedDataTypes { + public static int TYPE_ACTIVITY = 0x00000001; + public static int TYPE_WORKOUTS = 0x00000002; + public static int TYPE_GPS_TRACKS = 0x00000004; + public static int TYPE_TEMPERATURE = 0x00000008; + public static int TYPE_DEBUGLOGS = 0x00000010; + + public static int TYPE_ALL = (int)0xffffffff; +} diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/DeviceCommunicationService.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/DeviceCommunicationService.java index 5547e291f..b918b2cc4 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/DeviceCommunicationService.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/DeviceCommunicationService.java @@ -86,7 +86,7 @@ import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.ACTION_DI import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.ACTION_ENABLE_HEARTRATE_SLEEP_SUPPORT; import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.ACTION_ENABLE_REALTIME_HEARTRATE_MEASUREMENT; import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.ACTION_ENABLE_REALTIME_STEPS; -import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.ACTION_FETCH_ACTIVITY_DATA; +import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.ACTION_FETCH_RECORDED_DATA; import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.ACTION_FIND_DEVICE; import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.ACTION_HEARTRATE_TEST; import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.ACTION_INSTALL; @@ -127,6 +127,7 @@ import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_CAN import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_CANNEDMESSAGES_TYPE; import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_CONFIG; import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_CONNECT_FIRST_TIME; +import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_RECORDED_DATA_TYPES; import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_FIND_START; import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_INTERVAL_SECONDS; import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_MUSIC_ALBUM; @@ -401,8 +402,9 @@ public class DeviceCommunicationService extends Service implements SharedPrefere mDeviceSupport.onHeartRateTest(); break; } - case ACTION_FETCH_ACTIVITY_DATA: { - mDeviceSupport.onFetchActivityData(); + case ACTION_FETCH_RECORDED_DATA: { + int dataTypes = intent.getIntExtra(EXTRA_RECORDED_DATA_TYPES, 0); + mDeviceSupport.onFetchRecordedData(dataTypes); break; } case ACTION_DISCONNECT: { diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/ServiceDeviceSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/ServiceDeviceSupport.java index 8a8fd2934..4c77c5a01 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/ServiceDeviceSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/ServiceDeviceSupport.java @@ -248,11 +248,11 @@ public class ServiceDeviceSupport implements DeviceSupport { } @Override - public void onFetchActivityData() { + public void onFetchRecordedData(int dataTypes) { if (checkBusy("fetch activity data")) { return; } - delegate.onFetchActivityData(); + delegate.onFetchRecordedData(dataTypes); } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/amazfitbip/AmazfitBipSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/amazfitbip/AmazfitBipSupport.java index 29c3eb31a..a853132a9 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/amazfitbip/AmazfitBipSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/amazfitbip/AmazfitBipSupport.java @@ -37,11 +37,11 @@ import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiWeatherConditions import nodomain.freeyourgadget.gadgetbridge.devices.huami.amazfitbip.AmazfitBipFWHelper; import nodomain.freeyourgadget.gadgetbridge.devices.huami.amazfitbip.AmazfitBipService; import nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBand2Service; -import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice; import nodomain.freeyourgadget.gadgetbridge.model.CallSpec; import nodomain.freeyourgadget.gadgetbridge.model.DeviceType; import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec; import nodomain.freeyourgadget.gadgetbridge.model.NotificationType; +import nodomain.freeyourgadget.gadgetbridge.model.RecordedDataTypes; import nodomain.freeyourgadget.gadgetbridge.model.Weather; import nodomain.freeyourgadget.gadgetbridge.model.WeatherSpec; import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder; @@ -49,9 +49,11 @@ import nodomain.freeyourgadget.gadgetbridge.service.btle.actions.ConditionalWrit import nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.alertnotification.AlertCategory; import nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.alertnotification.AlertNotificationProfile; import nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.alertnotification.NewAlert; +import nodomain.freeyourgadget.gadgetbridge.service.devices.amazfitbip.operations.AmazfitBipFetchLogsOperation; import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.HuamiIcon; import nodomain.freeyourgadget.gadgetbridge.service.devices.miband.NotificationStrategy; import nodomain.freeyourgadget.gadgetbridge.service.devices.miband2.MiBand2Support; +import nodomain.freeyourgadget.gadgetbridge.service.devices.miband2.operations.FetchActivityOperation; import nodomain.freeyourgadget.gadgetbridge.service.devices.miband2.operations.FetchSportsSummaryOperation; import nodomain.freeyourgadget.gadgetbridge.util.StringUtils; import nodomain.freeyourgadget.gadgetbridge.util.Version; @@ -283,12 +285,21 @@ public class AmazfitBipSupport extends MiBand2Support { } @Override - public void onTestNewFunction() { + public void onFetchRecordedData(int dataTypes) { try { -// new AmazfitBipFetchLogsOperation(this).perform(); - new FetchSportsSummaryOperation(this).perform(); + // FIXME: currently only one data type supported, these are meant to be flags + if (dataTypes == RecordedDataTypes.TYPE_ACTIVITY) { + new FetchActivityOperation(this).perform(); + } else if (dataTypes == RecordedDataTypes.TYPE_GPS_TRACKS) { + new FetchSportsSummaryOperation(this).perform(); + } else if (dataTypes == RecordedDataTypes.TYPE_DEBUGLOGS) { + new AmazfitBipFetchLogsOperation(this).perform(); + } + else { + LOG.warn("fetching multiple data types at once is not supported yet"); + } } catch (IOException ex) { - LOG.error("Unable to fetch logs", ex); + LOG.error("Unable to fetch recorded data types" + dataTypes, ex); } } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/hplus/HPlusSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/hplus/HPlusSupport.java index 7dacb2104..183370895 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/hplus/HPlusSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/hplus/HPlusSupport.java @@ -539,7 +539,7 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport { } @Override - public void onFetchActivityData() { + public void onFetchRecordedData(int dataTypes) { if (syncHelper == null){ syncHelper = new HPlusHandlerThread(gbDevice, getContext(), this); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/jyou/TeclastH30Support.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/jyou/TeclastH30Support.java index 59d356a96..9e9bf4358 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/jyou/TeclastH30Support.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/jyou/TeclastH30Support.java @@ -362,7 +362,7 @@ public class TeclastH30Support extends AbstractBTLEDeviceSupport { } @Override - public void onFetchActivityData() { + public void onFetchRecordedData(int dataTypes) { } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/MiBandSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/MiBandSupport.java index 6ed15eed6..8d07ed35b 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/MiBandSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/MiBandSupport.java @@ -761,7 +761,7 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport { } @Override - public void onFetchActivityData() { + public void onFetchRecordedData(int dataTypes) { try { new FetchActivityOperation(this).perform(); } catch (IOException ex) { diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband2/MiBand2Support.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband2/MiBand2Support.java index 735924f2f..a6d236d44 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband2/MiBand2Support.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband2/MiBand2Support.java @@ -40,7 +40,6 @@ import java.util.Date; import java.util.GregorianCalendar; import java.util.List; import java.util.Set; -import java.util.TimeZone; import java.util.Timer; import java.util.TimerTask; import java.util.UUID; @@ -804,7 +803,7 @@ public class MiBand2Support extends AbstractBTLEDeviceSupport { } @Override - public void onFetchActivityData() { + public void onFetchRecordedData(int dataTypes) { try { new FetchActivityOperation(this).perform(); } catch (IOException ex) { diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/no1f1/No1F1Support.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/no1f1/No1F1Support.java index 1df30c4f9..393ff82ff 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/no1f1/No1F1Support.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/no1f1/No1F1Support.java @@ -299,7 +299,7 @@ public class No1F1Support extends AbstractBTLEDeviceSupport { } @Override - public void onFetchActivityData() { + public void onFetchRecordedData(int dataTypes) { sendFetchCommand(No1F1Constants.CMD_FETCH_STEPS); } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vibratissimo/VibratissimoSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vibratissimo/VibratissimoSupport.java index 70e1f8521..caebf7a1d 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vibratissimo/VibratissimoSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vibratissimo/VibratissimoSupport.java @@ -206,7 +206,7 @@ public class VibratissimoSupport extends AbstractBTLEDeviceSupport { } @Override - public void onFetchActivityData() { + public void onFetchRecordedData(int dataTypes) { } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/xwatch/XWatchSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/xwatch/XWatchSupport.java index f7b351dd0..bc458d3ff 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/xwatch/XWatchSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/xwatch/XWatchSupport.java @@ -1,19 +1,19 @@ -/* Copyright (C) 2018 ladbsoft - - This file is part of Gadgetbridge. - - Gadgetbridge is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published - by the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - Gadgetbridge is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . */ +/* Copyright (C) 2018 ladbsoft + + This file is part of Gadgetbridge. + + Gadgetbridge is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Gadgetbridge is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . */ package nodomain.freeyourgadget.gadgetbridge.service.devices.xwatch; import android.bluetooth.BluetoothGatt; @@ -258,7 +258,7 @@ public class XWatchSupport extends AbstractBTLEDeviceSupport { } @Override - public void onFetchActivityData() { + public void onFetchRecordedData(int dataTypes) { try { if(builder == null) { builder = performInitialized("fetchActivityData"); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/serial/AbstractSerialDeviceSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/serial/AbstractSerialDeviceSupport.java index 35342a371..e73527eab 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/serial/AbstractSerialDeviceSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/serial/AbstractSerialDeviceSupport.java @@ -180,7 +180,7 @@ public abstract class AbstractSerialDeviceSupport extends AbstractDeviceSupport } @Override - public void onFetchActivityData() { + public void onFetchRecordedData(int dataTypes) { byte[] bytes = gbDeviceProtocol.encodeSynchronizeActivityData(); sendToDevice(bytes); } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/GB.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/GB.java index 2c4c8fd6a..3643549a7 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/GB.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/GB.java @@ -102,7 +102,7 @@ public class GB { PendingIntent disconnectPendingIntent = PendingIntent.getService(context, 0, deviceCommunicationServiceIntent, PendingIntent.FLAG_ONE_SHOT); builder.addAction(R.drawable.ic_notification_disconnected, context.getString(R.string.controlcenter_disconnect), disconnectPendingIntent); if (GBApplication.isRunningLollipopOrLater() && DeviceHelper.getInstance().getCoordinator(device).supportsActivityDataFetching()) { //for some reason this fails on KK - deviceCommunicationServiceIntent.setAction(DeviceService.ACTION_FETCH_ACTIVITY_DATA); + deviceCommunicationServiceIntent.setAction(DeviceService.ACTION_FETCH_RECORDED_DATA); PendingIntent fetchPendingIntent = PendingIntent.getService(context, 1, deviceCommunicationServiceIntent, PendingIntent.FLAG_ONE_SHOT); builder.addAction(R.drawable.ic_action_fetch_activity_data, context.getString(R.string.controlcenter_fetch_activity_data), fetchPendingIntent); } diff --git a/app/src/main/res/layout/activity_debug.xml b/app/src/main/res/layout/activity_debug.xml index 0a8a7e76d..32aa9a386 100644 --- a/app/src/main/res/layout/activity_debug.xml +++ b/app/src/main/res/layout/activity_debug.xml @@ -102,7 +102,7 @@ android:text="set music info" />