use of android.app.Application in project mosby by sockeqwe.
the class ViewGroupMvpViewStateDelegateImplTest method initComponents.
@Before
public void initComponents() {
view = new MvpView() {
};
savedState = null;
viewState = Mockito.mock(ViewState.class);
presenter = Mockito.mock(MvpPresenter.class);
callback = Mockito.mock(PartialViewGroupMvpViewStateDelegateCallbackImpl.class);
Mockito.doCallRealMethod().when(callback).setPresenter(presenter);
Mockito.doCallRealMethod().when(callback).getPresenter();
Mockito.doCallRealMethod().when(callback).setViewState(viewState);
Mockito.doCallRealMethod().when(callback).getViewState();
Mockito.doCallRealMethod().when(callback).superOnSaveInstanceState();
activity = Mockito.mock(FragmentActivity.class);
application = Mockito.mock(Application.class);
androidView = Mockito.mock(View.class);
Mockito.when(callback.getMvpView()).thenReturn(view);
Mockito.when(callback.getContext()).thenReturn(activity);
Mockito.when(activity.getApplication()).thenReturn(application);
Mockito.when(callback.createPresenter()).thenReturn(presenter);
Mockito.when(callback.createViewState()).thenReturn(viewState);
Mockito.when(androidView.isInEditMode()).thenReturn(false);
delegate = new ViewGroupMvpViewStateDelegateImpl<>(androidView, callback, true);
}
use of android.app.Application in project mosby by sockeqwe.
the class ViewGroupMvpDelegateImplTest method initComponents.
@Before
public void initComponents() {
view = new MvpView() {
};
savedState = null;
presenter = Mockito.mock(MvpPresenter.class);
callback = Mockito.mock(PartialViewGroupMvpDelegateCallbackImpl.class);
Mockito.doCallRealMethod().when(callback).setPresenter(presenter);
Mockito.doCallRealMethod().when(callback).getPresenter();
Mockito.doCallRealMethod().when(callback).superOnSaveInstanceState();
activity = Mockito.mock(FragmentActivity.class);
application = Mockito.mock(Application.class);
androidView = Mockito.mock(View.class);
Mockito.when(callback.getMvpView()).thenReturn(view);
Mockito.when(callback.getContext()).thenReturn(activity);
Mockito.when(activity.getApplication()).thenReturn(application);
Mockito.when(androidView.isInEditMode()).thenReturn(false);
delegate = new ViewGroupMvpDelegateImpl<>(androidView, callback, true);
}
use of android.app.Application in project Shuttle by timusus.
the class InputMethodManagerLeaks method fixFocusedViewLeak.
/**
* Fix for https://code.google.com/p/android/issues/detail?id=171190 .
* <p>
* When a view that has focus gets detached, we wait for the main thread to be idle and then
* check if the InputMethodManager is leaking a view. If yes, we tell it that the decor view got
* focus, which is what happens if you press home and come back from recent apps. This replaces
* the reference to the detached view with a reference to the decor view.
* <p>
* Should be called from {@link Activity#onCreate(android.os.Bundle)} )}.
*/
@SuppressLint("PrivateApi")
public static void fixFocusedViewLeak(Application application) {
// Still not fixed until android 23
if (SDK_INT < KITKAT || SDK_INT > Build.VERSION_CODES.N_MR1) {
return;
}
final InputMethodManager inputMethodManager = (InputMethodManager) application.getSystemService(INPUT_METHOD_SERVICE);
final Field mServedViewField;
final Field mHField;
final Method finishInputLockedMethod;
final Method focusInMethod;
try {
mServedViewField = InputMethodManager.class.getDeclaredField("mServedView");
mServedViewField.setAccessible(true);
mHField = InputMethodManager.class.getDeclaredField("mServedView");
mHField.setAccessible(true);
finishInputLockedMethod = InputMethodManager.class.getDeclaredMethod("finishInputLocked");
finishInputLockedMethod.setAccessible(true);
focusInMethod = InputMethodManager.class.getDeclaredMethod("focusIn", View.class);
focusInMethod.setAccessible(true);
} catch (NoSuchMethodException | NoSuchFieldException unexpected) {
Log.e("IMMLeaks", "Unexpected reflection exception", unexpected);
return;
}
application.registerActivityLifecycleCallbacks(new Application.ActivityLifecycleCallbacks() {
@Override
public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
}
@Override
public void onActivityStarted(Activity activity) {
ReferenceCleaner cleaner = new ReferenceCleaner(inputMethodManager, mHField, mServedViewField, finishInputLockedMethod);
View rootView = activity.getWindow().getDecorView().getRootView();
ViewTreeObserver viewTreeObserver = rootView.getViewTreeObserver();
viewTreeObserver.addOnGlobalFocusChangeListener(cleaner);
}
@Override
public void onActivityResumed(Activity activity) {
}
@Override
public void onActivityPaused(Activity activity) {
}
@Override
public void onActivityStopped(Activity activity) {
}
@Override
public void onActivitySaveInstanceState(Activity activity, Bundle outState) {
}
@Override
public void onActivityDestroyed(Activity activity) {
}
});
}
use of android.app.Application in project android_frameworks_base by crdroidandroid.
the class FalsingLog method wtf.
public static synchronized void wtf(String tag, String s, Throwable here) {
if (!ENABLED) {
return;
}
e(tag, s);
Application application = ActivityThread.currentApplication();
String fileMessage = "";
if (Build.IS_DEBUGGABLE && application != null) {
File f = new File(application.getDataDir(), "falsing-" + new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss").format(new Date()) + ".txt");
PrintWriter pw = null;
try {
pw = new PrintWriter(f);
dump(pw);
pw.close();
fileMessage = "Log written to " + f.getAbsolutePath();
} catch (IOException e) {
Log.e(TAG, "Unable to write falsing log", e);
} finally {
if (pw != null) {
pw.close();
}
}
} else {
Log.e(TAG, "Unable to write log, build must be debuggable.");
}
Log.wtf(TAG, tag + " " + s + "; " + fileMessage, here);
}
use of android.app.Application in project android-testing-templates by googlesamples.
the class LocalUnitTest method mockFinalMethod.
@Test
public void mockFinalMethod() {
Activity activity = mock(Activity.class);
Application app = mock(Application.class);
when(activity.getApplication()).thenReturn(app);
assertThat(app, is(equalTo(activity.getApplication())));
verify(activity).getApplication();
verifyNoMoreInteractions(activity);
}
Aggregations