use of com.jjoe64.graphview.GraphView in project SR-Tracker-for-Overwatch by Rexios80.
the class AnalysisFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
v = inflater.inflate(R.layout.analysis_fragment, container, false);
srGraph = (GraphView) v.findViewById(R.id.sr_graph);
srGraph.setTitle("SR");
srGraph.getViewport().setXAxisBoundsManual(true);
srGraph.getGridLabelRenderer().setLabelVerticalWidth((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 30, getResources().getDisplayMetrics()));
srGraph.getGridLabelRenderer().setTextSize(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 10, this.getResources().getDisplayMetrics()));
srGraph.getGridLabelRenderer().setHighlightZeroLines(false);
srSeries.setColor(ContextCompat.getColor(getContext(), R.color.colorAccent));
srSeries.setBackgroundColor(ContextCompat.getColor(getContext(), R.color.colorAccentLightTransparent));
srSeries.setDrawBackground(true);
srGraph.addSeries(srSeries);
streakGraph = (GraphView) v.findViewById(R.id.streak_graph);
streakGraph.setTitle("Streaks");
streakGraph.getViewport().setXAxisBoundsManual(true);
streakGraph.getGridLabelRenderer().setLabelVerticalWidth((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 30, getResources().getDisplayMetrics()));
streakGraph.getGridLabelRenderer().setTextSize(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 10, this.getResources().getDisplayMetrics()));
streakGraph.getGridLabelRenderer().setHighlightZeroLines(false);
winStreakSeries.setColor(ContextCompat.getColor(getContext(), R.color.colorAccent));
winStreakSeries.setBackgroundColor(ContextCompat.getColor(getContext(), R.color.colorAccentLightTransparent));
winStreakSeries.setDrawBackground(true);
streakGraph.addSeries(winStreakSeries);
lossStreakSeries.setColor(ContextCompat.getColor(getContext(), R.color.colorAccentOpposite));
lossStreakSeries.setBackgroundColor(ContextCompat.getColor(getContext(), R.color.colorAccentOppositeLightTransparent));
lossStreakSeries.setDrawBackground(true);
streakGraph.addSeries(lossStreakSeries);
if (dpWidth() > 750) {
if (dpWidth() >= 1000) {
TextView tv = (TextView) v.findViewById(R.id.analysis_header);
tv.setLayoutParams(new LinearLayout.LayoutParams(0, 0));
}
LinearLayout llAnalysis = (LinearLayout) v.findViewById(R.id.ll_analysis);
int cardBackground = ContextCompat.getColor(getActivity(), R.color.cardBackground);
llAnalysis.setBackgroundColor(cardBackground);
srGraph.getGridLabelRenderer().setHighlightZeroLines(false);
streakGraph.getGridLabelRenderer().setHighlightZeroLines(false);
srSeries.setThickness(2);
winStreakSeries.setThickness(2);
lossStreakSeries.setThickness(2);
}
refresh();
return v;
}
use of com.jjoe64.graphview.GraphView in project Thesis by bajnax.
the class LeConnectedDeviceActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_le_connected_device);
if (savedInstanceState != null) {
// Restore value of members from saved state
isServiceRunning = savedInstanceState.getBoolean(CONNECTION_STATE);
hasReceivedServices = savedInstanceState.getBoolean(RECEIVED_SERVICES);
} else {
isServiceRunning = false;
hasReceivedServices = false;
}
deviceStatus = (TextView) findViewById(R.id.deviceStatus);
// spinner, its neighbouring textView, graph and connectivity to the SaMi cloud
// won't be shown if another device is connected
spinner = (ProgressBar) findViewById(R.id.spinner);
lookUpText = (TextView) findViewById(R.id.lookUpTextView);
spinner.setVisibility(View.GONE);
lookUpText.setVisibility(View.GONE);
toolBar = (Toolbar) findViewById(R.id.tool_bar);
setSupportActionBar(toolBar);
// setting up the graph's vertical labels
sensorsGraph = (GraphView) findViewById(R.id.graph);
sensorsGraph.setTitle("Current sensor\'s data");
sensorsGraph.setTitleColor(R.color.colorPrimaryDark);
sensorsGraph.getGridLabelRenderer().setVerticalAxisTitle("Value");
sensorsGraph.getGridLabelRenderer().setHorizontalAxisTitle("Time");
// enabling horizontal zooming and scrolling
sensorsGraph.getViewport().setScalable(true);
sensorsGraph.getGridLabelRenderer().setLabelVerticalWidth(50);
sensorsGraph.getGridLabelRenderer().setLabelHorizontalHeight(50);
sensorsGraph.getViewport().setYAxisBoundsManual(true);
sensorsGraph.getViewport().setMinY(0);
sensorsGraph.getViewport().setMaxY(40);
// TODO: make the date labels on the X axis to be shown properly
// set date label formatter
SimpleDateFormat mDateFormatter = new SimpleDateFormat("MM-dd HH:mm:ss");
sensorsGraph.getGridLabelRenderer().setLabelFormatter(new DateAsXAxisLabelFormatter(LeConnectedDeviceActivity.this, mDateFormatter));
// only 2 because of the space
sensorsGraph.getGridLabelRenderer().setNumHorizontalLabels(2);
Calendar calendar = Calendar.getInstance();
long t1 = calendar.getTimeInMillis();
long t2 = calendar.getTimeInMillis() + 15000;
sensorsGraph.getViewport().setXAxisBoundsManual(true);
sensorsGraph.getViewport().setMinX((double) t1);
sensorsGraph.getViewport().setMaxX(((double) t2));
// as we use dates as labels, the human rounding to nice readable numbers
// is not necessary
sensorsGraph.getGridLabelRenderer().setHumanRounding(false);
temperatureSeries = new PointsGraphSeries<>();
sensorsGraph.addSeries(temperatureSeries);
expListView = (ExpandableListView) findViewById(R.id.expandableListView);
final BluetoothManager bluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
if (bluetoothManager != null)
mBluetoothAdapter = bluetoothManager.getAdapter();
else
finish();
// Get the Intent that started this activity and extract the string
Intent intent = getIntent();
deviceAddress = intent.getStringExtra("deviceAddress");
if (deviceAddress == null) {
finish();
}
// setting up the progress bar, in case the BLE Shield is connected
if (deviceAddress.equals(GattAttributesSample.DEVICE_ADDRESS)) {
Drawable progressDrawable = spinner.getIndeterminateDrawable().mutate();
progressDrawable.setColorFilter(getColor(R.color.colorPrimary), PorterDuff.Mode.MULTIPLY);
spinner.setProgressDrawable(progressDrawable);
spinner.setVisibility(View.VISIBLE);
lookUpText.setVisibility(View.VISIBLE);
}
// Starting service if it is not running yet and binding to it afterwards
Intent gattServiceIntent = new Intent(getApplicationContext(), BluetoothLowEnergyService.class);
// the service will be created only once
getApplicationContext().startService(gattServiceIntent);
// service clients are able to bind to it at any time
bindService(gattServiceIntent, mServiceConnection, BIND_AUTO_CREATE);
registerReceiver(mGattUpdateReceiver, GattUpdateIntentFilter());
/* if (mBluetoothLEService != null && !isServiceRunning) {
final boolean result = mBluetoothLEService.connect(deviceAddress);
Toast.makeText(LeConnectedDeviceActivity.this,
"Connect request result: " + result, Toast.LENGTH_SHORT).show();
}*/
expListView.setVisibility(View.GONE);
sensorsGraph.setVisibility(View.GONE);
final SensorsDataViewModel sensorsDataViewModel = ViewModelProviders.of(this).get(SensorsDataViewModel.class);
sensorsDataViewModel.getTemperatures().observe(this, new Observer<List<Temperature>>() {
@Override
public void onChanged(@Nullable final List<Temperature> temperatures) {
if (temperatures == null) {
Toast.makeText(LeConnectedDeviceActivity.this, "No data received", Toast.LENGTH_SHORT).show();
} else if (temperatures.size() > 0) {
if (temperatures.size() == 1) {
// set manual x bounds to have nice steps
// sensorsGraph.getViewport().setXAxisBoundsManual(true);
sensorsGraph.getViewport().setMinX((double) temperatures.get(0).getTimestamp());
sensorsGraph.getViewport().setMaxX((double) sensorsGraph.getViewport().getMinX(false) + 15000);
Log.d(TAG, "Initial timestamp, MinLabelX: " + mDateFormatter.format((double) temperatures.get(0).getTimestamp()));
Log.d(TAG, "Final timestamp, MaxLabelX: " + mDateFormatter.format(((double) sensorsGraph.getViewport().getMinX(false) + 15000)));
}
/*//scales programmatically
sensorsGraph.getViewport().setMaxX((double)temperatures.get(temperatures.size()-1).getTimestamp());*/
displayTemperature(temperatures.get(temperatures.size() - 1));
}
}
});
}
use of com.jjoe64.graphview.GraphView in project stillStanding by katsik.
the class GraphActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTheme(R.style.AppTheme);
setContentView(R.layout.activity_graph);
// Get a support ActionBar corresponding to this toolbar
ActionBar ab = getSupportActionBar();
// Enable the Up button
ab.setDisplayHomeAsUpEnabled(true);
sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
GraphView graph = (GraphView) findViewById(R.id.graph);
series = new LineGraphSeries<>();
series.setColor(Color.BLUE);
series.setThickness(10);
graph.addSeries(series);
series.setDrawBackground(true);
// activate horizontal zooming and scrolling
graph.getViewport().setScalable(true);
// activate horizontal scrolling
graph.getViewport().setScrollable(true);
// activate horizontal and vertical zooming and scrolling
graph.getViewport().setScalableY(true);
// activate vertical scrolling
graph.getViewport().setScrollableY(true);
// To set a fixed manual viewport use this:
// set manual X bounds
graph.getViewport().setXAxisBoundsManual(true);
graph.getViewport().setMinX(0.5);
graph.getViewport().setMaxX(6.5);
// set manual Y bounds
graph.getViewport().setYAxisBoundsManual(true);
graph.getViewport().setMinY(0);
graph.getViewport().setMaxY(20);
graph.setTitle(getString(R.string.graph_title));
currentX = 0;
// Start chart thread
liveChartExecutor = (ThreadPoolExecutor) Executors.newFixedThreadPool(1);
if (liveChartExecutor != null)
liveChartExecutor.execute(new AccelerationChart(new AccelerationChartHandler()));
}
use of com.jjoe64.graphview.GraphView in project WordPress-Android by wordpress-mobile.
the class StatsVisitorsAndViewsFragment method updateUI.
protected void updateUI() {
if (!isAdded()) {
return;
}
if (mVisitsData == null) {
setupNoResultsUI(false);
return;
}
final VisitModel[] dataToShowOnGraph = getDataToShowOnGraph(mVisitsData);
if (dataToShowOnGraph == null || dataToShowOnGraph.length == 0) {
setupNoResultsUI(false);
return;
}
// Hide the "no-activity this period" message
mNoActivtyThisPeriodContainer.setVisibility(View.GONE);
// Read the selected Tab in the UI
OverviewLabel selectedStatsType = overviewItems[mSelectedOverviewItemIndex];
// Update the Legend and enable/disable the visitors checkboxes
mLegendContainer.setVisibility(View.VISIBLE);
mLegendLabel.setText(StringUtils.capitalize(selectedStatsType.getLabel().toLowerCase()));
switch(selectedStatsType) {
case VIEWS:
mVisitorsCheckboxContainer.setVisibility(View.VISIBLE);
mVisitorsCheckbox.setEnabled(true);
mVisitorsCheckbox.setChecked(mIsCheckboxChecked);
break;
default:
mVisitorsCheckboxContainer.setVisibility(View.GONE);
break;
}
// Setting Up labels and prepare variables that hold series
final String[] horLabels = new String[dataToShowOnGraph.length];
mStatsDate = new String[dataToShowOnGraph.length];
GraphView.GraphViewData[] mainSeriesItems = new GraphView.GraphViewData[dataToShowOnGraph.length];
GraphView.GraphViewData[] secondarySeriesItems = null;
if (mIsCheckboxChecked && selectedStatsType == OverviewLabel.VIEWS) {
secondarySeriesItems = new GraphView.GraphViewData[dataToShowOnGraph.length];
}
// index of days that should be XXX on the graph
final boolean[] weekendDays;
if (getTimeframe() == StatsTimeframe.DAY) {
weekendDays = new boolean[dataToShowOnGraph.length];
} else {
weekendDays = null;
}
// Check we have at least one result in the current section.
boolean atLeastOneResultIsAvailable = false;
// Fill series variables with data
for (int i = 0; i < dataToShowOnGraph.length; i++) {
int currentItemValue = 0;
switch(selectedStatsType) {
case VIEWS:
currentItemValue = dataToShowOnGraph[i].getViews();
break;
case VISITORS:
currentItemValue = dataToShowOnGraph[i].getVisitors();
break;
case LIKES:
currentItemValue = dataToShowOnGraph[i].getLikes();
break;
case COMMENTS:
currentItemValue = dataToShowOnGraph[i].getComments();
break;
}
mainSeriesItems[i] = new GraphView.GraphViewData(i, currentItemValue);
if (currentItemValue > 0) {
atLeastOneResultIsAvailable = true;
}
if (mIsCheckboxChecked && secondarySeriesItems != null) {
secondarySeriesItems[i] = new GraphView.GraphViewData(i, dataToShowOnGraph[i].getVisitors());
}
String currentItemStatsDate = dataToShowOnGraph[i].getPeriod();
horLabels[i] = getDateLabelForBarInGraph(currentItemStatsDate);
mStatsDate[i] = currentItemStatsDate;
if (weekendDays != null) {
SimpleDateFormat from = new SimpleDateFormat(StatsConstants.STATS_INPUT_DATE_FORMAT);
try {
Date date = from.parse(currentItemStatsDate);
Calendar c = Calendar.getInstance();
c.setFirstDayOfWeek(Calendar.MONDAY);
c.setTimeInMillis(date.getTime());
weekendDays[i] = c.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY || c.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY;
} catch (ParseException e) {
weekendDays[i] = false;
AppLog.e(AppLog.T.STATS, e);
}
}
}
if (mGraphContainer.getChildCount() >= 1 && mGraphContainer.getChildAt(0) instanceof GraphView) {
mGraphView = (StatsBarGraph) mGraphContainer.getChildAt(0);
} else {
mGraphContainer.removeAllViews();
mGraphView = new StatsBarGraph(getActivity());
mGraphContainer.addView(mGraphView);
}
mGraphView.removeAllSeries();
GraphViewSeries mainSeriesOnScreen = new GraphViewSeries(mainSeriesItems);
mainSeriesOnScreen.getStyle().color = getResources().getColor(R.color.stats_bar_graph_main_series);
mainSeriesOnScreen.getStyle().outerColor = getResources().getColor(R.color.grey_lighten_30_translucent_50);
mainSeriesOnScreen.getStyle().highlightColor = getResources().getColor(R.color.stats_bar_graph_main_series_highlight);
mainSeriesOnScreen.getStyle().outerhighlightColor = getResources().getColor(R.color.stats_bar_graph_outer_highlight);
mainSeriesOnScreen.getStyle().padding = DisplayUtils.dpToPx(getActivity(), 5);
mGraphView.addSeries(mainSeriesOnScreen);
// Add the Visitors series if it's checked in the legend
if (mIsCheckboxChecked && secondarySeriesItems != null && selectedStatsType == OverviewLabel.VIEWS) {
GraphViewSeries secondarySeries = new GraphViewSeries(secondarySeriesItems);
secondarySeries.getStyle().padding = DisplayUtils.dpToPx(getActivity(), 10);
secondarySeries.getStyle().color = getResources().getColor(R.color.stats_bar_graph_secondary_series);
secondarySeries.getStyle().highlightColor = getResources().getColor(R.color.orange_fire);
mGraphView.addSeries(secondarySeries);
}
// the purpose of making these bars visually easily to compare.
switch(selectedStatsType) {
case VISITORS:
double maxYValue = getMaxYValueForVisitorsAndView(dataToShowOnGraph);
mGraphView.setManualYAxisBounds(maxYValue, 0d);
break;
default:
mGraphView.setManualYAxis(false);
break;
}
// Set the Graph Style
mGraphView.getGraphViewStyle().setNumHorizontalLabels(dataToShowOnGraph.length);
// Set the maximum size a column can get on the screen in PX
mGraphView.getGraphViewStyle().setMaxColumnWidth(DisplayUtils.dpToPx(getActivity(), StatsConstants.STATS_GRAPH_BAR_MAX_COLUMN_WIDTH_DP));
mGraphView.setHorizontalLabels(horLabels);
mGraphView.setGestureListener(this);
// If zero results in the current section disable clicks on the graph and show the dialog.
mNoActivtyThisPeriodContainer.setVisibility(atLeastOneResultIsAvailable ? View.GONE : View.VISIBLE);
mGraphView.setClickable(atLeastOneResultIsAvailable);
// Draw the background on weekend days
mGraphView.setWeekendDays(weekendDays);
// Only happens on 720DP tablets
if (mPrevNumberOfBarsGraph != -1 && mPrevNumberOfBarsGraph != dataToShowOnGraph.length) {
mSelectedBarGraphBarIndex = -1;
mPrevNumberOfBarsGraph = dataToShowOnGraph.length;
onBarTapped(dataToShowOnGraph.length - 1);
mGraphView.highlightBar(dataToShowOnGraph.length - 1);
return;
}
mPrevNumberOfBarsGraph = dataToShowOnGraph.length;
int barSelectedOnGraph;
if (mSelectedBarGraphBarIndex == -1) {
// No previous bar was highlighted, highlight the most recent one
barSelectedOnGraph = dataToShowOnGraph.length - 1;
} else if (mSelectedBarGraphBarIndex < dataToShowOnGraph.length) {
barSelectedOnGraph = mSelectedBarGraphBarIndex;
} else {
// A previous bar was highlighted, but it's out of the screen now. This should never happen atm.
barSelectedOnGraph = dataToShowOnGraph.length - 1;
mSelectedBarGraphBarIndex = barSelectedOnGraph;
}
updateUIBelowTheGraph(barSelectedOnGraph);
mGraphView.highlightBar(barSelectedOnGraph);
}
use of com.jjoe64.graphview.GraphView in project WordPress-Android by wordpress-mobile.
the class StatsSingleItemDetailsActivity method updateUI.
private void updateUI() {
if (isFinishing()) {
return;
}
final VisitModel[] dataToShowOnGraph = getDataToShowOnGraph();
if (dataToShowOnGraph == null || dataToShowOnGraph.length == 0) {
setupEmptyUI();
return;
}
final String[] horLabels = new String[dataToShowOnGraph.length];
String[] mStatsDate = new String[dataToShowOnGraph.length];
GraphView.GraphViewData[] views = new GraphView.GraphViewData[dataToShowOnGraph.length];
for (int i = 0; i < dataToShowOnGraph.length; i++) {
int currentItemValue = dataToShowOnGraph[i].getViews();
views[i] = new GraphView.GraphViewData(i, currentItemValue);
String currentItemStatsDate = dataToShowOnGraph[i].getPeriod();
horLabels[i] = StatsUtils.parseDate(currentItemStatsDate, StatsConstants.STATS_INPUT_DATE_FORMAT, StatsConstants.STATS_OUTPUT_DATE_MONTH_SHORT_DAY_SHORT_FORMAT);
mStatsDate[i] = currentItemStatsDate;
}
GraphViewSeries mCurrentSeriesOnScreen = new GraphViewSeries(views);
mCurrentSeriesOnScreen.getStyle().color = getResources().getColor(R.color.stats_bar_graph_main_series);
mCurrentSeriesOnScreen.getStyle().highlightColor = getResources().getColor(R.color.stats_bar_graph_main_series_highlight);
mCurrentSeriesOnScreen.getStyle().outerhighlightColor = getResources().getColor(R.color.stats_bar_graph_outer_highlight);
mCurrentSeriesOnScreen.getStyle().padding = DisplayUtils.dpToPx(this, 5);
StatsBarGraph mGraphView;
if (mGraphContainer.getChildCount() >= 1 && mGraphContainer.getChildAt(0) instanceof GraphView) {
mGraphView = (StatsBarGraph) mGraphContainer.getChildAt(0);
} else {
mGraphContainer.removeAllViews();
mGraphView = new StatsBarGraph(this);
mGraphContainer.addView(mGraphView);
}
mGraphView.removeAllSeries();
mGraphView.addSeries(mCurrentSeriesOnScreen);
//mGraphView.getGraphViewStyle().setNumHorizontalLabels(getNumOfHorizontalLabels(dataToShowOnGraph.length));
mGraphView.getGraphViewStyle().setNumHorizontalLabels(dataToShowOnGraph.length);
mGraphView.getGraphViewStyle().setMaxColumnWidth(DisplayUtils.dpToPx(this, StatsConstants.STATS_GRAPH_BAR_MAX_COLUMN_WIDTH_DP));
mGraphView.setHorizontalLabels(horLabels);
mGraphView.setGestureListener(this);
// Only happens on 720DP tablets
if (mPrevNumberOfBarsGraph != -1 && mPrevNumberOfBarsGraph != dataToShowOnGraph.length) {
mSelectedBarGraphIndex = dataToShowOnGraph.length - 1;
} else {
mSelectedBarGraphIndex = (mSelectedBarGraphIndex != -1) ? mSelectedBarGraphIndex : dataToShowOnGraph.length - 1;
}
mGraphView.highlightBar(mSelectedBarGraphIndex);
mPrevNumberOfBarsGraph = dataToShowOnGraph.length;
setMainViewsLabel(StatsUtils.parseDate(mStatsDate[mSelectedBarGraphIndex], StatsConstants.STATS_INPUT_DATE_FORMAT, StatsConstants.STATS_OUTPUT_DATE_MONTH_LONG_DAY_SHORT_FORMAT), dataToShowOnGraph[mSelectedBarGraphIndex].getViews());
showHideEmptyModulesIndicator(false);
mMonthsAndYearsList.setVisibility(View.VISIBLE);
List<PostViewsModel.Year> years = mRestResponseParsed.getYears();
MonthsAndYearsListAdapter monthsAndYearsListAdapter = new MonthsAndYearsListAdapter(this, years, mRestResponseParsed.getHighestMonth());
StatsUIHelper.reloadGroupViews(this, monthsAndYearsListAdapter, mYearsIdToExpandedMap, mMonthsAndYearsList);
mAveragesList.setVisibility(View.VISIBLE);
List<PostViewsModel.Year> averages = mRestResponseParsed.getAverages();
MonthsAndYearsListAdapter averagesListAdapter = new MonthsAndYearsListAdapter(this, averages, mRestResponseParsed.getHighestDayAverage());
StatsUIHelper.reloadGroupViews(this, averagesListAdapter, mAveragesIdToExpandedMap, mAveragesList);
mRecentWeeksList.setVisibility(View.VISIBLE);
List<PostViewsModel.Week> recentWeeks = mRestResponseParsed.getWeeks();
RecentWeeksListAdapter recentWeeksListAdapter = new RecentWeeksListAdapter(this, recentWeeks, mRestResponseParsed.getHighestWeekAverage());
StatsUIHelper.reloadGroupViews(this, recentWeeksListAdapter, mRecentWeeksIdToExpandedMap, mRecentWeeksList);
}
Aggregations