- touchcalculator.zip
- Article
- Article.html
- bareBones.PNG
- tc1.PNG
- tcMockup.png
- TouchCalc.PNG
- TouchCalc2.jpg
- TouchCalculator
- .classpath
- .project
- AndroidManifest.xml
- assets
- bin
- classes.dex
- com
- pragmatouch
- calculator
- KeypadAdapter.class
- KeypadButton.class
- KeypadButtonCategory.class
- main$1.class
- main$2.class
- main.class
- R$attr.class
- R$color.class
- R$drawable.class
- R$id.class
- R$layout.class
- R$string.class
- R.class
- resources.ap_
- TouchCalculator.apk
- default.properties
- gen
- com
- pragmatouch
- calculator
- res
- drawable
- drawable-hdpi
- icon.png
- drawable-ldpi
- icon.png
- drawable-mdpi
- icon.png
- layout
- values
- src
- com
- pragmatouch
- calculator
|
package com.pragmatouch.calculator;
import android.widget.*;
import android.content.*;
import android.view.*;
import android.view.View.OnClickListener;
public class KeypadAdapter extends BaseAdapter {
private Context mContext;
// Declare button click listener variable
private OnClickListener mOnButtonClick;
public KeypadAdapter(Context c) {
mContext = c;
}
// Method to set button click listener variable
public void setOnButtonClickListener(OnClickListener listener) {
mOnButtonClick = listener;
}
public int getCount() {
return mButtons.length;
}
public Object getItem(int position) {
return mButtons[position];
}
public long getItemId(int position) {
return 0;
}
// create a new ButtonView for each item referenced by the Adapter
public View getView(int position, View convertView, ViewGroup parent) {
Button btn;
if (convertView == null) { // if it's not recycled, initialize some
// attributes
btn = new Button(mContext);
KeypadButton keypadButton = mButtons[position];
switch(keypadButton.mCategory)
{
case MEMORYBUFFER:
btn.setBackgroundResource(R.drawable.keypadmembuffer1);
break;
case CLEAR:
btn.setBackgroundResource(R.drawable.keypadclear1);
break;
case NUMBER:
btn.setBackgroundResource(R.drawable.keypad1);
break;
case OPERATOR:
btn.setBackgroundResource(R.drawable.keypadop1);
break;
case OTHER:
btn.setBackgroundResource(R.drawable.keypadother1);
break;
case RESULT:
btn.setBackgroundResource(R.drawable.keypadresult1);
break;
case DUMMY:
btn.setBackgroundResource(R.drawable.appvertical1);
break;
default:
btn.setBackgroundResource(R.drawable.keypad1);
break;
}
// Set OnClickListener of the button to mOnButtonClick
if(keypadButton != KeypadButton.DUMMY)
btn.setOnClickListener(mOnButtonClick);
else
btn.setClickable(false);
// Set CalculatorButton enumeration as tag of the button so that we
// will use this information from our main view to identify what to do
btn.setTag(keypadButton);
} else {
btn = (Button) convertView;
}
btn.setText(mButtons[position].getText());
return btn;
}
// Create and populate keypad buttons array with CalculatorButton enum
// values
private KeypadButton[] mButtons = { KeypadButton.MC, KeypadButton.MR,KeypadButton.MS, KeypadButton.M_ADD, KeypadButton.M_REMOVE,
KeypadButton.BACKSPACE, KeypadButton.CE, KeypadButton.C,KeypadButton.SIGN, KeypadButton.SQRT,
KeypadButton.SEVEN,KeypadButton.EIGHT, KeypadButton.NINE, KeypadButton.DIV,KeypadButton.PERCENT,
KeypadButton.FOUR, KeypadButton.FIVE,KeypadButton.SIX, KeypadButton.MULTIPLY, KeypadButton.RECIPROC,
KeypadButton.ONE, KeypadButton.TWO, KeypadButton.THREE,KeypadButton.MINUS, KeypadButton.DECIMAL_SEP,
KeypadButton.DUMMY, KeypadButton.ZERO,KeypadButton.DUMMY,KeypadButton.PLUS, KeypadButton.CALCULATE };
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.