package com.qloudfin.jpaybusiness.pos;
import android.app.ActionBar;
import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.content.Intent;
import android.content.res.TypedArray;
import android.content.res.Resources.Theme;
import android.view.Menu;
import android.view.MenuItem;
import com.qloudfin.jpaywallet.R;
import com.qloudfin.jpaywallet.card.MyCardActivity;
import com.qloudfin.jpaywallet.card.NewCardActivity;
import com.qloudfin.jpaywallet.common.TabbedActivity;
import com.qloudfin.jpaywallet.scan.ActivityIntegrator;
import com.qloudgen.qwidget.internal.FragmentPagerAdapter;
import com.qloudgen.qwidget.internal.ViewPager;
/*
* ------刷卡 功能模块--------
*/
public class PosActivity extends TabbedActivity {
private ViewPager mViewPager;
private ViewPagerAdapter mViewPagerAdapter;
private CardDetailFragment fr1 = new CardDetailFragment();
private ConsumeFragment fr2 = new ConsumeFragment();
private AwardFragment fr3 = new AwardFragment();
private static final int TAB_INDEX_COUNT = 3;
private static final int TAB_INDEX_ONE = 0;
private static final int TAB_INDEX_TWO = 1;
private static final int TAB_INDEX_THREE = 2;
@Override
protected void setupTab() {
setContentView(R.layout.ac_container);
ActionBar ab = getActionBar();
ab.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
setUpViewPager();
setUpTabs();
}
// 使用下面的响应方法,需要在TabbedActivity中实现ActionBar.TabListener方法。
@Override
public void onTabSelected(ActionBar.Tab tab, FragmentTransaction ft) {
mViewPager.setCurrentItem(tab.getPosition());
}
private void setUpTabs() {
final ActionBar actionBar = getActionBar();
for (int i = 0; i < mViewPagerAdapter.getCount(); ++i) {
actionBar.addTab(actionBar.newTab()
.setText(mViewPagerAdapter.getPageTitle(i))
.setTabListener(this));
}
}
@Override
protected void onDestroy() {
super.onDestroy();
}
private void setUpViewPager() {
mViewPagerAdapter = new ViewPagerAdapter(getFragmentManager());
mViewPager = (ViewPager) findViewById(R.id.viewPager);
mViewPager.setAdapter(mViewPagerAdapter);
mViewPager
.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
@Override
public void onPageSelected(int position) {
final ActionBar actionBar = getActionBar();
actionBar.setSelectedNavigationItem(position);
}
@Override
public void onPageScrollStateChanged(int state) {
switch (state) {
case ViewPager.SCROLL_STATE_IDLE:
// TODO
break;
case ViewPager.SCROLL_STATE_DRAGGING:
// TODO
break;
case ViewPager.SCROLL_STATE_SETTLING:
// TODO
break;
default:
// TODO
break;
}
}
});
}
public class ViewPagerAdapter extends FragmentPagerAdapter {
public ViewPagerAdapter(FragmentManager fm) {
super(fm);
// TODO Auto-generated constructor stub
}
@Override
public Fragment getItem(int position) {
// TODO Auto-generated method stub
switch (position) {
case TAB_INDEX_ONE:
return fr1;
case TAB_INDEX_TWO:
return fr2;
case TAB_INDEX_THREE:
return fr3;
}
throw new IllegalStateException("No fragment at position "
+ position);
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return TAB_INDEX_COUNT;
}
@Override
public CharSequence getPageTitle(int position) {
String tabLabel = null;
switch (position) {
case TAB_INDEX_ONE:
tabLabel = getString(R.string.carddetail);
break;
case TAB_INDEX_TWO:
tabLabel = getString(R.string.consume);
break;
case TAB_INDEX_THREE:
tabLabel = getString(R.string.award);
break;
}
return tabLabel;
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuItem mi = menu.add(Menu.NONE, R.id.new_card_scan, 50, "new");
mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
TypedArray a = getTheme().obtainStyledAttributes(
new int[] { R.attr.ic_scan });
int rid = a.getResourceId(0, 0);
a.recycle();
if (rid > 0)
mi.setIcon(rid);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.new_card_scan:
ActivityIntegrator integrator = new ActivityIntegrator(this);
integrator.initiateScan();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
}
actionBar + viewPager实现活动tab
最新推荐文章于 2024-06-13 18:29:53 发布