Skip to content

Commit

Permalink
Trebuchet : Add a pref to set hotseat icon's number
Browse files Browse the repository at this point in the history
This adds a preference for the hotseat (Launcher main bar/dock)

- Choose the number of icons on the hotseat
- Choose the place of the applications drawer button by drag'n'drop

- Translations in English + French

This is usefull for big screen devices.
You can set from 1 to 9 buttons on the hotseat.
You can set the app button where you want by drag'n'drop.
Default values are keeped unchanged so there is no pb with first screen tuto + no pb with default shortcuts.

Demo video : https://www.dropbox.com/s/2wamj9yr1s3woxl/Trebuchet-hotseat-icons.mp4

Demo apk   : https://www.dropbox.com/s/psqab2gyivcyo3d/CmoaToto%20Trebuchet.apk

PatchSet 1 : initial commit

PatchSet 2 : coding style

PatchSet 3 : - Remove prefs for tablet
             - AllApps Button move by Drag'n'Drop (instead of pref)

PatchSet 4 : searchbar & deletebar don't dis/appear while dragging AllApps button)

PatchSet 5 : dropOnFlingToDeleteTarget disabled for AllApps button

PatchSet 6 : - Fix shortcuts errors in database
             - Set docks pref disabled for large screen programmatically
             - Fix english strings/french trads

Change-Id: I21f6a4610ed16c8780ccf6e2acffcf6e07511457

Conflicts:
	src/com/cyanogenmod/trebuchet/Hotseat.java
	src/com/cyanogenmod/trebuchet/LauncherModel.java
	src/com/cyanogenmod/trebuchet/Workspace.java
  • Loading branch information
CmoaToto authored and nebkat committed Dec 1, 2012
1 parent 3969253 commit e74a543
Show file tree
Hide file tree
Showing 15 changed files with 159 additions and 21 deletions.
2 changes: 2 additions & 0 deletions res/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@

<!-- Dock -->
<string name="preferences_interface_dock_title">Barre de Dock</string>
<string name="preferences_interface_dock_size_title">Icônes du dock</string>
<string name="preferences_interface_dock_size_summary">Définir le nombre d\'icône du dock</string>

<!-- Icons -->
<string name="preferences_interface_icons_title">Icônes</string>
Expand Down
2 changes: 2 additions & 0 deletions res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,8 @@ s -->

<!-- Dock -->
<string name="preferences_interface_dock_title">Dock</string>
<string name="preferences_interface_dock_size_title">Dock icons</string>
<string name="preferences_interface_dock_size_summary">Choose the number of icons in the dock</string>

<!-- Icons -->
<string name="preferences_interface_icons_title">Icons</string>
Expand Down
11 changes: 8 additions & 3 deletions res/xml/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,15 @@
</PreferenceScreen>

<!-- Dock -->
<!-- <PreferenceScreen android:key="ui_dock"
<PreferenceScreen android:key="ui_dock"
android:title="@string/preferences_interface_dock_title">
</PreferenceScreen> -->
<com.cyanogenmod.trebuchet.preference.NumberPickerPreference android:key="ui_dock_hotseat_size"
android:title="@string/preferences_interface_dock_size_title"
android:summary="@string/preferences_interface_dock_size_summary"
android:defaultValue="@integer/hotseat_cell_count"
launcher:max="9"
launcher:min="1" />
</PreferenceScreen>

<!-- Icons -->
<!-- <PreferenceScreen android:key="ui_icons"
Expand Down
35 changes: 35 additions & 0 deletions src/com/cyanogenmod/trebuchet/AllAppsButtonInfo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright (C) 2008 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.cyanogenmod.trebuchet;

/**
* Represents the AllApps button in hotseat
*/
class AllAppsButtonInfo extends ItemInfo {

AllAppsButtonInfo() {
itemType = LauncherSettings.BaseLauncherColumns.ITEM_TYPE_ALLAPPS;
}

@Override
public String toString() {
return "AllAppsButtonInfo(id=" + this.id + " type=" + this.itemType
+ " container=" + this.container + " screen=" + screen
+ " cellX=" + cellX + " cellY=" + cellY + " spanX=" + spanX + " spanY=" + spanY
+ " dropPos=" + dropPos + ")";
}
}
7 changes: 7 additions & 0 deletions src/com/cyanogenmod/trebuchet/DeleteDropTarget.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ private boolean isWorkspaceWidget(DragSource source, Object info) {
private boolean isWorkspaceFolder(DragSource source, Object info) {
return (source instanceof Workspace) && (info instanceof FolderInfo);
}
private boolean isAllAppsButton(Object info) {
return (info instanceof AllAppsButtonInfo);
}

private void setHoverColor() {
setTextColor(mHoverColor);
Expand All @@ -147,6 +150,10 @@ public boolean acceptDrop(DragObject d) {

@Override
public void onDragStart(DragSource source, Object info, int dragAction) {
// If it's the AllApps button, from Hotseat, don't do anything.
if (isAllAppsButton(info)) {
return;
}
boolean isUninstall = false;

// If we are dragging an application from AppsCustomize, only show the uninstall control if we
Expand Down
10 changes: 6 additions & 4 deletions src/com/cyanogenmod/trebuchet/DragController.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import android.view.inputmethod.InputMethodManager;

import com.cyanogenmod.trebuchet.R;
import com.cyanogenmod.trebuchet.DropTarget.DragObject;

import java.util.ArrayList;

Expand Down Expand Up @@ -440,7 +441,7 @@ public boolean onInterceptTouchEvent(MotionEvent ev) {
case MotionEvent.ACTION_UP:
mLastTouchUpTime = System.currentTimeMillis();
if (mDragging) {
PointF vec = isFlingingToDelete(mDragObject.dragSource);
PointF vec = isFlingingToDelete(mDragObject);
if (vec != null) {
dropOnFlingToDeleteTarget(dragLayerX, dragLayerY, vec);
} else {
Expand Down Expand Up @@ -582,7 +583,7 @@ public boolean onTouchEvent(MotionEvent ev) {
mHandler.removeCallbacks(mScrollRunnable);

if (mDragging) {
PointF vec = isFlingingToDelete(mDragObject.dragSource);
PointF vec = isFlingingToDelete(mDragObject);
if (vec != null) {
dropOnFlingToDeleteTarget(dragLayerX, dragLayerY, vec);
} else {
Expand All @@ -605,9 +606,10 @@ public boolean onTouchEvent(MotionEvent ev) {
*
* @return the vector at which the item was flung, or null if no fling was detected.
*/
private PointF isFlingingToDelete(DragSource source) {
private PointF isFlingingToDelete(DragObject object) {
if (mFlingToDeleteDropTarget == null) return null;
if (!source.supportsFlingToDelete()) return null;
if (!object.dragSource.supportsFlingToDelete()) return null;
if (object.dragInfo instanceof AllAppsButtonInfo) return null;

ViewConfiguration config = ViewConfiguration.get(mLauncher);
mVelocityTracker.computeCurrentVelocity(1000, config.getScaledMaximumFlingVelocity());
Expand Down
45 changes: 39 additions & 6 deletions src/com/cyanogenmod/trebuchet/Hotseat.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import android.widget.FrameLayout;

import com.cyanogenmod.trebuchet.R;
import com.cyanogenmod.trebuchet.preference.Preferences;
import com.cyanogenmod.trebuchet.preference.PreferencesProvider;

public class Hotseat extends FrameLayout {
@SuppressWarnings("unused")
Expand All @@ -39,6 +41,8 @@ public class Hotseat extends FrameLayout {
private int mCellCountY;
private int mAllAppsButtonRank;

private int xrrrr;

private boolean mTransposeLayoutWithOrientation;
private boolean mIsLandscape;

Expand All @@ -58,14 +62,29 @@ public Hotseat(Context context, AttributeSet attrs, int defStyle) {

TypedArray a = context.obtainStyledAttributes(attrs,
R.styleable.Hotseat, defStyle, 0);
Resources r = context.getResources();
mCellCountX = a.getInt(R.styleable.Hotseat_cellCountX, -1);
mCellCountY = a.getInt(R.styleable.Hotseat_cellCountY, -1);
mAllAppsButtonRank = r.getInteger(R.integer.hotseat_all_apps_index);
mTransposeLayoutWithOrientation =
r.getBoolean(R.bool.hotseat_transpose_layout_with_orientation);

int numberHotseatIcons = PreferencesProvider.Interface.Dock.getNumberHotseatIcons(context);
int defaultHotseatIcon = PreferencesProvider.Interface.Dock.getDefaultHotseatIcon(context,
context.getResources().getInteger(R.integer.hotseat_all_apps_index));
if (defaultHotseatIcon >= numberHotseatIcons) {
defaultHotseatIcon = numberHotseatIcons - 1;
PreferencesProvider.Interface.Dock.setDefaultHotseatIcon(context, defaultHotseatIcon);
}

mTransposeLayoutWithOrientation =
getResources().getBoolean(R.bool.hotseat_transpose_layout_with_orientation);

mIsLandscape = context.getResources().getConfiguration().orientation ==
Configuration.ORIENTATION_LANDSCAPE;

if (mIsLandscape) {
mCellCountX = a.getInt(R.styleable.Hotseat_cellCountX, -1);
mCellCountY = numberHotseatIcons;
} else {
mCellCountX = numberHotseatIcons;
mCellCountY = a.getInt(R.styleable.Hotseat_cellCountY, -1);
}
mAllAppsButtonRank = defaultHotseatIcon;
}

public void setup(Launcher launcher) {
Expand Down Expand Up @@ -139,10 +158,24 @@ public void onClick(android.view.View v) {
}
});

allAppsButton.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
if (mLauncher != null) {
return mLauncher.onLongClick(v);
}
return false;
}
});

// Note: We do this to ensure that the hotseat is always laid out in the orientation of
// the hotseat in order regardless of which orientation they were added
int x = getCellXFromOrder(mAllAppsButtonRank);
int y = getCellYFromOrder(mAllAppsButtonRank);
AllAppsButtonInfo allAppsButtonInfo = new AllAppsButtonInfo();
allAppsButtonInfo.cellX = x;
allAppsButtonInfo.cellY = y;
allAppsButton.setTag(allAppsButtonInfo);
CellLayout.LayoutParams lp = new CellLayout.LayoutParams(x,y,1,1);
lp.canReorder = false;
mContent.addViewToCellLayout(allAppsButton, -1, 0, lp, true);
Expand Down
1 change: 1 addition & 0 deletions src/com/cyanogenmod/trebuchet/ItemInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class ItemInfo {
/**
* One of {@link LauncherSettings.Favorites#ITEM_TYPE_APPLICATION},
* {@link LauncherSettings.Favorites#ITEM_TYPE_SHORTCUT},
* {@link LauncherSettings.Favorites#ITEM_TYPE_ALLAPPS},
* {@link LauncherSettings.Favorites#ITEM_TYPE_FOLDER}, or
* {@link LauncherSettings.Favorites#ITEM_TYPE_APPWIDGET}.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/com/cyanogenmod/trebuchet/Launcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -2445,7 +2445,7 @@ public boolean isAllAppsVisible() {
}

public boolean isAllAppsButtonRank(int rank) {
return mHotseat.isAllAppsButtonRank(rank);
return (mHotseat != null) ? mHotseat.isAllAppsButtonRank(rank) : false;
}

/**
Expand Down
13 changes: 10 additions & 3 deletions src/com/cyanogenmod/trebuchet/LauncherModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@

import com.cyanogenmod.trebuchet.R;
import com.cyanogenmod.trebuchet.InstallWidgetReceiver.WidgetMimeTypeHandlerData;
import com.cyanogenmod.trebuchet.preference.PreferencesProvider;

import java.lang.ref.WeakReference;
import java.net.URISyntaxException;
Expand Down Expand Up @@ -1181,13 +1182,15 @@ private boolean checkItemPlacement(ItemInfo occupied[][][], ItemInfo item) {

// We use the last index to refer to the hotseat and the screen as the rank, so
// test and update the occupied state accordingly
if (occupied[Launcher.MAX_SCREEN_COUNT][item.screen][0] != null) {
if (occupied[PreferencesProvider.Interface.Homescreen.getNumberHomescreens(mContext)]
[item.screen][0] != null) {
Log.e(TAG, "Error loading shortcut into hotseat " + item
+ " into position (" + item.screen + ":" + item.cellX + "," + item.cellY
+ ") occupied by " + occupied[Launcher.MAX_SCREEN_COUNT][item.screen][0]);
return false;
} else {
occupied[Launcher.MAX_SCREEN_COUNT][item.screen][0] = item;
occupied[PreferencesProvider.Interface.Homescreen.getNumberHomescreens(mContext)]
[item.screen][0] = item;
return true;
}
} else if (item.container != LauncherSettings.Favorites.CONTAINER_DESKTOP) {
Expand Down Expand Up @@ -1244,8 +1247,10 @@ private void loadWorkspace() {
// +1 for the hotseat (it can be larger than the workspace)
// Load workspace in reverse order to ensure that latest items are loaded first (and
// before any earlier duplicates)
int numberHotseatIcons = PreferencesProvider.Interface.Dock.getNumberHotseatIcons(mContext);
final ItemInfo occupied[][][] =
new ItemInfo[Launcher.MAX_SCREEN_COUNT + 1][mCellCountX + 1][mCellCountY + 1];
new ItemInfo[PreferencesProvider.Interface.Homescreen.getNumberHomescreens(mContext) + 1]
[Math.max(mCellCountX, numberHotseatIcons)][mCellCountY];

try {
final int idIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites._ID);
Expand Down Expand Up @@ -1333,6 +1338,8 @@ private void loadWorkspace() {

// check & update map of what's occupied
if (!checkItemPlacement(occupied, info)) {
id = c.getLong(idIndex);
itemsToRemove.add(id);
break;
}

Expand Down
5 changes: 5 additions & 0 deletions src/com/cyanogenmod/trebuchet/LauncherSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ static interface BaseLauncherColumns extends BaseColumns {
*/
static final int ITEM_TYPE_SHORTCUT = 1;

/**
* The gesture is the All Apps button
*/
static final int ITEM_TYPE_ALLAPPS = 5;

/**
* The icon type.
* <P>Type: INTEGER</P>
Expand Down
10 changes: 10 additions & 0 deletions src/com/cyanogenmod/trebuchet/SearchDropTargetBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,21 @@ public int getTransitionOutDuration() {
return sTransitionOutDuration;
}

private boolean isAllAppsButton(Object info) {
return (info instanceof AllAppsButtonInfo);
}

/*
* DragController.DragListener implementation
*/
@Override
public void onDragStart(DragSource source, Object info, int dragAction) {
// If it's the AllApps button, from Hotseat, don't do anything.
if (isAllAppsButton(info)) {
deferOnDragEnd();
return;
}

// Animate out the QSB search bar, and animate in the drop target bar
prepareStartAnimation(mDropTargetBar);
mDropTargetBarAnim.start();
Expand Down
19 changes: 16 additions & 3 deletions src/com/cyanogenmod/trebuchet/Workspace.java
Original file line number Diff line number Diff line change
Expand Up @@ -2409,8 +2409,17 @@ public void run() {
}
}

LauncherModel.moveItemInDatabase(mLauncher, info, container, screen, lp.cellX,
lp.cellY);
// No_id check required as the AllApps button doesn't have an item info id
if (info.id != ItemInfo.NO_ID) {
LauncherModel.moveItemInDatabase(mLauncher, info, container, screen, lp.cellX,
lp.cellY);
} else if (info instanceof AllAppsButtonInfo) {
if (!LauncherApplication.isScreenLandscape(getContext())) {
PreferencesProvider.Interface.Dock.setDefaultHotseatIcon(getContext(), lp.cellX);
} else {
PreferencesProvider.Interface.Dock.setDefaultHotseatIcon(getContext(), lp.cellY);
}
}
} else {
// If we can't find a drop location, we return the item to its original position
CellLayout.LayoutParams lp = (CellLayout.LayoutParams) cell.getLayoutParams();
Expand Down Expand Up @@ -2860,6 +2869,10 @@ private boolean isExternalDragWidget(DragObject d) {
return d.dragSource != this && isDragWidget(d);
}

private boolean isDragAllAppsButton(DragObject d) {
return (d.dragInfo instanceof AllAppsButtonInfo);
}

public void onDragOver(DragObject d) {
// Skip drag over events while we are dragging over side pages
if (mInScrollArea || mIsSwitchingState || mState == State.SMALL) return;
Expand Down Expand Up @@ -2903,7 +2916,7 @@ public void onDragOver(DragObject d) {
// Test to see if we are over the hotseat otherwise just use the current page
if (mLauncher.getHotseat() != null && !isDragWidget(d)) {
mLauncher.getHotseat().getHitRect(r);
if (r.contains(d.x, d.y)) {
if (r.contains(d.x, d.y) || isDragAllAppsButton(d)) {
layout = mLauncher.getHotseat().getLayout();
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/com/cyanogenmod/trebuchet/preference/Preferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import android.preference.Preference;
import android.preference.PreferenceActivity;

import com.cyanogenmod.trebuchet.LauncherApplication;
import com.cyanogenmod.trebuchet.R;

public class Preferences extends PreferenceActivity
Expand All @@ -35,6 +36,9 @@ public class Preferences extends PreferenceActivity
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
if (LauncherApplication.isScreenLarge()) {
findPreference("ui_dock").setEnabled(false);
}

mPrefs = getSharedPreferences(PreferencesProvider.PREFERENCES_KEY,
Context.MODE_PRIVATE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import android.content.SharedPreferences;

import com.cyanogenmod.trebuchet.LauncherApplication;
import com.cyanogenmod.trebuchet.R;
import com.cyanogenmod.trebuchet.Workspace;
import com.cyanogenmod.trebuchet.AppsCustomizePagedView;

Expand Down Expand Up @@ -117,7 +118,18 @@ public static boolean getFadeScrollingIndicator(Context context) {
}

public static class Dock {

public static int getNumberHotseatIcons(Context context) {
final SharedPreferences preferences = context.getSharedPreferences(PREFERENCES_KEY, 0);
return preferences.getInt("ui_dock_hotseat_size", context.getResources().getInteger(R.integer.hotseat_cell_count));
}
public static int getDefaultHotseatIcon(Context context, int def) {
final SharedPreferences preferences = context.getSharedPreferences(PREFERENCES_KEY, 0);
return preferences.getInt("ui_dock_hotseat_apps_index", def);
}
public static void setDefaultHotseatIcon(Context context, int val) {
final SharedPreferences preferences = context.getSharedPreferences(PREFERENCES_KEY, 0);
preferences.edit().putInt("ui_dock_hotseat_apps_index", val).apply();
}
}

public static class Icons {
Expand Down

0 comments on commit e74a543

Please sign in to comment.