Changeset 24257
- Timestamp:
- 2011-07-15T13:52:13+12:00 (12 years ago)
- Location:
- other-projects/tipple-android/trunk/src/org/greenstone/android/tipple
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
other-projects/tipple-android/trunk/src/org/greenstone/android/tipple/TippleActivity.java
r23977 r24257 1 1 package org.greenstone.android.tipple; 2 2 3 import java.io.DataOutputStream; 3 4 import java.io.File; 5 import java.io.FileOutputStream; 6 import java.io.IOException; 7 import java.io.InputStream; 4 8 import java.util.ArrayList; 5 9 import java.util.Locale; … … 21 25 import android.content.Intent; 22 26 import android.content.SharedPreferences; 27 import android.content.res.AssetManager; 23 28 import android.location.LocationListener; 24 29 import android.widget.FrameLayout; … … 36 41 37 42 // File storage 38 public static String dataDirectory;43 public static String geodataDirectory; 39 44 public static String logDirectory; 40 45 public static String audioDirectory; … … 76 81 77 82 83 protected boolean assetToExternalStorage(String asset_filename, String external_storage_filename) 84 { 85 boolean status = true; 86 87 try { 88 89 File external_storage_file = new File(external_storage_filename); 90 if (!external_storage_file.exists()) { 91 // Need to create the /sdcard version 92 93 AssetManager assetManager = getAssets(); 94 95 InputStream ais = assetManager.open(asset_filename); // ais = asset input stream 96 FileOutputStream fos = new FileOutputStream(external_storage_file); // fos = file output stream 97 98 byte [] buffer = new byte[1024]; 99 100 int buflen; 101 while ((buflen = ais.read(buffer))>0) { 102 fos.write(buffer,0,buflen); 103 } 104 105 ais.close(); 106 fos.close(); 107 } 108 109 } 110 catch (Exception e) { 111 e.printStackTrace(); 112 status = false; 113 } 114 115 return status; 116 } 117 118 protected boolean initTippleStore(String location) 119 { 120 121 // Locate map data directory 122 File external_root_file = Environment.getExternalStorageDirectory(); 123 String external_root = external_root_file.getAbsolutePath(); 124 String tipple_store_dir = external_root + "/tipple-store"; 125 126 geodataDirectory = tipple_store_dir + "/geodata/"; 127 logDirectory = tipple_store_dir + "/logs/"; 128 audioDirectory = tipple_store_dir + "/audio/"; 129 130 File tipple_store_file = new File(tipple_store_dir); 131 if (!tipple_store_file.exists()) { 132 if (!tipple_store_file.mkdir()) { 133 System.err.println("Failed to create directory: " + tipple_store_dir); 134 return false; 135 } 136 } 137 138 File geodataDirFile = new File(geodataDirectory); 139 if (!geodataDirFile.exists()) { 140 if (!geodataDirFile.mkdir()) { 141 System.err.println("Failed to create directory: " + geodataDirectory); 142 return false; 143 } 144 } 145 146 File logDirFile = new File(logDirectory); 147 if (!logDirFile.exists()) { 148 if (!logDirFile.mkdir()) { 149 System.err.println("Failed to create directory: " + logDirectory); 150 return false; 151 } 152 } 153 154 File audioDirFile = new File(audioDirectory); 155 if (!audioDirFile.exists()) { 156 if (!audioDirFile.mkdir()) { 157 System.err.println("Failed to create directory: " + audioDirectory); 158 return false; 159 } 160 } 161 162 // dig out the audio files 163 String[] audio_filenames = { "BeepMorseSonar.wav","Ding.wav","DingExtended.wav" }; 164 for (String audio_filename: audio_filenames) { 165 String audio_asset_filename = "audio/" + audio_filename; 166 String audio_exstore_filename = audioDirectory + audio_filename; 167 168 if (!assetToExternalStorage(audio_asset_filename,audio_exstore_filename)) { 169 System.err.println("Failed to transfer asset " + audio_asset_filename + " to " + audio_exstore_filename); 170 return false; 171 } 172 } 173 174 if ((location != null) && (!location.equals(""))) { 175 // get out map and XML location file 176 177 String map_asset_filename = "geodata/" + location + ".map"; 178 String map_exstore_filename = geodataDirectory + location + ".map"; 179 180 if (!assetToExternalStorage(map_asset_filename,map_exstore_filename)) { 181 System.err.println("Failed to transfer asset " + map_asset_filename + " to " + map_exstore_filename); 182 return false; 183 } 184 185 String loc_asset_filename = "geodata/" + location + ".loc"; 186 String loc_exstore_filename = geodataDirectory + location + ".loc"; 187 188 if (!assetToExternalStorage(loc_asset_filename,loc_exstore_filename)) { 189 System.err.println("Failed to transfer asset " + loc_asset_filename + " to " + loc_exstore_filename); 190 return false; 191 } 192 } 193 194 return true; 195 } 196 197 protected boolean initTippleStore() 198 { 199 return initTippleStore(null); 200 } 78 201 protected TextView createLongLatView() 79 202 { … … 98 221 map_view.setClickable(true); 99 222 map_view.setBuiltInZoomControls(true); 100 String full_map_filename = dataDirectory + map_filename; 223 String full_map_filename = geodataDirectory + map_filename; 224 101 225 map_view.setMapFile(full_map_filename); 102 226 103 227 LayoutParams map_view_layout 104 228 = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, 105 229 ViewGroup.LayoutParams.WRAP_CONTENT, 1); 230 106 231 map_view.setLayoutParams(map_view_layout); 107 232 108 233 109 234 return map_view; 235 } 236 237 protected MapView createMapViewFromAsset(String map_filename) 238 { 239 // Transfer asset to file in dataDirectory if it does not already exist 240 241 String asset_filename = "geodata" + File.separator + map_filename; 242 String external_storage_filename = geodataDirectory + map_filename; 243 244 assetToExternalStorage(asset_filename,external_storage_filename); 245 246 return createMapView(map_filename); 247 110 248 } 111 249 … … 188 326 System.err.println("*** TippleActivity::onCreate()"); 189 327 super.onCreate(savedInstanceState); 190 191 // Locate map data directory 192 File external_root_file = Environment.getExternalStorageDirectory(); 193 String external_root = external_root_file.getAbsolutePath(); 194 dataDirectory = external_root + "/tipple-store/geodata/"; 195 logDirectory = external_root + "/tipple-store/logs/"; 196 audioDirectory = external_root + "/tipple-store/audio/"; 328 329 if (!initTippleStore("hamilton")) { 330 System.err.println("Failed to initialize TippleStore on sdcard. Quiting"); 331 onDestroy(); 332 } 197 333 198 334 // Set up logging … … 223 359 224 360 longlat_view_ = createLongLatView(); 225 map_view_ = createMapView("new-zealand.map"); 361 //map_view_ = createMapView("new-zealand.map"); 362 map_view_ = createMapViewFromAsset("hamilton.map"); 363 226 364 text_view_ = createTextView(); 227 365 text_map_composite_ = compositTextViewOnMapView(map_view_,text_view_); … … 285 423 286 424 // now TTS initialized, init TTS aware place-locations 287 String loc_filename = dataDirectory + "hamilton.loc";425 String loc_filename = geodataDirectory + "hamilton.loc"; 288 426 tip_location_manager_ = new TipLocationManager(this,audio_player_view_,tts_); 289 427 locations_ = tip_location_manager_.loadTour(loc_filename); -
other-projects/tipple-android/trunk/src/org/greenstone/android/tipple/TippleLog.java
r23979 r24257 28 28 log_directory_ = logDirectory; 29 29 30 boolean logfile_ok = initLogging();31 alertLogging(logfile_ok);30 //boolean logfile_ok = initLogging(); 31 //alertLogging(logfile_ok); 32 32 } 33 33
Note:
See TracChangeset
for help on using the changeset viewer.