diff options
Diffstat (limited to 'src/com')
-rw-r--r-- | src/com/cyanogenmod/trebuchet/BubbleTextView.java | 12 | ||||
-rw-r--r-- | src/com/cyanogenmod/trebuchet/EditDropTarget.java | 124 | ||||
-rw-r--r-- | src/com/cyanogenmod/trebuchet/Launcher.java | 28 | ||||
-rw-r--r-- | src/com/cyanogenmod/trebuchet/LauncherModel.java | 14 | ||||
-rw-r--r-- | src/com/cyanogenmod/trebuchet/SearchDropTargetBar.java | 6 | ||||
-rw-r--r-- | src/com/cyanogenmod/trebuchet/ShortcutInfo.java | 20 | ||||
-rw-r--r-- | src/com/cyanogenmod/trebuchet/Workspace.java | 4 |
7 files changed, 198 insertions, 10 deletions
diff --git a/src/com/cyanogenmod/trebuchet/BubbleTextView.java b/src/com/cyanogenmod/trebuchet/BubbleTextView.java index 739440b..4c94bc9 100644 --- a/src/com/cyanogenmod/trebuchet/BubbleTextView.java +++ b/src/com/cyanogenmod/trebuchet/BubbleTextView.java @@ -33,7 +33,7 @@ import android.widget.TextView; * because we want to make the bubble taller than the text and TextView's clip is * too aggressive. */ -public class BubbleTextView extends TextView { +public class BubbleTextView extends TextView implements ShortcutInfo.ShortcutListener { static final float CORNER_RADIUS = 4.0f; static final float SHADOW_LARGE_RADIUS = 4.0f; static final float SHADOW_SMALL_RADIUS = 1.75f; @@ -98,6 +98,7 @@ public class BubbleTextView extends TextView { null, null); setText(info.title); setTag(info); + info.setListener(this); } @Override @@ -161,6 +162,15 @@ public class BubbleTextView extends TextView { super.drawableStateChanged(); } + @Override + public void onTitleChanged(CharSequence title) { + if (mTextVisible) { + setText(title); + } else { + mVisibleText = title; + } + } + /** * Draw this BubbleTextView into the given Canvas. * diff --git a/src/com/cyanogenmod/trebuchet/EditDropTarget.java b/src/com/cyanogenmod/trebuchet/EditDropTarget.java new file mode 100644 index 0000000..7089ef4 --- /dev/null +++ b/src/com/cyanogenmod/trebuchet/EditDropTarget.java @@ -0,0 +1,124 @@ +/* + * Copyright (C) 2011 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; + +import android.content.ComponentName; +import android.content.Context; +import android.content.res.ColorStateList; +import android.content.res.Configuration; +import android.content.res.Resources; +import android.graphics.drawable.TransitionDrawable; +import android.util.AttributeSet; +import android.view.View; +import android.view.ViewGroup; + +import com.cyanogenmod.trebuchet.R; + +public class EditDropTarget extends ButtonDropTarget { + + private ColorStateList mOriginalTextColor; + private TransitionDrawable mDrawable; + + public EditDropTarget(Context context, AttributeSet attrs) { + this(context, attrs, 0); + } + + public EditDropTarget(Context context, AttributeSet attrs, int defStyle) { + super(context, attrs, defStyle); + } + + @Override + protected void onFinishInflate() { + super.onFinishInflate(); + + mOriginalTextColor = getTextColors(); + + // Get the hover color + Resources r = getResources(); + mHoverColor = r.getColor(R.color.edit_target_hover_tint); + mDrawable = (TransitionDrawable) getCurrentDrawable(); + mDrawable.setCrossFadeEnabled(true); + + // Remove the text in the Phone UI in landscape + int orientation = getResources().getConfiguration().orientation; + if (orientation == Configuration.ORIENTATION_LANDSCAPE) { + if (!LauncherApplication.isScreenLarge()) { + setText(""); + } + } + } + + private boolean isDragSourceWorkspaceOrFolder(DragSource source) { + return (source instanceof Workspace) || (source instanceof Folder); + } + private boolean isWorkspaceOrFolderApplication(DragSource source, Object info) { + return isDragSourceWorkspaceOrFolder(source) && (info instanceof ShortcutInfo); + } + + @Override + public boolean acceptDrop(DragObject d) { + // acceptDrop is called just before onDrop. We do the work here, rather than + // in onDrop, because it allows us to reject the drop (by returning false) + // so that the object being dragged isn't removed from the drag source. + if (d.dragInfo instanceof ShortcutInfo) { + mLauncher.updateShortcut((ShortcutInfo) d.dragInfo); + } else if (d.dragInfo instanceof Folder) { + // + } + + // There is no post-drop animation, so clean up the DragView now + d.deferDragViewCleanupPostAnimation = false; + return false; + } + + @Override + public void onDragStart(DragSource source, Object info, int dragAction) { + boolean isVisible = true; + + // Hide this button unless we are dragging something from AllApps + if (!isWorkspaceOrFolderApplication(source, info)) { + isVisible = false; + } + + mActive = isVisible; + mDrawable.resetTransition(); + setTextColor(mOriginalTextColor); + ((ViewGroup) getParent()).setVisibility(isVisible ? View.VISIBLE : View.GONE); + } + + @Override + public void onDragEnd() { + super.onDragEnd(); + mActive = false; + } + + public void onDragEnter(DragObject d) { + super.onDragEnter(d); + + mDrawable.startTransition(mTransitionDuration); + setTextColor(mHoverColor); + } + + public void onDragExit(DragObject d) { + super.onDragExit(d); + + if (!d.dragComplete) { + mDrawable.resetTransition(); + setTextColor(mOriginalTextColor); + } + } +}
\ No newline at end of file diff --git a/src/com/cyanogenmod/trebuchet/Launcher.java b/src/com/cyanogenmod/trebuchet/Launcher.java index 3450db6..e43029d 100644 --- a/src/com/cyanogenmod/trebuchet/Launcher.java +++ b/src/com/cyanogenmod/trebuchet/Launcher.java @@ -29,6 +29,7 @@ import android.animation.ValueAnimator.AnimatorUpdateListener; import android.app.Activity; import android.app.ActivityManager; import android.app.ActivityOptions; +import android.app.AlertDialog; import android.app.SearchManager; import android.appwidget.AppWidgetHostView; import android.appwidget.AppWidgetManager; @@ -39,6 +40,7 @@ import android.content.ComponentCallbacks2; import android.content.ComponentName; import android.content.ContentResolver; import android.content.Context; +import android.content.DialogInterface; import android.content.Intent; import android.content.IntentFilter; import android.content.SharedPreferences; @@ -89,6 +91,7 @@ import android.view.animation.AccelerateInterpolator; import android.view.animation.DecelerateInterpolator; import android.view.inputmethod.InputMethodManager; import android.widget.Advanceable; +import android.widget.EditText; import android.widget.ImageView; import android.widget.PopupMenu; import android.widget.TextView; @@ -983,6 +986,31 @@ public final class Launcher extends Activity } /** + * Starts shortcut rename dialog. + * + * @param info The shortcut to be edited + */ + void updateShortcut(final ShortcutInfo info) { + AlertDialog.Builder builder = new AlertDialog.Builder(this); + View layout = mInflater.inflate(R.layout.dialog_edit, null); + ImageView icon = (ImageView) layout.findViewById(R.id.dialog_edit_icon); + icon.setImageBitmap(info.getIcon(mIconCache)); + final EditText title = (EditText) layout.findViewById(R.id.dialog_edit_text); + title.setText(info.title); + builder.setView(layout) + .setTitle(info.title) + .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int id) { + info.setTitle(title.getText()); + LauncherModel.updateItemInDatabase(Launcher.this, info); + } + }) + .setNegativeButton(android.R.string.cancel, null); + builder.show(); + } + + /** * Creates a view representing a shortcut. * * @param info The data structure describing the shortcut. diff --git a/src/com/cyanogenmod/trebuchet/LauncherModel.java b/src/com/cyanogenmod/trebuchet/LauncherModel.java index 39281d5..8fd446c 100644 --- a/src/com/cyanogenmod/trebuchet/LauncherModel.java +++ b/src/com/cyanogenmod/trebuchet/LauncherModel.java @@ -2153,8 +2153,14 @@ public class LauncherModel extends BroadcastReceiver { } info.setIcon(icon); + // from the db + if (info.title == null) { + if (c != null) { + info.title = c.getString(titleIndex); + } + } // from the resource - if (resolveInfo != null) { + if (info.title == null && resolveInfo != null) { ComponentName key = LauncherModel.getComponentNameFromResolveInfo(resolveInfo); if (labelCache != null && labelCache.containsKey(key)) { info.title = labelCache.get(key); @@ -2165,12 +2171,6 @@ public class LauncherModel extends BroadcastReceiver { } } } - // from the db - if (info.title == null) { - if (c != null) { - info.title = c.getString(titleIndex); - } - } // fall back to the class name of the activity if (info.title == null) { info.title = componentName.getClassName(); diff --git a/src/com/cyanogenmod/trebuchet/SearchDropTargetBar.java b/src/com/cyanogenmod/trebuchet/SearchDropTargetBar.java index 1f6335f..075adae 100644 --- a/src/com/cyanogenmod/trebuchet/SearchDropTargetBar.java +++ b/src/com/cyanogenmod/trebuchet/SearchDropTargetBar.java @@ -51,6 +51,7 @@ public class SearchDropTargetBar extends FrameLayout implements DragController.D private View mDropTargetBar; private ButtonDropTarget mInfoDropTarget; private ButtonDropTarget mDeleteDropTarget; + private ButtonDropTarget mEditDropTarget; private int mBarHeight; private boolean mDeferOnDragEnd = false; @@ -71,11 +72,14 @@ public class SearchDropTargetBar extends FrameLayout implements DragController.D dragController.addDragListener(this); dragController.addDragListener(mInfoDropTarget); dragController.addDragListener(mDeleteDropTarget); + dragController.addDragListener(mEditDropTarget); dragController.addDropTarget(mInfoDropTarget); dragController.addDropTarget(mDeleteDropTarget); + dragController.addDropTarget(mEditDropTarget); dragController.setFlingToDeleteDropTarget(mDeleteDropTarget); mInfoDropTarget.setLauncher(launcher); mDeleteDropTarget.setLauncher(launcher); + mEditDropTarget.setLauncher(launcher); } private void prepareStartAnimation(View v) { @@ -105,10 +109,12 @@ public class SearchDropTargetBar extends FrameLayout implements DragController.D mDropTargetBar = findViewById(R.id.drag_target_bar); mInfoDropTarget = (ButtonDropTarget) mDropTargetBar.findViewById(R.id.info_target_text); mDeleteDropTarget = (ButtonDropTarget) mDropTargetBar.findViewById(R.id.delete_target_text); + mEditDropTarget = (ButtonDropTarget) mDropTargetBar.findViewById(R.id.edit_target_text); mBarHeight = getResources().getDimensionPixelSize(R.dimen.qsb_bar_height); mInfoDropTarget.setSearchDropTargetBar(this); mDeleteDropTarget.setSearchDropTargetBar(this); + mEditDropTarget.setSearchDropTargetBar(this); mEnableDropDownDropTargets = getResources().getBoolean(R.bool.config_useDropTargetDownTransition); diff --git a/src/com/cyanogenmod/trebuchet/ShortcutInfo.java b/src/com/cyanogenmod/trebuchet/ShortcutInfo.java index cce432d..3c1f985 100644 --- a/src/com/cyanogenmod/trebuchet/ShortcutInfo.java +++ b/src/com/cyanogenmod/trebuchet/ShortcutInfo.java @@ -57,6 +57,11 @@ class ShortcutInfo extends ItemInfo { */ private Bitmap mIcon; + /** + * Title change listener + */ + private ShortcutListener mListener; + ShortcutInfo() { itemType = LauncherSettings.BaseLauncherColumns.ITEM_TYPE_SHORTCUT; } @@ -119,6 +124,17 @@ class ShortcutInfo extends ItemInfo { itemType = LauncherSettings.BaseLauncherColumns.ITEM_TYPE_APPLICATION; } + public void setTitle(CharSequence title) { + this.title = title; + if (mListener != null) { + mListener.onTitleChanged(title); + } + } + + void setListener(ShortcutListener listener) { + mListener = listener; + } + @Override void onAddToDatabase(ContentValues values) { super.onAddToDatabase(values); @@ -164,5 +180,9 @@ class ShortcutInfo extends ItemInfo { + " customIcon=" + info.customIcon); } } + + interface ShortcutListener { + public void onTitleChanged(CharSequence title); + } } diff --git a/src/com/cyanogenmod/trebuchet/Workspace.java b/src/com/cyanogenmod/trebuchet/Workspace.java index 3fc4ddf..4219e2b 100644 --- a/src/com/cyanogenmod/trebuchet/Workspace.java +++ b/src/com/cyanogenmod/trebuchet/Workspace.java @@ -4048,8 +4048,8 @@ public class Workspace extends SmoothPagedView } cellLayout.onDropChild(mDragInfo.cell); } - if (d.cancelled && mDragInfo.cell != null) { - mDragInfo.cell.setVisibility(VISIBLE); + if (mDragInfo.cell != null) { + mDragInfo.cell.setVisibility(VISIBLE); } mDragOutline = null; mDragInfo = null; |