Permalink
Browse files

more code cleanup

  • Loading branch information...
1 parent fec3d0d commit a5a237561d6e7c9c5f318e4961b0be781e82c7c4 @Xlythe committed Feb 9, 2013
View
@@ -12,6 +12,8 @@
<meta-data android:name="com.sec.android.support.multiwindow" android:value="true" />
<meta-data android:name="com.sec.android.multiwindow.DEFAULT_SIZE_W" android:resource="@dimen/app_defaultsize_w" />
<meta-data android:name="com.sec.android.multiwindow.DEFAULT_SIZE_H" android:resource="@dimen/app_defaultsize_h" />
+ <meta-data android:name="com.sec.android.multiwindow.MINIMUM_SIZE_W" android:resource="@dimen/app_minimumsize_w" />
+ <meta-data android:name="com.sec.android.multiwindow.MINIMUM_SIZE_H" android:resource="@dimen/app_minimumsize_h" />
<activity android:name=".Calculator"
android:theme="@android:style/Theme.Holo.NoActionBar"
android:windowSoftInputMode="stateAlwaysHidden"
View
@@ -93,7 +93,7 @@
android:id="@+id/panelswitch"
android:layout_width="match_parent"
android:layout_height="match_parent"
- android:layout_marginTop="@dimen/barHeight" />
+ android:layout_marginTop="@dimen/history_bar_height" />
</RelativeLayout>
</LinearLayout>
<include layout="@layout/simple_cling"
View
@@ -57,7 +57,7 @@
android:id="@+id/panelswitch"
android:layout_width="match_parent"
android:layout_height="match_parent"
- android:layout_marginTop="@dimen/barHeight" />
+ android:layout_marginTop="@dimen/history_bar_height" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
@@ -79,15 +79,15 @@
<FrameLayout
android:layout_width="0dp"
android:layout_weight="1"
- android:layout_height="@dimen/barHeight">
+ android:layout_height="@dimen/history_bar_height">
<!-- marginRight has to be 0 to catch border-touch -->
<com.android2.calculator3.view.ColorButton
android:id="@+id/clear"
android:text="@string/clear"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginRight="0dp"
- android:textSize="15dp"
+ android:textSize="15sp"
style="@style/button_style" />
<!-- marginRight has to be 0 to catch border-touch -->
<com.android2.calculator3.view.ColorButton
@@ -96,7 +96,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginRight="0dp"
- android:textSize="15dp"
+ android:textSize="15sp"
style="@style/button_style" />
</FrameLayout>
</LinearLayout>
@@ -94,7 +94,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
- android:layout_marginTop="@dimen/barHeight">
+ android:layout_marginTop="@dimen/history_bar_height">
<com.android2.calculator3.view.CalculatorViewPager
android:id="@+id/smallPanelswitch"
@@ -91,7 +91,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
- android:layout_marginTop="@dimen/barHeight">
+ android:layout_marginTop="@dimen/history_bar_height">
<com.android2.calculator3.view.CalculatorViewPager
android:id="@+id/smallPanelswitch"
android:layout_width="match_parent"
@@ -14,5 +14,5 @@
limitations under the License.
-->
<resources>
- <dimen name="barHeight">60dp</dimen>
+ <dimen name="history_bar_height">60dp</dimen>
</resources>
@@ -15,5 +15,5 @@
-->
<resources>
<dimen name="group_padding">48sp</dimen>
- <dimen name="barHeight">25dp</dimen>
+ <dimen name="history_bar_height">25dp</dimen>
</resources>
View
@@ -23,9 +23,15 @@
<dimen name="small_display_text_size">20sp</dimen>
<dimen name="min_display_height">100dp</dimen>
<dimen name="max_display_height">200dp</dimen>
- <dimen name="barHeight">25dp</dimen>
+ <dimen name="history_bar_height">25dp</dimen>
+ <dimen name="matrix_edit_text_padding">17dp</dimen>
+ <dimen name="button_hint_offset_x">10dp</dimen>
+ <dimen name="button_hint_offset_y">20dp</dimen>
+ <dimen name="button_hint_exponent_jump">10dp</dimen>
<dimen name="app_defaultsize_w">632.0dip</dimen>
<dimen name="app_defaultsize_h">598.0dip</dimen>
+ <dimen name="app_minimumsize_w">300dp</dimen>
+ <dimen name="app_minimumsize_h">300dp</dimen>
<!-- Cling -->
<dimen name="clingPunchThroughGraphicCenterRadius">94dp</dimen>
@@ -151,7 +151,7 @@ public void onCreate(Bundle state) {
mDisplay = (CalculatorDisplay) findViewById(R.id.display);
mPulldown = (Slider) findViewById(R.id.pulldown);
- mPulldown.setBarHeight(getResources().getDimensionPixelSize(R.dimen.barHeight));
+ mPulldown.setBarHeight(getResources().getDimensionPixelSize(R.dimen.history_bar_height));
mPulldown.setSlideDirection(Direction.DOWN);
mPulldown.setOnSlideListener(new OnSlideListener() {
@Override
@@ -1,42 +0,0 @@
-package com.android2.calculator3;
-
-import android.content.Context;
-import android.content.res.Resources;
-import android.util.DisplayMetrics;
-
-public class LogicalDensity {
- /**
- * This method convets dp unit to equivalent device specific value in
- * pixels.
- *
- * @param dp
- * A value in dp(Device independent pixels) unit. Which we need
- * to convert into pixels
- * @param context
- * Context to get resources and device specific display metrics
- * @return A float value to represent Pixels equivalent to dp according to
- * device
- */
- public static int convertDpToPixel(float dp, Context context) {
- Resources resources = context.getResources();
- DisplayMetrics metrics = resources.getDisplayMetrics();
- float px = dp * (metrics.densityDpi / 160f);
- return (int) px;
- }
-
- /**
- * This method converts device specific pixels to device independent pixels.
- *
- * @param px
- * A value in px (pixels) unit. Which we need to convert into db
- * @param context
- * Context to get resources and device specific display metrics
- * @return A float value to represent db equivalent to px value
- */
- public static int convertPixelsToDp(float px, Context context) {
- Resources resources = context.getResources();
- DisplayMetrics metrics = resources.getDisplayMetrics();
- float dp = px / (metrics.densityDpi / 160f);
- return (int) dp;
- }
-}
@@ -16,20 +16,22 @@
package com.android2.calculator3.view;
+import android.app.Activity;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
+import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
+import android.view.Window;
import android.widget.FrameLayout;
import com.android2.calculator3.Calculator;
-import com.android2.calculator3.LogicalDensity;
import com.android2.calculator3.R;
public class Cling extends FrameLayout {
@@ -149,7 +151,10 @@ protected void dispatchDraw(Canvas canvas) {
int dh = (int) (scale * mPunchThroughGraphic.getIntrinsicHeight());
// Determine where to draw the punch through graphic
- int statusBarHeight = LogicalDensity.convertDpToPixel(25, getContext());
+ Rect rect = new Rect();
+ Window window = ((Activity) getContext()).getWindow();
+ window.getDecorView().getWindowVisibleDisplayFrame(rect);
+ int statusBarHeight = rect.top;
int[] pos = getPunchThroughPosition();
cx = pos[0];
cy = pos[1] - statusBarHeight;
@@ -30,7 +30,6 @@
import com.android2.calculator3.Calculator;
import com.android2.calculator3.EventListener;
-import com.android2.calculator3.LogicalDensity;
import com.android2.calculator3.R;
/**
@@ -126,8 +125,9 @@ else if(isPressed()) {
CharSequence hint = getHint();
if(hint != null) {
String[] exponents = hint.toString().split(Pattern.quote("^"));
- int offsetX = LogicalDensity.convertDpToPixel(10, getContext());
- int offsetY = (int) ((mTextY + LogicalDensity.convertDpToPixel(20, getContext()) - getTextHeight(mHintPaint, hint.toString())) / 2)
+ int offsetX = getContext().getResources().getDimensionPixelSize(R.dimen.button_hint_offset_x);
+ int offsetY = (int) ((mTextY + getContext().getResources().getDimensionPixelSize(R.dimen.button_hint_offset_y) - getTextHeight(mHintPaint,
+ hint.toString())) / 2)
- getPaddingTop();
float textWidth = mHintPaint.measureText(hint.toString());
@@ -140,12 +140,12 @@ else if(isPressed()) {
for(String str : exponents) {
if(str == exponents[0]) {
canvas.drawText(str, 0, str.length(), mTextX + offsetX, mTextY - offsetY, mHintPaint);
- offsetY += LogicalDensity.convertDpToPixel(10, getContext());
+ offsetY += getContext().getResources().getDimensionPixelSize(R.dimen.button_hint_exponent_jump);
offsetX += mHintPaint.measureText(str);
}
else {
canvas.drawText(str, 0, str.length(), mTextX + offsetX, mTextY - offsetY, mHintPaint);
- offsetY += LogicalDensity.convertDpToPixel(10, getContext());
+ offsetY += getContext().getResources().getDimensionPixelSize(R.dimen.button_hint_exponent_jump);
offsetX += mHintPaint.measureText(str);
}
}
@@ -160,7 +160,7 @@ private int getTextHeight(Paint paint, String text) {
int height = bounds.height();
String[] exponents = text.split(Pattern.quote("^"));
for(int i = 1; i < exponents.length; i++) {
- height += LogicalDensity.convertDpToPixel(10, getContext());
+ height += getContext().getResources().getDimensionPixelSize(R.dimen.button_hint_exponent_jump);
}
return height;
}
@@ -33,7 +33,7 @@
import android.widget.EditText;
import com.android2.calculator3.Logic;
-import com.android2.calculator3.LogicalDensity;
+import com.android2.calculator3.R;
public class MatrixEditText extends EditText implements OnFocusChangeListener {
private static final char[] ACCEPTED_CHARS = "0123456789.-\u2212".toCharArray();
@@ -50,7 +50,8 @@ public MatrixEditText(final AdvancedDisplay display, final MatrixView parent) {
setCustomSelectionActionModeCallback(new NoTextSelectionMode());
InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(this, InputMethodManager.SHOW_IMPLICIT);
- setPadding(LogicalDensity.convertDpToPixel(17, getContext()), 0, LogicalDensity.convertDpToPixel(17, getContext()), 0);
+ int padding = getContext().getResources().getDimensionPixelSize(R.dimen.matrix_edit_text_padding);
+ setPadding(padding, 0, padding, 0);
this.parent = parent;
this.display = display;
setKeyListener(new MatrixKeyListener());

0 comments on commit a5a2375

Please sign in to comment.