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

Commit d2e20de6 authored by Adam Cohen's avatar Adam Cohen
Browse files

Adding framework support for resizable widgets

-> Added resizeMode to the widget xml
-> Fixed an unexposed bug in AppWidgetHost where
   minWidth and minHeight were never being converted
   from complex type to dp

Change-Id: Ibbc4fc6542d095623ac2a40694b6a3dbfeb279ad
parent 0277c171
Loading
Loading
Loading
Loading
+65 −0
Original line number Diff line number Diff line
@@ -7924,6 +7924,17 @@
 visibility="public"
>
</field>
<field name="resizeMode"
 type="int"
 transient="false"
 volatile="false"
 value="16843619"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="resizeable"
 type="int"
 transient="false"
@@ -39802,6 +39813,50 @@
 visibility="public"
>
</field>
<field name="RESIZE_BOTH"
 type="int"
 transient="false"
 volatile="false"
 value="3"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="RESIZE_HORIZONTAL"
 type="int"
 transient="false"
 volatile="false"
 value="1"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="RESIZE_NONE"
 type="int"
 transient="false"
 volatile="false"
 value="0"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="RESIZE_VERTICAL"
 type="int"
 transient="false"
 volatile="false"
 value="2"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="autoAdvanceViewId"
 type="int"
 transient="false"
@@ -39892,6 +39947,16 @@
 visibility="public"
>
</field>
<field name="resizableMode"
 type="int"
 transient="false"
 volatile="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="updatePeriodMillis"
 type="int"
 transient="false"
+17 −4
Original line number Diff line number Diff line
@@ -16,6 +16,9 @@

package android.appwidget;

import java.util.ArrayList;
import java.util.HashMap;

import android.content.Context;
import android.os.Handler;
import android.os.IBinder;
@@ -23,11 +26,10 @@ import android.os.Looper;
import android.os.Message;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.util.DisplayMetrics;
import android.util.TypedValue;
import android.widget.RemoteViews;

import java.util.ArrayList;
import java.util.HashMap;

import com.android.internal.appwidget.IAppWidgetHost;
import com.android.internal.appwidget.IAppWidgetService;

@@ -43,6 +45,7 @@ public class AppWidgetHost {

    final static Object sServiceLock = new Object();
    static IAppWidgetService sService;
    private DisplayMetrics mDisplayMetrics;

    Context mContext;
    String mPackageName;
@@ -103,6 +106,7 @@ public class AppWidgetHost {
        mContext = context;
        mHostId = hostId;
        mHandler = new UpdateHandler(context.getMainLooper());
        mDisplayMetrics = context.getResources().getDisplayMetrics();
        synchronized (sServiceLock) {
            if (sService == null) {
                IBinder b = ServiceManager.getService(Context.APPWIDGET_SERVICE);
@@ -249,6 +253,15 @@ public class AppWidgetHost {
     */
    protected void onProviderChanged(int appWidgetId, AppWidgetProviderInfo appWidget) {
        AppWidgetHostView v;

        // Convert complex to dp -- we are getting the AppWidgetProviderInfo from the
        // AppWidgetService, which doesn't have our context, hence we need to do the 
        // conversion here.
        appWidget.minWidth =
            TypedValue.complexToDimensionPixelSize(appWidget.minWidth, mDisplayMetrics);
        appWidget.minHeight =
            TypedValue.complexToDimensionPixelSize(appWidget.minHeight, mDisplayMetrics);

        synchronized (mViews) {
            v = mViews.get(appWidgetId);
        }
+27 −0
Original line number Diff line number Diff line
@@ -25,6 +25,24 @@ import android.content.ComponentName;
 * correspond to the fields in the <code>&lt;appwidget-provider&gt;</code> xml tag.
 */
public class AppWidgetProviderInfo implements Parcelable {

    /**
     * Widget is not resizable.
     */
    public static final int RESIZE_NONE             = 0;
    /**
     * Widget is resizable in the horizontal axis only.
     */
    public static final int RESIZE_HORIZONTAL       = 1;
    /**
     * Widget is resizable in the vertical axis only.
     */
    public static final int RESIZE_VERTICAL         = 2;
    /**
     * Widget is resizable in both the horizontal and vertical axes.
     */
    public static final int RESIZE_BOTH = RESIZE_HORIZONTAL | RESIZE_VERTICAL;

    /**
     * Identity of this AppWidget component.  This component should be a {@link
     * android.content.BroadcastReceiver}, and it will be sent the AppWidget intents
@@ -124,6 +142,13 @@ public class AppWidgetProviderInfo implements Parcelable {
     */
	public int previewImage;

    /**
     * The rules by which a widget can be resized. See {@link #RESIZE_NONE},
     * {@link #RESIZE_NONE}, {@link #RESIZE_HORIZONTAL},
     * {@link #RESIZE_VERTICAL}, {@link #RESIZE_BOTH}.
     */
    public int resizableMode;

    public AppWidgetProviderInfo() {
    }

@@ -145,6 +170,7 @@ public class AppWidgetProviderInfo implements Parcelable {
        this.icon = in.readInt();
        this.previewImage = in.readInt();
        this.autoAdvanceViewId = in.readInt();
        this.resizableMode = in.readInt();
    }

    public void writeToParcel(android.os.Parcel out, int flags) {
@@ -168,6 +194,7 @@ public class AppWidgetProviderInfo implements Parcelable {
        out.writeInt(this.icon);
        out.writeInt(this.previewImage);
        out.writeInt(this.autoAdvanceViewId);
        out.writeInt(this.resizableMode);
    }

    public int describeContents() {
+7 −0
Original line number Diff line number Diff line
@@ -4549,6 +4549,13 @@
        <!-- The view id of the AppWidget subview which should be auto-advanced.
             by the widget's host. -->
        <attr name="autoAdvanceViewId" format="reference" />
        <!-- Optional parameter which indicates if and how this widget can be 
             resized. -->
        <attr name="resizeMode" format="integer">
            <flag name="none" value="0x0" />
            <flag name="horizontal" value="0x1" />
            <flag name="vertical" value="0x2" />
        </attr>
    </declare-styleable>

    <!-- =============================== -->
+2 −1
Original line number Diff line number Diff line
@@ -1647,4 +1647,5 @@
     =============================================================== -->
  <eat-comment />
  <public type="attr" name="textCursorDrawable" id="0x01010362" />
  <public type="attr" name="resizeMode" />
</resources>
Loading