mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 03:09:04 +01:00
Switched Roboguice/Guice out for Dagger 2
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
package org.briarproject.android;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.StrictMode;
|
||||
import android.os.StrictMode.ThreadPolicy;
|
||||
import android.os.StrictMode.VmPolicy;
|
||||
@@ -11,29 +13,22 @@ import android.support.v7.preference.PreferenceManager;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import com.google.inject.Injector;
|
||||
|
||||
import org.briarproject.R;
|
||||
import org.briarproject.android.util.AndroidUtils;
|
||||
import org.briarproject.android.util.LayoutUtils;
|
||||
import org.briarproject.api.db.DatabaseConfig;
|
||||
import org.briarproject.api.ui.UiCallback;
|
||||
import org.briarproject.util.FileUtils;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import roboguice.RoboGuice;
|
||||
import roboguice.activity.RoboSplashActivity;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import static android.view.Gravity.CENTER;
|
||||
import static android.view.WindowManager.LayoutParams.FLAG_SECURE;
|
||||
import static java.util.logging.Level.INFO;
|
||||
import static org.briarproject.android.BaseActivity.PREFS_NAME;
|
||||
import static org.briarproject.android.BaseActivity.PREF_DB_KEY;
|
||||
import static org.briarproject.android.TestingConstants.DEFAULT_LOG_LEVEL;
|
||||
import static org.briarproject.android.TestingConstants.PREVENT_SCREENSHOTS;
|
||||
import static org.briarproject.android.TestingConstants.TESTING;
|
||||
import static org.briarproject.android.util.CommonLayoutParams.MATCH_MATCH;
|
||||
|
||||
public class SplashScreenActivity extends RoboSplashActivity {
|
||||
public class SplashScreenActivity extends BaseActivity {
|
||||
|
||||
private static final Logger LOG =
|
||||
Logger.getLogger(SplashScreenActivity.class.getName());
|
||||
@@ -43,18 +38,18 @@ public class SplashScreenActivity extends RoboSplashActivity {
|
||||
|
||||
private long now = System.currentTimeMillis();
|
||||
|
||||
@Inject
|
||||
DatabaseConfig dbConfig;
|
||||
|
||||
public SplashScreenActivity() {
|
||||
Logger.getLogger("").setLevel(DEFAULT_LOG_LEVEL);
|
||||
enableStrictMode();
|
||||
minDisplayMs = 500;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle state) {
|
||||
super.onCreate(state);
|
||||
|
||||
if (PREVENT_SCREENSHOTS) getWindow().addFlags(FLAG_SECURE);
|
||||
|
||||
LinearLayout layout = new LinearLayout(this);
|
||||
layout.setLayoutParams(MATCH_MATCH);
|
||||
layout.setGravity(CENTER);
|
||||
@@ -70,28 +65,36 @@ public class SplashScreenActivity extends RoboSplashActivity {
|
||||
setPreferencesDefaults();
|
||||
|
||||
setContentView(layout);
|
||||
|
||||
new Handler().postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
startNextActivity();
|
||||
}
|
||||
}, 500);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void injectActivity(AndroidComponent component) {
|
||||
component.inject(this);
|
||||
}
|
||||
|
||||
protected void startNextActivity() {
|
||||
long duration = System.currentTimeMillis() - now;
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("Guice startup took " + duration + " ms");
|
||||
if (System.currentTimeMillis() >= EXPIRY_DATE) {
|
||||
LOG.info("Expired");
|
||||
startActivity(new Intent(this, ExpiredActivity.class));
|
||||
} else {
|
||||
SharedPreferences prefs = getSharedPreferences(PREFS_NAME,
|
||||
MODE_PRIVATE);
|
||||
String hex = prefs.getString(PREF_DB_KEY, null);
|
||||
Injector i = RoboGuice.getBaseApplicationInjector(getApplication());
|
||||
DatabaseConfig databaseConfig = i.getInstance(DatabaseConfig.class);
|
||||
if (hex != null && databaseConfig.databaseExists()) {
|
||||
startActivity(new Intent(this, NavDrawerActivity.class));
|
||||
} else {
|
||||
prefs.edit().clear().apply();
|
||||
AndroidUtils.deleteAppData(this);
|
||||
startActivity(new Intent(this, SetupActivity.class));
|
||||
String hex = getEncryptedDatabaseKey();
|
||||
|
||||
if (dbConfig != null) {
|
||||
if (hex != null && dbConfig.databaseExists()) {
|
||||
startActivity(new Intent(this, NavDrawerActivity.class));
|
||||
} else {
|
||||
clearSharedPrefs();
|
||||
FileUtils.deleteFileOrDir(
|
||||
dbConfig.getDatabaseDirectory());
|
||||
startActivity(new Intent(this, SetupActivity.class));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -114,7 +117,7 @@ public class SplashScreenActivity extends RoboSplashActivity {
|
||||
@Override
|
||||
public void run() {
|
||||
PreferenceManager.setDefaultValues(SplashScreenActivity.this,
|
||||
R.xml.panic_preferences, false);
|
||||
R.xml.panic_preferences, false);
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user