Project

General

Profile

« Previous | Next » 

Revision e7f14a73

Added by Leszek Koltunski about 1 year ago

Move opening local files to the OSInterface

View differences:

src/main/java/org/distorted/os/OSInterface.java
10 10
package org.distorted.os;
11 11

  
12 12
import android.app.Activity;
13
import android.content.res.Resources;
13 14
import android.util.DisplayMetrics;
14 15
import android.view.MotionEvent;
15 16

  
17
import java.io.File;
18
import java.io.FileInputStream;
19
import java.io.FileNotFoundException;
20
import java.io.InputStream;
16 21
import java.lang.ref.WeakReference;
17 22
import org.distorted.objectlib.helpers.OperatingSystemInterface;
18 23

  
......
33 38
    }
34 39

  
35 40
///////////////////////////////////////////////////////////////////////////////////////////////////
36

  
37
  public void setMotionEvent(MotionEvent event)
38
    {
39
    mEvent = event;
40
    }
41

  
41
// SCREEN
42 42
///////////////////////////////////////////////////////////////////////////////////////////////////
43 43

  
44 44
  public int getScreenDensity()
......
48 48
    return dm.densityDpi;
49 49
    }
50 50

  
51
///////////////////////////////////////////////////////////////////////////////////////////////////
52
// TOUCH CONTROL
53
///////////////////////////////////////////////////////////////////////////////////////////////////
54

  
55
  public void setMotionEvent(MotionEvent event)
56
    {
57
    mEvent = event;
58
    }
59

  
51 60
///////////////////////////////////////////////////////////////////////////////////////////////////
52 61

  
53 62
  public int getAction()
......
146 155
    int index = mEvent.findPointerIndex(mPointer2);
147 156
    return mEvent.getY(index);
148 157
    }
158

  
159
///////////////////////////////////////////////////////////////////////////////////////////////////
160
// LOCAL FILES
161
///////////////////////////////////////////////////////////////////////////////////////////////////
162

  
163
  public InputStream openLocalFile(String name)
164
    {
165
    Activity act = mAct.get();
166
    File file = new File(act.getFilesDir(), name);
167
    InputStream stream;
168

  
169
    try
170
      {
171
      stream = new FileInputStream(file);
172
      }
173
    catch(FileNotFoundException fnf)
174
      {
175
      stream = null;
176
      }
177

  
178
    return stream;
179
    }
180

  
181
///////////////////////////////////////////////////////////////////////////////////////////////////
182

  
183
  public InputStream openLocalFile(int id)
184
    {
185
    Resources res = mAct.get().getResources();
186
    return res!=null ? res.openRawResource(id) : null;
187
    }
188

  
149 189
}

Also available in: Unified diff