Return to Snippet

Revision: 58341
at July 9, 2012 17:51 by vinny82


Updated Code
public class ShareButtonActivity extends Activity {

	// SocialAuth Component
	SocialAuthAdapter adapter;
	
	@Override
        public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
      
        // Welcome Message
        TextView textview = (TextView)findViewById(R.id.text);
        textview.setText("Welcome to SocialAuth Demo. We are sharing text SocialAuth Android by share button.");
        
        //Create Your Own Share Button
        Button share = (Button)findViewById(R.id.sharebutton);
        share.setText("Share");
        share.setTextColor(Color.WHITE);
        share.setBackgroundResource(R.drawable.button_gradient);
        		
        // Add it to Library
        adapter = new SocialAuthAdapter(new ResponseListener());
             	 
        // Add providers
        adapter.addProvider(Provider.FACEBOOK, R.drawable.facebook);
        adapter.addProvider(Provider.TWITTER, R.drawable.twitter);
        adapter.addProvider(Provider.LINKEDIN, R.drawable.linkedin);
        adapter.addProvider(Provider.MYSPACE, R.drawable.myspace);
        adapter.enable(share);
        
    }
	
	
	/**
	 * Listens Response from Library
	 * 
	 */
	
	private final class ResponseListener implements DialogListener 
        {
		/**
		 * 
		 */
		private static final long serialVersionUID = 1L;

		public void onComplete(Bundle values) {
     	    
			// Variable to receive message status
			boolean status;
			
			Log.d("ShareButton" , "Authentication Successful");
			
			// Get name of provider after authentication
			String providerName = values.getString(SocialAuthAdapter.PROVIDER);
			Log.d("ShareButton", "Provider Name = " + providerName);
			
			try 
			{
				// Please avoid sending duplicate message. Social Media Providers block duplicate messages.
				adapter.getCurrentProvider().updateStatus("SocialAuth Android" + System.currentTimeMillis());
				status = true;
			} 
			catch (Exception e) 
			{
				status = false;
			}
			
			// Post Toast or Dialog to display on screen
			if(status)
			Toast.makeText(ShareButtonActivity.this, "Message posted on " + providerName, Toast.LENGTH_SHORT).show();	
			else
			Toast.makeText(ShareButtonActivity.this, "Message not posted on" + providerName, Toast.LENGTH_SHORT).show();	
     	    	
         }

         public void onError(SocialAuthError error) {
        	 Log.d("ShareButton" , "Authentication Error");
         }

         public void onCancel() {
        	 Log.d("ShareButton" , "Authentication Cancelled");
         }

     }

}

Revision: 58340
at July 9, 2012 17:49 by vinny82


Initial Code
public class ShareButtonActivity extends Activity {

	// SocialAuth Component
	SocialAuthAdapter adapter;
	
	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
      
        // Welcome Message
        TextView textview = (TextView)findViewById(R.id.text);
        textview.setText("Welcome to SocialAuth Demo. We are sharing text SocialAuth Android by share button.");
        
        //Create Your Own Share Button
        Button share = (Button)findViewById(R.id.sharebutton);
        share.setText("Share");
        share.setTextColor(Color.WHITE);
        share.setBackgroundResource(R.drawable.button_gradient);
        		
        // Add it to Library
        adapter = new SocialAuthAdapter(new ResponseListener());
             	 
        // Add providers
        adapter.addProvider(Provider.FACEBOOK, R.drawable.facebook);
        adapter.addProvider(Provider.TWITTER, R.drawable.twitter);
        adapter.addProvider(Provider.LINKEDIN, R.drawable.linkedin);
        adapter.addProvider(Provider.MYSPACE, R.drawable.myspace);
        adapter.enable(share);
        
    }
	
	
	/**
	 * Listens Response from Library
	 * 
	 */
	
	private final class ResponseListener implements DialogListener 
    {
		/**
		 * 
		 */
		private static final long serialVersionUID = 1L;

		public void onComplete(Bundle values) {
     	    
			// Variable to receive message status
			boolean status;
			
			Log.d("ShareButton" , "Authentication Successful");
			
			// Get name of provider after authentication
			String providerName = values.getString(SocialAuthAdapter.PROVIDER);
			Log.d("ShareButton", "Provider Name = " + providerName);
			
			try 
			{
				// Please avoid sending duplicate message. Social Media Providers block duplicate messages.
				adapter.getCurrentProvider().updateStatus("SocialAuth Android" + System.currentTimeMillis());
				status = true;
			} 
			catch (Exception e) 
			{
				status = false;
			}
			
			// Post Toast or Dialog to display on screen
			if(status)
			Toast.makeText(ShareButtonActivity.this, "Message posted on " + providerName, Toast.LENGTH_SHORT).show();	
			else
			Toast.makeText(ShareButtonActivity.this, "Message not posted on" + providerName, Toast.LENGTH_SHORT).show();	
     	    	
         }

         public void onError(SocialAuthError error) {
        	 Log.d("ShareButton" , "Authentication Error");
         }

         public void onCancel() {
        	 Log.d("ShareButton" , "Authentication Cancelled");
         }

     }

}

Initial URL
http://code.google.com/p/socialauth-android/

Initial Description
The main objective of this example is to access social media providers Facebook, Twitter and others by clicking a single button "Share".On Clicking the button 
the api will open dialog of providers. User can access the provider from dialog 
and can update the status , get friends list , user profile

Initial Title
Integrate Linkedin, Facebook, Twitter, MySpace in Android App with One SDK

Initial Tags
twitter, facebook, android

Initial Language
Java