diff --git a/gen/org/solovyev/android/calculator/R.java b/gen/org/solovyev/android/calculator/R.java
index be166f9d..37993712 100644
--- a/gen/org/solovyev/android/calculator/R.java
+++ b/gen/org/solovyev/android/calculator/R.java
@@ -26,69 +26,82 @@ containing a value of this type.
*/
public static final int textUp=0x7f010000;
}
+ public static final class color {
+ public static final int button_text=0x7f050001;
+ public static final int magic_flame=0x7f050000;
+ }
public static final class drawable {
- public static final int down=0x7f020000;
- public static final int icon=0x7f020001;
- public static final int not_ok=0x7f020002;
- public static final int ok=0x7f020003;
- public static final int up=0x7f020004;
+ public static final int blue_button=0x7f020000;
+ public static final int button=0x7f020001;
+ public static final int down=0x7f020002;
+ public static final int icon=0x7f020003;
+ public static final int not_ok=0x7f020004;
+ public static final int ok=0x7f020005;
+ public static final int up=0x7f020006;
}
public static final class id {
- public static final int calibrationArrow=0x7f080000;
- public static final int calibrationButton=0x7f080001;
- public static final int calibrationStart=0x7f080002;
- public static final int curlyBracketsButton=0x7f080016;
- public static final int editText=0x7f080003;
- public static final int eigthDigitButton=0x7f080012;
- public static final int equalsButton=0x7f080014;
- public static final int fiveDigitButton=0x7f08000c;
- public static final int fourDigitButton=0x7f08000b;
- public static final int historyButton=0x7f08001b;
- public static final int menu_item_help=0x7f08001e;
- public static final int menu_item_settings=0x7f08001d;
- public static final int minusButton=0x7f08000f;
- public static final int muliplicationButton=0x7f080008;
- public static final int nineDigitButton=0x7f080013;
- public static final int numericButton=0x7f080019;
- public static final int oneDigitButton=0x7f080005;
- public static final int piButton=0x7f08001c;
- public static final int plusButton=0x7f080009;
- public static final int pointDigitButton=0x7f080018;
- public static final int resultEditText=0x7f080004;
- public static final int roundBracketsButton=0x7f08000a;
- public static final int sevenDigitButton=0x7f080011;
- public static final int simplifyButton=0x7f08001a;
- public static final int sixDigitButton=0x7f08000d;
- public static final int sqrtButton=0x7f080015;
- public static final int squareBracketsButton=0x7f080010;
- public static final int subtractionButton=0x7f08000e;
- public static final int threeDigitButton=0x7f080007;
- public static final int twoDigitButton=0x7f080006;
- public static final int zeroDigitButton=0x7f080017;
+ public static final int calibrationArrowLeft=0x7f090001;
+ public static final int calibrationArrowRight=0x7f090004;
+ public static final int calibrationButtonLeft=0x7f090002;
+ public static final int calibrationButtonRight=0x7f090003;
+ public static final int calibrationStart=0x7f090005;
+ public static final int curlyBracketsButton=0x7f09001b;
+ public static final int divisionButton=0x7f090011;
+ public static final int editText=0x7f090006;
+ public static final int eigthDigitButton=0x7f090014;
+ public static final int equalsButton=0x7f090016;
+ public static final int fiveDigitButton=0x7f09000f;
+ public static final int fourDigitButton=0x7f09000e;
+ public static final int historyButton=0x7f090020;
+ public static final int menu_item_help=0x7f090022;
+ public static final int menu_item_settings=0x7f090021;
+ public static final int muliplicationButton=0x7f09000c;
+ public static final int nineDigitButton=0x7f090015;
+ public static final int numericButton=0x7f09001e;
+ public static final int oneDigitButton=0x7f090009;
+ public static final int panelswitch=0x7f090008;
+ public static final int piButton=0x7f09001c;
+ public static final int plusButton=0x7f09000d;
+ public static final int pointDigitButton=0x7f09001d;
+ public static final int resultEditText=0x7f090007;
+ public static final int roundBracketsButton=0x7f090019;
+ public static final int sevenDigitButton=0x7f090013;
+ public static final int simplePad=0x7f090000;
+ public static final int simplifyButton=0x7f09001f;
+ public static final int sixDigitButton=0x7f090010;
+ public static final int sqrtButton=0x7f090017;
+ public static final int squareBracketsButton=0x7f09001a;
+ public static final int subtractionButton=0x7f090012;
+ public static final int threeDigitButton=0x7f09000b;
+ public static final int twoDigitButton=0x7f09000a;
+ public static final int zeroDigitButton=0x7f090018;
}
public static final class layout {
public static final int drag_button_calibration=0x7f030000;
public static final int main=0x7f030001;
}
public static final class menu {
- public static final int main_menu=0x7f070000;
+ public static final int main_menu=0x7f080000;
}
public static final class string {
- public static final int c_app_name=0x7f050000;
- public static final int c_app_settings=0x7f050001;
- public static final int c_down=0x7f050008;
- public static final int c_help=0x7f050004;
- public static final int c_prefs_drag_button_calibration=0x7f050006;
- public static final int c_prefs_drag_button_calibration_summary=0x7f050007;
- public static final int c_prefs_main_category=0x7f050005;
- public static final int c_restart=0x7f05000a;
- public static final int c_settings=0x7f050003;
- public static final int c_up=0x7f050009;
- public static final int syntax_error=0x7f050002;
+ public static final int c_app_name=0x7f060000;
+ public static final int c_app_settings=0x7f060001;
+ public static final int c_down=0x7f060008;
+ public static final int c_help=0x7f060004;
+ public static final int c_prefs_drag_button_calibration=0x7f060006;
+ public static final int c_prefs_drag_button_calibration_summary=0x7f060007;
+ public static final int c_prefs_main_category=0x7f060005;
+ public static final int c_restart=0x7f06000a;
+ public static final int c_settings=0x7f060003;
+ public static final int c_up=0x7f060009;
+ public static final int syntax_error=0x7f060002;
}
public static final class style {
- public static final int digitButtonStyle=0x7f060001;
- public static final int editTextInputStyle=0x7f060000;
+ public static final int button_small_style=0x7f070003;
+ public static final int button_style=0x7f070001;
+ public static final int digitButtonStyle=0x7f070002;
+ public static final int display_style=0x7f070004;
+ public static final int editTextInputStyle=0x7f070000;
}
public static final class xml {
public static final int preferences=0x7f040000;
diff --git a/res/drawable/blue_button.xml b/res/drawable/blue_button.xml
new file mode 100644
index 00000000..f4d6059b
--- /dev/null
+++ b/res/drawable/blue_button.xml
@@ -0,0 +1,21 @@
+
+
+
+
+
+
+
diff --git a/res/drawable/button.xml b/res/drawable/button.xml
new file mode 100644
index 00000000..e5112ee1
--- /dev/null
+++ b/res/drawable/button.xml
@@ -0,0 +1,21 @@
+
+
+
+
+
+
+
diff --git a/res/layout/drag_button_calibration.xml b/res/layout/drag_button_calibration.xml
index 93fbaef5..b01fdbc9 100644
--- a/res/layout/drag_button_calibration.xml
+++ b/res/layout/drag_button_calibration.xml
@@ -2,29 +2,46 @@
+ a:layout_width="match_parent"
+ a:layout_height="match_parent"
+ a:background="#ff000000">
-
+
-
+
-
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/res/values/colors.xml b/res/values/colors.xml
new file mode 100644
index 00000000..56cc6b39
--- /dev/null
+++ b/res/values/colors.xml
@@ -0,0 +1,4 @@
+
+ #00ffffff
+ #ffffffff
+
\ No newline at end of file
diff --git a/res/values/styles.xml b/res/values/styles.xml
index aec8278e..be73b39e 100644
--- a/res/values/styles.xml
+++ b/res/values/styles.xml
@@ -6,10 +6,34 @@
- wrap_content
- monospace
-
-
-
\ No newline at end of file
+
+
+
+
+
+
+
+
+
+
diff --git a/src/org/solovyev/android/calculator/CalculatorActivity.java b/src/org/solovyev/android/calculator/CalculatorActivity.java
index 0d1263d0..d778e0ab 100644
--- a/src/org/solovyev/android/calculator/CalculatorActivity.java
+++ b/src/org/solovyev/android/calculator/CalculatorActivity.java
@@ -10,7 +10,9 @@ import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Handler;
+import android.util.TypedValue;
import android.view.*;
+import android.widget.TextView;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.solovyev.android.view.*;
@@ -26,7 +28,9 @@ import android.util.Log;
import android.widget.EditText;
import org.solovyev.util.math.Point2d;
-public class CalculatorActivity extends Activity {
+public class CalculatorActivity extends Activity implements FontSizeAdjuster{
+
+ private static final int HVGA_WIDTH_PIXELS = 320;
@NotNull
private EditText editText;
@@ -273,4 +277,18 @@ public class CalculatorActivity extends Activity {
private void showHelp() {
Log.d(CalculatorActivity.class + "showHelp()", "Show help!");
}
+
+ /**
+ * The font sizes in the layout files are specified for a HVGA display.
+ * Adjust the font sizes accordingly if we are running on a different
+ * display.
+ */
+ @Override
+ public void adjustFontSize(@NotNull TextView view) {
+ float fontPixelSize = view.getTextSize();
+ Display display = getWindowManager().getDefaultDisplay();
+ int h = Math.min(display.getWidth(), display.getHeight());
+ float ratio = (float)h/HVGA_WIDTH_PIXELS;
+ view.setTextSize(TypedValue.COMPLEX_UNIT_PX, fontPixelSize*ratio);
+ }
}
\ No newline at end of file
diff --git a/src/org/solovyev/android/calculator/DragButtonCalibrationActivity.java b/src/org/solovyev/android/calculator/DragButtonCalibrationActivity.java
index cd934173..a2efa2b2 100644
--- a/src/org/solovyev/android/calculator/DragButtonCalibrationActivity.java
+++ b/src/org/solovyev/android/calculator/DragButtonCalibrationActivity.java
@@ -1,7 +1,6 @@
package org.solovyev.android.calculator;
import android.app.Activity;
-import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
@@ -24,7 +23,6 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.prefs.Preferences;
/**
* User: serso
@@ -33,14 +31,10 @@ import java.util.prefs.Preferences;
*/
public class DragButtonCalibrationActivity extends Activity {
- @NotNull
- private DragDirection dragDirection = DragDirection.up;
-
@NotNull
private final List dragHistory = new ArrayList();
- @NotNull
- private ImageView calibrationArrow;
+ private final Map map = new HashMap();
public static final String PREFERENCES = "dragButtonPreferences";
@@ -52,7 +46,6 @@ public class DragButtonCalibrationActivity extends Activity {
private static final float DEFAULT_VALUE = -999;
private static final int MIN_HISTORY_FOR_CALIBRATION = 10;
public static final String INTENT_ACTION = "org.solovyev.android.calculator.DragButtonPreferencesChanged";
- ;
public static enum PreferenceType {
angle,
@@ -67,26 +60,36 @@ public class DragButtonCalibrationActivity extends Activity {
setContentView(R.layout.drag_button_calibration);
- final DragButton calibrationButton = (DragButton) findViewById(R.id.calibrationButton);
- calibrationButton.setOnDragListener(new CalibrationOnDragListener());
-
- calibrationArrow = (ImageView) findViewById(R.id.calibrationArrow);
-
- createDragDirection(0);
+ createCalibrationButton(R.id.calibrationButtonRight, R.id.calibrationArrowRight);
+ createCalibrationButton(R.id.calibrationButtonLeft, R.id.calibrationArrowLeft);
}
- private void createDragDirection(long timeout) {
+ private void createCalibrationButton(int buttonId, int arrowId) {
+ final DragButton calibrationButton = (DragButton) findViewById(buttonId);
+ calibrationButton.setOnDragListener(new CalibrationOnDragListener());
+
+ ImageView imageView = (ImageView) findViewById(arrowId);
+ CalibrationArrow calibrationArrow = new CalibrationArrow(imageView);
+
+ createDragDirection(0, calibrationArrow);
+
+ map.put(calibrationButton, calibrationArrow);
+ }
+
+ private void createDragDirection(long timeout, @NotNull final CalibrationArrow calibrationArrow) {
new Handler().postDelayed(new Runnable() {
public void run() {
- dragDirection = Math.random() > 0.5 ? DragDirection.up : DragDirection.down;
+ calibrationArrow.dragDirection = Math.random() > 0.5 ? DragDirection.up : DragDirection.down;
- calibrationArrow.setImageResource(dragDirection == DragDirection.down ? R.drawable.down : R.drawable.up);
+ calibrationArrow.calibrationArrow.setImageResource(calibrationArrow.dragDirection == DragDirection.down ? R.drawable.down : R.drawable.up);
}
}, timeout);
}
public void restartClickHandler(View v) {
- createDragDirection(0);
+ for (CalibrationArrow calibrationArrow : map.values()) {
+ createDragDirection(0, calibrationArrow);
+ }
}
@@ -109,6 +112,9 @@ public class DragButtonCalibrationActivity extends Activity {
double angle = Math.toDegrees(MathUtils.getAngle(startPoint, MathUtils.sum(startPoint, SimpleOnDragListener.axis), endPoint));
+ final CalibrationArrow calibrationArrow = map.get(dragButton);
+ final DragDirection dragDirection = calibrationArrow.dragDirection;
+
assert dragDirection == DragDirection.up || dragDirection == DragDirection.down;
double deviationAngle = angle;
@@ -117,13 +123,13 @@ public class DragButtonCalibrationActivity extends Activity {
}
if (deviationAngle > 45) {
- calibrationArrow.setImageResource(R.drawable.not_ok);
+ calibrationArrow.calibrationArrow.setImageResource(R.drawable.not_ok);
} else {
- calibrationArrow.setImageResource(R.drawable.ok);
+ calibrationArrow.calibrationArrow.setImageResource(R.drawable.ok);
dragHistory.add(new DragData(dragDirection, distance, angle, (motionEvent.getEventTime() - motionEvent.getDownTime())));
}
- createDragDirection(500);
+ createDragDirection(500, calibrationArrow);
return true;
}
@@ -372,4 +378,16 @@ public class DragButtonCalibrationActivity extends Activity {
return time;
}
}
+
+ private class CalibrationArrow {
+ @NotNull
+ private ImageView calibrationArrow;
+
+ @NotNull
+ private DragDirection dragDirection = DragDirection.up;
+
+ private CalibrationArrow(@NotNull ImageView calibrationArrow) {
+ this.calibrationArrow = calibrationArrow;
+ }
+ }
}
diff --git a/src/org/solovyev/android/view/ColorButton.java b/src/org/solovyev/android/view/ColorButton.java
new file mode 100644
index 00000000..13ea5f43
--- /dev/null
+++ b/src/org/solovyev/android/view/ColorButton.java
@@ -0,0 +1,157 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * 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.
+ */
+
+package org.solovyev.android.view;
+
+import android.content.Context;
+import android.graphics.Canvas;
+import android.graphics.Paint;
+import android.graphics.Paint.Style;
+import android.util.AttributeSet;
+import android.widget.Button;
+import android.view.MotionEvent;
+import android.content.res.Resources;
+import org.jetbrains.annotations.NotNull;
+import org.solovyev.android.calculator.R;
+import org.solovyev.util.StringUtils;
+import org.solovyev.util.math.Point2d;
+
+/**
+ * NOTE: copied from com.android.calculator2.ColorButton
+ */
+
+/**
+ * Button with click-animation effect.
+ */
+public class ColorButton extends Button {
+ int CLICK_FEEDBACK_COLOR;
+ static final int CLICK_FEEDBACK_INTERVAL = 10;
+ static final int CLICK_FEEDBACK_DURATION = 350;
+
+ @NotNull
+ private Point2d textPosition;
+ private long mAnimStart;
+ private Paint mFeedbackPaint;
+
+ public ColorButton(Context context, AttributeSet attrs) {
+ this(context, attrs, true);
+ }
+
+ public ColorButton(Context context, AttributeSet attrs, boolean init) {
+ super(context, attrs);
+ if (init) {
+ init(context);
+ }
+ }
+
+ protected void init(Context context) {
+ Resources res = getResources();
+
+ CLICK_FEEDBACK_COLOR = res.getColor(R.color.magic_flame);
+ mFeedbackPaint = new Paint();
+ mFeedbackPaint.setStyle(Style.STROKE);
+ mFeedbackPaint.setStrokeWidth(2);
+ getPaint().setColor(res.getColor(R.color.button_text));
+
+ mAnimStart = -1;
+
+ if (context instanceof FontSizeAdjuster) {
+ ((FontSizeAdjuster) context).adjustFontSize(this);
+ }
+ }
+
+
+ @Override
+ public void onSizeChanged(int w, int h, int oldW, int oldH) {
+ measureText();
+ }
+
+ protected void measureText() {
+ Paint paint = getPaint();
+
+ if (getText() != null) {
+ textPosition = getTextPosition(paint, getText());
+ }
+ }
+
+ private Point2d getTextPosition(@NotNull Paint paint, @NotNull CharSequence text) {
+ final Point2d result = new Point2d();
+
+ result.setX((getWidth() - paint.measureText(text.toString())) / 2);
+
+ float height = getHeight() - paint.ascent() - paint.descent();
+
+ result.setY(height / 2);
+
+ return result;
+ }
+
+ @Override
+ protected void onTextChanged(CharSequence text, int start, int before, int after) {
+ measureText();
+ }
+
+ private void drawMagicFlame(int duration, Canvas canvas) {
+ int alpha = 255 - 255 * duration / CLICK_FEEDBACK_DURATION;
+ int color = CLICK_FEEDBACK_COLOR | (alpha << 24);
+
+ mFeedbackPaint.setColor(color);
+ canvas.drawRect(1, 1, getWidth() - 1, getHeight() - 1, mFeedbackPaint);
+ }
+
+ @Override
+ public void onDraw(Canvas canvas) {
+ if (mAnimStart != -1) {
+ int animDuration = (int) (System.currentTimeMillis() - mAnimStart);
+
+ if (animDuration >= CLICK_FEEDBACK_DURATION) {
+ mAnimStart = -1;
+ } else {
+ drawMagicFlame(animDuration, canvas);
+ postInvalidateDelayed(CLICK_FEEDBACK_INTERVAL);
+ }
+ } else if (isPressed()) {
+ drawMagicFlame(0, canvas);
+ }
+
+ CharSequence text = getText();
+ if (text != null && textPosition != null) {
+ canvas.drawText(text, 0, text.length(), textPosition.getX(), textPosition.getY(), getPaint());
+ }
+ }
+
+ public void animateClickFeedback() {
+ mAnimStart = System.currentTimeMillis();
+ invalidate();
+ }
+
+ @Override
+ public boolean onTouchEvent(MotionEvent event) {
+ boolean result = super.onTouchEvent(event);
+
+ switch (event.getAction()) {
+ case MotionEvent.ACTION_UP:
+ animateClickFeedback();
+ break;
+ case MotionEvent.ACTION_DOWN:
+ case MotionEvent.ACTION_CANCEL:
+ invalidate();
+ break;
+ }
+
+ return result;
+ }
+}
diff --git a/src/org/solovyev/android/view/DirectionDragButton.java b/src/org/solovyev/android/view/DirectionDragButton.java
index 761e212a..9828a844 100644
--- a/src/org/solovyev/android/view/DirectionDragButton.java
+++ b/src/org/solovyev/android/view/DirectionDragButton.java
@@ -2,12 +2,16 @@ package org.solovyev.android.view;
import android.content.Context;
import android.content.res.TypedArray;
+import android.graphics.Canvas;
+import android.graphics.Paint;
import android.text.Html;
+import android.text.TextPaint;
import android.util.AttributeSet;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.solovyev.android.calculator.R;
import org.solovyev.util.StringUtils;
+import org.solovyev.util.math.Point2d;
/**
* User: serso
@@ -25,15 +29,20 @@ public class DirectionDragButton extends DragButton {
@Nullable
private String textMiddle;
+ @NotNull
+ private Point2d textUpPosition;
+
+ @NotNull
+ private Point2d textDownPosition;
+
+ @NotNull
+ private TextPaint upDownTextPaint;
+
public DirectionDragButton(Context context, @NotNull AttributeSet attrs) {
- super(context, attrs);
+ super(context, attrs, false);
init(context, attrs);
}
- public DirectionDragButton(Context context, AttributeSet attrs, int defStyle) {
- super(context, attrs, defStyle);
- init(context, attrs);
- }
private void init(@NotNull Context context, @NotNull AttributeSet attrs) {
@@ -55,19 +64,81 @@ public class DirectionDragButton extends DragButton {
// backup text
this.textMiddle = String.valueOf(getText());
- setText(Html.fromHtml(getStyledUpDownText(this.textUp) + "" + StringUtils.getNotEmpty(this.textMiddle, " ") + " " + getStyledUpDownText(this.textDown)));
+ super.init(context);
+ }
- // change top padding in order to show all text
- setPadding(getPaddingLeft(), -7, getPaddingRight(), getPaddingBottom());
+ @Override
+ protected void measureText() {
+ super.measureText();
+
+ final Paint basePaint = getPaint();
+ initUpDownTextPaint(basePaint);
+
+ if (textUp != null) {
+ textUpPosition = getTextPosition(upDownTextPaint, basePaint, textUp, 1);
+ }
+
+ if (textDown != null) {
+ textDownPosition = getTextPosition(upDownTextPaint, basePaint, textDown, -1);
+ }
+
+ if ( textDownPosition != null && textUpPosition != null ) {
+ if ( textDownPosition.getX() > textUpPosition.getX() ) {
+ textDownPosition.setX(textUpPosition.getX());
+ } else {
+ textUpPosition.setX(textDownPosition.getX());
+ }
+ }
+
+ }
+
+ private Point2d getTextPosition(@NotNull Paint paint, @NotNull Paint basePaint, @NotNull CharSequence text, float direction) {
+ final Point2d result = new Point2d();
+
+ float width = paint.measureText(text.toString() + " ");
+ result.setX(getWidth() - width);
+
+ float selfHeight = paint.ascent() + paint.descent();
+
+ basePaint.measureText(StringUtils.getNotEmpty(getText(), "|"));
+
+ float height = getHeight() - basePaint.ascent() - basePaint.descent();
+ if (direction < 0) {
+ result.setY(height / 2 - direction * height / 3 + selfHeight);
+ } else {
+ result.setY(height / 2 - direction * height / 3);
+ }
+
+ return result;
+ }
+
+ @Override
+ public void onDraw(Canvas canvas) {
+ super.onDraw(canvas);
+
+ initUpDownTextPaint(null);
+
+ if (textUp != null && textUpPosition != null) {
+ canvas.drawText(textUp, 0, textUp.length(), textUpPosition.getX(), textUpPosition.getY(), upDownTextPaint);
+ }
+
+ if (textDown != null && textDownPosition != null) {
+ canvas.drawText(textDown, 0, textDown.length(), textDownPosition.getX(), textDownPosition.getY(), upDownTextPaint);
+ }
+ }
+
+ private void initUpDownTextPaint(@Nullable Paint paint) {
+ if (paint == null) {
+ paint = getPaint();
+ }
+
+ upDownTextPaint = new TextPaint(paint);
+ upDownTextPaint.setAlpha(150);
+ upDownTextPaint.setTextSize(paint.getTextSize() / 2);
}
private String getStyledUpDownText(@Nullable String text) {
- final StringBuilder sb = new StringBuilder();
-
- sb.append("");
- sb.append(StringUtils.getNotEmpty(text, " "));
- sb.append(" ");
- return sb.toString();
+ return StringUtils.getNotEmpty(text, " ");
}
public void setTextUp(@Nullable String textUp) {
diff --git a/src/org/solovyev/android/view/DragButton.java b/src/org/solovyev/android/view/DragButton.java
index 6c5e99a2..f1347fe3 100644
--- a/src/org/solovyev/android/view/DragButton.java
+++ b/src/org/solovyev/android/view/DragButton.java
@@ -2,22 +2,15 @@ package org.solovyev.android.view;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
-import org.solovyev.android.calculator.R;
-import org.solovyev.common.utils.StringsUtils;
-import org.solovyev.util.StringUtils;
-import org.solovyev.util.math.MathUtils;
import org.solovyev.util.math.Point2d;
import android.content.Context;
-import android.content.res.TypedArray;
-import android.text.Html;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
-import android.widget.Button;
-public class DragButton extends Button {
+public class DragButton extends ColorButton {
@Nullable
private Point2d startPoint = null;
@@ -28,13 +21,15 @@ public class DragButton extends Button {
private final OnTouchListener onTouchListener = new OnTouchListenerImpl();
public DragButton(Context context, @NotNull AttributeSet attrs) {
- super(context, attrs);
- setOnTouchListener(this.onTouchListener);
+ this(context, attrs, true);
}
- public DragButton(Context context, AttributeSet attrs, int defStyle) {
- super(context, attrs, defStyle);
+ public DragButton(Context context, @NotNull AttributeSet attrs, boolean init) {
+ super(context, attrs, false);
setOnTouchListener(this.onTouchListener);
+ if ( init ) {
+ super.init(context);
+ }
}
public void setOnDragListener(@Nullable OnDragListener onDragListener) {
diff --git a/src/org/solovyev/android/view/FontSizeAdjuster.java b/src/org/solovyev/android/view/FontSizeAdjuster.java
new file mode 100644
index 00000000..932b6272
--- /dev/null
+++ b/src/org/solovyev/android/view/FontSizeAdjuster.java
@@ -0,0 +1,14 @@
+package org.solovyev.android.view;
+
+import android.widget.TextView;
+import org.jetbrains.annotations.NotNull;
+
+/**
+ * User: serso
+ * Date: 9/10/11
+ * Time: 7:21 PM
+ */
+public interface FontSizeAdjuster {
+
+ void adjustFontSize(@NotNull TextView textView);
+}
diff --git a/src/org/solovyev/android/view/PanelSwitcher.java b/src/org/solovyev/android/view/PanelSwitcher.java
new file mode 100644
index 00000000..b8719de9
--- /dev/null
+++ b/src/org/solovyev/android/view/PanelSwitcher.java
@@ -0,0 +1,144 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * 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.
+ */
+
+package org.solovyev.android.view;
+
+import android.view.animation.TranslateAnimation;
+import android.view.MotionEvent;
+import android.view.View;
+import android.view.GestureDetector;
+import android.widget.FrameLayout;
+import android.content.Context;
+import android.util.AttributeSet;
+
+class PanelSwitcher extends FrameLayout {
+ private static final int MAJOR_MOVE = 60;
+ private static final int ANIM_DURATION = 400;
+
+ private GestureDetector mGestureDetector;
+ private int mCurrentView;
+ private View mChildren[] = new View[0];
+
+ private int mWidth;
+ private TranslateAnimation inLeft;
+ private TranslateAnimation outLeft;
+
+ private TranslateAnimation inRight;
+ private TranslateAnimation outRight;
+
+ private static final int LEFT = 1;
+ private static final int RIGHT = 2;
+ private int mPreviousMove;
+
+ public PanelSwitcher(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ mCurrentView = 0;
+ mGestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() {
+ public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
+ float velocityY) {
+ int dx = (int) (e2.getX() - e1.getX());
+
+ // don't accept the fling if it's too short
+ // as it may conflict with a button push
+ if (Math.abs(dx) > MAJOR_MOVE && Math.abs(velocityX) > Math.abs(velocityY)) {
+ if (velocityX > 0) {
+ moveRight();
+ } else {
+ moveLeft();
+ }
+ return true;
+ } else {
+ return false;
+ }
+ }
+ });
+ }
+
+ void setCurrentIndex(int current) {
+ mCurrentView = current;
+ updateCurrentView();
+ }
+
+ private void updateCurrentView() {
+ for (int i = mChildren.length-1; i >= 0 ; --i) {
+ mChildren[i].setVisibility(i==mCurrentView ? View.VISIBLE : View.GONE);
+ }
+ }
+
+ @Override
+ public void onSizeChanged(int w, int h, int oldW, int oldH) {
+ mWidth = w;
+ inLeft = new TranslateAnimation(mWidth, 0, 0, 0);
+ outLeft = new TranslateAnimation(0, -mWidth, 0, 0);
+ inRight = new TranslateAnimation(-mWidth, 0, 0, 0);
+ outRight = new TranslateAnimation(0, mWidth, 0, 0);
+
+ inLeft.setDuration(ANIM_DURATION);
+ outLeft.setDuration(ANIM_DURATION);
+ inRight.setDuration(ANIM_DURATION);
+ outRight.setDuration(ANIM_DURATION);
+ }
+
+ protected void onFinishInflate() {
+ int count = getChildCount();
+ mChildren = new View[count];
+ for (int i = 0; i < count; ++i) {
+ mChildren[i] = getChildAt(i);
+ }
+ updateCurrentView();
+ }
+
+ @Override
+ public boolean onTouchEvent(MotionEvent event) {
+ mGestureDetector.onTouchEvent(event);
+ return true;
+ }
+
+ @Override
+ public boolean onInterceptTouchEvent(MotionEvent event) {
+ return mGestureDetector.onTouchEvent(event);
+ }
+
+ void moveLeft() {
+ // <--
+ if (mCurrentView < mChildren.length - 1 && mPreviousMove != LEFT) {
+ mChildren[mCurrentView+1].setVisibility(View.VISIBLE);
+ mChildren[mCurrentView+1].startAnimation(inLeft);
+ mChildren[mCurrentView].startAnimation(outLeft);
+ mChildren[mCurrentView].setVisibility(View.GONE);
+
+ mCurrentView++;
+ mPreviousMove = LEFT;
+ }
+ }
+
+ void moveRight() {
+ // -->
+ if (mCurrentView > 0 && mPreviousMove != RIGHT) {
+ mChildren[mCurrentView-1].setVisibility(View.VISIBLE);
+ mChildren[mCurrentView-1].startAnimation(inRight);
+ mChildren[mCurrentView].startAnimation(outRight);
+ mChildren[mCurrentView].setVisibility(View.GONE);
+
+ mCurrentView--;
+ mPreviousMove = RIGHT;
+ }
+ }
+
+ int getCurrentIndex() {
+ return mCurrentView;
+ }
+}
diff --git a/src/org/solovyev/util/StringUtils.java b/src/org/solovyev/util/StringUtils.java
index dd37f27f..62dda574 100644
--- a/src/org/solovyev/util/StringUtils.java
+++ b/src/org/solovyev/util/StringUtils.java
@@ -5,13 +5,13 @@ import org.jetbrains.annotations.Nullable;
public class StringUtils {
- public static boolean isEmpty ( @Nullable String s ){
+ public static boolean isEmpty ( @Nullable CharSequence s ){
return s == null || s.length() == 0;
}
@NotNull
- public static String getNotEmpty ( @Nullable String s, @NotNull String defaultValue ){
- return isEmpty(s) ? defaultValue : s;
+ public static String getNotEmpty ( @Nullable CharSequence s, @NotNull String defaultValue ){
+ return isEmpty(s) ? defaultValue : s.toString();
}
}