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.
|
|
|
|
|
*/
|
|
|
|
|
|
2013-06-05 22:57:57 -04:00
|
|
|
package com.android.launcher3;
|
2011-05-31 16:50:48 -07:00
|
|
|
|
|
|
|
|
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;
|
2014-06-03 18:03:29 -07:00
|
|
|
import android.graphics.drawable.Drawable;
|
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
|
|
|
|
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
|
|
|
|
|
|
|
|
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);
|
2012-05-15 16:34:19 -07:00
|
|
|
mDrawable = (TransitionDrawable) getCurrentDrawable();
|
2014-06-03 18:03:29 -07:00
|
|
|
|
|
|
|
|
if (mDrawable == null) {
|
|
|
|
|
System.out.println("onFinishInflate -- drawable null");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// DEBUG CODE:
|
|
|
|
|
Drawable normal = r.getDrawable(R.drawable.ic_launcher_info_normal_holo);
|
|
|
|
|
Drawable active = r.getDrawable(R.drawable.ic_launcher_info_active_holo);
|
|
|
|
|
Drawable selector = r.getDrawable(R.drawable.info_target_selector);
|
|
|
|
|
System.out.println("Normal: " + normal);
|
|
|
|
|
System.out.println("Active: " + active);
|
|
|
|
|
System.out.println("Selector: " + selector);
|
|
|
|
|
|
2012-12-18 16:25:49 -08:00
|
|
|
if (null != mDrawable) {
|
|
|
|
|
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) {
|
2013-06-25 15:13:26 -04:00
|
|
|
if (!LauncherAppState.getInstance().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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@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;
|
2013-09-04 00:45:37 +02:00
|
|
|
if (d.dragInfo instanceof AppInfo) {
|
|
|
|
|
componentName = ((AppInfo) d.dragInfo).componentName;
|
2011-05-31 16:50:48 -07:00
|
|
|
} else if (d.dragInfo instanceof ShortcutInfo) {
|
|
|
|
|
componentName = ((ShortcutInfo) d.dragInfo).intent.getComponent();
|
2012-04-27 15:12:38 -07:00
|
|
|
} else if (d.dragInfo instanceof PendingAddItemInfo) {
|
|
|
|
|
componentName = ((PendingAddItemInfo) d.dragInfo).componentName;
|
2011-05-31 16:50:48 -07:00
|
|
|
}
|
|
|
|
|
if (componentName != null) {
|
|
|
|
|
mLauncher.startApplicationDetailsActivity(componentName);
|
|
|
|
|
}
|
2012-02-13 18:29:29 -08:00
|
|
|
|
|
|
|
|
// There is no post-drop animation, so clean up the DragView now
|
|
|
|
|
d.deferDragViewCleanupPostAnimation = false;
|
2011-05-31 16:50:48 -07:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onDragStart(DragSource source, Object info, int dragAction) {
|
|
|
|
|
boolean isVisible = true;
|
|
|
|
|
|
2012-04-27 15:12:38 -07:00
|
|
|
// Hide this button unless we are dragging something from AllApps
|
2013-11-25 17:01:34 +00:00
|
|
|
if (!source.supportsAppInfoDropTarget()) {
|
2011-05-31 16:50:48 -07:00
|
|
|
isVisible = false;
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-03 18:03:29 -07:00
|
|
|
if (mDrawable == null) {
|
|
|
|
|
System.out.println("onDragStart -- drawable null");
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-31 16:50:48 -07:00
|
|
|
mActive = isVisible;
|
2014-06-03 18:03:29 -07:00
|
|
|
if (mDrawable != null) {
|
|
|
|
|
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);
|
|
|
|
|
|
2014-06-03 18:03:29 -07:00
|
|
|
if (mDrawable != null) {
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
}
|