use of com.github.mikephil.charting.charts.PieChart in project Gadgetbridge by Freeyourgadget.
the class ActivityListingAdapter method fill_dashboard.
@Override
protected View fill_dashboard(ActivitySession item, int position, View view, ViewGroup parent, Context context) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(R.layout.activity_list_dashboard_item, parent, false);
PieChart ActiveStepsChart;
PieChart DistanceChart;
PieChart ActiveTimeChart;
ActiveStepsChart = view.findViewById(R.id.activity_dashboard_piechart1);
setUpChart(ActiveStepsChart);
int steps = item.getActiveSteps();
setChartsData(ActiveStepsChart, steps, stepsGoal, context.getString(R.string.activity_list_summary_active_steps), context);
DistanceChart = view.findViewById(R.id.activity_dashboard_piechart2);
setUpChart(DistanceChart);
float distance = item.getDistance();
setChartsData(DistanceChart, distance, distanceGoalMeters, context.getString(R.string.distance), context);
ActiveTimeChart = view.findViewById(R.id.activity_dashboard_piechart3);
setUpChart(ActiveTimeChart);
long duration = item.getEndTime().getTime() - item.getStartTime().getTime();
setChartsData(ActiveTimeChart, duration, activeTimeGoalTimeMillis, context.getString(R.string.activity_list_summary_active_time), context);
TextView stepLabel = view.findViewById(R.id.line_layout_step_label);
TextView stepTotalLabel = view.findViewById(R.id.line_layout_total_step_label);
TextView distanceLabel = view.findViewById(R.id.line_layout_distance_label);
TextView hrLabel = view.findViewById(R.id.heartrate_widget_label);
TextView intensityLabel = view.findViewById(R.id.intensity_widget_label);
TextView intensity2Label = view.findViewById(R.id.line_layout_intensity2_label);
TextView durationLabel = view.findViewById(R.id.line_layout_duration_label);
TextView sessionCountLabel = view.findViewById(R.id.line_layout_count_label);
LinearLayout durationLayout = view.findViewById(R.id.line_layout_duration);
LinearLayout countLayout = view.findViewById(R.id.line_layout_count);
View hrLayout = view.findViewById(R.id.heartrate_widget_icon);
LinearLayout stepsLayout = view.findViewById(R.id.line_layout_step);
LinearLayout stepsTotalLayout = view.findViewById(R.id.line_layout_total_step);
LinearLayout distanceLayout = view.findViewById(R.id.line_layout_distance);
View intensityLayout = view.findViewById(R.id.intensity_widget_icon);
View intensity2Layout = view.findViewById(R.id.line_layout_intensity2);
stepLabel.setText(getStepLabel(item));
stepTotalLabel.setText(getStepTotalLabel(item));
distanceLabel.setText(getDistanceLabel(item));
hrLabel.setText(getHrLabel(item));
intensityLabel.setText(getIntensityLabel(item));
intensity2Label.setText(getIntensityLabel(item));
durationLabel.setText(getDurationLabel(item));
sessionCountLabel.setText(getSessionCountLabel(item));
if (!hasHR(item)) {
hrLayout.setVisibility(View.GONE);
hrLabel.setVisibility(View.GONE);
} else {
hrLayout.setVisibility(View.VISIBLE);
hrLabel.setVisibility(View.VISIBLE);
}
if (!hasIntensity(item)) {
intensityLayout.setVisibility(View.GONE);
intensity2Layout.setVisibility(View.GONE);
intensityLabel.setVisibility(View.GONE);
intensity2Label.setVisibility(View.GONE);
} else {
intensityLayout.setVisibility(View.VISIBLE);
intensity2Layout.setVisibility(View.VISIBLE);
intensityLabel.setVisibility(View.VISIBLE);
intensity2Label.setVisibility(View.VISIBLE);
}
if (!hasDistance(item)) {
distanceLayout.setVisibility(View.GONE);
} else {
distanceLayout.setVisibility(View.VISIBLE);
}
if (!hasSteps(item)) {
stepsLayout.setVisibility(View.GONE);
} else {
stepsLayout.setVisibility(View.VISIBLE);
}
if (!hasTotalSteps(item)) {
stepsTotalLayout.setVisibility(View.GONE);
countLayout.setVisibility(View.GONE);
durationLayout.setVisibility(View.GONE);
} else {
stepsTotalLayout.setVisibility(View.VISIBLE);
countLayout.setVisibility(View.VISIBLE);
durationLayout.setVisibility(View.VISIBLE);
}
return view;
}
use of com.github.mikephil.charting.charts.PieChart in project Gadgetbridge by Freeyourgadget.
the class GBDeviceAdapterv2 method setActivityCard.
private void setActivityCard(ViewHolder holder, final GBDevice device, long[] dailyTotals) {
int steps = (int) dailyTotals[0];
int sleep = (int) dailyTotals[1];
ActivityUser activityUser = new ActivityUser();
int stepGoal = activityUser.getStepsGoal();
int sleepGoal = activityUser.getSleepDurationGoal();
int sleepGoalMinutes = sleepGoal * 60;
int distanceGoal = activityUser.getDistanceGoalMeters() * 100;
int stepLength = activityUser.getStepLengthCm();
double distanceMeters = dailyTotals[0] * stepLength * 0.01;
String distanceFormatted = FormatUtils.getFormattedDistanceLabel(distanceMeters);
setUpChart(holder.TotalStepsChart);
setChartsData(holder.TotalStepsChart, steps, stepGoal, context.getString(R.string.steps), String.valueOf(steps), context);
setUpChart(holder.TotalDistanceChart);
setChartsData(holder.TotalDistanceChart, steps * stepLength, distanceGoal, context.getString(R.string.distance), distanceFormatted, context);
setUpChart(holder.SleepTimeChart);
setChartsData(holder.SleepTimeChart, sleep, sleepGoalMinutes, context.getString(R.string.prefs_activity_in_device_card_sleep_title), String.format("%1s", getHM(sleep)), context);
boolean showActivityCard = GBApplication.getDeviceSpecificSharedPrefs(device.getAddress()).getBoolean(DeviceSettingsPreferenceConst.PREFS_ACTIVITY_IN_DEVICE_CARD, true);
holder.cardViewActivityCardLayout.setVisibility(showActivityCard ? View.VISIBLE : View.GONE);
boolean showActivitySteps = GBApplication.getDeviceSpecificSharedPrefs(device.getAddress()).getBoolean(DeviceSettingsPreferenceConst.PREFS_ACTIVITY_IN_DEVICE_CARD_STEPS, true);
boolean showActivitySleep = GBApplication.getDeviceSpecificSharedPrefs(device.getAddress()).getBoolean(DeviceSettingsPreferenceConst.PREFS_ACTIVITY_IN_DEVICE_CARD_SLEEP, true);
boolean showActivityDistance = GBApplication.getDeviceSpecificSharedPrefs(device.getAddress()).getBoolean(DeviceSettingsPreferenceConst.PREFS_ACTIVITY_IN_DEVICE_CARD_DISTANCE, true);
// do the multiple mini-charts for activities in a loop
Hashtable<PieChart, Pair<Boolean, Integer>> activitiesStatusMiniCharts = new Hashtable<>();
activitiesStatusMiniCharts.put(holder.TotalStepsChart, new Pair<>(showActivitySteps && steps > 0, ChartsActivity.getChartsTabIndex("stepsweek", device, context)));
activitiesStatusMiniCharts.put(holder.SleepTimeChart, new Pair<>(showActivitySleep && sleep > 0, ChartsActivity.getChartsTabIndex("sleep", device, context)));
activitiesStatusMiniCharts.put(holder.TotalDistanceChart, new Pair<>(showActivityDistance && steps > 0, ChartsActivity.getChartsTabIndex("activity", device, context)));
for (Map.Entry<PieChart, Pair<Boolean, Integer>> miniCharts : activitiesStatusMiniCharts.entrySet()) {
PieChart miniChart = miniCharts.getKey();
final Pair<Boolean, Integer> parameters = miniCharts.getValue();
miniChart.setVisibility(parameters.first ? View.VISIBLE : View.GONE);
miniChart.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent startIntent;
startIntent = new Intent(context, ChartsActivity.class);
startIntent.putExtra(GBDevice.EXTRA_DEVICE, device);
startIntent.putExtra(ChartsActivity.EXTRA_FRAGMENT_ID, parameters.second);
context.startActivity(startIntent);
}
});
}
}
use of com.github.mikephil.charting.charts.PieChart in project AmazeFileManager by TeamAmaze.
the class GeneralDialogCreation method showPropertiesDialog.
private static void showPropertiesDialog(final HybridFileParcelable baseFile, final String permissions, ThemedActivity base, boolean isRoot, AppTheme appTheme, boolean showPermissions, boolean forStorage) {
final ExecutorService executor = Executors.newFixedThreadPool(3);
final Context c = base.getApplicationContext();
int accentColor = base.getColorPreference().getColor(ColorUsage.ACCENT);
long last = baseFile.getDate();
final String date = Utils.getDate(last), items = c.getString(R.string.calculating), name = baseFile.getName(), parent = baseFile.getReadablePath(baseFile.getParent(c));
MaterialDialog.Builder builder = new MaterialDialog.Builder(base);
builder.title(c.getString(R.string.properties));
builder.theme(appTheme.getMaterialDialogTheme());
View v = base.getLayoutInflater().inflate(R.layout.properties_dialog, null);
TextView itemsText = (TextView) v.findViewById(R.id.t7);
/*View setup*/
{
TextView mNameTitle = (TextView) v.findViewById(R.id.title_name);
mNameTitle.setTextColor(accentColor);
TextView mDateTitle = (TextView) v.findViewById(R.id.title_date);
mDateTitle.setTextColor(accentColor);
TextView mSizeTitle = (TextView) v.findViewById(R.id.title_size);
mSizeTitle.setTextColor(accentColor);
TextView mLocationTitle = (TextView) v.findViewById(R.id.title_location);
mLocationTitle.setTextColor(accentColor);
TextView md5Title = (TextView) v.findViewById(R.id.title_md5);
md5Title.setTextColor(accentColor);
TextView sha256Title = (TextView) v.findViewById(R.id.title_sha256);
sha256Title.setTextColor(accentColor);
((TextView) v.findViewById(R.id.t5)).setText(name);
((TextView) v.findViewById(R.id.t6)).setText(parent);
itemsText.setText(items);
((TextView) v.findViewById(R.id.t8)).setText(date);
LinearLayout mNameLinearLayout = (LinearLayout) v.findViewById(R.id.properties_dialog_name);
LinearLayout mLocationLinearLayout = (LinearLayout) v.findViewById(R.id.properties_dialog_location);
LinearLayout mSizeLinearLayout = (LinearLayout) v.findViewById(R.id.properties_dialog_size);
LinearLayout mDateLinearLayout = (LinearLayout) v.findViewById(R.id.properties_dialog_date);
// setting click listeners for long press
mNameLinearLayout.setOnLongClickListener(v1 -> {
FileUtils.copyToClipboard(c, name);
Toast.makeText(c, c.getResources().getString(R.string.name) + " " + c.getResources().getString(R.string.properties_copied_clipboard), Toast.LENGTH_SHORT).show();
return false;
});
mLocationLinearLayout.setOnLongClickListener(v12 -> {
FileUtils.copyToClipboard(c, parent);
Toast.makeText(c, c.getResources().getString(R.string.location) + " " + c.getResources().getString(R.string.properties_copied_clipboard), Toast.LENGTH_SHORT).show();
return false;
});
mSizeLinearLayout.setOnLongClickListener(v13 -> {
FileUtils.copyToClipboard(c, items);
Toast.makeText(c, c.getResources().getString(R.string.size) + " " + c.getResources().getString(R.string.properties_copied_clipboard), Toast.LENGTH_SHORT).show();
return false;
});
mDateLinearLayout.setOnLongClickListener(v14 -> {
FileUtils.copyToClipboard(c, date);
Toast.makeText(c, c.getResources().getString(R.string.date) + " " + c.getResources().getString(R.string.properties_copied_clipboard), Toast.LENGTH_SHORT).show();
return false;
});
}
CountItemsOrAndSizeTask countItemsOrAndSizeTask = new CountItemsOrAndSizeTask(c, itemsText, baseFile, forStorage);
countItemsOrAndSizeTask.executeOnExecutor(executor);
GenerateHashesTask hashGen = new GenerateHashesTask(baseFile, c, v);
hashGen.executeOnExecutor(executor);
/*Chart creation and data loading*/
{
boolean isRightToLeft = c.getResources().getBoolean(R.bool.is_right_to_left);
boolean isDarkTheme = appTheme.getMaterialDialogTheme() == Theme.DARK;
PieChart chart = (PieChart) v.findViewById(R.id.chart);
chart.setTouchEnabled(false);
chart.setDrawEntryLabels(false);
chart.setDescription(null);
chart.setNoDataText(c.getString(R.string.loading));
chart.setRotationAngle(!isRightToLeft ? 0f : 180f);
chart.setHoleColor(Color.TRANSPARENT);
chart.setCenterTextColor(isDarkTheme ? Color.WHITE : Color.BLACK);
chart.getLegend().setEnabled(true);
chart.getLegend().setForm(Legend.LegendForm.CIRCLE);
chart.getLegend().setHorizontalAlignment(Legend.LegendHorizontalAlignment.CENTER);
chart.getLegend().setTypeface(Typeface.create("sans-serif-medium", Typeface.NORMAL));
chart.getLegend().setTextColor(isDarkTheme ? Color.WHITE : Color.BLACK);
chart.animateY(1000);
if (forStorage) {
final String[] LEGENDS = new String[] { c.getString(R.string.used), c.getString(R.string.free) };
final int[] COLORS = { Utils.getColor(c, R.color.piechart_red), Utils.getColor(c, R.color.piechart_green) };
long totalSpace = baseFile.getTotal(c), freeSpace = baseFile.getUsableSpace(), usedSpace = totalSpace - freeSpace;
List<PieEntry> entries = new ArrayList<>();
entries.add(new PieEntry(usedSpace, LEGENDS[0]));
entries.add(new PieEntry(freeSpace, LEGENDS[1]));
PieDataSet set = new PieDataSet(entries, null);
set.setColors(COLORS);
set.setXValuePosition(PieDataSet.ValuePosition.OUTSIDE_SLICE);
set.setYValuePosition(PieDataSet.ValuePosition.OUTSIDE_SLICE);
set.setSliceSpace(5f);
set.setAutomaticallyDisableSliceSpacing(true);
set.setValueLinePart2Length(1.05f);
set.setSelectionShift(0f);
PieData pieData = new PieData(set);
pieData.setValueFormatter(new SizeFormatter(c));
pieData.setValueTextColor(isDarkTheme ? Color.WHITE : Color.BLACK);
String totalSpaceFormatted = Formatter.formatFileSize(c, totalSpace);
chart.setCenterText(new SpannableString(c.getString(R.string.total) + "\n" + totalSpaceFormatted));
chart.setData(pieData);
} else {
LoadFolderSpaceDataTask loadFolderSpaceDataTask = new LoadFolderSpaceDataTask(c, appTheme, chart, baseFile);
loadFolderSpaceDataTask.executeOnExecutor(executor);
}
chart.invalidate();
}
if (!forStorage && showPermissions) {
final MainFragment main = ((MainActivity) base).mainFragment;
AppCompatButton appCompatButton = (AppCompatButton) v.findViewById(R.id.permissionsButton);
appCompatButton.setAllCaps(true);
final View permissionsTable = v.findViewById(R.id.permtable);
final View button = v.findViewById(R.id.set);
if (isRoot && permissions.length() > 6) {
appCompatButton.setVisibility(View.VISIBLE);
appCompatButton.setOnClickListener(v15 -> {
if (permissionsTable.getVisibility() == View.GONE) {
permissionsTable.setVisibility(View.VISIBLE);
button.setVisibility(View.VISIBLE);
setPermissionsDialog(permissionsTable, button, baseFile, permissions, c, main);
} else {
button.setVisibility(View.GONE);
permissionsTable.setVisibility(View.GONE);
}
});
}
}
builder.customView(v, true);
builder.positiveText(base.getResources().getString(R.string.ok));
builder.positiveColor(accentColor);
builder.dismissListener(dialog -> executor.shutdown());
MaterialDialog materialDialog = builder.build();
materialDialog.show();
materialDialog.getActionButton(DialogAction.NEGATIVE).setEnabled(false);
/*
View bottomSheet = c.findViewById(R.id.design_bottom_sheet);
BottomSheetBehavior bottomSheetBehavior = BottomSheetBehavior.from(bottomSheet);
bottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
bottomSheetBehavior.setPeekHeight(BottomSheetBehavior.STATE_DRAGGING);
*/
}
use of com.github.mikephil.charting.charts.PieChart in project Roblu by wdavies973.
the class RMetricToUI method generatePieChart.
public CardView generatePieChart(String metricName, LinkedHashMap<String, Double> data) {
PieChart chart = new PieChart(activity);
chart.setMinimumHeight(1000);
chart.setDrawHoleEnabled(false);
chart.setUsePercentValues(true);
chart.getLegend().setTextColor(rui.getText());
chart.setCenterText(metricName);
chart.setCenterTextColor(rui.getText());
chart.setCenterTextSize(15f);
chart.getDescription().setEnabled(false);
List<PieEntry> entries = new ArrayList<>();
for (Object o : data.keySet()) {
entries.add(new PieEntry((data.get(o.toString())).floatValue(), o.toString()));
}
PieDataSet set = new PieDataSet(entries, "");
set.setColors(ColorTemplate.MATERIAL_COLORS);
set.setValueTextSize(12f);
set.setValueTextColor(rui.getText());
PieData pieData = new PieData(set);
pieData.setValueFormatter(new PercentFormatter());
chart.setData(pieData);
chart.invalidate();
return getCard(chart);
}
Aggregations