Android Open Source - ShareManager Shares Adapter






From Project

Back to project page ShareManager.

License

The source code is released under:

Copyright (c) 2013, Nelspike All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Red...

If you think the Android project ShareManager 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 share.manager.adapters;
//from ww  w .  j  a v a  2  s.  co  m
import share.manager.stock.R;
import share.manager.utils.FileHandler;
import share.manager.utils.SharesGraphicsBuilder;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.TextView;

public class SharesAdapter extends ArrayAdapter<String> {

  private String[] strings, regions, shares, ticks;
  private Context context;
  private SharesGraphicsBuilder graph;

  public SharesAdapter(Context context, int textViewResourceId,
      String[] objects, String[] regions, String[] shares, String[] ticks,
      SharesGraphicsBuilder graph) {
    super(context, textViewResourceId, objects);
    this.context = context;
    this.strings = objects;
    this.regions = regions;
    this.ticks = ticks;
    this.shares = shares;
    this.graph = graph;
  }

  @Override
  public View getDropDownView(int position, View convertView, ViewGroup parent) {
    return getCustomView(position, convertView, parent);
  }

  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    return getCustomView(position, convertView, parent);
  }

  public View getCustomView(int position, View convertView, ViewGroup parent) {
    final int inner = position;
    LayoutInflater inflater = (LayoutInflater) context
        .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View row = inflater.inflate(R.layout.shares_box, parent, false);

    TextView label = (TextView) row.findViewById(R.id.shares_name_box);
    label.setText(strings[position]);

    TextView labelRegion = (TextView) row.findViewById(R.id.shares_region_box);
    labelRegion.setText(regions[position]);

    final TextView labelChange = (TextView) row
        .findViewById(R.id.shares_num_box);
    labelChange.setText(shares[position]);

    Button minus = (Button) row.findViewById(R.id.minus_share);
    minus.setOnClickListener(new OnClickListener() {

      @Override
      public void onClick(View v) {
        if (labelChange.getText().toString().equals("0")) return;

        FileHandler.changeShare(ticks[inner], false);
        labelChange.setText(FileHandler.getSharesFromTick(ticks[inner]));
        graph.repaintGraph(FileHandler.getSharePercentages(),
            FileHandler.getNamesString());
      }

    });

    Button plus = (Button) row.findViewById(R.id.plus_share);
    plus.setOnClickListener(new OnClickListener() {

      @Override
      public void onClick(View v) {
        FileHandler.changeShare(ticks[inner], true);
        labelChange.setText(FileHandler.getSharesFromTick(ticks[inner]));
        graph.repaintGraph(FileHandler.getSharePercentages(),
            FileHandler.getNamesString());
      }

    });

    return row;
  }
}




Java Source Code List

share.manager.adapters.CompanyAdapter.java
share.manager.adapters.DialogAdapter.java
share.manager.adapters.MainPagerAdapter.java
share.manager.adapters.SharesAdapter.java
share.manager.connection.ConnectionRunnable.java
share.manager.connection.ConnectionThread.java
share.manager.fragments.MineFragment.java
share.manager.fragments.PortfolioFragment.java
share.manager.fragments.SharesFragment.java
share.manager.listeners.ShareTabListener.java
share.manager.listeners.SwipeListener.java
share.manager.stock.CompanyActivity.java
share.manager.stock.MainActivity.java
share.manager.stock.ResultsActivity.java
share.manager.stock.SettingsActivity.java
share.manager.stock.ShareManager.java
share.manager.utils.CompanyGraphicsBuilder.java
share.manager.utils.FileHandler.java
share.manager.utils.GraphType.java
share.manager.utils.RESTFunction.java
share.manager.utils.ShareUtils.java
share.manager.utils.SharesGraphicsBuilder.java