diff options
Diffstat (limited to 'core/java/android')
| -rw-r--r-- | core/java/android/app/TaskStackBuilder.java | 2 | ||||
| -rw-r--r-- | core/java/android/text/format/DateFormat.java | 63 | ||||
| -rwxr-xr-x | core/java/android/util/PropertyValueModel.java | 143 | ||||
| -rwxr-xr-x | core/java/android/util/ValueModel.java | 74 | ||||
| -rw-r--r-- | core/java/android/widget/CheckBox.java | 23 | ||||
| -rw-r--r-- | core/java/android/widget/EditText.java | 23 | ||||
| -rw-r--r-- | core/java/android/widget/Editor.java | 14 | ||||
| -rw-r--r-- | core/java/android/widget/SeekBar.java | 20 | ||||
| -rwxr-xr-x | core/java/android/widget/ValueEditor.java | 53 |
9 files changed, 50 insertions, 365 deletions
diff --git a/core/java/android/app/TaskStackBuilder.java b/core/java/android/app/TaskStackBuilder.java index 9c83362..63987f1 100644 --- a/core/java/android/app/TaskStackBuilder.java +++ b/core/java/android/app/TaskStackBuilder.java @@ -162,7 +162,7 @@ public class TaskStackBuilder { ActivityInfo info = pm.getActivityInfo(sourceActivityName, 0); String parentActivity = info.parentActivityName; while (parentActivity != null) { - final ComponentName target = new ComponentName(mSourceContext, parentActivity); + final ComponentName target = new ComponentName(info.packageName, parentActivity); info = pm.getActivityInfo(target, 0); parentActivity = info.parentActivityName; final Intent parent = parentActivity == null && insertAt == 0 diff --git a/core/java/android/text/format/DateFormat.java b/core/java/android/text/format/DateFormat.java index 524f941..c36273e 100644 --- a/core/java/android/text/format/DateFormat.java +++ b/core/java/android/text/format/DateFormat.java @@ -35,10 +35,18 @@ import java.text.SimpleDateFormat; Utility class for producing strings with formatted date/time. <p> - This class takes as inputs a format string and a representation of a date/time. - The format string controls how the output is generated. + Most callers should avoid supplying their own format strings to this + class' {@code format} methods and rely on the correctly localized ones + supplied by the system. This class' factory methods return + appropriately-localized {@link java.text.DateFormat} instances, suitable + for both formatting and parsing dates. For the canonical documentation + of format strings, see {@link java.text.SimpleDateFormat}. </p> <p> + The format methods in this class takes as inputs a format string and a representation of a date/time. + The format string controls how the output is generated. + This class only supports a subset of the full Unicode specification. + Use {@link java.text.SimpleDateFormat} if you need more. Formatting characters may be repeated in order to get more detailed representations of that field. For instance, the format character 'M' is used to represent the month. Depending on how many times that character is repeated @@ -152,7 +160,8 @@ public class DateFormat { public static final char MINUTE = 'm'; /** - This designator indicates the month of the year + This designator indicates the month of the year. See also + {@link #STANDALONE_MONTH}. Examples for September: M -> 9 @@ -163,6 +172,14 @@ public class DateFormat { public static final char MONTH = 'M'; /** + This designator indicates the standalone month of the year, + necessary in some format strings in some languages. For + example, Russian distinguishes between the "June" in + "June" and that in "June 2010". + */ + public static final char STANDALONE_MONTH = 'L'; + + /** This designator indicates the seconds of the minute. Examples for 7 seconds past the minute: @@ -374,7 +391,7 @@ public class DateFormat { index++; } - if (!foundMonth && (c == MONTH)) { + if (!foundMonth && (c == MONTH || c == STANDALONE_MONTH)) { foundMonth = true; order[index] = MONTH; index++; @@ -494,9 +511,10 @@ public class DateFormat { break; case MONTH: - replacement = getMonthString(inDate, count); + case STANDALONE_MONTH: + replacement = getMonthString(inDate, count, c); break; - + case SECONDS: replacement = zeroPad(inDate.get(Calendar.SECOND), count); break; @@ -527,14 +545,19 @@ public class DateFormat { return s.toString(); } - private static final String getMonthString(Calendar inDate, int count) { + private static final String getMonthString(Calendar inDate, int count, int kind) { + boolean standalone = (kind == STANDALONE_MONTH); int month = inDate.get(Calendar.MONTH); - if (count >= 4) - return DateUtils.getMonthString(month, DateUtils.LENGTH_LONG); - else if (count == 3) - return DateUtils.getMonthString(month, DateUtils.LENGTH_MEDIUM); - else { + if (count >= 4) { + return standalone + ? DateUtils.getStandaloneMonthString(month, DateUtils.LENGTH_LONG) + : DateUtils.getMonthString(month, DateUtils.LENGTH_LONG); + } else if (count == 3) { + return standalone + ? DateUtils.getStandaloneMonthString(month, DateUtils.LENGTH_MEDIUM) + : DateUtils.getMonthString(month, DateUtils.LENGTH_MEDIUM); + } else { // Calendar.JANUARY == 0, so add 1 to month. return zeroPad(month+1, count); } @@ -574,7 +597,8 @@ public class DateFormat { private static final String getYearString(Calendar inDate, int count) { int year = inDate.get(Calendar.YEAR); - return (count <= 2) ? zeroPad(year % 100, 2) : String.valueOf(year); + return (count <= 2) ? zeroPad(year % 100, 2) + : String.format(Locale.getDefault(), "%d", year); } private static final int appendQuotedText(SpannableStringBuilder s, int i, int len) { @@ -615,17 +639,6 @@ public class DateFormat { } private static final String zeroPad(int inValue, int inMinDigits) { - String val = String.valueOf(inValue); - - if (val.length() < inMinDigits) { - char[] buf = new char[inMinDigits]; - - for (int i = 0; i < inMinDigits; i++) - buf[i] = '0'; - - val.getChars(0, val.length(), buf, inMinDigits - val.length()); - val = new String(buf); - } - return val; + return String.format(Locale.getDefault(), "%0" + inMinDigits + "d", inValue); } } diff --git a/core/java/android/util/PropertyValueModel.java b/core/java/android/util/PropertyValueModel.java deleted file mode 100755 index eb9c47d..0000000 --- a/core/java/android/util/PropertyValueModel.java +++ /dev/null @@ -1,143 +0,0 @@ -/* - * Copyright (C) 2012 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.util; - -/** - * A value model for a {@link Property property} of a host object. This class can be used for - * both reflective and non-reflective property implementations. - * - * @param <H> the host type, where the host is the object that holds this property - * @param <T> the value type - * - * @see Property - * @see ValueModel - */ -public class PropertyValueModel<H, T> extends ValueModel<T> { - private final H mHost; - private final Property<H, T> mProperty; - - private PropertyValueModel(H host, Property<H, T> property) { - mProperty = property; - mHost = host; - } - - /** - * Returns the host. - * - * @return the host - */ - public H getHost() { - return mHost; - } - - /** - * Returns the property. - * - * @return the property - */ - public Property<H, T> getProperty() { - return mProperty; - } - - @Override - public Class<T> getType() { - return mProperty.getType(); - } - - @Override - public T get() { - return mProperty.get(mHost); - } - - @Override - public void set(T value) { - mProperty.set(mHost, value); - } - - /** - * Return an appropriate PropertyValueModel for this host and property. - * - * @param host the host - * @param property the property - * @return the value model - */ - public static <H, T> PropertyValueModel<H, T> of(H host, Property<H, T> property) { - return new PropertyValueModel<H, T>(host, property); - } - - /** - * Return a PropertyValueModel for this {@code host} and a - * reflective property, constructed from this {@code propertyType} and {@code propertyName}. - * - * @param host - * @param propertyType the property type - * @param propertyName the property name - * @return a value model with this host and a reflective property with this type and name - * - * @see Property#of - */ - public static <H, T> PropertyValueModel<H, T> of(H host, Class<T> propertyType, - String propertyName) { - return of(host, Property.of((Class<H>) host.getClass(), propertyType, propertyName)); - } - - private static Class getNullaryMethodReturnType(Class c, String name) { - try { - return c.getMethod(name).getReturnType(); - } catch (NoSuchMethodException e) { - return null; - } - } - - private static Class getFieldType(Class c, String name) { - try { - return c.getField(name).getType(); - } catch (NoSuchFieldException e) { - return null; - } - } - - private static String capitalize(String name) { - if (name.isEmpty()) { - return name; - } - return Character.toUpperCase(name.charAt(0)) + name.substring(1); - } - - /** - * Return a PropertyValueModel for this {@code host} and and {@code propertyName}. - * - * @param host the host - * @param propertyName the property name - * @return a value model with this host and a reflective property with this name - */ - public static PropertyValueModel of(Object host, String propertyName) { - Class clazz = host.getClass(); - String suffix = capitalize(propertyName); - Class propertyType = getNullaryMethodReturnType(clazz, "get" + suffix); - if (propertyType == null) { - propertyType = getNullaryMethodReturnType(clazz, "is" + suffix); - } - if (propertyType == null) { - propertyType = getFieldType(clazz, propertyName); - } - if (propertyType == null) { - throw new NoSuchPropertyException(propertyName); - } - return of(host, propertyType, propertyName); - } -} diff --git a/core/java/android/util/ValueModel.java b/core/java/android/util/ValueModel.java deleted file mode 100755 index 4789682..0000000 --- a/core/java/android/util/ValueModel.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright (C) 2012 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.util; - -/** - * A ValueModel is an abstraction for a 'slot' or place in memory in which a value - * may be stored and retrieved. A common implementation of ValueModel is a regular property of - * an object, whose value may be retrieved by calling the appropriate <em>getter</em> - * method and set by calling the corresponding <em>setter</em> method. - * - * @param <T> the value type - * - * @see PropertyValueModel - */ -public abstract class ValueModel<T> { - /** - * The empty model should be used in place of {@code null} to indicate that a - * model has not been set. The empty model has no value and does nothing when it is set. - */ - public static final ValueModel EMPTY = new ValueModel() { - @Override - public Class getType() { - return Object.class; - } - - @Override - public Object get() { - return null; - } - - @Override - public void set(Object value) { - - } - }; - - protected ValueModel() { - } - - /** - * Returns the type of this property. - * - * @return the property type - */ - public abstract Class<T> getType(); - - /** - * Returns the value of this property. - * - * @return the property value - */ - public abstract T get(); - - /** - * Sets the value of this property. - * - * @param value the new value for this property - */ - public abstract void set(T value); -}
\ No newline at end of file diff --git a/core/java/android/widget/CheckBox.java b/core/java/android/widget/CheckBox.java index 41ab5f2..f1804f8 100644 --- a/core/java/android/widget/CheckBox.java +++ b/core/java/android/widget/CheckBox.java @@ -20,7 +20,6 @@ import android.content.Context; import android.util.AttributeSet; import android.view.accessibility.AccessibilityEvent; import android.view.accessibility.AccessibilityNodeInfo; -import android.util.ValueModel; /** @@ -56,9 +55,7 @@ import android.util.ValueModel; * {@link android.R.styleable#View View Attributes} * </p> */ -public class CheckBox extends CompoundButton implements ValueEditor<Boolean> { - private ValueModel<Boolean> mValueModel = ValueModel.EMPTY; - +public class CheckBox extends CompoundButton { public CheckBox(Context context) { this(context, null); } @@ -82,22 +79,4 @@ public class CheckBox extends CompoundButton implements ValueEditor<Boolean> { super.onInitializeAccessibilityNodeInfo(info); info.setClassName(CheckBox.class.getName()); } - - @Override - public ValueModel<Boolean> getValueModel() { - return mValueModel; - } - - @Override - public void setValueModel(ValueModel<Boolean> valueModel) { - mValueModel = valueModel; - setChecked(mValueModel.get()); - } - - @Override - public boolean performClick() { - boolean handled = super.performClick(); - mValueModel.set(isChecked()); - return handled; - } } diff --git a/core/java/android/widget/EditText.java b/core/java/android/widget/EditText.java index ec81214..57e51c2 100644 --- a/core/java/android/widget/EditText.java +++ b/core/java/android/widget/EditText.java @@ -17,7 +17,6 @@ package android.widget; import android.content.Context; -import android.graphics.Rect; import android.text.Editable; import android.text.Selection; import android.text.Spannable; @@ -25,7 +24,6 @@ import android.text.TextUtils; import android.text.method.ArrowKeyMovementMethod; import android.text.method.MovementMethod; import android.util.AttributeSet; -import android.util.ValueModel; import android.view.accessibility.AccessibilityEvent; import android.view.accessibility.AccessibilityNodeInfo; @@ -49,9 +47,7 @@ import android.view.accessibility.AccessibilityNodeInfo; * {@link android.R.styleable#TextView TextView Attributes}, * {@link android.R.styleable#View View Attributes} */ -public class EditText extends TextView implements ValueEditor<CharSequence> { - private ValueModel<CharSequence> mValueModel = ValueModel.EMPTY; - +public class EditText extends TextView { public EditText(Context context) { this(context, null); } @@ -132,21 +128,4 @@ public class EditText extends TextView implements ValueEditor<CharSequence> { super.onInitializeAccessibilityNodeInfo(info); info.setClassName(EditText.class.getName()); } - - @Override - public ValueModel<CharSequence> getValueModel() { - return mValueModel; - } - - @Override - public void setValueModel(ValueModel<CharSequence> valueModel) { - mValueModel = valueModel; - setText(mValueModel.get()); - } - - @Override - void sendAfterTextChanged(Editable text) { - super.sendAfterTextChanged(text); - mValueModel.set(text); - } } diff --git a/core/java/android/widget/Editor.java b/core/java/android/widget/Editor.java index 7f9dab9..237275a 100644 --- a/core/java/android/widget/Editor.java +++ b/core/java/android/widget/Editor.java @@ -1801,13 +1801,13 @@ public class Editor { mTextView.deleteText_internal(dragSourceStart, dragSourceEnd); // Make sure we do not leave two adjacent spaces. - CharSequence t = mTextView.getTransformedText(dragSourceStart - 1, dragSourceStart + 1); - if ( (dragSourceStart == 0 || Character.isSpaceChar(t.charAt(0))) && - (dragSourceStart == mTextView.getText().length() || - Character.isSpaceChar(t.charAt(1))) ) { - final int pos = dragSourceStart == mTextView.getText().length() ? - dragSourceStart - 1 : dragSourceStart; - mTextView.deleteText_internal(pos, pos + 1); + final int prevCharIdx = Math.max(0, dragSourceStart - 1); + final int nextCharIdx = Math.min(mTextView.getText().length(), dragSourceStart + 1); + if (nextCharIdx > prevCharIdx + 1) { + CharSequence t = mTextView.getTransformedText(prevCharIdx, nextCharIdx); + if (Character.isSpaceChar(t.charAt(0)) && Character.isSpaceChar(t.charAt(1))) { + mTextView.deleteText_internal(prevCharIdx, prevCharIdx + 1); + } } } } diff --git a/core/java/android/widget/SeekBar.java b/core/java/android/widget/SeekBar.java index a6486a8..2737f94 100644 --- a/core/java/android/widget/SeekBar.java +++ b/core/java/android/widget/SeekBar.java @@ -18,7 +18,6 @@ package android.widget; import android.content.Context; import android.util.AttributeSet; -import android.util.ValueModel; import android.view.accessibility.AccessibilityEvent; import android.view.accessibility.AccessibilityNodeInfo; @@ -34,7 +33,7 @@ import android.view.accessibility.AccessibilityNodeInfo; * * @attr ref android.R.styleable#SeekBar_thumb */ -public class SeekBar extends AbsSeekBar implements ValueEditor<Integer> { +public class SeekBar extends AbsSeekBar { /** * A callback that notifies clients when the progress level has been @@ -70,9 +69,8 @@ public class SeekBar extends AbsSeekBar implements ValueEditor<Integer> { void onStopTrackingTouch(SeekBar seekBar); } - private ValueModel<Integer> mValueModel = ValueModel.EMPTY; private OnSeekBarChangeListener mOnSeekBarChangeListener; - + public SeekBar(Context context) { this(context, null); } @@ -91,23 +89,9 @@ public class SeekBar extends AbsSeekBar implements ValueEditor<Integer> { if (mOnSeekBarChangeListener != null) { mOnSeekBarChangeListener.onProgressChanged(this, getProgress(), fromUser); - if (fromUser) { - mValueModel.set(getProgress()); - } } } - @Override - public ValueModel<Integer> getValueModel() { - return mValueModel; - } - - @Override - public void setValueModel(ValueModel<Integer> valueModel) { - mValueModel = valueModel; - setProgress(mValueModel.get()); - } - /** * Sets a listener to receive notifications of changes to the SeekBar's progress level. Also * provides notifications of when the user starts and stops a touch gesture within the SeekBar. diff --git a/core/java/android/widget/ValueEditor.java b/core/java/android/widget/ValueEditor.java deleted file mode 100755 index 2b91abf..0000000 --- a/core/java/android/widget/ValueEditor.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (C) 2012 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.widget; - -import android.util.ValueModel; - -/** - * An interface for editors of simple values. Classes implementing this interface are normally - * UI controls (subclasses of {@link android.view.View View}) that can provide a suitable - * user interface to display and edit values of the specified type. This interface is - * intended to describe editors for simple types, like {@code boolean}, {@code int} or - * {@code String}, where the values themselves are immutable. - * <p> - * For example, {@link android.widget.CheckBox CheckBox} implements - * this interface for the Boolean type as it is capable of providing an appropriate - * mechanism for displaying and changing the value of a Boolean property. - * - * @param <T> the value type that this editor supports - */ -public interface ValueEditor<T> { - /** - * Return the last value model that was set. If no value model has been set, the editor - * should return the value {@link android.util.ValueModel#EMPTY}. - * - * @return the value model - */ - public ValueModel<T> getValueModel(); - - /** - * Sets the value model for this editor. When the value model is set, the editor should - * retrieve the value from the value model, using {@link android.util.ValueModel#get()}, - * and set its internal state accordingly. Likewise, when the editor's internal state changes - * it should update the value model by calling {@link android.util.ValueModel#set(T)} - * with the appropriate value. - * - * @param valueModel the new value model for this editor. - */ - public void setValueModel(ValueModel<T> valueModel); -} |
