filename | android/src/org/lxdream/LxdreamActivity.java |
changeset | 1278:2f0de47738d0 |
prev | 1275:83b15705cdde |
next | 1285:f72cfb134a87 |
author | nkeynes |
date | Wed Mar 21 14:44:14 2012 +1000 (12 years ago) |
permissions | -rw-r--r-- |
last change | Dreamcast.stop() on pause, get rid of unnecessary onAppPause()/onAppResume() methods Set the run menu item to the right icon/state on pause as well. |
view | annotate | diff | log | raw |
1 /**
2 * $Id$
3 *
4 * Main Lxdream activity
5 *
6 * Copyright (c) 2011 Nathan Keynes.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 */
19 package org.lxdream;
21 import android.app.Activity;
22 import android.content.Context;
23 import android.content.res.Resources;
24 import android.graphics.drawable.Drawable;
25 import android.os.Bundle;
26 import android.util.Log;
27 import android.view.Menu;
28 import android.view.MenuInflater;
29 import android.view.MenuItem;
30 import android.view.WindowManager;
32 import java.io.File;
35 public class LxdreamActivity extends Activity {
36 LxdreamView view;
37 boolean isRunning = false;
38 Context ctx;
39 Drawable runIcon, pauseIcon;
40 MenuItem runMenuItem;
42 @Override
43 protected void onCreate(Bundle bundle) {
44 super.onCreate(bundle);
45 ctx = getApplication();
46 Resources res = ctx.getResources();
47 runIcon = res.getDrawable(R.drawable.tb_run);
48 pauseIcon = res.getDrawable(R.drawable.tb_pause);
50 Log.i("LxdreamActivity", "Calling Dreamcast.init");
51 Dreamcast.init( ctx.getFilesDir().toString() );
52 Log.i("LxdreamActivity", "Finished Dreamcast.init");
53 view = new LxdreamView(ctx);
54 setContentView(view);
55 }
57 @Override
58 public boolean onCreateOptionsMenu(Menu menu) {
59 MenuInflater inflater = getMenuInflater();
60 inflater.inflate(R.menu.main, menu);
61 runMenuItem = menu.findItem(R.id.menu_run);
62 return true;
63 }
66 @Override
67 protected void onPause() {
68 Dreamcast.stop();
69 runMenuItem.setIcon( runIcon );
70 isRunning = false;
71 super.onPause();
72 }
74 @Override
75 protected void onResume() {
76 super.onResume();
77 }
79 public void onRunClicked( MenuItem item ) {
80 if( isRunning ) {
81 item.setIcon( runIcon );
82 } else {
83 item.setIcon( pauseIcon );
84 }
85 Dreamcast.toggleRun();
86 isRunning = !isRunning;
87 }
89 public void onResetClicked( MenuItem item ) {
90 Dreamcast.reset();
91 }
93 public void onPreferencesClicked( MenuItem item ) {
94 /* TODO */
95 }
96 }
.