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 onCreate(Bundle savedInstanceState)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 preOnCreate()37 public void preOnCreate() { 38 } 39 40 @Override onCreate(Bundle savedInstanceState)41 public void onCreate(Bundle savedInstanceState) { 42 } 43 44 @Override preOnResume()45 public void preOnResume() { 46 } 47 48 @Override onResume()49 public void onResume() { 50 } 51 52 @Override onStart()53 public void onStart() { 54 } 55 56 @Override onStop()57 public void onStop() { 58 } 59 60 @Override onPause()61 public void onPause() { 62 } 63 64 @Override onDestroy()65 public void onDestroy() { 66 } 67 68 @Override onSaveInstanceState(Bundle outState)69 public void onSaveInstanceState(Bundle outState) { 70 } 71 72 @Override onPostCreate(Bundle savedInstanceState)73 public void onPostCreate(Bundle savedInstanceState) { 74 } 75 76 @Override onNewIntent(Intent intent)77 public void onNewIntent(Intent intent) { 78 } 79 80 @Override onActivityResult(int requestCode, int resultCode, Intent data)81 public void onActivityResult(int requestCode, int resultCode, Intent data) { 82 } 83 84 @Override onWindowFocusChanged(boolean hasFocus)85 public void onWindowFocusChanged(boolean hasFocus) { 86 } 87 88 @Override onPrepareOptionsMenu(Menu menu)89 public boolean onPrepareOptionsMenu(Menu menu) { 90 return false; 91 } 92 93 @Override dump(String prefix, FileDescriptor fd, PrintWriter w, String[] args)94 public void dump(String prefix, FileDescriptor fd, PrintWriter w, String[] args) { 95 } 96 97 @Override onHomeIntent()98 public void onHomeIntent() { 99 } 100 101 @Override handleBackPressed()102 public boolean handleBackPressed() { 103 if (mLauncherOverlay.isOverlayPanelShowing()) { 104 mLauncherOverlay.hideOverlayPanel(); 105 return true; 106 } 107 return false; 108 } 109 110 @Override onLauncherProviderChange()111 public void onLauncherProviderChange() { 112 } 113 114 @Override finishBindingItems(boolean upgradePath)115 public void finishBindingItems(boolean upgradePath) { 116 } 117 118 @Override onClickAllAppsButton(View v)119 public void onClickAllAppsButton(View v) { 120 } 121 122 @Override bindAllApplications(ArrayList<AppInfo> apps)123 public void bindAllApplications(ArrayList<AppInfo> apps) { 124 } 125 126 @Override onClickFolderIcon(View v)127 public void onClickFolderIcon(View v) { 128 } 129 130 @Override onClickAppShortcut(View v)131 public void onClickAppShortcut(View v) { 132 } 133 134 @Override onClickPagedViewIcon(View v)135 public void onClickPagedViewIcon(View v) { 136 } 137 138 @Override onClickWallpaperPicker(View v)139 public void onClickWallpaperPicker(View v) { 140 } 141 142 @Override onClickSettingsButton(View v)143 public void onClickSettingsButton(View v) { 144 } 145 146 @Override onClickAddWidgetButton(View v)147 public void onClickAddWidgetButton(View v) { 148 } 149 150 @Override onPageSwitch(View newPage, int newPageIndex)151 public void onPageSwitch(View newPage, int newPageIndex) { 152 } 153 154 @Override onWorkspaceLockedChanged()155 public void onWorkspaceLockedChanged() { 156 } 157 158 @Override onDragStarted(View view)159 public void onDragStarted(View view) { 160 } 161 162 @Override onInteractionBegin()163 public void onInteractionBegin() { 164 } 165 166 @Override onInteractionEnd()167 public void onInteractionEnd() { 168 } 169 170 @Override forceDisableVoiceButtonProxy()171 public boolean forceDisableVoiceButtonProxy() { 172 return false; 173 } 174 175 @Override providesSearch()176 public boolean providesSearch() { 177 return true; 178 } 179 180 @Override startSearch(String initialQuery, boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds)181 public boolean startSearch(String initialQuery, boolean selectInitialQuery, 182 Bundle appSearchData, Rect sourceBounds) { 183 return false; 184 } 185 186 @Override startVoice()187 public void startVoice() { 188 } 189 190 @Override hasCustomContentToLeft()191 public boolean hasCustomContentToLeft() { 192 return false; 193 } 194 195 @Override populateCustomContentContainer()196 public void populateCustomContentContainer() { 197 } 198 199 @Override getQsbBar()200 public View getQsbBar() { 201 return mLauncherOverlay.getSearchBox(); 202 } 203 204 @Override getFirstRunActivity()205 public Intent getFirstRunActivity() { 206 return null; 207 } 208 209 @Override hasFirstRunActivity()210 public boolean hasFirstRunActivity() { 211 return false; 212 } 213 214 @Override hasDismissableIntroScreen()215 public boolean hasDismissableIntroScreen() { 216 return false; 217 } 218 219 @Override getIntroScreen()220 public View getIntroScreen() { 221 return null; 222 } 223 224 @Override shouldMoveToDefaultScreenOnHomeIntent()225 public boolean shouldMoveToDefaultScreenOnHomeIntent() { 226 return true; 227 } 228 229 @Override hasSettings()230 public boolean hasSettings() { 231 return false; 232 } 233 234 @Override getWallpaperPickerComponent()235 public ComponentName getWallpaperPickerComponent() { 236 return null; 237 } 238 239 @Override overrideWallpaperDimensions()240 public boolean overrideWallpaperDimensions() { 241 return false; 242 } 243 244 @Override isLauncherPreinstalled()245 public boolean isLauncherPreinstalled() { 246 return false; 247 } 248 249 @Override hasLauncherOverlay()250 public boolean hasLauncherOverlay() { 251 return true; 252 } 253 254 @Override setLauncherOverlayView(InsettableFrameLayout container, LauncherOverlayCallbacks callbacks)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 onScrollInteractionBegin()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 onScrollChange(int progress, boolean rtl)284 public void onScrollChange(int progress, boolean rtl) { 285 mProgress = progress; 286 if (mShowOverlayFeedback) { 287 updatePanelOffset(progress); 288 } 289 } 290 updatePanelOffset(int progress)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 onScrollInteractionEnd()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 onScrollSettled()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 hideOverlayPanel()323 public void hideOverlayPanel() { 324 mLauncherOverlayCallbacks.exitFullImmersion(); 325 mSearchOverlay.setVisibility(View.INVISIBLE); 326 mOverlayPanelShowing = false; 327 } 328 isOverlayPanelShowing()329 public boolean isOverlayPanelShowing() { 330 return mOverlayPanelShowing; 331 } 332 333 @Override forceExitFullImmersion()334 public void forceExitFullImmersion() { 335 hideOverlayPanel(); 336 } 337 setOverlayContainer(InsettableFrameLayout container)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 getSearchBox()345 public View getSearchBox() { 346 return mSearchBox; 347 } 348 setOverlayCallbacks(LauncherOverlayCallbacks callbacks)349 public void setOverlayCallbacks(LauncherOverlayCallbacks callbacks) { 350 mLauncherOverlayCallbacks = callbacks; 351 } 352 }; 353 } 354 } 355