The base files for the project & activities and XML resources
Test: build and run manually Change-Id: I6eb7f1a444703e99f592ac9106261f9c6bd90127
This commit is contained in:
@@ -0,0 +1,126 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.example.android.intentplayground;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.ActivityManager;
|
||||
import android.app.FragmentManager;
|
||||
import android.app.FragmentTransaction;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* All of the other activities extend BaseActivity, the shared functionality is implemented here
|
||||
*/
|
||||
public abstract class BaseActivity extends Activity {
|
||||
public final static String LAUNCH_FORWARD = "com.example.android.launchForward";
|
||||
public final static String BUILDER_FRAGMENT = "com.example.android.builderFragment";
|
||||
protected ComponentName mActivityToLaunch;
|
||||
protected List<ActivityManager.AppTask> mTasks;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
if (BuildConfig.DEBUG) Log.d(this.getLocalClassName(), "onCreate()");
|
||||
Intent intent = getIntent();
|
||||
FragmentManager fragmentManager = getFragmentManager();
|
||||
FragmentTransaction transaction = fragmentManager.beginTransaction();
|
||||
transaction.add(R.id.fragment_container, new CurrentTaskFragment());
|
||||
TreeFragment currentTaskFrag = new TreeFragment();
|
||||
Bundle args = new Bundle();
|
||||
args.putString(TreeFragment.FRAGMENT_TITLE,
|
||||
getString(R.string.current_task_hierarchy_title));
|
||||
currentTaskFrag.setArguments(args);
|
||||
transaction.add(R.id.fragment_container, currentTaskFrag);
|
||||
|
||||
if (intent.hasExtra(TestBase.EXPECTED_HIERARCHY)) {
|
||||
// That means this activity was launched as a test show the result fragment
|
||||
TreeFragment expectedView = new TreeFragment();
|
||||
Bundle expectedArgs = new Bundle();
|
||||
expectedArgs.putParcelable(TreeFragment.TREE_NODE,
|
||||
intent.getParcelableExtra(TestBase.EXPECTED_HIERARCHY));
|
||||
expectedArgs.putString(TreeFragment.FRAGMENT_TITLE,
|
||||
getString(R.string.expected_task_hierarchy_title));
|
||||
expectedView.setArguments(expectedArgs);
|
||||
transaction.add(R.id.fragment_container, expectedView);
|
||||
}
|
||||
|
||||
transaction.add(R.id.fragment_container, new IntentFragment());
|
||||
transaction.add(R.id.fragment_container, new IntentBuilderFragment(), BUILDER_FRAGMENT);
|
||||
transaction.commit();
|
||||
|
||||
if (intent.hasExtra(LAUNCH_FORWARD)) {
|
||||
ArrayList<Intent> intents = intent.getParcelableArrayListExtra(LAUNCH_FORWARD);
|
||||
if (!intents.isEmpty()) {
|
||||
Intent nextIntent = intents.remove(0);
|
||||
nextIntent.putParcelableArrayListExtra(LAUNCH_FORWARD, intents);
|
||||
if (BuildConfig.DEBUG) {
|
||||
Log.d(this.getLocalClassName(),
|
||||
LAUNCH_FORWARD + " " + nextIntent.getComponent().toString());
|
||||
}
|
||||
startActivity(nextIntent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Launches activity with the selected options
|
||||
*/
|
||||
public void launchActivity(View view) {
|
||||
Intent customIntent = new Intent();
|
||||
LinearLayout flagBuilder = findViewById(R.id.build_intent_flags);
|
||||
// Gather flags from flag builder checkbox list
|
||||
childrenOfGroup(flagBuilder, CheckBox.class)
|
||||
.forEach(checkbox -> {
|
||||
int flagVal = FlagUtils.value(checkbox.getText().toString());
|
||||
if (checkbox.isChecked()) customIntent.addFlags(flagVal);
|
||||
else customIntent.removeFlags(flagVal);
|
||||
});
|
||||
customIntent.setComponent(mActivityToLaunch);
|
||||
startActivity(customIntent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method to retrieve children of a certain type from a {@link ViewGroup}
|
||||
* @param group the ViewGroup to retrieve children from
|
||||
*/
|
||||
protected static <T> List<T> childrenOfGroup(ViewGroup group, Class<T> viewType) {
|
||||
List<T> list = new LinkedList<>();
|
||||
for (int i = 0; i < group.getChildCount(); i++) {
|
||||
View v = group.getChildAt(i);
|
||||
if (viewType.isAssignableFrom(v.getClass())) list.add(viewType.cast(v));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onNewIntent(Intent intent) {
|
||||
super.onNewIntent(intent);
|
||||
setIntent(intent);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.example.android.intentplayground;
|
||||
|
||||
/**
|
||||
* An activity with clearTaskOnLaunch flag set in AndroidManifest.xml
|
||||
*/
|
||||
public class ClearTaskOnLaunchActivity extends BaseActivity {}
|
||||
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.example.android.intentplayground;
|
||||
|
||||
/**
|
||||
* An activity with documentLaunch="always" set in AndroidManifest.xml
|
||||
*/
|
||||
public class DocumentLaunchAlwaysActivity extends BaseActivity {}
|
||||
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.example.android.intentplayground;
|
||||
|
||||
/**
|
||||
* An activity with documentLaunch="intoExisting" set in AndroidManifest.xml
|
||||
*/
|
||||
public class DocumentLaunchIntoActivity extends BaseActivity {}
|
||||
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.example.android.intentplayground;
|
||||
|
||||
/**
|
||||
* An activity with documentLaunch="never" set in AndroidManifest.xml
|
||||
*/
|
||||
public class DocumentLaunchNeverActivity extends BaseActivity {}
|
||||
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.example.android.intentplayground;
|
||||
|
||||
import android.content.ComponentName;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
|
||||
/**
|
||||
* A singleInstance activity that is responsible for a launching a bootstrap stack of activities
|
||||
*/
|
||||
public class LauncherActivity extends BaseActivity {
|
||||
private TestBase mTester;
|
||||
public static final String TAG = "LauncherActivity";
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
Node mRoot = new Node(new ComponentName(this, LauncherActivity.class));
|
||||
// Describe initial setup of tasks
|
||||
// create singleTask, singleInstance, and two documents in separate tasks
|
||||
mRoot.addChild( new Node(new ComponentName(this, SingleTaskActivity.class)))
|
||||
.addChild( new Node(new ComponentName(this, DocumentLaunchAlwaysActivity.class)))
|
||||
.addChild( new Node(new ComponentName(this, DocumentLaunchIntoActivity.class)));
|
||||
// Create three tasks with three activities each, with affinity set
|
||||
Node taskAffinity1 = new Node(new ComponentName(this, TaskAffinity1Activity.class));
|
||||
taskAffinity1
|
||||
.addChild(new Node(new ComponentName(this, TaskAffinity1Activity.class)))
|
||||
.addChild(new Node(new ComponentName(this, TaskAffinity1Activity.class)));
|
||||
Node taskAffinity2 = new Node(new ComponentName(this, ClearTaskOnLaunchActivity.class));
|
||||
taskAffinity2
|
||||
.addChild(new Node(new ComponentName(this, TaskAffinity2Activity.class)))
|
||||
.addChild(new Node(new ComponentName(this, TaskAffinity2Activity.class)));
|
||||
Node taskAffinity3 = new Node(new ComponentName(this, TaskAffinity3Activity.class));
|
||||
taskAffinity3
|
||||
.addChild(new Node(new ComponentName(this, TaskAffinity3Activity.class)))
|
||||
.addChild(new Node(new ComponentName(this, TaskAffinity3Activity.class)));
|
||||
mRoot.addChild(taskAffinity1).addChild(taskAffinity2).addChild(taskAffinity3);
|
||||
mTester = new TestBase(this, mRoot);
|
||||
mTester.setupActivities(TestBase.LaunchStyle.TASK_STACK_BUILDER);
|
||||
}
|
||||
|
||||
/**
|
||||
* Launches activity with the selected options
|
||||
*/
|
||||
public void launchActivity(Intent customIntent) {
|
||||
customIntent.putExtra(TestBase.EXPECTED_HIERARCHY, mTester.computeExpected(customIntent));
|
||||
startActivity(customIntent);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.example.android.intentplayground;
|
||||
|
||||
/**
|
||||
* An activity with noHistory="true" set in AndroidManifest.xml
|
||||
*/
|
||||
public class NoHistoryActivity extends BaseActivity {}
|
||||
@@ -0,0 +1,76 @@
|
||||
/** TODO: http://go/java-style#javadoc */
|
||||
package com.example.android.intentplayground;
|
||||
|
||||
import android.app.Fragment;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.view.View;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
class TestBase {
|
||||
static final String EXPECTED_HIERARCHY = "";
|
||||
enum LaunchStyle { TASK_STACK_BUILDER, COMMAND_LINE, LAUNCH_FORWARD }
|
||||
TestBase(Context context, Node hierarchy) {}
|
||||
void setupActivities(LaunchStyle style) {}
|
||||
Node computeExpected(Intent intent) { return null; }
|
||||
static Node describeTaskHierarchy(Context context) { return null; }
|
||||
|
||||
}
|
||||
class TreeFragment extends Fragment {
|
||||
static final String TREE_NODE = "";
|
||||
static final String FRAGMENT_TITLE = "";
|
||||
}
|
||||
class CurrentTaskFragment extends Fragment {}
|
||||
class IntentFragment extends Fragment {}
|
||||
class IntentBuilderFragment extends Fragment implements View.OnClickListener {
|
||||
ComponentName mActivityToLaunch;
|
||||
void selectLaunchMode(View view) {}
|
||||
public void onClick(View view) {}
|
||||
void clearFlags() {}
|
||||
void selectFlags(List<String> flags) {}
|
||||
}
|
||||
class BuildConfig {
|
||||
static final boolean DEBUG = true;
|
||||
}
|
||||
class Node implements Parcelable, Comparable<Node> {
|
||||
ComponentName name;
|
||||
boolean isTaskNode;
|
||||
int taskId;
|
||||
static final String TAG = "";
|
||||
public static final Creator<Node> CREATOR = new Creator<Node>() {
|
||||
@Override
|
||||
public Node createFromParcel(Parcel in) {
|
||||
return new Node(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Node[] newArray(int size) {
|
||||
return new Node[size];
|
||||
}
|
||||
};;
|
||||
List<Node> children;
|
||||
Node(ComponentName data) {}
|
||||
Node(int taskId) {}
|
||||
Node(Node other) {}
|
||||
Node(Parcel in) {}
|
||||
Node addChild(Node child) { return null; }
|
||||
boolean equals(Node other) { return false; }
|
||||
public int compareTo(Node o) {return 0;}
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {}
|
||||
@Override
|
||||
public int describeContents() { return 0; }
|
||||
}
|
||||
class FlagUtils {
|
||||
static List<String> discoverFlags(Intent intent) { return null; }
|
||||
static List<String> intentFlags() { return null; }
|
||||
static Map<String, List<String>> intentFlagsByCategory() { return null; }
|
||||
static int value(String flagName) { return 0; }
|
||||
static List<String> discoverActivityFlags() { return null; }
|
||||
static String camelify(String snake) { return null; }
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.example.android.intentplayground;
|
||||
|
||||
/**
|
||||
* An activity with launchMode="singleInstance" set in AndroidManifest.xml
|
||||
*/
|
||||
public class SingleInstanceActivity extends BaseActivity {}
|
||||
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.example.android.intentplayground;
|
||||
|
||||
/**
|
||||
* An activity with launchMode="singleTask" set in AndroidManifest.xml
|
||||
*/
|
||||
public class SingleTaskActivity extends BaseActivity {}
|
||||
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.example.android.intentplayground;
|
||||
|
||||
/**
|
||||
* An activity with launchMode="singleTop" set in AndroidManifest.xml
|
||||
*/
|
||||
public class SingleTopActivity extends BaseActivity {}
|
||||
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.example.android.intentplayground;
|
||||
|
||||
/**
|
||||
* An activity with taskAffinity=".t1" set in AndroidManifest.xml
|
||||
*/
|
||||
public class TaskAffinity1Activity extends BaseActivity {}
|
||||
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.example.android.intentplayground;
|
||||
|
||||
/**
|
||||
* An activity with taskAffinity=".t2" set in AndroidManifest.xml
|
||||
*/
|
||||
public class TaskAffinity2Activity extends BaseActivity {}
|
||||
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.example.android.intentplayground;
|
||||
|
||||
/**
|
||||
* An activity with taskAffinity=".t3" set in AndroidManifest.xml
|
||||
*/
|
||||
public class TaskAffinity3Activity extends BaseActivity {}
|
||||
Reference in New Issue
Block a user