Skip to content

Commit

Permalink
issue resolved
Browse files Browse the repository at this point in the history
  • Loading branch information
surinder83singh committed Dec 10, 2016
1 parent 4eadb25 commit c108160
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ protected FieldView buildFieldView(Field field) {
case Field.TYPE_ANGLE: {
BasicFieldAngleView fieldAngleView = new BasicFieldAngleView(mContext);
fieldAngleView.setField((FieldAngle) field);
fieldAngleView.setWorkspaceHelper(mHelper);
return fieldAngleView;
}
case Field.TYPE_CHECKBOX: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import android.util.AttributeSet;
import android.widget.TextView;

import com.google.blockly.android.ui.WorkspaceHelper;
import com.google.blockly.model.Field;
import com.google.blockly.model.FieldAngle;

Expand All @@ -29,21 +30,16 @@
*/
public class BasicFieldAngleView extends TextView implements FieldView {
private static final char DEGREE_SYMBOL = '\u00B0';
protected WorkspaceHelper mHelper;

protected Field.Observer mFieldObserver = new Field.Observer() {
@Override
public void onValueChanged(Field angleField, String oldValue, String newValue) {
assert (angleField == mAngleField);

CharSequence curDisplayText = getText();
int len = curDisplayText.length();

// Trim the degree symbol
if (len > 0 && curDisplayText.charAt(len - 1) == DEGREE_SYMBOL) {
curDisplayText = curDisplayText.subSequence(0, len - 1);
}
String curDisplayText = removeSymbol(getText().toString());
if (!newValue.contentEquals(curDisplayText)) {
setText(newValue + DEGREE_SYMBOL);
setValue(newValue);
}
}
};
Expand All @@ -65,6 +61,41 @@ public BasicFieldAngleView(Context context, AttributeSet attrs, int defStyleAttr
initTextWatcher();
}

public void setWorkspaceHelper(WorkspaceHelper helper){
mHelper = helper;
setValue(getCleanValue());
}

public String getCleanValue(){
if(mAngleField!=null){
return Float.toString(mAngleField.getAngle());
}
return removeSymbol(getText().toString());
}

private String removeSymbol(String string){
int len = string.length();

// Trim the degree symbol
if (len > 0){
if(string.charAt(len - 1) == DEGREE_SYMBOL) {
string = string.substring(0, len - 1);
}else if(string.charAt(0) == DEGREE_SYMBOL){
string = string.substring(1);
}
}

return string;
}

private void setValue(String value){
if(mHelper!=null && mHelper.useRtl()) {
setText(DEGREE_SYMBOL + value);
}else{
setText(value + DEGREE_SYMBOL);
}
}

private void initTextWatcher() {
addTextChangedListener(new TextWatcher() {
@Override
Expand Down Expand Up @@ -96,8 +127,7 @@ public void setField(Field field) {
}
mAngleField = angleField;
if (mAngleField != null) {
// TODO(#438): Degree symbol on the left in RTL modes
setText(Float.toString(mAngleField.getAngle()) + DEGREE_SYMBOL);
setValue(Float.toString(mAngleField.getAngle()));
mAngleField.registerObserver(mFieldObserver);
} else {
setText("");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.google.blockly.android.ui.BlockTouchHandler;
import com.google.blockly.android.ui.BlockViewFactory;
import com.google.blockly.android.ui.WorkspaceHelper;
import com.google.blockly.android.ui.fieldview.BasicFieldAngleView;
import com.google.blockly.android.ui.fieldview.BasicFieldVariableView;
import com.google.blockly.android.ui.fieldview.FieldView;
import com.google.blockly.model.Block;
Expand Down Expand Up @@ -133,6 +134,11 @@ protected FieldView buildFieldView(Field field) {
colorView.setWorkspaceHelper(mHelper);
break;
}
case Field.TYPE_ANGLE: {
BasicFieldAngleView angleView = (BasicFieldAngleView) fieldView;
angleView.setWorkspaceHelper(mHelper);
break;
}
case Field.TYPE_VARIABLE: {
BasicFieldVariableView varView = (BasicFieldVariableView) fieldView;
varView.setAdapter(getVariableAdapter());
Expand Down

0 comments on commit c108160

Please sign in to comment.