in Android/app/src/main/java/com/harvard/studyappmodule/ChartActivity.java [797:1192]
public void addTimeLayout(
String time,
String charttype,
final LineChart chart,
final RealmResults<StepRecordCustom> stepRecordCustomList,
final List<String> filteredXValues,
final List<Entry> entryList,
final RealmResults<ActivityRun> activityRuns,
int position,
final String barColor,
final String activityId) {
linearLayout1 = new LinearLayout(ChartActivity.this);
linearLayout1.setGravity(Gravity.CENTER);
linearLayout1.setLayoutParams(layoutParams);
final TextView textView1 = new TextView(ChartActivity.this);
LinearLayout.LayoutParams layoutParams1 =
new LinearLayout.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
layoutParams1.gravity = Gravity.CENTER_HORIZONTAL;
layoutParams1.setMargins(50, 10, 50, 10);
textView1.setLayoutParams(layoutParams1);
textView1.setPadding(10, 10, 10, 10);
textView1.setTextColor(Color.BLACK);
textView1.setGravity(View.TEXT_ALIGNMENT_CENTER);
if (time.equalsIgnoreCase(DAY)) {
setDay(textView1);
} else if (time.equalsIgnoreCase(WEEK)) {
setWeek(textView1);
} else if (time.equalsIgnoreCase(MONTH)) {
setMonth(textView1);
} else {
setYear(textView1);
}
textView1.setTag(charttype);
textView1.setTag(R.string.charttag, activityId);
final ImageView rightArrow = new ImageView(ChartActivity.this);
rightArrow.setImageResource(R.drawable.arrow2_right);
rightArrow.setPadding(10, 10, 10, 10);
rightArrow.setTag(position);
final ImageView leftArrow = new ImageView(ChartActivity.this);
leftArrow.setTag(position);
leftArrow.setImageResource(R.drawable.arrow2_left);
leftArrow.setPadding(10, 10, 10, 10);
if (dashboardData.getDashboard().getCharts().get(position).isScrollable()) {
rightArrow.setVisibility(View.VISIBLE);
leftArrow.setVisibility(View.VISIBLE);
} else {
rightArrow.setVisibility(View.GONE);
leftArrow.setVisibility(View.GONE);
}
leftArrow.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View view) {
Bundle eventProperties = new Bundle();
eventProperties.putString(
CustomFirebaseAnalytics.Param.BUTTON_CLICK_REASON,
getString(R.string.chart_actvity_left_arrow));
analyticsInstance.logEvent(
CustomFirebaseAnalytics.Event.ADD_BUTTON_CLICK, eventProperties);
if (dateTypeArray.get((int) leftArrow.getTag()).equalsIgnoreCase(DAY)) {
try {
SimpleDateFormat simpleDateFormat = AppController.getDateFormatForApi();
Date selectedStartDAte =
simpleDateFormat.parse(fromDayVals.get((int) leftArrow.getTag()));
Date selectedEndDate =
simpleDateFormat.parse(toDayVals.get((int) leftArrow.getTag()));
Calendar calendarStart = Calendar.getInstance();
calendarStart.setTime(selectedStartDAte);
calendarStart.add(Calendar.DATE, -1);
Calendar calendarEnd = Calendar.getInstance();
calendarEnd.setTime(selectedEndDate);
calendarEnd.add(Calendar.DATE, -1);
fromDayVals.set(
(int) leftArrow.getTag(), simpleDateFormat.format(calendarStart.getTime()));
toDayVals.set(
(int) leftArrow.getTag(), simpleDateFormat.format(calendarEnd.getTime()));
SimpleDateFormat dateFormatForDashboardAndChartCurrentDayOut =
AppController.getDateFormatForDashboardAndChartCurrentDayOut();
textView1.setText(
dateFormatForDashboardAndChartCurrentDayOut.format(calendarStart.getTime()));
refreshchartdata(
"" + textView1.getTag(),
calendarStart.getTime(),
calendarEnd.getTime(),
chart,
stepRecordCustomList,
filteredXValues,
entryList,
activityRuns,
barColor,
"" + textView1.getTag(R.string.charttag));
} catch (ParseException e) {
Logger.log(e);
}
} else if (dateTypeArray.get((int) leftArrow.getTag()).equalsIgnoreCase(WEEK)) {
try {
SimpleDateFormat dateFormatForApi = AppController.getDateFormatForApi();
Date selectedStartDAte =
dateFormatForApi.parse(fromDayVals.get((int) leftArrow.getTag()));
Date selectedEndDate =
dateFormatForApi.parse(toDayVals.get((int) leftArrow.getTag()));
Calendar calendarStart = Calendar.getInstance();
calendarStart.setTime(selectedStartDAte);
calendarStart.add(Calendar.DATE, -7);
Calendar calendarEnd = Calendar.getInstance();
calendarEnd.setTime(selectedEndDate);
calendarEnd.add(Calendar.DATE, -7);
fromDayVals.set(
(int) leftArrow.getTag(), dateFormatForApi.format(calendarStart.getTime()));
toDayVals.set(
(int) leftArrow.getTag(), dateFormatForApi.format(calendarEnd.getTime()));
SimpleDateFormat simpleDateFormat =
AppController.getDateFormatForDashboardAndChartCurrentDayOut();
textView1.setText(
simpleDateFormat.format(calendarStart.getTime())
+ " - "
+ simpleDateFormat.format(calendarEnd.getTime()));
refreshchartdata(
"" + textView1.getTag(),
calendarStart.getTime(),
calendarEnd.getTime(),
chart,
stepRecordCustomList,
filteredXValues,
entryList,
activityRuns,
barColor,
"" + textView1.getTag(R.string.charttag));
} catch (ParseException e) {
Logger.log(e);
}
} else if (dateTypeArray.get((int) leftArrow.getTag()).equalsIgnoreCase(MONTH)) {
try {
SimpleDateFormat dateFormatForApi = AppController.getDateFormatForApi();
Date selectedStartDAte =
dateFormatForApi.parse(fromDayVals.get((int) leftArrow.getTag()));
Date selectedEndDate =
dateFormatForApi.parse(toDayVals.get((int) leftArrow.getTag()));
Calendar calendarStart = Calendar.getInstance();
calendarStart.setTime(selectedStartDAte);
calendarStart.add(Calendar.MONTH, -1);
Calendar calendarEnd = Calendar.getInstance();
calendarEnd.setTime(selectedEndDate);
calendarEnd.add(Calendar.MONTH, -1);
fromDayVals.set(
(int) leftArrow.getTag(), dateFormatForApi.format(calendarStart.getTime()));
toDayVals.set(
(int) leftArrow.getTag(), dateFormatForApi.format(calendarEnd.getTime()));
SimpleDateFormat dateFormatForChartAndStat =
AppController.getDateFormatForChartAndStat();
textView1.setText(dateFormatForChartAndStat.format(calendarStart.getTime()));
refreshchartdata(
"" + textView1.getTag(),
calendarStart.getTime(),
calendarEnd.getTime(),
chart,
stepRecordCustomList,
filteredXValues,
entryList,
activityRuns,
barColor,
"" + textView1.getTag(R.string.charttag));
} catch (ParseException e) {
Logger.log(e);
}
} else if (dateTypeArray.get((int) leftArrow.getTag()).equalsIgnoreCase(YEAR)) {
try {
SimpleDateFormat dateFormatForApi = AppController.getDateFormatForApi();
Date selectedStartDAte =
dateFormatForApi.parse(fromDayVals.get((int) leftArrow.getTag()));
Date selectedEndDate =
dateFormatForApi.parse(toDayVals.get((int) leftArrow.getTag()));
Calendar calendarStart = Calendar.getInstance();
calendarStart.setTime(selectedStartDAte);
calendarStart.add(Calendar.YEAR, -1);
Calendar calendarEnd = Calendar.getInstance();
calendarEnd.setTime(selectedEndDate);
calendarEnd.add(Calendar.YEAR, -1);
fromDayVals.set(
(int) leftArrow.getTag(), dateFormatForApi.format(calendarStart.getTime()));
toDayVals.set(
(int) leftArrow.getTag(), dateFormatForApi.format(calendarEnd.getTime()));
SimpleDateFormat simpleDateFormat = AppController.getDateFormatYearFormat();
textView1.setText(simpleDateFormat.format(calendarStart.getTime()));
refreshchartdata(
"" + textView1.getTag(),
calendarStart.getTime(),
calendarEnd.getTime(),
chart,
stepRecordCustomList,
filteredXValues,
entryList,
activityRuns,
barColor,
"" + textView1.getTag(R.string.charttag));
} catch (ParseException e) {
Logger.log(e);
}
}
}
});
rightArrow.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View view) {
Bundle eventProperties = new Bundle();
eventProperties.putString(
CustomFirebaseAnalytics.Param.BUTTON_CLICK_REASON,
getString(R.string.chart_actvity_right_arrow));
analyticsInstance.logEvent(
CustomFirebaseAnalytics.Event.ADD_BUTTON_CLICK, eventProperties);
if (dateTypeArray.get((int) rightArrow.getTag()).equalsIgnoreCase(DAY)) {
try {
SimpleDateFormat simpleDateFormat =
AppController.getDateFormatForDashboardAndChartCurrentDayOut();
SimpleDateFormat dateFormatForApi = AppController.getDateFormatForApi();
Date selectedStartDAte =
dateFormatForApi.parse(fromDayVals.get((int) rightArrow.getTag()));
Date selectedEndDate =
dateFormatForApi.parse(toDayVals.get((int) rightArrow.getTag()));
Calendar calendarStart = Calendar.getInstance();
calendarStart.setTime(selectedStartDAte);
calendarStart.add(Calendar.DATE, 1);
Calendar calendarEnd = Calendar.getInstance();
calendarEnd.setTime(selectedEndDate);
calendarEnd.add(Calendar.DATE, 1);
if (!calendarStart.getTime().after(new Date())) {
fromDayVals.set(
(int) rightArrow.getTag(), dateFormatForApi.format(calendarStart.getTime()));
toDayVals.set(
(int) rightArrow.getTag(), dateFormatForApi.format(calendarEnd.getTime()));
textView1.setText(simpleDateFormat.format(calendarStart.getTime()));
refreshchartdata(
"" + textView1.getTag(),
calendarStart.getTime(),
calendarEnd.getTime(),
chart,
stepRecordCustomList,
filteredXValues,
entryList,
activityRuns,
barColor,
"" + textView1.getTag(R.string.charttag));
}
} catch (ParseException e) {
Logger.log(e);
}
} else if (dateTypeArray.get((int) rightArrow.getTag()).equalsIgnoreCase(WEEK)) {
try {
SimpleDateFormat simpleDateFormat =
AppController.getDateFormatForDashboardAndChartCurrentDayOut();
SimpleDateFormat dateFormatForApi = AppController.getDateFormatForApi();
Date selectedStartDAte =
dateFormatForApi.parse(fromDayVals.get((int) rightArrow.getTag()));
Date selectedEndDate =
dateFormatForApi.parse(toDayVals.get((int) rightArrow.getTag()));
Calendar calendarStart = Calendar.getInstance();
calendarStart.setTime(selectedStartDAte);
calendarStart.add(Calendar.DATE, 7);
Calendar calendarEnd = Calendar.getInstance();
calendarEnd.setTime(selectedEndDate);
calendarEnd.add(Calendar.DATE, 7);
if (!calendarStart.getTime().after(new Date())) {
fromDayVals.set(
(int) rightArrow.getTag(), dateFormatForApi.format(calendarStart.getTime()));
toDayVals.set(
(int) rightArrow.getTag(), dateFormatForApi.format(calendarEnd.getTime()));
if (calendarEnd.getTime().after(new Date())) {
textView1.setText(
simpleDateFormat.format(calendarStart.getTime())
+ " - "
+ simpleDateFormat.format(new Date()));
refreshchartdata(
"" + textView1.getTag(),
calendarStart.getTime(),
new Date(),
chart,
stepRecordCustomList,
filteredXValues,
entryList,
activityRuns,
barColor,
"" + textView1.getTag(R.string.charttag));
} else {
textView1.setText(
simpleDateFormat.format(calendarStart.getTime())
+ " - "
+ simpleDateFormat.format(calendarEnd.getTime()));
refreshchartdata(
"" + textView1.getTag(),
calendarStart.getTime(),
calendarEnd.getTime(),
chart,
stepRecordCustomList,
filteredXValues,
entryList,
activityRuns,
barColor,
"" + textView1.getTag(R.string.charttag));
}
}
} catch (ParseException e) {
Logger.log(e);
}
} else if (dateTypeArray.get((int) rightArrow.getTag()).equalsIgnoreCase(MONTH)) {
try {
SimpleDateFormat simpleDateFormat = AppController.getDateFormatForApi();
SimpleDateFormat dateFormatForChartAndStat =
AppController.getDateFormatForChartAndStat();
Date selectedStartDAte =
simpleDateFormat.parse(fromDayVals.get((int) rightArrow.getTag()));
Date selectedEndDate =
simpleDateFormat.parse(toDayVals.get((int) rightArrow.getTag()));
Calendar calendarStart = Calendar.getInstance();
calendarStart.setTime(selectedStartDAte);
calendarStart.add(Calendar.MONTH, 1);
Calendar calendarEnd = Calendar.getInstance();
calendarEnd.setTime(selectedEndDate);
calendarEnd.add(Calendar.MONTH, 1);
if (!calendarStart.getTime().after(new Date())) {
fromDayVals.set(
(int) rightArrow.getTag(), simpleDateFormat.format(calendarStart.getTime()));
toDayVals.set(
(int) rightArrow.getTag(), simpleDateFormat.format(calendarEnd.getTime()));
textView1.setText(dateFormatForChartAndStat.format(calendarStart.getTime()));
refreshchartdata(
"" + textView1.getTag(),
calendarStart.getTime(),
calendarEnd.getTime(),
chart,
stepRecordCustomList,
filteredXValues,
entryList,
activityRuns,
barColor,
"" + textView1.getTag(R.string.charttag));
}
} catch (ParseException e) {
Logger.log(e);
}
} else if (dateTypeArray.get((int) rightArrow.getTag()).equalsIgnoreCase(YEAR)) {
try {
SimpleDateFormat simpleDateFormat = AppController.getDateFormatForApi();
SimpleDateFormat dateFormatForApi = AppController.getDateFormatYearFormat();
Date selectedStartDAte =
simpleDateFormat.parse(fromDayVals.get((int) rightArrow.getTag()));
Date selectedEndDate =
simpleDateFormat.parse(toDayVals.get((int) rightArrow.getTag()));
Calendar calendarStart = Calendar.getInstance();
calendarStart.setTime(selectedStartDAte);
calendarStart.add(Calendar.YEAR, 1);
Calendar calendarEnd = Calendar.getInstance();
calendarEnd.setTime(selectedEndDate);
calendarEnd.add(Calendar.YEAR, 1);
if (!calendarStart.getTime().after(new Date())) {
fromDayVals.set(
(int) rightArrow.getTag(), simpleDateFormat.format(calendarStart.getTime()));
toDayVals.set(
(int) rightArrow.getTag(), simpleDateFormat.format(calendarEnd.getTime()));
textView1.setText(dateFormatForApi.format(calendarStart.getTime()));
refreshchartdata(
"" + textView1.getTag(),
calendarStart.getTime(),
calendarEnd.getTime(),
chart,
stepRecordCustomList,
filteredXValues,
entryList,
activityRuns,
barColor,
"" + textView1.getTag(R.string.charttag));
}
} catch (ParseException e) {
Logger.log(e);
}
}
}
});
linearLayout1.addView(leftArrow);
linearLayout1.addView(textView1);
linearLayout1.addView(rightArrow);
}