JaRMoS  1.1
Java Reduced Model Simulations
 All Classes Namespaces Files Functions Variables Enumerator Groups Pages
SDModelManager.java
Go to the documentation of this file.
1 package jarmos.app.io;
2 
3 import jarmos.app.Const;
5 
6 import java.io.File;
7 import java.io.IOException;
8 
9 import android.content.Context;
10 import android.os.Environment;
11 import android.util.Log;
12 
19 public class SDModelManager extends FileModelManager {
20 
24  private static final String JARMOSA_SD_DIR = "jarmosa_models";
25 
29  public static final String SD_BASE_DIR = Environment.getExternalStorageDirectory().toString();
30 
34  public static final String SD_MODEL_DIR = SD_BASE_DIR + File.separator + JARMOSA_SD_DIR;
35 
36  private DexHelper dh;
37 
42  public SDModelManager(Context c) {
43  super(SD_MODEL_DIR);
44  dh = new DexHelper(c);
45  }
46 
50  @Override
51  public ClassLoader getClassLoader() {
52  try {
53  return dh.getDexClassLoader(getInStream(Const.DEX_CLASSES_JARFILE));
54  } catch (IOException e) {
55  Log.e("SDModelManager", "I/O Exception during input stream creation for file " + Const.DEX_CLASSES_JARFILE
56  + " in model " + getModelDir() + ", loading from SD card", e);
57  e.printStackTrace();
58  return null;
59  }
60  }
61 
66  public static boolean ensureSDDir() {
67  File f = new File(SD_MODEL_DIR);
68  if (!f.exists())
69  return f.mkdirs();
70  return true;
71  }
72 
73  @Override
74  protected String getLoadingMessage() {
75  return "Reading SD card models";
76  }
77 }
String getLoadingMessage()
A short message that writes "loading SD models" dependent on the actual instance. ...
static final String SD_BASE_DIR
SD Card base directory string.
Class for model loading from the local SD card of the mobile device running android.
Manages models loaded from the file system available via the java.io classes.
final InputStream getInStream(String filename)
Returns an InputStream instance streaming the contents of the file given by filename.
static final String DEX_CLASSES_JARFILE
The file name within a model directory that contains any runtime-loadable classes.
Definition: Const.java:33
static final String SD_MODEL_DIR
rbAppMIT's root folder on the SD-Card
Class that contains miscellaneous JaRMoS specific constants and static functions. ...
Definition: Const.java:26
Utility class for providing class loaders that load from dex-jarfiles.
Definition: DexHelper.java:26