Skip to content

Instantly share code, notes, and snippets.

@jasonpolites
Created November 18, 2011 10:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasonpolites/1376163 to your computer and use it in GitHub Desktop.
Save jasonpolites/1376163 to your computer and use it in GitHub Desktop.
Socialize Action Bar Init (Simple)
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import com.socialize.ui.SocializeUI;
public class SampleActivity extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// These can be specified in a config file
// called socialize.properties and places in your assets path.
final String consumerKey = "00000000-0000-0000-000000000000";
final String consumerSecret = "00000000-0000-0000-000000000000";
// YOUR Facebook App ID
final String facebookAppId = "1234567890";
// Your entity key. May be passed as a Bundle parameter to your activity
final String entityKey = "http://someurl.com";
// Setup the credentials for Socialize
SocializeUI.getInstance().setSocializeCredentials(consumerKey, consumerSecret);
SocializeUI.getInstance().setFacebookAppId(facebookAppId);
// Disable ONLY if you experience problems
SocializeUI.getInstance().setFacebookSingleSignOnEnabled(true);
// Wrap your existing view with the action bar.
// your_layout refers to the resource ID of your current layout.
View actionBarWrapped = SocializeUI.getInstance().showActionBar(this, R.layout.your_layout, entityKey);
// Now set the view for your activity to be the wrapped view.
setContentView(actionBarWrapped);
}
}
import android.app.Activity;
import android.os.Bundle;
import com.socialize.ui.SocializeUI;
import com.socialize.ui.actionbar.ActionBarListener;
import com.socialize.ui.actionbar.ActionBarView;
public class ActionBarReloadActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String entityKey = "your_key";
// Setup a listener to retain a reference
MyActionBarListener listener = new MyActionBarListener();
// Use the listener when you show the action bar
SocializeUI.getInstance().showActionBar(this, R.layout.your_layout, entityKey, listener);
// Later (After the action bar has loaded!), you can reference the view to refresh
ActionBarView view = listener.getActionBarView();
if(view != null) {
view.setEntityKey("new_entity");
view.refresh();
}
}
// Create a class to hold the action bar. This does not have to be defined in your Activity.
protected class MyActionBarListener implements ActionBarListener {
private ActionBarView actionBarView;
@Override
public void onCreate(ActionBarView actionBar) {
// Store a reference to the actionBar view
this.actionBarView = actionBar;
}
public ActionBarView getActionBarView() {
return actionBarView;
}
}
}
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Entity entity = Entity.newInstance("http://www.example.com/object/1234", "Example Entity");
View actionBarWrapped = ActionBarUtils.showActionBar(this, R.layout.main, entity);
setContentView(actionBarWrapped);
}
SocializeUI.getInstance().setEntityLoader(new SocializeEntityLoader() {
public void loadEntity(Activity activity, Entity entity) {
// Load the original view for this entity
}
});
SocializeUI.getInstance().showActionBar(this, R.layout.your_layout, entityKey, new ActionBarListener() {
@Override
public void onCreate(ActionBarView actionBar) {
actionBar.setOnActionBarEventListener(new OnActionBarEventListener() {
@Override
public void onUpdate(ActionBarView actionBar) {
// Called when the action bar has its data updated
}
@Override
public void onPostUnlike(ActionBarView actionBar) {
// Called AFTER a user has removed a like
}
@Override
public void onPostShare(ActionBarView actionBar, Share share) {
// Called AFTER a user has posted a share
}
@Override
public void onPostLike(ActionBarView actionBar, Like like) {
// Called AFTER a user has posted a like
}
@Override
public void onLoad(ActionBarView actionBar) {
// Called when the action bar is loaded
}
@Override
public void onGetLike(ActionBarView actionBar, Like like) {
// Called when the action bar retrieves the like for the current user
}
@Override
public void onGetEntity(ActionBarView actionBar, Entity entity) {
// Called when the action bar retrieves the entity data
}
@Override
public void onClick(ActionBarView actionBar, ActionBarEvent evt) {
// Called when the user clicks on the action bar
}
});
}
});
SocializeUI.getInstance().showActionBar(this, R.layout.your_layout, entityKey, new ActionBarListener() {
@Override
public void onCreate(ActionBarView actionBar) {
// The ActionBar is really just a fancy LinearLayout
}
});
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import com.socialize.ui.SocializeUI;
public class SampleActivity extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ActionBarOptions options = new ActionBarOptions();
options.setEntityName(entityName); // Optional. Set a name for your entity if you have it.
options.setAddScrollView(false); // Disable scroll view
View actionBarWrapped = SocializeUI.getInstance().showActionBar(this, R.layout.your_layout, entityKey, options);
setContentView(actionBarWrapped);
}
}
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="@+id/socializeActionBar"
android:fillViewport="true"
android:isScrollContainer="false">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<!-- Your existing content goes here -->
</LinearLayout>
</ScrollView>
<!-- The ActionBar MUST appear AFTER your content in your layout -->
<com.socialize.ui.actionbar.ActionBarView
android:id="@id/socializeActionBar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import com.socialize.ui.SocializeUI;
public class SampleActivity extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Your entity key. May be passed as a Bundle parameter to your activity
final String entityKey = "http://someurl.com";
// Wrap your existing view with the action bar.
// your_layout refers to the resource ID of your current layout.
View actionBarWrapped = SocializeUI.getInstance().showActionBar(this, R.layout.your_layout, entityKey);
// Now set the view for your activity to be the wrapped view.
setContentView(actionBarWrapped);
}
}
// Disable ONLY if you experience problems
SocializeUI.getInstance().setFacebookSingleSignOnEnabled(false);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment