summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlindatseng <lindatseng@google.com>2020-10-02 17:33:54 -0700
committerlindatseng <lindatseng@google.com>2020-10-05 09:47:50 -0700
commit646181f4dd10e51404768d2883389b2617cb6db6 (patch)
treed6b1101422986a4621e4ddc97c1dfb04f0bb6d77
parent8aa4aa8104bdc44ee086d5519ef3c9e811e33a46 (diff)
downloadEmergencyInfo-646181f4dd10e51404768d2883389b2617cb6db6.tar.gz
Add skeleton activity for handling emergency
action (Will be launched by panic gesture) Screenshot: https://screenshot.googleplex.com/9w5pNam5ETJwvGf.png Bug: 169946301 Test: atest EmergencyActionActivityTest Change-Id: I8656538d5583454430326fdee8f07a33b31e712d
-rw-r--r--Android.bp1
-rw-r--r--AndroidManifest.xml25
-rw-r--r--res/layout/emergency_action_activity.xml23
-rw-r--r--res/layout/emergency_action_fragment.xml35
-rw-r--r--res/values/colors.xml3
-rw-r--r--res/values/strings.xml3
-rw-r--r--res/values/styles.xml6
-rw-r--r--src/com/android/emergency/action/EmergencyActionActivity.java54
-rw-r--r--src/com/android/emergency/action/EmergencyActionFragment.java39
-rw-r--r--tests/robolectric/src/com/android/emergency/action/EmergencyActionActivityTest.java53
10 files changed, 241 insertions, 1 deletions
diff --git a/Android.bp b/Android.bp
index d2de99b6..678582f6 100644
--- a/Android.bp
+++ b/Android.bp
@@ -34,6 +34,7 @@ android_library {
resource_dirs: ["res"],
srcs: ["src/**/*.java"],
static_libs: [
+ "android-support-v4",
"androidx.legacy_legacy-preference-v14",
"androidx.legacy_legacy-support-v13",
"androidx.appcompat_appcompat",
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index b58f327b..2bff9bdb 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -15,6 +15,7 @@
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:tools="http://schemas.android.com/tools"
package="com.android.emergency"
android:sharedUserId="com.android.emergency.uid">
@@ -42,7 +43,9 @@
android:icon="@mipmap/ic_local_hospital_24dp"
android:directBootAware="true"
android:label="@string/app_label"
- android:supportsRtl="true">
+ android:supportsRtl="true"
+ android:appComponentFactory="androidx.core.app.CoreComponentFactory"
+ tools:replace="android:appComponentFactory">
<activity android:name=".view.ViewInfoActivity"
android:theme="@style/AppThemeEmergency"
android:taskAffinity="com.android.settings"
@@ -117,6 +120,26 @@
</intent-filter>
</activity>
+ <activity-alias android:name=".action.EmergencyAction"
+ android:label="Emergency Action"
+ android:targetActivity=".action.EmergencyActionActivity"
+ android:permission="android.permission.MANAGE_SENSOR_PRIVACY"
+ android:enabled="true"
+ android:exported="true">
+
+ <intent-filter>
+ <!-- TODO (b/169175022) Update action name and docs when feature name is locked -->
+ <action android:name="com.android.systemui.action.LAUNCH_EMERGENCY"/>
+ </intent-filter>
+ </activity-alias>
+
+ <activity android:name=".action.EmergencyActionActivity"
+ android:label="Emergency Action"
+ android:theme="@style/AppThemeEmergencyAction"
+ android:showWhenLocked="true"
+ android:exported="false">
+ </activity>
+
<provider android:name=".EmergencySearchIndexablesProvider"
android:authorities="com.android.emergency"
android:multiprocess="false"
diff --git a/res/layout/emergency_action_activity.xml b/res/layout/emergency_action_activity.xml
new file mode 100644
index 00000000..3d2f1c20
--- /dev/null
+++ b/res/layout/emergency_action_activity.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ ~ Copyright (C) 2020 The Android Open Source Project
+ ~
+ ~ Licensed under the Apache License, Version 2.0 (the "License");
+ ~ you may not use this file except in compliance with the License.
+ ~ You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ -->
+
+<FrameLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@android:id/content"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:fitsSystemWindows="true"/> \ No newline at end of file
diff --git a/res/layout/emergency_action_fragment.xml b/res/layout/emergency_action_fragment.xml
new file mode 100644
index 00000000..c49aac37
--- /dev/null
+++ b/res/layout/emergency_action_fragment.xml
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2020 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<LinearLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:orientation="vertical"
+ android:background="@android:color/black">
+
+ <TextView
+ android:id="@+id/title"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_marginTop="64dp"
+ android:text="@string/emergency_action_title"
+ android:fontFamily="sans-serif"
+ android:textSize="24sp"
+ android:lineHeight="32dp"
+ android:textColor="@color/emergency_action_title_color"
+ android:textAlignment="center"/>
+
+</LinearLayout> \ No newline at end of file
diff --git a/res/values/colors.xml b/res/values/colors.xml
index 9d0aa89c..606ebce2 100644
--- a/res/values/colors.xml
+++ b/res/values/colors.xml
@@ -27,4 +27,7 @@
<color name="primary_dark_color">@color/material_grey_300</color>
<color name="accent_color_light">@color/accent_material_light</color>
<color name="accent_color_dark">@color/accent_material_dark</color>
+
+ <color name="emergency_action_title_color">#F28B82</color>
+
</resources>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 71e475ef..4f409ea4 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -226,4 +226,7 @@
<string name="user_image_photo_selector">Select photo</string>
<!-- Title for the preference to enter the nickname of the user to display in the user switcher [CHAR LIMIT=25]-->
<string name="user_nickname">Nickname</string>
+
+ <!-- Title for the emergency action view. [CHAR LIMIT=25]-->
+ <string name="emergency_action_title">Emergency SOS</string>
</resources>
diff --git a/res/values/styles.xml b/res/values/styles.xml
index e3b83bbb..12ed6083 100644
--- a/res/values/styles.xml
+++ b/res/values/styles.xml
@@ -31,6 +31,12 @@
<item name="preferenceTheme">@style/PreferenceTheme</item>
</style>
+ <!-- Base emergency theme. -->
+ <style name="AppThemeEmergencyAction" parent="Theme.AppCompat.Light.NoActionBar">
+ <item name="colorPrimaryDark">@android:color/black</item>
+ <item name="colorPrimary">@color/primary_dark_color</item>
+ </style>
+
<!-- ActionBar -->
<style name="ActionBarThemeOverlay" parent="ThemeOverlay.AppCompat.ActionBar">
<item name="colorAccent">@color/accent_color_dark</item>
diff --git a/src/com/android/emergency/action/EmergencyActionActivity.java b/src/com/android/emergency/action/EmergencyActionActivity.java
new file mode 100644
index 00000000..f15f3037
--- /dev/null
+++ b/src/com/android/emergency/action/EmergencyActionActivity.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.emergency.action;
+
+import android.annotation.Nullable;
+import android.app.Activity;
+import android.os.Bundle;
+import android.support.v4.app.FragmentActivity;
+import android.view.WindowInsets;
+import android.view.WindowInsetsController;
+
+import com.android.emergency.R;
+
+/**
+ * Activity for handling emergency action.
+ */
+public class EmergencyActionActivity extends FragmentActivity {
+
+ @Override
+ protected void onCreate(@Nullable Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.emergency_action_activity);
+
+ getWindow().setDecorFitsSystemWindows(false);
+ WindowInsetsController controller = getWindow().getInsetsController();
+ if (controller != null) {
+ controller.hide(WindowInsets.Type.statusBars() | WindowInsets.Type.navigationBars());
+ controller.setSystemBarsBehavior(
+ WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE);
+ }
+
+ if (savedInstanceState == null) {
+ EmergencyActionFragment albumFragment = new EmergencyActionFragment();
+ getSupportFragmentManager().beginTransaction().add(android.R.id.content,
+ albumFragment).commit();
+ }
+
+
+ }
+}
diff --git a/src/com/android/emergency/action/EmergencyActionFragment.java b/src/com/android/emergency/action/EmergencyActionFragment.java
new file mode 100644
index 00000000..98bf9a57
--- /dev/null
+++ b/src/com/android/emergency/action/EmergencyActionFragment.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.emergency.action;
+
+import android.os.Bundle;
+import android.support.v4.app.Fragment;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+import androidx.annotation.UiThread;
+
+import com.android.emergency.R;
+
+@UiThread
+public class EmergencyActionFragment extends Fragment {
+
+ @Override
+ public View onCreateView(@NonNull LayoutInflater inflater,
+ @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
+ return inflater.inflate(R.layout.emergency_action_fragment, container, false);
+ }
+}
diff --git a/tests/robolectric/src/com/android/emergency/action/EmergencyActionActivityTest.java b/tests/robolectric/src/com/android/emergency/action/EmergencyActionActivityTest.java
new file mode 100644
index 00000000..e046938d
--- /dev/null
+++ b/tests/robolectric/src/com/android/emergency/action/EmergencyActionActivityTest.java
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.emergency.action;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import android.content.Context;
+import android.content.Intent;
+import android.content.pm.PackageManager;
+import android.content.pm.ResolveInfo;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.RobolectricTestRunner;
+import org.robolectric.RuntimeEnvironment;
+
+@RunWith(RobolectricTestRunner.class)
+public class EmergencyActionActivityTest {
+
+ private Context mContext;
+
+ @Before
+ public void setUp() {
+ mContext = RuntimeEnvironment.application;
+ }
+
+ @Test
+ public void shouldHandleIntentAction() {
+ PackageManager packageManager = mContext.getPackageManager();
+
+ Intent intent = new Intent("android.intent.action.EMERGENCY");
+ ResolveInfo resolveInfo =
+ packageManager.resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY);
+ assertThat(resolveInfo).isNotNull();
+ assertThat(resolveInfo.activityInfo.targetActivity)
+ .isEqualTo(EmergencyActionActivity.class.getName());
+ }
+}