mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 10:49:06 +01:00
Added a settings screen and a setting for activating Bluetooth. Bug #28.
This commit is contained in:
@@ -1,16 +1,16 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="org.briarproject"
|
||||
android:versionCode="2"
|
||||
android:versionName="0.2" >
|
||||
android:versionCode="4"
|
||||
android:versionName="0.4" >
|
||||
|
||||
<uses-sdk android:minSdkVersion="7" android:targetSdkVersion="19" />
|
||||
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
|
||||
<uses-permission android:name="android.permission.BLUETOOTH" />
|
||||
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
|
||||
<uses-permission android:name="android.permission.VIBRATE" />
|
||||
<!-- FIXME: Only needed for alpha and beta builds -->
|
||||
<uses-permission android:name="android.permission.READ_LOGS" />
|
||||
@@ -43,6 +43,16 @@
|
||||
android:logo="@drawable/logo"
|
||||
android:label="@string/app_name" >
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".android.SettingsActivity"
|
||||
android:logo="@drawable/logo"
|
||||
android:label="@string/settings_title"
|
||||
android:parentActivityName=".android.DashboardActivity" >
|
||||
<meta-data
|
||||
android:name="android.support.PARENT_ACTIVITY"
|
||||
android:value=".android.DashboardActivity"
|
||||
/>
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".android.SetupActivity"
|
||||
android:logo="@drawable/logo"
|
||||
@@ -63,10 +73,10 @@
|
||||
android:label="@string/app_name" >
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".android.contact.ContactListActivity"
|
||||
android:name=".android.contact.ContactListActivity"
|
||||
android:logo="@drawable/logo"
|
||||
android:label="@string/contact_list_title"
|
||||
android:parentActivityName=".android.DashboardActivity" >
|
||||
android:label="@string/contact_list_title"
|
||||
android:parentActivityName=".android.DashboardActivity" >
|
||||
<meta-data
|
||||
android:name="android.support.PARENT_ACTIVITY"
|
||||
android:value=".android.DashboardActivity"
|
||||
@@ -77,7 +87,7 @@
|
||||
android:logo="@drawable/logo"
|
||||
android:label="@string/app_name"
|
||||
android:windowSoftInputMode="stateHidden"
|
||||
android:parentActivityName=".android.contact.ContactListActivity" >
|
||||
android:parentActivityName=".android.contact.ContactListActivity" >
|
||||
<meta-data
|
||||
android:name="android.support.PARENT_ACTIVITY"
|
||||
android:value=".android.contact.ContactListActivity"
|
||||
@@ -87,7 +97,7 @@
|
||||
android:name=".android.contact.ReadPrivateMessageActivity"
|
||||
android:logo="@drawable/logo"
|
||||
android:label="@string/app_name"
|
||||
android:parentActivityName=".android.contact.ContactListActivity" >
|
||||
android:parentActivityName=".android.contact.ContactListActivity" >
|
||||
<meta-data
|
||||
android:name="android.support.PARENT_ACTIVITY"
|
||||
android:value=".android.contact.ContactListActivity"
|
||||
@@ -97,7 +107,7 @@
|
||||
android:name=".android.contact.WritePrivateMessageActivity"
|
||||
android:logo="@drawable/logo"
|
||||
android:label="@string/app_name"
|
||||
android:parentActivityName=".android.contact.ContactListActivity" >
|
||||
android:parentActivityName=".android.contact.ContactListActivity" >
|
||||
<meta-data
|
||||
android:name="android.support.PARENT_ACTIVITY"
|
||||
android:value=".android.contact.ContactListActivity"
|
||||
@@ -107,7 +117,7 @@
|
||||
android:name=".android.groups.ConfigureGroupActivity"
|
||||
android:logo="@drawable/logo"
|
||||
android:label="@string/app_name"
|
||||
android:parentActivityName=".android.groups.GroupListActivity" >
|
||||
android:parentActivityName=".android.groups.GroupListActivity" >
|
||||
<meta-data
|
||||
android:name="android.support.PARENT_ACTIVITY"
|
||||
android:value=".android.groups.GroupListActivity"
|
||||
@@ -117,7 +127,7 @@
|
||||
android:name=".android.groups.CreateGroupActivity"
|
||||
android:logo="@drawable/logo"
|
||||
android:label="@string/create_forum_title"
|
||||
android:parentActivityName=".android.groups.GroupListActivity" >
|
||||
android:parentActivityName=".android.groups.GroupListActivity" >
|
||||
<meta-data
|
||||
android:name="android.support.PARENT_ACTIVITY"
|
||||
android:value=".android.groups.GroupListActivity"
|
||||
@@ -127,7 +137,7 @@
|
||||
android:name=".android.groups.GroupActivity"
|
||||
android:logo="@drawable/logo"
|
||||
android:label="@string/app_name"
|
||||
android:parentActivityName=".android.groups.GroupListActivity" >
|
||||
android:parentActivityName=".android.groups.GroupListActivity" >
|
||||
<meta-data
|
||||
android:name="android.support.PARENT_ACTIVITY"
|
||||
android:value=".android.groups.GroupListActivity"
|
||||
@@ -137,17 +147,17 @@
|
||||
android:name=".android.groups.GroupListActivity"
|
||||
android:logo="@drawable/logo"
|
||||
android:label="@string/forums_title"
|
||||
android:parentActivityName=".android.DashboardActivity" >
|
||||
android:parentActivityName=".android.DashboardActivity" >
|
||||
<meta-data
|
||||
android:name="android.support.PARENT_ACTIVITY"
|
||||
android:value=".android.DashboardActivity"
|
||||
/>
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".android.groups.ManageGroupsActivity"
|
||||
android:name=".android.groups.ManageGroupsActivity"
|
||||
android:logo="@drawable/logo"
|
||||
android:label="@string/manage_forums_title"
|
||||
android:parentActivityName=".android.groups.GroupListActivity" >
|
||||
android:label="@string/manage_forums_title"
|
||||
android:parentActivityName=".android.groups.GroupListActivity" >
|
||||
<meta-data
|
||||
android:name="android.support.PARENT_ACTIVITY"
|
||||
android:value=".android.groups.GroupListActivity"
|
||||
@@ -157,7 +167,7 @@
|
||||
android:name=".android.groups.ReadGroupPostActivity"
|
||||
android:logo="@drawable/logo"
|
||||
android:label="@string/app_name"
|
||||
android:parentActivityName=".android.groups.GroupListActivity" >
|
||||
android:parentActivityName=".android.groups.GroupListActivity" >
|
||||
<meta-data
|
||||
android:name="android.support.PARENT_ACTIVITY"
|
||||
android:value=".android.groups.GroupListActivity"
|
||||
@@ -167,7 +177,7 @@
|
||||
android:name=".android.groups.WriteGroupPostActivity"
|
||||
android:logo="@drawable/logo"
|
||||
android:label="@string/app_name"
|
||||
android:parentActivityName=".android.groups.GroupListActivity" >
|
||||
android:parentActivityName=".android.groups.GroupListActivity" >
|
||||
<meta-data
|
||||
android:name="android.support.PARENT_ACTIVITY"
|
||||
android:value=".android.groups.GroupListActivity"
|
||||
@@ -182,7 +192,7 @@
|
||||
android:name=".android.invitation.AddContactActivity"
|
||||
android:logo="@drawable/logo"
|
||||
android:label="@string/add_contact_title"
|
||||
android:parentActivityName=".android.contact.ContactListActivity" >
|
||||
android:parentActivityName=".android.contact.ContactListActivity" >
|
||||
<meta-data
|
||||
android:name="android.support.PARENT_ACTIVITY"
|
||||
android:value=".android.contact.ContactListActivity"
|
||||
|
||||
BIN
briar-android/res/drawable-hdpi/action_about.png
Normal file
BIN
briar-android/res/drawable-hdpi/action_about.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.7 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 1.5 KiB |
BIN
briar-android/res/drawable-mdpi/action_about.png
Normal file
BIN
briar-android/res/drawable-mdpi/action_about.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.4 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 1.3 KiB |
BIN
briar-android/res/drawable-xhdpi/action_about.png
Normal file
BIN
briar-android/res/drawable-xhdpi/action_about.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.2 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 1.8 KiB |
@@ -16,8 +16,9 @@
|
||||
<string name="expiry_warning">This software has expired.\nPlease install a newer version.</string>
|
||||
<string name="contact_list_button">Contacts</string>
|
||||
<string name="forums_button">Forums</string>
|
||||
<string name="testing_button">Testing</string>
|
||||
<string name="settings_button">Settings</string>
|
||||
<string name="sign_out_button">Sign Out</string>
|
||||
<string name="testing_button">Testing</string>
|
||||
<string name="contact_list_title">Contacts</string>
|
||||
<string name="no_contacts">No contacts</string>
|
||||
<string name="contact_connected">Connected</string>
|
||||
@@ -79,4 +80,7 @@
|
||||
<string name="private_message_notification_text">Touch to show.</string>
|
||||
<string name="group_post_notification_title">New forum post</string>
|
||||
<string name="group_post_notification_text">Touch to show.</string>
|
||||
<string name="settings_title">Settings</string>
|
||||
<string name="activate_bluetooth_option">Activate Bluetooth while signed in</string>
|
||||
<string name="activate_bluetooth_explanation">Briar uses Bluetooth to communicate with nearby contacts</string>
|
||||
</resources>
|
||||
@@ -114,19 +114,19 @@ public class DashboardActivity extends BriarActivity {
|
||||
});
|
||||
buttons.add(forumsButton);
|
||||
|
||||
Button testingButton = new Button(this);
|
||||
testingButton.setLayoutParams(matchMatch);
|
||||
testingButton.setBackgroundResource(0);
|
||||
testingButton.setCompoundDrawablesWithIntrinsicBounds(0,
|
||||
R.drawable.action_help, 0, 0);
|
||||
testingButton.setText(R.string.testing_button);
|
||||
testingButton.setOnClickListener(new OnClickListener() {
|
||||
Button settingsButton = new Button(this);
|
||||
settingsButton.setLayoutParams(matchMatch);
|
||||
settingsButton.setBackgroundResource(0);
|
||||
settingsButton.setCompoundDrawablesWithIntrinsicBounds(0,
|
||||
R.drawable.action_settings, 0, 0);
|
||||
settingsButton.setText(R.string.settings_button);
|
||||
settingsButton.setOnClickListener(new OnClickListener() {
|
||||
public void onClick(View view) {
|
||||
startActivity(new Intent(DashboardActivity.this,
|
||||
TestingActivity.class));
|
||||
SettingsActivity.class));
|
||||
}
|
||||
});
|
||||
buttons.add(testingButton);
|
||||
buttons.add(settingsButton);
|
||||
|
||||
Button signOutButton = new Button(this);
|
||||
signOutButton.setLayoutParams(matchMatch);
|
||||
|
||||
160
briar-android/src/org/briarproject/android/SettingsActivity.java
Normal file
160
briar-android/src/org/briarproject/android/SettingsActivity.java
Normal file
@@ -0,0 +1,160 @@
|
||||
package org.briarproject.android;
|
||||
|
||||
import static android.view.Gravity.CENTER;
|
||||
import static android.view.View.GONE;
|
||||
import static android.view.View.VISIBLE;
|
||||
import static android.widget.LinearLayout.VERTICAL;
|
||||
import static java.util.logging.Level.WARNING;
|
||||
import static org.briarproject.android.util.CommonLayoutParams.MATCH_WRAP;
|
||||
import static org.briarproject.android.util.CommonLayoutParams.MATCH_WRAP_1;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.briarproject.R;
|
||||
import org.briarproject.android.util.HorizontalBorder;
|
||||
import org.briarproject.android.util.LayoutUtils;
|
||||
import org.briarproject.android.util.ListLoadingProgressBar;
|
||||
import org.briarproject.api.TransportConfig;
|
||||
import org.briarproject.api.TransportId;
|
||||
import org.briarproject.api.db.DatabaseComponent;
|
||||
import org.briarproject.api.db.DbException;
|
||||
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Resources;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.ScrollView;
|
||||
import android.widget.TextView;
|
||||
|
||||
public class SettingsActivity extends BriarActivity implements OnClickListener {
|
||||
|
||||
private static final Logger LOG =
|
||||
Logger.getLogger(SettingsActivity.class.getName());
|
||||
|
||||
private CheckBox bluetooth = null;
|
||||
private ScrollView scroll = null;
|
||||
private ListLoadingProgressBar progress = null;
|
||||
private ImageButton testingButton = null;
|
||||
|
||||
// Fields that are accessed from background threads must be volatile
|
||||
@Inject private volatile DatabaseComponent db;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle state) {
|
||||
super.onCreate(state);
|
||||
|
||||
LinearLayout layout = new LinearLayout(this);
|
||||
layout.setOrientation(VERTICAL);
|
||||
|
||||
scroll = new ScrollView(this);
|
||||
|
||||
LinearLayout settings = new LinearLayout(this);
|
||||
settings.setOrientation(VERTICAL);
|
||||
int pad = LayoutUtils.getPadding(this);
|
||||
settings.setPadding(pad, pad, pad, pad);
|
||||
|
||||
bluetooth = new CheckBox(this);
|
||||
bluetooth.setLayoutParams(MATCH_WRAP);
|
||||
bluetooth.setTextSize(18);
|
||||
bluetooth.setText(R.string.activate_bluetooth_option);
|
||||
bluetooth.setOnClickListener(this);
|
||||
settings.addView(bluetooth);
|
||||
|
||||
TextView bluetoothHint = new TextView(this);
|
||||
bluetoothHint.setText(R.string.activate_bluetooth_explanation);
|
||||
settings.addView(bluetoothHint);
|
||||
|
||||
scroll.addView(settings);
|
||||
scroll.setLayoutParams(MATCH_WRAP_1);
|
||||
scroll.setVisibility(GONE);
|
||||
layout.addView(scroll);
|
||||
|
||||
progress = new ListLoadingProgressBar(this);
|
||||
layout.addView(progress);
|
||||
|
||||
layout.addView(new HorizontalBorder(this));
|
||||
|
||||
LinearLayout footer = new LinearLayout(this);
|
||||
footer.setLayoutParams(MATCH_WRAP);
|
||||
footer.setGravity(CENTER);
|
||||
Resources res = getResources();
|
||||
footer.setBackgroundColor(res.getColor(R.color.button_bar_background));
|
||||
testingButton = new ImageButton(this);
|
||||
testingButton.setBackgroundResource(0);
|
||||
testingButton.setImageResource(R.drawable.action_about);
|
||||
testingButton.setOnClickListener(this);
|
||||
footer.addView(testingButton);
|
||||
layout.addView(footer);
|
||||
|
||||
setContentView(layout);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
loadSettings();
|
||||
}
|
||||
|
||||
private void loadSettings() {
|
||||
runOnDbThread(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
boolean activateBluetooth = true;
|
||||
TransportConfig c = db.getConfig(new TransportId("bt"));
|
||||
if(c != null && "false".equals(c.get("enable")))
|
||||
activateBluetooth = false;
|
||||
displaySettings(activateBluetooth);
|
||||
} catch(DbException e) {
|
||||
if(LOG.isLoggable(WARNING))
|
||||
LOG.log(WARNING, e.toString(), e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void displaySettings(final boolean activateBluetooth) {
|
||||
runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
scroll.setVisibility(VISIBLE);
|
||||
progress.setVisibility(GONE);
|
||||
bluetooth.setChecked(activateBluetooth);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void onClick(View view) {
|
||||
if(testingButton == null) return; // Not created yet
|
||||
if(view == bluetooth) {
|
||||
boolean activateBluetooth = bluetooth.isChecked();
|
||||
if(!activateBluetooth) {
|
||||
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
|
||||
if(adapter != null) adapter.disable();
|
||||
}
|
||||
storeSettings(activateBluetooth);
|
||||
} else if(view == testingButton) {
|
||||
startActivity(new Intent(this, TestingActivity.class));
|
||||
}
|
||||
}
|
||||
|
||||
private void storeSettings(final boolean activateBluetooth) {
|
||||
runOnDbThread(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
TransportConfig c = new TransportConfig();
|
||||
c.put("enable", String.valueOf(activateBluetooth));
|
||||
db.mergeConfig(new TransportId("bt"), c);
|
||||
} catch(DbException e) {
|
||||
if(LOG.isLoggable(WARNING))
|
||||
LOG.log(WARNING, e.toString(), e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user