Improve MultiWindow sample

Now using only one activity able to showcase supported launching options.
Added instance counter for better visibility.

Bug: 28848683
Change-Id: Ib98dad994d39aff1b617dce4371699c846d06f6f
This commit is contained in:
Andrii Kulian
2016-05-17 19:26:48 -07:00
parent e1d8a63bc2
commit 7d7cc03dbc
8 changed files with 119 additions and 144 deletions

View File

@@ -0,0 +1,71 @@
/*
* Copyright (C) 2015 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.multiwindow;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
public class LaunchingAdjacentActivity extends Activity implements View.OnClickListener {
private static final String INSTANCE_NUMBER_KEY = "instance_number";
private static int mInstanceCount;
private int mInstanceNumber;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.launching_adjacent_layout);
findViewById(R.id.launch_settings_adjacent).setOnClickListener(this);
findViewById(R.id.launch_new_task).setOnClickListener(this);
findViewById(R.id.launch_new_task_adjacent).setOnClickListener(this);
if (savedInstanceState != null) {
mInstanceNumber = savedInstanceState.getInt(INSTANCE_NUMBER_KEY);
} else {
mInstanceNumber = mInstanceCount++;
}
((TextView) findViewById(R.id.instance_number))
.setText(getString(R.string.instance_number) + mInstanceNumber);
}
@Override
public void onClick(View v) {
if (v.getId() == R.id.launch_settings_adjacent) {
Intent intent = new Intent("android.settings.SETTINGS");
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT);
startActivity(intent);
} else if (v.getId() == R.id.launch_new_task) {
Intent intent = new Intent(this, LaunchingAdjacentActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
} else if (v.getId() == R.id.launch_new_task_adjacent) {
Intent intent = new Intent(this, LaunchingAdjacentActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK
| Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT);
startActivity(intent);
}
}
@Override
public void onSaveInstanceState(Bundle savedInstanceState) {
savedInstanceState.putInt(INSTANCE_NUMBER_KEY, mInstanceNumber);
super.onSaveInstanceState(savedInstanceState);
}
}

View File

@@ -1,45 +0,0 @@
/*
* Copyright (C) 2015 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.multiwindow;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
public class LaunchingToSideActivity extends Activity implements View.OnClickListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.launching_to_side_layout);
findViewById(R.id.launch_to_the_side).setOnClickListener(this);
findViewById(R.id.launch_new_task).setOnClickListener(this);
}
@Override
public void onClick(View v) {
if (v.getId() == R.id.launch_to_the_side) {
Intent intent = new Intent("android.settings.SETTINGS");
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT);
startActivity(intent);
} else if (v.getId() == R.id.launch_new_task) {
Intent intent = new Intent(this, MoveTaskToSideActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
startActivity(intent);
}
}
}

View File

@@ -1,22 +0,0 @@
package com.example.android.multiwindow;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
public class MoveTaskToSideActivity extends Activity implements View.OnClickListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.move_task_to_side_layout);
findViewById(R.id.button).setOnClickListener(this);
}
@Override
public void onClick(View v) {
Intent intent = new Intent(this, LaunchingToSideActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT);
startActivity(intent);
}
}