OpenGL ES SDK for Android ARM Developer Center
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FileLoading.java
Go to the documentation of this file.
1 /* Copyright (c) 2014-2017, ARM Limited and Contributors
2  *
3  * SPDX-License-Identifier: MIT
4  *
5  * Permission is hereby granted, free of charge,
6  * to any person obtaining a copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation the rights to
8  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
9  * and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
12  *
13  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
14  * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
16  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
17  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19  */
20 
21 package com.arm.malideveloper.openglessdk.fileloading;
22 
23 import java.io.File;
24 import java.io.IOException;
25 import java.io.InputStream;
26 import java.io.RandomAccessFile;
27 
28 import android.os.Bundle;
29 import android.os.Environment;
30 import android.app.Activity;
31 import android.content.SharedPreferences;
32 import android.content.res.AssetManager;
33 import android.util.Log;
34 
35 public class FileLoading extends Activity
36 {
37  private String LOGTAG = "FirstLoading";
38 
39  /* [savePreferences] */
40  @Override protected void onCreate(Bundle savedInstanceState)
41  {
42  super.onCreate(savedInstanceState);
43 
44  SharedPreferences savedValues = getSharedPreferences("savedValues", MODE_PRIVATE);
45  int programRuns = savedValues.getInt("programRuns", 1);
46 
47  Log.d(LOGTAG, "This application has been run " + programRuns + " times");
48  programRuns++;
49 
50  SharedPreferences.Editor editor = savedValues.edit();
51  editor.putInt("programRuns", programRuns);
52  editor.commit();
53  /* [savePreferences] */
54 
55  /* [publicPrivateCacheFileLocations] */
56  String privateAssetDirectory = getFilesDir().getAbsolutePath();
57  String publicAssetDirectory = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath();
58  String cacheAssetDirectory = getCacheDir().getAbsolutePath();
59 
60  Log.i(LOGTAG, "privateAssetDirectory's path is equal to: " + privateAssetDirectory);
61  Log.i(LOGTAG, "publicAssetDirectory's path is equal to: " + publicAssetDirectory);
62  Log.i(LOGTAG, "cacheAssetDirectory's path is equal to: " + cacheAssetDirectory);
63  /* [publicPrivateCacheFileLocations] */
64 
65  /* [callExtractAssets] */
66  String privateApplicationFileName = "privateApplicationFile.txt";
67  String publicApplicationFileName = "publicApplicationFile.txt";
68  String cacheApplicationFileName = "cacheApplicationFile.txt";
69 
70  extractAsset(privateApplicationFileName, privateAssetDirectory);
71  extractAsset(publicApplicationFileName, publicAssetDirectory);
72  extractAsset(cacheApplicationFileName, cacheAssetDirectory);
73  /* [callExtractAssets] */
74 
75  /* [initNativeCall] */
76  NativeLibrary.init(privateAssetDirectory + "/" + privateApplicationFileName, publicAssetDirectory + "/" + publicApplicationFileName, cacheAssetDirectory + "/" + cacheApplicationFileName);
77  /* [initNativeCall] */
78  }
79 
80  @Override protected void onPause()
81  {
82  super.onPause();
83  }
84 
85  @Override protected void onResume()
86  {
87  super.onResume();
88  }
89 
90  /* [extractAssetBeginning] */
91  private void extractAsset(String assetName, String assetPath)
92  {
93  File fileTest = new File(assetPath, assetName);
94 
95  if(fileTest.exists())
96  {
97  Log.d(LOGTAG, assetName + " already exists no extraction needed\n");
98  }
99  else
100  {
101  Log.d(LOGTAG, assetName + " doesn't exist extraction needed \n");
102  /* [extractAssetBeginning] */
103  /* [extractAssets] */
104  try
105  {
106  RandomAccessFile out = new RandomAccessFile(fileTest,"rw");
107  AssetManager am = getResources().getAssets();
108 
109  InputStream inputStream = am.open(assetName);
110  byte buffer[] = new byte[1024];
111  int count = inputStream.read(buffer, 0, 1024);
112 
113  while (count > 0)
114  {
115  out.write(buffer, 0, count);
116  count = inputStream.read(buffer, 0, 1024);
117  }
118  out.close();
119  inputStream.close();
120  }
121  /* [extractAssets] */
122  /* [extractAssetsErrorChecking] */
123  catch(Exception e)
124  {
125  Log.e(LOGTAG, "Failure in extractAssets(): " + e.toString() + " " + assetPath+assetName);
126  }
127  if(fileTest.exists())
128  {
129  Log.d(LOGTAG,"File Extracted successfully");
130  }
131  /* [extractAssetsErrorChecking] */
132  }
133  }
134 }
GLenum GLenum GLsizei count
Definition: gl2ext.h:133
void extractAsset(String assetName, String assetPath)
GLenum GLuint buffer
Definition: gl2ext.h:628