Home | History | Annotate | Download | only in android.multiwindowplayground
      1 /*
      2  * Copyright (C) 2016 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.android.multiwindowplayground;
     18 
     19 import com.android.multiwindowplayground.activities.AdjacentActivity;
     20 import com.android.multiwindowplayground.activities.BasicActivity;
     21 import com.android.multiwindowplayground.activities.CustomConfigurationChangeActivity;
     22 import com.android.multiwindowplayground.activities.LaunchBoundsActivity;
     23 import com.android.multiwindowplayground.activities.LoggingActivity;
     24 import com.android.multiwindowplayground.activities.MinimumSizeActivity;
     25 import com.android.multiwindowplayground.activities.UnresizableActivity;
     26 
     27 import android.app.ActivityOptions;
     28 import android.content.Intent;
     29 import android.graphics.Rect;
     30 import android.os.Bundle;
     31 import android.util.Log;
     32 import android.view.View;
     33 
     34 public class MainActivity extends LoggingActivity {
     35 
     36     @Override
     37     protected void onCreate(Bundle savedInstanceState) {
     38         super.onCreate(savedInstanceState);
     39         setContentView(R.layout.activity_main);
     40 
     41         View multiDisabledMessage = findViewById(R.id.warning_multiwindow_disabled);
     42         // Display an additional message if the app is not in multiwindow mode.
     43         if (!isInMultiWindowMode()) {
     44             multiDisabledMessage.setVisibility(View.VISIBLE);
     45         } else {
     46             multiDisabledMessage.setVisibility(View.GONE);
     47         }
     48     }
     49 
     50     public void onStartUnresizableClick(View view) {
     51         Log.d(mLogTag, "** starting UnresizableActivity");
     52 
     53         /*
     54          * This activity is marked as 'unresizable' in the AndroidManifest. We need to specify the
     55          * FLAG_ACTIVITY_NEW_TASK flag here to launch it into a new task stack, otherwise the
     56          * properties from the root activity would have been inherited (which was here marked as
     57          * resizable by default).
     58         */
     59         Intent intent = new Intent(this, UnresizableActivity.class);
     60         intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
     61         startActivity(intent);
     62     }
     63 
     64     public void onStartMinimumSizeActivity(View view) {
     65         Log.d(mLogTag, "** starting MinimumSizeActivity");
     66 
     67         startActivity(new Intent(this, MinimumSizeActivity.class));
     68     }
     69 
     70     public void onStartAdjacentActivity(View view) {
     71         Log.d(mLogTag, "** starting AdjacentActivity");
     72 
     73         /*
     74          * Start this activity adjacent to the focused activity (ie. this activity) if possible.
     75          * Note that this flag is just a hint to the system and may be ignored. For example,
     76          * if the activity is launched within the same task, it will be launched on top of the
     77          * previous activity that started the Intent. That's why the Intent.FLAG_ACTIVITY_NEW_TASK
     78          * flag is specified here in the intent - this will start the activity in a new task.
     79          */
     80         Intent intent = new Intent(this, AdjacentActivity.class);
     81         intent.addFlags(Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT | Intent.FLAG_ACTIVITY_NEW_TASK);
     82         startActivity(intent);
     83     }
     84 
     85     public void onStartLaunchBoundsActivity(View view) {
     86         Log.d(mLogTag, "** starting LaunchBoundsActivity");
     87 
     88         // Define the bounds in which the Activity will be launched into.
     89         Rect bounds = new Rect(500, 300, 100, 0);
     90 
     91         // Set the bounds as an activity option.
     92         ActivityOptions options = ActivityOptions.makeBasic();
     93         options.setLaunchBounds(bounds);
     94 
     95         // Start the LaunchBoundsActivity with the specified options
     96         Intent intent = new Intent(this, LaunchBoundsActivity.class);
     97         startActivity(intent, options.toBundle());
     98 
     99     }
    100 
    101     public void onStartBasicActivity(View view) {
    102         Log.d(mLogTag, "** starting BasicActivity");
    103 
    104         // Start an Activity with the default options in the 'singleTask' launch mode as defined in
    105         // the AndroidManifest.xml.
    106         startActivity(new Intent(this, BasicActivity.class));
    107 
    108     }
    109 
    110     public void onStartCustomConfigurationActivity(View view) {
    111         Log.d(mLogTag, "** starting CustomConfigurationChangeActivity");
    112 
    113         // Start an Activity that handles all configuration changes itself.
    114         startActivity(new Intent(this, CustomConfigurationChangeActivity.class));
    115 
    116     }
    117 }
    118