Android Open Source - makler Symbols






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  .j  av a 2 s  .c o m*/
import java.util.ArrayList;
import java.util.List;

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.gpw.QuotesReceiver;
import pl.net.newton.Makler.gpw.ex.GpwException;
import pl.net.newton.Makler.history.service.HistoryService;
import pl.net.newton.Makler.ui.adapter.SymbolsAdapter;
import pl.net.newton.Makler.common.DateFormatUtils;
import android.app.Activity;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;

public class Symbols extends AbstractActivity implements OnItemClickListener {
  private List<Symbol> symbols;

  private ListView symbolsList;

  private boolean forWalletSell = false;

  private boolean forceUpdate;

  private boolean refreshList;

  private WalletDb walletDb;

  private SymbolsDb symbolsDb;

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.symbols);
    symbolsList = (ListView) findViewById(R.id.symbolsListView);
    symbolsList.setOnItemClickListener(this);

    if (getIntent().getBooleanExtra("update", false)) {
      forceUpdate = true;
    } else if (getIntent().getBooleanExtra("forWalletSell", false)) {
      forWalletSell = true;
      findViewById(R.id.symbolsSearchRow).setVisibility(View.GONE);
    } else {
      refreshList = true;
    }

    EditText findSymbolName = (EditText) findViewById(R.id.findSymbolName);
    findSymbolName.addTextChangedListener(new TextWatcher() {
      @Override
      public void onTextChanged(CharSequence s, int start, int before, int count) {
        refreshList();
      }

      @Override
      public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        // do nothing
      }

      @Override
      public void afterTextChanged(Editable s) {
        // do nothing
      }
    });

    setTitle("Walory");
  }

  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.symbols_menu, menu);
    return true;
  }

  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == R.id.refreshSymbols) {
      updateSymbols();
    }

    return super.onOptionsItemSelected(item);
  }

  public void refreshList() {
    if (walletDb == null || symbolsDb == null) {
      return;
    }

    EditText findSymbolName = (EditText) findViewById(R.id.findSymbolName);
    String name = findSymbolName.getText().toString();

    if (forWalletSell) {
      symbols = new ArrayList<Symbol>();
      for (WalletItem item : walletDb.getWalletItems()) {
        symbols.add(symbolsDb.getSymbolBySymbol(item.getSymbol()));
      }
    } else {
      symbols = symbolsDb.getSymbols(name);
    }

    symbolsList.setAdapter(new SymbolsAdapter(this, symbols));
  }

  public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    Intent resultIntent = new Intent();
    resultIntent.putExtra("symbol", symbols.get(position).getSymbol());
    setResult(Activity.RESULT_OK, resultIntent);
    finish();
  }

  private void updateSymbols() {
    perform(new ProcessPerformer() {
      public void showResults(boolean result) {
        refreshList();
      }

      public boolean perform(QuotesReceiver quotesReceiver) throws GpwException {
        List<Symbol> updatedSymbols;
        updatedSymbols = quotesReceiver.getSymbols();
        if (updatedSymbols != null) {
          config.setLastSymbolsUpdated(DateFormatUtils.formatCurrentDate());
          symbolsDb.updateSymbols(updatedSymbols);
          return true;
        } else {
          return false;
        }
      }
    }, true);
  }

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

    if (forceUpdate) {
      updateSymbols();
    }
    if (refreshList || forWalletSell) {
      refreshList();
    }
  }

}




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