summaryrefslogtreecommitdiffstats
path: root/core/java/android
diff options
context:
space:
mode:
Diffstat (limited to 'core/java/android')
-rw-r--r--core/java/android/content/ComponentName.java52
-rw-r--r--core/java/android/content/pm/PackageParser.java80
-rw-r--r--core/java/android/content/pm/ResolveInfo.java22
-rw-r--r--core/java/android/printservice/PrintService.java40
-rw-r--r--core/java/android/transition/TextChange.java50
-rw-r--r--core/java/android/transition/Transition.java6
-rw-r--r--core/java/android/widget/AbsListView.java15
-rw-r--r--core/java/android/widget/FastScroller.java2
-rw-r--r--core/java/android/widget/ListView.java2
-rw-r--r--core/java/android/widget/PopupMenu.java13
10 files changed, 232 insertions, 50 deletions
diff --git a/core/java/android/content/ComponentName.java b/core/java/android/content/ComponentName.java
index 7ca0f01..547a2c3 100644
--- a/core/java/android/content/ComponentName.java
+++ b/core/java/android/content/ComponentName.java
@@ -18,6 +18,8 @@ package android.content;
import android.os.Parcel;
import android.os.Parcelable;
+
+import java.io.PrintWriter;
import java.lang.Comparable;
/**
@@ -109,6 +111,32 @@ public final class ComponentName implements Parcelable, Cloneable, Comparable<Co
return mClass;
}
+ private static void appendShortClassName(StringBuilder sb, String packageName,
+ String className) {
+ if (className.startsWith(packageName)) {
+ int PN = packageName.length();
+ int CN = className.length();
+ if (CN > PN && className.charAt(PN) == '.') {
+ sb.append(className, PN, CN);
+ return;
+ }
+ }
+ sb.append(className);
+ }
+
+ private static void printShortClassName(PrintWriter pw, String packageName,
+ String className) {
+ if (className.startsWith(packageName)) {
+ int PN = packageName.length();
+ int CN = className.length();
+ if (CN > PN && className.charAt(PN) == '.') {
+ pw.write(className, PN, CN-PN);
+ return;
+ }
+ }
+ pw.print(className);
+ }
+
/**
* Return a String that unambiguously describes both the package and
* class names contained in the ComponentName. You can later recover
@@ -137,9 +165,29 @@ public final class ComponentName implements Parcelable, Cloneable, Comparable<Co
* @see #unflattenFromString(String)
*/
public String flattenToShortString() {
- return mPackage + "/" + getShortClassName();
+ StringBuilder sb = new StringBuilder(mPackage.length() + mClass.length());
+ appendShortString(sb, mPackage, mClass);
+ return sb.toString();
}
-
+
+ /** @hide */
+ public void appendShortString(StringBuilder sb) {
+ appendShortString(sb, mPackage, mClass);
+ }
+
+ /** @hide */
+ public static void appendShortString(StringBuilder sb, String packageName, String className) {
+ sb.append(packageName).append('/');
+ appendShortClassName(sb, packageName, className);
+ }
+
+ /** @hide */
+ public static void printShortString(PrintWriter pw, String packageName, String className) {
+ pw.print(packageName);
+ pw.print('/');
+ printShortClassName(pw, packageName, className);
+ }
+
/**
* Recover a ComponentName from a String that was previously created with
* {@link #flattenToString()}. It splits the string at the first '/',
diff --git a/core/java/android/content/pm/PackageParser.java b/core/java/android/content/pm/PackageParser.java
index 2e25177..b489ee9 100644
--- a/core/java/android/content/pm/PackageParser.java
+++ b/core/java/android/content/pm/PackageParser.java
@@ -39,6 +39,7 @@ import java.io.BufferedInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
+import java.io.PrintWriter;
import java.lang.ref.WeakReference;
import java.security.KeyFactory;
import java.security.NoSuchAlgorithmException;
@@ -3707,18 +3708,15 @@ public class PackageParser {
}
return componentName;
}
-
- public String getComponentShortName() {
- if (componentShortName != null) {
- return componentShortName;
- }
- ComponentName component = getComponentName();
- if (component != null) {
- componentShortName = component.flattenToShortString();
- }
- return componentShortName;
+
+ public void appendComponentShortName(StringBuilder sb) {
+ ComponentName.appendShortString(sb, owner.applicationInfo.packageName, className);
}
-
+
+ public void printComponentShortName(PrintWriter pw) {
+ ComponentName.printShortString(pw, owner.applicationInfo.packageName, className);
+ }
+
public void setPackageName(String packageName) {
componentName = null;
componentShortName = null;
@@ -3917,9 +3915,13 @@ public class PackageParser {
}
public String toString() {
- return "Activity{"
- + Integer.toHexString(System.identityHashCode(this))
- + " " + getComponentShortName() + "}";
+ StringBuilder sb = new StringBuilder(128);
+ sb.append("Activity{");
+ sb.append(Integer.toHexString(System.identityHashCode(this)));
+ sb.append(' ');
+ appendComponentShortName(sb);
+ sb.append('}');
+ return sb.toString();
}
}
@@ -3954,9 +3956,13 @@ public class PackageParser {
}
public String toString() {
- return "Service{"
- + Integer.toHexString(System.identityHashCode(this))
- + " " + getComponentShortName() + "}";
+ StringBuilder sb = new StringBuilder(128);
+ sb.append("Service{");
+ sb.append(Integer.toHexString(System.identityHashCode(this)));
+ sb.append(' ');
+ appendComponentShortName(sb);
+ sb.append('}');
+ return sb.toString();
}
}
@@ -3999,9 +4005,13 @@ public class PackageParser {
}
public String toString() {
- return "Provider{"
- + Integer.toHexString(System.identityHashCode(this))
- + " " + info.name + "}";
+ StringBuilder sb = new StringBuilder(128);
+ sb.append("Provider{");
+ sb.append(Integer.toHexString(System.identityHashCode(this)));
+ sb.append(' ');
+ appendComponentShortName(sb);
+ sb.append('}');
+ return sb.toString();
}
}
@@ -4040,9 +4050,13 @@ public class PackageParser {
}
public String toString() {
- return "Instrumentation{"
- + Integer.toHexString(System.identityHashCode(this))
- + " " + getComponentShortName() + "}";
+ StringBuilder sb = new StringBuilder(128);
+ sb.append("Instrumentation{");
+ sb.append(Integer.toHexString(System.identityHashCode(this)));
+ sb.append(' ');
+ appendComponentShortName(sb);
+ sb.append('}');
+ return sb.toString();
}
}
@@ -4074,9 +4088,13 @@ public class PackageParser {
}
public String toString() {
- return "ActivityIntentInfo{"
- + Integer.toHexString(System.identityHashCode(this))
- + " " + activity.info.name + "}";
+ StringBuilder sb = new StringBuilder(128);
+ sb.append("ActivityIntentInfo{");
+ sb.append(Integer.toHexString(System.identityHashCode(this)));
+ sb.append(' ');
+ activity.appendComponentShortName(sb);
+ sb.append('}');
+ return sb.toString();
}
}
@@ -4088,9 +4106,13 @@ public class PackageParser {
}
public String toString() {
- return "ServiceIntentInfo{"
- + Integer.toHexString(System.identityHashCode(this))
- + " " + service.info.name + "}";
+ StringBuilder sb = new StringBuilder(128);
+ sb.append("ServiceIntentInfo{");
+ sb.append(Integer.toHexString(System.identityHashCode(this)));
+ sb.append(' ');
+ service.appendComponentShortName(sb);
+ sb.append('}');
+ return sb.toString();
}
}
diff --git a/core/java/android/content/pm/ResolveInfo.java b/core/java/android/content/pm/ResolveInfo.java
index de8e256..e360e40 100644
--- a/core/java/android/content/pm/ResolveInfo.java
+++ b/core/java/android/content/pm/ResolveInfo.java
@@ -16,6 +16,7 @@
package android.content.pm;
+import android.content.ComponentName;
import android.content.IntentFilter;
import android.graphics.drawable.Drawable;
import android.os.Parcel;
@@ -247,10 +248,23 @@ public class ResolveInfo implements Parcelable {
public String toString() {
ComponentInfo ci = activityInfo != null ? activityInfo : serviceInfo;
- return "ResolveInfo{"
- + Integer.toHexString(System.identityHashCode(this))
- + " " + ci.name + " p=" + priority + " o="
- + preferredOrder + " m=0x" + Integer.toHexString(match) + "}";
+ StringBuilder sb = new StringBuilder(128);
+ sb.append("ResolveInfo{");
+ sb.append(Integer.toHexString(System.identityHashCode(this)));
+ sb.append(' ');
+ ComponentName.appendShortString(sb, ci.packageName, ci.name);
+ if (priority != 0) {
+ sb.append(" p=");
+ sb.append(priority);
+ }
+ if (preferredOrder != 0) {
+ sb.append(" o=");
+ sb.append(preferredOrder);
+ }
+ sb.append(" m=0x");
+ sb.append(Integer.toHexString(match));
+ sb.append('}');
+ return sb.toString();
}
public int describeContents() {
diff --git a/core/java/android/printservice/PrintService.java b/core/java/android/printservice/PrintService.java
index e5ebf77..e73a53b 100644
--- a/core/java/android/printservice/PrintService.java
+++ b/core/java/android/printservice/PrintService.java
@@ -383,6 +383,10 @@ public abstract class PrintService extends Service {
final int action = message.what;
switch (action) {
case MSG_CREATE_PRINTER_DISCOVERY_SESSION: {
+ if (DEBUG) {
+ Log.i(LOG_TAG, "MSG_CREATE_PRINTER_DISCOVERY_SESSION "
+ + getPackageName());
+ }
PrinterDiscoverySession session = onCreatePrinterDiscoverySession();
if (session == null) {
throw new NullPointerException("session cannot be null");
@@ -396,6 +400,10 @@ public abstract class PrintService extends Service {
} break;
case MSG_DESTROY_PRINTER_DISCOVERY_SESSION: {
+ if (DEBUG) {
+ Log.i(LOG_TAG, "MSG_DESTROY_PRINTER_DISCOVERY_SESSION "
+ + getPackageName());
+ }
if (mDiscoverySession != null) {
mDiscoverySession.destroy();
mDiscoverySession = null;
@@ -403,6 +411,10 @@ public abstract class PrintService extends Service {
} break;
case MSG_START_PRINTER_DISCOVERY: {
+ if (DEBUG) {
+ Log.i(LOG_TAG, "MSG_START_PRINTER_DISCOVERY "
+ + getPackageName());
+ }
if (mDiscoverySession != null) {
List<PrinterId> priorityList = (ArrayList<PrinterId>) message.obj;
mDiscoverySession.startPrinterDiscovery(priorityList);
@@ -410,12 +422,20 @@ public abstract class PrintService extends Service {
} break;
case MSG_STOP_PRINTER_DISCOVERY: {
+ if (DEBUG) {
+ Log.i(LOG_TAG, "MSG_STOP_PRINTER_DISCOVERY "
+ + getPackageName());
+ }
if (mDiscoverySession != null) {
mDiscoverySession.stopPrinterDiscovery();
}
} break;
case MSG_VALIDATE_PRINTERS: {
+ if (DEBUG) {
+ Log.i(LOG_TAG, "MSG_VALIDATE_PRINTERS "
+ + getPackageName());
+ }
if (mDiscoverySession != null) {
List<PrinterId> printerIds = (List<PrinterId>) message.obj;
mDiscoverySession.validatePrinters(printerIds);
@@ -423,6 +443,10 @@ public abstract class PrintService extends Service {
} break;
case MSG_START_PRINTER_STATE_TRACKING: {
+ if (DEBUG) {
+ Log.i(LOG_TAG, "MSG_START_PRINTER_STATE_TRACKING "
+ + getPackageName());
+ }
if (mDiscoverySession != null) {
PrinterId printerId = (PrinterId) message.obj;
mDiscoverySession.startPrinterStateTracking(printerId);
@@ -430,6 +454,10 @@ public abstract class PrintService extends Service {
} break;
case MSG_STOP_PRINTER_STATE_TRACKING: {
+ if (DEBUG) {
+ Log.i(LOG_TAG, "MSG_STOP_PRINTER_STATE_TRACKING "
+ + getPackageName());
+ }
if (mDiscoverySession != null) {
PrinterId printerId = (PrinterId) message.obj;
mDiscoverySession.stopPrinterStateTracking(printerId);
@@ -437,11 +465,19 @@ public abstract class PrintService extends Service {
} break;
case MSG_ON_REQUEST_CANCEL_PRINTJOB: {
+ if (DEBUG) {
+ Log.i(LOG_TAG, "MSG_ON_REQUEST_CANCEL_PRINTJOB "
+ + getPackageName());
+ }
PrintJobInfo printJobInfo = (PrintJobInfo) message.obj;
onRequestCancelPrintJob(new PrintJob(printJobInfo, mClient));
} break;
case MSG_ON_PRINTJOB_QUEUED: {
+ if (DEBUG) {
+ Log.i(LOG_TAG, "MSG_ON_PRINTJOB_QUEUED "
+ + getPackageName());
+ }
PrintJobInfo printJobInfo = (PrintJobInfo) message.obj;
if (DEBUG) {
Log.i(LOG_TAG, "Queued: " + printJobInfo);
@@ -450,6 +486,10 @@ public abstract class PrintService extends Service {
} break;
case MSG_SET_CLEINT: {
+ if (DEBUG) {
+ Log.i(LOG_TAG, "MSG_SET_CLEINT "
+ + getPackageName());
+ }
mClient = (IPrintServiceClient) message.obj;
if (mClient != null) {
onConnected();
diff --git a/core/java/android/transition/TextChange.java b/core/java/android/transition/TextChange.java
index fa2f548..cf190a1 100644
--- a/core/java/android/transition/TextChange.java
+++ b/core/java/android/transition/TextChange.java
@@ -23,6 +23,7 @@ import android.animation.ValueAnimator;
import android.graphics.Color;
import android.util.Log;
import android.view.ViewGroup;
+import android.widget.EditText;
import android.widget.TextView;
import java.util.Map;
@@ -41,6 +42,10 @@ public class TextChange extends Transition {
private static final String LOG_TAG = "TextChange";
private static final String PROPNAME_TEXT = "android:textchange:text";
+ private static final String PROPNAME_TEXT_SELECTION_START =
+ "android:textchange:textSelectionStart";
+ private static final String PROPNAME_TEXT_SELECTION_END =
+ "android:textchange:textSelectionEnd";
private static final String PROPNAME_TEXT_COLOR = "android:textchange:textColor";
private int mChangeBehavior = CHANGE_BEHAVIOR_KEEP;
@@ -84,7 +89,9 @@ public class TextChange extends Transition {
public static final int CHANGE_BEHAVIOR_OUT_IN = 3;
private static final String[] sTransitionProperties = {
- PROPNAME_TEXT
+ PROPNAME_TEXT,
+ PROPNAME_TEXT_SELECTION_START,
+ PROPNAME_TEXT_SELECTION_END
};
/**
@@ -122,6 +129,12 @@ public class TextChange extends Transition {
if (transitionValues.view instanceof TextView) {
TextView textview = (TextView) transitionValues.view;
transitionValues.values.put(PROPNAME_TEXT, textview.getText());
+ if (textview instanceof EditText) {
+ transitionValues.values.put(PROPNAME_TEXT_SELECTION_START,
+ textview.getSelectionStart());
+ transitionValues.values.put(PROPNAME_TEXT_SELECTION_END,
+ textview.getSelectionEnd());
+ }
if (mChangeBehavior > CHANGE_BEHAVIOR_KEEP) {
transitionValues.values.put(PROPNAME_TEXT_COLOR, textview.getCurrentTextColor());
}
@@ -152,8 +165,24 @@ public class TextChange extends Transition {
(CharSequence) startVals.get(PROPNAME_TEXT) : "";
final CharSequence endText = endVals.get(PROPNAME_TEXT) != null ?
(CharSequence) endVals.get(PROPNAME_TEXT) : "";
+ final int startSelectionStart, startSelectionEnd, endSelectionStart, endSelectionEnd;
+ if (view instanceof EditText) {
+ startSelectionStart = startVals.get(PROPNAME_TEXT_SELECTION_START) != null ?
+ (Integer) startVals.get(PROPNAME_TEXT_SELECTION_START) : -1;
+ startSelectionEnd = startVals.get(PROPNAME_TEXT_SELECTION_END) != null ?
+ (Integer) startVals.get(PROPNAME_TEXT_SELECTION_END) : startSelectionStart;
+ endSelectionStart = endVals.get(PROPNAME_TEXT_SELECTION_START) != null ?
+ (Integer) endVals.get(PROPNAME_TEXT_SELECTION_START) : -1;
+ endSelectionEnd = endVals.get(PROPNAME_TEXT_SELECTION_END) != null ?
+ (Integer) endVals.get(PROPNAME_TEXT_SELECTION_END) : endSelectionStart;
+ } else {
+ startSelectionStart = startSelectionEnd = endSelectionStart = endSelectionEnd = -1;
+ }
if (!startText.equals(endText)) {
view.setText(startText);
+ if (view instanceof EditText) {
+ setSelection(((EditText) view), startSelectionStart, startSelectionEnd);
+ }
Animator anim;
if (mChangeBehavior == CHANGE_BEHAVIOR_KEEP) {
anim = ValueAnimator.ofFloat(0, 1);
@@ -163,6 +192,9 @@ public class TextChange extends Transition {
if (startText.equals(view.getText())) {
// Only set if it hasn't been changed since anim started
view.setText(endText);
+ if (view instanceof EditText) {
+ setSelection(((EditText) view), endSelectionStart, endSelectionEnd);
+ }
}
}
});
@@ -188,6 +220,10 @@ public class TextChange extends Transition {
if (startText.equals(view.getText())) {
// Only set if it hasn't been changed since anim started
view.setText(endText);
+ if (view instanceof EditText) {
+ setSelection(((EditText) view), endSelectionStart,
+ endSelectionEnd);
+ }
}
}
});
@@ -220,11 +256,17 @@ public class TextChange extends Transition {
@Override
public void onTransitionPause(Transition transition) {
view.setText(endText);
+ if (view instanceof EditText) {
+ setSelection(((EditText) view), endSelectionStart, endSelectionEnd);
+ }
}
@Override
public void onTransitionResume(Transition transition) {
view.setText(startText);
+ if (view instanceof EditText) {
+ setSelection(((EditText) view), startSelectionStart, startSelectionEnd);
+ }
}
};
addListener(transitionListener);
@@ -235,4 +277,10 @@ public class TextChange extends Transition {
}
return null;
}
+
+ private void setSelection(EditText editText, int start, int end) {
+ if (start >= 0 && end >= 0) {
+ editText.setSelection(start, end);
+ }
+ }
}
diff --git a/core/java/android/transition/Transition.java b/core/java/android/transition/Transition.java
index 4a99153..a552fd4 100644
--- a/core/java/android/transition/Transition.java
+++ b/core/java/android/transition/Transition.java
@@ -1094,7 +1094,11 @@ public abstract class Transition implements Cloneable {
}
TransitionValues values = new TransitionValues();
values.view = view;
- captureStartValues(values);
+ if (start) {
+ captureStartValues(values);
+ } else {
+ captureEndValues(values);
+ }
if (start) {
if (!isListViewItem) {
mStartValues.viewValues.put(view, values);
diff --git a/core/java/android/widget/AbsListView.java b/core/java/android/widget/AbsListView.java
index 7378d74..41a8fd1 100644
--- a/core/java/android/widget/AbsListView.java
+++ b/core/java/android/widget/AbsListView.java
@@ -675,11 +675,6 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
private int mLastAccessibilityScrollEventToIndex;
/**
- * Track if we are currently attached to a window.
- */
- boolean mIsAttached;
-
- /**
* Track the item count from the last time we handled a data change.
*/
private int mLastHandledItemCount;
@@ -1904,7 +1899,7 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
protected void onFocusChanged(boolean gainFocus, int direction, Rect previouslyFocusedRect) {
super.onFocusChanged(gainFocus, direction, previouslyFocusedRect);
if (gainFocus && mSelectedPosition < 0 && !isInTouchMode()) {
- if (!mIsAttached && mAdapter != null) {
+ if (!isAttachedToWindow() && mAdapter != null) {
// Data may have changed while we were detached and it's valid
// to change focus while detached. Refresh so we don't die.
mDataChanged = true;
@@ -2715,7 +2710,6 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
mOldItemCount = mItemCount;
mItemCount = mAdapter.getCount();
}
- mIsAttached = true;
}
@Override
@@ -2770,7 +2764,6 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
removeCallbacks(mTouchModeReset);
mTouchModeReset.run();
}
- mIsAttached = false;
}
@Override
@@ -3397,7 +3390,7 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
mPositionScroller.stop();
}
- if (!mIsAttached) {
+ if (!isAttachedToWindow()) {
// Something isn't right.
// Since we rely on being attached to get data set change notifications,
// don't risk doing anything where we might try to resync and find things
@@ -3636,7 +3629,7 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
mTouchMode = TOUCH_MODE_REST;
child.setPressed(false);
setPressed(false);
- if (!mDataChanged) {
+ if (!mDataChanged && isAttachedToWindow()) {
performClick.run();
}
}
@@ -3911,7 +3904,7 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
mPositionScroller.stop();
}
- if (!mIsAttached) {
+ if (!isAttachedToWindow()) {
// Something isn't right.
// Since we rely on being attached to get data set change notifications,
// don't risk doing anything where we might try to resync and find things
diff --git a/core/java/android/widget/FastScroller.java b/core/java/android/widget/FastScroller.java
index 006b96e..e2f6d7d 100644
--- a/core/java/android/widget/FastScroller.java
+++ b/core/java/android/widget/FastScroller.java
@@ -210,7 +210,7 @@ class FastScroller {
private final Runnable mDeferStartDrag = new Runnable() {
@Override
public void run() {
- if (mList.mIsAttached) {
+ if (mList.isAttachedToWindow()) {
beginDrag();
final float pos = getPosFromMotionEvent(mInitialTouchY);
diff --git a/core/java/android/widget/ListView.java b/core/java/android/widget/ListView.java
index b239fbd..4b00f90 100644
--- a/core/java/android/widget/ListView.java
+++ b/core/java/android/widget/ListView.java
@@ -2122,7 +2122,7 @@ public class ListView extends AbsListView {
}
private boolean commonKey(int keyCode, int count, KeyEvent event) {
- if (mAdapter == null || !mIsAttached) {
+ if (mAdapter == null || !isAttachedToWindow()) {
return false;
}
diff --git a/core/java/android/widget/PopupMenu.java b/core/java/android/widget/PopupMenu.java
index 603db70..9ac6a59 100644
--- a/core/java/android/widget/PopupMenu.java
+++ b/core/java/android/widget/PopupMenu.java
@@ -93,7 +93,20 @@ public class PopupMenu implements MenuBuilder.Callback, MenuPresenter.Callback {
if (mDragListener == null) {
mDragListener = new ForwardingListener(mAnchor) {
@Override
+ protected boolean onForwardingStarted() {
+ show();
+ return true;
+ }
+
+ @Override
+ protected boolean onForwardingStopped() {
+ dismiss();
+ return true;
+ }
+
+ @Override
public ListPopupWindow getPopup() {
+ // This will be null until show() is called.
return mPopup.getPopup();
}
};