Merge "Setting drawable to droptarget in the code to avoid multiple drawable inflation" into ub-launcher3-burnaby

This commit is contained in:
Sunny Goyal
2015-05-20 23:50:54 +00:00
committed by Android (Google) Code Review
2 changed files with 8 additions and 31 deletions

View File

@@ -36,8 +36,6 @@
<com.android.launcher3.DeleteDropTarget
android:id="@+id/delete_target_text"
style="@style/DropTargetButton"
android:drawableLeft="@drawable/remove_target_selector"
android:drawableStart="@drawable/remove_target_selector"
android:text="@string/delete_target_label" />
</FrameLayout>
@@ -50,8 +48,6 @@
<com.android.launcher3.InfoDropTarget
android:id="@+id/info_target_text"
style="@style/DropTargetButton"
android:drawableLeft="@drawable/info_target_selector"
android:drawableStart="@drawable/info_target_selector"
android:text="@string/info_target_label" />
</FrameLayout>
@@ -64,8 +60,6 @@
<com.android.launcher3.UninstallDropTarget
android:id="@+id/uninstall_target_text"
style="@style/DropTargetButton"
android:drawableLeft="@drawable/uninstall_target_selector"
android:drawableStart="@drawable/uninstall_target_selector"
android:text="@string/delete_target_uninstall_label" />
</FrameLayout>
</LinearLayout>

View File

@@ -23,7 +23,6 @@ import android.content.res.ColorStateList;
import android.content.res.Configuration;
import android.graphics.PointF;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.TransitionDrawable;
import android.os.Build;
import android.util.AttributeSet;
@@ -85,21 +84,15 @@ public abstract class ButtonDropTarget extends TextView
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
protected void setDrawable(int resId) {
// Get the hover color
mDrawable = (TransitionDrawable) getCurrentDrawable();
// We do not set the drawable in the xml as that inflates two drawables corresponding to
// drawableLeft and drawableStart.
mDrawable = (TransitionDrawable) getResources().getDrawable(resId);
mDrawable.setCrossFadeEnabled(true);
if (mDrawable == null) {
// TODO: investigate why this is ever happening. Presently only on one known device.
mDrawable = (TransitionDrawable) getResources().getDrawable(resId);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
setCompoundDrawablesRelativeWithIntrinsicBounds(mDrawable, null, null, null);
} else {
setCompoundDrawablesWithIntrinsicBounds(mDrawable, null, null, null);
}
}
if (null != mDrawable) {
mDrawable.setCrossFadeEnabled(true);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
setCompoundDrawablesRelativeWithIntrinsicBounds(mDrawable, null, null, null);
} else {
setCompoundDrawablesWithIntrinsicBounds(mDrawable, null, null, null);
}
}
@@ -111,16 +104,6 @@ public abstract class ButtonDropTarget extends TextView
mSearchDropTargetBar = searchDropTargetBar;
}
protected Drawable getCurrentDrawable() {
Drawable[] drawables = getCompoundDrawables();
for (int i = 0; i < drawables.length; ++i) {
if (drawables[i] != null) {
return drawables[i];
}
}
return null;
}
@Override
public void onFlingToDelete(DragObject d, PointF vec) { }