use of run.wallet.iota.model.Tick in project run-wallet-android by runplay.
the class ChooseSeedFragment method drawChart.
private void drawChart() {
long displayBalance = 0L;
if (Store.getCurrentWallet() != null) {
seedName.setText(Store.getCurrentSeed().name);
displayBalance = Store.getCurrentWallet().getBalanceDisplay();
}
Currency cur = Store.getDefaultCurrency(getActivity());
seedValue.setText(IotaToText.convertRawIotaAmountToDisplayText(displayBalance, true));
Ticker ticker = Store.getTicker("IOTA:" + cur.getCurrencyCode());
if (ticker != null) {
seedCurrency.setText(ticker.getIotaValString(displayBalance) + "\n" + cur.getSymbol());
DecimalFormat udf = df;
if (ticker.getLast() < 0.01)
udf = dfs;
xchangeLast.setText(udf.format(ticker.getLast()));
xchangeHigh.setText(udf.format(ticker.getHigh()));
xchangeLow.setText(udf.format(ticker.getLow()));
}
// Log.e("THIST","go 3");
chart.setNoDataText(getString(R.string.messages_no_chart_data));
chart.setNoDataTextColor(ContextCompat.getColor(getActivity(), R.color.white));
chart.setGridBackgroundColor(ContextCompat.getColor(getActivity(), R.color.colorLight));
Paint p = chart.getPaint(Chart.PAINT_INFO);
p.setColor(ContextCompat.getColor(getActivity(), AppTheme.getPrimaryDark()));
chart.getDescription().setEnabled(false);
chart.setDragDecelerationFrictionCoef(0.95f);
// chart.setExtraOffsets(15.f, 15.f, 15.f, 15.f);
chart.setHighlightPerTapEnabled(false);
chart.setEnabled(false);
chart.setTouchEnabled(false);
chart.animateX(1000);
chart.setPadding(0, 0, 0, 0);
chart.getAxisLeft().setEnabled(false);
chart.getAxisRight().setEnabled(false);
chart.getXAxis().setEnabled(false);
// chart.setZ(0.5f);
chart.zoomOut();
chart.setPinchZoom(false);
chart.setPinchZoom(false);
chart.setFocusable(false);
Legend leg = chart.getLegend();
leg.setVerticalAlignment(Legend.LegendVerticalAlignment.BOTTOM);
leg.setHorizontalAlignment(Legend.LegendHorizontalAlignment.LEFT);
leg.setOrientation(Legend.LegendOrientation.HORIZONTAL);
leg.setDrawInside(false);
leg.setEnabled(false);
List<Entry> entries = new ArrayList<Entry>();
List<Entry> entriesvol = new ArrayList<Entry>();
// Log
history = Store.getTickerHist(getActivity(), Store.getDefaultCurrency(getActivity()).getCurrencyCode(), currentStep);
double avg = 0D;
if (history != null) {
// Log.e("THIST","go 4");
List<Tick> tickers = history.getTicks();
Collections.reverse(tickers);
// double min=tickers.get(0).getLast();
double max = tickers.get(0).getLast();
double lastvol = 0;
double maxvol = 0;
double minvol = 0D;
for (int i = 0; i < tickers.size(); i++) {
double last = tickers.get(i).getLast();
double tmpvol = tickers.get(i).getVol();
if (avg == 0D) {
avg = last;
} else {
avg = (avg + last) / 2;
}
if (last > max)
max = last;
if (tmpvol > maxvol)
maxvol = tmpvol;
if (minvol == 0)
minvol = tmpvol;
else if (tmpvol < minvol)
minvol = tmpvol;
Entry e = new Entry(i * 10, Double.valueOf(last).floatValue());
entries.add(e);
}
max = Math.abs(max);
double voldivide = (100 / maxvol) / 70;
for (int i = tickers.size() - 1; i >= 0; i--) {
double tmpvol = tickers.get(i).getVol() * voldivide;
// Log.e("YUP", "vol: "+tickers.get(i).getVol()+" = " + tmpvol);
Entry ev = new Entry(i * 10, Double.valueOf(tmpvol + (0.015 * history.getStep())).floatValue());
entriesvol.add(ev);
}
Collections.reverse(entriesvol);
// add entries to dataset
LineDataSet dataSet = new LineDataSet(entries, "IOTA:" + Store.getDefaultCurrency(getActivity()).getCurrencyCode());
dataSet.setDrawCircleHole(false);
dataSet.setDrawCircles(false);
dataSet.setDrawFilled(true);
dataSet.setFillColor(getResources().getColor(AppTheme.getPrimaryDark()));
dataSet.setFillAlpha(100);
dataSet.setColor(B.getColor(getActivity(), AppTheme.getPrimary()));
// add entries to dataset
LineDataSet idataSet = new LineDataSet(entriesvol, "Vol");
idataSet.setDrawCircleHole(false);
idataSet.setDrawCircles(false);
idataSet.setDrawFilled(true);
idataSet.setFillColor(getResources().getColor(R.color.colorMiddle));
idataSet.setColor(B.getColor(getActivity(), AppTheme.getPrimaryDark()));
idataSet.setFillAlpha(100);
ArrayList<ILineDataSet> dataSets = new ArrayList<ILineDataSet>();
dataSets.add(dataSet);
dataSets.add(idataSet);
LineData lineData = new LineData(dataSets);
chart.setData(lineData);
float gomin = Double.valueOf(0).floatValue();
float gomax = +Double.valueOf(max * 1.4).floatValue();
chart.getAxisLeft().setAxisMinimum(gomin);
chart.getAxisLeft().setAxisMaximum(gomax);
chart.getAxisRight().setAxisMinimum(gomin);
chart.getAxisRight().setAxisMaximum(gomax);
}
// refresh
chart.invalidate();
}
Aggregations