diff options
Diffstat (limited to 'src/com/android/launcher3/Launcher.java')
-rw-r--r-- | src/com/android/launcher3/Launcher.java | 130 |
1 files changed, 116 insertions, 14 deletions
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java index 15373c20b..8f3bbf578 100644 --- a/src/com/android/launcher3/Launcher.java +++ b/src/com/android/launcher3/Launcher.java @@ -32,7 +32,6 @@ import android.app.AlertDialog; import android.app.Fragment; import android.app.FragmentManager; import android.app.FragmentTransaction; -import android.app.Dialog; import android.app.SearchManager; import android.appwidget.AppWidgetHostView; import android.appwidget.AppWidgetManager; @@ -258,6 +257,7 @@ public class Launcher extends Activity private DragController mDragController; private View mWeightWatcher; protected HiddenFolderFragment mHiddenFolderFragment; + private DynamicGridSizeFragment mDynamicGridSizeFragment; private AppWidgetManagerCompat mAppWidgetManager; private LauncherAppWidgetHost mAppWidgetHost; @@ -273,6 +273,7 @@ public class Launcher extends Activity @Thunk Hotseat mHotseat; private ViewGroup mOverviewPanel; + private View mDarkPanel; OverviewSettingsPanel mOverviewSettingsPanel; private View mAllAppsButton; @@ -369,6 +370,20 @@ public class Launcher extends Activity private BubbleTextView mWaitingForResume; private boolean mReloadLauncher; + private boolean mResizeGridRequired; + + public Animator.AnimatorListener mAnimatorListener = new Animator.AnimatorListener() { + @Override + public void onAnimationStart(Animator arg0) {} + @Override + public void onAnimationRepeat(Animator arg0) {} + @Override + public void onAnimationEnd(Animator arg0) { + mDarkPanel.setVisibility(View.GONE); + } + @Override + public void onAnimationCancel(Animator arg0) {} + }; // Preferences private boolean mHideIconLabels; @@ -1120,6 +1135,13 @@ public class Launcher extends Activity mLauncherCallbacks.onResume(); } + // Close out fragments + Fragment gridFragment = getFragmentManager().findFragmentByTag( + DynamicGridSizeFragment.DYNAMIC_GRID_SIZE_FRAGMENT); + if (gridFragment != null) { + mDynamicGridSizeFragment.setSize(); + } + reloadLauncherIfNeeded(); //Close out Fragments @@ -1439,6 +1461,8 @@ public class Launcher extends Activity mOverviewSettingsPanel = new OverviewSettingsPanel(this); mOverviewSettingsPanel.initializeAdapter(); + mDarkPanel = mOverviewPanel.findViewById(R.id.dark_panel); + mWidgetsButton = findViewById(R.id.widget_button); mWidgetsButton.setOnClickListener(new OnClickListener() { @Override @@ -1759,11 +1783,13 @@ public class Launcher extends Activity } /** - * Sets the reload launcher flag to true, which will reload the launcher at the next appropriate - * time. + * Sets the reload launcher flag to true and the resize grid flag to the parameter value, + * which will reload the launcher/grid size at the next appropriate time. + * @param shouldResizeGrid Indicates whether the grid needs to be resized. */ - public void setReloadLauncher() { + public void setReloadLauncher(boolean shouldResizeGrid) { mReloadLauncher = true; + mResizeGridRequired = shouldResizeGrid; } /** @@ -1774,6 +1800,7 @@ public class Launcher extends Activity if (mReloadLauncher) { reloadLauncher(mWorkspace.getCurrentPage()); mReloadLauncher = false; + mResizeGridRequired = false; return true; } @@ -1797,12 +1824,76 @@ public class Launcher extends Activity // Reload mModel.resetLoadedState(true, true); - mModel.startLoader(page, LauncherModel.LOADER_FLAG_NONE); + int flag = mResizeGridRequired ? LauncherModel.LOADER_FLAG_RESIZE_GRID : + LauncherModel.LOADER_FLAG_NONE; + mModel.startLoader(page, flag); mWorkspace.updateCustomContentVisibility(); mAppsView.reset(); } + /** + * Replaces currently added fragments in the launcher layout with a + * {@link DynamicGridSizeFragment}. + */ + public void onClickDynamicGridSizeButton() { + FragmentManager fragmentManager = getFragmentManager(); + FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); + + mDynamicGridSizeFragment = new DynamicGridSizeFragment(); + fragmentTransaction.replace(R.id.launcher, mDynamicGridSizeFragment, + DynamicGridSizeFragment.DYNAMIC_GRID_SIZE_FRAGMENT); + fragmentTransaction.commit(); + } + + /** + * If the new grid size is different from the current grid size, the launcher will be reloaded + * and the overview settings panel updated with the new grid size value. + * @param size The new grid size to set the workspace to. + */ + public void setDynamicGridSize(InvariantDeviceProfile.GridSize size) { + int gridSize = SettingsProvider.getIntCustomDefault(this, + SettingsProvider.SETTINGS_UI_DYNAMIC_GRID_SIZE, 0); + boolean customValuesChanged = false; + if (gridSize == size.getValue() && size == InvariantDeviceProfile.GridSize.Custom) { + int tempRows = SettingsProvider.getIntCustomDefault(this, + SettingsProvider.SETTINGS_UI_HOMESCREEN_ROWS, mDeviceProfile.inv.numRows); + int tempColumns = SettingsProvider.getIntCustomDefault(this, + SettingsProvider.SETTINGS_UI_HOMESCREEN_COLUMNS, mDeviceProfile.inv.numColumns); + if (tempColumns != mDeviceProfile.inv.numColumns || + tempRows != mDeviceProfile.inv.numRows) { + customValuesChanged = true; + } + } + + if (gridSize != size.getValue() || customValuesChanged) { + SettingsProvider.putInt(this, + SettingsProvider.SETTINGS_UI_DYNAMIC_GRID_SIZE, size.getValue()); + + setReloadLauncher(true); + } + + mOverviewSettingsPanel.notifyDataSetInvalidated(); + + FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction(); + Configuration config = getResources().getConfiguration(); + if(config.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL) { + fragmentTransaction + .setCustomAnimations(0, R.anim.exit_out_left); + } else { + fragmentTransaction + .setCustomAnimations(0, R.anim.exit_out_right); + } + fragmentTransaction + .remove(mDynamicGridSizeFragment).commit(); + + mDarkPanel.setVisibility(View.VISIBLE); + ObjectAnimator anim = ObjectAnimator.ofFloat( + mDarkPanel, "alpha", 0.3f, 0.0f); + anim.start(); + anim.addListener(mAnimatorListener); + } + @Override public void onAttachedToWindow() { super.onAttachedToWindow(); @@ -2000,6 +2091,10 @@ public class Launcher extends Activity return mOverviewPanel; } + public View getDarkPanel() { + return mDarkPanel; + } + public SearchDropTargetBar getSearchDropTargetBar() { return mSearchDropTargetBar; } @@ -2627,7 +2722,14 @@ public class Launcher extends Activity } else if (isWidgetsViewVisible()) { showOverviewMode(true); } else if (mWorkspace.isInOverviewMode()) { - showWorkspace(true); + Fragment gridFragment = getFragmentManager().findFragmentByTag( + DynamicGridSizeFragment.DYNAMIC_GRID_SIZE_FRAGMENT); + if (gridFragment != null) { + mDynamicGridSizeFragment.setSize(); + } + else { + showWorkspace(true); + } } else if (mWorkspace.getOpenFolder() != null) { Folder openFolder = mWorkspace.getOpenFolder(); if (openFolder.isEditingName()) { @@ -3516,6 +3618,8 @@ public class Launcher extends Activity } void showWorkspace(int snapToPage, boolean animated, Runnable onCompleteRunnable) { + reloadLauncherIfNeeded(); + boolean changed = mState != State.WORKSPACE || mWorkspace.getState() != Workspace.State.NORMAL; if (changed) { @@ -3544,6 +3648,8 @@ public class Launcher extends Activity } void showOverviewMode(boolean animated) { + reloadLauncherIfNeeded(); + mWorkspace.setVisibility(View.VISIBLE); mStateTransitionAnimation.startAnimationToWorkspace(mState, mWorkspace.getState(), Workspace.State.OVERVIEW, @@ -4293,6 +4399,10 @@ public class Launcher extends Activity if (mLauncherCallbacks != null) { mLauncherCallbacks.finishBindingItems(false); } + + if (mWorkspace.isInOverviewMode()) { + reloadLauncherIfNeeded(); + } } private void sendLoadingCompleteBroadcastIfNecessary() { @@ -4978,14 +5088,6 @@ public class Launcher extends Activity AnimationDrawable frameAnimation = (AnimationDrawable) mAnimatedArrow.getBackground(); frameAnimation.start(); - - /*if (mLauncher.updateGridIfNeeded()) { - Workspace workspace = mLauncher.getWorkspace(); - if (workspace.isInOverviewMode()) { - workspace.setChildrenOutlineAlpha(1.0f); - mLauncher.mSearchDropTargetBar.hideSearchBar(false); - } - }*/ } @Override |