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 MadMax by deviz92.
the class DetailFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// create the view to return
View mainView = null;
//get the bundle
Bundle bundle = this.getArguments();
// the listener will be the GroupDetailActivity or the FriendDetailActivity
setInterface((OnItemClickInterface) getActivity());
databaseReference = FirebaseDatabase.getInstance().getReference();
// when an item in the list will be clicked the onListItemClicked will be called
groupsViewAdapter = new GroupsViewAdapter(this.getContext(), this, groups, DetailFragment.TAG);
if (activityName.equals("FriendDetailActivity")) {
// Inflate the layout for this fragment
mainView = inflater.inflate(R.layout.shared_groups_list, container, false);
RecyclerView.ItemDecoration divider = new InsetDivider.Builder(getContext()).orientation(InsetDivider.VERTICAL_LIST).dividerHeight(getResources().getDimensionPixelSize(R.dimen.divider_height)).color(getResources().getColor(R.color.colorDivider)).insets(getResources().getDimensionPixelSize(R.dimen.divider_inset), 0).overlay(true).build();
recyclerView = (RecyclerView) mainView.findViewById(R.id.rv_skeleton);
layoutManager = new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false);
recyclerView.setLayoutManager(layoutManager);
recyclerView.addItemDecoration(divider);
recyclerView.setAdapter(groupsViewAdapter);
//Extract data from bundle
friendID = bundle.getString("friendID");
//Show shared groups
databaseReference.child("users").child(MainActivity.getCurrentUser().getID()).child("friends").child(friendID).child("sharedGroups").addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot sharedGroupSnapshot : dataSnapshot.getChildren()) {
FirebaseUtils.getInstance().getGroup(sharedGroupSnapshot.getKey(), groups, groupsViewAdapter);
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
} else if (activityName.equals("GroupDetailActivity")) {
groupID = bundle.getString("groupID");
mainView = inflater.inflate(R.layout.fragment_group_detail, container, false);
fab = (FloatingActionButton) getActivity().findViewById(R.id.fab);
fab.setImageResource(android.R.drawable.ic_input_add);
TabLayout tabLayout = (TabLayout) mainView.findViewById(R.id.tab_layout);
tabLayout.addTab(tabLayout.newTab().setText(R.string.expenses));
tabLayout.addTab(tabLayout.newTab().setText(R.string.members));
tabLayout.addTab(tabLayout.newTab().setText(R.string.activities));
tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);
updateFab(0);
final ViewPager viewPager = (ViewPager) mainView.findViewById(R.id.main_view_pager);
final DetailFragment.PagerAdapter adapter = new DetailFragment.PagerAdapter(getActivity().getSupportFragmentManager(), tabLayout.getTabCount());
viewPager.setAdapter(adapter);
viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
@Override
public void onTabSelected(TabLayout.Tab tab) {
Log.d(TAG, "selected tab " + tab.getPosition());
updateFab(tab.getPosition());
viewPager.setCurrentItem(tab.getPosition());
}
@Override
public void onTabUnselected(TabLayout.Tab tab) {
}
@Override
public void onTabReselected(TabLayout.Tab tab) {
}
});
}
return mainView;
}
use of android.support.design.widget.TabLayout in project MadMax by deviz92.
the class MainActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.i(TAG, "onCreate");
FirebaseUtils.getInstance().setUp();
firebaseDatabase = FirebaseUtils.getFirebaseDatabase();
databaseReference = FirebaseUtils.getDatabaseReference();
usersRef = databaseReference.child("users");
groupRef = databaseReference.child("groups");
auth = FirebaseAuth.getInstance();
/*
// getting Intent from invitation
Intent intent = getIntent();
String action = intent.getAction();
Log.d(TAG, "action " + action);
// retrieving data from the intent inviterUID & groupToBeAddedID as the group ID where to add the current user
Uri data = intent.getData();
if(data != null) {
// to be used to set the current user as friend of the inviter
Log.d(TAG, "there is an invite");
inviterUID = data.getQueryParameter("inviterUID");
groupToBeAddedID = data.getQueryParameter("groupToBeAddedID");
}
else {
inviterUID = null;
groupToBeAddedID = null;
Log.d(TAG, "there is not an invite");
}*/
// getting currentUID from Intent (from LoginSignUpActivity or EmailVerificationActivity)
startingIntent = getIntent();
Uri data = startingIntent.getData();
if (data != null) {
inviterID = data.getQueryParameter("inviterID");
groupToBeAddedID = data.getQueryParameter("groupToBeAddedID");
} else {
// retrieving data from the intent inviterID & groupToBeAddedID as the group ID where to add the current user
if (startingIntent.hasExtra("inviterID")) {
// to be used to set the current user as friend of the inviter
Log.d(TAG, "there is an invite");
inviterID = startingIntent.getStringExtra("inviterID");
startingIntent.removeExtra("inviterID");
} else
inviterID = null;
if (startingIntent.hasExtra("groupToBeAddedID")) {
groupToBeAddedID = startingIntent.getStringExtra("groupToBeAddedID");
startingIntent.removeExtra("groupToBeAddedID");
} else
groupToBeAddedID = null;
}
//todo a cosa serve?
currentFragment = startingIntent.getIntExtra("currentFragment", 1);
if ((auth.getCurrentUser() == null) || (!auth.getCurrentUser().isEmailVerified())) {
if (auth.getCurrentUser() != null) {
auth.signOut();
}
Intent doLogin = new Intent(getApplicationContext(), LoginSignUpActivity.class).setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
if (inviterID != null)
doLogin.putExtra("inviterID", inviterID);
if (groupToBeAddedID != null)
doLogin.putExtra("groupToBeAddedID", groupToBeAddedID);
startActivity(doLogin);
//0 for no animation
overridePendingTransition(0, 0);
finish();
}
// insert tabs and current fragment in the main layout
mainView.addView(getLayoutInflater().inflate(R.layout.skeleton_tab, null));
tabLayout = (TabLayout) findViewById(R.id.tab_layout);
tabLayout.addTab(tabLayout.newTab().setText(friends));
tabLayout.addTab(tabLayout.newTab().setText(R.string.groups));
tabLayout.addTab(tabLayout.newTab().setText(R.string.pending));
tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);
viewPager = (ViewPager) findViewById(R.id.main_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) {
}
});
// in the main we don't want an expansible bar
AppBarLayout appBarLayout = (AppBarLayout) findViewById(R.id.app_bar);
appBarLayout.setExpanded(false);
//todo: capire come bloccare la barra nel main
progressDialog = new ProgressDialog(this);
}
use of android.support.design.widget.TabLayout in project MadMax by deviz92.
the class LoginSignUpActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// the first time user open the app the default preferences must be setted up
PreferenceManager.setDefaultValues(this, R.layout.preferences, false);
Log.i(TAG, "onCreate");
FirebaseUtils.getInstance().setUp();
// getting Intent from invitation
Intent startingIntent = getIntent();
//prepare intent for MainActivity
goToMain = new Intent(getApplicationContext(), MainActivity.class);
goToMain.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
String action = startingIntent.getAction();
Log.d(TAG, "action " + action);
// retrieving data from the intent inviterID & groupToBeAddedID as the group ID where to add the current user
if (startingIntent.hasExtra("inviterID")) {
// to be used to set the current user as friend of the inviter
Log.d(TAG, "there is an invite");
inviterID = startingIntent.getStringExtra("inviterID");
startingIntent.removeExtra("inviterID");
goToMain.putExtra("inviterID", inviterID);
} else
inviterID = null;
if (startingIntent.hasExtra("groupToBeAddedID")) {
groupToBeAddedID = startingIntent.getStringExtra("groupToBeAddedID");
startingIntent.removeExtra("groupToBeAddedID");
goToMain.putExtra("groupToBeAddedID", groupToBeAddedID);
} else
groupToBeAddedID = null;
// insert tabs and current fragment in the main layout
setContentView(R.layout.activity_log_in_signup);
// for adding custom font to the title of the app
TextView titleTextView = (TextView) findViewById(R.id.title);
Typeface mycustomfont = Typeface.createFromAsset(getAssets(), "fonts/Lobster-Regular.ttf");
titleTextView.setTypeface(mycustomfont);
// for adding custom background image
ImageView background = (ImageView) findViewById(R.id.background);
Glide.with(this).load(R.drawable.background).centerCrop().diskCacheStrategy(DiskCacheStrategy.ALL).into(background);
// findViewById(R.id.activity_log_in_signup_layout).setOnClickListener(this);
TabLayout tabLayout = (TabLayout) findViewById(R.id.tab_layout);
tabLayout.addTab(tabLayout.newTab().setText(R.string.login));
tabLayout.addTab(tabLayout.newTab().setText(R.string.signup));
tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);
viewPager = (ViewPager) findViewById(R.id.main_view_pager);
adapter = new PagerAdapter(getSupportFragmentManager(), tabLayout.getTabCount());
viewPager.setAdapter(adapter);
viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
viewPager.setCurrentItem(0);
tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
@Override
public void onTabSelected(TabLayout.Tab tab) {
Log.d(TAG, String.valueOf(tab.getPosition()));
viewPager.setCurrentItem(tab.getPosition());
}
@Override
public void onTabUnselected(TabLayout.Tab tab) {
}
@Override
public void onTabReselected(TabLayout.Tab tab) {
}
});
}
use of android.support.design.widget.TabLayout in project Varis-Android by dkhmelenko.
the class RepoDetailsActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_repo_details);
ButterKnife.bind(this);
TravisApp.instance().activityInjector().inject(this);
initToolbar();
// setting view pager
ViewPager vpPager = (ViewPager) findViewById(R.id.repo_details_view_pager);
mAdapterViewPager = new PagerAdapter(getSupportFragmentManager());
vpPager.setAdapter(mAdapterViewPager);
vpPager.setOffscreenPageLimit(PagerAdapter.ITEMS_COUNT);
TabLayout tabLayout = (TabLayout) findViewById(R.id.repo_details_view_tabs);
tabLayout.setupWithViewPager(vpPager);
}
Aggregations