Revision: 45737
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at May 6, 2011 17:15 by arunmishra07
Initial Code
private void submitData(final String _country,final String _phone,final String _initial,final String _email,final double _wpm){
Thread _thread = new Thread(){
@Override
public void run() {
Message _msg = new Message();
_msg.what = _updataSmsLog;
String _url = "http://facebookwidgets4all.com/clients/thumbsupchamp/thumbsupsubmit.php?initials="+_initial+"&email="+_email+"&smartphone="+_phone+"&country="+_country+"&wpm="+_wpm+"&Submit=submit";
try{
URL url = new URL(_url);
URLConnection conn = url.openConnection();
int response = -1;
HttpURLConnection httpConn = (HttpURLConnection) conn;
httpConn.setAllowUserInteraction(false);
httpConn.setInstanceFollowRedirects(true);
httpConn.setRequestMethod("GET");
httpConn.connect();
response = httpConn.getResponseCode();
if (response == HttpURLConnection.HTTP_OK) {
_successFlag = true;
}
}
catch(Exception e){
}
Qualify2.this._uicallback.sendMessage(_msg);
}
};
_thread.run();
}
Handler _uicallback = new Handler(){
public void handleMessage(Message msg) {
switch(msg.what){
case _updataSmsLog :
if(_successFlag){
_progresssDialog.dismiss();
final Dialog _finalDialog=new Dialog(Qualify2.this,android.R.style.Theme_Translucent_NoTitleBar);
_finalDialog.setContentView(R.layout.final_qualify);
_finalDialog.show();
_rank=(TextView)_finalDialog.findViewById(R.id.rank);
HttpClient httpClient = new DefaultHttpClient();
HttpGet httpPost = new HttpGet("http://facebookwidgets4all.com/clients/thumbsupchamp/thumbsupsubmit.php");
httpPost.addHeader("Content-Type","application/x-www-form-urlencoded");
HttpResponse httpResponse;
try {
httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
if (httpEntity !=null) {
InputStream inputStream = httpEntity.getContent();
// Convert Stream to String
result = convertStreamToString(inputStream);
inputStream.close();
httpClient =null;
httpPost.abort();
}
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
int count = 0;
ArrayList<String> arrList = new ArrayList<String>();
String str = result;
int index = 0;
String str1 = null;
Log.e("string", str+"");
while(str.contains(" ")){
str1 = str.substring(0, str.indexOf(" "));
str = str.substring(str.indexOf(" ")+" ".length());
arrList.add(str1);
count++;
}
_rank.setText(str);
Log.e("ram", str+"");
Log.e("rank", str1+"");
facebook = new Facebook(APP_ID);
restoreCredentials(facebook);
String facebookMessage = getIntent().getStringExtra("facebookMessage");
if (facebookMessage == null){
facebookMessage = "I just typed"+" "+wpmResult+" " +"words per minute with my thumbs, how about you? http://www.thumbsupchamp.com";
}
messageToPost = facebookMessage;
Button _twitter, _facebook, _return;
_twitter=(Button)_finalDialog.findViewById(R.id.twitterBtn);
_facebook=(Button)_finalDialog.findViewById(R.id.facebookBtn);
_return=(Button)_finalDialog.findViewById(R.id.Button03);
_twitter.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
Intent intent = new Intent(Qualify2.this,TestConnect.class);
startActivity(intent);
}});
_facebook.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
if (! facebook.isSessionValid()) {
loginAndPostToWall();
}
else {
postToWall(messageToPost);
}
}
class LoginDialogListener implements DialogListener {
public void onComplete(Bundle values) {
saveCredentials(facebook);
if (messageToPost != null){
postToWall(messageToPost);
}
}
public void onFacebookError(FacebookError error) {
showToast("Authentication with Facebook failed!");
finish();
}
public void onError(DialogError error) {
showToast("Authentication with Facebook failed!");
finish();
}
public void onCancel() {
showToast("Authentication with Facebook cancelled!");
finish();
}
}
class WallPostDialogListener implements DialogListener {
public void onComplete(Bundle values) {
final String postId = values.getString("post_id");
if (postId != null) {
showToast("Message posted to your facebook wall!");
} else {
showToast("Wall post cancelled!");
}
finish();
}
public void onFacebookError(FacebookError e) {
showToast("Failed to post to wall!");
e.printStackTrace();
finish();
}
public void onError(DialogError e) {
showToast("Failed to post to wall!");
e.printStackTrace();
finish();
}
public void onCancel() {
showToast("Wall post cancelled!");
finish();
}
}
private void showToast(String message){
Toast.makeText(getApplicationContext(), message, Toast.LENGTH_SHORT).show();
}
private void postToWall(String message) {
Bundle parameters = new Bundle();
parameters.putString("message", message);
facebook.dialog(Qualify2.this, "stream.publish", parameters, new WallPostDialogListener());
}
private void loginAndPostToWall() {
facebook.authorize(Qualify2.this,PERMISSIONS, new LoginDialogListener());
}});
_return.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
Qualify2.this.finish();
}});
//Toast.makeText(Qualify2.this,"Data Saved Successfully",Toast.LENGTH_LONG).show();
}
else{
_progresssDialog.dismiss();
Toast.makeText(Qualify2.this,"Network Error",Toast.LENGTH_LONG).show();
}
}
}
Initial URL
Initial Description
Initial Title
Submit data on network
Initial Tags
data, java
Initial Language
Java