Lockscreen widget
This commit is contained in:
parent
323804484f
commit
6e1fb64774
105
android-app-core/res/layout/cpp_simple_keyboard_lockscreen.xml
Normal file
105
android-app-core/res/layout/cpp_simple_keyboard_lockscreen.xml
Normal file
@ -0,0 +1,105 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<!--
|
||||
~ Copyright 2013 serso aka se.solovyev
|
||||
~
|
||||
~ 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.
|
||||
~
|
||||
~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
~ Contact details
|
||||
~
|
||||
~ Email: se.solovyev@gmail.com
|
||||
~ Site: http://se.solovyev.org
|
||||
-->
|
||||
|
||||
<LinearLayout xmlns:a="http://schemas.android.com/apk/res/android"
|
||||
a:layout_width="match_parent"
|
||||
a:layout_height="match_parent"
|
||||
a:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
a:layout_weight="1"
|
||||
a:layout_width="match_parent"
|
||||
a:layout_height="0dp">
|
||||
|
||||
<include layout="@layout/cpp_simple_button_7"/>
|
||||
|
||||
<include layout="@layout/cpp_simple_button_8"/>
|
||||
|
||||
<include layout="@layout/cpp_simple_button_9"/>
|
||||
|
||||
<include layout="@layout/cpp_simple_button_multiplication"/>
|
||||
|
||||
<include layout="@layout/cpp_simple_button_percent"/>
|
||||
|
||||
<include layout="@layout/cpp_simple_button_clear"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
a:layout_weight="1"
|
||||
a:layout_width="match_parent"
|
||||
a:layout_height="0dp">
|
||||
|
||||
<include layout="@layout/cpp_simple_button_4"/>
|
||||
|
||||
<include layout="@layout/cpp_simple_button_5"/>
|
||||
|
||||
<include layout="@layout/cpp_simple_button_6"/>
|
||||
|
||||
<include layout="@layout/cpp_simple_button_division"/>
|
||||
|
||||
<include layout="@layout/cpp_simple_button_power"/>
|
||||
|
||||
<include layout="@layout/cpp_simple_button_erase"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
a:layout_weight="1"
|
||||
a:layout_width="match_parent"
|
||||
a:layout_height="0dp">
|
||||
|
||||
<include layout="@layout/cpp_simple_button_1"/>
|
||||
|
||||
<include layout="@layout/cpp_simple_button_2"/>
|
||||
|
||||
<include layout="@layout/cpp_simple_button_3"/>
|
||||
|
||||
<include layout="@layout/cpp_simple_button_plus"/>
|
||||
|
||||
<include layout="@layout/cpp_simple_button_left"/>
|
||||
|
||||
<include layout="@layout/cpp_simple_button_copy"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
a:layout_weight="1"
|
||||
a:layout_width="match_parent"
|
||||
a:layout_height="0dp">
|
||||
|
||||
<include layout="@layout/cpp_simple_button_round_brackets"/>
|
||||
|
||||
<include layout="@layout/cpp_simple_button_0"/>
|
||||
|
||||
<include layout="@layout/cpp_simple_button_dot"/>
|
||||
|
||||
<include layout="@layout/cpp_simple_button_subtraction"/>
|
||||
|
||||
<include layout="@layout/cpp_simple_button_right"/>
|
||||
|
||||
<include layout="@layout/cpp_simple_button_paste"/>
|
||||
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
@ -0,0 +1,86 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<!--
|
||||
~ Copyright 2013 serso aka se.solovyev
|
||||
~
|
||||
~ 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.
|
||||
~
|
||||
~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
~ Contact details
|
||||
~
|
||||
~ Email: se.solovyev@gmail.com
|
||||
~ Site: http://se.solovyev.org
|
||||
-->
|
||||
|
||||
<LinearLayout xmlns:a="http://schemas.android.com/apk/res/android"
|
||||
a:layout_width="match_parent"
|
||||
a:layout_height="match_parent"
|
||||
a:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
a:layout_weight="1"
|
||||
a:layout_width="match_parent"
|
||||
a:layout_height="0dp">
|
||||
|
||||
<include layout="@layout/cpp_simple_button_7"/>
|
||||
|
||||
<include layout="@layout/cpp_simple_button_8"/>
|
||||
|
||||
<include layout="@layout/cpp_simple_button_9"/>
|
||||
|
||||
<include layout="@layout/cpp_simple_button_multiplication"/>
|
||||
|
||||
<include layout="@layout/cpp_simple_button_plus"/>
|
||||
|
||||
<include layout="@layout/cpp_simple_button_clear"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
a:layout_weight="1"
|
||||
a:layout_width="match_parent"
|
||||
a:layout_height="0dp">
|
||||
|
||||
<include layout="@layout/cpp_simple_button_4"/>
|
||||
|
||||
<include layout="@layout/cpp_simple_button_5"/>
|
||||
|
||||
<include layout="@layout/cpp_simple_button_6"/>
|
||||
|
||||
<include layout="@layout/cpp_simple_button_division"/>
|
||||
|
||||
<include layout="@layout/cpp_simple_button_subtraction"/>
|
||||
|
||||
<include layout="@layout/cpp_simple_button_erase"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
a:layout_weight="1"
|
||||
a:layout_width="match_parent"
|
||||
a:layout_height="0dp">
|
||||
|
||||
<include layout="@layout/cpp_simple_button_1"/>
|
||||
|
||||
<include layout="@layout/cpp_simple_button_2"/>
|
||||
|
||||
<include layout="@layout/cpp_simple_button_3"/>
|
||||
|
||||
<include layout="@layout/cpp_simple_button_0"/>
|
||||
|
||||
<include layout="@layout/cpp_simple_button_percent"/>
|
||||
|
||||
<include layout="@layout/cpp_simple_button_dot"/>
|
||||
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
41
android-app-widget/res/layout/widget_layout_lockscreen.xml
Normal file
41
android-app-widget/res/layout/widget_layout_lockscreen.xml
Normal file
@ -0,0 +1,41 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<LinearLayout xmlns:a="http://schemas.android.com/apk/res/android"
|
||||
a:layout_width="match_parent"
|
||||
a:layout_height="match_parent"
|
||||
a:orientation="vertical"
|
||||
style="@style/cpp_widget_main_layout_style">
|
||||
|
||||
<include
|
||||
layout="@layout/widget_editor"
|
||||
a:layout_weight="2"
|
||||
a:layout_width="match_parent"
|
||||
a:layout_height="0dp" />
|
||||
|
||||
<LinearLayout
|
||||
a:layout_weight="1"
|
||||
a:layout_width="match_parent"
|
||||
a:layout_height="0dp">
|
||||
|
||||
<include
|
||||
layout="@layout/cpp_simple_button_equals"
|
||||
a:layout_margin="@dimen/cpp_button_margin"
|
||||
a:layout_weight="1"
|
||||
a:layout_width="0dp"
|
||||
a:layout_height="match_parent" />
|
||||
|
||||
<include
|
||||
layout="@layout/widget_display"
|
||||
a:layout_weight="5"
|
||||
a:layout_width="0dp"
|
||||
a:layout_height="wrap_content" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<include
|
||||
layout="@layout/cpp_simple_keyboard_lockscreen"
|
||||
a:layout_weight="4"
|
||||
a:layout_width="match_parent"
|
||||
a:layout_height="0dp" />
|
||||
|
||||
</LinearLayout>
|
@ -0,0 +1,58 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<LinearLayout xmlns:a="http://schemas.android.com/apk/res/android"
|
||||
a:layout_width="match_parent"
|
||||
a:layout_height="match_parent"
|
||||
a:orientation="vertical"
|
||||
style="@style/cpp_widget_main_layout_style">
|
||||
|
||||
<LinearLayout
|
||||
a:id="@+id/main_fragment_layout"
|
||||
style="@style/cpp_default_fragment_layout_style"
|
||||
a:orientation="horizontal"
|
||||
a:layout_width="match_parent"
|
||||
a:layout_height="0dp"
|
||||
a:layout_weight="2"
|
||||
a:padding="0dp">
|
||||
|
||||
<TextView
|
||||
a:padding="@dimen/cpp_editor_padding"
|
||||
a:layout_weight="3"
|
||||
a:layout_width="0dp"
|
||||
a:id="@+id/calculator_editor"
|
||||
style="@style/cpp_widget_editor_style"
|
||||
a:textSize="@dimen/cpp_widget_editor_text_size_collapsed"
|
||||
a:gravity="center_vertical|left"
|
||||
a:textIsSelectable="true"
|
||||
a:singleLine="false"
|
||||
a:scrollbars="vertical"
|
||||
a:hint="@string/c_calc_editor_hint"/>
|
||||
|
||||
<include
|
||||
layout="@layout/cpp_simple_button_equals"
|
||||
a:layout_margin="@dimen/cpp_button_margin"
|
||||
a:layout_weight="1"
|
||||
a:layout_width="0dp"
|
||||
a:layout_height="match_parent" />
|
||||
|
||||
<TextView
|
||||
a:id="@+id/calculator_display"
|
||||
a:textSize="@dimen/cpp_widget_display_text_size_collapsed"
|
||||
a:layout_weight="2"
|
||||
a:layout_width="0dp"
|
||||
a:layout_height="wrap_content"
|
||||
style="@style/cpp_widget_display_style"
|
||||
a:textIsSelectable="true"
|
||||
a:padding="@dimen/cpp_display_padding"
|
||||
a:singleLine="false"
|
||||
a:scrollbars="vertical"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<include
|
||||
layout="@layout/cpp_simple_keyboard_lockscreen_collapsed"
|
||||
a:layout_weight="4"
|
||||
a:layout_width="match_parent"
|
||||
a:layout_height="0dp" />
|
||||
|
||||
</LinearLayout>
|
@ -1,6 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<dimen name="cpp_widget_editor_text_size_collapsed">16sp</dimen>
|
||||
<dimen name="cpp_widget_editor_text_size">25sp</dimen>
|
||||
<dimen name="cpp_widget_display_text_size_collapsed">16sp</dimen>
|
||||
<dimen name="cpp_widget_display_text_size">25sp</dimen>
|
||||
<dimen name="cpp_widget_margin">6dp</dimen>
|
||||
<dimen name="min_expanded_height_lock_screen">300dp</dimen>
|
||||
</resources>
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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">
|
||||
|
||||
|
@ -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">
|
||||
|
||||
|
@ -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">
|
||||
|
||||
|
@ -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">
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user