Search
lxdream.org :: lxdream/android/src/org/lxdream/LxdreamActivity.java
lxdream 0.9.1
released Jun 29
Download Now
filename android/src/org/lxdream/LxdreamActivity.java
changeset 1285:f72cfb134a87
prev1278:2f0de47738d0
author nkeynes
date Tue Apr 17 21:53:55 2012 +1000 (12 years ago)
permissions -rw-r--r--
last change Set the android default directory to $SDCARD/lxdream instead of the /data
directory.
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.os.Environment;
    27 import android.util.Log;
    28 import android.view.Menu;
    29 import android.view.MenuInflater;
    30 import android.view.MenuItem;
    31 import android.view.WindowManager;
    33 import java.io.File;
    36 public class LxdreamActivity extends Activity {
    37     LxdreamView view;
    38     boolean isRunning = false;
    39     Context ctx;
    40     Drawable runIcon, pauseIcon;
    41     MenuItem runMenuItem;
    43     @Override 
    44     protected void onCreate(Bundle bundle) {
    45         super.onCreate(bundle);
    46         ctx = getApplication();
    47         Resources res = ctx.getResources();
    48         runIcon = res.getDrawable(R.drawable.tb_run);
    49         pauseIcon = res.getDrawable(R.drawable.tb_pause);
    51         Log.i("LxdreamActivity", "Calling Dreamcast.init");
    52         Dreamcast.init( Environment.getExternalStorageDirectory().toString() + "/lxdream" );
    53         Log.i("LxdreamActivity", "Finished Dreamcast.init");
    54         view = new LxdreamView(ctx);
    55         setContentView(view);
    56     }
    58     @Override
    59     public boolean onCreateOptionsMenu(Menu menu) {
    60         MenuInflater inflater = getMenuInflater();
    61         inflater.inflate(R.menu.main, menu);
    62         runMenuItem = menu.findItem(R.id.menu_run);
    63         return true;
    64     }
    67     @Override 
    68     protected void onPause() {
    69         Dreamcast.stop();
    70         runMenuItem.setIcon( runIcon );
    71         isRunning = false;
    72         super.onPause();
    73     }
    75     @Override 
    76     protected void onResume() {
    77         super.onResume();
    78     }
    80     public void onRunClicked( MenuItem item ) {
    81     	if( isRunning ) {
    82     		item.setIcon( runIcon );
    83     	} else {
    84     		item.setIcon( pauseIcon );
    85     	}
    86     	Dreamcast.toggleRun();
    87     	isRunning = !isRunning;
    88     }
    90     public void onResetClicked( MenuItem item ) {
    91     	Dreamcast.reset();
    92     }
    94     public void onPreferencesClicked( MenuItem item ) {
    95     	/* TODO */
    96     }
    97 }
.