Commit 430cb3cd authored by Luboš Horáček's avatar Luboš Horáček

#60 Nacitani dat ve hrach Unos a Pronasledovani

parent 6c94a1d3
......@@ -114,7 +114,6 @@ public class Tablexia extends com.activeandroid.app.Application {
tablexiaState = TablexiaState.getTablexiaState(false);
globalSoundControl = new SoundControl(getApplicationContext(), 10);
ExportControl.tryToSendData(this);
}
......@@ -154,8 +153,8 @@ public class Tablexia extends com.activeandroid.app.Application {
@Override
public void onObbStateChange(String path, int state) {
super.onObbStateChange(path, state);
android.util.Log.e(TAG, "ObbStateChanged to " + state + " file: " + path);
android.util.Log.e(TAG, "Mounted Obb path : " + storageManager.getMountedObbPath(path));
android.util.Log.i(TAG, "ObbStateChanged to " + state + " file: " + path);
android.util.Log.i(TAG, "Mounted Obb path : " + storageManager.getMountedObbPath(path));
if ((state == OnObbStateChangeListener.MOUNTED) || (state == OnObbStateChangeListener.ERROR_ALREADY_MOUNTED)) {
globalSoundControl.loadPermanentSounds();
if (onDataMountedListener != null) {
......
......@@ -98,7 +98,7 @@ public class SoundControl {
public void addSound(String sound) {
if (!soundMap.containsKey(sound)) {
Tablexia tablexia = (Tablexia) context.getApplicationContext();
soundMap.put(sound, soundPool.load(tablexia.getStorageManager().getMountedObbPath(tablexia.getObbPath()) + File.separator + sound, 1));
soundMap.put(sound, soundPool.load(tablexia.getMountPath() + File.separator + sound, 1));
}
}
......
......@@ -33,6 +33,7 @@ import org.andengine.engine.options.ScreenOrientation;
import org.andengine.engine.options.resolutionpolicy.FillResolutionPolicy;
import org.andengine.entity.primitive.Rectangle;
import org.andengine.entity.scene.Scene;
import org.andengine.opengl.view.RenderSurfaceView;
import org.andengine.ui.activity.LayoutGameActivity;
import org.andengine.util.adt.color.Color;
......@@ -61,6 +62,7 @@ import android.widget.RelativeLayout;
import android.widget.TextView;
import cz.nic.tablexia.R;
import cz.nic.tablexia.Tablexia;
import cz.nic.tablexia.Tablexia.OnDataMountedListener;
import cz.nic.tablexia.audio.SoundControl;
import cz.nic.tablexia.audio.resources.PermanentSounds;
import cz.nic.tablexia.audio.resources.SfxSounds;
......@@ -147,6 +149,22 @@ public abstract class GameActivity extends LayoutGameActivity implements MenuAct
}
}
@Override
protected void onSetContentView() {
// do nothing until mounted
setContentView(getLayoutID());
}
public void onObbMounted() {
runOnUiThread(new Runnable() {
@Override
public void run() {
mRenderSurfaceView = (RenderSurfaceView) findViewById(getRenderSurfaceViewID());
mRenderSurfaceView.setRenderer(mEngine, GameActivity.this);
}
});
}
@Override
public boolean isGameActive(GamesDefinition gameDefinitionToCheck) {
return (gamesDefinition == gameDefinitionToCheck) && (gameState == GameState.STARTED);
......@@ -375,6 +393,12 @@ public abstract class GameActivity extends LayoutGameActivity implements MenuAct
}
lowProfileMode();
showLoadingScreen();
getTablexiaContext().startMount(new OnDataMountedListener() {
@Override
public void onDataMounted() {
onObbMounted();
}
});
}
@Override
......
package cz.nic.tablexia.game.games.pronasledovani;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
......@@ -7,15 +9,17 @@ import org.andengine.opengl.texture.TextureManager;
import org.andengine.opengl.texture.TextureOptions;
import org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlas;
import org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlasTextureRegionFactory;
import org.andengine.opengl.texture.atlas.bitmap.source.FileBitmapTextureAtlasSource;
import org.andengine.opengl.texture.region.ITextureRegion;
import org.andengine.opengl.texture.region.TextureRegionFactory;
import android.content.Context;
import android.graphics.Point;
import cz.nic.tablexia.Tablexia;
import cz.nic.tablexia.game.games.pronasledovani.model.Card;
public class CardDeckGenerator {
private static final String TEXTURES_BASE_PATH = "pronasledovani/textures/";
private static final String TEXTURES_BASE_PATH = PronasledovaniActivity.BASE_DIR + "textures/";
private int cardTextureWidth;
private int cardWidth;
......@@ -28,6 +32,7 @@ public class CardDeckGenerator {
private ArrayList<Card> cards;
public CardDeckGenerator(Context context, int cardGridSize, String currentMapName, TextureManager textureManager, Point displaySize, int gridOffsetY) {
Tablexia tablexia = (Tablexia) context.getApplicationContext();
gridOffset = new Point();
gridOffset.y = gridOffsetY;
......@@ -38,7 +43,7 @@ public class CardDeckGenerator {
BitmapTextureAtlasTextureRegionFactory.setAssetBasePath(TEXTURES_BASE_PATH);
mCardDeckTexture = new BitmapTextureAtlas(textureManager, 1300, 1300, TextureOptions.BILINEAR);
BitmapTextureAtlasTextureRegionFactory.createFromAsset(mCardDeckTexture, context, currentMapName, 0, 0);
BitmapTextureAtlasTextureRegionFactory.createFromSource(mCardDeckTexture, FileBitmapTextureAtlasSource.create(new File(tablexia.getMountPath() + File.separator + TEXTURES_BASE_PATH + currentMapName)), 0, 0);
mCardDeckTexture.load();
cards = new ArrayList<Card>();
......
......@@ -16,6 +16,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/
package cz.nic.tablexia.game.games.pronasledovani;
import java.io.IOException;
......@@ -35,10 +36,7 @@ import org.andengine.entity.scene.background.RepeatingSpriteBackground;
import org.andengine.entity.sprite.Sprite;
import org.andengine.input.touch.TouchEvent;
import org.andengine.input.touch.controller.MultiTouch;
import org.andengine.opengl.font.Font;
import org.andengine.opengl.font.FontFactory;
import org.andengine.opengl.texture.ITexture;
import org.andengine.opengl.texture.TextureOptions;
import org.andengine.opengl.texture.region.ITextureRegion;
import org.andengine.opengl.texture.region.TextureRegion;
import org.andengine.opengl.texture.region.TextureRegionFactory;
......@@ -46,7 +44,6 @@ import org.andengine.util.modifier.ease.EaseLinear;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.graphics.Point;
import android.os.Bundle;
import android.os.Handler;
......@@ -86,8 +83,6 @@ public class PronasledovaniActivity extends GameActivity implements IOnSceneTouc
private static final String TAG = PronasledovaniActivity.class.getSimpleName();
public static final String BASE_DIR = "pronasledovani/";
private static final int MAPSCOUNT = 7;
private static final String FONTS_BASE_PATH = "shared/fonts/";
private static final String FONT = "Roboto-Regular.ttf";
private static final int MINIMUM_ROTATION_FOR_ANIMATION = 20; // o kolik stupnu se musi dilek minimalne otocit,aby
// se nedoanimoval
// zpet na
......@@ -102,8 +97,8 @@ public class PronasledovaniActivity extends GameActivity implements IOnSceneTouc
// puvodni hodnotu rotace
private static final int ASSET_BITMAP_SIZE = 1300;
private static final int GRID_OFFSET_Y = 10;
private static final int ASSET_BITMAP_SIZE = 1300;
private static final int GRID_OFFSET_Y = 10;
private static final ArrayList<Entry<Position, Position>> carStartAndEndPoints = new ArrayList<Map.Entry<Position, Position>>();
{
carStartAndEndPoints.add(new AbstractMap.SimpleEntry<Position, Position>(new Position(1163, 1083), new Position(263, 193)));
......@@ -131,7 +126,8 @@ public class PronasledovaniActivity extends GameActivity implements IOnSceneTouc
private int pieceHovered; // poradi prave prekruyvaneho dilku v mrizce
private int cardWidth; // sirka karty samotne
private int textureID; // cislo mapy, ktera bude zobrazena pri startu aplikace,
private int textureID; // cislo mapy, ktera bude zobrazena pri startu
// aplikace,
// po dohrani mapy se cislo v DB inkrementuje
private boolean gameRunning;
......@@ -139,8 +135,6 @@ public class PronasledovaniActivity extends GameActivity implements IOnSceneTouc
private Position firstFingerFirstTouch;
private Position secondFingerFirstTouch;
private Font mFont;
private HashMap<Card, ITextureRegion> mCardTotextureRegionMap;
// List, ktery obsahuje vsechny karty a jejich info
private ArrayList<Card> cards;
......@@ -197,8 +191,8 @@ public class PronasledovaniActivity extends GameActivity implements IOnSceneTouc
private boolean animationCanceled;
SfxManager sfxManager;
private TextureRegion carTextureRegion; // auticko, ktere se zobraz po dohrani hry
private TextureRegion flagTextureRegion; // oznaceni sidla lupicu na mape
private TextureRegion carTextureRegion; // auticko, ktere se zobraz po dohrani hry
private TextureRegion flagTextureRegion; // oznaceni sidla lupicu na mape
int coordinationArrayPointer;
Position[] lastFiveCarCoordinates;
......@@ -248,10 +242,6 @@ public class PronasledovaniActivity extends GameActivity implements IOnSceneTouc
public void onCreateResources(OnCreateResourcesCallback pOnCreateResourcesCallback) throws IOException {
sfxManager = new SfxManager(getSoundManager(), this);
sfxManager.loadSounds();
/* Vytvori font, ktery budeme pouzivat */
FontFactory.setAssetBasePath(FONTS_BASE_PATH);
mFont = FontFactory.createFromAsset(getFontManager(), getTextureManager(), 512, 512, TextureOptions.BILINEAR, getAssets(), FONT, 32, true, Color.WHITE);
mFont.load();
TexturesGenerator texturesGenerator = new TexturesGenerator(this, getTextureManager(), getAssets());
// AUTICKO
......@@ -273,6 +263,7 @@ public class PronasledovaniActivity extends GameActivity implements IOnSceneTouc
// mEngine.registerUpdateHandler(new FPSLogger());
scene.setOnAreaTouchTraversalFrontToBack();
}
/*
* Metoda nastavi prostredi, nahodne vybere texturu, ktera se pouzije pro
* skladanou mapu
......@@ -424,6 +415,7 @@ public class PronasledovaniActivity extends GameActivity implements IOnSceneTouc
}
return -1;
}
/*
* Metoda pro zamichani karet ve mrizce vygeneruje hodnoty od 0 do poctu
* karet v mrizce -1 nastavi pozice karet na tyto nove hodnoty a rovnez
......@@ -450,6 +442,7 @@ public class PronasledovaniActivity extends GameActivity implements IOnSceneTouc
cards.get(i).setRotation(0 + (int) (Math.random() * possibleDirections));
}
}
/*
* Metoda vraci pozici karty s ID predanym v parametru v pixelech
*/
......@@ -624,7 +617,7 @@ public class PronasledovaniActivity extends GameActivity implements IOnSceneTouc
}
private void rotatePieceToAngle(int pieceID, float initialRotation, float endRotation) {
if (pieceID != -1 && (scene.getChildByTag(pieceID) != null)) {
if ((pieceID != -1) && (scene.getChildByTag(pieceID) != null)) {
if (rotationModifier != null) {
scene.getChildByTag(pieceID).unregisterEntityModifier(rotationModifier);
shadowSprite.unregisterEntityModifier(rotationModifier);
......@@ -638,7 +631,7 @@ public class PronasledovaniActivity extends GameActivity implements IOnSceneTouc
// TODO pozdeji dodelat aby animace fungovala
private void scalePieceToSize(int pieceID, float initialScale, float finalScale) {
if ((pieceID != -1) && (scene.getChildByTag(pieceID) != null)) {
if ((pieceID != -1) && (scene.getChildByTag(pieceID) != null)) {
// if (scaleModifier != null) {
// scene.getChildByTag(pieceID).unregisterEntityModifier(
// scaleModifier);
......@@ -665,7 +658,7 @@ public class PronasledovaniActivity extends GameActivity implements IOnSceneTouc
animateInPosition(pieceReleasedOnID, secondPiecePosition.getX(), secondPiecePosition.getY(), firstPiecePosition.getX(), firstPiecePosition.getY());
// pomocna promenna pro pozdejsi prohozeni tagu
int workingTag = -5;
if (scene.getChildByTag(pieceDraggedID) != null) {
scene.getChildByTag(pieceDraggedID).setTag(workingTag);
}
......@@ -687,7 +680,7 @@ public class PronasledovaniActivity extends GameActivity implements IOnSceneTouc
* Metoda pro zvyrazneni dilku, nad kterym prave projizdime
*/
private void scaleHoveredPiece(int hoveredPieceID) {
if (hoveredPieceID != -1 && (scene.getChildByTag(hoveredPieceID) != null)) {
if ((hoveredPieceID != -1) && (scene.getChildByTag(hoveredPieceID) != null)) {
for (int i = 0; i < (gridSize * gridSize); i++) {
if ((i == hoveredPieceID) && (i != pieceTouched)) {
if (!scene.getChildByTag(i).isScaled()) {
......
......@@ -16,8 +16,10 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/
package cz.nic.tablexia.game.games.pronasledovani;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
......@@ -27,15 +29,17 @@ import org.andengine.audio.sound.SoundFactory;
import org.andengine.audio.sound.SoundManager;
import android.content.Context;
import android.util.Log;
import cz.nic.tablexia.Tablexia;
public class SfxManager {
private static final String SOUNDS_DIR = PronasledovaniActivity.BASE_DIR + "sfx/";
public static final String SOUNDS_EXTENSION = ".mp3";
private static final String TAG = SfxManager.class.getSimpleName();
private static final String SOUNDS_DIR = PronasledovaniActivity.BASE_DIR + "sfx/";
public static final String SOUNDS_EXTENSION = ".mp3";
private Map<SoundsEnum, Sound> sounds = new HashMap<SoundsEnum, Sound>();
private SoundManager soundManager;
private Context context;
private SoundManager soundManager;
private Context context;
public SfxManager(SoundManager soundManager, Context context) {
this.soundManager = soundManager;
......@@ -48,9 +52,13 @@ public class SfxManager {
loadSound(sound);
}
}
private void loadSound(SoundsEnum sound) {
try {
Sound soundInstance = SoundFactory.createSoundFromAsset(soundManager, context, sound.getResourceName() + SOUNDS_EXTENSION);
Tablexia tablexia = (Tablexia) context.getApplicationContext();
String path = tablexia.getMountPath() + File.separator + SOUNDS_DIR + sound.getResourceName() + SOUNDS_EXTENSION;
Log.i(TAG, "Loading sound: " + path);
Sound soundInstance = SoundFactory.createSoundFromPath(soundManager, path);
sounds.put(sound, soundInstance);
} catch (final IOException e) {
// TODO remove TestFlight.log("Error loading sound " + e.getMessage());
......@@ -63,6 +71,4 @@ public class SfxManager {
s.play();
}
}
package cz.nic.tablexia.game.games.pronasledovani;
import java.io.File;
import java.io.IOException;
import org.andengine.opengl.texture.ITexture;
......@@ -7,52 +9,55 @@ import org.andengine.opengl.texture.TextureManager;
import org.andengine.opengl.texture.TextureOptions;
import org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlas;
import org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlasTextureRegionFactory;
import org.andengine.opengl.texture.bitmap.AssetBitmapTexture;
import org.andengine.opengl.texture.atlas.bitmap.source.FileBitmapTextureAtlasSource;
import org.andengine.opengl.texture.bitmap.BitmapTexture;
import org.andengine.opengl.texture.region.TextureRegion;
import android.content.Context;
import android.content.res.AssetManager;
import cz.nic.tablexia.Tablexia;
import cz.nic.tablexia.util.andengine.FileInputStreamOpener;
public class TexturesGenerator {
private static final String TEXTURES_BASE_PATH = "pronasledovani/textures/";
private static final String BACKGROUND_PATH = "pronasledovani/textures/background2.png";
private static final String SHADOW_PATH = "shadow.png";
private static final String CAR_PATH = "car.png";
private static final String FLAG_PATH = "flag.png";
private static final String TEXTURES_BASE_PATH = PronasledovaniActivity.BASE_DIR + "textures/";
private static final String BACKGROUND_PATH = PronasledovaniActivity.BASE_DIR + "textures/background2.png";
private static final String SHADOW_PATH = "shadow.png";
private static final String CAR_PATH = "car.png";
private static final String FLAG_PATH = "flag.png";
// auticko, ktere se zobraz po dohrani hry
private BitmapTextureAtlas carTexture;
private TextureRegion carTextureRegion;
private BitmapTextureAtlas carTexture;
private TextureRegion carTextureRegion;
// oznaceni sidla lupicu na mape
private BitmapTextureAtlas flagTexture;
private TextureRegion flagTextureRegion;
private BitmapTextureAtlas flagTexture;
private TextureRegion flagTextureRegion;
// textura predstavujici stin pod dilkem
private BitmapTextureAtlas shadowTexture;
private TextureRegion shadowTextureRegion;
private BitmapTextureAtlas shadowTexture;
private TextureRegion shadowTextureRegion;
// pozadi
private ITexture backgroundTexture;
private ITexture backgroundTexture;
public TexturesGenerator(Context context, TextureManager textureManager, AssetManager assetManager) {
Tablexia tablexia = (Tablexia) context.getApplicationContext();
// AUTICKO
carTexture = new BitmapTextureAtlas(textureManager, 54, 92, TextureOptions.BILINEAR);
BitmapTextureAtlasTextureRegionFactory.setAssetBasePath(TEXTURES_BASE_PATH);
carTextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(carTexture, context, CAR_PATH, 0, 0);
carTextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromSource(carTexture, FileBitmapTextureAtlasSource.create(new File(tablexia.getMountPath() + File.separator + TEXTURES_BASE_PATH + CAR_PATH)), 0, 0);
carTexture.load();
// VLAJKA OZNACUJICI SIDLO LUPICU
flagTexture = new BitmapTextureAtlas(textureManager, 127, 101, TextureOptions.BILINEAR);
flagTextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(flagTexture, context, FLAG_PATH, 0, 0);
flagTextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromSource(flagTexture, FileBitmapTextureAtlasSource.create(new File(tablexia.getMountPath() + File.separator + TEXTURES_BASE_PATH + FLAG_PATH)), 0, 0);
flagTexture.load();
shadowTexture = new BitmapTextureAtlas(textureManager, 352, 316, TextureOptions.BILINEAR);
BitmapTextureAtlasTextureRegionFactory.setAssetBasePath(TEXTURES_BASE_PATH);
shadowTextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(shadowTexture, context, SHADOW_PATH, 0, 0);
shadowTextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromSource(shadowTexture, FileBitmapTextureAtlasSource.create(new File(tablexia.getMountPath() + File.separator + TEXTURES_BASE_PATH + SHADOW_PATH)), 0, 0);
shadowTexture.load();
// POZADI
try {
backgroundTexture = new AssetBitmapTexture(textureManager, assetManager, BACKGROUND_PATH, TextureOptions.REPEATING_NEAREST_PREMULTIPLYALPHA);
backgroundTexture = new BitmapTexture(textureManager, new FileInputStreamOpener(new File(tablexia.getMountPath() + File.separator + TEXTURES_BASE_PATH + BACKGROUND_PATH)), TextureOptions.REPEATING_NEAREST_PREMULTIPLYALPHA);
} catch (IOException e) {
e.printStackTrace();
}
......
......@@ -19,6 +19,7 @@
package cz.nic.tablexia.game.games.unos;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
......@@ -167,7 +168,7 @@ public class UnosActivity extends GameActivity {
});
try {
Bitmap bm = BitmapHelper.getBitmapFromAsset(this, BASE_DIR + "gfx/ear.png");
Bitmap bm = BitmapHelper.getBitmapFromFile(this, getTablexiaContext().getMountPath() + File.separator + BASE_DIR + "gfx/ear.png");
ImageView imageViewEar = (ImageView) layoutInstructions.findViewById(R.id.imageView_ear);
imageViewEar.setImageBitmap(bm);
} catch (IOException e) {
......
......@@ -19,13 +19,13 @@
package cz.nic.tablexia.game.games.unos.media;
import java.io.File;
import java.io.IOException;
import java.util.Collection;
import java.util.HashMap;
import org.andengine.opengl.texture.Texture;
import org.andengine.opengl.texture.TextureManager;
import org.andengine.opengl.texture.bitmap.AssetBitmapTexture;
import org.andengine.opengl.texture.bitmap.BitmapTexture;
import org.andengine.opengl.texture.region.TextureRegion;
import org.andengine.opengl.texture.region.TextureRegionFactory;
......@@ -34,9 +34,11 @@ import android.content.Context;
import android.content.res.AssetManager;
import android.util.Log;
import android.util.Pair;
import cz.nic.tablexia.Tablexia;
import cz.nic.tablexia.game.games.unos.UnosActivity;
import cz.nic.tablexia.game.games.unos.generator.TextureType;
import cz.nic.tablexia.game.games.unos.model.Tile;
import cz.nic.tablexia.util.andengine.FileInputStreamOpener;
/**
* @author lhoracek
......@@ -53,26 +55,29 @@ public class GfxManager extends HashMap<TextureType, Pair<Texture, TextureRegion
private final AssetManager assetManager;
private final TileManager tileManager;
private final Context context;
public GfxManager(TextureManager textureManager, AssetManager assetManager, Context context) {
super();
this.textureManager = textureManager;
this.assetManager = assetManager;
tileManager = new TileManager(textureManager, assetManager, context);
this.context = context;
}
public void loadTextures(Collection<Tile> tiles) {
Tablexia tablexia = (Tablexia) context.getApplicationContext();
for (TextureType textureType : TextureType.values()) {
String path = TEXTURE_DIR + textureType.getResource() + TEXTURE_EXTENSION;
String path = tablexia.getMountPath() + File.separator + TEXTURE_DIR + textureType.getResource() + TEXTURE_EXTENSION;
try {
Log.v(TAG, "Loading texture " + textureType.getResource());
BitmapTexture texture = new AssetBitmapTexture(textureManager, assetManager, path);
Log.v(TAG, "Loading texture " + path);
BitmapTexture texture = new BitmapTexture(textureManager, new FileInputStreamOpener(new File(path)));
texture.load();
TextureRegion textureRegion = TextureRegionFactory.extractFromTexture(texture);
put(textureType, new Pair<Texture, TextureRegion>(texture, textureRegion));
} catch (IOException e) {
Log.e(TAG, "Error loading texture " + path);
// TODO remove TestFlight.log("Error loading texture " + path);
}
}
tileManager.loadTileTextures(tiles);
......
......@@ -19,6 +19,7 @@
package cz.nic.tablexia.game.games.unos.media;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
......@@ -36,6 +37,7 @@ import android.media.MediaPlayer.OnCompletionListener;
import com.activeandroid.util.Log;
import cz.nic.tablexia.Tablexia;
import cz.nic.tablexia.game.games.unos.UnosActivity;
import cz.nic.tablexia.game.games.unos.media.SoundType.SoundClass;
......@@ -77,9 +79,11 @@ public class MfxManager {
private void loadSound(SoundType sound) {
Tablexia tablexia = (Tablexia) context.getApplicationContext();
if (sound.getSoundClass() == SoundClass.SOUND) {
try {
Sound soundInstance = SoundFactory.createSoundFromAsset(soundManager, context, sound.getResource() + SOUNDS_EXTENSION);
Sound soundInstance = SoundFactory.createSoundFromPath(soundManager, tablexia.getMountPath() + File.separator + SOUNDS_DIR + sound.getResource() + SOUNDS_EXTENSION);
sounds.put(sound, soundInstance);
} catch (final IOException e) {
Log.e(TAG, "Error loading sound " + e.getMessage() + " - resource " + sound.getResource());
......@@ -88,7 +92,7 @@ public class MfxManager {
} else {
try {
Log.v(TAG, "Loading sound " + sound.getResource());
Music music = MusicFactory.createMusicFromAsset(musicManager, context, sound.getResource() + SOUNDS_EXTENSION);
Music music = MusicFactory.createMusicFromFile(musicManager, new File(tablexia.getMountPath() + File.separator + SOUNDS_DIR + sound.getResource() + SOUNDS_EXTENSION));
musics.put(sound, music);
} catch (final IOException e) {
Log.e(TAG, "Error loading sound " + e.getMessage() + " - resource: " + sound.getResource());
......@@ -140,7 +144,9 @@ public class MfxManager {
*/
public void playSound(String sound, final OnCompletionListener onCompletionListener, boolean isRetry) {
try {
Music music = MusicFactory.createMusicFromAsset(musicManager, context, sound + SOUNDS_EXTENSION);
Tablexia tablexia = (Tablexia) context.getApplicationContext();
Music music = MusicFactory.createMusicFromFile(musicManager, new File(tablexia.getMountPath() + File.separator + SOUNDS_DIR + sound + SOUNDS_EXTENSION));
music.setOnCompletionListener(new OnCompletionListener() {
@Override
......@@ -154,7 +160,6 @@ public class MfxManager {
music.play();
} catch (final IOException e) {
// TODO remove TestFlight.log("Error loading sound " + e.getMessage() + " - resource " + sound);
if (!isRetry) {
playSound(sound, onCompletionListener, true);
}
......
......@@ -19,6 +19,7 @@
package cz.nic.tablexia.game.games.unos.media;
import java.io.File;
import java.io.IOException;
import java.util.Collection;
import java.util.HashMap;
......@@ -27,7 +28,6 @@ import java.util.Set;
import org.andengine.opengl.texture.Texture;
import org.andengine.opengl.texture.TextureManager;
import org.andengine.opengl.texture.bitmap.AssetBitmapTexture;
import org.andengine.opengl.texture.bitmap.BitmapTexture;
import org.andengine.opengl.texture.region.TextureRegion;
import org.andengine.opengl.texture.region.TextureRegionFactory;
......@@ -36,8 +36,10 @@ import android.content.Context;
import android.content.res.AssetManager;
import android.util.Log;
import android.util.Pair;
import cz.nic.tablexia.Tablexia;
import cz.nic.tablexia.game.games.unos.UnosActivity;
import cz.nic.tablexia.game.games.unos.model.Tile;
import cz.nic.tablexia.util.andengine.FileInputStreamOpener;
/**
* @author lhoracek
......@@ -52,27 +54,30 @@ public class TileManager extends HashMap<Tile, Pair<Texture, TextureRegion>> {
private TextureManager textureManager;
private AssetManager assetManager;
private Context context;
public TileManager(TextureManager textureManager, AssetManager assetManager, Context context) {
super();
this.textureManager = textureManager;
this.assetManager = assetManager;
this.context = context;
}
public void loadTileTextures(Collection<Tile> tiles) {
Tablexia tablexia = (Tablexia) context.getApplicationContext();
Set<Tile> tileSet = new HashSet<Tile>(tiles);
for (Tile tile : tileSet) {
if (!containsKey(tile)) {
String path = TILES_DIR + tile.getResource() + TILES_EXTENSION;
String path = tablexia.getMountPath() + File.separator + TILES_DIR + tile.getResource() + TILES_EXTENSION;
try {
Log.v(TAG, "Loading tile " + tile.getResource());
BitmapTexture tileTexture = new AssetBitmapTexture(textureManager, assetManager, path);
Log.v(TAG, "Loading tile " + path);
BitmapTexture tileTexture = new BitmapTexture(textureManager, new FileInputStreamOpener(new File(path)));
tileTexture.load();
TextureRegion tileTextureRegion = TextureRegionFactory.extractFromTexture(tileTexture);
put(tile, new Pair<Texture, TextureRegion>(tileTexture, tileTextureRegion));
} catch (IOException e) {
Log.e(TAG, "Error loading texture " + path);
// TODO remove TestFlight.log("Error loading texture " + path);
}
}
}
......
......@@ -115,7 +115,10 @@ public class MainActivity extends FragmentActivity implements MenuActivity {
// show menu toggle button when there is selected user
if (getTablexiaContext().getSelectedUser() != null) {
findViewById(R.id.mainmenu_rightborder).setVisibility(View.VISIBLE);
View v = findViewById(R.id.mainmenu_rightborder);
if (v != null) {
v.setVisibility(View.VISIBLE);
}
}
getTablexiaContext().showAllScreen(null);
......
/*******************************************************************************
* Tablexia
* Tablexia
*
* Copyright (C) 2013 CZ NIC z.s.p.o. <podpora at nic dot cz>
*
......@@ -20,10 +20,8 @@
package cz.nic.tablexia.util;
import java.io.IOException;
import java.io.InputStream;
import android.content.Context;
import android.content.res.AssetManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
......@@ -31,10 +29,8 @@ import android.graphics.BitmapFactory;
* @author lhoracek
*/
public class BitmapHelper {
public static Bitmap getBitmapFromAsset(Context context, String strName) throws IOException {
AssetManager assetManager = context.getAssets();
InputStream istr = assetManager.open(strName);
Bitmap bitmap = BitmapFactory.decodeStream(istr);
public static Bitmap getBitmapFromFile(Context context, String strName) throws IOException {
Bitmap bitmap = BitmapFactory.decodeFile(strName);
return bitmap;
}
}
/**
*
*/
package cz.nic.tablexia.util.andengine;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import org.andengine.util.adt.io.in.IInputStreamOpener;
import android.util.Log;
/**
* @author lhoracek
*/
public class FileInputStreamOpener implements IInputStreamOpener {
private static final String TAG = FileInputStreamOpener.class.getSimpleName();
private final File file;
public FileInputStreamOpener(File file) {
super();
this.file = file;
}
@Override
public InputStream open() throws IOException {
Log.i(TAG, "Opening stream for: " + file.getPath());
return new FileInputStream(file);
}
}