Home | History | Annotate | Download | only in launcher3
      1 package com.android.launcher3;
      2 
      3 import android.animation.Animator;
      4 import android.animation.Animator.AnimatorListener;
      5 import android.animation.AnimatorListenerAdapter;
      6 import android.animation.ObjectAnimator;
      7 import android.content.ComponentName;
      8 import android.content.Intent;
      9 import android.graphics.Rect;
     10 import android.os.Bundle;
     11 import android.view.Menu;
     12 import android.view.View;
     13 import android.view.ViewGroup;
     14 
     15 import java.io.FileDescriptor;
     16 import java.io.PrintWriter;
     17 import java.util.ArrayList;
     18 
     19 /**
     20  * This class represents a very trivial LauncherExtension. It primarily serves as a simple
     21  * class to exercise the LauncherOverlay interface.
     22  */
     23 public class LauncherExtension extends Launcher {
     24 
     25     //------ Activity methods -------//
     26     @Override
     27     public void onCreate(Bundle savedInstanceState) {
     28         setLauncherCallbacks(new LauncherExtensionCallbacks());
     29         super.onCreate(savedInstanceState);
     30     }
     31 
     32     public class LauncherExtensionCallbacks implements LauncherCallbacks {
     33 
     34         LauncherExtensionOverlay mLauncherOverlay = new LauncherExtensionOverlay();
     35 
     36         @Override
     37         public void preOnCreate() {
     38         }
     39 
     40         @Override
     41         public void onCreate(Bundle savedInstanceState) {
     42         }
     43 
     44         @Override
     45         public void preOnResume() {
     46         }
     47 
     48         @Override
     49         public void onResume() {
     50         }
     51 
     52         @Override
     53         public void onStart() {
     54         }
     55 
     56         @Override
     57         public void onStop() {
     58         }
     59 
     60         @Override
     61         public void onPause() {
     62         }
     63 
     64         @Override
     65         public void onDestroy() {
     66         }
     67 
     68         @Override
     69         public void onSaveInstanceState(Bundle outState) {
     70         }
     71 
     72         @Override
     73         public void onPostCreate(Bundle savedInstanceState) {
     74         }
     75 
     76         @Override
     77         public void onNewIntent(Intent intent) {
     78         }
     79 
     80         @Override
     81         public void onActivityResult(int requestCode, int resultCode, Intent data) {
     82         }
     83 
     84         @Override
     85         public void onWindowFocusChanged(boolean hasFocus) {
     86         }
     87 
     88         @Override
     89         public boolean onPrepareOptionsMenu(Menu menu) {
     90             return false;
     91         }
     92 
     93         @Override
     94         public void dump(String prefix, FileDescriptor fd, PrintWriter w, String[] args) {
     95         }
     96 
     97         @Override
     98         public void onHomeIntent() {
     99         }
    100 
    101         @Override
    102         public boolean handleBackPressed() {
    103             if (mLauncherOverlay.isOverlayPanelShowing()) {
    104                 mLauncherOverlay.hideOverlayPanel();
    105                 return true;
    106             }
    107             return false;
    108         }
    109 
    110         @Override
    111         public void onLauncherProviderChange() {
    112         }
    113 
    114         @Override
    115         public void finishBindingItems(boolean upgradePath) {
    116         }
    117 
    118         @Override
    119         public void onClickAllAppsButton(View v) {
    120         }
    121 
    122         @Override
    123         public void bindAllApplications(ArrayList<AppInfo> apps) {
    124         }
    125 
    126         @Override
    127         public void onClickFolderIcon(View v) {
    128         }
    129 
    130         @Override
    131         public void onClickAppShortcut(View v) {
    132         }
    133 
    134         @Override
    135         public void onClickPagedViewIcon(View v) {
    136         }
    137 
    138         @Override
    139         public void onClickWallpaperPicker(View v) {
    140         }
    141 
    142         @Override
    143         public void onClickSettingsButton(View v) {
    144         }
    145 
    146         @Override
    147         public void onClickAddWidgetButton(View v) {
    148         }
    149 
    150         @Override
    151         public void onPageSwitch(View newPage, int newPageIndex) {
    152         }
    153 
    154         @Override
    155         public void onWorkspaceLockedChanged() {
    156         }
    157 
    158         @Override
    159         public void onDragStarted(View view) {
    160         }
    161 
    162         @Override
    163         public void onInteractionBegin() {
    164         }
    165 
    166         @Override
    167         public void onInteractionEnd() {
    168         }
    169 
    170         @Override
    171         public boolean forceDisableVoiceButtonProxy() {
    172             return false;
    173         }
    174 
    175         @Override
    176         public boolean providesSearch() {
    177             return true;
    178         }
    179 
    180         @Override
    181         public boolean startSearch(String initialQuery, boolean selectInitialQuery,
    182                 Bundle appSearchData, Rect sourceBounds) {
    183             return false;
    184         }
    185 
    186         @Override
    187         public void startVoice() {
    188         }
    189 
    190         @Override
    191         public boolean hasCustomContentToLeft() {
    192             return false;
    193         }
    194 
    195         @Override
    196         public void populateCustomContentContainer() {
    197         }
    198 
    199         @Override
    200         public View getQsbBar() {
    201             return mLauncherOverlay.getSearchBox();
    202         }
    203 
    204         @Override
    205         public Intent getFirstRunActivity() {
    206             return null;
    207         }
    208 
    209         @Override
    210         public boolean hasFirstRunActivity() {
    211             return false;
    212         }
    213 
    214         @Override
    215         public boolean hasDismissableIntroScreen() {
    216             return false;
    217         }
    218 
    219         @Override
    220         public View getIntroScreen() {
    221             return null;
    222         }
    223 
    224         @Override
    225         public boolean shouldMoveToDefaultScreenOnHomeIntent() {
    226             return true;
    227         }
    228 
    229         @Override
    230         public boolean hasSettings() {
    231             return false;
    232         }
    233 
    234         @Override
    235         public ComponentName getWallpaperPickerComponent() {
    236             return null;
    237         }
    238 
    239         @Override
    240         public boolean overrideWallpaperDimensions() {
    241             return false;
    242         }
    243 
    244         @Override
    245         public boolean isLauncherPreinstalled() {
    246             return false;
    247         }
    248 
    249         @Override
    250         public boolean hasLauncherOverlay() {
    251             return true;
    252         }
    253 
    254         @Override
    255         public LauncherOverlay setLauncherOverlayView(InsettableFrameLayout container,
    256                 LauncherOverlayCallbacks callbacks) {
    257 
    258             mLauncherOverlay.setOverlayCallbacks(callbacks);
    259             mLauncherOverlay.setOverlayContainer(container);
    260 
    261             return mLauncherOverlay;
    262         }
    263 
    264         class LauncherExtensionOverlay implements LauncherOverlay {
    265             LauncherOverlayCallbacks mLauncherOverlayCallbacks;
    266             ViewGroup mOverlayView;
    267             View mSearchBox;
    268             View mSearchOverlay;
    269             boolean mShowOverlayFeedback;
    270             int mProgress;
    271             boolean mOverlayPanelShowing;
    272 
    273             @Override
    274             public void onScrollInteractionBegin() {
    275                 if (mLauncherOverlayCallbacks.canEnterFullImmersion()) {
    276                     mShowOverlayFeedback = true;
    277                     updatePanelOffset(0);
    278                     mSearchOverlay.setVisibility(View.VISIBLE);
    279                     mSearchOverlay.setLayerType(View.LAYER_TYPE_HARDWARE, null);
    280                 }
    281             }
    282 
    283             @Override
    284             public void onScrollChange(int progress, boolean rtl) {
    285                 mProgress = progress;
    286                 if (mShowOverlayFeedback) {
    287                     updatePanelOffset(progress);
    288                 }
    289             }
    290 
    291             private void updatePanelOffset(int progress) {
    292                 int panelWidth = mSearchOverlay.getMeasuredWidth();
    293                 int offset = (int) ((progress / 100f) * panelWidth);
    294                 mSearchOverlay.setTranslationX(- panelWidth + offset);
    295             }
    296 
    297             @Override
    298             public void onScrollInteractionEnd() {
    299                 if (mProgress > 25 && mLauncherOverlayCallbacks.enterFullImmersion()) {
    300                     ObjectAnimator oa = LauncherAnimUtils.ofFloat(mSearchOverlay, "translationX", 0);
    301                     oa.addListener(new AnimatorListenerAdapter() {
    302                         @Override
    303                         public void onAnimationEnd(Animator arg0) {
    304                             mSearchOverlay.setLayerType(View.LAYER_TYPE_NONE, null);
    305                         }
    306                     });
    307                     oa.start();
    308                     mOverlayPanelShowing = true;
    309                     mShowOverlayFeedback = false;
    310                 }
    311             }
    312 
    313             @Override
    314             public void onScrollSettled() {
    315                 if (mShowOverlayFeedback) {
    316                     mSearchOverlay.setVisibility(View.INVISIBLE);
    317                     mSearchOverlay.setLayerType(View.LAYER_TYPE_NONE, null);
    318                 }
    319                 mShowOverlayFeedback = false;
    320                 mProgress = 0;
    321             }
    322 
    323             public void hideOverlayPanel() {
    324                 mLauncherOverlayCallbacks.exitFullImmersion();
    325                 mSearchOverlay.setVisibility(View.INVISIBLE);
    326                 mOverlayPanelShowing = false;
    327             }
    328 
    329             public boolean isOverlayPanelShowing() {
    330                 return mOverlayPanelShowing;
    331             }
    332 
    333             @Override
    334             public void forceExitFullImmersion() {
    335                 hideOverlayPanel();
    336             }
    337 
    338             public void setOverlayContainer(InsettableFrameLayout container) {
    339                 mOverlayView = (ViewGroup) getLayoutInflater().inflate(
    340                         R.layout.launcher_overlay_example, container);
    341                 mSearchOverlay = mOverlayView.findViewById(R.id.search_overlay);
    342                 mSearchBox = mOverlayView.findViewById(R.id.search_box);
    343             }
    344 
    345             public View getSearchBox() {
    346                 return mSearchBox;
    347             }
    348 
    349             public void setOverlayCallbacks(LauncherOverlayCallbacks callbacks) {
    350                 mLauncherOverlayCallbacks = callbacks;
    351             }
    352         };
    353     }
    354 }
    355