com.badlogic.gdx.backends.android.AndroidApplication Java Examples

The following examples show how to use com.badlogic.gdx.backends.android.AndroidApplication. 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
Source File: WndAndroidTextInput.java    From shattered-pixel-dungeon with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void destroy() {
	super.destroy();
	if (textInput != null){
		((AndroidApplication)Gdx.app).runOnUiThread(new Runnable() {
			@Override
			public void run() {
				//make sure we remove the edit text and soft keyboard
				((ViewGroup) textInput.getParent()).removeView(textInput);

				InputMethodManager imm = (InputMethodManager)((AndroidApplication)Gdx.app).getSystemService(Activity.INPUT_METHOD_SERVICE);
				imm.hideSoftInputFromWindow(((AndroidGraphics)Gdx.app.getGraphics()).getView().getWindowToken(), 0);

				//Soft keyboard sometimes triggers software buttons, so make sure to reassert immersive
				ShatteredPixelDungeon.updateSystemUI();

				textInput = null;
			}
		});
	}
}
 
Example #2
Source File: CrashTest.java    From gdx-fireapp with Apache License 2.0 6 votes vote down vote up
@Test
public void initialize() {
    // Given
    PowerMockito.mockStatic(Crashlytics.class);
    PowerMockito.mockStatic(Fabric.class);
    Crash crash = new Crash();

    // When
    crash.initialize();
    crash.initialize();
    crash.initialize();

    // Then
    PowerMockito.verifyStatic(Fabric.class, VerificationModeFactory.times(1));
    Fabric.with(Mockito.any(AndroidApplication.class), Mockito.any(Crashlytics.class));
    PowerMockito.verifyNoMoreInteractions(Fabric.class);
}
 
Example #3
Source File: GoogleAuth.java    From gdx-fireapp with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public Promise<Void> signOut() {
    return FuturePromise.when(new Consumer<FuturePromise<Void>>() {
        @Override
        public void accept(final FuturePromise<Void> voidFuturePromise) {
            GoogleSignInClient client = GoogleSignIn.getClient((AndroidApplication) Gdx.app, GoogleSignInOptionsFactory.factory());
            client.signOut().addOnCompleteListener(new OnCompleteListener<Void>() {
                @Override
                public void onComplete(@NonNull Task<Void> task) {
                    if (task.isSuccessful()) {
                        voidFuturePromise.doComplete(null);
                    } else {
                        voidFuturePromise.doFail(task.getException());
                    }
                }
            });
        }
    });
}
 
Example #4
Source File: GoogleAuth.java    From gdx-fireapp with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public Promise<Void> revokeAccess() {
    return FuturePromise.when(new Consumer<FuturePromise<Void>>() {
        @Override
        public void accept(final FuturePromise<Void> voidFuturePromise) {
            GoogleSignInClient client = GoogleSignIn.getClient((AndroidApplication) Gdx.app, GoogleSignInOptionsFactory.factory());
            client.revokeAccess().addOnCompleteListener(new OnCompleteListener<Void>() {
                @Override
                public void onComplete(@NonNull Task<Void> task) {
                    if (task.isSuccessful()) {
                        voidFuturePromise.doComplete(null);
                    } else {
                        voidFuturePromise.doFail(task.getException());
                    }
                }
            });
        }
    });
}
 
Example #5
Source File: AndroidContextTest.java    From gdx-fireapp with 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 #6
Source File: AnalyticsTest.java    From gdx-fireapp with Apache License 2.0 6 votes vote down vote up
@Test
public void setScreen() {
    // Given
    Analytics analytics = new Analytics();
    Mockito.doAnswer(new Answer() {
        @Override
        public Object answer(InvocationOnMock invocation) {
            ((Runnable) invocation.getArgument(0)).run();
            return null;
        }
    }).when(((AndroidApplication) Gdx.app)).runOnUiThread(Mockito.any(Runnable.class));


    // When
    analytics.setScreen("test", AnalyticsTest.class);

    // Then
    PowerMockito.verifyStatic(FirebaseAnalytics.class, VerificationModeFactory.times(1));
    FirebaseAnalytics.getInstance((Context) Gdx.app);
    Mockito.verify(firebaseAnalytics, VerificationModeFactory.times(1))
            .setCurrentScreen(Mockito.eq((Activity) Gdx.app), Mockito.eq("test"), Mockito.eq(AnalyticsTest.class.getSimpleName()));
    Mockito.verifyNoMoreInteractions(firebaseAnalytics);
}
 
Example #7
Source File: GoogleSignInListenerTest.java    From gdx-fireapp with Apache License 2.0 6 votes vote down vote up
@Test
public void onActivityResult_validRequestCode_apiException() throws Throwable {
    // Given
    FuturePromise promise = Mockito.mock(FuturePromise.class);
    GoogleSignInListener listener = new GoogleSignInListener(promise);
    Intent intent = PowerMockito.mock(Intent.class);
    int requestCode = Const.GOOGLE_SIGN_IN;
    int resultCode = -1;
    final Task task = Mockito.mock(Task.class);
    Mockito.when(task.getResult(ApiException.class)).then(new Answer<Object>() {
        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            throw new ApiException(Status.RESULT_CANCELED);
        }
    });
    Mockito.when(GoogleSignIn.getSignedInAccountFromIntent(Mockito.any(Intent.class))).thenReturn(task);

    // When
    listener.onActivityResult(requestCode, resultCode, intent);

    // Then
    Mockito.verify(((AndroidApplication) Gdx.app), VerificationModeFactory.times(1)).removeAndroidEventListener(Mockito.refEq(listener));
    Mockito.verify(promise, VerificationModeFactory.times(1)).doFail(Mockito.nullable(Exception.class));
}
 
Example #8
Source File: GoogleSignInListenerTest.java    From gdx-fireapp with Apache License 2.0 5 votes vote down vote up
@Test
public void onActivityResult_wrongRequestCode() {
    // Given
    FuturePromise promise = Mockito.mock(FuturePromise.class);
    GoogleSignInListener listener = new GoogleSignInListener(promise);
    Intent intent = PowerMockito.mock(Intent.class);
    int requestCode = -1;
    int resultCode = -1;

    // When
    listener.onActivityResult(requestCode, resultCode, intent);

    // Then
    Mockito.verify(((AndroidApplication) Gdx.app), VerificationModeFactory.times(1)).removeAndroidEventListener(Mockito.refEq(listener));
}
 
Example #9
Source File: GoogleAuthTest.java    From gdx-fireapp with Apache License 2.0 5 votes vote down vote up
@Test
public void signIn() {
    // Given
    // mock GoogleSignInOptions?
    GoogleAuth googleAuth = new GoogleAuth();

    // When
    googleAuth.signIn().subscribe();

    // Then
    Mockito.verify(((AndroidApplication) Gdx.app), VerificationModeFactory.times(1)).startActivityForResult(Mockito.nullable(Intent.class), Mockito.anyInt());
    PowerMockito.verifyStatic(GoogleSignIn.class, VerificationModeFactory.times(1));
    GoogleSignIn.getClient((Activity) Mockito.refEq(Gdx.app), Mockito.any(GoogleSignInOptions.class));
}
 
Example #10
Source File: StringResourceTest.java    From gdx-fireapp with Apache License 2.0 5 votes vote down vote up
@Test
public void getStringResourceByName() {
    // Given
    Resources resources = Mockito.mock(Resources.class);
    String name = "test";
    Mockito.when(((AndroidApplication) Gdx.app).getResources()).thenReturn(resources);
    Mockito.when(resources.getString(Mockito.anyInt())).thenReturn("test_return");

    // When
    String result = StringResource.getStringResourceByName(name);

    // Then
    Assert.assertEquals("test_return", result);
}
 
Example #11
Source File: GoogleSignInListenerTest.java    From gdx-fireapp with Apache License 2.0 5 votes vote down vote up
@Test
public void onActivityResult_validRequestCode_failTask() throws Throwable {
    // Given
    FuturePromise promise = Mockito.mock(FuturePromise.class);
    GoogleSignInListener listener = new GoogleSignInListener(promise);
    Intent intent = PowerMockito.mock(Intent.class);
    int requestCode = Const.GOOGLE_SIGN_IN;
    int resultCode = -1;
    final Task task = Mockito.mock(Task.class);
    Mockito.when(task.getResult(ApiException.class)).thenReturn(Mockito.mock(GoogleSignInAccount.class));
    Mockito.when(GoogleSignIn.getSignedInAccountFromIntent(Mockito.any(Intent.class))).thenReturn(task);
    Mockito.when(task.isSuccessful()).thenReturn(false);
    Mockito.when(firebaseAuth.signInWithCredential(Mockito.any(AuthCredential.class))).thenReturn(task);
    Mockito.when(task.addOnCompleteListener(Mockito.any(Activity.class), Mockito.any(OnCompleteListener.class))).thenAnswer(new Answer<Object>() {
        @Override
        public Object answer(InvocationOnMock invocation) {
            ((OnCompleteListener) invocation.getArgument(1)).onComplete(task);
            return null;
        }
    });

    // When
    listener.onActivityResult(requestCode, resultCode, intent);

    // Then
    Mockito.verify(((AndroidApplication) Gdx.app), VerificationModeFactory.times(1)).removeAndroidEventListener(Mockito.refEq(listener));
    Mockito.verify(promise, VerificationModeFactory.times(1)).doFail(Mockito.nullable(Exception.class));
}
 
Example #12
Source File: GoogleSignInListenerTest.java    From gdx-fireapp with Apache License 2.0 5 votes vote down vote up
@Test
public void onActivityResult_validRequestCode_successTask() throws Throwable {
    // Given
    FuturePromise promise = Mockito.mock(FuturePromise.class);
    GoogleSignInListener listener = new GoogleSignInListener(promise);
    Intent intent = PowerMockito.mock(Intent.class);
    int requestCode = Const.GOOGLE_SIGN_IN;
    int resultCode = -1;
    final Task task = Mockito.mock(Task.class);
    Mockito.when(task.getResult(ApiException.class)).thenReturn(Mockito.mock(GoogleSignInAccount.class));
    Mockito.when(GoogleSignIn.getSignedInAccountFromIntent(Mockito.any(Intent.class))).thenReturn(task);
    Mockito.when(task.isSuccessful()).thenReturn(true);
    Mockito.when(firebaseAuth.signInWithCredential(Mockito.any(AuthCredential.class))).thenReturn(task);
    Mockito.when(task.addOnCompleteListener(Mockito.any(Activity.class), Mockito.any(OnCompleteListener.class))).thenAnswer(new Answer<Object>() {
        @Override
        public Object answer(InvocationOnMock invocation) {
            ((OnCompleteListener) invocation.getArgument(1)).onComplete(task);
            return null;
        }
    });

    // When
    listener.onActivityResult(requestCode, resultCode, intent);

    // Then
    Mockito.verify(((AndroidApplication) Gdx.app), VerificationModeFactory.times(1)).removeAndroidEventListener(Mockito.refEq(listener));
    Mockito.verify(promise, VerificationModeFactory.times(1)).doComplete(Mockito.nullable(GdxFirebaseUser.class));
}
 
Example #13
Source File: Analytics.java    From gdx-fireapp with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void setScreen(final String name, final Class<?> screenClass) {
    ((AndroidApplication) Gdx.app).runOnUiThread(new Runnable() {
        @Override
        public void run() {
            FirebaseAnalytics.getInstance((AndroidApplication) Gdx.app).setCurrentScreen((AndroidApplication) Gdx.app, name, screenClass.getSimpleName());
        }
    });
}
 
Example #14
Source File: GoogleAuth.java    From gdx-fireapp with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public Promise<GdxFirebaseUser> signIn() {
    return FuturePromise.when(new Consumer<FuturePromise<GdxFirebaseUser>>() {
        @Override
        public void accept(FuturePromise<GdxFirebaseUser> gdxFirebaseUserFuturePromise) {
            GoogleSignInOptions gso = GoogleSignInOptionsFactory.factory();
            ((AndroidApplication) Gdx.app).addAndroidEventListener(new GoogleSignInListener(gdxFirebaseUserFuturePromise));
            ((AndroidApplication) Gdx.app).startActivityForResult(
                    GoogleSignIn.getClient((AndroidApplication) Gdx.app, gso).getSignInIntent(), Const.GOOGLE_SIGN_IN);
        }
    });
}
 
Example #15
Source File: ControllerLifeCycleListener.java    From gdx-controllerutils with Apache License 2.0 4 votes vote down vote up
public ControllerLifeCycleListener(AndroidControllers controllers) {
	this.controllers = controllers;
	this.inputManager = (InputManager)((Context) Gdx.app).getSystemService(Context.INPUT_SERVICE);
	Gdx.app.addLifecycleListener(this);
	inputManager.registerInputDeviceListener(this, ((AndroidApplication) Gdx.app).handler);
}
 
Example #16
Source File: Crash.java    From gdx-fireapp with Apache License 2.0 4 votes vote down vote up
private synchronized void initializeOnce() {
    if (!initialized) {
        initialized = true;
        Fabric.with((AndroidApplication) Gdx.app, new Crashlytics());
    }
}
 
Example #17
Source File: Analytics.java    From gdx-fireapp with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void setUserId(String id) {
    FirebaseAnalytics.getInstance((AndroidApplication) Gdx.app).setUserId(id);
}
 
Example #18
Source File: Analytics.java    From gdx-fireapp with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void setUserProperty(String name, String value) {
    FirebaseAnalytics.getInstance((AndroidApplication) Gdx.app).setUserProperty(name, value);
}
 
Example #19
Source File: StringResource.java    From gdx-fireapp with Apache License 2.0 4 votes vote down vote up
static String getStringResourceByName(String name) {
    int id = ((AndroidApplication) Gdx.app).getResources().getIdentifier(name, "string", ((AndroidApplication) Gdx.app).getPackageName());
    return ((AndroidApplication) Gdx.app).getResources().getString(id);
}
 
Example #20
Source File: ControllerLifeCycleListener.java    From gdx-controllerutils with Apache License 2.0 4 votes vote down vote up
@Override
public void resume () {
	inputManager.registerInputDeviceListener(this, ((AndroidApplication) Gdx.app).handler);
	Gdx.app.log(TAG, "controller life cycle listener resumed");
}