2011-05-31 16:50:48 -07:00
|
|
|
/*
|
|
|
|
|
* 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.android.launcher2;
|
|
|
|
|
|
|
|
|
|
import android.content.ComponentName;
|
|
|
|
|
import android.content.Context;
|
2011-07-11 15:20:48 -07:00
|
|
|
import android.content.res.ColorStateList;
|
2011-06-20 15:41:53 -07:00
|
|
|
import android.content.res.Configuration;
|
2011-05-31 16:50:48 -07:00
|
|
|
import android.content.res.Resources;
|
|
|
|
|
import android.graphics.PorterDuff;
|
|
|
|
|
import android.graphics.PorterDuffColorFilter;
|
2011-06-30 18:09:30 -07:00
|
|
|
import android.graphics.drawable.TransitionDrawable;
|
2011-05-31 16:50:48 -07:00
|
|
|
import android.util.AttributeSet;
|
|
|
|
|
import android.view.View;
|
2011-07-27 10:53:39 -07:00
|
|
|
import android.view.ViewGroup;
|
2011-05-31 16:50:48 -07:00
|
|
|
|
|
|
|
|
import com.android.launcher.R;
|
|
|
|
|
|
2011-06-12 15:15:29 -07:00
|
|
|
public class InfoDropTarget extends ButtonDropTarget {
|
2011-05-31 16:50:48 -07:00
|
|
|
|
2011-07-11 15:20:48 -07:00
|
|
|
private ColorStateList mOriginalTextColor;
|
2011-06-30 18:09:30 -07:00
|
|
|
private TransitionDrawable mDrawable;
|
2011-05-31 16:50:48 -07:00
|
|
|
private int mHoverColor = 0xFF0000FF;
|
|
|
|
|
|
|
|
|
|
public InfoDropTarget(Context context, AttributeSet attrs) {
|
|
|
|
|
this(context, attrs, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public InfoDropTarget(Context context, AttributeSet attrs, int defStyle) {
|
|
|
|
|
super(context, attrs, defStyle);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void onFinishInflate() {
|
|
|
|
|
super.onFinishInflate();
|
|
|
|
|
|
2011-07-27 10:53:39 -07:00
|
|
|
mOriginalTextColor = getTextColors();
|
2011-06-20 15:41:53 -07:00
|
|
|
|
2011-05-31 16:50:48 -07:00
|
|
|
// Get the hover color
|
|
|
|
|
Resources r = getResources();
|
|
|
|
|
mHoverColor = r.getColor(R.color.info_target_hover_tint);
|
|
|
|
|
mHoverPaint.setColorFilter(new PorterDuffColorFilter(
|
|
|
|
|
mHoverColor, PorterDuff.Mode.SRC_ATOP));
|
2011-07-27 10:53:39 -07:00
|
|
|
mDrawable = (TransitionDrawable) getCompoundDrawables()[0];
|
2011-06-30 18:09:30 -07:00
|
|
|
mDrawable.setCrossFadeEnabled(true);
|
2011-06-20 15:41:53 -07:00
|
|
|
|
|
|
|
|
// Remove the text in the Phone UI in landscape
|
|
|
|
|
int orientation = getResources().getConfiguration().orientation;
|
|
|
|
|
if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
|
|
|
|
|
if (!LauncherApplication.isScreenLarge()) {
|
2011-07-27 10:53:39 -07:00
|
|
|
setText("");
|
2011-06-20 15:41:53 -07:00
|
|
|
}
|
|
|
|
|
}
|
2011-05-31 16:50:48 -07:00
|
|
|
}
|
|
|
|
|
|
2011-06-20 15:41:53 -07:00
|
|
|
private boolean isAllAppsApplication(DragSource source, Object info) {
|
|
|
|
|
return (source instanceof AppsCustomizePagedView) && (info instanceof ApplicationInfo);
|
2011-05-31 16:50:48 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@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.
|
|
|
|
|
ComponentName componentName = null;
|
|
|
|
|
if (d.dragInfo instanceof ApplicationInfo) {
|
|
|
|
|
componentName = ((ApplicationInfo) d.dragInfo).componentName;
|
|
|
|
|
} else if (d.dragInfo instanceof ShortcutInfo) {
|
|
|
|
|
componentName = ((ShortcutInfo) d.dragInfo).intent.getComponent();
|
|
|
|
|
}
|
|
|
|
|
if (componentName != null) {
|
|
|
|
|
mLauncher.startApplicationDetailsActivity(componentName);
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onDragStart(DragSource source, Object info, int dragAction) {
|
|
|
|
|
boolean isVisible = true;
|
|
|
|
|
|
|
|
|
|
// If we are dragging a widget or shortcut, hide the info target
|
2011-06-20 15:41:53 -07:00
|
|
|
if (!isAllAppsApplication(source, info)) {
|
2011-05-31 16:50:48 -07:00
|
|
|
isVisible = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mActive = isVisible;
|
2011-07-11 21:06:30 -07:00
|
|
|
mDrawable.resetTransition();
|
2011-07-27 10:53:39 -07:00
|
|
|
setTextColor(mOriginalTextColor);
|
|
|
|
|
((ViewGroup) getParent()).setVisibility(isVisible ? View.VISIBLE : View.GONE);
|
2011-05-31 16:50:48 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onDragEnd() {
|
|
|
|
|
super.onDragEnd();
|
|
|
|
|
mActive = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void onDragEnter(DragObject d) {
|
|
|
|
|
super.onDragEnter(d);
|
|
|
|
|
|
2011-06-30 18:09:30 -07:00
|
|
|
mDrawable.startTransition(mTransitionDuration);
|
2011-07-27 10:53:39 -07:00
|
|
|
setTextColor(mHoverColor);
|
2011-05-31 16:50:48 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void onDragExit(DragObject d) {
|
|
|
|
|
super.onDragExit(d);
|
|
|
|
|
|
2011-07-11 21:06:30 -07:00
|
|
|
if (!d.dragComplete) {
|
|
|
|
|
mDrawable.resetTransition();
|
2011-07-27 10:53:39 -07:00
|
|
|
setTextColor(mOriginalTextColor);
|
2011-07-11 21:06:30 -07:00
|
|
|
}
|
2011-05-31 16:50:48 -07:00
|
|
|
}
|
|
|
|
|
}
|