commit
d1e4ca91c6
@ -112,6 +112,19 @@
|
|||||||
|
|
||||||
<!-- WIDGET CONFIG -->
|
<!-- WIDGET CONFIG -->
|
||||||
|
|
||||||
|
<receiver android:icon="@drawable/ic_launcher" android:label="@string/c_app_name" android:name=".widget.CalculatorWidget">
|
||||||
|
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.appwidget.action.APPWIDGET_UPDATE"/>
|
||||||
|
<action android:name="org.solovyev.android.calculator.INIT"/>
|
||||||
|
<action android:name="org.solovyev.android.calculator.EDITOR_STATE_CHANGED"/>
|
||||||
|
<action android:name="org.solovyev.android.calculator.DISPLAY_STATE_CHANGED"/>
|
||||||
|
<action android:name="org.solovyev.android.calculator.BUTTON_PRESSED"/>
|
||||||
|
</intent-filter>
|
||||||
|
|
||||||
|
<meta-data android:name="android.appwidget.provider" android:resource="@xml/calculator_widget"/>
|
||||||
|
</receiver>
|
||||||
|
|
||||||
<receiver android:icon="@drawable/ic_launcher" android:label="@string/c_app_widget_3x3_name" android:name=".widget.CalculatorWidgetProvider">
|
<receiver android:icon="@drawable/ic_launcher" android:label="@string/c_app_widget_3x3_name" android:name=".widget.CalculatorWidgetProvider">
|
||||||
|
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
|
@ -23,20 +23,25 @@
|
|||||||
package org.solovyev.android.calculator;
|
package org.solovyev.android.calculator;
|
||||||
|
|
||||||
import android.app.Application;
|
import android.app.Application;
|
||||||
import android.content.Context;
|
import android.appwidget.AppWidgetManager;
|
||||||
|
import android.appwidget.AppWidgetProvider;
|
||||||
|
import android.content.ComponentName;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.text.TextUtils;
|
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
|
import org.solovyev.android.Android;
|
||||||
import org.solovyev.android.UiThreadExecutor;
|
import org.solovyev.android.UiThreadExecutor;
|
||||||
import org.solovyev.android.Views;
|
import org.solovyev.android.Views;
|
||||||
import org.solovyev.android.calculator.ga.Ga;
|
import org.solovyev.android.calculator.ga.Ga;
|
||||||
import org.solovyev.android.calculator.view.ScreenMetrics;
|
import org.solovyev.android.calculator.view.ScreenMetrics;
|
||||||
|
import org.solovyev.android.calculator.widget.BaseCalculatorWidgetProvider;
|
||||||
|
import org.solovyev.android.calculator.widget.CalculatorWidgetProvider;
|
||||||
|
import org.solovyev.android.calculator.widget.CalculatorWidgetProvider3x4;
|
||||||
|
import org.solovyev.android.calculator.widget.CalculatorWidgetProvider4x4;
|
||||||
|
import org.solovyev.android.calculator.widget.CalculatorWidgetProvider4x5;
|
||||||
import org.solovyev.android.checkout.*;
|
import org.solovyev.android.checkout.*;
|
||||||
import org.solovyev.android.view.VibratorContainer;
|
|
||||||
import org.solovyev.common.listeners.JEvent;
|
import org.solovyev.common.listeners.JEvent;
|
||||||
import org.solovyev.common.listeners.JEventListener;
|
import org.solovyev.common.listeners.JEventListener;
|
||||||
import org.solovyev.common.listeners.JEventListeners;
|
import org.solovyev.common.listeners.JEventListeners;
|
||||||
@ -46,7 +51,9 @@ import org.solovyev.common.threads.DelayedExecutor;
|
|||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -62,14 +69,8 @@ import java.util.concurrent.Executor;
|
|||||||
* Before first usage this class must be initialized by calling {@link App#init(android.app.Application)} method (for example, from {@link android.app.Application#onCreate()})
|
* Before first usage this class must be initialized by calling {@link App#init(android.app.Application)} method (for example, from {@link android.app.Application#onCreate()})
|
||||||
*/
|
*/
|
||||||
public final class App {
|
public final class App {
|
||||||
|
@Nonnull
|
||||||
/*
|
private static final List<Class<? extends BaseCalculatorWidgetProvider>> OLD_WIDGETS = Arrays.asList(CalculatorWidgetProvider.class, CalculatorWidgetProvider3x4.class, CalculatorWidgetProvider4x4.class, CalculatorWidgetProvider4x5.class);
|
||||||
**********************************************************************
|
|
||||||
*
|
|
||||||
* FIELDS
|
|
||||||
*
|
|
||||||
**********************************************************************
|
|
||||||
*/
|
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
private static volatile Application application;
|
private static volatile Application application;
|
||||||
@ -166,12 +167,43 @@ public final class App {
|
|||||||
App.broadcaster = new CalculatorBroadcaster(application);
|
App.broadcaster = new CalculatorBroadcaster(application);
|
||||||
App.vibrator = new Vibrator(application, preferences);
|
App.vibrator = new Vibrator(application, preferences);
|
||||||
App.screenMetrics = new ScreenMetrics(application);
|
App.screenMetrics = new ScreenMetrics(application);
|
||||||
|
|
||||||
|
final List<Class<? extends AppWidgetProvider>> oldNotUsedWidgetClasses = findNotUsedWidgets(application);
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1) {
|
||||||
|
for (Class<? extends AppWidgetProvider> oldNotUsedWidgetClass : oldNotUsedWidgetClasses) {
|
||||||
|
Android.enableComponent(application, oldNotUsedWidgetClass, false);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// smaller widgets should be still used for smaller screens
|
||||||
|
if (oldNotUsedWidgetClasses.contains(CalculatorWidgetProvider4x5.class)) {
|
||||||
|
Android.enableComponent(application, CalculatorWidgetProvider4x5.class, false);
|
||||||
|
}
|
||||||
|
if (oldNotUsedWidgetClasses.contains(CalculatorWidgetProvider4x4.class)) {
|
||||||
|
Android.enableComponent(application, CalculatorWidgetProvider4x4.class, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
App.initialized = true;
|
App.initialized = true;
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalStateException("Already initialized!");
|
throw new IllegalStateException("Already initialized!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
|
private static List<Class<? extends AppWidgetProvider>> findNotUsedWidgets(@Nonnull Application application) {
|
||||||
|
final List<Class<? extends AppWidgetProvider>> result = new ArrayList<>();
|
||||||
|
|
||||||
|
final AppWidgetManager widgetManager = AppWidgetManager.getInstance(application);
|
||||||
|
for (Class<? extends AppWidgetProvider> widgetClass : OLD_WIDGETS) {
|
||||||
|
final int ids[] = widgetManager.getAppWidgetIds(new ComponentName(application, widgetClass));
|
||||||
|
if (ids == null || ids.length == 0) {
|
||||||
|
result.add(widgetClass);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
private static void checkInit() {
|
private static void checkInit() {
|
||||||
if (!initialized) {
|
if (!initialized) {
|
||||||
throw new IllegalStateException("App should be initialized!");
|
throw new IllegalStateException("App should be initialized!");
|
||||||
|
@ -1,38 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.solovyev.android.calculator.external;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* User: serso
|
|
||||||
* Date: 11/20/12
|
|
||||||
* Time: 10:33 PM
|
|
||||||
*/
|
|
||||||
public interface ExternalCalculatorIntentHandler {
|
|
||||||
|
|
||||||
void onIntent(@Nonnull Context context, @Nonnull Intent intent);
|
|
||||||
}
|
|
@ -49,7 +49,7 @@ import static org.solovyev.android.calculator.CalculatorReceiver.newButtonClicke
|
|||||||
* Date: 19.10.12
|
* Date: 19.10.12
|
||||||
* Time: 16:18
|
* Time: 16:18
|
||||||
*/
|
*/
|
||||||
abstract class AbstractCalculatorWidgetProvider extends AppWidgetProvider {
|
public abstract class BaseCalculatorWidgetProvider extends AppWidgetProvider {
|
||||||
|
|
||||||
private static final String TAG = "Calculator++ Widget";
|
private static final String TAG = "Calculator++ Widget";
|
||||||
private static final int WIDGET_CATEGORY_KEYGUARD = 2;
|
private static final int WIDGET_CATEGORY_KEYGUARD = 2;
|
||||||
@ -75,7 +75,7 @@ abstract class AbstractCalculatorWidgetProvider extends AppWidgetProvider {
|
|||||||
**********************************************************************
|
**********************************************************************
|
||||||
*/
|
*/
|
||||||
|
|
||||||
protected AbstractCalculatorWidgetProvider() {
|
protected BaseCalculatorWidgetProvider() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -116,7 +116,7 @@ abstract class AbstractCalculatorWidgetProvider extends AppWidgetProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
protected Class<? extends AbstractCalculatorWidgetProvider> getComponentClass() {
|
protected Class<? extends BaseCalculatorWidgetProvider> getComponentClass() {
|
||||||
return this.getClass();
|
return this.getClass();
|
||||||
}
|
}
|
||||||
|
|
@ -0,0 +1,4 @@
|
|||||||
|
package org.solovyev.android.calculator.widget;
|
||||||
|
|
||||||
|
public class CalculatorWidget extends BaseCalculatorWidgetProvider {
|
||||||
|
}
|
@ -27,5 +27,5 @@ package org.solovyev.android.calculator.widget;
|
|||||||
* Date: 11/18/12
|
* Date: 11/18/12
|
||||||
* Time: 1:00 PM
|
* Time: 1:00 PM
|
||||||
*/
|
*/
|
||||||
public class CalculatorWidgetProvider extends AbstractCalculatorWidgetProvider {
|
public class CalculatorWidgetProvider extends BaseCalculatorWidgetProvider {
|
||||||
}
|
}
|
||||||
|
@ -27,5 +27,5 @@ package org.solovyev.android.calculator.widget;
|
|||||||
* Date: 11/18/12
|
* Date: 11/18/12
|
||||||
* Time: 1:01 PM
|
* Time: 1:01 PM
|
||||||
*/
|
*/
|
||||||
public class CalculatorWidgetProvider3x4 extends AbstractCalculatorWidgetProvider {
|
public class CalculatorWidgetProvider3x4 extends BaseCalculatorWidgetProvider {
|
||||||
}
|
}
|
||||||
|
@ -27,5 +27,5 @@ package org.solovyev.android.calculator.widget;
|
|||||||
* Date: 11/18/12
|
* Date: 11/18/12
|
||||||
* Time: 1:01 PM
|
* Time: 1:01 PM
|
||||||
*/
|
*/
|
||||||
public class CalculatorWidgetProvider4x4 extends AbstractCalculatorWidgetProvider {
|
public class CalculatorWidgetProvider4x4 extends BaseCalculatorWidgetProvider {
|
||||||
}
|
}
|
||||||
|
@ -27,5 +27,5 @@ package org.solovyev.android.calculator.widget;
|
|||||||
* Date: 11/18/12
|
* Date: 11/18/12
|
||||||
* Time: 7:43 PM
|
* Time: 7:43 PM
|
||||||
*/
|
*/
|
||||||
public class CalculatorWidgetProvider4x5 extends AbstractCalculatorWidgetProvider {
|
public class CalculatorWidgetProvider4x5 extends BaseCalculatorWidgetProvider {
|
||||||
}
|
}
|
||||||
|
36
android-app/src/main/res/xml/calculator_widget.xml
Normal file
36
android-app/src/main/res/xml/calculator_widget.xml
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
<?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
|
||||||
|
-->
|
||||||
|
|
||||||
|
<appwidget-provider xmlns:a="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
a:initialKeyguardLayout="@layout/widget_layout_lockscreen"
|
||||||
|
a:initialLayout="@layout/widget_layout"
|
||||||
|
a:minHeight="250dp"
|
||||||
|
a:minResizeHeight="180dp"
|
||||||
|
a:minResizeWidth="180dp"
|
||||||
|
a:minWidth="250dp"
|
||||||
|
a:previewImage="@drawable/widget_preview"
|
||||||
|
a:resizeMode="horizontal|vertical"
|
||||||
|
a:widgetCategory="home_screen|keyguard"
|
||||||
|
tools:ignore="UnusedAttribute"/>
|
34
android-app/src/main/res/xml/calculator_widget_info.xml
Normal file
34
android-app/src/main/res/xml/calculator_widget_info.xml
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
<?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
|
||||||
|
-->
|
||||||
|
|
||||||
|
<appwidget-provider xmlns:a="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
a:initialKeyguardLayout="@layout/widget_layout_lockscreen"
|
||||||
|
a:initialLayout="@layout/widget_layout"
|
||||||
|
a:minHeight="180dp"
|
||||||
|
a:minWidth="180dp"
|
||||||
|
a:previewImage="@drawable/widget_preview"
|
||||||
|
a:resizeMode="horizontal|vertical"
|
||||||
|
a:widgetCategory="home_screen|keyguard"
|
||||||
|
tools:ignore="UnusedAttribute"/>
|
@ -23,12 +23,10 @@
|
|||||||
-->
|
-->
|
||||||
|
|
||||||
<appwidget-provider xmlns:a="http://schemas.android.com/apk/res/android"
|
<appwidget-provider xmlns:a="http://schemas.android.com/apk/res/android"
|
||||||
a:minWidth="180dp"
|
|
||||||
a:minHeight="180dp"
|
|
||||||
a:initialLayout="@layout/widget_layout"
|
|
||||||
a:initialKeyguardLayout="@layout/widget_layout_lockscreen"
|
a:initialKeyguardLayout="@layout/widget_layout_lockscreen"
|
||||||
a:widgetCategory="home_screen|keyguard"
|
a:initialLayout="@layout/widget_layout"
|
||||||
|
a:minHeight="180dp"
|
||||||
|
a:minWidth="180dp"
|
||||||
a:previewImage="@drawable/widget_preview"
|
a:previewImage="@drawable/widget_preview"
|
||||||
a:resizeMode="horizontal|vertical">
|
a:resizeMode="horizontal|vertical"
|
||||||
|
a:widgetCategory="home_screen|keyguard"/>
|
||||||
</appwidget-provider>
|
|
||||||
|
@ -23,12 +23,10 @@
|
|||||||
-->
|
-->
|
||||||
|
|
||||||
<appwidget-provider xmlns:a="http://schemas.android.com/apk/res/android"
|
<appwidget-provider xmlns:a="http://schemas.android.com/apk/res/android"
|
||||||
a:minWidth="180dp"
|
|
||||||
a:minHeight="250dp"
|
|
||||||
a:initialLayout="@layout/widget_layout"
|
|
||||||
a:initialKeyguardLayout="@layout/widget_layout_lockscreen"
|
a:initialKeyguardLayout="@layout/widget_layout_lockscreen"
|
||||||
a:widgetCategory="home_screen|keyguard"
|
a:initialLayout="@layout/widget_layout"
|
||||||
|
a:minHeight="250dp"
|
||||||
|
a:minWidth="180dp"
|
||||||
a:previewImage="@drawable/widget_preview"
|
a:previewImage="@drawable/widget_preview"
|
||||||
a:resizeMode="horizontal|vertical">
|
a:resizeMode="horizontal|vertical"
|
||||||
|
a:widgetCategory="home_screen|keyguard"/>
|
||||||
</appwidget-provider>
|
|
||||||
|
@ -23,12 +23,14 @@
|
|||||||
-->
|
-->
|
||||||
|
|
||||||
<appwidget-provider xmlns:a="http://schemas.android.com/apk/res/android"
|
<appwidget-provider xmlns:a="http://schemas.android.com/apk/res/android"
|
||||||
a:minWidth="250dp"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
a:minHeight="250dp"
|
|
||||||
a:initialLayout="@layout/widget_layout"
|
|
||||||
a:initialKeyguardLayout="@layout/widget_layout_lockscreen"
|
a:initialKeyguardLayout="@layout/widget_layout_lockscreen"
|
||||||
a:widgetCategory="home_screen|keyguard"
|
a:initialLayout="@layout/widget_layout"
|
||||||
|
a:minHeight="250dp"
|
||||||
|
a:minResizeHeight="180dp"
|
||||||
|
a:minResizeWidth="180dp"
|
||||||
|
a:minWidth="250dp"
|
||||||
a:previewImage="@drawable/widget_preview"
|
a:previewImage="@drawable/widget_preview"
|
||||||
a:resizeMode="horizontal|vertical">
|
a:resizeMode="horizontal|vertical"
|
||||||
|
a:widgetCategory="home_screen|keyguard"
|
||||||
</appwidget-provider>
|
tools:ignore="UnusedAttribute"/>
|
||||||
|
@ -23,12 +23,12 @@
|
|||||||
-->
|
-->
|
||||||
|
|
||||||
<appwidget-provider xmlns:a="http://schemas.android.com/apk/res/android"
|
<appwidget-provider xmlns:a="http://schemas.android.com/apk/res/android"
|
||||||
a:minWidth="250dp"
|
|
||||||
a:minHeight="320dp"
|
|
||||||
a:initialLayout="@layout/widget_layout"
|
|
||||||
a:initialKeyguardLayout="@layout/widget_layout_lockscreen"
|
a:initialKeyguardLayout="@layout/widget_layout_lockscreen"
|
||||||
a:widgetCategory="home_screen|keyguard"
|
a:initialLayout="@layout/widget_layout"
|
||||||
|
a:minHeight="320dp"
|
||||||
|
a:minResizeHeight="180dp"
|
||||||
|
a:minResizeWidth="180dp"
|
||||||
|
a:minWidth="250dp"
|
||||||
a:previewImage="@drawable/widget_preview"
|
a:previewImage="@drawable/widget_preview"
|
||||||
a:resizeMode="horizontal|vertical">
|
a:resizeMode="horizontal|vertical"
|
||||||
|
a:widgetCategory="home_screen|keyguard"/>
|
||||||
</appwidget-provider>
|
|
Loading…
Reference in New Issue
Block a user