Java tutorial
/* * Copyright 2015 Google Inc. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.eusecom.attendance; import android.content.Intent; import android.os.Bundle; import android.support.design.widget.TabLayout; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentPagerAdapter; import android.support.v4.view.ViewPager; import android.view.Menu; import android.view.MenuItem; import android.view.View; import com.eusecom.attendance.fragment.MyPostsFragment; import com.eusecom.attendance.fragment.MyTopPostsFragment; import com.eusecom.attendance.fragment.RecentPostsFragment; import com.google.firebase.auth.FirebaseAuth; public class DatabaseActivity extends BaseDatabaseActivity { private static final String TAG = "MainActivity"; private FragmentPagerAdapter mPagerAdapter; private ViewPager mViewPager; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_database); //showProgressDialog(); // Create the adapter that will return a fragment for each section mPagerAdapter = new FragmentPagerAdapter(getSupportFragmentManager()) { private final Fragment[] mFragments = new Fragment[] { new RecentPostsFragment(), new MyPostsFragment(), new MyTopPostsFragment(), }; private final String[] mFragmentNames = new String[] { "Recent", "My Posts", "My Top Posts" }; @Override public Fragment getItem(int position) { return mFragments[position]; } @Override public int getCount() { return mFragments.length; } @Override public CharSequence getPageTitle(int position) { return mFragmentNames[position]; } }; // Set up the ViewPager with the sections adapter. mViewPager = (ViewPager) findViewById(R.id.container); mViewPager.setAdapter(mPagerAdapter); TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs); tabLayout.setupWithViewPager(mViewPager); // Button launches NewPostActivity findViewById(R.id.fab_new_post).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent i = new Intent(DatabaseActivity.this, NewPostActivity.class); Bundle extras = new Bundle(); extras.putString("editx", "0"); extras.putString("keyx", "0"); i.putExtras(extras); startActivity(i); } }); //hideProgressDialog(); } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.menu_database, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.action_logout: FirebaseAuth.getInstance().signOut(); startActivity(new Intent(this, EmailPasswordActivity.class)); finish(); return true; case R.id.action_settings: FirebaseAuth.getInstance().signOut(); startActivity(new Intent(this, SettingsActivity.class)); finish(); return true; default: return super.onOptionsItemSelected(item); } } }