Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Updated file to follow android standards.

  • Loading branch information...
commit d1be01a9cf0950ed796326ab3ea229d314225bb7 1 parent cf69614
@joekukish joekukish authored
View
4 RealFarm/.classpath
@@ -2,7 +2,7 @@
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/>
- <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
- <classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
+ <classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
+ <classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
<classpathentry kind="output" path="bin/classes"/>
</classpath>
View
311 RealFarm/src/com/commonsensenet/realfarm/control/kannadaNumberPicker.java
@@ -12,196 +12,199 @@
import android.widget.EditText;
import android.widget.LinearLayout;
+public class KannadaNumberPicker extends LinearLayout {
-public class kannadaNumberPicker extends LinearLayout {
-
- private final long REPEAT_DELAY = 50;
-
- private final int ELEMENT_HEIGHT =70;
- private final int ELEMENT_WIDTH = 50; // you're all squares, yo
-
- private final int MINIMUM = 0;
- private final int MAXIMUM = 999;
-
- private final int TEXT_SIZE = 25;
-
- public Integer value;
-
- Button decrement;
- Button increment;
- public EditText valueText;
-
- private Handler repeatUpdateHandler = new Handler();
-
- private boolean autoIncrement = false;
- private boolean autoDecrement = false;
-
-
- class RepetetiveUpdater implements Runnable {
+ private class RepetetiveUpdater implements Runnable {
public void run() {
- if( autoIncrement ){
+ if (mAutoIncrement) {
increment();
- repeatUpdateHandler.postDelayed( new RepetetiveUpdater(), REPEAT_DELAY );
- } else if( autoDecrement ){
+ mRepeatUpdateHandler.postDelayed(new RepetetiveUpdater(),
+ REPEAT_DELAY);
+ } else if (mAutoDecrement) {
decrement();
- repeatUpdateHandler.postDelayed( new RepetetiveUpdater(), REPEAT_DELAY );
+ mRepeatUpdateHandler.postDelayed(new RepetetiveUpdater(),
+ REPEAT_DELAY);
}
}
}
-
- public kannadaNumberPicker( Context context, AttributeSet attributeSet ) {
+
+ private static final int ELEMENT_HEIGHT = 70;
+ private static final int ELEMENT_WIDTH = 50;
+ private static final int MAXIMUM = 999;
+ private static final int MINIMUM = 0;
+ private static final long REPEAT_DELAY = 50;
+ private static final int TEXT_SIZE = 25;
+
+ private boolean mAutoDecrement;
+ private boolean mAutoIncrement;
+ private Button mDecrement;
+ private Button mIncrement;
+ private Handler mRepeatUpdateHandler;
+ private Integer mValue;
+ private EditText mValueText;
+
+ public KannadaNumberPicker(Context context, AttributeSet attributeSet) {
super(context, attributeSet);
-
- this.setLayoutParams( new LinearLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT ) );
- LayoutParams elementParams = new LinearLayout.LayoutParams( ELEMENT_HEIGHT, ELEMENT_WIDTH );
-
+
+ // sets the default values.
+ mAutoDecrement = false;
+ mAutoIncrement = false;
+ mRepeatUpdateHandler = new Handler();
+
+ setLayoutParams(new LinearLayout.LayoutParams(
+ LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
+ LayoutParams elementParams = new LinearLayout.LayoutParams(
+ ELEMENT_HEIGHT, ELEMENT_WIDTH);
+
// init the individual elements
- initDecrementButton( context );
- initValueEditText( context );
- initIncrementButton( context );
-
+ initDecrementButton(context);
+ initValueEditText(context);
+ initIncrementButton(context);
+
// Can be configured to be vertical or horizontal
- // Thanks for the help, LinearLayout!
- if( getOrientation() == VERTICAL ){
- addView( increment, elementParams );
- addView( valueText, elementParams );
- addView( decrement, elementParams );
+ // Thanks for the help, LinearLayout!
+ if (getOrientation() == VERTICAL) {
+ addView(mIncrement, elementParams);
+ addView(mValueText, elementParams);
+ addView(mDecrement, elementParams);
} else {
- addView( decrement, elementParams );
- addView( valueText, elementParams );
- addView( increment, elementParams );
+ addView(mDecrement, elementParams);
+ addView(mValueText, elementParams);
+ addView(mIncrement, elementParams);
}
}
-
- private void initIncrementButton( Context context){
- increment = new Button( context );
- increment.setTextSize( TEXT_SIZE );
- increment.setText( "+" );
-
+
+ public void decrement() {
+ if (mValue > MINIMUM) {
+ mValue--;
+ mValueText.setText(mValue.toString());
+ }
+ }
+
+ public int getValue() {
+ return mValue;
+ }
+
+ public void increment() {
+ if (mValue < MAXIMUM) {
+ mValue++;
+ mValueText.setText(mValue.toString());
+ }
+ }
+
+ private void initDecrementButton(Context context) {
+ mDecrement = new Button(context);
+ mDecrement.setTextSize(TEXT_SIZE);
+ mDecrement.setText("-");
+
+ // Decrement once for a click
+ mDecrement.setOnClickListener(new View.OnClickListener() {
+ public void onClick(View v) {
+ decrement();
+ }
+ });
+
+ // Auto Decrement for a long click
+ mDecrement.setOnLongClickListener(new View.OnLongClickListener() {
+ public boolean onLongClick(View arg0) {
+ mAutoDecrement = true;
+ mRepeatUpdateHandler.post(new RepetetiveUpdater());
+ return false;
+ }
+ });
+
+ // When the button is released, if we're auto decrementing, stop
+ mDecrement.setOnTouchListener(new View.OnTouchListener() {
+ public boolean onTouch(View v, MotionEvent event) {
+ if (event.getAction() == MotionEvent.ACTION_UP
+ && mAutoDecrement) {
+ mAutoDecrement = false;
+ }
+ return false;
+ }
+ });
+ }
+
+ private void initIncrementButton(Context context) {
+ mIncrement = new Button(context);
+ mIncrement.setTextSize(TEXT_SIZE);
+ mIncrement.setText("+");
+
// Increment once for a click
- increment.setOnClickListener(new View.OnClickListener() {
- public void onClick(View v) {
- increment();
- }
- });
-
+ mIncrement.setOnClickListener(new View.OnClickListener() {
+ public void onClick(View v) {
+ increment();
+ }
+ });
+
// Auto increment for a long click
- increment.setOnLongClickListener(
- new View.OnLongClickListener(){
- public boolean onLongClick(View arg0) {
- autoIncrement = true;
- repeatUpdateHandler.post( new RepetetiveUpdater() );
- return false;
- }
- }
- );
-
+ mIncrement.setOnLongClickListener(new View.OnLongClickListener() {
+ public boolean onLongClick(View arg0) {
+ mAutoIncrement = true;
+ mRepeatUpdateHandler.post(new RepetetiveUpdater());
+ return false;
+ }
+ });
+
// When the button is released, if we're auto incrementing, stop
- increment.setOnTouchListener( new View.OnTouchListener() {
+ mIncrement.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
- if( event.getAction() == MotionEvent.ACTION_UP && autoIncrement ){
- autoIncrement = false;
+ if (event.getAction() == MotionEvent.ACTION_UP
+ && mAutoIncrement) {
+ mAutoIncrement = false;
}
return false;
}
});
}
-
- private void initValueEditText( Context context){
-
- value = new Integer( 0 );
-
- valueText = new EditText( context );
- valueText.setTextSize( TEXT_SIZE );
- valueText.setEnabled(false);
-
-
- valueText.setOnKeyListener(new View.OnKeyListener() {
+
+ private void initValueEditText(Context context) {
+
+ mValue = new Integer(0);
+
+ mValueText = new EditText(context);
+ mValueText.setTextSize(TEXT_SIZE);
+ mValueText.setEnabled(false);
+
+ mValueText.setOnKeyListener(new View.OnKeyListener() {
public boolean onKey(View v, int arg1, KeyEvent event) {
- int backupValue = value;
+ int backupValue = mValue;
try {
- value = Integer.parseInt( ((EditText)v).getText().toString() );
- } catch( NumberFormatException nfe ){
- value = backupValue;
+ mValue = Integer.parseInt(((EditText) v).getText()
+ .toString());
+ } catch (NumberFormatException nfe) {
+ mValue = backupValue;
}
return false;
}
});
-
+
// Highlight the number when we get focus
- valueText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
+ mValueText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
public void onFocusChange(View v, boolean hasFocus) {
- if( hasFocus ){
- ((EditText)v).selectAll();
+ if (hasFocus) {
+ ((EditText) v).selectAll();
}
}
});
- valueText.setGravity( Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL );
- valueText.setText( value.toString() );
- valueText.setInputType( InputType.TYPE_CLASS_NUMBER );
-
+ mValueText.setGravity(Gravity.CENTER_VERTICAL
+ | Gravity.CENTER_HORIZONTAL);
+ mValueText.setText(mValue.toString());
+ mValueText.setInputType(InputType.TYPE_CLASS_NUMBER);
}
-
- private void initDecrementButton( Context context){
- decrement = new Button( context );
- decrement.setTextSize( TEXT_SIZE );
- decrement.setText( "-" );
-
- // Decrement once for a click
- decrement.setOnClickListener(new View.OnClickListener() {
- public void onClick(View v) {
- decrement();
- }
- });
-
-
- // Auto Decrement for a long click
- decrement.setOnLongClickListener(
- new View.OnLongClickListener(){
- public boolean onLongClick(View arg0) {
- autoDecrement = true;
- repeatUpdateHandler.post( new RepetetiveUpdater() );
- return false;
- }
- }
- );
-
- // When the button is released, if we're auto decrementing, stop
- decrement.setOnTouchListener( new View.OnTouchListener() {
- public boolean onTouch(View v, MotionEvent event) {
- if( event.getAction() == MotionEvent.ACTION_UP && autoDecrement ){
- autoDecrement = false;
- }
- return false;
- }
- });
- }
-
- public void increment(){
- if( value < MAXIMUM ){
- value = value + 1;
- valueText.setText( value.toString() );
- }
- }
-
- public void decrement(){
- if( value > MINIMUM ){
- value = value - 1;
- valueText.setText( value.toString() );
+ public void setValue(int value) {
+ // checks that it does not exceed the maximum
+ if (value > MAXIMUM) {
+ value = MAXIMUM;
}
- }
-
- public int getValue(){
- return value;
- }
-
- public void setValue( int value ){
- if( value > MAXIMUM ) value = MAXIMUM;
- if( value >= 0 ){
- this.value = value;
- valueText.setText( this.value.toString() );
+ // and the minimum
+ if (value < MINIMUM) {
+ value = MINIMUM;
}
+
+ // sets the value
+ mValue = value;
+ mValueText.setText(mValue.toString());
}
-
}
Please sign in to comment.
Something went wrong with that request. Please try again.