mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 18:59:06 +01:00
99 lines
2.7 KiB
Java
99 lines
2.7 KiB
Java
package org.briarproject.android;
|
|
|
|
import android.os.Bundle;
|
|
import android.os.IBinder;
|
|
import android.support.v7.app.AppCompatActivity;
|
|
import android.view.View;
|
|
import android.view.inputmethod.InputMethodManager;
|
|
|
|
import org.briarproject.android.controller.ActivityLifecycleController;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
import static android.view.WindowManager.LayoutParams.FLAG_SECURE;
|
|
import static android.view.inputmethod.InputMethodManager.SHOW_IMPLICIT;
|
|
import static org.briarproject.android.TestingConstants.PREVENT_SCREENSHOTS;
|
|
|
|
public abstract class BaseActivity extends AppCompatActivity {
|
|
|
|
protected ActivityComponent activityComponent;
|
|
|
|
private List<ActivityLifecycleController> lifecycleControllers =
|
|
new ArrayList<ActivityLifecycleController>();
|
|
|
|
public void addLifecycleController(
|
|
ActivityLifecycleController lifecycleController) {
|
|
this.lifecycleControllers.add(lifecycleController);
|
|
}
|
|
|
|
@Override
|
|
public void onCreate(Bundle savedInstanceState) {
|
|
super.onCreate(savedInstanceState);
|
|
|
|
if (PREVENT_SCREENSHOTS) getWindow().addFlags(FLAG_SECURE);
|
|
|
|
AndroidComponent applicationComponent =
|
|
((BriarApplication) getApplication()).getApplicationComponent();
|
|
|
|
activityComponent = DaggerActivityComponent.builder()
|
|
.androidComponent(applicationComponent)
|
|
.activityModule(new ActivityModule(this))
|
|
.build();
|
|
|
|
injectActivity(activityComponent);
|
|
|
|
for (ActivityLifecycleController alc : lifecycleControllers) {
|
|
alc.onActivityCreate();
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void onPostCreate(Bundle savedInstanceState) {
|
|
super.onPostCreate(savedInstanceState);
|
|
// Post call used for controllers to ensure that the onCreate method
|
|
// override in inherited Activities has finished
|
|
// for (ActivityLifecycleController alc : lifecycleControllers) {
|
|
// alc.onActivityCreate();
|
|
// }
|
|
}
|
|
|
|
@Override
|
|
protected void onResume() {
|
|
super.onResume();
|
|
for (ActivityLifecycleController alc : lifecycleControllers) {
|
|
alc.onActivityResume();
|
|
}
|
|
}
|
|
|
|
@Override
|
|
protected void onPause() {
|
|
super.onPause();
|
|
for (ActivityLifecycleController alc : lifecycleControllers) {
|
|
alc.onActivityPause();
|
|
}
|
|
}
|
|
|
|
@Override
|
|
protected void onDestroy() {
|
|
super.onDestroy();
|
|
for (ActivityLifecycleController alc : lifecycleControllers) {
|
|
alc.onActivityDestroy();
|
|
}
|
|
}
|
|
|
|
public abstract void injectActivity(ActivityComponent component);
|
|
|
|
protected void showSoftKeyboard(View view) {
|
|
Object o = getSystemService(INPUT_METHOD_SERVICE);
|
|
((InputMethodManager) o).showSoftInput(view, SHOW_IMPLICIT);
|
|
}
|
|
|
|
public void hideSoftKeyboard(View view) {
|
|
IBinder token = view.getWindowToken();
|
|
Object o = getSystemService(INPUT_METHOD_SERVICE);
|
|
((InputMethodManager) o).hideSoftInputFromWindow(token, 0);
|
|
}
|
|
|
|
}
|