import android.view.ViewGroup.MarginLayoutParams;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
+import com.android.launcher3.settings.SettingsProvider;
import com.android.launcher3.allapps.AllAppsContainerView;
public final int allAppsIconTextSizePx;
// QSB
+ public boolean searchBarVisible;
private int searchBarSpaceWidthPx;
private int searchBarSpaceHeightPx;
// Calculate the remaining vars
updateAvailableDimensions(dm, res);
computeAllAppsButtonSize(context);
+
+ // Search Bar
+ searchBarVisible = isSearchBarEnabled(context);
+ searchBarSpaceWidthPx = Math.min(searchBarSpaceWidthPx, widthPx);
+ searchBarSpaceHeightPx = 2 * edgeMarginPx + (searchBarVisible ?
+ searchBarSpaceHeightPx - getSearchBarTopOffset() : 3 * edgeMarginPx);
}
/**
/** Returns the search bar top offset */
private int getSearchBarTopOffset() {
if (isTablet && !isVerticalBarLayout()) {
- return 4 * edgeMarginPx;
+ return searchBarVisible ? 4 * edgeMarginPx : 0;
} else {
- return 2 * edgeMarginPx;
+ return searchBarVisible ? 2 * edgeMarginPx : 0;
}
}
(inv.numColumns * cellWidthPx)) / (2 * (inv.numColumns + 1)));
bounds.set(edgeMarginPx + gap, getSearchBarTopOffset(),
availableWidthPx - (edgeMarginPx + gap),
- searchBarSpaceHeightPx);
+ searchBarVisible ? searchBarSpaceHeightPx : edgeMarginPx);
} else {
bounds.set(desiredWorkspaceLeftRightMarginPx - defaultWidgetPadding.left,
getSearchBarTopOffset(),
availableWidthPx - (desiredWorkspaceLeftRightMarginPx -
- defaultWidgetPadding.right), searchBarSpaceHeightPx);
+ defaultWidgetPadding.right), searchBarVisible ? searchBarSpaceHeightPx :
+ edgeMarginPx);
}
}
return bounds;
return visibleChildren;
}
- public void layout(Launcher launcher) {
- FrameLayout.LayoutParams lp;
- boolean hasVerticalBarLayout = isVerticalBarLayout();
- final boolean isLayoutRtl = Utilities.isRtl(launcher.getResources());
+ public void layoutSearchBar(Launcher launcher, boolean hasVerticalBarLayout) {
+ // Update search bar for live settings
+ searchBarVisible = isSearchBarEnabled(launcher);
// Layout the search bar space
View searchBar = launcher.getSearchDropTargetBar();
- lp = (FrameLayout.LayoutParams) searchBar.getLayoutParams();
+ FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) searchBar.getLayoutParams();
if (hasVerticalBarLayout) {
+ // If search bar is invisible add some extra padding for the drop targets
+ searchBarSpaceHeightPx = searchBarVisible ? searchBarSpaceHeightPx
+ : searchBarSpaceHeightPx + 5 * edgeMarginPx;
+
// Vertical search bar space -- The search bar is fixed in the layout to be on the left
// of the screen regardless of RTL
lp.gravity = Gravity.LEFT;
LinearLayout targets = (LinearLayout) searchBar.findViewById(R.id.drag_target_bar);
targets.setOrientation(LinearLayout.VERTICAL);
- FrameLayout.LayoutParams targetsLp = (FrameLayout.LayoutParams) targets.getLayoutParams();
+ FrameLayout.LayoutParams targetsLp =
+ (FrameLayout.LayoutParams) targets.getLayoutParams();
targetsLp.gravity = Gravity.TOP;
targetsLp.height = LayoutParams.WRAP_CONTENT;
}
searchBar.setLayoutParams(lp);
+ View qsbBar = launcher.getOrCreateQsbBar();
+ if (qsbBar != null) {
+ qsbBar.setVisibility(searchBarVisible ? View.VISIBLE : View.GONE);
+ LayoutParams vglp = qsbBar.getLayoutParams();
+ vglp.width = LayoutParams.MATCH_PARENT;
+ vglp.height = LayoutParams.MATCH_PARENT;
+ qsbBar.setLayoutParams(vglp);
+ }
+ }
+
+ public void layout(Launcher launcher) {
+ FrameLayout.LayoutParams lp;
+ boolean hasVerticalBarLayout = isVerticalBarLayout();
+ final boolean isLayoutRtl = Utilities.isRtl(launcher.getResources());
+
+ layoutSearchBar(launcher, hasVerticalBarLayout);
+
// Layout the workspace
PagedView workspace = (PagedView) launcher.findViewById(R.id.workspace);
lp = (FrameLayout.LayoutParams) workspace.getLayoutParams();
? Math.min(widthPx, heightPx)
: Math.max(widthPx, heightPx);
}
+
+ private boolean isSearchBarEnabled(Context context) {
+ boolean searchActivityExists = Utilities.searchActivityExists(context);
+
+ boolean isSearchEnabled = SettingsProvider.getBoolean(context,
+ SettingsProvider.SETTINGS_UI_HOMESCREEN_SEARCH,
+ R.bool.preferences_interface_homescreen_search_default);
+
+ if (searchActivityExists) {
+ return isSearchEnabled;
+ } else {
+ if (isSearchEnabled) {
+ // Disable search bar
+ SettingsProvider.putBoolean(context,
+ SettingsProvider.SETTINGS_UI_HOMESCREEN_SEARCH, false);
+ }
+
+ return false;
+ }
+ }
}
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
+import java.util.Iterator;
import java.util.List;
import java.util.Locale;
+import java.util.Map;
import java.util.Set;
import java.util.Stack;
}
/**
+ * Empty out the cache that aren't of the correct grid size
+ */
+ public synchronized void flushInvalidIcons(DeviceProfile deviceProfile) {
+ Iterator<Map.Entry<ComponentKey, CacheEntry>> it = mCache.entrySet().iterator();
+ while (it.hasNext()) {
+ final CacheEntry e = it.next().getValue();
+ if ((e.icon != null) && (e.icon.getWidth() < deviceProfile.iconSizePx
+ || e.icon.getHeight() < deviceProfile.iconSizePx)) {
+ it.remove();
+ }
+ }
+ }
+
+ /**
* Remove any records for the supplied package name from memory.
*/
private void removeFromMemCacheLocked(String packageName, UserHandleCompat user) {
// the press state and keep this reference to reset the press state when we return to launcher.
private BubbleTextView mWaitingForResume;
+ private boolean mReloadLauncher;
+
// Preferences
private boolean mHideIconLabels;
if (mLauncherCallbacks != null) {
mLauncherCallbacks.onResume();
}
+
+ reloadLauncherIfNeeded();
}
@Override
}
};
+ /**
+ * Initializes the device profile based off of the launcher app state and screen orientation
+ * @param app The launcher app state
+ */
public void initializeDeviceProfile(LauncherAppState app) {
// Load configuration-specific DeviceProfile
mDeviceProfile = getResources().getConfiguration().orientation
app.getInvariantDeviceProfile().landscapeProfile
: app.getInvariantDeviceProfile().portraitProfile;
- mModel = app.setLauncher(this);
- mIconCache = app.getIconCache();
-
mHideIconLabels = SettingsProvider.getBoolean(this,
SettingsProvider.SETTINGS_UI_HOMESCREEN_HIDE_ICON_LABELS,
R.bool.preferences_interface_homescreen_hide_icon_labels_default);
+
+ mModel = app.setLauncher(this);
+ mIconCache = app.getIconCache();
+ mIconCache.flushInvalidIcons(mDeviceProfile);
+ }
+
+ /**
+ * Sets the reload launcher flag to true, which will reload the launcher at the next appropriate
+ * time.
+ */
+ public void setReloadLauncher() {
+ mReloadLauncher = true;
}
- public void reloadLauncher()
+ /**
+ * If the reload launcher flag is set to true, the launcher will be reloaded.
+ * @return Whether the launcher was actually reloaded.
+ */
+ public boolean reloadLauncherIfNeeded() {
+ if (mReloadLauncher) {
+ reloadLauncher(mWorkspace.getCurrentPage());
+ mReloadLauncher = false;
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
+ * Reloads the launcher by re-initializing the device profile and layout
+ * @param page
+ */
+ public void reloadLauncher(int page)
{
+ mSearchDropTargetBar.setupQsb(this);
+
// Re-initialize device profile
LauncherAppState app = LauncherAppState.getInstance();
app.initInvariantDeviceProfile();
// Reload
mModel.resetLoadedState(true, true);
- mModel.startLoader(mWorkspace.getRestorePage(), LauncherModel.LOADER_FLAG_NONE);
+ mModel.startLoader(page, LauncherModel.LOADER_FLAG_NONE);
mWorkspace.updateCustomContentVisibility();
mAppsView.reset();
}
super.onNewIntent(intent);
+ reloadLauncherIfNeeded();
+
// Close the menu
Folder openFolder = mWorkspace.getOpenFolder();
boolean alreadyOnHome = mHasFocus && ((intent.getFlags() &
res.getString(R.string.icon_labels)};
String[] valuesApp = new String[] {
- res.getString(R.string.larger_icons_text),
- res.getString(R.string.protected_app_settings)};
+ res.getString(R.string.larger_icons_text)/*,
+ TODO: Uncomment
+ res.getString(R.string.protected_app_settings)*/};
mSettingsAdapter = new SettingsPinnedHeaderAdapter(mLauncher);
mSettingsAdapter.setHeaders(headers);
private static final AccelerateInterpolator sAccelerateInterpolator =
new AccelerateInterpolator();
+ private Launcher mLauncher;
private State mState = State.SEARCH_BAR;
@Thunk View mQSB;
@Thunk View mDropTargetBar;
}
public void setup(Launcher launcher, DragController dragController) {
+ mLauncher = launcher;
+
dragController.addDragListener(this);
dragController.setFlingToDeleteDropTarget(mDeleteDropTarget);
});
}
+ public void setupQsb(Launcher launcher) {
+ mLauncher = launcher;
+ mQSB = launcher.getOrCreateQsbBar();
+ }
+
public void setQsbSearchBar(View qsb) {
+ float alpha = 1f;
+ int visibility = View.VISIBLE;
+ if (mQSB != null) {
+ alpha = mQSB.getAlpha();
+ visibility = mQSB.getVisibility();
+ }
+
mQSB = qsb;
if (mQSB != null) {
- // Update the search ber animation
+ mQSB.setAlpha(alpha);
+ mQSB.setVisibility(visibility);
+
+ // Update the search bar animation
mQSBSearchBarAnimator = new LauncherViewPropertyAnimator(mQSB);
mQSBSearchBarAnimator.setInterpolator(sAccelerateInterpolator);
mQSBSearchBarAnimator.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationStart(Animator animation) {
// Ensure that the view is visible for the animation
- if (mQSB != null) {
+ if (mQSB != null && isSearchBarVisible()) {
mQSB.setVisibility(View.VISIBLE);
}
}
@Override
public void onAnimationEnd(Animator animation) {
- if (mQSB != null) {
+ if (mQSB != null && isSearchBarVisible()) {
AlphaUpdateListener.updateVisibility(mQSB, mAccessibilityEnabled);
}
}
AccessibilityManager am = (AccessibilityManager)
getContext().getSystemService(Context.ACCESSIBILITY_SERVICE);
mAccessibilityEnabled = am.isEnabled();
-
- animateViewAlpha(mQSBSearchBarAnimator, mQSB, newState.getSearchBarAlpha(),
- duration);
+ if (mLauncher.getDeviceProfile().searchBarVisible) {
+ animateViewAlpha(mQSBSearchBarAnimator, mQSB, newState.getSearchBarAlpha(),
+ duration);
+ }
animateViewAlpha(mDropTargetBarAnimator, mDropTargetBar, newState.getDropTargetBarAlpha(),
duration);
}
}
}
+ public boolean isSearchBarVisible() {
+ if (mLauncher != null) {
+ return mLauncher.getDeviceProfile().searchBarVisible;
+ }
+ return true;
+ }
+
public void enableAccessibleDrag(boolean enable) {
- if (mQSB != null) {
+ if (mQSB != null && isSearchBarVisible()) {
mQSB.setVisibility(enable ? View.GONE : View.VISIBLE);
}
mInfoDropTarget.enableAccessibleDrag(enable);
public static String createDbSelectionQuery(String columnName, Iterable<?> values) {
return String.format(Locale.ENGLISH, "%s IN (%s)", columnName, TextUtils.join(", ", values));
}
+
+ public static boolean searchActivityExists(Context context) {
+ final SearchManager searchManager =
+ (SearchManager) context.getSystemService(Context.SEARCH_SERVICE);
+ ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
+
+ return globalSearchActivity != null;
+ }
}
updateScrubber();
}
+ /**
+ * Resets the existing apps in the list
+ */
public void reset() {
List<AppInfo> apps = mApps.getApps();
updateApps(apps);
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.TextView;
+import android.widget.Toast;
import com.android.launcher3.Launcher;
import com.android.launcher3.OverviewSettingsPanel;
import com.android.launcher3.R;
+import com.android.launcher3.Utilities;
import com.android.launcher3.settings.SettingsProvider;
public class SettingsPinnedHeaderAdapter extends PinnedHeaderListAdapter {
Resources res = mLauncher.getResources();
- boolean current = false;
- String state = "";
+ boolean current;
+ String state;
switch (partition) {
case OverviewSettingsPanel.HOME_SETTINGS_POSITION:
switch (position) {
- /*case 0:
- current = mLauncher.isSearchBarEnabled();
+ case 0:
+ current = SettingsProvider.getBoolean(mContext,
+ SettingsProvider.SETTINGS_UI_HOMESCREEN_SEARCH,
+ R.bool.preferences_interface_homescreen_search_default);
state = current ? res.getString(R.string.setting_state_on)
: res.getString(R.string.setting_state_off);
((TextView) v.findViewById(R.id.item_state)).setText(state);
- break;*/
+ break;
case 1:
current = SettingsProvider.getBoolean(mContext,
SettingsProvider.SETTINGS_UI_HOMESCREEN_HIDE_ICON_LABELS,
switch (partition) {
case OverviewSettingsPanel.HOME_SETTINGS_POSITION:
switch (position) {
- /*case 0:
+ case 0:
updateSearchBarVisibility(v);
- mLauncher.setUpdateDynamicGrid(false);
- break;*/
+ mLauncher.setReloadLauncher();
+ break;
case 1:
onIconLabelsBooleanChanged(v,
SettingsProvider.SETTINGS_UI_HOMESCREEN_HIDE_ICON_LABELS,
R.bool.preferences_interface_homescreen_hide_icon_labels_default);
- mLauncher.reloadLauncher();
+ mLauncher.setReloadLauncher();
break;
case 2:
onSettingsBooleanChanged(v,
SettingsProvider.SETTINGS_UI_HOMESCREEN_SCROLLING_WALLPAPER_SCROLL,
R.bool.preferences_interface_homescreen_scrolling_wallpaper_scroll_default);
- mLauncher.reloadLauncher();
+ mLauncher.setReloadLauncher();
break;
/*case 3:
mLauncher.onClickDynamicGridSizeButton();
onIconLabelsBooleanChanged(v,
SettingsProvider.SETTINGS_UI_DRAWER_HIDE_ICON_LABELS,
R.bool.preferences_interface_drawer_hide_icon_labels_default);
- mLauncher.reloadLauncher();
+ mLauncher.setReloadLauncher();
break;
}
break;
onSettingsBooleanChanged(v,
SettingsProvider.SETTINGS_UI_GENERAL_ICONS_LARGE,
R.bool.preferences_interface_general_icons_large_default);
- mLauncher.reloadLauncher();
+ mLauncher.setReloadLauncher();
break;
/*case 1:
Intent intent = new Intent();
}
};
- /*private void updateSearchBarVisibility(View v) {
+ private void updateSearchBarVisibility(View v) {
boolean isSearchEnabled = SettingsProvider.getBoolean(mContext,
SettingsProvider.SETTINGS_UI_HOMESCREEN_SEARCH,
R.bool.preferences_interface_homescreen_search_default);
onSettingsBooleanChanged(v,
SettingsProvider.SETTINGS_UI_HOMESCREEN_SEARCH,
R.bool.preferences_interface_homescreen_search_default);
- }*/
+ }
private void onSettingsBooleanChanged(View v, String key, int res) {
boolean current = SettingsProvider.getBoolean(