Skip to content
This repository has been archived by the owner on Jun 18, 2023. It is now read-only.

Commit

Permalink
- Added new participant view, which is a restricted interface for stu…
Browse files Browse the repository at this point in the history
…dy participants. This is enabled with interface_locked setting from the dashboard or inside the client

- Fixed some missing androidx references from older appcompat in ESMs layouts
  • Loading branch information
denzilferreira committed Aug 12, 2019
1 parent 1e49fa5 commit aca3184
Show file tree
Hide file tree
Showing 14 changed files with 195 additions and 20 deletions.
3 changes: 2 additions & 1 deletion aware-core/aware.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ buildscript {
mqtt_libs = '1.2.1'
ion_libs = "2.+"
google_libs = "17.0.0"
version_code = 816
version_code = 817
version_readable = "4.0." + version_code + "." + "bundle"
compile_sdk = 28
target_sdk = 28
Expand All @@ -13,6 +13,7 @@ buildscript {
aware_libs = "master-SNAPSHOT"
kotlin_version = "1.3.41"
build_gradle = "3.4.2"
anko_version = "0.10.8"
}

repositories {
Expand Down
2 changes: 2 additions & 0 deletions aware-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ dependencies {
implementation "org.eclipse.paho:org.eclipse.paho.client.mqttv3:$mqtt_libs"
implementation 'com.koushikdutta.ion:ion:2.2.1'
implementation "com.google.android.material:material:1.1.0-alpha09"
implementation "org.jetbrains.anko:anko:$anko_version"

implementation "androidx.gridlayout:gridlayout:1.0.0"
implementation "androidx.cardview:cardview:1.0.0"

Expand Down
5 changes: 5 additions & 0 deletions aware-core/src/main/java/com/aware/Aware_Preferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -650,4 +650,9 @@ public class Aware_Preferences {
* Masks text produced by touch events
*/
public static final String MASK_TOUCH_TEXT = "mask_touch_text";

/**
* Lock interface after participant joins study
*/
public static final String INTERFACE_LOCKED = "interface_locked";
}
4 changes: 2 additions & 2 deletions aware-core/src/main/res/layout/esm_datetime.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
android:layout_below="@id/esm_title"
android:padding="16dp" />

<android.support.design.widget.TabLayout
<com.google.android.material.tabs.TabLayout
android:id="@+id/datetimetabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
Expand All @@ -34,7 +34,7 @@
app:tabSelectedTextColor="#FFF"
app:tabTextColor="#000" />

<android.support.v4.view.ViewPager
<androidx.viewpager.widget.ViewPager
android:id="@+id/datetimepager"
android:layout_width="match_parent"
android:layout_height="250dp"
Expand Down
8 changes: 8 additions & 0 deletions aware-core/src/main/res/xml/aware_preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -945,6 +945,14 @@
android:summary="WARNING: This may cause problems with some sensors or plugins if they rely on history data (e.g., battery charges, discharges, ...)"
android:title="Wipe data on upload" />

<CheckBoxPreference
android:defaultValue="false"
android:key="interface_locked"
android:persistent="true"
android:summary="Simplifies the interface for participants after joining a study"
android:title="Participant interface mode"
/>

<CheckBoxPreference
android:defaultValue="false"
android:key="frequency_enforce_all"
Expand Down
11 changes: 11 additions & 0 deletions aware-phone/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
apply plugin: 'com.android.application'

apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-android'

android {
compileSdkVersion compile_sdk
buildToolsVersion build_tools
Expand Down Expand Up @@ -102,6 +105,10 @@ if (System.getenv("storeFile") != null && System.getenv("storePassword") != null
}

dependencies {

implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation "org.jetbrains.anko:anko:$anko_version"

implementation "me.dm7.barcodescanner:zbar:1.9.8"

implementation "com.google.android.material:material:1.1.0-alpha09"
Expand All @@ -122,3 +129,7 @@ dependencies {
api (project(":com.aware.plugin.sentimental"))
}

repositories {
mavenCentral()
}

1 change: 1 addition & 0 deletions aware-phone/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@
android:name="android.support.PARENT_ACTIVITY"
android:value="com.aware.phone.Aware_Client" />
</activity>
<activity android:name=".ui.Aware_Participant" />

<receiver
android:name="com.aware.Aware$AndroidPackageMonitor" android:exported="true">
Expand Down
16 changes: 13 additions & 3 deletions aware-phone/src/main/java/com/aware/phone/Aware_Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import com.aware.Aware_Preferences;
import com.aware.phone.ui.Aware_Activity;
import com.aware.phone.ui.Aware_Join_Study;
import com.aware.phone.ui.Aware_Participant;
import com.aware.ui.PermissionsHandler;
import com.aware.utils.Https;
import com.aware.utils.SSLManager;
Expand Down Expand Up @@ -70,6 +71,9 @@ protected void onCreate(Bundle savedInstanceState) {
}

prefs = getSharedPreferences("com.aware.phone", Context.MODE_PRIVATE);
addPreferencesFromResource(R.xml.aware_preferences);

setContentView(R.layout.aware_ui);

optionalSensors.put(Aware_Preferences.STATUS_ACCELEROMETER, Sensor.TYPE_ACCELEROMETER);
optionalSensors.put(Aware_Preferences.STATUS_SIGNIFICANT_MOTION, Sensor.TYPE_ACCELEROMETER);
Expand All @@ -90,9 +94,6 @@ protected void onCreate(Bundle savedInstanceState) {
listSensorType.put(sensors.get(i).getType(), true);
}

addPreferencesFromResource(R.xml.aware_preferences);
setContentView(R.layout.aware_ui);

REQUIRED_PERMISSIONS.add(Manifest.permission.WRITE_EXTERNAL_STORAGE);
REQUIRED_PERMISSIONS.add(Manifest.permission.ACCESS_WIFI_STATE);
REQUIRED_PERMISSIONS.add(Manifest.permission.CAMERA);
Expand Down Expand Up @@ -427,6 +428,15 @@ protected void onResume() {
findPreference(Aware_Preferences.STATUS_TOUCH)
);
}

if (Aware.isStudy(this)) {
if (Aware.getSetting(this, Aware_Preferences.INTERFACE_LOCKED).equals("true") ||
Aware.getSetting(this, "ui_mode").equals("1") || Aware.getSetting(this, "ui_mode").equals("2")
) {
finish();
startActivity(new Intent(this, Aware_Participant.class));
}
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,6 @@ public boolean onNavigationItemSelected(@NonNull MenuItem item) {
case R.id.aware_plugins: //Plugins
Intent pluginsManager = new Intent(getApplicationContext(), Plugins_Manager.class);
startActivity(pluginsManager);
/*Intent playStore = new Intent(Intent.ACTION_VIEW);
playStore.setData(Uri.parse("market://search?q=awareframework&c=apps"));
try {
startActivity(playStore);
} catch (ActivityNotFoundException e) {
Toast.makeText(getApplicationContext(), "Google Play Store installed?", Toast.LENGTH_SHORT).show();
}*/
break;
case R.id.aware_stream: //Stream
Intent stream_ui = new Intent(getApplicationContext(), Stream_UI.class);
Expand Down
16 changes: 12 additions & 4 deletions aware-phone/src/main/java/com/aware/phone/ui/Aware_Join_Study.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.aware.phone.R;
import com.aware.providers.Aware_Provider;
import com.aware.utils.*;
import com.google.android.material.bottomnavigation.BottomNavigationView;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
Expand Down Expand Up @@ -72,6 +73,7 @@ protected void onCreate(Bundle savedInstanceState) {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}

@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
Aware.setSetting(getApplicationContext(), Aware_Preferences.DEVICE_LABEL, s.toString());
Expand All @@ -93,11 +95,12 @@ public void afterTextChanged(Editable s) {
//If we are getting here from an AWARE study link
String scheme = getIntent().getScheme();
if (scheme != null) {
if (Aware.DEBUG) Log.d(Aware.TAG, "AWARE Link detected: " + getIntent().getDataString() + " SCHEME: " + scheme);
if (Aware.DEBUG)
Log.d(Aware.TAG, "AWARE Link detected: " + getIntent().getDataString() + " SCHEME: " + scheme);
if (scheme.equalsIgnoreCase("aware")) {
study_url = getIntent().getDataString().replace("aware://","http://");
study_url = getIntent().getDataString().replace("aware://", "http://");
} else if (scheme.equalsIgnoreCase("aware-ssl")) {
study_url = getIntent().getDataString().replace("aware-ssl://","https://");
study_url = getIntent().getDataString().replace("aware-ssl://", "https://");
}
}

Expand Down Expand Up @@ -292,7 +295,7 @@ protected JSONObject doInBackground(String... params) {
//Note: Joining a study always downloads the certificate.
SSLManager.handleUrl(getApplicationContext(), study_url, true);

while(!SSLManager.hasCertificate(getApplicationContext(), study_uri.getHost())) {
while (!SSLManager.hasCertificate(getApplicationContext(), study_uri.getHost())) {
//wait until we have the certificate downloaded
}

Expand Down Expand Up @@ -640,6 +643,11 @@ public void onClick(View view) {
}
qry.close();
}

if (Aware.getSetting(this, Aware_Preferences.INTERFACE_LOCKED).equals("true")) {
BottomNavigationView bottomNavigationView = (BottomNavigationView) findViewById(R.id.aware_bottombar);
bottomNavigationView.setVisibility(View.GONE);
}
}

private boolean verifyInstalledPlugins() {
Expand Down
87 changes: 87 additions & 0 deletions aware-phone/src/main/java/com/aware/phone/ui/Aware_Participant.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package com.aware.phone.ui

import android.Manifest
import android.content.Intent
import android.content.pm.PackageManager
import android.os.Build
import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
import android.widget.Toast
import androidx.appcompat.app.ActionBar
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.PermissionChecker
import com.aware.Aware
import com.aware.Aware_Preferences
import com.aware.phone.R
import com.aware.ui.PermissionsHandler
import kotlinx.android.synthetic.main.aware_ui_participant.*
import java.util.ArrayList

class Aware_Participant : AppCompatActivity() {

override fun onPostCreate(savedInstanceState: Bundle?) {
super.onPostCreate(savedInstanceState)

(supportActionBar as ActionBar).setDisplayHomeAsUpEnabled(false)
(supportActionBar as ActionBar).setDisplayShowHomeEnabled(false)
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.aware_ui_participant)
}

override fun onResume() {
super.onResume()
device_id.text = Aware.getSetting(this, Aware_Preferences.DEVICE_ID)
device_name.text = Aware.getSetting(this, Aware_Preferences.DEVICE_LABEL)
study_url.text = Aware.getSetting(this, Aware_Preferences.WEBSERVICE_SERVER)
}

override fun onCreateOptionsMenu(menu: Menu): Boolean {
menuInflater.inflate(R.menu.aware_menu, menu)
for (i in 0 until menu.size()) {
val item = menu.getItem(i)
if (item.title.toString().equals(resources.getString(R.string.aware_qrcode), ignoreCase = true)) item.isVisible = false
if (item.title.toString().equals(resources.getString(R.string.aware_team), ignoreCase = true)) item.isVisible = false
if (item.title.toString().equals(resources.getString(R.string.aware_study), ignoreCase = true)) item.isVisible = true
if (item.title.toString().equals(resources.getString(R.string.aware_sync), ignoreCase = true)) item.isVisible = true
}
return true
}

override fun onOptionsItemSelected(item: MenuItem): Boolean {
if (item.title.toString().equals(resources.getString(R.string.aware_qrcode), ignoreCase = true)) {
if (PermissionChecker.checkSelfPermission(this, Manifest.permission.CAMERA) != PermissionChecker.PERMISSION_GRANTED) {
val permission = ArrayList<String>()
permission.add(Manifest.permission.CAMERA)

val permissions = Intent(this, PermissionsHandler::class.java)
permissions.putExtra(PermissionsHandler.EXTRA_REQUIRED_PERMISSIONS, permission)
permissions.putExtra(PermissionsHandler.EXTRA_REDIRECT_ACTIVITY, "$packageName/$packageName.ui.Aware_QRCode")
permissions.flags = Intent.FLAG_ACTIVITY_NEW_TASK
startActivity(permissions)
} else {
val qrcode = Intent(this@Aware_Participant, Aware_QRCode::class.java)
qrcode.flags = Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_NEW_TASK
startActivity(qrcode)
}
}
if (item.title.toString().equals(resources.getString(R.string.aware_study), ignoreCase = true)) {
val studyInfo = Intent(this@Aware_Participant, Aware_Join_Study::class.java)
studyInfo.putExtra(Aware_Join_Study.EXTRA_STUDY_URL, Aware.getSetting(this, Aware_Preferences.WEBSERVICE_SERVER))
startActivity(studyInfo)
}
if (item.title.toString().equals(resources.getString(R.string.aware_team), ignoreCase = true)) {
val about_us = Intent(this@Aware_Participant, About::class.java)
startActivity(about_us)
}
if (item.title.toString().equals(resources.getString(R.string.aware_sync), ignoreCase = true)) {
Toast.makeText(applicationContext, "Syncing data...", Toast.LENGTH_SHORT).show()
val sync = Intent(Aware.ACTION_AWARE_SYNC_DATA)
sendBroadcast(sync)
}
return super.onOptionsItemSelected(item)
}
}
4 changes: 2 additions & 2 deletions aware-phone/src/main/res/layout/aware_join_study.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,15 @@
android:textSize="16dp"
android:textStyle="bold" />

<android.support.v7.widget.RecyclerView
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv_plugins"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:padding="5dp"
android:scrollbars="vertical">

</android.support.v7.widget.RecyclerView>
</androidx.recyclerview.widget.RecyclerView>
</LinearLayout>

</LinearLayout>
Expand Down
48 changes: 48 additions & 0 deletions aware-phone/src/main/res/layout/aware_ui_participant.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/aware_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Study ID"
android:textAppearance="@style/Base.TextAppearance.AppCompat.Title" />

<TextView
android:id="@+id/study_url"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Device ID"
android:textAppearance="@style/Base.TextAppearance.AppCompat.Title" />

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/device_id"
android:text="Device ID" />

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Device name"
android:textAppearance="@style/Base.TextAppearance.AppCompat.Title" />

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/device_name" />

</LinearLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ buildscript {
mqtt_libs = '1.2.1'
ion_libs = "2.+"
google_libs = "17.0.0"
version_code = 816
version_code = 817
version_readable = "4.0." + version_code + "." + "bundle"
compile_sdk = 28
target_sdk = 28
Expand All @@ -13,6 +13,7 @@ buildscript {
aware_libs = "master-SNAPSHOT"
kotlin_version = "1.3.41"
build_gradle = "3.4.2"
anko_version = "0.10.8"
}

repositories {
Expand Down

0 comments on commit aca3184

Please sign in to comment.