Android Open Source - makler Wallet Form






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;
/*w  ww  . jav  a 2 s. com*/
import java.math.BigDecimal;

import org.apache.commons.lang3.StringUtils;

import pl.net.newton.Makler.R;
import pl.net.newton.Makler.db.symbol.Symbol;
import pl.net.newton.Makler.db.symbol.SymbolsDb;
import pl.net.newton.Makler.db.wallet.WalletDb;
import pl.net.newton.Makler.db.wallet.WalletItem;
import pl.net.newton.Makler.history.service.HistoryService;
import android.app.Activity;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.RadioButton;

public class WalletForm extends AbstractActivity implements OnClickListener {

  private RadioButton kupno, sprzedaz;

  private EditText walor, ilosc, kurs;

  private SymbolsDb symbolsDb;

  private WalletDb walletDb;

  public static final int GET_SYMBOL_K = 200;

  public static final int GET_SYMBOL_S = 201;

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.wallet_trans);

    kupno = (RadioButton) findViewById(R.id.transTypeK);
    sprzedaz = (RadioButton) findViewById(R.id.transTypeS);
    ilosc = (EditText) findViewById(R.id.transIlosc);
    walor = (EditText) findViewById(R.id.transWalor);
    kurs = (EditText) findViewById(R.id.transKurs);

    findViewById(R.id.transWalorBtn).setOnClickListener(new OnClickListener() {
      public void onClick(View v) {
        Intent intent = new Intent(v.getContext(), Symbols.class);
        if (kupno.isChecked()) {
          startActivityForResult(intent, GET_SYMBOL_K);
        } else if (sprzedaz.isChecked()) {
          intent.putExtra("forWalletSell", true);
          startActivityForResult(intent, GET_SYMBOL_S);
        }
      }
    });

    findViewById(R.id.transDodaj).setOnClickListener(this);

    String symbol = getIntent().getStringExtra("symbol");
    String quote = getIntent().getStringExtra("quote");
    if (symbol != null) {
      this.walor.setText(symbol);
    }
    if (quote != null) {
      this.kurs.setText(quote.replace(',', '.').replaceAll("[^0-9\\.]", ""));
    }

  }

  @Override
  public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if ((requestCode == GET_SYMBOL_K || requestCode == GET_SYMBOL_S) && resultCode == Activity.RESULT_OK) {
      String symbol = data.getStringExtra("symbol");
      walor.setText(symbol);
    }
  }

  public void onClick(View v) {
    Character type = null;
    if (kupno.isChecked()) {
      type = 'K';
    } else if (sprzedaz.isChecked()) {
      type = 'S';
    }
    final String name = this.walor.getText().toString();
    final String quantity = this.ilosc.getText().toString();
    final String quote = this.kurs.getText().toString();
    if (StringUtils.isAnyEmpty(name, quantity, quote) || type == null) {
      return;
    }
    if (addTransaction(quantity, quote, type, name)) {
      Intent resultIntent = new Intent();
      setResult(Activity.RESULT_OK, resultIntent);
      finish();
    }

  }

  private boolean addTransaction(String quantity, String quote, Character type, String symbolName) {
    Symbol s = symbolsDb.getSymbolBySymbol(symbolName);
    if (s == null) {
      return false;
    }
    if (s.isIndex()) {
      showMessage("Nie mo?esz przeprowadzi? transakcji z indeksem");
      return false;
    }
    WalletItem item = walletDb.getWalletItem(s);
    String q = quantity;
    if (type == 'S' && item.getQuantity() < Integer.parseInt(quantity)) {
      q = item.getQuantity().toString();
    }

    BigDecimal commision = config.getCommision();
    BigDecimal minCommision = config.getMinCommision();
    BigDecimal account = config.getWalletAccount();
    BigDecimal value = new BigDecimal(quote).multiply(new BigDecimal(q));
    BigDecimal com = value.divide(new BigDecimal(100)).multiply(commision);
    if (com.compareTo(minCommision) < 0) {
      com = minCommision;
    }
    account = account.subtract(com);
    if (type == 'K') {
      account = account.subtract(value);
    } else {
      account = account.add(value);
    }

    item.addTrans(type, Integer.parseInt(quantity), new BigDecimal(quote.replace(" ", "")), com);
    walletDb.updateWalletItem(item);
    config.setWalletAccount(account.toString());
    return true;
  }

  @Override
  protected void initUi(SQLiteDatabase sqlDb, HistoryService historyService) {
    this.walletDb = new WalletDb(sqlDb, this);
    this.symbolsDb = new SymbolsDb(sqlDb, this);
  }
}




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