Skip to content
Browse files

Adding intent filter options dialog

  • Loading branch information...
1 parent 070785b commit 6997f74319810a6611ce50f3bbe78245a2f3b4f8 @gnorsilva gnorsilva committed Aug 4, 2011
View
4 ActivitesLaunchModes/AndroidManifest.xml
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.novoda.demos.activitylaunchmode"
- android:versionCode="1"
- android:versionName="1.0">
+ android:versionCode="101"
+ android:versionName="1.1">
<uses-sdk android:minSdkVersion="4" />
<application android:icon="@drawable/icon" android:label="Activities launchMode Demo"
View
BIN ActivitesLaunchModes/market_resources/512x512icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
8 ActivitesLaunchModes/res/layout/main.xml
@@ -64,7 +64,7 @@
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/btn_singletop"
- android:onClick="onStandardClick"
+ android:onClick="generalOnClick"
android:id="@+id/btn_standard"
android:text="standard"
android:textColor="@color/green" />
@@ -73,7 +73,7 @@
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/btn_singletask"
- android:onClick="onSingleTopClick"
+ android:onClick="generalOnClick"
android:id="@+id/btn_singletop"
android:text="singleTop"
android:textColor="@color/blue" />
@@ -82,7 +82,7 @@
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/btn_singleInstance"
- android:onClick="onSingleTaskClick"
+ android:onClick="generalOnClick"
android:id="@+id/btn_singletask"
android:text="singleTask"
android:textColor="#ff6600" />
@@ -91,7 +91,7 @@
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
- android:onClick="onSingleInstanceClick"
+ android:onClick="generalOnClick"
android:id="@+id/btn_singleInstance"
android:text="singleInstance"
android:textColor="@color/red" />
View
5 ActivitesLaunchModes/res/menu/base_activity.xml
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+<menu xmlns:android="http://schemas.android.com/apk/res/android">
+ <item android:id="@+id/menuitem_intentfilter_mode"
+ android:title="IntentFilter mode" />
+</menu>
View
151 ActivitesLaunchModes/src/com/novoda/demos/activitylaunchmode/BaseActivity.java
@@ -3,11 +3,18 @@
import java.util.Stack;
import android.app.Activity;
+import android.app.AlertDialog.Builder;
+import android.content.DialogInterface;
import android.content.Intent;
+import android.content.DialogInterface.OnClickListener;
+import android.content.DialogInterface.OnMultiChoiceClickListener;
import android.os.Bundle;
import android.os.Handler;
import android.text.method.ScrollingMovementMethod;
import android.util.Log;
+import android.view.Menu;
+import android.view.MenuInflater;
+import android.view.MenuItem;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
@@ -16,6 +23,37 @@
public abstract class BaseActivity extends Activity {
+ private String [] intentFlagsText = {
+ "CLEAR_TOP"
+ , "CLEAR_WHEN_TASK_RESET"
+ , "EXCLUDE_FROM_RECENTS"
+ , "FORWARD_RESULT"
+ , "MULTIPLE_TASK"
+ , "NEW_TASK"
+ , "NO_HISTORY"
+ , "NO_USER_ACTION"
+ , "PREVIOUS_IS_TOP"
+ , "REORDER_TO_FRONT"
+ , "RESET_TASK_IF_NEEDED"
+ , "SINGLE_TOP"};
+
+ private int [] intentFlags = {
+ Intent.FLAG_ACTIVITY_CLEAR_TOP,
+ Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET,
+ Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS,
+ Intent.FLAG_ACTIVITY_FORWARD_RESULT,
+ Intent.FLAG_ACTIVITY_MULTIPLE_TASK,
+ Intent.FLAG_ACTIVITY_NEW_TASK,
+ Intent.FLAG_ACTIVITY_NO_HISTORY,
+ Intent.FLAG_ACTIVITY_NO_USER_ACTION,
+ Intent.FLAG_ACTIVITY_PREVIOUS_IS_TOP,
+ Intent.FLAG_ACTIVITY_REORDER_TO_FRONT,
+ Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED,
+ Intent.FLAG_ACTIVITY_SINGLE_TOP
+ };
+
+ private int chosenFlags;
+
private static final String LOG_TAG = "ActivitesLaunchDemo";
private final int DISPLAY_STACK_DELAY = 500;
@@ -48,7 +86,7 @@ public void run() {
}
};
-
+
@Override
public void onContentChanged() {
log();
@@ -58,8 +96,7 @@ public void onContentChanged() {
@Override
protected void onDestroy() {
log();
- BaseApplication app = (BaseApplication)getApplication();
- app.removeFromStack(this);
+ removeFromStack();
super.onDestroy();
}
@@ -160,26 +197,102 @@ private void addToStack() {
BaseApplication app = (BaseApplication)getApplication();
app.pushToStack(this);
}
+
+ private void removeFromStack() {
+ BaseApplication app = (BaseApplication)getApplication();
+ app.removeFromStack(this);
+ }
private String getLaunchMode(){
return "[" + hashCode() + "] " + getClass().getSimpleName();
}
-
- public void onStandardClick(View v){
- startActivity(new Intent(this, Standard.class));
- }
-
- public void onSingleTopClick(View v){
- startActivity(new Intent(this, SingleTop.class));
- }
-
- public void onSingleTaskClick(View v){
- startActivity(new Intent(this, SingleTask.class));
- }
-
- public void onSingleInstanceClick(View v){
- startActivity(new Intent(this, SingleInstance.class));
- }
+
+ public void generalOnClick(View v){
+ if(isIntentFilterMode()){
+ showIntentFilterDialog(v);
+ }else{
+ startActivity(getNextIntent(v));
+ }
+ }
+
+ private void showIntentFilterDialog(final View nextActivityBtn) {
+ chosenFlags = 0;
+ final Builder build = new Builder(this);
+ build.setTitle("List selection");
+ build.setCancelable(true);
+ final OnMultiChoiceClickListener onClick =
+ new OnMultiChoiceClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which, boolean isChecked) {
+ chosenFlags |= intentFlags[which];
+ }
+ };
+ build.setMultiChoiceItems(intentFlagsText, null, onClick);
+ build.setPositiveButton("Done", new OnClickListener() {
+ @Override public void onClick(final DialogInterface dialog, final int which) {
+ Intent intent = getNextIntent(nextActivityBtn);
+ intent.setFlags(chosenFlags);
+ startActivity(intent);
+ }
+ });
+ build.show();
+ }
+
+ private boolean isIntentFilterMode() {
+ BaseApplication app = (BaseApplication)getApplication();
+ return app.isIntentFilterMode();
+ }
+
+ private void setIntentFilterMode(boolean mode) {
+ BaseApplication app = (BaseApplication)getApplication();
+ app.setIntentFilterMode(mode);
+ }
+
+ private Intent getNextIntent(View v){
+ Class<? extends BaseActivity> nextActivity = null;
+ switch(v.getId()){
+ case R.id.btn_standard:
+ nextActivity = Standard.class;
+ break;
+ case R.id.btn_singletop:
+ nextActivity = SingleTop.class;
+ break;
+ case R.id.btn_singletask:
+ nextActivity = SingleTask.class;
+ break;
+ case R.id.btn_singleInstance:
+ nextActivity = SingleInstance.class;
+ break;
+ }
+ return new Intent(this, nextActivity);
+ }
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ MenuInflater inflater = getMenuInflater();
+ inflater.inflate(R.menu.base_activity, menu);
+ log();
+ return true;
+ }
+
+ @Override
+ public boolean onPrepareOptionsMenu(Menu menu) {
+ MenuItem filterOption = menu.findItem(R.id.menuitem_intentfilter_mode);
+ String title = "Turn " + (isIntentFilterMode() ? "off" : "on") + " IntentFilter mode";
+ filterOption.setTitle(title);
+ return super.onPrepareOptionsMenu(menu);
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ switch (item.getItemId()) {
+ case R.id.menuitem_intentfilter_mode:
+ setIntentFilterMode(!isIntentFilterMode());
+ return true;
+ default:
+ return super.onOptionsItemSelected(item);
+ }
+ }
public abstract int getBackgroundColour();
}
View
10 ActivitesLaunchModes/src/com/novoda/demos/activitylaunchmode/BaseApplication.java
@@ -14,6 +14,8 @@
private ActivityManager manager;
+ private boolean intentFilterMode;
+
@Override
public void onCreate() {
super.onCreate();
@@ -47,4 +49,12 @@ public void removeFromStack(BaseActivity activity){
return tasks.get(getCurrentTaskId());
}
+ public void setIntentFilterMode(boolean mode){
+ intentFilterMode = mode;
+ }
+
+ public boolean isIntentFilterMode(){
+ return intentFilterMode;
+ }
+
}

0 comments on commit 6997f74

Please sign in to comment.
Something went wrong with that request. Please try again.