1. Karan R
  2. MovieLists-android

Source

MovieLists-android / MovieLists / src / com / example / movielists / MainActivity.java

package com.example.movielists;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

public class MainActivity extends Activity implements OnClickListener {

	Button newMovies, listAll, getStats, clearAll;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		initialize();
	}

	private void initialize() {
		newMovies = (Button) findViewById(R.id.bratenew);
		listAll = (Button) findViewById(R.id.blistall);
		getStats = (Button) findViewById(R.id.bcheckstats);
		clearAll = (Button) findViewById(R.id.bclearall);
		newMovies.setOnClickListener(this);
		listAll.setOnClickListener(this);
		getStats.setOnClickListener(this);
		clearAll.setOnClickListener(this);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_main, menu);
		return true;
	}

	@Override
	public void onClick(View button) {
		switch (button.getId()) {
		case (R.id.bratenew):
			Intent i = new Intent(this, RateMovie.class);
		startActivity(i);
		break;
		case (R.id.blistall):
			Intent i1 = new Intent(this, ListAllMovies.class);
		startActivity(i1);
		break;
		case (R.id.bcheckstats):
			Intent t2=new StatChart().getIntent(this);
		startActivity(t2);
			break;
		case (R.id.bclearall):
			final Runnable del = new Runnable() {
			@Override
			public void run() {
				getApplicationContext().deleteDatabase(
						MovieDbContract.DATABASE_NAME);
				Toast.makeText(getApplicationContext(), R.string.clearlist,
						Toast.LENGTH_SHORT).show();
			}};
		ConfirmationDialog.confirm(this, del);

		break;
		}
	}

}