Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
package com.sample;
import com.calatrava.CalatravaPage;
import com.calatrava.shell.WebViewActivity;
import android.os.Bundle;
import android.widget.EditText;
import android.widget.TextView;
import android.view.View;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Iterator;
@CalatravaPage(name = "conversionForm")
public class ConversionForm extends com.calatrava.bridge.RegisteredActivity {
@Override
public String getFieldValue(String field){
if(field.equalsIgnoreCase("in_currency")){
return "USD";
}else if(field.equalsIgnoreCase("out_currency")){
return "AUD";
}else if(field.equalsIgnoreCase("in_amount")){
return ((EditText) findViewById(R.id.unconvertedEditText)).getText().toString();
}
return null;
}
@Override
public void render(final String json){
try{
JSONObject jsonObj = new JSONObject(json);
Iterator<?> keys = jsonObj.keys();
while(keys.hasNext()){
final String key = (String)keys.next();
final String value = jsonObj.getString(key);
this.runOnUiThread(new Runnable() {
@Override
public void run() {
setFieldValue(key, value);
}
});
}
}catch(JSONException e){}
}
protected void setFieldValue(String key, String value){
if(key.equalsIgnoreCase("inCurrencies")){
//TODO
}else if(key.equalsIgnoreCase("outCurrencies")){
//TODO
}else if(key.equalsIgnoreCase("in_amount")){
((EditText)findViewById(R.id.unconvertedEditText)).setText(value);
}else if(key.equalsIgnoreCase("out_amount")){
((TextView)findViewById(R.id.convertedTextView)).setText(value);
}
}
@Override
protected String getPageName() {
return "conversionForm";
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.conversion_form);
}
public void convert(View v) {
this.triggerEvent("convert", new String[] {});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.