Android Open Source - makler Symbols Adapter






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.adapter;
//ww w  .  ja v a  2 s  .co  m
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import pl.net.newton.Makler.R;
import pl.net.newton.Makler.db.symbol.Symbol;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.SectionIndexer;
import android.widget.TextView;

public class SymbolsAdapter extends BaseAdapter implements SectionIndexer {
  private LayoutInflater mInflater;

  private List<Symbol> symbols;

  private Map<Character, Integer> sectionBegins;

  private List<Character> sections;

  public SymbolsAdapter(Context context, List<Symbol> symbols) {
    mInflater = LayoutInflater.from(context);
    this.symbols = symbols;
    sectionBegins = new HashMap<Character, Integer>();
    sections = new ArrayList<Character>();
    Character c = null;
    for (int i = 0; i < symbols.size(); i++) {
      Symbol s = symbols.get(i);
      if (s.getSymbol().length() == 0) {
        continue;
      }
      Character d = s.getSymbol().charAt(0);
      if (d != c) {
        sectionBegins.put(d, i);
        sections.add(d);
        c = d;
      }
    }
  }

  public int getCount() {
    return symbols.size();
  }

  public Object getItem(int position) {
    return symbols.get(position);
  }

  public long getItemId(int position) {
    return position;
  }

  public View getView(int position, View view, ViewGroup parent) {
    ViewHolder holder;
    View convertView = view;
    if (convertView == null) {
      convertView = mInflater.inflate(R.layout.symbol_item, null);
      holder = new ViewHolder();
      holder.symbol = (TextView) convertView.findViewById(R.id.symbolItemSymbol);
      holder.name = (TextView) convertView.findViewById(R.id.symbolItemName);
      convertView.setTag(holder);
    } else {
      holder = (ViewHolder) convertView.getTag();
    }

    Symbol symbol = symbols.get(position);
    holder.symbol.setText(symbol.getSymbol());
    if (symbol.isIndex()) {
      holder.name.setText("");
    } else {
      holder.name.setText(symbol.getName());
    }
    return convertView;
  }

  static class ViewHolder {
    TextView symbol;

    TextView name;
  }

  public int getPositionForSection(int i) {
    return sectionBegins.get(sections.get(i));
  }

  public int getSectionForPosition(int i) {
    for (int j = 0; j < sections.size(); j++) {
      int pos = getPositionForSection(j);
      if (pos > i) {
        return j - 1;
      }
    }
    return sections.size() - 1;
  }

  public Object[] getSections() {
    return sections.toArray();
  }
}




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