add bunch of new java APIs: mostly stubs or copied from AOSP

Many of these classes are only needed to be subclassed by androidx
support library, which is used in many android apps
This commit is contained in:
Julian Winkler
2023-08-17 10:46:24 +02:00
parent a8e39cd613
commit 82744e9e5e
87 changed files with 2746 additions and 46 deletions

View File

@@ -0,0 +1,5 @@
package android.view;
public class AbsSavedState {
}

View File

@@ -0,0 +1,358 @@
/*
* Copyright (C) 2010 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.
*/
package android.view;
import android.graphics.Rect;
/**
* Represents a contextual mode of the user interface. Action modes can be used to provide
* alternative interaction modes and replace parts of the normal UI until finished.
* Examples of good action modes include text selection and contextual actions.
* <div class="special reference">
* <h3>Developer Guides</h3>
* <p>For information about how to provide contextual actions with {@code ActionMode},
* read the <a href="{@docRoot}guide/topics/ui/menus.html#context-menu">Menus</a>
* developer guide.</p>
* </div>
*/
public abstract class ActionMode {
/**
* The action mode is treated as a Primary mode. This is the default.
* Use with {@link #setType}.
*/
public static final int TYPE_PRIMARY = 0;
/**
* The action mode is treated as a Floating Toolbar.
* Use with {@link #setType}.
*/
public static final int TYPE_FLOATING = 1;
/**
* Default value to hide the action mode for
* {@link ViewConfiguration#getDefaultActionModeHideDuration()}.
*/
public static final int DEFAULT_HIDE_DURATION = -1;
private Object mTag;
private boolean mTitleOptionalHint;
private int mType = TYPE_PRIMARY;
/**
* Set a tag object associated with this ActionMode.
*
* <p>Like the tag available to views, this allows applications to associate arbitrary
* data with an ActionMode for later reference.
*
* @param tag Tag to associate with this ActionMode
*
* @see #getTag()
*/
public void setTag(Object tag) {
mTag = tag;
}
/**
* Retrieve the tag object associated with this ActionMode.
*
* <p>Like the tag available to views, this allows applications to associate arbitrary
* data with an ActionMode for later reference.
*
* @return Tag associated with this ActionMode
*
* @see #setTag(Object)
*/
public Object getTag() {
return mTag;
}
/**
* Set the title of the action mode. This method will have no visible effect if
* a custom view has been set.
*
* @param title Title string to set
*
* @see #setTitle(int)
* @see #setCustomView(View)
*/
public abstract void setTitle(CharSequence title);
/**
* Set the title of the action mode. This method will have no visible effect if
* a custom view has been set.
*
* @param resId Resource ID of a string to set as the title
*
* @see #setTitle(CharSequence)
* @see #setCustomView(View)
*/
public abstract void setTitle(int resId);
/**
* Set the subtitle of the action mode. This method will have no visible effect if
* a custom view has been set.
*
* @param subtitle Subtitle string to set
*
* @see #setSubtitle(int)
* @see #setCustomView(View)
*/
public abstract void setSubtitle(CharSequence subtitle);
/**
* Set the subtitle of the action mode. This method will have no visible effect if
* a custom view has been set.
*
* @param resId Resource ID of a string to set as the subtitle
*
* @see #setSubtitle(CharSequence)
* @see #setCustomView(View)
*/
public abstract void setSubtitle(int resId);
/**
* Set whether or not the title/subtitle display for this action mode
* is optional.
*
* <p>In many cases the supplied title for an action mode is merely
* meant to add context and is not strictly required for the action
* mode to be useful. If the title is optional, the system may choose
* to hide the title entirely rather than truncate it due to a lack
* of available space.</p>
*
* <p>Note that this is merely a hint; the underlying implementation
* may choose to ignore this setting under some circumstances.</p>
*
* @param titleOptional true if the title only presents optional information.
*/
public void setTitleOptionalHint(boolean titleOptional) {
mTitleOptionalHint = titleOptional;
}
/**
* @return true if this action mode has been given a hint to consider the
* title/subtitle display to be optional.
*
* @see #setTitleOptionalHint(boolean)
* @see #isTitleOptional()
*/
public boolean getTitleOptionalHint() {
return mTitleOptionalHint;
}
/**
* @return true if this action mode considers the title and subtitle fields
* as optional. Optional titles may not be displayed to the user.
*/
public boolean isTitleOptional() {
return false;
}
/**
* Set a custom view for this action mode. The custom view will take the place of
* the title and subtitle. Useful for things like search boxes.
*
* @param view Custom view to use in place of the title/subtitle.
*
* @see #setTitle(CharSequence)
* @see #setSubtitle(CharSequence)
*/
public abstract void setCustomView(View view);
/**
* Set a type for this action mode. This will affect how the system renders the action mode if
* it has to.
*
* @param type One of {@link #TYPE_PRIMARY} or {@link #TYPE_FLOATING}.
*/
public void setType(int type) {
mType = type;
}
/**
* Returns the type for this action mode.
*
* @return One of {@link #TYPE_PRIMARY} or {@link #TYPE_FLOATING}.
*/
public int getType() {
return mType;
}
/**
* Invalidate the action mode and refresh menu content. The mode's
* {@link ActionMode.Callback} will have its
* {@link Callback#onPrepareActionMode(ActionMode, Menu)} method called.
* If it returns true the menu will be scanned for updated content and any relevant changes
* will be reflected to the user.
*/
public abstract void invalidate();
/**
* Invalidate the content rect associated to this ActionMode. This only makes sense for
* action modes that support dynamic positioning on the screen, and provides a more efficient
* way to reposition it without invalidating the whole action mode.
*
* @see Callback2#onGetContentRect(ActionMode, View, Rect) .
*/
public void invalidateContentRect() {}
/**
* Hide the action mode view from obstructing the content below for a short duration.
* This only makes sense for action modes that support dynamic positioning on the screen.
* If this method is called again before the hide duration expires, the later hide call will
* cancel the former and then take effect.
* NOTE that there is an internal limit to how long the mode can be hidden for. It's typically
* about a few seconds.
*
* @param duration The number of milliseconds to hide for.
* @see #DEFAULT_HIDE_DURATION
*/
public void hide(long duration) {}
/**
* Finish and close this action mode. The action mode's {@link ActionMode.Callback} will
* have its {@link Callback#onDestroyActionMode(ActionMode)} method called.
*/
public abstract void finish();
/**
* Returns the menu of actions that this action mode presents.
* @return The action mode's menu.
*/
public abstract Menu getMenu();
/**
* Returns the current title of this action mode.
* @return Title text
*/
public abstract CharSequence getTitle();
/**
* Returns the current subtitle of this action mode.
* @return Subtitle text
*/
public abstract CharSequence getSubtitle();
/**
* Returns the current custom view for this action mode.
* @return The current custom view
*/
public abstract View getCustomView();
/**
* Returns a {@link MenuInflater} with the ActionMode's context.
*/
public abstract MenuInflater getMenuInflater();
/**
* Called when the window containing the view that started this action mode gains or loses
* focus.
*
* @param hasWindowFocus True if the window containing the view that started this action mode
* now has focus, false otherwise.
*
*/
public void onWindowFocusChanged(boolean hasWindowFocus) {}
/**
* Returns whether the UI presenting this action mode can take focus or not.
* This is used by internal components within the framework that would otherwise
* present an action mode UI that requires focus, such as an EditText as a custom view.
*
* @return true if the UI used to show this action mode can take focus
* @hide Internal use only
*/
public boolean isUiFocusable() {
return true;
}
/**
* Callback interface for action modes. Supplied to
* {@link View#startActionMode(Callback)}, a Callback
* configures and handles events raised by a user's interaction with an action mode.
*
* <p>An action mode's lifecycle is as follows:
* <ul>
* <li>{@link Callback#onCreateActionMode(ActionMode, Menu)} once on initial
* creation</li>
* <li>{@link Callback#onPrepareActionMode(ActionMode, Menu)} after creation
* and any time the {@link ActionMode} is invalidated</li>
* <li>{@link Callback#onActionItemClicked(ActionMode, MenuItem)} any time a
* contextual action button is clicked</li>
* <li>{@link Callback#onDestroyActionMode(ActionMode)} when the action mode
* is closed</li>
* </ul>
*/
public interface Callback {
/**
* Called when action mode is first created. The menu supplied will be used to
* generate action buttons for the action mode.
*
* @param mode ActionMode being created
* @param menu Menu used to populate action buttons
* @return true if the action mode should be created, false if entering this
* mode should be aborted.
*/
public boolean onCreateActionMode(ActionMode mode, Menu menu);
/**
* Called to refresh an action mode's action menu whenever it is invalidated.
*
* @param mode ActionMode being prepared
* @param menu Menu used to populate action buttons
* @return true if the menu or action mode was updated, false otherwise.
*/
public boolean onPrepareActionMode(ActionMode mode, Menu menu);
/**
* Called to report a user click on an action button.
*
* @param mode The current ActionMode
* @param item The item that was clicked
* @return true if this callback handled the event, false if the standard MenuItem
* invocation should continue.
*/
public boolean onActionItemClicked(ActionMode mode, MenuItem item);
/**
* Called when an action mode is about to be exited and destroyed.
*
* @param mode The current ActionMode being destroyed
*/
public void onDestroyActionMode(ActionMode mode);
}
/**
* Extension of {@link ActionMode.Callback} to provide content rect information. This is
* required for ActionModes with dynamic positioning such as the ones with type
* {@link ActionMode#TYPE_FLOATING} to ensure the positioning doesn't obscure app content. If
* an app fails to provide a subclass of this class, a default implementation will be used.
*/
public static abstract class Callback2 implements ActionMode.Callback {
/**
* Called when an ActionMode needs to be positioned on screen, potentially occluding view
* content. Note this may be called on a per-frame basis.
*
* @param mode The ActionMode that requires positioning.
* @param view The View that originated the ActionMode, in whose coordinates the Rect should
* be provided.
* @param outRect The Rect to be populated with the content position. Use this to specify
* where the content in your app lives within the given view. This will be used
* to avoid occluding the given content Rect with the created ActionMode.
*/
public void onGetContentRect(ActionMode mode, View view, Rect outRect) {
if (view != null) {
outRect.set(0, 0, view.getWidth(), view.getHeight());
} else {
outRect.set(0, 0, 0, 0);
}
}
}
}

View File

@@ -0,0 +1,12 @@
package android.view;
import android.content.Context;
import android.content.ContextWrapper;
public class ContextThemeWrapper extends ContextWrapper {
public ContextThemeWrapper(Context context, int themeResId) {
super(context);
}
}

View File

@@ -0,0 +1,5 @@
package android.view;
public class InflateException extends Exception {
}

View File

@@ -18,14 +18,14 @@ public class LayoutInflater {
public interface Factory2 {
}
private Factory2 factory2;
private Factory2 mFactory2;
public final LayoutInflater.Factory getFactory() {
return null;
}
public void setFactory2(Factory2 factory) {
this.factory2 = factory;
this.mFactory2 = factory;
}
public static LayoutInflater from(Context context) {
@@ -215,13 +215,51 @@ public class LayoutInflater {
}
private void parseInclude(XmlPullParser parser, View parent, AttributeSet attrs) throws Exception {
int layout = attrs.getAttributeResourceValue(null, "layout", 0);
View view = inflate(layout, (ViewGroup)parent, true);
if (view == null)
return;
int type;
int id = attrs.getAttributeResourceValue("http://schemas.android.com/apk/res/android", "id", 0);
if (id != 0)
view.setId(id);
int layout = attrs.getAttributeResourceValue(null, "layout", 0);
final XmlResourceParser childParser = Context.this_application.getResources().getLayout(layout);
final AttributeSet childAttrs = Xml.asAttributeSet(childParser);
while ((type = childParser.next()) != XmlPullParser.START_TAG &&
type != XmlPullParser.END_DOCUMENT) {
// Empty.
}
if (type != XmlPullParser.START_TAG) {
throw new Exception(childParser.getPositionDescription() + ": No start tag found!");
}
final String childName = childParser.getName();
if ("merge".equals(childName)) {
// The <merge> tag doesn't support android:theme, so
// nothing special to do here.
rInflate(childParser, parent, childAttrs, false);
} else {
final View view = createViewFromTag(parent, childName, childAttrs);
final ViewGroup group = (ViewGroup)parent;
ViewGroup.LayoutParams params = null;
try {
params = group.generateLayoutParams(attrs);
} catch (RuntimeException e) {
// Ignore, just fail over to child attrs.
}
if (params == null) {
params = group.generateLayoutParams(childAttrs);
}
view.setLayoutParams(params);
// Inflate all children.
rInflate(childParser, view, childAttrs, true);
int id = attrs.getAttributeResourceValue("http://schemas.android.com/apk/res/android", "id", 0);
if (id != 0)
view.setId(id);
group.addView(view);
}
}
public LayoutInflater cloneInContext(Context context) {
return this;
}
}

View File

@@ -1,4 +1,12 @@
package android.view;
public interface Menu {
public MenuItem add(int groupId, int itemId, int order, CharSequence title);
public MenuItem add(int groupId, int itemId,int order, int titleRes);
public MenuItem findItem(int id);
public void clear();
}

View File

@@ -0,0 +1,11 @@
package android.view;
import android.content.Context;
public class MenuInflater {
public MenuInflater(Context context) {}
public void inflate(int menuRes, Menu menu) {}
}

View File

@@ -0,0 +1,11 @@
package android.view;
public interface MenuItem {
public interface OnMenuItemClickListener {}
public MenuItem setIcon(int iconRes);
public MenuItem setVisible(boolean visible);
}

View File

@@ -0,0 +1,5 @@
package android.view;
public interface SubMenu extends Menu {
}

View File

@@ -4,10 +4,16 @@ import android.content.Context;
import android.content.res.Resources;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.os.IBinder;
import android.os.Looper;
import android.util.AttributeSet;
import android.util.LayoutDirection;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
public class View extends Object {
@@ -590,6 +596,22 @@ public class View extends Object {
// boolean onKey(View v, int keyCode, KeyEvent event);
}
public interface OnLongClickListener {
// TODO
}
public interface OnHoverListener {
// TODO
}
public interface OnApplyWindowInsetsListener {
// TODO
}
public interface OnLayoutChangeListener {
// TODO
}
public interface OnCreateContextMenuListener {
/**
* Called when the context menu for this view is being built. It is not
@@ -747,6 +769,7 @@ public class View extends Object {
public AttributeSet attrs;
protected ViewGroup.LayoutParams layout_params;
private Context context;
private Map<Integer,Object> tags = new HashMap<>();
public long widget; // pointer
@@ -764,6 +787,10 @@ public class View extends Object {
}
}
public View(Context context, AttributeSet attrs, int defStyle) {
this(context, attrs);
}
public View findViewById(int id) {
/* TODO: this should probably only search among children, but the id is surely unique anyway? :P */
return view_by_id.get(id);
@@ -836,6 +863,7 @@ public class View extends Object {
}
public void setId(int id) {
this.id = id;
view_by_id.put(id, this);
}
@@ -950,4 +978,90 @@ public class View extends Object {
public void refreshDrawableState() {
}
public void setDescendantFocusability(int value) {}
public void setAccessibilityDelegate(AccessibilityDelegate delegate) {}
public static class AccessibilityDelegate {}
public Drawable getBackground() {
return null;
}
public void setClickable(boolean clickable) {}
public void setEnabled(boolean enabled) {}
public CharSequence getContentDescription() {
return null;
}
public void setOnLongClickListener(OnLongClickListener listener) {}
public void setLongClickable(boolean longClickable) {}
public void setOnHoverListener(OnHoverListener listener) {}
public final void measure (int widthMeasureSpec, int heightMeasureSpec) {}
public final int getMeasuredWidth() {
return getWidth();
}
public final int getMeasuredHeight() {
return getHeight();
}
public void setBackgroundDrawable(Drawable backgroundDrawable) {}
public int getOverScrollMode() {return 0;}
public void setFitsSystemWindows(boolean fitsSystemWindows) {}
public void setWillNotDraw(boolean value) {}
public void setScrollContainer(boolean isScrollContainer) {}
public boolean removeCallbacks(Runnable action) {return false;}
public void requestLayout() {};
public void setOverScrollMode(int mode) {}
public int getId() {return id;}
public boolean postDelayed(Runnable action, long delayMillis) {
new Handler(Looper.getMainLooper()).postDelayed(action, delayMillis);
return true;
}
public boolean post(Runnable action) {
new Handler(Looper.getMainLooper()).post(action);
return true;
}
public void setSaveFromParentEnabled(boolean enabled) {}
public void setTag(int key, Object tag) {
tags.put(key, tag);
}
public Object getTag(int key) {
return tags.get(key);
}
public void addOnLayoutChangeListener(OnLayoutChangeListener listener) {}
public boolean isSelected() {return false;}
public void sendAccessibilityEvent(int eventType) {}
public void setMinimumHeight(int minHeight) {}
public void setMinimumWidth(int minWidth) {}
public void setActivated (boolean activated) {}
public int getVisibility() {return View.VISIBLE;}
public boolean isInEditMode() {return false;}
}

View File

@@ -0,0 +1,34 @@
package android.view;
import android.content.Context;
public class ViewConfiguration {
public static ViewConfiguration get(Context context) {
return new ViewConfiguration();
}
public int getScaledTouchSlop() {
return 0;
}
public int getScaledMaximumFlingVelocity() {
return 0;
}
public int getScaledMinimumFlingVelocity() {
return 0;
}
public static int getTapTimeout() {
return 0;
}
public static int getLongPressTimeout() {
return 0;
}
public int getScaledPagingTouchSlop(){
return 0;
}
}

View File

@@ -1,6 +1,9 @@
package android.view;
import android.R;
import android.animation.LayoutTransition;
import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import java.util.ArrayList;
@@ -89,6 +92,72 @@ public class ViewGroup extends View implements ViewParent, ViewManager {
return true;
}
public LayoutTransition getLayoutTransition() {return null;}
public static int getChildMeasureSpec(int spec, int padding, int childDimension) {
int specMode = MeasureSpec.getMode(spec);
int specSize = MeasureSpec.getSize(spec);
int size = Math.max(0, specSize - padding);
int resultSize = 0;
int resultMode = 0;
switch (specMode) {
// Parent has imposed an exact size on us
case MeasureSpec.EXACTLY:
if (childDimension >= 0) {
resultSize = childDimension;
resultMode = MeasureSpec.EXACTLY;
} else if (childDimension == LayoutParams.MATCH_PARENT) {
// Child wants to be our size. So be it.
resultSize = size;
resultMode = MeasureSpec.EXACTLY;
} else if (childDimension == LayoutParams.WRAP_CONTENT) {
// Child wants to determine its own size. It can't be
// bigger than us.
resultSize = size;
resultMode = MeasureSpec.AT_MOST;
}
break;
// Parent has imposed a maximum size on us
case MeasureSpec.AT_MOST:
if (childDimension >= 0) {
// Child wants a specific size... so be it
resultSize = childDimension;
resultMode = MeasureSpec.EXACTLY;
} else if (childDimension == LayoutParams.MATCH_PARENT) {
// Child wants to be our size, but our size is not fixed.
// Constrain child to not be bigger than us.
resultSize = size;
resultMode = MeasureSpec.AT_MOST;
} else if (childDimension == LayoutParams.WRAP_CONTENT) {
// Child wants to determine its own size. It can't be
// bigger than us.
resultSize = size;
resultMode = MeasureSpec.AT_MOST;
}
break;
// Parent asked to see how big we want to be
case MeasureSpec.UNSPECIFIED:
if (childDimension >= 0) {
// Child wants a specific size... let them have it
resultSize = childDimension;
resultMode = MeasureSpec.EXACTLY;
} else if (childDimension == LayoutParams.MATCH_PARENT) {
// Child wants to be our size... find out how big it should
// be
resultSize = 0; //View.sUseZeroUnspecifiedMeasureSpec ? 0 : size;
resultMode = MeasureSpec.UNSPECIFIED;
} else if (childDimension == LayoutParams.WRAP_CONTENT) {
// Child wants to determine its own size.... find out how
// big it should be
resultSize = 0; //View.sUseZeroUnspecifiedMeasureSpec ? 0 : size;
resultMode = MeasureSpec.UNSPECIFIED;
}
break;
}
//noinspection ResourceType
return MeasureSpec.makeMeasureSpec(resultSize, resultMode);
}
public static class LayoutParams {
public static final int FILL_PARENT = -1;
public static final int MATCH_PARENT = -1;
@@ -115,9 +184,11 @@ public class ViewGroup extends View implements ViewParent, ViewManager {
}
public LayoutParams(Context context, AttributeSet attrs) {
this.width = attrs.getAttributeIntValue("http://schemas.android.com/apk/res/android", "layout_width", 0);
this.height = attrs.getAttributeIntValue("http://schemas.android.com/apk/res/android", "layout_height", 0);
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ViewGroup_Layout);
width = a.getLayoutDimension(R.styleable.ViewGroup_Layout_layout_width, "layout_width");
height = a.getLayoutDimension(R.styleable.ViewGroup_Layout_layout_height, "layout_height");
this.gravity = attrs.getAttributeIntValue("http://schemas.android.com/apk/res/android", "layout_gravity", -1);
a.recycle();
}
public void setMargins(int left, int top, int right, int bottom) {}
@@ -129,6 +200,10 @@ public class ViewGroup extends View implements ViewParent, ViewManager {
}
public static class MarginLayoutParams extends ViewGroup.LayoutParams {
public int leftMargin;
public int topMargin;
public int rightMargin;
public int bottomMargin;
public MarginLayoutParams() {
super();

View File

@@ -1,8 +1,22 @@
package android.view;
public class Window {
public static interface Callback {}
public static class fixme_callback implements Callback {}
public static interface Callback {
public void onContentChanged();
public abstract boolean onCreatePanelMenu(int featureId, Menu menu);
}
public static class fixme_callback implements Callback {
@Override
public void onContentChanged() {
}
@Override
public boolean onCreatePanelMenu(int featureId, Menu menu) {
return false;
}
}
// FIXME private
public long native_window;
@@ -43,4 +57,12 @@ public class Window {
public boolean requestFeature(int featureId) {
return false;
}
public View findViewById(int id) {
return View.view_by_id.get(id);
}
public View peekDecorView() {
return null;
}
}

View File

@@ -0,0 +1,5 @@
package android.view.accessibility;
public class AccessibilityManager {
}

View File

@@ -0,0 +1,5 @@
package android.view.animation;
public class DecelerateInterpolator implements Interpolator{
}

View File

@@ -26,7 +26,6 @@ import android.text.TextUtils;
import android.util.Log;
import android.view.View;
class InputMethodManager {}
class Editable {}
class ComposingText {

View File

@@ -0,0 +1,5 @@
package android.view.inputmethod;
public class InputMethodManager {
}

View File

@@ -0,0 +1,5 @@
package android.view.textservice;
public class TextServicesManager {
}