Home | History | Annotate | Download | only in pip
      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.systemui.tv.pip;
     18 
     19 import android.animation.Animator;
     20 import android.animation.AnimatorInflater;
     21 import android.app.Activity;
     22 import android.os.Bundle;
     23 import android.view.View;
     24 
     25 import com.android.systemui.R;
     26 import com.android.systemui.Interpolators;
     27 
     28 /**
     29  * Activity to show the PIP menu to control PIP.
     30  */
     31 public class PipMenuActivity extends Activity implements PipManager.Listener {
     32     private static final String TAG = "PipMenuActivity";
     33 
     34     private final PipManager mPipManager = PipManager.getInstance();
     35 
     36     private Animator mFadeInAnimation;
     37     private Animator mFadeOutAnimation;
     38     private View mPipControlsView;
     39     private boolean mRestorePipSizeWhenClose;
     40 
     41     @Override
     42     protected void onCreate(Bundle bundle) {
     43         super.onCreate(bundle);
     44         setContentView(R.layout.tv_pip_menu);
     45         mPipManager.addListener(this);
     46 
     47         mRestorePipSizeWhenClose = true;
     48         mPipControlsView = (PipControlsView) findViewById(R.id.pip_controls);
     49         mFadeInAnimation = AnimatorInflater.loadAnimator(
     50                 this, R.anim.tv_pip_menu_fade_in_animation);
     51         mFadeInAnimation.setTarget(mPipControlsView);
     52         mFadeOutAnimation = AnimatorInflater.loadAnimator(
     53                 this, R.anim.tv_pip_menu_fade_out_animation);
     54         mFadeOutAnimation.setTarget(mPipControlsView);
     55     }
     56 
     57     private void restorePipAndFinish() {
     58         if (mRestorePipSizeWhenClose) {
     59             // When PIP menu activity is closed, restore to the default position.
     60             mPipManager.resizePinnedStack(PipManager.STATE_PIP_OVERLAY);
     61         }
     62         finish();
     63     }
     64 
     65     @Override
     66     public void onResume() {
     67         super.onResume();
     68         mFadeInAnimation.start();
     69     }
     70 
     71     @Override
     72     public void onPause() {
     73         super.onPause();
     74         mFadeOutAnimation.start();
     75         restorePipAndFinish();
     76     }
     77 
     78     @Override
     79     protected void onDestroy() {
     80         super.onDestroy();
     81         mPipManager.removeListener(this);
     82         mPipManager.resumePipResizing(
     83                 PipManager.SUSPEND_PIP_RESIZE_REASON_WAITING_FOR_MENU_ACTIVITY_FINISH);
     84     }
     85 
     86     @Override
     87     public void onBackPressed() {
     88         restorePipAndFinish();
     89     }
     90 
     91     @Override
     92     public void onPipEntered() { }
     93 
     94     @Override
     95     public void onPipActivityClosed() {
     96         finish();
     97     }
     98 
     99     @Override
    100     public void onShowPipMenu() { }
    101 
    102     @Override
    103     public void onMoveToFullscreen() {
    104         // Moving PIP to fullscreen is implemented by resizing PINNED_STACK with null bounds.
    105         // This conflicts with restoring PIP position, so disable it.
    106         mRestorePipSizeWhenClose = false;
    107         finish();
    108     }
    109 
    110     @Override
    111     public void onPipResizeAboutToStart() {
    112         finish();
    113         mPipManager.suspendPipResizing(
    114                 PipManager.SUSPEND_PIP_RESIZE_REASON_WAITING_FOR_MENU_ACTIVITY_FINISH);
    115     }
    116 }
    117