summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Henigan <robert.henigan@livio.io>2020-05-29 12:47:39 -0400
committerGitHub <noreply@github.com>2020-05-29 12:47:39 -0400
commit230737e50c21d7de5e25f8fdb3ac1a8c77d06aff (patch)
tree5ec978030d3a8cbe2775d3a40f8b5cab288761d8
parent62c69338e73872536d3b5b1e36b8909025878309 (diff)
parent38324c820fb86cb842e0b42a886db5afb0f8b6fa (diff)
downloadsdl_android-230737e50c21d7de5e25f8fdb3ac1a8c77d06aff.tar.gz
Merge pull request #1355 from smartdevicelink/ios_Alignment/LockScreen
iOS alignment/lock screen
-rw-r--r--android/sdl_android/src/main/java/com/smartdevicelink/managers/lockscreen/SDLLockScreenActivity.java95
-rw-r--r--android/sdl_android/src/main/res/drawable-hdpi/sdl_lockscreen_icon.pngbin2570 -> 2531 bytes
-rw-r--r--android/sdl_android/src/main/res/drawable-mdpi/sdl_lockscreen_icon.pngbin1791 -> 1461 bytes
-rw-r--r--android/sdl_android/src/main/res/drawable-xhdpi/sdl_lockscreen_icon.pngbin3487 -> 3207 bytes
-rw-r--r--android/sdl_android/src/main/res/drawable-xxhdpi/sdl_lockscreen_icon.pngbin5172 -> 4680 bytes
-rw-r--r--android/sdl_android/src/main/res/drawable-xxxhdpi/sdl_lockscreen_icon.pngbin6666 -> 6160 bytes
-rw-r--r--android/sdl_android/src/main/res/layout/activity_sdllock_screen.xml14
7 files changed, 98 insertions, 11 deletions
diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/managers/lockscreen/SDLLockScreenActivity.java b/android/sdl_android/src/main/java/com/smartdevicelink/managers/lockscreen/SDLLockScreenActivity.java
index d87d27ca2..a1af673a2 100644
--- a/android/sdl_android/src/main/java/com/smartdevicelink/managers/lockscreen/SDLLockScreenActivity.java
+++ b/android/sdl_android/src/main/java/com/smartdevicelink/managers/lockscreen/SDLLockScreenActivity.java
@@ -38,9 +38,14 @@ import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.Bitmap;
+import android.graphics.Color;
+import android.graphics.ColorFilter;
+import android.graphics.ColorMatrixColorFilter;
+import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.GestureDetector;
import android.view.MotionEvent;
+import android.view.View;
import android.view.Window;
import android.widget.ImageView;
import android.widget.RelativeLayout;
@@ -64,6 +69,9 @@ public class SDLLockScreenActivity extends Activity {
private static final int MIN_SWIPE_DISTANCE = 200;
private boolean mIsDismissible;
private GestureDetector mGestureDetector;
+ private int backgroundColor = Color.parseColor("#394e60");
+ private boolean useWhiteIconAndTextColor;
+
private final BroadcastReceiver lockScreenBroadcastReceiver = new BroadcastReceiver() {
@Override
@@ -137,18 +145,20 @@ public class SDLLockScreenActivity extends Activity {
int customIcon = intent.getIntExtra(LOCKSCREEN_ICON_EXTRA, 0);
int customView = intent.getIntExtra(LOCKSCREEN_CUSTOM_VIEW_EXTRA, 0);
Bitmap deviceIcon = intent.getParcelableExtra(LOCKSCREEN_DEVICE_LOGO_BITMAP);
+ backgroundColor = (customColor != 0) ? customColor : backgroundColor;
if (customView != 0){
setCustomView(customView);
} else {
setContentView(R.layout.activity_sdllock_screen);
+ setBackgroundColor();
+ useWhiteIconAndTextColor = shouldUseWhiteForegroundForBackgroundColor();
- if (customColor != 0){
- changeBackgroundColor(customColor);
- }
-
+ // set Lock Screen Icon
if (customIcon != 0){
changeIcon(customIcon);
+ } else {
+ setSdlLogo();
}
if (deviceLogoEnabled && deviceIcon != null){
@@ -158,19 +168,85 @@ public class SDLLockScreenActivity extends Activity {
String warningMsg = intent.getStringExtra(KEY_LOCKSCREEN_WARNING_MSG);
if (mIsDismissible) {
setLockscreenWarningMessage(warningMsg);
+ } else if (!useWhiteIconAndTextColor) {
+ setTextColorBlack();
}
}
}
}
- private void changeBackgroundColor(int customColor) {
+ /**
+ * Sets the lockScreen logo
+ */
+ private void setSdlLogo() {
+ ImageView lockScreen_iv = findViewById(R.id.lockscreen_image);
+ Drawable sdlIcon = getResources().getDrawable(R.drawable.sdl_lockscreen_icon);
+ // Checks color contrast and determines if the logo should be black or white
+ if (useWhiteIconAndTextColor) {
+ int color = Color.parseColor("#ffffff");
+
+ int red = (color & 0xFF0000) / 0xFFFF;
+ int green = (color & 0xFF00) / 0xFF;
+ int blue = color & 0xFF;
+
+ float[] matrix = {0, 0, 0, 0, red,
+ 0, 0, 0, 0, green,
+ 0, 0, 0, 0, blue,
+ 0, 0, 0, 1, 0};
+
+ ColorFilter colorFilter = new ColorMatrixColorFilter(matrix);
+ sdlIcon.setColorFilter(colorFilter);
+ }
+ lockScreen_iv.setImageDrawable(sdlIcon);
+ }
+
+ /**
+ * Changes the text color to white on the lockScreen
+ */
+ private void setTextColorBlack() {
+ TextView tv = findViewById(R.id.lockscreen_text);
+ tv.setTextColor(Color.parseColor("#000000"));
+ }
+
+ /**
+ * Calculates the contrast of the background to determine if the Icon and Text color
+ * should be white or black
+ * @return True if Background and Icon should be white, False if black
+ */
+ private boolean shouldUseWhiteForegroundForBackgroundColor() {
+ float r = Color.red(backgroundColor) / 255f;
+ float b = Color.blue(backgroundColor) / 255f;
+ float g = Color.green(backgroundColor) / 255f;
+
+ // http://stackoverflow.com/a/3943023
+ r = (r <= 0.3928f) ? (r / 12.92f) : (float) Math.pow(((r + 0.055f) / 1.055f), 2.4f);
+ g = (g <= 0.3928f) ? (g / 12.92f) : (float) Math.pow(((g + 0.055f) / 1.055f), 2.4f);
+ b = (b <= 0.3928f) ? (b / 12.92f) : (float) Math.pow(((b + 0.055f) / 1.055f), 2.4f);
+
+ float luminescence = 0.2126f * r + 0.7152f * g + 0.0722f * b;
+ return luminescence <= 0.179;
+ }
+
+ /**
+ * Sets the color of the background
+ * Will use default color if not set in LockScreenConfig
+ */
+ private void setBackgroundColor() {
RelativeLayout layout = findViewById(R.id.lockscreen_relative_layout);
- layout.setBackgroundColor(getResources().getColor(customColor));
+ layout.setBackgroundColor(backgroundColor);
}
+ /**
+ * Used to change LockScreen default Icon to customIcon set in LockScreenConfig
+ * @param customIcon
+ */
private void changeIcon(int customIcon) {
- ImageView lockscreen_iv = findViewById(R.id.lockscreen_image);
- lockscreen_iv.setBackgroundResource(customIcon);
+ ImageView lockScreen_iv = findViewById(R.id.lockscreen_image);
+ lockScreen_iv.setVisibility(View.GONE);
+
+ ImageView lockScreenCustom_iv = findViewById(R.id.appIcon);
+ lockScreenCustom_iv.setVisibility(View.VISIBLE);
+ lockScreenCustom_iv.setBackgroundResource(customIcon);
}
private void setDeviceLogo(Bitmap deviceLogo) {
@@ -183,6 +259,9 @@ public class SDLLockScreenActivity extends Activity {
private void setLockscreenWarningMessage(String msg) {
TextView tv = findViewById(R.id.lockscreen_text);
if (tv != null) {
+ if (!useWhiteIconAndTextColor) {
+ tv.setTextColor(Color.parseColor("#000000"));
+ }
tv.setText(msg != null ? msg : getString(R.string.default_lockscreen_warning_message));
}
}
diff --git a/android/sdl_android/src/main/res/drawable-hdpi/sdl_lockscreen_icon.png b/android/sdl_android/src/main/res/drawable-hdpi/sdl_lockscreen_icon.png
index 625eb35ea..a5fa05f58 100644
--- a/android/sdl_android/src/main/res/drawable-hdpi/sdl_lockscreen_icon.png
+++ b/android/sdl_android/src/main/res/drawable-hdpi/sdl_lockscreen_icon.png
Binary files differ
diff --git a/android/sdl_android/src/main/res/drawable-mdpi/sdl_lockscreen_icon.png b/android/sdl_android/src/main/res/drawable-mdpi/sdl_lockscreen_icon.png
index d13a55e0b..a254d37ec 100644
--- a/android/sdl_android/src/main/res/drawable-mdpi/sdl_lockscreen_icon.png
+++ b/android/sdl_android/src/main/res/drawable-mdpi/sdl_lockscreen_icon.png
Binary files differ
diff --git a/android/sdl_android/src/main/res/drawable-xhdpi/sdl_lockscreen_icon.png b/android/sdl_android/src/main/res/drawable-xhdpi/sdl_lockscreen_icon.png
index d7de7cabe..ef2574797 100644
--- a/android/sdl_android/src/main/res/drawable-xhdpi/sdl_lockscreen_icon.png
+++ b/android/sdl_android/src/main/res/drawable-xhdpi/sdl_lockscreen_icon.png
Binary files differ
diff --git a/android/sdl_android/src/main/res/drawable-xxhdpi/sdl_lockscreen_icon.png b/android/sdl_android/src/main/res/drawable-xxhdpi/sdl_lockscreen_icon.png
index bd0c40e67..f03e41322 100644
--- a/android/sdl_android/src/main/res/drawable-xxhdpi/sdl_lockscreen_icon.png
+++ b/android/sdl_android/src/main/res/drawable-xxhdpi/sdl_lockscreen_icon.png
Binary files differ
diff --git a/android/sdl_android/src/main/res/drawable-xxxhdpi/sdl_lockscreen_icon.png b/android/sdl_android/src/main/res/drawable-xxxhdpi/sdl_lockscreen_icon.png
index 21962c148..7a1cde649 100644
--- a/android/sdl_android/src/main/res/drawable-xxxhdpi/sdl_lockscreen_icon.png
+++ b/android/sdl_android/src/main/res/drawable-xxxhdpi/sdl_lockscreen_icon.png
Binary files differ
diff --git a/android/sdl_android/src/main/res/layout/activity_sdllock_screen.xml b/android/sdl_android/src/main/res/layout/activity_sdllock_screen.xml
index 43b5e6840..ce287ed04 100644
--- a/android/sdl_android/src/main/res/layout/activity_sdllock_screen.xml
+++ b/android/sdl_android/src/main/res/layout/activity_sdllock_screen.xml
@@ -1,8 +1,7 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/lockscreen_relative_layout"
android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:background="#2c3d4d">
+ android:layout_height="fill_parent">
<LinearLayout
android:id="@+id/lockscreen_linear_layout"
@@ -13,12 +12,21 @@
<ImageView
android:id="@+id/lockscreen_image"
+ android:layout_width="187dp"
+ android:layout_height="78dp"
+ android:scaleType="fitXY"
+ android:layout_gravity="center_horizontal"
+ android:contentDescription="@string/lockscreen_image_description"
+ android:adjustViewBounds="true" />
+
+ <ImageView
+ android:id="@+id/appIcon"
android:layout_width="120dp"
android:layout_height="120dp"
android:scaleType="fitXY"
android:layout_gravity="center_horizontal"
android:contentDescription="@string/lockscreen_image_description"
- android:background="@drawable/sdl_lockscreen_icon"/>
+ android:visibility="gone"/>
<ImageView
android:id="@+id/device_image"