Android Open Source - makler Makler Graphical View






From Project

Back to project page makler.

License

The source code is released under:

GNU General Public License

If you think the Android project makler listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package pl.net.newton.Makler.ui.graph;
//  w  w  w . j  a  va  2  s  .c  o  m
import java.math.BigDecimal;
import java.util.Locale;

import org.achartengine.GraphicalView;
import org.achartengine.chart.AbstractChart;
import org.achartengine.chart.XYChart;
import org.achartengine.model.SeriesSelection;

import pl.net.newton.Makler.db.quote.Quote;
import pl.net.newton.Makler.db.quote.QuoteField;
import pl.net.newton.Makler.history.EntryListWithIndexes;
import pl.net.newton.Makler.ui.graph.GraphView.GraphRange;
import pl.net.newton.Makler.common.NumberFormatUtils;
import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.PointF;
import android.util.Log;
import android.view.MotionEvent;

/**
 * Implementacja GraphicalView z achartengine. Rysuj? na widoku zmian? w procentach dla zadanego zakresu.
 * 
 * @author Igor Andruszkiewicz
 * 
 */
@SuppressLint("ViewConstructor")
public class MaklerGraphicalView extends GraphicalView {
  private static final String TAG = "MaklerGraphicalView";

  private Paint paint = null;

  private final EntryListWithIndexes entries;

  private final Quote quote;

  private final int graphRange;

  private AbstractChart mChart;

  private double selectedValue;

  private PointF selectedPoint = null;

  public MaklerGraphicalView(Context context, AbstractChart chart, final EntryListWithIndexes entries,
      Quote quote, int graphRange) {
    super(context, chart);

    this.entries = entries;
    this.quote = quote;
    this.graphRange = graphRange;
    this.mChart = chart;

    paint = new Paint();
    paint.setAntiAlias(true);
    // Must manually scale the desired text size to match screen density
    paint.setTextSize(13 * getResources().getDisplayMetrics().density);

  }

  @Override
  protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    double change = 0;

    // For 1D graph range
    if (graphRange == GraphRange.D1) {
      final BigDecimal q = quote.getAsDecimal(QuoteField.QUOTE);
      final BigDecimal r = quote.getAsDecimal(QuoteField.REFERENCE);
      if (q != null && r != null) {
        change = (q.doubleValue() - r.doubleValue()) / r.doubleValue() * 100;
      }
    } else {
      double x1 = ((double) entries.getClose(0)) / 100;
      double x2 = ((double) entries.getClose(entries.getLength() - 1)) / 100;

      change = (x2 - x1) / x1 * 100;
    }

    if (change < 0) {
      paint.setColor(Color.RED);
    } else if (change > 0) {
      paint.setColor(Color.GREEN);
    } else {
      paint.setColor(Color.GRAY);
    }

    String text = NumberFormatUtils.formatNumber(change) + "%";
    canvas.drawText(text, canvas.getWidth() - paint.measureText(text), 19, paint);

    /**
     * Paint current selected value.
     */
    BigDecimal kurs = quote.chooseKurs();
    paint.setColor(Color.GRAY);
    if (kurs != null) {
      double value = kurs.doubleValue();
      if (value > selectedValue) {
        paint.setColor(Color.RED);
      } else if (value < selectedValue) {
        paint.setColor(Color.GREEN);
      }
    }

    if (selectedPoint != null) {
      String valueToDraw = String.format(Locale.US, "%.2f", selectedValue);

      canvas.drawText(valueToDraw, canvas.getWidth() - paint.measureText(valueToDraw), 50, paint);
      canvas.drawCircle(selectedPoint.x, selectedPoint.y, 4, paint);
    }

  }

  @Override
  public boolean onTouchEvent(MotionEvent event) {

    if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_UP) {
      selectedValue = 0.0;
      selectedPoint = null;
      repaint();
      return false;
    }

    SeriesSelection seriesSelection = getCurrentSeriesAndPointForScreeXCoordinate(event.getX());

    if (seriesSelection == null && mChart instanceof XYChart) {
      Log.d(TAG, "No chart element was clicked");
      selectedValue = 0.0;
      selectedPoint = null;
    } else {
      double[] xy = new double[2];
      xy[0] = seriesSelection.getXValue();
      xy[1] = seriesSelection.getValue();
      xy = ((XYChart) mChart).toScreenPoint(xy);
      selectedPoint = new PointF((float) xy[0], (float) xy[1]);
      selectedValue = seriesSelection.getValue();

      repaint();
    }

    return false;
  }
}




Java Source Code List

pl.net.newton.Makler.common.Configuration.java
pl.net.newton.Makler.common.DateFormatUtils.java
pl.net.newton.Makler.common.GpwUtils.java
pl.net.newton.Makler.common.LocaleUtils.java
pl.net.newton.Makler.common.NumberFormatUtils.java
pl.net.newton.Makler.db.Constants.java
pl.net.newton.Makler.db.DbHelper.java
pl.net.newton.Makler.db.SqlConnection.java
pl.net.newton.Makler.db.alert.AlertBuilder.java
pl.net.newton.Makler.db.alert.AlertChecker.java
pl.net.newton.Makler.db.alert.AlertValue.java
pl.net.newton.Makler.db.alert.Alert.java
pl.net.newton.Makler.db.alert.AlertsDao.java
pl.net.newton.Makler.db.alert.Event.java
pl.net.newton.Makler.db.alert.Subject.java
pl.net.newton.Makler.db.quote.QuoteField.java
pl.net.newton.Makler.db.quote.Quote.java
pl.net.newton.Makler.db.quote.QuotesDao.java
pl.net.newton.Makler.db.service.SqlProvider.java
pl.net.newton.Makler.db.symbol.SymbolBuilder.java
pl.net.newton.Makler.db.symbol.Symbol.java
pl.net.newton.Makler.db.symbol.SymbolsDb.java
pl.net.newton.Makler.db.wallet.WalletDb.java
pl.net.newton.Makler.db.wallet.WalletItemBuilder.java
pl.net.newton.Makler.db.wallet.WalletItem.java
pl.net.newton.Makler.gpw.DefaultQuotesReceiver.java
pl.net.newton.Makler.gpw.QuotesReceiver.java
pl.net.newton.Makler.gpw.ex.GpwException.java
pl.net.newton.Makler.gpw.service.QuotesListener.java
pl.net.newton.Makler.gpw.service.QuotesService.java
pl.net.newton.Makler.gpw.service.UpdatingThread.java
pl.net.newton.Makler.history.BossaProvider.java
pl.net.newton.Makler.history.ByteArrayUtils.java
pl.net.newton.Makler.history.Cache.java
pl.net.newton.Makler.history.ChannelTools.java
pl.net.newton.Makler.history.EntryListWithIndexes.java
pl.net.newton.Makler.history.EntryList.java
pl.net.newton.Makler.history.HistoryFilter.java
pl.net.newton.Makler.history.HistoryProvider.java
pl.net.newton.Makler.history.service.HistoryListener.java
pl.net.newton.Makler.history.service.HistoryService.java
pl.net.newton.Makler.httpClient.Connector.java
pl.net.newton.Makler.receivers.QuotesAlarmReceiver.java
pl.net.newton.Makler.receivers.StartupReceiver.java
pl.net.newton.Makler.service.ServiceManager.java
pl.net.newton.Makler.ui.About.java
pl.net.newton.Makler.ui.AbstractActivity.java
pl.net.newton.Makler.ui.Alerts.java
pl.net.newton.Makler.ui.FullScreenGraph.java
pl.net.newton.Makler.ui.Preferences.java
pl.net.newton.Makler.ui.QuoteDetails.java
pl.net.newton.Makler.ui.Quotes.java
pl.net.newton.Makler.ui.Symbols.java
pl.net.newton.Makler.ui.WalletForm.java
pl.net.newton.Makler.ui.WalletItemCalculator.java
pl.net.newton.Makler.ui.Wallet.java
pl.net.newton.Makler.ui.adapter.AlertsAdapter.java
pl.net.newton.Makler.ui.adapter.QuotesAdapter.java
pl.net.newton.Makler.ui.adapter.SymbolsAdapter.java
pl.net.newton.Makler.ui.adapter.WalletAdapter.java
pl.net.newton.Makler.ui.graph.GraphView.java
pl.net.newton.Makler.ui.graph.MaklerGraphicalView.java