Android Open Source - bankomatinfos Result Activity






From Project

Back to project page bankomatinfos.

License

The source code is released under:

GNU General Public License

If you think the Android project bankomatinfos 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 at.zweng.bankomatinfos.ui;
//w w w .  j av a 2 s . c om
import static at.zweng.bankomatinfos.util.Utils.showAboutDialog;
import static at.zweng.bankomatinfos.util.Utils.showChangelogDialog;

import java.util.Locale;

import android.app.ActionBar;
import android.app.FragmentTransaction;
import android.content.ComponentName;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ShareActionProvider;
import at.zweng.bankomatinfos.AppController;
import at.zweng.bankomatinfos2.R;

// TODO: maybe also add share action for general and transations fragment

/**
 * Activity for displaying the results (hosts fragements in tabs).
 * 
 * @author Johannes Zweng <johannes@zweng.at>
 */
public class ResultActivity extends FragmentActivity implements
    ActionBar.TabListener {

  private static AppController _controller = AppController.getInstance();
  private Fragment _fragmentResultInfos;
  private Fragment _fragmentResultEmxTxList;
  private Fragment _fragmentResultQuickTxList;
  private Fragment _fragmentResultLog;
  private boolean _showQuickLog;
  private boolean _showEmvLog;
  private int _numLogTabs;

  /**
   * The {@link android.support.v4.view.PagerAdapter} that will provide
   * fragments for each of the sections. We use a
   * {@link android.support.v4.app.FragmentPagerAdapter} derivative, which
   * will keep every loaded fragment in memory. If this becomes too memory
   * intensive, it may be best to switch to a
   * {@link android.support.v4.app.FragmentStatePagerAdapter}.
   */
  private SectionsPagerAdapter _sectionsPagerAdapter;

  /**
   * The {@link ViewPager} that will host the section contents.
   */
  private ViewPager _viewPager;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_result);
    _showQuickLog = (_controller.getCardInfoNullSafe(this).getQuickLog()
        .size() > 0);
    _showEmvLog = _controller.getCardInfoNullSafe(this).isEmvCard();
    if (_showEmvLog && _showQuickLog) {
      _numLogTabs = 2;
    } else {
      _numLogTabs = 1;
    }
    _fragmentResultInfos = new ResultInfosListFragment();
    if (_showEmvLog) {
      _fragmentResultEmxTxList = new ResultEmvTxListFragment();
    }
    if (_showQuickLog) {
      _fragmentResultQuickTxList = new ResultQuickTxListFragment();
    }
    _fragmentResultLog = new ResultLogFragment();

    // Set up the action bar.
    final ActionBar actionBar = getActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    // Create the adapter that will return a fragment for each of the
    // primary sections of the app.
    _sectionsPagerAdapter = new SectionsPagerAdapter(
        getSupportFragmentManager());

    // Set up the ViewPager with the sections adapter.
    _viewPager = (ViewPager) findViewById(R.id.pager);
    _viewPager.setAdapter(_sectionsPagerAdapter);

    // When swiping between different sections, select the corresponding
    // tab. We can also use ActionBar.Tab#select() to do this if we have
    // a reference to the Tab.
    _viewPager
        .setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
          @Override
          public void onPageSelected(int position) {
            actionBar.setSelectedNavigationItem(position);
          }
        });

    // For each of the sections in the app, add a tab to the action bar.
    for (int i = 0; i < _sectionsPagerAdapter.getCount(); i++) {
      // Create a tab with text corresponding to the page title defined by
      // the adapter. Also specify this Activity object, which implements
      // the TabListener interface, as the callback (listener) for when
      // this tab is selected.
      actionBar.addTab(actionBar.newTab()
          .setText(_sectionsPagerAdapter.getPageTitle(i))
          .setTabListener(this));
    }
  }

  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main_menu, menu);
    // Locate MenuItem with ShareActionProvider
    MenuItem item = menu.findItem(R.id.action_share);
    // Fetch and store ShareActionProvider
    ShareActionProvider shareActionProvider = (ShareActionProvider) item
        .getActionProvider();

    // set the log content as share content
    Intent shareIntent = new Intent();
    shareIntent.setAction(Intent.ACTION_SEND);
    shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,
        getResources().getString(R.string.action_share_subject));
    shareIntent.putExtra(Intent.EXTRA_TEXT, AppController.getInstance()
        .getLog());
    shareIntent.setType("text/plain");
    shareActionProvider.setShareIntent(shareIntent);
    return true;
  }

  /**
   * Called whenever we call invalidateOptionsMenu()
   */
  @Override
  public boolean onPrepareOptionsMenu(Menu menu) {
    // show share action only on Tab 2 (Log)
    // (tab index starts with 0)
    if (_viewPager.getCurrentItem() == 2 && _numLogTabs == 1) {
      menu.findItem(R.id.action_share).setVisible(true);
    } else if (_viewPager.getCurrentItem() == 3 && _numLogTabs == 2) {
      menu.findItem(R.id.action_share).setVisible(true);
    } else {
      menu.findItem(R.id.action_share).setVisible(false);
    }
    return true;
  }

  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.action_about:
      showAboutDialog(getFragmentManager());
      return true;
    case R.id.action_changelog:
      showChangelogDialog(getFragmentManager(), true);
      return true;
    case R.id.action_settings:
      Intent i = new Intent();
      i.setComponent(new ComponentName(getApplicationContext(),
          SettingsActivity.class));
      startActivity(i);
      return true;
    }
    return false;
  }

  @Override
  public void onTabSelected(ActionBar.Tab tab,
      FragmentTransaction fragmentTransaction) {
    // When the given tab is selected, switch to the corresponding page in
    // the ViewPager.
    _viewPager.setCurrentItem(tab.getPosition());
    invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
  }

  @Override
  public void onTabUnselected(ActionBar.Tab tab,
      FragmentTransaction fragmentTransaction) {
  }

  @Override
  public void onTabReselected(ActionBar.Tab tab,
      FragmentTransaction fragmentTransaction) {
  }

  /**
   * A {@link FragmentPagerAdapter} that returns a fragment corresponding to
   * one of the sections/tabs/pages.
   */
  public class SectionsPagerAdapter extends FragmentPagerAdapter {

    public SectionsPagerAdapter(FragmentManager fm) {
      super(fm);
    }

    @Override
    public Fragment getItem(int position) {
      if (position == 0) {
        return _fragmentResultInfos;
      } else if (position == 1 && _showEmvLog) {
        return _fragmentResultEmxTxList;
      } else if (position == 1 && !_showEmvLog && _showQuickLog) {
        return _fragmentResultQuickTxList;
      } else if (position == 2 && _showEmvLog && _showQuickLog) {
        return _fragmentResultQuickTxList;
      } else {
        return _fragmentResultLog;
      }
    }

    @Override
    public int getCount() {
      return 2 + _numLogTabs;
    }

    @Override
    public CharSequence getPageTitle(int position) {
      Locale locale = Locale.getDefault();

      if (position == 0) {
        return getString(R.string.title_section_infos).toUpperCase(locale);
      } else if (position == 1 && _showEmvLog) {
        return getString(R.string.title_section_emv_logs).toUpperCase(locale);
      } else if (position == 1 && !_showEmvLog && _showQuickLog) {
        return getString(R.string.title_section_quick_logs).toUpperCase(locale);
      } else if (position == 2 && _showEmvLog && _showQuickLog) {
        return getString(R.string.title_section_quick_logs).toUpperCase(locale);
      } else {
        return getString(R.string.title_section_debug_log).toUpperCase(locale);
      }
    }
  }

}




Java Source Code List

at.zweng.bankomatinfos.AppController.java
at.zweng.bankomatinfos.exceptions.NoSmartCardException.java
at.zweng.bankomatinfos.exceptions.TlvParsingException.java
at.zweng.bankomatinfos.iso7816emv.BERTLV.java
at.zweng.bankomatinfos.iso7816emv.ByteArrayWrapper.java
at.zweng.bankomatinfos.iso7816emv.CPLC.java
at.zweng.bankomatinfos.iso7816emv.EMVTags.java
at.zweng.bankomatinfos.iso7816emv.EmvTag.java
at.zweng.bankomatinfos.iso7816emv.EmvUtils.java
at.zweng.bankomatinfos.iso7816emv.GPTags.java
at.zweng.bankomatinfos.iso7816emv.Iso3166CountryCodes.java
at.zweng.bankomatinfos.iso7816emv.Iso4217CurrencyCodes.java
at.zweng.bankomatinfos.iso7816emv.NfcBankomatCardReader.java
at.zweng.bankomatinfos.iso7816emv.TagAndValue.java
at.zweng.bankomatinfos.iso7816emv.TagImpl.java
at.zweng.bankomatinfos.iso7816emv.TagType.java
at.zweng.bankomatinfos.iso7816emv.TagValueType.java
at.zweng.bankomatinfos.model.AbstractTransactionLogEntry.java
at.zweng.bankomatinfos.model.CardInfo.java
at.zweng.bankomatinfos.model.EmvTransactionLogEntry.java
at.zweng.bankomatinfos.model.InfoKeyValuePair.java
at.zweng.bankomatinfos.model.QuickTransactionLogEntry.java
at.zweng.bankomatinfos.ui.AboutDialogFragment.java
at.zweng.bankomatinfos.ui.ChangelogDialogFragment.java
at.zweng.bankomatinfos.ui.ListAdapterEmvTransactions.java
at.zweng.bankomatinfos.ui.ListAdapterInfos.java
at.zweng.bankomatinfos.ui.ListAdapterQuickTransactions.java
at.zweng.bankomatinfos.ui.MainActivity.java
at.zweng.bankomatinfos.ui.NfcDisabledActivity.java
at.zweng.bankomatinfos.ui.ResultActivity.java
at.zweng.bankomatinfos.ui.ResultEmvTxListFragment.java
at.zweng.bankomatinfos.ui.ResultInfosListFragment.java
at.zweng.bankomatinfos.ui.ResultLogFragment.java
at.zweng.bankomatinfos.ui.ResultQuickTxListFragment.java
at.zweng.bankomatinfos.ui.SettingsActivity.java
at.zweng.bankomatinfos.util.ChangeLog.java
at.zweng.bankomatinfos.util.CustomAlertDialog.java
at.zweng.bankomatinfos.util.Utils.java