fork download
  1. package com.sara.facebookappl;
  2.  
  3. import java.io.IOException;
  4. import java.net.MalformedURLException;
  5.  
  6.  
  7. import org.json.JSONException;
  8. import org.json.JSONObject;
  9.  
  10.  
  11. import android.app.Activity;
  12. import android.app.ProgressDialog;
  13. import android.content.Intent;
  14. import android.content.SharedPreferences;
  15. import android.content.SharedPreferences.Editor;
  16. import android.os.AsyncTask;
  17. import android.os.Bundle;
  18. import android.os.Looper;
  19. import android.view.Menu;
  20. import android.view.View;
  21. import android.view.View.OnClickListener;
  22. import android.widget.Button;
  23. import android.widget.ImageView;
  24. import android.widget.TextView;
  25. import android.widget.Toast;
  26.  
  27. import com.facebook.android.DialogError;
  28. import com.facebook.android.Facebook;
  29. import com.facebook.android.Facebook.DialogListener;
  30. import com.facebook.android.FacebookError;
  31. import com.facebook.android.Util;
  32.  
  33. public class MainActivity extends Activity implements OnClickListener, DialogListener {
  34.  
  35. Facebook fb;
  36. ImageView button;
  37. private SharedPreferences sp;
  38. TextView welcome;
  39. Button post;
  40.  
  41. @SuppressWarnings("deprecation")
  42. @Override
  43. protected void onCreate(Bundle savedInstanceState) {
  44. super.onCreate(savedInstanceState);
  45. setContentView(R.layout.activity_main);
  46.  
  47. post=(Button)findViewById(R.id.button1);
  48.  
  49. String APP_ID = getString(R.string.APP_ID);
  50. fb= new Facebook(APP_ID);
  51.  
  52. Looper.prepare();
  53. new PostTask().execute(fb);
  54. Looper.loop();
  55.  
  56. sp =getPreferences(MODE_PRIVATE);
  57. String access_token=sp.getString("access_token", null);
  58. long expires=sp.getLong("access_expires", 0);
  59.  
  60. if (access_token !=null) {
  61. fb.setAccessToken(access_token);
  62. }
  63. if(expires !=0) {
  64. fb.setAccessExpires(expires);
  65. }
  66.  
  67.  
  68. button=(ImageView)findViewById(R.id.login);
  69. button.setOnClickListener((OnClickListener) this);
  70. updateButtonImage();
  71.  
  72. }
  73.  
  74. private class PostTask extends AsyncTask<Facebook, Integer, String> {
  75.  
  76. ProgressDialog dialog;
  77.  
  78. protected void onPreExecute() {
  79. dialog = new ProgressDialog(MainActivity.this);
  80. dialog.setProgress(ProgressDialog.STYLE_HORIZONTAL);
  81. dialog.setMax(100);
  82. dialog.show();
  83.  
  84.  
  85. }
  86.  
  87. @SuppressWarnings("deprecation")
  88. @Override
  89. protected String doInBackground(Facebook... params) {
  90. if (fb.isSessionValid()) {
  91. button.setImageResource(R.drawable.com_facebook_loginbutton_blue);
  92. // ^logout button
  93.  
  94. JSONObject obj=null;
  95.  
  96. try {
  97. String jsonUser= fb.request("me");
  98. obj = Util.parseJson(jsonUser);
  99. String name = obj.optString("name");
  100. welcome.setText("Welcome, " + name);
  101. }catch(FacebookError e) {
  102. e.printStackTrace();
  103.  
  104. }catch (JSONException e) {
  105. e.printStackTrace();
  106. }catch (MalformedURLException e) {
  107. e.printStackTrace();
  108. }catch (IOException e) {
  109. e.printStackTrace();
  110. }
  111.  
  112. }else {
  113. post.setVisibility(Button.VISIBLE);
  114. button.setImageResource(R.drawable.com_facebook_loginbutton_blue);
  115. }
  116. return null;
  117. }
  118. }
  119.  
  120. protected void onProgressUpdated(Integer...progress) {
  121.  
  122. }
  123.  
  124. @SuppressWarnings("deprecation")
  125. protected void onPostExecute(Facebook result) {
  126.  
  127. // ^logout button
  128. try {JSONObject obj=null;
  129. String jsonUser= fb.request("me");
  130. obj = Util.parseJson(jsonUser);
  131. String name = obj.optString("name");
  132. welcome.setText("Welcome, " + name);}
  133. catch(FacebookError e) {
  134. e.printStackTrace();
  135.  
  136. }catch (JSONException e) {
  137. e.printStackTrace();
  138. }catch (MalformedURLException e) {
  139. e.printStackTrace();
  140. }catch (IOException e) {
  141. e.printStackTrace();
  142. }
  143. }
  144.  
  145.  
  146. private void updateButtonImage() {
  147. // TODO Auto-generated method stub
  148.  
  149. post.setVisibility(Button.VISIBLE);
  150. button.setImageResource(R.drawable.com_facebook_loginbutton_blue);
  151. //logout button
  152.  
  153.  
  154. }
  155.  
  156. @SuppressWarnings("deprecation")
  157. public void buttonClicks(View v) {
  158. switch (v.getId()) {
  159. case R.id.button1:
  160. //post
  161.  
  162. Bundle params= new Bundle();
  163.  
  164. params.putString("name", "User X");
  165. params.putString("caption", "Rating");
  166. params.putString("description", "User X Rated");
  167. params.putString("link", "http://...");
  168.  
  169.  
  170.  
  171. fb.dialog(MainActivity.this, "feed", params, new Facebook.DialogListener() {
  172.  
  173. @Override
  174. public void onFacebookError(FacebookError e) {
  175. // TODO Auto-generated method stub
  176.  
  177. }
  178.  
  179. @Override
  180. public void onError(DialogError e) {
  181. // TODO Auto-generated method stub
  182.  
  183. }
  184.  
  185. @Override
  186. public void onComplete(Bundle values) {
  187. // TODO Auto-generated method stub
  188.  
  189. }
  190.  
  191. @Override
  192. public void onCancel() {
  193. // TODO Auto-generated method stub
  194.  
  195. }
  196. });
  197. break;
  198. }
  199. }
  200. @SuppressWarnings("deprecation")
  201. public void onClick(View v) {
  202. if(fb.isSessionValid()) {
  203.  
  204. try {
  205. fb.logout(getApplicationContext());
  206. updateButtonImage();
  207. //button will close our our session
  208. e.printStackTrace();
  209. } catch(IOException e) {
  210. e.printStackTrace();
  211. }
  212. }else{
  213. //login into facebook
  214. fb.authorize(MainActivity.this, new String[] {"email"}, new Facebook.DialogListener() {
  215.  
  216. @Override
  217. public void onFacebookError(FacebookError e) {
  218. // TODO Auto-generated method stub
  219. Toast.makeText(MainActivity.this, "fbError", Toast.LENGTH_SHORT).show();
  220. }
  221.  
  222. @Override
  223. public void onError(DialogError e) {
  224. // TODO Auto-generated method stub
  225. Toast.makeText(MainActivity.this, "onError", Toast.LENGTH_SHORT).show();
  226. }
  227.  
  228. @Override
  229. public void onComplete(Bundle values) {
  230. // TODO Auto-generated method stub
  231. Editor editor=sp.edit();
  232. editor.putString("access_token", fb.getAccessToken());
  233. editor.putLong("access_expires", fb.getAccessExpires());
  234. editor.commit();
  235. updateButtonImage();
  236. }
  237.  
  238. @Override
  239. public void onCancel() {
  240. // TODO Auto-generated method stub
  241. Toast.makeText(MainActivity.this, "onCancel", Toast.LENGTH_SHORT).show();
  242. }
  243. });
  244.  
  245. }
  246. }
  247.  
  248.  
  249. @Override
  250. public boolean onCreateOptionsMenu(Menu menu) {
  251. // Inflate the menu; this adds items to the action bar if it is present.
  252. getMenuInflater().inflate(R.menu.activity_main, menu);
  253. return true;
  254. }
  255.  
  256. @SuppressWarnings("deprecation")
  257. @Override
  258. protected void onActivityResult(int requestCode, int resultCode, Intent data) {
  259. super.onActivityResult(requestCode, resultCode, data);
  260. fb.authorizeCallback(requestCode, resultCode, data);
  261. }
  262.  
  263. @Override
  264. public void onComplete(Bundle values) {
  265. // TODO Auto-generated method stub
  266.  
  267. }
  268.  
  269. @Override
  270. public void onFacebookError(FacebookError e) {
  271. // TODO Auto-generated method stub
  272.  
  273. }
  274.  
  275. @Override
  276. public void onError(DialogError e) {
  277. // TODO Auto-generated method stub
  278.  
  279. }
  280.  
  281. @Override
  282. public void onCancel() {
  283. // TODO Auto-generated method stub
  284.  
  285. }
  286.  
  287. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:33: class MainActivity is public, should be declared in a file named MainActivity.java
public class MainActivity extends Activity implements OnClickListener, DialogListener {
       ^
Main.java:7: package org.json does not exist
import org.json.JSONException;
               ^
Main.java:8: package org.json does not exist
import org.json.JSONObject;
               ^
Main.java:11: package android.app does not exist
import android.app.Activity;
                  ^
Main.java:12: package android.app does not exist
import android.app.ProgressDialog;
                  ^
Main.java:13: package android.content does not exist
import android.content.Intent;
                      ^
Main.java:14: package android.content does not exist
import android.content.SharedPreferences;
                      ^
Main.java:15: package android.content.SharedPreferences does not exist
import android.content.SharedPreferences.Editor;
                                        ^
Main.java:16: package android.os does not exist
import android.os.AsyncTask;
                 ^
Main.java:17: package android.os does not exist
import android.os.Bundle;
                 ^
Main.java:18: package android.os does not exist
import android.os.Looper;
                 ^
Main.java:19: package android.view does not exist
import android.view.Menu;
                   ^
Main.java:20: package android.view does not exist
import android.view.View;
                   ^
Main.java:21: package android.view.View does not exist
import android.view.View.OnClickListener;
                        ^
Main.java:22: package android.widget does not exist
import android.widget.Button;
                     ^
Main.java:23: package android.widget does not exist
import android.widget.ImageView;
                     ^
Main.java:24: package android.widget does not exist
import android.widget.TextView;
                     ^
Main.java:25: package android.widget does not exist
import android.widget.Toast;
                     ^
Main.java:27: package com.facebook.android does not exist
import com.facebook.android.DialogError;
                           ^
Main.java:28: package com.facebook.android does not exist
import com.facebook.android.Facebook;
                           ^
Main.java:29: package com.facebook.android.Facebook does not exist
import com.facebook.android.Facebook.DialogListener;
                                    ^
Main.java:30: package com.facebook.android does not exist
import com.facebook.android.FacebookError;
                           ^
Main.java:31: package com.facebook.android does not exist
import com.facebook.android.Util;
                           ^
Main.java:33: cannot find symbol
symbol: class Activity
public class MainActivity extends Activity implements OnClickListener, DialogListener {
                                  ^
Main.java:33: cannot find symbol
symbol: class OnClickListener
public class MainActivity extends Activity implements OnClickListener, DialogListener {
                                                      ^
Main.java:33: cannot find symbol
symbol: class DialogListener
public class MainActivity extends Activity implements OnClickListener, DialogListener {
                                                                       ^
Main.java:35: cannot find symbol
symbol  : class Facebook
location: class com.sara.facebookappl.MainActivity
	Facebook fb; 
	^
Main.java:36: cannot find symbol
symbol  : class ImageView
location: class com.sara.facebookappl.MainActivity
	ImageView button; 
	^
Main.java:37: cannot find symbol
symbol  : class SharedPreferences
location: class com.sara.facebookappl.MainActivity
	private SharedPreferences sp; 
	        ^
Main.java:38: cannot find symbol
symbol  : class TextView
location: class com.sara.facebookappl.MainActivity
	TextView welcome; 
	^
Main.java:39: cannot find symbol
symbol  : class Button
location: class com.sara.facebookappl.MainActivity
	Button post; 
	^
Main.java:43: cannot find symbol
symbol  : class Bundle
location: class com.sara.facebookappl.MainActivity
	protected void onCreate(Bundle savedInstanceState) {
	                        ^
Main.java:125: cannot find symbol
symbol  : class Facebook
location: class com.sara.facebookappl.MainActivity
	protected void onPostExecute(Facebook result) {
	                             ^
Main.java:157: cannot find symbol
symbol  : class View
location: class com.sara.facebookappl.MainActivity
	public void buttonClicks(View v) {
	                         ^
Main.java:201: cannot find symbol
symbol  : class View
location: class com.sara.facebookappl.MainActivity
	public void onClick(View v) {
	                    ^
Main.java:251: cannot find symbol
symbol  : class Menu
location: class com.sara.facebookappl.MainActivity
	public boolean onCreateOptionsMenu(Menu menu) {
	                                   ^
Main.java:259: cannot find symbol
symbol  : class Intent
location: class com.sara.facebookappl.MainActivity
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
	                                                                 ^
Main.java:265: cannot find symbol
symbol  : class Bundle
location: class com.sara.facebookappl.MainActivity
	public void onComplete(Bundle values) {
	                       ^
Main.java:271: cannot find symbol
symbol  : class FacebookError
location: class com.sara.facebookappl.MainActivity
	public void onFacebookError(FacebookError e) {
	                            ^
Main.java:277: cannot find symbol
symbol  : class DialogError
location: class com.sara.facebookappl.MainActivity
	public void onError(DialogError e) {
	                    ^
Main.java:74: cannot find symbol
symbol  : class AsyncTask
location: class com.sara.facebookappl.MainActivity
	private class PostTask extends AsyncTask<Facebook, Integer, String> {
	                               ^
Main.java:74: cannot find symbol
symbol  : class Facebook
location: class com.sara.facebookappl.MainActivity
	private class PostTask extends AsyncTask<Facebook, Integer, String> {
	                                         ^
Main.java:76: cannot find symbol
symbol  : class ProgressDialog
location: class com.sara.facebookappl.MainActivity.PostTask
		ProgressDialog dialog; 
		^
Main.java:89: cannot find symbol
symbol  : class Facebook
location: class com.sara.facebookappl.MainActivity.PostTask
		protected String doInBackground(Facebook... params) {
		                                ^
Main.java:44: cannot find symbol
symbol  : variable super
location: class com.sara.facebookappl.MainActivity
		super.onCreate(savedInstanceState);
		^
Main.java:45: package R does not exist
		setContentView(R.layout.activity_main);
		                ^
Main.java:47: cannot find symbol
symbol  : class Button
location: class com.sara.facebookappl.MainActivity
		post=(Button)findViewById(R.id.button1);
		      ^
Main.java:47: package R does not exist
		post=(Button)findViewById(R.id.button1);
		                           ^
Main.java:49: package R does not exist
		String APP_ID = getString(R.string.APP_ID);
		                           ^
Main.java:50: cannot find symbol
symbol  : class Facebook
location: class com.sara.facebookappl.MainActivity
		fb= new Facebook(APP_ID);
		        ^
Main.java:52: cannot find symbol
symbol  : variable Looper
location: class com.sara.facebookappl.MainActivity
		Looper.prepare(); 
		^
Main.java:54: cannot find symbol
symbol  : variable Looper
location: class com.sara.facebookappl.MainActivity
		Looper.loop(); 
		^
Main.java:56: cannot find symbol
symbol  : variable MODE_PRIVATE
location: class com.sara.facebookappl.MainActivity
		sp =getPreferences(MODE_PRIVATE);
		                   ^
Main.java:68: cannot find symbol
symbol  : class ImageView
location: class com.sara.facebookappl.MainActivity
		button=(ImageView)findViewById(R.id.login);
		        ^
Main.java:68: package R does not exist
		button=(ImageView)findViewById(R.id.login);
		                                ^
Main.java:69: cannot find symbol
symbol  : class OnClickListener
location: class com.sara.facebookappl.MainActivity
		button.setOnClickListener((OnClickListener) this);
		                           ^
Main.java:42: method does not override or implement a method from a supertype
	@Override
	^
Main.java:79: cannot find symbol
symbol  : class ProgressDialog
location: class com.sara.facebookappl.MainActivity.PostTask
			dialog = new ProgressDialog(MainActivity.this);
			             ^
Main.java:80: cannot find symbol
symbol  : variable ProgressDialog
location: class com.sara.facebookappl.MainActivity.PostTask
			dialog.setProgress(ProgressDialog.STYLE_HORIZONTAL);
			                   ^
Main.java:91: package R does not exist
				button.setImageResource(R.drawable.com_facebook_loginbutton_blue);
				                         ^
Main.java:94: cannot find symbol
symbol  : class JSONObject
location: class com.sara.facebookappl.MainActivity.PostTask
			JSONObject obj=null;
			^
Main.java:98: cannot find symbol
symbol  : variable Util
location: class com.sara.facebookappl.MainActivity.PostTask
			obj = Util.parseJson(jsonUser);
			      ^
Main.java:101: cannot find symbol
symbol  : class FacebookError
location: class com.sara.facebookappl.MainActivity.PostTask
			}catch(FacebookError e) {
			       ^
Main.java:104: cannot find symbol
symbol  : class JSONException
location: class com.sara.facebookappl.MainActivity.PostTask
			}catch (JSONException e) {
			        ^
Main.java:113: cannot find symbol
symbol  : variable Button
location: class com.sara.facebookappl.MainActivity.PostTask
				post.setVisibility(Button.VISIBLE);
				                   ^
Main.java:114: package R does not exist
				button.setImageResource(R.drawable.com_facebook_loginbutton_blue);
				                         ^
Main.java:88: method does not override or implement a method from a supertype
		@Override
		^
Main.java:128: cannot find symbol
symbol  : class JSONObject
location: class com.sara.facebookappl.MainActivity
		try {JSONObject obj=null;
		     ^
Main.java:130: cannot find symbol
symbol  : variable Util
location: class com.sara.facebookappl.MainActivity
		obj = Util.parseJson(jsonUser);
		      ^
Main.java:133: cannot find symbol
symbol  : class FacebookError
location: class com.sara.facebookappl.MainActivity
		catch(FacebookError e) {
		      ^
Main.java:136: cannot find symbol
symbol  : class JSONException
location: class com.sara.facebookappl.MainActivity
		}catch (JSONException e) {
		        ^
Main.java:149: cannot find symbol
symbol  : variable Button
location: class com.sara.facebookappl.MainActivity
		post.setVisibility(Button.VISIBLE);
		                   ^
Main.java:150: package R does not exist
		button.setImageResource(R.drawable.com_facebook_loginbutton_blue);
		                         ^
Main.java:159: package R does not exist
			case R.id.button1:
			      ^
Main.java:162: cannot find symbol
symbol  : class Bundle
location: class com.sara.facebookappl.MainActivity
				Bundle params= new Bundle();
				^
Main.java:162: cannot find symbol
symbol  : class Bundle
location: class com.sara.facebookappl.MainActivity
				Bundle params= new Bundle();
				                   ^
Main.java:171: package Facebook does not exist
				fb.dialog(MainActivity.this, "feed", params, new Facebook.DialogListener() {
				                                                         ^
Main.java:205: cannot find symbol
symbol  : method getApplicationContext()
location: class com.sara.facebookappl.MainActivity
			fb.logout(getApplicationContext());
			          ^
Main.java:215: package Facebook does not exist
			fb.authorize(MainActivity.this, new String[] {"email"}, new Facebook.DialogListener() {
			                                                                    ^
Main.java:253: package R does not exist
		getMenuInflater().inflate(R.menu.activity_main, menu);
		                           ^
Main.java:253: cannot find symbol
symbol  : method getMenuInflater()
location: class com.sara.facebookappl.MainActivity
		getMenuInflater().inflate(R.menu.activity_main, menu);
		^
Main.java:250: method does not override or implement a method from a supertype
	@Override
	^
Main.java:260: cannot find symbol
symbol  : variable super
location: class com.sara.facebookappl.MainActivity
		super.onActivityResult(requestCode, resultCode, data);
		^
Main.java:258: method does not override or implement a method from a supertype
	@Override
	^
Main.java:264: method does not override or implement a method from a supertype
	@Override
	^
Main.java:270: method does not override or implement a method from a supertype
	@Override
	^
Main.java:276: method does not override or implement a method from a supertype
	@Override
	^
Main.java:282: method does not override or implement a method from a supertype
	@Override
	^
88 errors
stdout

Standard output is empty