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

Commit 848fe6be authored by Filip Gruszczynski's avatar Filip Gruszczynski
Browse files

API for specifying size/gravity of launching activity.

Change-Id: I4d75b3fa56ff9c35be9beeba81e3ec9ab28a9996
parent 658b8c25
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -8881,6 +8881,7 @@ package android.content.pm {
    field public int configChanges;
    field public int documentLaunchMode;
    field public int flags;
    field public android.content.pm.ActivityInfo.InitialLayout initialLayout;
    field public int launchMode;
    field public int maxRecents;
    field public java.lang.String parentActivityName;
@@ -8894,6 +8895,15 @@ package android.content.pm {
    field public int uiOptions;
  }
  public static final class ActivityInfo.InitialLayout {
    ctor public ActivityInfo.InitialLayout(int, float, int, float, int);
    field public final int gravity;
    field public final int height;
    field public final float heightFraction;
    field public final int width;
    field public final float widthFraction;
  }
  public class ApplicationInfo extends android.content.pm.PackageItemInfo implements android.os.Parcelable {
    ctor public ApplicationInfo();
    ctor public ApplicationInfo(android.content.pm.ApplicationInfo);
+10 −0
Original line number Diff line number Diff line
@@ -9139,6 +9139,7 @@ package android.content.pm {
    field public int configChanges;
    field public int documentLaunchMode;
    field public int flags;
    field public android.content.pm.ActivityInfo.InitialLayout initialLayout;
    field public int launchMode;
    field public int maxRecents;
    field public java.lang.String parentActivityName;
@@ -9152,6 +9153,15 @@ package android.content.pm {
    field public int uiOptions;
  }
  public static final class ActivityInfo.InitialLayout {
    ctor public ActivityInfo.InitialLayout(int, float, int, float, int);
    field public final int gravity;
    field public final int height;
    field public final float heightFraction;
    field public final int width;
    field public final float widthFraction;
  }
  public class ApplicationInfo extends android.content.pm.PackageItemInfo implements android.os.Parcelable {
    ctor public ApplicationInfo();
    ctor public ApplicationInfo(android.content.pm.ApplicationInfo);
+46 −1
Original line number Diff line number Diff line
@@ -698,6 +698,8 @@ public class ActivityInfo extends ComponentInfo
     */
    public int lockTaskLaunchMode;

    public InitialLayout initialLayout;

    public ActivityInfo() {
    }

@@ -763,6 +765,11 @@ public class ActivityInfo extends ComponentInfo
        }
        pw.println(prefix + "resizeable=" + resizeable + " lockTaskLaunchMode="
                + lockTaskLaunchModeToString(lockTaskLaunchMode));
        if (initialLayout != null) {
            pw.println(prefix + "initialLayout=" + initialLayout.width + "|"
                    + initialLayout.widthFraction + ", " + initialLayout.height + "|"
                    + initialLayout.heightFraction + ", " + initialLayout.gravity);
        }
        super.dumpBack(pw, prefix);
    }

@@ -793,6 +800,16 @@ public class ActivityInfo extends ComponentInfo
        dest.writeInt(maxRecents);
        dest.writeInt(resizeable ? 1 : 0);
        dest.writeInt(lockTaskLaunchMode);
        if (initialLayout != null) {
            dest.writeInt(1);
            dest.writeInt(initialLayout.width);
            dest.writeFloat(initialLayout.widthFraction);
            dest.writeInt(initialLayout.height);
            dest.writeFloat(initialLayout.heightFraction);
            dest.writeInt(initialLayout.gravity);
        } else {
            dest.writeInt(0);
        }
    }

    public static final Parcelable.Creator<ActivityInfo> CREATOR
@@ -822,5 +839,33 @@ public class ActivityInfo extends ComponentInfo
        maxRecents = source.readInt();
        resizeable = (source.readInt() == 1);
        lockTaskLaunchMode = source.readInt();
        if (source.readInt() == 1) {
            initialLayout = new InitialLayout(source);
        }
    }

    public static final class InitialLayout {
        public InitialLayout(int width, float widthFraction, int height, float heightFraction,
                int gravity) {
            this.width = width;
            this.widthFraction = widthFraction;
            this.height = height;
            this.heightFraction = heightFraction;
            this.gravity = gravity;
        }

        InitialLayout(Parcel source) {
            width = source.readInt();
            widthFraction = source.readFloat();
            height = source.readInt();
            heightFraction = source.readFloat();
            gravity = source.readInt();
        }

        public final int width;
        public final float widthFraction;
        public final int height;
        public final float heightFraction;
        public final int gravity;
    }
}
+41 −1
Original line number Diff line number Diff line
@@ -50,6 +50,7 @@ import android.util.Log;
import android.util.Pair;
import android.util.Slog;
import android.util.TypedValue;
import android.view.Gravity;

import com.android.internal.R;
import com.android.internal.util.ArrayUtils;
@@ -3264,6 +3265,8 @@ public class PackageParser {
                        outError)) == null) {
                    return null;
                }
            } else if (!receiver && parser.getName().equals("initial-layout")) {
                parseInitialLayout(res, attrs, a);
            } else {
                if (!RIGID_PARSER) {
                    Slog.w(TAG, "Problem in package " + mArchiveSourcePath + ":");
@@ -3296,6 +3299,43 @@ public class PackageParser {
        return a;
    }

    private void parseInitialLayout(Resources res, AttributeSet attrs, Activity a) {
        TypedArray sw = res.obtainAttributes(attrs,
                com.android.internal.R.styleable.AndroidManifestInitialLayout);
        int width = -1;
        float widthFraction = -1f;
        int height = -1;
        float heightFraction = -1f;
        final int widthType = sw.getType(
                com.android.internal.R.styleable.AndroidManifestInitialLayout_activity_width);
        if (widthType == TypedValue.TYPE_FRACTION) {
            widthFraction = sw.getFraction(
                    com.android.internal.R.styleable.AndroidManifestInitialLayout_activity_width,
                    1, 1, -1);
        } else if (widthType == TypedValue.TYPE_DIMENSION) {
            width = sw.getDimensionPixelSize(
                    com.android.internal.R.styleable.AndroidManifestInitialLayout_activity_width,
                    -1);
        }
        final int heightType = sw.getType(
                com.android.internal.R.styleable.AndroidManifestInitialLayout_activity_height);
        if (heightType == TypedValue.TYPE_FRACTION) {
            heightFraction = sw.getFraction(
                    com.android.internal.R.styleable.AndroidManifestInitialLayout_activity_height,
                    1, 1, -1);
        } else if (heightType == TypedValue.TYPE_DIMENSION) {
            height = sw.getDimensionPixelSize(
                    com.android.internal.R.styleable.AndroidManifestInitialLayout_activity_height,
                    -1);
        }
        int gravity = sw.getInt(
                com.android.internal.R.styleable.AndroidManifestInitialLayout_gravity,
                Gravity.CENTER);
        sw.recycle();
        a.info.initialLayout = new ActivityInfo.InitialLayout(width, widthFraction,
                height, heightFraction, gravity);
    }

    private Activity parseActivityAlias(Package owner, Resources res,
            XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
            throws XmlPullParserException, IOException {
+14 −0
Original line number Diff line number Diff line
@@ -2195,4 +2195,18 @@
      <attr name="name" />
    </declare-styleable>

    <!-- <code>initial-layout</code> tag allows configuring the initial layout for the activity
         within multi-window environment. -->
    <declare-styleable name="AndroidManifestInitialLayout" parent="AndroidManifestActivity">
        <!-- Initial width of the activity. Can be either a fixed value or fraction, in which case
             the width will be constructed as a fraction of the total available width. -->
        <attr name="activity_width" format="dimension|fraction" />
        <!-- Initial height of the activity. Can be either a fixed value or fraction, in which case
             the height will be constructed as a fraction of the total available height. -->
        <attr name="activity_height" format="dimension|fraction" />
        <!-- Where to initially position the activity inside the available space. Uses constants
             defined in {@link android.view.Gravity}. -->
        <attr name="gravity" />
    </declare-styleable>

</resources>