1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-06-23 13:30:48 +02:00

finally fix build with SDK 23

This commit is contained in:
Andreas Shimokawa 2015-08-29 11:31:48 +02:00
parent 15fc5a02ae
commit 13300fcb5d
4 changed files with 22 additions and 21 deletions

View File

@ -1,7 +1,7 @@
package nodomain.freeyourgadget.gadgetbridge.activities; package nodomain.freeyourgadget.gadgetbridge.activities;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.support.annotation.Nullable;
import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentActivity;
/** /**
@ -41,7 +41,7 @@ public abstract class AbstractGBFragment extends Fragment {
} }
protected void updateActivityTitle() { protected void updateActivityTitle() {
FragmentActivity activity = getActivity(); FragmentActivity activity = (FragmentActivity) getActivity();
if (activity != null && !activity.isFinishing() && !activity.isDestroyed()) { if (activity != null && !activity.isFinishing() && !activity.isDestroyed()) {
if (getTitle() != null) { if (getTitle() != null) {
activity.setTitle(getTitle()); activity.setTitle(getTitle());

View File

@ -49,7 +49,7 @@ import nodomain.freeyourgadget.gadgetbridge.util.DeviceHelper;
* and add the samples to the chart. The actual rendering, which must be performed in the UI * and add the samples to the chart. The actual rendering, which must be performed in the UI
* thread, must be done in #renderCharts(). * thread, must be done in #renderCharts().
* Access functionality of the hosting activity with #getHost() * Access functionality of the hosting activity with #getHost()
* * <p/>
* The hosting ChartsHost activity provides a section for displaying a date or date range * The hosting ChartsHost activity provides a section for displaying a date or date range
* being the basis for the chart, as well as two buttons for moving backwards and forward * being the basis for the chart, as well as two buttons for moving backwards and forward
* in time. The date is held by the activity, so that it can be shared by multiple chart * in time. The date is held by the activity, so that it can be shared by multiple chart
@ -145,19 +145,19 @@ public abstract class AbstractChartFragment extends AbstractGBFragment {
} }
private void setStartDate(Date date) { private void setStartDate(Date date) {
getHost().setStartDate(date); ((ChartsHost) getHost()).setStartDate(date);
} }
private void setEndDate(Date date) { private void setEndDate(Date date) {
getHost().setEndDate(date); ((ChartsHost) getHost()).setEndDate(date);
} }
public Date getStartDate() { public Date getStartDate() {
return getHost().getStartDate(); return ((ChartsHost) getHost()).getStartDate();
} }
public Date getEndDate() { public Date getEndDate() {
return getHost().getEndDate(); return ((ChartsHost) getHost()).getEndDate();
} }
/** /**
@ -194,6 +194,7 @@ public abstract class AbstractChartFragment extends AbstractGBFragment {
/** /**
* Default implementation shifts the dates by one day, if visible * Default implementation shifts the dates by one day, if visible
* and calls #refreshIfVisible(). * and calls #refreshIfVisible().
*
* @param startDate * @param startDate
* @param endDate * @param endDate
*/ */
@ -209,6 +210,7 @@ public abstract class AbstractChartFragment extends AbstractGBFragment {
/** /**
* Default implementation shifts the dates by one day, if visible * Default implementation shifts the dates by one day, if visible
* and calls #refreshIfVisible(). * and calls #refreshIfVisible().
*
* @param startDate * @param startDate
* @param endDate * @param endDate
*/ */
@ -231,9 +233,10 @@ public abstract class AbstractChartFragment extends AbstractGBFragment {
/** /**
* Shifts the given dates by offset days. offset may be positive or negative. * Shifts the given dates by offset days. offset may be positive or negative.
*
* @param startDate * @param startDate
* @param endDate * @param endDate
* @param offset a positive or negative number of days to shift the dates * @param offset a positive or negative number of days to shift the dates
* @return true if the shift was successful and false otherwise * @return true if the shift was successful and false otherwise
*/ */
protected boolean shiftDates(Date startDate, Date endDate, int offset) { protected boolean shiftDates(Date startDate, Date endDate, int offset) {
@ -263,6 +266,7 @@ public abstract class AbstractChartFragment extends AbstractGBFragment {
/** /**
* Returns all kinds of samples for the given device. * Returns all kinds of samples for the given device.
* To be called from a background thread. * To be called from a background thread.
*
* @param device * @param device
* @param tsFrom * @param tsFrom
* @param tsTo * @param tsTo
@ -339,7 +343,7 @@ public abstract class AbstractChartFragment extends AbstractGBFragment {
* #renderCharts * #renderCharts
*/ */
protected void refresh() { protected void refresh() {
if (getHost().getDevice() != null) { if (((ChartsHost) getHost()).getDevice() != null) {
mChartDirty = false; mChartDirty = false;
updateDateInfo(getStartDate(), getEndDate()); updateDateInfo(getStartDate(), getEndDate());
createRefreshTask("Visualizing data", getActivity()).execute(); createRefreshTask("Visualizing data", getActivity()).execute();
@ -474,6 +478,7 @@ public abstract class AbstractChartFragment extends AbstractGBFragment {
/** /**
* Implement this to supply the samples to be displayed. * Implement this to supply the samples to be displayed.
*
* @param db * @param db
* @param device * @param device
* @param tsFrom * @param tsFrom
@ -550,13 +555,13 @@ public abstract class AbstractChartFragment extends AbstractGBFragment {
@Override @Override
protected void doInBackground(DBHandler db) { protected void doInBackground(DBHandler db) {
refreshInBackground(db, getHost().getDevice()); refreshInBackground(db, ((ChartsHost) getHost()).getDevice());
} }
@Override @Override
protected void onPostExecute(Object o) { protected void onPostExecute(Object o) {
super.onPostExecute(o); super.onPostExecute(o);
FragmentActivity activity = getActivity(); FragmentActivity activity = (FragmentActivity) getActivity();
if (activity != null && !activity.isFinishing() && !activity.isDestroyed()) { if (activity != null && !activity.isFinishing() && !activity.isDestroyed()) {
renderCharts(); renderCharts();
} else { } else {
@ -568,12 +573,13 @@ public abstract class AbstractChartFragment extends AbstractGBFragment {
/** /**
* Returns true if the date was successfully shifted, and false if the shift * Returns true if the date was successfully shifted, and false if the shift
* was ignored, e.g. when the to-value is in the future. * was ignored, e.g. when the to-value is in the future.
*
* @param from * @param from
* @param to * @param to
*/ */
public boolean setDateRange(Date from, Date to) { public boolean setDateRange(Date from, Date to) {
if (from.compareTo(to) > 0) { if (from.compareTo(to) > 0) {
throw new IllegalArgumentException("Bad date range: " +from + ".." + to); throw new IllegalArgumentException("Bad date range: " + from + ".." + to);
} }
Date now = new Date(); Date now = new Date();
if (to.after(now)) { if (to.after(now)) {
@ -586,9 +592,9 @@ public abstract class AbstractChartFragment extends AbstractGBFragment {
protected void updateDateInfo(Date from, Date to) { protected void updateDateInfo(Date from, Date to) {
if (from.equals(to)) { if (from.equals(to)) {
getHost().setDateInfo(DateTimeUtils.formatDate(from)); ((ChartsHost) getHost()).setDateInfo(DateTimeUtils.formatDate(from));
} else { } else {
getHost().setDateInfo(DateTimeUtils.formatDateRange(from, to)); ((ChartsHost) getHost()).setDateInfo(DateTimeUtils.formatDateRange(from, to));
} }
} }
@ -607,8 +613,4 @@ public abstract class AbstractChartFragment extends AbstractGBFragment {
private int toTimestamp(Date date) { private int toTimestamp(Date date) {
return (int) ((date.getTime() / 1000) & 0xffffffff); return (int) ((date.getTime() / 1000) & 0xffffffff);
} }
protected ChartsHost getHost() {
return (ChartsHost) getActivity();
}
} }

View File

@ -9,7 +9,6 @@ import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter; import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.content.LocalBroadcastManager; import android.support.v4.content.LocalBroadcastManager;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager; import android.support.v4.view.ViewPager;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;

View File

@ -126,8 +126,8 @@ public class WeekStepsChartFragment extends AbstractChartFragment {
View rootView = inflater.inflate(R.layout.fragment_sleepchart, container, false); View rootView = inflater.inflate(R.layout.fragment_sleepchart, container, false);
GBDevice device = getHost().getDevice(); GBDevice device = ((ChartsHost) getHost()).getDevice();
if(device != null) { if (device != null) {
mTargetSteps = MiBandCoordinator.getFitnessGoal(device.getAddress()); mTargetSteps = MiBandCoordinator.getFitnessGoal(device.getAddress());
} }