Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import android.app.Activity;
- import android.os.Bundle;
- import android.view.Menu;
- import android.view.View;
- import android.view.View.OnClickListener;
- import android.widget.ViewSwitcher;
- public class MainActivity extends Activity implements OnClickListener {
- private static ViewSwitcher switcher;// needed for control of ViewSwitcher
- private static View sad;// needed for onClick
- private static View isSad;// needed for sadPictureReturn()
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- // setup switcher view
- switcher = (ViewSwitcher) findViewById(R.id.ViewSwitcher1);
- switcher.setInAnimation(this, android.R.anim.fade_in);
- switcher.setOutAnimation(this, android.R.anim.fade_out);
- sad = (View) findViewById(R.id.Viewsad);
- sad.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.main, menu);
- return true;
- }
- @Override
- public void onClick(View arg0) {
- // called when sad view is clicked
- // switch to happy face and play sound
- if (arg0.getId() == R.id.Viewsad) {
- switcher.showNext();
- MyMediaPlayer.mediaPlaySound(getBaseContext());
- // else switch to sad face
- } else {
- switcher.showPrevious();
- }
- }
- public static void sadPictureReturn() {
- // When sound is finished return to sad view
- // check if next view is sad. if it is then switch
- // if not then do nothing because it is already on sad view
- isSad = switcher.getNextView();
- if (isSad == sad) {
- switcher.showPrevious();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement