Skip to content

Commit

Permalink
Updated the example project to include removeAction and removeActionAt.
Browse files Browse the repository at this point in the history
  • Loading branch information
johannilsson committed Mar 4, 2011
1 parent aed73df commit da687d2
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 28 deletions.
65 changes: 40 additions & 25 deletions actionbarexample/res/layout/main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,45 @@
android:id="@+id/actionbar"
style="@style/ActionBar"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Home home"
/>
<LinearLayout
android:layout_width="match_parent"
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="20dip">
<Button
android:id="@+id/start_progress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Start Progress" />
<Button
android:id="@+id/stop_progress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Stop Progress" />
<Button
android:id="@+id/remove_actions"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Clear actionbar" />
</LinearLayout>
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginTop="20dip">
<Button
android:id="@+id/start_progress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Start Progress" />
<Button
android:id="@+id/stop_progress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Stop Progress" />
<Button
android:id="@+id/remove_actions"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Clear actionbar" />
<Button
android:id="@+id/add_action"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Add action" />
<Button
android:id="@+id/remove_action"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Remove action" />
<Button
android:id="@+id/remove_share_action"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Remove share action" />
</LinearLayout>
</ScrollView>
</LinearLayout>
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.markupartist.android.actionbar.example;

import com.markupartist.android.widget.ActionBar;
import com.markupartist.android.widget.ActionBar.Action;
import com.markupartist.android.widget.ActionBar.IntentAction;

import android.app.Activity;
Expand All @@ -10,6 +11,7 @@
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

public class HomeActivity extends Activity {
/** Called when the activity is first created. */
Expand All @@ -21,9 +23,12 @@ public void onCreate(Bundle savedInstanceState) {
final ActionBar actionBar = (ActionBar) findViewById(R.id.actionbar);
//actionBar.setHomeAction(new IntentAction(this, createIntent(this), R.drawable.ic_title_home_demo));
actionBar.setTitle("Home");
actionBar.addAction(new IntentAction(this, createShareIntent(), R.drawable.ic_title_share_default));
actionBar.addAction(new IntentAction(this, new Intent(this, OtherActivity.class), R.drawable.ic_title_export_default));


final Action shareAction = new IntentAction(this, createShareIntent(), R.drawable.ic_title_share_default);
actionBar.addAction(shareAction);
final Action otherAction = new IntentAction(this, new Intent(this, OtherActivity.class), R.drawable.ic_title_export_default);
actionBar.addAction(otherAction);

Button startProgress = (Button) findViewById(R.id.start_progress);
startProgress.setOnClickListener(new OnClickListener() {
@Override
Expand All @@ -48,7 +53,40 @@ public void onClick(View view) {
}
});

Button addAction = (Button) findViewById(R.id.add_action);
addAction.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
actionBar.addAction(new Action() {
@Override
public void performAction(View view) {
Toast.makeText(HomeActivity.this, "Added action.", Toast.LENGTH_SHORT).show();
}
@Override
public int getDrawable() {
return R.drawable.ic_title_share_default;
}
});
}
});

Button removeAction = (Button) findViewById(R.id.remove_action);
removeAction.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
int actionCount = actionBar.getActionCount();
actionBar.removeActionAt(actionCount - 1);
Toast.makeText(HomeActivity.this, "Removed action." , Toast.LENGTH_SHORT).show();
}
});

Button removeShareAction = (Button) findViewById(R.id.remove_share_action);
removeShareAction.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
actionBar.removeAction(shareAction);
}
});
}

public static Intent createIntent(Context context) {
Expand Down

0 comments on commit da687d2

Please sign in to comment.