code reformat

This commit is contained in:
Sergey Solovyev
2013-06-15 00:31:49 +04:00
parent 30e8b55a73
commit e57ce8cf2c
523 changed files with 20785 additions and 19727 deletions

View File

@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="org.solovyev.android.calculator.widget"
android:versionCode="1"
android:versionName="1.0"/>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.solovyev.android.calculator.widget"
android:versionCode="1"
android:versionName="1.0" />

View File

@@ -1,16 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.solovyev.android</groupId>
<artifactId>calculatorpp-parent</artifactId>
<version>1.6.3-SNAPSHOT</version>
</parent>
<parent>
<groupId>org.solovyev.android</groupId>
<artifactId>calculatorpp-parent</artifactId>
<version>1.6.3-SNAPSHOT</version>
</parent>
<groupId>org.solovyev.android</groupId>
<artifactId>calculatorpp-android-app-widget</artifactId>
<version>1.6.3-SNAPSHOT</version>
<groupId>org.solovyev.android</groupId>
<artifactId>calculatorpp-android-app-widget</artifactId>
<version>1.6.3-SNAPSHOT</version>
<name>Calculator++ Application Widget</name>
<packaging>apklib</packaging>
@@ -27,16 +27,16 @@
<type>apklib</type>
</dependency>
<dependency>
<groupId>com.google.android</groupId>
<artifactId>android</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.android</groupId>
<artifactId>android</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.android</groupId>
<artifactId>support-v4</artifactId>
</dependency>
<dependency>
<groupId>com.google.android</groupId>
<artifactId>support-v4</artifactId>
</dependency>
</dependencies>
@@ -50,5 +50,5 @@
</extensions>
</build>
</project>

View File

@@ -6,11 +6,10 @@
~ or visit http://se.solovyev.org
-->
<TextView
xmlns:a="http://schemas.android.com/apk/res/android"
a:id="@+id/calculator_display"
style="@style/cpp_widget_display_style"
a:textIsSelectable="true"
a:padding="@dimen/cpp_display_padding"
a:singleLine="false"
a:scrollbars="vertical"/>
<TextView xmlns:a="http://schemas.android.com/apk/res/android"
a:id="@+id/calculator_display"
style="@style/cpp_widget_display_style"
a:textIsSelectable="true"
a:padding="@dimen/cpp_display_padding"
a:singleLine="false"
a:scrollbars="vertical" />

View File

@@ -7,18 +7,18 @@
-->
<LinearLayout xmlns:a="http://schemas.android.com/apk/res/android"
a:id="@+id/main_fragment_layout"
style="@style/cpp_default_fragment_layout_style"
a:layout_width="match_parent"
a:layout_height="match_parent"
a:padding="@dimen/cpp_editor_padding">
a:id="@+id/main_fragment_layout"
style="@style/cpp_default_fragment_layout_style"
a:layout_width="match_parent"
a:layout_height="match_parent"
a:padding="@dimen/cpp_editor_padding">
<TextView
a:id="@+id/calculator_editor"
style="@style/cpp_widget_editor_style"
a:textIsSelectable="true"
a:singleLine="false"
a:scrollbars="vertical"
a:hint="@string/c_calc_editor_hint"/>
<TextView
a:id="@+id/calculator_editor"
style="@style/cpp_widget_editor_style"
a:textIsSelectable="true"
a:singleLine="false"
a:scrollbars="vertical"
a:hint="@string/c_calc_editor_hint" />
</LinearLayout>

View File

@@ -1,36 +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">
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"/>
<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">
<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/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"/>
<include
layout="@layout/widget_display"
a:layout_weight="5"
a:layout_width="0dp"
a:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
<include layout="@layout/cpp_simple_keyboard"
a:layout_weight="5"
a:layout_width="match_parent"
a:layout_height="0dp"/>
<include
layout="@layout/cpp_simple_keyboard"
a:layout_weight="5"
a:layout_width="match_parent"
a:layout_height="0dp" />
</LinearLayout>

View File

@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="cpp_widget_cursor_color">#ff707070</color>
<color name="cpp_widget_cursor_color">#ff707070</color>
</resources>

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="cpp_widget_editor_text_size">25sp</dimen>
<dimen name="cpp_widget_display_text_size">25sp</dimen>
<dimen name="cpp_widget_margin">6dp</dimen>
<dimen name="cpp_widget_editor_text_size">25sp</dimen>
<dimen name="cpp_widget_display_text_size">25sp</dimen>
<dimen name="cpp_widget_margin">6dp</dimen>
</resources>

View File

@@ -1,17 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="cpp_widget_main_layout_style" parent="cpp_default_main_layout_style">
<item name="android:padding">1dp</item>
<item name="android:layout_margin">@dimen/cpp_widget_margin</item>
</style>
<style name="cpp_widget_main_layout_style" parent="cpp_default_main_layout_style">
<item name="android:padding">1dp</item>
<item name="android:layout_margin">@dimen/cpp_widget_margin</item>
</style>
<style name="cpp_widget_editor_style" parent="cpp_editor_style">
<item name="android:textSize">@dimen/cpp_widget_editor_text_size</item>
</style>
<style name="cpp_widget_editor_style" parent="cpp_editor_style">
<item name="android:textSize">@dimen/cpp_widget_editor_text_size</item>
</style>
<style name="cpp_widget_display_style" parent="cpp_display_style">
<item name="android:textSize">@dimen/cpp_widget_display_text_size</item>
</style>
<style name="cpp_widget_display_style" parent="cpp_display_style">
<item name="android:textSize">@dimen/cpp_widget_display_text_size</item>
</style>
</resources>

View File

@@ -21,140 +21,140 @@ import org.solovyev.android.calculator.external.ExternalCalculatorStateUpdater;
*/
abstract class AbstractCalculatorWidgetProvider extends AppWidgetProvider implements ExternalCalculatorStateUpdater {
static final String BUTTON_ID_EXTRA = "buttonId";
static final String BUTTON_PRESSED_ACTION = "org.solovyev.android.calculator.widget.BUTTON_PRESSED";
static final String BUTTON_ID_EXTRA = "buttonId";
static final String BUTTON_PRESSED_ACTION = "org.solovyev.android.calculator.widget.BUTTON_PRESSED";
private static final String TAG = "Calculator++ Widget";
private static final String TAG = "Calculator++ Widget";
/*
**********************************************************************
*
* FIELDS
*
**********************************************************************
*/
/*
**********************************************************************
*
* FIELDS
*
**********************************************************************
*/
@Nullable
private String cursorColor;
@Nullable
private String cursorColor;
@NotNull
private ExternalCalculatorIntentHandler intentHandler = new CalculatorWidgetIntentHandler(this);
@NotNull
private ExternalCalculatorIntentHandler intentHandler = new CalculatorWidgetIntentHandler(this);
/*
**********************************************************************
*
* CONSTRUCTORS
*
**********************************************************************
*/
/*
**********************************************************************
*
* CONSTRUCTORS
*
**********************************************************************
*/
protected AbstractCalculatorWidgetProvider() {
final Class<? extends AppWidgetProvider> componentClass = this.getComponentClass();
protected AbstractCalculatorWidgetProvider() {
final Class<? extends AppWidgetProvider> componentClass = this.getComponentClass();
Locator.getInstance().getExternalListenersContainer().addExternalListener(componentClass);
}
Locator.getInstance().getExternalListenersContainer().addExternalListener(componentClass);
}
/*
**********************************************************************
*
* METHODS
*
**********************************************************************
*/
/*
**********************************************************************
*
* METHODS
*
**********************************************************************
*/
@Override
public void onEnabled(Context context) {
super.onEnabled(context);
@Override
public void onEnabled(Context context) {
super.onEnabled(context);
getCursorColor(context);
}
getCursorColor(context);
}
@NotNull
private String getCursorColor(@NotNull Context context) {
if (cursorColor == null) {
cursorColor = Integer.toHexString(context.getResources().getColor(R.color.cpp_widget_cursor_color)).substring(2);
}
return cursorColor;
}
@NotNull
private String getCursorColor(@NotNull Context context) {
if (cursorColor == null) {
cursorColor = Integer.toHexString(context.getResources().getColor(R.color.cpp_widget_cursor_color)).substring(2);
}
return cursorColor;
}
@Override
public void onUpdate(@NotNull Context context,
@NotNull AppWidgetManager appWidgetManager,
@NotNull int[] appWidgetIds) {
super.onUpdate(context, appWidgetManager, appWidgetIds);
@Override
public void onUpdate(@NotNull Context context,
@NotNull AppWidgetManager appWidgetManager,
@NotNull int[] appWidgetIds) {
super.onUpdate(context, appWidgetManager, appWidgetIds);
updateWidget(context, appWidgetManager, appWidgetIds, Locator.getInstance().getEditor().getViewState(), Locator.getInstance().getDisplay().getViewState());
}
updateWidget(context, appWidgetManager, appWidgetIds, Locator.getInstance().getEditor().getViewState(), Locator.getInstance().getDisplay().getViewState());
}
@Override
public void updateState(@NotNull Context context,
@NotNull CalculatorEditorViewState editorState,
@NotNull CalculatorDisplayViewState displayState) {
final AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
final int[] appWidgetIds = appWidgetManager.getAppWidgetIds(new ComponentName(context, getComponentClass()));
updateWidget(context, appWidgetManager, appWidgetIds, editorState, displayState);
}
@Override
public void updateState(@NotNull Context context,
@NotNull CalculatorEditorViewState editorState,
@NotNull CalculatorDisplayViewState displayState) {
final AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
final int[] appWidgetIds = appWidgetManager.getAppWidgetIds(new ComponentName(context, getComponentClass()));
updateWidget(context, appWidgetManager, appWidgetIds, editorState, displayState);
}
@NotNull
protected Class<? extends AbstractCalculatorWidgetProvider> getComponentClass(){
return this.getClass();
}
@NotNull
protected Class<? extends AbstractCalculatorWidgetProvider> getComponentClass() {
return this.getClass();
}
private void updateWidget(@NotNull Context context,
@NotNull AppWidgetManager appWidgetManager,
@NotNull int[] appWidgetIds,
@NotNull CalculatorEditorViewState editorState,
@NotNull CalculatorDisplayViewState displayState) {
for (int appWidgetId : appWidgetIds) {
final RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_layout);
private void updateWidget(@NotNull Context context,
@NotNull AppWidgetManager appWidgetManager,
@NotNull int[] appWidgetIds,
@NotNull CalculatorEditorViewState editorState,
@NotNull CalculatorDisplayViewState displayState) {
for (int appWidgetId : appWidgetIds) {
final RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_layout);
for (CalculatorButton button : CalculatorButton.values()) {
final Intent onButtonClickIntent = new Intent(context, getComponentClass());
onButtonClickIntent.setAction(BUTTON_PRESSED_ACTION);
onButtonClickIntent.putExtra(BUTTON_ID_EXTRA, button.getButtonId());
final PendingIntent pendingIntent = PendingIntent.getBroadcast(context, button.getButtonId(), onButtonClickIntent, PendingIntent.FLAG_UPDATE_CURRENT);
if (pendingIntent != null) {
views.setOnClickPendingIntent(button.getButtonId(), pendingIntent);
}
}
for (CalculatorButton button : CalculatorButton.values()) {
final Intent onButtonClickIntent = new Intent(context, getComponentClass());
onButtonClickIntent.setAction(BUTTON_PRESSED_ACTION);
onButtonClickIntent.putExtra(BUTTON_ID_EXTRA, button.getButtonId());
final PendingIntent pendingIntent = PendingIntent.getBroadcast(context, button.getButtonId(), onButtonClickIntent, PendingIntent.FLAG_UPDATE_CURRENT);
if (pendingIntent != null) {
views.setOnClickPendingIntent(button.getButtonId(), pendingIntent);
}
}
updateEditorState(context, views, editorState);
updateDisplayState(context, views, displayState);
updateEditorState(context, views, editorState);
updateDisplayState(context, views, displayState);
CalculatorButtons.initMultiplicationButton(views);
CalculatorButtons.initMultiplicationButton(views);
appWidgetManager.updateAppWidget(appWidgetId, views);
}
}
appWidgetManager.updateAppWidget(appWidgetId, views);
}
}
@Override
public void onReceive(Context context, Intent intent) {
super.onReceive(context, intent);
@Override
public void onReceive(Context context, Intent intent) {
super.onReceive(context, intent);
this.intentHandler.onIntent(context, intent);
}
this.intentHandler.onIntent(context, intent);
}
private void updateDisplayState(@NotNull Context context, @NotNull RemoteViews views, @NotNull CalculatorDisplayViewState displayState) {
if (displayState.isValid()) {
views.setTextViewText(R.id.calculator_display, displayState.getText());
views.setTextColor(R.id.calculator_display, context.getResources().getColor(R.color.cpp_default_text_color));
} else {
views.setTextColor(R.id.calculator_display, context.getResources().getColor(R.color.cpp_display_error_text_color));
}
}
private void updateDisplayState(@NotNull Context context, @NotNull RemoteViews views, @NotNull CalculatorDisplayViewState displayState) {
if (displayState.isValid()) {
views.setTextViewText(R.id.calculator_display, displayState.getText());
views.setTextColor(R.id.calculator_display, context.getResources().getColor(R.color.cpp_default_text_color));
} else {
views.setTextColor(R.id.calculator_display, context.getResources().getColor(R.color.cpp_display_error_text_color));
}
}
private void updateEditorState(@NotNull Context context, @NotNull RemoteViews views, @NotNull CalculatorEditorViewState editorState) {
String text = editorState.getText();
private void updateEditorState(@NotNull Context context, @NotNull RemoteViews views, @NotNull CalculatorEditorViewState editorState) {
String text = editorState.getText();
CharSequence newText = text;
int selection = editorState.getSelection();
if (selection >= 0 && selection <= text.length()) {
// inject cursor
newText = Html.fromHtml(text.substring(0, selection) + "<font color=\"#" + getCursorColor(context) + "\">|</font>" + text.substring(selection));
}
Locator.getInstance().getNotifier().showDebugMessage(TAG, "New editor state: " + text);
views.setTextViewText(R.id.calculator_editor, newText);
}
CharSequence newText = text;
int selection = editorState.getSelection();
if (selection >= 0 && selection <= text.length()) {
// inject cursor
newText = Html.fromHtml(text.substring(0, selection) + "<font color=\"#" + getCursorColor(context) + "\">|</font>" + text.substring(selection));
}
Locator.getInstance().getNotifier().showDebugMessage(TAG, "New editor state: " + text);
views.setTextViewText(R.id.calculator_editor, newText);
}
}

View File

@@ -15,24 +15,24 @@ import org.solovyev.android.calculator.external.ExternalCalculatorStateUpdater;
*/
public class CalculatorWidgetIntentHandler extends DefaultExternalCalculatorIntentHandler {
public CalculatorWidgetIntentHandler(@NotNull ExternalCalculatorStateUpdater stateUpdater) {
super(stateUpdater);
}
public CalculatorWidgetIntentHandler(@NotNull ExternalCalculatorStateUpdater stateUpdater) {
super(stateUpdater);
}
@Override
public void onIntent(@NotNull Context context, @NotNull Intent intent) {
super.onIntent(context, intent);
@Override
public void onIntent(@NotNull Context context, @NotNull Intent intent) {
super.onIntent(context, intent);
if (AbstractCalculatorWidgetProvider.BUTTON_PRESSED_ACTION.equals(intent.getAction())) {
final int buttonId = intent.getIntExtra(AbstractCalculatorWidgetProvider.BUTTON_ID_EXTRA, 0);
if (AbstractCalculatorWidgetProvider.BUTTON_PRESSED_ACTION.equals(intent.getAction())) {
final int buttonId = intent.getIntExtra(AbstractCalculatorWidgetProvider.BUTTON_ID_EXTRA, 0);
final CalculatorButton button = CalculatorButton.getById(buttonId);
if (button != null) {
button.onClick(context);
}
} else if (Intent.ACTION_CONFIGURATION_CHANGED.equals(intent.getAction())) {
updateState(context, Locator.getInstance().getEditor().getViewState(), Locator.getInstance().getDisplay().getViewState());
}
}
final CalculatorButton button = CalculatorButton.getById(buttonId);
if (button != null) {
button.onClick(context);
}
} else if (Intent.ACTION_CONFIGURATION_CHANGED.equals(intent.getAction())) {
updateState(context, Locator.getInstance().getEditor().getViewState(), Locator.getInstance().getDisplay().getViewState());
}
}
}