1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
|
import java.util.ArrayList;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import android.app.Activity;
import android.content.DialogInterface;
import android.content.DialogInterface.OnKeyListener;
import android.os.Bundle;
import android.os.Handler;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;
public class Connection<TranslateTask> extends Activity {
private Spinner fromSpinner;
private Spinner toSpinner;
private EditText origText;
private TextView translatedText;
private TextView retransText;
private Button bsearch;
//private OnItemSelectedListener itemListener;
private Handler guiThread;
private Runnable updateTask;
private static final String SOAP_ACTION_Translate= "url/methode";
private static final String METHOD_TRANSLATE= "ma_fonction";
private static final String NAMESPACE= "le_namespace";
private static final String URL= "http://url_exact_de_ma_service.svc";
//getting the word to translate and the languages:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
findViews();
getLanguages();
bsearch.setOnClickListener(new OnClickListener() {
public void onClick(View view) {
Translate();
}
});
}
/** Get a handle to all user interface elements */
private void findViews() {
fromSpinner = (Spinner) findViewById(R.id.from_language);
toSpinner = (Spinner) findViewById(R.id.to_language);
origText = (EditText) findViewById(R.id.original_text);
translatedText = (TextView) findViewById(R.id.translated_text);
bsearch = (Button)findViewById(R.id.search);
}//findViews()
/**choisir une langue:
*/
private void getLanguages() {
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
this, R.array.languages,
android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(
android.R.layout.simple_spinner_dropdown_item);
fromSpinner.setAdapter(adapter);
toSpinner.setAdapter(adapter);
//default languages :
fromSpinner.setSelection(0); // German (Ge)
toSpinner.setSelection(4); // Wolof (fr)
}
/** this nethode handles the methode GetTranslation from the API :*/
@SuppressWarnings("unchecked")
private void Translate() {
String wordToTranslate = origText.getText().toString().trim();
int fLang = fromSpinner.getSelectedItemPosition();
int tLang = toSpinner.getSelectedItemPosition();
SoapObject Request = new SoapObject(NAMESPACE,METHOD_TRANSLATE);
PropertyInfo param1 =new PropertyInfo();
/* je veux initialiser ma fonction :*/
//premier parametre :
param1.setName("fLang");
param1.setValue(fLang);
Request.addProperty(param1);
//2eme parametre:
PropertyInfo param2 =new PropertyInfo();
param2.setName("tLang");
param2.setValue(tLang);
Request.addProperty(param2);
//3 eme parametre :
PropertyInfo param3 =new PropertyInfo();
param3.setName("word");
param3.setValue(wordToTranslate);
Request.addProperty(param3);
/*************** :cry: début probléme:******************/
SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
soapEnvelope.dotNet=true;
soapEnvelope.setOutputSoapObject(Request);
HttpTransportSE androidHttpTransport= new HttpTransportSE(URL);
//ma fonction doit retourner un array:
ArrayList <String> a= new ArrayList<String>();
try{
androidHttpTransport.call(SOAP_ACTION_Translate, soapEnvelope);
java.util.Vector<String>receiveString=(java.util.Vector<String>)soapEnvelope.getResponse();
if(receiveString!=null)
{
//je mets mes strings retournés par ma fonction dans l' ArrayList:
for(String b :receiveString)
a.add(b);
}
}
/************ :mouarf: fin probléme*******************/
catch(Exception e){
e.printStackTrace();
}
//testons ce qu'il y' a dans a:
if(a.isEmpty()){
translatedText.setText("a est vide");
}else
translatedText.setText("a n'est pas vide !");
} |