use of android.support.design.widget.TabLayout in project MadMax by deviz92.
the class ExpenseDetailActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_expense_detail);
Intent intent = getIntent();
groupID = intent.getStringExtra("groupID");
userID = intent.getStringExtra("userID");
expenseID = intent.getStringExtra("expenseID");
fab = (FloatingActionButton) findViewById(R.id.fab);
updateFab(0);
toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
toolbar.setBackgroundColor(0x0000FF00);
// Get a support ActionBar corresponding to this toolbar
ActionBar ab = getSupportActionBar();
// Enable the Up button
ab.setDisplayHomeAsUpEnabled(true);
// insert tabs and current fragment in the main layout
// mainView.addView(getLayoutInflater().inflate(R.layout.activity_expense_detail, null));
TabLayout tabLayout = (TabLayout) findViewById(R.id.tab_layout);
tabLayout.addTab(tabLayout.newTab().setText(R.string.expense_detail));
tabLayout.addTab(tabLayout.newTab().setText(R.string.comments));
tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);
viewPager = (ViewPager) findViewById(R.id.expense_detail_view_pager);
viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
@Override
public void onTabSelected(TabLayout.Tab tab) {
Log.d(TAG, String.valueOf(tab.getPosition()));
updateFab(tab.getPosition());
viewPager.setCurrentItem(tab.getPosition());
}
@Override
public void onTabUnselected(TabLayout.Tab tab) {
}
@Override
public void onTabReselected(TabLayout.Tab tab) {
}
});
ExpenseDetailPagerAdapter adapter = new ExpenseDetailPagerAdapter(getSupportFragmentManager(), tabLayout.getTabCount(), expenseID, TAG);
viewPager.setAdapter(adapter);
viewPager.setCurrentItem(0);
// Set data of upper part of Activity
imageView = (ImageView) findViewById(R.id.img_photo);
amountTextView = (TextView) findViewById(R.id.tv_amount);
creatorNameTextView = (TextView) findViewById(R.id.tv_creator_name);
expenseNameTextView = (TextView) findViewById(R.id.tv_pending_name);
balanceTextTextView = (TextView) findViewById(R.id.tv_balance_text);
balanceTextView = (TextView) findViewById(R.id.tv_balance);
payExpenseButton = (Button) findViewById(R.id.btn_pay_debt);
userImage = MainActivity.getCurrentUser().getProfileImage();
payExpenseButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.d(TAG, "Clicked payButton");
if (expenseBalance >= 0) {
Toast.makeText(ExpenseDetailActivity.this, getString(R.string.no_debts_to_pay_for_expense), Toast.LENGTH_SHORT).show();
} else {
Intent intent = new Intent(ExpenseDetailActivity.this, PayExpenseActivity.class);
intent.putExtra("groupID", groupID);
intent.putExtra("userID", userID);
intent.putExtra("userImage", userImage);
intent.putExtra("debt", expenseBalance);
intent.putExtra("expenseID", expenseID);
intent.putExtra("expenseName", expenseName);
intent.putExtra("expenseCurrency", currency);
intent.putExtra("expenseImage", expensePhoto);
startActivity(intent);
finish();
}
}
});
// Retrieve data of this expense
databaseReference.child("expenses").child(expenseID).addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
expenseName = dataSnapshot.child("description").getValue(String.class);
Double amount = dataSnapshot.child("amount").getValue(Double.class);
currency = dataSnapshot.child("currency").getValue(String.class);
expensePhoto = dataSnapshot.child("expensePhoto").getValue(String.class);
expenseNameTextView.setText(expenseName);
// .load(dataSnapshot.child("image").getValue(String.class))
Glide.with(getApplicationContext()).load(dataSnapshot.child("expensePhoto").getValue(String.class)).placeholder(R.color.colorPrimary).centerCrop().diskCacheStrategy(DiskCacheStrategy.ALL).into(imageView);
DecimalFormat df = new DecimalFormat("#.##");
amountTextView.setText(df.format(amount) + " " + currency);
// Retrieve my balance for this expense
Double dueImport = Double.parseDouble(String.valueOf(dataSnapshot.child("participants").child(userID).child("fraction").getValue())) * dataSnapshot.child("amount").getValue(Double.class);
Double alreadyPaid = dataSnapshot.child("participants").child(userID).child("alreadyPaid").getValue(Double.class);
expenseBalance = alreadyPaid - dueImport;
expenseBalance = Math.floor(expenseBalance * 100) / 100;
if (expenseBalance > 0) {
balanceTextTextView.setText("For this expense you should receive");
balanceTextView.setText(expenseBalance.toString() + " " + currency);
} else if (expenseBalance < 0) {
balanceTextTextView.setText("For this expense you should pay");
Double absBalance = abs(expenseBalance);
balanceTextView.setText(absBalance.toString() + " " + currency);
} else if (expenseBalance == 0) {
balanceTextTextView.setText("For this expense you have no debts");
balanceTextView.setText("0" + " " + currency);
}
// Retrieve name and surname of creator
String creatorID = dataSnapshot.child("creatorID").getValue(String.class);
databaseReference.child("users").child(creatorID).addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
String name = dataSnapshot.child("name").getValue(String.class);
String surname = dataSnapshot.child("surname").getValue(String.class);
creatorNameTextView.setText(name + " " + surname);
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
use of android.support.design.widget.TabLayout in project DevRing by LJYcoder.
the class MovieActivity method initEvent.
@Override
protected void initEvent() {
// 设置TabLayout选项卡的点击事件
mTlMovie.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
@Override
public void onTabSelected(TabLayout.Tab tab) {
switch(tab.getPosition()) {
case 0:
clickPlaying();
break;
case 1:
clickComming();
break;
}
}
@Override
public void onTabUnselected(TabLayout.Tab tab) {
}
@Override
public void onTabReselected(TabLayout.Tab tab) {
}
});
// 设置DrawerLayout滑动的相关监听
ActionBarDrawerToggle mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, mToolbar, R.string.open, R.string.close) {
@Override
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
}
@Override
public void onDrawerClosed(View drawerView) {
super.onDrawerClosed(drawerView);
}
};
mDrawerToggle.syncState();
mDrawerLayout.addDrawerListener(mDrawerToggle);
mDrawerLayout.addDrawerListener(new DrawerLayout.DrawerListener() {
@Override
public void onDrawerSlide(View drawerView, float slideOffset) {
View mContent = mDrawerLayout.getChildAt(0);
mContent.setTranslationX(drawerView.getMeasuredWidth() * slideOffset);
}
@Override
public void onDrawerOpened(View drawerView) {
}
@Override
public void onDrawerClosed(View drawerView) {
}
@Override
public void onDrawerStateChanged(int newState) {
}
});
// 设置侧滑栏中的菜单项点击事件
mNavigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
switch(item.getItemId()) {
case R.id.nav_item_collect:
startActivity(new Intent(MovieActivity.this, CollectActivity.class));
break;
case R.id.nav_item_upload:
startActivity(new Intent(MovieActivity.this, UploadActivity.class));
break;
case R.id.nav_item_download:
startActivity(new Intent(MovieActivity.this, DownloadActivity.class));
break;
}
// true则点击的菜单项会变成选中状态,,false则不会变成选中状态
return false;
}
});
mIvAvatar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
RingToast.show(R.string.github_star);
}
});
}
use of android.support.design.widget.TabLayout in project BeautifulRefreshLayout by android-cjj.
the class MainActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
final ActionBar ab = getSupportActionBar();
ab.setHomeAsUpIndicator(R.drawable.ic_menu);
ab.setDisplayHomeAsUpEnabled(true);
ab.setTitle(null);
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
if (navigationView != null) {
setupDrawerContent(navigationView);
}
ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager);
if (viewPager != null) {
setupViewPager(viewPager);
}
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "I'm CJJ", Snackbar.LENGTH_LONG).setAction("Action", null).show();
}
});
TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
tabLayout.setupWithViewPager(viewPager);
}
use of android.support.design.widget.TabLayout in project JustAndroid by chinaltz.
the class MainActivity method InitView.
//初始化View
private void InitView() {
viewPager.setOffscreenPageLimit(4);
fragmentList = new ArrayList<Fragment>();
homeBaseUIFragment = new HomeBaseUIFragment();
netAndDbDataFragment = new NetAndDBDataFragment();
designPatternFragment = new DesignPatternFragment();
shopFragment = new ShopFragment();
otherUtilsFragment = new OtherUtilsFragment();
fragmentList.add(homeBaseUIFragment);
fragmentList.add(netAndDbDataFragment);
fragmentList.add(designPatternFragment);
fragmentList.add(shopFragment);
fragmentList.add(otherUtilsFragment);
tabLayout.setTabMode(TabLayout.MODE_FIXED);
titleList = new String[] { "UI", "Net&DB", "设计模式", "购物车", "其他" };
MainFragmentAdapter adapter = new MainFragmentAdapter(getSupportFragmentManager(), titleList, fragmentList);
viewPager.setAdapter(adapter);
tabLayout.setupWithViewPager(viewPager);
//设置ViewPager 是否可以滑动
viewPager.setPagingEnabled(true);
viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
}
@Override
public void onPageSelected(int position) {
for (int i = 0; i < titleList.length; i++) {
TabLayout.Tab tab = tabLayout.getTabAt(i);
View view = tab.getCustomView();
ImageView img = (ImageView) view.findViewById(R.id.tab_icon);
TextView title = (TextView) view.findViewById(R.id.tab_title);
if (position == i) {
img.setImageResource(icons_press[i]);
title.setTextColor(getResources().getColor(R.color.mainColor));
} else {
img.setImageResource(icons[i]);
title.setTextColor(getResources().getColor(R.color.gray));
}
}
}
@Override
public void onPageScrollStateChanged(int state) {
}
});
//为TabLayout添加tab名称
for (int i = 0; i < titleList.length; i++) {
TabLayout.Tab tab = tabLayout.getTabAt(i);
tab.setCustomView(getTabView(i));
}
viewPager.setCurrentItem(0);
}
use of android.support.design.widget.TabLayout in project FastDev4Android by jiangqqlmj.
the class TabInfoFragment method initValidata.
private void initValidata() {
fragments = new ArrayList<>();
for (int i = 0; i < 12; i++) {
OneFragment oneFragment = new OneFragment();
Bundle bundle = new Bundle();
bundle.putString("extra", titles[i]);
oneFragment.setArguments(bundle);
fragments.add(oneFragment);
}
//创建Fragment的 ViewPager 自定义适配器
mPagerAdater = new CNKFixedPagerAdapter(getChildFragmentManager());
//设置显示的标题
mPagerAdater.setTitles(titles);
//设置需要进行滑动的页面Fragment
mPagerAdater.setFragments(fragments);
info_viewpager.setAdapter(mPagerAdater);
tab_layout.setupWithViewPager(info_viewpager);
//设置Tablayout
//设置TabLayout模式 -该使用Tab数量比较多的情况
tab_layout.setTabMode(TabLayout.MODE_SCROLLABLE);
//设置自定义Tab--加入图标的demo
for (int i = 0; i < 12; i++) {
TabLayout.Tab tab = tab_layout.getTabAt(i);
tab.setCustomView(mPagerAdater.getTabView(i));
}
}
Aggregations