Skip to content
This repository was archived by the owner on Apr 9, 2021. It is now read-only.

Default transferring mechanism and UI improvements #290

Merged
merged 23 commits into from
Aug 18, 2019
Merged
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
9a9d5c6
✨ feat: added the list preference
huangyz0918 Aug 2, 2019
f6d9f27
✨ feat: remove the asking dialog.
huangyz0918 Aug 3, 2019
a7cc2ac
🚑 quickfix: fixed the unit tests.
huangyz0918 Aug 3, 2019
dda6460
💄 ui: added a animation while sending by bluetooth.
huangyz0918 Aug 3, 2019
7c37c29
🚑 quickfix: remove the animate lib, replaced with a progress bar.
huangyz0918 Aug 3, 2019
84f7ac1
✨ feat: added sections in settings.
huangyz0918 Aug 4, 2019
d9c3ffc
✨ feat: add the switch option for senders.
huangyz0918 Aug 6, 2019
3d69968
✨ feat: add switch option in the receiver's menu.
huangyz0918 Aug 6, 2019
a42ef74
💄 ui: change color theme for bluetooth specific activities.
huangyz0918 Aug 9, 2019
c5805f1
💄 ui: added icons in the menu of sending/receiving pages.
huangyz0918 Aug 10, 2019
54243a7
🚑 quickfix: fixed unit tests.
huangyz0918 Aug 10, 2019
0877e6d
🐛 fix: resolved conflicts.
huangyz0918 Aug 11, 2019
a0a3445
💄 ui: added icons in the dialog.
huangyz0918 Aug 12, 2019
c52969d
🐛 fix: resolved conflicts.
huangyz0918 Aug 16, 2019
df08543
💄 ui: add icon to bluetooth sender.
huangyz0918 Aug 16, 2019
038e47f
🐛 fix: resolved conflicts and improved the dialog.
huangyz0918 Aug 16, 2019
7f95a1a
🚑 quickfix: add default text for bluetooth name.
huangyz0918 Aug 18, 2019
0bbd4ea
🚑 quickfix: add @NonNull checks for dialog utils.
huangyz0918 Aug 18, 2019
6a0fb00
🐛 fix: fix some issues
huangyz0918 Aug 18, 2019
d827d3a
🚑 quickfix: add comment for dialog utils.
huangyz0918 Aug 18, 2019
9638567
🚑 quickfix: fixed the settings text.
huangyz0918 Aug 18, 2019
c4fb32b
🚑 quickfix:
huangyz0918 Aug 18, 2019
d16605f
✅ test: fix unit tests.
huangyz0918 Aug 18, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
✨ feat: added sections in settings.
huangyz0918 committed Aug 4, 2019

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 84f7ac176f40084ad0167bcc7d4b2b364fc42b6c
Original file line number Diff line number Diff line change
@@ -131,7 +131,13 @@ private void setupDataStreamsAndReceive(@Share.TransferMethod int method) {
BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
BluetoothDevice bluetoothDevice = bluetoothAdapter.getRemoteDevice(targetMacAddress);
if (bluetoothDevice != null) {
bluetoothSocket = bluetoothDevice.createRfcommSocketToServiceRecord(SPP_UUID);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext().getApplicationContext());
boolean isSecureMode = prefs.getBoolean(PreferenceKeys.KEY_BLUETOOTH_SECURE_MODE, true);
if (isSecureMode) {
bluetoothSocket = bluetoothDevice.createRfcommSocketToServiceRecord(SPP_UUID);
} else {
bluetoothSocket = bluetoothDevice.createInsecureRfcommSocketToServiceRecord(SPP_UUID);
}

if (!bluetoothSocket.isConnected()) {
bluetoothSocket.connect();
Original file line number Diff line number Diff line change
@@ -8,6 +8,8 @@
import android.os.Bundle;
import android.os.CountDownTimer;
import android.text.TextUtils;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;

@@ -49,6 +51,9 @@ public class BtSenderActivity extends InjectableActivity {
@BindView(R.id.toolbar)
Toolbar toolbar;

@BindView(R.id.progressBar)
ProgressBar progressBar;

@Inject
RxEventBus rxEventBus;

@@ -62,6 +67,7 @@ public class BtSenderActivity extends InjectableActivity {
private CountDownTimer countDownTimer;
private static final int CONNECT_TIMEOUT = 120;
private static final int COUNT_DOWN_INTERVAL = 1000;
private BtSenderActivity thisActivity = this;


@Override
@@ -126,6 +132,7 @@ private Disposable addUploadEventSubscription() {
Toast.makeText(this, alertMsg, Toast.LENGTH_SHORT).show();
break;
case FINISHED:
progressBar.setVisibility(View.GONE);
String result = uploadEvent.getResult();
if (TextUtils.isEmpty(result)) {
resultTextView.setText(getString(R.string.tv_form_already_exist));
@@ -136,9 +143,11 @@ private Disposable addUploadEventSubscription() {
Toast.makeText(this, getString(R.string.transfer_result) + " : " + result, Toast.LENGTH_SHORT).show();
break;
case ERROR:
progressBar.setVisibility(View.GONE);
Toast.makeText(this, getString(R.string.error_while_uploading, uploadEvent.getResult()), Toast.LENGTH_SHORT).show();
break;
case CANCELLED:
progressBar.setVisibility(View.GONE);
Toast.makeText(this, getString(R.string.canceled), Toast.LENGTH_LONG).show();
break;
}
@@ -179,7 +188,9 @@ public void onTick(long millisUntilFinished) {

@Override
public void onFinish() {
alertDialog.show();
if (!BluetoothUtils.isActivityDestroyed(thisActivity)) {
alertDialog.show();
}
}
}.start();
}
Original file line number Diff line number Diff line change
@@ -11,6 +11,8 @@ public class PreferenceKeys {
public static final String KEY_HOTSPOT_PWD_REQUIRE = "hotspot_pwd_require";
public static final String KEY_ODK_DESTINATION_DIR = "odk_destination_dir";
public static final String KEY_DEFAULT_TRANSFER_METHOD = "default_transfer_method";
public static final String KEY_BLUETOOTH_NAME = "bluetooth_name";
public static final String KEY_BLUETOOTH_SECURE_MODE = "bluetooth_secure_mode";

private PreferenceKeys() {

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.odk.share.views.ui.settings;

import android.bluetooth.BluetoothAdapter;
import android.content.SharedPreferences;
import android.os.Build;
import android.os.Bundle;
@@ -32,8 +33,10 @@
public class SettingsActivity extends PreferenceActivity {

EditTextPreference hotspotNamePreference;
EditTextPreference bluetoothNamePreference;
Preference hotspotPasswordPreference;
CheckBoxPreference passwordRequirePreference;
CheckBoxPreference btSecureModePreference;
EditTextPreference odkDestinationDirPreference;
ListPreference defaultMethodPreference;
private SharedPreferences prefs;
@@ -61,8 +64,10 @@ public boolean onOptionsItemSelected(MenuItem item) {
private void addPreferences() {
defaultMethodPreference = (ListPreference) findPreference(PreferenceKeys.KEY_DEFAULT_TRANSFER_METHOD);
hotspotNamePreference = (EditTextPreference) findPreference(PreferenceKeys.KEY_HOTSPOT_NAME);
bluetoothNamePreference = (EditTextPreference) findPreference(PreferenceKeys.KEY_BLUETOOTH_NAME);
hotspotPasswordPreference = findPreference(PreferenceKeys.KEY_HOTSPOT_PASSWORD);
passwordRequirePreference = (CheckBoxPreference) findPreference(PreferenceKeys.KEY_HOTSPOT_PWD_REQUIRE);
btSecureModePreference = (CheckBoxPreference) findPreference(PreferenceKeys.KEY_BLUETOOTH_SECURE_MODE);
odkDestinationDirPreference = (EditTextPreference) findPreference(PreferenceKeys.KEY_ODK_DESTINATION_DIR);

prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
@@ -71,14 +76,19 @@ private void addPreferences() {
getString(R.string.hotspot)));
hotspotNamePreference.setSummary(prefs.getString(PreferenceKeys.KEY_HOTSPOT_NAME,
getString(R.string.default_hotspot_ssid)));
bluetoothNamePreference.setSummary(prefs.getString(PreferenceKeys.KEY_BLUETOOTH_NAME,
BluetoothAdapter.getDefaultAdapter().getName()));
boolean isPasswordSet = prefs.getBoolean(PreferenceKeys.KEY_HOTSPOT_PWD_REQUIRE, false);
odkDestinationDirPreference.setSummary(prefs.getString(PreferenceKeys.KEY_ODK_DESTINATION_DIR,
getString(R.string.default_odk_destination_dir)));
boolean isSecureMode = prefs.getBoolean(PreferenceKeys.KEY_BLUETOOTH_SECURE_MODE, true);

hotspotPasswordPreference.setEnabled(isPasswordSet);
passwordRequirePreference.setChecked(isPasswordSet);
btSecureModePreference.setChecked(isSecureMode);

hotspotNamePreference.setOnPreferenceChangeListener(preferenceChangeListener());
bluetoothNamePreference.setOnPreferenceChangeListener(preferenceChangeListener());
hotspotPasswordPreference.setOnPreferenceChangeListener(preferenceChangeListener());
passwordRequirePreference.setOnPreferenceChangeListener(preferenceChangeListener());
odkDestinationDirPreference.setOnPreferenceChangeListener(preferenceChangeListener());
@@ -110,6 +120,17 @@ private Preference.OnPreferenceChangeListener preferenceChangeListener() {
hotspotNamePreference.setSummary(name);
}
break;
case PreferenceKeys.KEY_BLUETOOTH_NAME:
String bluetoothName = newValue.toString();
if (bluetoothName.length() == 0) {
Toast.makeText(getBaseContext(), getString(R.string.bluetooth_name_error), Toast.LENGTH_LONG).show();
return false;
} else {
bluetoothNamePreference.setSummary(bluetoothName);
BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
bluetoothAdapter.setName(bluetoothName);
}
break;
case PreferenceKeys.KEY_HOTSPOT_PASSWORD:
String password = newValue.toString();
if (password.length() < 8) {
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M17.71,7.71L12,2h-1v7.59L6.41,5 5,6.41 10.59,12 5,17.59 6.41,19 11,14.41L11,22h1l5.71,-5.71 -4.3,-4.29 4.3,-4.29zM13,5.83l1.88,1.88L13,9.59L13,5.83zM14.88,16.29L13,18.17v-3.76l1.88,1.88z"/>
</vector>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M12,1L3,5v6c0,5.55 3.84,10.74 9,12 5.16,-1.26 9,-6.45 9,-12L21,5l-9,-4zM12,11.99h7c-0.53,4.12 -3.28,7.79 -7,8.94L12,12L5,12L5,6.3l7,-3.11v8.8z"/>
</vector>
4 changes: 4 additions & 0 deletions skunkworks_crow/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -37,11 +37,15 @@
<string name="open_source_licenses">Open Source Licenses</string>
<string name="default_hotspot_ssid">hotspot</string>
<string name="default_hotspot_password">12345678</string>
<string name="title_bluetooth_name">Bluetooth Name</string>
<string name="title_hotspot_ssid">Hotspot SSID</string>
<string name="title_hotspot_password">Set Hotspot password</string>
<string name="summary_security_bluetooth">Use secure transfer (needs pairing code)</string>
<string name="set_password">Set Password</string>
<string name="secure_mode">Enable Secure Mode</string>
<string name="password_hotspot">Password required to connect with hotspot</string>
<string name="hotspot_name_error">Hotspot name should not be empty</string>
<string name="bluetooth_name_error">Bluetooth name should not be empty</string>
<string name="hotspot_password_error">Password length should be atleast 8 characters long</string>
<string name="waiting_connection">Waiting for connection to accept</string>
<string name="waiting_hotspot">Waiting for hotspot to connect</string>
16 changes: 16 additions & 0 deletions skunkworks_crow/src/main/res/xml/preferences_menu.xml
Original file line number Diff line number Diff line change
@@ -45,4 +45,20 @@
android:title="@string/set_password" />

</PreferenceCategory>

<PreferenceCategory android:title="Bluetooth Settings">

<EditTextPreference
android:icon="@drawable/ic_bluetooth_black_24dp"
android:key="bluetooth_name"
android:title="@string/title_bluetooth_name" />

<CheckBoxPreference
android:defaultValue="true"
android:icon="@drawable/ic_security_black_24dp"
android:key="bluetooth_secure_mode"
android:summary="@string/summary_security_bluetooth"
android:title="@string/secure_mode" />

</PreferenceCategory>
</PreferenceScreen>
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package org.odk.share.activities;

import android.bluetooth.BluetoothAdapter;
import android.content.SharedPreferences;
import android.preference.CheckBoxPreference;
import android.preference.EditTextPreference;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.PreferenceManager;

@@ -32,6 +34,9 @@ public class SettingsActivityTest {
private CheckBoxPreference passwordRequirePreference;
private EditTextPreference hotspotNamePreference;
private EditTextPreference odkDestinationDirPreference;
private CheckBoxPreference btSecureModePreference;
private ListPreference defaultMethodPreference;
private EditTextPreference bluetoothNamePreference;

@Before
public void setUp() throws Exception {
@@ -72,6 +77,12 @@ public void preferenceMenuTest() {
assertNotNull(settingsActivity.findPreference(PreferenceKeys.KEY_HOTSPOT_PWD_REQUIRE));
//test for odkDestinationDirPreference
assertNotNull(settingsActivity.findPreference(PreferenceKeys.KEY_ODK_DESTINATION_DIR));
//test for KEY_BLUETOOTH_SECURE_MODE
assertNotNull(settingsActivity.findPreference(PreferenceKeys.KEY_BLUETOOTH_SECURE_MODE));
//test for KEY_BLUETOOTH_NAME
assertNotNull(settingsActivity.findPreference(PreferenceKeys.KEY_BLUETOOTH_NAME));
//test for KEY_DEFAULT_TRANSFER_METHOD
assertNotNull(settingsActivity.findPreference(PreferenceKeys.KEY_DEFAULT_TRANSFER_METHOD));
}

/**
@@ -81,20 +92,25 @@ public void preferenceMenuTest() {
public void preferenceSummaryTest() {
hotspotNamePreference = (EditTextPreference) settingsActivity.findPreference(PreferenceKeys.KEY_HOTSPOT_NAME);
odkDestinationDirPreference = (EditTextPreference) settingsActivity.findPreference(PreferenceKeys.KEY_ODK_DESTINATION_DIR);
bluetoothNamePreference = (EditTextPreference) settingsActivity.findPreference(PreferenceKeys.KEY_BLUETOOTH_NAME);

//test the summary
assertEquals(prefs.getString(PreferenceKeys.KEY_HOTSPOT_NAME,
settingsActivity.getString(R.string.default_hotspot_ssid)), hotspotNamePreference.getSummary());

assertEquals(prefs.getString(PreferenceKeys.KEY_ODK_DESTINATION_DIR,
settingsActivity.getString(R.string.default_odk_destination_dir)), odkDestinationDirPreference.getSummary());

assertEquals(prefs.getString(PreferenceKeys.KEY_BLUETOOTH_NAME,
BluetoothAdapter.getDefaultAdapter().getName()), bluetoothNamePreference.getSummary());
}

/**
* {@link Test} the preference status, like {@link android.widget.CheckBox}, and whether enable or not.
*/
@Test
public void preferenceStatusTest() {
btSecureModePreference = (CheckBoxPreference) settingsActivity.findPreference(PreferenceKeys.KEY_BLUETOOTH_SECURE_MODE);
hotspotPasswordPreference = settingsActivity.findPreference(PreferenceKeys.KEY_HOTSPOT_PASSWORD);
passwordRequirePreference = (CheckBoxPreference) settingsActivity.findPreference(PreferenceKeys.KEY_HOTSPOT_PWD_REQUIRE);

@@ -107,5 +123,23 @@ public void preferenceStatusTest() {
assertFalse(passwordRequirePreference.isChecked());
passwordRequirePreference.setChecked(true);
assertTrue(passwordRequirePreference.isChecked());

btSecureModePreference.setChecked(false);
assertFalse(btSecureModePreference.isChecked());
passwordRequirePreference.setChecked(true);
assertTrue(passwordRequirePreference.isChecked());
}

/**
* {@link Test} for {@link ListPreference}.
*/
@Test
public void listPreferenceTest() {
defaultMethodPreference = (ListPreference) settingsActivity.findPreference(PreferenceKeys.KEY_DEFAULT_TRANSFER_METHOD);
defaultMethodPreference.setValue(settingsActivity.getString(R.string.hotspot));
assertEquals(settingsActivity.getString(R.string.hotspot), defaultMethodPreference.getValue());
defaultMethodPreference.setValue(settingsActivity.getString(R.string.bluetooth));
assertEquals(settingsActivity.getString(R.string.bluetooth), defaultMethodPreference.getValue());
assertEquals(defaultMethodPreference.getEntries().length, settingsActivity.getResources().getStringArray(R.array.methods_array).length);
}
}