diff --git a/android-app-core/res/layout/cpp_simple_keyboard_lockscreen.xml b/android-app-core/res/layout/cpp_simple_keyboard_lockscreen.xml
new file mode 100644
index 00000000..297f86f8
--- /dev/null
+++ b/android-app-core/res/layout/cpp_simple_keyboard_lockscreen.xml
@@ -0,0 +1,105 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/android-app-core/res/layout/cpp_simple_keyboard_lockscreen_collapsed.xml b/android-app-core/res/layout/cpp_simple_keyboard_lockscreen_collapsed.xml
new file mode 100644
index 00000000..ec2ae6e6
--- /dev/null
+++ b/android-app-core/res/layout/cpp_simple_keyboard_lockscreen_collapsed.xml
@@ -0,0 +1,86 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/android-app-widget/res/layout/widget_layout_lockscreen.xml b/android-app-widget/res/layout/widget_layout_lockscreen.xml
new file mode 100644
index 00000000..f191b35c
--- /dev/null
+++ b/android-app-widget/res/layout/widget_layout_lockscreen.xml
@@ -0,0 +1,41 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/android-app-widget/res/layout/widget_layout_lockscreen_collapsed.xml b/android-app-widget/res/layout/widget_layout_lockscreen_collapsed.xml
new file mode 100644
index 00000000..2f5799a6
--- /dev/null
+++ b/android-app-widget/res/layout/widget_layout_lockscreen_collapsed.xml
@@ -0,0 +1,58 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/android-app-widget/res/values/dimens.xml b/android-app-widget/res/values/dimens.xml
index 77ae2926..3f631a5a 100644
--- a/android-app-widget/res/values/dimens.xml
+++ b/android-app-widget/res/values/dimens.xml
@@ -1,6 +1,9 @@
+ 16sp
25sp
+ 16sp
25sp
6dp
+ 300dp
\ No newline at end of file
diff --git a/android-app-widget/src/main/java/org/solovyev/android/calculator/widget/AbstractCalculatorWidgetProvider.java b/android-app-widget/src/main/java/org/solovyev/android/calculator/widget/AbstractCalculatorWidgetProvider.java
index b5ee508b..ae492696 100644
--- a/android-app-widget/src/main/java/org/solovyev/android/calculator/widget/AbstractCalculatorWidgetProvider.java
+++ b/android-app-widget/src/main/java/org/solovyev/android/calculator/widget/AbstractCalculatorWidgetProvider.java
@@ -28,6 +28,9 @@ import android.appwidget.AppWidgetProvider;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
+import android.content.res.Resources;
+import android.os.Build;
+import android.os.Bundle;
import android.text.Html;
import android.widget.RemoteViews;
import org.solovyev.android.calculator.*;
@@ -48,6 +51,9 @@ import static org.solovyev.android.calculator.CalculatorReceiver.newButtonClicke
abstract class AbstractCalculatorWidgetProvider extends AppWidgetProvider {
private static final String TAG = "Calculator++ Widget";
+ private static final int WIDGET_CATEGORY_KEYGUARD = 2;
+ private static final String OPTION_APPWIDGET_HOST_CATEGORY = "appWidgetCategory";
+ private static final String ACTION_APPWIDGET_OPTIONS_CHANGED = "android.appwidget.action.APPWIDGET_UPDATE_OPTIONS";
/*
**********************************************************************
@@ -119,8 +125,9 @@ abstract class AbstractCalculatorWidgetProvider extends AppWidgetProvider {
final CalculatorEditorViewState editorState = Locator.getInstance().getEditor().getViewState();
final CalculatorDisplayViewState displayState = Locator.getInstance().getDisplay().getViewState();
+ final Resources resources = context.getResources();
for (int appWidgetId : appWidgetIds) {
- final RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_layout);
+ final RemoteViews views = new RemoteViews(context.getPackageName(), getLayout(appWidgetManager, appWidgetId, resources));
for (CalculatorButton button : CalculatorButton.values()) {
final PendingIntent pendingIntent = PendingIntent.getBroadcast(context, button.getButtonId(), newButtonClickedIntent(context, button), PendingIntent.FLAG_UPDATE_CURRENT);
@@ -138,6 +145,33 @@ abstract class AbstractCalculatorWidgetProvider extends AppWidgetProvider {
}
}
+ private int getLayout(@Nonnull AppWidgetManager appWidgetManager, int appWidgetId, @Nonnull Resources resources) {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
+ final Bundle options = appWidgetManager.getAppWidgetOptions(appWidgetId);
+
+ if (options != null) {
+ // Get the value of OPTION_APPWIDGET_HOST_CATEGORY
+ final int category = options.getInt(OPTION_APPWIDGET_HOST_CATEGORY, -1);
+
+ if (category != -1) {
+ // If the value is WIDGET_CATEGORY_KEYGUARD, it's a lockscreen widget
+ final boolean keyguard = category == WIDGET_CATEGORY_KEYGUARD;
+ if(keyguard) {
+ final int minHeightDp = options.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT, -1);
+ final int minHeight = resources.getDimensionPixelSize(R.dimen.min_expanded_height_lock_screen);
+ final boolean expanded = (minHeightDp >= minHeight / resources.getDisplayMetrics().density);
+ if (expanded) {
+ return R.layout.widget_layout_lockscreen;
+ } else {
+ return R.layout.widget_layout_lockscreen_collapsed;
+ }
+ }
+ }
+ }
+ }
+ return R.layout.widget_layout;
+ }
+
@Override
public void onReceive(Context context, Intent intent) {
super.onReceive(context, intent);
@@ -149,6 +183,8 @@ abstract class AbstractCalculatorWidgetProvider extends AppWidgetProvider {
updateState(context);
} else if (ACTION_DISPLAY_STATE_CHANGED.equals(action)) {
updateState(context);
+ } else if (ACTION_APPWIDGET_OPTIONS_CHANGED.equals(action)) {
+ updateState(context);
}
}
diff --git a/android-app/res/xml/calculator_widget_info_3x3.xml b/android-app/res/xml/calculator_widget_info_3x3.xml
index 80d33ce9..8ca2536e 100644
--- a/android-app/res/xml/calculator_widget_info_3x3.xml
+++ b/android-app/res/xml/calculator_widget_info_3x3.xml
@@ -26,6 +26,8 @@
a:minWidth="180dp"
a:minHeight="180dp"
a:initialLayout="@layout/widget_layout"
+ a:initialKeyguardLayout="@layout/widget_layout_lockscreen"
+ a:widgetCategory="home_screen|keyguard"
a:previewImage="@drawable/widget_preview"
a:resizeMode="horizontal|vertical">
diff --git a/android-app/res/xml/calculator_widget_info_3x4.xml b/android-app/res/xml/calculator_widget_info_3x4.xml
index bd3e878b..c19ef448 100644
--- a/android-app/res/xml/calculator_widget_info_3x4.xml
+++ b/android-app/res/xml/calculator_widget_info_3x4.xml
@@ -26,6 +26,8 @@
a:minWidth="180dp"
a:minHeight="250dp"
a:initialLayout="@layout/widget_layout"
+ a:initialKeyguardLayout="@layout/widget_layout_lockscreen"
+ a:widgetCategory="home_screen|keyguard"
a:previewImage="@drawable/widget_preview"
a:resizeMode="horizontal|vertical">
diff --git a/android-app/res/xml/calculator_widget_info_4x4.xml b/android-app/res/xml/calculator_widget_info_4x4.xml
index 89585b63..99425b46 100644
--- a/android-app/res/xml/calculator_widget_info_4x4.xml
+++ b/android-app/res/xml/calculator_widget_info_4x4.xml
@@ -26,6 +26,8 @@
a:minWidth="250dp"
a:minHeight="250dp"
a:initialLayout="@layout/widget_layout"
+ a:initialKeyguardLayout="@layout/widget_layout_lockscreen"
+ a:widgetCategory="home_screen|keyguard"
a:previewImage="@drawable/widget_preview"
a:resizeMode="horizontal|vertical">
diff --git a/android-app/res/xml/calculator_widget_info_4x5.xml b/android-app/res/xml/calculator_widget_info_4x5.xml
index a64b34a4..1c71062e 100644
--- a/android-app/res/xml/calculator_widget_info_4x5.xml
+++ b/android-app/res/xml/calculator_widget_info_4x5.xml
@@ -26,6 +26,8 @@
a:minWidth="250dp"
a:minHeight="320dp"
a:initialLayout="@layout/widget_layout"
+ a:initialKeyguardLayout="@layout/widget_layout_lockscreen"
+ a:widgetCategory="home_screen|keyguard"
a:previewImage="@drawable/widget_preview"
a:resizeMode="horizontal|vertical">