Java Code Examples for com.badlogic.gdx.Application

The following examples show how to use com.badlogic.gdx.Application. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Override
public void playSourceInstance(AudioNode audioNode) {
    Gdx.app.log("GdxAudioRenderer", "playSourceInstance");
    GdxAudioData audioData;
    audioData = (GdxAudioData) audioNode.getAudioData();
    Music music = musicMap.get(audioNode);
    if (Gdx.app.getType() == Application.ApplicationType.iOS && audioData.getAssetKey().getName().endsWith(".ogg")) {
        return;
    }
    if (music == null) {
        music = Gdx.audio.newMusic(GdxAssetCache.getFileHandle(audioData.getAssetKey().getName()));
        musicMap.put(audioNode, music);
    }
    music.stop();
    music.play();
    audioNode.setStatus(AudioNode.Status.Playing);
}
 
Example 2
Source Project: gdx-fireapp   Source File: DatabaseTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
    public void readValue() throws Exception {
        // Given
        String testReference = "test_reference";
        Database database = new Database();
        mockStatic(QueryReadValue.class);
        QueryReadValue query = spy(new QueryReadValue(database, testReference));
        PowerMockito.whenNew(QueryReadValue.class).withAnyArguments().thenReturn(query);
        Gdx.app = Mockito.mock(Application.class);
        Class dataType = String.class;


        // When
        ((FuturePromise) database.inReference(testReference).readValue(dataType).subscribe()).doComplete(testReference);

        // Then
//        PowerMockito.verifyNew(ReadValueQuery.class).withArguments(Mockito.any());
        PowerMockito.verifyStatic(QueryReadValue.class);
        QueryReadValue.once(Mockito.any(DatabaseReference.class), Mockito.any(ConverterPromise.class));
    }
 
Example 3
Source Project: gdx-fireapp   Source File: DatabaseTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
    public void onDataChange() throws Exception {
        // Given
        String testReference = "test_reference";
        Database database = new Database();
        mockStatic(QueryOnDataChange.class);
        QueryOnDataChange query = spy(new QueryOnDataChange(database, testReference));
        PowerMockito.whenNew(QueryOnDataChange.class).withAnyArguments().thenReturn(query);
        Gdx.app = Mockito.mock(Application.class);
        PowerMockito.doReturn(false).when(GwtDataPromisesManager.class, "hasPromise", testReference);
        Class dataType = String.class;

        // When
        ((FuturePromise) database.inReference(testReference).onDataChange(dataType).subscribe()).doComplete(testReference);

        // Then
//        PowerMockito.verifyNew(OnDataChangeQuery.class).withArguments(Mockito.any());
        PowerMockito.verifyStatic(QueryOnDataChange.class);
        QueryOnDataChange.onValue(eq(testReference), Mockito.any(DatabaseReference.class));
    }
 
Example 4
Source Project: gdx-fireapp   Source File: DatabaseTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void onChildChange() throws Exception {
    // Given
    String testReference = "test_reference";
    Database database = new Database();
    mockStatic(QueryOnChildChange.class);
    QueryOnChildChange query = spy(new QueryOnChildChange(database, testReference));
    PowerMockito.whenNew(QueryOnChildChange.class).withAnyArguments().thenReturn(query);
    Gdx.app = Mockito.mock(Application.class);
    PowerMockito.doReturn(false).when(GwtDataPromisesManager.class, "hasPromise", testReference + "child_added");
    Class dataType = String.class;

    // When
    ((FuturePromise) database.inReference(testReference)
            .onChildChange(dataType, ChildEventType.ADDED).subscribe()).doComplete(testReference);

    // Then
    PowerMockito.verifyStatic(QueryOnChildChange.class);
    QueryOnChildChange.onEvent(eq(testReference), eq("child_added"), Mockito.any(DatabaseReference.class));
}
 
Example 5
Source Project: gdx-fireapp   Source File: DatabaseTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
    public void onDataChange_detach() throws Exception {
        // Given
        String testReference = "test_reference";
        Database database = new Database();
        mockStatic(QueryOnDataChange.class);
        QueryOnDataChange query = spy(new QueryOnDataChange(database, testReference));
        PowerMockito.whenNew(QueryOnDataChange.class).withAnyArguments().thenReturn(query);
        PowerMockito.doReturn(false).when(GwtDataPromisesManager.class, "hasPromise", testReference);
        GwtDataPromisesManager.removeDataPromise(testReference);
        Gdx.app = Mockito.mock(Application.class);

        // When
        FutureListenerPromise promise = ((FutureListenerPromise) database.inReference(testReference).onDataChange(String.class).subscribe());
        promise.doComplete(testReference);
        PowerMockito.doReturn(true).when(GwtDataPromisesManager.class, "hasPromise", testReference);
        promise.cancel();

        // Then
//        PowerMockito.verifyNew(OnDataChangeQuery.class).withArguments(Mockito.any());
        PowerMockito.verifyStatic(QueryOnDataChange.class);
        QueryOnDataChange.offValue(eq(testReference));
    }
 
Example 6
Source Project: gdx-fireapp   Source File: AndroidContextTest.java    License: Apache License 2.0 6 votes vote down vote up
@Before
public void setup() throws Exception {
    PowerMockito.mockStatic(GdxNativesLoader.class);
    AndroidApplication application = PowerMockito.mock(AndroidApplication.class);
    Mockito.when(application.getType()).thenReturn(Application.ApplicationType.Android);
    Gdx.app = application;
    PowerMockito.mockStatic(Timer.class);
    PowerMockito.when(Timer.post(any(Timer.Task.class))).then(new Answer() {
        @Override
        public Object answer(InvocationOnMock invocation) {
            ((Timer.Task) invocation.getArgument(0)).run();
            return null;
        }
    });
    GdxFIRApp.setThrowFailureByDefault(false);
}
 
Example 7
Source Project: gdx-fireapp   Source File: PlatformDistributor.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Creates platform specific object by reflection.
 * <p>
 * Uses class names given by {@link #getAndroidClassName()} and {@link #getIOSClassName()}
 * <p>
 * If you need to run project on different platform use {@link #setMockObject(Object)} to polyfill platform object.
 *
 * @throws PlatformDistributorException Throws when something is wrong with environment
 */
@SuppressWarnings("unchecked")
protected PlatformDistributor() {
    String className = null;
    if (Gdx.app.getType() == Application.ApplicationType.Android) {
        className = getAndroidClassName();
    } else if (Gdx.app.getType() == Application.ApplicationType.iOS) {
        className = getIOSClassName();
    } else if (Gdx.app.getType() == Application.ApplicationType.WebGL) {
        className = getWebGLClassName();
    } else {
        return;
    }
    try {
        Class objClass = ClassReflection.forName(className);
        platformObject = (T) ClassReflection.getConstructor(objClass).newInstance();
    } catch (ReflectionException e) {
        throw new PlatformDistributorException("Something wrong with environment", e);
    }
}
 
Example 8
Source Project: dice-heroes   Source File: UserDataHelper.java    License: GNU General Public License v3.0 6 votes vote down vote up
void saveUserData(UserData userData) {
    DumperOptions options = new DumperOptions();
    options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
    String toSave = new Yaml(options).dump(UserData.serialize(userData));
    if (Gdx.app.getType() == Application.ApplicationType.Desktop) {
        Gdx.files.local("game.save").writeString(toSave, false);
        return;
    }
    try {
        loadKey();
        byte[] bytes = encrypt(key, toSave.getBytes("UTF-8"));
        Gdx.files.local("game.save").writeBytes(bytes, false);
    } catch (Exception e) {
        Gdx.files.local("game.save").writeString(toSave, false);
    }
}
 
Example 9
Source Project: dice-heroes   Source File: DiceHeroes.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
public void create() {
    Gdx.app.setLogLevel(Application.LOG_DEBUG);
    Gdx.input.setCatchBackKey(true);
    Gdx.input.setCatchMenuKey(true);
    Config.clearRegions();
    Config.shapeRenderer = new ShapeRenderer();
    Config.assetManager = new AssetManager();
    Config.preferences = new DicePreferences(Gdx.app.getPreferences("com.vlaaad.dice.preferences"), this);
    Tutorial.killAll();

    setState(new IntroState(new IntroState.Callback() {
        @Override public void onEnded() {
            setScale(Config.preferences.getScale());
            setState(new LoadGameResourcesState(new LoadGameResourcesState.Callback() {
                @Override
                public void onResourcesLoaded() {
                    start();
                }
            }));
        }
    }));
}
 
Example 10
Source Project: gdx-facebook   Source File: GDXFacebookLoaderUnitTests.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void returnIOSGDXFacebookWhenOnIOS() {
    Application mockApplication = mock(Application.class);
    when(mockApplication.getType()).thenReturn(Application.ApplicationType.iOS);
    Gdx.app = mockApplication;

    try {
        Constructor mockConstructor = PowerMockito.mock(Constructor.class);
        GDXFacebook mockFacebook = mock(IOSGDXFacebook.class);

        when(ClassReflection.forName(GDXFacebookVars.CLASSNAME_IOS)).thenReturn(IOSGDXFacebook.class);
        when(ClassReflection.getConstructor(IOSGDXFacebook.class, GDXFacebookConfig.class)).thenReturn(mockConstructor);
        when(mockConstructor.newInstance(anyObject())).thenReturn(mockFacebook);

    } catch (ReflectionException e) {
        e.printStackTrace();
    }

    facebook = GDXFacebookSystem.install(new GDXFacebookConfig());
    assertTrue(facebook instanceof IOSGDXFacebook);
}
 
Example 11
Source Project: gdx-facebook   Source File: GDXFacebookLoaderUnitTests.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void returnDesktopGDXFacebookWhenOnDesktop() {
    Application mockApplication = mock(Application.class);
    when(mockApplication.getType()).thenReturn(Application.ApplicationType.Desktop);
    Gdx.app = mockApplication;

    try {
        Constructor mockConstructor = PowerMockito.mock(Constructor.class);
        GDXFacebook mockFacebook = mock(DesktopGDXFacebook.class);

        when(ClassReflection.forName(GDXFacebookVars.CLASSNAME_DESKTOP)).thenReturn(DesktopGDXFacebook.class);
        when(ClassReflection.getConstructor(DesktopGDXFacebook.class, GDXFacebookConfig.class)).thenReturn(mockConstructor);
        when(mockConstructor.newInstance(anyObject())).thenReturn(mockFacebook);

    } catch (ReflectionException e) {
        e.printStackTrace();
    }

    facebook = GDXFacebookSystem.install(new GDXFacebookConfig());
    assertTrue(facebook instanceof DesktopGDXFacebook);
}
 
Example 12
Source Project: gdx-facebook   Source File: GDXFacebookLoaderUnitTests.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void returnHTMLGDXFacebookWhenOnWebGL() {
    Application mockApplication = mock(Application.class);
    when(mockApplication.getType()).thenReturn(Application.ApplicationType.WebGL);
    Gdx.app = mockApplication;

    try {
        Constructor mockConstructor = PowerMockito.mock(Constructor.class);
        GDXFacebook mockFacebook = mock(HTMLGDXFacebook.class);

        when(ClassReflection.forName(GDXFacebookVars.CLASSNAME_HTML)).thenReturn(HTMLGDXFacebook.class);
        when(ClassReflection.getConstructor(HTMLGDXFacebook.class, GDXFacebookConfig.class)).thenReturn(mockConstructor);
        when(mockConstructor.newInstance(anyObject())).thenReturn(mockFacebook);

    } catch (ReflectionException e) {
        e.printStackTrace();
    }

    facebook = GDXFacebookSystem.install(new GDXFacebookConfig());
    assertTrue(facebook instanceof HTMLGDXFacebook);
}
 
Example 13
Source Project: Radix   Source File: DesktopLauncher.java    License: MIT License 6 votes vote down vote up
public static void main (String[] arg) {
LwjglApplicationConfiguration config;
      FileHandle glConfigFile = new FileHandle("conf/lwjgl.json");
      Gson gson = new GsonBuilder().setPrettyPrinting().create();
      if(!glConfigFile.exists()) {
          config = createDefaultConfig();
          glConfigFile.writeString(gson.toJson(config), false);
      } else {
          try {
              config = gson.fromJson(glConfigFile.readString(), LwjglApplicationConfiguration.class);
          } catch (Exception e) {
              e.printStackTrace();
              System.err.println("Error reading lwjgl config! Using defaults.");
              config = createDefaultConfig();
          }
      }
new LwjglApplication(new RadixClient(), config);
      Gdx.app.setLogLevel(Application.LOG_DEBUG);
  }
 
Example 14
Source Project: riiablo   Source File: MSI.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void create() {
  Gdx.app.setLogLevel(Application.LOG_DEBUG);

  final Calendar calendar = Calendar.getInstance();
  DateFormat format = DateFormat.getDateTimeInstance();
  Gdx.app.log(TAG, format.format(calendar.getTime()));

  try {
    InetAddress address = InetAddress.getLocalHost();
    Gdx.app.log(TAG, "IP Address: " + address.getHostAddress() + ":" + PORT);
    Gdx.app.log(TAG, "Host Name: " + address.getHostName());
  } catch (UnknownHostException e) {
    Gdx.app.error(TAG, e.getMessage(), e);
  }

  Gdx.app.log(TAG, "Starting server...");
  server = Gdx.net.newServerSocket(Net.Protocol.TCP, PORT, null);
  buffer = BufferUtils.newByteBuffer(4096);
}
 
Example 15
Source Project: riiablo   Source File: GdxKeyMapper.java    License: Apache License 2.0 6 votes vote down vote up
@Nullable
@Override
public int[] load(MappedKey key) {
  String alias = key.getAlias();
  String serializedValue = PREFERENCES.getString(alias);
  if (serializedValue == null || serializedValue.isEmpty()) return null;

  int[] assignments;
  try {
    assignments = IntArrayStringSerializer.INSTANCE.deserialize(serializedValue);
  } catch (SerializeException t) {
    Gdx.app.error(TAG, String.format("removing %s from preferences (invalid save format): %s", alias, t.getMessage()), t);
    PREFERENCES.remove(alias);
    PREFERENCES.flush();
    throw t;
  }

  if (Gdx.app.getLogLevel() >= Application.LOG_DEBUG) {
    String[] keycodeNames = getKeycodeNames(assignments);
    Gdx.app.debug(TAG, String.format("%s [%s] loaded as %s (raw: \"%s\")",
        key.getName(), key.getAlias(), Arrays.toString(keycodeNames), serializedValue));
  }

  KEYS.put(alias.toLowerCase(), key);
  return assignments;
}
 
Example 16
Source Project: riiablo   Source File: GdxKeyMapper.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void save(MappedKey key) {
  if (Gdx.app.getLogLevel() >= Application.LOG_DEBUG && !isManaging(key)) {
    Gdx.app.debug(TAG, String.format("key %s is being saved by a key mapper not managing it", key));
  }

  int[] assignments = key.getAssignments();
  String serializedValue = IntArrayStringSerializer.INSTANCE.serialize(assignments);
  PREFERENCES.putString(key.getAlias(), serializedValue);
  PREFERENCES.flush();
  if (Gdx.app.getLogLevel() >= Application.LOG_DEBUG) {
    String[] keycodeNames = getKeycodeNames(assignments);
    Gdx.app.debug(TAG, String.format("%s [%s] saved as %s (raw: \"%s\")",
        key.getName(), key.getAlias(), Arrays.toString(keycodeNames), serializedValue));
  }
}
 
Example 17
Source Project: riiablo   Source File: GdxCvarManager.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public <T> void save(Cvar<T> cvar) {
  String alias = cvar.getAlias();
  if (Gdx.app.getLogLevel() >= Application.LOG_DEBUG && !isManaging(cvar)) {
    throw new CvarManagerException("%s must be managed by this CvarManager", alias);
  }

  StringSerializer<T> serializer = ObjectUtils.firstNonNull(cvar.getSerializer(), getSerializer(cvar));
  if (serializer == null) {
    throw new CvarManagerException("%s cannot be saved (no serializer found for %s)", alias, cvar.getType().getName());
  }

  T value = cvar.get();
  String serialization = serializer.serialize(value);
  PREFERENCES.putString(alias, serialization);
  PREFERENCES.flush();
  if (Gdx.app.getLogLevel() >= Application.LOG_DEBUG) {
    Gdx.app.debug(TAG, String.format("%s saved as \"%s\" (raw: \"%s\")", alias, value, serialization));
  }
}
 
Example 18
Source Project: riiablo   Source File: GdxCvarManager.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public <T> T load(Cvar<T> cvar) {
  String alias = cvar.getAlias();
  StringSerializer<T> serializer = ObjectUtils.firstNonNull(cvar.getSerializer(), getSerializer(cvar));
  if (serializer == null) {
    try {
      throw new CvarManagerException("%s cannot be loaded (no deserializer found for %s)", alias, cvar.getType().getName());
    } finally {
      return cvar.getDefault();
    }
  }

  String serialization = PREFERENCES.getString(alias, null);
  if (serialization == null) return cvar.getDefault();

  T deserialization = serializer.deserialize(serialization);
  if (Gdx.app.getLogLevel() >= Application.LOG_DEBUG) {
    Gdx.app.debug(TAG, String.format("%s loaded as \"%s\" [%s] (raw: \"%s\")",
        alias, deserialization, deserialization.getClass().getName(), serialization));
  }

  return deserialization;
}
 
Example 19
Source Project: riiablo   Source File: MusicController.java    License: Apache License 2.0 6 votes vote down vote up
public void next() {
  stop();
  if (PLAYLIST.isEmpty()) {
    return;
  }

  this.asset = PLAYLIST.removeFirst();
  ASSETS.load(asset, Music.class);
  ASSETS.finishLoadingAsset(asset);
  this.track = ASSETS.get(asset, Music.class);
  track.setOnCompletionListener(this);
  track.play();
  if (Gdx.app.getLogLevel() >= Application.LOG_DEBUG) {
    Gdx.app.debug(TAG, "Now playing \"" + asset + "\"");
  }
}
 
Example 20
Source Project: Mundus   Source File: ShaderUtils.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Compiles and links shader.
 *
 * @param vertexShader
 *            path to vertex shader
 * @param fragmentShader
 *            path to fragment shader
 *
 * @return compiled shader program
 */
public static ShaderProgram compile(String vertexShader, String fragmentShader) {
    String vert;
    String frag;

    if (Gdx.app.getType() == Application.ApplicationType.WebGL) {
        vert = Gdx.files.internal(vertexShader).readString();
        frag = Gdx.files.internal(fragmentShader).readString();
    } else {
        vert = Gdx.files.classpath(vertexShader).readString();
        frag = Gdx.files.classpath(fragmentShader).readString();
    }

    ShaderProgram program = new ShaderProgram(vert, frag);
    if (!program.isCompiled()) {
        throw new GdxRuntimeException(program.getLog());
    }

    return program;
}
 
Example 21
Source Project: Cubes   Source File: DesktopCompatibility.java    License: MIT License 6 votes vote down vote up
protected DesktopCompatibility(DesktopLauncher desktopLauncher, Application.ApplicationType applicationType, String[] arg) {
  super(desktopLauncher, applicationType);
  this.arg = arg;

  String str = (System.getProperty("os.name")).toUpperCase();
  if (str.contains("WIN")) {
    os = OS.Windows;
  } else if (str.contains("MAC")) {
    os = OS.Mac;
  } else if (str.contains("LINUX")) {
    os = OS.Linux;
  } else {
    os = OS.Unknown;
  }

  modLoader = new DesktopModLoader();
}
 
Example 22
Source Project: Cubes   Source File: Screenshot.java    License: MIT License 6 votes vote down vote up
public static Setting screenshotResolutionSetting() {
  return new DropDownSetting(resolutions) {
    @Override
    public void onChange() {
      if ("normal".equals(selected) || "max".equals(selected)) return;

      IntBuffer intBuffer = BufferUtils.newIntBuffer(2);
      Gdx.gl20.glGetIntegerv(GL20.GL_MAX_VIEWPORT_DIMS, intBuffer);
      int maxWidth = intBuffer.get(0);
      int maxHeight = intBuffer.get(1);

      int[] resolution = resolutionMap.get(selected);
      if (resolution[0] > maxWidth || resolution[1] > maxHeight) selected = "normal";
    }

    @Override
    public boolean shouldDisplay() {
      return Compatibility.get().getApplicationType() == Application.ApplicationType.Desktop;
    }
  };
}
 
Example 23
Source Project: Cubes   Source File: CubesShaderProvider.java    License: MIT License 6 votes vote down vote up
public static Setting getSetting() {
  return new BooleanSetting(false) {
    @Override
    public boolean shouldDisplay() {
      return Compatibility.get().getApplicationType() == Application.ApplicationType.Desktop;
    }

    @Override
    public void onChange() {
      super.onChange();
      Log.debug("Emptying shader cache");
      for (int i = 0; i < shaders.length; i++) {
        if (shaders[i] != null) shaders[i].dispose();
        shaders[i] = null;
      }
    }
  };
}
 
Example 24
Source Project: gdx-vfx   Source File: MotionBlurEffect.java    License: Apache License 2.0 5 votes vote down vote up
public MotionBlurEffect(Pixmap.Format pixelFormat, MixEffect.Method mixMethod, float blurFactor) {
	mixFilter = register(new MixEffect(mixMethod));
	mixFilter.setMixFactor(blurFactor);

	copyFilter = register(new CopyEffect());

	localBuffer = new VfxFrameBufferQueue(pixelFormat,
			// On WebGL (GWT) we cannot render from/into the same texture simultaneously.
			// Will use ping-pong approach to avoid "writing into itself".
			Gdx.app.getType() == Application.ApplicationType.WebGL ? 2 : 1
	);
}
 
Example 25
Source Project: gdx-gamesvcs   Source File: GpgsClient.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Gdx to Log4j log level mapping
 */
private static Level getLogLevel(int logLevel) {
    switch (logLevel) {
        case Application.LOG_NONE:
            return Level.OFF;
        case Application.LOG_ERROR:
            return Level.SEVERE;
        case Application.LOG_INFO:
            return Level.INFO;
        case Application.LOG_DEBUG:
            return Level.FINEST;
        default:
            return Level.ALL;
    }
}
 
Example 26
Source Project: Klooni1010   Source File: Klooni.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public void create() {
    onDesktop = Gdx.app.getType().equals(Application.ApplicationType.Desktop);
    prefs = Gdx.app.getPreferences("dev.lonami.klooni.game");

    // Load the best match for the skin (depending on the device screen dimensions)
    skin = SkinLoader.loadSkin();

    // Use only one instance for the theme, so anyone using it uses the most up-to-date
    Theme.skin = skin; // Not the best idea
    final String themeName = prefs.getString("themeName", "default");
    if (Theme.exists(themeName))
        theme = Theme.getTheme(themeName);
    else
        theme = Theme.getTheme("default");

    Gdx.input.setCatchBackKey(true); // To show the pause menu
    setScreen(new MainMenuScreen(this));
    String effectName = prefs.getString("effectName", "vanish");
    effectSounds = new HashMap<String, Sound>(EFFECTS.length);
    effect = EFFECTS[0];
    for (IEffectFactory e : EFFECTS) {
        loadEffectSound(e.getName());
        if (e.getName().equals(effectName)) {
            effect = e;
        }
    }
}
 
Example 27
Source Project: gdx-fireapp   Source File: DatabaseTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void setPersistenceEnabled() {
    // Given
    Database database = new Database();
    Application application = Mockito.mock(Application.class);
    Gdx.app = application;

    // When
    database.setPersistenceEnabled(true);

    // Then
    Mockito.verify(application).log(Mockito.anyString(), Mockito.anyString());
}
 
Example 28
Source Project: gdx-fireapp   Source File: TextureRegionDownloader.java    License: Apache License 2.0 5 votes vote down vote up
FuturePromise<TextureRegion> download() {
    return FuturePromise.when(new Consumer<FuturePromise<TextureRegion>>() {
        @Override
        public void accept(final FuturePromise<TextureRegion> textureRegionFuturePromise) {
            GdxFIRStorage.instance().download(path, Long.MAX_VALUE).then(new Consumer<byte[]>() {
                @Override
                public void accept(final byte[] bytes) {
                    Gdx.app.postRunnable(new Runnable() {
                        @Override
                        public void run() {
                            if (Gdx.app.getType() != Application.ApplicationType.WebGL) {
                                TextureRegion region = imageHelper.createTextureFromBytes(bytes);
                                textureRegionFuturePromise.doComplete(region);
                            } else {
                                imageHelper.createTextureFromBytes(bytes, new Consumer<TextureRegion>() {
                                    @Override
                                    public void accept(TextureRegion textureRegion) {
                                        textureRegionFuturePromise.doComplete(textureRegion);
                                    }
                                });
                            }
                        }
                    });
                }
            }).fail(new BiConsumer<String, Throwable>() {
                @Override
                public void accept(String s, Throwable throwable) {
                    textureRegionFuturePromise.doFail(s, throwable);
                }
            });
        }
    });
}
 
Example 29
Source Project: gdx-fireapp   Source File: JavaCoreClassDetectorTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void isJavaCoreClass() {
    Assert.assertTrue(JavaCoreClassDetector.isJavaCoreClass(String.class));
    Assert.assertTrue(JavaCoreClassDetector.isJavaCoreClass(Number.class));
    Assert.assertTrue(JavaCoreClassDetector.isJavaCoreClass(ArrayList.class));
    Assert.assertTrue(JavaCoreClassDetector.isJavaCoreClass(RuntimeException.class));
    Assert.assertTrue(JavaCoreClassDetector.isJavaCoreClass(HashMap.class));
    Assert.assertFalse(JavaCoreClassDetector.isJavaCoreClass(Application.class));
    Assert.assertFalse(JavaCoreClassDetector.isJavaCoreClass(Array.class));
    Assert.assertFalse(JavaCoreClassDetector.isJavaCoreClass(Pixmap.class));
    Assert.assertFalse(JavaCoreClassDetector.isJavaCoreClass(SpriteBatch.class));
    Assert.assertFalse(JavaCoreClassDetector.isJavaCoreClass(GdxFirebaseUser.class));
}
 
Example 30
Source Project: gdx-fireapp   Source File: GdxIOSAppTest.java    License: Apache License 2.0 5 votes vote down vote up
@Before
public void setup() {
    PowerMockito.mockStatic(NatJ.class);
    IOSApplication application = Mockito.mock(IOSApplication.class);
    Mockito.when(application.getType()).thenReturn(Application.ApplicationType.iOS);
    Gdx.app = application;
    GdxFIRApp.setThrowFailureByDefault(false);
}