0
私はすべてのデータを挿入してグラフに表示していますが、greendaoの過去7日間のグラフのみを表示する方法はありますか?例えばのためにgreendao androidに7日間の記録を表示するにはどうすればいいですか?
:
- 私は今日のデータを挿入するために起動した場合。今日の日付のみが表示されます(例:22/07など)
- 翌日にデータが挿入されます。 (22/07、23/07を表示する必要があります)
- 私の現在の日付が30/07の場合、私は(23/07,24/07/25/07から30/07まで)表示する必要があります他のデータ、すなわち22/07。
私はすべてのデータを取得していますが、私の場合は表示されています。つまり22/07〜30/07です。古いものを削除して7日間のみ表示する方法。 この問題を解決するのを手伝ってください。
ここはすべてのデータを表示している私のコードです。 DetectiveGraphExcecutorで
:
public List<DetectiveGraph> getDetectionsGraphBetweenTime(Date fromDateAndTime, Date toTimeAndDate) {
List<DetectiveGraph> mTask = mDetectiveGraphDao.queryBuilder().where(DetectiveGraphDao.Properties.Detective_date.between(fromDateAndTime, toTimeAndDate)).list();
closeSession();
return mTask;
}
public List<DetectiveGraph> getAllDetections() { //getting all datas
return mDetectiveGraphDao.queryBuilder().orderAsc(DetectiveGraphDao.Properties.Detective_date).list();
}
public class ActivityTracking extends Activity{
private DetectiveGraphExecutor mDetectiveGraphExecutor;
private List<DetectiveGraph> mDetectiveGraphList;
private int columnIndex;
private List<DetectiveGraph> activities; //The activities.
@Override
protected void onCreate(Bundle savedInstanceState) { //onCreate
super.onCreate(savedInstanceState); //super
setContentView(R.layout.activity_tracking);
mDetectiveGraphList = mDetectiveGraphExecutor.getAllDetections();
maxDate = mDetectiveGraphList.get(mDetectiveGraphList.size()-1).getDetectiveDate();
toDates = maxDate; // maximumDate
Calendar toDateCalendar = Calendar.getInstance(); //toDateCalendar
toDateCalendar.setTime(toDates); //toDateCalendar
Calendar fromDateCalendar = (Calendar) toDateCalendar.clone();
fromDateCalendar.add(Calendar.DATE, -7); //fromDateCalendar
fromDateCalendar.add(Calendar.MINUTE, -fromDateCalendar.get(Calendar.MINUTE)); //minute
fromDateCalendar.set(Calendar.SECOND, 0); //second
Long initialLogTime = Long.valueOf(VALRTApplication.getPrefString(ActivityTracking.this, "epochTime"));
Calendar calendar = Calendar.getInstance(); //calendar
calendar.setTimeInMillis(initialLogTime); //setTime
calendar.add(Calendar.MINUTE, -calendar.get(Calendar.MINUTE)); //minute
calendar.set(Calendar.SECOND, 0); //second
Calendar fromDateTime = calendar; //fromDate
columnIndex = -1; //columnIndex
do {
Date fromDate = null, toDate = null; //fromDate
Calendar toDateTime = (Calendar) fromDateTime.clone(); //toDate
toDateTime.add(Calendar.MINUTE, 60); //toDateTime
SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MMM-yyyy hh:mm:ss:aa"); //dateFormat
dateString = dateFormat.format(fromDateTime.getTime()); //dateString
dateString1 = dateFormat.format(toDateTime.getTime()); //dateString1
try {
fromDate = dateFormat.parse(dateString); //dateString
toDate = dateFormat.parse(dateString1);//toDate
} catch (ParseException e) {
LogUtils.e(VALRTApplication.TAG, e); //exceptional handling
}
if (fromDate != null && toDate != null) { //fromDate and to date not null
updateGraph(fromDate, toDate, entries, labels);
}
textName.setText(iAddedDate); //setText
fromDateTime.add(Calendar.HOUR, 1); //add
}
while (Calendar.getInstance().getTimeInMillis() >= fromDateTime.getTimeInMillis()); //getTime
}
//in this I am updating graph based on the date and updating in UI.
private void updateGraph(Date fromDate, Date toDate, List<BarEntry> entries, ArrayList<String> labels) {
activities = mDetectiveGraphExecutor.getDetectionsGraphBetweenTime(fromDate, toDate); //getDetectionGraph
SimpleDateFormat dateFormats = new SimpleDateFormat("h:aa"); //hour and am/pm
SimpleDateFormat withDateTimes = new SimpleDateFormat("MM/dd/yyyy"); //withDateTimes
iAddedDate = withDateTimes.format(toDate.getTime()); //getTime
String newDate = iAddedDate.substring(0, iAddedDate.length() - 5); //newDate
String dateToTimes = dateFormats.format(toDate.getTime()); //getTime
String replaceTime = dateToTimes.replaceAll(":", " ").toUpperCase(); //toUpperCase
String outputDates = "\n" + newDate + "\n" + replaceTime; //replaceTime
entries.add(new BarEntry(activities.size(), ++columnIndex)); //columnIndex
labels.add(outputDates); //outputDates
BarDataSet dataset = new BarDataSet(entries, ""); //dataset
BarData data = new BarData(labels, dataset); //data
data.setDrawValues(false); //setDrawValues
barChart.setData(data); //setData
}