Android Open Source - trivial-password Account Pager Activity






From Project

Back to project page trivial-password.

License

The source code is released under:

MIT License

If you think the Android project trivial-password 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 org.hbabcock.trivialpassword;
/*  w  w  w  .j  av  a 2s. c  o m*/
import java.util.ArrayList;
import java.util.UUID;

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.FragmentStatePagerAdapter;
import android.support.v4.view.ViewPager;

public class AccountPagerActivity extends FragmentActivity {
  private ArrayList<Account> mAccounts;
  private ViewPager mViewPager;
  private Boolean mNewAccount;
  
  @Override
  public void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_account_pager);
    
    mAccounts = AccountManager.get(this).getAccounts();
    
    FragmentManager fm = getSupportFragmentManager();
    mViewPager = (ViewPager)findViewById(R.id.pager);
    mViewPager.setAdapter(new FragmentStatePagerAdapter(fm){
      @Override
      public int getCount(){
        return mAccounts.size();
      }
      
      @Override
      public Fragment getItem(int pos){
        Account a = mAccounts.get(pos);
        Fragment f = AccountFragment.newInstance(a.getId(), mNewAccount);
        mNewAccount = false;
        return f;
      }
    });
    mViewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener(){
      public void onPageScrollStateChanged(int state){}
      
      public void onPageScrolled(int pos, float posOffset, int posOffsetPixels){}
      
      public void onPageSelected(int pos){
        Account a = mAccounts.get(pos);
        if (a.getAccount() != null){
          setTitle(a.getAccount());
        }
      }
    });
    
    UUID aId = (UUID)getIntent().getSerializableExtra(AccountFragment.EXTRA_ACCOUNT_ID);
    mNewAccount = (Boolean)getIntent().getSerializableExtra(AccountFragment.EXTRA_NEW_ACCOUNT);
    for (int i=0;i<mAccounts.size();i++){
      if (mAccounts.get(i).getId().equals(aId)){
        mViewPager.setCurrentItem(i);
        break;
      }
    }
  }
}




Java Source Code List

org.hbabcock.trivialpassword.AccountEditorFragment.java
org.hbabcock.trivialpassword.AccountFragment.java
org.hbabcock.trivialpassword.AccountListActivity.java
org.hbabcock.trivialpassword.AccountListFragment.java
org.hbabcock.trivialpassword.AccountManager.java
org.hbabcock.trivialpassword.AccountPagerActivity.java
org.hbabcock.trivialpassword.Account.java
org.hbabcock.trivialpassword.PasswordActivity.java
org.hbabcock.trivialpassword.PasswordChangeFragment.java
org.hbabcock.trivialpassword.PasswordFragment.java
org.hbabcock.trivialpassword.PasswordManager.java
org.hbabcock.trivialpassword.SingleFragmentActivity.java
org.hbabcock.trivialpassword.TrivialPasswordJSONSerializer.java