--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/Datastructures/FrontendDataUtils.java Mon Aug 20 21:05:57 2012 +0200
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/Datastructures/FrontendDataUtils.java Wed Aug 22 01:30:56 2012 +0200
@@ -25,6 +25,7 @@
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import org.hedgewars.hedgeroid.R;
import org.hedgewars.hedgeroid.util.FileUtils;
@@ -38,9 +39,9 @@
/**
* @throws FileNotFoundException if the sdcard isn't available or the Maps directory doesn't exist
*/
- public static ArrayList<MapFile> getMaps(Context c) throws FileNotFoundException {
+ public static List<MapFile> getMaps(Context c) throws FileNotFoundException {
File[] files = FileUtils.getFilesFromRelativeDir(c,"Maps");
- ArrayList<MapFile> ret = new ArrayList<MapFile>();
+ List<MapFile> ret = new ArrayList<MapFile>();
for(File f : files) {
boolean isMission = FileUtils.hasFileWithSuffix(f, ".lua");
@@ -56,7 +57,7 @@
*/
public static List<String> getGameStyles(Context c) throws FileNotFoundException {
File[] files = FileUtils.getFilesFromRelativeDir(c, "Scripts/Multiplayer");
- ArrayList<String> ret = new ArrayList<String>();
+ List<String> ret = new ArrayList<String>();
/*
* Caution: It is important that the "empty" style has this exact name, because
* it will be interpreted as "don't load a script" by the frontlib, and also by
@@ -84,23 +85,19 @@
/**
* @throws FileNotFoundException if the sdcard isn't available or the Graphics/Graves directory doesn't exist
*/
- public static ArrayList<HashMap<String, ?>> getGraves(Context c) throws FileNotFoundException {
- File gravePath = new File(new File(FileUtils.getDataPathFile(c), "Graphics"), "Graves");
- ArrayList<String> names = FileUtils.getFileNamesFromDirWithSuffix(c,"Graphics/Graves", ".png", true);
- ArrayList<HashMap<String, ?>> data = new ArrayList<HashMap<String, ?>>(names.size());
+ public static List<Map<String, ?>> getGraves(Context c) throws FileNotFoundException {
+ File gravePath = FileUtils.getDataPathFile(c, "Graphics", "Graves");
+ List<String> names = FileUtils.getFileNamesFromDirWithSuffix(c,"Graphics/Graves", ".png", true);
+ List<Map<String, ?>> data = new ArrayList<Map<String, ?>>(names.size());
for(String s : names){
HashMap<String, Object> map = new HashMap<String, Object>();
map.put("txt", s);
Bitmap b = BitmapFactory.decodeFile(new File(gravePath, s + ".png").getAbsolutePath());
int width = b.getWidth();
- if(b.getHeight() > width){//some pictures contain more 'frames' underneath each other, if so we only use the first frame
- Bitmap tmp = Bitmap.createBitmap(width, width, b.getConfig());
- int[] pixels = new int[width * width];
- b.getPixels(pixels, 0,width,0,0,width,width);
- tmp.setPixels(pixels,0,width,0,0,width,width);
- b.recycle();
- b = tmp;
+ if(b.getHeight() > width){
+ // some pictures contain more 'frames' underneath each other, if so we only use the first frame
+ b = Bitmap.createBitmap(b, 0, 0, width, width);
}
map.put("img", b);
data.add(map);
@@ -111,13 +108,13 @@
/**
* @throws FileNotFoundException if the sdcard isn't available or the Graphics/Graves directory doesn't exist
*/
- public static ArrayList<HashMap<String, ?>> getFlags(Context c) throws FileNotFoundException {
- File flagsPath = new File(new File(FileUtils.getDataPathFile(c), "Graphics"), "Flags");
- ArrayList<String> names = FileUtils.getFileNamesFromDirWithSuffix(c, "Graphics/Flags", ".png", true);
- ArrayList<HashMap<String, ?>> data = new ArrayList<HashMap<String, ?>>(names.size());
+ public static List<Map<String, ?>> getFlags(Context c) throws FileNotFoundException {
+ File flagsPath = FileUtils.getDataPathFile(c, "Graphics", "Flags");
+ List<String> names = FileUtils.getFileNamesFromDirWithSuffix(c, "Graphics/Flags", ".png", true);
+ List<Map<String, ?>> data = new ArrayList<Map<String, ?>>(names.size());
for(String s : names){
- HashMap<String, Object> map = new HashMap<String, Object>();
+ Map<String, Object> map = new HashMap<String, Object>();
map.put("txt", s);
Bitmap b = BitmapFactory.decodeFile(new File(flagsPath, s + ".png").getAbsolutePath());
map.put("img", b);
@@ -129,9 +126,9 @@
/**
* @throws FileNotFoundException if the sdcard isn't available or the Sounds/voices directory doesn't exist
*/
- public static ArrayList<String> getVoices(Context c) throws FileNotFoundException {
+ public static List<String> getVoices(Context c) throws FileNotFoundException {
File[] files = FileUtils.getFilesFromRelativeDir(c, "Sounds/voices");
- ArrayList<String> ret = new ArrayList<String>();
+ List<String> ret = new ArrayList<String>();
for(File f : files){
if(f.isDirectory()) ret.add(f.getName());
@@ -142,17 +139,17 @@
/**
* @throws FileNotFoundException if the sdcard isn't available or the Forts directory doesn't exist
*/
- public static ArrayList<String> getForts(Context c) throws FileNotFoundException {
+ public static List<String> getForts(Context c) throws FileNotFoundException {
return FileUtils.getFileNamesFromDirWithSuffix(c,"Forts", "L.png", true);
}
- public static ArrayList<HashMap<String, ?>> getTypes(Context c){
- ArrayList<HashMap<String, ?>> data = new ArrayList<HashMap<String, ?>>(6);
+ public static List<Map<String, ?>> getTypes(Context c){
+ List<Map<String, ?>> data = new ArrayList<Map<String, ?>>(6);
String[] levels = {c.getString(R.string.human), c.getString(R.string.bot5), c.getString(R.string.bot4), c.getString(R.string.bot3), c.getString(R.string.bot2), c.getString(R.string.bot1)};
int[] images = {R.drawable.human, R.drawable.bot5, R.drawable.bot4, R.drawable.bot3, R.drawable.bot2, R.drawable.bot1};
for(int i = 0; i < levels.length; i++){
- HashMap<String, Object> map = new HashMap<String, Object>();
+ Map<String, Object> map = new HashMap<String, Object>();
map.put("txt", levels[i]);
map.put("img", images[i]);
map.put("level", i);
@@ -166,15 +163,14 @@
/**
* @throws FileNotFoundException if the sdcard isn't available or the Graphics/Hats directory doesn't exist
*/
- public static ArrayList<HashMap<String, ?>> getHats(Context c) throws FileNotFoundException {
- ArrayList<String> files = FileUtils.getFileNamesFromDirWithSuffix(c,"Graphics/Hats", ".png", true);
- File hatsPath = new File(new File(FileUtils.getDataPathFile(c), "Graphics"), "Hats");
+ public static List<Map<String, ?>> getHats(Context c) throws FileNotFoundException {
+ List<String> files = FileUtils.getFileNamesFromDirWithSuffix(c,"Graphics/Hats", ".png", true);
+ File hatsPath = FileUtils.getDataPathFile(c, "Graphics", "Hats");
int size = files.size();
- ArrayList<HashMap<String, ?>> data = new ArrayList<HashMap<String, ?>>(size);
+ List<Map<String, ?>> data = new ArrayList<Map<String, ?>>(size);
- HashMap<String, Object> hashmap;
for(String s : files){
- hashmap = new HashMap<String, Object>();
+ Map<String, Object> hashmap = new HashMap<String, Object>();
hashmap.put("txt", s);
Bitmap b = BitmapFactory.decodeFile(new File(hatsPath, s + ".png").getAbsolutePath());
b = Bitmap.createBitmap(b, 0,0,b.getWidth()/2, b.getWidth()/2);
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/Datastructures/Grave.java Mon Aug 20 21:05:57 2012 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,35 +0,0 @@
-/*
- * Hedgewars for Android. An Android port of Hedgewars, a free turn based strategy game
- * Copyright (c) 2011-2012 Richard Deurwaarder <xeli@xelification.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-package org.hedgewars.hedgeroid.Datastructures;
-
-public final class Grave{
- public final String name;
- public final String path;
-
- public Grave(String name, String path) {
- this.name = name;
- this.path = path;
- }
-
- @Override
- public String toString() {
- return "Grave [name=" + name + ", path=" + path + "]";
- }
-}
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/Datastructures/MapFile.java Mon Aug 20 21:05:57 2012 +0200
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/Datastructures/MapFile.java Wed Aug 22 01:30:56 2012 +0200
@@ -49,7 +49,7 @@
* @throws FileNotFoundException if the sdcard is not available. Does NOT throw if the requested map file does not exist.
*/
public static File getFileForMapname(Context ctx, String mapname) throws FileNotFoundException {
- return new File(new File(FileUtils.getDataPathFile(ctx), MAP_DIRECTORY), mapname);
+ return FileUtils.getDataPathFile(ctx, MAP_DIRECTORY, mapname);
}
public static final Comparator<MapFile> MISSIONS_FIRST_NAME_ORDER = new Comparator<MapFile>() {
@@ -72,7 +72,7 @@
}
public static File getPreviewFile(Context c, String mapName) throws FileNotFoundException {
- return new File(FileUtils.getDataPathFile(c), MAP_DIRECTORY + "/" + mapName + "/" + "preview.png");
+ return FileUtils.getDataPathFile(c, MAP_DIRECTORY, mapName, "preview.png");
}
public static List<String> toDisplayNameList(List<MapFile> mapFiles, Resources res) {
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/Downloader/DownloadPackage.java Mon Aug 20 21:05:57 2012 +0200
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/Downloader/DownloadPackage.java Wed Aug 22 01:30:56 2012 +0200
@@ -137,7 +137,7 @@
version = -1;
}
}else if(name.equals("path")){
- path = FileUtils.getDataPath(c) + text;
+ path = FileUtils.getDataPathFile(c, text).getAbsolutePath();
}else if(name.equals("representation")){
representation = text;
}else if(name.equals("description")){
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/LobbyActivity.java Mon Aug 20 21:05:57 2012 +0200
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/LobbyActivity.java Wed Aug 22 01:30:56 2012 +0200
@@ -67,9 +67,9 @@
tabHost.setup();
tabHost.getTabWidget().setOrientation(LinearLayout.VERTICAL);
- tabHost.addTab(tabHost.newTabSpec("rooms").setIndicator(UiUtils.createTabIndicator(tabHost, R.string.lobby_tab_rooms, R.drawable.roomlist_ingame)).setContent(R.id.roomListFragment));
- tabHost.addTab(tabHost.newTabSpec("chat").setIndicator(UiUtils.createTabIndicator(tabHost, R.string.lobby_tab_chat, R.drawable.edit)).setContent(R.id.chatFragment));
- tabHost.addTab(tabHost.newTabSpec("players").setIndicator(UiUtils.createTabIndicator(tabHost, R.string.lobby_tab_players, R.drawable.human)).setContent(R.id.playerListFragment));
+ tabHost.addTab(tabHost.newTabSpec("rooms").setIndicator(UiUtils.createVerticalTabIndicator(tabHost, R.string.lobby_tab_rooms, R.drawable.roomlist_ingame)).setContent(R.id.roomListFragment));
+ tabHost.addTab(tabHost.newTabSpec("chat").setIndicator(UiUtils.createVerticalTabIndicator(tabHost, R.string.lobby_tab_chat, R.drawable.edit)).setContent(R.id.chatFragment));
+ tabHost.addTab(tabHost.newTabSpec("players").setIndicator(UiUtils.createVerticalTabIndicator(tabHost, R.string.lobby_tab_players, R.drawable.human)).setContent(R.id.playerListFragment));
if (icicle != null) {
tabHost.setCurrentTabByTag(icicle.getString("currentTab"));
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/LocalRoomActivity.java Mon Aug 20 21:05:57 2012 +0200
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/LocalRoomActivity.java Wed Aug 22 01:30:56 2012 +0200
@@ -66,9 +66,9 @@
tabHost.setup();
tabHost.getTabWidget().setOrientation(LinearLayout.VERTICAL);
- tabHost.addTab(tabHost.newTabSpec("map").setIndicator(UiUtils.createTabIndicator(tabHost, R.string.room_tab_map, 0)).setContent(R.id.mapFragment));
- tabHost.addTab(tabHost.newTabSpec("settings").setIndicator(UiUtils.createTabIndicator(tabHost, R.string.room_tab_settings, 0)).setContent(R.id.settingsFragment));
- tabHost.addTab(tabHost.newTabSpec("teams").setIndicator(UiUtils.createTabIndicator(tabHost, R.string.room_tab_teams, 0)).setContent(R.id.teamlistContainer));
+ tabHost.addTab(tabHost.newTabSpec("map").setIndicator(UiUtils.createVerticalTabIndicator(tabHost, R.string.room_tab_map, 0)).setContent(R.id.mapFragment));
+ tabHost.addTab(tabHost.newTabSpec("settings").setIndicator(UiUtils.createVerticalTabIndicator(tabHost, R.string.room_tab_settings, 0)).setContent(R.id.settingsFragment));
+ tabHost.addTab(tabHost.newTabSpec("teams").setIndicator(UiUtils.createVerticalTabIndicator(tabHost, R.string.room_tab_teams, 0)).setContent(R.id.teamlistContainer));
if (icicle != null) {
tabHost.setCurrentTabByTag(icicle.getString("currentTab"));
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/NetRoomActivity.java Mon Aug 20 21:05:57 2012 +0200
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/NetRoomActivity.java Wed Aug 22 01:30:56 2012 +0200
@@ -75,11 +75,11 @@
tabHost.setup();
tabHost.getTabWidget().setOrientation(LinearLayout.VERTICAL);
- tabHost.addTab(tabHost.newTabSpec("map").setIndicator(UiUtils.createTabIndicator(tabHost, R.string.room_tab_map, 0)).setContent(R.id.mapFragment));
- tabHost.addTab(tabHost.newTabSpec("settings").setIndicator(UiUtils.createTabIndicator(tabHost, R.string.room_tab_settings, 0)).setContent(R.id.settingsFragment));
- tabHost.addTab(tabHost.newTabSpec("teams").setIndicator(UiUtils.createTabIndicator(tabHost, R.string.room_tab_teams, 0)).setContent(R.id.teamlistFragment));
- tabHost.addTab(tabHost.newTabSpec("chat").setIndicator(UiUtils.createTabIndicator(tabHost, R.string.room_tab_chat, 0)).setContent(R.id.chatFragment));
- tabHost.addTab(tabHost.newTabSpec("players").setIndicator(UiUtils.createTabIndicator(tabHost, R.string.room_tab_players, 0)).setContent(R.id.playerListContainer));
+ tabHost.addTab(tabHost.newTabSpec("map").setIndicator(UiUtils.createVerticalTabIndicator(tabHost, R.string.room_tab_map, 0)).setContent(R.id.mapFragment));
+ tabHost.addTab(tabHost.newTabSpec("settings").setIndicator(UiUtils.createVerticalTabIndicator(tabHost, R.string.room_tab_settings, 0)).setContent(R.id.settingsFragment));
+ tabHost.addTab(tabHost.newTabSpec("teams").setIndicator(UiUtils.createVerticalTabIndicator(tabHost, R.string.room_tab_teams, 0)).setContent(R.id.teamlistFragment));
+ tabHost.addTab(tabHost.newTabSpec("chat").setIndicator(UiUtils.createVerticalTabIndicator(tabHost, R.string.room_tab_chat, 0)).setContent(R.id.chatFragment));
+ tabHost.addTab(tabHost.newTabSpec("players").setIndicator(UiUtils.createVerticalTabIndicator(tabHost, R.string.room_tab_players, 0)).setContent(R.id.playerListContainer));
if (icicle != null) {
tabHost.setCurrentTabByTag(icicle.getString("currentTab"));
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/SettingsFragment.java Mon Aug 20 21:05:57 2012 +0200
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/SettingsFragment.java Wed Aug 22 01:30:56 2012 +0200
@@ -191,7 +191,7 @@
stateManager.changeMapTheme(themes.get(position));
String theme = themes.get(position);
try {
- File iconFile = new File(FileUtils.getDataPathFile(getActivity()), "Themes/" + theme + "/icon@2X.png");
+ File iconFile = FileUtils.getDataPathFile(getActivity(), "Themes", theme, "icon@2X.png");
Drawable themeIconDrawable = Drawable.createFromPath(iconFile.getAbsolutePath());
themeIcon.setImageDrawable(themeIconDrawable);
} catch (FileNotFoundException e) {
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/TeamCreatorActivity.java Mon Aug 20 21:05:57 2012 +0200
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/TeamCreatorActivity.java Wed Aug 22 01:30:56 2012 +0200
@@ -24,7 +24,6 @@
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
-import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
@@ -39,6 +38,7 @@
import android.graphics.drawable.Drawable;
import android.media.MediaPlayer;
import android.os.Bundle;
+import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
@@ -62,6 +62,7 @@
*/
public class TeamCreatorActivity extends Activity implements Runnable {
public static final String PARAMETER_EXISTING_TEAMNAME = "existingTeamName";
+ private static final String TAG = TeamCreatorActivity.class.getSimpleName();
private TextView name;
private Spinner difficulty, grave, flag, voice, fort;
@@ -76,10 +77,10 @@
private String existingTeamName = null;
- private final List<HashMap<String, ?>> flagsData = new ArrayList<HashMap<String, ?>>();
- private final List<HashMap<String, ?>> typesData = new ArrayList<HashMap<String, ?>>();
- private final List<HashMap<String, ?>> gravesData = new ArrayList<HashMap<String, ?>>();
- private final List<HashMap<String, ?>> hatsData = new ArrayList<HashMap<String, ?>>();
+ private final List<Map<String, ?>> flagsData = new ArrayList<Map<String, ?>>();
+ private final List<Map<String, ?>> typesData = new ArrayList<Map<String, ?>>();
+ private final List<Map<String, ?>> gravesData = new ArrayList<Map<String, ?>>();
+ private final List<Map<String, ?>> hatsData = new ArrayList<Map<String, ?>>();
private final List<String> voicesData = new ArrayList<String>();
private final List<String> fortsData = new ArrayList<String>();
@@ -158,7 +159,7 @@
public void run(){
try {
- final ArrayList<HashMap<String, ?>> gravesDataNew = FrontendDataUtils.getGraves(this);
+ final List<Map<String, ?>> gravesDataNew = FrontendDataUtils.getGraves(this);
runOnUiThread(new Runnable(){
public void run() {
gravesData.addAll(gravesDataNew);
@@ -166,7 +167,7 @@
}
});
- final ArrayList<HashMap<String, ?>> flagsDataNew = FrontendDataUtils.getFlags(this);
+ final List<Map<String, ?>> flagsDataNew = FrontendDataUtils.getFlags(this);
runOnUiThread(new Runnable(){
public void run() {
flagsData.addAll(flagsDataNew);
@@ -174,7 +175,7 @@
}
});
- final ArrayList<HashMap<String, ?>> typesDataNew = FrontendDataUtils.getTypes(this);
+ final List<Map<String, ?>> typesDataNew = FrontendDataUtils.getTypes(this);
runOnUiThread(new Runnable(){
public void run() {
typesData.addAll(typesDataNew);
@@ -182,7 +183,7 @@
}
});
- final ArrayList<HashMap<String, ?>> hatsDataNew = FrontendDataUtils.getHats(this);
+ final List<Map<String, ?>> hatsDataNew = FrontendDataUtils.getHats(this);
runOnUiThread(new Runnable(){
public void run() {
hatsData.addAll(hatsDataNew);
@@ -190,7 +191,7 @@
}
});
- final ArrayList<String> voicesDataNew = FrontendDataUtils.getVoices(this);
+ final List<String> voicesDataNew = FrontendDataUtils.getVoices(this);
runOnUiThread(new Runnable(){
public void run() {
voicesData.addAll(voicesDataNew);
@@ -198,7 +199,7 @@
}
});
- final ArrayList<String> fortsDataNew = FrontendDataUtils.getForts(this);
+ final List<String> fortsDataNew = FrontendDataUtils.getForts(this);
runOnUiThread(new Runnable(){
public void run() {
fortsData.addAll(fortsDataNew);
@@ -295,11 +296,13 @@
public void onItemSelected(AdapterView<?> arg0, View arg1,
int position, long arg3) {
String fortName = (String) arg0.getAdapter().getItem(position);
- Drawable fortIconDrawable = Drawable.createFromPath(FileUtils
- .getDataPath(TeamCreatorActivity.this)
- + "Forts/"
- + fortName + "L.png");
- imgFort.setImageDrawable(fortIconDrawable);
+ try {
+ File fortImage = FileUtils.getDataPathFile(TeamCreatorActivity.this, "Forts", fortName, "L.png");
+ Drawable fortIconDrawable = Drawable.createFromPath(fortImage.getAbsolutePath());
+ imgFort.setImageDrawable(fortIconDrawable);
+ } catch(IOException e) {
+ Log.e(TAG, "Unable to show fort image", e);
+ }
scroller.fullScroll(ScrollView.FOCUS_DOWN);// Scroll the scrollview
// to the bottom, work
// around for scrollview
@@ -315,9 +318,7 @@
private OnClickListener voiceClicker = new OnClickListener() {
public void onClick(View v) {
try {
- File dir = new File(String.format("%sSounds/voices/%s",
- FileUtils.getDataPath(TeamCreatorActivity.this),
- voice.getSelectedItem()));
+ File dir = FileUtils.getDataPathFile(TeamCreatorActivity.this, "Sounds", "voices", (String)voice.getSelectedItem());
String file = "";
File[] dirs = dir.listFiles();
File f = dirs[(int) Math.round(Math.random() * dirs.length)];
@@ -332,11 +333,11 @@
mp.prepare();
mp.start();
} catch (IllegalArgumentException e) {
- e.printStackTrace();
+ Log.e(TAG, "Unable to play voice sample", e);
} catch (IllegalStateException e) {
- e.printStackTrace();
+ Log.e(TAG, "Unable to play voice sample", e);
} catch (IOException e) {
- e.printStackTrace();
+ Log.e(TAG, "Unable to play voice sample", e);
}
}
};
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/util/CalmDownHandler.java Wed Aug 22 01:30:56 2012 +0200
@@ -0,0 +1,62 @@
+/*
+ * Hedgewars for Android. An Android port of Hedgewars, a free turn based strategy game
+ * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.hedgewars.hedgeroid.util;
+
+import android.os.Handler;
+import android.os.Looper;
+import android.os.Message;
+
+/**
+ * This class allows you to define a runnable that is called when there has been
+ * no activity for a set amount of time, where activity is determined by calls
+ * to the activity() method of the handler. It is used to update the map preview
+ * when there have been no updates to the relevant map information for a time,
+ * to prevent triggering several updates at once when different parts of the
+ * information change.
+ */
+public final class CalmDownHandler extends Handler {
+ int runningMessagesCounter = 0;
+ final Runnable inactivityRunnable;
+ final long inactivityMs;
+ boolean stopped;
+
+ public CalmDownHandler(Looper looper, Runnable runnable, long inactivityMs) {
+ super(looper);
+ this.inactivityRunnable = runnable;
+ this.inactivityMs = inactivityMs;
+ }
+
+ public void activity() {
+ runningMessagesCounter++;
+ sendMessageDelayed(obtainMessage(), inactivityMs);
+ }
+
+ @Override
+ public void handleMessage(Message msg) {
+ runningMessagesCounter--;
+ if(runningMessagesCounter==0 && !stopped) {
+ inactivityRunnable.run();
+ }
+ }
+
+ public void stop() {
+ stopped = true;
+ }
+}
\ No newline at end of file
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/util/FileUtils.java Mon Aug 20 21:05:57 2012 +0200
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/util/FileUtils.java Wed Aug 22 01:30:56 2012 +0200
@@ -71,21 +71,14 @@
}
}
- public static File getDataPathFile(Context c) throws FileNotFoundException {
- return new File(getCachePath(c), ROOT_DIR);
+ public static File getDataPathFile(Context c, String...subpath) throws FileNotFoundException {
+ File file = new File(getCachePath(c), ROOT_DIR);
+ for(String pathcomponent : subpath) {
+ file = new File(file, pathcomponent);
+ }
+ return file;
}
- // TODO Several callers are unaware that this may fail, so it throws an RTE now.
- // Should be handled better though.
- @Deprecated
- public static String getDataPath(Context c) {
- try {
- return getDataPathFile(c).getAbsolutePath()+"/";
- } catch(FileNotFoundException e) {
- throw new RuntimeException(e);
- }
- }
-
@TargetApi(8)
private static class FroyoSDCardDir{
public static File getDownloadPath(Context c){
@@ -113,7 +106,7 @@
* @throws FileNotFoundException If the sdcard is not available or the subdirectory "dirName" does not exist
*/
public static File[] getFilesFromRelativeDir(Context c, String dirName) throws FileNotFoundException {
- File f = new File(getDataPathFile(c), dirName);
+ File f = getDataPathFile(c, dirName);
if(f.isDirectory()) {
return f.listFiles();
@@ -160,9 +153,9 @@
* Get all files from directory dir which have the given suffix
* @throws FileNotFoundException If the sdcard is not available or the subdirectory "dir" does not exist
*/
- public static ArrayList<String> getFileNamesFromDirWithSuffix(Context c, String dir, String suffix, boolean removeSuffix) throws FileNotFoundException{
+ public static List<String> getFileNamesFromDirWithSuffix(Context c, String dir, String suffix, boolean removeSuffix) throws FileNotFoundException{
File[] files = FileUtils.getFilesFromRelativeDir(c, dir);
- ArrayList<String> ret = new ArrayList<String>();
+ List<String> ret = new ArrayList<String>();
for(File file : files){
String s = file.getName();
if(s.endsWith(suffix)){
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/util/UiUtils.java Mon Aug 20 21:05:57 2012 +0200
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/util/UiUtils.java Wed Aug 22 01:30:56 2012 +0200
@@ -33,7 +33,7 @@
throw new AssertionError("This class is not meant to be instantiated");
}
- public static View createTabIndicator(TabHost tabHost, int label, int icon) {
+ public static View createVerticalTabIndicator(TabHost tabHost, int label, int icon) {
LayoutInflater inflater = (LayoutInflater) tabHost.getContext()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);