Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

enable/disable views

  • Loading branch information...
commit 61bf15a91808bc56f32184631ee4a98753f67244 1 parent 3cf8107
@Xlythe authored
View
6 res/layout/history_entry.xml
@@ -3,12 +3,13 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="12dp" >
- <TextView
+ <com.android2.calculator3.view.CalculatorEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="@dimen/small_display_text_size"
android:textColor="@color/history_input"
- android:layout_marginBottom="-5dp"
+ android:enabled="false"
+ android:background="@android:color/transparent"
android:id="@+id/base" />
<TextView
android:layout_width="match_parent"
@@ -16,6 +17,5 @@
android:textSize="@dimen/display_text_size"
android:textColor="@color/history_result"
android:gravity="right"
- android:layout_marginBottom="-5dp"
android:id="@+id/edited" />
</com.android2.calculator3.view.HistoryLine>
View
7 src/com/android2/calculator3/Calculator.java
@@ -25,7 +25,6 @@
import android.content.Intent;
import android.graphics.Point;
import android.os.Bundle;
-import android.text.Html;
import android.view.Display;
import android.view.KeyEvent;
import android.view.Menu;
@@ -67,8 +66,6 @@
private Slider mPulldown;
private Graph mGraph;
- private EquationFormatter mEquationFormatter;
-
private boolean clingActive = false;
private Direction previousDirection = Direction.DOWN;
@@ -130,8 +127,6 @@ public void onCreate(Bundle state) {
mSmallPager = (CalculatorViewPager) findViewById(R.id.smallPanelswitch);
mLargePager = (CalculatorViewPager) findViewById(R.id.largePanelswitch);
- mEquationFormatter = new EquationFormatter();
-
if(mClearButton == null) {
mClearButton = findViewById(R.id.clear);
mClearButton.setOnClickListener(mListener);
@@ -486,7 +481,7 @@ private void setUpHistory() {
entry.setHistoryEntry(he);
entry.setHistory(mHistory);
TextView base = (TextView) entry.findViewById(R.id.base);
- base.setText(Html.fromHtml(mEquationFormatter.insertSupscripts((he.getBase()))));
+ base.setText(he.getBase());
TextView edited = (TextView) entry.findViewById(R.id.edited);
edited.setText(he.getEdited());
mHistoryView.addView(entry);
View
15 src/com/android2/calculator3/view/AdvancedDisplay.java
@@ -7,6 +7,7 @@
import android.text.Editable.Factory;
import android.text.TextUtils;
import android.text.method.KeyListener;
+import android.util.AttributeSet;
import android.view.ContextMenu;
import android.view.Menu;
import android.view.MenuItem;
@@ -29,7 +30,11 @@
Factory mFactory;
public AdvancedDisplay(Context context) {
- super(context);
+ this(context, null);
+ }
+
+ public AdvancedDisplay(Context context, AttributeSet attrs) {
+ super(context, attrs);
setOrientation(HORIZONTAL);
}
@@ -167,6 +172,14 @@ public View getLastView() {
}
@Override
+ public void setEnabled(boolean enabled) {
+ super.setEnabled(enabled);
+ for(int i = 0; i < getChildCount(); i++) {
+ getChildAt(i).setEnabled(enabled);
+ }
+ }
+
+ @Override
public boolean performLongClick() {
showContextMenu();
return true;
View
30 src/com/android2/calculator3/view/CalculatorEditText.java
@@ -24,6 +24,7 @@
import android.text.Editable;
import android.text.Html;
import android.text.TextWatcher;
+import android.util.AttributeSet;
import android.view.ActionMode;
import android.view.Menu;
import android.view.MenuItem;
@@ -50,18 +51,29 @@ public void run() {
};
private String input = "";
- public CalculatorEditText(Context context) {
- super(context);
+ public CalculatorEditText(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ setUp();
}
public CalculatorEditText(final AdvancedDisplay display) {
super(display.getContext());
+ setUp();
+ mDisplay = display;
+ setOnFocusChangeListener(new OnFocusChangeListener() {
+ @Override
+ public void onFocusChange(View v, boolean hasFocus) {
+ if(hasFocus) display.mActiveEditText = CalculatorEditText.this;
+ }
+ });
+ }
+
+ private void setUp() {
setCustomSelectionActionModeCallback(new NoTextSelectionMode());
InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(this, InputMethodManager.SHOW_IMPLICIT);
mEquationFormatter = new EquationFormatter();
- mDisplay = display;
addTextChangedListener(new TextWatcher() {
boolean updating = false;
@@ -90,13 +102,6 @@ public void afterTextChanged(Editable s) {
updating = false;
}
});
-
- setOnFocusChangeListener(new OnFocusChangeListener() {
- @Override
- public void onFocusChange(View v, boolean hasFocus) {
- if(hasFocus) display.mActiveEditText = CalculatorEditText.this;
- }
- });
}
class NoTextSelectionMode implements ActionMode.Callback {
@@ -164,11 +169,12 @@ public static String load(String text, final AdvancedDisplay parent, final int p
final CalculatorEditText et = new CalculatorEditText(parent);
et.setText(text);
et.setSelection(0);
- et.setKeyListener(parent.mKeyListener);
- et.setEditableFactory(parent.mFactory);
+ if(parent.mKeyListener != null) et.setKeyListener(parent.mKeyListener);
+ if(parent.mFactory != null) et.setEditableFactory(parent.mFactory);
et.setBackgroundResource(android.R.color.transparent);
et.setTextAppearance(parent.getContext(), R.style.display_style);
et.setPadding(5, 0, 5, 0);
+ et.setEnabled(parent.isEnabled());
parent.addView(et, pos);
return "";
}
View
11 src/com/android2/calculator3/view/MatrixView.java
@@ -164,6 +164,17 @@ View nextView(View currentView) {
}
@Override
+ public void setEnabled(boolean enabled) {
+ super.setEnabled(enabled);
+ for(int row = 0; row < rows; row++) {
+ TableRow tr = (TableRow) getChildAt(row);
+ for(int column = 0; column < columns; column++) {
+ tr.getChildAt(column).setEnabled(enabled);
+ }
+ }
+ }
+
+ @Override
public String toString() {
String input = "[";
String[][] data = getDataAsString();
Please sign in to comment.
Something went wrong with that request. Please try again.