Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

cleaned up matrix code

  • Loading branch information...
commit afbc96a1efbd95ec36a62c6d4d7403fa216b7b80 1 parent ee5b7a6
Will authored
8 res/layout/history_entry.xml
View
@@ -1,23 +1,23 @@
<com.android2.calculator3.HistoryLine xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
- android:layout_height="wrap_content">
+ android:layout_height="wrap_content" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="@dimen/display_text_size"
- android:id="@+id/base"/>
+ android:id="@+id/base" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="@dimen/display_text_size"
android:paddingLeft="8dp"
android:paddingRight="8dp"
- android:text="@string/equal"/>
+ android:text="@string/equal" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="@dimen/display_text_size"
android:textColor="@color/history_result"
- android:id="@+id/edited"/>
+ android:id="@+id/edited" />
</com.android2.calculator3.HistoryLine>
64 res/layout/matrix.xml
View
@@ -1,65 +1,21 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:id="@+id/matrixPopup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:orientation="horizontal"
- android:layout_gravity="center"
- >
+ android:orientation="vertical"
+ android:id="@+id/theMatrix"
+ android:background="@drawable/matrix_background" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:orientation="horizontal">
- <LinearLayout
- android:layout_width="15dp"
- android:layout_height="match_parent"
- android:background="@drawable/grip_bar_port"
- android:id="@+id/grip_bar_port"
- />
- <LinearLayout
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:orientation="vertical"
- >
- <include layout="@layout/the_matrix"/>
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="15dp"
- android:background="@drawable/grip_bar_land"
- android:id="@+id/grip_bar_land"
- />
- </LinearLayout>
+ android:orientation="horizontal" >
+ <include layout="@layout/single_matrix_input_box" />
+ <include layout="@layout/single_matrix_input_box" />
</LinearLayout>
<LinearLayout
- android:layout_width="match_parent"
+ android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:orientation="vertical"
- android:id="@+id/matrixButtons"
- android:minWidth="15dp"
- >
- <com.android2.calculator3.ColorButton
- android:id="@+id/matrixPlus"
- android:text="@string/plus"
- style="@style/button_style"
- />
- <com.android2.calculator3.ColorButton
- android:id="@+id/matrixMul"
- android:text="@string/mul"
- style="@style/button_style"
- />
- <com.android2.calculator3.ColorButton
- android:id="@+id/matrixDot"
- android:text="@string/dotProduct"
- style="@style/button_style"
- />
- <com.android2.calculator3.ColorButton
- android:id="@+id/matrixCross"
- android:text="@string/crossProduct"
- style="@style/button_style"
- />
- <com.android2.calculator3.ColorButton
- android:id="@+id/ok"
- android:text="@android:string/ok"
- style="@style/button_small_style"
- />
+ android:orientation="horizontal" >
+ <include layout="@layout/single_matrix_input_box" />
+ <include layout="@layout/single_matrix_input_box" />
</LinearLayout>
</LinearLayout>
6 res/layout/matrix_panel.xml
View
@@ -1,18 +1,18 @@
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
- android:isScrollContainer="true">
+ android:isScrollContainer="true" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/matrices"
- android:orientation="vertical">
+ android:orientation="vertical" >
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/matrix_add_drawable"
android:id="@+id/matrixAdd"
android:scaleType="fitXY"
- android:contentDescription="@null"/>
+ android:contentDescription="@null" />
</LinearLayout>
</ScrollView>
55 res/layout/matrix_popup.xml
View
@@ -0,0 +1,55 @@
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/matrixPopup"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:orientation="horizontal"
+ android:layout_gravity="center" >
+ <LinearLayout
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:orientation="horizontal">
+ <LinearLayout
+ android:layout_width="15dp"
+ android:layout_height="match_parent"
+ android:background="@drawable/grip_bar_port"
+ android:id="@+id/grip_bar_port" />
+ <LinearLayout
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:orientation="vertical" >
+ <include layout="@layout/matrix"/>
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="15dp"
+ android:background="@drawable/grip_bar_land"
+ android:id="@+id/grip_bar_land" />
+ </LinearLayout>
+ </LinearLayout>
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="vertical"
+ android:id="@+id/matrixButtons"
+ android:minWidth="15dp" >
+ <com.android2.calculator3.ColorButton
+ android:id="@+id/matrixPlus"
+ android:text="@string/plus"
+ style="@style/button_style" />
+ <com.android2.calculator3.ColorButton
+ android:id="@+id/matrixMul"
+ android:text="@string/mul"
+ style="@style/button_style" />
+ <com.android2.calculator3.ColorButton
+ android:id="@+id/matrixDot"
+ android:text="@string/dotProduct"
+ style="@style/button_style" />
+ <com.android2.calculator3.ColorButton
+ android:id="@+id/matrixCross"
+ android:text="@string/crossProduct"
+ style="@style/button_style" />
+ <com.android2.calculator3.ColorButton
+ android:id="@+id/ok"
+ android:text="@android:string/ok"
+ style="@style/button_small_style" />
+ </LinearLayout>
+</LinearLayout>
4 res/layout/single_matrix_input_box.xml
View
@@ -1,6 +1,6 @@
<EditText xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="75dp"
- android:layout_height="100dp"
+ android:layout_width="@dimen/matrixInputBoxWidth"
+ android:layout_height="@dimen/matrixInputBoxHeight"
android:inputType="number"
android:hint="@null"
android:gravity="center"
24 res/layout/the_matrix.xml
View
@@ -1,24 +0,0 @@
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:orientation="vertical"
- android:id="@+id/theMatrix"
- android:background="@drawable/matrix_background"
- >
- <LinearLayout
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:orientation="horizontal"
- >
- <include layout="@layout/single_matrix_input_box"/>
- <include layout="@layout/single_matrix_input_box"/>
- </LinearLayout>
- <LinearLayout
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:orientation="horizontal"
- >
- <include layout="@layout/single_matrix_input_box"/>
- <include layout="@layout/single_matrix_input_box"/>
- </LinearLayout>
-</LinearLayout>
4 res/values/constants.xml
View
@@ -25,5 +25,9 @@
<item type="bool" name="RETURN_TO_BASIC">true</item>
<item type="dimen" name="barHeight">25dp</item>
<item type="integer" name="barHeight">25</item>
+ <item type="dimen" name="matrixInputBoxHeight">100dp</item>
+ <item type="integer" name="matrixInputBoxHeight">100</item>
+ <item type="dimen" name="matrixInputBoxWidth">75dp</item>
+ <item type="integer" name="matrixInputBoxWidth">75</item>
<item type="string" name="wolframAlphaKey">T2YJW3-7XQX257LAP</item>
</resources>
34 src/com/android2/calculator3/MatrixFragment.java
View
@@ -4,7 +4,6 @@
import android.app.Fragment;
import android.content.Context;
import android.os.Bundle;
-import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
@@ -36,7 +35,7 @@ public View onCreateView(final LayoutInflater inflater, ViewGroup container, Bun
@Override
public void onClick(View v) {
final AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
- View view = inflater.inflate(R.layout.matrix, null);
+ View view = inflater.inflate(R.layout.matrix_popup, null);
final LinearLayout theMatrix = (LinearLayout) view.findViewById(R.id.theMatrix);
final LinearLayout matrixPopup = (LinearLayout) view.findViewById(R.id.matrixPopup);
final LinearLayout matrixButtons = (LinearLayout) matrixPopup.findViewById(R.id.matrixButtons);
@@ -162,9 +161,10 @@ public void onClick(View v) {
alertDialog.dismiss();
}
});
- DisplayMetrics metrics = new DisplayMetrics();
- getActivity().getWindowManager().getDefaultDisplay().getMetrics(metrics);
- final float logicalDensity = metrics.density;
+ int widthInDp = getResources().getInteger(R.integer.matrixInputBoxWidth);
+ int heightInDp = getResources().getInteger(R.integer.matrixInputBoxHeight);
+ final float widthInPx = LogicalDensity.convertDpToPixel(widthInDp, mContext);
+ final float heightInPx = LogicalDensity.convertDpToPixel(heightInDp, mContext);
final LinearLayout grip_bar_port = (LinearLayout) view.findViewById(R.id.grip_bar_port);
grip_bar_port.setOnTouchListener(new OnTouchListener() {
long distance = 0;
@@ -177,25 +177,25 @@ public boolean onTouch(View v, MotionEvent event) {
case MotionEvent.ACTION_UP:
break;
case MotionEvent.ACTION_MOVE:
- if((event.getX()-0.5)/logicalDensity>75+distance) {
+ if(event.getX()>widthInPx+distance) {
int rows = ((LinearLayout) theMatrix.getChildAt(0)).getChildCount();
if(rows > 1) {
for(int i=0; i<theMatrix.getChildCount(); i++) {
LinearLayout l = (LinearLayout) theMatrix.getChildAt(i);
l.removeViewAt(l.getChildCount()-1);
}
- distance += 75;
+ distance += widthInPx;
}
}
- else if((event.getX()-0.5)/logicalDensity<-75+distance) {
+ else if(event.getX()<-widthInPx+distance) {
for(int i=0; i<theMatrix.getChildCount(); i++) {
LinearLayout l = (LinearLayout) theMatrix.getChildAt(i);
EditText e = (EditText) inflater.inflate(R.layout.single_matrix_input_box, null);
- e.setWidth((int) (75*logicalDensity+0.5));
- e.setHeight((int) (100*logicalDensity+0.5));
+ e.setWidth((int) widthInPx);
+ e.setHeight((int) heightInPx);
l.addView(e);
}
- distance -= 75;
+ distance -= widthInPx;
}
break;
}
@@ -214,26 +214,26 @@ public boolean onTouch(View v, MotionEvent event) {
case MotionEvent.ACTION_UP:
break;
case MotionEvent.ACTION_MOVE:
- if((event.getY()-0.5)/logicalDensity>100+distance) {
+ if(event.getY()>heightInPx+distance) {
int rows = ((LinearLayout) theMatrix.getChildAt(0)).getChildCount();
LinearLayout l = new LinearLayout(mContext);
l.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
l.setOrientation(LinearLayout.HORIZONTAL);
for(int i=0; i<rows; i++) {
EditText e = (EditText) inflater.inflate(R.layout.single_matrix_input_box, null);
- e.setWidth((int) (75*logicalDensity+0.5));
- e.setHeight((int) (100*logicalDensity+0.5));
+ e.setWidth((int) widthInPx);
+ e.setHeight((int) heightInPx);
l.addView(e);
}
theMatrix.addView(l);
- distance += 100;
+ distance += heightInPx;
}
- else if((event.getY()-0.5)/logicalDensity<-100+distance) {
+ else if(event.getY()<-heightInPx+distance) {
int columns = theMatrix.getChildCount();
if(columns > 1) {
theMatrix.removeViewAt(0);
- distance -= 100;
+ distance -= heightInPx;
}
}
break;
Please sign in to comment.
Something went wrong with that request. Please try again.