Skip to content

Commit

Permalink
enable/disable views
Browse files Browse the repository at this point in the history
  • Loading branch information
Xlythe committed Feb 5, 2013
1 parent 3cf8107 commit 61bf15a
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 22 deletions.
6 changes: 3 additions & 3 deletions res/layout/history_entry.xml
Expand Up @@ -3,19 +3,19 @@
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"
android:layout_height="wrap_content"
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>
7 changes: 1 addition & 6 deletions src/com/android2/calculator3/Calculator.java
Expand Up @@ -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;
Expand Down Expand Up @@ -67,8 +66,6 @@ public class Calculator extends Activity implements Logic.Listener, OnClickListe
private Slider mPulldown;
private Graph mGraph;

private EquationFormatter mEquationFormatter;

private boolean clingActive = false;
private Direction previousDirection = Direction.DOWN;

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
15 changes: 14 additions & 1 deletion src/com/android2/calculator3/view/AdvancedDisplay.java
Expand Up @@ -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;
Expand All @@ -29,7 +30,11 @@ public class AdvancedDisplay extends LinearLayout {
Factory mFactory;

public AdvancedDisplay(Context context) {
super(context);
this(context, null);
}

public AdvancedDisplay(Context context, AttributeSet attrs) {
super(context, attrs);
setOrientation(HORIZONTAL);
}

Expand Down Expand Up @@ -166,6 +171,14 @@ public View getLastView() {
return getChildAt(getChildCount() - 1);
}

@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();
Expand Down
30 changes: 18 additions & 12 deletions src/com/android2/calculator3/view/CalculatorEditText.java
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 "";
}
Expand Down
11 changes: 11 additions & 0 deletions src/com/android2/calculator3/view/MatrixView.java
Expand Up @@ -163,6 +163,17 @@ View nextView(View currentView) {
return parent.getChildAt(parent.getChildIndex(this) + 1);
}

@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 = "[";
Expand Down

0 comments on commit 61bf15a

Please sign in to comment.