Merge branch '184-background-threads' into 'master'

Do Bluetooth Adapter enabling/disabling in background thread

Also set the default preferences in a background thread when app starts.

Closes #184

See merge request !66
This commit is contained in:
akwizgran
2016-01-19 15:16:49 +00:00
4 changed files with 29 additions and 5 deletions

View File

@@ -17,6 +17,7 @@ import android.widget.TextView;
import org.briarproject.R;
import org.briarproject.android.panic.PanicPreferencesActivity;
import org.briarproject.android.util.AndroidUtils;
import org.briarproject.android.util.FixedVerticalSpace;
import org.briarproject.android.util.HorizontalBorder;
import org.briarproject.android.util.LayoutUtils;
@@ -330,8 +331,7 @@ OnClickListener {
bluetoothSetting = !bluetoothSetting;
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
if (adapter != null) {
if (bluetoothSetting) adapter.enable();
else adapter.disable();
AndroidUtils.setBluetooth(adapter, bluetoothSetting);
}
storeBluetoothSetting();
displaySettings();

View File

@@ -65,8 +65,7 @@ public class SplashScreenActivity extends RoboSplashActivity {
logo.setImageResource(R.drawable.briar_logo_large);
layout.addView(logo);
PreferenceManager
.setDefaultValues(this, R.xml.panic_preferences, false);
setPreferencesDefaults();
setContentView(layout);
}
@@ -111,4 +110,15 @@ public class SplashScreenActivity extends RoboSplashActivity {
if (f.isFile()) f.delete();
else if (f.isDirectory()) for (File child : f.listFiles()) delete(child);
}
private void setPreferencesDefaults() {
new Thread() {
@Override
public void run() {
PreferenceManager
.setDefaultValues(SplashScreenActivity.this,
R.xml.panic_preferences, false);
}
}.start();
}
}

View File

@@ -7,6 +7,7 @@ import android.widget.Toast;
import org.briarproject.R;
import org.briarproject.android.BriarActivity;
import org.briarproject.android.util.AndroidUtils;
import org.briarproject.api.TransportConfig;
import org.briarproject.api.TransportId;
import org.briarproject.api.android.ReferenceManager;
@@ -333,7 +334,7 @@ implements InvitationListener {
if (LOG.isLoggable(INFO)) LOG.info("Turning off Bluetooth again");
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
if (adapter != null) adapter.disable();
if (adapter != null) AndroidUtils.setBluetooth(adapter, false);
}
}

View File

@@ -1,6 +1,7 @@
package org.briarproject.android.util;
import android.annotation.SuppressLint;
import android.bluetooth.BluetoothAdapter;
import android.os.Build;
import android.support.design.widget.TextInputLayout;
@@ -32,4 +33,16 @@ public class AndroidUtils {
} else
til.setError(null);
}
public static void setBluetooth(final BluetoothAdapter adapter,
final boolean activate) {
new Thread() {
@Override
public void run() {
if (activate) adapter.enable();
else adapter.disable();
}
}.start();
}
}