Search in sources :

Example 71 with TabLayout

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);
}
Also used : ShopFragment(com.litingzhe.justandroid.main.fragment.ShopFragment) OtherUtilsFragment(com.litingzhe.justandroid.main.fragment.OtherUtilsFragment) DesignPatternFragment(com.litingzhe.justandroid.main.fragment.DesignPatternFragment) HomeBaseUIFragment(com.litingzhe.justandroid.main.fragment.HomeBaseUIFragment) NetAndDBDataFragment(com.litingzhe.justandroid.main.fragment.NetAndDBDataFragment) ShopFragment(com.litingzhe.justandroid.main.fragment.ShopFragment) Fragment(android.support.v4.app.Fragment) OtherUtilsFragment(com.litingzhe.justandroid.main.fragment.OtherUtilsFragment) HomeBaseUIFragment(com.litingzhe.justandroid.main.fragment.HomeBaseUIFragment) ViewPager(android.support.v4.view.ViewPager) AbViewPager(com.ningcui.mylibrary.viewLib.sample.AbViewPager) ImageView(android.widget.ImageView) BindView(butterknife.BindView) View(android.view.View) TextView(android.widget.TextView) DesignPatternFragment(com.litingzhe.justandroid.main.fragment.DesignPatternFragment) NetAndDBDataFragment(com.litingzhe.justandroid.main.fragment.NetAndDBDataFragment) MainFragmentAdapter(com.litingzhe.justandroid.main.adapter.MainFragmentAdapter) TabLayout(android.support.design.widget.TabLayout) TextView(android.widget.TextView) ImageView(android.widget.ImageView)

Example 72 with TabLayout

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;
}
Also used : GroupsViewAdapter(com.polito.mad17.madmax.activities.groups.GroupsViewAdapter) Bundle(android.os.Bundle) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) DataSnapshot(com.google.firebase.database.DataSnapshot) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) ViewPager(android.support.v4.view.ViewPager) FragmentPagerAdapter(android.support.v4.app.FragmentPagerAdapter) DatabaseError(com.google.firebase.database.DatabaseError) TabLayout(android.support.design.widget.TabLayout) FloatingActionButton(android.support.design.widget.FloatingActionButton) RecyclerView(android.support.v7.widget.RecyclerView) ValueEventListener(com.google.firebase.database.ValueEventListener)

Example 73 with TabLayout

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);
}
Also used : TabLayout(android.support.design.widget.TabLayout) LoginSignUpActivity(com.polito.mad17.madmax.activities.login.LoginSignUpActivity) Intent(android.content.Intent) AppBarLayout(android.support.design.widget.AppBarLayout) ProgressDialog(android.app.ProgressDialog) Uri(android.net.Uri)

Example 74 with TabLayout

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) {
        }
    });
}
Also used : Typeface(android.graphics.Typeface) TabLayout(android.support.design.widget.TabLayout) Intent(android.content.Intent) TextView(android.widget.TextView) MainActivity(com.polito.mad17.madmax.activities.MainActivity) ImageView(android.widget.ImageView) FragmentPagerAdapter(android.support.v4.app.FragmentPagerAdapter)

Example 75 with TabLayout

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);
}
Also used : TabLayout(android.support.design.widget.TabLayout) ViewPager(android.support.v4.view.ViewPager) SmartFragmentStatePagerAdapter(com.khmelenko.lab.varis.adapter.SmartFragmentStatePagerAdapter)

Aggregations

TabLayout (android.support.design.widget.TabLayout)75 View (android.view.View)33 ViewPager (android.support.v4.view.ViewPager)28 Toolbar (android.support.v7.widget.Toolbar)17 TextView (android.widget.TextView)13 Intent (android.content.Intent)12 ActionBar (android.support.v7.app.ActionBar)10 RecyclerView (android.support.v7.widget.RecyclerView)10 Fragment (android.support.v4.app.Fragment)8 ImageView (android.widget.ImageView)8 Test (org.junit.Test)8 FloatingActionButton (android.support.design.widget.FloatingActionButton)7 UiController (android.support.test.espresso.UiController)7 ViewAction (android.support.test.espresso.ViewAction)7 AppBarLayout (android.support.design.widget.AppBarLayout)6 NavigationView (android.support.design.widget.NavigationView)6 ViewGroup (android.view.ViewGroup)6 FragmentPagerAdapter (android.support.v4.app.FragmentPagerAdapter)5 SlowTest (io.github.hidroh.materialistic.test.suite.SlowTest)5 PagerAdapter (android.support.v4.view.PagerAdapter)4