Ejemplo n.º 1
0
 public void restart() {
   Log.i("OF", "onRestart");
   enableTouchEvents();
   onRestart();
   /*if(OFAndroidSoundStream.isInitialized() && OFAndroidSoundStream.wasStarted())
   OFAndroidSoundStream.getInstance().start();*/
 }
Ejemplo n.º 2
0
  public void resume() {
    Log.i("OF", "onResume");
    enableTouchEvents();
    mGLView.onResume();

    for (OFAndroidObject object : OFAndroidObject.ofObjects) {
      object.onResume();
    }

    onResume();

    if (OFAndroid.orientation != -1) OFAndroid.setScreenOrientation(OFAndroid.orientation);

    if (wl != null) lockScreenSleep();
  }
Ejemplo n.º 3
0
  public void resume() {
    if (mGLView == null || resumed) return;
    resumed = true;
    Log.i("OF", "onResume");
    enableTouchEvents();
    mGLView.onResume();
    synchronized (OFAndroidObject.ofObjects) {
      for (OFAndroidObject object : OFAndroidObject.ofObjects) {
        object.onResume();
      }
    }

    if (mGLView.isSetup()) {
      Log.i("OF", "resume view and native");
      onResume();
    }

    if (OFAndroid.orientation != -1) OFAndroid.setScreenOrientation(OFAndroid.orientation);

    if (networkStateReceiver != null) {
      monitorNetworkState();
    }
  }
Ejemplo n.º 4
0
  public OFAndroid(String packageName, Activity ofActivity) {
    ofActivity.setVolumeControlStream(AudioManager.STREAM_MUSIC);
    // Log.i("OF","external files dir: "+
    // ofActivity.getApplicationContext().getExternalFilesDir(null));
    OFAndroid.packageName = packageName;
    OFAndroidObject.setActivity(ofActivity);
    try {

      // try to find if R.raw class exists will throw
      // an exception if not
      Class<?> raw = Class.forName(packageName + ".R$raw");

      // if it exists copy all the raw resources
      // to a folder in the sdcard
      Field[] files = raw.getDeclaredFields();

      boolean copydata = false;

      SharedPreferences preferences = ofActivity.getPreferences(Context.MODE_PRIVATE);
      long lastInstalled = preferences.getLong("installed", 0);

      PackageManager pm = ofActivity.getPackageManager();
      ApplicationInfo appInfo = pm.getApplicationInfo(packageName, 0);
      String appFile = appInfo.sourceDir;
      long installed = new File(appFile).lastModified();
      if (installed > lastInstalled) {
        Editor editor = preferences.edit();
        editor.putLong("installed", installed);
        editor.commit();
        copydata = true;
      }

      dataPath = "";
      try {
        // dataPath = Environment.getExternalStorageDirectory().getAbsolutePath();
        dataPath = getRealExternalStorageDirectory();
        dataPath += "/" + packageName;
        Log.i("OF", "creating app directory: " + dataPath);
        try {

          File dir = new File(dataPath);

          if (!dir.exists() && dir.mkdir() != true) throw new Exception();
        } catch (Exception e) {
          Log.e("OF", "error creating dir " + dataPath, e);
        }

        if (copydata) {
          for (int i = 0; i < files.length; i++) {
            int fileId;
            String fileName = "";

            InputStream from = null;
            File toFile = null;
            FileOutputStream to = null;
            try {
              fileId = files[i].getInt(null);
              String resName = ofActivity.getResources().getText(fileId).toString();
              fileName = resName.substring(resName.lastIndexOf("/"));

              from = ofActivity.getResources().openRawResource(fileId);
              // toFile = new File(Environment.getExternalStorageDirectory() + "/" + appName + "/"
              // +fileName);
              Log.i("OF", "copying file " + fileName + " to " + dataPath);
              toFile = new File(dataPath + "/" + fileName);
              to = new FileOutputStream(toFile);
              byte[] buffer = new byte[4096];
              int bytesRead;

              while ((bytesRead = from.read(buffer)) != -1) to.write(buffer, 0, bytesRead); // write
            } catch (Exception e) {
              Log.e("OF", "error copying file", e);
            } finally {
              if (from != null)
                try {
                  from.close();
                } catch (IOException e) {
                }

              if (to != null)
                try {
                  to.close();
                } catch (IOException e) {
                }
            }
          }
        }
      } catch (Exception e) {
        Log.e("OF", "couldn't move app resources to data directory " + dataPath);
        e.printStackTrace();
      }
      String app_name = "";
      try {
        int app_name_id =
            Class.forName(packageName + ".R$string").getField("app_name").getInt(null);
        app_name = ofActivity.getResources().getText(app_name_id).toString();
        Log.i("OF", "app name: " + app_name);
      } catch (Exception e) {
        // TODO Auto-generated catch block
        Log.e("OF", "error retrieving app name", e);
      }
      OFAndroid.setAppDataDir(dataPath, app_name);

    } catch (ClassNotFoundException e1) {

    } catch (NameNotFoundException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    OFAndroid.ofActivity = ofActivity;

    gestureListener = new OFGestureListener(ofActivity);

    try {
      Log.v("OF", "trying to find class: " + packageName + ".R$layout");
      Class<?> layout = Class.forName(packageName + ".R$layout");
      View view =
          ofActivity.getLayoutInflater().inflate(layout.getField("main_layout").getInt(null), null);
      ofActivity.setContentView(view);

      Class<?> id = Class.forName(packageName + ".R$id");
      mGLView =
          (OFGLSurfaceView) ofActivity.findViewById(id.getField("of_gl_surface").getInt(null));
      enableTouchEvents();

    } catch (Exception e) {
      Log.e("OF", "couldn't create view from layout falling back to GL only", e);
      mGLView = new OFGLSurfaceView(ofActivity);
      ofActivity.setContentView(mGLView);
      enableTouchEvents();
    }
    // android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_URGENT_AUDIO);
  }
Ejemplo n.º 5
0
 public void start() {
   Log.i("OF", "onStart");
   enableTouchEvents();
 }