diff --git a/briar-android/src/org/briarproject/android/ActivityComponent.java b/briar-android/src/org/briarproject/android/ActivityComponent.java index 529bbf7ba2a69379d6e56580d2ef8206467e0493..6fec172b40ffe8ee4922ca850502f2d9c30fbed5 100644 --- a/briar-android/src/org/briarproject/android/ActivityComponent.java +++ b/briar-android/src/org/briarproject/android/ActivityComponent.java @@ -28,6 +28,7 @@ import dagger.Component; @Component(modules = ActivityModule.class, dependencies = AndroidComponent.class) public interface ActivityComponent { + Activity activity(); void inject(SplashScreenActivity activity); @@ -64,23 +65,8 @@ public interface ActivityComponent { void inject(SettingsActivity activity); - /* - void inject(ContactListFragment fragment); - - void inject(ForumListFragment fragment); - - void inject(ShowQrCodeFragment fragment); - */ - void inject(IntroductionActivity activity); - /* - void inject(ContactChooserFragment fragment); - - void inject(introductionmessagefragment fragment); - - */ - @Named("ContactListFragment") BaseFragment newContactListFragment(); diff --git a/briar-android/src/org/briarproject/android/AndroidComponent.java b/briar-android/src/org/briarproject/android/AndroidComponent.java index ba2578addca7d1cd26378440b28add5ba3b20420..6f5454a05abbe36e7407926a5c1a345fa46ddc2b 100644 --- a/briar-android/src/org/briarproject/android/AndroidComponent.java +++ b/briar-android/src/org/briarproject/android/AndroidComponent.java @@ -49,6 +49,7 @@ import dagger.Component; AndroidSystemModule.class }) public interface AndroidComponent extends CoreEagerSingletons { + // Exposed objects @CryptoExecutor Executor cryptoExecutor(); diff --git a/briar-android/src/org/briarproject/android/BaseActivity.java b/briar-android/src/org/briarproject/android/BaseActivity.java index fa2e68d6b8e57d60d3f7d693a5b14fb0e7a72275..38063e239e5b46ea9ce0ae233f06c76d647bf495 100644 --- a/briar-android/src/org/briarproject/android/BaseActivity.java +++ b/briar-android/src/org/briarproject/android/BaseActivity.java @@ -19,12 +19,13 @@ public abstract class BaseActivity extends AppCompatActivity { protected ActivityComponent activityComponent; - private List<ActivityLifecycleController> lifecycleControllers = - new ArrayList<ActivityLifecycleController>(); + private final List<ActivityLifecycleController> lifecycleControllers = + new ArrayList<>(); - public void addLifecycleController( - ActivityLifecycleController lifecycleController) { - this.lifecycleControllers.add(lifecycleController); + public abstract void injectActivity(ActivityComponent component); + + public void addLifecycleController(ActivityLifecycleController alc) { + lifecycleControllers.add(alc); } @Override @@ -77,9 +78,7 @@ public abstract class BaseActivity extends AppCompatActivity { } } - public abstract void injectActivity(ActivityComponent component); - - protected void showSoftKeyboard(View view) { + public void showSoftKeyboard(View view) { Object o = getSystemService(INPUT_METHOD_SERVICE); ((InputMethodManager) o).showSoftInput(view, SHOW_IMPLICIT); } @@ -89,5 +88,4 @@ public abstract class BaseActivity extends AppCompatActivity { Object o = getSystemService(INPUT_METHOD_SERVICE); ((InputMethodManager) o).hideSoftInputFromWindow(token, 0); } - } diff --git a/briar-android/src/org/briarproject/android/BriarActivity.java b/briar-android/src/org/briarproject/android/BriarActivity.java index 0da52cf2be6bfd4689d2d42afbbf5f9acdefea63..ed9c8dd87e4d32e805a763f4d7840289c82564cb 100644 --- a/briar-android/src/org/briarproject/android/BriarActivity.java +++ b/briar-android/src/org/briarproject/android/BriarActivity.java @@ -69,14 +69,13 @@ public abstract class BriarActivity extends BaseActivity { } private void startExitActivity() { - Intent intent = new Intent(BriarActivity.this, - ExitActivity.class); - intent.addFlags(FLAG_ACTIVITY_NEW_TASK + Intent i = new Intent(this, ExitActivity.class); + i.addFlags(FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS | FLAG_ACTIVITY_NO_ANIMATION); if (Build.VERSION.SDK_INT >= 11) - intent.addFlags(FLAG_ACTIVITY_CLEAR_TASK); - startActivity(intent); + i.addFlags(FLAG_ACTIVITY_CLEAR_TASK); + startActivity(i); } private void finishAndExit() { @@ -94,6 +93,7 @@ public abstract class BriarActivity extends BaseActivity { @Deprecated protected void finishOnUiThread() { runOnUiThread(new Runnable() { + @Override public void run() { finish(); } diff --git a/briar-android/src/org/briarproject/android/BriarApplicationImpl.java b/briar-android/src/org/briarproject/android/BriarApplicationImpl.java index 5abe5dff2d542cec09ffd8be44e930ea24e6d800..080fffdcabf57ade9bee5159d65a4460172cfb92 100644 --- a/briar-android/src/org/briarproject/android/BriarApplicationImpl.java +++ b/briar-android/src/org/briarproject/android/BriarApplicationImpl.java @@ -22,7 +22,8 @@ import java.util.logging.Logger; resDialogOkToast = R.string.dev_report_saved, deleteOldUnsentReportsOnApplicationStart = false ) -public class BriarApplicationImpl extends Application implements BriarApplication { +public class BriarApplicationImpl extends Application + implements BriarApplication { private static final Logger LOG = Logger.getLogger(BriarApplicationImpl.class.getName()); @@ -50,6 +51,7 @@ public class BriarApplicationImpl extends Application implements BriarApplicatio AndroidEagerSingletons.initEagerSingletons(applicationComponent); } + @Override public AndroidComponent getApplicationComponent() { return applicationComponent; } diff --git a/briar-android/src/org/briarproject/android/BriarFragmentActivity.java b/briar-android/src/org/briarproject/android/BriarFragmentActivity.java index 00fe0f39acd18b60e4339ef8deaca47ebb305097..dddc8a003892ebbceb6b50148011e9cfd6111d12 100644 --- a/briar-android/src/org/briarproject/android/BriarFragmentActivity.java +++ b/briar-android/src/org/briarproject/android/BriarFragmentActivity.java @@ -58,9 +58,8 @@ public abstract class BriarFragmentActivity extends BriarActivity { protected void startFragment(BaseFragment fragment) { if (getSupportFragmentManager().getBackStackEntryCount() == 0) - this.startFragment(fragment, false); - else - this.startFragment(fragment, true); + startFragment(fragment, false); + else startFragment(fragment, true); } protected void showMessageDialog(int titleStringId, int msgStringId) { @@ -76,7 +75,7 @@ public abstract class BriarFragmentActivity extends BriarActivity { protected void startFragment(BaseFragment fragment, boolean isAddedToBackStack) { - this.startFragment(fragment, 0, 0, isAddedToBackStack); + startFragment(fragment, 0, 0, isAddedToBackStack); } protected void startFragment(BaseFragment fragment, @@ -94,5 +93,4 @@ public abstract class BriarFragmentActivity extends BriarActivity { trans.commit(); updateToolbarTitle(fragment.getUniqueTag()); } - } diff --git a/briar-android/src/org/briarproject/android/DevReportActivity.java b/briar-android/src/org/briarproject/android/DevReportActivity.java index 8f94b5a07624c4e9cc6f4e42d9ad8e7e01ebeb0c..a55ffd26c5eddb1d8ba09ddf969659a48166c3ee 100644 --- a/briar-android/src/org/briarproject/android/DevReportActivity.java +++ b/briar-android/src/org/briarproject/android/DevReportActivity.java @@ -16,7 +16,6 @@ import android.widget.LinearLayout; import android.widget.TextView; import org.acra.ACRA; -import org.acra.ACRAConstants; import org.acra.ReportField; import org.acra.collector.CrashReportData; import org.acra.dialog.BaseCrashReportDialog; @@ -24,7 +23,6 @@ import org.acra.file.CrashReportPersister; import org.acra.prefs.SharedPreferencesFactory; import org.briarproject.R; import org.briarproject.android.util.UserFeedback; -import org.briarproject.api.reporting.DevReporter; import java.io.File; import java.io.IOException; @@ -34,12 +32,12 @@ import java.util.Map.Entry; import java.util.Set; import java.util.logging.Logger; -import javax.inject.Inject; - +import static android.content.DialogInterface.BUTTON_POSITIVE; import static android.view.View.GONE; import static android.view.View.INVISIBLE; import static android.view.View.VISIBLE; import static java.util.logging.Level.WARNING; +import static org.acra.ACRAConstants.EXTRA_REPORT_FILE; import static org.acra.ReportField.ANDROID_VERSION; import static org.acra.ReportField.APP_VERSION_CODE; import static org.acra.ReportField.APP_VERSION_NAME; @@ -68,9 +66,6 @@ public class DevReportActivity extends BaseCrashReportDialog requiredFields.add(STACK_TRACE); } - @Inject - protected DevReporter reporter; - private SharedPreferencesFactory sharedPreferencesFactory; private Set<ReportField> excludedFields; private EditText userCommentView = null; @@ -86,17 +81,15 @@ public class DevReportActivity extends BaseCrashReportDialog super.onCreate(state); setContentView(R.layout.activity_dev_report); - ((BriarApplication) getApplication()).getApplicationComponent() - .inject(this); + BriarApplication app = (BriarApplication) getApplication(); + app.getApplicationComponent().inject(this); - - sharedPreferencesFactory = - new SharedPreferencesFactory(getApplicationContext(), - getConfig()); + sharedPreferencesFactory = new SharedPreferencesFactory( + getApplicationContext(), getConfig()); final SharedPreferences prefs = sharedPreferencesFactory.create(); excludedFields = new HashSet<>(); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { + if (Build.VERSION.SDK_INT >= 11) { for (String name : prefs.getStringSet(PREF_EXCLUDED_FIELDS, new HashSet<String>())) { excludedFields.add(ReportField.valueOf(name)); @@ -163,11 +156,8 @@ public class DevReportActivity extends BaseCrashReportDialog @Override public void onClick(DialogInterface dialog, int which) { - if (which == DialogInterface.BUTTON_POSITIVE) { - dialog.dismiss(); - } else { - dialog.cancel(); - } + if (which == BUTTON_POSITIVE) dialog.dismiss(); + else dialog.cancel(); } @Override @@ -179,10 +169,8 @@ public class DevReportActivity extends BaseCrashReportDialog public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { ReportField field = (ReportField) buttonView.getTag(); if (field != null) { - if (isChecked) - excludedFields.remove(field); - else - excludedFields.add(field); + if (isChecked) excludedFields.remove(field); + else excludedFields.add(field); } } @@ -214,7 +202,7 @@ public class DevReportActivity extends BaseCrashReportDialog @Override protected CrashReportData doInBackground(Void... args) { File reportFile = (File) getIntent().getSerializableExtra( - ACRAConstants.EXTRA_REPORT_FILE); + EXTRA_REPORT_FILE); final CrashReportPersister persister = new CrashReportPersister(); try { @@ -272,7 +260,7 @@ public class DevReportActivity extends BaseCrashReportDialog @Override protected Boolean doInBackground(Void... args) { File reportFile = (File) getIntent().getSerializableExtra( - ACRAConstants.EXTRA_REPORT_FILE); + EXTRA_REPORT_FILE); CrashReportPersister persister = new CrashReportPersister(); try { CrashReportData data = persister.load(reportFile); @@ -303,7 +291,7 @@ public class DevReportActivity extends BaseCrashReportDialog protected void onPostExecute(Boolean success) { final SharedPreferences prefs = sharedPreferencesFactory.create(); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { + if (Build.VERSION.SDK_INT >= 11) { final SharedPreferences.Editor prefEditor = prefs.edit(); Set<String> fields = new HashSet<>(); diff --git a/briar-android/src/org/briarproject/android/NavDrawerActivity.java b/briar-android/src/org/briarproject/android/NavDrawerActivity.java index 4d18cd6ec588ebcb0834e503a72923ac3425fb9b..56caa5c8fbb48f7a266a4a143c32ddfd44e68fb7 100644 --- a/briar-android/src/org/briarproject/android/NavDrawerActivity.java +++ b/briar-android/src/org/briarproject/android/NavDrawerActivity.java @@ -6,7 +6,6 @@ import android.content.SharedPreferences; import android.content.res.Configuration; import android.content.res.Resources; import android.os.Bundle; -import android.support.v4.view.GravityCompat; import android.support.v4.widget.DrawerLayout; import android.support.v7.app.ActionBarDrawerToggle; import android.support.v7.widget.Toolbar; @@ -33,6 +32,11 @@ import java.util.logging.Logger; import javax.inject.Inject; +import static android.support.v4.view.GravityCompat.START; +import static android.support.v4.widget.DrawerLayout.LOCK_MODE_LOCKED_CLOSED; +import static android.support.v4.widget.DrawerLayout.LOCK_MODE_UNLOCKED; +import static android.view.View.INVISIBLE; + public class NavDrawerActivity extends BriarFragmentActivity implements BaseFragment.BaseFragmentListener, TransportStateListener { @@ -51,7 +55,6 @@ public class NavDrawerActivity extends BriarFragmentActivity implements private Toolbar toolbar; private DrawerLayout drawerLayout; - private GridView transportsView; private TextView progressTitle; private ViewGroup progressViewGroup; @@ -88,7 +91,7 @@ public class NavDrawerActivity extends BriarFragmentActivity implements toolbar = (Toolbar) findViewById(R.id.toolbar); drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); - transportsView = (GridView) findViewById(R.id.transportsView); + GridView transportsView = (GridView) findViewById(R.id.transportsView); progressTitle = (TextView) findViewById(R.id.title_progress_bar); progressViewGroup = (ViewGroup) findViewById(R.id.container_progress); @@ -98,19 +101,10 @@ public class NavDrawerActivity extends BriarFragmentActivity implements drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, toolbar, R.string.nav_drawer_open_description, - R.string.nav_drawer_close_description - ) { - - public void onDrawerClosed(View view) { - super.onDrawerClosed(view); - } - - public void onDrawerOpened(View drawerView) { - super.onDrawerOpened(drawerView); - } - }; + R.string.nav_drawer_close_description); drawerLayout.setDrawerListener(drawerToggle); - if (state == null) startFragment(activityComponent.newContactListFragment()); + if (state == null) + startFragment(activityComponent.newContactListFragment()); checkAuthorHandle(getIntent()); initializeTransports(getLayoutInflater()); @@ -156,18 +150,17 @@ public class NavDrawerActivity extends BriarFragmentActivity implements return false; } - private void storeLocalAuthor(final LocalAuthor a) { - controller.storeLocalAuthor(a, - new UiResultHandler<Void>(this) { - @Override - public void onResultUi(Void result) { - hideLoadingScreen(); - } - }); + private void storeLocalAuthor(LocalAuthor a) { + controller.storeLocalAuthor(a, new UiResultHandler<Void>(this) { + @Override + public void onResultUi(Void result) { + hideLoadingScreen(); + } + }); } public void onNavigationClick(View view) { - drawerLayout.closeDrawer(GravityCompat.START); + drawerLayout.closeDrawer(START); clearBackStack(); switch (view.getId()) { case R.id.nav_btn_contacts: @@ -189,8 +182,8 @@ public class NavDrawerActivity extends BriarFragmentActivity implements @Override public void onBackPressed() { if (getSupportFragmentManager().getBackStackEntryCount() == 0 - && drawerLayout.isDrawerOpen(GravityCompat.START)) { - drawerLayout.closeDrawer(GravityCompat.START); + && drawerLayout.isDrawerOpen(START)) { + drawerLayout.closeDrawer(START); return; } super.onBackPressed(); @@ -218,8 +211,7 @@ public class NavDrawerActivity extends BriarFragmentActivity implements public void showLoadingScreen(boolean isBlocking, int stringId) { if (isBlocking) { // Disable navigation drawer slide to open - drawerLayout - .setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED); + drawerLayout.setDrawerLockMode(LOCK_MODE_LOCKED_CLOSED); CustomAnimations.animateHeight(toolbar, false, 250); } progressTitle.setText(stringId); @@ -228,14 +220,13 @@ public class NavDrawerActivity extends BriarFragmentActivity implements @Override public void hideLoadingScreen() { - drawerLayout - .setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED); + drawerLayout.setDrawerLockMode(LOCK_MODE_UNLOCKED); CustomAnimations.animateHeight(toolbar, true, 250); - progressViewGroup.setVisibility(View.INVISIBLE); + progressViewGroup.setVisibility(INVISIBLE); } private void initializeTransports(final LayoutInflater inflater) { - transports = new ArrayList<Transport>(3); + transports = new ArrayList<>(3); Transport tor = new Transport(); tor.id = new TransportId("tor"); @@ -277,8 +268,8 @@ public class NavDrawerActivity extends BriarFragmentActivity implements @Override public View getView(int position, View convertView, ViewGroup parent) { - ViewGroup view = (ViewGroup) inflater - .inflate(R.layout.list_item_transport, parent, false); + ViewGroup view = (ViewGroup) inflater.inflate( + R.layout.list_item_transport, parent, false); Transport t = getItem(position); Resources r = getResources(); @@ -304,6 +295,7 @@ public class NavDrawerActivity extends BriarFragmentActivity implements private void setTransport(final TransportId id, final boolean enabled) { runOnUiThread(new Runnable() { + @Override public void run() { if (transports == null || transportsAdapter == null) return; for (Transport t : transports) { @@ -331,9 +323,10 @@ public class NavDrawerActivity extends BriarFragmentActivity implements } private static class Transport { - TransportId id; - boolean enabled; - int iconId; - int textId; + + private TransportId id; + private boolean enabled; + private int iconId; + private int textId; } } diff --git a/briar-android/src/org/briarproject/android/PasswordActivity.java b/briar-android/src/org/briarproject/android/PasswordActivity.java index 346b2f2cd96f5e69b1db0de6038d744c27b63913..5fa6eebf52b016e4202a6e7b25a05fad38182f23 100644 --- a/briar-android/src/org/briarproject/android/PasswordActivity.java +++ b/briar-android/src/org/briarproject/android/PasswordActivity.java @@ -30,20 +30,20 @@ import static android.view.View.VISIBLE; public class PasswordActivity extends BaseActivity { + @Inject + protected PasswordController passwordController; + private Button signInButton; private ProgressBar progress; private TextInputLayout input; private EditText password; - @Inject - PasswordController passwordController; - @Override public void onCreate(Bundle state) { super.onCreate(state); - if (!passwordController.initialized()) { - clearSharedPrefsAndDeleteEverything(); + if (!passwordController.accountExists()) { + deleteAccount(); return; } @@ -61,6 +61,7 @@ public class PasswordActivity extends BaseActivity { } }); password.addTextChangedListener(new TextWatcher() { + @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { @@ -91,9 +92,8 @@ public class PasswordActivity extends BaseActivity { startActivity(intent); } - private void clearSharedPrefsAndDeleteEverything() { - passwordController.clearPrefs(); - AndroidUtils.deleteAppData(this); + private void deleteAccount() { + passwordController.deleteAccount(this); setResult(RESULT_CANCELED); startActivity(new Intent(this, SetupActivity.class)); finish(); @@ -114,7 +114,7 @@ public class PasswordActivity extends BaseActivity { new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { - clearSharedPrefsAndDeleteEverything(); + deleteAccount(); } }); AlertDialog dialog = builder.create(); @@ -140,8 +140,7 @@ public class PasswordActivity extends BaseActivity { } private void tryAgain() { - AndroidUtils.setError(input, getString(R.string.try_again), - true); + AndroidUtils.setError(input, getString(R.string.try_again), true); signInButton.setVisibility(VISIBLE); progress.setVisibility(INVISIBLE); password.setText(""); @@ -149,5 +148,4 @@ public class PasswordActivity extends BaseActivity { // show the keyboard again showSoftKeyboard(password); } - } diff --git a/briar-android/src/org/briarproject/android/SetupActivity.java b/briar-android/src/org/briarproject/android/SetupActivity.java index 13bb49f4b2410e1e222bfb285cbe79e6e6d03fef..9080e1722f29d15d5069caed2d13f98ce1bce4b7 100644 --- a/briar-android/src/org/briarproject/android/SetupActivity.java +++ b/briar-android/src/org/briarproject/android/SetupActivity.java @@ -27,8 +27,6 @@ import javax.inject.Inject; import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK; import static android.view.View.INVISIBLE; import static android.view.View.VISIBLE; -import static android.view.WindowManager.LayoutParams.FLAG_SECURE; -import static org.briarproject.android.TestingConstants.PREVENT_SCREENSHOTS; import static org.briarproject.api.crypto.PasswordStrengthEstimator.WEAK; import static org.briarproject.api.identity.AuthorConstants.MAX_AUTHOR_NAME_LENGTH; @@ -38,15 +36,15 @@ public class SetupActivity extends BaseActivity implements OnClickListener, @Inject protected SetupController setupController; - TextInputLayout nicknameEntryWrapper; - TextInputLayout passwordEntryWrapper; - TextInputLayout passwordConfirmationWrapper; - EditText nicknameEntry; - EditText passwordEntry; - EditText passwordConfirmation; - StrengthMeter strengthMeter; - Button createAccountButton; - ProgressBar progress; + private TextInputLayout nicknameEntryWrapper; + private TextInputLayout passwordEntryWrapper; + private TextInputLayout passwordConfirmationWrapper; + private EditText nicknameEntry; + private EditText passwordEntry; + private EditText passwordConfirmation; + private StrengthMeter strengthMeter; + private Button createAccountButton; + private ProgressBar progress; @Override public void onCreate(Bundle state) { @@ -66,9 +64,8 @@ public class SetupActivity extends BaseActivity implements OnClickListener, createAccountButton = (Button) findViewById(R.id.create_account); progress = (ProgressBar) findViewById(R.id.progress_wheel); - if (PREVENT_SCREENSHOTS) getWindow().addFlags(FLAG_SECURE); - TextWatcher tw = new TextWatcher() { + @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { @@ -107,7 +104,8 @@ public class SetupActivity extends BaseActivity implements OnClickListener, String firstPassword = passwordEntry.getText().toString(); String secondPassword = passwordConfirmation.getText().toString(); boolean passwordsMatch = firstPassword.equals(secondPassword); - float strength = setupController.estimatePasswordStrength(firstPassword); + float strength = + setupController.estimatePasswordStrength(firstPassword); strengthMeter.setStrength(strength); AndroidUtils.setError(nicknameEntryWrapper, getString(R.string.name_too_long), @@ -123,18 +121,19 @@ public class SetupActivity extends BaseActivity implements OnClickListener, && passwordsMatch && strength >= WEAK); } + @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { hideSoftKeyboard(v); - return true; } + @Override public void onClick(View view) { // Replace the button with a progress bar createAccountButton.setVisibility(INVISIBLE); progress.setVisibility(VISIBLE); - final String nickname = nicknameEntry.getText().toString(); - final String password = passwordEntry.getText().toString(); + String nickname = nicknameEntry.getText().toString(); + String password = passwordEntry.getText().toString(); setupController.createIdentity(nickname, password, new UiResultHandler<Long>(this) { @Override @@ -145,8 +144,7 @@ public class SetupActivity extends BaseActivity implements OnClickListener, } private void showMain(final long handle) { - Intent i = new Intent(SetupActivity.this, - NavDrawerActivity.class); + Intent i = new Intent(this, NavDrawerActivity.class); i.putExtra(BriarActivity.KEY_LOCAL_AUTHOR_HANDLE, handle); i.setFlags(FLAG_ACTIVITY_NEW_TASK); startActivity(i); diff --git a/briar-android/src/org/briarproject/android/SplashScreenActivity.java b/briar-android/src/org/briarproject/android/SplashScreenActivity.java index e4ff0b9418a3397ab1e893dc267f05a1616a2b4e..a3e4c6336ce416adc578283d47906c7e49bb8bc7 100644 --- a/briar-android/src/org/briarproject/android/SplashScreenActivity.java +++ b/briar-android/src/org/briarproject/android/SplashScreenActivity.java @@ -11,7 +11,6 @@ import android.support.v7.preference.PreferenceManager; import org.briarproject.R; import org.briarproject.android.api.AndroidExecutor; import org.briarproject.android.controller.ConfigController; -import org.briarproject.android.util.AndroidUtils; import java.util.logging.Logger; @@ -29,7 +28,7 @@ public class SplashScreenActivity extends BaseActivity { private static final long EXPIRY_DATE = 1464735600 * 1000L; @Inject - ConfigController configController; + protected ConfigController configController; @Inject protected AndroidExecutor androidExecutor; @@ -65,12 +64,10 @@ public class SplashScreenActivity extends BaseActivity { LOG.info("Expired"); startActivity(new Intent(this, ExpiredActivity.class)); } else { - if (configController.initialized()) { + if (configController.accountExists()) { startActivity(new Intent(this, NavDrawerActivity.class)); } else { - configController.clearPrefs(); - // TODO replace this static call with a controller method - AndroidUtils.deleteAppData(this); + configController.deleteAccount(this); startActivity(new Intent(this, SetupActivity.class)); } } @@ -91,6 +88,7 @@ public class SplashScreenActivity extends BaseActivity { private void setPreferencesDefaults() { androidExecutor.execute(new Runnable() { + @Override public void run() { PreferenceManager.setDefaultValues(SplashScreenActivity.this, R.xml.panic_preferences, false); diff --git a/briar-android/src/org/briarproject/android/contact/BaseContactListAdapter.java b/briar-android/src/org/briarproject/android/contact/BaseContactListAdapter.java index 908afe48307fa1bd9ed3ce80baac447a9be1fe2a..f4481726a253a1ebb4e3969a39da5bc1b71a729a 100644 --- a/briar-android/src/org/briarproject/android/contact/BaseContactListAdapter.java +++ b/briar-android/src/org/briarproject/android/contact/BaseContactListAdapter.java @@ -25,15 +25,15 @@ public abstract class BaseContactListAdapter<VH extends BaseContactListAdapter.B protected final OnItemClickListener listener; protected Context ctx; - public BaseContactListAdapter(Context context, OnItemClickListener listener) { - this.ctx = context; + public BaseContactListAdapter(Context ctx, OnItemClickListener listener) { + this.ctx = ctx; this.listener = listener; this.contacts = new SortedList<>(ContactListItem.class, new SortedListCallBacks()); } @Override - public void onBindViewHolder(final VH ui, final int position) { + public void onBindViewHolder(final VH ui, int position) { final ContactListItem item = getItem(position); Author author = item.getContact().getAuthor(); @@ -96,6 +96,7 @@ public abstract class BaseContactListAdapter<VH extends BaseContactListAdapter.B } public static class BaseContactHolder extends RecyclerView.ViewHolder { + public final ViewGroup layout; public final ImageView avatar; public final TextView name; @@ -132,7 +133,8 @@ public abstract class BaseContactListAdapter<VH extends BaseContactListAdapter.B return 0; } - protected class SortedListCallBacks extends SortedList.Callback<ContactListItem> { + protected class SortedListCallBacks + extends SortedList.Callback<ContactListItem> { @Override public void onInserted(int position, int count) { @@ -185,5 +187,4 @@ public abstract class BaseContactListAdapter<VH extends BaseContactListAdapter.B public interface OnItemClickListener { void onItemClick(View view, ContactListItem item); } - } diff --git a/briar-android/src/org/briarproject/android/contact/ContactListAdapter.java b/briar-android/src/org/briarproject/android/contact/ContactListAdapter.java index dee3031f74130789fad146d55eab1266431d7cf1..b47d5b7a0a13f7e22c0b85fa168dcb57e60cf93f 100644 --- a/briar-android/src/org/briarproject/android/contact/ContactListAdapter.java +++ b/briar-android/src/org/briarproject/android/contact/ContactListAdapter.java @@ -20,17 +20,17 @@ public class ContactListAdapter @Override public ContactHolder onCreateViewHolder(ViewGroup viewGroup, int i) { - View v = LayoutInflater.from(viewGroup.getContext()) - .inflate(R.layout.list_item_contact, viewGroup, false); + View v = LayoutInflater.from(viewGroup.getContext()).inflate( + R.layout.list_item_contact, viewGroup, false); return new ContactHolder(v); } @Override - public void onBindViewHolder(final ContactHolder ui, final int position) { + public void onBindViewHolder(ContactHolder ui, int position) { super.onBindViewHolder(ui, position); - final ContactListItem item = getItem(position); + ContactListItem item = getItem(position); // name and unread count String contactName = item.getContact().getAuthor().getName(); @@ -84,5 +84,4 @@ public class ContactListAdapter public int compareContactListItems(ContactListItem c1, ContactListItem c2) { return compareByTime(c1, c2); } - } diff --git a/briar-android/src/org/briarproject/android/contact/ContactListFragment.java b/briar-android/src/org/briarproject/android/contact/ContactListFragment.java index 5e7e017cd6139f37769bfc4e0bee392947aa7be4..d01e6571dfb74052cea5ebb8e797bc10515ea8a3 100644 --- a/briar-android/src/org/briarproject/android/contact/ContactListFragment.java +++ b/briar-android/src/org/briarproject/android/contact/ContactListFragment.java @@ -54,18 +54,16 @@ import static org.briarproject.android.BriarActivity.GROUP_ID; public class ContactListFragment extends BaseFragment implements EventListener { - private static final Logger LOG = - Logger.getLogger(ContactListFragment.class.getName()); - public final static String TAG = "ContactListFragment"; - @Override - public String getUniqueTag() { - return TAG; - } + private static final Logger LOG = + Logger.getLogger(ContactListFragment.class.getName()); @Inject protected ConnectionRegistry connectionRegistry; + @Inject + protected EventBus eventBus; + private ContactListAdapter adapter = null; private BriarRecyclerView list = null; @@ -80,15 +78,17 @@ public class ContactListFragment extends BaseFragment implements EventListener { protected volatile IntroductionManager introductionManager; @Inject protected volatile ForumSharingManager forumSharingManager; - @Inject - protected volatile EventBus eventBus; - @Inject public ContactListFragment() { } + @Override + public String getUniqueTag() { + return TAG; + } + @Nullable @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, @@ -160,11 +160,11 @@ public class ContactListFragment extends BaseFragment implements EventListener { private void loadContacts() { listener.runOnDbThread(new Runnable() { + @Override public void run() { try { long now = System.currentTimeMillis(); - List<ContactListItem> contacts = - new ArrayList<ContactListItem>(); + List<ContactListItem> contacts = new ArrayList<>(); for (Contact c : contactManager.getActiveContacts()) { try { ContactId id = c.getId(); @@ -196,6 +196,7 @@ public class ContactListFragment extends BaseFragment implements EventListener { private void displayContacts(final List<ContactListItem> contacts) { listener.runOnUiThread(new Runnable() { + @Override public void run() { if (contacts.size() == 0) list.showData(); else adapter.addAll(contacts); @@ -203,9 +204,10 @@ public class ContactListFragment extends BaseFragment implements EventListener { }); } + @Override public void eventOccurred(Event e) { if (e instanceof ContactAddedEvent) { - if(((ContactAddedEvent) e).isActive()) { + if (((ContactAddedEvent) e).isActive()) { LOG.info("Contact added as active, reloading"); loadContacts(); } @@ -233,6 +235,7 @@ public class ContactListFragment extends BaseFragment implements EventListener { private void reloadConversation(final GroupId g) { listener.runOnDbThread(new Runnable() { + @Override public void run() { try { ContactId c = messagingManager.getContactId(g); @@ -252,6 +255,7 @@ public class ContactListFragment extends BaseFragment implements EventListener { private void updateItem(final ContactId c, final Collection<ConversationItem> messages) { listener.runOnUiThread(new Runnable() { + @Override public void run() { int position = adapter.findItemPosition(c); ContactListItem item = adapter.getItem(position); @@ -265,6 +269,7 @@ public class ContactListFragment extends BaseFragment implements EventListener { private void removeItem(final ContactId c) { listener.runOnUiThread(new Runnable() { + @Override public void run() { int position = adapter.findItemPosition(c); ContactListItem item = adapter.getItem(position); @@ -275,6 +280,7 @@ public class ContactListFragment extends BaseFragment implements EventListener { private void setConnected(final ContactId c, final boolean connected) { listener.runOnUiThread(new Runnable() { + @Override public void run() { int position = adapter.findItemPosition(c); ContactListItem item = adapter.getItem(position); @@ -286,14 +292,13 @@ public class ContactListFragment extends BaseFragment implements EventListener { }); } - /** This needs to be called from the DbThread */ + // This needs to be called from the DB thread private Collection<ConversationItem> getMessages(ContactId id) throws DbException { long now = System.currentTimeMillis(); - Collection<ConversationItem> messages = - new ArrayList<ConversationItem>(); + Collection<ConversationItem> messages = new ArrayList<>(); Collection<PrivateMessageHeader> headers = messagingManager.getMessageHeaders(id); diff --git a/briar-android/src/org/briarproject/android/contact/ConversationActivity.java b/briar-android/src/org/briarproject/android/contact/ConversationActivity.java index 045c58e7f165e4b72ba16e08fa8ed05093624ac5..70dc1ff32171cc1381c75f7b0f2886cd585f028b 100644 --- a/briar-android/src/org/briarproject/android/contact/ConversationActivity.java +++ b/briar-android/src/org/briarproject/android/contact/ConversationActivity.java @@ -24,12 +24,12 @@ import android.widget.Toast; import org.briarproject.R; import org.briarproject.android.ActivityComponent; -import org.briarproject.android.AndroidComponent; import org.briarproject.android.BriarActivity; import org.briarproject.android.api.AndroidNotificationManager; import org.briarproject.android.introduction.IntroductionActivity; import org.briarproject.android.util.BriarRecyclerView; import org.briarproject.api.FormatException; +import org.briarproject.api.clients.SessionId; import org.briarproject.api.contact.Contact; import org.briarproject.api.contact.ContactId; import org.briarproject.api.contact.ContactManager; @@ -55,7 +55,6 @@ import org.briarproject.api.introduction.IntroductionManager; import org.briarproject.api.introduction.IntroductionMessage; import org.briarproject.api.introduction.IntroductionRequest; import org.briarproject.api.introduction.IntroductionResponse; -import org.briarproject.api.clients.SessionId; import org.briarproject.api.messaging.MessagingManager; import org.briarproject.api.messaging.PrivateMessage; import org.briarproject.api.messaging.PrivateMessageFactory; @@ -95,25 +94,37 @@ public class ConversationActivity extends BriarActivity private static final Logger LOG = Logger.getLogger(ConversationActivity.class.getName()); - @Inject protected AndroidNotificationManager notificationManager; - @Inject protected ConnectionRegistry connectionRegistry; - @Inject @CryptoExecutor protected Executor cryptoExecutor; - private Map<MessageId, byte[]> bodyCache = new HashMap<MessageId, byte[]>(); - private ConversationAdapter adapter = null; + @Inject + protected AndroidNotificationManager notificationManager; + @Inject + protected ConnectionRegistry connectionRegistry; + @Inject + @CryptoExecutor + protected Executor cryptoExecutor; + + private Map<MessageId, byte[]> bodyCache = new HashMap<>(); + private ConversationAdapter adapter; private CircleImageView toolbarAvatar; private ImageView toolbarStatus; private TextView toolbarTitle; - private BriarRecyclerView list = null; - private EditText content = null; - private ImageButton sendButton = null; + private BriarRecyclerView list; + private EditText content; + private ImageButton sendButton; // Fields that are accessed from background threads must be volatile - @Inject protected volatile ContactManager contactManager; - @Inject protected volatile MessagingManager messagingManager; - @Inject protected volatile EventBus eventBus; - @Inject protected volatile PrivateMessageFactory privateMessageFactory; - @Inject protected volatile IntroductionManager introductionManager; - @Inject protected volatile ForumSharingManager forumSharingManager; + @Inject + protected volatile ContactManager contactManager; + @Inject + protected volatile MessagingManager messagingManager; + @Inject + protected volatile EventBus eventBus; + @Inject + protected volatile PrivateMessageFactory privateMessageFactory; + @Inject + protected volatile IntroductionManager introductionManager; + @Inject + protected volatile ForumSharingManager forumSharingManager; + private volatile GroupId groupId = null; private volatile ContactId contactId = null; private volatile String contactName = null; @@ -218,6 +229,7 @@ public class ConversationActivity extends BriarActivity private void loadData() { runOnDbThread(new Runnable() { + @Override public void run() { try { long now = System.currentTimeMillis(); @@ -248,6 +260,7 @@ public class ConversationActivity extends BriarActivity private void displayContactDetails() { runOnUiThread(new Runnable() { + @Override public void run() { toolbarAvatar.setImageDrawable( new IdenticonDrawable(contactIdenticonKey)); @@ -273,6 +286,7 @@ public class ConversationActivity extends BriarActivity private void loadMessages() { runOnDbThread(new Runnable() { + @Override public void run() { try { long now = System.currentTimeMillis(); @@ -304,6 +318,7 @@ public class ConversationActivity extends BriarActivity final Collection<IntroductionMessage> introductions, final Collection<ForumInvitationMessage> invitations) { runOnUiThread(new Runnable() { + @Override public void run() { sendButton.setEnabled(true); if (headers.isEmpty() && introductions.isEmpty() && @@ -312,8 +327,7 @@ public class ConversationActivity extends BriarActivity // so let the list know to hide progress bar list.showData(); } else { - List<ConversationItem> items = - new ArrayList<ConversationItem>(); + List<ConversationItem> items = new ArrayList<>(); for (PrivateMessageHeader h : headers) { ConversationMessageItem item = (ConversationMessageItem) ConversationItem @@ -350,6 +364,7 @@ public class ConversationActivity extends BriarActivity private void loadMessageBody(final PrivateMessageHeader h) { runOnDbThread(new Runnable() { + @Override public void run() { try { long now = System.currentTimeMillis(); @@ -370,6 +385,7 @@ public class ConversationActivity extends BriarActivity private void displayMessageBody(final MessageId m, final byte[] body) { runOnUiThread(new Runnable() { + @Override public void run() { bodyCache.put(m, body); SparseArray<ConversationMessageItem> messages = @@ -399,9 +415,8 @@ public class ConversationActivity extends BriarActivity } private void markMessagesRead() { - List<MessageId> unread = new ArrayList<MessageId>(); - SparseArray<IncomingItem> list = - adapter.getIncomingMessages(); + List<MessageId> unread = new ArrayList<>(); + SparseArray<IncomingItem> list = adapter.getIncomingMessages(); for (int i = 0; i < list.size(); i++) { IncomingItem item = list.valueAt(i); if (!item.isRead()) unread.add(item.getId()); @@ -414,6 +429,7 @@ public class ConversationActivity extends BriarActivity private void markMessagesRead(final Collection<MessageId> unread) { runOnDbThread(new Runnable() { + @Override public void run() { try { long now = System.currentTimeMillis(); @@ -432,6 +448,7 @@ public class ConversationActivity extends BriarActivity }); } + @Override public void eventOccurred(Event e) { if (e instanceof ContactRemovedEvent) { ContactRemovedEvent c = (ContactRemovedEvent) e; @@ -501,6 +518,7 @@ public class ConversationActivity extends BriarActivity private void markMessageReadIfNew(final Message m) { runOnUiThread(new Runnable() { + @Override public void run() { ConversationItem item = adapter.getLastItem(); if (item != null) { @@ -519,6 +537,7 @@ public class ConversationActivity extends BriarActivity private void markNewMessageRead(final Message m) { runOnDbThread(new Runnable() { + @Override public void run() { try { messagingManager.setReadFlag(m.getId(), true); @@ -534,10 +553,10 @@ public class ConversationActivity extends BriarActivity private void markMessages(final Collection<MessageId> messageIds, final boolean sent, final boolean seen) { runOnUiThread(new Runnable() { + @Override public void run() { - Set<MessageId> messages = new HashSet<MessageId>(messageIds); - SparseArray<OutgoingItem> list = - adapter.getOutgoingMessages(); + Set<MessageId> messages = new HashSet<>(messageIds); + SparseArray<OutgoingItem> list = adapter.getOutgoingMessages(); for (int i = 0; i < list.size(); i++) { OutgoingItem item = list.valueAt(i); if (messages.contains(item.getId())) { @@ -550,6 +569,7 @@ public class ConversationActivity extends BriarActivity }); } + @Override public void onClick(View view) { markMessagesRead(); String message = content.getText().toString(); @@ -569,6 +589,7 @@ public class ConversationActivity extends BriarActivity private void createMessage(final byte[] body, final long timestamp) { cryptoExecutor.execute(new Runnable() { + @Override public void run() { try { storeMessage(privateMessageFactory.createPrivateMessage( @@ -582,6 +603,7 @@ public class ConversationActivity extends BriarActivity private void storeMessage(final PrivateMessage m) { runOnDbThread(new Runnable() { + @Override public void run() { try { long now = System.currentTimeMillis(); @@ -617,6 +639,7 @@ public class ConversationActivity extends BriarActivity private void removeContact() { runOnDbThread(new Runnable() { + @Override public void run() { try { // make sure contactId is initialised @@ -648,6 +671,7 @@ public class ConversationActivity extends BriarActivity private void hideIntroductionActionWhenOneContact(final MenuItem item) { runOnDbThread(new Runnable() { + @Override public void run() { try { if (contactManager.getActiveContacts().size() < 2) { @@ -689,11 +713,7 @@ public class ConversationActivity extends BriarActivity timestamp); } loadMessages(); - } catch (DbException e) { - introductionResponseError(); - if (LOG.isLoggable(WARNING)) - LOG.log(WARNING, e.toString(), e); - } catch (FormatException e) { + } catch (DbException | FormatException e) { introductionResponseError(); if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e); diff --git a/briar-android/src/org/briarproject/android/contact/ConversationAdapter.java b/briar-android/src/org/briarproject/android/contact/ConversationAdapter.java index cf1a4b738ea6610e31637d67378e50ea40da6af8..acc6ca6ca21749e41102d1ac15eb7dcaa2e4b9d3 100644 --- a/briar-android/src/org/briarproject/android/contact/ConversationAdapter.java +++ b/briar-android/src/org/briarproject/android/contact/ConversationAdapter.java @@ -41,6 +41,7 @@ class ConversationAdapter extends RecyclerView.Adapter { private final SortedList<ConversationItem> items = new SortedList<>(ConversationItem.class, new ListCallbacks()); + private Context ctx; private IntroductionHandler intro; private String contactName; @@ -67,44 +68,38 @@ class ConversationAdapter extends RecyclerView.Adapter { // outgoing message (local) if (type == MSG_OUT) { - v = LayoutInflater.from(viewGroup.getContext()) - .inflate(R.layout.list_item_msg_out, viewGroup, false); + v = LayoutInflater.from(viewGroup.getContext()).inflate( + R.layout.list_item_msg_out, viewGroup, false); return new MessageHolder(v, type); - } - else if (type == INTRODUCTION_IN) { - v = LayoutInflater.from(viewGroup.getContext()) - .inflate(R.layout.list_item_introduction_in, viewGroup, false); + } else if (type == INTRODUCTION_IN) { + v = LayoutInflater.from(viewGroup.getContext()).inflate( + R.layout.list_item_introduction_in, viewGroup, false); return new IntroductionHolder(v, type); - } - else if (type == INTRODUCTION_OUT) { - v = LayoutInflater.from(viewGroup.getContext()) - .inflate(R.layout.list_item_introduction_out, viewGroup, false); + } else if (type == INTRODUCTION_OUT) { + v = LayoutInflater.from(viewGroup.getContext()).inflate( + R.layout.list_item_introduction_out, viewGroup, false); return new IntroductionHolder(v, type); - } - else if (type == NOTICE_IN) { - v = LayoutInflater.from(viewGroup.getContext()) - .inflate(R.layout.list_item_notice_in, viewGroup, false); + } else if (type == NOTICE_IN) { + v = LayoutInflater.from(viewGroup.getContext()).inflate( + R.layout.list_item_notice_in, viewGroup, false); return new NoticeHolder(v, type); - } - else if (type == NOTICE_OUT) { - v = LayoutInflater.from(viewGroup.getContext()) - .inflate(R.layout.list_item_notice_out, viewGroup, false); + } else if (type == NOTICE_OUT) { + v = LayoutInflater.from(viewGroup.getContext()).inflate( + R.layout.list_item_notice_out, viewGroup, false); return new NoticeHolder(v, type); - } - else if (type == FORUM_INVITATION_IN) { - v = LayoutInflater.from(viewGroup.getContext()) - .inflate(R.layout.list_item_forum_invitation_in, viewGroup, false); + } else if (type == FORUM_INVITATION_IN) { + v = LayoutInflater.from(viewGroup.getContext()).inflate( + R.layout.list_item_forum_invitation_in, viewGroup, false); return new InvitationHolder(v, type); - } - else if (type == FORUM_INVITATION_OUT) { - v = LayoutInflater.from(viewGroup.getContext()) - .inflate(R.layout.list_item_forum_invitation_out, viewGroup, false); + } else if (type == FORUM_INVITATION_OUT) { + v = LayoutInflater.from(viewGroup.getContext()).inflate( + R.layout.list_item_forum_invitation_out, viewGroup, false); return new InvitationHolder(v, type); } // incoming message (non-local) else { - v = LayoutInflater.from(viewGroup.getContext()) - .inflate(R.layout.list_item_msg_in, viewGroup, false); + v = LayoutInflater.from(viewGroup.getContext()).inflate( + R.layout.list_item_msg_in, viewGroup, false); return new MessageHolder(v, type); } } @@ -126,10 +121,10 @@ class ConversationAdapter extends RecyclerView.Adapter { bindNotice((NoticeHolder) ui, (ConversationNoticeInItem) item); } else if (item instanceof ConversationForumInvitationOutItem) { bindInvitation((InvitationHolder) ui, - (ConversationForumInvitationOutItem) item, position); + (ConversationForumInvitationOutItem) item); } else if (item instanceof ConversationForumInvitationInItem) { bindInvitation((InvitationHolder) ui, - (ConversationForumInvitationInItem) item, position); + (ConversationForumInvitationInItem) item); } else { throw new IllegalArgumentException("Unhandled Conversation Item"); } @@ -200,13 +195,16 @@ class ConversationAdapter extends RecyclerView.Adapter { (ConversationIntroductionOutItem) item; if (i.isSeen()) { ui.status.setImageResource(R.drawable.message_delivered); - ui.message.status.setImageResource(R.drawable.message_delivered_white); + ui.message.status.setImageResource( + R.drawable.message_delivered_white); } else if (i.isSent()) { ui.status.setImageResource(R.drawable.message_sent); - ui.message.status.setImageResource(R.drawable.message_sent_white); + ui.message.status.setImageResource( + R.drawable.message_sent_white); } else { ui.status.setImageResource(R.drawable.message_stored); - ui.message.status.setImageResource(R.drawable.message_stored_white); + ui.message.status.setImageResource( + R.drawable.message_stored_white); } } // Incoming Introduction Request (Answered) @@ -279,7 +277,7 @@ class ConversationAdapter extends RecyclerView.Adapter { } private void bindInvitation(InvitationHolder ui, - final ConversationForumInvitationItem item, final int position) { + final ConversationForumInvitationItem item) { ForumInvitationMessage fim = item.getForumInvitationMessage(); @@ -301,13 +299,16 @@ class ConversationAdapter extends RecyclerView.Adapter { (ConversationForumInvitationOutItem) item; if (i.isSeen()) { ui.status.setImageResource(R.drawable.message_delivered); - ui.message.status.setImageResource(R.drawable.message_delivered_white); + ui.message.status.setImageResource( + R.drawable.message_delivered_white); } else if (i.isSent()) { ui.status.setImageResource(R.drawable.message_sent); - ui.message.status.setImageResource(R.drawable.message_sent_white); + ui.message.status.setImageResource( + R.drawable.message_sent_white); } else { ui.status.setImageResource(R.drawable.message_stored); - ui.message.status.setImageResource(R.drawable.message_stored_white); + ui.message.status.setImageResource( + R.drawable.message_stored_white); } } // Incoming Invitation @@ -321,9 +322,8 @@ class ConversationAdapter extends RecyclerView.Adapter { .setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - Intent intent = - new Intent(ctx, - AvailableForumsActivity.class); + Intent intent = new Intent(ctx, + AvailableForumsActivity.class); ctx.startActivity(intent); } }); @@ -380,7 +380,7 @@ class ConversationAdapter extends RecyclerView.Adapter { } public SparseArray<ConversationMessageItem> getPrivateMessages() { - SparseArray<ConversationMessageItem> messages = new SparseArray<>(); + SparseArray<ConversationMessageItem> messages = new SparseArray<>(); for (int i = 0; i < items.size(); i++) { ConversationItem item = items.get(i); @@ -426,19 +426,17 @@ class ConversationAdapter extends RecyclerView.Adapter { private static class IntroductionHolder extends RecyclerView.ViewHolder { - final private ViewGroup layout; - final private View messageLayout; - final private MessageHolder message; - final private TextView text; - final private Button acceptButton; - final private Button declineButton; - final private TextView date; - final private ImageView status; + private final View messageLayout; + private final MessageHolder message; + private final TextView text; + private final Button acceptButton; + private final Button declineButton; + private final TextView date; + private final ImageView status; public IntroductionHolder(View v, int type) { super(v); - layout = (ViewGroup) v.findViewById(R.id.introductionLayout); messageLayout = v.findViewById(R.id.messageLayout); message = new MessageHolder(messageLayout, type == INTRODUCTION_IN ? MSG_IN : MSG_OUT); @@ -457,15 +455,13 @@ class ConversationAdapter extends RecyclerView.Adapter { private static class NoticeHolder extends RecyclerView.ViewHolder { - final private ViewGroup layout; - final private TextView text; - final private TextView date; - final private ImageView status; + private final TextView text; + private final TextView date; + private final ImageView status; public NoticeHolder(View v, int type) { super(v); - layout = (ViewGroup) v.findViewById(R.id.noticeLayout); text = (TextView) v.findViewById(R.id.noticeText); date = (TextView) v.findViewById(R.id.noticeTime); @@ -479,18 +475,16 @@ class ConversationAdapter extends RecyclerView.Adapter { private static class InvitationHolder extends RecyclerView.ViewHolder { - final private ViewGroup layout; - final private View messageLayout; - final private MessageHolder message; - final private TextView text; - final private Button showForumsButton; - final private TextView date; - final private ImageView status; + private final View messageLayout; + private final MessageHolder message; + private final TextView text; + private final Button showForumsButton; + private final TextView date; + private final ImageView status; public InvitationHolder(View v, int type) { super(v); - layout = (ViewGroup) v.findViewById(R.id.introductionLayout); messageLayout = v.findViewById(R.id.messageLayout); message = new MessageHolder(messageLayout, type == FORUM_INVITATION_IN ? MSG_IN : MSG_OUT); @@ -507,6 +501,7 @@ class ConversationAdapter extends RecyclerView.Adapter { } private class ListCallbacks extends SortedList.Callback<ConversationItem> { + @Override public void onInserted(int position, int count) { notifyItemRangeInserted(position, count); @@ -551,8 +546,6 @@ class ConversationAdapter extends RecyclerView.Adapter { } public interface IntroductionHandler { - void respondToIntroduction(final SessionId sessionId, - final boolean accept); + void respondToIntroduction(SessionId sessionId, boolean accept); } - } diff --git a/briar-android/src/org/briarproject/android/contact/ConversationForumInvitationInItem.java b/briar-android/src/org/briarproject/android/contact/ConversationForumInvitationInItem.java index 06bf4a1adb5529fdfee54af829d84f2c9b41a69c..b082fe4d6af5ce16614c6fce3ef084d4bf1ec79b 100644 --- a/briar-android/src/org/briarproject/android/contact/ConversationForumInvitationInItem.java +++ b/briar-android/src/org/briarproject/android/contact/ConversationForumInvitationInItem.java @@ -29,5 +29,4 @@ public class ConversationForumInvitationInItem public void setRead(boolean read) { this.read = read; } - } diff --git a/briar-android/src/org/briarproject/android/contact/ConversationForumInvitationItem.java b/briar-android/src/org/briarproject/android/contact/ConversationForumInvitationItem.java index 0bf7d72abe85136c49fb2ce2e89df8e4d6621ba9..eb303d16b58e964efd36da5003d08a410765e086 100644 --- a/briar-android/src/org/briarproject/android/contact/ConversationForumInvitationItem.java +++ b/briar-android/src/org/briarproject/android/contact/ConversationForumInvitationItem.java @@ -4,7 +4,7 @@ import org.briarproject.api.forum.ForumInvitationMessage; abstract class ConversationForumInvitationItem extends ConversationItem { - private ForumInvitationMessage fim; + private final ForumInvitationMessage fim; public ConversationForumInvitationItem(ForumInvitationMessage fim) { super(fim.getId(), fim.getTimestamp()); @@ -15,5 +15,4 @@ abstract class ConversationForumInvitationItem extends ConversationItem { public ForumInvitationMessage getForumInvitationMessage() { return fim; } - } diff --git a/briar-android/src/org/briarproject/android/contact/ConversationForumInvitationOutItem.java b/briar-android/src/org/briarproject/android/contact/ConversationForumInvitationOutItem.java index 2d4699abf3e3df877463227d5c028e0bb9c0124c..202023dda2fd3dd68534f276fedc005c98dd8327 100644 --- a/briar-android/src/org/briarproject/android/contact/ConversationForumInvitationOutItem.java +++ b/briar-android/src/org/briarproject/android/contact/ConversationForumInvitationOutItem.java @@ -6,7 +6,7 @@ import org.briarproject.api.forum.ForumInvitationMessage; * This class is needed and can not be replaced by an ConversationNoticeOutItem, * because it carries the optional invitation message * to be displayed as a regular private message. - * + * <p/> * This class is not thread-safe */ public class ConversationForumInvitationOutItem @@ -45,5 +45,4 @@ public class ConversationForumInvitationOutItem public void setSeen(boolean seen) { this.seen = seen; } - } diff --git a/briar-android/src/org/briarproject/android/contact/ConversationIntroductionInItem.java b/briar-android/src/org/briarproject/android/contact/ConversationIntroductionInItem.java index 9ccf21efdc57355a009f12b141d731b8a00955fd..caefec6a61bb328f602e1c972273653f53c29792 100644 --- a/briar-android/src/org/briarproject/android/contact/ConversationIntroductionInItem.java +++ b/briar-android/src/org/briarproject/android/contact/ConversationIntroductionInItem.java @@ -1,7 +1,6 @@ package org.briarproject.android.contact; import org.briarproject.api.introduction.IntroductionRequest; -import org.briarproject.api.sync.MessageId; // This class is not thread-safe public class ConversationIntroductionInItem extends ConversationIntroductionItem @@ -29,5 +28,4 @@ public class ConversationIntroductionInItem extends ConversationIntroductionItem public void setRead(boolean read) { this.read = read; } - } diff --git a/briar-android/src/org/briarproject/android/contact/ConversationIntroductionItem.java b/briar-android/src/org/briarproject/android/contact/ConversationIntroductionItem.java index 565f9f1f8d48a423320bba341d880c321313a532..51a7c3ebbc789ba05adfea1e4ee3a8afd5964f2c 100644 --- a/briar-android/src/org/briarproject/android/contact/ConversationIntroductionItem.java +++ b/briar-android/src/org/briarproject/android/contact/ConversationIntroductionItem.java @@ -2,9 +2,10 @@ package org.briarproject.android.contact; import org.briarproject.api.introduction.IntroductionRequest; +// This class is not thread-safe abstract class ConversationIntroductionItem extends ConversationItem { - private IntroductionRequest ir; + private final IntroductionRequest ir; private boolean answered; public ConversationIntroductionItem(IntroductionRequest ir) { @@ -25,5 +26,4 @@ abstract class ConversationIntroductionItem extends ConversationItem { public void setAnswered(boolean answered) { this.answered = answered; } - } diff --git a/briar-android/src/org/briarproject/android/contact/ConversationIntroductionOutItem.java b/briar-android/src/org/briarproject/android/contact/ConversationIntroductionOutItem.java index 7584c87380b1aa0581675df02ffaca9b403aaf8b..7c7082a8d0538da2b74656a935ba64269de290ab 100644 --- a/briar-android/src/org/briarproject/android/contact/ConversationIntroductionOutItem.java +++ b/briar-android/src/org/briarproject/android/contact/ConversationIntroductionOutItem.java @@ -45,5 +45,4 @@ public class ConversationIntroductionOutItem public void setSeen(boolean seen) { this.seen = seen; } - } diff --git a/briar-android/src/org/briarproject/android/contact/ConversationItem.java b/briar-android/src/org/briarproject/android/contact/ConversationItem.java index 93e95e24f3a0490364db04867365b1054956a18b..7b75cb13a61209323544f2ab6937c14177fd3b0c 100644 --- a/briar-android/src/org/briarproject/android/contact/ConversationItem.java +++ b/briar-android/src/org/briarproject/android/contact/ConversationItem.java @@ -103,8 +103,9 @@ public abstract class ConversationItem { } } - /** This method should not be used to get user-facing objects, - * Its purpose is to provider data for the contact list. + /** + * This method should not be used to get user-facing objects, + * Its purpose is to provider data for the contact list. */ public static ConversationItem from(IntroductionMessage im) { if (im.isLocal()) @@ -115,17 +116,24 @@ public abstract class ConversationItem { } protected interface OutgoingItem { + MessageId getId(); + boolean isSent(); + void setSent(boolean sent); + boolean isSeen(); + void setSeen(boolean seen); } protected interface IncomingItem { + MessageId getId(); + boolean isRead(); + void setRead(boolean read); } - } diff --git a/briar-android/src/org/briarproject/android/contact/ConversationMessageInItem.java b/briar-android/src/org/briarproject/android/contact/ConversationMessageInItem.java index c24f86a1288376748fc0a8ba05390047d53368c2..7969aebd7890d6ee06b168ac07a7fc1ec7527502 100644 --- a/briar-android/src/org/briarproject/android/contact/ConversationMessageInItem.java +++ b/briar-android/src/org/briarproject/android/contact/ConversationMessageInItem.java @@ -28,5 +28,4 @@ public class ConversationMessageInItem extends ConversationMessageItem public void setRead(boolean read) { this.read = read; } - } diff --git a/briar-android/src/org/briarproject/android/contact/ConversationMessageItem.java b/briar-android/src/org/briarproject/android/contact/ConversationMessageItem.java index db780efbcad65a42a7f0654d0b63666fedf8f6d5..f151cde176483d72be4637e4c9924ce9e517d97c 100644 --- a/briar-android/src/org/briarproject/android/contact/ConversationMessageItem.java +++ b/briar-android/src/org/briarproject/android/contact/ConversationMessageItem.java @@ -26,5 +26,4 @@ abstract class ConversationMessageItem extends ConversationItem { void setBody(byte[] body) { this.body = body; } - } diff --git a/briar-android/src/org/briarproject/android/contact/ConversationMessageOutItem.java b/briar-android/src/org/briarproject/android/contact/ConversationMessageOutItem.java index cfdf871afb2421b58a2dce072bbff583b4d0083e..7fc6025546ad15f50858c1601b8ff22acba3a647 100644 --- a/briar-android/src/org/briarproject/android/contact/ConversationMessageOutItem.java +++ b/briar-android/src/org/briarproject/android/contact/ConversationMessageOutItem.java @@ -39,5 +39,4 @@ public class ConversationMessageOutItem extends ConversationMessageItem public void setSeen(boolean seen) { this.seen = seen; } - } diff --git a/briar-android/src/org/briarproject/android/contact/ConversationNoticeInItem.java b/briar-android/src/org/briarproject/android/contact/ConversationNoticeInItem.java index 3affb3d4836e73ed130a152a1b41505230a7e8e1..9b4acb556aea257f5b52d96019794266e45b9738 100644 --- a/briar-android/src/org/briarproject/android/contact/ConversationNoticeInItem.java +++ b/briar-android/src/org/briarproject/android/contact/ConversationNoticeInItem.java @@ -3,8 +3,8 @@ package org.briarproject.android.contact; import org.briarproject.api.sync.MessageId; // This class is not thread-safe -public class ConversationNoticeInItem extends ConversationNoticeItem implements - ConversationItem.IncomingItem { +public class ConversationNoticeInItem extends ConversationNoticeItem + implements ConversationItem.IncomingItem { private boolean read; @@ -29,5 +29,4 @@ public class ConversationNoticeInItem extends ConversationNoticeItem implements public void setRead(boolean read) { this.read = read; } - } diff --git a/briar-android/src/org/briarproject/android/contact/ConversationNoticeItem.java b/briar-android/src/org/briarproject/android/contact/ConversationNoticeItem.java index eabc73970aafd87593be54283b909dddce5d50c4..8245f775887c7994bee6a5f19d87b73f41b621cb 100644 --- a/briar-android/src/org/briarproject/android/contact/ConversationNoticeItem.java +++ b/briar-android/src/org/briarproject/android/contact/ConversationNoticeItem.java @@ -4,7 +4,7 @@ import org.briarproject.api.sync.MessageId; abstract class ConversationNoticeItem extends ConversationItem { - private String text; + private final String text; public ConversationNoticeItem(MessageId id, String text, long time) { super(id, time); @@ -15,5 +15,4 @@ abstract class ConversationNoticeItem extends ConversationItem { public String getText() { return text; } - } diff --git a/briar-android/src/org/briarproject/android/contact/ConversationNoticeOutItem.java b/briar-android/src/org/briarproject/android/contact/ConversationNoticeOutItem.java index ca4503cf671e23595c7cbcd6d459e6f3c2f92689..c8a6b5459c1b6af0638d6b183e2e3004db07c381 100644 --- a/briar-android/src/org/briarproject/android/contact/ConversationNoticeOutItem.java +++ b/briar-android/src/org/briarproject/android/contact/ConversationNoticeOutItem.java @@ -3,14 +3,13 @@ package org.briarproject.android.contact; import org.briarproject.api.sync.MessageId; // This class is not thread-safe -public class ConversationNoticeOutItem extends ConversationNoticeItem implements - ConversationItem.OutgoingItem { +public class ConversationNoticeOutItem extends ConversationNoticeItem + implements ConversationItem.OutgoingItem { private boolean sent, seen; public ConversationNoticeOutItem(MessageId id, String text, long time, boolean sent, boolean seen) { - super(id, text, time); this.sent = sent; @@ -41,5 +40,4 @@ public class ConversationNoticeOutItem extends ConversationNoticeItem implements public void setSeen(boolean seen) { this.seen = seen; } - } diff --git a/briar-android/src/org/briarproject/android/controller/BriarController.java b/briar-android/src/org/briarproject/android/controller/BriarController.java index 4be89b1085be3057c68b3d6b1b54ce0f078798ae..e2253c3dc76723f76891f331e23f4aed854763be 100644 --- a/briar-android/src/org/briarproject/android/controller/BriarController.java +++ b/briar-android/src/org/briarproject/android/controller/BriarController.java @@ -1,9 +1,9 @@ package org.briarproject.android.controller; - import org.briarproject.android.controller.handler.ResultHandler; public interface BriarController extends ActivityLifecycleController { + void runOnDbThread(final Runnable task); void startAndBindService(); diff --git a/briar-android/src/org/briarproject/android/controller/BriarControllerImpl.java b/briar-android/src/org/briarproject/android/controller/BriarControllerImpl.java index fd24291c78233b44cdc4c14cb3e61cddf654055a..337e0436e3646974e532a6a5907306d8c2b3e5cc 100644 --- a/briar-android/src/org/briarproject/android/controller/BriarControllerImpl.java +++ b/briar-android/src/org/briarproject/android/controller/BriarControllerImpl.java @@ -26,14 +26,15 @@ public class BriarControllerImpl implements BriarController { protected BriarServiceConnection serviceConnection; @Inject protected DatabaseConfig databaseConfig; + @Inject + protected Activity activity; + // Fields that are accessed from background threads must be volatile @Inject @DatabaseExecutor protected volatile Executor dbExecutor; @Inject protected volatile LifecycleManager lifecycleManager; - @Inject - protected Activity activity; private boolean bound = false; @@ -64,6 +65,7 @@ public class BriarControllerImpl implements BriarController { unbindService(); } + @Override public void startAndBindService() { activity.startService(new Intent(activity, BriarService.class)); bound = activity.bindService(new Intent(activity, BriarService.class), @@ -83,7 +85,8 @@ public class BriarControllerImpl implements BriarController { try { // Wait for the service to finish starting up IBinder binder = serviceConnection.waitForBinder(); - BriarService service = ((BriarService.BriarBinder) binder).getService(); + BriarService service = + ((BriarService.BriarBinder) binder).getService(); service.waitForStartup(); // Shut down the service and wait for it to shut down LOG.info("Shutting down service"); @@ -101,8 +104,10 @@ public class BriarControllerImpl implements BriarController { if (bound) activity.unbindService(serviceConnection); } + @Override public void runOnDbThread(final Runnable task) { dbExecutor.execute(new Runnable() { + @Override public void run() { try { lifecycleManager.waitForDatabase(); @@ -114,5 +119,4 @@ public class BriarControllerImpl implements BriarController { } }); } - } diff --git a/briar-android/src/org/briarproject/android/controller/ConfigController.java b/briar-android/src/org/briarproject/android/controller/ConfigController.java index cddbc1bc688e98e21cc7e562175e91d073c52698..38ad81121b4281272362b07d6cbf834519150f25 100644 --- a/briar-android/src/org/briarproject/android/controller/ConfigController.java +++ b/briar-android/src/org/briarproject/android/controller/ConfigController.java @@ -1,9 +1,12 @@ package org.briarproject.android.controller; +import android.content.Context; + public interface ConfigController { + String getEncryptedDatabaseKey(); - void clearPrefs(); + void deleteAccount(Context ctx); - boolean initialized(); + boolean accountExists(); } diff --git a/briar-android/src/org/briarproject/android/controller/ConfigControllerImpl.java b/briar-android/src/org/briarproject/android/controller/ConfigControllerImpl.java index b823b98e2c879478517211cfedaeceeaa30efa90..1f6c88e500f822b83a8fa967c2f2e5eaabff0371 100644 --- a/briar-android/src/org/briarproject/android/controller/ConfigControllerImpl.java +++ b/briar-android/src/org/briarproject/android/controller/ConfigControllerImpl.java @@ -1,14 +1,16 @@ package org.briarproject.android.controller; +import android.content.Context; import android.content.SharedPreferences; +import org.briarproject.android.util.AndroidUtils; import org.briarproject.api.db.DatabaseConfig; import javax.inject.Inject; public class ConfigControllerImpl implements ConfigController { - private final static String PREF_DB_KEY = "key"; + private static final String PREF_DB_KEY = "key"; @Inject protected SharedPreferences briarPrefs; @@ -20,22 +22,22 @@ public class ConfigControllerImpl implements ConfigController { } + @Override public String getEncryptedDatabaseKey() { return briarPrefs.getString(PREF_DB_KEY, null); } - public void clearPrefs() { + @Override + public void deleteAccount(Context ctx) { SharedPreferences.Editor editor = briarPrefs.edit(); editor.clear(); editor.apply(); + AndroidUtils.deleteAppData(ctx); } @Override - public boolean initialized() { + public boolean accountExists() { String hex = getEncryptedDatabaseKey(); - if (hex != null && databaseConfig.databaseExists()) { - return true; - } - return false; + return hex != null && databaseConfig.databaseExists(); } } diff --git a/briar-android/src/org/briarproject/android/controller/NavDrawerController.java b/briar-android/src/org/briarproject/android/controller/NavDrawerController.java index 56d48b1ca17feddac9c6cf0aa1363864681984dc..db389706b4b8c8586b61a1ef66ab263740157925 100644 --- a/briar-android/src/org/briarproject/android/controller/NavDrawerController.java +++ b/briar-android/src/org/briarproject/android/controller/NavDrawerController.java @@ -5,6 +5,7 @@ import org.briarproject.api.TransportId; import org.briarproject.api.identity.LocalAuthor; public interface NavDrawerController extends BriarController { + void setTransportListener(TransportStateListener transportListener); boolean isTransportRunning(TransportId transportId); diff --git a/briar-android/src/org/briarproject/android/controller/NavDrawerControllerImpl.java b/briar-android/src/org/briarproject/android/controller/NavDrawerControllerImpl.java index 4be03f94999432a82e25051b354597eefbdc46ab..651f60bcbd304aec89b6a7f7f95d498e652cf942 100644 --- a/briar-android/src/org/briarproject/android/controller/NavDrawerControllerImpl.java +++ b/briar-android/src/org/briarproject/android/controller/NavDrawerControllerImpl.java @@ -16,8 +16,6 @@ import org.briarproject.api.identity.LocalAuthor; import org.briarproject.api.plugins.Plugin; import org.briarproject.api.plugins.PluginManager; -import java.util.ArrayList; -import java.util.List; import java.util.logging.Logger; import javax.inject.Inject; @@ -34,15 +32,15 @@ public class NavDrawerControllerImpl extends BriarControllerImpl @Inject protected ReferenceManager referenceManager; @Inject - protected volatile IdentityManager identityManager; - @Inject protected PluginManager pluginManager; @Inject protected EventBus eventBus; @Inject protected Activity activity; - private List<Plugin> transports = new ArrayList<Plugin>(); + // Fields that are accessed from background threads must be volatile + @Inject + protected volatile IdentityManager identityManager; private TransportStateListener transportStateListener; @@ -112,6 +110,7 @@ public class NavDrawerControllerImpl extends BriarControllerImpl public void storeLocalAuthor(final LocalAuthor author, final UiResultHandler<Void> resultHandler) { runOnDbThread(new Runnable() { + @Override public void run() { try { long now = System.currentTimeMillis(); @@ -130,7 +129,6 @@ public class NavDrawerControllerImpl extends BriarControllerImpl @Override public LocalAuthor removeAuthorHandle(long handle) { - return referenceManager.removeReference(handle, - LocalAuthor.class); + return referenceManager.removeReference(handle, LocalAuthor.class); } } diff --git a/briar-android/src/org/briarproject/android/controller/PasswordController.java b/briar-android/src/org/briarproject/android/controller/PasswordController.java index bf1c9b230ec1349c2fda9f076d6880c7dac1fc6e..b49c4c3fa69a377ebd19af07f5a54e0f7579357d 100644 --- a/briar-android/src/org/briarproject/android/controller/PasswordController.java +++ b/briar-android/src/org/briarproject/android/controller/PasswordController.java @@ -3,6 +3,7 @@ package org.briarproject.android.controller; import org.briarproject.android.controller.handler.ResultHandler; public interface PasswordController extends ConfigController { + void validatePassword(String password, ResultHandler<Boolean> resultHandler); } diff --git a/briar-android/src/org/briarproject/android/controller/PasswordControllerImpl.java b/briar-android/src/org/briarproject/android/controller/PasswordControllerImpl.java index 12f7e424072860a6853beee0d70542e76b0cb201..22025b0a2172f788ba066fdc49d0c986a0b859e4 100644 --- a/briar-android/src/org/briarproject/android/controller/PasswordControllerImpl.java +++ b/briar-android/src/org/briarproject/android/controller/PasswordControllerImpl.java @@ -33,6 +33,7 @@ public class PasswordControllerImpl extends ConfigControllerImpl final ResultHandler<Boolean> resultHandler) { final byte[] encrypted = getEncryptedKey(); cryptoExecutor.execute(new Runnable() { + @Override public void run() { byte[] key = crypto.decryptWithPassword(encrypted, password); if (key == null) { @@ -48,7 +49,7 @@ public class PasswordControllerImpl extends ConfigControllerImpl private byte[] getEncryptedKey() { String hex = getEncryptedDatabaseKey(); if (hex == null) - throw new IllegalStateException("Encrypted database key is null."); + throw new IllegalStateException("Encrypted database key is null"); return StringUtils.fromHexString(hex); } } diff --git a/briar-android/src/org/briarproject/android/controller/SetupController.java b/briar-android/src/org/briarproject/android/controller/SetupController.java index 476db0f5e8cefddf5fa661e5ad9249281a768730..567d34b43ebbd0857ceda6b792cb447c5e97d1ff 100644 --- a/briar-android/src/org/briarproject/android/controller/SetupController.java +++ b/briar-android/src/org/briarproject/android/controller/SetupController.java @@ -3,6 +3,7 @@ package org.briarproject.android.controller; import org.briarproject.android.controller.handler.ResultHandler; public interface SetupController { + float estimatePasswordStrength(String password); void createIdentity(String nickname, String password, diff --git a/briar-android/src/org/briarproject/android/controller/SetupControllerImpl.java b/briar-android/src/org/briarproject/android/controller/SetupControllerImpl.java index 29bed6d1940dbe3863666fc9ccd143e60b88b979..6500346ebeafd8d99170c0a823533bccf59e666f 100644 --- a/briar-android/src/org/briarproject/android/controller/SetupControllerImpl.java +++ b/briar-android/src/org/briarproject/android/controller/SetupControllerImpl.java @@ -34,6 +34,10 @@ public class SetupControllerImpl implements SetupController { protected Executor cryptoExecutor; @Inject protected PasswordStrengthEstimator strengthEstimator; + @Inject + protected Activity activity; + @Inject + protected SharedPreferences briarPrefs; // Fields that are accessed from background threads must be volatile @Inject @@ -44,10 +48,6 @@ public class SetupControllerImpl implements SetupController { protected volatile AuthorFactory authorFactory; @Inject protected volatile ReferenceManager referenceManager; - @Inject - protected Activity activity; - @Inject - protected SharedPreferences briarPrefs; @Inject public SetupControllerImpl() { @@ -85,6 +85,7 @@ public class SetupControllerImpl implements SetupController { public void createIdentity(final String nickname, final String password, final ResultHandler<Long> resultHandler) { cryptoExecutor.execute(new Runnable() { + @Override public void run() { SecretKey key = crypto.generateSecretKey(); databaseConfig.setEncryptionKey(key); @@ -98,10 +99,9 @@ public class SetupControllerImpl implements SetupController { }); } - private void storeEncryptedDatabaseKey(final String hex) { + private void storeEncryptedDatabaseKey(String hex) { SharedPreferences.Editor editor = briarPrefs.edit(); editor.putString(PREF_DB_KEY, hex); editor.apply(); } - } diff --git a/briar-android/src/org/briarproject/android/controller/TransportStateListener.java b/briar-android/src/org/briarproject/android/controller/TransportStateListener.java index 0a00c0f7dc0c73d846e3222884b7d37311fde601..7f472b601768a4a93c413a3a584f751c7a63c7cb 100644 --- a/briar-android/src/org/briarproject/android/controller/TransportStateListener.java +++ b/briar-android/src/org/briarproject/android/controller/TransportStateListener.java @@ -3,5 +3,6 @@ package org.briarproject.android.controller; import org.briarproject.api.TransportId; public interface TransportStateListener { + void stateUpdate(TransportId id, boolean enabled); } diff --git a/briar-android/src/org/briarproject/android/controller/handler/ResultExceptionHandler.java b/briar-android/src/org/briarproject/android/controller/handler/ResultExceptionHandler.java index 5d3cb030109f11e730e54c6ff3ecffe2e8667d60..3743c0804bb8d4646b21a753e930664685087255 100644 --- a/briar-android/src/org/briarproject/android/controller/handler/ResultExceptionHandler.java +++ b/briar-android/src/org/briarproject/android/controller/handler/ResultExceptionHandler.java @@ -1,6 +1,8 @@ package org.briarproject.android.controller.handler; public interface ResultExceptionHandler<R, E extends Exception> { + void onResult(R result); + void onException(E exception); } diff --git a/briar-android/src/org/briarproject/android/controller/handler/ResultHandler.java b/briar-android/src/org/briarproject/android/controller/handler/ResultHandler.java index 55516f9422162e458633532d60043989dfb6c58b..601ff294d50136b9f0b705075e15c6fd824ade86 100644 --- a/briar-android/src/org/briarproject/android/controller/handler/ResultHandler.java +++ b/briar-android/src/org/briarproject/android/controller/handler/ResultHandler.java @@ -1,5 +1,6 @@ package org.briarproject.android.controller.handler; public interface ResultHandler<R> { + void onResult(R result); } diff --git a/briar-android/src/org/briarproject/android/controller/handler/UiResultExceptionHandler.java b/briar-android/src/org/briarproject/android/controller/handler/UiResultExceptionHandler.java index 7d9c08f4fb2b1ef3ad67f0806186b9b965b292e1..89659b71d09965fbe1767360e7d99d30a0fc855a 100644 --- a/briar-android/src/org/briarproject/android/controller/handler/UiResultExceptionHandler.java +++ b/briar-android/src/org/briarproject/android/controller/handler/UiResultExceptionHandler.java @@ -11,16 +11,20 @@ public abstract class UiResultExceptionHandler<R, E extends Exception> this.activity = activity; } + @Override public void onResult(final R result) { activity.runOnUiThread(new Runnable() { + @Override public void run() { onResultUi(result); } }); } + @Override public void onException(final E exception) { activity.runOnUiThread(new Runnable() { + @Override public void run() { onExceptionUi(exception); } diff --git a/briar-android/src/org/briarproject/android/controller/handler/UiResultHandler.java b/briar-android/src/org/briarproject/android/controller/handler/UiResultHandler.java index 1998060a5c9ff4b736f0e4102e3237d19122f4b1..5aa32e25a7cae4fef97910fe83c054980c1ffab8 100644 --- a/briar-android/src/org/briarproject/android/controller/handler/UiResultHandler.java +++ b/briar-android/src/org/briarproject/android/controller/handler/UiResultHandler.java @@ -10,8 +10,10 @@ public abstract class UiResultHandler<R> implements ResultHandler<R> { this.activity = activity; } + @Override public void onResult(final R result) { activity.runOnUiThread(new Runnable() { + @Override public void run() { onResultUi(result); } diff --git a/briar-android/src/org/briarproject/android/forum/AvailableForumsActivity.java b/briar-android/src/org/briarproject/android/forum/AvailableForumsActivity.java index f1e1a7b9efb6cdee845c4338a0359ef6b122b487..bcf39e8360766b1e722912f3a6c7faec994f4ceb 100644 --- a/briar-android/src/org/briarproject/android/forum/AvailableForumsActivity.java +++ b/briar-android/src/org/briarproject/android/forum/AvailableForumsActivity.java @@ -6,7 +6,6 @@ import android.widget.Toast; import org.briarproject.R; import org.briarproject.android.ActivityComponent; -import org.briarproject.android.AndroidComponent; import org.briarproject.android.BriarActivity; import org.briarproject.android.util.BriarRecyclerView; import org.briarproject.api.contact.Contact; @@ -44,9 +43,12 @@ public class AvailableForumsActivity extends BriarActivity private AvailableForumsAdapter adapter; // Fields that are accessed from background threads must be volatile - @Inject protected volatile ForumManager forumManager; - @Inject protected volatile ForumSharingManager forumSharingManager; - @Inject protected volatile EventBus eventBus; + @Inject + protected volatile ForumManager forumManager; + @Inject + protected volatile ForumSharingManager forumSharingManager; + @Inject + protected volatile EventBus eventBus; @Override public void onCreate(Bundle state) { @@ -75,6 +77,7 @@ public class AvailableForumsActivity extends BriarActivity private void loadForums() { runOnDbThread(new Runnable() { + @Override public void run() { try { Collection<ForumContacts> available = new ArrayList<>(); @@ -102,6 +105,7 @@ public class AvailableForumsActivity extends BriarActivity private void displayForums(final Collection<ForumContacts> available) { runOnUiThread(new Runnable() { + @Override public void run() { if (available.isEmpty()) { LOG.info("No forums available, finishing"); @@ -124,6 +128,7 @@ public class AvailableForumsActivity extends BriarActivity eventBus.removeListener(this); } + @Override public void eventOccurred(Event e) { if (e instanceof ContactRemovedEvent) { LOG.info("Contact removed, reloading"); @@ -146,6 +151,7 @@ public class AvailableForumsActivity extends BriarActivity } } + @Override public void onItemClick(AvailableForumsItem item, boolean accept) { respondToInvitation(item.getForum(), accept); @@ -157,6 +163,7 @@ public class AvailableForumsActivity extends BriarActivity private void respondToInvitation(final Forum f, final boolean accept) { runOnDbThread(new Runnable() { + @Override public void run() { try { forumSharingManager.respondToInvitation(f, accept); @@ -168,5 +175,4 @@ public class AvailableForumsActivity extends BriarActivity } }); } - } diff --git a/briar-android/src/org/briarproject/android/forum/AvailableForumsAdapter.java b/briar-android/src/org/briarproject/android/forum/AvailableForumsAdapter.java index 0cd0e818123de7c70ef8c405786a1599d99a51c9..409cbaa75ce081b9f25bc5faca2a8ade202fb471 100644 --- a/briar-android/src/org/briarproject/android/forum/AvailableForumsAdapter.java +++ b/briar-android/src/org/briarproject/android/forum/AvailableForumsAdapter.java @@ -25,9 +25,7 @@ class AvailableForumsAdapter extends new SortedList<>(AvailableForumsItem.class, new SortedListCallBacks()); - AvailableForumsAdapter(Context ctx, - AvailableForumClickListener listener) { - + AvailableForumsAdapter(Context ctx, AvailableForumClickListener listener) { this.ctx = ctx; this.listener = listener; } @@ -90,16 +88,14 @@ class AvailableForumsAdapter extends protected static class AvailableForumViewHolder extends RecyclerView.ViewHolder { - public final ViewGroup layout; - public final TextView name; - public final TextView sharedBy; - public final Button accept; - public final Button decline; + private final TextView name; + private final TextView sharedBy; + private final Button accept; + private final Button decline; public AvailableForumViewHolder(View v) { super(v); - layout = (ViewGroup) v; name = (TextView) v.findViewById(R.id.forumNameView); sharedBy = (TextView) v.findViewById(R.id.sharedByView); accept = (Button) v.findViewById(R.id.acceptButton); @@ -156,5 +152,4 @@ class AvailableForumsAdapter extends interface AvailableForumClickListener { void onItemClick(AvailableForumsItem item, boolean accept); } - } diff --git a/briar-android/src/org/briarproject/android/forum/ContactSelectorAdapter.java b/briar-android/src/org/briarproject/android/forum/ContactSelectorAdapter.java index 2f1ce156b65c3ca75406156bf207d27339f27b32..23ef1e78cc0b1e7715fd43f2d2873d2d5204341c 100644 --- a/briar-android/src/org/briarproject/android/forum/ContactSelectorAdapter.java +++ b/briar-android/src/org/briarproject/android/forum/ContactSelectorAdapter.java @@ -20,8 +20,7 @@ import java.util.ArrayList; import java.util.Collection; public class ContactSelectorAdapter - extends - BaseContactListAdapter<ContactSelectorAdapter.SelectableContactHolder> { + extends BaseContactListAdapter<ContactSelectorAdapter.SelectableContactHolder> { public ContactSelectorAdapter(Context context, OnItemClickListener listener) { @@ -32,19 +31,17 @@ public class ContactSelectorAdapter @Override public SelectableContactHolder onCreateViewHolder(ViewGroup viewGroup, int i) { - View v = LayoutInflater.from(ctx) - .inflate(R.layout.list_item_selectable_contact, viewGroup, - false); + View v = LayoutInflater.from(ctx).inflate( + R.layout.list_item_selectable_contact, viewGroup, false); return new SelectableContactHolder(v); } @Override - public void onBindViewHolder(final SelectableContactHolder ui, - final int position) { + public void onBindViewHolder(SelectableContactHolder ui, int position) { super.onBindViewHolder(ui, position); - final SelectableContactListItem item = + SelectableContactListItem item = (SelectableContactListItem) getItem(position); if (item.isSelected()) { @@ -90,7 +87,7 @@ public class ContactSelectorAdapter } private void grayOutItem(final SelectableContactHolder ui) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { + if (Build.VERSION.SDK_INT >= 11) { float alpha = 0.25f; ui.avatar.setAlpha(alpha); ui.name.setAlpha(alpha); @@ -103,5 +100,4 @@ public class ContactSelectorAdapter ui.checkBox.setEnabled(false); } } - } diff --git a/briar-android/src/org/briarproject/android/forum/ContactSelectorFragment.java b/briar-android/src/org/briarproject/android/forum/ContactSelectorFragment.java index cd5ff9bcffa3353f5abc0cf94c4b7765e6e2ad82..8cefe834f75e42d1b7f107b4f052c1054301a0c2 100644 --- a/briar-android/src/org/briarproject/android/forum/ContactSelectorFragment.java +++ b/briar-android/src/org/briarproject/android/forum/ContactSelectorFragment.java @@ -44,17 +44,17 @@ public class ContactSelectorFragment extends BaseFragment implements BaseContactListAdapter.OnItemClickListener { public final static String TAG = "ContactSelectorFragment"; + + private static final Logger LOG = + Logger.getLogger(ContactSelectorFragment.class.getName()); + private ShareForumActivity shareForumActivity; private Menu menu; private BriarRecyclerView list; private ContactSelectorAdapter adapter; private Collection<ContactId> selectedContacts; - private static final Logger LOG = - Logger.getLogger(ContactSelectorFragment.class.getName()); - // Fields that are accessed from background threads must be volatile - protected volatile GroupId groupId; @Inject protected volatile ContactManager contactManager; @Inject @@ -62,6 +62,8 @@ public class ContactSelectorFragment extends BaseFragment implements @Inject protected volatile ForumSharingManager forumSharingManager; + protected volatile GroupId groupId; + public void initBundle(GroupId groupId) { Bundle bundle = new Bundle(); bundle.putByteArray(GROUP_ID, groupId.getBytes()); @@ -97,11 +99,10 @@ public class ContactSelectorFragment extends BaseFragment implements public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - View contentView = - inflater.inflate(R.layout.introduction_contact_chooser, - container, false); + View contentView = inflater.inflate( + R.layout.introduction_contact_chooser, container, false); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + if (Build.VERSION.SDK_INT >= 21) { setExitTransition(new Fade()); } @@ -116,7 +117,8 @@ public class ContactSelectorFragment extends BaseFragment implements if (savedInstanceState != null) { ArrayList<Integer> intContacts = savedInstanceState.getIntegerArrayList(CONTACTS); - selectedContacts = ShareForumActivity.getContactsFromIntegers(intContacts); + selectedContacts = ShareForumActivity.getContactsFromIntegers( + intContacts); } return contentView; @@ -126,11 +128,9 @@ public class ContactSelectorFragment extends BaseFragment implements public void onResume() { super.onResume(); - if (selectedContacts != null) { + if (selectedContacts != null) loadContacts(Collections.unmodifiableCollection(selectedContacts)); - } else { - loadContacts(null); - } + else loadContacts(null); } @Override @@ -182,11 +182,11 @@ public class ContactSelectorFragment extends BaseFragment implements private void loadContacts(final Collection<ContactId> selection) { shareForumActivity.runOnDbThread(new Runnable() { + @Override public void run() { try { long now = System.currentTimeMillis(); - List<ContactListItem> contacts = - new ArrayList<>(); + List<ContactListItem> contacts = new ArrayList<>(); for (Contact c : contactManager.getActiveContacts()) { LocalAuthor localAuthor = identityManager @@ -197,9 +197,8 @@ public class ContactSelectorFragment extends BaseFragment implements // do we have already some sharing with that contact? boolean disabled = !forumSharingManager.canBeShared(groupId, c); - contacts.add( - new SelectableContactListItem(c, localAuthor, - groupId, selected, disabled)); + contacts.add(new SelectableContactListItem(c, + localAuthor, groupId, selected, disabled)); } long duration = System.currentTimeMillis() - now; if (LOG.isLoggable(INFO)) @@ -216,12 +215,10 @@ public class ContactSelectorFragment extends BaseFragment implements private void displayContacts(final List<ContactListItem> contacts) { shareForumActivity.runOnUiThread(new Runnable() { + @Override public void run() { - if (!contacts.isEmpty()) { - adapter.addAll(contacts); - } else { - list.showData(); - } + if (!contacts.isEmpty()) adapter.addAll(contacts); + else list.showData(); updateMenuItem(); } }); @@ -239,5 +236,4 @@ public class ContactSelectorFragment extends BaseFragment implements item.setVisible(false); } } - } diff --git a/briar-android/src/org/briarproject/android/forum/CreateForumActivity.java b/briar-android/src/org/briarproject/android/forum/CreateForumActivity.java index fbb10650e834a08d2f288279aebd3febb0063253..f3053067a7190c8ada8535a00e83bdcb2c11751c 100644 --- a/briar-android/src/org/briarproject/android/forum/CreateForumActivity.java +++ b/briar-android/src/org/briarproject/android/forum/CreateForumActivity.java @@ -40,10 +40,10 @@ public class CreateForumActivity extends BriarActivity private static final Logger LOG = Logger.getLogger(CreateForumActivity.class.getName()); - private EditText nameEntry = null; - private Button createForumButton = null; - private ProgressBar progress = null; - private TextView feedback = null; + private EditText nameEntry; + private Button createForumButton; + private ProgressBar progress; + private TextView feedback; // Fields that are accessed from background threads must be volatile @Inject @@ -95,6 +95,7 @@ public class CreateForumActivity extends BriarActivity createForumButton.setEnabled(validateName()); } + @Override public boolean onEditorAction(TextView textView, int actionId, KeyEvent e) { hideSoftKeyboard(textView); return true; @@ -111,6 +112,7 @@ public class CreateForumActivity extends BriarActivity return length > 0; } + @Override public void onClick(View view) { if (view == createForumButton) { hideSoftKeyboard(view); @@ -123,6 +125,7 @@ public class CreateForumActivity extends BriarActivity private void storeForum(final String name) { runOnDbThread(new Runnable() { + @Override public void run() { try { long now = System.currentTimeMillis(); @@ -143,6 +146,7 @@ public class CreateForumActivity extends BriarActivity private void displayForum(final Forum f) { runOnUiThread(new Runnable() { + @Override public void run() { Intent i = new Intent(CreateForumActivity.this, ForumActivity.class); diff --git a/briar-android/src/org/briarproject/android/forum/ForumListAdapter.java b/briar-android/src/org/briarproject/android/forum/ForumListAdapter.java index 7eb5dc3eab4d9d8af69e30a7c1f09fd56583dcf8..9054bed9bfb39d0e4fc13549ecbaae56fdf3e83b 100644 --- a/briar-android/src/org/briarproject/android/forum/ForumListAdapter.java +++ b/briar-android/src/org/briarproject/android/forum/ForumListAdapter.java @@ -26,6 +26,7 @@ public class ForumListAdapter extends private SortedList<ForumListItem> forums = new SortedList<>( ForumListItem.class, new SortedList.Callback<ForumListItem>() { + @Override public int compare(ForumListItem a, ForumListItem b) { if (a == b) return 0; @@ -71,6 +72,7 @@ public class ForumListAdapter extends return a.getForum().equals(b.getForum()); } }); + private final Context ctx; public ForumListAdapter(Context ctx) { @@ -78,11 +80,9 @@ public class ForumListAdapter extends } @Override - public ForumViewHolder onCreateViewHolder(ViewGroup parent, - int viewType) { - - View v = LayoutInflater.from(ctx) - .inflate(R.layout.list_item_forum, parent, false); + public ForumViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { + View v = LayoutInflater.from(ctx).inflate( + R.layout.list_item_forum, parent, false); return new ForumViewHolder(v); } @@ -175,10 +175,10 @@ public class ForumListAdapter extends protected static class ForumViewHolder extends RecyclerView.ViewHolder { - public final ViewGroup layout; - public final TextView name; - public final TextView unread; - public final TextView date; + private final ViewGroup layout; + private final TextView name; + private final TextView unread; + private final TextView date; public ForumViewHolder(View v) { super(v); @@ -189,5 +189,4 @@ public class ForumListAdapter extends date = (TextView) v.findViewById(R.id.dateView); } } - } diff --git a/briar-android/src/org/briarproject/android/forum/ForumListFragment.java b/briar-android/src/org/briarproject/android/forum/ForumListFragment.java index 0129990936a525b30ee901014cec39cb06faa345..1f35e55f0560de75c3ca3f44847e859e4623c013 100644 --- a/briar-android/src/org/briarproject/android/forum/ForumListFragment.java +++ b/briar-android/src/org/briarproject/android/forum/ForumListFragment.java @@ -134,6 +134,7 @@ public class ForumListFragment extends BaseEventFragment implements private void loadForumHeaders() { listener.runOnDbThread(new Runnable() { + @Override public void run() { try { // load forums @@ -162,6 +163,7 @@ public class ForumListFragment extends BaseEventFragment implements private void displayForumHeaders(final Collection<ForumListItem> forums) { listener.runOnUiThread(new Runnable() { + @Override public void run() { if (forums.size() > 0) adapter.addAll(forums); else list.showData(); @@ -171,6 +173,7 @@ public class ForumListFragment extends BaseEventFragment implements private void loadAvailableForums() { listener.runOnDbThread(new Runnable() { + @Override public void run() { try { long now = System.currentTimeMillis(); @@ -190,6 +193,7 @@ public class ForumListFragment extends BaseEventFragment implements private void displayAvailableForums(final int availableCount) { listener.runOnUiThread(new Runnable() { + @Override public void run() { if (availableCount == 0) { snackbar.dismiss(); @@ -203,6 +207,7 @@ public class ForumListFragment extends BaseEventFragment implements }); } + @Override public void eventOccurred(Event e) { if (e instanceof ContactRemovedEvent) { LOG.info("Contact removed, reloading available forums"); @@ -235,6 +240,7 @@ public class ForumListFragment extends BaseEventFragment implements private void loadForumHeaders(final GroupId g) { listener.runOnDbThread(new Runnable() { + @Override public void run() { try { long now = System.currentTimeMillis(); @@ -272,9 +278,9 @@ public class ForumListFragment extends BaseEventFragment implements }); } + @Override public void onClick(View view) { // snackbar click startActivity(new Intent(getContext(), AvailableForumsActivity.class)); } - } diff --git a/briar-android/src/org/briarproject/android/forum/SelectableContactListItem.java b/briar-android/src/org/briarproject/android/forum/SelectableContactListItem.java index 6b9116ca41a8b2feb935fe0b7e7c123a075376c3..fa5ad2284f0852d98ec3460f87c5018f72d8e06b 100644 --- a/briar-android/src/org/briarproject/android/forum/SelectableContactListItem.java +++ b/briar-android/src/org/briarproject/android/forum/SelectableContactListItem.java @@ -16,7 +16,8 @@ public class SelectableContactListItem extends ContactListItem { public SelectableContactListItem(Contact contact, LocalAuthor localAuthor, GroupId groupId, boolean selected, boolean disabled) { - super(contact, localAuthor, false, groupId, Collections.<ConversationItem>emptyList()); + super(contact, localAuthor, false, groupId, + Collections.<ConversationItem>emptyList()); this.selected = selected; this.disabled = disabled; @@ -37,5 +38,4 @@ public class SelectableContactListItem extends ContactListItem { public boolean isDisabled() { return disabled; } - } diff --git a/briar-android/src/org/briarproject/android/forum/ShareForumMessageFragment.java b/briar-android/src/org/briarproject/android/forum/ShareForumMessageFragment.java index ab2586666e9df61356badaec563bac9c78c5e23f..d88c33d548a6a2bf67bc874e8266fc1840a0596d 100644 --- a/briar-android/src/org/briarproject/android/forum/ShareForumMessageFragment.java +++ b/briar-android/src/org/briarproject/android/forum/ShareForumMessageFragment.java @@ -9,7 +9,6 @@ import android.view.View; import android.view.ViewGroup; import android.widget.Button; import android.widget.EditText; -import android.widget.TextView; import android.widget.Toast; import org.briarproject.R; @@ -25,6 +24,7 @@ import java.util.logging.Logger; import javax.inject.Inject; +import static android.widget.Toast.LENGTH_SHORT; import static java.util.logging.Level.WARNING; import static org.briarproject.android.forum.ShareForumActivity.CONTACTS; import static org.briarproject.android.forum.ShareForumActivity.getContactsFromIds; @@ -32,15 +32,17 @@ import static org.briarproject.api.forum.ForumConstants.GROUP_ID; public class ShareForumMessageFragment extends BaseFragment { + public final static String TAG = "IntroductionMessageFragment"; + private static final Logger LOG = Logger.getLogger(ShareForumMessageFragment.class.getName()); - public final static String TAG = "IntroductionMessageFragment"; private ShareForumActivity shareForumActivity; private ViewHolder ui; // Fields that are accessed from background threads must be volatile - @Inject protected volatile ForumSharingManager forumSharingManager; + @Inject + protected volatile ForumSharingManager forumSharingManager; private volatile GroupId groupId; private volatile Collection<ContactId> contacts; @@ -81,9 +83,8 @@ public class ShareForumMessageFragment extends BaseFragment { setHasOptionsMenu(true); // inflate view - View v = - inflater.inflate(R.layout.share_forum_message, container, - false); + View v = inflater.inflate(R.layout.share_forum_message, container, + false); ui = new ViewHolder(v); ui.button.setOnClickListener(new View.OnClickListener() { @Override @@ -131,11 +132,12 @@ public class ShareForumMessageFragment extends BaseFragment { private void shareForum(final String msg) { shareForumActivity.runOnDbThread(new Runnable() { + @Override public void run() { try { for (ContactId c : contacts) { - forumSharingManager - .sendForumInvitation(groupId, c, msg); + forumSharingManager.sendForumInvitation(groupId, c, + msg); } } catch (DbException e) { sharingError(); @@ -148,21 +150,20 @@ public class ShareForumMessageFragment extends BaseFragment { private void sharingError() { shareForumActivity.runOnUiThread(new Runnable() { + @Override public void run() { Toast.makeText(shareForumActivity, - R.string.introduction_error, Toast.LENGTH_SHORT) - .show(); + R.string.introduction_error, LENGTH_SHORT).show(); } }); } private static class ViewHolder { - final private TextView text; - final private EditText message; - final private Button button; + + private final EditText message; + private final Button button; ViewHolder(View v) { - text = (TextView) v.findViewById(R.id.introductionText); message = (EditText) v.findViewById(R.id.invitationMessageView); button = (Button) v.findViewById(R.id.shareForumButton); } diff --git a/briar-android/src/org/briarproject/android/fragment/BaseFragment.java b/briar-android/src/org/briarproject/android/fragment/BaseFragment.java index 96efaad58c2a7201c795daefaf66d3dd326d2ba1..cb0c69c93f682980593c75c9b3ff7c6b5f42236a 100644 --- a/briar-android/src/org/briarproject/android/fragment/BaseFragment.java +++ b/briar-android/src/org/briarproject/android/fragment/BaseFragment.java @@ -6,10 +6,10 @@ import android.support.v4.app.Fragment; public abstract class BaseFragment extends Fragment { - public abstract String getUniqueTag(); - protected BaseFragmentListener listener; + public abstract String getUniqueTag(); + @Override public void onAttach(Context context) { super.onAttach(context); @@ -27,6 +27,7 @@ public abstract class BaseFragment extends Fragment { } public interface BaseFragmentListener { + void showLoadingScreen(boolean isBlocking, int stringId); void hideLoadingScreen(); @@ -35,5 +36,4 @@ public abstract class BaseFragment extends Fragment { void runOnDbThread(Runnable runnable); } - } diff --git a/briar-android/src/org/briarproject/android/identity/CreateIdentityActivity.java b/briar-android/src/org/briarproject/android/identity/CreateIdentityActivity.java index b95ca581fcb5879bc198e345f0f25c07c2d8e53a..0a9ca9d76dd7cdb9622b44833409d1075200cebb 100644 --- a/briar-android/src/org/briarproject/android/identity/CreateIdentityActivity.java +++ b/briar-android/src/org/briarproject/android/identity/CreateIdentityActivity.java @@ -15,7 +15,6 @@ import android.widget.Toast; import org.briarproject.R; import org.briarproject.android.ActivityComponent; -import org.briarproject.android.AndroidComponent; import org.briarproject.android.BriarActivity; import org.briarproject.android.util.LayoutUtils; import org.briarproject.api.crypto.CryptoComponent; @@ -47,21 +46,27 @@ import static org.briarproject.android.util.CommonLayoutParams.WRAP_WRAP; import static org.briarproject.api.identity.AuthorConstants.MAX_AUTHOR_NAME_LENGTH; public class CreateIdentityActivity extends BriarActivity -implements OnEditorActionListener, OnClickListener { + implements OnEditorActionListener, OnClickListener { private static final Logger LOG = Logger.getLogger(CreateIdentityActivity.class.getName()); - @Inject @CryptoExecutor protected Executor cryptoExecutor; - private EditText nicknameEntry = null; - private Button createIdentityButton = null; - private ProgressBar progress = null; - private TextView feedback = null; + @Inject + @CryptoExecutor + protected Executor cryptoExecutor; + + private EditText nicknameEntry; + private Button createIdentityButton; + private ProgressBar progress; + private TextView feedback; // Fields that are accessed from background threads must be volatile - @Inject protected volatile CryptoComponent crypto; - @Inject protected volatile AuthorFactory authorFactory; - @Inject protected volatile IdentityManager identityManager; + @Inject + protected volatile CryptoComponent crypto; + @Inject + protected volatile AuthorFactory authorFactory; + @Inject + protected volatile IdentityManager identityManager; @Override public void onCreate(Bundle state) { @@ -124,6 +129,7 @@ implements OnEditorActionListener, OnClickListener { createIdentityButton.setEnabled(validateNickname()); } + @Override public boolean onEditorAction(TextView textView, int actionId, KeyEvent e) { hideSoftKeyboard(textView); return true; @@ -140,6 +146,7 @@ implements OnEditorActionListener, OnClickListener { return length > 0; } + @Override public void onClick(View view) { hideSoftKeyboard(view); if (!validateNickname()) return; @@ -149,6 +156,7 @@ implements OnEditorActionListener, OnClickListener { // Create the identity in a background thread final String nickname = nicknameEntry.getText().toString(); cryptoExecutor.execute(new Runnable() { + @Override public void run() { KeyPair keyPair = crypto.generateSignatureKeyPair(); final byte[] publicKey = keyPair.getPublic().getEncoded(); @@ -162,6 +170,7 @@ implements OnEditorActionListener, OnClickListener { private void storeLocalAuthor(final LocalAuthor a) { runOnDbThread(new Runnable() { + @Override public void run() { try { long now = System.currentTimeMillis(); @@ -180,6 +189,7 @@ implements OnEditorActionListener, OnClickListener { private void setResultAndFinish(final LocalAuthor a) { runOnUiThread(new Runnable() { + @Override public void run() { Intent i = new Intent(); i.putExtra("briar.LOCAL_AUTHOR_ID", a.getId().getBytes()); diff --git a/briar-android/src/org/briarproject/android/introduction/ContactChooserAdapter.java b/briar-android/src/org/briarproject/android/introduction/ContactChooserAdapter.java index 8c96163be0b83801984df47842b8513a60336cf2..cdb20408b8f71bbc68d2d9004276845038b0ddbb 100644 --- a/briar-android/src/org/briarproject/android/introduction/ContactChooserAdapter.java +++ b/briar-android/src/org/briarproject/android/introduction/ContactChooserAdapter.java @@ -55,7 +55,7 @@ public class ContactChooserAdapter extends ContactListAdapter { } private void grayOutItem(final ContactHolder ui) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { + if (Build.VERSION.SDK_INT >= 11) { float alpha = 0.25f; ui.bulb.setAlpha(alpha); ui.avatar.setAlpha(alpha); diff --git a/briar-android/src/org/briarproject/android/introduction/ContactChooserFragment.java b/briar-android/src/org/briarproject/android/introduction/ContactChooserFragment.java index 7b1bcbb5cb90c6465841adf142e066ee8119e3e3..2a2bd5143b60c7c8572bfa28bb525e90b7ba1d18 100644 --- a/briar-android/src/org/briarproject/android/introduction/ContactChooserFragment.java +++ b/briar-android/src/org/briarproject/android/introduction/ContactChooserFragment.java @@ -44,14 +44,15 @@ import static java.util.logging.Level.WARNING; public class ContactChooserFragment extends BaseFragment { public final static String TAG = "ContactChooserFragment"; + + private static final Logger LOG = + Logger.getLogger(ContactChooserFragment.class.getName()); + private IntroductionActivity introductionActivity; private BriarRecyclerView list; private ContactChooserAdapter adapter; private int contactId; - private static final Logger LOG = - Logger.getLogger(ContactChooserFragment.class.getName()); - // Fields that are accessed from background threads must be volatile protected volatile Contact c1; @Inject @@ -76,7 +77,7 @@ public class ContactChooserFragment extends BaseFragment { try { introductionActivity = (IntroductionActivity) context; } catch (ClassCastException e) { - throw new java.lang.InstantiationError( + throw new InstantiationError( "This fragment is only meant to be attached to the IntroductionActivity"); } } @@ -90,7 +91,7 @@ public class ContactChooserFragment extends BaseFragment { container, false); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + if (Build.VERSION.SDK_INT >= 21) { setExitTransition(new Fade()); } @@ -99,14 +100,15 @@ public class ContactChooserFragment extends BaseFragment { @Override public void onItemClick(View view, ContactListItem item) { if (c1 == null) { - throw new RuntimeException("c1 not initialized"); + throw new RuntimeException("c1 not accountExists"); } Contact c2 = item.getContact(); if (!c1.getLocalAuthorId() .equals(c2.getLocalAuthorId())) { warnAboutDifferentIdentities(view, c1, c2); } else { - introductionActivity.showMessageScreen(view, c1, c2); + introductionActivity.showMessageScreen(view, c1, + c2); } } }; @@ -142,11 +144,11 @@ public class ContactChooserFragment extends BaseFragment { private void loadContacts() { introductionActivity.runOnDbThread(new Runnable() { + @Override public void run() { try { - List<ContactListItem> contacts = - new ArrayList<ContactListItem>(); - AuthorId localAuthorId= null; + List<ContactListItem> contacts = new ArrayList<>(); + AuthorId localAuthorId = null; for (Contact c : contactManager.getActiveContacts()) { if (c.getId().getInt() == contactId) { c1 = c; @@ -177,6 +179,7 @@ public class ContactChooserFragment extends BaseFragment { private void displayContacts(final AuthorId localAuthorId, final List<ContactListItem> contacts) { introductionActivity.runOnUiThread(new Runnable() { + @Override public void run() { adapter.setLocalAuthor(localAuthorId); if (contacts.size() == 0) list.showData(); @@ -206,14 +209,15 @@ public class ContactChooserFragment extends BaseFragment { builder.show(); } - /** This needs to be called from the DbThread */ + /** + * This needs to be called from the DbThread + */ private Collection<ConversationItem> getMessages(ContactId id) throws DbException { long now = System.currentTimeMillis(); - Collection<ConversationItem> messages = - new ArrayList<ConversationItem>(); + Collection<ConversationItem> messages = new ArrayList<>(); Collection<PrivateMessageHeader> headers = messagingManager.getMessageHeaders(id); @@ -237,5 +241,4 @@ public class ContactChooserFragment extends BaseFragment { return messages; } - } diff --git a/briar-android/src/org/briarproject/android/introduction/IntroductionActivity.java b/briar-android/src/org/briarproject/android/introduction/IntroductionActivity.java index 79d511291f0065a8db188f480b819e7a373116e3..5c00e2562888ac2af45ec9dc2406e3c59a338b99 100644 --- a/briar-android/src/org/briarproject/android/introduction/IntroductionActivity.java +++ b/briar-android/src/org/briarproject/android/introduction/IntroductionActivity.java @@ -3,7 +3,6 @@ package org.briarproject.android.introduction; import android.content.Intent; import android.os.Build; import android.os.Bundle; -import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import android.transition.ChangeBounds; import android.transition.Fade; @@ -20,6 +19,7 @@ public class IntroductionActivity extends BriarActivity implements BaseFragment.BaseFragmentListener { public static final String CONTACT_ID = "briar.CONTACT_ID"; + private int contactId; @Override @@ -34,7 +34,8 @@ public class IntroductionActivity extends BriarActivity implements setContentView(R.layout.activity_introduction); if (savedInstanceState == null) { - getSupportFragmentManager().beginTransaction() + getSupportFragmentManager() + .beginTransaction() .add(R.id.introductionContainer, activityComponent.newContactChooserFragment()) .commit(); @@ -82,21 +83,21 @@ public class IntroductionActivity extends BriarActivity implements return contactId; } - public void showMessageScreen(final View view, final Contact c1, - final Contact c2) { + public void showMessageScreen(View view, Contact c1, Contact c2) { IntroductionMessageFragment messageFragment = activityComponent.newIntroductionMessageFragment(); messageFragment.initBundle(c1.getId().getInt(), c2.getId().getInt()); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + if (Build.VERSION.SDK_INT >= 21) { messageFragment.setSharedElementEnterTransition(new ChangeBounds()); messageFragment.setEnterTransition(new Fade()); - messageFragment - .setSharedElementReturnTransition(new ChangeBounds()); + messageFragment.setSharedElementReturnTransition( + new ChangeBounds()); } - getSupportFragmentManager().beginTransaction() + getSupportFragmentManager() + .beginTransaction() .setCustomAnimations(android.R.anim.fade_in, android.R.anim.fade_out, android.R.anim.slide_in_left, @@ -107,5 +108,4 @@ public class IntroductionActivity extends BriarActivity implements .addToBackStack(null) .commit(); } - } diff --git a/briar-android/src/org/briarproject/android/introduction/IntroductionMessageFragment.java b/briar-android/src/org/briarproject/android/introduction/IntroductionMessageFragment.java index 48f0726c086d49de467bacbb17a9ff3ec483ea6e..93b7c6c070412e86891e67099eff3f58d87125e6 100644 --- a/briar-android/src/org/briarproject/android/introduction/IntroductionMessageFragment.java +++ b/briar-android/src/org/briarproject/android/introduction/IntroductionMessageFragment.java @@ -28,20 +28,23 @@ import javax.inject.Inject; import de.hdodenhof.circleimageview.CircleImageView; import im.delight.android.identicons.IdenticonDrawable; +import static android.view.View.GONE; +import static android.view.View.VISIBLE; +import static android.widget.Toast.LENGTH_SHORT; import static java.util.logging.Level.WARNING; public class IntroductionMessageFragment extends BaseFragment { + public final static String TAG = "IntroductionMessageFragment"; + + private final static String CONTACT_ID_1 = "contact1"; + private final static String CONTACT_ID_2 = "contact2"; private static final Logger LOG = Logger.getLogger(IntroductionMessageFragment.class.getName()); - public final static String TAG = "IntroductionMessageFragment"; private IntroductionActivity introductionActivity; private ViewHolder ui; - private final static String CONTACT_ID_1 = "contact1"; - private final static String CONTACT_ID_2 = "contact2"; - // Fields that are accessed from background threads must be volatile @Inject protected volatile ContactManager contactManager; @@ -83,13 +86,12 @@ public class IntroductionMessageFragment extends BaseFragment { } // inflate view - View v = - inflater.inflate(R.layout.introduction_message, container, - false); + View v = inflater.inflate(R.layout.introduction_message, container, + false); // show progress bar until contacts have been loaded ui = new ViewHolder(v); - ui.text.setVisibility(View.GONE); + ui.text.setVisibility(GONE); ui.button.setEnabled(false); // get contact IDs from fragment arguments @@ -114,12 +116,13 @@ public class IntroductionMessageFragment extends BaseFragment { private void prepareToSetUpViews(final int contactId1, final int contactId2) { introductionActivity.runOnDbThread(new Runnable() { + @Override public void run() { try { - Contact c1 = contactManager - .getContact(new ContactId(contactId1)); - Contact c2 = contactManager - .getContact(new ContactId(contactId2)); + Contact c1 = contactManager.getContact( + new ContactId(contactId1)); + Contact c2 = contactManager.getContact( + new ContactId(contactId2)); setUpViews(c1, c2); } catch (DbException e) { if (LOG.isLoggable(WARNING)) @@ -131,6 +134,7 @@ public class IntroductionMessageFragment extends BaseFragment { private void setUpViews(final Contact c1, final Contact c2) { introductionActivity.runOnUiThread(new Runnable() { + @Override public void run() { // set avatars ui.avatar1.setImageDrawable(new IdenticonDrawable( @@ -152,8 +156,8 @@ public class IntroductionMessageFragment extends BaseFragment { }); // hide progress bar and show views - ui.progressBar.setVisibility(View.GONE); - ui.text.setVisibility(View.VISIBLE); + ui.progressBar.setVisibility(GONE); + ui.text.setVisibility(VISIBLE); ui.button.setEnabled(true); } }); @@ -174,17 +178,14 @@ public class IntroductionMessageFragment extends BaseFragment { private void makeIntroduction(final Contact c1, final Contact c2, final String msg) { introductionActivity.runOnDbThread(new Runnable() { + @Override public void run() { // actually make the introduction try { long timestamp = System.currentTimeMillis(); - introductionManager - .makeIntroduction(c1, c2, msg, timestamp); - } catch (DbException e) { - if (LOG.isLoggable(WARNING)) - LOG.log(WARNING, e.toString(), e); - introductionError(); - } catch (FormatException e) { + introductionManager.makeIntroduction(c1, c2, msg, + timestamp); + } catch (DbException | FormatException e) { if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e); introductionError(); @@ -195,26 +196,24 @@ public class IntroductionMessageFragment extends BaseFragment { private void introductionError() { introductionActivity.runOnUiThread(new Runnable() { + @Override public void run() { Toast.makeText(introductionActivity, - R.string.introduction_error, Toast.LENGTH_SHORT) - .show(); + R.string.introduction_error, LENGTH_SHORT).show(); } }); } private static class ViewHolder { - ProgressBar progressBar; - ViewGroup header; - CircleImageView avatar1; - CircleImageView avatar2; - TextView text; - EditText message; - Button button; + + private final ProgressBar progressBar; + private final CircleImageView avatar1, avatar2; + private final TextView text; + private final EditText message; + private final Button button; ViewHolder(View v) { progressBar = (ProgressBar) v.findViewById(R.id.progressBar); - header = (ViewGroup) v.findViewById(R.id.introductionHeader); avatar1 = (CircleImageView) v.findViewById(R.id.avatarContact1); avatar2 = (CircleImageView) v.findViewById(R.id.avatarContact2); text = (TextView) v.findViewById(R.id.introductionText); diff --git a/briar-android/src/org/briarproject/android/keyagreement/ChooseIdentityFragment.java b/briar-android/src/org/briarproject/android/keyagreement/ChooseIdentityFragment.java index 40206766ed660e72b846596dd34cc57c8493aa55..c74b0a366bdebeaefef12364bda30672c0ad766c 100644 --- a/briar-android/src/org/briarproject/android/keyagreement/ChooseIdentityFragment.java +++ b/briar-android/src/org/briarproject/android/keyagreement/ChooseIdentityFragment.java @@ -13,8 +13,6 @@ import android.widget.AdapterView.OnItemSelectedListener; import android.widget.Spinner; import org.briarproject.R; -import org.briarproject.android.ActivityComponent; -import org.briarproject.android.AndroidComponent; import org.briarproject.android.fragment.BaseFragment; import org.briarproject.android.identity.CreateIdentityActivity; import org.briarproject.android.identity.LocalAuthorItem; @@ -42,18 +40,17 @@ public class ChooseIdentityFragment extends BaseFragment void identitySelected(AuthorId localAuthorId); } + public static final String TAG = "ChooseIdentityFragment"; + private static final Logger LOG = Logger.getLogger(ChooseIdentityFragment.class.getName()); - public static final String TAG = "ChooseIdentityFragment"; - private static final int REQUEST_CREATE_IDENTITY = 1; private IdentitySelectedListener lsnr; private LocalAuthorSpinnerAdapter adapter; private Spinner spinner; private View button; - private AuthorId localAuthorId; // Fields that are accessed from background threads must be volatile @@ -112,6 +109,7 @@ public class ChooseIdentityFragment extends BaseFragment private void loadLocalAuthors() { listener.runOnDbThread(new Runnable() { + @Override public void run() { try { long now = System.currentTimeMillis(); @@ -157,6 +155,7 @@ public class ChooseIdentityFragment extends BaseFragment button.setEnabled(localAuthorId != null); } + @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { LocalAuthorItem item = adapter.getItem(position); @@ -169,6 +168,7 @@ public class ChooseIdentityFragment extends BaseFragment } } + @Override public void onNothingSelected(AdapterView<?> parent) { setLocalAuthorId(null); } diff --git a/briar-android/src/org/briarproject/android/keyagreement/KeyAgreementActivity.java b/briar-android/src/org/briarproject/android/keyagreement/KeyAgreementActivity.java index b2395eaa2fe985529914fe17384c434361c6d711..40122d928a1cd928042c0334156dd1209e0140da 100644 --- a/briar-android/src/org/briarproject/android/keyagreement/KeyAgreementActivity.java +++ b/briar-android/src/org/briarproject/android/keyagreement/KeyAgreementActivity.java @@ -8,7 +8,6 @@ import android.widget.Toast; import org.briarproject.R; import org.briarproject.android.ActivityComponent; -import org.briarproject.android.AndroidComponent; import org.briarproject.android.BriarFragmentActivity; import org.briarproject.android.fragment.BaseFragment; import org.briarproject.android.util.CustomAnimations; @@ -24,7 +23,6 @@ import org.briarproject.api.identity.AuthorId; import org.briarproject.api.identity.IdentityManager; import org.briarproject.api.identity.LocalAuthor; import org.briarproject.api.keyagreement.KeyAgreementResult; -import org.briarproject.api.settings.SettingsManager; import java.util.logging.Logger; @@ -49,8 +47,6 @@ public class KeyAgreementActivity extends BriarFragmentActivity implements @Inject protected EventBus eventBus; - @Inject - protected SettingsManager settingsManager; private Toolbar toolbar; private View progressContainer; @@ -58,6 +54,7 @@ public class KeyAgreementActivity extends BriarFragmentActivity implements private AuthorId localAuthorId; + // Fields that are accessed from background threads must be volatile @Inject protected volatile ContactExchangeTask contactExchangeTask; @Inject @@ -193,6 +190,7 @@ public class KeyAgreementActivity extends BriarFragmentActivity implements @Override public void contactExchangeSucceeded(final Author remoteAuthor) { runOnUiThread(new Runnable() { + @Override public void run() { String contactName = remoteAuthor.getName(); String format = getString(R.string.contact_added_toast); @@ -207,6 +205,7 @@ public class KeyAgreementActivity extends BriarFragmentActivity implements @Override public void duplicateContact(final Author remoteAuthor) { runOnUiThread(new Runnable() { + @Override public void run() { String contactName = remoteAuthor.getName(); String format = getString(R.string.contact_already_exists); @@ -221,6 +220,7 @@ public class KeyAgreementActivity extends BriarFragmentActivity implements @Override public void contactExchangeFailed() { runOnUiThread(new Runnable() { + @Override public void run() { Toast.makeText(KeyAgreementActivity.this, R.string.contact_exchange_failed, LENGTH_LONG).show(); diff --git a/briar-android/src/org/briarproject/android/keyagreement/ShowQrCodeFragment.java b/briar-android/src/org/briarproject/android/keyagreement/ShowQrCodeFragment.java index 8a997168d94403c77ad8395fef40d11b1af9f1d4..60c7ca85bd794414fa1dd27d2b0ddce1fe455a66 100644 --- a/briar-android/src/org/briarproject/android/keyagreement/ShowQrCodeFragment.java +++ b/briar-android/src/org/briarproject/android/keyagreement/ShowQrCodeFragment.java @@ -57,11 +57,11 @@ import static java.util.logging.Level.WARNING; public class ShowQrCodeFragment extends BaseEventFragment implements QrCodeDecoder.ResultCallback { + public static final String TAG = "ShowQrCodeFragment"; + private static final Logger LOG = Logger.getLogger(ShowQrCodeFragment.class.getName()); - public static final String TAG = "ShowQrCodeFragment"; - @Inject protected KeyAgreementTaskFactory keyAgreementTaskFactory; @Inject @@ -138,6 +138,7 @@ public class ShowQrCodeFragment extends BaseEventFragment if (adapter != null && !adapter.isEnabled()) { waitingForBluetooth = true; androidExecutor.execute(new Runnable() { + @Override public void run() { adapter.enable(); } @@ -342,6 +343,7 @@ public class ShowQrCodeFragment extends BaseEventFragment @Override public void handleResult(final Result result) { listener.runOnUiThread(new Runnable() { + @Override public void run() { LOG.info("Got result from decoder"); if (!gotRemotePayload) { diff --git a/briar-android/src/org/briarproject/android/panic/ExitActivity.java b/briar-android/src/org/briarproject/android/panic/ExitActivity.java index 7e85402018ee18a2c7bb901439cea1dfa7a5337f..363270f26fd167cc9dc0c62b3fcf126366dee291 100644 --- a/briar-android/src/org/briarproject/android/panic/ExitActivity.java +++ b/briar-android/src/org/briarproject/android/panic/ExitActivity.java @@ -4,7 +4,6 @@ import android.os.Build; import android.os.Bundle; import org.briarproject.android.ActivityComponent; -import org.briarproject.android.AndroidComponent; import org.briarproject.android.BaseActivity; import java.util.logging.Logger; diff --git a/briar-android/src/org/briarproject/android/panic/PanicPreferencesActivity.java b/briar-android/src/org/briarproject/android/panic/PanicPreferencesActivity.java index f0645f3c2ed495066ab7d0b67cb536fc8f2c4e3e..7fbd2ff97a6c304ac68131cf1f6c7f3e72daba3a 100644 --- a/briar-android/src/org/briarproject/android/panic/PanicPreferencesActivity.java +++ b/briar-android/src/org/briarproject/android/panic/PanicPreferencesActivity.java @@ -6,7 +6,6 @@ import android.view.MenuItem; import org.briarproject.R; import org.briarproject.android.ActivityComponent; -import org.briarproject.android.AndroidComponent; import org.briarproject.android.BriarActivity; public class PanicPreferencesActivity extends BriarActivity { @@ -29,6 +28,7 @@ public class PanicPreferencesActivity extends BriarActivity { component.inject(this); } + @Override public boolean onOptionsItemSelected(MenuItem item) { if (item.getItemId() == android.R.id.home) { onBackPressed(); @@ -36,5 +36,4 @@ public class PanicPreferencesActivity extends BriarActivity { } return false; } - } diff --git a/briar-android/src/org/briarproject/android/panic/PanicResponderActivity.java b/briar-android/src/org/briarproject/android/panic/PanicResponderActivity.java index fbe549e6ee0cd1c17eca51d0da70966ec2373bf5..ff3ba954a7f0580b71cb196a020ce368f383287d 100644 --- a/briar-android/src/org/briarproject/android/panic/PanicResponderActivity.java +++ b/briar-android/src/org/briarproject/android/panic/PanicResponderActivity.java @@ -11,7 +11,6 @@ import org.briarproject.android.ActivityComponent; import org.briarproject.android.BriarActivity; import org.briarproject.android.api.AndroidExecutor; import org.briarproject.android.controller.ConfigController; -import org.briarproject.android.util.AndroidUtils; import org.iilab.IilabEngineeringRSA2048Pin; import java.util.logging.Logger; @@ -32,7 +31,9 @@ public class PanicResponderActivity extends BriarActivity { private static final Logger LOG = Logger.getLogger(PanicResponderActivity.class.getName()); - @Inject protected ConfigController configController; + + @Inject + protected ConfigController configController; @Inject protected AndroidExecutor androidExecutor; @@ -76,8 +77,6 @@ public class PanicResponderActivity extends BriarActivity { LOG.info("Signing out..."); signOut(true); } - - // TODO send a pre-defined message to certain contacts (#212) } // Performing non-destructive default panic response else if (sharedPref.getBoolean(KEY_LOCK, true)) { @@ -109,11 +108,10 @@ public class PanicResponderActivity extends BriarActivity { private void deleteAllData() { androidExecutor.execute(new Runnable() { + @Override public void run() { - configController.clearPrefs(); + configController.deleteAccount(PanicResponderActivity.this); // TODO somehow delete/shred the database more thoroughly - // TODO replace this static call with a controller method - AndroidUtils.deleteAppData(PanicResponderActivity.this); PanicResponder.deleteAllAppData(PanicResponderActivity.this); // nothing left to do after everything is deleted, diff --git a/briar-android/src/org/briarproject/android/util/CustomAnimations.java b/briar-android/src/org/briarproject/android/util/CustomAnimations.java index 78987efe6de3addfa83f4acfa10fc0bf5e93bb77..07dec13243138a1cec3ea150b6d84e4e85f66868 100644 --- a/briar-android/src/org/briarproject/android/util/CustomAnimations.java +++ b/briar-android/src/org/briarproject/android/util/CustomAnimations.java @@ -4,67 +4,61 @@ import android.animation.Animator; import android.animation.ValueAnimator; import android.annotation.SuppressLint; import android.os.Build; -import android.view.View; import android.view.ViewGroup; +import static android.view.View.GONE; +import static android.view.View.MeasureSpec.UNSPECIFIED; +import static android.view.View.VISIBLE; + public class CustomAnimations { - public static void animateHeight( - final ViewGroup viewGroup, final boolean isExtending, + public static void animateHeight(ViewGroup viewGroup, boolean isExtending, int duration) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { + if (Build.VERSION.SDK_INT >= 11) { animateHeightPostGingerbread(viewGroup, isExtending, duration); } else { - animateHeightGingerbread(viewGroup, isExtending, duration); + animateHeightGingerbread(viewGroup, isExtending); } } - private static void animateHeightGingerbread(final ViewGroup viewGroup, - final boolean isExtending, int duration) { + private static void animateHeightGingerbread(ViewGroup viewGroup, + boolean isExtending) { // No animations for Gingerbread - if (isExtending) { - viewGroup.setVisibility(View.VISIBLE); - } else { - viewGroup.setVisibility(View.GONE); - } + if (isExtending) viewGroup.setVisibility(VISIBLE); + else viewGroup.setVisibility(GONE); } @SuppressLint("NewApi") - private static void animateHeightPostGingerbread( - final ViewGroup viewGroup, - final boolean isExtending, - int duration) { + private static void animateHeightPostGingerbread(final ViewGroup viewGroup, + final boolean isExtending, int duration) { ValueAnimator anim; if (isExtending) { - viewGroup.setVisibility(View.VISIBLE); - viewGroup.measure(View.MeasureSpec.UNSPECIFIED, - View.MeasureSpec.UNSPECIFIED); + viewGroup.setVisibility(VISIBLE); + viewGroup.measure(UNSPECIFIED, UNSPECIFIED); anim = ValueAnimator.ofInt(0, viewGroup.getMeasuredHeight()); } else { anim = ValueAnimator.ofInt(viewGroup.getHeight(), 0); } anim.addListener(new Animator.AnimatorListener() { + @Override public void onAnimationStart(Animator animation) { - } @Override public void onAnimationEnd(Animator animation) { if (!isExtending) { - viewGroup.setVisibility(View.GONE); + viewGroup.setVisibility(GONE); } } @Override public void onAnimationCancel(Animator animation) { - } @Override public void onAnimationRepeat(Animator animation) { - } }); anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @@ -76,7 +70,6 @@ public class CustomAnimations { layoutParams.height = val; viewGroup.setLayoutParams(layoutParams); } - }); anim.setDuration(duration); anim.start(); diff --git a/briar-android/src/org/briarproject/system/AndroidSeedProvider.java b/briar-android/src/org/briarproject/system/AndroidSeedProvider.java index 59c7a6e3a5bc8f25d52d909c5a979af320f61409..ea40d43feff48db4de7445c77189a4269b75e51a 100644 --- a/briar-android/src/org/briarproject/system/AndroidSeedProvider.java +++ b/briar-android/src/org/briarproject/system/AndroidSeedProvider.java @@ -8,7 +8,6 @@ import android.provider.Settings; import java.io.DataOutputStream; import java.io.IOException; -import java.util.logging.Logger; import javax.inject.Inject; @@ -16,9 +15,6 @@ import static android.provider.Settings.Secure.ANDROID_ID; class AndroidSeedProvider extends LinuxSeedProvider { - private static final Logger LOG = - Logger.getLogger(LinuxSeedProvider.class.getName()); - private final Context appContext; @Inject @@ -34,10 +30,8 @@ class AndroidSeedProvider extends LinuxSeedProvider { if (Build.FINGERPRINT != null) out.writeUTF(Build.FINGERPRINT); if (Build.SERIAL != null) out.writeUTF(Build.SERIAL); ContentResolver contentResolver = appContext.getContentResolver(); - String str = Settings.Secure.getString(contentResolver, ANDROID_ID); - if (str != null) { - out.writeUTF(str); - } + String id = Settings.Secure.getString(contentResolver, ANDROID_ID); + if (id != null) out.writeUTF(id); super.writeToEntropyPool(out); } } diff --git a/briar-android/test/java/briarproject/activity/SetupActivityTest.java b/briar-android/test/java/briarproject/activity/SetupActivityTest.java index b58d033b25b53394602b52d00dd4836242a10717..ebd1120b2b24588ee10435123cde220fe24015da 100644 --- a/briar-android/test/java/briarproject/activity/SetupActivityTest.java +++ b/briar-android/test/java/briarproject/activity/SetupActivityTest.java @@ -48,23 +48,23 @@ import static org.robolectric.Shadows.shadowOf; @RunWith(RobolectricGradleTestRunner.class) @Config(constants = BuildConfig.class, sdk = 21, - application = TestBriarApplicationImp.class) + application = TestBriarApplication.class) public class SetupActivityTest { - TestSetupActivity setupActivity; - TextInputLayout nicknameEntryWrapper; - TextInputLayout passwordEntryWrapper; - TextInputLayout passwordConfirmationWrapper; - EditText nicknameEntry; - EditText passwordEntry; - EditText passwordConfirmation; - StrengthMeter strengthMeter; - Button createAccountButton; + private TestSetupActivity setupActivity; + private TextInputLayout nicknameEntryWrapper; + private TextInputLayout passwordEntryWrapper; + private TextInputLayout passwordConfirmationWrapper; + private EditText nicknameEntry; + private EditText passwordEntry; + private EditText passwordConfirmation; + private StrengthMeter strengthMeter; + private Button createAccountButton; @Mock - SetupController setupController; + private SetupController setupController; @Captor - ArgumentCaptor<ResultHandler<Long>> resultCaptor; + private ArgumentCaptor<ResultHandler<Long>> resultCaptor; @Before public void setUp() { @@ -225,5 +225,4 @@ public class SetupActivityTest { Mockito.verify(mockedController, Mockito.times(1)) .estimatePasswordStrength(eq("empty")); } - } diff --git a/briar-android/test/java/briarproject/activity/TestBriarApplicationImp.java b/briar-android/test/java/briarproject/activity/TestBriarApplication.java similarity index 81% rename from briar-android/test/java/briarproject/activity/TestBriarApplicationImp.java rename to briar-android/test/java/briarproject/activity/TestBriarApplication.java index 8e29d9efd238946a641c836aec944196f7ddd97c..9da4a6fe3a5a528a1a4a0bbd8f6a80725087891c 100644 --- a/briar-android/test/java/briarproject/activity/TestBriarApplicationImp.java +++ b/briar-android/test/java/briarproject/activity/TestBriarApplication.java @@ -12,13 +12,13 @@ import org.briarproject.android.DaggerAndroidComponent; import java.util.logging.Logger; /** - * This Class only exists to get around ACRA + * This class only exists to avoid static initialisation of ACRA */ -public class TestBriarApplicationImp extends Application implements - BriarApplication{ +public class TestBriarApplication extends Application + implements BriarApplication { private static final Logger LOG = - Logger.getLogger(TestBriarApplicationImp.class.getName()); + Logger.getLogger(TestBriarApplication.class.getName()); private AndroidComponent applicationComponent; @@ -37,6 +37,7 @@ public class TestBriarApplicationImp extends Application implements AndroidEagerSingletons.initEagerSingletons(applicationComponent); } + @Override public AndroidComponent getApplicationComponent() { return applicationComponent; } diff --git a/briar-android/test/java/briarproject/activity/TestSetupActivity.java b/briar-android/test/java/briarproject/activity/TestSetupActivity.java index 923372a494b72a011757be7602cd457750b1d18a..2b4b9d6a1fbbf1b92ca65ebe76a92d4d79007f41 100644 --- a/briar-android/test/java/briarproject/activity/TestSetupActivity.java +++ b/briar-android/test/java/briarproject/activity/TestSetupActivity.java @@ -10,11 +10,10 @@ import org.briarproject.android.controller.SetupController; public class TestSetupActivity extends SetupActivity { public SetupController getController() { - return this.setupController; + return setupController; } public void setController(SetupController setupController) { this.setupController = setupController; } - }