Java tutorial
package ca.ualberta.slevinsk.gameshow; /** * Copyright 2015 John Slevinsky * * 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. */ import android.content.ActivityNotFoundException; import android.content.Intent; import android.os.Bundle; import android.support.design.widget.FloatingActionButton; import android.support.design.widget.Snackbar; import android.support.design.widget.TabLayout; import android.support.v4.view.ViewPager; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.Toast; public class StatsActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_stats); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager); viewPager.setAdapter(new StatsFragmentPagerAdapter(getSupportFragmentManager(), StatsActivity.this)); TabLayout tabLayout = (TabLayout) findViewById(R.id.sliding_tabs); tabLayout.setupWithViewPager(viewPager); getSupportActionBar().setDisplayHomeAsUpEnabled(true); ReactionTimersManager.initManager(getApplicationContext()); BuzzerCounterManager.initManager(getApplicationContext()); FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/rfc822"); intent.putExtra(Intent.EXTRA_SUBJECT, "slevinsk - stats"); intent.putExtra(Intent.EXTRA_TEXT, BuzzerCounterController.generateEmailData() + ReactionTimersController.generateEmailData()); try { startActivity(intent); } catch (ActivityNotFoundException e) { Snackbar.make(view, "There is no email client installed", Snackbar.LENGTH_LONG).show(); } } }); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.menu_stats, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); //noinspection SimplifiableIfStatement if (id == R.id.action_clear_buzz) { BuzzerCounterController.clearData(); } if (id == R.id.action_clear_react) { ReactionTimersController.clearData(); } return super.onOptionsItemSelected(item); } }