Android Open Source - UnitConverterUltimate-Studio Converter Pager Adapter






From Project

Back to project page UnitConverterUltimate-Studio.

License

The source code is released under:

GNU General Public License

If you think the Android project UnitConverterUltimate-Studio 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 com.physphil.android.unitconverterultimate.ui;
//w  w  w.j av  a2 s.c  o  m
import android.content.Context;
import android.content.res.TypedArray;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

import com.physphil.android.unitconverterultimate.R;
import com.physphil.android.unitconverterultimate.util.Constants;
import com.physphil.android.unitconverterultimate.util.Conversions;

public class ConverterPagerAdapter extends FragmentPagerAdapter{
  
//  private final int PAGE_COUNT = 14;
  private Context mContext;
  private String[] mConversions;

  public ConverterPagerAdapter(FragmentManager fm, Context context) {
    super(fm);
    mContext = context;
    mConversions = mContext.getResources().getStringArray(R.array.conversions);
  }
  
  @Override
  public int getCount() {
    return mConversions.length;
  }

  @Override
  public Fragment getItem(int position) {
    Bundle data = new Bundle();

    //Get info required to create appropriate fragment
    String[] fragmentNames = mContext.getResources().getStringArray(R.array.fragmentNames);
    String[] fromButtonTags = mContext.getResources().getStringArray(R.array.fromButtonTags);
    String[] toButtonTags = mContext.getResources().getStringArray(R.array.toButtonTags);
    TypedArray fromButtonGroupIds = mContext.getResources().obtainTypedArray(R.array.fromRadioGroupIds);
    TypedArray toButtonGroupIds = mContext.getResources().obtainTypedArray(R.array.toRadioGroupIds);
    TypedArray fragmentLayouts = mContext.getResources().obtainTypedArray(R.array.fragmentLayouts);
    
    ConversionFragment conversionFragment = new ConversionFragment();
    data.putInt(fragmentNames[position], position+1);
    data.putInt(Constants.FRAGMENT_LAYOUT, fragmentLayouts.getResourceId(position, 0));
    data.putString(Constants.FRAGMENT_FROM_BUTTON_TAG, fromButtonTags[position]);
    data.putString(Constants.FRAGMENT_TO_BUTTON_TAG, toButtonTags[position]);
    data.putInt(Constants.FRAGMENT_FROM_BUTTONS_ID, fromButtonGroupIds.getResourceId(position, 0));
    data.putInt(Constants.FRAGMENT_TO_BUTTONS_ID, toButtonGroupIds.getResourceId(position, 0));
    
    if(position == Conversions.TEMPERATURE){
      data.putBoolean(Constants.FRAGMENT_IS_TEMPERATURE, true);
    }
    else{
      data.putBoolean(Constants.FRAGMENT_IS_TEMPERATURE, false);
    }
    
    //Pass arguments to fragment
    conversionFragment.setArguments(data);
    
    //Recycle typed arrays
    fromButtonGroupIds.recycle();
    toButtonGroupIds.recycle();
    fragmentLayouts.recycle();
    
    //Return newly-created fragment
    return conversionFragment;
  }
  
  @Override
  public CharSequence getPageTitle(int position){
    return mConversions[position];
  }

}




Java Source Code List

com.physphil.android.unitconverterultimate.DonateActivity.java
com.physphil.android.unitconverterultimate.DonateFragment.java
com.physphil.android.unitconverterultimate.MainActivity.java
com.physphil.android.unitconverterultimate.iab.Base64DecoderException.java
com.physphil.android.unitconverterultimate.iab.Base64.java
com.physphil.android.unitconverterultimate.iab.IabException.java
com.physphil.android.unitconverterultimate.iab.IabHelper.java
com.physphil.android.unitconverterultimate.iab.IabResult.java
com.physphil.android.unitconverterultimate.iab.Inventory.java
com.physphil.android.unitconverterultimate.iab.Purchase.java
com.physphil.android.unitconverterultimate.iab.Security.java
com.physphil.android.unitconverterultimate.iab.SkuDetails.java
com.physphil.android.unitconverterultimate.ui.ConversionFragment.java
com.physphil.android.unitconverterultimate.ui.ConverterPagerAdapter.java
com.physphil.android.unitconverterultimate.ui.DonationListAdapter.java
com.physphil.android.unitconverterultimate.ui.SetDecimalSeparatorDialogFragment.java
com.physphil.android.unitconverterultimate.ui.SetDecimalsDialogFragment.java
com.physphil.android.unitconverterultimate.ui.SetSeparatorDialogFragment.java
com.physphil.android.unitconverterultimate.util.ChangeUnitListener.java
com.physphil.android.unitconverterultimate.util.Constants.java
com.physphil.android.unitconverterultimate.util.Conversions.java
com.physphil.android.unitconverterultimate.util.Convert.java
com.physphil.android.unitconverterultimate.util.Globals.java
com.physphil.android.unitconverterultimate.util.Util.java