Merge branch 'master' of https://github.com/serso/android-calculatorpp
This commit is contained in:
@@ -112,7 +112,7 @@ public class ActivityUi extends BaseUi {
|
||||
toggleTitle(activity, actionBar, true);
|
||||
|
||||
if (!homeAsUp) {
|
||||
actionBar.setIcon(R.drawable.ab_icon);
|
||||
actionBar.setIcon(R.drawable.ab_logo);
|
||||
}
|
||||
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
|
||||
}
|
||||
|
@@ -23,20 +23,31 @@
|
||||
package org.solovyev.android.calculator;
|
||||
|
||||
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.res.Configuration;
|
||||
import android.os.Build;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.app.FragmentTransaction;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import org.solovyev.android.Android;
|
||||
import org.solovyev.android.UiThreadExecutor;
|
||||
import org.solovyev.android.Views;
|
||||
import org.solovyev.android.calculator.ga.Ga;
|
||||
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.view.VibratorContainer;
|
||||
import org.solovyev.common.listeners.JEvent;
|
||||
import org.solovyev.common.listeners.JEventListener;
|
||||
import org.solovyev.common.listeners.JEventListeners;
|
||||
@@ -46,7 +57,9 @@ import org.solovyev.common.threads.DelayedExecutor;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
/**
|
||||
@@ -62,14 +75,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()})
|
||||
*/
|
||||
public final class App {
|
||||
|
||||
/*
|
||||
**********************************************************************
|
||||
*
|
||||
* FIELDS
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
@Nonnull
|
||||
private static final List<Class<? extends BaseCalculatorWidgetProvider>> OLD_WIDGETS = Arrays.asList(CalculatorWidgetProvider.class, CalculatorWidgetProvider3x4.class, CalculatorWidgetProvider4x4.class, CalculatorWidgetProvider4x5.class);
|
||||
|
||||
@Nonnull
|
||||
private static volatile Application application;
|
||||
@@ -166,12 +173,43 @@ public final class App {
|
||||
App.broadcaster = new CalculatorBroadcaster(application);
|
||||
App.vibrator = new Vibrator(application, preferences);
|
||||
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;
|
||||
} else {
|
||||
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() {
|
||||
if (!initialized) {
|
||||
throw new IllegalStateException("App should be initialized!");
|
||||
@@ -271,4 +309,18 @@ public final class App {
|
||||
public static ScreenMetrics getScreenMetrics() {
|
||||
return screenMetrics;
|
||||
}
|
||||
|
||||
public static void showDialog(@Nonnull DialogFragment dialogFragment,
|
||||
@Nonnull String fragmentTag,
|
||||
@Nonnull FragmentManager fm) {
|
||||
final FragmentTransaction ft = fm.beginTransaction();
|
||||
|
||||
Fragment prev = fm.findFragmentByTag(fragmentTag);
|
||||
if (prev != null) {
|
||||
ft.remove(prev);
|
||||
}
|
||||
|
||||
// Create and show the dialog.
|
||||
dialogFragment.show(ft, fragmentTag);
|
||||
}
|
||||
}
|
||||
|
@@ -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);
|
||||
}
|
@@ -44,7 +44,6 @@ import org.solovyev.android.calculator.math.edit.CalculatorFunctionsActivity;
|
||||
import org.solovyev.android.calculator.math.edit.CalculatorFunctionsFragment;
|
||||
import org.solovyev.android.calculator.math.edit.MathEntityRemover;
|
||||
import org.solovyev.android.calculator.model.AFunction;
|
||||
import org.solovyev.android.sherlock.AndroidSherlockUtils;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
@@ -210,7 +209,7 @@ public class FunctionEditDialogFragment extends DialogFragment implements Calcul
|
||||
}
|
||||
|
||||
public static void showDialog(@Nonnull Input input, @Nonnull FragmentManager fm) {
|
||||
AndroidSherlockUtils.showDialog(create(input), "function-editor", fm);
|
||||
App.showDialog(create(input), "function-editor", fm);
|
||||
}
|
||||
|
||||
public static class Input implements Parcelable {
|
||||
|
@@ -37,7 +37,6 @@ import jscl.math.function.IConstant;
|
||||
import org.solovyev.android.Views;
|
||||
import org.solovyev.android.calculator.*;
|
||||
import org.solovyev.android.calculator.model.Var;
|
||||
import org.solovyev.android.sherlock.AndroidSherlockUtils;
|
||||
import org.solovyev.common.text.Strings;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
@@ -257,7 +256,7 @@ public class VarEditDialogFragment extends DialogFragment implements CalculatorE
|
||||
*/
|
||||
|
||||
public static void showDialog(@Nonnull Input input, @Nonnull FragmentManager fm) {
|
||||
AndroidSherlockUtils.showDialog(create(input), "constant-editor", fm);
|
||||
App.showDialog(create(input), "constant-editor", fm);
|
||||
}
|
||||
|
||||
public static class Input {
|
||||
|
@@ -49,7 +49,7 @@ import static org.solovyev.android.calculator.CalculatorReceiver.newButtonClicke
|
||||
* Date: 19.10.12
|
||||
* Time: 16:18
|
||||
*/
|
||||
abstract class AbstractCalculatorWidgetProvider extends AppWidgetProvider {
|
||||
public abstract class BaseCalculatorWidgetProvider extends AppWidgetProvider {
|
||||
|
||||
private static final String TAG = "Calculator++ Widget";
|
||||
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
|
||||
protected Class<? extends AbstractCalculatorWidgetProvider> getComponentClass() {
|
||||
protected Class<? extends BaseCalculatorWidgetProvider> getComponentClass() {
|
||||
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
|
||||
* 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
|
||||
* 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
|
||||
* 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
|
||||
* Time: 7:43 PM
|
||||
*/
|
||||
public class CalculatorWidgetProvider4x5 extends AbstractCalculatorWidgetProvider {
|
||||
public class CalculatorWidgetProvider4x5 extends BaseCalculatorWidgetProvider {
|
||||
}
|
||||
|
@@ -1,63 +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.sherlock;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.app.FragmentTransaction;
|
||||
import android.view.MenuInflater;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
* Date: 8/13/12
|
||||
* Time: 2:04 AM
|
||||
*/
|
||||
public final class AndroidSherlockUtils {
|
||||
|
||||
private AndroidSherlockUtils() {
|
||||
throw new AssertionError("Not intended for instantiation!");
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public static MenuInflater getSupportMenuInflater(@Nonnull Activity activity) {
|
||||
return activity.getMenuInflater();
|
||||
}
|
||||
|
||||
public static void showDialog(@Nonnull DialogFragment dialogFragment,
|
||||
@Nonnull String fragmentTag,
|
||||
@Nonnull FragmentManager fm) {
|
||||
final FragmentTransaction ft = fm.beginTransaction();
|
||||
|
||||
Fragment prev = fm.findFragmentByTag(fragmentTag);
|
||||
if (prev != null) {
|
||||
ft.remove(prev);
|
||||
}
|
||||
|
||||
// Create and show the dialog.
|
||||
dialogFragment.show(ft, fragmentTag);
|
||||
}
|
||||
}
|
@@ -1,43 +0,0 @@
|
||||
package org.solovyev.android.sherlock;
|
||||
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.app.FragmentTransaction;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class Fragments extends org.solovyev.android.Fragments {
|
||||
|
||||
private Fragments() {
|
||||
}
|
||||
|
||||
public static void showDialog(@Nonnull DialogFragment dialogFragment,
|
||||
@Nonnull String fragmentTag,
|
||||
@Nonnull FragmentManager fm) {
|
||||
showDialog(dialogFragment, fragmentTag, fm, true);
|
||||
}
|
||||
|
||||
public static void showDialog(DialogFragment dialogFragment, String fragmentTag, FragmentManager fm, boolean useExisting) {
|
||||
Fragment prev = fm.findFragmentByTag(fragmentTag);
|
||||
if (prev != null) {
|
||||
if (!useExisting) {
|
||||
final FragmentTransaction ft = fm.beginTransaction();
|
||||
ft.remove(prev);
|
||||
ft.addToBackStack(null);
|
||||
|
||||
// Create and show the dialog.
|
||||
dialogFragment.show(ft, fragmentTag);
|
||||
fm.executePendingTransactions();
|
||||
}
|
||||
} else {
|
||||
final FragmentTransaction ft = fm.beginTransaction();
|
||||
|
||||
ft.addToBackStack(null);
|
||||
|
||||
// Create and show the dialog.
|
||||
dialogFragment.show(ft, fragmentTag);
|
||||
fm.executePendingTransactions();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user