Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 223622a5 authored by Alan Viverette's avatar Alan Viverette
Browse files

Add reveal drawable, APIs for forwarding Drawable focus and touch

Hotspot APIs are hidden pending finalization of how we handle IDs.

BUG: 11416827
Change-Id: Iecacb4b8e3690930d2d805ae65a50cf33482a218
parent ef3b704d
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -1814,6 +1814,7 @@ package android {
    field public static final int Theme_NoTitleBar_OverlayActionModes = 16973930; // 0x103006a
    field public static final int Theme_Panel = 16973913; // 0x1030059
    field public static final int Theme_Quantum = 16974318; // 0x10301ee
    field public static final int Theme_Quantum_NoActionBar = 16974319; // 0x10301ef
    field public static final int Theme_Translucent = 16973839; // 0x103000f
    field public static final int Theme_Translucent_NoTitleBar = 16973840; // 0x1030010
    field public static final int Theme_Translucent_NoTitleBar_Fullscreen = 16973841; // 0x1030011
@@ -2101,6 +2102,11 @@ package android {
    field public static final int Widget_ProgressBar_Large_Inverse = 16973916; // 0x103005c
    field public static final int Widget_ProgressBar_Small = 16973854; // 0x103001e
    field public static final int Widget_ProgressBar_Small_Inverse = 16973917; // 0x103005d
    field public static final int Widget_Quantum_Button = 16974320; // 0x10301f0
    field public static final int Widget_Quantum_Button_Borderless = 16974322; // 0x10301f2
    field public static final int Widget_Quantum_Button_Borderless_Small = 16974323; // 0x10301f3
    field public static final int Widget_Quantum_Button_Small = 16974321; // 0x10301f1
    field public static final int Widget_Quantum_ImageButton = 16974324; // 0x10301f4
    field public static final int Widget_RatingBar = 16973857; // 0x1030021
    field public static final int Widget_ScrollView = 16973869; // 0x103002d
    field public static final int Widget_SeekBar = 16973856; // 0x1030020
@@ -10425,6 +10431,10 @@ package android.graphics.drawable {
    method public void setPicture(android.graphics.Picture);
  }
  public class RevealDrawable extends android.graphics.drawable.LayerDrawable {
    ctor public RevealDrawable(android.graphics.drawable.Drawable[]);
  }
  public class RotateDrawable extends android.graphics.drawable.Drawable implements android.graphics.drawable.Drawable.Callback {
    ctor public RotateDrawable();
    method public void draw(android.graphics.Canvas);
+78 −4
Original line number Diff line number Diff line
@@ -57,6 +57,7 @@ import android.util.FloatProperty;
import android.util.LayoutDirection;
import android.util.Log;
import android.util.LongSparseLongArray;
import android.util.MathUtils;
import android.util.Pools.SynchronizedPool;
import android.util.Property;
import android.util.SparseArray;
@@ -86,6 +87,7 @@ import static java.lang.Math.max;
import com.android.internal.R;
import com.android.internal.util.Predicate;
import com.android.internal.view.menu.MenuBuilder;
import com.google.android.collect.Lists;
import com.google.android.collect.Maps;
@@ -4748,11 +4750,42 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
                mAttachInfo.mTreeObserver.dispatchOnGlobalFocusChange(oldFocus, this);
            }
            manageFocusHotspot(true, oldFocus);
            onFocusChanged(true, direction, previouslyFocusedRect);
            refreshDrawableState();
        }
    }
    /**
     * Forwards focus information to the background drawable, if necessary. When
     * the view is gaining focus, <code>v</code> is the previous focus holder.
     * When the view is losing focus, <code>v</code> is the next focus holder.
     *
     * @param focused whether this view is focused
     * @param v previous or the next focus holder, or null if none
     */
    private void manageFocusHotspot(boolean focused, View v) {
        if (mBackground != null && mBackground.supportsHotspots()) {
            final Rect r = new Rect();
            if (v != null) {
                v.getBoundsOnScreen(r);
                final int[] location = new int[2];
                getLocationOnScreen(location);
                r.offset(-location[0], -location[1]);
            } else {
                r.set(mLeft, mTop, mRight, mBottom);
            }
            final float x = r.exactCenterX();
            final float y = r.exactCenterY();
            mBackground.setHotspot(Drawable.HOTSPOT_FOCUS, x, y);
            if (!focused) {
                mBackground.removeHotspot(Drawable.HOTSPOT_FOCUS);
            }
        }
    }
    /**
     * Request that a rectangle of this view be visible on the screen,
     * scrolling if necessary just enough.
@@ -4839,7 +4872,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
            System.out.println(this + " clearFocus()");
        }
        clearFocusInternal(true, true);
        clearFocusInternal(null, true, true);
    }
    /**
@@ -4851,10 +4884,14 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
     * @param refocus when propagate is true, specifies whether to request the
     *            root view place new focus
     */
    void clearFocusInternal(boolean propagate, boolean refocus) {
    void clearFocusInternal(View focused, boolean propagate, boolean refocus) {
        if ((mPrivateFlags & PFLAG_FOCUSED) != 0) {
            mPrivateFlags &= ~PFLAG_FOCUSED;
            if (hasFocus()) {
                manageFocusHotspot(false, focused);
            }
            if (propagate && mParent != null) {
                mParent.clearChildFocus(this);
            }
@@ -4888,12 +4925,12 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
     * after calling this method. Otherwise, the view hierarchy may be left in
     * an inconstent state.
     */
    void unFocus() {
    void unFocus(View focused) {
        if (DBG) {
            System.out.println(this + " unFocus()");
        }
        clearFocusInternal(false, false);
        clearFocusInternal(focused, false, false);
    }
    /**
@@ -8909,12 +8946,49 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
                    }
                    break;
            }
            if (mBackground != null && mBackground.supportsHotspots()) {
                manageTouchHotspot(event);
            }
            return true;
        }
        return false;
    }
    private void manageTouchHotspot(MotionEvent event) {
        switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
            case MotionEvent.ACTION_POINTER_DOWN: {
                final int index = event.getActionIndex();
                setPointerHotspot(event, index);
            } break;
            case MotionEvent.ACTION_MOVE: {
                final int count = event.getPointerCount();
                for (int index = 0; index < count; index++) {
                    setPointerHotspot(event, index);
                }
            } break;
            case MotionEvent.ACTION_POINTER_UP: {
                final int actionIndex = event.getActionIndex();
                final int pointerId = event.getPointerId(actionIndex);
                mBackground.removeHotspot(pointerId);
            } break;
            case MotionEvent.ACTION_UP:
            case MotionEvent.ACTION_CANCEL:
                mBackground.clearHotspots();
                break;
        }
    }
    private void setPointerHotspot(MotionEvent event, int index) {
        final int id = event.getPointerId(index);
        final float x = event.getX(index);
        final float y = event.getY(index);
        mBackground.setHotspot(id, x, y);
    }
    /**
     * @hide
     */
+9 −9
Original line number Diff line number Diff line
@@ -598,7 +598,7 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
    @Override
    void handleFocusGainInternal(int direction, Rect previouslyFocusedRect) {
        if (mFocused != null) {
            mFocused.unFocus();
            mFocused.unFocus(this);
            mFocused = null;
        }
        super.handleFocusGainInternal(direction, previouslyFocusedRect);
@@ -616,12 +616,12 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
        }

        // Unfocus us, if necessary
        super.unFocus();
        super.unFocus(focused);

        // We had a previous notion of who had focus. Clear it.
        if (mFocused != child) {
            if (mFocused != null) {
                mFocused.unFocus();
                mFocused.unFocus(focused);
            }

            mFocused = child;
@@ -812,14 +812,14 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
     * {@inheritDoc}
     */
    @Override
    void unFocus() {
    void unFocus(View focused) {
        if (DBG) {
            System.out.println(this + " unFocus()");
        }
        if (mFocused == null) {
            super.unFocus();
            super.unFocus(focused);
        } else {
            mFocused.unFocus();
            mFocused.unFocus(focused);
            mFocused = null;
        }
    }
@@ -3827,7 +3827,7 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager

        boolean clearChildFocus = false;
        if (view == mFocused) {
            view.unFocus();
            view.unFocus(null);
            clearChildFocus = true;
        }

@@ -3922,7 +3922,7 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
            }

            if (view == focused) {
                view.unFocus();
                view.unFocus(null);
                clearChildFocus = true;
            }

@@ -4009,7 +4009,7 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
            }

            if (view == focused) {
                view.unFocus();
                view.unFocus(null);
                clearChildFocus = true;
            }

+1 −1
Original line number Diff line number Diff line
@@ -3331,7 +3331,7 @@ public final class ViewRootImpl implements ViewParent,
                } else {
                    // There's nothing to focus. Clear and propagate through the
                    // hierarchy, but don't attempt to place new focus.
                    focused.clearFocusInternal(true, false);
                    focused.clearFocusInternal(null, true, false);
                    return true;
                }
            }
+34 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2013 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.
-->

<reveal xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <selector>
            <item android:state_window_focused="false" android:state_enabled="true"
                android:drawable="@drawable/btn_default_normal_holo_light" />
            <item android:state_window_focused="false" android:state_enabled="false"
                android:drawable="@drawable/btn_default_disabled_holo_light" />
            <item android:state_focused="true" android:state_enabled="true"
                android:drawable="@drawable/btn_default_focused_holo_light" />
            <item android:state_enabled="true"
                android:drawable="@drawable/btn_default_normal_holo_light" />
            <item android:state_focused="true"
                android:drawable="@drawable/btn_default_disabled_focused_holo_light" />
            <item
                android:drawable="@drawable/btn_default_disabled_holo_light" />
        </selector>
    </item>
</reveal>
Loading