More WIP: sync from the charts activity

Also add preliminary buttons to go forward/backward in time.
master
cpfeiffer 2015-07-21 00:06:20 +02:00
parent 13d2c2166c
commit 0f6491a11d
4 changed files with 130 additions and 6 deletions

View File

@ -108,6 +108,7 @@ public class ControlCenter extends Activity {
Class<? extends Activity> primaryActivity = coordinator.getPrimaryActivity();
if (primaryActivity != null) {
Intent startIntent = new Intent(ControlCenter.this, primaryActivity);
startIntent.putExtra(GBDevice.EXTRA_DEVICE, gbDevice);
startActivity(startIntent);
}
} else {

View File

@ -1,25 +1,40 @@
package nodomain.freeyourgadget.gadgetbridge.activities;
import android.bluetooth.BluetoothDevice;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.content.LocalBroadcastManager;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ProgressBar;
import android.widget.TextView;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Locale;
import nodomain.freeyourgadget.gadgetbridge.BluetoothCommunicationService;
import nodomain.freeyourgadget.gadgetbridge.ControlCenter;
import nodomain.freeyourgadget.gadgetbridge.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.R;
public class ChartsActivity extends FragmentActivity {
private static final Logger LOG = LoggerFactory.getLogger(ChartsActivity.class);
/**
* The {@link android.support.v4.view.PagerAdapter} that will provide
* fragments for each of the sections. We use a
@ -28,18 +43,56 @@ public class ChartsActivity extends FragmentActivity {
* may be best to switch to a
* {@link android.support.v4.app.FragmentStatePagerAdapter}.
*/
SectionsPagerAdapter mSectionsPagerAdapter;
private SectionsPagerAdapter mSectionsPagerAdapter;
/**
* The {@link ViewPager} that will host the section contents.
*/
ViewPager mViewPager;
private ViewPager mViewPager;
private BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
switch (action) {
case ControlCenter.ACTION_QUIT:
finish();
break;
case ControlCenter.ACTION_REFRESH_DEVICELIST:
break;
case GBDevice.ACTION_DEVICE_CHANGED:
GBDevice dev = intent.getParcelableExtra(GBDevice.EXTRA_DEVICE);
refreshBusyState(dev);
break;
}
}
};
private ProgressBar mProgressBar;
private void refreshBusyState(GBDevice dev) {
if (dev.isBusy()) {
mProgressBar.setVisibility(View.VISIBLE);
} else {
boolean wasBusy = mProgressBar.getVisibility() != View.GONE;
if (wasBusy) {
mProgressBar.setVisibility(View.GONE);
// TODO: refresh current fragment
LocalBroadcastManager.getInstance(this).sendBroadcast(new Intent(AbstractChartFragment.ACTION_REFRESH));
}
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_charts);
IntentFilter filterLocal = new IntentFilter();
filterLocal.addAction(ControlCenter.ACTION_QUIT);
filterLocal.addAction(ControlCenter.ACTION_REFRESH_DEVICELIST);
filterLocal.addAction(GBDevice.ACTION_DEVICE_CHANGED);
LocalBroadcastManager.getInstance(this).registerReceiver(mReceiver, filterLocal);
// Create the adapter that will return a fragment for each of the three
// primary sections of the activity.
@ -49,6 +102,35 @@ public class ChartsActivity extends FragmentActivity {
mViewPager = (ViewPager) findViewById(R.id.pager);
mViewPager.setAdapter(mSectionsPagerAdapter);
mProgressBar = (ProgressBar) findViewById(R.id.charts_progress);
}
@Override
protected void onDestroy() {
LocalBroadcastManager.getInstance(this).unregisterReceiver(mReceiver);
super.onDestroy();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
getMenuInflater().inflate(R.menu.menu_charts, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.charts_fetch_activity_data:
Intent startIntent = new Intent(this, BluetoothCommunicationService.class);
startIntent.setAction(BluetoothCommunicationService.ACTION_FETCH_ACTIVITY_DATA);
startService(startIntent);
return true;
default:
break;
}
return super.onOptionsItemSelected(item);
}
/**

View File

@ -1,4 +1,40 @@
<android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:id="@+id/pager"
android:layout_width="match_parent" android:layout_height="match_parent"
tools:context="nodomain.freeyourgadget.gadgetbridge.activities.ChartsActivity" />
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent"
android:paddingLeft="0px"
android:paddingRight="0px"
android:paddingTop="0px"
android:paddingBottom="0px"
tools:context="nodomain.freeyourgadget.gadgetbridge.activities.ChartsActivity">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="@+id/charts_previous"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="&lt;" />
<Button
android:id="@+id/charts_next"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=">" />
<ProgressBar
android:id="@+id/charts_progress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:indeterminate="true"
android:visibility="gone"
/>
</LinearLayout>
<android.support.v4.view.ViewPager android:id="@+id/pager"
android:layout_width="match_parent" android:layout_height="match_parent"
tools:context="nodomain.freeyourgadget.gadgetbridge.activities.ChartsActivity" />
</LinearLayout>

View File

@ -4,4 +4,9 @@
tools:context="nodomain.freeyourgadget.gadgetbridge.activities.ChartsActivity">
<item android:id="@+id/action_settings" android:title="@string/action_settings"
android:orderInCategory="100" app:showAsAction="never" />
<item
android:id="@+id/charts_fetch_activity_data"
android:title="@string/controlcenter_fetch_activity_data"/>
</menu>