summaryrefslogtreecommitdiffstats
path: root/core/java
diff options
context:
space:
mode:
Diffstat (limited to 'core/java')
-rw-r--r--core/java/android/alsa/AlsaCardsParser.java193
-rw-r--r--core/java/android/alsa/AlsaDevicesParser.java173
-rw-r--r--core/java/android/animation/AnimatorInflater.java399
-rw-r--r--core/java/android/animation/AnimatorSet.java12
-rw-r--r--core/java/android/animation/ObjectAnimator.java21
-rw-r--r--core/java/android/animation/ValueAnimator.java16
-rw-r--r--core/java/android/app/Activity.java17
-rw-r--r--core/java/android/app/ActivityManagerNative.java77
-rw-r--r--core/java/android/app/ActivityThread.java13
-rw-r--r--core/java/android/app/ActivityView.java2
-rw-r--r--core/java/android/app/ContextImpl.java17
-rw-r--r--core/java/android/app/DatePickerDialog.java3
-rw-r--r--core/java/android/app/IActivityManager.java10
-rw-r--r--core/java/android/app/VoiceInteractor.java17
-rw-r--r--core/java/android/app/admin/DevicePolicyManager.java37
-rw-r--r--core/java/android/appwidget/AppWidgetHost.java50
-rw-r--r--core/java/android/appwidget/AppWidgetHostView.java5
-rw-r--r--core/java/android/bluetooth/BluetoothHeadsetClientCall.java25
-rw-r--r--core/java/android/content/ContentProviderOperation.java16
-rw-r--r--core/java/android/content/Context.java57
-rw-r--r--core/java/android/content/Intent.java2
-rw-r--r--core/java/android/content/res/ColorStateList.java400
-rw-r--r--core/java/android/content/res/Resources.java298
-rw-r--r--core/java/android/content/res/TypedArray.java351
-rw-r--r--core/java/android/hardware/camera2/params/LensShadingMap.java45
-rw-r--r--core/java/android/hardware/usb/UsbDevice.java1
-rw-r--r--core/java/android/midi/IMidiDeviceServer.aidl26
-rw-r--r--core/java/android/midi/IMidiListener.aidl26
-rw-r--r--core/java/android/midi/IMidiManager.aidl41
-rw-r--r--core/java/android/midi/MidiDevice.java101
-rw-r--r--core/java/android/midi/MidiDeviceInfo.aidl19
-rw-r--r--core/java/android/midi/MidiDeviceInfo.java203
-rw-r--r--core/java/android/midi/MidiDeviceServer.java261
-rw-r--r--core/java/android/midi/MidiInputPort.java70
-rw-r--r--core/java/android/midi/MidiManager.java195
-rw-r--r--core/java/android/midi/MidiOutputPort.java137
-rw-r--r--core/java/android/midi/MidiPort.java124
-rw-r--r--core/java/android/midi/MidiReceiver.java41
-rw-r--r--core/java/android/midi/MidiSender.java39
-rw-r--r--core/java/android/midi/MidiUtils.java65
-rw-r--r--core/java/android/net/ConnectivityManager.java2
-rw-r--r--core/java/android/os/Build.java43
-rw-r--r--core/java/android/os/Debug.java3
-rw-r--r--core/java/android/os/ParcelFileDescriptor.java18
-rw-r--r--core/java/android/os/StrictMode.java74
-rw-r--r--core/java/android/provider/Contacts.java49
-rw-r--r--core/java/android/provider/ContactsContract.java209
-rw-r--r--core/java/android/provider/Settings.java15
-rw-r--r--core/java/android/service/voice/VoiceInteractionService.java9
-rw-r--r--core/java/android/service/voice/VoiceInteractionSession.java77
-rw-r--r--core/java/android/speech/tts/ITextToSpeechCallback.aidl2
-rw-r--r--core/java/android/speech/tts/TextToSpeech.java4
-rw-r--r--core/java/android/speech/tts/TextToSpeechService.java79
-rw-r--r--core/java/android/speech/tts/UtteranceProgressListener.java19
-rw-r--r--core/java/android/text/StaticLayout.java366
-rw-r--r--core/java/android/text/util/Rfc822Token.java14
-rw-r--r--core/java/android/transition/ChangeScroll.java2
-rw-r--r--core/java/android/util/AttributeSet.java2
-rw-r--r--core/java/android/util/Spline.java2
-rw-r--r--core/java/android/util/StateSet.java83
-rw-r--r--core/java/android/view/ContextThemeWrapper.java14
-rw-r--r--core/java/android/view/GLES20Canvas.java791
-rw-r--r--core/java/android/view/GLES20RecordingCanvas.java2
-rw-r--r--core/java/android/view/HardwareCanvas.java25
-rw-r--r--core/java/android/view/HardwareLayer.java2
-rw-r--r--core/java/android/view/LayoutInflater.java69
-rw-r--r--core/java/android/view/RenderNode.java2
-rw-r--r--core/java/android/view/Surface.java1
-rw-r--r--core/java/android/view/View.java401
-rw-r--r--core/java/android/view/ViewGroup.java13
-rw-r--r--core/java/android/view/ViewStub.java25
-rw-r--r--core/java/android/view/WindowManagerGlobal.java8
-rw-r--r--core/java/android/view/inputmethod/InputMethodSubtypeArray.java59
-rw-r--r--core/java/android/webkit/CookieManager.java5
-rw-r--r--core/java/android/webkit/WebChromeClient.java24
-rw-r--r--core/java/android/webkit/WebResourceResponse.java18
-rw-r--r--core/java/android/webkit/WebView.java61
-rw-r--r--core/java/android/webkit/WebViewFactory.java8
-rw-r--r--core/java/android/widget/AbsListView.java20
-rw-r--r--core/java/android/widget/AbsSeekBar.java15
-rw-r--r--core/java/android/widget/AbsSpinner.java19
-rw-r--r--core/java/android/widget/ActionMenuPresenter.java5
-rw-r--r--core/java/android/widget/ActionMenuView.java14
-rw-r--r--core/java/android/widget/AdapterView.java18
-rw-r--r--core/java/android/widget/AdapterViewAnimator.java10
-rw-r--r--core/java/android/widget/AdapterViewFlipper.java10
-rw-r--r--core/java/android/widget/ArrayAdapter.java71
-rw-r--r--core/java/android/widget/Button.java10
-rw-r--r--core/java/android/widget/CalendarView.java6
-rw-r--r--core/java/android/widget/CheckBox.java10
-rw-r--r--core/java/android/widget/CheckedTextView.java10
-rw-r--r--core/java/android/widget/Chronometer.java10
-rw-r--r--core/java/android/widget/CompoundButton.java10
-rw-r--r--core/java/android/widget/CursorAdapter.java46
-rw-r--r--core/java/android/widget/DatePicker.java18
-rw-r--r--core/java/android/widget/DatePickerCalendarDelegate.java41
-rw-r--r--core/java/android/widget/DayPickerView.java21
-rw-r--r--core/java/android/widget/DigitalClock.java10
-rw-r--r--core/java/android/widget/EditText.java15
-rw-r--r--core/java/android/widget/Editor.java2
-rw-r--r--core/java/android/widget/ExpandableListView.java10
-rw-r--r--core/java/android/widget/FrameLayout.java10
-rw-r--r--core/java/android/widget/Gallery.java15
-rw-r--r--core/java/android/widget/GridLayout.java10
-rw-r--r--core/java/android/widget/GridView.java10
-rw-r--r--core/java/android/widget/HorizontalScrollView.java15
-rw-r--r--core/java/android/widget/ImageButton.java10
-rw-r--r--core/java/android/widget/ImageSwitcher.java10
-rw-r--r--core/java/android/widget/ImageView.java15
-rw-r--r--core/java/android/widget/LinearLayout.java10
-rw-r--r--core/java/android/widget/ListView.java10
-rw-r--r--core/java/android/widget/MediaController.java10
-rw-r--r--core/java/android/widget/MultiAutoCompleteTextView.java10
-rw-r--r--core/java/android/widget/NumberPicker.java5
-rw-r--r--core/java/android/widget/PopupMenu.java23
-rw-r--r--core/java/android/widget/PopupWindow.java103
-rw-r--r--core/java/android/widget/ProgressBar.java10
-rw-r--r--core/java/android/widget/QuickContactBadge.java10
-rw-r--r--core/java/android/widget/RadialTimePickerView.java618
-rw-r--r--core/java/android/widget/RadioButton.java10
-rw-r--r--core/java/android/widget/RadioGroup.java10
-rw-r--r--core/java/android/widget/RatingBar.java10
-rw-r--r--core/java/android/widget/RelativeLayout.java116
-rw-r--r--core/java/android/widget/ResourceCursorAdapter.java41
-rw-r--r--core/java/android/widget/ScrollBarDrawable.java215
-rw-r--r--core/java/android/widget/ScrollView.java15
-rw-r--r--core/java/android/widget/SearchView.java10
-rw-r--r--core/java/android/widget/SeekBar.java10
-rw-r--r--core/java/android/widget/SimpleAdapter.java55
-rw-r--r--core/java/android/widget/SimpleMonthAdapter.java13
-rw-r--r--core/java/android/widget/SimpleMonthView.java247
-rw-r--r--core/java/android/widget/SlidingDrawer.java10
-rw-r--r--core/java/android/widget/Spinner.java228
-rw-r--r--core/java/android/widget/SpinnerAdapter.java13
-rw-r--r--core/java/android/widget/StackView.java15
-rw-r--r--core/java/android/widget/SuggestionsAdapter.java39
-rw-r--r--core/java/android/widget/Switch.java15
-rw-r--r--core/java/android/widget/TabHost.java13
-rw-r--r--core/java/android/widget/TabWidget.java18
-rw-r--r--core/java/android/widget/TableLayout.java10
-rw-r--r--core/java/android/widget/TableRow.java10
-rw-r--r--core/java/android/widget/TextSwitcher.java10
-rw-r--r--core/java/android/widget/TextView.java446
-rw-r--r--core/java/android/widget/TextViewWithCircularIndicator.java43
-rw-r--r--core/java/android/widget/TimePicker.java18
-rw-r--r--core/java/android/widget/ToggleButton.java10
-rw-r--r--core/java/android/widget/TwoLineListItem.java10
-rw-r--r--core/java/android/widget/VideoView.java10
-rw-r--r--core/java/android/widget/ViewAnimator.java10
-rw-r--r--core/java/android/widget/ViewFlipper.java10
-rw-r--r--core/java/android/widget/ViewSwitcher.java10
-rw-r--r--core/java/android/widget/YearPickerView.java45
-rw-r--r--core/java/android/widget/ZoomButton.java10
-rw-r--r--core/java/android/widget/ZoomControls.java10
-rw-r--r--core/java/com/android/internal/app/ResolverActivity.java2
-rw-r--r--core/java/com/android/internal/util/UserIcons.java9
-rw-r--r--core/java/com/android/internal/view/menu/ActionMenuItemView.java6
-rw-r--r--core/java/com/android/internal/view/menu/ListMenuItemView.java4
-rw-r--r--core/java/com/android/internal/view/menu/MenuPopupHelper.java6
-rw-r--r--core/java/com/android/internal/widget/AccessibleDateAnimator.java4
-rw-r--r--core/java/com/android/internal/widget/ActionBarContextView.java4
-rw-r--r--core/java/com/android/internal/widget/ActionBarView.java6
-rw-r--r--core/java/com/android/internal/widget/ILockSettings.aidl1
-rw-r--r--core/java/com/android/internal/widget/LockPatternUtils.java863
-rw-r--r--core/java/com/android/internal/widget/LockPatternView.java41
-rw-r--r--core/java/com/android/internal/widget/ScrollingTabContainerView.java43
-rw-r--r--core/java/com/android/server/backup/AccountSyncSettingsBackupHelper.java380
-rw-r--r--core/java/com/android/server/backup/SystemBackupAgent.java4
168 files changed, 6444 insertions, 4204 deletions
diff --git a/core/java/android/alsa/AlsaCardsParser.java b/core/java/android/alsa/AlsaCardsParser.java
index 8b44881..2c7d502 100644
--- a/core/java/android/alsa/AlsaCardsParser.java
+++ b/core/java/android/alsa/AlsaCardsParser.java
@@ -22,46 +22,66 @@ import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
-import java.util.Vector;
+import java.util.ArrayList;
/**
* @hide Retrieves information from an ALSA "cards" file.
*/
public class AlsaCardsParser {
private static final String TAG = "AlsaCardsParser";
+ protected static final boolean DEBUG = true;
- private static LineTokenizer tokenizer_ = new LineTokenizer(" :[]");
+ private static final String kCardsFilePath = "/proc/asound/cards";
+
+ private static LineTokenizer mTokenizer = new LineTokenizer(" :[]");
+
+ private ArrayList<AlsaCardRecord> mCardRecords = new ArrayList<AlsaCardRecord>();
public class AlsaCardRecord {
+ private static final String TAG = "AlsaCardRecord";
+ private static final String kUsbCardKeyStr = "at usb-";
+
public int mCardNum = -1;
public String mField1 = "";
public String mCardName = "";
public String mCardDescription = "";
+ public boolean mIsUsb = false;
public AlsaCardRecord() {}
public boolean parse(String line, int lineIndex) {
int tokenIndex = 0;
int delimIndex = 0;
+
if (lineIndex == 0) {
// line # (skip)
- tokenIndex = tokenizer_.nextToken(line, tokenIndex);
- delimIndex = tokenizer_.nextDelimiter(line, tokenIndex);
+ tokenIndex = mTokenizer.nextToken(line, tokenIndex);
+ delimIndex = mTokenizer.nextDelimiter(line, tokenIndex);
+
+ try {
+ // mCardNum
+ mCardNum = Integer.parseInt(line.substring(tokenIndex, delimIndex));
+ } catch (NumberFormatException e) {
+ Slog.e(TAG, "Failed to parse line " + lineIndex + " of " + kCardsFilePath
+ + ": " + line.substring(tokenIndex, delimIndex));
+ return false;
+ }
// mField1
- tokenIndex = tokenizer_.nextToken(line, delimIndex);
- delimIndex = tokenizer_.nextDelimiter(line, tokenIndex);
+ tokenIndex = mTokenizer.nextToken(line, delimIndex);
+ delimIndex = mTokenizer.nextDelimiter(line, tokenIndex);
mField1 = line.substring(tokenIndex, delimIndex);
// mCardName
- tokenIndex = tokenizer_.nextToken(line, delimIndex);
- // delimIndex = tokenizer_.nextDelimiter(line, tokenIndex);
+ tokenIndex = mTokenizer.nextToken(line, delimIndex);
mCardName = line.substring(tokenIndex);
+
// done
} else if (lineIndex == 1) {
- tokenIndex = tokenizer_.nextToken(line, 0);
+ tokenIndex = mTokenizer.nextToken(line, 0);
if (tokenIndex != -1) {
mCardDescription = line.substring(tokenIndex);
+ mIsUsb = mCardDescription.contains(kUsbCardKeyStr);
}
}
@@ -73,44 +93,127 @@ public class AlsaCardsParser {
}
}
- private Vector<AlsaCardRecord> cardRecords_ = new Vector<AlsaCardRecord>();
+ public AlsaCardsParser() {}
public void scan() {
- cardRecords_.clear();
- final String cardsFilePath = "/proc/asound/cards";
- File cardsFile = new File(cardsFilePath);
- try {
- FileReader reader = new FileReader(cardsFile);
- BufferedReader bufferedReader = new BufferedReader(reader);
- String line = "";
- while ((line = bufferedReader.readLine()) != null) {
- AlsaCardRecord cardRecord = new AlsaCardRecord();
- cardRecord.parse(line, 0);
- cardRecord.parse(line = bufferedReader.readLine(), 1);
- cardRecords_.add(cardRecord);
- }
- reader.close();
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
-
- public AlsaCardRecord getCardRecordAt(int index) {
- return cardRecords_.get(index);
- }
-
- public int getNumCardRecords() {
- return cardRecords_.size();
- }
-
- public void Log() {
- int numCardRecs = getNumCardRecords();
- for (int index = 0; index < numCardRecs; ++index) {
- Slog.w(TAG, "usb:" + getCardRecordAt(index).textFormat());
- }
+ if (DEBUG) {
+ Slog.i(TAG, "AlsaCardsParser.scan()");
+ }
+ mCardRecords = new ArrayList<AlsaCardRecord>();
+
+ File cardsFile = new File(kCardsFilePath);
+ try {
+ FileReader reader = new FileReader(cardsFile);
+ BufferedReader bufferedReader = new BufferedReader(reader);
+ String line = "";
+ while ((line = bufferedReader.readLine()) != null) {
+ AlsaCardRecord cardRecord = new AlsaCardRecord();
+ if (DEBUG) {
+ Slog.i(TAG, " " + line);
+ }
+ cardRecord.parse(line, 0);
+
+ line = bufferedReader.readLine();
+ if (DEBUG) {
+ Slog.i(TAG, " " + line);
+ }
+ cardRecord.parse(line, 1);
+
+ mCardRecords.add(cardRecord);
+ }
+ reader.close();
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
}
- public AlsaCardsParser() {}
+ public ArrayList<AlsaCardRecord> getScanRecords() {
+ return mCardRecords;
+ }
+
+ public AlsaCardRecord getCardRecordAt(int index) {
+ return mCardRecords.get(index);
+ }
+
+ public AlsaCardRecord getCardRecordFor(int cardNum) {
+ for (AlsaCardRecord rec : mCardRecords) {
+ if (rec.mCardNum == cardNum) {
+ return rec;
+ }
+ }
+
+ return null;
+ }
+
+ public int getNumCardRecords() {
+ return mCardRecords.size();
+ }
+
+ public boolean isCardUsb(int cardNum) {
+ for (AlsaCardRecord rec : mCardRecords) {
+ if (rec.mCardNum == cardNum) {
+ return rec.mIsUsb;
+ }
+ }
+
+ return false;
+ }
+
+ // return -1 if none found
+ public int getDefaultUsbCard() {
+ // Choose the most-recently added EXTERNAL card
+ // or return the first added EXTERNAL card?
+ for (AlsaCardRecord rec : mCardRecords) {
+ if (rec.mIsUsb) {
+ return rec.mCardNum;
+ }
+ }
+
+ return -1;
+ }
+
+ public int getDefaultCard() {
+ // return an external card if possible
+ int card = getDefaultUsbCard();
+
+ if (card < 0 && getNumCardRecords() > 0) {
+ // otherwise return the (internal) card with the highest number
+ card = getCardRecordAt(getNumCardRecords() - 1).mCardNum;
+ }
+ return card;
+ }
+
+ static public boolean hasCardNumber(ArrayList<AlsaCardRecord> recs, int cardNum) {
+ for (AlsaCardRecord cardRec : recs) {
+ if (cardRec.mCardNum == cardNum) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public ArrayList<AlsaCardRecord> getNewCardRecords(ArrayList<AlsaCardRecord> prevScanRecs) {
+ ArrayList<AlsaCardRecord> newRecs = new ArrayList<AlsaCardRecord>();
+ for (AlsaCardRecord rec : mCardRecords) {
+ // now scan to see if this card number is in the previous scan list
+ if (!hasCardNumber(prevScanRecs, rec.mCardNum)) {
+ newRecs.add(rec);
+ }
+ }
+ return newRecs;
+ }
+
+ //
+ // Logging
+ //
+ public void Log(String heading) {
+ if (DEBUG) {
+ Slog.i(TAG, heading);
+ for (AlsaCardRecord cardRec : mCardRecords) {
+ Slog.i(TAG, cardRec.textFormat());
+ }
+ }
+ }
}
diff --git a/core/java/android/alsa/AlsaDevicesParser.java b/core/java/android/alsa/AlsaDevicesParser.java
index 82cc1ae..b140d3d 100644
--- a/core/java/android/alsa/AlsaDevicesParser.java
+++ b/core/java/android/alsa/AlsaDevicesParser.java
@@ -21,7 +21,7 @@ import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
-import java.util.Vector;
+import java.util.ArrayList;
/**
* @hide
@@ -29,6 +29,9 @@ import java.util.Vector;
*/
public class AlsaDevicesParser {
private static final String TAG = "AlsaDevicesParser";
+ protected static final boolean DEBUG = false;
+
+ private static final String kDevicesFilePath = "/proc/asound/devices";
private static final int kIndex_CardDeviceField = 5;
private static final int kStartIndex_CardNum = 6;
@@ -58,8 +61,7 @@ public class AlsaDevicesParser {
int mDeviceType = kDeviceType_Unknown;
int mDeviceDir = kDeviceDir_Unknown;
- public AlsaDeviceRecord() {
- }
+ public AlsaDeviceRecord() {}
public boolean parse(String line) {
// "0123456789012345678901234567890"
@@ -89,51 +91,57 @@ public class AlsaDevicesParser {
}
String token = line.substring(tokenOffset, delimOffset);
- switch (tokenIndex) {
- case kToken_LineNum:
- // ignore
- break;
-
- case kToken_CardNum:
- mCardNum = Integer.parseInt(token);
- if (line.charAt(delimOffset) != '-') {
- tokenIndex++; // no device # in the token stream
- }
- break;
-
- case kToken_DeviceNum:
- mDeviceNum = Integer.parseInt(token);
- break;
-
- case kToken_Type0:
- if (token.equals("digital")) {
- // NOP
- } else if (token.equals("control")) {
- mDeviceType = kDeviceType_Control;
- } else if (token.equals("raw")) {
- // NOP
- }
- break;
-
- case kToken_Type1:
- if (token.equals("audio")) {
- mDeviceType = kDeviceType_Audio;
- } else if (token.equals("midi")) {
- mDeviceType = kDeviceType_MIDI;
- mHasMIDIDevices = true;
- }
- break;
-
- case kToken_Type2:
- if (token.equals("capture")) {
- mDeviceDir = kDeviceDir_Capture;
- mHasCaptureDevices = true;
- } else if (token.equals("playback")) {
- mDeviceDir = kDeviceDir_Playback;
- mHasPlaybackDevices = true;
- }
- break;
- } // switch (tokenIndex)
+ try {
+ switch (tokenIndex) {
+ case kToken_LineNum:
+ // ignore
+ break;
+
+ case kToken_CardNum:
+ mCardNum = Integer.parseInt(token);
+ if (line.charAt(delimOffset) != '-') {
+ tokenIndex++; // no device # in the token stream
+ }
+ break;
+
+ case kToken_DeviceNum:
+ mDeviceNum = Integer.parseInt(token);
+ break;
+
+ case kToken_Type0:
+ if (token.equals("digital")) {
+ // NOP
+ } else if (token.equals("control")) {
+ mDeviceType = kDeviceType_Control;
+ } else if (token.equals("raw")) {
+ // NOP
+ }
+ break;
+
+ case kToken_Type1:
+ if (token.equals("audio")) {
+ mDeviceType = kDeviceType_Audio;
+ } else if (token.equals("midi")) {
+ mDeviceType = kDeviceType_MIDI;
+ mHasMIDIDevices = true;
+ }
+ break;
+
+ case kToken_Type2:
+ if (token.equals("capture")) {
+ mDeviceDir = kDeviceDir_Capture;
+ mHasCaptureDevices = true;
+ } else if (token.equals("playback")) {
+ mDeviceDir = kDeviceDir_Playback;
+ mHasPlaybackDevices = true;
+ }
+ break;
+ } // switch (tokenIndex)
+ } catch (NumberFormatException e) {
+ Slog.e(TAG, "Failed to parse token " + tokenIndex + " of " + kDevicesFilePath
+ + " token: " + token);
+ return false;
+ }
tokenIndex++;
} // while (true)
@@ -176,38 +184,27 @@ public class AlsaDevicesParser {
}
}
- private Vector<AlsaDeviceRecord>
- deviceRecords_ = new Vector<AlsaDeviceRecord>();
+ private ArrayList<AlsaDeviceRecord> mDeviceRecords = new ArrayList<AlsaDeviceRecord>();
- private boolean isLineDeviceRecord(String line) {
- return line.charAt(kIndex_CardDeviceField) == '[';
- }
+ public AlsaDevicesParser() {}
- public AlsaDevicesParser() {
+ //
+ // Access
+ //
+ public int getDefaultDeviceNum(int card) {
+ // TODO - This (obviously) isn't sufficient. Revisit.
+ return 0;
}
- public int getNumDeviceRecords() {
- return deviceRecords_.size();
- }
-
- public AlsaDeviceRecord getDeviceRecordAt(int index) {
- return deviceRecords_.get(index);
- }
-
- public void Log() {
- int numDevRecs = getNumDeviceRecords();
- for (int index = 0; index < numDevRecs; ++index) {
- Slog.w(TAG, "usb:" + getDeviceRecordAt(index).textFormat());
- }
- }
-
- public boolean hasPlaybackDevices() {
+ //
+ // Predicates
+ //
+ public boolean hasPlaybackDevices() {
return mHasPlaybackDevices;
}
public boolean hasPlaybackDevices(int card) {
- for (int index = 0; index < deviceRecords_.size(); index++) {
- AlsaDeviceRecord deviceRecord = deviceRecords_.get(index);
+ for (AlsaDeviceRecord deviceRecord : mDeviceRecords) {
if (deviceRecord.mCardNum == card &&
deviceRecord.mDeviceType == AlsaDeviceRecord.kDeviceType_Audio &&
deviceRecord.mDeviceDir == AlsaDeviceRecord.kDeviceDir_Playback) {
@@ -222,8 +219,7 @@ public class AlsaDevicesParser {
}
public boolean hasCaptureDevices(int card) {
- for (int index = 0; index < deviceRecords_.size(); index++) {
- AlsaDeviceRecord deviceRecord = deviceRecords_.get(index);
+ for (AlsaDeviceRecord deviceRecord : mDeviceRecords) {
if (deviceRecord.mCardNum == card &&
deviceRecord.mDeviceType == AlsaDeviceRecord.kDeviceType_Audio &&
deviceRecord.mDeviceDir == AlsaDeviceRecord.kDeviceDir_Capture) {
@@ -238,8 +234,7 @@ public class AlsaDevicesParser {
}
public boolean hasMIDIDevices(int card) {
- for (int index = 0; index < deviceRecords_.size(); index++) {
- AlsaDeviceRecord deviceRecord = deviceRecords_.get(index);
+ for (AlsaDeviceRecord deviceRecord : mDeviceRecords) {
if (deviceRecord.mCardNum == card &&
deviceRecord.mDeviceType == AlsaDeviceRecord.kDeviceType_MIDI) {
return true;
@@ -248,11 +243,17 @@ public class AlsaDevicesParser {
return false;
}
+ //
+ // Process
+ //
+ private boolean isLineDeviceRecord(String line) {
+ return line.charAt(kIndex_CardDeviceField) == '[';
+ }
+
public void scan() {
- deviceRecords_.clear();
+ mDeviceRecords.clear();
- final String devicesFilePath = "/proc/asound/devices";
- File devicesFile = new File(devicesFilePath);
+ File devicesFile = new File(kDevicesFilePath);
try {
FileReader reader = new FileReader(devicesFile);
BufferedReader bufferedReader = new BufferedReader(reader);
@@ -261,7 +262,7 @@ public class AlsaDevicesParser {
if (isLineDeviceRecord(line)) {
AlsaDeviceRecord deviceRecord = new AlsaDeviceRecord();
deviceRecord.parse(line);
- deviceRecords_.add(deviceRecord);
+ mDeviceRecords.add(deviceRecord);
}
}
reader.close();
@@ -271,5 +272,17 @@ public class AlsaDevicesParser {
e.printStackTrace();
}
}
+
+ //
+ // Loging
+ //
+ public void Log(String heading) {
+ if (DEBUG) {
+ Slog.i(TAG, heading);
+ for (AlsaDeviceRecord deviceRecord : mDeviceRecords) {
+ Slog.i(TAG, deviceRecord.textFormat());
+ }
+ }
+ }
} // class AlsaDevicesParser
diff --git a/core/java/android/animation/AnimatorInflater.java b/core/java/android/animation/AnimatorInflater.java
index 688d7e4..6ef3da8 100644
--- a/core/java/android/animation/AnimatorInflater.java
+++ b/core/java/android/animation/AnimatorInflater.java
@@ -42,6 +42,7 @@ import org.xmlpull.v1.XmlPullParserException;
import java.io.IOException;
import java.util.ArrayList;
+import java.util.List;
/**
* This class is used to instantiate animator XML files into Animator objects.
@@ -66,8 +67,7 @@ public class AnimatorInflater {
private static final int VALUE_TYPE_FLOAT = 0;
private static final int VALUE_TYPE_INT = 1;
private static final int VALUE_TYPE_PATH = 2;
- private static final int VALUE_TYPE_COLOR = 4;
- private static final int VALUE_TYPE_CUSTOM = 5;
+ private static final int VALUE_TYPE_COLOR = 3;
private static final boolean DBG_ANIMATOR_INFLATER = false;
@@ -296,39 +296,50 @@ public class AnimatorInflater {
}
}
- /**
- * @param anim The animator, must not be null
- * @param arrayAnimator Incoming typed array for Animator's attributes.
- * @param arrayObjectAnimator Incoming typed array for Object Animator's
- * attributes.
- * @param pixelSize The relative pixel size, used to calculate the
- * maximum error for path animations.
- */
- private static void parseAnimatorFromTypeArray(ValueAnimator anim,
- TypedArray arrayAnimator, TypedArray arrayObjectAnimator, float pixelSize) {
- long duration = arrayAnimator.getInt(R.styleable.Animator_duration, 300);
-
- long startDelay = arrayAnimator.getInt(R.styleable.Animator_startOffset, 0);
-
- int valueType = arrayAnimator.getInt(R.styleable.Animator_valueType,
- VALUE_TYPE_FLOAT);
-
- TypeEvaluator evaluator = null;
+ private static PropertyValuesHolder getPVH(TypedArray styledAttributes, int valueType,
+ int valueFromId, int valueToId, String propertyName) {
boolean getFloats = (valueType == VALUE_TYPE_FLOAT);
- TypedValue tvFrom = arrayAnimator.peekValue(R.styleable.Animator_valueFrom);
+ TypedValue tvFrom = styledAttributes.peekValue(valueFromId);
boolean hasFrom = (tvFrom != null);
int fromType = hasFrom ? tvFrom.type : 0;
- TypedValue tvTo = arrayAnimator.peekValue(R.styleable.Animator_valueTo);
+ TypedValue tvTo = styledAttributes.peekValue(valueToId);
boolean hasTo = (tvTo != null);
int toType = hasTo ? tvTo.type : 0;
- // TODO: Further clean up this part of code into 4 types : path, color,
- // integer and float.
+ PropertyValuesHolder returnValue = null;
+
if (valueType == VALUE_TYPE_PATH) {
- evaluator = setupAnimatorForPath(anim, arrayAnimator);
+ String fromString = styledAttributes.getString(valueFromId);
+ String toString = styledAttributes.getString(valueToId);
+ PathParser.PathDataNode[] nodesFrom = PathParser.createNodesFromPathData(fromString);
+ PathParser.PathDataNode[] nodesTo = PathParser.createNodesFromPathData(toString);
+
+ if (nodesFrom != null || nodesTo != null) {
+ if (nodesFrom != null) {
+ TypeEvaluator evaluator =
+ new PathDataEvaluator(PathParser.deepCopyNodes(nodesFrom));
+ if (nodesTo != null) {
+ if (!PathParser.canMorph(nodesFrom, nodesTo)) {
+ throw new InflateException(" Can't morph from " + fromString + " to " +
+ toString);
+ }
+ returnValue = PropertyValuesHolder.ofObject(propertyName, evaluator,
+ nodesFrom, nodesTo);
+ } else {
+ returnValue = PropertyValuesHolder.ofObject(propertyName, evaluator,
+ (Object) nodesFrom);
+ }
+ } else if (nodesTo != null) {
+ TypeEvaluator evaluator =
+ new PathDataEvaluator(PathParser.deepCopyNodes(nodesTo));
+ returnValue = PropertyValuesHolder.ofObject(propertyName, evaluator,
+ (Object) nodesTo);
+ }
+ }
} else {
+ TypeEvaluator evaluator = null;
// Integer and float value types are handled here.
if ((hasFrom && (fromType >= TypedValue.TYPE_FIRST_COLOR_INT) &&
(fromType <= TypedValue.TYPE_LAST_COLOR_INT)) ||
@@ -338,7 +349,101 @@ public class AnimatorInflater {
getFloats = false;
evaluator = ArgbEvaluator.getInstance();
}
- setupValues(anim, arrayAnimator, getFloats, hasFrom, fromType, hasTo, toType);
+ if (getFloats) {
+ float valueFrom;
+ float valueTo;
+ if (hasFrom) {
+ if (fromType == TypedValue.TYPE_DIMENSION) {
+ valueFrom = styledAttributes.getDimension(valueFromId, 0f);
+ } else {
+ valueFrom = styledAttributes.getFloat(valueFromId, 0f);
+ }
+ if (hasTo) {
+ if (toType == TypedValue.TYPE_DIMENSION) {
+ valueTo = styledAttributes.getDimension(valueToId, 0f);
+ } else {
+ valueTo = styledAttributes.getFloat(valueToId, 0f);
+ }
+ returnValue = PropertyValuesHolder.ofFloat(propertyName,
+ valueFrom, valueTo);
+ } else {
+ returnValue = PropertyValuesHolder.ofFloat(propertyName, valueFrom);
+ }
+ } else {
+ if (toType == TypedValue.TYPE_DIMENSION) {
+ valueTo = styledAttributes.getDimension(valueToId, 0f);
+ } else {
+ valueTo = styledAttributes.getFloat(valueToId, 0f);
+ }
+ returnValue = PropertyValuesHolder.ofFloat(propertyName, valueTo);
+ }
+ } else {
+ int valueFrom;
+ int valueTo;
+ if (hasFrom) {
+ if (fromType == TypedValue.TYPE_DIMENSION) {
+ valueFrom = (int) styledAttributes.getDimension(valueFromId, 0f);
+ } else if ((fromType >= TypedValue.TYPE_FIRST_COLOR_INT) &&
+ (fromType <= TypedValue.TYPE_LAST_COLOR_INT)) {
+ valueFrom = styledAttributes.getColor(valueFromId, 0);
+ } else {
+ valueFrom = styledAttributes.getInt(valueFromId, 0);
+ }
+ if (hasTo) {
+ if (toType == TypedValue.TYPE_DIMENSION) {
+ valueTo = (int) styledAttributes.getDimension(valueToId, 0f);
+ } else if ((toType >= TypedValue.TYPE_FIRST_COLOR_INT) &&
+ (toType <= TypedValue.TYPE_LAST_COLOR_INT)) {
+ valueTo = styledAttributes.getColor(valueToId, 0);
+ } else {
+ valueTo = styledAttributes.getInt(valueToId, 0);
+ }
+ returnValue = PropertyValuesHolder.ofInt(propertyName, valueFrom, valueTo);
+ } else {
+ returnValue = PropertyValuesHolder.ofInt(propertyName, valueFrom);
+ }
+ } else {
+ if (hasTo) {
+ if (toType == TypedValue.TYPE_DIMENSION) {
+ valueTo = (int) styledAttributes.getDimension(valueToId, 0f);
+ } else if ((toType >= TypedValue.TYPE_FIRST_COLOR_INT) &&
+ (toType <= TypedValue.TYPE_LAST_COLOR_INT)) {
+ valueTo = styledAttributes.getColor(valueToId, 0);
+ } else {
+ valueTo = styledAttributes.getInt(valueToId, 0);
+ }
+ returnValue = PropertyValuesHolder.ofInt(propertyName, valueTo);
+ }
+ }
+ }
+ if (returnValue != null && evaluator != null) {
+ returnValue.setEvaluator(evaluator);
+ }
+ }
+
+ return returnValue;
+ }
+
+ /**
+ * @param anim The animator, must not be null
+ * @param arrayAnimator Incoming typed array for Animator's attributes.
+ * @param arrayObjectAnimator Incoming typed array for Object Animator's
+ * attributes.
+ * @param pixelSize The relative pixel size, used to calculate the
+ * maximum error for path animations.
+ */
+ private static void parseAnimatorFromTypeArray(ValueAnimator anim,
+ TypedArray arrayAnimator, TypedArray arrayObjectAnimator, float pixelSize) {
+ long duration = arrayAnimator.getInt(R.styleable.Animator_duration, 300);
+
+ long startDelay = arrayAnimator.getInt(R.styleable.Animator_startOffset, 0);
+
+ int valueType = arrayAnimator.getInt(R.styleable.Animator_valueType, VALUE_TYPE_FLOAT);
+
+ PropertyValuesHolder pvh = getPVH(arrayAnimator, valueType,
+ R.styleable.Animator_valueFrom, R.styleable.Animator_valueTo, "");
+ if (pvh != null) {
+ anim.setValues(pvh);
}
anim.setDuration(duration);
@@ -353,12 +458,10 @@ public class AnimatorInflater {
arrayAnimator.getInt(R.styleable.Animator_repeatMode,
ValueAnimator.RESTART));
}
- if (evaluator != null) {
- anim.setEvaluator(evaluator);
- }
if (arrayObjectAnimator != null) {
- setupObjectAnimator(anim, arrayObjectAnimator, getFloats, pixelSize);
+ setupObjectAnimator(anim, arrayObjectAnimator, valueType == VALUE_TYPE_FLOAT,
+ pixelSize);
}
}
@@ -570,6 +673,7 @@ public class AnimatorInflater {
}
String name = parser.getName();
+ boolean gotValues = false;
if (name.equals("objectAnimator")) {
anim = loadObjectAnimator(res, theme, attrs, pixelSize);
@@ -588,11 +692,18 @@ public class AnimatorInflater {
createAnimatorFromXml(res, theme, parser, attrs, (AnimatorSet) anim, ordering,
pixelSize);
a.recycle();
+ } else if (name.equals("propertyValuesHolder")) {
+ PropertyValuesHolder[] values = loadValues(res, theme, parser,
+ Xml.asAttributeSet(parser));
+ if (values != null && anim != null && (anim instanceof ValueAnimator)) {
+ ((ValueAnimator) anim).setValues(values);
+ }
+ gotValues = true;
} else {
throw new RuntimeException("Unknown animator name: " + parser.getName());
}
- if (parent != null) {
+ if (parent != null && !gotValues) {
if (childAnims == null) {
childAnims = new ArrayList<Animator>();
}
@@ -612,7 +723,233 @@ public class AnimatorInflater {
}
}
return anim;
+ }
+
+ private static PropertyValuesHolder[] loadValues(Resources res, Theme theme,
+ XmlPullParser parser, AttributeSet attrs) throws XmlPullParserException, IOException {
+ ArrayList<PropertyValuesHolder> values = null;
+
+ int type;
+ while ((type = parser.getEventType()) != XmlPullParser.END_TAG &&
+ type != XmlPullParser.END_DOCUMENT) {
+
+ if (type != XmlPullParser.START_TAG) {
+ parser.next();
+ continue;
+ }
+
+ String name = parser.getName();
+
+ if (name.equals("propertyValuesHolder")) {
+ TypedArray a;
+ if (theme != null) {
+ a = theme.obtainStyledAttributes(attrs, R.styleable.PropertyValuesHolder, 0, 0);
+ } else {
+ a = res.obtainAttributes(attrs, R.styleable.PropertyValuesHolder);
+ }
+ String propertyName = a.getString(R.styleable.PropertyValuesHolder_propertyName);
+ int valueType = a.getInt(R.styleable.PropertyValuesHolder_valueType,
+ VALUE_TYPE_FLOAT);
+ PropertyValuesHolder pvh = loadPvh(res, theme, parser, propertyName, valueType);
+ if (pvh == null) {
+ pvh = getPVH(a, valueType,
+ R.styleable.PropertyValuesHolder_valueFrom,
+ R.styleable.PropertyValuesHolder_valueTo, propertyName);
+ }
+ if (pvh != null) {
+ if (values == null) {
+ values = new ArrayList<PropertyValuesHolder>();
+ }
+ values.add(pvh);
+ }
+ a.recycle();
+ }
+
+ parser.next();
+ }
+
+ PropertyValuesHolder[] valuesArray = null;
+ if (values != null) {
+ int count = values.size();
+ valuesArray = new PropertyValuesHolder[count];
+ for (int i = 0; i < count; ++i) {
+ valuesArray[i] = values.get(i);
+ }
+ }
+ return valuesArray;
+ }
+
+ private static void dumpKeyframes(Object[] keyframes, String header) {
+ if (keyframes == null || keyframes.length == 0) {
+ return;
+ }
+ Log.d(TAG, header);
+ int count = keyframes.length;
+ for (int i = 0; i < count; ++i) {
+ Keyframe keyframe = (Keyframe) keyframes[i];
+ Log.d(TAG, "Keyframe " + i + ": fraction " +
+ (keyframe.getFraction() < 0 ? "null" : keyframe.getFraction()) + ", " +
+ ", value : " + ((keyframe.hasValue()) ? keyframe.getValue() : "null"));
+ }
+ }
+
+ private static PropertyValuesHolder loadPvh(Resources res, Theme theme, XmlPullParser parser,
+ String propertyName, int valueType)
+ throws XmlPullParserException, IOException {
+
+ PropertyValuesHolder value = null;
+ ArrayList<Keyframe> keyframes = null;
+
+ int type;
+ while ((type = parser.next()) != XmlPullParser.END_TAG &&
+ type != XmlPullParser.END_DOCUMENT) {
+ String name = parser.getName();
+ if (name.equals("keyframe")) {
+ Keyframe keyframe = loadKeyframe(res, theme, Xml.asAttributeSet(parser), valueType);
+ if (keyframe != null) {
+ if (keyframes == null) {
+ keyframes = new ArrayList<Keyframe>();
+ }
+ keyframes.add(keyframe);
+ }
+ parser.next();
+ }
+ }
+
+ int count;
+ if (keyframes != null && (count = keyframes.size()) > 0) {
+ // make sure we have keyframes at 0 and 1
+ // If we have keyframes with set fractions, add keyframes at start/end
+ // appropriately. If start/end have no set fractions:
+ // if there's only one keyframe, set its fraction to 1 and add one at 0
+ // if >1 keyframe, set the last fraction to 1, the first fraction to 0
+ Keyframe firstKeyframe = keyframes.get(0);
+ Keyframe lastKeyframe = keyframes.get(count - 1);
+ float endFraction = lastKeyframe.getFraction();
+ if (endFraction < 1) {
+ if (endFraction < 0) {
+ lastKeyframe.setFraction(1);
+ } else {
+ keyframes.add(keyframes.size(), createNewKeyframe(lastKeyframe, 1));
+ ++count;
+ }
+ }
+ float startFraction = firstKeyframe.getFraction();
+ if (startFraction != 0) {
+ if (startFraction < 0) {
+ firstKeyframe.setFraction(0);
+ } else {
+ keyframes.add(0, createNewKeyframe(firstKeyframe, 0));
+ ++count;
+ }
+ }
+ Keyframe[] keyframeArray = new Keyframe[count];
+ keyframes.toArray(keyframeArray);
+ for (int i = 0; i < count; ++i) {
+ Keyframe keyframe = keyframeArray[i];
+ if (keyframe.getFraction() < 0) {
+ if (i == 0) {
+ keyframe.setFraction(0);
+ } else if (i == count - 1) {
+ keyframe.setFraction(1);
+ } else {
+ // figure out the start/end parameters of the current gap
+ // in fractions and distribute the gap among those keyframes
+ int startIndex = i;
+ int endIndex = i;
+ for (int j = startIndex + 1; j < count - 1; ++j) {
+ if (keyframeArray[j].getFraction() >= 0) {
+ break;
+ }
+ endIndex = j;
+ }
+ float gap = keyframeArray[endIndex + 1].getFraction() -
+ keyframeArray[startIndex - 1].getFraction();
+ distributeKeyframes(keyframeArray, gap, startIndex, endIndex);
+ }
+ }
+ }
+ value = PropertyValuesHolder.ofKeyframe(propertyName, keyframeArray);
+ if (valueType == VALUE_TYPE_COLOR) {
+ value.setEvaluator(ArgbEvaluator.getInstance());
+ }
+ }
+
+ return value;
+ }
+
+ private static Keyframe createNewKeyframe(Keyframe sampleKeyframe, float fraction) {
+ return sampleKeyframe.getType() == float.class ?
+ Keyframe.ofFloat(fraction) :
+ (sampleKeyframe.getType() == int.class) ?
+ Keyframe.ofInt(fraction) :
+ Keyframe.ofObject(fraction);
+ }
+
+ /**
+ * Utility function to set fractions on keyframes to cover a gap in which the
+ * fractions are not currently set. Keyframe fractions will be distributed evenly
+ * in this gap. For example, a gap of 1 keyframe in the range 0-1 will be at .5, a gap
+ * of .6 spread between two keyframes will be at .2 and .4 beyond the fraction at the
+ * keyframe before startIndex.
+ * Assumptions:
+ * - First and last keyframe fractions (bounding this spread) are already set. So,
+ * for example, if no fractions are set, we will already set first and last keyframe
+ * fraction values to 0 and 1.
+ * - startIndex must be >0 (which follows from first assumption).
+ * - endIndex must be >= startIndex.
+ *
+ * @param keyframes the array of keyframes
+ * @param gap The total gap we need to distribute
+ * @param startIndex The index of the first keyframe whose fraction must be set
+ * @param endIndex The index of the last keyframe whose fraction must be set
+ */
+ private static void distributeKeyframes(Keyframe[] keyframes, float gap,
+ int startIndex, int endIndex) {
+ int count = endIndex - startIndex + 2;
+ float increment = gap / count;
+ for (int i = startIndex; i <= endIndex; ++i) {
+ keyframes[i].setFraction(keyframes[i-1].getFraction() + increment);
+ }
+ }
+
+ private static Keyframe loadKeyframe(Resources res, Theme theme, AttributeSet attrs,
+ int valueType)
+ throws XmlPullParserException, IOException {
+
+ TypedArray a;
+ if (theme != null) {
+ a = theme.obtainStyledAttributes(attrs, R.styleable.Keyframe, 0, 0);
+ } else {
+ a = res.obtainAttributes(attrs, R.styleable.Keyframe);
+ }
+
+ Keyframe keyframe = null;
+
+ float fraction = a.getFloat(R.styleable.Keyframe_fraction, -1);
+
+ boolean hasValue = a.peekValue(R.styleable.Keyframe_value) != null;
+
+ if (hasValue) {
+ switch (valueType) {
+ case VALUE_TYPE_FLOAT:
+ float value = a.getFloat(R.styleable.Keyframe_value, 0);
+ keyframe = Keyframe.ofFloat(fraction, value);
+ break;
+ case VALUE_TYPE_COLOR:
+ case VALUE_TYPE_INT:
+ int intValue = a.getInt(R.styleable.Keyframe_value, 0);
+ keyframe = Keyframe.ofInt(fraction, intValue);
+ break;
+ }
+ } else {
+ keyframe = (valueType == VALUE_TYPE_FLOAT) ? Keyframe.ofFloat(fraction) :
+ Keyframe.ofInt(fraction);
+ }
+
+ a.recycle();
+ return keyframe;
}
private static ObjectAnimator loadObjectAnimator(Resources res, Theme theme, AttributeSet attrs,
diff --git a/core/java/android/animation/AnimatorSet.java b/core/java/android/animation/AnimatorSet.java
index 92762c3..53d5237 100644
--- a/core/java/android/animation/AnimatorSet.java
+++ b/core/java/android/animation/AnimatorSet.java
@@ -972,6 +972,18 @@ public final class AnimatorSet extends Animator {
}
}
+ @Override
+ public String toString() {
+ String returnVal = "AnimatorSet@" + Integer.toHexString(hashCode()) + "{";
+ boolean prevNeedsSort = mNeedsSort;
+ sortNodes();
+ mNeedsSort = prevNeedsSort;
+ for (Node node : mSortedNodes) {
+ returnVal += "\n " + node.animation.toString();
+ }
+ return returnVal + "\n}";
+ }
+
/**
* Dependency holds information about the node that some other node is
* dependent upon and the nature of that dependency.
diff --git a/core/java/android/animation/ObjectAnimator.java b/core/java/android/animation/ObjectAnimator.java
index 59daaab..71855da 100644
--- a/core/java/android/animation/ObjectAnimator.java
+++ b/core/java/android/animation/ObjectAnimator.java
@@ -33,6 +33,27 @@ import java.util.ArrayList;
* are then determined internally and the animation will call these functions as necessary to
* animate the property.
*
+ * <p>Animators can be created from either code or resource files, as shown here:</p>
+ *
+ * {@sample development/samples/ApiDemos/res/anim/object_animator.xml ObjectAnimatorResources}
+ *
+ * <p>When using resource files, it is possible to use {@link PropertyValuesHolder} and
+ * {@link Keyframe} to create more complex animations. Using PropertyValuesHolders
+ * allows animators to animate several properties in parallel, as shown in this sample:</p>
+ *
+ * {@sample development/samples/ApiDemos/res/anim/object_animator_pvh.xml
+ * PropertyValuesHolderResources}
+ *
+ * <p>Using Keyframes allows animations to follow more complex paths from the start
+ * to the end values. Note that you can specify explicit fractional values (from 0 to 1) for
+ * each keyframe to determine when, in the overall duration, the animation should arrive at that
+ * value. Alternatively, you can leave the fractions off and the keyframes will be equally
+ * distributed within the total duration. Also, a keyframe with no value will derive its value
+ * from the target object when the animator starts, just like animators with only one
+ * value specified.</p>
+ *
+ * {@sample development/samples/ApiDemos/res/anim/object_animator_pvh_kf.xml KeyframeResources}
+ *
* <div class="special reference">
* <h3>Developer Guides</h3>
* <p>For more information about animating with {@code ObjectAnimator}, read the
diff --git a/core/java/android/animation/ValueAnimator.java b/core/java/android/animation/ValueAnimator.java
index 9709555..292bb1d 100644
--- a/core/java/android/animation/ValueAnimator.java
+++ b/core/java/android/animation/ValueAnimator.java
@@ -17,6 +17,7 @@
package android.animation;
import android.content.res.ConfigurationBoundResourceCache;
+import android.os.Debug;
import android.os.Looper;
import android.os.Trace;
import android.util.AndroidRuntimeException;
@@ -40,6 +41,21 @@ import java.util.HashMap;
* out of an animation. This behavior can be changed by calling
* {@link ValueAnimator#setInterpolator(TimeInterpolator)}.</p>
*
+ * <p>Animators can be created from either code or resource files. Here is an example
+ * of a ValueAnimator resource file:</p>
+ *
+ * {@sample development/samples/ApiDemos/res/anim/animator.xml ValueAnimatorResources}
+ *
+ * <p>It is also possible to use a combination of {@link PropertyValuesHolder} and
+ * {@link Keyframe} resource tags to create a multi-step animation.
+ * Note that you can specify explicit fractional values (from 0 to 1) for
+ * each keyframe to determine when, in the overall duration, the animation should arrive at that
+ * value. Alternatively, you can leave the fractions off and the keyframes will be equally
+ * distributed within the total duration:</p>
+ *
+ * {@sample development/samples/ApiDemos/res/anim/value_animator_pvh_kf.xml
+ * ValueAnimatorKeyframeResources}
+ *
* <div class="special reference">
* <h3>Developer Guides</h3>
* <p>For more information about animating with {@code ValueAnimator}, read the
diff --git a/core/java/android/app/Activity.java b/core/java/android/app/Activity.java
index 38cd126..23b05c4 100644
--- a/core/java/android/app/Activity.java
+++ b/core/java/android/app/Activity.java
@@ -362,7 +362,7 @@ import java.util.HashMap;
*
* <p>Note the "Killable" column in the above table -- for those methods that
* are marked as being killable, after that method returns the process hosting the
- * activity may killed by the system <em>at any time</em> without another line
+ * activity may be killed by the system <em>at any time</em> without another line
* of its code being executed. Because of this, you should use the
* {@link #onPause} method to write any persistent data (such as user edits)
* to storage. In addition, the method
@@ -1242,22 +1242,18 @@ public class Activity extends ContextThemeWrapper
}
/**
- * @hide
* Check whether this activity is running as part of a voice interaction with the user.
* If true, it should perform its interaction with the user through the
* {@link VoiceInteractor} returned by {@link #getVoiceInteractor}.
*/
- @SystemApi
public boolean isVoiceInteraction() {
return mVoiceInteractor != null;
}
/**
- * @hide
* Retrieve the active {@link VoiceInteractor} that the user is going through to
* interact with this activity.
*/
- @SystemApi
public VoiceInteractor getVoiceInteractor() {
return mVoiceInteractor;
}
@@ -6072,6 +6068,17 @@ public class Activity extends ContextThemeWrapper
" did not call through to super.onResume()");
}
+ // invisible activities must be finished before onResume() completes
+ if (!mVisibleFromClient && !mFinished) {
+ Log.w(TAG, "An activity without a UI must call finish() before onResume() completes");
+ if (getApplicationInfo().targetSdkVersion
+ > android.os.Build.VERSION_CODES.LOLLIPOP_MR1) {
+ throw new IllegalStateException(
+ "Activity " + mComponent.toShortString() +
+ " did not call finish() prior to onResume() completing");
+ }
+ }
+
// Now really resume, and install the current status bar and menu.
mCalled = false;
diff --git a/core/java/android/app/ActivityManagerNative.java b/core/java/android/app/ActivityManagerNative.java
index a7099d4..379fe11 100644
--- a/core/java/android/app/ActivityManagerNative.java
+++ b/core/java/android/app/ActivityManagerNative.java
@@ -690,14 +690,6 @@ public abstract class ActivityManagerNative extends Binder implements IActivityM
return true;
}
- case MOVE_TASK_TO_BACK_TRANSACTION: {
- data.enforceInterface(IActivityManager.descriptor);
- int task = data.readInt();
- moveTaskToBack(task);
- reply.writeNoException();
- return true;
- }
-
case MOVE_ACTIVITY_TASK_TO_BACK_TRANSACTION: {
data.enforceInterface(IActivityManager.descriptor);
IBinder token = data.readStrongBinder();
@@ -729,7 +721,6 @@ public abstract class ActivityManagerNative extends Binder implements IActivityM
case RESIZE_STACK_TRANSACTION: {
data.enforceInterface(IActivityManager.descriptor);
int stackId = data.readInt();
- float weight = data.readFloat();
Rect r = Rect.CREATOR.createFromParcel(data);
resizeStack(stackId, r);
reply.writeNoException();
@@ -2184,13 +2175,13 @@ public abstract class ActivityManagerNative extends Binder implements IActivityM
return true;
}
- case CREATE_ACTIVITY_CONTAINER_TRANSACTION: {
+ case CREATE_VIRTUAL_ACTIVITY_CONTAINER_TRANSACTION: {
data.enforceInterface(IActivityManager.descriptor);
IBinder parentActivityToken = data.readStrongBinder();
IActivityContainerCallback callback =
IActivityContainerCallback.Stub.asInterface(data.readStrongBinder());
IActivityContainer activityContainer =
- createActivityContainer(parentActivityToken, callback);
+ createVirtualActivityContainer(parentActivityToken, callback);
reply.writeNoException();
if (activityContainer != null) {
reply.writeInt(1);
@@ -2210,6 +2201,20 @@ public abstract class ActivityManagerNative extends Binder implements IActivityM
return true;
}
+ case CREATE_STACK_ON_DISPLAY: {
+ data.enforceInterface(IActivityManager.descriptor);
+ int displayId = data.readInt();
+ IActivityContainer activityContainer = createStackOnDisplay(displayId);
+ reply.writeNoException();
+ if (activityContainer != null) {
+ reply.writeInt(1);
+ reply.writeStrongBinder(activityContainer.asBinder());
+ } else {
+ reply.writeInt(0);
+ }
+ return true;
+ }
+
case GET_ACTIVITY_CONTAINER_TRANSACTION: {
data.enforceInterface(IActivityManager.descriptor);
IBinder activityToken = data.readStrongBinder();
@@ -3000,7 +3005,7 @@ class ActivityManagerProxy implements IActivityManager
ArrayList<IAppTask> list = null;
int N = reply.readInt();
if (N >= 0) {
- list = new ArrayList<IAppTask>();
+ list = new ArrayList<>();
while (N > 0) {
IAppTask task = IAppTask.Stub.asInterface(reply.readStrongBinder());
list.add(task);
@@ -3038,7 +3043,8 @@ class ActivityManagerProxy implements IActivityManager
reply.recycle();
return size;
}
- public List getTasks(int maxNum, int flags) throws RemoteException {
+ public List<ActivityManager.RunningTaskInfo> getTasks(int maxNum, int flags)
+ throws RemoteException {
Parcel data = Parcel.obtain();
Parcel reply = Parcel.obtain();
data.writeInterfaceToken(IActivityManager.descriptor);
@@ -3046,10 +3052,10 @@ class ActivityManagerProxy implements IActivityManager
data.writeInt(flags);
mRemote.transact(GET_TASKS_TRANSACTION, data, reply, 0);
reply.readException();
- ArrayList list = null;
+ ArrayList<ActivityManager.RunningTaskInfo> list = null;
int N = reply.readInt();
if (N >= 0) {
- list = new ArrayList();
+ list = new ArrayList<>();
while (N > 0) {
ActivityManager.RunningTaskInfo info =
ActivityManager.RunningTaskInfo.CREATOR
@@ -3093,7 +3099,8 @@ class ActivityManagerProxy implements IActivityManager
reply.recycle();
return taskThumbnail;
}
- public List getServices(int maxNum, int flags) throws RemoteException {
+ public List<ActivityManager.RunningServiceInfo> getServices(int maxNum, int flags)
+ throws RemoteException {
Parcel data = Parcel.obtain();
Parcel reply = Parcel.obtain();
data.writeInterfaceToken(IActivityManager.descriptor);
@@ -3101,10 +3108,10 @@ class ActivityManagerProxy implements IActivityManager
data.writeInt(flags);
mRemote.transact(GET_SERVICES_TRANSACTION, data, reply, 0);
reply.readException();
- ArrayList list = null;
+ ArrayList<ActivityManager.RunningServiceInfo> list = null;
int N = reply.readInt();
if (N >= 0) {
- list = new ArrayList();
+ list = new ArrayList<>();
while (N > 0) {
ActivityManager.RunningServiceInfo info =
ActivityManager.RunningServiceInfo.CREATOR
@@ -3174,17 +3181,6 @@ class ActivityManagerProxy implements IActivityManager
data.recycle();
reply.recycle();
}
- public void moveTaskToBack(int task) throws RemoteException
- {
- Parcel data = Parcel.obtain();
- Parcel reply = Parcel.obtain();
- data.writeInterfaceToken(IActivityManager.descriptor);
- data.writeInt(task);
- mRemote.transact(MOVE_TASK_TO_BACK_TRANSACTION, data, reply, 0);
- reply.readException();
- data.recycle();
- reply.recycle();
- }
public boolean moveActivityTaskToBack(IBinder token, boolean nonRoot)
throws RemoteException {
Parcel data = Parcel.obtain();
@@ -5217,14 +5213,14 @@ class ActivityManagerProxy implements IActivityManager
reply.recycle();
}
- public IActivityContainer createActivityContainer(IBinder parentActivityToken,
+ public IActivityContainer createVirtualActivityContainer(IBinder parentActivityToken,
IActivityContainerCallback callback) throws RemoteException {
Parcel data = Parcel.obtain();
Parcel reply = Parcel.obtain();
data.writeInterfaceToken(IActivityManager.descriptor);
data.writeStrongBinder(parentActivityToken);
data.writeStrongBinder(callback == null ? null : callback.asBinder());
- mRemote.transact(CREATE_ACTIVITY_CONTAINER_TRANSACTION, data, reply, 0);
+ mRemote.transact(CREATE_VIRTUAL_ACTIVITY_CONTAINER_TRANSACTION, data, reply, 0);
reply.readException();
final int result = reply.readInt();
final IActivityContainer res;
@@ -5250,6 +5246,25 @@ class ActivityManagerProxy implements IActivityManager
reply.recycle();
}
+ public IActivityContainer createStackOnDisplay(int displayId) throws RemoteException {
+ Parcel data = Parcel.obtain();
+ Parcel reply = Parcel.obtain();
+ data.writeInterfaceToken(IActivityManager.descriptor);
+ data.writeInt(displayId);
+ mRemote.transact(CREATE_STACK_ON_DISPLAY, data, reply, 0);
+ reply.readException();
+ final int result = reply.readInt();
+ final IActivityContainer res;
+ if (result == 1) {
+ res = IActivityContainer.Stub.asInterface(reply.readStrongBinder());
+ } else {
+ res = null;
+ }
+ data.recycle();
+ reply.recycle();
+ return res;
+ }
+
public IActivityContainer getEnclosingActivityContainer(IBinder activityToken)
throws RemoteException {
Parcel data = Parcel.obtain();
diff --git a/core/java/android/app/ActivityThread.java b/core/java/android/app/ActivityThread.java
index fb2bcd0..ea37b89 100644
--- a/core/java/android/app/ActivityThread.java
+++ b/core/java/android/app/ActivityThread.java
@@ -46,7 +46,6 @@ import android.graphics.Canvas;
import android.hardware.display.DisplayManagerGlobal;
import android.net.ConnectivityManager;
import android.net.IConnectivityManager;
-import android.net.LinkProperties;
import android.net.Network;
import android.net.Proxy;
import android.net.ProxyInfo;
@@ -87,8 +86,6 @@ import android.util.Slog;
import android.util.SuperNotCalledException;
import android.view.Display;
import android.view.HardwareRenderer;
-import android.view.IWindowManager;
-import android.view.IWindowSessionCallback;
import android.view.View;
import android.view.ViewDebug;
import android.view.ViewManager;
@@ -165,8 +162,8 @@ public final class ActivityThread {
private static final long MIN_TIME_BETWEEN_GCS = 5*1000;
private static final Pattern PATTERN_SEMICOLON = Pattern.compile(";");
private static final int SQLITE_MEM_RELEASED_EVENT_LOG_TAG = 75003;
- private static final int LOG_ON_PAUSE_CALLED = 30021;
- private static final int LOG_ON_RESUME_CALLED = 30022;
+ private static final int LOG_AM_ON_PAUSE_CALLED = 30021;
+ private static final int LOG_AM_ON_RESUME_CALLED = 30022;
/** Type for IActivityManager.serviceDoneExecuting: anonymous operation */
public static final int SERVICE_DONE_EXECUTING_ANON = 0;
@@ -3000,7 +2997,7 @@ public final class ActivityThread {
}
r.activity.performResume();
- EventLog.writeEvent(LOG_ON_RESUME_CALLED,
+ EventLog.writeEvent(LOG_AM_ON_RESUME_CALLED,
UserHandle.myUserId(), r.activity.getComponentName().getClassName());
r.paused = false;
@@ -3270,7 +3267,7 @@ public final class ActivityThread {
// Now we are idle.
r.activity.mCalled = false;
mInstrumentation.callActivityOnPause(r.activity);
- EventLog.writeEvent(LOG_ON_PAUSE_CALLED, UserHandle.myUserId(),
+ EventLog.writeEvent(LOG_AM_ON_PAUSE_CALLED, UserHandle.myUserId(),
r.activity.getComponentName().getClassName());
if (!r.activity.mCalled) {
throw new SuperNotCalledException(
@@ -3667,7 +3664,7 @@ public final class ActivityThread {
try {
r.activity.mCalled = false;
mInstrumentation.callActivityOnPause(r.activity);
- EventLog.writeEvent(LOG_ON_PAUSE_CALLED, UserHandle.myUserId(),
+ EventLog.writeEvent(LOG_AM_ON_PAUSE_CALLED, UserHandle.myUserId(),
r.activity.getComponentName().getClassName());
if (!r.activity.mCalled) {
throw new SuperNotCalledException(
diff --git a/core/java/android/app/ActivityView.java b/core/java/android/app/ActivityView.java
index 94ea2c5..6d455b1 100644
--- a/core/java/android/app/ActivityView.java
+++ b/core/java/android/app/ActivityView.java
@@ -83,7 +83,7 @@ public class ActivityView extends ViewGroup {
try {
mActivityContainer = new ActivityContainerWrapper(
- ActivityManagerNative.getDefault().createActivityContainer(
+ ActivityManagerNative.getDefault().createVirtualActivityContainer(
mActivity.getActivityToken(), new ActivityContainerCallback(this)));
} catch (RemoteException e) {
throw new RuntimeException("ActivityView: Unable to create ActivityContainer. "
diff --git a/core/java/android/app/ContextImpl.java b/core/java/android/app/ContextImpl.java
index 2ef046d..e9df8c6 100644
--- a/core/java/android/app/ContextImpl.java
+++ b/core/java/android/app/ContextImpl.java
@@ -80,6 +80,8 @@ import android.media.projection.MediaProjectionManager;
import android.media.session.MediaSessionManager;
import android.media.tv.ITvInputManager;
import android.media.tv.TvInputManager;
+import android.midi.IMidiManager;
+import android.midi.MidiManager;
import android.net.ConnectivityManager;
import android.net.IConnectivityManager;
import android.net.EthernetManager;
@@ -92,6 +94,8 @@ import android.net.nsd.INsdManager;
import android.net.nsd.NsdManager;
import android.net.wifi.IWifiManager;
import android.net.wifi.WifiManager;
+import android.net.wifi.passpoint.IWifiPasspointManager;
+import android.net.wifi.passpoint.WifiPasspointManager;
import android.net.wifi.p2p.IWifiP2pManager;
import android.net.wifi.p2p.WifiP2pManager;
import android.net.wifi.IWifiScanner;
@@ -603,6 +607,13 @@ class ContextImpl extends Context {
return new WifiManager(ctx.getOuterContext(), service);
}});
+ registerService(WIFI_PASSPOINT_SERVICE, new ServiceFetcher() {
+ public Object createService(ContextImpl ctx) {
+ IBinder b = ServiceManager.getService(WIFI_PASSPOINT_SERVICE);
+ IWifiPasspointManager service = IWifiPasspointManager.Stub.asInterface(b);
+ return new WifiPasspointManager(ctx.getOuterContext(), service);
+ }});
+
registerService(WIFI_P2P_SERVICE, new ServiceFetcher() {
public Object createService(ContextImpl ctx) {
IBinder b = ServiceManager.getService(WIFI_P2P_SERVICE);
@@ -768,6 +779,12 @@ class ContextImpl extends Context {
IBinder b = ServiceManager.getService(APPWIDGET_SERVICE);
return new AppWidgetManager(ctx, IAppWidgetService.Stub.asInterface(b));
}});
+
+ registerService(MIDI_SERVICE, new ServiceFetcher() {
+ public Object createService(ContextImpl ctx) {
+ IBinder b = ServiceManager.getService(MIDI_SERVICE);
+ return new MidiManager(ctx, IMidiManager.Stub.asInterface(b));
+ }});
}
static ContextImpl getImpl(Context context) {
diff --git a/core/java/android/app/DatePickerDialog.java b/core/java/android/app/DatePickerDialog.java
index f79d32b..3fbbdff 100644
--- a/core/java/android/app/DatePickerDialog.java
+++ b/core/java/android/app/DatePickerDialog.java
@@ -131,6 +131,9 @@ public class DatePickerDialog extends AlertDialog implements OnClickListener,
switch (which) {
case BUTTON_POSITIVE:
if (mDateSetListener != null) {
+ // Clearing focus forces the dialog to commit any pending
+ // changes, e.g. typed text in a NumberPicker.
+ mDatePicker.clearFocus();
mDateSetListener.onDateSet(mDatePicker, mDatePicker.getYear(),
mDatePicker.getMonth(), mDatePicker.getDayOfMonth());
}
diff --git a/core/java/android/app/IActivityManager.java b/core/java/android/app/IActivityManager.java
index 70c14c6..f152c6f 100644
--- a/core/java/android/app/IActivityManager.java
+++ b/core/java/android/app/IActivityManager.java
@@ -131,7 +131,6 @@ public interface IActivityManager extends IInterface {
public List<ActivityManager.ProcessErrorStateInfo> getProcessesInErrorState()
throws RemoteException;
public void moveTaskToFront(int task, int flags, Bundle options) throws RemoteException;
- public void moveTaskToBack(int task) throws RemoteException;
public boolean moveActivityTaskToBack(IBinder token, boolean nonRoot) throws RemoteException;
public void moveTaskBackwards(int task) throws RemoteException;
public void moveTaskToStack(int taskId, int stackId, boolean toTop) throws RemoteException;
@@ -434,9 +433,11 @@ public interface IActivityManager extends IInterface {
public void performIdleMaintenance() throws RemoteException;
- public IActivityContainer createActivityContainer(IBinder parentActivityToken,
+ public IActivityContainer createVirtualActivityContainer(IBinder parentActivityToken,
IActivityContainerCallback callback) throws RemoteException;
+ public IActivityContainer createStackOnDisplay(int displayId) throws RemoteException;
+
public void deleteActivityContainer(IActivityContainer container) throws RemoteException;
public IActivityContainer getEnclosingActivityContainer(IBinder activityToken)
@@ -599,7 +600,7 @@ public interface IActivityManager extends IInterface {
int GET_CALLING_ACTIVITY_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+21;
int GET_TASKS_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+22;
int MOVE_TASK_TO_FRONT_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+23;
- int MOVE_TASK_TO_BACK_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+24;
+
int MOVE_TASK_BACKWARDS_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+25;
int GET_TASK_FOR_ACTIVITY_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+26;
@@ -739,7 +740,7 @@ public interface IActivityManager extends IInterface {
int KILL_UID_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+164;
int SET_USER_IS_MONKEY_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+165;
int HANG_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+166;
- int CREATE_ACTIVITY_CONTAINER_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+167;
+ int CREATE_VIRTUAL_ACTIVITY_CONTAINER_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+167;
int MOVE_TASK_TO_STACK_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+168;
int RESIZE_STACK_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+169;
int GET_ALL_STACK_INFOS_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+170;
@@ -798,4 +799,5 @@ public interface IActivityManager extends IInterface {
// Start of M transactions
int NOTIFY_CLEARTEXT_NETWORK_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+280;
+ int CREATE_STACK_ON_DISPLAY = IBinder.FIRST_CALL_TRANSACTION+281;
}
diff --git a/core/java/android/app/VoiceInteractor.java b/core/java/android/app/VoiceInteractor.java
index 723cb9b..7f9693f 100644
--- a/core/java/android/app/VoiceInteractor.java
+++ b/core/java/android/app/VoiceInteractor.java
@@ -16,7 +16,6 @@
package android.app;
-import android.annotation.SystemApi;
import android.content.Context;
import android.os.Bundle;
import android.os.IBinder;
@@ -34,7 +33,6 @@ import com.android.internal.os.SomeArgs;
import java.util.ArrayList;
/**
- * @hide
* Interface for an {@link Activity} to interact with the user through voice. Use
* {@link android.app.Activity#getVoiceInteractor() Activity.getVoiceInteractor}
* to retrieve the interface, if the activity is currently involved in a voice interaction.
@@ -56,7 +54,6 @@ import java.util.ArrayList;
* request, rather than holding on to the activity instance yourself, either explicitly
* or implicitly through a non-static inner class.
*/
-@SystemApi
public class VoiceInteractor {
static final String TAG = "VoiceInteractor";
static final boolean DEBUG = true;
@@ -108,9 +105,10 @@ public class VoiceInteractor {
request = pullRequest((IVoiceInteractorRequest)args.arg1, msg.arg1 != 0);
if (DEBUG) Log.d(TAG, "onCommandResult: req="
+ ((IVoiceInteractorRequest)args.arg1).asBinder() + "/" + request
- + " result=" + args.arg2);
+ + " completed=" + msg.arg1 + " result=" + args.arg2);
if (request != null) {
- ((CommandRequest)request).onCommandResult((Bundle) args.arg2);
+ ((CommandRequest)request).onCommandResult(msg.arg1 != 0,
+ (Bundle) args.arg2);
if (msg.arg1 != 0) {
request.clear();
}
@@ -321,7 +319,7 @@ public class VoiceInteractor {
* complete an action (e.g. booking a table might have several possible times that the
* user could select from or an app might need the user to agree to a terms of service).
* The result of the confirmation will be returned through an asynchronous call to
- * either {@link #onCommandResult(android.os.Bundle)} or
+ * either {@link #onCommandResult(boolean, android.os.Bundle)} or
* {@link #onCancel()}.
*
* <p>The command is a string that describes the generic operation to be performed.
@@ -338,7 +336,12 @@ public class VoiceInteractor {
mArgs = args;
}
- public void onCommandResult(Bundle result) {
+ /**
+ * Results for CommandRequest can be returned in partial chunks.
+ * The isCompleted is set to true iff all results have been returned, indicating the
+ * CommandRequest has completed.
+ */
+ public void onCommandResult(boolean isCompleted, Bundle result) {
}
IVoiceInteractorRequest submit(IVoiceInteractor interactor, String packageName,
diff --git a/core/java/android/app/admin/DevicePolicyManager.java b/core/java/android/app/admin/DevicePolicyManager.java
index 1ed709b..55c3960 100644
--- a/core/java/android/app/admin/DevicePolicyManager.java
+++ b/core/java/android/app/admin/DevicePolicyManager.java
@@ -52,11 +52,15 @@ import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Proxy;
+import java.security.KeyFactory;
import java.security.PrivateKey;
import java.security.cert.Certificate;
import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
+import java.security.spec.PKCS8EncodedKeySpec;
+import java.security.spec.InvalidKeySpecException;
+import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@@ -1934,13 +1938,15 @@ public class DevicePolicyManager {
String alias) {
try {
final byte[] pemCert = Credentials.convertToPem(cert);
- return mService.installKeyPair(who, privKey.getEncoded(), pemCert, alias);
- } catch (CertificateException e) {
- Log.w(TAG, "Error encoding certificate", e);
- } catch (IOException e) {
- Log.w(TAG, "Error writing certificate", e);
+ final byte[] pkcs8Key = KeyFactory.getInstance(privKey.getAlgorithm())
+ .getKeySpec(privKey, PKCS8EncodedKeySpec.class).getEncoded();
+ return mService.installKeyPair(who, pkcs8Key, pemCert, alias);
} catch (RemoteException e) {
Log.w(TAG, "Failed talking with device policy service", e);
+ } catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
+ Log.w(TAG, "Failed to obtain private key material", e);
+ } catch (CertificateException | IOException e) {
+ Log.w(TAG, "Could not pem-encode certificate", e);
}
return false;
}
@@ -2417,27 +2423,6 @@ public class DevicePolicyManager {
}
/**
- * @deprecated Use setProfileOwner(ComponentName ...)
- * @hide
- * Sets the given package as the profile owner of the given user profile. The package must
- * already be installed and there shouldn't be an existing profile owner registered for this
- * user. Also, this method must be called before the user has been used for the first time.
- * @param packageName the package name of the application to be registered as profile owner.
- * @param ownerName the human readable name of the organisation associated with this DPM.
- * @param userHandle the userId to set the profile owner for.
- * @return whether the package was successfully registered as the profile owner.
- * @throws IllegalArgumentException if packageName is null, the package isn't installed, or
- * the user has already been set up.
- */
- public boolean setProfileOwner(String packageName, String ownerName, int userHandle)
- throws IllegalArgumentException {
- if (packageName == null) {
- throw new NullPointerException("packageName cannot be null");
- }
- return setProfileOwner(new ComponentName(packageName, ""), ownerName, userHandle);
- }
-
- /**
* @hide
* Sets the given component as the profile owner of the given user profile. The package must
* already be installed and there shouldn't be an existing profile owner registered for this
diff --git a/core/java/android/appwidget/AppWidgetHost.java b/core/java/android/appwidget/AppWidgetHost.java
index 8e86824..1af4953 100644
--- a/core/java/android/appwidget/AppWidgetHost.java
+++ b/core/java/android/appwidget/AppWidgetHost.java
@@ -16,6 +16,7 @@
package android.appwidget;
+import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.HashMap;
@@ -58,18 +59,28 @@ public class AppWidgetHost {
private DisplayMetrics mDisplayMetrics;
private String mContextOpPackageName;
- Handler mHandler;
- int mHostId;
- Callbacks mCallbacks = new Callbacks();
- final HashMap<Integer,AppWidgetHostView> mViews = new HashMap<Integer, AppWidgetHostView>();
+ private final Handler mHandler;
+ private final int mHostId;
+ private final Callbacks mCallbacks;
+ private final HashMap<Integer,AppWidgetHostView> mViews = new HashMap<>();
private OnClickHandler mOnClickHandler;
- class Callbacks extends IAppWidgetHost.Stub {
+ static class Callbacks extends IAppWidgetHost.Stub {
+ private final WeakReference<Handler> mWeakHandler;
+
+ public Callbacks(Handler handler) {
+ mWeakHandler = new WeakReference<>(handler);
+ }
+
public void updateAppWidget(int appWidgetId, RemoteViews views) {
if (isLocalBinder() && views != null) {
views = views.clone();
}
- Message msg = mHandler.obtainMessage(HANDLE_UPDATE, appWidgetId, 0, views);
+ Handler handler = mWeakHandler.get();
+ if (handler == null) {
+ return;
+ }
+ Message msg = handler.obtainMessage(HANDLE_UPDATE, appWidgetId, 0, views);
msg.sendToTarget();
}
@@ -77,20 +88,36 @@ public class AppWidgetHost {
if (isLocalBinder() && info != null) {
info = info.clone();
}
- Message msg = mHandler.obtainMessage(HANDLE_PROVIDER_CHANGED,
+ Handler handler = mWeakHandler.get();
+ if (handler == null) {
+ return;
+ }
+ Message msg = handler.obtainMessage(HANDLE_PROVIDER_CHANGED,
appWidgetId, 0, info);
msg.sendToTarget();
}
public void providersChanged() {
- mHandler.obtainMessage(HANDLE_PROVIDERS_CHANGED).sendToTarget();
+ Handler handler = mWeakHandler.get();
+ if (handler == null) {
+ return;
+ }
+ handler.obtainMessage(HANDLE_PROVIDERS_CHANGED).sendToTarget();
}
public void viewDataChanged(int appWidgetId, int viewId) {
- Message msg = mHandler.obtainMessage(HANDLE_VIEW_DATA_CHANGED,
+ Handler handler = mWeakHandler.get();
+ if (handler == null) {
+ return;
+ }
+ Message msg = handler.obtainMessage(HANDLE_VIEW_DATA_CHANGED,
appWidgetId, viewId);
msg.sendToTarget();
}
+
+ private static boolean isLocalBinder() {
+ return Process.myPid() == Binder.getCallingPid();
+ }
}
class UpdateHandler extends Handler {
@@ -132,6 +159,7 @@ public class AppWidgetHost {
mHostId = hostId;
mOnClickHandler = handler;
mHandler = new UpdateHandler(looper);
+ mCallbacks = new Callbacks(mHandler);
mDisplayMetrics = context.getResources().getDisplayMetrics();
bindService();
}
@@ -251,10 +279,6 @@ public class AppWidgetHost {
}
}
- private boolean isLocalBinder() {
- return Process.myPid() == Binder.getCallingPid();
- }
-
/**
* Stop listening to changes for this AppWidget.
*/
diff --git a/core/java/android/appwidget/AppWidgetHostView.java b/core/java/android/appwidget/AppWidgetHostView.java
index 1ff476e..022e225 100644
--- a/core/java/android/appwidget/AppWidgetHostView.java
+++ b/core/java/android/appwidget/AppWidgetHostView.java
@@ -588,9 +588,10 @@ public class AppWidgetHostView extends FrameLayout {
return tv;
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
- super.onInitializeAccessibilityNodeInfo(info);
+ public void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) {
+ super.onInitializeAccessibilityNodeInfoInternal(info);
info.setClassName(AppWidgetHostView.class.getName());
}
diff --git a/core/java/android/bluetooth/BluetoothHeadsetClientCall.java b/core/java/android/bluetooth/BluetoothHeadsetClientCall.java
index a15bd97..7b5a045 100644
--- a/core/java/android/bluetooth/BluetoothHeadsetClientCall.java
+++ b/core/java/android/bluetooth/BluetoothHeadsetClientCall.java
@@ -61,6 +61,7 @@ public final class BluetoothHeadsetClientCall implements Parcelable {
*/
public static final int CALL_STATE_TERMINATED = 7;
+ private final BluetoothDevice mDevice;
private final int mId;
private int mState;
private String mNumber;
@@ -70,8 +71,9 @@ public final class BluetoothHeadsetClientCall implements Parcelable {
/**
* Creates BluetoothHeadsetClientCall instance.
*/
- public BluetoothHeadsetClientCall(int id, int state, String number, boolean multiParty,
- boolean outgoing) {
+ public BluetoothHeadsetClientCall(BluetoothDevice device, int id, int state, String number,
+ boolean multiParty, boolean outgoing) {
+ mDevice = device;
mId = id;
mState = state;
mNumber = number != null ? number : "";
@@ -114,6 +116,15 @@ public final class BluetoothHeadsetClientCall implements Parcelable {
}
/**
+ * Gets call's device.
+ *
+ * @return call device.
+ */
+ public BluetoothDevice getDevice() {
+ return mDevice;
+ }
+
+ /**
* Gets call's Id.
*
* @return call id.
@@ -161,7 +172,9 @@ public final class BluetoothHeadsetClientCall implements Parcelable {
}
public String toString() {
- StringBuilder builder = new StringBuilder("BluetoothHeadsetClientCall{mId: ");
+ StringBuilder builder = new StringBuilder("BluetoothHeadsetClientCall{mDevice: ");
+ builder.append(mDevice);
+ builder.append(", mId: ");
builder.append(mId);
builder.append(", mState: ");
switch (mState) {
@@ -192,8 +205,9 @@ public final class BluetoothHeadsetClientCall implements Parcelable {
new Parcelable.Creator<BluetoothHeadsetClientCall>() {
@Override
public BluetoothHeadsetClientCall createFromParcel(Parcel in) {
- return new BluetoothHeadsetClientCall(in.readInt(), in.readInt(),
- in.readString(), in.readInt() == 1, in.readInt() == 1);
+ return new BluetoothHeadsetClientCall((BluetoothDevice)in.readParcelable(null),
+ in.readInt(), in.readInt(), in.readString(),
+ in.readInt() == 1, in.readInt() == 1);
}
@Override
@@ -204,6 +218,7 @@ public final class BluetoothHeadsetClientCall implements Parcelable {
@Override
public void writeToParcel(Parcel out, int flags) {
+ out.writeParcelable(mDevice, 0);
out.writeInt(mId);
out.writeInt(mState);
out.writeString(mNumber);
diff --git a/core/java/android/content/ContentProviderOperation.java b/core/java/android/content/ContentProviderOperation.java
index 136e54d..49ac062 100644
--- a/core/java/android/content/ContentProviderOperation.java
+++ b/core/java/android/content/ContentProviderOperation.java
@@ -208,6 +208,22 @@ public class ContentProviderOperation implements Parcelable {
return mType;
}
+ public boolean isInsert() {
+ return mType == TYPE_INSERT;
+ }
+
+ public boolean isDelete() {
+ return mType == TYPE_DELETE;
+ }
+
+ public boolean isUpdate() {
+ return mType == TYPE_UPDATE;
+ }
+
+ public boolean isAssertQuery() {
+ return mType == TYPE_ASSERT;
+ }
+
public boolean isWriteOperation() {
return mType == TYPE_DELETE || mType == TYPE_INSERT || mType == TYPE_UPDATE;
}
diff --git a/core/java/android/content/Context.java b/core/java/android/content/Context.java
index 26735a6..dec2524 100644
--- a/core/java/android/content/Context.java
+++ b/core/java/android/content/Context.java
@@ -24,6 +24,7 @@ import android.annotation.SystemApi;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.res.AssetManager;
+import android.content.res.ColorStateList;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.content.res.TypedArray;
@@ -146,12 +147,13 @@ public abstract class Context {
@IntDef(flag = true,
value = {
BIND_AUTO_CREATE,
- BIND_AUTO_CREATE,
BIND_DEBUG_UNBIND,
BIND_NOT_FOREGROUND,
BIND_ABOVE_CLIENT,
BIND_ALLOW_OOM_MANAGEMENT,
- BIND_WAIVE_PRIORITY
+ BIND_WAIVE_PRIORITY,
+ BIND_IMPORTANT,
+ BIND_ADJUST_WITH_ACTIVITY
})
@Retention(RetentionPolicy.SOURCE)
public @interface BindServiceFlags {}
@@ -391,18 +393,55 @@ public abstract class Context {
}
/**
- * Return a drawable object associated with a particular resource ID and
+ * Returns a color associated with a particular resource ID and styled for
+ * the current theme.
+ *
+ * @param id The desired resource identifier, as generated by the aapt
+ * tool. This integer encodes the package, type, and resource
+ * entry. The value 0 is an invalid identifier.
+ * @return A single color value in the form 0xAARRGGBB.
+ * @throws android.content.res.Resources.NotFoundException if the given ID
+ * does not exist.
+ */
+ @Nullable
+ public final int getColor(int id) {
+ return getResources().getColor(id, getTheme());
+ }
+
+ /**
+ * Returns a drawable object associated with a particular resource ID and
* styled for the current theme.
*
* @param id The desired resource identifier, as generated by the aapt
* tool. This integer encodes the package, type, and resource
* entry. The value 0 is an invalid identifier.
- * @return Drawable An object that can be used to draw this resource.
+ * @return An object that can be used to draw this resource, or
+ * {@code null} if the resource could not be resolved.
+ * @throws android.content.res.Resources.NotFoundException if the given ID
+ * does not exist.
*/
+ @Nullable
public final Drawable getDrawable(int id) {
return getResources().getDrawable(id, getTheme());
}
+ /**
+ * Returns a color state list associated with a particular resource ID and
+ * styled for the current theme.
+ *
+ * @param id The desired resource identifier, as generated by the aapt
+ * tool. This integer encodes the package, type, and resource
+ * entry. The value 0 is an invalid identifier.
+ * @return A color state list, or {@code null} if the resource could not be
+ * resolved.
+ * @throws android.content.res.Resources.NotFoundException if the given ID
+ * does not exist.
+ */
+ @Nullable
+ public final ColorStateList getColorStateList(int id) {
+ return getResources().getColorStateList(id, getTheme());
+ }
+
/**
* Set the base theme for this context. Note that this should be called
* before any views are instantiated in the Context (for example before
@@ -2143,6 +2182,7 @@ public abstract class Context {
BATTERY_SERVICE,
JOB_SCHEDULER_SERVICE,
MEDIA_PROJECTION_SERVICE,
+ MIDI_SERVICE,
})
@Retention(RetentionPolicy.SOURCE)
public @interface ServiceName {}
@@ -2916,6 +2956,15 @@ public abstract class Context {
public static final String MEDIA_PROJECTION_SERVICE = "media_projection";
/**
+ * Use with {@link #getSystemService} to retrieve a
+ * {@link android.midi.MidiManager} for accessing the MIDI service.
+ *
+ * @see #getSystemService
+ * @hide
+ */
+ public static final String MIDI_SERVICE = "midi";
+
+ /**
* Determine whether the given permission is allowed for a particular
* process and user ID running in the system.
*
diff --git a/core/java/android/content/Intent.java b/core/java/android/content/Intent.java
index 2fe727c..37a46be 100644
--- a/core/java/android/content/Intent.java
+++ b/core/java/android/content/Intent.java
@@ -2808,14 +2808,12 @@ public class Intent implements Parcelable, Cloneable {
@SdkConstant(SdkConstantType.INTENT_CATEGORY)
public static final String CATEGORY_BROWSABLE = "android.intent.category.BROWSABLE";
/**
- * @hide
* Categories for activities that can participate in voice interaction.
* An activity that supports this category must be prepared to run with
* no UI shown at all (though in some case it may have a UI shown), and
* rely on {@link android.app.VoiceInteractor} to interact with the user.
*/
@SdkConstant(SdkConstantType.INTENT_CATEGORY)
- @SystemApi
public static final String CATEGORY_VOICE = "android.intent.category.VOICE";
/**
* Set if the activity should be considered as an alternative action to
diff --git a/core/java/android/content/res/ColorStateList.java b/core/java/android/content/res/ColorStateList.java
index 68a39d3..b42d8bc 100644
--- a/core/java/android/content/res/ColorStateList.java
+++ b/core/java/android/content/res/ColorStateList.java
@@ -16,8 +16,12 @@
package android.content.res;
+import android.annotation.NonNull;
+import android.annotation.Nullable;
+import android.content.res.Resources.Theme;
import android.graphics.Color;
+import com.android.internal.R;
import com.android.internal.util.ArrayUtils;
import com.android.internal.util.GrowingArrayUtils;
@@ -25,6 +29,7 @@ import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import android.util.AttributeSet;
+import android.util.Log;
import android.util.MathUtils;
import android.util.SparseArray;
import android.util.StateSet;
@@ -64,15 +69,23 @@ import java.util.Arrays;
* List Resource</a>.</p>
*/
public class ColorStateList implements Parcelable {
- private int[][] mStateSpecs; // must be parallel to mColors
- private int[] mColors; // must be parallel to mStateSpecs
- private int mDefaultColor = 0xffff0000;
-
+ private static final String TAG = "ColorStateList";
+ private static final int DEFAULT_COLOR = Color.RED;
private static final int[][] EMPTY = new int[][] { new int[0] };
private static final SparseArray<WeakReference<ColorStateList>> sCache =
new SparseArray<WeakReference<ColorStateList>>();
- private ColorStateList() { }
+ private int[][] mThemeAttrs;
+ private int mChangingConfigurations;
+
+ private int[][] mStateSpecs;
+ private int[] mColors;
+ private int mDefaultColor;
+ private boolean mIsOpaque;
+
+ private ColorStateList() {
+ // Not publicly instantiable.
+ }
/**
* Creates a ColorStateList that returns the specified mapping from
@@ -82,53 +95,102 @@ public class ColorStateList implements Parcelable {
mStateSpecs = states;
mColors = colors;
- if (states.length > 0) {
- mDefaultColor = colors[0];
-
- for (int i = 0; i < states.length; i++) {
- if (states[i].length == 0) {
- mDefaultColor = colors[i];
- }
- }
- }
+ onColorsChanged();
}
/**
- * Creates or retrieves a ColorStateList that always returns a single color.
+ * @return A ColorStateList containing a single color.
*/
+ @NonNull
public static ColorStateList valueOf(int color) {
- // TODO: should we collect these eventually?
synchronized (sCache) {
- final WeakReference<ColorStateList> ref = sCache.get(color);
+ final int index = sCache.indexOfKey(color);
+ if (index >= 0) {
+ final ColorStateList cached = sCache.valueAt(index).get();
+ if (cached != null) {
+ return cached;
+ }
- ColorStateList csl = ref != null ? ref.get() : null;
- if (csl != null) {
- return csl;
+ // Prune missing entry.
+ sCache.removeAt(index);
}
- csl = new ColorStateList(EMPTY, new int[] { color });
+ // Prune the cache before adding new items.
+ final int N = sCache.size();
+ for (int i = N - 1; i >= 0; i--) {
+ if (sCache.valueAt(i).get() == null) {
+ sCache.removeAt(i);
+ }
+ }
+
+ final ColorStateList csl = new ColorStateList(EMPTY, new int[] { color });
sCache.put(color, new WeakReference<ColorStateList>(csl));
return csl;
}
}
/**
- * Create a ColorStateList from an XML document, given a set of {@link Resources}.
+ * Creates a ColorStateList with the same properties as another
+ * ColorStateList.
+ * <p>
+ * The properties of the new ColorStateList can be modified without
+ * affecting the source ColorStateList.
+ *
+ * @param orig the source color state list
*/
+ private ColorStateList(ColorStateList orig) {
+ if (orig != null) {
+ mStateSpecs = orig.mStateSpecs;
+ mDefaultColor = orig.mDefaultColor;
+ mIsOpaque = orig.mIsOpaque;
+
+ // Deep copy, this may change due to theming.
+ mColors = orig.mColors.clone();
+ }
+ }
+
+ /**
+ * Creates a ColorStateList from an XML document.
+ *
+ * @param r Resources against which the ColorStateList should be inflated.
+ * @param parser Parser for the XML document defining the ColorStateList.
+ * @return A new color state list.
+ *
+ * @deprecated Use #createFromXml(Resources, XmlPullParser parser, Theme)
+ */
+ @NonNull
+ @Deprecated
public static ColorStateList createFromXml(Resources r, XmlPullParser parser)
throws XmlPullParserException, IOException {
+ return createFromXml(r, parser, null);
+ }
+
+ /**
+ * Creates a ColorStateList from an XML document using given a set of
+ * {@link Resources} and a {@link Theme}.
+ *
+ * @param r Resources against which the ColorStateList should be inflated.
+ * @param parser Parser for the XML document defining the ColorStateList.
+ * @param theme Optional theme to apply to the color state list, may be
+ * {@code null}.
+ * @return A new color state list.
+ */
+ @NonNull
+ public static ColorStateList createFromXml(@NonNull Resources r, @NonNull XmlPullParser parser,
+ @Nullable Theme theme) throws XmlPullParserException, IOException {
final AttributeSet attrs = Xml.asAttributeSet(parser);
int type;
- while ((type=parser.next()) != XmlPullParser.START_TAG
+ while ((type = parser.next()) != XmlPullParser.START_TAG
&& type != XmlPullParser.END_DOCUMENT) {
+ // Seek parser to start tag.
}
if (type != XmlPullParser.START_TAG) {
throw new XmlPullParserException("No start tag found");
}
- return createFromXmlInner(r, parser, attrs);
+ return createFromXmlInner(r, parser, attrs, theme);
}
/**
@@ -136,28 +198,31 @@ public class ColorStateList implements Parcelable {
* tag in an XML document, tries to create a ColorStateList from that tag.
*
* @throws XmlPullParserException if the current tag is not &lt;selector>
- * @return A color state list for the current tag.
+ * @return A new color state list for the current tag.
*/
- private static ColorStateList createFromXmlInner(Resources r, XmlPullParser parser,
- AttributeSet attrs) throws XmlPullParserException, IOException {
- final ColorStateList colorStateList;
+ @NonNull
+ private static ColorStateList createFromXmlInner(@NonNull Resources r,
+ @NonNull XmlPullParser parser, @NonNull AttributeSet attrs, @Nullable Theme theme)
+ throws XmlPullParserException, IOException {
final String name = parser.getName();
- if (name.equals("selector")) {
- colorStateList = new ColorStateList();
- } else {
+ if (!name.equals("selector")) {
throw new XmlPullParserException(
- parser.getPositionDescription() + ": invalid drawable tag " + name);
+ parser.getPositionDescription() + ": invalid color state list tag " + name);
}
- colorStateList.inflate(r, parser, attrs);
+ final ColorStateList colorStateList = new ColorStateList();
+ colorStateList.inflate(r, parser, attrs, theme);
return colorStateList;
}
/**
- * Creates a new ColorStateList that has the same states and
- * colors as this one but where each color has the specified alpha value
- * (0-255).
+ * Creates a new ColorStateList that has the same states and colors as this
+ * one but where each color has the specified alpha value (0-255).
+ *
+ * @param alpha The new alpha channel value (0-255).
+ * @return A new color state list.
*/
+ @NonNull
public ColorStateList withAlpha(int alpha) {
final int[] colors = new int[mColors.length];
final int len = colors.length;
@@ -171,88 +236,154 @@ public class ColorStateList implements Parcelable {
/**
* Fill in this object based on the contents of an XML "selector" element.
*/
- private void inflate(Resources r, XmlPullParser parser, AttributeSet attrs)
+ private void inflate(@NonNull Resources r, @NonNull XmlPullParser parser,
+ @NonNull AttributeSet attrs, @Nullable Theme theme)
throws XmlPullParserException, IOException {
- int type;
-
final int innerDepth = parser.getDepth()+1;
int depth;
+ int type;
+
+ int changingConfigurations = 0;
+ int defaultColor = DEFAULT_COLOR;
+
+ boolean hasUnresolvedAttrs = false;
int[][] stateSpecList = ArrayUtils.newUnpaddedArray(int[].class, 20);
+ int[][] themeAttrsList = new int[stateSpecList.length][];
int[] colorList = new int[stateSpecList.length];
int listSize = 0;
- while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
- && ((depth=parser.getDepth()) >= innerDepth
- || type != XmlPullParser.END_TAG)) {
- if (type != XmlPullParser.START_TAG) {
+ while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
+ && ((depth = parser.getDepth()) >= innerDepth || type != XmlPullParser.END_TAG)) {
+ if (type != XmlPullParser.START_TAG || depth > innerDepth
+ || !parser.getName().equals("item")) {
continue;
}
- if (depth > innerDepth || !parser.getName().equals("item")) {
- continue;
- }
+ final TypedArray a = Resources.obtainAttributes(r, theme, attrs,
+ R.styleable.ColorStateListItem);
+ final int[] themeAttrs = a.extractThemeAttrs();
+ final int baseColor = a.getColor(R.styleable.ColorStateListItem_color, 0);
+ final float alphaMod = a.getFloat(R.styleable.ColorStateListItem_alpha, 1.0f);
+
+ changingConfigurations |= a.getChangingConfigurations();
- int alphaRes = 0;
- float alpha = 1.0f;
- int colorRes = 0;
- int color = 0xffff0000;
- boolean haveColor = false;
+ a.recycle();
- int i;
+ // Parse all unrecognized attributes as state specifiers.
int j = 0;
final int numAttrs = attrs.getAttributeCount();
int[] stateSpec = new int[numAttrs];
- for (i = 0; i < numAttrs; i++) {
+ for (int i = 0; i < numAttrs; i++) {
final int stateResId = attrs.getAttributeNameResource(i);
- if (stateResId == 0) break;
- if (stateResId == com.android.internal.R.attr.alpha) {
- alphaRes = attrs.getAttributeResourceValue(i, 0);
- if (alphaRes == 0) {
- alpha = attrs.getAttributeFloatValue(i, 1.0f);
- }
- } else if (stateResId == com.android.internal.R.attr.color) {
- colorRes = attrs.getAttributeResourceValue(i, 0);
- if (colorRes == 0) {
- color = attrs.getAttributeIntValue(i, color);
- haveColor = true;
- }
- } else {
- stateSpec[j++] = attrs.getAttributeBooleanValue(i, false)
- ? stateResId : -stateResId;
+ switch (stateResId) {
+ case R.attr.color:
+ case R.attr.alpha:
+ // Recognized attribute, ignore.
+ break;
+ default:
+ stateSpec[j++] = attrs.getAttributeBooleanValue(i, false)
+ ? stateResId : -stateResId;
}
}
stateSpec = StateSet.trimStateSet(stateSpec, j);
- if (colorRes != 0) {
- color = r.getColor(colorRes);
- } else if (!haveColor) {
- throw new XmlPullParserException(
- parser.getPositionDescription()
- + ": <item> tag requires a 'android:color' attribute.");
- }
-
- if (alphaRes != 0) {
- alpha = r.getFloat(alphaRes);
- }
-
// Apply alpha modulation.
- final int alphaMod = MathUtils.constrain((int) (Color.alpha(color) * alpha), 0, 255);
- color = (color & 0xFFFFFF) | (alphaMod << 24);
-
+ final int color = modulateColorAlpha(baseColor, alphaMod);
if (listSize == 0 || stateSpec.length == 0) {
- mDefaultColor = color;
+ defaultColor = color;
+ }
+
+ if (themeAttrs != null) {
+ hasUnresolvedAttrs = true;
}
colorList = GrowingArrayUtils.append(colorList, listSize, color);
+ themeAttrsList = GrowingArrayUtils.append(themeAttrsList, listSize, themeAttrs);
stateSpecList = GrowingArrayUtils.append(stateSpecList, listSize, stateSpec);
listSize++;
}
+ mChangingConfigurations = changingConfigurations;
+ mDefaultColor = defaultColor;
+
+ if (hasUnresolvedAttrs) {
+ mThemeAttrs = new int[listSize][];
+ System.arraycopy(themeAttrsList, 0, mThemeAttrs, 0, listSize);
+ } else {
+ mThemeAttrs = null;
+ }
+
mColors = new int[listSize];
mStateSpecs = new int[listSize][];
System.arraycopy(colorList, 0, mColors, 0, listSize);
System.arraycopy(stateSpecList, 0, mStateSpecs, 0, listSize);
+
+ onColorsChanged();
+ }
+
+ /**
+ * Returns whether a theme can be applied to this color state list, which
+ * usually indicates that the color state list has unresolved theme
+ * attributes.
+ *
+ * @return whether a theme can be applied to this color state list
+ */
+ public boolean canApplyTheme() {
+ return mThemeAttrs != null;
+ }
+
+ /**
+ * Applies a theme to this color state list.
+ *
+ * @param t the theme to apply
+ */
+ public void applyTheme(Theme t) {
+ if (mThemeAttrs == null) {
+ return;
+ }
+
+ boolean hasUnresolvedAttrs = false;
+
+ final int[][] themeAttrsList = mThemeAttrs;
+ final int N = themeAttrsList.length;
+ for (int i = 0; i < N; i++) {
+ if (themeAttrsList[i] != null) {
+ final TypedArray a = t.resolveAttributes(themeAttrsList[i],
+ R.styleable.ColorStateListItem);
+ final int baseColor = a.getColor(
+ R.styleable.ColorStateListItem_color, mColors[i]);
+ final float alphaMod = a.getFloat(
+ R.styleable.ColorStateListItem_alpha, 1.0f);
+
+ mColors[i] = modulateColorAlpha(baseColor, alphaMod);
+ mChangingConfigurations |= a.getChangingConfigurations();
+
+ themeAttrsList[i] = a.extractThemeAttrs(themeAttrsList[i]);
+ if (themeAttrsList[i] != null) {
+ hasUnresolvedAttrs = true;
+ }
+
+ a.recycle();
+ }
+ }
+
+ if (!hasUnresolvedAttrs) {
+ mThemeAttrs = null;
+ }
+
+ onColorsChanged();
+ }
+
+ private int modulateColorAlpha(int baseColor, float alphaMod) {
+ if (alphaMod == 1.0f) {
+ return baseColor;
+ }
+
+ final int baseAlpha = Color.alpha(baseColor);
+ final int alpha = MathUtils.constrain((int) (baseAlpha * alphaMod + 0.5f), 0, 255);
+ final int color = (baseColor & 0xFFFFFF) | (alpha << 24);
+ return color;
}
/**
@@ -275,28 +406,24 @@ public class ColorStateList implements Parcelable {
* @return True if this color state list is opaque.
*/
public boolean isOpaque() {
- final int n = mColors.length;
- for (int i = 0; i < n; i++) {
- if (Color.alpha(mColors[i]) != 0xFF) {
- return false;
- }
- }
- return true;
+ return mIsOpaque;
}
/**
- * Return the color associated with the given set of {@link android.view.View} states.
+ * Return the color associated with the given set of
+ * {@link android.view.View} states.
*
* @param stateSet an array of {@link android.view.View} states
- * @param defaultColor the color to return if there's not state spec in this
- * {@link ColorStateList} that matches the stateSet.
+ * @param defaultColor the color to return if there's no matching state
+ * spec in this {@link ColorStateList} that matches the
+ * stateSet.
*
* @return the color associated with that set of states in this {@link ColorStateList}.
*/
- public int getColorForState(int[] stateSet, int defaultColor) {
+ public int getColorForState(@Nullable int[] stateSet, int defaultColor) {
final int setLength = mStateSpecs.length;
for (int i = 0; i < setLength; i++) {
- int[] stateSpec = mStateSpecs[i];
+ final int[] stateSpec = mStateSpecs[i];
if (StateSet.stateSetMatches(stateSpec, stateSet)) {
return mColors[i];
}
@@ -314,7 +441,9 @@ public class ColorStateList implements Parcelable {
}
/**
- * Return the states in this {@link ColorStateList}.
+ * Return the states in this {@link ColorStateList}. The returned array
+ * should not be modified.
+ *
* @return the states in this {@link ColorStateList}
* @hide
*/
@@ -323,7 +452,9 @@ public class ColorStateList implements Parcelable {
}
/**
- * Return the colors in this {@link ColorStateList}.
+ * Return the colors in this {@link ColorStateList}. The returned array
+ * should not be modified.
+ *
* @return the colors in this {@link ColorStateList}
* @hide
*/
@@ -374,11 +505,81 @@ public class ColorStateList implements Parcelable {
@Override
public String toString() {
return "ColorStateList{" +
+ "mThemeAttrs=" + Arrays.deepToString(mThemeAttrs) +
+ "mChangingConfigurations=" + mChangingConfigurations +
"mStateSpecs=" + Arrays.deepToString(mStateSpecs) +
"mColors=" + Arrays.toString(mColors) +
"mDefaultColor=" + mDefaultColor + '}';
}
+ /**
+ * Updates the default color and opacity.
+ */
+ private void onColorsChanged() {
+ int defaultColor = DEFAULT_COLOR;
+ boolean isOpaque = true;
+
+ final int[][] states = mStateSpecs;
+ final int[] colors = mColors;
+ final int N = states.length;
+ if (N > 0) {
+ defaultColor = colors[0];
+
+ for (int i = N - 1; i > 0; i--) {
+ if (states[i].length == 0) {
+ defaultColor = colors[i];
+ break;
+ }
+ }
+
+ for (int i = 0; i < N; i++) {
+ if (Color.alpha(colors[i]) != 0xFF) {
+ isOpaque = false;
+ break;
+ }
+ }
+ }
+
+ mDefaultColor = defaultColor;
+ mIsOpaque = isOpaque;
+ }
+
+ /**
+ * @return A factory that can create new instances of this ColorStateList.
+ */
+ ColorStateListFactory getFactory() {
+ return new ColorStateListFactory(this);
+ }
+
+ static class ColorStateListFactory extends ConstantState<ColorStateList> {
+ final ColorStateList mSrc;
+
+ public ColorStateListFactory(ColorStateList src) {
+ mSrc = src;
+ }
+
+ @Override
+ public int getChangingConfigurations() {
+ return mSrc.mChangingConfigurations;
+ }
+
+ @Override
+ public ColorStateList newInstance() {
+ return mSrc;
+ }
+
+ @Override
+ public ColorStateList newInstance(Resources res, Theme theme) {
+ if (theme == null || !mSrc.canApplyTheme()) {
+ return mSrc;
+ }
+
+ final ColorStateList clone = new ColorStateList(mSrc);
+ clone.applyTheme(theme);
+ return clone;
+ }
+ }
+
@Override
public int describeContents() {
return 0;
@@ -386,6 +587,9 @@ public class ColorStateList implements Parcelable {
@Override
public void writeToParcel(Parcel dest, int flags) {
+ if (canApplyTheme()) {
+ Log.w(TAG, "Wrote partially-resolved ColorStateList to parcel!");
+ }
final int N = mStateSpecs.length;
dest.writeInt(N);
for (int i = 0; i < N; i++) {
diff --git a/core/java/android/content/res/Resources.java b/core/java/android/content/res/Resources.java
index 73913b6..c931c01 100644
--- a/core/java/android/content/res/Resources.java
+++ b/core/java/android/content/res/Resources.java
@@ -16,21 +16,20 @@
package android.content.res;
-import android.animation.Animator;
-import android.animation.StateListAnimator;
-import android.annotation.NonNull;
-import android.util.Pools.SynchronizedPool;
-import android.view.ViewDebug;
import com.android.internal.util.XmlUtils;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
+import android.animation.Animator;
+import android.animation.StateListAnimator;
+import android.annotation.NonNull;
import android.annotation.Nullable;
import android.content.pm.ActivityInfo;
+import android.content.res.ColorStateList.ColorStateListFactory;
import android.graphics.Movie;
-import android.graphics.drawable.Drawable;
import android.graphics.drawable.ColorDrawable;
+import android.graphics.drawable.Drawable;
import android.graphics.drawable.Drawable.ConstantState;
import android.os.Build;
import android.os.Bundle;
@@ -40,9 +39,11 @@ import android.util.ArrayMap;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.util.Log;
+import android.util.LongSparseArray;
+import android.util.Pools.SynchronizedPool;
import android.util.Slog;
import android.util.TypedValue;
-import android.util.LongSparseArray;
+import android.view.ViewDebug;
import java.io.IOException;
import java.io.InputStream;
@@ -97,8 +98,8 @@ public class Resources {
private static final LongSparseArray<ConstantState>[] sPreloadedDrawables;
private static final LongSparseArray<ConstantState> sPreloadedColorDrawables
= new LongSparseArray<ConstantState>();
- private static final LongSparseArray<ColorStateList> sPreloadedColorStateLists
- = new LongSparseArray<ColorStateList>();
+ private static final LongSparseArray<ColorStateListFactory> sPreloadedColorStateLists
+ = new LongSparseArray<ColorStateListFactory>();
// Pool of TypedArrays targeted to this Resources object.
final SynchronizedPool<TypedArray> mTypedArrayPool = new SynchronizedPool<TypedArray>(5);
@@ -116,8 +117,8 @@ public class Resources {
new ArrayMap<String, LongSparseArray<WeakReference<ConstantState>>>();
private final ArrayMap<String, LongSparseArray<WeakReference<ConstantState>>> mColorDrawableCache =
new ArrayMap<String, LongSparseArray<WeakReference<ConstantState>>>();
- private final LongSparseArray<WeakReference<ColorStateList>> mColorStateListCache =
- new LongSparseArray<WeakReference<ColorStateList>>();
+ private final ConfigurationBoundResourceCache<ColorStateList> mColorStateListCache =
+ new ConfigurationBoundResourceCache<ColorStateList>(this);
private final ConfigurationBoundResourceCache<Animator> mAnimatorCache =
new ConfigurationBoundResourceCache<Animator>(this);
private final ConfigurationBoundResourceCache<StateListAnimator> mStateListAnimatorCache =
@@ -897,20 +898,41 @@ public class Resources {
}
/**
- * Return a color integer associated with a particular resource ID.
- * If the resource holds a complex
- * {@link android.content.res.ColorStateList}, then the default color from
- * the set is returned.
+ * Returns a color integer associated with a particular resource ID. If the
+ * resource holds a complex {@link ColorStateList}, then the default color
+ * from the set is returned.
*
* @param id The desired resource identifier, as generated by the aapt
* tool. This integer encodes the package, type, and resource
* entry. The value 0 is an invalid identifier.
*
- * @throws NotFoundException Throws NotFoundException if the given ID does not exist.
+ * @throws NotFoundException Throws NotFoundException if the given ID does
+ * not exist.
*
- * @return Returns a single color value in the form 0xAARRGGBB.
+ * @return A single color value in the form 0xAARRGGBB.
+ * @deprecated Use {@link #getColor(int, Theme)} instead.
*/
public int getColor(int id) throws NotFoundException {
+ return getColor(id, null);
+ }
+
+ /**
+ * Returns a themed color integer associated with a particular resource ID.
+ * If the resource holds a complex {@link ColorStateList}, then the default
+ * color from the set is returned.
+ *
+ * @param id The desired resource identifier, as generated by the aapt
+ * tool. This integer encodes the package, type, and resource
+ * entry. The value 0 is an invalid identifier.
+ * @param theme The theme used to style the color attributes, may be
+ * {@code null}.
+ *
+ * @throws NotFoundException Throws NotFoundException if the given ID does
+ * not exist.
+ *
+ * @return A single color value in the form 0xAARRGGBB.
+ */
+ public int getColor(int id, @Nullable Theme theme) throws NotFoundException {
TypedValue value;
synchronized (mAccessLock) {
value = mTmpValue;
@@ -919,40 +941,77 @@ public class Resources {
}
getValue(id, value, true);
if (value.type >= TypedValue.TYPE_FIRST_INT
- && value.type <= TypedValue.TYPE_LAST_INT) {
+ && value.type <= TypedValue.TYPE_LAST_INT) {
mTmpValue = value;
return value.data;
} else if (value.type != TypedValue.TYPE_STRING) {
throw new NotFoundException(
- "Resource ID #0x" + Integer.toHexString(id) + " type #0x"
- + Integer.toHexString(value.type) + " is not valid");
+ "Resource ID #0x" + Integer.toHexString(id) + " type #0x"
+ + Integer.toHexString(value.type) + " is not valid");
}
mTmpValue = null;
}
- ColorStateList csl = loadColorStateList(value, id);
+
+ final ColorStateList csl = loadColorStateList(value, id, theme);
synchronized (mAccessLock) {
if (mTmpValue == null) {
mTmpValue = value;
}
}
+
return csl.getDefaultColor();
}
/**
- * Return a color state list associated with a particular resource ID. The
- * resource may contain either a single raw color value, or a complex
- * {@link android.content.res.ColorStateList} holding multiple possible colors.
+ * Returns a color state list associated with a particular resource ID. The
+ * resource may contain either a single raw color value or a complex
+ * {@link ColorStateList} holding multiple possible colors.
*
* @param id The desired resource identifier of a {@link ColorStateList},
- * as generated by the aapt tool. This integer encodes the package, type, and resource
- * entry. The value 0 is an invalid identifier.
+ * as generated by the aapt tool. This integer encodes the
+ * package, type, and resource entry. The value 0 is an invalid
+ * identifier.
*
- * @throws NotFoundException Throws NotFoundException if the given ID does not exist.
+ * @throws NotFoundException Throws NotFoundException if the given ID does
+ * not exist.
*
- * @return Returns a ColorStateList object containing either a single
- * solid color or multiple colors that can be selected based on a state.
+ * @return A ColorStateList object containing either a single solid color
+ * or multiple colors that can be selected based on a state.
+ * @deprecated Use {@link #getColorStateList(int, Theme)} instead.
*/
+ @Nullable
public ColorStateList getColorStateList(int id) throws NotFoundException {
+ final ColorStateList csl = getColorStateList(id, null);
+ if (csl != null && csl.canApplyTheme()) {
+ Log.w(TAG, "ColorStateList " + getResourceName(id) + " has "
+ + "unresolved theme attributes! Consider using "
+ + "Resources.getColorStateList(int, Theme) or "
+ + "Context.getColorStateList(int).", new RuntimeException());
+ }
+ return csl;
+ }
+
+ /**
+ * Returns a themed color state list associated with a particular resource
+ * ID. The resource may contain either a single raw color value or a
+ * complex {@link ColorStateList} holding multiple possible colors.
+ *
+ * @param id The desired resource identifier of a {@link ColorStateList},
+ * as generated by the aapt tool. This integer encodes the
+ * package, type, and resource entry. The value 0 is an invalid
+ * identifier.
+ * @param theme The theme used to style the color attributes, may be
+ * {@code null}.
+ *
+ * @throws NotFoundException Throws NotFoundException if the given ID does
+ * not exist.
+ *
+ * @return A themed ColorStateList object containing either a single solid
+ * color or multiple colors that can be selected based on a state.
+ */
+ @Nullable
+ public ColorStateList getColorStateList(int id, @Nullable Theme theme)
+ throws NotFoundException {
TypedValue value;
synchronized (mAccessLock) {
value = mTmpValue;
@@ -963,15 +1022,19 @@ public class Resources {
}
getValue(id, value, true);
}
- ColorStateList res = loadColorStateList(value, id);
+
+ final ColorStateList res = loadColorStateList(value, id, theme);
synchronized (mAccessLock) {
if (mTmpValue == null) {
mTmpValue = value;
}
}
+
return res;
}
+
+
/**
* Return a boolean associated with a particular resource ID. This can be
* used with any integral resource value, and will return true if it is
@@ -1843,11 +1906,10 @@ public class Resources {
clearDrawableCachesLocked(mDrawableCache, configChanges);
clearDrawableCachesLocked(mColorDrawableCache, configChanges);
+ mColorStateListCache.onConfigurationChange(configChanges);
mAnimatorCache.onConfigurationChange(configChanges);
mStateListAnimatorCache.onConfigurationChange(configChanges);
- mColorStateListCache.clear();
-
flushLayoutCache();
}
synchronized (sSync) {
@@ -2425,6 +2487,9 @@ public class Resources {
final String themeKey = theme == null ? "" : theme.mKey;
LongSparseArray<WeakReference<ConstantState>> themedCache = caches.get(themeKey);
if (themedCache == null) {
+ // Clean out the caches before we add more. This shouldn't
+ // happen very often.
+ pruneCaches(caches);
themedCache = new LongSparseArray<WeakReference<ConstantState>>(1);
caches.put(themeKey, themedCache);
}
@@ -2434,12 +2499,46 @@ public class Resources {
}
/**
+ * Prunes empty caches from the cache map.
+ *
+ * @param caches The map of caches to prune.
+ */
+ private void pruneCaches(ArrayMap<String,
+ LongSparseArray<WeakReference<ConstantState>>> caches) {
+ final int N = caches.size();
+ for (int i = N - 1; i >= 0; i--) {
+ final LongSparseArray<WeakReference<ConstantState>> cache = caches.valueAt(i);
+ if (pruneCache(cache)) {
+ caches.removeAt(i);
+ }
+ }
+ }
+
+ /**
+ * Prunes obsolete weak references from a cache, returning {@code true} if
+ * the cache is empty and should be removed.
+ *
+ * @param cache The cache of weak references to prune.
+ * @return {@code true} if the cache is empty and should be removed.
+ */
+ private boolean pruneCache(LongSparseArray<WeakReference<ConstantState>> cache) {
+ final int N = cache.size();
+ for (int i = N - 1; i >= 0; i--) {
+ final WeakReference entry = cache.valueAt(i);
+ if (entry == null || entry.get() == null) {
+ cache.removeAt(i);
+ }
+ }
+ return cache.size() == 0;
+ }
+
+ /**
* Loads a drawable from XML or resources stream.
*/
private Drawable loadDrawableForCookie(TypedValue value, int id, Theme theme) {
if (value.string == null) {
throw new NotFoundException("Resource \"" + getResourceName(id) + "\" ("
- + Integer.toHexString(id) + ") is not a Drawable (color or path): " + value);
+ + Integer.toHexString(id) + ") is not a Drawable (color or path): " + value);
}
final String file = value.string.toString();
@@ -2530,7 +2629,8 @@ public class Resources {
return null;
}
- /*package*/ ColorStateList loadColorStateList(TypedValue value, int id)
+ @Nullable
+ ColorStateList loadColorStateList(TypedValue value, int id, Theme theme)
throws NotFoundException {
if (TRACE_FOR_PRELOAD) {
// Log only framework resources
@@ -2544,101 +2644,107 @@ public class Resources {
ColorStateList csl;
- if (value.type >= TypedValue.TYPE_FIRST_COLOR_INT &&
- value.type <= TypedValue.TYPE_LAST_COLOR_INT) {
-
- csl = sPreloadedColorStateLists.get(key);
- if (csl != null) {
- return csl;
+ // Handle inline color definitions.
+ if (value.type >= TypedValue.TYPE_FIRST_COLOR_INT
+ && value.type <= TypedValue.TYPE_LAST_COLOR_INT) {
+ final ColorStateListFactory factory = sPreloadedColorStateLists.get(key);
+ if (factory != null) {
+ return factory.newInstance();
}
csl = ColorStateList.valueOf(value.data);
+
if (mPreloading) {
if (verifyPreloadConfig(value.changingConfigurations, 0, value.resourceId,
"color")) {
- sPreloadedColorStateLists.put(key, csl);
+ sPreloadedColorStateLists.put(key, csl.getFactory());
}
}
return csl;
}
- csl = getCachedColorStateList(key);
+ final ConfigurationBoundResourceCache<ColorStateList> cache = mColorStateListCache;
+
+ csl = cache.get(key, theme);
if (csl != null) {
return csl;
}
- csl = sPreloadedColorStateLists.get(key);
+ final ColorStateListFactory factory = sPreloadedColorStateLists.get(key);
+ if (factory != null) {
+ csl = factory.newInstance(this, theme);
+ }
+
+ if (csl == null) {
+ csl = loadColorStateListForCookie(value, id, theme);
+ }
+
if (csl != null) {
- return csl;
+ if (mPreloading) {
+ if (verifyPreloadConfig(value.changingConfigurations, 0, value.resourceId,
+ "color")) {
+ sPreloadedColorStateLists.put(key, csl.getFactory());
+ }
+ } else {
+ cache.put(key, theme, csl.getFactory());
+ }
}
+ return csl;
+ }
+
+ private ColorStateList loadColorStateListForCookie(TypedValue value, int id, Theme theme) {
if (value.string == null) {
- throw new NotFoundException(
- "Resource is not a ColorStateList (color or path): " + value);
+ throw new UnsupportedOperationException(
+ "Can't convert to color state list: type=0x" + value.type);
}
-
+
final String file = value.string.toString();
+ if (TRACE_FOR_MISS_PRELOAD) {
+ // Log only framework resources
+ if ((id >>> 24) == 0x1) {
+ final String name = getResourceName(id);
+ if (name != null) {
+ Log.d(TAG, "Loading framework color state list #" + Integer.toHexString(id)
+ + ": " + name + " at " + file);
+ }
+ }
+ }
+
+ if (DEBUG_LOAD) {
+ Log.v(TAG, "Loading color state list for cookie " + value.assetCookie + ": " + file);
+ }
+
+ final ColorStateList csl;
+
+ Trace.traceBegin(Trace.TRACE_TAG_RESOURCES, file);
if (file.endsWith(".xml")) {
- Trace.traceBegin(Trace.TRACE_TAG_RESOURCES, file);
try {
final XmlResourceParser rp = loadXmlResourceParser(
- file, id, value.assetCookie, "colorstatelist");
- csl = ColorStateList.createFromXml(this, rp);
+ file, id, value.assetCookie, "colorstatelist");
+ csl = ColorStateList.createFromXml(this, rp, theme);
rp.close();
} catch (Exception e) {
Trace.traceEnd(Trace.TRACE_TAG_RESOURCES);
- NotFoundException rnf = new NotFoundException(
- "File " + file + " from color state list resource ID #0x"
- + Integer.toHexString(id));
+ final NotFoundException rnf = new NotFoundException(
+ "File " + file + " from color state list resource ID #0x"
+ + Integer.toHexString(id));
rnf.initCause(e);
throw rnf;
}
- Trace.traceEnd(Trace.TRACE_TAG_RESOURCES);
} else {
+ Trace.traceEnd(Trace.TRACE_TAG_RESOURCES);
throw new NotFoundException(
"File " + file + " from drawable resource ID #0x"
- + Integer.toHexString(id) + ": .xml extension required");
- }
-
- if (csl != null) {
- if (mPreloading) {
- if (verifyPreloadConfig(value.changingConfigurations, 0, value.resourceId,
- "color")) {
- sPreloadedColorStateLists.put(key, csl);
- }
- } else {
- synchronized (mAccessLock) {
- //Log.i(TAG, "Saving cached color state list @ #" +
- // Integer.toHexString(key.intValue())
- // + " in " + this + ": " + csl);
- mColorStateListCache.put(key, new WeakReference<ColorStateList>(csl));
- }
- }
+ + Integer.toHexString(id) + ": .xml extension required");
}
+ Trace.traceEnd(Trace.TRACE_TAG_RESOURCES);
return csl;
}
- private ColorStateList getCachedColorStateList(long key) {
- synchronized (mAccessLock) {
- WeakReference<ColorStateList> wr = mColorStateListCache.get(key);
- if (wr != null) { // we have the key
- ColorStateList entry = wr.get();
- if (entry != null) {
- //Log.i(TAG, "Returning cached color state list @ #" +
- // Integer.toHexString(((Integer)key).intValue())
- // + " in " + this + ": " + entry);
- return entry;
- } else { // our entry has been purged
- mColorStateListCache.delete(key);
- }
- }
- }
- return null;
- }
-
/*package*/ XmlResourceParser loadXmlResourceParser(int id, String type)
throws NotFoundException {
synchronized (mAccessLock) {
@@ -2715,6 +2821,20 @@ public class Resources {
}
}
+ /**
+ * Obtains styled attributes from the theme, if available, or unstyled
+ * resources if the theme is null.
+ *
+ * @hide
+ */
+ public static TypedArray obtainAttributes(
+ Resources res, Theme theme, AttributeSet set, int[] attrs) {
+ if (theme == null) {
+ return res.obtainAttributes(set, attrs);
+ }
+ return theme.obtainStyledAttributes(set, attrs, 0, 0);
+ }
+
private Resources() {
mAssets = AssetManager.getSystem();
// NOTE: Intentionally leaving this uninitialized (all values set
diff --git a/core/java/android/content/res/TypedArray.java b/core/java/android/content/res/TypedArray.java
index 02602fb..f15b6b9 100644
--- a/core/java/android/content/res/TypedArray.java
+++ b/core/java/android/content/res/TypedArray.java
@@ -18,6 +18,7 @@ package android.content.res;
import android.annotation.Nullable;
import android.graphics.drawable.Drawable;
+import android.os.StrictMode;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.util.Log;
@@ -73,7 +74,9 @@ public class TypedArray {
/*package*/ TypedValue mValue = new TypedValue();
/**
- * Return the number of values in this array.
+ * Returns the number of values in this array.
+ *
+ * @throws RuntimeException if the TypedArray has already been recycled.
*/
public int length() {
if (mRecycled) {
@@ -85,6 +88,8 @@ public class TypedArray {
/**
* Return the number of indices in the array that actually have data.
+ *
+ * @throws RuntimeException if the TypedArray has already been recycled.
*/
public int getIndexCount() {
if (mRecycled) {
@@ -95,13 +100,14 @@ public class TypedArray {
}
/**
- * Return an index in the array that has data.
+ * Returns an index in the array that has data.
*
* @param at The index you would like to returned, ranging from 0 to
- * {@link #getIndexCount()}.
+ * {@link #getIndexCount()}.
*
* @return The index at the given offset, which can be used with
- * {@link #getValue} and related APIs.
+ * {@link #getValue} and related APIs.
+ * @throws RuntimeException if the TypedArray has already been recycled.
*/
public int getIndex(int at) {
if (mRecycled) {
@@ -112,7 +118,9 @@ public class TypedArray {
}
/**
- * Return the Resources object this array was loaded from.
+ * Returns the Resources object this array was loaded from.
+ *
+ * @throws RuntimeException if the TypedArray has already been recycled.
*/
public Resources getResources() {
if (mRecycled) {
@@ -123,12 +131,17 @@ public class TypedArray {
}
/**
- * Retrieve the styled string value for the attribute at <var>index</var>.
+ * Retrieves the styled string value for the attribute at <var>index</var>.
+ * <p>
+ * If the attribute is not a string, this method will attempt to coerce
+ * it to a string.
*
* @param index Index of attribute to retrieve.
*
- * @return CharSequence holding string data. May be styled. Returns
- * null if the attribute is not defined.
+ * @return CharSequence holding string data. May be styled. Returns
+ * {@code null} if the attribute is not defined or could not be
+ * coerced to a string.
+ * @throws RuntimeException if the TypedArray has already been recycled.
*/
public CharSequence getText(int index) {
if (mRecycled) {
@@ -144,23 +157,28 @@ public class TypedArray {
return loadStringValueAt(index);
}
- TypedValue v = mValue;
+ final TypedValue v = mValue;
if (getValueAt(index, v)) {
- Log.w(Resources.TAG, "Converting to string: " + v);
+ StrictMode.noteResourceMismatch(v);
return v.coerceToString();
}
- Log.w(Resources.TAG, "getString of bad type: 0x"
- + Integer.toHexString(type));
- return null;
+
+ // We already checked for TYPE_NULL. This should never happen.
+ throw new RuntimeException("getText of bad type: 0x" + Integer.toHexString(type));
}
/**
- * Retrieve the string value for the attribute at <var>index</var>.
+ * Retrieves the string value for the attribute at <var>index</var>.
+ * <p>
+ * If the attribute is not a string, this method will attempt to coerce
+ * it to a string.
*
* @param index Index of attribute to retrieve.
*
- * @return String holding string data. Any styling information is
- * removed. Returns null if the attribute is not defined.
+ * @return String holding string data. Any styling information is removed.
+ * Returns {@code null} if the attribute is not defined or could
+ * not be coerced to a string.
+ * @throws RuntimeException if the TypedArray has already been recycled.
*/
public String getString(int index) {
if (mRecycled) {
@@ -176,19 +194,19 @@ public class TypedArray {
return loadStringValueAt(index).toString();
}
- TypedValue v = mValue;
+ final TypedValue v = mValue;
if (getValueAt(index, v)) {
- Log.w(Resources.TAG, "Converting to string: " + v);
- CharSequence cs = v.coerceToString();
+ StrictMode.noteResourceMismatch(v);
+ final CharSequence cs = v.coerceToString();
return cs != null ? cs.toString() : null;
}
- Log.w(Resources.TAG, "getString of bad type: 0x"
- + Integer.toHexString(type));
- return null;
+
+ // We already checked for TYPE_NULL. This should never happen.
+ throw new RuntimeException("getString of bad type: 0x" + Integer.toHexString(type));
}
/**
- * Retrieve the string value for the attribute at <var>index</var>, but
+ * Retrieves the string value for the attribute at <var>index</var>, but
* only if that string comes from an immediate value in an XML file. That
* is, this does not allow references to string resources, string
* attributes, or conversions from other types. As such, this method
@@ -197,9 +215,10 @@ public class TypedArray {
*
* @param index Index of attribute to retrieve.
*
- * @return String holding string data. Any styling information is
- * removed. Returns null if the attribute is not defined or is not
- * an immediate string value.
+ * @return String holding string data. Any styling information is removed.
+ * Returns {@code null} if the attribute is not defined or is not
+ * an immediate string value.
+ * @throws RuntimeException if the TypedArray has already been recycled.
*/
public String getNonResourceString(int index) {
if (mRecycled) {
@@ -220,16 +239,17 @@ public class TypedArray {
}
/**
- * @hide
- * Retrieve the string value for the attribute at <var>index</var> that is
+ * Retrieves the string value for the attribute at <var>index</var> that is
* not allowed to change with the given configurations.
*
* @param index Index of attribute to retrieve.
* @param allowedChangingConfigs Bit mask of configurations from
- * {@link Configuration}.NATIVE_CONFIG_* that are allowed to change.
+ * {@link Configuration}.NATIVE_CONFIG_* that are allowed to change.
*
- * @return String holding string data. Any styling information is
- * removed. Returns null if the attribute is not defined.
+ * @return String holding string data. Any styling information is removed.
+ * Returns {@code null} if the attribute is not defined.
+ * @throws RuntimeException if the TypedArray has already been recycled.
+ * @hide
*/
public String getNonConfigurationString(int index, int allowedChangingConfigs) {
if (mRecycled) {
@@ -248,24 +268,33 @@ public class TypedArray {
return loadStringValueAt(index).toString();
}
- TypedValue v = mValue;
+ final TypedValue v = mValue;
if (getValueAt(index, v)) {
- Log.w(Resources.TAG, "Converting to string: " + v);
- CharSequence cs = v.coerceToString();
+ StrictMode.noteResourceMismatch(v);
+ final CharSequence cs = v.coerceToString();
return cs != null ? cs.toString() : null;
}
- Log.w(Resources.TAG, "getString of bad type: 0x"
- + Integer.toHexString(type));
- return null;
+
+ // We already checked for TYPE_NULL. This should never happen.
+ throw new RuntimeException("getNonConfigurationString of bad type: 0x"
+ + Integer.toHexString(type));
}
/**
* Retrieve the boolean value for the attribute at <var>index</var>.
+ * <p>
+ * If the attribute is an integer value, this method will return whether
+ * it is equal to zero. If the attribute is not a boolean or integer value,
+ * this method will attempt to coerce it to an integer using
+ * {@link Integer#decode(String)} and return whether it is equal to zero.
*
* @param index Index of attribute to retrieve.
- * @param defValue Value to return if the attribute is not defined.
+ * @param defValue Value to return if the attribute is not defined or
+ * cannot be coerced to an integer.
*
- * @return Attribute boolean value, or defValue if not defined.
+ * @return Boolean value of the attribute, or defValue if the attribute was
+ * not defined or could not be coerced to an integer.
+ * @throws RuntimeException if the TypedArray has already been recycled.
*/
public boolean getBoolean(int index, boolean defValue) {
if (mRecycled) {
@@ -278,28 +307,33 @@ public class TypedArray {
if (type == TypedValue.TYPE_NULL) {
return defValue;
} else if (type >= TypedValue.TYPE_FIRST_INT
- && type <= TypedValue.TYPE_LAST_INT) {
+ && type <= TypedValue.TYPE_LAST_INT) {
return data[index+AssetManager.STYLE_DATA] != 0;
}
- TypedValue v = mValue;
+ final TypedValue v = mValue;
if (getValueAt(index, v)) {
- Log.w(Resources.TAG, "Converting to boolean: " + v);
- return XmlUtils.convertValueToBoolean(
- v.coerceToString(), defValue);
+ StrictMode.noteResourceMismatch(v);
+ return XmlUtils.convertValueToBoolean(v.coerceToString(), defValue);
}
- Log.w(Resources.TAG, "getBoolean of bad type: 0x"
- + Integer.toHexString(type));
- return defValue;
+
+ // We already checked for TYPE_NULL. This should never happen.
+ throw new RuntimeException("getBoolean of bad type: 0x" + Integer.toHexString(type));
}
/**
* Retrieve the integer value for the attribute at <var>index</var>.
+ * <p>
+ * If the attribute is not an integer, this method will attempt to coerce
+ * it to an integer using {@link Integer#decode(String)}.
*
* @param index Index of attribute to retrieve.
- * @param defValue Value to return if the attribute is not defined.
+ * @param defValue Value to return if the attribute is not defined or
+ * cannot be coerced to an integer.
*
- * @return Attribute int value, or defValue if not defined.
+ * @return Integer value of the attribute, or defValue if the attribute was
+ * not defined or could not be coerced to an integer.
+ * @throws RuntimeException if the TypedArray has already been recycled.
*/
public int getInt(int index, int defValue) {
if (mRecycled) {
@@ -312,27 +346,31 @@ public class TypedArray {
if (type == TypedValue.TYPE_NULL) {
return defValue;
} else if (type >= TypedValue.TYPE_FIRST_INT
- && type <= TypedValue.TYPE_LAST_INT) {
+ && type <= TypedValue.TYPE_LAST_INT) {
return data[index+AssetManager.STYLE_DATA];
}
- TypedValue v = mValue;
+ final TypedValue v = mValue;
if (getValueAt(index, v)) {
- Log.w(Resources.TAG, "Converting to int: " + v);
- return XmlUtils.convertValueToInt(
- v.coerceToString(), defValue);
+ StrictMode.noteResourceMismatch(v);
+ return XmlUtils.convertValueToInt(v.coerceToString(), defValue);
}
- Log.w(Resources.TAG, "getInt of bad type: 0x"
- + Integer.toHexString(type));
- return defValue;
+
+ // We already checked for TYPE_NULL. This should never happen.
+ throw new RuntimeException("getInt of bad type: 0x" + Integer.toHexString(type));
}
/**
* Retrieve the float value for the attribute at <var>index</var>.
+ * <p>
+ * If the attribute is not a float or an integer, this method will attempt
+ * to coerce it to a float using {@link Float#parseFloat(String)}.
*
* @param index Index of attribute to retrieve.
*
- * @return Attribute float value, or defValue if not defined..
+ * @return Attribute float value, or defValue if the attribute was
+ * not defined or could not be coerced to a float.
+ * @throws RuntimeException if the TypedArray has already been recycled.
*/
public float getFloat(int index, float defValue) {
if (mRecycled) {
@@ -347,21 +385,21 @@ public class TypedArray {
} else if (type == TypedValue.TYPE_FLOAT) {
return Float.intBitsToFloat(data[index+AssetManager.STYLE_DATA]);
} else if (type >= TypedValue.TYPE_FIRST_INT
- && type <= TypedValue.TYPE_LAST_INT) {
+ && type <= TypedValue.TYPE_LAST_INT) {
return data[index+AssetManager.STYLE_DATA];
}
- TypedValue v = mValue;
+ final TypedValue v = mValue;
if (getValueAt(index, v)) {
- Log.w(Resources.TAG, "Converting to float: " + v);
- CharSequence str = v.coerceToString();
+ final CharSequence str = v.coerceToString();
if (str != null) {
+ StrictMode.noteResourceMismatch(v);
return Float.parseFloat(str.toString());
}
}
- Log.w(Resources.TAG, "getFloat of bad type: 0x"
- + Integer.toHexString(type));
- return defValue;
+
+ // We already checked for TYPE_NULL. This should never happen.
+ throw new RuntimeException("getFloat of bad type: 0x" + Integer.toHexString(type));
}
/**
@@ -369,12 +407,18 @@ public class TypedArray {
* the attribute references a color resource holding a complex
* {@link android.content.res.ColorStateList}, then the default color from
* the set is returned.
+ * <p>
+ * This method will throw an exception if the attribute is defined but is
+ * not an integer color or color state list.
*
* @param index Index of attribute to retrieve.
* @param defValue Value to return if the attribute is not defined or
* not a resource.
*
* @return Attribute color value, or defValue if not defined.
+ * @throws RuntimeException if the TypedArray has already been recycled.
+ * @throws UnsupportedOperationException if the attribute is defined but is
+ * not an integer color or color state list.
*/
public int getColor(int index, int defValue) {
if (mRecycled) {
@@ -387,18 +431,19 @@ public class TypedArray {
if (type == TypedValue.TYPE_NULL) {
return defValue;
} else if (type >= TypedValue.TYPE_FIRST_INT
- && type <= TypedValue.TYPE_LAST_INT) {
+ && type <= TypedValue.TYPE_LAST_INT) {
return data[index+AssetManager.STYLE_DATA];
} else if (type == TypedValue.TYPE_STRING) {
final TypedValue value = mValue;
if (getValueAt(index, value)) {
- ColorStateList csl = mResources.loadColorStateList(
- value, value.resourceId);
+ final ColorStateList csl = mResources.loadColorStateList(
+ value, value.resourceId, mTheme);
return csl.getDefaultColor();
}
return defValue;
} else if (type == TypedValue.TYPE_ATTRIBUTE) {
- throw new RuntimeException("Failed to resolve attribute at index " + index);
+ throw new UnsupportedOperationException(
+ "Failed to resolve attribute at index " + index);
}
throw new UnsupportedOperationException("Can't convert to color: type=0x"
@@ -408,12 +453,22 @@ public class TypedArray {
/**
* Retrieve the ColorStateList for the attribute at <var>index</var>.
* The value may be either a single solid color or a reference to
- * a color or complex {@link android.content.res.ColorStateList} description.
+ * a color or complex {@link android.content.res.ColorStateList}
+ * description.
+ * <p>
+ * This method will return {@code null} if the attribute is not defined or
+ * is not an integer color or color state list.
*
* @param index Index of attribute to retrieve.
*
- * @return ColorStateList for the attribute, or null if not defined.
+ * @return ColorStateList for the attribute, or {@code null} if not
+ * defined.
+ * @throws RuntimeException if the attribute if the TypedArray has already
+ * been recycled.
+ * @throws UnsupportedOperationException if the attribute is defined but is
+ * not an integer color or color state list.
*/
+ @Nullable
public ColorStateList getColorStateList(int index) {
if (mRecycled) {
throw new RuntimeException("Cannot make calls to a recycled instance!");
@@ -422,21 +477,28 @@ public class TypedArray {
final TypedValue value = mValue;
if (getValueAt(index*AssetManager.STYLE_NUM_ENTRIES, value)) {
if (value.type == TypedValue.TYPE_ATTRIBUTE) {
- throw new RuntimeException("Failed to resolve attribute at index " + index);
+ throw new UnsupportedOperationException(
+ "Failed to resolve attribute at index " + index);
}
- return mResources.loadColorStateList(value, value.resourceId);
+ return mResources.loadColorStateList(value, value.resourceId, mTheme);
}
return null;
}
/**
* Retrieve the integer value for the attribute at <var>index</var>.
+ * <p>
+ * Unlike {@link #getInt(int, int)}, this method will throw an exception if
+ * the attribute is defined but is not an integer.
*
* @param index Index of attribute to retrieve.
* @param defValue Value to return if the attribute is not defined or
* not a resource.
*
* @return Attribute integer value, or defValue if not defined.
+ * @throws RuntimeException if the TypedArray has already been recycled.
+ * @throws UnsupportedOperationException if the attribute is defined but is
+ * not an integer.
*/
public int getInteger(int index, int defValue) {
if (mRecycled) {
@@ -449,10 +511,11 @@ public class TypedArray {
if (type == TypedValue.TYPE_NULL) {
return defValue;
} else if (type >= TypedValue.TYPE_FIRST_INT
- && type <= TypedValue.TYPE_LAST_INT) {
+ && type <= TypedValue.TYPE_LAST_INT) {
return data[index+AssetManager.STYLE_DATA];
} else if (type == TypedValue.TYPE_ATTRIBUTE) {
- throw new RuntimeException("Failed to resolve attribute at index " + index);
+ throw new UnsupportedOperationException(
+ "Failed to resolve attribute at index " + index);
}
throw new UnsupportedOperationException("Can't convert to integer: type=0x"
@@ -460,17 +523,23 @@ public class TypedArray {
}
/**
- * Retrieve a dimensional unit attribute at <var>index</var>. Unit
+ * Retrieve a dimensional unit attribute at <var>index</var>. Unit
* conversions are based on the current {@link DisplayMetrics}
* associated with the resources this {@link TypedArray} object
* came from.
+ * <p>
+ * This method will throw an exception if the attribute is defined but is
+ * not a dimension.
*
* @param index Index of attribute to retrieve.
* @param defValue Value to return if the attribute is not defined or
* not a resource.
*
* @return Attribute dimension value multiplied by the appropriate
- * metric, or defValue if not defined.
+ * metric, or defValue if not defined.
+ * @throws RuntimeException if the TypedArray has already been recycled.
+ * @throws UnsupportedOperationException if the attribute is defined but is
+ * not an integer.
*
* @see #getDimensionPixelOffset
* @see #getDimensionPixelSize
@@ -487,9 +556,10 @@ public class TypedArray {
return defValue;
} else if (type == TypedValue.TYPE_DIMENSION) {
return TypedValue.complexToDimension(
- data[index+AssetManager.STYLE_DATA], mMetrics);
+ data[index + AssetManager.STYLE_DATA], mMetrics);
} else if (type == TypedValue.TYPE_ATTRIBUTE) {
- throw new RuntimeException("Failed to resolve attribute at index " + index);
+ throw new UnsupportedOperationException(
+ "Failed to resolve attribute at index " + index);
}
throw new UnsupportedOperationException("Can't convert to dimension: type=0x"
@@ -502,13 +572,19 @@ public class TypedArray {
* {@link #getDimension}, except the returned value is converted to
* integer pixels for you. An offset conversion involves simply
* truncating the base value to an integer.
+ * <p>
+ * This method will throw an exception if the attribute is defined but is
+ * not a dimension.
*
* @param index Index of attribute to retrieve.
* @param defValue Value to return if the attribute is not defined or
* not a resource.
*
* @return Attribute dimension value multiplied by the appropriate
- * metric and truncated to integer pixels, or defValue if not defined.
+ * metric and truncated to integer pixels, or defValue if not defined.
+ * @throws RuntimeException if the TypedArray has already been recycled.
+ * @throws UnsupportedOperationException if the attribute is defined but is
+ * not an integer.
*
* @see #getDimension
* @see #getDimensionPixelSize
@@ -525,9 +601,10 @@ public class TypedArray {
return defValue;
} else if (type == TypedValue.TYPE_DIMENSION) {
return TypedValue.complexToDimensionPixelOffset(
- data[index+AssetManager.STYLE_DATA], mMetrics);
+ data[index + AssetManager.STYLE_DATA], mMetrics);
} else if (type == TypedValue.TYPE_ATTRIBUTE) {
- throw new RuntimeException("Failed to resolve attribute at index " + index);
+ throw new UnsupportedOperationException(
+ "Failed to resolve attribute at index " + index);
}
throw new UnsupportedOperationException("Can't convert to dimension: type=0x"
@@ -541,13 +618,19 @@ public class TypedArray {
* integer pixels for use as a size. A size conversion involves
* rounding the base value, and ensuring that a non-zero base value
* is at least one pixel in size.
+ * <p>
+ * This method will throw an exception if the attribute is defined but is
+ * not a dimension.
*
* @param index Index of attribute to retrieve.
* @param defValue Value to return if the attribute is not defined or
* not a resource.
*
* @return Attribute dimension value multiplied by the appropriate
- * metric and truncated to integer pixels, or defValue if not defined.
+ * metric and truncated to integer pixels, or defValue if not defined.
+ * @throws RuntimeException if the TypedArray has already been recycled.
+ * @throws UnsupportedOperationException if the attribute is defined but is
+ * not a dimension.
*
* @see #getDimension
* @see #getDimensionPixelOffset
@@ -566,7 +649,8 @@ public class TypedArray {
return TypedValue.complexToDimensionPixelSize(
data[index+AssetManager.STYLE_DATA], mMetrics);
} else if (type == TypedValue.TYPE_ATTRIBUTE) {
- throw new RuntimeException("Failed to resolve attribute at index " + index);
+ throw new UnsupportedOperationException(
+ "Failed to resolve attribute at index " + index);
}
throw new UnsupportedOperationException("Can't convert to dimension: type=0x"
@@ -578,12 +662,18 @@ public class TypedArray {
* {@link android.view.ViewGroup}'s layout_width and layout_height
* attributes. This is only here for performance reasons; applications
* should use {@link #getDimensionPixelSize}.
+ * <p>
+ * This method will throw an exception if the attribute is defined but is
+ * not a dimension or integer (enum).
*
* @param index Index of the attribute to retrieve.
* @param name Textual name of attribute for error reporting.
*
* @return Attribute dimension value multiplied by the appropriate
- * metric and truncated to integer pixels.
+ * metric and truncated to integer pixels.
+ * @throws RuntimeException if the TypedArray has already been recycled.
+ * @throws UnsupportedOperationException if the attribute is defined but is
+ * not a dimension or integer (enum).
*/
public int getLayoutDimension(int index, String name) {
if (mRecycled) {
@@ -600,10 +690,11 @@ public class TypedArray {
return TypedValue.complexToDimensionPixelSize(
data[index+AssetManager.STYLE_DATA], mMetrics);
} else if (type == TypedValue.TYPE_ATTRIBUTE) {
- throw new RuntimeException("Failed to resolve attribute at index " + index);
+ throw new UnsupportedOperationException(
+ "Failed to resolve attribute at index " + index);
}
- throw new RuntimeException(getPositionDescription()
+ throw new UnsupportedOperationException(getPositionDescription()
+ ": You must supply a " + name + " attribute.");
}
@@ -615,10 +706,11 @@ public class TypedArray {
*
* @param index Index of the attribute to retrieve.
* @param defValue The default value to return if this attribute is not
- * default or contains the wrong type of data.
+ * default or contains the wrong type of data.
*
* @return Attribute dimension value multiplied by the appropriate
- * metric and truncated to integer pixels.
+ * metric and truncated to integer pixels.
+ * @throws RuntimeException if the TypedArray has already been recycled.
*/
public int getLayoutDimension(int index, int defValue) {
if (mRecycled) {
@@ -633,14 +725,14 @@ public class TypedArray {
return data[index+AssetManager.STYLE_DATA];
} else if (type == TypedValue.TYPE_DIMENSION) {
return TypedValue.complexToDimensionPixelSize(
- data[index+AssetManager.STYLE_DATA], mMetrics);
+ data[index + AssetManager.STYLE_DATA], mMetrics);
}
return defValue;
}
/**
- * Retrieve a fractional unit attribute at <var>index</var>.
+ * Retrieves a fractional unit attribute at <var>index</var>.
*
* @param index Index of attribute to retrieve.
* @param base The base value of this fraction. In other words, a
@@ -652,7 +744,10 @@ public class TypedArray {
* not a resource.
*
* @return Attribute fractional value multiplied by the appropriate
- * base value, or defValue if not defined.
+ * base value, or defValue if not defined.
+ * @throws RuntimeException if the TypedArray has already been recycled.
+ * @throws UnsupportedOperationException if the attribute is defined but is
+ * not a fraction.
*/
public float getFraction(int index, int base, int pbase, float defValue) {
if (mRecycled) {
@@ -668,7 +763,8 @@ public class TypedArray {
return TypedValue.complexToFraction(
data[index+AssetManager.STYLE_DATA], base, pbase);
} else if (type == TypedValue.TYPE_ATTRIBUTE) {
- throw new RuntimeException("Failed to resolve attribute at index " + index);
+ throw new UnsupportedOperationException(
+ "Failed to resolve attribute at index " + index);
}
throw new UnsupportedOperationException("Can't convert to fraction: type=0x"
@@ -676,7 +772,7 @@ public class TypedArray {
}
/**
- * Retrieve the resource identifier for the attribute at
+ * Retrieves the resource identifier for the attribute at
* <var>index</var>. Note that attribute resource as resolved when
* the overall {@link TypedArray} object is retrieved. As a
* result, this function will return the resource identifier of the
@@ -688,6 +784,7 @@ public class TypedArray {
* not a resource.
*
* @return Attribute resource identifier, or defValue if not defined.
+ * @throws RuntimeException if the TypedArray has already been recycled.
*/
public int getResourceId(int index, int defValue) {
if (mRecycled) {
@@ -706,13 +803,15 @@ public class TypedArray {
}
/**
- * Retrieve the theme attribute resource identifier for the attribute at
+ * Retrieves the theme attribute resource identifier for the attribute at
* <var>index</var>.
*
* @param index Index of attribute to retrieve.
* @param defValue Value to return if the attribute is not defined or not a
- * resource.
+ * resource.
+ *
* @return Theme attribute resource identifier, or defValue if not defined.
+ * @throws RuntimeException if the TypedArray has already been recycled.
* @hide
*/
public int getThemeAttributeId(int index, int defValue) {
@@ -730,10 +829,16 @@ public class TypedArray {
/**
* Retrieve the Drawable for the attribute at <var>index</var>.
+ * <p>
+ * This method will throw an exception if the attribute is defined but is
+ * not a color or drawable resource.
*
* @param index Index of attribute to retrieve.
*
- * @return Drawable for the attribute, or null if not defined.
+ * @return Drawable for the attribute, or {@code null} if not defined.
+ * @throws RuntimeException if the TypedArray has already been recycled.
+ * @throws UnsupportedOperationException if the attribute is defined but is
+ * not a color or drawable resource.
*/
@Nullable
public Drawable getDrawable(int index) {
@@ -744,7 +849,8 @@ public class TypedArray {
final TypedValue value = mValue;
if (getValueAt(index*AssetManager.STYLE_NUM_ENTRIES, value)) {
if (value.type == TypedValue.TYPE_ATTRIBUTE) {
- throw new RuntimeException("Failed to resolve attribute at index " + index);
+ throw new UnsupportedOperationException(
+ "Failed to resolve attribute at index " + index);
}
return mResources.loadDrawable(value, value.resourceId, mTheme);
}
@@ -756,10 +862,15 @@ public class TypedArray {
* This gets the resource ID of the selected attribute, and uses
* {@link Resources#getTextArray Resources.getTextArray} of the owning
* Resources object to retrieve its String[].
+ * <p>
+ * This method will throw an exception if the attribute is defined but is
+ * not a text array resource.
*
* @param index Index of attribute to retrieve.
*
- * @return CharSequence[] for the attribute, or null if not defined.
+ * @return CharSequence[] for the attribute, or {@code null} if not
+ * defined.
+ * @throws RuntimeException if the TypedArray has already been recycled.
*/
public CharSequence[] getTextArray(int index) {
if (mRecycled) {
@@ -780,7 +891,8 @@ public class TypedArray {
* @param outValue TypedValue object in which to place the attribute's
* data.
*
- * @return Returns true if the value was retrieved, else false.
+ * @return {@code true} if the value was retrieved, false otherwise.
+ * @throws RuntimeException if the TypedArray has already been recycled.
*/
public boolean getValue(int index, TypedValue outValue) {
if (mRecycled) {
@@ -794,7 +906,9 @@ public class TypedArray {
* Returns the type of attribute at the specified index.
*
* @param index Index of attribute whose type to retrieve.
+ *
* @return Attribute type.
+ * @throws RuntimeException if the TypedArray has already been recycled.
*/
public int getType(int index) {
if (mRecycled) {
@@ -814,6 +928,7 @@ public class TypedArray {
* @param index Index of attribute to retrieve.
*
* @return True if the attribute has a value, false otherwise.
+ * @throws RuntimeException if the TypedArray has already been recycled.
*/
public boolean hasValue(int index) {
if (mRecycled) {
@@ -834,6 +949,7 @@ public class TypedArray {
* @param index Index of attribute to retrieve.
*
* @return True if the attribute has a value or is empty, false otherwise.
+ * @throws RuntimeException if the TypedArray has already been recycled.
*/
public boolean hasValueOrEmpty(int index) {
if (mRecycled) {
@@ -857,6 +973,7 @@ public class TypedArray {
* @return Returns a TypedValue object if the attribute is defined,
* containing its data; otherwise returns null. (You will not
* receive a TypedValue whose type is TYPE_NULL.)
+ * @throws RuntimeException if the TypedArray has already been recycled.
*/
public TypedValue peekValue(int index) {
if (mRecycled) {
@@ -872,6 +989,9 @@ public class TypedArray {
/**
* Returns a message about the parser state suitable for printing error messages.
+ *
+ * @return Human-readable description of current parser state.
+ * @throws RuntimeException if the TypedArray has already been recycled.
*/
public String getPositionDescription() {
if (mRecycled) {
@@ -882,8 +1002,10 @@ public class TypedArray {
}
/**
- * Recycle the TypedArray, to be re-used by a later caller. After calling
+ * Recycles the TypedArray, to be re-used by a later caller. After calling
* this function you must not ever touch the typed array again.
+ *
+ * @throws RuntimeException if the TypedArray has already been recycled.
*/
public void recycle() {
if (mRecycled) {
@@ -908,9 +1030,19 @@ public class TypedArray {
* @return an array of length {@link #getIndexCount()} populated with theme
* attributes, or null if there are no theme attributes in the typed
* array
+ * @throws RuntimeException if the TypedArray has already been recycled.
* @hide
*/
+ @Nullable
public int[] extractThemeAttrs() {
+ return extractThemeAttrs(null);
+ }
+
+ /**
+ * @hide
+ */
+ @Nullable
+ public int[] extractThemeAttrs(@Nullable int[] scrap) {
if (mRecycled) {
throw new RuntimeException("Cannot make calls to a recycled instance!");
}
@@ -922,6 +1054,7 @@ public class TypedArray {
for (int i = 0; i < N; i++) {
final int index = i * AssetManager.STYLE_NUM_ENTRIES;
if (data[index + AssetManager.STYLE_TYPE] != TypedValue.TYPE_ATTRIBUTE) {
+ // Not an attribute, ignore.
continue;
}
@@ -930,13 +1063,20 @@ public class TypedArray {
final int attr = data[index + AssetManager.STYLE_DATA];
if (attr == 0) {
- // This attribute is useless!
+ // Useless data, ignore.
continue;
}
+ // Ensure we have a usable attribute array.
if (attrs == null) {
- attrs = new int[N];
+ if (scrap != null && scrap.length == N) {
+ attrs = scrap;
+ Arrays.fill(attrs, 0);
+ } else {
+ attrs = new int[N];
+ }
}
+
attrs[i] = attr;
}
@@ -949,9 +1089,14 @@ public class TypedArray {
*
* @return Returns a mask of the changing configuration parameters, as
* defined by {@link android.content.pm.ActivityInfo}.
+ * @throws RuntimeException if the TypedArray has already been recycled.
* @see android.content.pm.ActivityInfo
*/
public int getChangingConfigurations() {
+ if (mRecycled) {
+ throw new RuntimeException("Cannot make calls to a recycled instance!");
+ }
+
int changingConfig = 0;
final int[] data = mData;
diff --git a/core/java/android/hardware/camera2/params/LensShadingMap.java b/core/java/android/hardware/camera2/params/LensShadingMap.java
index 9bbc33a..13929b1 100644
--- a/core/java/android/hardware/camera2/params/LensShadingMap.java
+++ b/core/java/android/hardware/camera2/params/LensShadingMap.java
@@ -238,6 +238,51 @@ public final class LensShadingMap {
return HashCodeHelpers.hashCode(mRows, mColumns, elemsHash);
}
+ /**
+ * Return the LensShadingMap as a string representation.
+ *
+ * <p> {@code "LensShadingMap{R:([%f, %f, ... %f], ... [%f, %f, ... %f]), G_even:([%f, %f, ...
+ * %f], ... [%f, %f, ... %f]), G_odd:([%f, %f, ... %f], ... [%f, %f, ... %f]), B:([%f, %f, ...
+ * %f], ... [%f, %f, ... %f])}"},
+ * where each {@code %f} represents one gain factor and each {@code [%f, %f, ... %f]} represents
+ * a row of the lens shading map</p>
+ *
+ * @return string representation of {@link LensShadingMap}
+ */
+ @Override
+ public String toString() {
+ StringBuilder str = new StringBuilder();
+ str.append("LensShadingMap{");
+
+ final String channelPrefix[] = {"R:(", "G_even:(", "G_odd:(", "B:("};
+
+ for (int ch = 0; ch < COUNT; ch++) {
+ str.append(channelPrefix[ch]);
+
+ for (int r = 0; r < mRows; r++) {
+ str.append("[");
+ for (int c = 0; c < mColumns; c++) {
+ float gain = getGainFactor(ch, c, r);
+ str.append(gain);
+ if (c < mColumns - 1) {
+ str.append(", ");
+ }
+ }
+ str.append("]");
+ if (r < mRows - 1) {
+ str.append(", ");
+ }
+ }
+
+ str.append(")");
+ if (ch < COUNT - 1) {
+ str.append(", ");
+ }
+ }
+
+ str.append("}");
+ return str.toString();
+ }
private final int mRows;
private final int mColumns;
diff --git a/core/java/android/hardware/usb/UsbDevice.java b/core/java/android/hardware/usb/UsbDevice.java
index d90e06e..1a42319 100644
--- a/core/java/android/hardware/usb/UsbDevice.java
+++ b/core/java/android/hardware/usb/UsbDevice.java
@@ -40,6 +40,7 @@ import android.os.Parcelable;
public class UsbDevice implements Parcelable {
private static final String TAG = "UsbDevice";
+ private static final boolean DEBUG = false;
private final String mName;
private final String mManufacturerName;
diff --git a/core/java/android/midi/IMidiDeviceServer.aidl b/core/java/android/midi/IMidiDeviceServer.aidl
new file mode 100644
index 0000000..31fdbbb
--- /dev/null
+++ b/core/java/android/midi/IMidiDeviceServer.aidl
@@ -0,0 +1,26 @@
+/*
+ * Copyright (C) 2014 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.midi;
+
+import android.os.ParcelFileDescriptor;
+
+/** @hide */
+interface IMidiDeviceServer
+{
+ ParcelFileDescriptor openInputPort(int portNumber);
+ ParcelFileDescriptor openOutputPort(int portNumber);
+}
diff --git a/core/java/android/midi/IMidiListener.aidl b/core/java/android/midi/IMidiListener.aidl
new file mode 100644
index 0000000..b650593
--- /dev/null
+++ b/core/java/android/midi/IMidiListener.aidl
@@ -0,0 +1,26 @@
+/*
+ * Copyright (C) 2014 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.midi;
+
+import android.midi.MidiDeviceInfo;
+
+/** @hide */
+oneway interface IMidiListener
+{
+ void onDeviceAdded(in MidiDeviceInfo device);
+ void onDeviceRemoved(in MidiDeviceInfo device);
+}
diff --git a/core/java/android/midi/IMidiManager.aidl b/core/java/android/midi/IMidiManager.aidl
new file mode 100644
index 0000000..575b525
--- /dev/null
+++ b/core/java/android/midi/IMidiManager.aidl
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2014 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.midi;
+
+import android.midi.IMidiDeviceServer;
+import android.midi.IMidiListener;
+import android.midi.MidiDeviceInfo;
+import android.os.Bundle;
+import android.os.IBinder;
+
+/** @hide */
+interface IMidiManager
+{
+ MidiDeviceInfo[] getDeviceList();
+
+ // for device creation & removal notifications
+ void registerListener(IBinder token, in IMidiListener listener);
+ void unregisterListener(IBinder token, in IMidiListener listener);
+
+ // for communicating with MIDI devices
+ IMidiDeviceServer openDevice(IBinder token, in MidiDeviceInfo device);
+
+ // for implementing virtual MIDI devices
+ MidiDeviceInfo registerDeviceServer(in IMidiDeviceServer server, int numInputPorts,
+ int numOutputPorts, in Bundle properties, boolean isPrivate, int type);
+ void unregisterDeviceServer(in IMidiDeviceServer server);
+}
diff --git a/core/java/android/midi/MidiDevice.java b/core/java/android/midi/MidiDevice.java
new file mode 100644
index 0000000..8aaa86d
--- /dev/null
+++ b/core/java/android/midi/MidiDevice.java
@@ -0,0 +1,101 @@
+/*
+ * Copyright (C) 2014 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.midi;
+
+import android.os.ParcelFileDescriptor;
+import android.os.RemoteException;
+import android.util.Log;
+
+import java.io.FileDescriptor;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+
+/**
+ * This class is used for sending and receiving data to and from an MIDI device
+ * Instances of this class are created by {@link MidiManager#openDevice}.
+ *
+ * @hide
+ */
+public final class MidiDevice {
+ private static final String TAG = "MidiDevice";
+
+ private final MidiDeviceInfo mDeviceInfo;
+ private final IMidiDeviceServer mServer;
+
+ /**
+ * MidiDevice should only be instantiated by MidiManager
+ * @hide
+ */
+ public MidiDevice(MidiDeviceInfo deviceInfo, IMidiDeviceServer server) {
+ mDeviceInfo = deviceInfo;
+ mServer = server;
+ }
+
+ /**
+ * Returns a {@link MidiDeviceInfo} object, which describes this device.
+ *
+ * @return the {@link MidiDeviceInfo} object
+ */
+ public MidiDeviceInfo getInfo() {
+ return mDeviceInfo;
+ }
+
+ /**
+ * Called to open a {@link MidiInputPort} for the specified port number.
+ *
+ * @param portNumber the number of the input port to open
+ * @return the {@link MidiInputPort}
+ */
+ public MidiInputPort openInputPort(int portNumber) {
+ try {
+ ParcelFileDescriptor pfd = mServer.openInputPort(portNumber);
+ if (pfd == null) {
+ return null;
+ }
+ return new MidiInputPort(pfd, portNumber);
+ } catch (RemoteException e) {
+ Log.e(TAG, "RemoteException in openInputPort");
+ return null;
+ }
+ }
+
+ /**
+ * Called to open a {@link MidiOutputPort} for the specified port number.
+ *
+ * @param portNumber the number of the output port to open
+ * @return the {@link MidiOutputPort}
+ */
+ public MidiOutputPort openOutputPort(int portNumber) {
+ try {
+ ParcelFileDescriptor pfd = mServer.openOutputPort(portNumber);
+ if (pfd == null) {
+ return null;
+ }
+ return new MidiOutputPort(pfd, portNumber);
+ } catch (RemoteException e) {
+ Log.e(TAG, "RemoteException in openOutputPort");
+ return null;
+ }
+ }
+
+ @Override
+ public String toString() {
+ return ("MidiDevice: " + mDeviceInfo.toString());
+ }
+}
diff --git a/core/java/android/midi/MidiDeviceInfo.aidl b/core/java/android/midi/MidiDeviceInfo.aidl
new file mode 100644
index 0000000..59be059
--- /dev/null
+++ b/core/java/android/midi/MidiDeviceInfo.aidl
@@ -0,0 +1,19 @@
+/*
+ * Copyright (C) 2014, 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.midi;
+
+parcelable MidiDeviceInfo;
diff --git a/core/java/android/midi/MidiDeviceInfo.java b/core/java/android/midi/MidiDeviceInfo.java
new file mode 100644
index 0000000..5cf62b5
--- /dev/null
+++ b/core/java/android/midi/MidiDeviceInfo.java
@@ -0,0 +1,203 @@
+/*
+ * Copyright (C) 2014 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.midi;
+
+import android.os.Bundle;
+import android.os.Parcel;
+import android.os.Parcelable;
+
+/**
+ * This class contains information to describe a MIDI device.
+ * For now we only have information that can be retrieved easily for USB devices,
+ * but we will probably expand this in the future.
+ *
+ * This class is just an immutable object to encapsulate the MIDI device description.
+ * Use the MidiDevice class to actually communicate with devices.
+ *
+ * @hide
+ */
+public class MidiDeviceInfo implements Parcelable {
+
+ private static final String TAG = "MidiDeviceInfo";
+
+ /**
+ * Constant representing USB MIDI devices for {@link #getType}
+ */
+ public static final int TYPE_USB = 1;
+
+ /**
+ * Constant representing virtual (software based) MIDI devices for {@link #getType}
+ */
+ public static final int TYPE_VIRTUAL = 2;
+
+ private final int mType; // USB or virtual
+ private final int mId; // unique ID generated by MidiService
+ private final int mInputPortCount;
+ private final int mOutputPortCount;
+ private final Bundle mProperties;
+
+ /**
+ * Bundle key for the device's manufacturer name property.
+ * Used with the {@link android.os.Bundle} returned by {@link #getProperties}.
+ * Matches the USB device manufacturer name string for USB MIDI devices.
+ */
+ public static final String PROPERTY_MANUFACTURER = "manufacturer";
+
+ /**
+ * Bundle key for the device's model name property.
+ * Used with the {@link android.os.Bundle} returned by {@link #getProperties}
+ * Matches the USB device product name string for USB MIDI devices.
+ */
+ public static final String PROPERTY_MODEL = "model";
+
+ /**
+ * Bundle key for the device's serial number property.
+ * Used with the {@link android.os.Bundle} returned by {@link #getProperties}
+ * Matches the USB device serial number for USB MIDI devices.
+ */
+ public static final String PROPERTY_SERIAL_NUMBER = "serial_number";
+
+ /**
+ * Bundle key for the device's {@link android.hardware.usb.UsbDevice}.
+ * Only set for USB MIDI devices.
+ * Used with the {@link android.os.Bundle} returned by {@link #getProperties}
+ */
+ public static final String PROPERTY_USB_DEVICE = "usb_device";
+
+ /**
+ * Bundle key for the device's ALSA card number.
+ * Only set for USB MIDI devices.
+ * Used with the {@link android.os.Bundle} returned by {@link #getProperties}
+ */
+ public static final String PROPERTY_ALSA_CARD = "alsa_card";
+
+ /**
+ * Bundle key for the device's ALSA device number.
+ * Only set for USB MIDI devices.
+ * Used with the {@link android.os.Bundle} returned by {@link #getProperties}
+ */
+ public static final String PROPERTY_ALSA_DEVICE = "alsa_device";
+
+ /**
+ * MidiDeviceInfo should only be instantiated by MidiService implementation
+ * @hide
+ */
+ public MidiDeviceInfo(int type, int id, int numInputPorts, int numOutputPorts,
+ Bundle properties) {
+ mType = type;
+ mId = id;
+ mInputPortCount = numInputPorts;
+ mOutputPortCount = numOutputPorts;
+ mProperties = properties;
+ }
+
+ /**
+ * Returns the type of the device.
+ *
+ * @return the device's type
+ */
+ public int getType() {
+ return mType;
+ }
+
+ /**
+ * Returns the ID of the device.
+ * This ID is generated by the MIDI service and is not persistent across device unplugs.
+ *
+ * @return the device's ID
+ */
+ public int getId() {
+ return mId;
+ }
+
+ /**
+ * Returns the device's number of input ports.
+ *
+ * @return the number of input ports
+ */
+ public int getInputPortCount() {
+ return mInputPortCount;
+ }
+
+ /**
+ * Returns the device's number of output ports.
+ *
+ * @return the number of output ports
+ */
+ public int getOutputPortCount() {
+ return mOutputPortCount;
+ }
+
+ /**
+ * Returns the {@link android.os.Bundle} containing the device's properties.
+ *
+ * @return the device's properties
+ */
+ public Bundle getProperties() {
+ return mProperties;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (o instanceof MidiDeviceInfo) {
+ return (((MidiDeviceInfo)o).mId == mId);
+ } else {
+ return false;
+ }
+ }
+
+ @Override
+ public int hashCode() {
+ return mId;
+ }
+
+ @Override
+ public String toString() {
+ return ("MidiDeviceInfo[mType=" + mType +
+ ",mInputPortCount=" + mInputPortCount +
+ ",mOutputPortCount=" + mOutputPortCount +
+ ",mProperties=" + mProperties);
+ }
+
+ public static final Parcelable.Creator<MidiDeviceInfo> CREATOR =
+ new Parcelable.Creator<MidiDeviceInfo>() {
+ public MidiDeviceInfo createFromParcel(Parcel in) {
+ int type = in.readInt();
+ int id = in.readInt();
+ int inputPorts = in.readInt();
+ int outputPorts = in.readInt();
+ Bundle properties = in.readBundle();
+ return new MidiDeviceInfo(type, id, inputPorts, outputPorts, properties);
+ }
+
+ public MidiDeviceInfo[] newArray(int size) {
+ return new MidiDeviceInfo[size];
+ }
+ };
+
+ public int describeContents() {
+ return 0;
+ }
+
+ public void writeToParcel(Parcel parcel, int flags) {
+ parcel.writeInt(mType);
+ parcel.writeInt(mId);
+ parcel.writeInt(mInputPortCount);
+ parcel.writeInt(mOutputPortCount);
+ parcel.writeBundle(mProperties);
+ }
+}
diff --git a/core/java/android/midi/MidiDeviceServer.java b/core/java/android/midi/MidiDeviceServer.java
new file mode 100644
index 0000000..ccb2e0c
--- /dev/null
+++ b/core/java/android/midi/MidiDeviceServer.java
@@ -0,0 +1,261 @@
+/*
+ * Copyright (C) 2014 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.midi;
+
+import android.os.ParcelFileDescriptor;
+import android.os.RemoteException;
+import android.system.OsConstants;
+import android.util.Log;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.util.ArrayList;
+
+/** @hide */
+public final class MidiDeviceServer implements Closeable {
+ private static final String TAG = "MidiDeviceServer";
+
+ private final IMidiManager mMidiManager;
+
+ // MidiDeviceInfo for the device implemented by this server
+ private MidiDeviceInfo mDeviceInfo;
+ private int mInputPortCount;
+ private int mOutputPortCount;
+
+ // output ports for receiving messages from our clients
+ // we can have only one per port number
+ private MidiOutputPort[] mInputPortSenders;
+
+ // receivers attached to our input ports
+ private ArrayList<MidiReceiver>[] mInputPortReceivers;
+
+ // input ports for sending messages to our clients
+ // we can have multiple outputs per port number
+ private ArrayList<MidiInputPort>[] mOutputPortReceivers;
+
+ // subclass of MidiInputPort for passing to clients
+ // that notifies us when the connection has failed
+ private class ServerInputPort extends MidiInputPort {
+ ServerInputPort(ParcelFileDescriptor pfd, int portNumber) {
+ super(pfd, portNumber);
+ }
+
+ @Override
+ public void onIOException() {
+ synchronized (mOutputPortReceivers) {
+ mOutputPortReceivers[getPortNumber()].clear();
+ }
+ }
+ }
+
+ // subclass of MidiOutputPort for passing to clients
+ // that notifies us when the connection has failed
+ private class ServerOutputPort extends MidiOutputPort {
+ ServerOutputPort(ParcelFileDescriptor pfd, int portNumber) {
+ super(pfd, portNumber);
+ }
+
+ @Override
+ public void onIOException() {
+ synchronized (mInputPortSenders) {
+ mInputPortSenders[getPortNumber()] = null;
+ }
+ }
+ }
+
+ // Binder interface stub for receiving connection requests from clients
+ private final IMidiDeviceServer mServer = new IMidiDeviceServer.Stub() {
+
+ @Override
+ public ParcelFileDescriptor openInputPort(int portNumber) {
+ if (portNumber < 0 || portNumber >= mInputPortCount) {
+ Log.e(TAG, "portNumber out of range in openInputPort: " + portNumber);
+ return null;
+ }
+
+ ParcelFileDescriptor result = null;
+
+ synchronized (mInputPortSenders) {
+ if (mInputPortSenders[portNumber] != null) {
+ Log.d(TAG, "port " + portNumber + " already open");
+ return null;
+ }
+
+ try {
+ ParcelFileDescriptor[] pair = ParcelFileDescriptor.createSocketPair(
+ OsConstants.SOCK_SEQPACKET);
+ MidiOutputPort newOutputPort = new ServerOutputPort(pair[0], portNumber);
+ mInputPortSenders[portNumber] = newOutputPort;
+ result = pair[1];
+
+ ArrayList<MidiReceiver> receivers = mInputPortReceivers[portNumber];
+ synchronized (receivers) {
+ for (int i = 0; i < receivers.size(); i++) {
+ newOutputPort.connect(receivers.get(i));
+ }
+ }
+ } catch (IOException e) {
+ Log.e(TAG, "unable to create ParcelFileDescriptors in openInputPort");
+ return null;
+ }
+ }
+
+ return result;
+ }
+
+ @Override
+ public ParcelFileDescriptor openOutputPort(int portNumber) {
+ if (portNumber < 0 || portNumber >= mOutputPortCount) {
+ Log.e(TAG, "portNumber out of range in openOutputPort: " + portNumber);
+ return null;
+ }
+ synchronized (mOutputPortReceivers) {
+ try {
+ ParcelFileDescriptor[] pair = ParcelFileDescriptor.createSocketPair(
+ OsConstants.SOCK_SEQPACKET);
+ mOutputPortReceivers[portNumber].add(new ServerInputPort(pair[0], portNumber));
+ return pair[1];
+ } catch (IOException e) {
+ Log.e(TAG, "unable to create ParcelFileDescriptors in openOutputPort");
+ return null;
+ }
+ }
+ }
+ };
+
+ /* package */ MidiDeviceServer(IMidiManager midiManager) {
+ mMidiManager = midiManager;
+ }
+
+ /* package */ IMidiDeviceServer getBinderInterface() {
+ return mServer;
+ }
+
+ /* package */ void setDeviceInfo(MidiDeviceInfo deviceInfo) {
+ if (mDeviceInfo != null) {
+ throw new IllegalStateException("setDeviceInfo should only be called once");
+ }
+ mDeviceInfo = deviceInfo;
+ mInputPortCount = deviceInfo.getInputPortCount();
+ mOutputPortCount = deviceInfo.getOutputPortCount();
+ mInputPortSenders = new MidiOutputPort[mInputPortCount];
+
+ mInputPortReceivers = new ArrayList[mInputPortCount];
+ for (int i = 0; i < mInputPortCount; i++) {
+ mInputPortReceivers[i] = new ArrayList<MidiReceiver>();
+ }
+
+ mOutputPortReceivers = new ArrayList[mOutputPortCount];
+ for (int i = 0; i < mOutputPortCount; i++) {
+ mOutputPortReceivers[i] = new ArrayList<MidiInputPort>();
+ }
+ }
+
+ @Override
+ public void close() throws IOException {
+ try {
+ // FIXME - close input and output ports too?
+ mMidiManager.unregisterDeviceServer(mServer);
+ } catch (RemoteException e) {
+ Log.e(TAG, "RemoteException in unregisterDeviceServer");
+ }
+ }
+
+ /**
+ * Returns a {@link MidiDeviceInfo} object, which describes this device.
+ *
+ * @return the {@link MidiDeviceInfo} object
+ */
+ public MidiDeviceInfo getInfo() {
+ return mDeviceInfo;
+ }
+
+ /**
+ * Called to open a {@link MidiSender} to allow receiving MIDI messages
+ * on the device's input port for the specified port number.
+ *
+ * @param portNumber the number of the input port
+ * @return the {@link MidiSender}
+ */
+ public MidiSender openInputPortSender(int portNumber) {
+ if (portNumber < 0 || portNumber >= mDeviceInfo.getInputPortCount()) {
+ throw new IllegalArgumentException("portNumber " + portNumber + " out of range");
+ }
+ final int portNumberF = portNumber;
+ return new MidiSender() {
+
+ @Override
+ public void connect(MidiReceiver receiver) {
+ // We always synchronize on mInputPortSenders before receivers if we need to
+ // synchronize on both.
+ synchronized (mInputPortSenders) {
+ ArrayList<MidiReceiver> receivers = mInputPortReceivers[portNumberF];
+ synchronized (receivers) {
+ receivers.add(receiver);
+ MidiOutputPort outputPort = mInputPortSenders[portNumberF];
+ if (outputPort != null) {
+ outputPort.connect(receiver);
+ }
+ }
+ }
+ }
+
+ @Override
+ public void disconnect(MidiReceiver receiver) {
+ // We always synchronize on mInputPortSenders before receivers if we need to
+ // synchronize on both.
+ synchronized (mInputPortSenders) {
+ ArrayList<MidiReceiver> receivers = mInputPortReceivers[portNumberF];
+ synchronized (receivers) {
+ receivers.remove(receiver);
+ MidiOutputPort outputPort = mInputPortSenders[portNumberF];
+ if (outputPort != null) {
+ outputPort.disconnect(receiver);
+ }
+ }
+ }
+ }
+ };
+ }
+
+ /**
+ * Called to open a {@link MidiReceiver} to allow sending MIDI messages
+ * on the virtual device's output port for the specified port number.
+ *
+ * @param portNumber the number of the output port
+ * @return the {@link MidiReceiver}
+ */
+ public MidiReceiver openOutputPortReceiver(int portNumber) {
+ if (portNumber < 0 || portNumber >= mDeviceInfo.getOutputPortCount()) {
+ throw new IllegalArgumentException("portNumber " + portNumber + " out of range");
+ }
+ final int portNumberF = portNumber;
+ return new MidiReceiver() {
+
+ @Override
+ public void onPost(byte[] msg, int offset, int count, long timestamp) throws IOException {
+ ArrayList<MidiInputPort> receivers = mOutputPortReceivers[portNumberF];
+ synchronized (receivers) {
+ for (int i = 0; i < receivers.size(); i++) {
+ // FIXME catch errors and remove dead ones
+ receivers.get(i).onPost(msg, offset, count, timestamp);
+ }
+ }
+ }
+ };
+ }
+}
diff --git a/core/java/android/midi/MidiInputPort.java b/core/java/android/midi/MidiInputPort.java
new file mode 100644
index 0000000..5d806cf
--- /dev/null
+++ b/core/java/android/midi/MidiInputPort.java
@@ -0,0 +1,70 @@
+/*
+ * Copyright (C) 2014 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.midi;
+
+import android.os.ParcelFileDescriptor;
+
+import libcore.io.IoUtils;
+
+import java.io.FileOutputStream;
+import java.io.IOException;
+
+/**
+ * This class is used for sending data to a port on a MIDI device
+ *
+ * @hide
+ */
+public class MidiInputPort extends MidiPort implements MidiReceiver {
+
+ private final FileOutputStream mOutputStream;
+
+ // buffer to use for sending messages out our output stream
+ private final byte[] mBuffer = new byte[MAX_PACKED_MESSAGE_SIZE];
+
+ /* package */ MidiInputPort(ParcelFileDescriptor pfd, int portNumber) {
+ super(portNumber);
+ mOutputStream = new ParcelFileDescriptor.AutoCloseOutputStream(pfd);
+ }
+
+ /**
+ * Writes a MIDI message to the input port
+ *
+ * @param msg byte array containing the message
+ * @param offset offset of first byte of the message in msg byte array
+ * @param count size of the message in bytes
+ * @param timestamp future time to post the message (based on
+ * {@link java.lang.System#nanoTime}
+ */
+ public void onPost(byte[] msg, int offset, int count, long timestamp) throws IOException {
+ synchronized (mBuffer) {
+ int length = packMessage(msg, offset, count, timestamp, mBuffer);
+ try {
+ mOutputStream.write(mBuffer, 0, length);
+ } catch (IOException e) {
+ IoUtils.closeQuietly(mOutputStream);
+ // report I/O failure
+ onIOException();
+ throw e;
+ }
+ }
+ }
+
+ @Override
+ public void close() throws IOException {
+ mOutputStream.close();
+ }
+}
diff --git a/core/java/android/midi/MidiManager.java b/core/java/android/midi/MidiManager.java
new file mode 100644
index 0000000..2c1c7bf
--- /dev/null
+++ b/core/java/android/midi/MidiManager.java
@@ -0,0 +1,195 @@
+/*
+ * Copyright (C) 2014 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.midi;
+
+import android.content.Context;
+import android.os.Binder;
+import android.os.IBinder;
+import android.os.Bundle;
+import android.os.RemoteException;
+import android.util.Log;
+
+import java.io.IOException;
+import java.util.HashMap;
+
+/**
+ * This class is the public application interface to the MIDI service.
+ *
+ * <p>You can obtain an instance of this class by calling
+ * {@link android.content.Context#getSystemService(java.lang.String) Context.getSystemService()}.
+ *
+ * {@samplecode
+ * MidiManager manager = (MidiManager) getSystemService(Context.MIDI_SERVICE);}
+ *
+ * @hide
+ */
+public class MidiManager {
+ private static final String TAG = "MidiManager";
+
+ private final Context mContext;
+ private final IMidiManager mService;
+ private final IBinder mToken = new Binder();
+
+ private HashMap<DeviceCallback,DeviceListener> mDeviceListeners =
+ new HashMap<DeviceCallback,DeviceListener>();
+
+ // Binder stub for receiving device notifications from MidiService
+ private class DeviceListener extends IMidiListener.Stub {
+ private DeviceCallback mCallback;
+
+ public DeviceListener(DeviceCallback callback) {
+ mCallback = callback;
+ }
+
+ public void onDeviceAdded(MidiDeviceInfo device) {
+ mCallback.onDeviceAdded(device);
+ }
+
+ public void onDeviceRemoved(MidiDeviceInfo device) {
+ mCallback.onDeviceRemoved(device);
+ }
+ }
+
+ /**
+ * Callback interface used for clients to receive MIDI device added and removed notifications
+ */
+ public interface DeviceCallback {
+ /**
+ * Called to notify when a new MIDI device has been added
+ *
+ * @param device a {@link MidiDeviceInfo} for the newly added device
+ */
+ void onDeviceAdded(MidiDeviceInfo device);
+
+ /**
+ * Called to notify when a MIDI device has been removed
+ *
+ * @param device a {@link MidiDeviceInfo} for the removed device
+ */
+ void onDeviceRemoved(MidiDeviceInfo device);
+ }
+
+ /**
+ * @hide
+ */
+ public MidiManager(Context context, IMidiManager service) {
+ mContext = context;
+ mService = service;
+ }
+
+ /**
+ * Registers a callback to receive notifications when MIDI devices are added and removed.
+ *
+ * @param callback a {@link DeviceCallback} for MIDI device notifications
+ */
+ public void registerDeviceCallback(DeviceCallback callback) {
+ DeviceListener deviceListener = new DeviceListener(callback);
+ try {
+ mService.registerListener(mToken, deviceListener);
+ } catch (RemoteException e) {
+ Log.e(TAG, "RemoteException in registerDeviceListener");
+ return;
+ }
+ mDeviceListeners.put(callback, deviceListener);
+ }
+
+ /**
+ * Unregisters a {@link DeviceCallback}.
+ *
+ * @param callback a {@link DeviceCallback} to unregister
+ */
+ public void unregisterDeviceCallback(DeviceCallback callback) {
+ DeviceListener deviceListener = mDeviceListeners.remove(callback);
+ if (deviceListener != null) {
+ try {
+ mService.unregisterListener(mToken, deviceListener);
+ } catch (RemoteException e) {
+ Log.e(TAG, "RemoteException in unregisterDeviceListener");
+ }
+ }
+ }
+
+ /**
+ * Gets the list of all connected MIDI devices.
+ *
+ * @return an array of all MIDI devices
+ */
+ public MidiDeviceInfo[] getDeviceList() {
+ try {
+ return mService.getDeviceList();
+ } catch (RemoteException e) {
+ Log.e(TAG, "RemoteException in getDeviceList");
+ return new MidiDeviceInfo[0];
+ }
+ }
+
+ /**
+ * Opens a MIDI device for reading and writing.
+ *
+ * @param deviceInfo a {@link android.midi.MidiDeviceInfo} to open
+ * @return a {@link MidiDevice} object for the device
+ */
+ public MidiDevice openDevice(MidiDeviceInfo deviceInfo) {
+ try {
+ IMidiDeviceServer server = mService.openDevice(mToken, deviceInfo);
+ if (server == null) {
+ Log.e(TAG, "could not open device " + deviceInfo);
+ return null;
+ }
+ return new MidiDevice(deviceInfo, server);
+ } catch (RemoteException e) {
+ Log.e(TAG, "RemoteException in openDevice");
+ }
+ return null;
+ }
+
+ /** @hide */
+ public MidiDeviceServer createDeviceServer(int numInputPorts, int numOutputPorts,
+ Bundle properties, boolean isPrivate, int type) {
+ try {
+ MidiDeviceServer server = new MidiDeviceServer(mService);
+ MidiDeviceInfo deviceInfo = mService.registerDeviceServer(server.getBinderInterface(),
+ numInputPorts, numOutputPorts, properties, isPrivate, type);
+ if (deviceInfo == null) {
+ Log.e(TAG, "registerVirtualDevice failed");
+ return null;
+ }
+ server.setDeviceInfo(deviceInfo);
+ return server;
+ } catch (RemoteException e) {
+ Log.e(TAG, "RemoteException in createVirtualDevice");
+ return null;
+ }
+ }
+
+ /**
+ * Creates a new MIDI virtual device.
+ *
+ * @param numInputPorts number of input ports for the virtual device
+ * @param numOutputPorts number of output ports for the virtual device
+ * @param properties a {@link android.os.Bundle} containing properties describing the device
+ * @param isPrivate true if this device should only be visible and accessible to apps
+ * with the same UID as the caller
+ * @return a {@link MidiVirtualDevice} object to locally represent the device
+ */
+ public MidiDeviceServer createDeviceServer(int numInputPorts, int numOutputPorts,
+ Bundle properties, boolean isPrivate) {
+ return createDeviceServer(numInputPorts, numOutputPorts, properties,
+ isPrivate, MidiDeviceInfo.TYPE_VIRTUAL);
+ }
+
+}
diff --git a/core/java/android/midi/MidiOutputPort.java b/core/java/android/midi/MidiOutputPort.java
new file mode 100644
index 0000000..b550ed4
--- /dev/null
+++ b/core/java/android/midi/MidiOutputPort.java
@@ -0,0 +1,137 @@
+/*
+ * Copyright (C) 2014 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.midi;
+
+import android.os.ParcelFileDescriptor;
+import android.util.Log;
+
+import libcore.io.IoUtils;
+
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+
+/**
+ * This class is used for receiving data to a port on a MIDI device
+ *
+ * @hide
+ */
+public class MidiOutputPort extends MidiPort implements MidiSender {
+ private static final String TAG = "MidiOutputPort";
+
+ private final FileInputStream mInputStream;
+
+ // array of receiver lists, indexed by port number
+ private final ArrayList<MidiReceiver> mReceivers = new ArrayList<MidiReceiver>();
+
+ private int mReceiverCount; // total number of receivers for all ports
+
+ // This thread reads MIDI events from a socket and distributes them to the list of
+ // MidiReceivers attached to this device.
+ private final Thread mThread = new Thread() {
+ @Override
+ public void run() {
+ byte[] buffer = new byte[MAX_PACKED_MESSAGE_SIZE];
+ ArrayList<MidiReceiver> deadReceivers = new ArrayList<MidiReceiver>();
+
+ try {
+ while (true) {
+ // read next event
+ int count = mInputStream.read(buffer);
+ if (count < 0) {
+ break;
+ } else if (count < MIN_PACKED_MESSAGE_SIZE || count > MAX_PACKED_MESSAGE_SIZE) {
+ Log.e(TAG, "Number of bytes read out of range: " + count);
+ continue;
+ }
+
+ int offset = getMessageOffset(buffer, count);
+ int size = getMessageSize(buffer, count);
+ long timestamp = getMessageTimeStamp(buffer, count);
+
+ synchronized (mReceivers) {
+ for (int i = 0; i < mReceivers.size(); i++) {
+ MidiReceiver receiver = mReceivers.get(i);
+ try {
+ receiver.onPost(buffer, offset, size, timestamp);
+ } catch (IOException e) {
+ Log.e(TAG, "post failed");
+ deadReceivers.add(receiver);
+ }
+ }
+ // remove any receivers that failed
+ if (deadReceivers.size() > 0) {
+ for (MidiReceiver receiver: deadReceivers) {
+ mReceivers.remove(receiver);
+ mReceiverCount--;
+ }
+ deadReceivers.clear();
+ }
+ // exit if we have no receivers left
+ if (mReceiverCount == 0) {
+ break;
+ }
+ }
+ }
+ } catch (IOException e) {
+ Log.e(TAG, "read failed");
+ // report I/O failure
+ IoUtils.closeQuietly(mInputStream);
+ onIOException();
+ }
+ }
+ };
+
+
+ /* package */ MidiOutputPort(ParcelFileDescriptor pfd, int portNumber) {
+ super(portNumber);
+ mInputStream = new ParcelFileDescriptor.AutoCloseInputStream(pfd);
+ }
+
+ /**
+ * Connects a {@link MidiReceiver} to the output port to allow receiving
+ * MIDI messages from the port.
+ *
+ * @param receiver the receiver to connect
+ */
+ public void connect(MidiReceiver receiver) {
+ synchronized (mReceivers) {
+ mReceivers.add(receiver);
+ if (mReceiverCount++ == 0) {
+ mThread.start();
+ }
+ }
+ }
+
+ /**
+ * Disconnects a {@link MidiReceiver} from the output port.
+ *
+ * @param receiver the receiver to connect
+ */
+ public void disconnect(MidiReceiver receiver) {
+ synchronized (mReceivers) {
+ if (mReceivers.remove(receiver)) {
+ mReceiverCount--;
+ }
+ }
+ }
+
+ @Override
+ public void close() throws IOException {
+ mInputStream.close();
+ }
+}
diff --git a/core/java/android/midi/MidiPort.java b/core/java/android/midi/MidiPort.java
new file mode 100644
index 0000000..1fa7946
--- /dev/null
+++ b/core/java/android/midi/MidiPort.java
@@ -0,0 +1,124 @@
+/*
+ * Copyright (C) 2014 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.midi;
+
+import android.util.Log;
+
+import java.io.Closeable;
+
+/**
+ * This class represents a MIDI input or output port.
+ * Base class for {@link MidiInputPort} and {@link MidiOutputPort}
+ *
+ * @hide
+ */
+abstract public class MidiPort implements Closeable {
+ private static final String TAG = "MidiPort";
+
+ private final int mPortNumber;
+
+ /**
+ * Minimum size of packed message as sent through our ParcelFileDescriptor
+ * 8 bytes for timestamp and 1 to 3 bytes for message
+ */
+ protected static final int MIN_PACKED_MESSAGE_SIZE = 9;
+
+ /**
+ * Maximum size of packed message as sent through our ParcelFileDescriptor
+ * 8 bytes for timestamp and 1 to 3 bytes for message
+ */
+ protected static final int MAX_PACKED_MESSAGE_SIZE = 11;
+
+
+ /* package */ MidiPort(int portNumber) {
+ mPortNumber = portNumber;
+ }
+
+ /**
+ * Returns the port number of this port
+ *
+ * @return the port's port number
+ */
+ public final int getPortNumber() {
+ return mPortNumber;
+ }
+
+ /**
+ * Called when an IOExeption occurs while sending or receiving data.
+ * Subclasses can override to be notified of such errors
+ *
+ */
+ public void onIOException() {
+ }
+
+ /**
+ * Utility function for packing a MIDI message to be sent through our ParcelFileDescriptor
+ *
+ * message byte array contains variable length MIDI message.
+ * messageSize is size of variable length MIDI message
+ * timestamp is message timestamp to pack
+ * dest is buffer to pack into
+ * returns size of packed message
+ */
+ protected static int packMessage(byte[] message, int offset, int size, long timestamp,
+ byte[] dest) {
+ // pack variable length message first
+ System.arraycopy(message, offset, dest, 0, size);
+ int destOffset = size;
+ // timestamp takes 8 bytes
+ for (int i = 0; i < 8; i++) {
+ dest[destOffset++] = (byte)timestamp;
+ timestamp >>= 8;
+ }
+
+ return destOffset;
+ }
+
+ /**
+ * Utility function for unpacking a MIDI message to be sent through our ParcelFileDescriptor
+ * returns the offet of of MIDI message in packed buffer
+ */
+ protected static int getMessageOffset(byte[] buffer, int bufferLength) {
+ // message is at start of buffer
+ return 0;
+ }
+
+ /**
+ * Utility function for unpacking a MIDI message to be sent through our ParcelFileDescriptor
+ * returns size of MIDI message in packed buffer
+ */
+ protected static int getMessageSize(byte[] buffer, int bufferLength) {
+ // message length is total buffer length minus size of the timestamp and port number
+ return bufferLength - 8 /* sizeof(timestamp) */;
+ }
+
+ /**
+ * Utility function for unpacking a MIDI message to be sent through our ParcelFileDescriptor
+ * unpacks timestamp from packed buffer
+ */
+ protected static long getMessageTimeStamp(byte[] buffer, int bufferLength) {
+ long timestamp = 0;
+
+ // timestamp follows variable length message data
+ int dataLength = getMessageSize(buffer, bufferLength);
+ for (int i = dataLength + 7; i >= dataLength; i--) {
+ int b = (int)buffer[i] & 0xFF;
+ timestamp = (timestamp << 8) | b;
+ }
+ return timestamp;
+ }
+}
diff --git a/core/java/android/midi/MidiReceiver.java b/core/java/android/midi/MidiReceiver.java
new file mode 100644
index 0000000..0b183cc
--- /dev/null
+++ b/core/java/android/midi/MidiReceiver.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2014 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.midi;
+
+import java.io.IOException;
+
+/**
+ * Interface for receiving events from a MIDI device.
+ *
+ * @hide
+ */
+public interface MidiReceiver {
+ /**
+ * Called to pass a MIDI event to the receiver.
+ *
+ * NOTE: the msg array parameter is only valid within the context of this call.
+ * The msg bytes should be copied by the receiver rather than retaining a reference
+ * to this parameter.
+ *
+ * @param msg a byte array containing the MIDI message
+ * @param offset the offset of the first byte of the message in the byte array
+ * @param count the number of bytes in the message
+ * @param timestamp the timestamp of the message (based on {@link java.lang.System#nanoTime}
+ * @throws IOException
+ */
+ public void onPost(byte[] msg, int offset, int count, long timestamp) throws IOException;
+}
diff --git a/core/java/android/midi/MidiSender.java b/core/java/android/midi/MidiSender.java
new file mode 100644
index 0000000..7958a06
--- /dev/null
+++ b/core/java/android/midi/MidiSender.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2014 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.midi;
+
+/**
+ * Interface provided by a device to allow attaching
+ * MidiReceivers to a MIDI device.
+ *
+ * @hide
+ */
+public interface MidiSender {
+ /**
+ * Called to connect a {@link MidiReceiver} to the sender
+ *
+ * @param receiver the receiver to connect
+ */
+ public void connect(MidiReceiver receiver);
+
+ /**
+ * Called to disconnect a {@link MidiReceiver} from the sender
+ *
+ * @param receiver the receiver to disconnect
+ */
+ public void disconnect(MidiReceiver receiver);
+}
diff --git a/core/java/android/midi/MidiUtils.java b/core/java/android/midi/MidiUtils.java
new file mode 100644
index 0000000..e60e2db
--- /dev/null
+++ b/core/java/android/midi/MidiUtils.java
@@ -0,0 +1,65 @@
+/*
+ * Copyright (C) 2014 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.midi;
+
+import android.util.Log;
+
+/**
+ * Class containing miscellaneous MIDI utilities.
+ *
+ * @hide
+ */
+public final class MidiUtils {
+ private static final String TAG = "MidiUtils";
+
+ private MidiUtils() { }
+
+ /**
+ * Returns data size of a MIDI message based on the message's command byte
+ * @param b the message command byte
+ * @return the message's data length
+ */
+ public static int getMessageDataSize(byte b) {
+ switch (b & 0xF0) {
+ case 0x80:
+ case 0x90:
+ case 0xA0:
+ case 0xB0:
+ case 0xE0:
+ return 2;
+ case 0xC0:
+ case 0xD0:
+ return 1;
+ case 0xF0:
+ switch (b & 0x0F) {
+ case 0x00:
+ Log.e(TAG, "System Exclusive not supported yet");
+ return -1;
+ case 0x01:
+ case 0x03:
+ return 1;
+ case 0x02:
+ return 2;
+ default:
+ return 0;
+ }
+ default:
+ Log.e(TAG, "unknown MIDI command " + b);
+ return -1;
+ }
+ }
+}
diff --git a/core/java/android/net/ConnectivityManager.java b/core/java/android/net/ConnectivityManager.java
index cdc8661..1a51808 100644
--- a/core/java/android/net/ConnectivityManager.java
+++ b/core/java/android/net/ConnectivityManager.java
@@ -504,6 +504,8 @@ public class ConnectivityManager {
return "MOBILE_EMERGENCY";
case TYPE_PROXY:
return "PROXY";
+ case TYPE_VPN:
+ return "VPN";
default:
return Integer.toString(type);
}
diff --git a/core/java/android/os/Build.java b/core/java/android/os/Build.java
index b209690..2dfd919 100644
--- a/core/java/android/os/Build.java
+++ b/core/java/android/os/Build.java
@@ -91,7 +91,7 @@ public class Build {
/** The name of the hardware (from the kernel command line or /proc). */
public static final String HARDWARE = getString("ro.hardware");
- /** A hardware serial number, if available. Alphanumeric only, case-insensitive. */
+ /** A hardware serial number, if available. Alphanumeric only, case-insensitive. */
public static final String SERIAL = getString("ro.serialno");
/**
@@ -159,7 +159,7 @@ public class Build {
/**
* The user-visible SDK version of the framework in its raw String
* representation; use {@link #SDK_INT} instead.
- *
+ *
* @deprecated Use {@link #SDK_INT} to easily get this as an integer.
*/
@Deprecated
@@ -207,25 +207,25 @@ public class Build {
* not yet turned into an official release.
*/
public static final int CUR_DEVELOPMENT = 10000;
-
+
/**
* October 2008: The original, first, version of Android. Yay!
*/
public static final int BASE = 1;
-
+
/**
* February 2009: First Android update, officially called 1.1.
*/
public static final int BASE_1_1 = 2;
-
+
/**
* May 2009: Android 1.5.
*/
public static final int CUPCAKE = 3;
-
+
/**
* September 2009: Android 1.6.
- *
+ *
* <p>Applications targeting this or a later release will get these
* new changes in behavior:</p>
* <ul>
@@ -247,10 +247,10 @@ public class Build {
* </ul>
*/
public static final int DONUT = 4;
-
+
/**
* November 2009: Android 2.0
- *
+ *
* <p>Applications targeting this or a later release will get these
* new changes in behavior:</p>
* <ul>
@@ -267,22 +267,22 @@ public class Build {
* </ul>
*/
public static final int ECLAIR = 5;
-
+
/**
* December 2009: Android 2.0.1
*/
public static final int ECLAIR_0_1 = 6;
-
+
/**
* January 2010: Android 2.1
*/
public static final int ECLAIR_MR1 = 7;
-
+
/**
* June 2010: Android 2.2
*/
public static final int FROYO = 8;
-
+
/**
* November 2010: Android 2.3
*
@@ -294,7 +294,7 @@ public class Build {
* </ul>
*/
public static final int GINGERBREAD = 9;
-
+
/**
* February 2011: Android 2.3.3.
*/
@@ -339,12 +339,12 @@ public class Build {
* </ul>
*/
public static final int HONEYCOMB = 11;
-
+
/**
* May 2011: Android 3.1.
*/
public static final int HONEYCOMB_MR1 = 12;
-
+
/**
* June 2011: Android 3.2.
*
@@ -598,7 +598,7 @@ public class Build {
*/
public static final int LOLLIPOP_MR1 = 22;
}
-
+
/** The type of build, like "user" or "eng". */
public static final String TYPE = getString("ro.build.type");
@@ -653,6 +653,7 @@ public class Build {
public static boolean isFingerprintConsistent() {
final String system = SystemProperties.get("ro.build.fingerprint");
final String vendor = SystemProperties.get("ro.vendor.build.fingerprint");
+ final String bootimage = SystemProperties.get("ro.bootimage.build.fingerprint");
if (TextUtils.isEmpty(system)) {
Slog.e(TAG, "Required ro.build.fingerprint is empty!");
@@ -667,6 +668,14 @@ public class Build {
}
}
+ if (!TextUtils.isEmpty(bootimage)) {
+ if (!Objects.equals(system, bootimage)) {
+ Slog.e(TAG, "Mismatched fingerprints; system reported " + system
+ + " but bootimage reported " + bootimage);
+ return false;
+ }
+ }
+
return true;
}
diff --git a/core/java/android/os/Debug.java b/core/java/android/os/Debug.java
index 2d92c7b..d03365b 100644
--- a/core/java/android/os/Debug.java
+++ b/core/java/android/os/Debug.java
@@ -1286,7 +1286,10 @@ href="{@docRoot}guide/developing/tools/traceview.html">Traceview: A Graphical Lo
* + icount.globalMethodInvocations());
* }
* </pre>
+ *
+ * @deprecated Instruction counting is no longer supported.
*/
+ @Deprecated
public static class InstructionCount {
private static final int NUM_INSTR =
OpcodeInfo.MAXIMUM_PACKED_VALUE + 1;
diff --git a/core/java/android/os/ParcelFileDescriptor.java b/core/java/android/os/ParcelFileDescriptor.java
index c6b2151..4e8ec89 100644
--- a/core/java/android/os/ParcelFileDescriptor.java
+++ b/core/java/android/os/ParcelFileDescriptor.java
@@ -395,10 +395,17 @@ public class ParcelFileDescriptor implements Parcelable, Closeable {
* connected to each other. The two sockets are indistinguishable.
*/
public static ParcelFileDescriptor[] createSocketPair() throws IOException {
+ return createSocketPair(SOCK_STREAM);
+ }
+
+ /**
+ * @hide
+ */
+ public static ParcelFileDescriptor[] createSocketPair(int type) throws IOException {
try {
final FileDescriptor fd0 = new FileDescriptor();
final FileDescriptor fd1 = new FileDescriptor();
- Os.socketpair(AF_UNIX, SOCK_STREAM, 0, fd0, fd1);
+ Os.socketpair(AF_UNIX, type, 0, fd0, fd1);
return new ParcelFileDescriptor[] {
new ParcelFileDescriptor(fd0),
new ParcelFileDescriptor(fd1) };
@@ -417,11 +424,18 @@ public class ParcelFileDescriptor implements Parcelable, Closeable {
* This can also be used to detect remote crashes.
*/
public static ParcelFileDescriptor[] createReliableSocketPair() throws IOException {
+ return createReliableSocketPair(SOCK_STREAM);
+ }
+
+ /**
+ * @hide
+ */
+ public static ParcelFileDescriptor[] createReliableSocketPair(int type) throws IOException {
try {
final FileDescriptor[] comm = createCommSocketPair();
final FileDescriptor fd0 = new FileDescriptor();
final FileDescriptor fd1 = new FileDescriptor();
- Os.socketpair(AF_UNIX, SOCK_STREAM, 0, fd0, fd1);
+ Os.socketpair(AF_UNIX, type, 0, fd0, fd1);
return new ParcelFileDescriptor[] {
new ParcelFileDescriptor(fd0, comm[0]),
new ParcelFileDescriptor(fd1, comm[1]) };
diff --git a/core/java/android/os/StrictMode.java b/core/java/android/os/StrictMode.java
index 5018711..0b55998 100644
--- a/core/java/android/os/StrictMode.java
+++ b/core/java/android/os/StrictMode.java
@@ -145,7 +145,7 @@ public final class StrictMode {
* in {@link VmPolicy.Builder#detectAll()}. Apps can still always opt-into
* detection using {@link VmPolicy.Builder#detectCleartextNetwork()}.
*/
- private static final String CLEARTEXT_PROPERTY = "persist.sys.strictmode.nonssl";
+ private static final String CLEARTEXT_PROPERTY = "persist.sys.strictmode.clear";
// Only log a duplicate stack trace to the logs every second.
private static final long MIN_LOG_INTERVAL_MS = 1000;
@@ -184,8 +184,16 @@ public final class StrictMode {
*/
public static final int DETECT_CUSTOM = 0x08; // for ThreadPolicy
+ /**
+ * For StrictMode.noteResourceMismatch()
+ *
+ * @hide
+ */
+ public static final int DETECT_RESOURCE_MISMATCH = 0x10; // for ThreadPolicy
+
private static final int ALL_THREAD_DETECT_BITS =
- DETECT_DISK_WRITE | DETECT_DISK_READ | DETECT_NETWORK | DETECT_CUSTOM;
+ DETECT_DISK_WRITE | DETECT_DISK_READ | DETECT_NETWORK | DETECT_CUSTOM |
+ DETECT_RESOURCE_MISMATCH;
// Byte 2: Process-policy
@@ -460,6 +468,22 @@ public final class StrictMode {
}
/**
+ * Disable detection of mismatches between defined resource types
+ * and getter calls.
+ */
+ public Builder permitResourceMismatches() {
+ return disable(DETECT_RESOURCE_MISMATCH);
+ }
+
+ /**
+ * Enable detection of mismatches between defined resource types
+ * and getter calls.
+ */
+ public Builder detectResourceMismatches() {
+ return enable(DETECT_RESOURCE_MISMATCH);
+ }
+
+ /**
* Enable detection of disk writes.
*/
public Builder detectDiskWrites() {
@@ -739,8 +763,6 @@ public final class StrictMode {
* This inspects both IPv4/IPv6 and TCP/UDP network traffic, but it
* may be subject to false positives, such as when STARTTLS
* protocols or HTTP proxies are used.
- *
- * @hide
*/
public Builder detectCleartextNetwork() {
return enable(DETECT_VM_CLEARTEXT_NETWORK);
@@ -760,7 +782,6 @@ public final class StrictMode {
* detected.
*
* @see #detectCleartextNetwork()
- * @hide
*/
public Builder penaltyDeathOnCleartextNetwork() {
return enable(PENALTY_DEATH_ON_CLEARTEXT_NETWORK);
@@ -923,6 +944,15 @@ public final class StrictMode {
}
/**
+ * @hide
+ */
+ private static class StrictModeResourceMismatchViolation extends StrictModeViolation {
+ public StrictModeResourceMismatchViolation(int policyMask, Object tag) {
+ super(policyMask, DETECT_RESOURCE_MISMATCH, tag != null ? tag.toString() : null);
+ }
+ }
+
+ /**
* Returns the bitmask of the current thread's policy.
*
* @return the bitmask of all the DETECT_* and PENALTY_* bits currently enabled
@@ -1197,6 +1227,20 @@ public final class StrictMode {
startHandlingViolationException(e);
}
+ // Not part of BlockGuard.Policy; just part of StrictMode:
+ void onResourceMismatch(Object tag) {
+ if ((mPolicyMask & DETECT_RESOURCE_MISMATCH) == 0) {
+ return;
+ }
+ if (tooManyViolationsThisLoop()) {
+ return;
+ }
+ BlockGuard.BlockGuardPolicyException e =
+ new StrictModeResourceMismatchViolation(mPolicyMask, tag);
+ e.fillInStackTrace();
+ startHandlingViolationException(e);
+ }
+
// Part of BlockGuard.Policy interface:
public void onReadFromDisk() {
if ((mPolicyMask & DETECT_DISK_READ) == 0) {
@@ -2083,6 +2127,26 @@ public final class StrictMode {
}
/**
+ * For code to note that a resource was obtained using a type other than
+ * its defined type. This is a no-op unless the current thread's
+ * {@link android.os.StrictMode.ThreadPolicy} has
+ * {@link android.os.StrictMode.ThreadPolicy.Builder#detectResourceMismatches()}
+ * enabled.
+ *
+ * @param tag an object for the exception stack trace that's
+ * built if when this fires.
+ * @hide
+ */
+ public static void noteResourceMismatch(Object tag) {
+ BlockGuard.Policy policy = BlockGuard.getThreadPolicy();
+ if (!(policy instanceof AndroidBlockGuardPolicy)) {
+ // StrictMode not enabled.
+ return;
+ }
+ ((AndroidBlockGuardPolicy) policy).onResourceMismatch(tag);
+ }
+
+ /**
* @hide
*/
public static void noteDiskRead() {
diff --git a/core/java/android/provider/Contacts.java b/core/java/android/provider/Contacts.java
index d4c5cfb..3aa526d 100644
--- a/core/java/android/provider/Contacts.java
+++ b/core/java/android/provider/Contacts.java
@@ -2077,12 +2077,12 @@ public class Contacts {
/**
* Intents related to the Contacts app UI.
- * @deprecated see {@link android.provider.ContactsContract}
+ * @deprecated Do not use. This is not supported.
*/
@Deprecated
public static final class UI {
/**
- * @deprecated see {@link android.provider.ContactsContract}
+ * @deprecated Do not use. This is not supported.
*/
@Deprecated
public UI() {
@@ -2090,76 +2090,77 @@ public class Contacts {
/**
* The action for the default contacts list tab.
- * @deprecated see {@link android.provider.ContactsContract}
+ * @deprecated Do not use. This is not supported.
*/
@Deprecated
- public static final String LIST_DEFAULT = ContactsContract.Intents.UI.LIST_DEFAULT;
+ public static final String LIST_DEFAULT
+ = "com.android.contacts.action.LIST_DEFAULT";
/**
* The action for the contacts list tab.
- * @deprecated see {@link android.provider.ContactsContract}
+ * @deprecated Do not use. This is not supported.
*/
@Deprecated
public static final String LIST_GROUP_ACTION =
- ContactsContract.Intents.UI.LIST_GROUP_ACTION;
+ "com.android.contacts.action.LIST_GROUP";
/**
* When in LIST_GROUP_ACTION mode, this is the group to display.
- * @deprecated see {@link android.provider.ContactsContract}
+ * @deprecated Do not use. This is not supported.
*/
@Deprecated
public static final String GROUP_NAME_EXTRA_KEY =
- ContactsContract.Intents.UI.GROUP_NAME_EXTRA_KEY;
+ "com.android.contacts.extra.GROUP";
/**
* The action for the all contacts list tab.
- * @deprecated see {@link android.provider.ContactsContract}
+ * @deprecated Do not use. This is not supported.
*/
@Deprecated
public static final String LIST_ALL_CONTACTS_ACTION =
- ContactsContract.Intents.UI.LIST_ALL_CONTACTS_ACTION;
+ "com.android.contacts.action.LIST_ALL_CONTACTS";
/**
* The action for the contacts with phone numbers list tab.
- * @deprecated see {@link android.provider.ContactsContract}
+ * @deprecated Do not use. This is not supported.
*/
@Deprecated
public static final String LIST_CONTACTS_WITH_PHONES_ACTION =
- ContactsContract.Intents.UI.LIST_CONTACTS_WITH_PHONES_ACTION;
+ "com.android.contacts.action.LIST_CONTACTS_WITH_PHONES";
/**
* The action for the starred contacts list tab.
- * @deprecated see {@link android.provider.ContactsContract}
+ * @deprecated Do not use. This is not supported.
*/
@Deprecated
public static final String LIST_STARRED_ACTION =
- ContactsContract.Intents.UI.LIST_STARRED_ACTION;
+ "com.android.contacts.action.LIST_STARRED";
/**
* The action for the frequent contacts list tab.
- * @deprecated see {@link android.provider.ContactsContract}
+ * @deprecated Do not use. This is not supported.
*/
@Deprecated
public static final String LIST_FREQUENT_ACTION =
- ContactsContract.Intents.UI.LIST_FREQUENT_ACTION;
+ "com.android.contacts.action.LIST_FREQUENT";
/**
* The action for the "strequent" contacts list tab. It first lists the starred
* contacts in alphabetical order and then the frequent contacts in descending
* order of the number of times they have been contacted.
- * @deprecated see {@link android.provider.ContactsContract}
+ * @deprecated Do not use. This is not supported.
*/
@Deprecated
public static final String LIST_STREQUENT_ACTION =
- ContactsContract.Intents.UI.LIST_STREQUENT_ACTION;
+ "com.android.contacts.action.LIST_STREQUENT";
/**
* A key for to be used as an intent extra to set the activity
* title to a custom String value.
- * @deprecated see {@link android.provider.ContactsContract}
+ * @deprecated Do not use. This is not supported.
*/
@Deprecated
public static final String TITLE_EXTRA_KEY =
- ContactsContract.Intents.UI.TITLE_EXTRA_KEY;
+ "com.android.contacts.extra.TITLE_EXTRA";
/**
* Activity Action: Display a filtered list of contacts
@@ -2168,20 +2169,20 @@ public class Contacts {
* filtering
* <p>
* Output: Nothing.
- * @deprecated see {@link android.provider.ContactsContract}
+ * @deprecated Do not use. This is not supported.
*/
@Deprecated
public static final String FILTER_CONTACTS_ACTION =
- ContactsContract.Intents.UI.FILTER_CONTACTS_ACTION;
+ "com.android.contacts.action.FILTER_CONTACTS";
/**
* Used as an int extra field in {@link #FILTER_CONTACTS_ACTION}
* intents to supply the text on which to filter.
- * @deprecated see {@link android.provider.ContactsContract}
+ * @deprecated Do not use. This is not supported.
*/
@Deprecated
public static final String FILTER_TEXT_EXTRA_KEY =
- ContactsContract.Intents.UI.FILTER_TEXT_EXTRA_KEY;
+ "com.android.contacts.extra.FILTER_TEXT";
}
/**
diff --git a/core/java/android/provider/ContactsContract.java b/core/java/android/provider/ContactsContract.java
index 18a9eb1..d24e614 100644
--- a/core/java/android/provider/ContactsContract.java
+++ b/core/java/android/provider/ContactsContract.java
@@ -197,12 +197,15 @@ public final class ContactsContract {
* API for obtaining a pre-authorized version of a URI that normally requires special
* permission (beyond READ_CONTACTS) to read. The caller obtaining the pre-authorized URI
* must already have the necessary permissions to access the URI; otherwise a
- * {@link SecurityException} will be thrown.
+ * {@link SecurityException} will be thrown. Unlike {@link Context#grantUriPermission},
+ * this can be used to grant permissions that aren't explicitly required for the URI inside
+ * AndroidManifest.xml. For example, permissions that are only required when reading URIs
+ * that refer to the user's profile.
* </p>
* <p>
* The authorized URI returned in the bundle contains an expiring token that allows the
* caller to execute the query without having the special permissions that would normally
- * be required.
+ * be required. The token expires in five minutes.
* </p>
* <p>
* This API does not access disk, and should be safe to invoke from the UI thread.
@@ -226,7 +229,6 @@ public final class ContactsContract {
* }
* </pre>
* </p>
- * @hide
*/
public static final class Authorization {
/**
@@ -1790,52 +1792,26 @@ public final class ContactsContract {
public static final String CONTENT_DIRECTORY = "suggestions";
/**
- * Used with {@link Builder#addParameter} to specify what kind of data is
- * supplied for the suggestion query.
+ * Used to specify what kind of data is supplied for the suggestion query.
*
* @hide
*/
public static final String PARAMETER_MATCH_NAME = "name";
/**
- * Used with {@link Builder#addParameter} to specify what kind of data is
- * supplied for the suggestion query.
- *
- * @hide
- */
- public static final String PARAMETER_MATCH_EMAIL = "email";
-
- /**
- * Used with {@link Builder#addParameter} to specify what kind of data is
- * supplied for the suggestion query.
- *
- * @hide
- */
- public static final String PARAMETER_MATCH_PHONE = "phone";
-
- /**
- * Used with {@link Builder#addParameter} to specify what kind of data is
- * supplied for the suggestion query.
- *
- * @hide
- */
- public static final String PARAMETER_MATCH_NICKNAME = "nickname";
-
- /**
* A convenience builder for aggregation suggestion content URIs.
- *
- * TODO: change documentation for this class to use the builder.
- * @hide
*/
public static final class Builder {
private long mContactId;
- private ArrayList<String> mKinds = new ArrayList<String>();
- private ArrayList<String> mValues = new ArrayList<String>();
+ private final ArrayList<String> mValues = new ArrayList<String>();
private int mLimit;
/**
* Optional existing contact ID. If it is not provided, the search
- * will be based exclusively on the values supplied with {@link #addParameter}.
+ * will be based exclusively on the values supplied with {@link #addNameParameter}.
+ *
+ * @param contactId contact to find aggregation suggestions for
+ * @return This Builder object to allow for chaining of calls to builder methods
*/
public Builder setContactId(long contactId) {
this.mContactId = contactId;
@@ -1843,28 +1819,31 @@ public final class ContactsContract {
}
/**
- * A value that can be used when searching for an aggregation
- * suggestion.
+ * Add a name to be used when searching for aggregation suggestions.
*
- * @param kind can be one of
- * {@link AggregationSuggestions#PARAMETER_MATCH_NAME},
- * {@link AggregationSuggestions#PARAMETER_MATCH_EMAIL},
- * {@link AggregationSuggestions#PARAMETER_MATCH_NICKNAME},
- * {@link AggregationSuggestions#PARAMETER_MATCH_PHONE}
+ * @param name name to find aggregation suggestions for
+ * @return This Builder object to allow for chaining of calls to builder methods
*/
- public Builder addParameter(String kind, String value) {
- if (!TextUtils.isEmpty(value)) {
- mKinds.add(kind);
- mValues.add(value);
- }
+ public Builder addNameParameter(String name) {
+ mValues.add(name);
return this;
}
+ /**
+ * Sets the Maximum number of suggested aggregations that should be returned.
+ * @param limit The maximum number of suggested aggregations
+ *
+ * @return This Builder object to allow for chaining of calls to builder methods
+ */
public Builder setLimit(int limit) {
mLimit = limit;
return this;
}
+ /**
+ * Combine all of the options that have been set and return a new {@link Uri}
+ * object for fetching aggregation suggestions.
+ */
public Uri build() {
android.net.Uri.Builder builder = Contacts.CONTENT_URI.buildUpon();
builder.appendEncodedPath(String.valueOf(mContactId));
@@ -1873,9 +1852,10 @@ public final class ContactsContract {
builder.appendQueryParameter("limit", String.valueOf(mLimit));
}
- int count = mKinds.size();
+ int count = mValues.size();
for (int i = 0; i < count; i++) {
- builder.appendQueryParameter("query", mKinds.get(i) + ":" + mValues.get(i));
+ builder.appendQueryParameter("query", PARAMETER_MATCH_NAME
+ + ":" + mValues.get(i));
}
return builder.build();
@@ -7839,9 +7819,7 @@ public final class ContactsContract {
}
/**
- * Private API for inquiring about the general status of the provider.
- *
- * @hide
+ * API for inquiring about the general status of the provider.
*/
public static final class ProviderStatus {
@@ -7854,8 +7832,6 @@ public final class ContactsContract {
/**
* The content:// style URI for this table. Requests to this URI can be
* performed on the UI thread because they are always unblocking.
- *
- * @hide
*/
public static final Uri CONTENT_URI =
Uri.withAppendedPath(AUTHORITY_URI, "provider_status");
@@ -7863,64 +7839,35 @@ public final class ContactsContract {
/**
* The MIME-type of {@link #CONTENT_URI} providing a directory of
* settings.
- *
- * @hide
*/
public static final String CONTENT_TYPE = "vnd.android.cursor.dir/provider_status";
/**
* An integer representing the current status of the provider.
- *
- * @hide
*/
public static final String STATUS = "status";
/**
* Default status of the provider.
- *
- * @hide
*/
public static final int STATUS_NORMAL = 0;
/**
* The status used when the provider is in the process of upgrading. Contacts
* are temporarily unaccessible.
- *
- * @hide
*/
public static final int STATUS_UPGRADING = 1;
/**
- * The status used if the provider was in the process of upgrading but ran
- * out of storage. The DATA1 column will contain the estimated amount of
- * storage required (in bytes). Update status to STATUS_NORMAL to force
- * the provider to retry the upgrade.
- *
- * @hide
- */
- public static final int STATUS_UPGRADE_OUT_OF_MEMORY = 2;
-
- /**
* The status used during a locale change.
- *
- * @hide
*/
public static final int STATUS_CHANGING_LOCALE = 3;
/**
* The status that indicates that there are no accounts and no contacts
* on the device.
- *
- * @hide
*/
public static final int STATUS_NO_ACCOUNTS_NO_CONTACTS = 4;
-
- /**
- * Additional data associated with the status.
- *
- * @hide
- */
- public static final String DATA1 = "data1";
}
/**
@@ -8538,102 +8485,6 @@ public final class ContactsContract {
public static final String EXTRA_EXCLUDE_MIMES = "exclude_mimes";
/**
- * Intents related to the Contacts app UI.
- *
- * @hide
- */
- public static final class UI {
- /**
- * The action for the default contacts list tab.
- */
- public static final String LIST_DEFAULT =
- "com.android.contacts.action.LIST_DEFAULT";
-
- /**
- * The action for the contacts list tab.
- */
- public static final String LIST_GROUP_ACTION =
- "com.android.contacts.action.LIST_GROUP";
-
- /**
- * When in LIST_GROUP_ACTION mode, this is the group to display.
- */
- public static final String GROUP_NAME_EXTRA_KEY = "com.android.contacts.extra.GROUP";
-
- /**
- * The action for the all contacts list tab.
- */
- public static final String LIST_ALL_CONTACTS_ACTION =
- "com.android.contacts.action.LIST_ALL_CONTACTS";
-
- /**
- * The action for the contacts with phone numbers list tab.
- */
- public static final String LIST_CONTACTS_WITH_PHONES_ACTION =
- "com.android.contacts.action.LIST_CONTACTS_WITH_PHONES";
-
- /**
- * The action for the starred contacts list tab.
- */
- public static final String LIST_STARRED_ACTION =
- "com.android.contacts.action.LIST_STARRED";
-
- /**
- * The action for the frequent contacts list tab.
- */
- public static final String LIST_FREQUENT_ACTION =
- "com.android.contacts.action.LIST_FREQUENT";
-
- /**
- * The action for the "Join Contact" picker.
- */
- public static final String PICK_JOIN_CONTACT_ACTION =
- "com.android.contacts.action.JOIN_CONTACT";
-
- /**
- * The action for the "strequent" contacts list tab. It first lists the starred
- * contacts in alphabetical order and then the frequent contacts in descending
- * order of the number of times they have been contacted.
- */
- public static final String LIST_STREQUENT_ACTION =
- "com.android.contacts.action.LIST_STREQUENT";
-
- /**
- * A key for to be used as an intent extra to set the activity
- * title to a custom String value.
- */
- public static final String TITLE_EXTRA_KEY =
- "com.android.contacts.extra.TITLE_EXTRA";
-
- /**
- * Activity Action: Display a filtered list of contacts
- * <p>
- * Input: Extra field {@link #FILTER_TEXT_EXTRA_KEY} is the text to use for
- * filtering
- * <p>
- * Output: Nothing.
- */
- public static final String FILTER_CONTACTS_ACTION =
- "com.android.contacts.action.FILTER_CONTACTS";
-
- /**
- * Used as an int extra field in {@link #FILTER_CONTACTS_ACTION}
- * intents to supply the text on which to filter.
- */
- public static final String FILTER_TEXT_EXTRA_KEY =
- "com.android.contacts.extra.FILTER_TEXT";
-
- /**
- * Used with JOIN_CONTACT action to set the target for aggregation. This action type
- * uses contact ids instead of contact uris for the sake of backwards compatibility.
- * <p>
- * Type: LONG
- */
- public static final String TARGET_CONTACT_ID_EXTRA_KEY
- = "com.android.contacts.action.CONTACT_ID";
- }
-
- /**
* Convenience class that contains string constants used
* to create contact {@link android.content.Intent Intents}.
*/
diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java
index 3e75460..e055203 100644
--- a/core/java/android/provider/Settings.java
+++ b/core/java/android/provider/Settings.java
@@ -18,7 +18,6 @@ package android.provider;
import android.annotation.SdkConstant;
import android.annotation.SdkConstant.SdkConstantType;
-import android.annotation.SystemApi;
import android.app.SearchManager;
import android.app.WallpaperManager;
import android.content.ComponentName;
@@ -132,7 +131,6 @@ public final class Settings {
"android.settings.AIRPLANE_MODE_SETTINGS";
/**
- * @hide
* Activity Action: Modify Airplane mode settings using the users voice.
* <p>
* In some cases, a matching Activity may not exist, so ensure you safeguard against this.
@@ -154,7 +152,6 @@ public final class Settings {
* Output: Nothing.
*/
@SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
- @SystemApi
public static final String ACTION_VOICE_CONTROL_AIRPLANE_MODE =
"android.settings.VOICE_CONTROL_AIRPLANE_MODE";
@@ -308,7 +305,7 @@ public final class Settings {
/**
* Activity Action: Show settings to allow configuration of
- * cast endpoints.
+ * {@link android.media.routing.MediaRouteService media route providers}.
* <p>
* In some cases, a matching Activity may not exist, so ensure you
* safeguard against this.
@@ -991,13 +988,11 @@ public final class Settings {
public static final String EXTRA_INPUT_DEVICE_IDENTIFIER = "input_device_identifier";
/**
- * @hide
* Activity Extra: Enable or disable Airplane Mode.
* <p>
* This can be passed as an extra field to the {@link #ACTION_VOICE_CONTROL_AIRPLANE_MODE}
* intent as a boolean.
*/
- @SystemApi
public static final String EXTRA_AIRPLANE_MODE_ENABLED = "airplane_mode_enabled";
private static final String JID_RESOURCE_PREFIX = "android";
@@ -3657,6 +3652,7 @@ public final class Settings {
* A flag containing settings used for biometric weak
* @hide
*/
+ @Deprecated
public static final String LOCK_BIOMETRIC_WEAK_FLAGS =
"lock_biometric_weak_flags";
@@ -3668,7 +3664,11 @@ public final class Settings {
/**
* Whether autolock is enabled (0 = false, 1 = true)
+ *
+ * @deprecated Use {@link android.app.KeyguardManager} to determine the state and security
+ * level of the keyguard.
*/
+ @Deprecated
public static final String LOCK_PATTERN_ENABLED = "lock_pattern_autolock";
/**
@@ -3707,6 +3707,7 @@ public final class Settings {
* Ids of the user-selected appwidgets on the lockscreen (comma-delimited).
* @hide
*/
+ @Deprecated
public static final String LOCK_SCREEN_APPWIDGET_IDS =
"lock_screen_appwidget_ids";
@@ -3720,6 +3721,7 @@ public final class Settings {
* Id of the appwidget shown on the lock screen when appwidgets are disabled.
* @hide
*/
+ @Deprecated
public static final String LOCK_SCREEN_FALLBACK_APPWIDGET_ID =
"lock_screen_fallback_appwidget_id";
@@ -3727,6 +3729,7 @@ public final class Settings {
* Index of the lockscreen appwidget to restore, -1 if none.
* @hide
*/
+ @Deprecated
public static final String LOCK_SCREEN_STICKY_APPWIDGET =
"lock_screen_sticky_appwidget";
diff --git a/core/java/android/service/voice/VoiceInteractionService.java b/core/java/android/service/voice/VoiceInteractionService.java
index 0cde4f2..65e6988 100644
--- a/core/java/android/service/voice/VoiceInteractionService.java
+++ b/core/java/android/service/voice/VoiceInteractionService.java
@@ -40,15 +40,16 @@ import java.util.Locale;
/**
* Top-level service of the current global voice interactor, which is providing
- * support for hotwording etc.
+ * support for hotwording, the back-end of a {@link android.app.VoiceInteractor}, etc.
* The current VoiceInteractionService that has been selected by the user is kept
* always running by the system, to allow it to do things like listen for hotwords
- * in the background.
+ * in the background to instigate voice interactions.
*
* <p>Because this service is always running, it should be kept as lightweight as
* possible. Heavy-weight operations (including showing UI) should be implemented
- * in the associated {@link android.service.voice.VoiceInteractionSessionService}
- * that only runs while the operation is active.
+ * in the associated {@link android.service.voice.VoiceInteractionSessionService} when
+ * an actual voice interaction is taking place, and that service should run in a
+ * separate process from this one.
*/
public class VoiceInteractionService extends Service {
/**
diff --git a/core/java/android/service/voice/VoiceInteractionSession.java b/core/java/android/service/voice/VoiceInteractionSession.java
index 749f813..19d14bf 100644
--- a/core/java/android/service/voice/VoiceInteractionSession.java
+++ b/core/java/android/service/voice/VoiceInteractionSession.java
@@ -16,7 +16,6 @@
package android.service.voice;
-import android.annotation.SystemApi;
import android.app.Dialog;
import android.app.Instrumentation;
import android.content.Context;
@@ -54,7 +53,15 @@ import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
/**
- * An active interaction session, started by a {@link VoiceInteractionService}.
+ * An active voice interaction session, providing a facility for the implementation
+ * to interact with the user in the voice interaction layer. This interface is no shown
+ * by default, but you can request that it be shown with {@link #showWindow()}, which
+ * will result in a later call to {@link #onCreateContentView()} in which the UI can be
+ * built
+ *
+ * <p>A voice interaction session can be self-contained, ultimately calling {@link #finish}
+ * when done. It can also initiate voice interactions with applications by calling
+ * {@link #startVoiceActivity}</p>.
*/
public abstract class VoiceInteractionSession implements KeyEvent.Callback {
static final String TAG = "VoiceInteractionSession";
@@ -168,10 +175,6 @@ public abstract class VoiceInteractionSession implements KeyEvent.Callback {
}
};
- /**
- * @hide
- */
- @SystemApi
public static class Request {
final IVoiceInteractorRequest mInterface = new IVoiceInteractorRequest.Stub() {
@Override
@@ -255,10 +258,6 @@ public abstract class VoiceInteractionSession implements KeyEvent.Callback {
}
}
- /**
- * @hide
- */
- @SystemApi
public static class Caller {
final String packageName;
final int uid;
@@ -354,10 +353,8 @@ public abstract class VoiceInteractionSession implements KeyEvent.Callback {
final MyCallbacks mCallbacks = new MyCallbacks();
/**
- * @hide
* Information about where interesting parts of the input method UI appear.
*/
- @SystemApi
public static final class Insets {
/**
* This is the part of the UI that is the main content. It is
@@ -477,10 +474,6 @@ public abstract class VoiceInteractionSession implements KeyEvent.Callback {
mContentFrame = (FrameLayout)mRootView.findViewById(android.R.id.content);
}
- /**
- * @hide
- */
- @SystemApi
public void showWindow() {
if (DEBUG) Log.v(TAG, "Showing window: mWindowAdded=" + mWindowAdded
+ " mWindowVisible=" + mWindowVisible);
@@ -509,10 +502,6 @@ public abstract class VoiceInteractionSession implements KeyEvent.Callback {
}
}
- /**
- * @hide
- */
- @SystemApi
public void hideWindow() {
if (mWindowVisible) {
mWindow.hide();
@@ -521,13 +510,11 @@ public abstract class VoiceInteractionSession implements KeyEvent.Callback {
}
/**
- * @hide
* You can call this to customize the theme used by your IME's window.
* This must be set before {@link #onCreate}, so you
* will typically call it in your constructor with the resource ID
* of your custom theme.
*/
- @SystemApi
public void setTheme(int theme) {
if (mWindow != null) {
throw new IllegalStateException("Must be called before onCreate()");
@@ -536,7 +523,6 @@ public abstract class VoiceInteractionSession implements KeyEvent.Callback {
}
/**
- * @hide
* Ask that a new activity be started for voice interaction. This will create a
* new dedicated task in the activity manager for this voice interaction session;
* this means that {@link Intent#FLAG_ACTIVITY_NEW_TASK Intent.FLAG_ACTIVITY_NEW_TASK}
@@ -557,7 +543,6 @@ public abstract class VoiceInteractionSession implements KeyEvent.Callback {
* always have {@link Intent#CATEGORY_VOICE Intent.CATEGORY_VOICE} added to it, since
* this is part of a voice interaction.
*/
- @SystemApi
public void startVoiceActivity(Intent intent) {
if (mToken == null) {
throw new IllegalStateException("Can't call before onCreate()");
@@ -573,19 +558,15 @@ public abstract class VoiceInteractionSession implements KeyEvent.Callback {
}
/**
- * @hide
* Convenience for inflating views.
*/
- @SystemApi
public LayoutInflater getLayoutInflater() {
return mInflater;
}
/**
- * @hide
* Retrieve the window being used to show the session's UI.
*/
- @SystemApi
public Dialog getWindow() {
return mWindow;
}
@@ -631,10 +612,8 @@ public abstract class VoiceInteractionSession implements KeyEvent.Callback {
}
/**
- * @hide
* Hook in which to create the session's UI.
*/
- @SystemApi
public View onCreateContentView() {
return null;
}
@@ -647,42 +626,22 @@ public abstract class VoiceInteractionSession implements KeyEvent.Callback {
}
- /**
- * @hide
- */
- @SystemApi
public boolean onKeyDown(int keyCode, KeyEvent event) {
return false;
}
- /**
- * @hide
- */
- @SystemApi
public boolean onKeyLongPress(int keyCode, KeyEvent event) {
return false;
}
- /**
- * @hide
- */
- @SystemApi
public boolean onKeyUp(int keyCode, KeyEvent event) {
return false;
}
- /**
- * @hide
- */
- @SystemApi
public boolean onKeyMultiple(int keyCode, int count, KeyEvent event) {
return false;
}
- /**
- * @hide
- */
- @SystemApi
public void onBackPressed() {
finish();
}
@@ -697,14 +656,12 @@ public abstract class VoiceInteractionSession implements KeyEvent.Callback {
}
/**
- * @hide
* Compute the interesting insets into your UI. The default implementation
* uses the entire window frame as the insets. The default touchable
* insets are {@link Insets#TOUCHABLE_INSETS_FRAME}.
*
* @param outInsets Fill in with the current UI insets.
*/
- @SystemApi
public void onComputeInsets(Insets outInsets) {
int[] loc = mTmpLocation;
View decor = getWindow().getWindow().getDecorView();
@@ -718,8 +675,6 @@ public abstract class VoiceInteractionSession implements KeyEvent.Callback {
}
/**
- * @hide
- * @SystemApi
* Called when a task initiated by {@link #startVoiceActivity(android.content.Intent)}
* has actually started.
*
@@ -731,8 +686,6 @@ public abstract class VoiceInteractionSession implements KeyEvent.Callback {
}
/**
- * @hide
- * @SystemApi
* Called when the last activity of a task initiated by
* {@link #startVoiceActivity(android.content.Intent)} has finished. The default
* implementation calls {@link #finish()} on the assumption that this represents
@@ -748,8 +701,6 @@ public abstract class VoiceInteractionSession implements KeyEvent.Callback {
}
/**
- * @hide
- * @SystemApi
* Request to query for what extended commands the session supports.
*
* @param caller Who is making the request.
@@ -764,8 +715,6 @@ public abstract class VoiceInteractionSession implements KeyEvent.Callback {
}
/**
- * @hide
- * @SystemApi
* Request to confirm with the user before proceeding with an unrecoverable operation,
* corresponding to a {@link android.app.VoiceInteractor.ConfirmationRequest
* VoiceInteractor.ConfirmationRequest}.
@@ -781,8 +730,6 @@ public abstract class VoiceInteractionSession implements KeyEvent.Callback {
Bundle extras);
/**
- * @hide
- * @SystemApi
* Request to complete the voice interaction session because the voice activity successfully
* completed its interaction using voice. Corresponds to
* {@link android.app.VoiceInteractor.CompleteVoiceRequest
@@ -804,8 +751,6 @@ public abstract class VoiceInteractionSession implements KeyEvent.Callback {
}
/**
- * @hide
- * @SystemApi
* Request to abort the voice interaction session because the voice activity can not
* complete its interaction using voice. Corresponds to
* {@link android.app.VoiceInteractor.AbortVoiceRequest
@@ -824,8 +769,6 @@ public abstract class VoiceInteractionSession implements KeyEvent.Callback {
}
/**
- * @hide
- * @SystemApi
* Process an arbitrary extended command from the caller,
* corresponding to a {@link android.app.VoiceInteractor.CommandRequest
* VoiceInteractor.CommandRequest}.
@@ -840,8 +783,6 @@ public abstract class VoiceInteractionSession implements KeyEvent.Callback {
public abstract void onCommand(Caller caller, Request request, String command, Bundle extras);
/**
- * @hide
- * @SystemApi
* Called when the {@link android.app.VoiceInteractor} has asked to cancel a {@link Request}
* that was previously delivered to {@link #onConfirm} or {@link #onCommand}.
*
diff --git a/core/java/android/speech/tts/ITextToSpeechCallback.aidl b/core/java/android/speech/tts/ITextToSpeechCallback.aidl
index 899515f..d785c3f 100644
--- a/core/java/android/speech/tts/ITextToSpeechCallback.aidl
+++ b/core/java/android/speech/tts/ITextToSpeechCallback.aidl
@@ -40,7 +40,7 @@ oneway interface ITextToSpeechCallback {
*
* @param utteranceId Unique id identifying synthesis request.
*/
- void onStop(String utteranceId);
+ void onStop(String utteranceId, boolean isStarted);
/**
* Tells the client that the synthesis has failed.
diff --git a/core/java/android/speech/tts/TextToSpeech.java b/core/java/android/speech/tts/TextToSpeech.java
index c59ca8a..06e9ce0 100644
--- a/core/java/android/speech/tts/TextToSpeech.java
+++ b/core/java/android/speech/tts/TextToSpeech.java
@@ -2066,10 +2066,10 @@ public class TextToSpeech {
private boolean mEstablished;
private final ITextToSpeechCallback.Stub mCallback = new ITextToSpeechCallback.Stub() {
- public void onStop(String utteranceId) throws RemoteException {
+ public void onStop(String utteranceId, boolean isStarted) throws RemoteException {
UtteranceProgressListener listener = mUtteranceProgressListener;
if (listener != null) {
- listener.onDone(utteranceId);
+ listener.onStop(utteranceId, isStarted);
}
};
diff --git a/core/java/android/speech/tts/TextToSpeechService.java b/core/java/android/speech/tts/TextToSpeechService.java
index 9bb7f02..02c9a36 100644
--- a/core/java/android/speech/tts/TextToSpeechService.java
+++ b/core/java/android/speech/tts/TextToSpeechService.java
@@ -455,10 +455,37 @@ public abstract class TextToSpeechService extends Service {
private class SynthHandler extends Handler {
private SpeechItem mCurrentSpeechItem = null;
+ private ArrayList<Object> mFlushedObjects = new ArrayList<Object>();
+ private boolean mFlushAll;
+
public SynthHandler(Looper looper) {
super(looper);
}
+ private void startFlushingSpeechItems(Object callerIdentity) {
+ synchronized (mFlushedObjects) {
+ if (callerIdentity == null) {
+ mFlushAll = true;
+ } else {
+ mFlushedObjects.add(callerIdentity);
+ }
+ }
+ }
+ private void endFlushingSpeechItems(Object callerIdentity) {
+ synchronized (mFlushedObjects) {
+ if (callerIdentity == null) {
+ mFlushAll = false;
+ } else {
+ mFlushedObjects.remove(callerIdentity);
+ }
+ }
+ }
+ private boolean isFlushed(SpeechItem speechItem) {
+ synchronized (mFlushedObjects) {
+ return mFlushAll || mFlushedObjects.contains(speechItem.getCallerIdentity());
+ }
+ }
+
private synchronized SpeechItem getCurrentSpeechItem() {
return mCurrentSpeechItem;
}
@@ -522,9 +549,13 @@ public abstract class TextToSpeechService extends Service {
Runnable runnable = new Runnable() {
@Override
public void run() {
- setCurrentSpeechItem(speechItem);
- speechItem.play();
- setCurrentSpeechItem(null);
+ if (isFlushed(speechItem)) {
+ speechItem.stop();
+ } else {
+ setCurrentSpeechItem(speechItem);
+ speechItem.play();
+ setCurrentSpeechItem(null);
+ }
}
};
Message msg = Message.obtain(this, runnable);
@@ -552,12 +583,14 @@ public abstract class TextToSpeechService extends Service {
*
* Called on a service binder thread.
*/
- public int stopForApp(Object callerIdentity) {
+ public int stopForApp(final Object callerIdentity) {
if (callerIdentity == null) {
return TextToSpeech.ERROR;
}
- removeCallbacksAndMessages(callerIdentity);
+ // Flush pending messages from callerIdentity
+ startFlushingSpeechItems(callerIdentity);
+
// This stops writing data to the file / or publishing
// items to the audio playback handler.
//
@@ -573,20 +606,39 @@ public abstract class TextToSpeechService extends Service {
// Remove any enqueued audio too.
mAudioPlaybackHandler.stopForApp(callerIdentity);
+ // Stop flushing pending messages
+ Runnable runnable = new Runnable() {
+ @Override
+ public void run() {
+ endFlushingSpeechItems(callerIdentity);
+ }
+ };
+ sendMessage(Message.obtain(this, runnable));
return TextToSpeech.SUCCESS;
}
public int stopAll() {
+ // Order to flush pending messages
+ startFlushingSpeechItems(null);
+
// Stop the current speech item unconditionally .
SpeechItem current = setCurrentSpeechItem(null);
if (current != null) {
current.stop();
}
- // Remove all other items from the queue.
- removeCallbacksAndMessages(null);
// Remove all pending playback as well.
mAudioPlaybackHandler.stop();
+ // Message to stop flushing pending messages
+ Runnable runnable = new Runnable() {
+ @Override
+ public void run() {
+ endFlushingSpeechItems(null);
+ }
+ };
+ sendMessage(Message.obtain(this, runnable));
+
+
return TextToSpeech.SUCCESS;
}
}
@@ -698,7 +750,6 @@ public abstract class TextToSpeechService extends Service {
return mCallerIdentity;
}
-
public int getCallerUid() {
return mCallerUid;
}
@@ -752,6 +803,10 @@ public abstract class TextToSpeechService extends Service {
protected synchronized boolean isStopped() {
return mStopped;
}
+
+ protected synchronized boolean isStarted() {
+ return mStarted;
+ }
}
/**
@@ -777,7 +832,7 @@ public abstract class TextToSpeechService extends Service {
public void dispatchOnStop() {
final String utteranceId = getUtteranceId();
if (utteranceId != null) {
- mCallbacks.dispatchOnStop(getCallerIdentity(), utteranceId);
+ mCallbacks.dispatchOnStop(getCallerIdentity(), utteranceId, isStarted());
}
}
@@ -940,6 +995,8 @@ public abstract class TextToSpeechService extends Service {
// turn implies that synthesis would not have started.
synthesisCallback.stop();
TextToSpeechService.this.onStop();
+ } else {
+ dispatchOnStop();
}
}
@@ -1345,11 +1402,11 @@ public abstract class TextToSpeechService extends Service {
}
}
- public void dispatchOnStop(Object callerIdentity, String utteranceId) {
+ public void dispatchOnStop(Object callerIdentity, String utteranceId, boolean started) {
ITextToSpeechCallback cb = getCallbackFor(callerIdentity);
if (cb == null) return;
try {
- cb.onStop(utteranceId);
+ cb.onStop(utteranceId, started);
} catch (RemoteException e) {
Log.e(TAG, "Callback onStop failed: " + e);
}
diff --git a/core/java/android/speech/tts/UtteranceProgressListener.java b/core/java/android/speech/tts/UtteranceProgressListener.java
index 6769794..9eb22ef 100644
--- a/core/java/android/speech/tts/UtteranceProgressListener.java
+++ b/core/java/android/speech/tts/UtteranceProgressListener.java
@@ -60,6 +60,20 @@ public abstract class UtteranceProgressListener {
}
/**
+ * Called when an utterance has been stopped while in progress or flushed from the
+ * synthesis queue. This can happen if client calls {@link TextToSpeech#stop()}
+ * or use {@link TextToSpeech#QUEUE_FLUSH} as an argument in
+ * {@link TextToSpeech#speak} or {@link TextToSpeech#synthesizeToFile} methods.
+ *
+ * @param utteranceId the utterance ID of the utterance.
+ * @param isStarted If true, then utterance was interrupted while being synthesized
+ * and it's output is incomplete. If it's false, then utterance was flushed
+ * before the synthesis started.
+ */
+ public void onStop(String utteranceId, boolean isStarted) {
+ }
+
+ /**
* Wraps an old deprecated OnUtteranceCompletedListener with a shiny new
* progress listener.
*
@@ -83,6 +97,11 @@ public abstract class UtteranceProgressListener {
// Left unimplemented, has no equivalent in the old
// API.
}
+
+ @Override
+ public void onStop(String utteranceId, boolean isStarted) {
+ listener.onUtteranceCompleted(utteranceId);
+ }
};
}
}
diff --git a/core/java/android/text/StaticLayout.java b/core/java/android/text/StaticLayout.java
index 74b7b69..5b07397 100644
--- a/core/java/android/text/StaticLayout.java
+++ b/core/java/android/text/StaticLayout.java
@@ -28,6 +28,8 @@ import android.util.Log;
import com.android.internal.util.ArrayUtils;
import com.android.internal.util.GrowingArrayUtils;
+import java.util.Arrays;
+
/**
* StaticLayout is a Layout for text that will not be edited after it
* is laid out. Use {@link DynamicLayout} for text that may change.
@@ -161,7 +163,12 @@ public class StaticLayout extends Layout {
float spacingadd, boolean includepad,
boolean trackpad, float ellipsizedWidth,
TextUtils.TruncateAt ellipsize) {
- int[] breakOpp = null;
+ LineBreaks lineBreaks = new LineBreaks();
+ // store span end locations
+ int[] spanEndCache = new int[4];
+ // store fontMetrics per span range
+ // must be a multiple of 4 (and > 0) (store top, bottom, ascent, and descent per range)
+ int[] fmCache = new int[4 * 4];
final String localeLanguageTag = paint.getTextLocale().toLanguageTag();
mLineCount = 0;
@@ -186,7 +193,7 @@ public class StaticLayout extends Layout {
else
paraEnd++;
- int firstWidthLineLimit = mLineCount + 1;
+ int firstWidthLineCount = 1;
int firstWidth = outerWidth;
int restWidth = outerWidth;
@@ -204,9 +211,8 @@ public class StaticLayout extends Layout {
// leading margin spans, not just this particular one
if (lms instanceof LeadingMarginSpan2) {
LeadingMarginSpan2 lms2 = (LeadingMarginSpan2) lms;
- int lmsFirstLine = getLineForOffset(spanned.getSpanStart(lms2));
- firstWidthLineLimit = Math.max(firstWidthLineLimit,
- lmsFirstLine + lms2.getLeadingMarginLineCount());
+ firstWidthLineCount = Math.max(firstWidthLineCount,
+ lms2.getLeadingMarginLineCount());
}
}
@@ -242,34 +248,23 @@ public class StaticLayout extends Layout {
int dir = measured.mDir;
boolean easy = measured.mEasy;
- breakOpp = nLineBreakOpportunities(localeLanguageTag, chs, paraEnd - paraStart, breakOpp);
- int breakOppIndex = 0;
-
- int width = firstWidth;
-
- float w = 0;
- // here is the offset of the starting character of the line we are currently measuring
- int here = paraStart;
-
- // ok is a character offset located after a word separator (space, tab, number...) where
- // we would prefer to cut the current line. Equals to here when no such break was found.
- int ok = paraStart;
- float okWidth = w;
- int okAscent = 0, okDescent = 0, okTop = 0, okBottom = 0;
-
- // fit is a character offset such that the [here, fit[ range fits in the allowed width.
- // We will cut the line there if no ok position is found.
- int fit = paraStart;
- float fitWidth = w;
- int fitAscent = 0, fitDescent = 0, fitTop = 0, fitBottom = 0;
- // same as fitWidth but not including any trailing whitespace
- float fitWidthGraphing = w;
-
- boolean hasTabOrEmoji = false;
- boolean hasTab = false;
- TabStops tabStops = null;
-
+ // measurement has to be done before performing line breaking
+ // but we don't want to recompute fontmetrics or span ranges the
+ // second time, so we cache those and then use those stored values
+ int fmCacheCount = 0;
+ int spanEndCacheCount = 0;
for (int spanStart = paraStart, spanEnd; spanStart < paraEnd; spanStart = spanEnd) {
+ if (fmCacheCount * 4 >= fmCache.length) {
+ int[] grow = new int[fmCacheCount * 4 * 2];
+ System.arraycopy(fmCache, 0, grow, 0, fmCacheCount * 4);
+ fmCache = grow;
+ }
+
+ if (spanEndCacheCount >= spanEndCache.length) {
+ int[] grow = new int[spanEndCacheCount * 2];
+ System.arraycopy(spanEndCache, 0, grow, 0, spanEndCacheCount);
+ spanEndCache = grow;
+ }
if (spanned == null) {
spanEnd = paraEnd;
@@ -285,200 +280,107 @@ public class StaticLayout extends Layout {
measured.addStyleRun(paint, spans, spanLen, fm);
}
- int fmTop = fm.top;
- int fmBottom = fm.bottom;
- int fmAscent = fm.ascent;
- int fmDescent = fm.descent;
-
- for (int j = spanStart; j < spanEnd; j++) {
- char c = chs[j - paraStart];
-
- if (c == CHAR_NEW_LINE) {
- // intentionally left empty
- } else if (c == CHAR_TAB) {
- if (hasTab == false) {
- hasTab = true;
- hasTabOrEmoji = true;
- if (spanned != null) {
- // First tab this para, check for tabstops
- TabStopSpan[] spans = getParagraphSpans(spanned, paraStart,
- paraEnd, TabStopSpan.class);
- if (spans.length > 0) {
- tabStops = new TabStops(TAB_INCREMENT, spans);
- }
- }
- }
- if (tabStops != null) {
- w = tabStops.nextTab(w);
- } else {
- w = TabStops.nextDefaultStop(w, TAB_INCREMENT);
- }
- } else if (c >= CHAR_FIRST_HIGH_SURROGATE && c <= CHAR_LAST_LOW_SURROGATE
- && j + 1 < spanEnd) {
- int emoji = Character.codePointAt(chs, j - paraStart);
-
- if (emoji >= MIN_EMOJI && emoji <= MAX_EMOJI) {
- Bitmap bm = EMOJI_FACTORY.getBitmapFromAndroidPua(emoji);
-
- if (bm != null) {
- Paint whichPaint;
-
- if (spanned == null) {
- whichPaint = paint;
- } else {
- whichPaint = mWorkPaint;
- }
-
- float wid = bm.getWidth() * -whichPaint.ascent() / bm.getHeight();
-
- w += wid;
- hasTabOrEmoji = true;
- j++;
- } else {
- w += widths[j - paraStart];
- }
- } else {
- w += widths[j - paraStart];
- }
- } else {
- w += widths[j - paraStart];
+ // the order of storage here (top, bottom, ascent, descent) has to match the code below
+ // where these values are retrieved
+ fmCache[fmCacheCount * 4 + 0] = fm.top;
+ fmCache[fmCacheCount * 4 + 1] = fm.bottom;
+ fmCache[fmCacheCount * 4 + 2] = fm.ascent;
+ fmCache[fmCacheCount * 4 + 3] = fm.descent;
+ fmCacheCount++;
+
+ spanEndCache[spanEndCacheCount] = spanEnd;
+ spanEndCacheCount++;
+ }
+
+ // tab stop locations
+ int[] variableTabStops = null;
+ if (spanned != null) {
+ TabStopSpan[] spans = getParagraphSpans(spanned, paraStart,
+ paraEnd, TabStopSpan.class);
+ if (spans.length > 0) {
+ int[] stops = new int[spans.length];
+ for (int i = 0; i < spans.length; i++) {
+ stops[i] = spans[i].getTabStop();
}
+ Arrays.sort(stops, 0, stops.length);
+ variableTabStops = stops;
+ }
+ }
- boolean isSpaceOrTab = c == CHAR_SPACE || c == CHAR_TAB || c == CHAR_ZWSP;
+ int breakCount = nComputeLineBreaks(localeLanguageTag, chs, widths, paraEnd - paraStart, firstWidth,
+ firstWidthLineCount, restWidth, variableTabStops, TAB_INCREMENT, false, lineBreaks,
+ lineBreaks.breaks, lineBreaks.widths, lineBreaks.flags, lineBreaks.breaks.length);
- if (w <= width || isSpaceOrTab) {
- fitWidth = w;
- if (!isSpaceOrTab) {
- fitWidthGraphing = w;
- }
- fit = j + 1;
-
- if (fmTop < fitTop)
- fitTop = fmTop;
- if (fmAscent < fitAscent)
- fitAscent = fmAscent;
- if (fmDescent > fitDescent)
- fitDescent = fmDescent;
- if (fmBottom > fitBottom)
- fitBottom = fmBottom;
-
- while (breakOpp[breakOppIndex] != -1
- && breakOpp[breakOppIndex] < j - paraStart + 1) {
- breakOppIndex++;
- }
- boolean isLineBreak = breakOppIndex < breakOpp.length &&
- breakOpp[breakOppIndex] == j - paraStart + 1;
-
- if (isLineBreak) {
- okWidth = fitWidthGraphing;
- ok = j + 1;
-
- if (fitTop < okTop)
- okTop = fitTop;
- if (fitAscent < okAscent)
- okAscent = fitAscent;
- if (fitDescent > okDescent)
- okDescent = fitDescent;
- if (fitBottom > okBottom)
- okBottom = fitBottom;
- }
- } else {
- int endPos;
- int above, below, top, bottom;
- float currentTextWidth;
-
- if (ok != here) {
- endPos = ok;
- above = okAscent;
- below = okDescent;
- top = okTop;
- bottom = okBottom;
- currentTextWidth = okWidth;
- } else if (fit != here) {
- endPos = fit;
- above = fitAscent;
- below = fitDescent;
- top = fitTop;
- bottom = fitBottom;
- currentTextWidth = fitWidth;
- } else {
- // must make progress, so take next character
- endPos = here + 1;
- // but to deal properly with clusters
- // take all zero width characters following that
- while (endPos < spanEnd && widths[endPos - paraStart] == 0) {
- endPos++;
- }
- above = fmAscent;
- below = fmDescent;
- top = fmTop;
- bottom = fmBottom;
- currentTextWidth = widths[here - paraStart];
- }
+ int[] breaks = lineBreaks.breaks;
+ float[] lineWidths = lineBreaks.widths;
+ boolean[] flags = lineBreaks.flags;
- int ellipseEnd = endPos;
- if (mMaximumVisibleLineCount == 1 && ellipsize == TextUtils.TruncateAt.MIDDLE) {
- ellipseEnd = paraEnd;
- }
- v = out(source, here, ellipseEnd,
- above, below, top, bottom,
- v, spacingmult, spacingadd, chooseHt,chooseHtv, fm, hasTabOrEmoji,
- needMultiply, chdirs, dir, easy, bufEnd, includepad, trackpad,
- chs, widths, paraStart, ellipsize, ellipsizedWidth,
- currentTextWidth, paint, true);
-
- here = endPos;
- j = here - 1; // restart j-span loop from here, compensating for the j++
- ok = fit = here;
- w = 0;
- fitWidthGraphing = w;
- fitAscent = fitDescent = fitTop = fitBottom = 0;
- okAscent = okDescent = okTop = okBottom = 0;
-
- if (--firstWidthLineLimit <= 0) {
- width = restWidth;
- }
+ // here is the offset of the starting character of the line we are currently measuring
+ int here = paraStart;
- if (here < spanStart) {
- // The text was cut before the beginning of the current span range.
- // Exit the span loop, and get spanStart to start over from here.
- measured.setPos(here);
- spanEnd = here;
- break;
- }
+ int fmTop = 0, fmBottom = 0, fmAscent = 0, fmDescent = 0;
+ int fmCacheIndex = 0;
+ int spanEndCacheIndex = 0;
+ int breakIndex = 0;
+ for (int spanStart = paraStart, spanEnd; spanStart < paraEnd; spanStart = spanEnd) {
+ // retrieve end of span
+ spanEnd = spanEndCache[spanEndCacheIndex++];
+
+ // retrieve cached metrics, order matches above
+ fm.top = fmCache[fmCacheIndex * 4 + 0];
+ fm.bottom = fmCache[fmCacheIndex * 4 + 1];
+ fm.ascent = fmCache[fmCacheIndex * 4 + 2];
+ fm.descent = fmCache[fmCacheIndex * 4 + 3];
+ fmCacheIndex++;
+
+ if (fm.top < fmTop) {
+ fmTop = fm.top;
+ }
+ if (fm.ascent < fmAscent) {
+ fmAscent = fm.ascent;
+ }
+ if (fm.descent > fmDescent) {
+ fmDescent = fm.descent;
+ }
+ if (fm.bottom > fmBottom) {
+ fmBottom = fm.bottom;
+ }
- if (mLineCount >= mMaximumVisibleLineCount) {
- return;
- }
- }
+ // skip breaks ending before current span range
+ while (breakIndex < breakCount && paraStart + breaks[breakIndex] < spanStart) {
+ breakIndex++;
}
- }
- if (paraEnd != here && mLineCount < mMaximumVisibleLineCount) {
- if ((fitTop | fitBottom | fitDescent | fitAscent) == 0) {
- paint.getFontMetricsInt(fm);
+ while (breakIndex < breakCount && paraStart + breaks[breakIndex] <= spanEnd) {
+ int endPos = paraStart + breaks[breakIndex];
- fitTop = fm.top;
- fitBottom = fm.bottom;
- fitAscent = fm.ascent;
- fitDescent = fm.descent;
- }
+ boolean moreChars = (endPos < paraEnd); // XXX is this the right way to calculate this?
- // Log.e("text", "output rest " + here + " to " + end);
-
- v = out(source,
- here, paraEnd, fitAscent, fitDescent,
- fitTop, fitBottom,
- v,
- spacingmult, spacingadd, chooseHt,
- chooseHtv, fm, hasTabOrEmoji,
- needMultiply, chdirs, dir, easy, bufEnd,
- includepad, trackpad, chs,
- widths, paraStart, ellipsize,
- ellipsizedWidth, w, paint, paraEnd != bufEnd);
- }
+ v = out(source, here, endPos,
+ fmAscent, fmDescent, fmTop, fmBottom,
+ v, spacingmult, spacingadd, chooseHt,chooseHtv, fm, flags[breakIndex],
+ needMultiply, chdirs, dir, easy, bufEnd, includepad, trackpad,
+ chs, widths, paraStart, ellipsize, ellipsizedWidth,
+ lineWidths[breakIndex], paint, moreChars);
- paraStart = paraEnd;
+ if (endPos < spanEnd) {
+ // preserve metrics for current span
+ fmTop = fm.top;
+ fmBottom = fm.bottom;
+ fmAscent = fm.ascent;
+ fmDescent = fm.descent;
+ } else {
+ fmTop = fmBottom = fmAscent = fmDescent = 0;
+ }
+
+ here = endPos;
+ breakIndex++;
+
+ if (mLineCount >= mMaximumVisibleLineCount) {
+ return;
+ }
+ }
+ }
if (paraEnd == bufEnd)
break;
@@ -488,7 +390,7 @@ public class StaticLayout extends Layout {
mLineCount < mMaximumVisibleLineCount) {
// Log.e("text", "output last " + bufEnd);
- measured.setPara(source, bufStart, bufEnd, textDir);
+ measured.setPara(source, bufEnd, bufEnd, textDir);
paint.getFontMetricsInt(fm);
@@ -848,15 +750,20 @@ public class StaticLayout extends Layout {
void prepare() {
mMeasured = MeasuredText.obtain();
}
-
+
void finish() {
mMeasured = MeasuredText.recycle(mMeasured);
}
- // returns an array with terminal sentinel value -1 to indicate end
- // this is so that arrays can be recycled instead of allocating new arrays
- // every time
- private static native int[] nLineBreakOpportunities(String locale, char[] text, int length, int[] recycle);
+ // populates LineBreaks and returns the number of breaks found
+ //
+ // the arrays inside the LineBreaks objects are passed in as well
+ // to reduce the number of JNI calls in the common case where the
+ // arrays do not have to be resized
+ private static native int nComputeLineBreaks(String locale, char[] text, float[] widths,
+ int length, float firstWidth, int firstWidthLineCount, float restWidth,
+ int[] variableTabStops, int defaultTabStop, boolean optimize, LineBreaks recycle,
+ int[] recycleBreaks, float[] recycleWidths, boolean[] recycleFlags, int recycleLength);
private int mLineCount;
private int mTopPadding, mBottomPadding;
@@ -884,18 +791,23 @@ public class StaticLayout extends Layout {
private static final int TAB_INCREMENT = 20; // same as Layout, but that's private
private static final char CHAR_NEW_LINE = '\n';
- private static final char CHAR_TAB = '\t';
- private static final char CHAR_SPACE = ' ';
- private static final char CHAR_ZWSP = '\u200B';
private static final double EXTRA_ROUNDING = 0.5;
- private static final int CHAR_FIRST_HIGH_SURROGATE = 0xD800;
- private static final int CHAR_LAST_LOW_SURROGATE = 0xDFFF;
-
/*
* This is reused across calls to generate()
*/
private MeasuredText mMeasured;
private Paint.FontMetricsInt mFontMetricsInt = new Paint.FontMetricsInt();
+
+ // This is used to return three arrays from a single JNI call when
+ // performing line breaking
+ /*package*/ static class LineBreaks {
+ private static final int INITIAL_SIZE = 16;
+ public int[] breaks = new int[INITIAL_SIZE];
+ public float[] widths = new float[INITIAL_SIZE];
+ public boolean[] flags = new boolean[INITIAL_SIZE]; // hasTabOrEmoji
+ // breaks, widths, and flags should all have the same length
+ }
+
}
diff --git a/core/java/android/text/util/Rfc822Token.java b/core/java/android/text/util/Rfc822Token.java
index 0edeeb5..058757a 100644
--- a/core/java/android/text/util/Rfc822Token.java
+++ b/core/java/android/text/util/Rfc822Token.java
@@ -16,18 +16,21 @@
package android.text.util;
+import android.annotation.Nullable;
+
/**
* This class stores an RFC 822-like name, address, and comment,
* and provides methods to convert them to quoted strings.
*/
public class Rfc822Token {
+ @Nullable
private String mName, mAddress, mComment;
/**
* Creates a new Rfc822Token with the specified name, address,
* and comment.
*/
- public Rfc822Token(String name, String address, String comment) {
+ public Rfc822Token(@Nullable String name, @Nullable String address, @Nullable String comment) {
mName = name;
mAddress = address;
mComment = comment;
@@ -36,6 +39,7 @@ public class Rfc822Token {
/**
* Returns the name part.
*/
+ @Nullable
public String getName() {
return mName;
}
@@ -43,6 +47,7 @@ public class Rfc822Token {
/**
* Returns the address part.
*/
+ @Nullable
public String getAddress() {
return mAddress;
}
@@ -50,6 +55,7 @@ public class Rfc822Token {
/**
* Returns the comment part.
*/
+ @Nullable
public String getComment() {
return mComment;
}
@@ -57,21 +63,21 @@ public class Rfc822Token {
/**
* Changes the name to the specified name.
*/
- public void setName(String name) {
+ public void setName(@Nullable String name) {
mName = name;
}
/**
* Changes the address to the specified address.
*/
- public void setAddress(String address) {
+ public void setAddress(@Nullable String address) {
mAddress = address;
}
/**
* Changes the comment to the specified comment.
*/
- public void setComment(String comment) {
+ public void setComment(@Nullable String comment) {
mComment = comment;
}
diff --git a/core/java/android/transition/ChangeScroll.java b/core/java/android/transition/ChangeScroll.java
index 39291bf..5a78b94 100644
--- a/core/java/android/transition/ChangeScroll.java
+++ b/core/java/android/transition/ChangeScroll.java
@@ -28,8 +28,6 @@ import android.view.ViewGroup;
/**
* This transition captures the scroll properties of targets before and after
* the scene change and animates any changes.
- *
- * @hide
*/
public class ChangeScroll extends Transition {
diff --git a/core/java/android/util/AttributeSet.java b/core/java/android/util/AttributeSet.java
index 74942ba..eb8c168 100644
--- a/core/java/android/util/AttributeSet.java
+++ b/core/java/android/util/AttributeSet.java
@@ -39,7 +39,7 @@ package android.util;
* is more useful in conjunction with compiled XML resources:
*
* <pre>
- * XmlPullParser parser = resources.getXml(myResouce);
+ * XmlPullParser parser = resources.getXml(myResource);
* AttributeSet attributes = Xml.asAttributeSet(parser);</pre>
*
* <p>The implementation returned here, unlike using
diff --git a/core/java/android/util/Spline.java b/core/java/android/util/Spline.java
index 41a2e5d..bed3a60 100644
--- a/core/java/android/util/Spline.java
+++ b/core/java/android/util/Spline.java
@@ -165,7 +165,7 @@ public abstract class Spline {
throw new IllegalArgumentException("The control points must have "
+ "monotonic Y values.");
}
- float h = FloatMath.hypot(a, b);
+ float h = (float) Math.hypot(a, b);
if (h > 9f) {
float t = 3f / h;
m[i] = t * a * d[i];
diff --git a/core/java/android/util/StateSet.java b/core/java/android/util/StateSet.java
index 2623638..83dfc47 100644
--- a/core/java/android/util/StateSet.java
+++ b/core/java/android/util/StateSet.java
@@ -36,7 +36,88 @@ import com.android.internal.R;
*/
public class StateSet {
- /** @hide */ public StateSet() {}
+ /**
+ * The order here is very important to
+ * {@link android.view.View#getDrawableState()}
+ */
+ private static final int[][] VIEW_STATE_SETS;
+
+ /** @hide */
+ public static final int VIEW_STATE_WINDOW_FOCUSED = 1;
+ /** @hide */
+ public static final int VIEW_STATE_SELECTED = 1 << 1;
+ /** @hide */
+ public static final int VIEW_STATE_FOCUSED = 1 << 2;
+ /** @hide */
+ public static final int VIEW_STATE_ENABLED = 1 << 3;
+ /** @hide */
+ public static final int VIEW_STATE_PRESSED = 1 << 4;
+ /** @hide */
+ public static final int VIEW_STATE_ACTIVATED = 1 << 5;
+ /** @hide */
+ public static final int VIEW_STATE_ACCELERATED = 1 << 6;
+ /** @hide */
+ public static final int VIEW_STATE_HOVERED = 1 << 7;
+ /** @hide */
+ public static final int VIEW_STATE_DRAG_CAN_ACCEPT = 1 << 8;
+ /** @hide */
+ public static final int VIEW_STATE_DRAG_HOVERED = 1 << 9;
+
+ static final int[] VIEW_STATE_IDS = new int[] {
+ R.attr.state_window_focused, VIEW_STATE_WINDOW_FOCUSED,
+ R.attr.state_selected, VIEW_STATE_SELECTED,
+ R.attr.state_focused, VIEW_STATE_FOCUSED,
+ R.attr.state_enabled, VIEW_STATE_ENABLED,
+ R.attr.state_pressed, VIEW_STATE_PRESSED,
+ R.attr.state_activated, VIEW_STATE_ACTIVATED,
+ R.attr.state_accelerated, VIEW_STATE_ACCELERATED,
+ R.attr.state_hovered, VIEW_STATE_HOVERED,
+ R.attr.state_drag_can_accept, VIEW_STATE_DRAG_CAN_ACCEPT,
+ R.attr.state_drag_hovered, VIEW_STATE_DRAG_HOVERED
+ };
+
+ static {
+ if ((VIEW_STATE_IDS.length / 2) != R.styleable.ViewDrawableStates.length) {
+ throw new IllegalStateException(
+ "VIEW_STATE_IDs array length does not match ViewDrawableStates style array");
+ }
+
+ final int[] orderedIds = new int[VIEW_STATE_IDS.length];
+ for (int i = 0; i < R.styleable.ViewDrawableStates.length; i++) {
+ final int viewState = R.styleable.ViewDrawableStates[i];
+ for (int j = 0; j < VIEW_STATE_IDS.length; j += 2) {
+ if (VIEW_STATE_IDS[j] == viewState) {
+ orderedIds[i * 2] = viewState;
+ orderedIds[i * 2 + 1] = VIEW_STATE_IDS[j + 1];
+ }
+ }
+ }
+
+ final int NUM_BITS = VIEW_STATE_IDS.length / 2;
+ VIEW_STATE_SETS = new int[1 << NUM_BITS][];
+ for (int i = 0; i < VIEW_STATE_SETS.length; i++) {
+ final int numBits = Integer.bitCount(i);
+ final int[] set = new int[numBits];
+ int pos = 0;
+ for (int j = 0; j < orderedIds.length; j += 2) {
+ if ((i & orderedIds[j + 1]) != 0) {
+ set[pos++] = orderedIds[j];
+ }
+ }
+ VIEW_STATE_SETS[i] = set;
+ }
+ }
+
+ /** @hide */
+ public static int[] get(int mask) {
+ if (mask >= VIEW_STATE_SETS.length) {
+ throw new IllegalArgumentException("Invalid state set mask");
+ }
+ return VIEW_STATE_SETS[mask];
+ }
+
+ /** @hide */
+ public StateSet() {}
public static final int[] WILD_CARD = new int[0];
public static final int[] NOTHING = new int[] { 0 };
diff --git a/core/java/android/view/ContextThemeWrapper.java b/core/java/android/view/ContextThemeWrapper.java
index 0afbde9..d9f6054 100644
--- a/core/java/android/view/ContextThemeWrapper.java
+++ b/core/java/android/view/ContextThemeWrapper.java
@@ -35,13 +35,19 @@ public class ContextThemeWrapper extends ContextWrapper {
public ContextThemeWrapper() {
super(null);
}
-
- public ContextThemeWrapper(Context base, int themeres) {
+
+ public ContextThemeWrapper(Context base, int themeResId) {
+ super(base);
+ mThemeResource = themeResId;
+ }
+
+ public ContextThemeWrapper(Context base, Resources.Theme theme) {
super(base);
- mThemeResource = themeres;
+ mTheme = theme;
}
- @Override protected void attachBaseContext(Context newBase) {
+ @Override
+ protected void attachBaseContext(Context newBase) {
super.attachBaseContext(newBase);
}
diff --git a/core/java/android/view/GLES20Canvas.java b/core/java/android/view/GLES20Canvas.java
index 60a489b..3cb4666 100644
--- a/core/java/android/view/GLES20Canvas.java
+++ b/core/java/android/view/GLES20Canvas.java
@@ -19,19 +19,13 @@ package android.view;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.CanvasProperty;
-import android.graphics.DrawFilter;
import android.graphics.Matrix;
import android.graphics.NinePatch;
import android.graphics.Paint;
-import android.graphics.PaintFlagsDrawFilter;
import android.graphics.Path;
import android.graphics.Picture;
-import android.graphics.PorterDuff;
import android.graphics.Rect;
import android.graphics.RectF;
-import android.graphics.Region;
-import android.graphics.Shader;
-import android.graphics.TemporaryBuffer;
import android.text.GraphicsOperations;
import android.text.SpannableString;
import android.text.SpannedString;
@@ -41,14 +35,6 @@ import android.text.TextUtils;
* An implementation of Canvas on top of OpenGL ES 2.0.
*/
class GLES20Canvas extends HardwareCanvas {
- private final boolean mOpaque;
- protected long mRenderer;
-
- // The native renderer will be destroyed when this object dies.
- // DO NOT overwrite this reference once it is set.
- @SuppressWarnings({"unused", "FieldCanBeLocal"})
- private CanvasFinalizer mFinalizer;
-
private int mWidth;
private int mHeight;
@@ -58,8 +44,6 @@ class GLES20Canvas extends HardwareCanvas {
private Rect mClipBounds;
private RectF mPathBounds;
- private DrawFilter mFilter;
-
///////////////////////////////////////////////////////////////////////////
// JNI
///////////////////////////////////////////////////////////////////////////
@@ -77,39 +61,10 @@ class GLES20Canvas extends HardwareCanvas {
// TODO: Merge with GLES20RecordingCanvas
protected GLES20Canvas() {
- mOpaque = false;
- mRenderer = nCreateDisplayListRenderer();
- setupFinalizer();
- }
-
- private void setupFinalizer() {
- if (mRenderer == 0) {
- throw new IllegalStateException("Could not create GLES20Canvas renderer");
- } else {
- mFinalizer = new CanvasFinalizer(mRenderer);
- }
+ super(nCreateDisplayListRenderer());
}
private static native long nCreateDisplayListRenderer();
- private static native void nResetDisplayListRenderer(long renderer);
- private static native void nDestroyRenderer(long renderer);
-
- private static final class CanvasFinalizer {
- private final long mRenderer;
-
- public CanvasFinalizer(long renderer) {
- mRenderer = renderer;
- }
-
- @Override
- protected void finalize() throws Throwable {
- try {
- nDestroyRenderer(mRenderer);
- } finally {
- super.finalize();
- }
- }
- }
public static void setProperty(String name, String value) {
nSetProperty(name, value);
@@ -123,7 +78,7 @@ class GLES20Canvas extends HardwareCanvas {
@Override
public boolean isOpaque() {
- return mOpaque;
+ return false;
}
@Override
@@ -153,7 +108,7 @@ class GLES20Canvas extends HardwareCanvas {
* Returns the native OpenGLRenderer object.
*/
long getRenderer() {
- return mRenderer;
+ return mNativeCanvasWrapper;
}
///////////////////////////////////////////////////////////////////////////
@@ -165,7 +120,7 @@ class GLES20Canvas extends HardwareCanvas {
mWidth = width;
mHeight = height;
- nSetViewport(mRenderer, width, height);
+ nSetViewport(mNativeCanvasWrapper, width, height);
}
private static native void nSetViewport(long renderer,
@@ -173,40 +128,38 @@ class GLES20Canvas extends HardwareCanvas {
@Override
public void setHighContrastText(boolean highContrastText) {
- nSetHighContrastText(mRenderer, highContrastText);
+ nSetHighContrastText(mNativeCanvasWrapper, highContrastText);
}
private static native void nSetHighContrastText(long renderer, boolean highContrastText);
@Override
public void insertReorderBarrier() {
- nInsertReorderBarrier(mRenderer, true);
+ nInsertReorderBarrier(mNativeCanvasWrapper, true);
}
@Override
public void insertInorderBarrier() {
- nInsertReorderBarrier(mRenderer, false);
+ nInsertReorderBarrier(mNativeCanvasWrapper, false);
}
private static native void nInsertReorderBarrier(long renderer, boolean enableReorder);
@Override
- public int onPreDraw(Rect dirty) {
+ public void onPreDraw(Rect dirty) {
if (dirty != null) {
- return nPrepareDirty(mRenderer, dirty.left, dirty.top, dirty.right, dirty.bottom,
- mOpaque);
+ nPrepareDirty(mNativeCanvasWrapper, dirty.left, dirty.top, dirty.right, dirty.bottom);
} else {
- return nPrepare(mRenderer, mOpaque);
+ nPrepare(mNativeCanvasWrapper);
}
}
- private static native int nPrepare(long renderer, boolean opaque);
- private static native int nPrepareDirty(long renderer, int left, int top, int right, int bottom,
- boolean opaque);
+ private static native void nPrepare(long renderer);
+ private static native void nPrepareDirty(long renderer, int left, int top, int right, int bottom);
@Override
public void onPostDraw() {
- nFinish(mRenderer);
+ nFinish(mNativeCanvasWrapper);
}
private static native void nFinish(long renderer);
@@ -216,11 +169,11 @@ class GLES20Canvas extends HardwareCanvas {
///////////////////////////////////////////////////////////////////////////
@Override
- public int callDrawGLFunction2(long drawGLFunction) {
- return nCallDrawGLFunction(mRenderer, drawGLFunction);
+ public void callDrawGLFunction2(long drawGLFunction) {
+ nCallDrawGLFunction(mNativeCanvasWrapper, drawGLFunction);
}
- private static native int nCallDrawGLFunction(long renderer, long drawGLFunction);
+ private static native void nCallDrawGLFunction(long renderer, long drawGLFunction);
///////////////////////////////////////////////////////////////////////////
// Display list
@@ -229,12 +182,12 @@ class GLES20Canvas extends HardwareCanvas {
protected static native long nFinishRecording(long renderer);
@Override
- public int drawRenderNode(RenderNode renderNode, Rect dirty, int flags) {
- return nDrawRenderNode(mRenderer, renderNode.getNativeDisplayList(), dirty, flags);
+ public void drawRenderNode(RenderNode renderNode, int flags) {
+ nDrawRenderNode(mNativeCanvasWrapper, renderNode.getNativeDisplayList(), flags);
}
- private static native int nDrawRenderNode(long renderer, long renderNode,
- Rect dirty, int flags);
+ private static native void nDrawRenderNode(long renderer, long renderNode,
+ int flags);
///////////////////////////////////////////////////////////////////////////
// Hardware layer
@@ -242,332 +195,32 @@ class GLES20Canvas extends HardwareCanvas {
void drawHardwareLayer(HardwareLayer layer, float x, float y, Paint paint) {
layer.setLayerPaint(paint);
- nDrawLayer(mRenderer, layer.getLayerHandle(), x, y);
+ nDrawLayer(mNativeCanvasWrapper, layer.getLayerHandle(), x, y);
}
private static native void nDrawLayer(long renderer, long layer, float x, float y);
///////////////////////////////////////////////////////////////////////////
- // Support
- ///////////////////////////////////////////////////////////////////////////
-
- private Rect getInternalClipBounds() {
- if (mClipBounds == null) mClipBounds = new Rect();
- return mClipBounds;
- }
-
-
- private RectF getPathBounds() {
- if (mPathBounds == null) mPathBounds = new RectF();
- return mPathBounds;
- }
-
- private float[] getPointStorage() {
- if (mPoint == null) mPoint = new float[2];
- return mPoint;
- }
-
- private float[] getLineStorage() {
- if (mLine == null) mLine = new float[4];
- return mLine;
- }
-
- ///////////////////////////////////////////////////////////////////////////
- // Clipping
- ///////////////////////////////////////////////////////////////////////////
-
- @Override
- public boolean clipPath(Path path) {
- return nClipPath(mRenderer, path.mNativePath, Region.Op.INTERSECT.nativeInt);
- }
-
- @Override
- public boolean clipPath(Path path, Region.Op op) {
- return nClipPath(mRenderer, path.mNativePath, op.nativeInt);
- }
-
- private static native boolean nClipPath(long renderer, long path, int op);
-
- @Override
- public boolean clipRect(float left, float top, float right, float bottom) {
- return nClipRect(mRenderer, left, top, right, bottom, Region.Op.INTERSECT.nativeInt);
- }
-
- private static native boolean nClipRect(long renderer, float left, float top,
- float right, float bottom, int op);
-
- @Override
- public boolean clipRect(float left, float top, float right, float bottom, Region.Op op) {
- return nClipRect(mRenderer, left, top, right, bottom, op.nativeInt);
- }
-
- @Override
- public boolean clipRect(int left, int top, int right, int bottom) {
- return nClipRect(mRenderer, left, top, right, bottom, Region.Op.INTERSECT.nativeInt);
- }
-
- private static native boolean nClipRect(long renderer, int left, int top,
- int right, int bottom, int op);
-
- @Override
- public boolean clipRect(Rect rect) {
- return nClipRect(mRenderer, rect.left, rect.top, rect.right, rect.bottom,
- Region.Op.INTERSECT.nativeInt);
- }
-
- @Override
- public boolean clipRect(Rect rect, Region.Op op) {
- return nClipRect(mRenderer, rect.left, rect.top, rect.right, rect.bottom, op.nativeInt);
- }
-
- @Override
- public boolean clipRect(RectF rect) {
- return nClipRect(mRenderer, rect.left, rect.top, rect.right, rect.bottom,
- Region.Op.INTERSECT.nativeInt);
- }
-
- @Override
- public boolean clipRect(RectF rect, Region.Op op) {
- return nClipRect(mRenderer, rect.left, rect.top, rect.right, rect.bottom, op.nativeInt);
- }
-
- @Override
- public boolean clipRegion(Region region) {
- return nClipRegion(mRenderer, region.mNativeRegion, Region.Op.INTERSECT.nativeInt);
- }
-
- @Override
- public boolean clipRegion(Region region, Region.Op op) {
- return nClipRegion(mRenderer, region.mNativeRegion, op.nativeInt);
- }
-
- private static native boolean nClipRegion(long renderer, long region, int op);
-
- @Override
- public boolean getClipBounds(Rect bounds) {
- return nGetClipBounds(mRenderer, bounds);
- }
-
- private static native boolean nGetClipBounds(long renderer, Rect bounds);
-
- @Override
- public boolean quickReject(float left, float top, float right, float bottom, EdgeType type) {
- return nQuickReject(mRenderer, left, top, right, bottom);
- }
-
- private static native boolean nQuickReject(long renderer, float left, float top,
- float right, float bottom);
-
- @Override
- public boolean quickReject(Path path, EdgeType type) {
- RectF pathBounds = getPathBounds();
- path.computeBounds(pathBounds, true);
- return nQuickReject(mRenderer, pathBounds.left, pathBounds.top,
- pathBounds.right, pathBounds.bottom);
- }
-
- @Override
- public boolean quickReject(RectF rect, EdgeType type) {
- return nQuickReject(mRenderer, rect.left, rect.top, rect.right, rect.bottom);
- }
-
- ///////////////////////////////////////////////////////////////////////////
- // Transformations
- ///////////////////////////////////////////////////////////////////////////
-
- @Override
- public void translate(float dx, float dy) {
- if (dx != 0.0f || dy != 0.0f) nTranslate(mRenderer, dx, dy);
- }
-
- private static native void nTranslate(long renderer, float dx, float dy);
-
- @Override
- public void skew(float sx, float sy) {
- nSkew(mRenderer, sx, sy);
- }
-
- private static native void nSkew(long renderer, float sx, float sy);
-
- @Override
- public void rotate(float degrees) {
- nRotate(mRenderer, degrees);
- }
-
- private static native void nRotate(long renderer, float degrees);
-
- @Override
- public void scale(float sx, float sy) {
- nScale(mRenderer, sx, sy);
- }
-
- private static native void nScale(long renderer, float sx, float sy);
-
- @Override
- public void setMatrix(Matrix matrix) {
- nSetMatrix(mRenderer, matrix == null ? 0 : matrix.native_instance);
- }
-
- private static native void nSetMatrix(long renderer, long matrix);
-
- @SuppressWarnings("deprecation")
- @Override
- public void getMatrix(Matrix matrix) {
- nGetMatrix(mRenderer, matrix.native_instance);
- }
-
- private static native void nGetMatrix(long renderer, long matrix);
-
- @Override
- public void concat(Matrix matrix) {
- if (matrix != null) nConcatMatrix(mRenderer, matrix.native_instance);
- }
-
- private static native void nConcatMatrix(long renderer, long matrix);
-
- ///////////////////////////////////////////////////////////////////////////
- // State management
- ///////////////////////////////////////////////////////////////////////////
-
- @Override
- public int save() {
- return nSave(mRenderer, Canvas.CLIP_SAVE_FLAG | Canvas.MATRIX_SAVE_FLAG);
- }
-
- @Override
- public int save(int saveFlags) {
- return nSave(mRenderer, saveFlags);
- }
-
- private static native int nSave(long renderer, int flags);
-
- @Override
- public int saveLayer(RectF bounds, Paint paint, int saveFlags) {
- if (bounds != null) {
- return saveLayer(bounds.left, bounds.top, bounds.right, bounds.bottom, paint, saveFlags);
- }
-
- final long nativePaint = paint == null ? 0 : paint.mNativePaint;
- return nSaveLayer(mRenderer, nativePaint, saveFlags);
- }
-
- private static native int nSaveLayer(long renderer, long paint, int saveFlags);
-
- @Override
- public int saveLayer(float left, float top, float right, float bottom, Paint paint,
- int saveFlags) {
- if (left < right && top < bottom) {
- final long nativePaint = paint == null ? 0 : paint.mNativePaint;
- return nSaveLayer(mRenderer, left, top, right, bottom, nativePaint, saveFlags);
- }
- return save(saveFlags);
- }
-
- private static native int nSaveLayer(long renderer, float left, float top,
- float right, float bottom, long paint, int saveFlags);
-
- @Override
- public int saveLayerAlpha(RectF bounds, int alpha, int saveFlags) {
- if (bounds != null) {
- return saveLayerAlpha(bounds.left, bounds.top, bounds.right, bounds.bottom,
- alpha, saveFlags);
- }
- return nSaveLayerAlpha(mRenderer, alpha, saveFlags);
- }
-
- private static native int nSaveLayerAlpha(long renderer, int alpha, int saveFlags);
-
- @Override
- public int saveLayerAlpha(float left, float top, float right, float bottom, int alpha,
- int saveFlags) {
- if (left < right && top < bottom) {
- return nSaveLayerAlpha(mRenderer, left, top, right, bottom, alpha, saveFlags);
- }
- return save(saveFlags);
- }
-
- private static native int nSaveLayerAlpha(long renderer, float left, float top, float right,
- float bottom, int alpha, int saveFlags);
-
- @Override
- public void restore() {
- nRestore(mRenderer);
- }
-
- private static native void nRestore(long renderer);
-
- @Override
- public void restoreToCount(int saveCount) {
- nRestoreToCount(mRenderer, saveCount);
- }
-
- private static native void nRestoreToCount(long renderer, int saveCount);
-
- @Override
- public int getSaveCount() {
- return nGetSaveCount(mRenderer);
- }
-
- private static native int nGetSaveCount(long renderer);
-
- ///////////////////////////////////////////////////////////////////////////
- // Filtering
- ///////////////////////////////////////////////////////////////////////////
-
- @Override
- public void setDrawFilter(DrawFilter filter) {
- mFilter = filter;
- if (filter == null) {
- nResetPaintFilter(mRenderer);
- } else if (filter instanceof PaintFlagsDrawFilter) {
- PaintFlagsDrawFilter flagsFilter = (PaintFlagsDrawFilter) filter;
- nSetupPaintFilter(mRenderer, flagsFilter.clearBits, flagsFilter.setBits);
- }
- }
-
- private static native void nResetPaintFilter(long renderer);
- private static native void nSetupPaintFilter(long renderer, int clearBits, int setBits);
-
- @Override
- public DrawFilter getDrawFilter() {
- return mFilter;
- }
-
- ///////////////////////////////////////////////////////////////////////////
// Drawing
///////////////////////////////////////////////////////////////////////////
- @Override
- public void drawArc(float left, float top, float right, float bottom,
- float startAngle, float sweepAngle, boolean useCenter, Paint paint) {
- nDrawArc(mRenderer, left, top, right, bottom,
- startAngle, sweepAngle, useCenter, paint.mNativePaint);
- }
-
- private static native void nDrawArc(long renderer, float left, float top,
- float right, float bottom, float startAngle, float sweepAngle,
- boolean useCenter, long paint);
-
- @Override
- public void drawARGB(int a, int r, int g, int b) {
- drawColor((a & 0xFF) << 24 | (r & 0xFF) << 16 | (g & 0xFF) << 8 | (b & 0xFF));
- }
-
+ // TODO: move to Canvas.java
@Override
public void drawPatch(NinePatch patch, Rect dst, Paint paint) {
Bitmap bitmap = patch.getBitmap();
throwIfCannotDraw(bitmap);
- final long nativePaint = paint == null ? 0 : paint.mNativePaint;
- nDrawPatch(mRenderer, bitmap.mNativeBitmap, patch.mNativeChunk,
+ final long nativePaint = paint == null ? 0 : paint.getNativeInstance();
+ nDrawPatch(mNativeCanvasWrapper, bitmap.mNativeBitmap, patch.mNativeChunk,
dst.left, dst.top, dst.right, dst.bottom, nativePaint);
}
+ // TODO: move to Canvas.java
@Override
public void drawPatch(NinePatch patch, RectF dst, Paint paint) {
Bitmap bitmap = patch.getBitmap();
throwIfCannotDraw(bitmap);
- final long nativePaint = paint == null ? 0 : paint.mNativePaint;
- nDrawPatch(mRenderer, bitmap.mNativeBitmap, patch.mNativeChunk,
+ final long nativePaint = paint == null ? 0 : paint.getNativeInstance();
+ nDrawPatch(mNativeCanvasWrapper, bitmap.mNativeBitmap, patch.mNativeChunk,
dst.left, dst.top, dst.right, dst.bottom, nativePaint);
}
@@ -575,148 +228,9 @@ class GLES20Canvas extends HardwareCanvas {
float left, float top, float right, float bottom, long paint);
@Override
- public void drawBitmap(Bitmap bitmap, float left, float top, Paint paint) {
- throwIfCannotDraw(bitmap);
- final long nativePaint = paint == null ? 0 : paint.mNativePaint;
- nDrawBitmap(mRenderer, bitmap.mNativeBitmap, left, top, nativePaint);
- }
-
- private static native void nDrawBitmap(long renderer, long bitmap, float left,
- float top, long paint);
-
- @Override
- public void drawBitmap(Bitmap bitmap, Matrix matrix, Paint paint) {
- throwIfCannotDraw(bitmap);
- final long nativePaint = paint == null ? 0 : paint.mNativePaint;
- nDrawBitmap(mRenderer, bitmap.mNativeBitmap, matrix.native_instance, nativePaint);
- }
-
- private static native void nDrawBitmap(long renderer, long bitmap,
- long matrix, long paint);
-
- @Override
- public void drawBitmap(Bitmap bitmap, Rect src, Rect dst, Paint paint) {
- throwIfCannotDraw(bitmap);
- final long nativePaint = paint == null ? 0 : paint.mNativePaint;
-
- int left, top, right, bottom;
- if (src == null) {
- left = top = 0;
- right = bitmap.getWidth();
- bottom = bitmap.getHeight();
- } else {
- left = src.left;
- right = src.right;
- top = src.top;
- bottom = src.bottom;
- }
-
- nDrawBitmap(mRenderer, bitmap.mNativeBitmap, left, top, right, bottom,
- dst.left, dst.top, dst.right, dst.bottom, nativePaint);
- }
-
- @Override
- public void drawBitmap(Bitmap bitmap, Rect src, RectF dst, Paint paint) {
- throwIfCannotDraw(bitmap);
- final long nativePaint = paint == null ? 0 : paint.mNativePaint;
-
- float left, top, right, bottom;
- if (src == null) {
- left = top = 0;
- right = bitmap.getWidth();
- bottom = bitmap.getHeight();
- } else {
- left = src.left;
- right = src.right;
- top = src.top;
- bottom = src.bottom;
- }
-
- nDrawBitmap(mRenderer, bitmap.mNativeBitmap, left, top, right, bottom,
- dst.left, dst.top, dst.right, dst.bottom, nativePaint);
- }
-
- private static native void nDrawBitmap(long renderer, long bitmap,
- float srcLeft, float srcTop, float srcRight, float srcBottom,
- float left, float top, float right, float bottom, long paint);
-
- @Override
- public void drawBitmap(int[] colors, int offset, int stride, float x, float y,
- int width, int height, boolean hasAlpha, Paint paint) {
- if (width < 0) {
- throw new IllegalArgumentException("width must be >= 0");
- }
-
- if (height < 0) {
- throw new IllegalArgumentException("height must be >= 0");
- }
-
- if (Math.abs(stride) < width) {
- throw new IllegalArgumentException("abs(stride) must be >= width");
- }
-
- int lastScanline = offset + (height - 1) * stride;
- int length = colors.length;
-
- if (offset < 0 || (offset + width > length) || lastScanline < 0 ||
- (lastScanline + width > length)) {
- throw new ArrayIndexOutOfBoundsException();
- }
-
- final long nativePaint = paint == null ? 0 : paint.mNativePaint;
- nDrawBitmap(mRenderer, colors, offset, stride, x, y,
- width, height, hasAlpha, nativePaint);
- }
-
- private static native void nDrawBitmap(long renderer, int[] colors, int offset, int stride,
- float x, float y, int width, int height, boolean hasAlpha, long nativePaint);
-
- @Override
- public void drawBitmap(int[] colors, int offset, int stride, int x, int y,
- int width, int height, boolean hasAlpha, Paint paint) {
- drawBitmap(colors, offset, stride, (float) x, (float) y, width, height, hasAlpha, paint);
- }
-
- @Override
- public void drawBitmapMesh(Bitmap bitmap, int meshWidth, int meshHeight, float[] verts,
- int vertOffset, int[] colors, int colorOffset, Paint paint) {
- throwIfCannotDraw(bitmap);
- if (meshWidth < 0 || meshHeight < 0 || vertOffset < 0 || colorOffset < 0) {
- throw new ArrayIndexOutOfBoundsException();
- }
-
- if (meshWidth == 0 || meshHeight == 0) {
- return;
- }
-
- final int count = (meshWidth + 1) * (meshHeight + 1);
- checkRange(verts.length, vertOffset, count * 2);
-
- if (colors != null) {
- checkRange(colors.length, colorOffset, count);
- }
-
- final long nativePaint = paint == null ? 0 : paint.mNativePaint;
- nDrawBitmapMesh(mRenderer, bitmap.mNativeBitmap, meshWidth, meshHeight,
- verts, vertOffset, colors, colorOffset, nativePaint);
- }
-
- private static native void nDrawBitmapMesh(long renderer, long bitmap,
- int meshWidth, int meshHeight, float[] verts, int vertOffset,
- int[] colors, int colorOffset, long paint);
-
- @Override
- public void drawCircle(float cx, float cy, float radius, Paint paint) {
- nDrawCircle(mRenderer, cx, cy, radius, paint.mNativePaint);
- }
-
- private static native void nDrawCircle(long renderer, float cx, float cy,
- float radius, long paint);
-
- @Override
public void drawCircle(CanvasProperty<Float> cx, CanvasProperty<Float> cy,
CanvasProperty<Float> radius, CanvasProperty<Paint> paint) {
- nDrawCircle(mRenderer, cx.getNativeContainer(), cy.getNativeContainer(),
+ nDrawCircle(mNativeCanvasWrapper, cx.getNativeContainer(), cy.getNativeContainer(),
radius.getNativeContainer(), paint.getNativeContainer());
}
@@ -727,7 +241,7 @@ class GLES20Canvas extends HardwareCanvas {
public void drawRoundRect(CanvasProperty<Float> left, CanvasProperty<Float> top,
CanvasProperty<Float> right, CanvasProperty<Float> bottom, CanvasProperty<Float> rx,
CanvasProperty<Float> ry, CanvasProperty<Paint> paint) {
- nDrawRoundRect(mRenderer, left.getNativeContainer(), top.getNativeContainer(),
+ nDrawRoundRect(mNativeCanvasWrapper, left.getNativeContainer(), top.getNativeContainer(),
right.getNativeContainer(), bottom.getNativeContainer(),
rx.getNativeContainer(), ry.getNativeContainer(),
paint.getNativeContainer());
@@ -736,73 +250,18 @@ class GLES20Canvas extends HardwareCanvas {
private static native void nDrawRoundRect(long renderer, long propLeft, long propTop,
long propRight, long propBottom, long propRx, long propRy, long propPaint);
- @Override
- public void drawColor(int color) {
- drawColor(color, PorterDuff.Mode.SRC_OVER);
- }
-
- @Override
- public void drawColor(int color, PorterDuff.Mode mode) {
- nDrawColor(mRenderer, color, mode.nativeInt);
- }
-
- private static native void nDrawColor(long renderer, int color, int mode);
-
- @Override
- public void drawLine(float startX, float startY, float stopX, float stopY, Paint paint) {
- float[] line = getLineStorage();
- line[0] = startX;
- line[1] = startY;
- line[2] = stopX;
- line[3] = stopY;
- drawLines(line, 0, 4, paint);
- }
-
- @Override
- public void drawLines(float[] pts, int offset, int count, Paint paint) {
- if (count < 4) return;
-
- if ((offset | count) < 0 || offset + count > pts.length) {
- throw new IllegalArgumentException("The lines array must contain 4 elements per line.");
- }
- nDrawLines(mRenderer, pts, offset, count, paint.mNativePaint);
- }
-
- private static native void nDrawLines(long renderer, float[] points,
- int offset, int count, long paint);
-
- @Override
- public void drawLines(float[] pts, Paint paint) {
- drawLines(pts, 0, pts.length, paint);
- }
-
- @Override
- public void drawOval(float left, float top, float right, float bottom, Paint paint) {
- nDrawOval(mRenderer, left, top, right, bottom, paint.mNativePaint);
- }
-
- private static native void nDrawOval(long renderer, float left, float top,
- float right, float bottom, long paint);
-
- @Override
- public void drawPaint(Paint paint) {
- final Rect r = getInternalClipBounds();
- nGetClipBounds(mRenderer, r);
- drawRect(r.left, r.top, r.right, r.bottom, paint);
- }
-
+ // TODO: move this optimization to Canvas.java
@Override
public void drawPath(Path path, Paint paint) {
if (path.isSimplePath) {
if (path.rects != null) {
- nDrawRects(mRenderer, path.rects.mNativeRegion, paint.mNativePaint);
+ nDrawRects(mNativeCanvasWrapper, path.rects.mNativeRegion, paint.getNativeInstance());
}
} else {
- nDrawPath(mRenderer, path.mNativePath, paint.mNativePaint);
+ super.drawPath(path, paint);
}
}
- private static native void nDrawPath(long renderer, long path, long paint);
private static native void nDrawRects(long renderer, long region, long paint);
@Override
@@ -810,190 +269,4 @@ class GLES20Canvas extends HardwareCanvas {
picture.endRecording();
// TODO: Implement rendering
}
-
- @Override
- public void drawPoint(float x, float y, Paint paint) {
- float[] point = getPointStorage();
- point[0] = x;
- point[1] = y;
- drawPoints(point, 0, 2, paint);
- }
-
- @Override
- public void drawPoints(float[] pts, Paint paint) {
- drawPoints(pts, 0, pts.length, paint);
- }
-
- @Override
- public void drawPoints(float[] pts, int offset, int count, Paint paint) {
- if (count < 2) return;
-
- nDrawPoints(mRenderer, pts, offset, count, paint.mNativePaint);
- }
-
- private static native void nDrawPoints(long renderer, float[] points,
- int offset, int count, long paint);
-
- // Note: drawPosText just uses implementation in Canvas
-
- @Override
- public void drawRect(float left, float top, float right, float bottom, Paint paint) {
- if (left == right || top == bottom) return;
- nDrawRect(mRenderer, left, top, right, bottom, paint.mNativePaint);
- }
-
- private static native void nDrawRect(long renderer, float left, float top,
- float right, float bottom, long paint);
-
- @Override
- public void drawRect(Rect r, Paint paint) {
- drawRect(r.left, r.top, r.right, r.bottom, paint);
- }
-
- @Override
- public void drawRect(RectF r, Paint paint) {
- drawRect(r.left, r.top, r.right, r.bottom, paint);
- }
-
- @Override
- public void drawRGB(int r, int g, int b) {
- drawColor(0xFF000000 | (r & 0xFF) << 16 | (g & 0xFF) << 8 | (b & 0xFF));
- }
-
- @Override
- public void drawRoundRect(float left, float top, float right, float bottom, float rx, float ry,
- Paint paint) {
- nDrawRoundRect(mRenderer, left, top, right, bottom, rx, ry, paint.mNativePaint);
- }
-
- private static native void nDrawRoundRect(long renderer, float left, float top,
- float right, float bottom, float rx, float y, long paint);
-
- @Override
- public void drawText(char[] text, int index, int count, float x, float y, Paint paint) {
- if ((index | count | (index + count) | (text.length - index - count)) < 0) {
- throw new IndexOutOfBoundsException();
- }
-
- nDrawText(mRenderer, text, index, count, x, y,
- paint.mBidiFlags, paint.mNativePaint, paint.mNativeTypeface);
- }
-
- private static native void nDrawText(long renderer, char[] text, int index, int count,
- float x, float y, int bidiFlags, long paint, long typeface);
-
- @Override
- public void drawText(CharSequence text, int start, int end, float x, float y, Paint paint) {
- if ((start | end | (end - start) | (text.length() - end)) < 0) {
- throw new IndexOutOfBoundsException();
- }
- if (text instanceof String || text instanceof SpannedString ||
- text instanceof SpannableString) {
- nDrawText(mRenderer, text.toString(), start, end, x, y, paint.mBidiFlags,
- paint.mNativePaint, paint.mNativeTypeface);
- } else if (text instanceof GraphicsOperations) {
- ((GraphicsOperations) text).drawText(this, start, end, x, y, paint);
- } else {
- char[] buf = TemporaryBuffer.obtain(end - start);
- TextUtils.getChars(text, start, end, buf, 0);
- nDrawText(mRenderer, buf, 0, end - start, x, y,
- paint.mBidiFlags, paint.mNativePaint, paint.mNativeTypeface);
- TemporaryBuffer.recycle(buf);
- }
- }
-
- @Override
- public void drawText(String text, int start, int end, float x, float y, Paint paint) {
- if ((start | end | (end - start) | (text.length() - end)) < 0) {
- throw new IndexOutOfBoundsException();
- }
-
- nDrawText(mRenderer, text, start, end, x, y,
- paint.mBidiFlags, paint.mNativePaint, paint.mNativeTypeface);
- }
-
- private static native void nDrawText(long renderer, String text, int start, int end,
- float x, float y, int bidiFlags, long paint, long typeface);
-
- @Override
- public void drawText(String text, float x, float y, Paint paint) {
- nDrawText(mRenderer, text, 0, text.length(), x, y,
- paint.mBidiFlags, paint.mNativePaint, paint.mNativeTypeface);
- }
-
- @Override
- public void drawTextOnPath(char[] text, int index, int count, Path path, float hOffset,
- float vOffset, Paint paint) {
- if (index < 0 || index + count > text.length) {
- throw new ArrayIndexOutOfBoundsException();
- }
-
- nDrawTextOnPath(mRenderer, text, index, count, path.mNativePath, hOffset, vOffset,
- paint.mBidiFlags, paint.mNativePaint, paint.mNativeTypeface);
- }
-
- private static native void nDrawTextOnPath(long renderer, char[] text, int index, int count,
- long path, float hOffset, float vOffset, int bidiFlags, long nativePaint,
- long typeface);
-
- @Override
- public void drawTextOnPath(String text, Path path, float hOffset, float vOffset, Paint paint) {
- if (text.length() == 0) return;
-
- nDrawTextOnPath(mRenderer, text, 0, text.length(), path.mNativePath, hOffset, vOffset,
- paint.mBidiFlags, paint.mNativePaint, paint.mNativeTypeface);
- }
-
- private static native void nDrawTextOnPath(long renderer, String text, int start, int end,
- long path, float hOffset, float vOffset, int bidiFlags, long nativePaint,
- long typeface);
-
- @Override
- public void drawTextRun(char[] text, int index, int count, int contextIndex, int contextCount,
- float x, float y, boolean isRtl, Paint paint) {
- if ((index | count | text.length - index - count) < 0) {
- throw new IndexOutOfBoundsException();
- }
-
- nDrawTextRun(mRenderer, text, index, count, contextIndex, contextCount, x, y, isRtl,
- paint.mNativePaint, paint.mNativeTypeface);
- }
-
- private static native void nDrawTextRun(long renderer, char[] text, int index, int count,
- int contextIndex, int contextCount, float x, float y, boolean isRtl, long nativePaint, long nativeTypeface);
-
- @Override
- public void drawTextRun(CharSequence text, int start, int end, int contextStart, int contextEnd,
- float x, float y, boolean isRtl, Paint paint) {
- if ((start | end | end - start | text.length() - end) < 0) {
- throw new IndexOutOfBoundsException();
- }
-
- if (text instanceof String || text instanceof SpannedString ||
- text instanceof SpannableString) {
- nDrawTextRun(mRenderer, text.toString(), start, end, contextStart,
- contextEnd, x, y, isRtl, paint.mNativePaint, paint.mNativeTypeface);
- } else if (text instanceof GraphicsOperations) {
- ((GraphicsOperations) text).drawTextRun(this, start, end,
- contextStart, contextEnd, x, y, isRtl, paint);
- } else {
- int contextLen = contextEnd - contextStart;
- int len = end - start;
- char[] buf = TemporaryBuffer.obtain(contextLen);
- TextUtils.getChars(text, contextStart, contextEnd, buf, 0);
- nDrawTextRun(mRenderer, buf, start - contextStart, len, 0, contextLen,
- x, y, isRtl, paint.mNativePaint, paint.mNativeTypeface);
- TemporaryBuffer.recycle(buf);
- }
- }
-
- private static native void nDrawTextRun(long renderer, String text, int start, int end,
- int contextStart, int contextEnd, float x, float y, boolean isRtl, long nativePaint, long nativeTypeface);
-
- @Override
- public void drawVertices(VertexMode mode, int vertexCount, float[] verts, int vertOffset,
- float[] texs, int texOffset, int[] colors, int colorOffset, short[] indices,
- int indexOffset, int indexCount, Paint paint) {
- // TODO: Implement
- }
}
diff --git a/core/java/android/view/GLES20RecordingCanvas.java b/core/java/android/view/GLES20RecordingCanvas.java
index 5e49d8e..5ca5626 100644
--- a/core/java/android/view/GLES20RecordingCanvas.java
+++ b/core/java/android/view/GLES20RecordingCanvas.java
@@ -56,7 +56,7 @@ class GLES20RecordingCanvas extends GLES20Canvas {
}
long finishRecording() {
- return nFinishRecording(mRenderer);
+ return nFinishRecording(mNativeCanvasWrapper);
}
@Override
diff --git a/core/java/android/view/HardwareCanvas.java b/core/java/android/view/HardwareCanvas.java
index 18accb8..cdb350f 100644
--- a/core/java/android/view/HardwareCanvas.java
+++ b/core/java/android/view/HardwareCanvas.java
@@ -29,6 +29,14 @@ import android.graphics.Rect;
*/
public abstract class HardwareCanvas extends Canvas {
+ /**
+ * Pass a reference to the native renderer to our superclass's
+ * constructor.
+ */
+ protected HardwareCanvas(long renderer) {
+ super(renderer);
+ }
+
@Override
public boolean isHardwareAccelerated() {
return true;
@@ -43,12 +51,10 @@ public abstract class HardwareCanvas extends Canvas {
* Invoked before any drawing operation is performed in this canvas.
*
* @param dirty The dirty rectangle to update, can be null.
- * @return {@link RenderNode#STATUS_DREW} if anything was drawn (such as a call to clear
- * the canvas).
*
* @hide
*/
- public abstract int onPreDraw(Rect dirty);
+ public abstract void onPreDraw(Rect dirty);
/**
* Invoked after all drawing operation have been performed.
@@ -64,7 +70,7 @@ public abstract class HardwareCanvas extends Canvas {
* @param renderNode The RenderNode to replay.
*/
public void drawRenderNode(RenderNode renderNode) {
- drawRenderNode(renderNode, null, RenderNode.FLAG_CLIP_CHILDREN);
+ drawRenderNode(renderNode, RenderNode.FLAG_CLIP_CHILDREN);
}
/**
@@ -75,12 +81,9 @@ public abstract class HardwareCanvas extends Canvas {
* @param flags Optional flags about drawing, see {@link RenderNode} for
* the possible flags.
*
- * @return One of {@link RenderNode#STATUS_DONE} or {@link RenderNode#STATUS_DREW}
- * if anything was drawn.
- *
* @hide
*/
- public abstract int drawRenderNode(RenderNode renderNode, Rect dirty, int flags);
+ public abstract void drawRenderNode(RenderNode renderNode, int flags);
/**
* Draws the specified layer onto this canvas.
@@ -101,11 +104,11 @@ public abstract class HardwareCanvas extends Canvas {
*
* @param drawGLFunction A native function pointer
*
- * @return {@link RenderNode#STATUS_DONE}
- *
* @hide
*/
- public abstract int callDrawGLFunction2(long drawGLFunction);
+ public void callDrawGLFunction2(long drawGLFunction) {
+ // Noop - this is done in the display list recorder subclass
+ }
public abstract void drawCircle(CanvasProperty<Float> cx, CanvasProperty<Float> cy,
CanvasProperty<Float> radius, CanvasProperty<Paint> paint);
diff --git a/core/java/android/view/HardwareLayer.java b/core/java/android/view/HardwareLayer.java
index a130bda..65ae8a6 100644
--- a/core/java/android/view/HardwareLayer.java
+++ b/core/java/android/view/HardwareLayer.java
@@ -52,7 +52,7 @@ final class HardwareLayer {
* @see View#setLayerPaint(android.graphics.Paint)
*/
public void setLayerPaint(Paint paint) {
- nSetLayerPaint(mFinalizer.get(), paint.mNativePaint);
+ nSetLayerPaint(mFinalizer.get(), paint.getNativeInstance());
mRenderer.pushLayerUpdate(this);
}
diff --git a/core/java/android/view/LayoutInflater.java b/core/java/android/view/LayoutInflater.java
index 1546877..ac32430 100644
--- a/core/java/android/view/LayoutInflater.java
+++ b/core/java/android/view/LayoutInflater.java
@@ -16,10 +16,12 @@
package android.view;
+import android.annotation.Nullable;
import android.graphics.Canvas;
import android.os.Handler;
import android.os.Message;
import android.os.Trace;
+import android.util.TypedValue;
import android.widget.FrameLayout;
import org.xmlpull.v1.XmlPullParser;
@@ -64,6 +66,7 @@ import java.util.HashMap;
* @see Context#getSystemService
*/
public abstract class LayoutInflater {
+
private static final String TAG = LayoutInflater.class.getSimpleName();
private static final boolean DEBUG = false;
@@ -90,12 +93,16 @@ public abstract class LayoutInflater {
private HashMap<String, Boolean> mFilterMap;
+ private TypedValue mTempValue;
+
private static final String TAG_MERGE = "merge";
private static final String TAG_INCLUDE = "include";
private static final String TAG_1995 = "blink";
private static final String TAG_REQUEST_FOCUS = "requestFocus";
private static final String TAG_TAG = "tag";
+ private static final String ATTR_LAYOUT = "layout";
+
private static final int[] ATTRS_THEME = new int[] {
com.android.internal.R.attr.theme };
@@ -361,7 +368,7 @@ public abstract class LayoutInflater {
* this is the root View; otherwise it is the root of the inflated
* XML file.
*/
- public View inflate(int resource, ViewGroup root) {
+ public View inflate(int resource, @Nullable ViewGroup root) {
return inflate(resource, root, root != null);
}
@@ -381,7 +388,7 @@ public abstract class LayoutInflater {
* this is the root View; otherwise it is the root of the inflated
* XML file.
*/
- public View inflate(XmlPullParser parser, ViewGroup root) {
+ public View inflate(XmlPullParser parser, @Nullable ViewGroup root) {
return inflate(parser, root, root != null);
}
@@ -402,7 +409,7 @@ public abstract class LayoutInflater {
* attachToRoot is true, this is root; otherwise it is the root of
* the inflated XML file.
*/
- public View inflate(int resource, ViewGroup root, boolean attachToRoot) {
+ public View inflate(int resource, @Nullable ViewGroup root, boolean attachToRoot) {
final Resources res = getContext().getResources();
if (DEBUG) {
Log.d(TAG, "INFLATING from resource: \"" + res.getResourceName(resource) + "\" ("
@@ -439,7 +446,7 @@ public abstract class LayoutInflater {
* attachToRoot is true, this is root; otherwise it is the root of
* the inflated XML file.
*/
- public View inflate(XmlPullParser parser, ViewGroup root, boolean attachToRoot) {
+ public View inflate(XmlPullParser parser, @Nullable ViewGroup root, boolean attachToRoot) {
synchronized (mConstructorArgs) {
Trace.traceBegin(Trace.TRACE_TAG_VIEW, "inflate");
@@ -837,7 +844,7 @@ public abstract class LayoutInflater {
throws XmlPullParserException, IOException {
int type;
- final TypedArray ta = mContext.obtainStyledAttributes(
+ final TypedArray ta = view.getContext().obtainStyledAttributes(
attrs, com.android.internal.R.styleable.ViewTag);
final int key = ta.getResourceId(com.android.internal.R.styleable.ViewTag_id, 0);
final CharSequence value = ta.getText(com.android.internal.R.styleable.ViewTag_value);
@@ -856,16 +863,41 @@ public abstract class LayoutInflater {
int type;
if (parent instanceof ViewGroup) {
- final int layout = attrs.getAttributeResourceValue(null, "layout", 0);
+ Context context = inheritContext ? parent.getContext() : mContext;
+
+ // Apply a theme wrapper, if requested.
+ final TypedArray ta = context.obtainStyledAttributes(attrs, ATTRS_THEME);
+ final int themeResId = ta.getResourceId(0, 0);
+ if (themeResId != 0) {
+ context = new ContextThemeWrapper(context, themeResId);
+ }
+ ta.recycle();
+
+ // If the layout is pointing to a theme attribute, we have to
+ // massage the value to get a resource identifier out of it.
+ int layout = attrs.getAttributeResourceValue(null, ATTR_LAYOUT, 0);
if (layout == 0) {
- final String value = attrs.getAttributeValue(null, "layout");
- if (value == null) {
- throw new InflateException("You must specifiy a layout in the"
+ final String value = attrs.getAttributeValue(null, ATTR_LAYOUT);
+ if (value == null || value.length() < 1) {
+ throw new InflateException("You must specify a layout in the"
+ " include tag: <include layout=\"@layout/layoutID\" />");
- } else {
- throw new InflateException("You must specifiy a valid layout "
- + "reference. The layout ID " + value + " is not valid.");
}
+
+ layout = context.getResources().getIdentifier(value.substring(1), null, null);
+ }
+
+ // The layout might be referencing a theme attribute.
+ if (mTempValue == null) {
+ mTempValue = new TypedValue();
+ }
+ if (layout != 0 && context.getTheme().resolveAttribute(layout, mTempValue, true)) {
+ layout = mTempValue.resourceId;
+ }
+
+ if (layout == 0) {
+ final String value = attrs.getAttributeValue(null, ATTR_LAYOUT);
+ throw new InflateException("You must specify a valid layout "
+ + "reference. The layout ID " + value + " is not valid.");
} else {
final XmlResourceParser childParser =
getContext().getResources().getLayout(layout);
@@ -915,13 +947,12 @@ public abstract class LayoutInflater {
// Inflate all children.
rInflate(childParser, view, childAttrs, true, true);
- // Attempt to override the included layout's android:id with the
- // one set on the <include /> tag itself.
- TypedArray a = mContext.obtainStyledAttributes(attrs,
- com.android.internal.R.styleable.View, 0, 0);
- int id = a.getResourceId(com.android.internal.R.styleable.View_id, View.NO_ID);
- // While we're at it, let's try to override android:visibility.
- int visibility = a.getInt(com.android.internal.R.styleable.View_visibility, -1);
+ final TypedArray a = context.obtainStyledAttributes(
+ attrs, com.android.internal.R.styleable.Include);
+ final int id = a.getResourceId(
+ com.android.internal.R.styleable.Include_id, View.NO_ID);
+ final int visibility = a.getInt(
+ com.android.internal.R.styleable.Include_visibility, -1);
a.recycle();
if (id != View.NO_ID) {
diff --git a/core/java/android/view/RenderNode.java b/core/java/android/view/RenderNode.java
index 47f72a8..09eb486 100644
--- a/core/java/android/view/RenderNode.java
+++ b/core/java/android/view/RenderNode.java
@@ -305,7 +305,7 @@ public class RenderNode {
}
public boolean setLayerPaint(Paint paint) {
- return nSetLayerPaint(mNativeRenderNode, paint != null ? paint.mNativePaint : 0);
+ return nSetLayerPaint(mNativeRenderNode, paint != null ? paint.getNativeInstance() : 0);
}
public boolean setClipBounds(@Nullable Rect rect) {
diff --git a/core/java/android/view/Surface.java b/core/java/android/view/Surface.java
index 33ce517..83b8100 100644
--- a/core/java/android/view/Surface.java
+++ b/core/java/android/view/Surface.java
@@ -322,7 +322,6 @@ public class Surface implements Parcelable {
* @return A canvas for drawing into the surface.
*
* @throws IllegalStateException If the canvas cannot be locked.
- * @hide
*/
public Canvas lockHardwareCanvas() {
synchronized (mLock) {
diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java
index 6a36c26..1e6f6c9 100644
--- a/core/java/android/view/View.java
+++ b/core/java/android/view/View.java
@@ -66,6 +66,7 @@ import android.util.LongSparseLongArray;
import android.util.Pools.SynchronizedPool;
import android.util.Property;
import android.util.SparseArray;
+import android.util.StateSet;
import android.util.SuperNotCalledException;
import android.util.TypedValue;
import android.view.ContextMenu.ContextMenuInfo;
@@ -439,7 +440,7 @@ import java.util.concurrent.atomic.AtomicInteger;
* </p>
*
* <p>
- * To intiate a layout, call {@link #requestLayout}. This method is typically
+ * To initiate a layout, call {@link #requestLayout}. This method is typically
* called by a view on itself when it believes that is can no longer fit within
* its current bounds.
* </p>
@@ -1438,140 +1439,87 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
*/
protected static final int[] PRESSED_ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET;
- /**
- * The order here is very important to {@link #getDrawableState()}
- */
- private static final int[][] VIEW_STATE_SETS;
-
- static final int VIEW_STATE_WINDOW_FOCUSED = 1;
- static final int VIEW_STATE_SELECTED = 1 << 1;
- static final int VIEW_STATE_FOCUSED = 1 << 2;
- static final int VIEW_STATE_ENABLED = 1 << 3;
- static final int VIEW_STATE_PRESSED = 1 << 4;
- static final int VIEW_STATE_ACTIVATED = 1 << 5;
- static final int VIEW_STATE_ACCELERATED = 1 << 6;
- static final int VIEW_STATE_HOVERED = 1 << 7;
- static final int VIEW_STATE_DRAG_CAN_ACCEPT = 1 << 8;
- static final int VIEW_STATE_DRAG_HOVERED = 1 << 9;
-
- static final int[] VIEW_STATE_IDS = new int[] {
- R.attr.state_window_focused, VIEW_STATE_WINDOW_FOCUSED,
- R.attr.state_selected, VIEW_STATE_SELECTED,
- R.attr.state_focused, VIEW_STATE_FOCUSED,
- R.attr.state_enabled, VIEW_STATE_ENABLED,
- R.attr.state_pressed, VIEW_STATE_PRESSED,
- R.attr.state_activated, VIEW_STATE_ACTIVATED,
- R.attr.state_accelerated, VIEW_STATE_ACCELERATED,
- R.attr.state_hovered, VIEW_STATE_HOVERED,
- R.attr.state_drag_can_accept, VIEW_STATE_DRAG_CAN_ACCEPT,
- R.attr.state_drag_hovered, VIEW_STATE_DRAG_HOVERED
- };
-
static {
- if ((VIEW_STATE_IDS.length/2) != R.styleable.ViewDrawableStates.length) {
- throw new IllegalStateException(
- "VIEW_STATE_IDs array length does not match ViewDrawableStates style array");
- }
- int[] orderedIds = new int[VIEW_STATE_IDS.length];
- for (int i = 0; i < R.styleable.ViewDrawableStates.length; i++) {
- int viewState = R.styleable.ViewDrawableStates[i];
- for (int j = 0; j<VIEW_STATE_IDS.length; j += 2) {
- if (VIEW_STATE_IDS[j] == viewState) {
- orderedIds[i * 2] = viewState;
- orderedIds[i * 2 + 1] = VIEW_STATE_IDS[j + 1];
- }
- }
- }
- final int NUM_BITS = VIEW_STATE_IDS.length / 2;
- VIEW_STATE_SETS = new int[1 << NUM_BITS][];
- for (int i = 0; i < VIEW_STATE_SETS.length; i++) {
- int numBits = Integer.bitCount(i);
- int[] set = new int[numBits];
- int pos = 0;
- for (int j = 0; j < orderedIds.length; j += 2) {
- if ((i & orderedIds[j+1]) != 0) {
- set[pos++] = orderedIds[j];
- }
- }
- VIEW_STATE_SETS[i] = set;
- }
-
- EMPTY_STATE_SET = VIEW_STATE_SETS[0];
- WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[VIEW_STATE_WINDOW_FOCUSED];
- SELECTED_STATE_SET = VIEW_STATE_SETS[VIEW_STATE_SELECTED];
- SELECTED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[
- VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_SELECTED];
- FOCUSED_STATE_SET = VIEW_STATE_SETS[VIEW_STATE_FOCUSED];
- FOCUSED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[
- VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_FOCUSED];
- FOCUSED_SELECTED_STATE_SET = VIEW_STATE_SETS[
- VIEW_STATE_SELECTED | VIEW_STATE_FOCUSED];
- FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[
- VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_SELECTED
- | VIEW_STATE_FOCUSED];
- ENABLED_STATE_SET = VIEW_STATE_SETS[VIEW_STATE_ENABLED];
- ENABLED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[
- VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_ENABLED];
- ENABLED_SELECTED_STATE_SET = VIEW_STATE_SETS[
- VIEW_STATE_SELECTED | VIEW_STATE_ENABLED];
- ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[
- VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_SELECTED
- | VIEW_STATE_ENABLED];
- ENABLED_FOCUSED_STATE_SET = VIEW_STATE_SETS[
- VIEW_STATE_FOCUSED | VIEW_STATE_ENABLED];
- ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[
- VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_FOCUSED
- | VIEW_STATE_ENABLED];
- ENABLED_FOCUSED_SELECTED_STATE_SET = VIEW_STATE_SETS[
- VIEW_STATE_SELECTED | VIEW_STATE_FOCUSED
- | VIEW_STATE_ENABLED];
- ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[
- VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_SELECTED
- | VIEW_STATE_FOCUSED| VIEW_STATE_ENABLED];
-
- PRESSED_STATE_SET = VIEW_STATE_SETS[VIEW_STATE_PRESSED];
- PRESSED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[
- VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_PRESSED];
- PRESSED_SELECTED_STATE_SET = VIEW_STATE_SETS[
- VIEW_STATE_SELECTED | VIEW_STATE_PRESSED];
- PRESSED_SELECTED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[
- VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_SELECTED
- | VIEW_STATE_PRESSED];
- PRESSED_FOCUSED_STATE_SET = VIEW_STATE_SETS[
- VIEW_STATE_FOCUSED | VIEW_STATE_PRESSED];
- PRESSED_FOCUSED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[
- VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_FOCUSED
- | VIEW_STATE_PRESSED];
- PRESSED_FOCUSED_SELECTED_STATE_SET = VIEW_STATE_SETS[
- VIEW_STATE_SELECTED | VIEW_STATE_FOCUSED
- | VIEW_STATE_PRESSED];
- PRESSED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[
- VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_SELECTED
- | VIEW_STATE_FOCUSED | VIEW_STATE_PRESSED];
- PRESSED_ENABLED_STATE_SET = VIEW_STATE_SETS[
- VIEW_STATE_ENABLED | VIEW_STATE_PRESSED];
- PRESSED_ENABLED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[
- VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_ENABLED
- | VIEW_STATE_PRESSED];
- PRESSED_ENABLED_SELECTED_STATE_SET = VIEW_STATE_SETS[
- VIEW_STATE_SELECTED | VIEW_STATE_ENABLED
- | VIEW_STATE_PRESSED];
- PRESSED_ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[
- VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_SELECTED
- | VIEW_STATE_ENABLED | VIEW_STATE_PRESSED];
- PRESSED_ENABLED_FOCUSED_STATE_SET = VIEW_STATE_SETS[
- VIEW_STATE_FOCUSED | VIEW_STATE_ENABLED
- | VIEW_STATE_PRESSED];
- PRESSED_ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[
- VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_FOCUSED
- | VIEW_STATE_ENABLED | VIEW_STATE_PRESSED];
- PRESSED_ENABLED_FOCUSED_SELECTED_STATE_SET = VIEW_STATE_SETS[
- VIEW_STATE_SELECTED | VIEW_STATE_FOCUSED
- | VIEW_STATE_ENABLED | VIEW_STATE_PRESSED];
- PRESSED_ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[
- VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_SELECTED
- | VIEW_STATE_FOCUSED| VIEW_STATE_ENABLED
- | VIEW_STATE_PRESSED];
+ EMPTY_STATE_SET = StateSet.get(0);
+
+ WINDOW_FOCUSED_STATE_SET = StateSet.get(StateSet.VIEW_STATE_WINDOW_FOCUSED);
+
+ SELECTED_STATE_SET = StateSet.get(StateSet.VIEW_STATE_SELECTED);
+ SELECTED_WINDOW_FOCUSED_STATE_SET = StateSet.get(
+ StateSet.VIEW_STATE_WINDOW_FOCUSED | StateSet.VIEW_STATE_SELECTED);
+
+ FOCUSED_STATE_SET = StateSet.get(StateSet.VIEW_STATE_FOCUSED);
+ FOCUSED_WINDOW_FOCUSED_STATE_SET = StateSet.get(
+ StateSet.VIEW_STATE_WINDOW_FOCUSED | StateSet.VIEW_STATE_FOCUSED);
+ FOCUSED_SELECTED_STATE_SET = StateSet.get(
+ StateSet.VIEW_STATE_SELECTED | StateSet.VIEW_STATE_FOCUSED);
+ FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET = StateSet.get(
+ StateSet.VIEW_STATE_WINDOW_FOCUSED | StateSet.VIEW_STATE_SELECTED
+ | StateSet.VIEW_STATE_FOCUSED);
+
+ ENABLED_STATE_SET = StateSet.get(StateSet.VIEW_STATE_ENABLED);
+ ENABLED_WINDOW_FOCUSED_STATE_SET = StateSet.get(
+ StateSet.VIEW_STATE_WINDOW_FOCUSED | StateSet.VIEW_STATE_ENABLED);
+ ENABLED_SELECTED_STATE_SET = StateSet.get(
+ StateSet.VIEW_STATE_SELECTED | StateSet.VIEW_STATE_ENABLED);
+ ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET = StateSet.get(
+ StateSet.VIEW_STATE_WINDOW_FOCUSED | StateSet.VIEW_STATE_SELECTED
+ | StateSet.VIEW_STATE_ENABLED);
+ ENABLED_FOCUSED_STATE_SET = StateSet.get(
+ StateSet.VIEW_STATE_FOCUSED | StateSet.VIEW_STATE_ENABLED);
+ ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET = StateSet.get(
+ StateSet.VIEW_STATE_WINDOW_FOCUSED | StateSet.VIEW_STATE_FOCUSED
+ | StateSet.VIEW_STATE_ENABLED);
+ ENABLED_FOCUSED_SELECTED_STATE_SET = StateSet.get(
+ StateSet.VIEW_STATE_SELECTED | StateSet.VIEW_STATE_FOCUSED
+ | StateSet.VIEW_STATE_ENABLED);
+ ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET = StateSet.get(
+ StateSet.VIEW_STATE_WINDOW_FOCUSED | StateSet.VIEW_STATE_SELECTED
+ | StateSet.VIEW_STATE_FOCUSED| StateSet.VIEW_STATE_ENABLED);
+
+ PRESSED_STATE_SET = StateSet.get(StateSet.VIEW_STATE_PRESSED);
+ PRESSED_WINDOW_FOCUSED_STATE_SET = StateSet.get(
+ StateSet.VIEW_STATE_WINDOW_FOCUSED | StateSet.VIEW_STATE_PRESSED);
+ PRESSED_SELECTED_STATE_SET = StateSet.get(
+ StateSet.VIEW_STATE_SELECTED | StateSet.VIEW_STATE_PRESSED);
+ PRESSED_SELECTED_WINDOW_FOCUSED_STATE_SET = StateSet.get(
+ StateSet.VIEW_STATE_WINDOW_FOCUSED | StateSet.VIEW_STATE_SELECTED
+ | StateSet.VIEW_STATE_PRESSED);
+ PRESSED_FOCUSED_STATE_SET = StateSet.get(
+ StateSet.VIEW_STATE_FOCUSED | StateSet.VIEW_STATE_PRESSED);
+ PRESSED_FOCUSED_WINDOW_FOCUSED_STATE_SET = StateSet.get(
+ StateSet.VIEW_STATE_WINDOW_FOCUSED | StateSet.VIEW_STATE_FOCUSED
+ | StateSet.VIEW_STATE_PRESSED);
+ PRESSED_FOCUSED_SELECTED_STATE_SET = StateSet.get(
+ StateSet.VIEW_STATE_SELECTED | StateSet.VIEW_STATE_FOCUSED
+ | StateSet.VIEW_STATE_PRESSED);
+ PRESSED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET = StateSet.get(
+ StateSet.VIEW_STATE_WINDOW_FOCUSED | StateSet.VIEW_STATE_SELECTED
+ | StateSet.VIEW_STATE_FOCUSED | StateSet.VIEW_STATE_PRESSED);
+ PRESSED_ENABLED_STATE_SET = StateSet.get(
+ StateSet.VIEW_STATE_ENABLED | StateSet.VIEW_STATE_PRESSED);
+ PRESSED_ENABLED_WINDOW_FOCUSED_STATE_SET = StateSet.get(
+ StateSet.VIEW_STATE_WINDOW_FOCUSED | StateSet.VIEW_STATE_ENABLED
+ | StateSet.VIEW_STATE_PRESSED);
+ PRESSED_ENABLED_SELECTED_STATE_SET = StateSet.get(
+ StateSet.VIEW_STATE_SELECTED | StateSet.VIEW_STATE_ENABLED
+ | StateSet.VIEW_STATE_PRESSED);
+ PRESSED_ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET = StateSet.get(
+ StateSet.VIEW_STATE_WINDOW_FOCUSED | StateSet.VIEW_STATE_SELECTED
+ | StateSet.VIEW_STATE_ENABLED | StateSet.VIEW_STATE_PRESSED);
+ PRESSED_ENABLED_FOCUSED_STATE_SET = StateSet.get(
+ StateSet.VIEW_STATE_FOCUSED | StateSet.VIEW_STATE_ENABLED
+ | StateSet.VIEW_STATE_PRESSED);
+ PRESSED_ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET = StateSet.get(
+ StateSet.VIEW_STATE_WINDOW_FOCUSED | StateSet.VIEW_STATE_FOCUSED
+ | StateSet.VIEW_STATE_ENABLED | StateSet.VIEW_STATE_PRESSED);
+ PRESSED_ENABLED_FOCUSED_SELECTED_STATE_SET = StateSet.get(
+ StateSet.VIEW_STATE_SELECTED | StateSet.VIEW_STATE_FOCUSED
+ | StateSet.VIEW_STATE_ENABLED | StateSet.VIEW_STATE_PRESSED);
+ PRESSED_ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET = StateSet.get(
+ StateSet.VIEW_STATE_WINDOW_FOCUSED | StateSet.VIEW_STATE_SELECTED
+ | StateSet.VIEW_STATE_FOCUSED| StateSet.VIEW_STATE_ENABLED
+ | StateSet.VIEW_STATE_PRESSED);
}
/**
@@ -1977,7 +1925,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
static final int LAYOUT_DIRECTION_RESOLVED_DEFAULT = LAYOUT_DIRECTION_LTR;
/**
- * Text direction is inherited thru {@link ViewGroup}
+ * Text direction is inherited through {@link ViewGroup}
*/
public static final int TEXT_DIRECTION_INHERIT = 0;
@@ -2545,7 +2493,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
/**
* Flag for {@link #setSystemUiVisibility(int)}: View would like its window
- * to be layed out as if it has requested
+ * to be laid out as if it has requested
* {@link #SYSTEM_UI_FLAG_HIDE_NAVIGATION}, even if it currently hasn't. This
* allows it to avoid artifacts when switching in and out of that mode, at
* the expense that some of its user interface may be covered by screen
@@ -2557,7 +2505,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
/**
* Flag for {@link #setSystemUiVisibility(int)}: View would like its window
- * to be layed out as if it has requested
+ * to be laid out as if it has requested
* {@link #SYSTEM_UI_FLAG_FULLSCREEN}, even if it currently hasn't. This
* allows it to avoid artifacts when switching in and out of that mode, at
* the expense that some of its user interface may be covered by screen
@@ -4508,6 +4456,8 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
if (scrollabilityCache.scrollBar == null) {
scrollabilityCache.scrollBar = new ScrollBarDrawable();
+ scrollabilityCache.scrollBar.setCallback(this);
+ scrollabilityCache.scrollBar.setState(getDrawableState());
}
final boolean fadeScrollbars = a.getBoolean(R.styleable.View_fadeScrollbars, true);
@@ -5123,7 +5073,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
}
/**
- * Returns true if this view has focus iteself, or is the ancestor of the
+ * Returns true if this view has focus itself, or is the ancestor of the
* view that has focus.
*
* @return True if this view has or contains focus, false otherwise.
@@ -5220,7 +5170,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
* populate the text content of the event source including its descendants,
* and last calls
* {@link ViewParent#requestSendAccessibilityEvent(View, AccessibilityEvent)}
- * on its parent to resuest sending of the event to interested parties.
+ * on its parent to request sending of the event to interested parties.
* <p>
* If an {@link AccessibilityDelegate} has been specified via calling
* {@link #setAccessibilityDelegate(AccessibilityDelegate)} its
@@ -5270,8 +5220,10 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
* @see #sendAccessibilityEvent(int)
*
* Note: Called from the default {@link AccessibilityDelegate}.
+ *
+ * @hide
*/
- void sendAccessibilityEventInternal(int eventType) {
+ public void sendAccessibilityEventInternal(int eventType) {
if (AccessibilityManager.getInstance(mContext).isEnabled()) {
sendAccessibilityEventUnchecked(AccessibilityEvent.obtain(eventType));
}
@@ -5304,8 +5256,10 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
* @see #sendAccessibilityEventUnchecked(AccessibilityEvent)
*
* Note: Called from the default {@link AccessibilityDelegate}.
+ *
+ * @hide
*/
- void sendAccessibilityEventUncheckedInternal(AccessibilityEvent event) {
+ public void sendAccessibilityEventUncheckedInternal(AccessibilityEvent event) {
if (!isShown()) {
return;
}
@@ -5355,8 +5309,10 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
* @see #dispatchPopulateAccessibilityEvent(AccessibilityEvent)
*
* Note: Called from the default {@link AccessibilityDelegate}.
+ *
+ * @hide
*/
- boolean dispatchPopulateAccessibilityEventInternal(AccessibilityEvent event) {
+ public boolean dispatchPopulateAccessibilityEventInternal(AccessibilityEvent event) {
onPopulateAccessibilityEvent(event);
return false;
}
@@ -5404,8 +5360,10 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
* @see #onPopulateAccessibilityEvent(AccessibilityEvent)
*
* Note: Called from the default {@link AccessibilityDelegate}.
+ *
+ * @hide
*/
- void onPopulateAccessibilityEventInternal(AccessibilityEvent event) {
+ public void onPopulateAccessibilityEventInternal(AccessibilityEvent event) {
}
/**
@@ -5446,8 +5404,10 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
* @see #onInitializeAccessibilityEvent(AccessibilityEvent)
*
* Note: Called from the default {@link AccessibilityDelegate}.
+ *
+ * @hide
*/
- void onInitializeAccessibilityEventInternal(AccessibilityEvent event) {
+ public void onInitializeAccessibilityEventInternal(AccessibilityEvent event) {
event.setSource(this);
event.setClassName(View.class.getName());
event.setPackageName(getContext().getPackageName());
@@ -5502,8 +5462,10 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
/**
* @see #createAccessibilityNodeInfo()
+ *
+ * @hide
*/
- AccessibilityNodeInfo createAccessibilityNodeInfoInternal() {
+ public AccessibilityNodeInfo createAccessibilityNodeInfoInternal() {
AccessibilityNodeProvider provider = getAccessibilityNodeProvider();
if (provider != null) {
return provider.createAccessibilityNodeInfo(View.NO_ID);
@@ -5602,8 +5564,10 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
* @see #onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo)
*
* Note: Called from the default {@link AccessibilityDelegate}.
+ *
+ * @hide
*/
- void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) {
+ public void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) {
Rect bounds = mAttachInfo.mTmpInvalRect;
getDrawingRect(bounds);
@@ -7529,8 +7493,8 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
* including this view if it is focusable itself) to views. This method
* adds all focusable views regardless if we are in touch mode or
* only views focusable in touch mode if we are in touch mode or
- * only views that can take accessibility focus if accessibility is enabeld
- * depending on the focusable mode paramater.
+ * only views that can take accessibility focus if accessibility is enabled
+ * depending on the focusable mode parameter.
*
* @param views Focusable views found so far or null if all we are interested is
* the number of focusables.
@@ -7816,7 +7780,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
/**
* Call this to try to give focus to a specific view or to one of its descendants. This is a
- * special variant of {@link #requestFocus() } that will allow views that are not focuable in
+ * special variant of {@link #requestFocus() } that will allow views that are not focusable in
* touch mode to request focus when they are touched.
*
* @return Whether this view or one of its descendants actually took focus.
@@ -8218,7 +8182,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
*
* Note: Called from the default {@link AccessibilityDelegate}.
*
- * @hide Until we've refactored all accessibility delegation methods.
+ * @hide
*/
public boolean performAccessibilityActionInternal(int action, Bundle arguments) {
if (isNestedScrollingEnabled()
@@ -8988,7 +8952,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
* Called when the current configuration of the resources being used
* by the application have changed. You can use this to decide when
* to reload resources that can changed based on orientation and other
- * configuration characterstics. You only need to use this if you are
+ * configuration characteristics. You only need to use this if you are
* not relying on the normal {@link android.app.Activity} mechanism of
* recreating the activity instance upon a configuration change.
*
@@ -10657,7 +10621,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
* <p>Note that if the view is backed by a
* {@link #setLayerType(int, android.graphics.Paint) layer} and is associated with a
* {@link #setLayerPaint(android.graphics.Paint) layer paint}, setting an alpha value less than
- * 1.0 will supercede the alpha of the layer paint.</p>
+ * 1.0 will supersede the alpha of the layer paint.</p>
*
* @param alpha The opacity of the view.
*
@@ -11705,7 +11669,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
* </p>
*
* <p>
- * This method should be invoked everytime a subclass directly updates the
+ * This method should be invoked every time a subclass directly updates the
* scroll parameters.
* </p>
*
@@ -11744,7 +11708,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
* </p>
*
* <p>
- * This method should be invoked everytime a subclass directly updates the
+ * This method should be invoked every time a subclass directly updates the
* scroll parameters.
* </p>
*
@@ -11752,7 +11716,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
* should start; when the delay is 0, the animation starts
* immediately
*
- * @param invalidate Wheter this method should call invalidate
+ * @param invalidate Whether this method should call invalidate
*
* @return true if the animation is played, false otherwise
*
@@ -11772,6 +11736,8 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
if (scrollCache.scrollBar == null) {
scrollCache.scrollBar = new ScrollBarDrawable();
+ scrollCache.scrollBar.setCallback(this);
+ scrollCache.scrollBar.setState(getDrawableState());
}
if (isHorizontalScrollBarEnabled() || isVerticalScrollBarEnabled()) {
@@ -12657,7 +12623,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
/**
* Define whether scrollbars will fade when the view is not scrolling.
*
- * @param fadeScrollbars wheter to enable fading
+ * @param fadeScrollbars whether to enable fading
*
* @attr ref android.R.styleable#View_fadeScrollbars
*/
@@ -13509,7 +13475,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
* after onDetachedFromWindow().
*
* If you override this you *MUST* call super.onDetachedFromWindowInternal()!
- * The super method should be called at the end of the overriden method to ensure
+ * The super method should be called at the end of the overridden method to ensure
* subclasses are destroyed first
*
* @hide
@@ -13910,7 +13876,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
* <p>Note: if this view's parent addStateFromChildren property is enabled and this
* property is enabled, an exception will be thrown.</p>
*
- * <p>Note: if the child view uses and updates additionnal states which are unknown to the
+ * <p>Note: if the child view uses and updates additional states which are unknown to the
* parent, these states should not be affected by this method.</p>
*
* @param enabled True to enable duplication of the parent's drawable state, false
@@ -13951,7 +13917,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
* </ul>
*
* <p>If this view has an alpha value set to < 1.0 by calling
- * {@link #setAlpha(float)}, the alpha value of the layer's paint is superceded
+ * {@link #setAlpha(float)}, the alpha value of the layer's paint is superseded
* by this view's alpha value.</p>
*
* <p>Refer to the documentation of {@link #LAYER_TYPE_NONE},
@@ -14019,7 +13985,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
* </ul>
*
* <p>If this view has an alpha value set to < 1.0 by calling {@link #setAlpha(float)}, the
- * alpha value of the layer's paint is superceded by this view's alpha value.</p>
+ * alpha value of the layer's paint is superseded by this view's alpha value.</p>
*
* @param paint The paint used to compose the layer. This argument is optional
* and can be null. It is ignored when the layer type is
@@ -15261,7 +15227,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
}
} else {
mPrivateFlags &= ~PFLAG_DIRTY_MASK;
- ((HardwareCanvas) canvas).drawRenderNode(renderNode, null, flags);
+ ((HardwareCanvas) canvas).drawRenderNode(renderNode, flags);
}
}
} else if (cache != null) {
@@ -16084,7 +16050,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
* @see #drawableStateChanged()
*/
protected boolean verifyDrawable(Drawable who) {
- return who == mBackground;
+ return who == mBackground || (mScrollCache != null && mScrollCache.scrollBar == who);
}
/**
@@ -16099,13 +16065,22 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
* @see Drawable#setState(int[])
*/
protected void drawableStateChanged() {
+ final int[] state = getDrawableState();
+
final Drawable d = mBackground;
if (d != null && d.isStateful()) {
- d.setState(getDrawableState());
+ d.setState(state);
+ }
+
+ if (mScrollCache != null) {
+ final Drawable scrollBar = mScrollCache.scrollBar;
+ if (scrollBar != null && scrollBar.isStateful()) {
+ scrollBar.setState(state);
+ }
}
if (mStateListAnimator != null) {
- mStateListAnimator.setState(getDrawableState());
+ mStateListAnimator.setState(state);
}
}
@@ -16203,26 +16178,30 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
int privateFlags = mPrivateFlags;
int viewStateIndex = 0;
- if ((privateFlags & PFLAG_PRESSED) != 0) viewStateIndex |= VIEW_STATE_PRESSED;
- if ((mViewFlags & ENABLED_MASK) == ENABLED) viewStateIndex |= VIEW_STATE_ENABLED;
- if (isFocused()) viewStateIndex |= VIEW_STATE_FOCUSED;
- if ((privateFlags & PFLAG_SELECTED) != 0) viewStateIndex |= VIEW_STATE_SELECTED;
- if (hasWindowFocus()) viewStateIndex |= VIEW_STATE_WINDOW_FOCUSED;
- if ((privateFlags & PFLAG_ACTIVATED) != 0) viewStateIndex |= VIEW_STATE_ACTIVATED;
+ if ((privateFlags & PFLAG_PRESSED) != 0) viewStateIndex |= StateSet.VIEW_STATE_PRESSED;
+ if ((mViewFlags & ENABLED_MASK) == ENABLED) viewStateIndex |= StateSet.VIEW_STATE_ENABLED;
+ if (isFocused()) viewStateIndex |= StateSet.VIEW_STATE_FOCUSED;
+ if ((privateFlags & PFLAG_SELECTED) != 0) viewStateIndex |= StateSet.VIEW_STATE_SELECTED;
+ if (hasWindowFocus()) viewStateIndex |= StateSet.VIEW_STATE_WINDOW_FOCUSED;
+ if ((privateFlags & PFLAG_ACTIVATED) != 0) viewStateIndex |= StateSet.VIEW_STATE_ACTIVATED;
if (mAttachInfo != null && mAttachInfo.mHardwareAccelerationRequested &&
HardwareRenderer.isAvailable()) {
// This is set if HW acceleration is requested, even if the current
// process doesn't allow it. This is just to allow app preview
// windows to better match their app.
- viewStateIndex |= VIEW_STATE_ACCELERATED;
+ viewStateIndex |= StateSet.VIEW_STATE_ACCELERATED;
}
- if ((privateFlags & PFLAG_HOVERED) != 0) viewStateIndex |= VIEW_STATE_HOVERED;
+ if ((privateFlags & PFLAG_HOVERED) != 0) viewStateIndex |= StateSet.VIEW_STATE_HOVERED;
final int privateFlags2 = mPrivateFlags2;
- if ((privateFlags2 & PFLAG2_DRAG_CAN_ACCEPT) != 0) viewStateIndex |= VIEW_STATE_DRAG_CAN_ACCEPT;
- if ((privateFlags2 & PFLAG2_DRAG_HOVERED) != 0) viewStateIndex |= VIEW_STATE_DRAG_HOVERED;
+ if ((privateFlags2 & PFLAG2_DRAG_CAN_ACCEPT) != 0) {
+ viewStateIndex |= StateSet.VIEW_STATE_DRAG_CAN_ACCEPT;
+ }
+ if ((privateFlags2 & PFLAG2_DRAG_HOVERED) != 0) {
+ viewStateIndex |= StateSet.VIEW_STATE_DRAG_HOVERED;
+ }
- drawableState = VIEW_STATE_SETS[viewStateIndex];
+ drawableState = StateSet.get(viewStateIndex);
//noinspection ConstantIfStatement
if (false) {
@@ -16310,6 +16289,19 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
}
/**
+ * If the view has a ColorDrawable background, returns the color of that
+ * drawable.
+ *
+ * @return The color of the ColorDrawable background, if set, otherwise 0.
+ */
+ public int getBackgroundColor() {
+ if (mBackground instanceof ColorDrawable) {
+ return ((ColorDrawable) mBackground).getColor();
+ }
+ return 0;
+ }
+
+ /**
* Set the background to a given resource. The resource should refer to
* a Drawable object or 0 to remove the background.
* @param resid The identifier of the resource.
@@ -16771,8 +16763,8 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
}
/**
- * Return if the padding as been set thru relative values
- * {@link #setPaddingRelative(int, int, int, int)} or thru
+ * Return if the padding has been set through relative values
+ * {@link #setPaddingRelative(int, int, int, int)} or through
* @attr ref android.R.styleable#View_paddingStart or
* @attr ref android.R.styleable#View_paddingEnd
*
@@ -17396,7 +17388,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
*
* The specified key should be an id declared in the resources of the
* application to ensure it is unique (see the <a
- * href={@docRoot}guide/topics/resources/more-resources.html#Id">ID resource type</a>).
+ * href="{@docRoot}guide/topics/resources/more-resources.html#Id">ID resource type</a>).
* Keys identified as belonging to
* the Android framework or not associated with any package will cause
* an {@link IllegalArgumentException} to be thrown.
@@ -17694,7 +17686,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
* <p>
* Measure the view and its content to determine the measured width and the
* measured height. This method is invoked by {@link #measure(int, int)} and
- * should be overriden by subclasses to provide accurate and efficient
+ * should be overridden by subclasses to provide accurate and efficient
* measurement of their contents.
* </p>
*
@@ -17807,37 +17799,40 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
/**
* Utility to reconcile a desired size and state, with constraints imposed
- * by a MeasureSpec. Will take the desired size, unless a different size
- * is imposed by the constraints. The returned value is a compound integer,
+ * by a MeasureSpec. Will take the desired size, unless a different size
+ * is imposed by the constraints. The returned value is a compound integer,
* with the resolved size in the {@link #MEASURED_SIZE_MASK} bits and
- * optionally the bit {@link #MEASURED_STATE_TOO_SMALL} set if the resulting
- * size is smaller than the size the view wants to be.
+ * optionally the bit {@link #MEASURED_STATE_TOO_SMALL} set if the
+ * resulting size is smaller than the size the view wants to be.
*
- * @param size How big the view wants to be
- * @param measureSpec Constraints imposed by the parent
+ * @param size How big the view wants to be.
+ * @param measureSpec Constraints imposed by the parent.
+ * @param childMeasuredState Size information bit mask for the view's
+ * children.
* @return Size information bit mask as defined by
- * {@link #MEASURED_SIZE_MASK} and {@link #MEASURED_STATE_TOO_SMALL}.
+ * {@link #MEASURED_SIZE_MASK} and
+ * {@link #MEASURED_STATE_TOO_SMALL}.
*/
public static int resolveSizeAndState(int size, int measureSpec, int childMeasuredState) {
- int result = size;
- int specMode = MeasureSpec.getMode(measureSpec);
- int specSize = MeasureSpec.getSize(measureSpec);
+ final int specMode = MeasureSpec.getMode(measureSpec);
+ final int specSize = MeasureSpec.getSize(measureSpec);
+ final int result;
switch (specMode) {
- case MeasureSpec.UNSPECIFIED:
- result = size;
- break;
- case MeasureSpec.AT_MOST:
- if (specSize < size) {
- result = specSize | MEASURED_STATE_TOO_SMALL;
- } else {
+ case MeasureSpec.AT_MOST:
+ if (specSize < size) {
+ result = specSize | MEASURED_STATE_TOO_SMALL;
+ } else {
+ result = size;
+ }
+ break;
+ case MeasureSpec.EXACTLY:
+ result = specSize;
+ break;
+ case MeasureSpec.UNSPECIFIED:
+ default:
result = size;
- }
- break;
- case MeasureSpec.EXACTLY:
- result = specSize;
- break;
}
- return result | (childMeasuredState&MEASURED_STATE_MASK);
+ return result | (childMeasuredState & MEASURED_STATE_MASK);
}
/**
@@ -18300,7 +18295,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
* appearance as the given View. The default also positions the center of the drag shadow
* directly under the touch point. If no View is provided (the constructor with no parameters
* is used), and {@link #onProvideShadowMetrics(Point,Point) onProvideShadowMetrics()} and
- * {@link #onDrawShadow(Canvas) onDrawShadow()} are not overriden, then the
+ * {@link #onDrawShadow(Canvas) onDrawShadow()} are not overridden, then the
* default is an invisible drag shadow.
* <p>
* You are not required to use the View you provide to the constructor as the basis of the
diff --git a/core/java/android/view/ViewGroup.java b/core/java/android/view/ViewGroup.java
index 0d509e7..ee9845f 100644
--- a/core/java/android/view/ViewGroup.java
+++ b/core/java/android/view/ViewGroup.java
@@ -774,8 +774,10 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
* @see #onRequestSendAccessibilityEvent(View, AccessibilityEvent)
*
* Note: Called from the default {@link View.AccessibilityDelegate}.
+ *
+ * @hide
*/
- boolean onRequestSendAccessibilityEventInternal(View child, AccessibilityEvent event) {
+ public boolean onRequestSendAccessibilityEventInternal(View child, AccessibilityEvent event) {
return true;
}
@@ -2846,8 +2848,9 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
}
}
+ /** @hide */
@Override
- boolean dispatchPopulateAccessibilityEventInternal(AccessibilityEvent event) {
+ public boolean dispatchPopulateAccessibilityEventInternal(AccessibilityEvent event) {
boolean handled = false;
if (includeForAccessibility()) {
handled = super.dispatchPopulateAccessibilityEventInternal(event);
@@ -2874,8 +2877,9 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
return false;
}
+ /** @hide */
@Override
- void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) {
+ public void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) {
super.onInitializeAccessibilityNodeInfoInternal(info);
if (mAttachInfo != null) {
final ArrayList<View> childrenForAccessibility = mAttachInfo.mTempArrayList;
@@ -2890,8 +2894,9 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
}
}
+ /** @hide */
@Override
- void onInitializeAccessibilityEventInternal(AccessibilityEvent event) {
+ public void onInitializeAccessibilityEventInternal(AccessibilityEvent event) {
super.onInitializeAccessibilityEventInternal(event);
event.setClassName(ViewGroup.class.getName());
}
diff --git a/core/java/android/view/ViewStub.java b/core/java/android/view/ViewStub.java
index d68a860..9f9ed5b 100644
--- a/core/java/android/view/ViewStub.java
+++ b/core/java/android/view/ViewStub.java
@@ -69,8 +69,8 @@ import java.lang.ref.WeakReference;
*/
@RemoteView
public final class ViewStub extends View {
- private int mLayoutResource = 0;
private int mInflatedId;
+ private int mLayoutResource;
private WeakReference<View> mInflatedViewRef;
@@ -78,7 +78,7 @@ public final class ViewStub extends View {
private OnInflateListener mInflateListener;
public ViewStub(Context context) {
- initialize(context);
+ this(context, 0);
}
/**
@@ -88,38 +88,29 @@ public final class ViewStub extends View {
* @param layoutResource The reference to a layout resource that will be inflated.
*/
public ViewStub(Context context, int layoutResource) {
+ this(context, null);
+
mLayoutResource = layoutResource;
- initialize(context);
}
public ViewStub(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
- @SuppressWarnings({"UnusedDeclaration"})
public ViewStub(Context context, AttributeSet attrs, int defStyleAttr) {
this(context, attrs, defStyleAttr, 0);
}
public ViewStub(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
- TypedArray a = context.obtainStyledAttributes(
- attrs, com.android.internal.R.styleable.ViewStub, defStyleAttr, defStyleRes);
+ super(context);
+ final TypedArray a = context.obtainStyledAttributes(attrs,
+ R.styleable.ViewStub, defStyleAttr, defStyleRes);
mInflatedId = a.getResourceId(R.styleable.ViewStub_inflatedId, NO_ID);
mLayoutResource = a.getResourceId(R.styleable.ViewStub_layout, 0);
-
- a.recycle();
-
- a = context.obtainStyledAttributes(
- attrs, com.android.internal.R.styleable.View, defStyleAttr, defStyleRes);
- mID = a.getResourceId(R.styleable.View_id, NO_ID);
+ mID = a.getResourceId(R.styleable.ViewStub_id, NO_ID);
a.recycle();
- initialize(context);
- }
-
- private void initialize(Context context) {
- mContext = context;
setVisibility(GONE);
setWillNotDraw(true);
}
diff --git a/core/java/android/view/WindowManagerGlobal.java b/core/java/android/view/WindowManagerGlobal.java
index a14c766..ed17e3f 100644
--- a/core/java/android/view/WindowManagerGlobal.java
+++ b/core/java/android/view/WindowManagerGlobal.java
@@ -213,15 +213,15 @@ public final class WindowManagerGlobal {
throw new IllegalArgumentException("Params must be WindowManager.LayoutParams");
}
- final WindowManager.LayoutParams wparams = (WindowManager.LayoutParams)params;
+ final WindowManager.LayoutParams wparams = (WindowManager.LayoutParams) params;
if (parentWindow != null) {
parentWindow.adjustLayoutParamsForSubWindow(wparams);
- } else {
+ } else if (ActivityManager.isHighEndGfx()) {
// If there's no parent and we're running on L or above (or in the
// system context), assume we want hardware acceleration.
final Context context = view.getContext();
- if (context != null
- && context.getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.LOLLIPOP) {
+ if (context != null && context.getApplicationInfo().targetSdkVersion
+ >= Build.VERSION_CODES.LOLLIPOP) {
wparams.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
}
}
diff --git a/core/java/android/view/inputmethod/InputMethodSubtypeArray.java b/core/java/android/view/inputmethod/InputMethodSubtypeArray.java
index 5bef71f..3ff099a 100644
--- a/core/java/android/view/inputmethod/InputMethodSubtypeArray.java
+++ b/core/java/android/view/inputmethod/InputMethodSubtypeArray.java
@@ -203,43 +203,20 @@ public class InputMethodSubtypeArray {
}
private static byte[] compress(final byte[] data) {
- ByteArrayOutputStream resultStream = null;
- GZIPOutputStream zipper = null;
- try {
- resultStream = new ByteArrayOutputStream();
- zipper = new GZIPOutputStream(resultStream);
+ try (final ByteArrayOutputStream resultStream = new ByteArrayOutputStream();
+ final GZIPOutputStream zipper = new GZIPOutputStream(resultStream)) {
zipper.write(data);
- } catch(IOException e) {
+ zipper.finish();
+ return resultStream.toByteArray();
+ } catch(Exception e) {
+ Slog.e(TAG, "Failed to compress the data.", e);
return null;
- } finally {
- try {
- if (zipper != null) {
- zipper.close();
- }
- } catch (IOException e) {
- zipper = null;
- Slog.e(TAG, "Failed to close the stream.", e);
- // swallowed, not propagated back to the caller
- }
- try {
- if (resultStream != null) {
- resultStream.close();
- }
- } catch (IOException e) {
- resultStream = null;
- Slog.e(TAG, "Failed to close the stream.", e);
- // swallowed, not propagated back to the caller
- }
}
- return resultStream != null ? resultStream.toByteArray() : null;
}
private static byte[] decompress(final byte[] data, final int expectedSize) {
- ByteArrayInputStream inputStream = null;
- GZIPInputStream unzipper = null;
- try {
- inputStream = new ByteArrayInputStream(data);
- unzipper = new GZIPInputStream(inputStream);
+ try (final ByteArrayInputStream inputStream = new ByteArrayInputStream(data);
+ final GZIPInputStream unzipper = new GZIPInputStream(inputStream)) {
final byte [] result = new byte[expectedSize];
int totalReadBytes = 0;
while (totalReadBytes < result.length) {
@@ -254,25 +231,9 @@ public class InputMethodSubtypeArray {
return null;
}
return result;
- } catch(IOException e) {
+ } catch(Exception e) {
+ Slog.e(TAG, "Failed to decompress the data.", e);
return null;
- } finally {
- try {
- if (unzipper != null) {
- unzipper.close();
- }
- } catch (IOException e) {
- Slog.e(TAG, "Failed to close the stream.", e);
- // swallowed, not propagated back to the caller
- }
- try {
- if (inputStream != null) {
- inputStream.close();
- }
- } catch (IOException e) {
- Slog.e(TAG, "Failed to close the stream.", e);
- // swallowed, not propagated back to the caller
- }
}
}
}
diff --git a/core/java/android/webkit/CookieManager.java b/core/java/android/webkit/CookieManager.java
index eca96f9..6d5fac1 100644
--- a/core/java/android/webkit/CookieManager.java
+++ b/core/java/android/webkit/CookieManager.java
@@ -31,10 +31,7 @@ public abstract class CookieManager {
}
/**
- * Gets the singleton CookieManager instance. If this method is used
- * before the application instantiates a {@link WebView} instance,
- * {@link CookieSyncManager#createInstance CookieSyncManager.createInstance(Context)}
- * must be called first.
+ * Gets the singleton CookieManager instance.
*
* @return the singleton CookieManager instance
*/
diff --git a/core/java/android/webkit/WebChromeClient.java b/core/java/android/webkit/WebChromeClient.java
index 768dc9f..4737e9b 100644
--- a/core/java/android/webkit/WebChromeClient.java
+++ b/core/java/android/webkit/WebChromeClient.java
@@ -70,13 +70,14 @@ public class WebChromeClient {
}
/**
- * Notify the host application that the current page would
- * like to show a custom View. This is used for Fullscreen
- * video playback; see "HTML5 Video support" documentation on
+ * Notify the host application that the current page has entered full
+ * screen mode. The host application must show the custom View which
+ * contains the web contents &mdash; video or other HTML content &mdash;
+ * in full screen mode. Also see "Full screen support" documentation on
* {@link WebView}.
* @param view is the View object to be shown.
- * @param callback is the callback to be invoked if and when the view
- * is dismissed.
+ * @param callback invoke this callback to request the page to exit
+ * full screen mode.
*/
public void onShowCustomView(View view, CustomViewCallback callback) {};
@@ -96,8 +97,10 @@ public class WebChromeClient {
CustomViewCallback callback) {};
/**
- * Notify the host application that the current page would
- * like to hide its custom view.
+ * Notify the host application that the current page has exited full
+ * screen mode. The host application must hide the custom View, ie. the
+ * View passed to {@link #onShowCustomView} when the content entered fullscreen.
+ * Also see "Full screen support" documentation on {@link WebView}.
*/
public void onHideCustomView() {}
@@ -377,10 +380,9 @@ public class WebChromeClient {
}
/**
- * When the user starts to playback a video element, it may take time for enough
- * data to be buffered before the first frames can be rendered. While this buffering
- * is taking place, the ChromeClient can use this function to provide a View to be
- * displayed. For example, the ChromeClient could show a spinner animation.
+ * Obtains a View to be displayed while buffering of full screen video is taking
+ * place. The host application can override this method to provide a View
+ * containing a spinner or similar.
*
* @return View The View to be displayed whilst the video is loading.
*/
diff --git a/core/java/android/webkit/WebResourceResponse.java b/core/java/android/webkit/WebResourceResponse.java
index ad6e9aa..f487a4e 100644
--- a/core/java/android/webkit/WebResourceResponse.java
+++ b/core/java/android/webkit/WebResourceResponse.java
@@ -17,6 +17,7 @@
package android.webkit;
import java.io.InputStream;
+import java.io.StringBufferInputStream;
import java.util.Map;
/**
@@ -40,13 +41,14 @@ public class WebResourceResponse {
*
* @param mimeType the resource response's MIME type, for example text/html
* @param encoding the resource response's encoding
- * @param data the input stream that provides the resource response's data
+ * @param data the input stream that provides the resource response's data. Must not be a
+ * StringBufferInputStream.
*/
public WebResourceResponse(String mimeType, String encoding,
InputStream data) {
mMimeType = mimeType;
mEncoding = encoding;
- mInputStream = data;
+ setData(data);
}
/**
@@ -62,7 +64,8 @@ public class WebResourceResponse {
* and not empty.
* @param responseHeaders the resource response's headers represented as a mapping of header
* name -> header value.
- * @param data the input stream that provides the resource response's data
+ * @param data the input stream that provides the resource response's data. Must not be a
+ * StringBufferInputStream.
*/
public WebResourceResponse(String mimeType, String encoding, int statusCode,
String reasonPhrase, Map<String, String> responseHeaders, InputStream data) {
@@ -178,9 +181,16 @@ public class WebResourceResponse {
* Sets the input stream that provides the resource response's data. Callers
* must implement {@link InputStream#read(byte[]) InputStream.read(byte[])}.
*
- * @param data the input stream that provides the resource response's data
+ * @param data the input stream that provides the resource response's data. Must not be a
+ * StringBufferInputStream.
*/
public void setData(InputStream data) {
+ // If data is (or is a subclass of) StringBufferInputStream
+ if (data != null && StringBufferInputStream.class.isAssignableFrom(data.getClass())) {
+ throw new IllegalArgumentException("StringBufferInputStream is deprecated and must " +
+ "not be passed to a WebResourceResponse");
+ }
+
mInputStream = data;
}
diff --git a/core/java/android/webkit/WebView.java b/core/java/android/webkit/WebView.java
index bab1f3b..4a7cc6d 100644
--- a/core/java/android/webkit/WebView.java
+++ b/core/java/android/webkit/WebView.java
@@ -233,12 +233,48 @@ import java.util.Map;
*
* <h3>HTML5 Video support</h3>
*
- * <p>In order to support inline HTML5 video in your application, you need to have hardware
- * acceleration turned on, and set a {@link android.webkit.WebChromeClient}. For full screen support,
- * implementations of {@link WebChromeClient#onShowCustomView(View, WebChromeClient.CustomViewCallback)}
- * and {@link WebChromeClient#onHideCustomView()} are required,
- * {@link WebChromeClient#getVideoLoadingProgressView()} is optional.
+ * <p>In order to support inline HTML5 video in your application you need to have hardware
+ * acceleration turned on.
* </p>
+ *
+ * <h3>Full screen support</h3>
+ *
+ * <p>In order to support full screen &mdash; for video or other HTML content &mdash; you need to set a
+ * {@link android.webkit.WebChromeClient} and implement both
+ * {@link WebChromeClient#onShowCustomView(View, WebChromeClient.CustomViewCallback)}
+ * and {@link WebChromeClient#onHideCustomView()}. If the implementation of either of these two methods is
+ * missing then the web contents will not be allowed to enter full screen. Optionally you can implement
+ * {@link WebChromeClient#getVideoLoadingProgressView()} to customize the View displayed whilst a video
+ * is loading.
+ * </p>
+ *
+ * <h3>Layout size</h3>
+ * <p>
+ * It is recommended to set the WebView layout height to a fixed value or to
+ * {@link android.view.ViewGroup.LayoutParams#MATCH_PARENT} instead of using
+ * {@link android.view.ViewGroup.LayoutParams#WRAP_CONTENT}.
+ * When using {@link android.view.ViewGroup.LayoutParams#MATCH_PARENT}
+ * for the height none of the WebView's parents should use a
+ * {@link android.view.ViewGroup.LayoutParams#WRAP_CONTENT} layout height since that could result in
+ * incorrect sizing of the views.
+ * </p>
+ *
+ * <p>Setting the WebView's height to {@link android.view.ViewGroup.LayoutParams#WRAP_CONTENT}
+ * enables the following behaviors:
+ * <ul>
+ * <li>The HTML body layout height is set to a fixed value. This means that elements with a height
+ * relative to the HTML body may not be sized correctly. </li>
+ * <li>For applications targetting {@link android.os.Build.VERSION_CODES#KITKAT} and earlier SDKs the
+ * HTML viewport meta tag will be ignored in order to preserve backwards compatibility. </li>
+ * </ul>
+ * </p>
+ *
+ * <p>
+ * Using a layout width of {@link android.view.ViewGroup.LayoutParams#WRAP_CONTENT} is not
+ * supported. If such a width is used the WebView will attempt to use the width of the parent
+ * instead.
+ * </p>
+ *
*/
// Implementation notes.
// The WebView is a thin API class that delegates its public API to a backend WebViewProvider
@@ -2043,7 +2079,7 @@ public class WebView extends AbsoluteLayout
}
public boolean super_performAccessibilityAction(int action, Bundle arguments) {
- return WebView.super.performAccessibilityAction(action, arguments);
+ return WebView.super.performAccessibilityActionInternal(action, arguments);
}
public boolean super_performLongClick() {
@@ -2351,22 +2387,25 @@ public class WebView extends AbsoluteLayout
return mProvider.getViewDelegate().shouldDelayChildPressedState();
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
- super.onInitializeAccessibilityNodeInfo(info);
+ public void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) {
+ super.onInitializeAccessibilityNodeInfoInternal(info);
info.setClassName(WebView.class.getName());
mProvider.getViewDelegate().onInitializeAccessibilityNodeInfo(info);
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
- super.onInitializeAccessibilityEvent(event);
+ public void onInitializeAccessibilityEventInternal(AccessibilityEvent event) {
+ super.onInitializeAccessibilityEventInternal(event);
event.setClassName(WebView.class.getName());
mProvider.getViewDelegate().onInitializeAccessibilityEvent(event);
}
+ /** @hide */
@Override
- public boolean performAccessibilityAction(int action, Bundle arguments) {
+ public boolean performAccessibilityActionInternal(int action, Bundle arguments) {
return mProvider.getViewDelegate().performAccessibilityAction(action, arguments);
}
diff --git a/core/java/android/webkit/WebViewFactory.java b/core/java/android/webkit/WebViewFactory.java
index 474ef42..cafe053 100644
--- a/core/java/android/webkit/WebViewFactory.java
+++ b/core/java/android/webkit/WebViewFactory.java
@@ -117,12 +117,8 @@ public final class WebViewFactory {
StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
Trace.traceBegin(Trace.TRACE_TAG_WEBVIEW, "providerClass.newInstance()");
try {
- try {
- sProviderInstance = providerClass.getConstructor(WebViewDelegate.class)
- .newInstance(new WebViewDelegate());
- } catch (Exception e) {
- sProviderInstance = providerClass.newInstance();
- }
+ sProviderInstance = providerClass.getConstructor(WebViewDelegate.class)
+ .newInstance(new WebViewDelegate());
if (DEBUG) Log.v(LOGTAG, "Loaded provider: " + sProviderInstance);
return sProviderInstance;
} catch (Exception e) {
diff --git a/core/java/android/widget/AbsListView.java b/core/java/android/widget/AbsListView.java
index 1e269a3..7ea3265 100644
--- a/core/java/android/widget/AbsListView.java
+++ b/core/java/android/widget/AbsListView.java
@@ -1466,8 +1466,9 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
onScrollChanged(0, 0, 0, 0); // dummy values, View's implementation does not use these.
}
+ /** @hide */
@Override
- public void sendAccessibilityEvent(int eventType) {
+ public void sendAccessibilityEventInternal(int eventType) {
// Since this class calls onScrollChanged even if the mFirstPosition and the
// child count have not changed we will avoid sending duplicate accessibility
// events.
@@ -1482,18 +1483,20 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
mLastAccessibilityScrollEventToIndex = lastVisiblePosition;
}
}
- super.sendAccessibilityEvent(eventType);
+ super.sendAccessibilityEventInternal(eventType);
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
- super.onInitializeAccessibilityEvent(event);
+ public void onInitializeAccessibilityEventInternal(AccessibilityEvent event) {
+ super.onInitializeAccessibilityEventInternal(event);
event.setClassName(AbsListView.class.getName());
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
- super.onInitializeAccessibilityNodeInfo(info);
+ public void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) {
+ super.onInitializeAccessibilityNodeInfoInternal(info);
info.setClassName(AbsListView.class.getName());
if (isEnabled()) {
if (canScrollUp()) {
@@ -1522,9 +1525,10 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
}
}
+ /** @hide */
@Override
- public boolean performAccessibilityAction(int action, Bundle arguments) {
- if (super.performAccessibilityAction(action, arguments)) {
+ public boolean performAccessibilityActionInternal(int action, Bundle arguments) {
+ if (super.performAccessibilityActionInternal(action, arguments)) {
return true;
}
switch (action) {
diff --git a/core/java/android/widget/AbsSeekBar.java b/core/java/android/widget/AbsSeekBar.java
index a3ce808..1f7be63 100644
--- a/core/java/android/widget/AbsSeekBar.java
+++ b/core/java/android/widget/AbsSeekBar.java
@@ -715,15 +715,17 @@ public abstract class AbsSeekBar extends ProgressBar {
return super.onKeyDown(keyCode, event);
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
- super.onInitializeAccessibilityEvent(event);
+ public void onInitializeAccessibilityEventInternal(AccessibilityEvent event) {
+ super.onInitializeAccessibilityEventInternal(event);
event.setClassName(AbsSeekBar.class.getName());
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
- super.onInitializeAccessibilityNodeInfo(info);
+ public void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) {
+ super.onInitializeAccessibilityNodeInfoInternal(info);
info.setClassName(AbsSeekBar.class.getName());
if (isEnabled()) {
@@ -737,9 +739,10 @@ public abstract class AbsSeekBar extends ProgressBar {
}
}
+ /** @hide */
@Override
- public boolean performAccessibilityAction(int action, Bundle arguments) {
- if (super.performAccessibilityAction(action, arguments)) {
+ public boolean performAccessibilityActionInternal(int action, Bundle arguments) {
+ if (super.performAccessibilityActionInternal(action, arguments)) {
return true;
}
if (!isEnabled()) {
diff --git a/core/java/android/widget/AbsSpinner.java b/core/java/android/widget/AbsSpinner.java
index 6a4ad75..5d8d48f 100644
--- a/core/java/android/widget/AbsSpinner.java
+++ b/core/java/android/widget/AbsSpinner.java
@@ -73,13 +73,12 @@ public abstract class AbsSpinner extends AdapterView<SpinnerAdapter> {
initAbsSpinner();
final TypedArray a = context.obtainStyledAttributes(
- attrs, com.android.internal.R.styleable.AbsSpinner, defStyleAttr, defStyleRes);
+ attrs, R.styleable.AbsSpinner, defStyleAttr, defStyleRes);
- CharSequence[] entries = a.getTextArray(R.styleable.AbsSpinner_entries);
+ final CharSequence[] entries = a.getTextArray(R.styleable.AbsSpinner_entries);
if (entries != null) {
- ArrayAdapter<CharSequence> adapter =
- new ArrayAdapter<CharSequence>(context,
- R.layout.simple_spinner_item, entries);
+ final ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>(
+ context, R.layout.simple_spinner_item, entries);
adapter.setDropDownViewResource(R.layout.simple_spinner_dropdown_item);
setAdapter(adapter);
}
@@ -471,15 +470,17 @@ public abstract class AbsSpinner extends AdapterView<SpinnerAdapter> {
}
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
- super.onInitializeAccessibilityEvent(event);
+ public void onInitializeAccessibilityEventInternal(AccessibilityEvent event) {
+ super.onInitializeAccessibilityEventInternal(event);
event.setClassName(AbsSpinner.class.getName());
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
- super.onInitializeAccessibilityNodeInfo(info);
+ public void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) {
+ super.onInitializeAccessibilityNodeInfoInternal(info);
info.setClassName(AbsSpinner.class.getName());
}
}
diff --git a/core/java/android/widget/ActionMenuPresenter.java b/core/java/android/widget/ActionMenuPresenter.java
index 18f15a0..94827dd 100644
--- a/core/java/android/widget/ActionMenuPresenter.java
+++ b/core/java/android/widget/ActionMenuPresenter.java
@@ -645,9 +645,10 @@ public class ActionMenuPresenter extends BaseMenuPresenter
return false;
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
- super.onInitializeAccessibilityNodeInfo(info);
+ public void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) {
+ super.onInitializeAccessibilityNodeInfoInternal(info);
info.setCanOpenPopup(true);
}
diff --git a/core/java/android/widget/ActionMenuView.java b/core/java/android/widget/ActionMenuView.java
index 0a8a01f..403e4ac 100644
--- a/core/java/android/widget/ActionMenuView.java
+++ b/core/java/android/widget/ActionMenuView.java
@@ -116,11 +116,14 @@ public class ActionMenuView extends LinearLayout implements MenuBuilder.ItemInvo
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
- mPresenter.updateMenuView(false);
- if (mPresenter != null && mPresenter.isOverflowMenuShowing()) {
- mPresenter.hideOverflowMenu();
- mPresenter.showOverflowMenu();
+ if (mPresenter != null) {
+ mPresenter.updateMenuView(false);
+
+ if (mPresenter.isOverflowMenuShowing()) {
+ mPresenter.hideOverflowMenu();
+ mPresenter.showOverflowMenu();
+ }
}
}
@@ -700,7 +703,8 @@ public class ActionMenuView extends LinearLayout implements MenuBuilder.ItemInvo
return result;
}
- public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
+ /** @hide */
+ public boolean dispatchPopulateAccessibilityEventInternal(AccessibilityEvent event) {
return false;
}
diff --git a/core/java/android/widget/AdapterView.java b/core/java/android/widget/AdapterView.java
index 5e2394c..428b6ce 100644
--- a/core/java/android/widget/AdapterView.java
+++ b/core/java/android/widget/AdapterView.java
@@ -929,8 +929,9 @@ public abstract class AdapterView<T extends Adapter> extends ViewGroup {
}
}
+ /** @hide */
@Override
- public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
+ public boolean dispatchPopulateAccessibilityEventInternal(AccessibilityEvent event) {
View selectedView = getSelectedView();
if (selectedView != null && selectedView.getVisibility() == VISIBLE
&& selectedView.dispatchPopulateAccessibilityEvent(event)) {
@@ -939,9 +940,10 @@ public abstract class AdapterView<T extends Adapter> extends ViewGroup {
return false;
}
+ /** @hide */
@Override
- public boolean onRequestSendAccessibilityEvent(View child, AccessibilityEvent event) {
- if (super.onRequestSendAccessibilityEvent(child, event)) {
+ public boolean onRequestSendAccessibilityEventInternal(View child, AccessibilityEvent event) {
+ if (super.onRequestSendAccessibilityEventInternal(child, event)) {
// Add a record for ourselves as well.
AccessibilityEvent record = AccessibilityEvent.obtain();
onInitializeAccessibilityEvent(record);
@@ -953,9 +955,10 @@ public abstract class AdapterView<T extends Adapter> extends ViewGroup {
return false;
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
- super.onInitializeAccessibilityNodeInfo(info);
+ public void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) {
+ super.onInitializeAccessibilityNodeInfoInternal(info);
info.setClassName(AdapterView.class.getName());
info.setScrollable(isScrollableForAccessibility());
View selectedView = getSelectedView();
@@ -964,9 +967,10 @@ public abstract class AdapterView<T extends Adapter> extends ViewGroup {
}
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
- super.onInitializeAccessibilityEvent(event);
+ public void onInitializeAccessibilityEventInternal(AccessibilityEvent event) {
+ super.onInitializeAccessibilityEventInternal(event);
event.setClassName(AdapterView.class.getName());
event.setScrollable(isScrollableForAccessibility());
View selectedView = getSelectedView();
diff --git a/core/java/android/widget/AdapterViewAnimator.java b/core/java/android/widget/AdapterViewAnimator.java
index 1bc2f4b..96eb0e2 100644
--- a/core/java/android/widget/AdapterViewAnimator.java
+++ b/core/java/android/widget/AdapterViewAnimator.java
@@ -1084,15 +1084,17 @@ public abstract class AdapterViewAnimator extends AdapterView<Adapter>
public void fyiWillBeAdvancedByHostKThx() {
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
- super.onInitializeAccessibilityEvent(event);
+ public void onInitializeAccessibilityEventInternal(AccessibilityEvent event) {
+ super.onInitializeAccessibilityEventInternal(event);
event.setClassName(AdapterViewAnimator.class.getName());
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
- super.onInitializeAccessibilityNodeInfo(info);
+ public void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) {
+ super.onInitializeAccessibilityNodeInfoInternal(info);
info.setClassName(AdapterViewAnimator.class.getName());
}
}
diff --git a/core/java/android/widget/AdapterViewFlipper.java b/core/java/android/widget/AdapterViewFlipper.java
index 285dee8..a7ba617 100644
--- a/core/java/android/widget/AdapterViewFlipper.java
+++ b/core/java/android/widget/AdapterViewFlipper.java
@@ -304,15 +304,17 @@ public class AdapterViewFlipper extends AdapterViewAnimator {
updateRunning(false);
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
- super.onInitializeAccessibilityEvent(event);
+ public void onInitializeAccessibilityEventInternal(AccessibilityEvent event) {
+ super.onInitializeAccessibilityEventInternal(event);
event.setClassName(AdapterViewFlipper.class.getName());
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
- super.onInitializeAccessibilityNodeInfo(info);
+ public void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) {
+ super.onInitializeAccessibilityNodeInfoInternal(info);
info.setClassName(AdapterViewFlipper.class.getName());
}
}
diff --git a/core/java/android/widget/ArrayAdapter.java b/core/java/android/widget/ArrayAdapter.java
index 97926a7..aff5e29 100644
--- a/core/java/android/widget/ArrayAdapter.java
+++ b/core/java/android/widget/ArrayAdapter.java
@@ -17,7 +17,9 @@
package android.widget;
import android.content.Context;
+import android.content.res.Resources;
import android.util.Log;
+import android.view.ContextThemeWrapper;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -44,7 +46,8 @@ import java.util.List;
* or to have some of data besides toString() results fill the views,
* override {@link #getView(int, View, ViewGroup)} to return the type of view you want.
*/
-public class ArrayAdapter<T> extends BaseAdapter implements Filterable {
+public class ArrayAdapter<T> extends BaseAdapter implements Filterable,
+ Spinner.ThemedSpinnerAdapter {
/**
* Contains the list of objects that represent the data of this ArrayAdapter.
* The content of this list is referred to as "the array" in the documentation.
@@ -93,6 +96,9 @@ public class ArrayAdapter<T> extends BaseAdapter implements Filterable {
private LayoutInflater mInflater;
+ /** Layout inflater used for {@link #getDropDownView(int, View, ViewGroup)}. */
+ private LayoutInflater mDropDownInflater;
+
/**
* Constructor
*
@@ -101,7 +107,7 @@ public class ArrayAdapter<T> extends BaseAdapter implements Filterable {
* instantiating views.
*/
public ArrayAdapter(Context context, int resource) {
- init(context, resource, 0, new ArrayList<T>());
+ this(context, resource, 0, new ArrayList<T>());
}
/**
@@ -113,7 +119,7 @@ public class ArrayAdapter<T> extends BaseAdapter implements Filterable {
* @param textViewResourceId The id of the TextView within the layout resource to be populated
*/
public ArrayAdapter(Context context, int resource, int textViewResourceId) {
- init(context, resource, textViewResourceId, new ArrayList<T>());
+ this(context, resource, textViewResourceId, new ArrayList<T>());
}
/**
@@ -125,7 +131,7 @@ public class ArrayAdapter<T> extends BaseAdapter implements Filterable {
* @param objects The objects to represent in the ListView.
*/
public ArrayAdapter(Context context, int resource, T[] objects) {
- init(context, resource, 0, Arrays.asList(objects));
+ this(context, resource, 0, Arrays.asList(objects));
}
/**
@@ -138,7 +144,7 @@ public class ArrayAdapter<T> extends BaseAdapter implements Filterable {
* @param objects The objects to represent in the ListView.
*/
public ArrayAdapter(Context context, int resource, int textViewResourceId, T[] objects) {
- init(context, resource, textViewResourceId, Arrays.asList(objects));
+ this(context, resource, textViewResourceId, Arrays.asList(objects));
}
/**
@@ -150,7 +156,7 @@ public class ArrayAdapter<T> extends BaseAdapter implements Filterable {
* @param objects The objects to represent in the ListView.
*/
public ArrayAdapter(Context context, int resource, List<T> objects) {
- init(context, resource, 0, objects);
+ this(context, resource, 0, objects);
}
/**
@@ -163,7 +169,11 @@ public class ArrayAdapter<T> extends BaseAdapter implements Filterable {
* @param objects The objects to represent in the ListView.
*/
public ArrayAdapter(Context context, int resource, int textViewResourceId, List<T> objects) {
- init(context, resource, textViewResourceId, objects);
+ mContext = context;
+ mInflater = LayoutInflater.from(context);
+ mResource = mDropDownResource = resource;
+ mObjects = objects;
+ mFieldId = textViewResourceId;
}
/**
@@ -305,14 +315,6 @@ public class ArrayAdapter<T> extends BaseAdapter implements Filterable {
mNotifyOnChange = notifyOnChange;
}
- private void init(Context context, int resource, int textViewResourceId, List<T> objects) {
- mContext = context;
- mInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
- mResource = mDropDownResource = resource;
- mObjects = objects;
- mFieldId = textViewResourceId;
- }
-
/**
* Returns the context associated with this array adapter. The context is used
* to create views from the resource passed to the constructor.
@@ -359,16 +361,16 @@ public class ArrayAdapter<T> extends BaseAdapter implements Filterable {
* {@inheritDoc}
*/
public View getView(int position, View convertView, ViewGroup parent) {
- return createViewFromResource(position, convertView, parent, mResource);
+ return createViewFromResource(mInflater, position, convertView, parent, mResource);
}
- private View createViewFromResource(int position, View convertView, ViewGroup parent,
- int resource) {
+ private View createViewFromResource(LayoutInflater inflater, int position, View convertView,
+ ViewGroup parent, int resource) {
View view;
TextView text;
if (convertView == null) {
- view = mInflater.inflate(resource, parent, false);
+ view = inflater.inflate(resource, parent, false);
} else {
view = convertView;
}
@@ -408,11 +410,40 @@ public class ArrayAdapter<T> extends BaseAdapter implements Filterable {
}
/**
+ * Sets the {@link Resources.Theme} against which drop-down views are
+ * inflated.
+ * <p>
+ * By default, drop-down views are inflated against the theme of the
+ * {@link Context} passed to the adapter's constructor.
+ *
+ * @param theme the theme against which to inflate drop-down views or
+ * {@code null} to use the theme from the adapter's context
+ * @see #getDropDownView(int, View, ViewGroup)
+ */
+ @Override
+ public void setDropDownViewTheme(Resources.Theme theme) {
+ if (theme == null) {
+ mDropDownInflater = null;
+ } else if (theme == mInflater.getContext().getTheme()) {
+ mDropDownInflater = mInflater;
+ } else {
+ final Context context = new ContextThemeWrapper(mContext, theme);
+ mDropDownInflater = LayoutInflater.from(context);
+ }
+ }
+
+ @Override
+ public Resources.Theme getDropDownViewTheme() {
+ return mDropDownInflater == null ? null : mDropDownInflater.getContext().getTheme();
+ }
+
+ /**
* {@inheritDoc}
*/
@Override
public View getDropDownView(int position, View convertView, ViewGroup parent) {
- return createViewFromResource(position, convertView, parent, mDropDownResource);
+ final LayoutInflater inflater = mDropDownInflater == null ? mInflater : mDropDownInflater;
+ return createViewFromResource(inflater, position, convertView, parent, mDropDownResource);
}
/**
diff --git a/core/java/android/widget/Button.java b/core/java/android/widget/Button.java
index 1663620..90d77f9 100644
--- a/core/java/android/widget/Button.java
+++ b/core/java/android/widget/Button.java
@@ -111,15 +111,17 @@ public class Button extends TextView {
super(context, attrs, defStyleAttr, defStyleRes);
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
- super.onInitializeAccessibilityEvent(event);
+ public void onInitializeAccessibilityEventInternal(AccessibilityEvent event) {
+ super.onInitializeAccessibilityEventInternal(event);
event.setClassName(Button.class.getName());
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
- super.onInitializeAccessibilityNodeInfo(info);
+ public void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) {
+ super.onInitializeAccessibilityNodeInfoInternal(info);
info.setClassName(Button.class.getName());
}
}
diff --git a/core/java/android/widget/CalendarView.java b/core/java/android/widget/CalendarView.java
index ed59ea6..d58da8f 100644
--- a/core/java/android/widget/CalendarView.java
+++ b/core/java/android/widget/CalendarView.java
@@ -501,13 +501,15 @@ public class CalendarView extends FrameLayout {
mDelegate.onConfigurationChanged(newConfig);
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
+ public void onInitializeAccessibilityEventInternal(AccessibilityEvent event) {
event.setClassName(CalendarView.class.getName());
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
+ public void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) {
info.setClassName(CalendarView.class.getName());
}
diff --git a/core/java/android/widget/CheckBox.java b/core/java/android/widget/CheckBox.java
index 71438c9..b1fb338 100644
--- a/core/java/android/widget/CheckBox.java
+++ b/core/java/android/widget/CheckBox.java
@@ -72,15 +72,17 @@ public class CheckBox extends CompoundButton {
super(context, attrs, defStyleAttr, defStyleRes);
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
- super.onInitializeAccessibilityEvent(event);
+ public void onInitializeAccessibilityEventInternal(AccessibilityEvent event) {
+ super.onInitializeAccessibilityEventInternal(event);
event.setClassName(CheckBox.class.getName());
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
- super.onInitializeAccessibilityNodeInfo(info);
+ public void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) {
+ super.onInitializeAccessibilityNodeInfoInternal(info);
info.setClassName(CheckBox.class.getName());
}
}
diff --git a/core/java/android/widget/CheckedTextView.java b/core/java/android/widget/CheckedTextView.java
index 69969a9..477862b 100644
--- a/core/java/android/widget/CheckedTextView.java
+++ b/core/java/android/widget/CheckedTextView.java
@@ -435,16 +435,18 @@ public class CheckedTextView extends TextView implements Checkable {
}
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
- super.onInitializeAccessibilityEvent(event);
+ public void onInitializeAccessibilityEventInternal(AccessibilityEvent event) {
+ super.onInitializeAccessibilityEventInternal(event);
event.setClassName(CheckedTextView.class.getName());
event.setChecked(mChecked);
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
- super.onInitializeAccessibilityNodeInfo(info);
+ public void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) {
+ super.onInitializeAccessibilityNodeInfoInternal(info);
info.setClassName(CheckedTextView.class.getName());
info.setCheckable(true);
info.setChecked(mChecked);
diff --git a/core/java/android/widget/Chronometer.java b/core/java/android/widget/Chronometer.java
index f94789d..05fc6a1 100644
--- a/core/java/android/widget/Chronometer.java
+++ b/core/java/android/widget/Chronometer.java
@@ -281,15 +281,17 @@ public class Chronometer extends TextView {
}
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
- super.onInitializeAccessibilityEvent(event);
+ public void onInitializeAccessibilityEventInternal(AccessibilityEvent event) {
+ super.onInitializeAccessibilityEventInternal(event);
event.setClassName(Chronometer.class.getName());
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
- super.onInitializeAccessibilityNodeInfo(info);
+ public void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) {
+ super.onInitializeAccessibilityNodeInfoInternal(info);
info.setClassName(Chronometer.class.getName());
}
}
diff --git a/core/java/android/widget/CompoundButton.java b/core/java/android/widget/CompoundButton.java
index 447ccc2..41a3915 100644
--- a/core/java/android/widget/CompoundButton.java
+++ b/core/java/android/widget/CompoundButton.java
@@ -324,16 +324,18 @@ public abstract class CompoundButton extends Button implements Checkable {
}
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
- super.onInitializeAccessibilityEvent(event);
+ public void onInitializeAccessibilityEventInternal(AccessibilityEvent event) {
+ super.onInitializeAccessibilityEventInternal(event);
event.setClassName(CompoundButton.class.getName());
event.setChecked(mChecked);
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
- super.onInitializeAccessibilityNodeInfo(info);
+ public void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) {
+ super.onInitializeAccessibilityNodeInfoInternal(info);
info.setClassName(CompoundButton.class.getName());
info.setCheckable(true);
info.setChecked(mChecked);
diff --git a/core/java/android/widget/CursorAdapter.java b/core/java/android/widget/CursorAdapter.java
index d4c5be0..8e318fd 100644
--- a/core/java/android/widget/CursorAdapter.java
+++ b/core/java/android/widget/CursorAdapter.java
@@ -17,11 +17,14 @@
package android.widget;
import android.content.Context;
+import android.content.res.Resources;
import android.database.ContentObserver;
import android.database.Cursor;
import android.database.DataSetObserver;
import android.os.Handler;
import android.util.Log;
+import android.view.ContextThemeWrapper;
+import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -35,7 +38,7 @@ import android.view.ViewGroup;
* columns.
*/
public abstract class CursorAdapter extends BaseAdapter implements Filterable,
- CursorFilter.CursorFilterClient {
+ CursorFilter.CursorFilterClient, Spinner.ThemedSpinnerAdapter {
/**
* This field should be made private, so it is hidden from the SDK.
* {@hide}
@@ -57,6 +60,11 @@ public abstract class CursorAdapter extends BaseAdapter implements Filterable,
*/
protected Context mContext;
/**
+ * Context used for {@link #getDropDownView(int, View, ViewGroup)}.
+ * {@hide}
+ */
+ protected Context mDropDownContext;
+ /**
* This field should be made private, so it is hidden from the SDK.
* {@hide}
*/
@@ -185,6 +193,33 @@ public abstract class CursorAdapter extends BaseAdapter implements Filterable,
}
/**
+ * Sets the {@link Resources.Theme} against which drop-down views are
+ * inflated.
+ * <p>
+ * By default, drop-down views are inflated against the theme of the
+ * {@link Context} passed to the adapter's constructor.
+ *
+ * @param theme the theme against which to inflate drop-down views or
+ * {@code null} to use the theme from the adapter's context
+ * @see #newDropDownView(Context, Cursor, ViewGroup)
+ */
+ @Override
+ public void setDropDownViewTheme(Resources.Theme theme) {
+ if (theme == null) {
+ mDropDownContext = null;
+ } else if (theme == mContext.getTheme()) {
+ mDropDownContext = mContext;
+ } else {
+ mDropDownContext = new ContextThemeWrapper(mContext, theme);
+ }
+ }
+
+ @Override
+ public Resources.Theme getDropDownViewTheme() {
+ return mDropDownContext == null ? null : mDropDownContext.getTheme();
+ }
+
+ /**
* Returns the cursor.
* @return the cursor.
*/
@@ -258,20 +293,21 @@ public abstract class CursorAdapter extends BaseAdapter implements Filterable,
@Override
public View getDropDownView(int position, View convertView, ViewGroup parent) {
if (mDataValid) {
+ final Context context = mDropDownContext == null ? mContext : mDropDownContext;
mCursor.moveToPosition(position);
- View v;
+ final View v;
if (convertView == null) {
- v = newDropDownView(mContext, mCursor, parent);
+ v = newDropDownView(context, mCursor, parent);
} else {
v = convertView;
}
- bindView(v, mContext, mCursor);
+ bindView(v, context, mCursor);
return v;
} else {
return null;
}
}
-
+
/**
* Makes a new view to hold the data pointed to by cursor.
* @param context Interface to application's global information
diff --git a/core/java/android/widget/DatePicker.java b/core/java/android/widget/DatePicker.java
index 0ca08e1..0f0cd2e 100644
--- a/core/java/android/widget/DatePicker.java
+++ b/core/java/android/widget/DatePicker.java
@@ -283,26 +283,30 @@ public class DatePicker extends FrameLayout {
return mDelegate.isEnabled();
}
+ /** @hide */
@Override
- public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
+ public boolean dispatchPopulateAccessibilityEventInternal(AccessibilityEvent event) {
return mDelegate.dispatchPopulateAccessibilityEvent(event);
}
+ /** @hide */
@Override
- public void onPopulateAccessibilityEvent(AccessibilityEvent event) {
- super.onPopulateAccessibilityEvent(event);
+ public void onPopulateAccessibilityEventInternal(AccessibilityEvent event) {
+ super.onPopulateAccessibilityEventInternal(event);
mDelegate.onPopulateAccessibilityEvent(event);
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
- super.onInitializeAccessibilityEvent(event);
+ public void onInitializeAccessibilityEventInternal(AccessibilityEvent event) {
+ super.onInitializeAccessibilityEventInternal(event);
mDelegate.onInitializeAccessibilityEvent(event);
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
- super.onInitializeAccessibilityNodeInfo(info);
+ public void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) {
+ super.onInitializeAccessibilityNodeInfoInternal(info);
mDelegate.onInitializeAccessibilityNodeInfo(info);
}
diff --git a/core/java/android/widget/DatePickerCalendarDelegate.java b/core/java/android/widget/DatePickerCalendarDelegate.java
index e75643ab..a3b834e 100644
--- a/core/java/android/widget/DatePickerCalendarDelegate.java
+++ b/core/java/android/widget/DatePickerCalendarDelegate.java
@@ -145,8 +145,8 @@ class DatePickerCalendarDelegate extends DatePicker.AbstractDatePickerDelegate i
// Use Theme attributes if possible
final int dayOfWeekTextAppearanceResId = a.getResourceId(
- R.styleable.DatePicker_dayOfWeekTextAppearance, -1);
- if (dayOfWeekTextAppearanceResId != -1) {
+ R.styleable.DatePicker_dayOfWeekTextAppearance, 0);
+ if (dayOfWeekTextAppearanceResId != 0) {
mDayOfWeekView.setTextAppearance(context, dayOfWeekTextAppearanceResId);
}
@@ -157,8 +157,8 @@ class DatePickerCalendarDelegate extends DatePicker.AbstractDatePickerDelegate i
final int headerSelectedTextColor = a.getColor(
R.styleable.DatePicker_headerSelectedTextColor, defaultHighlightColor);
final int monthTextAppearanceResId = a.getResourceId(
- R.styleable.DatePicker_headerMonthTextAppearance, -1);
- if (monthTextAppearanceResId != -1) {
+ R.styleable.DatePicker_headerMonthTextAppearance, 0);
+ if (monthTextAppearanceResId != 0) {
mHeaderMonthTextView.setTextAppearance(context, monthTextAppearanceResId);
}
mHeaderMonthTextView.setTextColor(ColorStateList.addFirstIfMissing(
@@ -166,18 +166,18 @@ class DatePickerCalendarDelegate extends DatePicker.AbstractDatePickerDelegate i
headerSelectedTextColor));
final int dayOfMonthTextAppearanceResId = a.getResourceId(
- R.styleable.DatePicker_headerDayOfMonthTextAppearance, -1);
- if (dayOfMonthTextAppearanceResId != -1) {
+ R.styleable.DatePicker_headerDayOfMonthTextAppearance, 0);
+ if (dayOfMonthTextAppearanceResId != 0) {
mHeaderDayOfMonthTextView.setTextAppearance(context, dayOfMonthTextAppearanceResId);
}
mHeaderDayOfMonthTextView.setTextColor(ColorStateList.addFirstIfMissing(
mHeaderDayOfMonthTextView.getTextColors(), R.attr.state_selected,
headerSelectedTextColor));
- final int yearTextAppearanceResId = a.getResourceId(
- R.styleable.DatePicker_headerYearTextAppearance, -1);
- if (yearTextAppearanceResId != -1) {
- mHeaderYearTextView.setTextAppearance(context, yearTextAppearanceResId);
+ final int headerYearTextAppearanceResId = a.getResourceId(
+ R.styleable.DatePicker_headerYearTextAppearance, 0);
+ if (headerYearTextAppearanceResId != 0) {
+ mHeaderYearTextView.setTextAppearance(context, headerYearTextAppearanceResId);
}
mHeaderYearTextView.setTextColor(ColorStateList.addFirstIfMissing(
mHeaderYearTextView.getTextColors(), R.attr.state_selected,
@@ -193,16 +193,23 @@ class DatePickerCalendarDelegate extends DatePicker.AbstractDatePickerDelegate i
mYearPickerView = new YearPickerView(mContext);
mYearPickerView.init(this);
- final int yearSelectedCircleColor = a.getColor(R.styleable.DatePicker_yearListSelectorColor,
- defaultHighlightColor);
- mYearPickerView.setYearSelectedCircleColor(yearSelectedCircleColor);
+ final ColorStateList yearBackgroundColor = a.getColorStateList(
+ R.styleable.DatePicker_yearListSelectorColor);
+ mYearPickerView.setYearBackgroundColor(yearBackgroundColor);
+
+ final int yearTextAppearanceResId = a.getResourceId(
+ R.styleable.DatePicker_yearListItemTextAppearance, 0);
+ if (yearTextAppearanceResId != 0) {
+ mYearPickerView.setYearTextAppearance(yearTextAppearanceResId);
+ }
final ColorStateList calendarTextColor = a.getColorStateList(
R.styleable.DatePicker_calendarTextColor);
- final int calendarSelectedTextColor = a.getColor(
- R.styleable.DatePicker_calendarSelectedTextColor, defaultHighlightColor);
- mDayPickerView.setCalendarTextColor(ColorStateList.addFirstIfMissing(
- calendarTextColor, R.attr.state_selected, calendarSelectedTextColor));
+ mDayPickerView.setCalendarTextColor(calendarTextColor);
+
+ final ColorStateList calendarDayBackgroundColor = a.getColorStateList(
+ R.styleable.DatePicker_calendarDayBackgroundColor);
+ mDayPickerView.setCalendarDayBackgroundColor(calendarDayBackgroundColor);
mDayPickerDescription = res.getString(R.string.day_picker_description);
mSelectDay = res.getString(R.string.select_day);
diff --git a/core/java/android/widget/DayPickerView.java b/core/java/android/widget/DayPickerView.java
index 7db3fb9..65af45d 100644
--- a/core/java/android/widget/DayPickerView.java
+++ b/core/java/android/widget/DayPickerView.java
@@ -305,6 +305,10 @@ class DayPickerView extends ListView implements AbsListView.OnScrollListener {
mAdapter.setCalendarTextColor(colors);
}
+ void setCalendarDayBackgroundColor(ColorStateList dayBackgroundColor) {
+ mAdapter.setCalendarDayBackgroundColor(dayBackgroundColor);
+ }
+
void setCalendarTextAppearance(int resId) {
mAdapter.setCalendarTextAppearance(resId);
}
@@ -459,9 +463,10 @@ class DayPickerView extends ListView implements AbsListView.OnScrollListener {
mYearFormat = new SimpleDateFormat("yyyy", Locale.getDefault());
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
- super.onInitializeAccessibilityEvent(event);
+ public void onInitializeAccessibilityEventInternal(AccessibilityEvent event) {
+ super.onInitializeAccessibilityEventInternal(event);
event.setItemCount(-1);
}
@@ -476,22 +481,26 @@ class DayPickerView extends ListView implements AbsListView.OnScrollListener {
/**
* Necessary for accessibility, to ensure we support "scrolling" forward and backward
* in the month list.
+ *
+ * @hide
*/
@Override
- public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
- super.onInitializeAccessibilityNodeInfo(info);
+ public void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) {
+ super.onInitializeAccessibilityNodeInfoInternal(info);
info.addAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_SCROLL_FORWARD);
info.addAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_SCROLL_BACKWARD);
}
/**
* When scroll forward/backward events are received, announce the newly scrolled-to month.
+ *
+ * @hide
*/
@Override
- public boolean performAccessibilityAction(int action, Bundle arguments) {
+ public boolean performAccessibilityActionInternal(int action, Bundle arguments) {
if (action != AccessibilityNodeInfo.ACTION_SCROLL_FORWARD &&
action != AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD) {
- return super.performAccessibilityAction(action, arguments);
+ return super.performAccessibilityActionInternal(action, arguments);
}
// Figure out what month is showing.
diff --git a/core/java/android/widget/DigitalClock.java b/core/java/android/widget/DigitalClock.java
index b6c1e5b..372bdb3 100644
--- a/core/java/android/widget/DigitalClock.java
+++ b/core/java/android/widget/DigitalClock.java
@@ -115,16 +115,18 @@ public class DigitalClock extends TextView {
}
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
- super.onInitializeAccessibilityEvent(event);
+ public void onInitializeAccessibilityEventInternal(AccessibilityEvent event) {
+ super.onInitializeAccessibilityEventInternal(event);
//noinspection deprecation
event.setClassName(DigitalClock.class.getName());
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
- super.onInitializeAccessibilityNodeInfo(info);
+ public void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) {
+ super.onInitializeAccessibilityNodeInfoInternal(info);
//noinspection deprecation
info.setClassName(DigitalClock.class.getName());
}
diff --git a/core/java/android/widget/EditText.java b/core/java/android/widget/EditText.java
index a8ff562..f54beb5 100644
--- a/core/java/android/widget/EditText.java
+++ b/core/java/android/widget/EditText.java
@@ -122,20 +122,23 @@ public class EditText extends TextView {
super.setEllipsize(ellipsis);
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
- super.onInitializeAccessibilityEvent(event);
+ public void onInitializeAccessibilityEventInternal(AccessibilityEvent event) {
+ super.onInitializeAccessibilityEventInternal(event);
event.setClassName(EditText.class.getName());
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
- super.onInitializeAccessibilityNodeInfo(info);
+ public void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) {
+ super.onInitializeAccessibilityNodeInfoInternal(info);
info.setClassName(EditText.class.getName());
}
+ /** @hide */
@Override
- public boolean performAccessibilityAction(int action, Bundle arguments) {
+ public boolean performAccessibilityActionInternal(int action, Bundle arguments) {
switch (action) {
case AccessibilityNodeInfo.ACTION_SET_TEXT: {
CharSequence text = (arguments != null) ? arguments.getCharSequence(
@@ -147,7 +150,7 @@ public class EditText extends TextView {
return true;
}
default: {
- return super.performAccessibilityAction(action, arguments);
+ return super.performAccessibilityActionInternal(action, arguments);
}
}
}
diff --git a/core/java/android/widget/Editor.java b/core/java/android/widget/Editor.java
index 936da32..d5166f3 100644
--- a/core/java/android/widget/Editor.java
+++ b/core/java/android/widget/Editor.java
@@ -1402,7 +1402,7 @@ public class Editor {
blockDisplayList.setLeftTopRightBottom(left, top, right, bottom);
}
- ((HardwareCanvas) canvas).drawRenderNode(blockDisplayList, null,
+ ((HardwareCanvas) canvas).drawRenderNode(blockDisplayList,
0 /* no child clipping, our TextView parent enforces it */);
endOfPreviousBlock = blockEndLine;
diff --git a/core/java/android/widget/ExpandableListView.java b/core/java/android/widget/ExpandableListView.java
index 70089e0..675dc9b 100644
--- a/core/java/android/widget/ExpandableListView.java
+++ b/core/java/android/widget/ExpandableListView.java
@@ -1341,15 +1341,17 @@ public class ExpandableListView extends ListView {
}
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
- super.onInitializeAccessibilityEvent(event);
+ public void onInitializeAccessibilityEventInternal(AccessibilityEvent event) {
+ super.onInitializeAccessibilityEventInternal(event);
event.setClassName(ExpandableListView.class.getName());
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
- super.onInitializeAccessibilityNodeInfo(info);
+ public void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) {
+ super.onInitializeAccessibilityNodeInfoInternal(info);
info.setClassName(ExpandableListView.class.getName());
}
}
diff --git a/core/java/android/widget/FrameLayout.java b/core/java/android/widget/FrameLayout.java
index d974c29..f208fff 100644
--- a/core/java/android/widget/FrameLayout.java
+++ b/core/java/android/widget/FrameLayout.java
@@ -704,15 +704,17 @@ public class FrameLayout extends ViewGroup {
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
- super.onInitializeAccessibilityEvent(event);
+ public void onInitializeAccessibilityEventInternal(AccessibilityEvent event) {
+ super.onInitializeAccessibilityEventInternal(event);
event.setClassName(FrameLayout.class.getName());
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
- super.onInitializeAccessibilityNodeInfo(info);
+ public void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) {
+ super.onInitializeAccessibilityNodeInfoInternal(info);
info.setClassName(FrameLayout.class.getName());
}
diff --git a/core/java/android/widget/Gallery.java b/core/java/android/widget/Gallery.java
index f7c839f..3c428b0 100644
--- a/core/java/android/widget/Gallery.java
+++ b/core/java/android/widget/Gallery.java
@@ -1373,15 +1373,17 @@ public class Gallery extends AbsSpinner implements GestureDetector.OnGestureList
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
- super.onInitializeAccessibilityEvent(event);
+ public void onInitializeAccessibilityEventInternal(AccessibilityEvent event) {
+ super.onInitializeAccessibilityEventInternal(event);
event.setClassName(Gallery.class.getName());
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
- super.onInitializeAccessibilityNodeInfo(info);
+ public void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) {
+ super.onInitializeAccessibilityNodeInfoInternal(info);
info.setClassName(Gallery.class.getName());
info.setScrollable(mItemCount > 1);
if (isEnabled()) {
@@ -1394,9 +1396,10 @@ public class Gallery extends AbsSpinner implements GestureDetector.OnGestureList
}
}
+ /** @hide */
@Override
- public boolean performAccessibilityAction(int action, Bundle arguments) {
- if (super.performAccessibilityAction(action, arguments)) {
+ public boolean performAccessibilityActionInternal(int action, Bundle arguments) {
+ if (super.performAccessibilityActionInternal(action, arguments)) {
return true;
}
switch (action) {
diff --git a/core/java/android/widget/GridLayout.java b/core/java/android/widget/GridLayout.java
index 161ae7e..cc925eb 100644
--- a/core/java/android/widget/GridLayout.java
+++ b/core/java/android/widget/GridLayout.java
@@ -1190,15 +1190,17 @@ public class GridLayout extends ViewGroup {
}
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
- super.onInitializeAccessibilityEvent(event);
+ public void onInitializeAccessibilityEventInternal(AccessibilityEvent event) {
+ super.onInitializeAccessibilityEventInternal(event);
event.setClassName(GridLayout.class.getName());
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
- super.onInitializeAccessibilityNodeInfo(info);
+ public void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) {
+ super.onInitializeAccessibilityNodeInfoInternal(info);
info.setClassName(GridLayout.class.getName());
}
diff --git a/core/java/android/widget/GridView.java b/core/java/android/widget/GridView.java
index efd6fc0..f7ce57b 100644
--- a/core/java/android/widget/GridView.java
+++ b/core/java/android/widget/GridView.java
@@ -2341,15 +2341,17 @@ public class GridView extends AbsListView {
return result;
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
- super.onInitializeAccessibilityEvent(event);
+ public void onInitializeAccessibilityEventInternal(AccessibilityEvent event) {
+ super.onInitializeAccessibilityEventInternal(event);
event.setClassName(GridView.class.getName());
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
- super.onInitializeAccessibilityNodeInfo(info);
+ public void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) {
+ super.onInitializeAccessibilityNodeInfoInternal(info);
info.setClassName(GridView.class.getName());
final int columnsCount = getNumColumns();
diff --git a/core/java/android/widget/HorizontalScrollView.java b/core/java/android/widget/HorizontalScrollView.java
index 371b480..c6c979e 100644
--- a/core/java/android/widget/HorizontalScrollView.java
+++ b/core/java/android/widget/HorizontalScrollView.java
@@ -774,9 +774,10 @@ public class HorizontalScrollView extends FrameLayout {
outRects.add(bounds);
}
+ /** @hide */
@Override
- public boolean performAccessibilityAction(int action, Bundle arguments) {
- if (super.performAccessibilityAction(action, arguments)) {
+ public boolean performAccessibilityActionInternal(int action, Bundle arguments) {
+ if (super.performAccessibilityActionInternal(action, arguments)) {
return true;
}
switch (action) {
@@ -806,9 +807,10 @@ public class HorizontalScrollView extends FrameLayout {
return false;
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
- super.onInitializeAccessibilityNodeInfo(info);
+ public void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) {
+ super.onInitializeAccessibilityNodeInfoInternal(info);
info.setClassName(HorizontalScrollView.class.getName());
final int scrollRange = getScrollRange();
if (scrollRange > 0) {
@@ -822,9 +824,10 @@ public class HorizontalScrollView extends FrameLayout {
}
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
- super.onInitializeAccessibilityEvent(event);
+ public void onInitializeAccessibilityEventInternal(AccessibilityEvent event) {
+ super.onInitializeAccessibilityEventInternal(event);
event.setClassName(HorizontalScrollView.class.getName());
event.setScrollable(getScrollRange() > 0);
event.setScrollX(mScrollX);
diff --git a/core/java/android/widget/ImageButton.java b/core/java/android/widget/ImageButton.java
index 3a20628..3b6825d 100644
--- a/core/java/android/widget/ImageButton.java
+++ b/core/java/android/widget/ImageButton.java
@@ -92,15 +92,17 @@ public class ImageButton extends ImageView {
return false;
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
- super.onInitializeAccessibilityEvent(event);
+ public void onInitializeAccessibilityEventInternal(AccessibilityEvent event) {
+ super.onInitializeAccessibilityEventInternal(event);
event.setClassName(ImageButton.class.getName());
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
- super.onInitializeAccessibilityNodeInfo(info);
+ public void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) {
+ super.onInitializeAccessibilityNodeInfoInternal(info);
info.setClassName(ImageButton.class.getName());
}
}
diff --git a/core/java/android/widget/ImageSwitcher.java b/core/java/android/widget/ImageSwitcher.java
index c048970..0910eb0 100644
--- a/core/java/android/widget/ImageSwitcher.java
+++ b/core/java/android/widget/ImageSwitcher.java
@@ -56,15 +56,17 @@ public class ImageSwitcher extends ViewSwitcher
showNext();
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
- super.onInitializeAccessibilityEvent(event);
+ public void onInitializeAccessibilityEventInternal(AccessibilityEvent event) {
+ super.onInitializeAccessibilityEventInternal(event);
event.setClassName(ImageSwitcher.class.getName());
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
- super.onInitializeAccessibilityNodeInfo(info);
+ public void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) {
+ super.onInitializeAccessibilityNodeInfoInternal(info);
info.setClassName(ImageSwitcher.class.getName());
}
}
diff --git a/core/java/android/widget/ImageView.java b/core/java/android/widget/ImageView.java
index c68bfca..fbad314 100644
--- a/core/java/android/widget/ImageView.java
+++ b/core/java/android/widget/ImageView.java
@@ -239,9 +239,10 @@ public class ImageView extends View {
return (getBackground() != null && getBackground().getCurrent() != null);
}
+ /** @hide */
@Override
- public void onPopulateAccessibilityEvent(AccessibilityEvent event) {
- super.onPopulateAccessibilityEvent(event);
+ public void onPopulateAccessibilityEventInternal(AccessibilityEvent event) {
+ super.onPopulateAccessibilityEventInternal(event);
CharSequence contentDescription = getContentDescription();
if (!TextUtils.isEmpty(contentDescription)) {
event.getText().add(contentDescription);
@@ -1418,15 +1419,17 @@ public class ImageView extends View {
}
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
- super.onInitializeAccessibilityEvent(event);
+ public void onInitializeAccessibilityEventInternal(AccessibilityEvent event) {
+ super.onInitializeAccessibilityEventInternal(event);
event.setClassName(ImageView.class.getName());
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
- super.onInitializeAccessibilityNodeInfo(info);
+ public void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) {
+ super.onInitializeAccessibilityNodeInfoInternal(info);
info.setClassName(ImageView.class.getName());
}
}
diff --git a/core/java/android/widget/LinearLayout.java b/core/java/android/widget/LinearLayout.java
index 6476cdc..28e50c4 100644
--- a/core/java/android/widget/LinearLayout.java
+++ b/core/java/android/widget/LinearLayout.java
@@ -1806,15 +1806,17 @@ public class LinearLayout extends ViewGroup {
return p instanceof LinearLayout.LayoutParams;
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
- super.onInitializeAccessibilityEvent(event);
+ public void onInitializeAccessibilityEventInternal(AccessibilityEvent event) {
+ super.onInitializeAccessibilityEventInternal(event);
event.setClassName(LinearLayout.class.getName());
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
- super.onInitializeAccessibilityNodeInfo(info);
+ public void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) {
+ super.onInitializeAccessibilityNodeInfoInternal(info);
info.setClassName(LinearLayout.class.getName());
}
diff --git a/core/java/android/widget/ListView.java b/core/java/android/widget/ListView.java
index ba6f061..df0d1fd 100644
--- a/core/java/android/widget/ListView.java
+++ b/core/java/android/widget/ListView.java
@@ -3878,15 +3878,17 @@ public class ListView extends AbsListView {
return false;
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
- super.onInitializeAccessibilityEvent(event);
+ public void onInitializeAccessibilityEventInternal(AccessibilityEvent event) {
+ super.onInitializeAccessibilityEventInternal(event);
event.setClassName(ListView.class.getName());
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
- super.onInitializeAccessibilityNodeInfo(info);
+ public void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) {
+ super.onInitializeAccessibilityNodeInfoInternal(info);
info.setClassName(ListView.class.getName());
final int rowsCount = getCount();
diff --git a/core/java/android/widget/MediaController.java b/core/java/android/widget/MediaController.java
index f1aaa4d..4cafe72 100644
--- a/core/java/android/widget/MediaController.java
+++ b/core/java/android/widget/MediaController.java
@@ -625,15 +625,17 @@ public class MediaController extends FrameLayout {
super.setEnabled(enabled);
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
- super.onInitializeAccessibilityEvent(event);
+ public void onInitializeAccessibilityEventInternal(AccessibilityEvent event) {
+ super.onInitializeAccessibilityEventInternal(event);
event.setClassName(MediaController.class.getName());
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
- super.onInitializeAccessibilityNodeInfo(info);
+ public void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) {
+ super.onInitializeAccessibilityNodeInfoInternal(info);
info.setClassName(MediaController.class.getName());
}
diff --git a/core/java/android/widget/MultiAutoCompleteTextView.java b/core/java/android/widget/MultiAutoCompleteTextView.java
index cbd01b0..6954eea 100644
--- a/core/java/android/widget/MultiAutoCompleteTextView.java
+++ b/core/java/android/widget/MultiAutoCompleteTextView.java
@@ -202,15 +202,17 @@ public class MultiAutoCompleteTextView extends AutoCompleteTextView {
editable.replace(start, end, mTokenizer.terminateToken(text));
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
- super.onInitializeAccessibilityEvent(event);
+ public void onInitializeAccessibilityEventInternal(AccessibilityEvent event) {
+ super.onInitializeAccessibilityEventInternal(event);
event.setClassName(MultiAutoCompleteTextView.class.getName());
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
- super.onInitializeAccessibilityNodeInfo(info);
+ public void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) {
+ super.onInitializeAccessibilityNodeInfoInternal(info);
info.setClassName(MultiAutoCompleteTextView.class.getName());
}
diff --git a/core/java/android/widget/NumberPicker.java b/core/java/android/widget/NumberPicker.java
index ee17b78..16dc26d 100644
--- a/core/java/android/widget/NumberPicker.java
+++ b/core/java/android/widget/NumberPicker.java
@@ -1558,9 +1558,10 @@ public class NumberPicker extends LinearLayout {
}
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
- super.onInitializeAccessibilityEvent(event);
+ public void onInitializeAccessibilityEventInternal(AccessibilityEvent event) {
+ super.onInitializeAccessibilityEventInternal(event);
event.setClassName(NumberPicker.class.getName());
event.setScrollable(true);
event.setScrollY((mMinValue + mValue) * mSelectorElementHeight);
diff --git a/core/java/android/widget/PopupMenu.java b/core/java/android/widget/PopupMenu.java
index 2708398..06ac1c3 100644
--- a/core/java/android/widget/PopupMenu.java
+++ b/core/java/android/widget/PopupMenu.java
@@ -115,6 +115,29 @@ public class PopupMenu implements MenuBuilder.Callback, MenuPresenter.Callback {
}
/**
+ * Sets the gravity used to align the popup window to its anchor view.
+ * <p>
+ * If the popup is showing, calling this method will take effect only
+ * the next time the popup is shown.
+ *
+ * @param gravity the gravity used to align the popup window
+ *
+ * @see #getGravity()
+ */
+ public void setGravity(int gravity) {
+ mPopup.setGravity(gravity);
+ }
+
+ /**
+ * @return the gravity used to align the popup window to its anchor view
+ *
+ * @see #setGravity(int)
+ */
+ public int getGravity() {
+ return mPopup.getGravity();
+ }
+
+ /**
* Returns an {@link OnTouchListener} that can be added to the anchor view
* to implement drag-to-open behavior.
* <p>
diff --git a/core/java/android/widget/PopupWindow.java b/core/java/android/widget/PopupWindow.java
index 5419ab6..f5cd915 100644
--- a/core/java/android/widget/PopupWindow.java
+++ b/core/java/android/widget/PopupWindow.java
@@ -18,11 +18,9 @@ package android.widget;
import com.android.internal.R;
-import android.animation.ValueAnimator;
import android.content.Context;
import android.content.res.Resources;
import android.content.res.TypedArray;
-import android.graphics.Insets;
import android.graphics.PixelFormat;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
@@ -195,7 +193,7 @@ public class PopupWindow {
*/
public PopupWindow(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
mContext = context;
- mWindowManager = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
+ mWindowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
final TypedArray a = context.obtainStyledAttributes(
attrs, R.styleable.PopupWindow, defStyleAttr, defStyleRes);
@@ -871,6 +869,34 @@ public class PopupWindow {
}
/**
+ * Sets whether the popup window should overlap its anchor view when
+ * displayed as a drop-down.
+ * <p>
+ * If the popup is showing, calling this method will take effect only
+ * the next time the popup is shown.
+ *
+ * @param overlapAnchor Whether the popup should overlap its anchor.
+ *
+ * @see #getOverlapAnchor()
+ * @see #isShowing()
+ */
+ public void setOverlapAnchor(boolean overlapAnchor) {
+ mOverlapAnchor = overlapAnchor;
+ }
+
+ /**
+ * Returns whether the popup window should overlap its anchor view when
+ * displayed as a drop-down.
+ *
+ * @return Whether the popup should overlap its anchor.
+ *
+ * @see #setOverlapAnchor(boolean)
+ */
+ public boolean getOverlapAnchor() {
+ return mOverlapAnchor;
+ }
+
+ /**
* <p>Indicate whether this popup window is showing on screen.</p>
*
* @return true if the popup is showing, false otherwise
@@ -934,11 +960,12 @@ public class PopupWindow {
}
/**
- * <p>Display the content view in a popup window anchored to the bottom-left
+ * Display the content view in a popup window anchored to the bottom-left
* corner of the anchor view. If there is not enough room on screen to show
* the popup in its entirety, this method tries to find a parent scroll
- * view to scroll. If no parent scroll view can be scrolled, the bottom-left
- * corner of the popup is pinned at the top left corner of the anchor view.</p>
+ * view to scroll. If no parent scroll view can be scrolled, the
+ * bottom-left corner of the popup is pinned at the top left corner of the
+ * anchor view.
*
* @param anchor the view on which to pin the popup window
*
@@ -949,14 +976,15 @@ public class PopupWindow {
}
/**
- * <p>Display the content view in a popup window anchored to the bottom-left
+ * Display the content view in a popup window anchored to the bottom-left
* corner of the anchor view offset by the specified x and y coordinates.
- * If there is not enough room on screen to show
- * the popup in its entirety, this method tries to find a parent scroll
- * view to scroll. If no parent scroll view can be scrolled, the bottom-left
- * corner of the popup is pinned at the top left corner of the anchor view.</p>
- * <p>If the view later scrolls to move <code>anchor</code> to a different
- * location, the popup will be moved correspondingly.</p>
+ * If there is not enough room on screen to show the popup in its entirety,
+ * this method tries to find a parent scroll view to scroll. If no parent
+ * scroll view can be scrolled, the bottom-left corner of the popup is
+ * pinned at the top left corner of the anchor view.
+ * <p>
+ * If the view later scrolls to move <code>anchor</code> to a different
+ * location, the popup will be moved correspondingly.
*
* @param anchor the view on which to pin the popup window
* @param xoff A horizontal offset from the anchor in pixels
@@ -969,14 +997,17 @@ public class PopupWindow {
}
/**
- * <p>Display the content view in a popup window anchored to the bottom-left
- * corner of the anchor view offset by the specified x and y coordinates.
- * If there is not enough room on screen to show
- * the popup in its entirety, this method tries to find a parent scroll
- * view to scroll. If no parent scroll view can be scrolled, the bottom-left
- * corner of the popup is pinned at the top left corner of the anchor view.</p>
- * <p>If the view later scrolls to move <code>anchor</code> to a different
- * location, the popup will be moved correspondingly.</p>
+ * Displays the content view in a popup window anchored to the corner of
+ * another view. The window is positioned according to the specified
+ * gravity and offset by the specified x and y coordinates.
+ * <p>
+ * If there is not enough room on screen to show the popup in its entirety,
+ * this method tries to find a parent scroll view to scroll. If no parent
+ * view can be scrolled, the specified vertical gravity will be ignored and
+ * the popup will anchor itself such that it is visible.
+ * <p>
+ * If the view later scrolls to move <code>anchor</code> to a different
+ * location, the popup will be moved correspondingly.
*
* @param anchor the view on which to pin the popup window
* @param xoff A horizontal offset from the anchor in pixels
@@ -1571,7 +1602,7 @@ public class PopupWindow {
* @param height the new height, can be -1 to ignore
*/
public void update(View anchor, int width, int height) {
- update(anchor, false, 0, 0, true, width, height, mAnchoredGravity);
+ update(anchor, false, 0, 0, true, width, height);
}
/**
@@ -1590,30 +1621,26 @@ public class PopupWindow {
* @param height the new height, can be -1 to ignore
*/
public void update(View anchor, int xoff, int yoff, int width, int height) {
- update(anchor, true, xoff, yoff, true, width, height, mAnchoredGravity);
+ update(anchor, true, xoff, yoff, true, width, height);
}
private void update(View anchor, boolean updateLocation, int xoff, int yoff,
- boolean updateDimension, int width, int height, int gravity) {
+ boolean updateDimension, int width, int height) {
if (!isShowing() || mContentView == null) {
return;
}
- WeakReference<View> oldAnchor = mAnchor;
- final boolean needsUpdate = updateLocation
- && (mAnchorXoff != xoff || mAnchorYoff != yoff);
+ final WeakReference<View> oldAnchor = mAnchor;
+ final boolean needsUpdate = updateLocation && (mAnchorXoff != xoff || mAnchorYoff != yoff);
if (oldAnchor == null || oldAnchor.get() != anchor || (needsUpdate && !mIsDropdown)) {
- registerForScrollChanged(anchor, xoff, yoff, gravity);
+ registerForScrollChanged(anchor, xoff, yoff, mAnchoredGravity);
} else if (needsUpdate) {
// No need to register again if this is a DropDown, showAsDropDown already did.
mAnchorXoff = xoff;
mAnchorYoff = yoff;
- mAnchoredGravity = gravity;
}
- WindowManager.LayoutParams p = (WindowManager.LayoutParams) mPopupView.getLayoutParams();
-
if (updateDimension) {
if (width == -1) {
width = mPopupWidth;
@@ -1627,11 +1654,12 @@ public class PopupWindow {
}
}
- int x = p.x;
- int y = p.y;
-
+ final WindowManager.LayoutParams p =
+ (WindowManager.LayoutParams) mPopupView.getLayoutParams();
+ final int x = p.x;
+ final int y = p.y;
if (updateLocation) {
- updateAboveAnchor(findDropDownPosition(anchor, p, xoff, yoff, gravity));
+ updateAboveAnchor(findDropDownPosition(anchor, p, xoff, yoff, mAnchoredGravity));
} else {
updateAboveAnchor(findDropDownPosition(anchor, p, mAnchorXoff, mAnchorYoff,
mAnchoredGravity));
@@ -1748,13 +1776,14 @@ public class PopupWindow {
}
}
+ /** @hide */
@Override
- public void sendAccessibilityEvent(int eventType) {
+ public void sendAccessibilityEventInternal(int eventType) {
// clinets are interested in the content not the container, make it event source
if (mContentView != null) {
mContentView.sendAccessibilityEvent(eventType);
} else {
- super.sendAccessibilityEvent(eventType);
+ super.sendAccessibilityEventInternal(eventType);
}
}
}
diff --git a/core/java/android/widget/ProgressBar.java b/core/java/android/widget/ProgressBar.java
index de1bbc7..d32cb10 100644
--- a/core/java/android/widget/ProgressBar.java
+++ b/core/java/android/widget/ProgressBar.java
@@ -1825,17 +1825,19 @@ public class ProgressBar extends View {
mAttached = false;
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
- super.onInitializeAccessibilityEvent(event);
+ public void onInitializeAccessibilityEventInternal(AccessibilityEvent event) {
+ super.onInitializeAccessibilityEventInternal(event);
event.setClassName(ProgressBar.class.getName());
event.setItemCount(mMax);
event.setCurrentItemIndex(mProgress);
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
- super.onInitializeAccessibilityNodeInfo(info);
+ public void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) {
+ super.onInitializeAccessibilityNodeInfoInternal(info);
info.setClassName(ProgressBar.class.getName());
}
diff --git a/core/java/android/widget/QuickContactBadge.java b/core/java/android/widget/QuickContactBadge.java
index 23fa402..d0e8081 100644
--- a/core/java/android/widget/QuickContactBadge.java
+++ b/core/java/android/widget/QuickContactBadge.java
@@ -304,15 +304,17 @@ public class QuickContactBadge extends ImageView implements OnClickListener {
}
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
- super.onInitializeAccessibilityEvent(event);
+ public void onInitializeAccessibilityEventInternal(AccessibilityEvent event) {
+ super.onInitializeAccessibilityEventInternal(event);
event.setClassName(QuickContactBadge.class.getName());
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
- super.onInitializeAccessibilityNodeInfo(info);
+ public void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) {
+ super.onInitializeAccessibilityNodeInfoInternal(info);
info.setClassName(QuickContactBadge.class.getName());
}
diff --git a/core/java/android/widget/RadialTimePickerView.java b/core/java/android/widget/RadialTimePickerView.java
index 7b64cf5..094a712 100644
--- a/core/java/android/widget/RadialTimePickerView.java
+++ b/core/java/android/widget/RadialTimePickerView.java
@@ -23,18 +23,22 @@ import android.animation.ObjectAnimator;
import android.animation.PropertyValuesHolder;
import android.animation.ValueAnimator;
import android.content.Context;
+import android.content.res.ColorStateList;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
+import android.graphics.Path;
import android.graphics.Rect;
+import android.graphics.Region;
import android.graphics.Typeface;
import android.os.Bundle;
import android.util.AttributeSet;
import android.util.IntArray;
import android.util.Log;
import android.util.MathUtils;
+import android.util.StateSet;
import android.util.TypedValue;
import android.view.HapticFeedbackConstants;
import android.view.MotionEvent;
@@ -56,8 +60,8 @@ import java.util.Locale;
*
* @hide
*/
-public class RadialTimePickerView extends View implements View.OnTouchListener {
- private static final String TAG = "ClockView";
+public class RadialTimePickerView extends View {
+ private static final String TAG = "RadialTimePickerView";
private static final boolean DEBUG = false;
@@ -82,12 +86,6 @@ public class RadialTimePickerView extends View implements View.OnTouchListener {
// Transparent alpha level
private static final int ALPHA_TRANSPARENT = 0;
- // Alpha level of color for selector.
- private static final int ALPHA_SELECTOR = 60; // was 51
-
- private static final float COSINE_30_DEGREES = ((float) Math.sqrt(3)) * 0.5f;
- private static final float SINE_30_DEGREES = 0.5f;
-
private static final int DEGREES_FOR_ONE_HOUR = 30;
private static final int DEGREES_FOR_ONE_MINUTE = 6;
@@ -97,7 +95,27 @@ public class RadialTimePickerView extends View implements View.OnTouchListener {
private static final int CENTER_RADIUS = 2;
- private static int[] sSnapPrefer30sMap = new int[361];
+ private static final int FADE_OUT_DURATION = 500;
+ private static final int FADE_IN_DURATION = 500;
+
+ private static final int[] SNAP_PREFER_30S_MAP = new int[361];
+
+ private static final int NUM_POSITIONS = 12;
+ private static final float[] COS_30 = new float[NUM_POSITIONS];
+ private static final float[] SIN_30 = new float[NUM_POSITIONS];
+
+ static {
+ // Prepare mapping to snap touchable degrees to selectable degrees.
+ preparePrefer30sMap();
+
+ final double increment = 2.0 * Math.PI / NUM_POSITIONS;
+ double angle = Math.PI / 2.0;
+ for (int i = 0; i < NUM_POSITIONS; i++) {
+ COS_30[i] = (float) Math.cos(angle);
+ SIN_30[i] = (float) Math.sin(angle);
+ angle += increment;
+ }
+ }
private final InvalidateUpdateListener mInvalidateUpdateListener =
new InvalidateUpdateListener();
@@ -108,7 +126,6 @@ public class RadialTimePickerView extends View implements View.OnTouchListener {
private final String[] mMinutesTexts = new String[12];
private final Paint[] mPaint = new Paint[2];
- private final int[] mColor = new int[2];
private final IntHolder[] mAlpha = new IntHolder[2];
private final Paint mPaintCenter = new Paint();
@@ -122,26 +139,18 @@ public class RadialTimePickerView extends View implements View.OnTouchListener {
private final Typeface mTypeface;
- private final float[] mCircleRadius = new float[3];
-
private final float[] mTextSize = new float[2];
- private final float[][] mTextGridHeights = new float[2][7];
- private final float[][] mTextGridWidths = new float[2][7];
+ private final float[][] mOuterTextX = new float[2][12];
+ private final float[][] mOuterTextY = new float[2][12];
- private final float[] mInnerTextGridHeights = new float[7];
- private final float[] mInnerTextGridWidths = new float[7];
+ private final float[] mInnerTextX = new float[12];
+ private final float[] mInnerTextY = new float[12];
- private final float[] mCircleRadiusMultiplier = new float[2];
private final float[] mNumbersRadiusMultiplier = new float[3];
private final float[] mTextSizeMultiplier = new float[3];
- private final float[] mAnimationRadiusMultiplier = new float[3];
-
- private final float mTransitionMidRadiusMultiplier;
- private final float mTransitionEndRadiusMultiplier;
-
private final int[] mLineLength = new int[3];
private final int[] mSelectionRadius = new int[3];
private final float mSelectionRadiusMultiplier;
@@ -152,7 +161,7 @@ public class RadialTimePickerView extends View implements View.OnTouchListener {
private final RadialPickerTouchHelper mTouchHelper;
- private float mInnerTextSize;
+ private ColorStateList mNumbersTextColor;
private boolean mIs24HourMode;
private boolean mShowHours;
@@ -163,8 +172,9 @@ public class RadialTimePickerView extends View implements View.OnTouchListener {
*/
private boolean mIsOnInnerCircle;
- private int mXCenter;
- private int mYCenter;
+ private float mXCenter;
+ private float mYCenter;
+ private float mCircleRadius;
private int mMinHypotenuseForInnerNumber;
private int mMaxHypotenuseForOuterNumber;
@@ -186,11 +196,6 @@ public class RadialTimePickerView extends View implements View.OnTouchListener {
void onValueSelected(int pickerIndex, int newValue, boolean autoAdvance);
}
- static {
- // Prepare mapping to snap touchable degrees to selectable degrees.
- preparePrefer30sMap();
- }
-
/**
* Split up the 360 degrees of the circle among the 60 selectable values. Assigns a larger
* selectable area to each of the 12 visible values, such that the ratio of space apportioned
@@ -225,7 +230,7 @@ public class RadialTimePickerView extends View implements View.OnTouchListener {
// Iterate through the input.
for (int degrees = 0; degrees < 361; degrees++) {
// Save the input-output mapping.
- sSnapPrefer30sMap[degrees] = snappedOutputDegrees;
+ SNAP_PREFER_30S_MAP[degrees] = snappedOutputDegrees;
// If this is the last input for the specified output, calculate the next output and
// the next expected count.
if (count == expectedCount) {
@@ -252,10 +257,10 @@ public class RadialTimePickerView extends View implements View.OnTouchListener {
* mapping.
*/
private static int snapPrefer30s(int degrees) {
- if (sSnapPrefer30sMap == null) {
+ if (SNAP_PREFER_30S_MAP == null) {
return -1;
}
- return sSnapPrefer30sMap[degrees];
+ return SNAP_PREFER_30S_MAP[degrees];
}
/**
@@ -327,63 +332,56 @@ public class RadialTimePickerView extends View implements View.OnTouchListener {
}
}
- final int numbersTextColor = a.getColor(R.styleable.TimePicker_numbersTextColor,
- res.getColor(R.color.timepicker_default_text_color_material));
+ mNumbersTextColor = a.getColorStateList(
+ R.styleable.TimePicker_numbersTextColor);
mPaint[HOURS] = new Paint();
mPaint[HOURS].setAntiAlias(true);
mPaint[HOURS].setTextAlign(Paint.Align.CENTER);
- mColor[HOURS] = numbersTextColor;
mPaint[MINUTES] = new Paint();
mPaint[MINUTES].setAntiAlias(true);
mPaint[MINUTES].setTextAlign(Paint.Align.CENTER);
- mColor[MINUTES] = numbersTextColor;
- mPaintCenter.setColor(numbersTextColor);
+ final ColorStateList selectorColors = a.getColorStateList(
+ R.styleable.TimePicker_numbersSelectorColor);
+ final int selectorActivatedColor = selectorColors.getColorForState(
+ StateSet.get(StateSet.VIEW_STATE_ENABLED | StateSet.VIEW_STATE_ACTIVATED), 0);
+
+ mPaintCenter.setColor(selectorActivatedColor);
mPaintCenter.setAntiAlias(true);
- mPaintCenter.setTextAlign(Paint.Align.CENTER);
+
+ final int textActivatedColor = mNumbersTextColor.getColorForState(
+ StateSet.get(StateSet.VIEW_STATE_ENABLED | StateSet.VIEW_STATE_ACTIVATED), 0);
mPaintSelector[HOURS][SELECTOR_CIRCLE] = new Paint();
mPaintSelector[HOURS][SELECTOR_CIRCLE].setAntiAlias(true);
- mColorSelector[HOURS][SELECTOR_CIRCLE] = a.getColor(
- R.styleable.TimePicker_numbersSelectorColor,
- R.color.timepicker_default_selector_color_material);
+ mColorSelector[HOURS][SELECTOR_CIRCLE] = selectorActivatedColor;
mPaintSelector[HOURS][SELECTOR_DOT] = new Paint();
mPaintSelector[HOURS][SELECTOR_DOT].setAntiAlias(true);
- mColorSelector[HOURS][SELECTOR_DOT] = a.getColor(
- R.styleable.TimePicker_numbersSelectorColor,
- R.color.timepicker_default_selector_color_material);
+ mColorSelector[HOURS][SELECTOR_DOT] = textActivatedColor;
mPaintSelector[HOURS][SELECTOR_LINE] = new Paint();
mPaintSelector[HOURS][SELECTOR_LINE].setAntiAlias(true);
mPaintSelector[HOURS][SELECTOR_LINE].setStrokeWidth(2);
- mColorSelector[HOURS][SELECTOR_LINE] = a.getColor(
- R.styleable.TimePicker_numbersSelectorColor,
- R.color.timepicker_default_selector_color_material);
+ mColorSelector[HOURS][SELECTOR_LINE] = selectorActivatedColor;
mPaintSelector[MINUTES][SELECTOR_CIRCLE] = new Paint();
mPaintSelector[MINUTES][SELECTOR_CIRCLE].setAntiAlias(true);
- mColorSelector[MINUTES][SELECTOR_CIRCLE] = a.getColor(
- R.styleable.TimePicker_numbersSelectorColor,
- R.color.timepicker_default_selector_color_material);
+ mColorSelector[MINUTES][SELECTOR_CIRCLE] = selectorActivatedColor;
mPaintSelector[MINUTES][SELECTOR_DOT] = new Paint();
mPaintSelector[MINUTES][SELECTOR_DOT].setAntiAlias(true);
- mColorSelector[MINUTES][SELECTOR_DOT] = a.getColor(
- R.styleable.TimePicker_numbersSelectorColor,
- R.color.timepicker_default_selector_color_material);
+ mColorSelector[MINUTES][SELECTOR_DOT] = textActivatedColor;
mPaintSelector[MINUTES][SELECTOR_LINE] = new Paint();
mPaintSelector[MINUTES][SELECTOR_LINE].setAntiAlias(true);
mPaintSelector[MINUTES][SELECTOR_LINE].setStrokeWidth(2);
- mColorSelector[MINUTES][SELECTOR_LINE] = a.getColor(
- R.styleable.TimePicker_numbersSelectorColor,
- R.color.timepicker_default_selector_color_material);
+ mColorSelector[MINUTES][SELECTOR_LINE] = selectorActivatedColor;
mPaintBackground.setColor(a.getColor(R.styleable.TimePicker_numbersBackgroundColor,
- res.getColor(R.color.timepicker_default_numbers_background_color_material)));
+ context.getColor(R.color.timepicker_default_numbers_background_color_material)));
mPaintBackground.setAntiAlias(true);
if (DEBUG) {
@@ -409,22 +407,10 @@ public class RadialTimePickerView extends View implements View.OnTouchListener {
initHoursAndMinutesText();
initData();
- mTransitionMidRadiusMultiplier = Float.parseFloat(
- res.getString(R.string.timepicker_transition_mid_radius_multiplier));
- mTransitionEndRadiusMultiplier = Float.parseFloat(
- res.getString(R.string.timepicker_transition_end_radius_multiplier));
-
- mTextGridHeights[HOURS] = new float[7];
- mTextGridHeights[MINUTES] = new float[7];
-
- mSelectionRadiusMultiplier = Float.parseFloat(
- res.getString(R.string.timepicker_selection_radius_multiplier));
+ mSelectionRadiusMultiplier = res.getFloat(R.dimen.timepicker_selection_radius_multiplier);
a.recycle();
- setOnTouchListener(this);
- setClickable(true);
-
// Initial values
final Calendar calendar = Calendar.getInstance(Locale.getDefault());
final int currentHour = calendar.get(Calendar.HOUR_OF_DAY);
@@ -436,21 +422,6 @@ public class RadialTimePickerView extends View implements View.OnTouchListener {
setHapticFeedbackEnabled(true);
}
- /**
- * Measure the view to end up as a square, based on the minimum of the height and width.
- */
- @Override
- public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
- int measuredWidth = MeasureSpec.getSize(widthMeasureSpec);
- int widthMode = MeasureSpec.getMode(widthMeasureSpec);
- int measuredHeight = MeasureSpec.getSize(heightMeasureSpec);
- int heightMode = MeasureSpec.getMode(heightMeasureSpec);
- int minDimension = Math.min(measuredWidth, measuredHeight);
-
- super.onMeasure(MeasureSpec.makeMeasureSpec(minDimension, widthMode),
- MeasureSpec.makeMeasureSpec(minDimension, heightMode));
- }
-
public void initialize(int hour, int minute, boolean is24HourMode) {
if (mIs24HourMode != is24HourMode) {
mIs24HourMode = is24HourMode;
@@ -512,7 +483,6 @@ public class RadialTimePickerView extends View implements View.OnTouchListener {
mIsOnInnerCircle = isOnInnerCircle;
initData();
- updateLayoutData();
mTouchHelper.invalidateRoot();
}
@@ -601,24 +571,32 @@ public class RadialTimePickerView extends View implements View.OnTouchListener {
}
public void showHours(boolean animate) {
- if (mShowHours) return;
+ if (mShowHours) {
+ return;
+ }
+
mShowHours = true;
+
if (animate) {
startMinutesToHoursAnimation();
}
+
initData();
- updateLayoutData();
invalidate();
}
public void showMinutes(boolean animate) {
- if (!mShowHours) return;
+ if (!mShowHours) {
+ return;
+ }
+
mShowHours = false;
+
if (animate) {
startHoursToMinutesAnimation();
}
+
initData();
- updateLayoutData();
invalidate();
}
@@ -645,93 +623,71 @@ public class RadialTimePickerView extends View implements View.OnTouchListener {
final Resources res = getResources();
- if (mShowHours) {
- if (mIs24HourMode) {
- mCircleRadiusMultiplier[HOURS] = Float.parseFloat(
- res.getString(R.string.timepicker_circle_radius_multiplier_24HourMode));
- mNumbersRadiusMultiplier[HOURS] = Float.parseFloat(
- res.getString(R.string.timepicker_numbers_radius_multiplier_outer));
- mTextSizeMultiplier[HOURS] = Float.parseFloat(
- res.getString(R.string.timepicker_text_size_multiplier_outer));
-
- mNumbersRadiusMultiplier[HOURS_INNER] = Float.parseFloat(
- res.getString(R.string.timepicker_numbers_radius_multiplier_inner));
- mTextSizeMultiplier[HOURS_INNER] = Float.parseFloat(
- res.getString(R.string.timepicker_text_size_multiplier_inner));
- } else {
- mCircleRadiusMultiplier[HOURS] = Float.parseFloat(
- res.getString(R.string.timepicker_circle_radius_multiplier));
- mNumbersRadiusMultiplier[HOURS] = Float.parseFloat(
- res.getString(R.string.timepicker_numbers_radius_multiplier_normal));
- mTextSizeMultiplier[HOURS] = Float.parseFloat(
- res.getString(R.string.timepicker_text_size_multiplier_normal));
- }
+ if (mIs24HourMode) {
+ mNumbersRadiusMultiplier[HOURS] = res.getFloat(
+ R.dimen.timepicker_numbers_radius_multiplier_outer);
+ mTextSizeMultiplier[HOURS] = res.getFloat(
+ R.dimen.timepicker_text_size_multiplier_outer);
+
+ mNumbersRadiusMultiplier[HOURS_INNER] = res.getFloat(
+ R.dimen.timepicker_numbers_radius_multiplier_inner);
+ mTextSizeMultiplier[HOURS_INNER] = res.getFloat(
+ R.dimen.timepicker_text_size_multiplier_inner);
} else {
- mCircleRadiusMultiplier[MINUTES] = Float.parseFloat(
- res.getString(R.string.timepicker_circle_radius_multiplier));
- mNumbersRadiusMultiplier[MINUTES] = Float.parseFloat(
- res.getString(R.string.timepicker_numbers_radius_multiplier_normal));
- mTextSizeMultiplier[MINUTES] = Float.parseFloat(
- res.getString(R.string.timepicker_text_size_multiplier_normal));
- }
-
- mAnimationRadiusMultiplier[HOURS] = 1;
- mAnimationRadiusMultiplier[HOURS_INNER] = 1;
- mAnimationRadiusMultiplier[MINUTES] = 1;
-
- mAlpha[HOURS].setValue(mShowHours ? ALPHA_OPAQUE : ALPHA_TRANSPARENT);
- mAlpha[MINUTES].setValue(mShowHours ? ALPHA_TRANSPARENT : ALPHA_OPAQUE);
-
- mAlphaSelector[HOURS][SELECTOR_CIRCLE].setValue(
- mShowHours ? ALPHA_SELECTOR : ALPHA_TRANSPARENT);
- mAlphaSelector[HOURS][SELECTOR_DOT].setValue(
- mShowHours ? ALPHA_OPAQUE : ALPHA_TRANSPARENT);
- mAlphaSelector[HOURS][SELECTOR_LINE].setValue(
- mShowHours ? ALPHA_SELECTOR : ALPHA_TRANSPARENT);
-
- mAlphaSelector[MINUTES][SELECTOR_CIRCLE].setValue(
- mShowHours ? ALPHA_TRANSPARENT : ALPHA_SELECTOR);
- mAlphaSelector[MINUTES][SELECTOR_DOT].setValue(
- mShowHours ? ALPHA_TRANSPARENT : ALPHA_OPAQUE);
- mAlphaSelector[MINUTES][SELECTOR_LINE].setValue(
- mShowHours ? ALPHA_TRANSPARENT : ALPHA_SELECTOR);
+ mNumbersRadiusMultiplier[HOURS] = res.getFloat(
+ R.dimen.timepicker_numbers_radius_multiplier_normal);
+ mTextSizeMultiplier[HOURS] = res.getFloat(
+ R.dimen.timepicker_text_size_multiplier_normal);
+ }
+
+ mNumbersRadiusMultiplier[MINUTES] = res.getFloat(
+ R.dimen.timepicker_numbers_radius_multiplier_normal);
+ mTextSizeMultiplier[MINUTES] = res.getFloat(
+ R.dimen.timepicker_text_size_multiplier_normal);
+
+ final int hoursAlpha = mShowHours ? ALPHA_OPAQUE : ALPHA_TRANSPARENT;
+ mAlpha[HOURS].setValue(hoursAlpha);
+ mAlphaSelector[HOURS][SELECTOR_CIRCLE].setValue(hoursAlpha);
+ mAlphaSelector[HOURS][SELECTOR_DOT].setValue(hoursAlpha);
+ mAlphaSelector[HOURS][SELECTOR_LINE].setValue(hoursAlpha);
+
+ final int minutesAlpha = mShowHours ? ALPHA_TRANSPARENT : ALPHA_OPAQUE;
+ mAlpha[MINUTES].setValue(minutesAlpha);
+ mAlphaSelector[MINUTES][SELECTOR_CIRCLE].setValue(minutesAlpha);
+ mAlphaSelector[MINUTES][SELECTOR_DOT].setValue(minutesAlpha);
+ mAlphaSelector[MINUTES][SELECTOR_LINE].setValue(minutesAlpha);
}
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
- updateLayoutData();
- }
+ if (!changed) {
+ return;
+ }
- private void updateLayoutData() {
mXCenter = getWidth() / 2;
mYCenter = getHeight() / 2;
+ mCircleRadius = Math.min(mXCenter, mYCenter);
- final int min = Math.min(mXCenter, mYCenter);
-
- mCircleRadius[HOURS] = min * mCircleRadiusMultiplier[HOURS];
- mCircleRadius[HOURS_INNER] = min * mCircleRadiusMultiplier[HOURS];
- mCircleRadius[MINUTES] = min * mCircleRadiusMultiplier[MINUTES];
-
- mMinHypotenuseForInnerNumber = (int) (mCircleRadius[HOURS]
+ mMinHypotenuseForInnerNumber = (int) (mCircleRadius
* mNumbersRadiusMultiplier[HOURS_INNER]) - mSelectionRadius[HOURS];
- mMaxHypotenuseForOuterNumber = (int) (mCircleRadius[HOURS]
+ mMaxHypotenuseForOuterNumber = (int) (mCircleRadius
* mNumbersRadiusMultiplier[HOURS]) + mSelectionRadius[HOURS];
- mHalfwayHypotenusePoint = (int) (mCircleRadius[HOURS]
+ mHalfwayHypotenusePoint = (int) (mCircleRadius
* ((mNumbersRadiusMultiplier[HOURS] + mNumbersRadiusMultiplier[HOURS_INNER]) / 2));
- mTextSize[HOURS] = mCircleRadius[HOURS] * mTextSizeMultiplier[HOURS];
- mTextSize[MINUTES] = mCircleRadius[MINUTES] * mTextSizeMultiplier[MINUTES];
+ mTextSize[HOURS] = mCircleRadius * mTextSizeMultiplier[HOURS];
+ mTextSize[MINUTES] = mCircleRadius * mTextSizeMultiplier[MINUTES];
if (mIs24HourMode) {
- mInnerTextSize = mCircleRadius[HOURS] * mTextSizeMultiplier[HOURS_INNER];
+ mTextSize[HOURS_INNER] = mCircleRadius * mTextSizeMultiplier[HOURS_INNER];
}
- calculateGridSizesHours();
- calculateGridSizesMinutes();
+ calculatePositionsHours();
+ calculatePositionsMinutes();
- mSelectionRadius[HOURS] = (int) (mCircleRadius[HOURS] * mSelectionRadiusMultiplier);
+ mSelectionRadius[HOURS] = (int) (mCircleRadius * mSelectionRadiusMultiplier);
mSelectionRadius[HOURS_INNER] = mSelectionRadius[HOURS];
- mSelectionRadius[MINUTES] = (int) (mCircleRadius[MINUTES] * mSelectionRadiusMultiplier);
+ mSelectionRadius[MINUTES] = (int) (mCircleRadius * mSelectionRadiusMultiplier);
mTouchHelper.invalidateRoot();
}
@@ -744,25 +700,48 @@ public class RadialTimePickerView extends View implements View.OnTouchListener {
canvas.save();
}
- calculateGridSizesHours();
- calculateGridSizesMinutes();
-
drawCircleBackground(canvas);
- drawSelector(canvas);
-
- drawTextElements(canvas, mTextSize[HOURS], mTypeface, mOuterTextHours,
- mTextGridWidths[HOURS], mTextGridHeights[HOURS], mPaint[HOURS],
- mColor[HOURS], mAlpha[HOURS].getValue());
- if (mIs24HourMode && mInnerTextHours != null) {
- drawTextElements(canvas, mInnerTextSize, mTypeface, mInnerTextHours,
- mInnerTextGridWidths, mInnerTextGridHeights, mPaint[HOURS],
- mColor[HOURS], mAlpha[HOURS].getValue());
+ final int hoursAlpha = mAlpha[HOURS].getValue();
+ if (hoursAlpha > 0) {
+ // Draw the hour selector under the elements.
+ drawSelector(canvas, mIsOnInnerCircle ? HOURS_INNER : HOURS, null);
+
+ // Draw outer hours.
+ drawTextElements(canvas, mTextSize[HOURS], mTypeface, mOuterTextHours,
+ mOuterTextX[HOURS], mOuterTextY[HOURS], mPaint[HOURS], hoursAlpha,
+ !mIsOnInnerCircle, mSelectionDegrees[HOURS], false);
+
+ // Draw inner hours (12-23) for 24-hour time.
+ if (mIs24HourMode && mInnerTextHours != null) {
+ drawTextElements(canvas, mTextSize[HOURS_INNER], mTypeface, mInnerTextHours,
+ mInnerTextX, mInnerTextY, mPaint[HOURS], hoursAlpha,
+ mIsOnInnerCircle, mSelectionDegrees[HOURS], false);
+ }
}
- drawTextElements(canvas, mTextSize[MINUTES], mTypeface, mOuterTextMinutes,
- mTextGridWidths[MINUTES], mTextGridHeights[MINUTES], mPaint[MINUTES],
- mColor[MINUTES], mAlpha[MINUTES].getValue());
+ final int minutesAlpha = mAlpha[MINUTES].getValue();
+ if (minutesAlpha > 0) {
+ drawSelector(canvas, MINUTES, mSelectorPath);
+
+ // Exclude the selector region, then draw minutes with no
+ // activated states.
+ canvas.save(Canvas.CLIP_SAVE_FLAG);
+ canvas.clipPath(mSelectorPath, Region.Op.DIFFERENCE);
+ drawTextElements(canvas, mTextSize[MINUTES], mTypeface, mOuterTextMinutes,
+ mOuterTextX[MINUTES], mOuterTextY[MINUTES], mPaint[MINUTES], minutesAlpha,
+ false, 0, false);
+ canvas.restore();
+
+ // Intersect the selector region, then draw minutes with only
+ // activated states.
+ canvas.save(Canvas.CLIP_SAVE_FLAG);
+ canvas.clipPath(mSelectorPath, Region.Op.INTERSECT);
+ drawTextElements(canvas, mTextSize[MINUTES], mTypeface, mOuterTextMinutes,
+ mOuterTextX[MINUTES], mOuterTextY[MINUTES], mPaint[MINUTES], minutesAlpha,
+ true, mSelectionDegrees[MINUTES], true);
+ canvas.restore();
+ }
drawCenter(canvas);
@@ -774,31 +753,27 @@ public class RadialTimePickerView extends View implements View.OnTouchListener {
}
private void drawCircleBackground(Canvas canvas) {
- canvas.drawCircle(mXCenter, mYCenter, mCircleRadius[HOURS], mPaintBackground);
+ canvas.drawCircle(mXCenter, mYCenter, mCircleRadius, mPaintBackground);
}
private void drawCenter(Canvas canvas) {
canvas.drawCircle(mXCenter, mYCenter, CENTER_RADIUS, mPaintCenter);
}
- private void drawSelector(Canvas canvas) {
- drawSelector(canvas, mIsOnInnerCircle ? HOURS_INNER : HOURS);
- drawSelector(canvas, MINUTES);
- }
-
private int getMultipliedAlpha(int argb, int alpha) {
return (int) (Color.alpha(argb) * (alpha / 255.0) + 0.5);
}
- private void drawSelector(Canvas canvas, int index) {
+ private final Path mSelectorPath = new Path();
+
+ private void drawSelector(Canvas canvas, int index, Path selectorPath) {
// Calculate the current radius at which to place the selection circle.
- mLineLength[index] = (int) (mCircleRadius[index]
- * mNumbersRadiusMultiplier[index] * mAnimationRadiusMultiplier[index]);
+ mLineLength[index] = (int) (mCircleRadius * mNumbersRadiusMultiplier[index]);
- double selectionRadians = Math.toRadians(mSelectionDegrees[index]);
+ final double selectionRadians = Math.toRadians(mSelectionDegrees[index]);
- int pointX = mXCenter + (int) (mLineLength[index] * Math.sin(selectionRadians));
- int pointY = mYCenter - (int) (mLineLength[index] * Math.cos(selectionRadians));
+ float pointX = mXCenter + (int) (mLineLength[index] * Math.sin(selectionRadians));
+ float pointY = mYCenter - (int) (mLineLength[index] * Math.cos(selectionRadians));
int color;
int alpha;
@@ -812,23 +787,29 @@ public class RadialTimePickerView extends View implements View.OnTouchListener {
paint.setAlpha(getMultipliedAlpha(color, alpha));
canvas.drawCircle(pointX, pointY, mSelectionRadius[index], paint);
- // Draw the dot if needed
- if (mSelectionDegrees[index] % 30 != 0) {
+ // If needed, set up the clip path for later.
+ if (selectorPath != null) {
+ mSelectorPath.reset();
+ mSelectorPath.addCircle(pointX, pointY, mSelectionRadius[index], Path.Direction.CCW);
+ }
+
+ // Draw the dot if needed.
+ final boolean shouldDrawDot = mSelectionDegrees[index] % 30 != 0;
+ if (shouldDrawDot) {
// We're not on a direct tick
color = mColorSelector[index % 2][SELECTOR_DOT];
alpha = mAlphaSelector[index % 2][SELECTOR_DOT].getValue();
paint = mPaintSelector[index % 2][SELECTOR_DOT];
paint.setColor(color);
paint.setAlpha(getMultipliedAlpha(color, alpha));
- canvas.drawCircle(pointX, pointY, (mSelectionRadius[index] * 2 / 7), paint);
- } else {
- // We're not drawing the dot, so shorten the line to only go as far as the edge of the
- // selection circle
- int lineLength = mLineLength[index] - mSelectionRadius[index];
- pointX = mXCenter + (int) (lineLength * Math.sin(selectionRadians));
- pointY = mYCenter - (int) (lineLength * Math.cos(selectionRadians));
+ canvas.drawCircle(pointX, pointY, (mSelectionRadius[index] * 0.125f), paint);
}
+ // Shorten the line to only go to the edge of the selection circle.
+ final int lineLength = mLineLength[index] - mSelectionRadius[index];
+ pointX = mXCenter + (int) (lineLength * Math.sin(selectionRadians));
+ pointY = mYCenter - (int) (lineLength * Math.cos(selectionRadians));
+
// Draw the line
color = mColorSelector[index % 2][SELECTOR_LINE];
alpha = mAlphaSelector[index % 2][SELECTOR_LINE].getValue();
@@ -840,15 +821,15 @@ public class RadialTimePickerView extends View implements View.OnTouchListener {
private void drawDebug(Canvas canvas) {
// Draw outer numbers circle
- final float outerRadius = mCircleRadius[HOURS] * mNumbersRadiusMultiplier[HOURS];
+ final float outerRadius = mCircleRadius * mNumbersRadiusMultiplier[HOURS];
canvas.drawCircle(mXCenter, mYCenter, outerRadius, mPaintDebug);
// Draw inner numbers circle
- final float innerRadius = mCircleRadius[HOURS] * mNumbersRadiusMultiplier[HOURS_INNER];
+ final float innerRadius = mCircleRadius * mNumbersRadiusMultiplier[HOURS_INNER];
canvas.drawCircle(mXCenter, mYCenter, innerRadius, mPaintDebug);
// Draw outer background circle
- canvas.drawCircle(mXCenter, mYCenter, mCircleRadius[HOURS], mPaintDebug);
+ canvas.drawCircle(mXCenter, mYCenter, mCircleRadius, mPaintDebug);
// Draw outer rectangle for circles
float left = mXCenter - outerRadius;
@@ -858,10 +839,10 @@ public class RadialTimePickerView extends View implements View.OnTouchListener {
canvas.drawRect(left, top, right, bottom, mPaintDebug);
// Draw outer rectangle for background
- left = mXCenter - mCircleRadius[HOURS];
- top = mYCenter - mCircleRadius[HOURS];
- right = mXCenter + mCircleRadius[HOURS];
- bottom = mYCenter + mCircleRadius[HOURS];
+ left = mXCenter - mCircleRadius;
+ top = mYCenter - mCircleRadius;
+ right = mXCenter + mCircleRadius;
+ bottom = mYCenter + mCircleRadius;
canvas.drawRect(left, top, right, bottom, mPaintDebug);
// Draw outer view rectangle
@@ -888,185 +869,104 @@ public class RadialTimePickerView extends View implements View.OnTouchListener {
canvas.drawText(selected, x, y, paint);
}
- private void calculateGridSizesHours() {
+ private void calculatePositionsHours() {
// Calculate the text positions
- float numbersRadius = mCircleRadius[HOURS]
- * mNumbersRadiusMultiplier[HOURS] * mAnimationRadiusMultiplier[HOURS];
+ final float numbersRadius = mCircleRadius * mNumbersRadiusMultiplier[HOURS];
// Calculate the positions for the 12 numbers in the main circle.
- calculateGridSizes(mPaint[HOURS], numbersRadius, mXCenter, mYCenter,
- mTextSize[HOURS], mTextGridHeights[HOURS], mTextGridWidths[HOURS]);
+ calculatePositions(mPaint[HOURS], numbersRadius, mXCenter, mYCenter,
+ mTextSize[HOURS], mOuterTextX[HOURS], mOuterTextY[HOURS]);
// If we have an inner circle, calculate those positions too.
if (mIs24HourMode) {
- float innerNumbersRadius = mCircleRadius[HOURS_INNER]
- * mNumbersRadiusMultiplier[HOURS_INNER]
- * mAnimationRadiusMultiplier[HOURS_INNER];
+ final float innerNumbersRadius = mCircleRadius
+ * mNumbersRadiusMultiplier[HOURS_INNER];
- calculateGridSizes(mPaint[HOURS], innerNumbersRadius, mXCenter, mYCenter,
- mInnerTextSize, mInnerTextGridHeights, mInnerTextGridWidths);
+ calculatePositions(mPaint[HOURS], innerNumbersRadius, mXCenter, mYCenter,
+ mTextSize[HOURS_INNER], mInnerTextX, mInnerTextY);
}
}
- private void calculateGridSizesMinutes() {
+ private void calculatePositionsMinutes() {
// Calculate the text positions
- float numbersRadius = mCircleRadius[MINUTES]
- * mNumbersRadiusMultiplier[MINUTES] * mAnimationRadiusMultiplier[MINUTES];
+ final float numbersRadius = mCircleRadius * mNumbersRadiusMultiplier[MINUTES];
// Calculate the positions for the 12 numbers in the main circle.
- calculateGridSizes(mPaint[MINUTES], numbersRadius, mXCenter, mYCenter,
- mTextSize[MINUTES], mTextGridHeights[MINUTES], mTextGridWidths[MINUTES]);
+ calculatePositions(mPaint[MINUTES], numbersRadius, mXCenter, mYCenter,
+ mTextSize[MINUTES], mOuterTextX[MINUTES], mOuterTextY[MINUTES]);
}
-
/**
* Using the trigonometric Unit Circle, calculate the positions that the text will need to be
* drawn at based on the specified circle radius. Place the values in the textGridHeights and
* textGridWidths parameters.
*/
- private static void calculateGridSizes(Paint paint, float numbersRadius, float xCenter,
- float yCenter, float textSize, float[] textGridHeights, float[] textGridWidths) {
- /*
- * The numbers need to be drawn in a 7x7 grid, representing the points on the Unit Circle.
- */
- final float offset1 = numbersRadius;
- // cos(30) = a / r => r * cos(30)
- final float offset2 = numbersRadius * COSINE_30_DEGREES;
- // sin(30) = o / r => r * sin(30)
- final float offset3 = numbersRadius * SINE_30_DEGREES;
-
+ private static void calculatePositions(Paint paint, float radius, float xCenter, float yCenter,
+ float textSize, float[] x, float[] y) {
+ // Adjust yCenter to account for the text's baseline.
paint.setTextSize(textSize);
- // We'll need yTextBase to be slightly lower to account for the text's baseline.
yCenter -= (paint.descent() + paint.ascent()) / 2;
- textGridHeights[0] = yCenter - offset1;
- textGridWidths[0] = xCenter - offset1;
- textGridHeights[1] = yCenter - offset2;
- textGridWidths[1] = xCenter - offset2;
- textGridHeights[2] = yCenter - offset3;
- textGridWidths[2] = xCenter - offset3;
- textGridHeights[3] = yCenter;
- textGridWidths[3] = xCenter;
- textGridHeights[4] = yCenter + offset3;
- textGridWidths[4] = xCenter + offset3;
- textGridHeights[5] = yCenter + offset2;
- textGridWidths[5] = xCenter + offset2;
- textGridHeights[6] = yCenter + offset1;
- textGridWidths[6] = xCenter + offset1;
+ for (int i = 0; i < NUM_POSITIONS; i++) {
+ x[i] = xCenter - radius * COS_30[i];
+ y[i] = yCenter - radius * SIN_30[i];
+ }
}
/**
* Draw the 12 text values at the positions specified by the textGrid parameters.
*/
private void drawTextElements(Canvas canvas, float textSize, Typeface typeface, String[] texts,
- float[] textGridWidths, float[] textGridHeights, Paint paint, int color, int alpha) {
+ float[] textX, float[] textY, Paint paint, int alpha, boolean showActivated,
+ int activatedDegrees, boolean activatedOnly) {
paint.setTextSize(textSize);
paint.setTypeface(typeface);
- paint.setColor(color);
- paint.setAlpha(getMultipliedAlpha(color, alpha));
- canvas.drawText(texts[0], textGridWidths[3], textGridHeights[0], paint);
- canvas.drawText(texts[1], textGridWidths[4], textGridHeights[1], paint);
- canvas.drawText(texts[2], textGridWidths[5], textGridHeights[2], paint);
- canvas.drawText(texts[3], textGridWidths[6], textGridHeights[3], paint);
- canvas.drawText(texts[4], textGridWidths[5], textGridHeights[4], paint);
- canvas.drawText(texts[5], textGridWidths[4], textGridHeights[5], paint);
- canvas.drawText(texts[6], textGridWidths[3], textGridHeights[6], paint);
- canvas.drawText(texts[7], textGridWidths[2], textGridHeights[5], paint);
- canvas.drawText(texts[8], textGridWidths[1], textGridHeights[4], paint);
- canvas.drawText(texts[9], textGridWidths[0], textGridHeights[3], paint);
- canvas.drawText(texts[10], textGridWidths[1], textGridHeights[2], paint);
- canvas.drawText(texts[11], textGridWidths[2], textGridHeights[1], paint);
- }
- // Used for animating the hours by changing their radius
- @SuppressWarnings("unused")
- private void setAnimationRadiusMultiplierHours(float animationRadiusMultiplier) {
- mAnimationRadiusMultiplier[HOURS] = animationRadiusMultiplier;
- mAnimationRadiusMultiplier[HOURS_INNER] = animationRadiusMultiplier;
- }
+ // The activated index can touch a range of elements.
+ final float activatedIndex = activatedDegrees / (360.0f / NUM_POSITIONS);
+ final int activatedFloor = (int) activatedIndex;
+ final int activatedCeil = ((int) Math.ceil(activatedIndex)) % NUM_POSITIONS;
- // Used for animating the minutes by changing their radius
- @SuppressWarnings("unused")
- private void setAnimationRadiusMultiplierMinutes(float animationRadiusMultiplier) {
- mAnimationRadiusMultiplier[MINUTES] = animationRadiusMultiplier;
- }
+ for (int i = 0; i < 12; i++) {
+ final boolean activated = (activatedFloor == i || activatedCeil == i);
+ if (activatedOnly && !activated) {
+ continue;
+ }
- private static ObjectAnimator getRadiusDisappearAnimator(Object target,
- String radiusPropertyName, InvalidateUpdateListener updateListener,
- float midRadiusMultiplier, float endRadiusMultiplier) {
- Keyframe kf0, kf1, kf2;
- float midwayPoint = 0.2f;
- int duration = 500;
-
- kf0 = Keyframe.ofFloat(0f, 1);
- kf1 = Keyframe.ofFloat(midwayPoint, midRadiusMultiplier);
- kf2 = Keyframe.ofFloat(1f, endRadiusMultiplier);
- PropertyValuesHolder radiusDisappear = PropertyValuesHolder.ofKeyframe(
- radiusPropertyName, kf0, kf1, kf2);
-
- ObjectAnimator animator = ObjectAnimator.ofPropertyValuesHolder(
- target, radiusDisappear).setDuration(duration);
- animator.addUpdateListener(updateListener);
- return animator;
- }
+ final int stateMask = StateSet.VIEW_STATE_ENABLED
+ | (showActivated && activated ? StateSet.VIEW_STATE_ACTIVATED : 0);
+ final int color = mNumbersTextColor.getColorForState(StateSet.get(stateMask), 0);
+ paint.setColor(color);
+ paint.setAlpha(getMultipliedAlpha(color, alpha));
- private static ObjectAnimator getRadiusReappearAnimator(Object target,
- String radiusPropertyName, InvalidateUpdateListener updateListener,
- float midRadiusMultiplier, float endRadiusMultiplier) {
- Keyframe kf0, kf1, kf2, kf3;
- float midwayPoint = 0.2f;
- int duration = 500;
-
- // Set up animator for reappearing.
- float delayMultiplier = 0.25f;
- float transitionDurationMultiplier = 1f;
- float totalDurationMultiplier = transitionDurationMultiplier + delayMultiplier;
- int totalDuration = (int) (duration * totalDurationMultiplier);
- float delayPoint = (delayMultiplier * duration) / totalDuration;
- midwayPoint = 1 - (midwayPoint * (1 - delayPoint));
-
- kf0 = Keyframe.ofFloat(0f, endRadiusMultiplier);
- kf1 = Keyframe.ofFloat(delayPoint, endRadiusMultiplier);
- kf2 = Keyframe.ofFloat(midwayPoint, midRadiusMultiplier);
- kf3 = Keyframe.ofFloat(1f, 1);
- PropertyValuesHolder radiusReappear = PropertyValuesHolder.ofKeyframe(
- radiusPropertyName, kf0, kf1, kf2, kf3);
-
- ObjectAnimator animator = ObjectAnimator.ofPropertyValuesHolder(
- target, radiusReappear).setDuration(totalDuration);
- animator.addUpdateListener(updateListener);
- return animator;
+ canvas.drawText(texts[i], textX[i], textY[i], paint);
+ }
}
private static ObjectAnimator getFadeOutAnimator(IntHolder target, int startAlpha, int endAlpha,
InvalidateUpdateListener updateListener) {
- int duration = 500;
- ObjectAnimator animator = ObjectAnimator.ofInt(target, "value", startAlpha, endAlpha);
- animator.setDuration(duration);
+ final ObjectAnimator animator = ObjectAnimator.ofInt(target, "value", startAlpha, endAlpha);
+ animator.setDuration(FADE_OUT_DURATION);
animator.addUpdateListener(updateListener);
-
return animator;
}
private static ObjectAnimator getFadeInAnimator(IntHolder target, int startAlpha, int endAlpha,
InvalidateUpdateListener updateListener) {
- Keyframe kf0, kf1, kf2;
- int duration = 500;
-
- // Set up animator for reappearing.
- float delayMultiplier = 0.25f;
- float transitionDurationMultiplier = 1f;
- float totalDurationMultiplier = transitionDurationMultiplier + delayMultiplier;
- int totalDuration = (int) (duration * totalDurationMultiplier);
- float delayPoint = (delayMultiplier * duration) / totalDuration;
+ final float delayMultiplier = 0.25f;
+ final float transitionDurationMultiplier = 1f;
+ final float totalDurationMultiplier = transitionDurationMultiplier + delayMultiplier;
+ final int totalDuration = (int) (FADE_IN_DURATION * totalDurationMultiplier);
+ final float delayPoint = (delayMultiplier * FADE_IN_DURATION) / totalDuration;
+ final Keyframe kf0, kf1, kf2;
kf0 = Keyframe.ofInt(0f, startAlpha);
kf1 = Keyframe.ofInt(delayPoint, startAlpha);
kf2 = Keyframe.ofInt(1f, endAlpha);
- PropertyValuesHolder fadeIn = PropertyValuesHolder.ofKeyframe("value", kf0, kf1, kf2);
+ final PropertyValuesHolder fadeIn = PropertyValuesHolder.ofKeyframe("value", kf0, kf1, kf2);
- ObjectAnimator animator = ObjectAnimator.ofPropertyValuesHolder(
- target, fadeIn).setDuration(totalDuration);
+ final ObjectAnimator animator = ObjectAnimator.ofPropertyValuesHolder(target, fadeIn);
+ animator.setDuration(totalDuration);
animator.addUpdateListener(updateListener);
return animator;
}
@@ -1080,29 +980,23 @@ public class RadialTimePickerView extends View implements View.OnTouchListener {
private void startHoursToMinutesAnimation() {
if (mHoursToMinutesAnims.size() == 0) {
- mHoursToMinutesAnims.add(getRadiusDisappearAnimator(this,
- "animationRadiusMultiplierHours", mInvalidateUpdateListener,
- mTransitionMidRadiusMultiplier, mTransitionEndRadiusMultiplier));
mHoursToMinutesAnims.add(getFadeOutAnimator(mAlpha[HOURS],
ALPHA_OPAQUE, ALPHA_TRANSPARENT, mInvalidateUpdateListener));
mHoursToMinutesAnims.add(getFadeOutAnimator(mAlphaSelector[HOURS][SELECTOR_CIRCLE],
- ALPHA_SELECTOR, ALPHA_TRANSPARENT, mInvalidateUpdateListener));
+ ALPHA_OPAQUE, ALPHA_TRANSPARENT, mInvalidateUpdateListener));
mHoursToMinutesAnims.add(getFadeOutAnimator(mAlphaSelector[HOURS][SELECTOR_DOT],
ALPHA_OPAQUE, ALPHA_TRANSPARENT, mInvalidateUpdateListener));
mHoursToMinutesAnims.add(getFadeOutAnimator(mAlphaSelector[HOURS][SELECTOR_LINE],
- ALPHA_SELECTOR, ALPHA_TRANSPARENT, mInvalidateUpdateListener));
+ ALPHA_OPAQUE, ALPHA_TRANSPARENT, mInvalidateUpdateListener));
- mHoursToMinutesAnims.add(getRadiusReappearAnimator(this,
- "animationRadiusMultiplierMinutes", mInvalidateUpdateListener,
- mTransitionMidRadiusMultiplier, mTransitionEndRadiusMultiplier));
mHoursToMinutesAnims.add(getFadeInAnimator(mAlpha[MINUTES],
ALPHA_TRANSPARENT, ALPHA_OPAQUE, mInvalidateUpdateListener));
mHoursToMinutesAnims.add(getFadeInAnimator(mAlphaSelector[MINUTES][SELECTOR_CIRCLE],
- ALPHA_TRANSPARENT, ALPHA_SELECTOR, mInvalidateUpdateListener));
+ ALPHA_TRANSPARENT, ALPHA_OPAQUE, mInvalidateUpdateListener));
mHoursToMinutesAnims.add(getFadeInAnimator(mAlphaSelector[MINUTES][SELECTOR_DOT],
ALPHA_TRANSPARENT, ALPHA_OPAQUE, mInvalidateUpdateListener));
mHoursToMinutesAnims.add(getFadeInAnimator(mAlphaSelector[MINUTES][SELECTOR_LINE],
- ALPHA_TRANSPARENT, ALPHA_SELECTOR, mInvalidateUpdateListener));
+ ALPHA_TRANSPARENT, ALPHA_OPAQUE, mInvalidateUpdateListener));
}
if (mTransition != null && mTransition.isRunning()) {
@@ -1115,29 +1009,23 @@ public class RadialTimePickerView extends View implements View.OnTouchListener {
private void startMinutesToHoursAnimation() {
if (mMinuteToHoursAnims.size() == 0) {
- mMinuteToHoursAnims.add(getRadiusDisappearAnimator(this,
- "animationRadiusMultiplierMinutes", mInvalidateUpdateListener,
- mTransitionMidRadiusMultiplier, mTransitionEndRadiusMultiplier));
mMinuteToHoursAnims.add(getFadeOutAnimator(mAlpha[MINUTES],
ALPHA_OPAQUE, ALPHA_TRANSPARENT, mInvalidateUpdateListener));
mMinuteToHoursAnims.add(getFadeOutAnimator(mAlphaSelector[MINUTES][SELECTOR_CIRCLE],
- ALPHA_SELECTOR, ALPHA_TRANSPARENT, mInvalidateUpdateListener));
+ ALPHA_OPAQUE, ALPHA_TRANSPARENT, mInvalidateUpdateListener));
mMinuteToHoursAnims.add(getFadeOutAnimator(mAlphaSelector[MINUTES][SELECTOR_DOT],
ALPHA_OPAQUE, ALPHA_TRANSPARENT, mInvalidateUpdateListener));
mMinuteToHoursAnims.add(getFadeOutAnimator(mAlphaSelector[MINUTES][SELECTOR_LINE],
- ALPHA_SELECTOR, ALPHA_TRANSPARENT, mInvalidateUpdateListener));
+ ALPHA_OPAQUE, ALPHA_TRANSPARENT, mInvalidateUpdateListener));
- mMinuteToHoursAnims.add(getRadiusReappearAnimator(this,
- "animationRadiusMultiplierHours", mInvalidateUpdateListener,
- mTransitionMidRadiusMultiplier, mTransitionEndRadiusMultiplier));
mMinuteToHoursAnims.add(getFadeInAnimator(mAlpha[HOURS],
ALPHA_TRANSPARENT, ALPHA_OPAQUE, mInvalidateUpdateListener));
mMinuteToHoursAnims.add(getFadeInAnimator(mAlphaSelector[HOURS][SELECTOR_CIRCLE],
- ALPHA_TRANSPARENT, ALPHA_SELECTOR, mInvalidateUpdateListener));
+ ALPHA_TRANSPARENT, ALPHA_OPAQUE, mInvalidateUpdateListener));
mMinuteToHoursAnims.add(getFadeInAnimator(mAlphaSelector[HOURS][SELECTOR_DOT],
ALPHA_TRANSPARENT, ALPHA_OPAQUE, mInvalidateUpdateListener));
mMinuteToHoursAnims.add(getFadeInAnimator(mAlphaSelector[HOURS][SELECTOR_LINE],
- ALPHA_TRANSPARENT, ALPHA_SELECTOR, mInvalidateUpdateListener));
+ ALPHA_TRANSPARENT, ALPHA_OPAQUE, mInvalidateUpdateListener));
}
if (mTransition != null && mTransition.isRunning()) {
@@ -1148,20 +1036,21 @@ public class RadialTimePickerView extends View implements View.OnTouchListener {
mTransition.start();
}
- private int getDegreesFromXY(float x, float y) {
+ private int getDegreesFromXY(float x, float y, boolean constrainOutside) {
final double hypotenuse = Math.sqrt(
(y - mYCenter) * (y - mYCenter) + (x - mXCenter) * (x - mXCenter));
// Basic check if we're outside the range of the disk
- if (hypotenuse > mCircleRadius[HOURS]) {
+ if (constrainOutside && hypotenuse > mCircleRadius) {
return -1;
}
+
// Check
if (mIs24HourMode && mShowHours) {
if (hypotenuse >= mMinHypotenuseForInnerNumber
&& hypotenuse <= mHalfwayHypotenusePoint) {
mIsOnInnerCircle = true;
- } else if (hypotenuse <= mMaxHypotenuseForOuterNumber
+ } else if ((hypotenuse <= mMaxHypotenuseForOuterNumber || !constrainOutside)
&& hypotenuse >= mHalfwayHypotenusePoint) {
mIsOnInnerCircle = false;
} else {
@@ -1169,11 +1058,12 @@ public class RadialTimePickerView extends View implements View.OnTouchListener {
}
} else {
final int index = (mShowHours) ? HOURS : MINUTES;
- final float length = (mCircleRadius[index] * mNumbersRadiusMultiplier[index]);
- final int distanceToNumber = (int) Math.abs(hypotenuse - length);
+ final float length = (mCircleRadius * mNumbersRadiusMultiplier[index]);
+ final int distanceToNumber = (int) (hypotenuse - length);
final int maxAllowedDistance =
- (int) (mCircleRadius[index] * (1 - mNumbersRadiusMultiplier[index]));
- if (distanceToNumber > maxAllowedDistance) {
+ (int) (mCircleRadius * (1 - mNumbersRadiusMultiplier[index]));
+ if (distanceToNumber < -maxAllowedDistance
+ || (constrainOutside && distanceToNumber > maxAllowedDistance)) {
return -1;
}
}
@@ -1203,7 +1093,7 @@ public class RadialTimePickerView extends View implements View.OnTouchListener {
boolean mChangedDuringTouch = false;
@Override
- public boolean onTouch(View v, MotionEvent event) {
+ public boolean onTouchEvent(MotionEvent event) {
if (!mInputEnabled) {
return true;
}
@@ -1240,7 +1130,7 @@ public class RadialTimePickerView extends View implements View.OnTouchListener {
// Calling getDegreesFromXY has side effects, so cache
// whether we used to be on the inner circle.
final boolean wasOnInnerCircle = mIsOnInnerCircle;
- final int degrees = getDegreesFromXY(x, y);
+ final int degrees = getDegreesFromXY(x, y, false);
if (degrees == -1) {
return false;
}
@@ -1381,7 +1271,7 @@ public class RadialTimePickerView extends View implements View.OnTouchListener {
@Override
protected int getVirtualViewAt(float x, float y) {
final int id;
- final int degrees = getDegreesFromXY(x, y);
+ final int degrees = getDegreesFromXY(x, y, true);
if (degrees != -1) {
final int snapDegrees = snapOnly30s(degrees, 0) % 360;
if (mShowHours) {
@@ -1523,16 +1413,16 @@ public class RadialTimePickerView extends View implements View.OnTouchListener {
if (type == TYPE_HOUR) {
final boolean innerCircle = mIs24HourMode && value > 0 && value <= 12;
if (innerCircle) {
- centerRadius = mCircleRadius[HOURS_INNER] * mNumbersRadiusMultiplier[HOURS_INNER];
+ centerRadius = mCircleRadius * mNumbersRadiusMultiplier[HOURS_INNER];
radius = mSelectionRadius[HOURS_INNER];
} else {
- centerRadius = mCircleRadius[HOURS] * mNumbersRadiusMultiplier[HOURS];
+ centerRadius = mCircleRadius * mNumbersRadiusMultiplier[HOURS];
radius = mSelectionRadius[HOURS];
}
degrees = getDegreesForHour(value);
} else if (type == TYPE_MINUTE) {
- centerRadius = mCircleRadius[MINUTES] * mNumbersRadiusMultiplier[MINUTES];
+ centerRadius = mCircleRadius * mNumbersRadiusMultiplier[MINUTES];
degrees = getDegreesForMinute(value);
radius = mSelectionRadius[MINUTES];
} else {
diff --git a/core/java/android/widget/RadioButton.java b/core/java/android/widget/RadioButton.java
index afc4830..82280b4 100644
--- a/core/java/android/widget/RadioButton.java
+++ b/core/java/android/widget/RadioButton.java
@@ -79,15 +79,17 @@ public class RadioButton extends CompoundButton {
}
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
- super.onInitializeAccessibilityEvent(event);
+ public void onInitializeAccessibilityEventInternal(AccessibilityEvent event) {
+ super.onInitializeAccessibilityEventInternal(event);
event.setClassName(RadioButton.class.getName());
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
- super.onInitializeAccessibilityNodeInfo(info);
+ public void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) {
+ super.onInitializeAccessibilityNodeInfoInternal(info);
info.setClassName(RadioButton.class.getName());
}
}
diff --git a/core/java/android/widget/RadioGroup.java b/core/java/android/widget/RadioGroup.java
index 78d05b0..c0f60eb 100644
--- a/core/java/android/widget/RadioGroup.java
+++ b/core/java/android/widget/RadioGroup.java
@@ -240,15 +240,17 @@ public class RadioGroup extends LinearLayout {
return new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
- super.onInitializeAccessibilityEvent(event);
+ public void onInitializeAccessibilityEventInternal(AccessibilityEvent event) {
+ super.onInitializeAccessibilityEventInternal(event);
event.setClassName(RadioGroup.class.getName());
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
- super.onInitializeAccessibilityNodeInfo(info);
+ public void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) {
+ super.onInitializeAccessibilityNodeInfoInternal(info);
info.setClassName(RadioGroup.class.getName());
}
diff --git a/core/java/android/widget/RatingBar.java b/core/java/android/widget/RatingBar.java
index 82b490e..2d0649d 100644
--- a/core/java/android/widget/RatingBar.java
+++ b/core/java/android/widget/RatingBar.java
@@ -331,15 +331,17 @@ public class RatingBar extends AbsSeekBar {
super.setMax(max);
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
- super.onInitializeAccessibilityEvent(event);
+ public void onInitializeAccessibilityEventInternal(AccessibilityEvent event) {
+ super.onInitializeAccessibilityEventInternal(event);
event.setClassName(RatingBar.class.getName());
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
- super.onInitializeAccessibilityNodeInfo(info);
+ public void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) {
+ super.onInitializeAccessibilityNodeInfoInternal(info);
info.setClassName(RatingBar.class.getName());
}
}
diff --git a/core/java/android/widget/RelativeLayout.java b/core/java/android/widget/RelativeLayout.java
index 5b604cd..71f4da0 100644
--- a/core/java/android/widget/RelativeLayout.java
+++ b/core/java/android/widget/RelativeLayout.java
@@ -201,7 +201,6 @@ public class RelativeLayout extends ViewGroup {
private static final int VALUE_NOT_SET = Integer.MIN_VALUE;
private View mBaselineView = null;
- private boolean mHasBaselineAlignedChild;
private int mGravity = Gravity.START | Gravity.TOP;
private final Rect mContentBounds = new Rect();
@@ -417,8 +416,6 @@ public class RelativeLayout extends ViewGroup {
height = myHeight;
}
- mHasBaselineAlignedChild = false;
-
View ignore = null;
int gravity = mGravity & Gravity.RELATIVE_HORIZONTAL_GRAVITY_MASK;
final boolean horizontalGravity = gravity != Gravity.START && gravity != 0;
@@ -473,11 +470,11 @@ public class RelativeLayout extends ViewGroup {
final int targetSdkVersion = getContext().getApplicationInfo().targetSdkVersion;
for (int i = 0; i < count; i++) {
- View child = views[i];
+ final View child = views[i];
if (child.getVisibility() != GONE) {
- LayoutParams params = (LayoutParams) child.getLayoutParams();
-
- applyVerticalSizeRules(params, myHeight);
+ final LayoutParams params = (LayoutParams) child.getLayoutParams();
+
+ applyVerticalSizeRules(params, myHeight, child.getBaseline());
measureChild(child, params, myWidth, myHeight);
if (positionChildVertical(child, params, myHeight, isWrapContentHeight)) {
offsetVerticalAxis = true;
@@ -519,26 +516,6 @@ public class RelativeLayout extends ViewGroup {
}
}
- if (mHasBaselineAlignedChild) {
- for (int i = 0; i < count; i++) {
- View child = getChildAt(i);
- if (child.getVisibility() != GONE) {
- LayoutParams params = (LayoutParams) child.getLayoutParams();
- alignBaseline(child, params);
-
- if (child != ignore || verticalGravity) {
- left = Math.min(left, params.mLeft - params.leftMargin);
- top = Math.min(top, params.mTop - params.topMargin);
- }
-
- if (child != ignore || horizontalGravity) {
- right = Math.max(right, params.mRight + params.rightMargin);
- bottom = Math.max(bottom, params.mBottom + params.bottomMargin);
- }
- }
- }
- }
-
if (isWrapContentWidth) {
// Width already has left padding in it since it was calculated by looking at
// the right of each child view
@@ -638,39 +615,22 @@ public class RelativeLayout extends ViewGroup {
params.mRight -= offsetWidth;
}
}
-
}
- setMeasuredDimension(width, height);
- }
-
- private void alignBaseline(View child, LayoutParams params) {
- final int layoutDirection = getLayoutDirection();
- int[] rules = params.getRules(layoutDirection);
- int anchorBaseline = getRelatedViewBaseline(rules, ALIGN_BASELINE);
-
- if (anchorBaseline != -1) {
- LayoutParams anchorParams = getRelatedViewParams(rules, ALIGN_BASELINE);
- if (anchorParams != null) {
- int offset = anchorParams.mTop + anchorBaseline;
- int baseline = child.getBaseline();
- if (baseline != -1) {
- offset -= baseline;
- }
- int height = params.mBottom - params.mTop;
- params.mTop = offset;
- params.mBottom = params.mTop + height;
+ // Use the bottom-most view as the baseline.
+ View baselineView = null;
+ int baseline = 0;
+ for (int i = 0; i < count; i++) {
+ final View child = getChildAt(i);
+ final int childBaseline = child.getBaseline();
+ if (childBaseline >= baseline) {
+ baselineView = child;
+ baseline = childBaseline;
}
}
+ mBaselineView = baselineView;
- if (mBaselineView == null) {
- mBaselineView = child;
- } else {
- LayoutParams lp = (LayoutParams) mBaselineView.getLayoutParams();
- if (params.mTop < lp.mTop || (params.mTop == lp.mTop && params.mLeft < lp.mLeft)) {
- mBaselineView = child;
- }
- }
+ setMeasuredDimension(width, height);
}
/**
@@ -950,8 +910,20 @@ public class RelativeLayout extends ViewGroup {
}
}
- private void applyVerticalSizeRules(LayoutParams childParams, int myHeight) {
- int[] rules = childParams.getRules();
+ private void applyVerticalSizeRules(LayoutParams childParams, int myHeight, int myBaseline) {
+ final int[] rules = childParams.getRules();
+
+ // Baseline alignment overrides any explicitly specified top or bottom.
+ int baselineOffset = getRelatedViewBaselineOffset(rules);
+ if (baselineOffset != -1) {
+ if (myBaseline != -1) {
+ baselineOffset -= myBaseline;
+ }
+ childParams.mTop = baselineOffset;
+ childParams.mBottom = VALUE_NOT_SET;
+ return;
+ }
+
RelativeLayout.LayoutParams anchorParams;
childParams.mTop = VALUE_NOT_SET;
@@ -1000,10 +972,6 @@ public class RelativeLayout extends ViewGroup {
childParams.mBottom = myHeight - mPaddingBottom - childParams.bottomMargin;
}
}
-
- if (rules[ALIGN_BASELINE] != 0) {
- mHasBaselineAlignedChild = true;
- }
}
private View getRelatedView(int[] rules, int relation) {
@@ -1038,10 +1006,17 @@ public class RelativeLayout extends ViewGroup {
return null;
}
- private int getRelatedViewBaseline(int[] rules, int relation) {
- View v = getRelatedView(rules, relation);
+ private int getRelatedViewBaselineOffset(int[] rules) {
+ final View v = getRelatedView(rules, ALIGN_BASELINE);
if (v != null) {
- return v.getBaseline();
+ final int baseline = v.getBaseline();
+ if (baseline != -1) {
+ final ViewGroup.LayoutParams params = v.getLayoutParams();
+ if (params instanceof LayoutParams) {
+ final LayoutParams anchorParams = (LayoutParams) v.getLayoutParams();
+ return anchorParams.mTop + baseline;
+ }
+ }
}
return -1;
}
@@ -1104,8 +1079,9 @@ public class RelativeLayout extends ViewGroup {
return new LayoutParams(p);
}
+ /** @hide */
@Override
- public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
+ public boolean dispatchPopulateAccessibilityEventInternal(AccessibilityEvent event) {
if (mTopToBottomLeftToRightSet == null) {
mTopToBottomLeftToRightSet = new TreeSet<View>(new TopToBottomLeftToRightComparator());
}
@@ -1127,15 +1103,17 @@ public class RelativeLayout extends ViewGroup {
return false;
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
- super.onInitializeAccessibilityEvent(event);
+ public void onInitializeAccessibilityEventInternal(AccessibilityEvent event) {
+ super.onInitializeAccessibilityEventInternal(event);
event.setClassName(RelativeLayout.class.getName());
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
- super.onInitializeAccessibilityNodeInfo(info);
+ public void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) {
+ super.onInitializeAccessibilityNodeInfoInternal(info);
info.setClassName(RelativeLayout.class.getName());
}
diff --git a/core/java/android/widget/ResourceCursorAdapter.java b/core/java/android/widget/ResourceCursorAdapter.java
index 7341c2c..100f919 100644
--- a/core/java/android/widget/ResourceCursorAdapter.java
+++ b/core/java/android/widget/ResourceCursorAdapter.java
@@ -17,7 +17,9 @@
package android.widget;
import android.content.Context;
+import android.content.res.Resources;
import android.database.Cursor;
+import android.view.ContextThemeWrapper;
import android.view.View;
import android.view.ViewGroup;
import android.view.LayoutInflater;
@@ -31,9 +33,10 @@ public abstract class ResourceCursorAdapter extends CursorAdapter {
private int mLayout;
private int mDropDownLayout;
-
+
private LayoutInflater mInflater;
-
+ private LayoutInflater mDropDownInflater;
+
/**
* Constructor the enables auto-requery.
*
@@ -52,8 +55,9 @@ public abstract class ResourceCursorAdapter extends CursorAdapter {
super(context, c);
mLayout = mDropDownLayout = layout;
mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+ mDropDownInflater = mInflater;
}
-
+
/**
* Constructor with default behavior as per
* {@link CursorAdapter#CursorAdapter(Context, Cursor, boolean)}; it is recommended
@@ -74,6 +78,7 @@ public abstract class ResourceCursorAdapter extends CursorAdapter {
super(context, c, autoRequery);
mLayout = mDropDownLayout = layout;
mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+ mDropDownInflater = mInflater;
}
/**
@@ -91,11 +96,37 @@ public abstract class ResourceCursorAdapter extends CursorAdapter {
super(context, c, flags);
mLayout = mDropDownLayout = layout;
mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+ mDropDownInflater = mInflater;
+ }
+
+ /**
+ * Sets the {@link android.content.res.Resources.Theme} against which drop-down views are
+ * inflated.
+ * <p>
+ * By default, drop-down views are inflated against the theme of the
+ * {@link Context} passed to the adapter's constructor.
+ *
+ * @param theme the theme against which to inflate drop-down views or
+ * {@code null} to use the theme from the adapter's context
+ * @see #newDropDownView(Context, Cursor, ViewGroup)
+ */
+ @Override
+ public void setDropDownViewTheme(Resources.Theme theme) {
+ super.setDropDownViewTheme(theme);
+
+ if (theme == null) {
+ mDropDownInflater = null;
+ } else if (theme == mInflater.getContext().getTheme()) {
+ mDropDownInflater = mInflater;
+ } else {
+ final Context context = new ContextThemeWrapper(mContext, theme);
+ mDropDownInflater = LayoutInflater.from(context);
+ }
}
/**
* Inflates view(s) from the specified XML file.
- *
+ *
* @see android.widget.CursorAdapter#newView(android.content.Context,
* android.database.Cursor, ViewGroup)
*/
@@ -106,7 +137,7 @@ public abstract class ResourceCursorAdapter extends CursorAdapter {
@Override
public View newDropDownView(Context context, Cursor cursor, ViewGroup parent) {
- return mInflater.inflate(mDropDownLayout, parent, false);
+ return mDropDownInflater.inflate(mDropDownLayout, parent, false);
}
/**
diff --git a/core/java/android/widget/ScrollBarDrawable.java b/core/java/android/widget/ScrollBarDrawable.java
index 10e9ff4..b12c581 100644
--- a/core/java/android/widget/ScrollBarDrawable.java
+++ b/core/java/android/widget/ScrollBarDrawable.java
@@ -23,62 +23,73 @@ import android.graphics.Rect;
import android.graphics.drawable.Drawable;
/**
- * This is only used by View for displaying its scroll bars. It should probably
+ * This is only used by View for displaying its scroll bars. It should probably
* be moved in to the view package since it is used in that lower-level layer.
* For now, we'll hide it so it can be cleaned up later.
+ *
* {@hide}
*/
-public class ScrollBarDrawable extends Drawable {
- private static final int[] STATE_ENABLED = new int[] { android.R.attr.state_enabled };
-
+public class ScrollBarDrawable extends Drawable implements Drawable.Callback {
private Drawable mVerticalTrack;
private Drawable mHorizontalTrack;
private Drawable mVerticalThumb;
private Drawable mHorizontalThumb;
+
private int mRange;
private int mOffset;
private int mExtent;
+
private boolean mVertical;
- private boolean mChanged;
+ private boolean mBoundsChanged;
private boolean mRangeChanged;
- private final Rect mTempBounds = new Rect();
private boolean mAlwaysDrawHorizontalTrack;
private boolean mAlwaysDrawVerticalTrack;
- public ScrollBarDrawable() {
- }
+ private int mAlpha = 255;
+ private boolean mHasSetAlpha;
+
+ private ColorFilter mColorFilter;
+ private boolean mHasSetColorFilter;
/**
- * Indicate whether the horizontal scrollbar track should always be drawn regardless of the
- * extent. Defaults to false.
+ * Indicate whether the horizontal scrollbar track should always be drawn
+ * regardless of the extent. Defaults to false.
+ *
+ * @param alwaysDrawTrack Whether the track should always be drawn
*
- * @param alwaysDrawTrack Set to true if the track should always be drawn
+ * @see #getAlwaysDrawHorizontalTrack()
*/
public void setAlwaysDrawHorizontalTrack(boolean alwaysDrawTrack) {
mAlwaysDrawHorizontalTrack = alwaysDrawTrack;
}
/**
- * Indicate whether the vertical scrollbar track should always be drawn regardless of the
- * extent. Defaults to false.
+ * Indicate whether the vertical scrollbar track should always be drawn
+ * regardless of the extent. Defaults to false.
*
- * @param alwaysDrawTrack Set to true if the track should always be drawn
+ * @param alwaysDrawTrack Whether the track should always be drawn
+ *
+ * @see #getAlwaysDrawVerticalTrack()
*/
public void setAlwaysDrawVerticalTrack(boolean alwaysDrawTrack) {
mAlwaysDrawVerticalTrack = alwaysDrawTrack;
}
/**
- * Indicates whether the vertical scrollbar track should always be drawn regardless of the
- * extent.
+ * @return whether the vertical scrollbar track should always be drawn
+ * regardless of the extent.
+ *
+ * @see #setAlwaysDrawVerticalTrack(boolean)
*/
public boolean getAlwaysDrawVerticalTrack() {
return mAlwaysDrawVerticalTrack;
}
/**
- * Indicates whether the horizontal scrollbar track should always be drawn regardless of the
- * extent.
+ * @return whether the horizontal scrollbar track should always be drawn
+ * regardless of the extent.
+ *
+ * @see #setAlwaysDrawHorizontalTrack(boolean)
*/
public boolean getAlwaysDrawHorizontalTrack() {
return mAlwaysDrawHorizontalTrack;
@@ -86,17 +97,18 @@ public class ScrollBarDrawable extends Drawable {
public void setParameters(int range, int offset, int extent, boolean vertical) {
if (mVertical != vertical) {
- mChanged = true;
+ mVertical = vertical;
+
+ mBoundsChanged = true;
}
if (mRange != range || mOffset != offset || mExtent != extent) {
+ mRange = range;
+ mOffset = offset;
+ mExtent = extent;
+
mRangeChanged = true;
}
-
- mRange = range;
- mOffset = offset;
- mExtent = extent;
- mVertical = vertical;
}
@Override
@@ -112,27 +124,29 @@ public class ScrollBarDrawable extends Drawable {
drawThumb = false;
}
- Rect r = getBounds();
+ final Rect r = getBounds();
if (canvas.quickReject(r.left, r.top, r.right, r.bottom, Canvas.EdgeType.AA)) {
return;
}
+
if (drawTrack) {
drawTrack(canvas, r, vertical);
}
if (drawThumb) {
- int size = vertical ? r.height() : r.width();
- int thickness = vertical ? r.width() : r.height();
- int length = Math.round((float) size * extent / range);
- int offset = Math.round((float) (size - length) * mOffset / (range - extent));
+ final int size = vertical ? r.height() : r.width();
+ final int thickness = vertical ? r.width() : r.height();
+ final int minLength = thickness * 2;
- // avoid the tiny thumb
- int minLength = thickness * 2;
+ // Avoid the tiny thumb.
+ int length = Math.round((float) size * extent / range);
if (length < minLength) {
length = minLength;
}
- // avoid the too-big thumb
- if (offset + length > size) {
+
+ // Avoid the too-big thumb.
+ int offset = Math.round((float) (size - length) * mOffset / (range - extent));
+ if (offset > size - length) {
offset = size - length;
}
@@ -143,80 +157,128 @@ public class ScrollBarDrawable extends Drawable {
@Override
protected void onBoundsChange(Rect bounds) {
super.onBoundsChange(bounds);
- mChanged = true;
+ mBoundsChanged = true;
}
- protected void drawTrack(Canvas canvas, Rect bounds, boolean vertical) {
- Drawable track;
+ @Override
+ public boolean isStateful() {
+ return (mVerticalTrack != null && mVerticalTrack.isStateful())
+ || (mVerticalThumb != null && mVerticalThumb.isStateful())
+ || (mHorizontalTrack != null && mHorizontalTrack.isStateful())
+ || (mHorizontalThumb != null && mHorizontalThumb.isStateful())
+ || super.isStateful();
+ }
+
+ @Override
+ protected boolean onStateChange(int[] state) {
+ boolean changed = super.onStateChange(state);
+ if (mVerticalTrack != null) {
+ changed |= mVerticalTrack.setState(state);
+ }
+ if (mVerticalThumb != null) {
+ changed |= mVerticalThumb.setState(state);
+ }
+ if (mHorizontalTrack != null) {
+ changed |= mHorizontalTrack.setState(state);
+ }
+ if (mHorizontalThumb != null) {
+ changed |= mHorizontalThumb.setState(state);
+ }
+ return changed;
+ }
+
+ private void drawTrack(Canvas canvas, Rect bounds, boolean vertical) {
+ final Drawable track;
if (vertical) {
track = mVerticalTrack;
} else {
track = mHorizontalTrack;
}
+
if (track != null) {
- if (mChanged) {
+ if (mBoundsChanged) {
track.setBounds(bounds);
}
track.draw(canvas);
}
}
- protected void drawThumb(Canvas canvas, Rect bounds, int offset, int length, boolean vertical) {
- final Rect thumbRect = mTempBounds;
- final boolean changed = mRangeChanged || mChanged;
- if (changed) {
- if (vertical) {
- thumbRect.set(bounds.left, bounds.top + offset,
- bounds.right, bounds.top + offset + length);
- } else {
- thumbRect.set(bounds.left + offset, bounds.top,
- bounds.left + offset + length, bounds.bottom);
- }
- }
-
+ private void drawThumb(Canvas canvas, Rect bounds, int offset, int length, boolean vertical) {
+ final boolean changed = mRangeChanged || mBoundsChanged;
if (vertical) {
if (mVerticalThumb != null) {
final Drawable thumb = mVerticalThumb;
- if (changed) thumb.setBounds(thumbRect);
+ if (changed) {
+ thumb.setBounds(bounds.left, bounds.top + offset,
+ bounds.right, bounds.top + offset + length);
+ }
+
thumb.draw(canvas);
}
} else {
if (mHorizontalThumb != null) {
final Drawable thumb = mHorizontalThumb;
- if (changed) thumb.setBounds(thumbRect);
+ if (changed) {
+ thumb.setBounds(bounds.left + offset, bounds.top,
+ bounds.left + offset + length, bounds.bottom);
+ }
+
thumb.draw(canvas);
}
}
}
public void setVerticalThumbDrawable(Drawable thumb) {
- if (thumb != null) {
- thumb.setState(STATE_ENABLED);
- mVerticalThumb = thumb;
+ if (mVerticalThumb != null) {
+ mVerticalThumb.setCallback(null);
}
+
+ propagateCurrentState(thumb);
+ mVerticalThumb = thumb;
}
public void setVerticalTrackDrawable(Drawable track) {
- if (track != null) {
- track.setState(STATE_ENABLED);
+ if (mVerticalTrack != null) {
+ mVerticalTrack.setCallback(null);
}
+
+ propagateCurrentState(track);
mVerticalTrack = track;
}
public void setHorizontalThumbDrawable(Drawable thumb) {
- if (thumb != null) {
- thumb.setState(STATE_ENABLED);
- mHorizontalThumb = thumb;
+ if (mHorizontalThumb != null) {
+ mHorizontalThumb.setCallback(null);
}
+
+ propagateCurrentState(thumb);
+ mHorizontalThumb = thumb;
}
public void setHorizontalTrackDrawable(Drawable track) {
- if (track != null) {
- track.setState(STATE_ENABLED);
+ if (mHorizontalTrack != null) {
+ mHorizontalTrack.setCallback(null);
}
+
+ propagateCurrentState(track);
mHorizontalTrack = track;
}
+ private void propagateCurrentState(Drawable d) {
+ if (d != null) {
+ d.setState(getState());
+ d.setCallback(this);
+
+ if (mHasSetAlpha) {
+ d.setAlpha(mAlpha);
+ }
+
+ if (mHasSetColorFilter) {
+ d.setColorFilter(mColorFilter);
+ }
+ }
+ }
+
public int getSize(boolean vertical) {
if (vertical) {
return mVerticalTrack != null ? mVerticalTrack.getIntrinsicWidth() :
@@ -229,6 +291,9 @@ public class ScrollBarDrawable extends Drawable {
@Override
public void setAlpha(int alpha) {
+ mAlpha = alpha;
+ mHasSetAlpha = true;
+
if (mVerticalTrack != null) {
mVerticalTrack.setAlpha(alpha);
}
@@ -245,12 +310,14 @@ public class ScrollBarDrawable extends Drawable {
@Override
public int getAlpha() {
- // All elements should have same alpha, just return one of them
- return mVerticalThumb.getAlpha();
+ return mAlpha;
}
@Override
public void setColorFilter(ColorFilter cf) {
+ mColorFilter = cf;
+ mHasSetColorFilter = true;
+
if (mVerticalTrack != null) {
mVerticalTrack.setColorFilter(cf);
}
@@ -266,11 +333,31 @@ public class ScrollBarDrawable extends Drawable {
}
@Override
+ public ColorFilter getColorFilter() {
+ return mColorFilter;
+ }
+
+ @Override
public int getOpacity() {
return PixelFormat.TRANSLUCENT;
}
@Override
+ public void invalidateDrawable(Drawable who) {
+ invalidateSelf();
+ }
+
+ @Override
+ public void scheduleDrawable(Drawable who, Runnable what, long when) {
+ scheduleSelf(what, when);
+ }
+
+ @Override
+ public void unscheduleDrawable(Drawable who, Runnable what) {
+ unscheduleSelf(what);
+ }
+
+ @Override
public String toString() {
return "ScrollBarDrawable: range=" + mRange + " offset=" + mOffset +
" extent=" + mExtent + (mVertical ? " V" : " H");
diff --git a/core/java/android/widget/ScrollView.java b/core/java/android/widget/ScrollView.java
index a90b392..1098419 100644
--- a/core/java/android/widget/ScrollView.java
+++ b/core/java/android/widget/ScrollView.java
@@ -809,9 +809,10 @@ public class ScrollView extends FrameLayout {
awakenScrollBars();
}
+ /** @hide */
@Override
- public boolean performAccessibilityAction(int action, Bundle arguments) {
- if (super.performAccessibilityAction(action, arguments)) {
+ public boolean performAccessibilityActionInternal(int action, Bundle arguments) {
+ if (super.performAccessibilityActionInternal(action, arguments)) {
return true;
}
if (!isEnabled()) {
@@ -838,9 +839,10 @@ public class ScrollView extends FrameLayout {
return false;
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
- super.onInitializeAccessibilityNodeInfo(info);
+ public void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) {
+ super.onInitializeAccessibilityNodeInfoInternal(info);
info.setClassName(ScrollView.class.getName());
if (isEnabled()) {
final int scrollRange = getScrollRange();
@@ -856,9 +858,10 @@ public class ScrollView extends FrameLayout {
}
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
- super.onInitializeAccessibilityEvent(event);
+ public void onInitializeAccessibilityEventInternal(AccessibilityEvent event) {
+ super.onInitializeAccessibilityEventInternal(event);
event.setClassName(ScrollView.class.getName());
final boolean scrollable = getScrollRange() > 0;
event.setScrollable(scrollable);
diff --git a/core/java/android/widget/SearchView.java b/core/java/android/widget/SearchView.java
index 4ee6418..a1f361a 100644
--- a/core/java/android/widget/SearchView.java
+++ b/core/java/android/widget/SearchView.java
@@ -1325,15 +1325,17 @@ public class SearchView extends LinearLayout implements CollapsibleActionView {
setIconified(false);
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
- super.onInitializeAccessibilityEvent(event);
+ public void onInitializeAccessibilityEventInternal(AccessibilityEvent event) {
+ super.onInitializeAccessibilityEventInternal(event);
event.setClassName(SearchView.class.getName());
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
- super.onInitializeAccessibilityNodeInfo(info);
+ public void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) {
+ super.onInitializeAccessibilityNodeInfoInternal(info);
info.setClassName(SearchView.class.getName());
}
diff --git a/core/java/android/widget/SeekBar.java b/core/java/android/widget/SeekBar.java
index dc7c04c..aa5c055 100644
--- a/core/java/android/widget/SeekBar.java
+++ b/core/java/android/widget/SeekBar.java
@@ -124,15 +124,17 @@ public class SeekBar extends AbsSeekBar {
}
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
- super.onInitializeAccessibilityEvent(event);
+ public void onInitializeAccessibilityEventInternal(AccessibilityEvent event) {
+ super.onInitializeAccessibilityEventInternal(event);
event.setClassName(SeekBar.class.getName());
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
- super.onInitializeAccessibilityNodeInfo(info);
+ public void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) {
+ super.onInitializeAccessibilityNodeInfoInternal(info);
info.setClassName(SeekBar.class.getName());
}
}
diff --git a/core/java/android/widget/SimpleAdapter.java b/core/java/android/widget/SimpleAdapter.java
index 98bcfff..a656712 100644
--- a/core/java/android/widget/SimpleAdapter.java
+++ b/core/java/android/widget/SimpleAdapter.java
@@ -17,6 +17,8 @@
package android.widget;
import android.content.Context;
+import android.content.res.Resources;
+import android.view.ContextThemeWrapper;
import android.view.View;
import android.view.ViewGroup;
import android.view.LayoutInflater;
@@ -40,14 +42,14 @@ import java.util.Map;
* If the returned value is false, the following views are then tried in order:
* <ul>
* <li> A view that implements Checkable (e.g. CheckBox). The expected bind value is a boolean.
- * <li> TextView. The expected bind value is a string and {@link #setViewText(TextView, String)}
+ * <li> TextView. The expected bind value is a string and {@link #setViewText(TextView, String)}
* is invoked.
- * <li> ImageView. The expected bind value is a resource id or a string and
- * {@link #setViewImage(ImageView, int)} or {@link #setViewImage(ImageView, String)} is invoked.
+ * <li> ImageView. The expected bind value is a resource id or a string and
+ * {@link #setViewImage(ImageView, int)} or {@link #setViewImage(ImageView, String)} is invoked.
* </ul>
* If no appropriate binding can be found, an {@link IllegalStateException} is thrown.
*/
-public class SimpleAdapter extends BaseAdapter implements Filterable {
+public class SimpleAdapter extends BaseAdapter implements Filterable, Spinner.ThemedSpinnerAdapter {
private int[] mTo;
private String[] mFrom;
private ViewBinder mViewBinder;
@@ -58,12 +60,15 @@ public class SimpleAdapter extends BaseAdapter implements Filterable {
private int mDropDownResource;
private LayoutInflater mInflater;
+ /** Layout inflater used for {@link #getDropDownView(int, View, ViewGroup)}. */
+ private LayoutInflater mDropDownInflater;
+
private SimpleFilter mFilter;
private ArrayList<Map<String, ?>> mUnfilteredData;
/**
* Constructor
- *
+ *
* @param context The context where the View associated with this SimpleAdapter is running
* @param data A List of Maps. Each entry in the List corresponds to one row in the list. The
* Maps contain the data for each row, and should include all the entries specified in
@@ -85,7 +90,6 @@ public class SimpleAdapter extends BaseAdapter implements Filterable {
mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
-
/**
* @see android.widget.Adapter#getCount()
*/
@@ -111,14 +115,14 @@ public class SimpleAdapter extends BaseAdapter implements Filterable {
* @see android.widget.Adapter#getView(int, View, ViewGroup)
*/
public View getView(int position, View convertView, ViewGroup parent) {
- return createViewFromResource(position, convertView, parent, mResource);
+ return createViewFromResource(mInflater, position, convertView, parent, mResource);
}
- private View createViewFromResource(int position, View convertView,
+ private View createViewFromResource(LayoutInflater inflater, int position, View convertView,
ViewGroup parent, int resource) {
View v;
if (convertView == null) {
- v = mInflater.inflate(resource, parent, false);
+ v = inflater.inflate(resource, parent, false);
} else {
v = convertView;
}
@@ -135,12 +139,41 @@ public class SimpleAdapter extends BaseAdapter implements Filterable {
* @see #getDropDownView(int, android.view.View, android.view.ViewGroup)
*/
public void setDropDownViewResource(int resource) {
- this.mDropDownResource = resource;
+ mDropDownResource = resource;
+ }
+
+ /**
+ * Sets the {@link android.content.res.Resources.Theme} against which drop-down views are
+ * inflated.
+ * <p>
+ * By default, drop-down views are inflated against the theme of the
+ * {@link Context} passed to the adapter's constructor.
+ *
+ * @param theme the theme against which to inflate drop-down views or
+ * {@code null} to use the theme from the adapter's context
+ * @see #getDropDownView(int, View, ViewGroup)
+ */
+ @Override
+ public void setDropDownViewTheme(Resources.Theme theme) {
+ if (theme == null) {
+ mDropDownInflater = null;
+ } else if (theme == mInflater.getContext().getTheme()) {
+ mDropDownInflater = mInflater;
+ } else {
+ final Context context = new ContextThemeWrapper(mInflater.getContext(), theme);
+ mDropDownInflater = LayoutInflater.from(context);
+ }
+ }
+
+ @Override
+ public Resources.Theme getDropDownViewTheme() {
+ return mDropDownInflater == null ? null : mDropDownInflater.getContext().getTheme();
}
@Override
public View getDropDownView(int position, View convertView, ViewGroup parent) {
- return createViewFromResource(position, convertView, parent, mDropDownResource);
+ return createViewFromResource(
+ mDropDownInflater, position, convertView, parent, mDropDownResource);
}
private void bindView(int position, View view) {
diff --git a/core/java/android/widget/SimpleMonthAdapter.java b/core/java/android/widget/SimpleMonthAdapter.java
index 24ebb2c..c807d56 100644
--- a/core/java/android/widget/SimpleMonthAdapter.java
+++ b/core/java/android/widget/SimpleMonthAdapter.java
@@ -39,6 +39,7 @@ class SimpleMonthAdapter extends BaseAdapter {
private Calendar mSelectedDay = Calendar.getInstance();
private ColorStateList mCalendarTextColors = ColorStateList.valueOf(Color.BLACK);
+ private ColorStateList mCalendarDayBackgroundColor = ColorStateList.valueOf(Color.MAGENTA);
private OnDaySelectedListener mOnDaySelectedListener;
private int mFirstDayOfWeek;
@@ -88,6 +89,10 @@ class SimpleMonthAdapter extends BaseAdapter {
mCalendarTextColors = colors;
}
+ void setCalendarDayBackgroundColor(ColorStateList dayBackgroundColor) {
+ mCalendarDayBackgroundColor = dayBackgroundColor;
+ }
+
/**
* Sets the text color, size, style, hint color, and highlight color from
* the specified TextAppearance resource. This is mostly copied from
@@ -144,9 +149,11 @@ class SimpleMonthAdapter extends BaseAdapter {
v.setClickable(true);
v.setOnDayClickListener(mOnDayClickListener);
- if (mCalendarTextColors != null) {
- v.setTextColor(mCalendarTextColors);
- }
+ v.setMonthTextColor(mCalendarTextColors);
+ v.setDayOfWeekTextColor(mCalendarTextColors);
+ v.setDayTextColor(mCalendarTextColors);
+
+ v.setDayBackgroundColor(mCalendarDayBackgroundColor);
}
final int minMonth = mMinDate.get(Calendar.MONTH);
diff --git a/core/java/android/widget/SimpleMonthView.java b/core/java/android/widget/SimpleMonthView.java
index d2a37ac..58ad515 100644
--- a/core/java/android/widget/SimpleMonthView.java
+++ b/core/java/android/widget/SimpleMonthView.java
@@ -27,12 +27,13 @@ import android.graphics.Paint.Style;
import android.graphics.Rect;
import android.graphics.Typeface;
import android.os.Bundle;
+import android.text.TextPaint;
import android.text.format.DateFormat;
import android.text.format.DateUtils;
import android.text.format.Time;
import android.util.AttributeSet;
import android.util.IntArray;
-import android.util.MathUtils;
+import android.util.StateSet;
import android.view.MotionEvent;
import android.view.View;
import android.view.accessibility.AccessibilityEvent;
@@ -44,7 +45,6 @@ import com.android.internal.widget.ExploreByTouchHelper;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Formatter;
-import java.util.List;
import java.util.Locale;
/**
@@ -52,8 +52,7 @@ import java.util.Locale;
* within the specified month.
*/
class SimpleMonthView extends View {
- private static final int DEFAULT_HEIGHT = 32;
- private static final int MIN_HEIGHT = 10;
+ private static final int MIN_ROW_HEIGHT = 10;
private static final int DEFAULT_SELECTED_DAY = -1;
private static final int DEFAULT_WEEK_START = Calendar.SUNDAY;
@@ -61,18 +60,21 @@ class SimpleMonthView extends View {
private static final int DEFAULT_NUM_ROWS = 6;
private static final int MAX_NUM_ROWS = 6;
- private static final int SELECTED_CIRCLE_ALPHA = 60;
-
- private static final int DAY_SEPARATOR_WIDTH = 1;
-
private final Formatter mFormatter;
private final StringBuilder mStringBuilder;
- private final int mMiniDayNumberTextSize;
- private final int mMonthLabelTextSize;
- private final int mMonthDayLabelTextSize;
- private final int mMonthHeaderSize;
- private final int mDaySelectedCircleSize;
+ private final int mMonthTextSize;
+ private final int mDayOfWeekTextSize;
+ private final int mDayTextSize;
+
+ /** Height of the header containing the month and day of week labels. */
+ private final int mMonthHeaderHeight;
+
+ private final TextPaint mMonthPaint = new TextPaint();
+ private final TextPaint mDayOfWeekPaint = new TextPaint();
+ private final TextPaint mDayPaint = new TextPaint();
+
+ private final Paint mDayBackgroundPaint = new Paint();
/** Single-letter (when available) formatter for the day of week label. */
private SimpleDateFormat mDayFormatter = new SimpleDateFormat("EEEEE", Locale.getDefault());
@@ -81,14 +83,7 @@ class SimpleMonthView extends View {
private int mPadding = 0;
private String mDayOfWeekTypeface;
- private String mMonthTitleTypeface;
-
- private Paint mDayNumberPaint;
- private Paint mDayNumberDisabledPaint;
- private Paint mDayNumberSelectedPaint;
-
- private Paint mMonthTitlePaint;
- private Paint mMonthDayLabelPaint;
+ private String mMonthTypeface;
private int mMonth;
private int mYear;
@@ -97,13 +92,13 @@ class SimpleMonthView extends View {
private int mWidth;
// The height this view should draw at in pixels, set by height param
- private int mRowHeight = DEFAULT_HEIGHT;
+ private final int mRowHeight;
// If this view contains the today
private boolean mHasToday = false;
// Which day is selected [0-6] or -1 if no day is selected
- private int mSelectedDay = -1;
+ private int mActivatedDay = -1;
// Which day is today [0-6] or -1 if no day is today
private int mToday = DEFAULT_SELECTED_DAY;
@@ -142,6 +137,8 @@ class SimpleMonthView extends View {
private int mDisabledTextColor;
private int mSelectedDayColor;
+ private ColorStateList mDayTextColor;
+
public SimpleMonthView(Context context) {
this(context, null);
}
@@ -159,22 +156,21 @@ class SimpleMonthView extends View {
final Resources res = context.getResources();
mDayOfWeekTypeface = res.getString(R.string.day_of_week_label_typeface);
- mMonthTitleTypeface = res.getString(R.string.sans_serif);
+ mMonthTypeface = res.getString(R.string.sans_serif);
mStringBuilder = new StringBuilder(50);
mFormatter = new Formatter(mStringBuilder, Locale.getDefault());
- mMiniDayNumberTextSize = res.getDimensionPixelSize(R.dimen.datepicker_day_number_size);
- mMonthLabelTextSize = res.getDimensionPixelSize(R.dimen.datepicker_month_label_size);
- mMonthDayLabelTextSize = res.getDimensionPixelSize(
+ mDayTextSize = res.getDimensionPixelSize(R.dimen.datepicker_day_number_size);
+ mMonthTextSize = res.getDimensionPixelSize(R.dimen.datepicker_month_label_size);
+ mDayOfWeekTextSize = res.getDimensionPixelSize(
R.dimen.datepicker_month_day_label_text_size);
- mMonthHeaderSize = res.getDimensionPixelOffset(
+ mMonthHeaderHeight = res.getDimensionPixelOffset(
R.dimen.datepicker_month_list_item_header_height);
- mDaySelectedCircleSize = res.getDimensionPixelSize(
- R.dimen.datepicker_day_number_select_circle_radius);
- mRowHeight = (res.getDimensionPixelOffset(R.dimen.datepicker_view_animator_height)
- - mMonthHeaderSize) / MAX_NUM_ROWS;
+ mRowHeight = Math.max(MIN_ROW_HEIGHT,
+ (res.getDimensionPixelOffset(R.dimen.datepicker_view_animator_height)
+ - mMonthHeaderHeight) / MAX_NUM_ROWS);
// Set up accessibility components.
mTouchHelper = new MonthViewTouchHelper(this);
@@ -182,8 +178,32 @@ class SimpleMonthView extends View {
setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_YES);
mLockAccessibilityDelegate = true;
- // Sets up any standard paints that will be used
- initView();
+ initPaints();
+ }
+
+ /**
+ * Sets up the text and style properties for painting.
+ */
+ private void initPaints() {
+ mMonthPaint.setAntiAlias(true);
+ mMonthPaint.setTextSize(mMonthTextSize);
+ mMonthPaint.setTypeface(Typeface.create(mMonthTypeface, Typeface.BOLD));
+ mMonthPaint.setTextAlign(Align.CENTER);
+ mMonthPaint.setStyle(Style.FILL);
+
+ mDayOfWeekPaint.setAntiAlias(true);
+ mDayOfWeekPaint.setTextSize(mDayOfWeekTextSize);
+ mDayOfWeekPaint.setTypeface(Typeface.create(mDayOfWeekTypeface, Typeface.BOLD));
+ mDayOfWeekPaint.setTextAlign(Align.CENTER);
+ mDayOfWeekPaint.setStyle(Style.FILL);
+
+ mDayBackgroundPaint.setAntiAlias(true);
+ mDayBackgroundPaint.setStyle(Style.FILL);
+
+ mDayPaint.setAntiAlias(true);
+ mDayPaint.setTextSize(mDayTextSize);
+ mDayPaint.setTextAlign(Align.CENTER);
+ mDayPaint.setStyle(Style.FILL);
}
@Override
@@ -193,22 +213,28 @@ class SimpleMonthView extends View {
mDayFormatter = new SimpleDateFormat("EEEEE", newConfig.locale);
}
- void setTextColor(ColorStateList colors) {
- final Resources res = getContext().getResources();
+ void setMonthTextColor(ColorStateList monthTextColor) {
+ final int enabledColor = monthTextColor.getColorForState(ENABLED_STATE_SET, 0);
+ mMonthPaint.setColor(enabledColor);
+ invalidate();
+ }
- mNormalTextColor = colors.getColorForState(ENABLED_STATE_SET,
- res.getColor(R.color.datepicker_default_normal_text_color_holo_light));
- mMonthTitlePaint.setColor(mNormalTextColor);
- mMonthDayLabelPaint.setColor(mNormalTextColor);
+ void setDayOfWeekTextColor(ColorStateList dayOfWeekTextColor) {
+ final int enabledColor = dayOfWeekTextColor.getColorForState(ENABLED_STATE_SET, 0);
+ mDayOfWeekPaint.setColor(enabledColor);
+ invalidate();
+ }
- mDisabledTextColor = colors.getColorForState(EMPTY_STATE_SET,
- res.getColor(R.color.datepicker_default_disabled_text_color_holo_light));
- mDayNumberDisabledPaint.setColor(mDisabledTextColor);
+ void setDayTextColor(ColorStateList dayTextColor) {
+ mDayTextColor = dayTextColor;
+ invalidate();
+ }
- mSelectedDayColor = colors.getColorForState(ENABLED_SELECTED_STATE_SET,
- res.getColor(R.color.holo_blue_light));
- mDayNumberSelectedPaint.setColor(mSelectedDayColor);
- mDayNumberSelectedPaint.setAlpha(SELECTED_CIRCLE_ALPHA);
+ void setDayBackgroundColor(ColorStateList dayBackgroundColor) {
+ final int activatedColor = dayBackgroundColor.getColorForState(
+ StateSet.get(StateSet.VIEW_STATE_ENABLED | StateSet.VIEW_STATE_ACTIVATED), 0);
+ mDayBackgroundPaint.setColor(activatedColor);
+ invalidate();
}
@Override
@@ -246,52 +272,6 @@ class SimpleMonthView extends View {
return true;
}
- /**
- * Sets up the text and style properties for painting.
- */
- private void initView() {
- mMonthTitlePaint = new Paint();
- mMonthTitlePaint.setAntiAlias(true);
- mMonthTitlePaint.setColor(mNormalTextColor);
- mMonthTitlePaint.setTextSize(mMonthLabelTextSize);
- mMonthTitlePaint.setTypeface(Typeface.create(mMonthTitleTypeface, Typeface.BOLD));
- mMonthTitlePaint.setTextAlign(Align.CENTER);
- mMonthTitlePaint.setStyle(Style.FILL);
- mMonthTitlePaint.setFakeBoldText(true);
-
- mMonthDayLabelPaint = new Paint();
- mMonthDayLabelPaint.setAntiAlias(true);
- mMonthDayLabelPaint.setColor(mNormalTextColor);
- mMonthDayLabelPaint.setTextSize(mMonthDayLabelTextSize);
- mMonthDayLabelPaint.setTypeface(Typeface.create(mDayOfWeekTypeface, Typeface.NORMAL));
- mMonthDayLabelPaint.setTextAlign(Align.CENTER);
- mMonthDayLabelPaint.setStyle(Style.FILL);
- mMonthDayLabelPaint.setFakeBoldText(true);
-
- mDayNumberSelectedPaint = new Paint();
- mDayNumberSelectedPaint.setAntiAlias(true);
- mDayNumberSelectedPaint.setColor(mSelectedDayColor);
- mDayNumberSelectedPaint.setAlpha(SELECTED_CIRCLE_ALPHA);
- mDayNumberSelectedPaint.setTextAlign(Align.CENTER);
- mDayNumberSelectedPaint.setStyle(Style.FILL);
- mDayNumberSelectedPaint.setFakeBoldText(true);
-
- mDayNumberPaint = new Paint();
- mDayNumberPaint.setAntiAlias(true);
- mDayNumberPaint.setTextSize(mMiniDayNumberTextSize);
- mDayNumberPaint.setTextAlign(Align.CENTER);
- mDayNumberPaint.setStyle(Style.FILL);
- mDayNumberPaint.setFakeBoldText(false);
-
- mDayNumberDisabledPaint = new Paint();
- mDayNumberDisabledPaint.setAntiAlias(true);
- mDayNumberDisabledPaint.setColor(mDisabledTextColor);
- mDayNumberDisabledPaint.setTextSize(mMiniDayNumberTextSize);
- mDayNumberDisabledPaint.setTextAlign(Align.CENTER);
- mDayNumberDisabledPaint.setStyle(Style.FILL);
- mDayNumberDisabledPaint.setFakeBoldText(false);
- }
-
@Override
protected void onDraw(Canvas canvas) {
drawMonthTitle(canvas);
@@ -323,11 +303,7 @@ class SimpleMonthView extends View {
*/
void setMonthParams(int selectedDay, int month, int year, int weekStart, int enabledDayStart,
int enabledDayEnd) {
- if (mRowHeight < MIN_HEIGHT) {
- mRowHeight = MIN_HEIGHT;
- }
-
- mSelectedDay = selectedDay;
+ mActivatedDay = selectedDay;
if (isValidMonth(month)) {
mMonth = month;
@@ -415,7 +391,7 @@ class SimpleMonthView extends View {
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
setMeasuredDimension(MeasureSpec.getSize(widthMeasureSpec), mRowHeight * mNumRows
- + mMonthHeaderSize);
+ + mMonthHeaderHeight);
}
@Override
@@ -437,21 +413,28 @@ class SimpleMonthView extends View {
private void drawMonthTitle(Canvas canvas) {
final float x = (mWidth + 2 * mPadding) / 2f;
- final float y = (mMonthHeaderSize - mMonthDayLabelTextSize) / 2f;
- canvas.drawText(getMonthAndYearString(), x, y, mMonthTitlePaint);
+
+ // Centered on the upper half of the month header.
+ final float lineHeight = mMonthPaint.ascent() + mMonthPaint.descent();
+ final float y = mMonthHeaderHeight * 0.25f - lineHeight / 2f;
+
+ canvas.drawText(getMonthAndYearString(), x, y, mMonthPaint);
}
private void drawWeekDayLabels(Canvas canvas) {
- final int y = mMonthHeaderSize - (mMonthDayLabelTextSize / 2);
- final int dayWidthHalf = (mWidth - mPadding * 2) / (mNumDays * 2);
+ final float dayWidthHalf = (mWidth - mPadding * 2) / (mNumDays * 2);
+
+ // Centered on the lower half of the month header.
+ final float lineHeight = mDayOfWeekPaint.ascent() + mDayOfWeekPaint.descent();
+ final float y = mMonthHeaderHeight * 0.75f - lineHeight / 2f;
for (int i = 0; i < mNumDays; i++) {
final int calendarDay = (i + mWeekStart) % mNumDays;
mDayLabelCalendar.set(Calendar.DAY_OF_WEEK, calendarDay);
final String dayLabel = mDayFormatter.format(mDayLabelCalendar.getTime());
- final int x = (2 * i + 1) * dayWidthHalf + mPadding;
- canvas.drawText(dayLabel, x, y, mMonthDayLabelPaint);
+ final float x = (2 * i + 1) * dayWidthHalf + mPadding;
+ canvas.drawText(dayLabel, x, y, mDayOfWeekPaint);
}
}
@@ -459,26 +442,40 @@ class SimpleMonthView extends View {
* Draws the month days.
*/
private void drawDays(Canvas canvas) {
- int y = (((mRowHeight + mMiniDayNumberTextSize) / 2) - DAY_SEPARATOR_WIDTH)
- + mMonthHeaderSize;
- int dayWidthHalf = (mWidth - mPadding * 2) / (mNumDays * 2);
- int j = findDayOffset();
- for (int day = 1; day <= mNumCells; day++) {
- int x = (2 * j + 1) * dayWidthHalf + mPadding;
- if (mSelectedDay == day) {
- canvas.drawCircle(x, y - (mMiniDayNumberTextSize / 3), mDaySelectedCircleSize,
- mDayNumberSelectedPaint);
+ final int dayWidthHalf = (mWidth - mPadding * 2) / (mNumDays * 2);
+
+ // Centered within the row.
+ final float lineHeight = mDayOfWeekPaint.ascent() + mDayOfWeekPaint.descent();
+ float y = mMonthHeaderHeight + (mRowHeight - lineHeight) / 2f;
+
+ for (int day = 1, j = findDayOffset(); day <= mNumCells; day++) {
+ final int x = (2 * j + 1) * dayWidthHalf + mPadding;
+ int stateMask = 0;
+
+ if (day >= mEnabledDayStart && day <= mEnabledDayEnd) {
+ stateMask |= StateSet.VIEW_STATE_ENABLED;
}
- if (mHasToday && mToday == day) {
- mDayNumberPaint.setColor(mSelectedDayColor);
- } else {
- mDayNumberPaint.setColor(mNormalTextColor);
+ if (mActivatedDay == day) {
+ stateMask |= StateSet.VIEW_STATE_ACTIVATED;
+
+ // Adjust the circle to be centered the row.
+ final float rowCenterY = y + lineHeight / 2;
+ canvas.drawCircle(x, rowCenterY, mRowHeight / 2,
+ mDayBackgroundPaint);
}
- final Paint paint = (day < mEnabledDayStart || day > mEnabledDayEnd) ?
- mDayNumberDisabledPaint : mDayNumberPaint;
- canvas.drawText(String.format("%d", day), x, y, paint);
+
+ final int[] stateSet = StateSet.get(stateMask);
+ final int dayTextColor = mDayTextColor.getColorForState(stateSet, 0);
+ mDayPaint.setColor(dayTextColor);
+
+ final boolean isDayToday = mHasToday && mToday == day;
+ mDayPaint.setFakeBoldText(isDayToday);
+
+ canvas.drawText(String.format("%d", day), x, y, mDayPaint);
+
j++;
+
if (j == mNumDays) {
j = 0;
y += mRowHeight;
@@ -504,7 +501,7 @@ class SimpleMonthView extends View {
return -1;
}
// Selection is (x - start) / (pixels/day) == (x -s) * day / pixels
- int row = (int) (y - mMonthHeaderSize) / mRowHeight;
+ int row = (int) (y - mMonthHeaderHeight) / mRowHeight;
int column = (int) ((x - dayStart) * mNumDays / (mWidth - dayStart - mPadding));
int day = column - findDayOffset() + 1;
@@ -628,7 +625,7 @@ class SimpleMonthView extends View {
node.setBoundsInParent(mTempRect);
node.addAction(AccessibilityNodeInfo.ACTION_CLICK);
- if (virtualViewId == mSelectedDay) {
+ if (virtualViewId == mActivatedDay) {
node.setSelected(true);
}
@@ -654,7 +651,7 @@ class SimpleMonthView extends View {
*/
private void getItemBounds(int day, Rect rect) {
final int offsetX = mPadding;
- final int offsetY = mMonthHeaderSize;
+ final int offsetY = mMonthHeaderHeight;
final int cellHeight = mRowHeight;
final int cellWidth = ((mWidth - (2 * mPadding)) / mNumDays);
final int index = ((day - 1) + findDayOffset());
@@ -679,7 +676,7 @@ class SimpleMonthView extends View {
final CharSequence date = DateFormat.format(DATE_FORMAT,
mTempCalendar.getTimeInMillis());
- if (day == mSelectedDay) {
+ if (day == mActivatedDay) {
return getContext().getString(R.string.item_is_selected, date);
}
diff --git a/core/java/android/widget/SlidingDrawer.java b/core/java/android/widget/SlidingDrawer.java
index ec06c02..e3f4a10 100644
--- a/core/java/android/widget/SlidingDrawer.java
+++ b/core/java/android/widget/SlidingDrawer.java
@@ -837,15 +837,17 @@ public class SlidingDrawer extends ViewGroup {
}
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
- super.onInitializeAccessibilityEvent(event);
+ public void onInitializeAccessibilityEventInternal(AccessibilityEvent event) {
+ super.onInitializeAccessibilityEventInternal(event);
event.setClassName(SlidingDrawer.class.getName());
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
- super.onInitializeAccessibilityNodeInfo(info);
+ public void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) {
+ super.onInitializeAccessibilityNodeInfoInternal(info);
info.setClassName(SlidingDrawer.class.getName());
}
diff --git a/core/java/android/widget/Spinner.java b/core/java/android/widget/Spinner.java
index 0d76239..a6e0e6d 100644
--- a/core/java/android/widget/Spinner.java
+++ b/core/java/android/widget/Spinner.java
@@ -16,11 +16,15 @@
package android.widget;
+import com.android.internal.R;
+
+import android.annotation.Nullable;
import android.annotation.Widget;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
+import android.content.res.Resources;
import android.content.res.TypedArray;
import android.database.DataSetObserver;
import android.graphics.Rect;
@@ -30,6 +34,7 @@ import android.os.Parcel;
import android.os.Parcelable;
import android.util.AttributeSet;
import android.util.Log;
+import android.view.ContextThemeWrapper;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
@@ -74,17 +79,22 @@ public class Spinner extends AbsSpinner implements OnClickListener {
* Use a dropdown anchored to the Spinner for selecting spinner options.
*/
public static final int MODE_DROPDOWN = 1;
-
+
/**
* Use the theme-supplied value to select the dropdown mode.
*/
private static final int MODE_THEME = -1;
+ /** Context used to inflate the popup window or dialog. */
+ private Context mPopupContext;
+
/** Forwarding listener used to implement drag-to-open. */
private ForwardingListener mForwardingListener;
+ /** Temporary holder for setAdapter() calls from the super constructor. */
+ private SpinnerAdapter mTempAdapter;
+
private SpinnerPopup mPopup;
- private DropDownAdapter mTempAdapter;
int mDropDownWidth;
private int mGravity;
@@ -184,69 +194,120 @@ public class Spinner extends AbsSpinner implements OnClickListener {
* @see #MODE_DIALOG
* @see #MODE_DROPDOWN
*/
- public Spinner(
- Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes, int mode) {
+ public Spinner(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes,
+ int mode) {
+ this(context, attrs, defStyleAttr, defStyleRes, mode, null);
+ }
+
+ /**
+ * Constructs a new spinner with the given context's theme, the supplied
+ * attribute set, default styles, popup mode (one of {@link #MODE_DIALOG}
+ * or {@link #MODE_DROPDOWN}), and the context against which the popup
+ * should be inflated.
+ *
+ * @param context The context against which the view is inflated, which
+ * provides access to the current theme, resources, etc.
+ * @param attrs The attributes of the XML tag that is inflating the view.
+ * @param defStyleAttr An attribute in the current theme that contains a
+ * reference to a style resource that supplies default
+ * values for the view. Can be 0 to not look for
+ * defaults.
+ * @param defStyleRes A resource identifier of a style resource that
+ * supplies default values for the view, used only if
+ * defStyleAttr is 0 or can not be found in the theme.
+ * Can be 0 to not look for defaults.
+ * @param mode Constant describing how the user will select choices from
+ * the spinner.
+ * @param popupContext The context against which the dialog or dropdown
+ * popup will be inflated. Can be null to use the view
+ * context. If set, this will override any value
+ * specified by
+ * {@link android.R.styleable#Spinner_popupTheme}.
+ *
+ * @see #MODE_DIALOG
+ * @see #MODE_DROPDOWN
+ */
+ public Spinner(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes, int mode,
+ Context popupContext) {
super(context, attrs, defStyleAttr, defStyleRes);
final TypedArray a = context.obtainStyledAttributes(
- attrs, com.android.internal.R.styleable.Spinner, defStyleAttr, defStyleRes);
+ attrs, R.styleable.Spinner, defStyleAttr, defStyleRes);
- if (mode == MODE_THEME) {
- mode = a.getInt(com.android.internal.R.styleable.Spinner_spinnerMode, MODE_DIALOG);
- }
-
- switch (mode) {
- case MODE_DIALOG: {
- mPopup = new DialogPopup();
- break;
+ if (popupContext != null) {
+ mPopupContext = popupContext;
+ } else {
+ final int popupThemeResId = a.getResourceId(R.styleable.Spinner_popupTheme, 0);
+ if (popupThemeResId != 0) {
+ mPopupContext = new ContextThemeWrapper(context, popupThemeResId);
+ } else {
+ mPopupContext = context;
+ }
}
- case MODE_DROPDOWN: {
- final DropdownPopup popup = new DropdownPopup(context, attrs, defStyleAttr, defStyleRes);
+ if (mode == MODE_THEME) {
+ mode = a.getInt(R.styleable.Spinner_spinnerMode, MODE_DIALOG);
+ }
- mDropDownWidth = a.getLayoutDimension(
- com.android.internal.R.styleable.Spinner_dropDownWidth,
- ViewGroup.LayoutParams.WRAP_CONTENT);
- popup.setBackgroundDrawable(a.getDrawable(
- com.android.internal.R.styleable.Spinner_popupBackground));
+ switch (mode) {
+ case MODE_DIALOG: {
+ mPopup = new DialogPopup();
+ mPopup.setPromptText(a.getString(R.styleable.Spinner_prompt));
+ break;
+ }
- mPopup = popup;
- mForwardingListener = new ForwardingListener(this) {
- @Override
- public ListPopupWindow getPopup() {
- return popup;
- }
+ case MODE_DROPDOWN: {
+ final DropdownPopup popup = new DropdownPopup(
+ mPopupContext, attrs, defStyleAttr, defStyleRes);
+ final TypedArray pa = mPopupContext.obtainStyledAttributes(
+ attrs, R.styleable.Spinner, defStyleAttr, defStyleRes);
+ mDropDownWidth = pa.getLayoutDimension(R.styleable.Spinner_dropDownWidth,
+ ViewGroup.LayoutParams.WRAP_CONTENT);
+ popup.setBackgroundDrawable(pa.getDrawable(R.styleable.Spinner_popupBackground));
+ popup.setPromptText(a.getString(R.styleable.Spinner_prompt));
+ pa.recycle();
+
+ mPopup = popup;
+ mForwardingListener = new ForwardingListener(this) {
+ @Override
+ public ListPopupWindow getPopup() {
+ return popup;
+ }
- @Override
- public boolean onForwardingStarted() {
- if (!mPopup.isShowing()) {
- mPopup.show(getTextDirection(), getTextAlignment());
+ @Override
+ public boolean onForwardingStarted() {
+ if (!mPopup.isShowing()) {
+ mPopup.show(getTextDirection(), getTextAlignment());
+ }
+ return true;
}
- return true;
- }
- };
- break;
- }
+ };
+ break;
+ }
}
- mGravity = a.getInt(com.android.internal.R.styleable.Spinner_gravity, Gravity.CENTER);
-
- mPopup.setPromptText(a.getString(com.android.internal.R.styleable.Spinner_prompt));
-
+ mGravity = a.getInt(R.styleable.Spinner_gravity, Gravity.CENTER);
mDisableChildrenWhenDisabled = a.getBoolean(
- com.android.internal.R.styleable.Spinner_disableChildrenWhenDisabled, false);
+ R.styleable.Spinner_disableChildrenWhenDisabled, false);
a.recycle();
// Base constructor can call setAdapter before we initialize mPopup.
// Finish setting things up if this happened.
if (mTempAdapter != null) {
- mPopup.setAdapter(mTempAdapter);
+ setAdapter(mTempAdapter);
mTempAdapter = null;
}
}
/**
+ * @return the context used to inflate the Spinner's popup or dialog window
+ */
+ public Context getPopupContext() {
+ return mPopupContext;
+ }
+
+ /**
* Set the background drawable for the spinner's popup window of choices.
* Only valid in {@link #MODE_DROPDOWN}; this method is a no-op in other modes.
*
@@ -259,7 +320,7 @@ public class Spinner extends AbsSpinner implements OnClickListener {
Log.e(TAG, "setPopupBackgroundDrawable: incompatible spinner mode; ignoring...");
return;
}
- ((DropdownPopup) mPopup).setBackgroundDrawable(background);
+ mPopup.setBackgroundDrawable(background);
}
/**
@@ -271,7 +332,7 @@ public class Spinner extends AbsSpinner implements OnClickListener {
* @attr ref android.R.styleable#Spinner_popupBackground
*/
public void setPopupBackgroundResource(int resId) {
- setPopupBackgroundDrawable(getContext().getDrawable(resId));
+ setPopupBackgroundDrawable(getPopupContext().getDrawable(resId));
}
/**
@@ -410,9 +471,17 @@ public class Spinner extends AbsSpinner implements OnClickListener {
}
/**
- * Sets the Adapter used to provide the data which backs this Spinner.
+ * Sets the {@link SpinnerAdapter} used to provide the data which backs
+ * this Spinner.
+ * <p>
+ * If this Spinner has a popup theme set in XML via the
+ * {@link android.R.styleable#Spinner_popupTheme popupTheme} attribute, the
+ * adapter should inflate drop-down views using the same theme. The easiest
+ * way to achieve this is by using {@link #getPopupContext()} to obtain a
+ * layout inflater for use in
+ * {@link SpinnerAdapter#getDropDownView(int, View, ViewGroup)}.
* <p>
- * Note that Spinner overrides {@link Adapter#getViewTypeCount()} on the
+ * Spinner overrides {@link Adapter#getViewTypeCount()} on the
* Adapter associated with this view. Calling
* {@link Adapter#getItemViewType(int) getItemViewType(int)} on the object
* returned from {@link #getAdapter()} will always return 0. Calling
@@ -429,6 +498,13 @@ public class Spinner extends AbsSpinner implements OnClickListener {
*/
@Override
public void setAdapter(SpinnerAdapter adapter) {
+ // The super constructor may call setAdapter before we're prepared.
+ // Postpone doing anything until we've finished construction.
+ if (mPopup == null) {
+ mTempAdapter = adapter;
+ return;
+ }
+
super.setAdapter(adapter);
mRecycler.clear();
@@ -439,11 +515,8 @@ public class Spinner extends AbsSpinner implements OnClickListener {
throw new IllegalArgumentException("Spinner adapter view type count must be 1");
}
- if (mPopup != null) {
- mPopup.setAdapter(new DropDownAdapter(adapter));
- } else {
- mTempAdapter = new DropDownAdapter(adapter);
- }
+ final Context popupContext = mPopupContext == null ? mContext : mPopupContext;
+ mPopup.setAdapter(new DropDownAdapter(adapter, popupContext.getTheme()));
}
@Override
@@ -692,15 +765,17 @@ public class Spinner extends AbsSpinner implements OnClickListener {
dialog.dismiss();
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
- super.onInitializeAccessibilityEvent(event);
+ public void onInitializeAccessibilityEventInternal(AccessibilityEvent event) {
+ super.onInitializeAccessibilityEventInternal(event);
event.setClassName(Spinner.class.getName());
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
- super.onInitializeAccessibilityNodeInfo(info);
+ public void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) {
+ super.onInitializeAccessibilityNodeInfoInternal(info);
info.setClassName(Spinner.class.getName());
if (mAdapter != null) {
@@ -847,14 +922,26 @@ public class Spinner extends AbsSpinner implements OnClickListener {
private ListAdapter mListAdapter;
/**
- * <p>Creates a new ListAdapter wrapper for the specified adapter.</p>
+ * Creates a new ListAdapter wrapper for the specified adapter.
*
- * @param adapter the Adapter to transform into a ListAdapter
+ * @param adapter the SpinnerAdapter to transform into a ListAdapter
+ * @param dropDownTheme the theme against which to inflate drop-down
+ * views, may be {@null} to use default theme
*/
- public DropDownAdapter(SpinnerAdapter adapter) {
- this.mAdapter = adapter;
+ public DropDownAdapter(@Nullable SpinnerAdapter adapter,
+ @Nullable Resources.Theme dropDownTheme) {
+ mAdapter = adapter;
+
if (adapter instanceof ListAdapter) {
- this.mListAdapter = (ListAdapter) adapter;
+ mListAdapter = (ListAdapter) adapter;
+ }
+
+ if (dropDownTheme != null && adapter instanceof Spinner.ThemedSpinnerAdapter) {
+ final Spinner.ThemedSpinnerAdapter themedAdapter =
+ (Spinner.ThemedSpinnerAdapter) adapter;
+ if (themedAdapter.getDropDownViewTheme() == null) {
+ themedAdapter.setDropDownViewTheme(dropDownTheme);
+ }
}
}
@@ -970,7 +1057,7 @@ public class Spinner extends AbsSpinner implements OnClickListener {
public int getVerticalOffset();
public int getHorizontalOffset();
}
-
+
private class DialogPopup implements SpinnerPopup, DialogInterface.OnClickListener {
private AlertDialog mPopup;
private ListAdapter mListAdapter;
@@ -994,7 +1081,7 @@ public class Spinner extends AbsSpinner implements OnClickListener {
public void setPromptText(CharSequence hintText) {
mPrompt = hintText;
}
-
+
public CharSequence getHintText() {
return mPrompt;
}
@@ -1003,7 +1090,7 @@ public class Spinner extends AbsSpinner implements OnClickListener {
if (mListAdapter == null) {
return;
}
- AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
+ AlertDialog.Builder builder = new AlertDialog.Builder(getPopupContext());
if (mPrompt != null) {
builder.setTitle(mPrompt);
}
@@ -1179,4 +1266,21 @@ public class Spinner extends AbsSpinner implements OnClickListener {
}
}
}
+
+ public interface ThemedSpinnerAdapter {
+ /**
+ * Sets the {@link Resources.Theme} against which drop-down views are
+ * inflated.
+ *
+ * @param theme the context against which to inflate drop-down views
+ * @see SpinnerAdapter#getDropDownView(int, View, ViewGroup)
+ */
+ public void setDropDownViewTheme(Resources.Theme theme);
+
+ /**
+ * @return The {@link Resources.Theme} against which drop-down views are
+ * inflated.
+ */
+ public Resources.Theme getDropDownViewTheme();
+ }
}
diff --git a/core/java/android/widget/SpinnerAdapter.java b/core/java/android/widget/SpinnerAdapter.java
index 91504cf..f99f45b 100644
--- a/core/java/android/widget/SpinnerAdapter.java
+++ b/core/java/android/widget/SpinnerAdapter.java
@@ -22,16 +22,17 @@ import android.view.ViewGroup;
/**
* Extended {@link Adapter} that is the bridge between a
* {@link android.widget.Spinner} and its data. A spinner adapter allows to
- * define two different views: one that shows the data in the spinner itself and
- * one that shows the data in the drop down list when the spinner is pressed.</p>
+ * define two different views: one that shows the data in the spinner itself
+ * and one that shows the data in the drop down list when the spinner is
+ * pressed.
*/
public interface SpinnerAdapter extends Adapter {
/**
- * <p>Get a {@link android.view.View} that displays in the drop down popup
- * the data at the specified position in the data set.</p>
+ * Gets a {@link android.view.View} that displays in the drop down popup
+ * the data at the specified position in the data set.
*
- * @param position index of the item whose view we want.
- * @param convertView the old view to reuse, if possible. Note: You should
+ * @param position index of the item whose view we want.
+ * @param convertView the old view to reuse, if possible. Note: You should
* check that this view is non-null and of an appropriate type before
* using. If it is not possible to convert this view to display the
* correct data, this method can create a new view.
diff --git a/core/java/android/widget/StackView.java b/core/java/android/widget/StackView.java
index 9e168b8..2aa1c09 100644
--- a/core/java/android/widget/StackView.java
+++ b/core/java/android/widget/StackView.java
@@ -1224,15 +1224,17 @@ public class StackView extends AdapterViewAnimator {
measureChildren();
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
- super.onInitializeAccessibilityEvent(event);
+ public void onInitializeAccessibilityEventInternal(AccessibilityEvent event) {
+ super.onInitializeAccessibilityEventInternal(event);
event.setClassName(StackView.class.getName());
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
- super.onInitializeAccessibilityNodeInfo(info);
+ public void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) {
+ super.onInitializeAccessibilityNodeInfoInternal(info);
info.setClassName(StackView.class.getName());
info.setScrollable(getChildCount() > 1);
if (isEnabled()) {
@@ -1245,9 +1247,10 @@ public class StackView extends AdapterViewAnimator {
}
}
+ /** @hide */
@Override
- public boolean performAccessibilityAction(int action, Bundle arguments) {
- if (super.performAccessibilityAction(action, arguments)) {
+ public boolean performAccessibilityActionInternal(int action, Bundle arguments) {
+ if (super.performAccessibilityActionInternal(action, arguments)) {
return true;
}
if (!isEnabled()) {
diff --git a/core/java/android/widget/SuggestionsAdapter.java b/core/java/android/widget/SuggestionsAdapter.java
index 6349347..4323851 100644
--- a/core/java/android/widget/SuggestionsAdapter.java
+++ b/core/java/android/widget/SuggestionsAdapter.java
@@ -145,8 +145,9 @@ class SuggestionsAdapter extends ResourceCursorAdapter implements OnClickListene
* copied to the query text field.
* <p>
*
- * @param refine which queries to refine. Possible values are {@link #REFINE_NONE},
- * {@link #REFINE_BY_ENTRY}, and {@link #REFINE_ALL}.
+ * @param refineWhat which queries to refine. Possible values are
+ * {@link #REFINE_NONE}, {@link #REFINE_BY_ENTRY}, and
+ * {@link #REFINE_ALL}.
*/
public void setQueryRefinement(int refineWhat) {
mQueryRefinement = refineWhat;
@@ -327,7 +328,7 @@ class SuggestionsAdapter extends ResourceCursorAdapter implements OnClickListene
// First check TEXT_2_URL
CharSequence text2 = getStringOrNull(cursor, mText2UrlCol);
if (text2 != null) {
- text2 = formatUrl(text2);
+ text2 = formatUrl(context, text2);
} else {
text2 = getStringOrNull(cursor, mText2Col);
}
@@ -372,12 +373,12 @@ class SuggestionsAdapter extends ResourceCursorAdapter implements OnClickListene
}
}
- private CharSequence formatUrl(CharSequence url) {
+ private CharSequence formatUrl(Context context, CharSequence url) {
if (mUrlColor == null) {
// Lazily get the URL color from the current theme.
TypedValue colorValue = new TypedValue();
- mContext.getTheme().resolveAttribute(R.attr.textColorSearchUrl, colorValue, true);
- mUrlColor = mContext.getResources().getColorStateList(colorValue.resourceId);
+ context.getTheme().resolveAttribute(R.attr.textColorSearchUrl, colorValue, true);
+ mUrlColor = context.getResources().getColorStateList(colorValue.resourceId);
}
SpannableString text = new SpannableString(url);
@@ -502,6 +503,30 @@ class SuggestionsAdapter extends ResourceCursorAdapter implements OnClickListene
}
/**
+ * This method is overridden purely to provide a bit of protection against
+ * flaky content providers.
+ *
+ * @see android.widget.CursorAdapter#getDropDownView(int, View, ViewGroup)
+ */
+ @Override
+ public View getDropDownView(int position, View convertView, ViewGroup parent) {
+ try {
+ return super.getDropDownView(position, convertView, parent);
+ } catch (RuntimeException e) {
+ Log.w(LOG_TAG, "Search suggestions cursor threw exception.", e);
+ // Put exception string in item title
+ final Context context = mDropDownContext == null ? mContext : mDropDownContext;
+ final View v = newDropDownView(context, mCursor, parent);
+ if (v != null) {
+ final ChildViewCache views = (ChildViewCache) v.getTag();
+ final TextView tv = views.mText1;
+ tv.setText(e.toString());
+ }
+ return v;
+ }
+ }
+
+ /**
* Gets a drawable given a value provided by a suggestion provider.
*
* This value could be just the string value of a resource id
@@ -570,7 +595,7 @@ class SuggestionsAdapter extends ResourceCursorAdapter implements OnClickListene
OpenResourceIdResult r =
mProviderContext.getContentResolver().getResourceId(uri);
try {
- return r.r.getDrawable(r.id, mContext.getTheme());
+ return r.r.getDrawable(r.id, mProviderContext.getTheme());
} catch (Resources.NotFoundException ex) {
throw new FileNotFoundException("Resource does not exist: " + uri);
}
diff --git a/core/java/android/widget/Switch.java b/core/java/android/widget/Switch.java
index 7a22224..13d6b42 100644
--- a/core/java/android/widget/Switch.java
+++ b/core/java/android/widget/Switch.java
@@ -665,9 +665,10 @@ public class Switch extends CompoundButton {
}
}
+ /** @hide */
@Override
- public void onPopulateAccessibilityEvent(AccessibilityEvent event) {
- super.onPopulateAccessibilityEvent(event);
+ public void onPopulateAccessibilityEventInternal(AccessibilityEvent event) {
+ super.onPopulateAccessibilityEventInternal(event);
final CharSequence text = isChecked() ? mTextOn : mTextOff;
if (text != null) {
@@ -1180,15 +1181,17 @@ public class Switch extends CompoundButton {
}
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
- super.onInitializeAccessibilityEvent(event);
+ public void onInitializeAccessibilityEventInternal(AccessibilityEvent event) {
+ super.onInitializeAccessibilityEventInternal(event);
event.setClassName(Switch.class.getName());
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
- super.onInitializeAccessibilityNodeInfo(info);
+ public void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) {
+ super.onInitializeAccessibilityNodeInfoInternal(info);
info.setClassName(Switch.class.getName());
CharSequence switchText = isChecked() ? mTextOn : mTextOff;
if (!TextUtils.isEmpty(switchText)) {
diff --git a/core/java/android/widget/TabHost.java b/core/java/android/widget/TabHost.java
index 89df51a..3c3389a 100644
--- a/core/java/android/widget/TabHost.java
+++ b/core/java/android/widget/TabHost.java
@@ -173,8 +173,9 @@ mTabHost.addTab(TAB_TAG_1, "Hello, world!", "Tab 1");
}
}
+ /** @hide */
@Override
- public void sendAccessibilityEvent(int eventType) {
+ public void sendAccessibilityEventInternal(int eventType) {
/* avoid super class behavior - TabWidget sends the right events */
}
@@ -383,15 +384,17 @@ mTabHost.addTab(TAB_TAG_1, "Hello, world!", "Tab 1");
}
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
- super.onInitializeAccessibilityEvent(event);
+ public void onInitializeAccessibilityEventInternal(AccessibilityEvent event) {
+ super.onInitializeAccessibilityEventInternal(event);
event.setClassName(TabHost.class.getName());
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
- super.onInitializeAccessibilityNodeInfo(info);
+ public void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) {
+ super.onInitializeAccessibilityNodeInfoInternal(info);
info.setClassName(TabHost.class.getName());
}
diff --git a/core/java/android/widget/TabWidget.java b/core/java/android/widget/TabWidget.java
index 47a5449..bddee91 100644
--- a/core/java/android/widget/TabWidget.java
+++ b/core/java/android/widget/TabWidget.java
@@ -401,8 +401,9 @@ public class TabWidget extends LinearLayout implements OnFocusChangeListener {
}
}
+ /** @hide */
@Override
- public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
+ public boolean dispatchPopulateAccessibilityEventInternal(AccessibilityEvent event) {
onPopulateAccessibilityEvent(event);
// Dispatch only to the selected tab.
if (mSelectedTab != -1) {
@@ -414,28 +415,31 @@ public class TabWidget extends LinearLayout implements OnFocusChangeListener {
return false;
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
- super.onInitializeAccessibilityEvent(event);
+ public void onInitializeAccessibilityEventInternal(AccessibilityEvent event) {
+ super.onInitializeAccessibilityEventInternal(event);
event.setClassName(TabWidget.class.getName());
event.setItemCount(getTabCount());
event.setCurrentItemIndex(mSelectedTab);
}
+ /** @hide */
@Override
- public void sendAccessibilityEventUnchecked(AccessibilityEvent event) {
+ public void sendAccessibilityEventUncheckedInternal(AccessibilityEvent event) {
// this class fires events only when tabs are focused or selected
if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_FOCUSED && isFocused()) {
event.recycle();
return;
}
- super.sendAccessibilityEventUnchecked(event);
+ super.sendAccessibilityEventUncheckedInternal(event);
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
- super.onInitializeAccessibilityNodeInfo(info);
+ public void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) {
+ super.onInitializeAccessibilityNodeInfoInternal(info);
info.setClassName(TabWidget.class.getName());
}
diff --git a/core/java/android/widget/TableLayout.java b/core/java/android/widget/TableLayout.java
index f4b2ce0..a6b78a4 100644
--- a/core/java/android/widget/TableLayout.java
+++ b/core/java/android/widget/TableLayout.java
@@ -666,15 +666,17 @@ public class TableLayout extends LinearLayout {
return new LayoutParams(p);
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
- super.onInitializeAccessibilityEvent(event);
+ public void onInitializeAccessibilityEventInternal(AccessibilityEvent event) {
+ super.onInitializeAccessibilityEventInternal(event);
event.setClassName(TableLayout.class.getName());
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
- super.onInitializeAccessibilityNodeInfo(info);
+ public void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) {
+ super.onInitializeAccessibilityNodeInfoInternal(info);
info.setClassName(TableLayout.class.getName());
}
diff --git a/core/java/android/widget/TableRow.java b/core/java/android/widget/TableRow.java
index fe3631a..c29296a 100644
--- a/core/java/android/widget/TableRow.java
+++ b/core/java/android/widget/TableRow.java
@@ -379,15 +379,17 @@ public class TableRow extends LinearLayout {
return new LayoutParams(p);
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
- super.onInitializeAccessibilityEvent(event);
+ public void onInitializeAccessibilityEventInternal(AccessibilityEvent event) {
+ super.onInitializeAccessibilityEventInternal(event);
event.setClassName(TableRow.class.getName());
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
- super.onInitializeAccessibilityNodeInfo(info);
+ public void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) {
+ super.onInitializeAccessibilityNodeInfoInternal(info);
info.setClassName(TableRow.class.getName());
}
diff --git a/core/java/android/widget/TextSwitcher.java b/core/java/android/widget/TextSwitcher.java
index 1aefd2b..7c883ba 100644
--- a/core/java/android/widget/TextSwitcher.java
+++ b/core/java/android/widget/TextSwitcher.java
@@ -91,15 +91,17 @@ public class TextSwitcher extends ViewSwitcher {
((TextView)getCurrentView()).setText(text);
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
- super.onInitializeAccessibilityEvent(event);
+ public void onInitializeAccessibilityEventInternal(AccessibilityEvent event) {
+ super.onInitializeAccessibilityEventInternal(event);
event.setClassName(TextSwitcher.class.getName());
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
- super.onInitializeAccessibilityNodeInfo(info);
+ public void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) {
+ super.onInitializeAccessibilityNodeInfoInternal(info);
info.setClassName(TextSwitcher.class.getName());
}
}
diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java
index 5b0e8e8..e8bf623 100644
--- a/core/java/android/widget/TextView.java
+++ b/core/java/android/widget/TextView.java
@@ -25,6 +25,7 @@ import android.content.Context;
import android.content.UndoManager;
import android.content.res.ColorStateList;
import android.content.res.CompatibilityInfo;
+import android.content.res.Configuration;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.content.res.XmlResourceParser;
@@ -32,6 +33,7 @@ import android.graphics.Canvas;
import android.graphics.Insets;
import android.graphics.Paint;
import android.graphics.Path;
+import android.graphics.PorterDuff;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.Typeface;
@@ -214,6 +216,8 @@ import static android.os.Build.VERSION_CODES.JELLY_BEAN_MR1;
* @attr ref android.R.styleable#TextView_drawableStart
* @attr ref android.R.styleable#TextView_drawableEnd
* @attr ref android.R.styleable#TextView_drawablePadding
+ * @attr ref android.R.styleable#TextView_drawableTint
+ * @attr ref android.R.styleable#TextView_drawableTintMode
* @attr ref android.R.styleable#TextView_lineSpacingExtra
* @attr ref android.R.styleable#TextView_lineSpacingMultiplier
* @attr ref android.R.styleable#TextView_marqueeRepeatLimit
@@ -298,7 +302,6 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
private float mShadowRadius, mShadowDx, mShadowDy;
private int mShadowColor;
-
private boolean mPreDrawRegistered;
private boolean mPreDrawListenerDetached;
@@ -312,16 +315,27 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
private TextUtils.TruncateAt mEllipsize;
static class Drawables {
- final static int DRAWABLE_NONE = -1;
- final static int DRAWABLE_RIGHT = 0;
- final static int DRAWABLE_LEFT = 1;
+ static final int LEFT = 0;
+ static final int TOP = 1;
+ static final int RIGHT = 2;
+ static final int BOTTOM = 3;
+
+ static final int DRAWABLE_NONE = -1;
+ static final int DRAWABLE_RIGHT = 0;
+ static final int DRAWABLE_LEFT = 1;
final Rect mCompoundRect = new Rect();
- Drawable mDrawableTop, mDrawableBottom, mDrawableLeft, mDrawableRight,
- mDrawableStart, mDrawableEnd, mDrawableError, mDrawableTemp;
+ final Drawable[] mShowing = new Drawable[4];
+ ColorStateList mTintList;
+ PorterDuff.Mode mTintMode;
+ boolean mHasTint;
+ boolean mHasTintMode;
+
+ Drawable mDrawableStart, mDrawableEnd, mDrawableError, mDrawableTemp;
Drawable mDrawableLeftInitial, mDrawableRightInitial;
+
boolean mIsRtlCompatibilityMode;
boolean mOverride;
@@ -344,19 +358,19 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
public void resolveWithLayoutDirection(int layoutDirection) {
// First reset "left" and "right" drawables to their initial values
- mDrawableLeft = mDrawableLeftInitial;
- mDrawableRight = mDrawableRightInitial;
+ mShowing[Drawables.LEFT] = mDrawableLeftInitial;
+ mShowing[Drawables.RIGHT] = mDrawableRightInitial;
if (mIsRtlCompatibilityMode) {
// Use "start" drawable as "left" drawable if the "left" drawable was not defined
- if (mDrawableStart != null && mDrawableLeft == null) {
- mDrawableLeft = mDrawableStart;
+ if (mDrawableStart != null && mShowing[Drawables.LEFT] == null) {
+ mShowing[Drawables.LEFT] = mDrawableStart;
mDrawableSizeLeft = mDrawableSizeStart;
mDrawableHeightLeft = mDrawableHeightStart;
}
// Use "end" drawable as "right" drawable if the "right" drawable was not defined
- if (mDrawableEnd != null && mDrawableRight == null) {
- mDrawableRight = mDrawableEnd;
+ if (mDrawableEnd != null && mShowing[Drawables.RIGHT] == null) {
+ mShowing[Drawables.RIGHT] = mDrawableEnd;
mDrawableSizeRight = mDrawableSizeEnd;
mDrawableHeightRight = mDrawableHeightEnd;
}
@@ -366,11 +380,11 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
switch(layoutDirection) {
case LAYOUT_DIRECTION_RTL:
if (mOverride) {
- mDrawableRight = mDrawableStart;
+ mShowing[Drawables.RIGHT] = mDrawableStart;
mDrawableSizeRight = mDrawableSizeStart;
mDrawableHeightRight = mDrawableHeightStart;
- mDrawableLeft = mDrawableEnd;
+ mShowing[Drawables.LEFT] = mDrawableEnd;
mDrawableSizeLeft = mDrawableSizeEnd;
mDrawableHeightLeft = mDrawableHeightEnd;
}
@@ -379,11 +393,11 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
case LAYOUT_DIRECTION_LTR:
default:
if (mOverride) {
- mDrawableLeft = mDrawableStart;
+ mShowing[Drawables.LEFT] = mDrawableStart;
mDrawableSizeLeft = mDrawableSizeStart;
mDrawableHeightLeft = mDrawableHeightStart;
- mDrawableRight = mDrawableEnd;
+ mShowing[Drawables.RIGHT] = mDrawableEnd;
mDrawableSizeRight = mDrawableSizeEnd;
mDrawableHeightRight = mDrawableHeightEnd;
}
@@ -395,17 +409,10 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
}
private void updateDrawablesLayoutDirection(int layoutDirection) {
- if (mDrawableLeft != null) {
- mDrawableLeft.setLayoutDirection(layoutDirection);
- }
- if (mDrawableRight != null) {
- mDrawableRight.setLayoutDirection(layoutDirection);
- }
- if (mDrawableTop != null) {
- mDrawableTop.setLayoutDirection(layoutDirection);
- }
- if (mDrawableBottom != null) {
- mDrawableBottom.setLayoutDirection(layoutDirection);
+ for (Drawable dr : mShowing) {
+ if (dr != null) {
+ dr.setLayoutDirection(layoutDirection);
+ }
}
}
@@ -415,10 +422,10 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
}
mDrawableError = dr;
- final Rect compoundRect = mCompoundRect;
- int[] state = tv.getDrawableState();
-
if (mDrawableError != null) {
+ final Rect compoundRect = mCompoundRect;
+ final int[] state = tv.getDrawableState();
+
mDrawableError.setState(state);
mDrawableError.copyBounds(compoundRect);
mDrawableError.setCallback(tv);
@@ -433,12 +440,12 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
// first restore the initial state if needed
switch (mDrawableSaved) {
case DRAWABLE_LEFT:
- mDrawableLeft = mDrawableTemp;
+ mShowing[Drawables.LEFT] = mDrawableTemp;
mDrawableSizeLeft = mDrawableSizeTemp;
mDrawableHeightLeft = mDrawableHeightTemp;
break;
case DRAWABLE_RIGHT:
- mDrawableRight = mDrawableTemp;
+ mShowing[Drawables.RIGHT] = mDrawableTemp;
mDrawableSizeRight = mDrawableSizeTemp;
mDrawableHeightRight = mDrawableHeightTemp;
break;
@@ -451,11 +458,11 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
case LAYOUT_DIRECTION_RTL:
mDrawableSaved = DRAWABLE_LEFT;
- mDrawableTemp = mDrawableLeft;
+ mDrawableTemp = mShowing[Drawables.LEFT];
mDrawableSizeTemp = mDrawableSizeLeft;
mDrawableHeightTemp = mDrawableHeightLeft;
- mDrawableLeft = mDrawableError;
+ mShowing[Drawables.LEFT] = mDrawableError;
mDrawableSizeLeft = mDrawableSizeError;
mDrawableHeightLeft = mDrawableHeightError;
break;
@@ -463,11 +470,11 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
default:
mDrawableSaved = DRAWABLE_RIGHT;
- mDrawableTemp = mDrawableRight;
+ mDrawableTemp = mShowing[Drawables.RIGHT];
mDrawableSizeTemp = mDrawableSizeRight;
mDrawableHeightTemp = mDrawableHeightRight;
- mDrawableRight = mDrawableError;
+ mShowing[Drawables.RIGHT] = mDrawableError;
mDrawableSizeRight = mDrawableSizeError;
mDrawableHeightRight = mDrawableHeightError;
break;
@@ -520,6 +527,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
private final TextPaint mTextPaint;
private boolean mUserSetTextScaleX;
private Layout mLayout;
+ private boolean mLocaleChanged = false;
private int mGravity = Gravity.TOP | Gravity.START;
private boolean mHorizontallyScrolling;
@@ -770,6 +778,8 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
boolean selectallonfocus = false;
Drawable drawableLeft = null, drawableTop = null, drawableRight = null,
drawableBottom = null, drawableStart = null, drawableEnd = null;
+ ColorStateList drawableTint = null;
+ PorterDuff.Mode drawableTintMode = null;
int drawablePadding = 0;
int ellipsize = -1;
boolean singleLine = false;
@@ -855,6 +865,14 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
drawableEnd = a.getDrawable(attr);
break;
+ case com.android.internal.R.styleable.TextView_drawableTint:
+ drawableTint = a.getColorStateList(attr);
+ break;
+
+ case com.android.internal.R.styleable.TextView_drawableTintMode:
+ drawableTintMode = Drawable.parseTintMode(a.getInt(attr, -1), drawableTintMode);
+ break;
+
case com.android.internal.R.styleable.TextView_drawablePadding:
drawablePadding = a.getDimensionPixelSize(attr, drawablePadding);
break;
@@ -1238,6 +1256,22 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
bufferType = BufferType.SPANNABLE;
}
+ // Set up the tint (if needed) before setting the drawables so that it
+ // gets applied correctly.
+ if (drawableTint != null || drawableTintMode != null) {
+ if (mDrawables == null) {
+ mDrawables = new Drawables(context);
+ }
+ if (drawableTint != null) {
+ mDrawables.mTintList = drawableTint;
+ mDrawables.mHasTint = true;
+ }
+ if (drawableTintMode != null) {
+ mDrawables.mTintMode = drawableTintMode;
+ mDrawables.mHasTintMode = true;
+ }
+ }
+
// This call will save the initial left/right drawables
setCompoundDrawablesWithIntrinsicBounds(
drawableLeft, drawableTop, drawableRight, drawableBottom);
@@ -1420,6 +1454,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
}
resetResolvedDrawables();
resolveDrawables();
+ applyCompoundDrawableTint();
}
}
@@ -1778,7 +1813,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
*/
public int getCompoundPaddingTop() {
final Drawables dr = mDrawables;
- if (dr == null || dr.mDrawableTop == null) {
+ if (dr == null || dr.mShowing[Drawables.TOP] == null) {
return mPaddingTop;
} else {
return mPaddingTop + dr.mDrawablePadding + dr.mDrawableSizeTop;
@@ -1791,7 +1826,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
*/
public int getCompoundPaddingBottom() {
final Drawables dr = mDrawables;
- if (dr == null || dr.mDrawableBottom == null) {
+ if (dr == null || dr.mShowing[Drawables.BOTTOM] == null) {
return mPaddingBottom;
} else {
return mPaddingBottom + dr.mDrawablePadding + dr.mDrawableSizeBottom;
@@ -1804,7 +1839,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
*/
public int getCompoundPaddingLeft() {
final Drawables dr = mDrawables;
- if (dr == null || dr.mDrawableLeft == null) {
+ if (dr == null || dr.mShowing[Drawables.LEFT] == null) {
return mPaddingLeft;
} else {
return mPaddingLeft + dr.mDrawablePadding + dr.mDrawableSizeLeft;
@@ -1817,7 +1852,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
*/
public int getCompoundPaddingRight() {
final Drawables dr = mDrawables;
- if (dr == null || dr.mDrawableRight == null) {
+ if (dr == null || dr.mShowing[Drawables.RIGHT] == null) {
return mPaddingRight;
} else {
return mPaddingRight + dr.mDrawablePadding + dr.mDrawableSizeRight;
@@ -2015,14 +2050,12 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
} else {
// We need to retain the last set padding, so just clear
// out all of the fields in the existing structure.
- if (dr.mDrawableLeft != null) dr.mDrawableLeft.setCallback(null);
- dr.mDrawableLeft = null;
- if (dr.mDrawableTop != null) dr.mDrawableTop.setCallback(null);
- dr.mDrawableTop = null;
- if (dr.mDrawableRight != null) dr.mDrawableRight.setCallback(null);
- dr.mDrawableRight = null;
- if (dr.mDrawableBottom != null) dr.mDrawableBottom.setCallback(null);
- dr.mDrawableBottom = null;
+ for (int i = dr.mShowing.length - 1; i >= 0; i--) {
+ if (dr.mShowing[i] != null) {
+ dr.mShowing[i].setCallback(null);
+ }
+ dr.mShowing[i] = null;
+ }
dr.mDrawableSizeLeft = dr.mDrawableHeightLeft = 0;
dr.mDrawableSizeRight = dr.mDrawableHeightRight = 0;
dr.mDrawableSizeTop = dr.mDrawableWidthTop = 0;
@@ -2036,25 +2069,25 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
mDrawables.mOverride = false;
- if (dr.mDrawableLeft != left && dr.mDrawableLeft != null) {
- dr.mDrawableLeft.setCallback(null);
+ if (dr.mShowing[Drawables.LEFT] != left && dr.mShowing[Drawables.LEFT] != null) {
+ dr.mShowing[Drawables.LEFT].setCallback(null);
}
- dr.mDrawableLeft = left;
+ dr.mShowing[Drawables.LEFT] = left;
- if (dr.mDrawableTop != top && dr.mDrawableTop != null) {
- dr.mDrawableTop.setCallback(null);
+ if (dr.mShowing[Drawables.TOP] != top && dr.mShowing[Drawables.TOP] != null) {
+ dr.mShowing[Drawables.TOP].setCallback(null);
}
- dr.mDrawableTop = top;
+ dr.mShowing[Drawables.TOP] = top;
- if (dr.mDrawableRight != right && dr.mDrawableRight != null) {
- dr.mDrawableRight.setCallback(null);
+ if (dr.mShowing[Drawables.RIGHT] != right && dr.mShowing[Drawables.RIGHT] != null) {
+ dr.mShowing[Drawables.RIGHT].setCallback(null);
}
- dr.mDrawableRight = right;
+ dr.mShowing[Drawables.RIGHT] = right;
- if (dr.mDrawableBottom != bottom && dr.mDrawableBottom != null) {
- dr.mDrawableBottom.setCallback(null);
+ if (dr.mShowing[Drawables.BOTTOM] != bottom && dr.mShowing[Drawables.BOTTOM] != null) {
+ dr.mShowing[Drawables.BOTTOM].setCallback(null);
}
- dr.mDrawableBottom = bottom;
+ dr.mShowing[Drawables.BOTTOM] = bottom;
final Rect compoundRect = dr.mCompoundRect;
int[] state;
@@ -2110,6 +2143,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
resetResolvedDrawables();
resolveDrawables();
+ applyCompoundDrawableTint();
invalidate();
requestLayout();
}
@@ -2193,10 +2227,14 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
// We're switching to relative, discard absolute.
if (dr != null) {
- if (dr.mDrawableLeft != null) dr.mDrawableLeft.setCallback(null);
- dr.mDrawableLeft = dr.mDrawableLeftInitial = null;
- if (dr.mDrawableRight != null) dr.mDrawableRight.setCallback(null);
- dr.mDrawableRight = dr.mDrawableRightInitial = null;
+ if (dr.mShowing[Drawables.LEFT] != null) {
+ dr.mShowing[Drawables.LEFT].setCallback(null);
+ }
+ dr.mShowing[Drawables.LEFT] = dr.mDrawableLeftInitial = null;
+ if (dr.mShowing[Drawables.RIGHT] != null) {
+ dr.mShowing[Drawables.RIGHT].setCallback(null);
+ }
+ dr.mShowing[Drawables.RIGHT] = dr.mDrawableRightInitial = null;
dr.mDrawableSizeLeft = dr.mDrawableHeightLeft = 0;
dr.mDrawableSizeRight = dr.mDrawableHeightRight = 0;
}
@@ -2214,12 +2252,18 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
// out all of the fields in the existing structure.
if (dr.mDrawableStart != null) dr.mDrawableStart.setCallback(null);
dr.mDrawableStart = null;
- if (dr.mDrawableTop != null) dr.mDrawableTop.setCallback(null);
- dr.mDrawableTop = null;
- if (dr.mDrawableEnd != null) dr.mDrawableEnd.setCallback(null);
+ if (dr.mShowing[Drawables.TOP] != null) {
+ dr.mShowing[Drawables.TOP].setCallback(null);
+ }
+ dr.mShowing[Drawables.TOP] = null;
+ if (dr.mDrawableEnd != null) {
+ dr.mDrawableEnd.setCallback(null);
+ }
dr.mDrawableEnd = null;
- if (dr.mDrawableBottom != null) dr.mDrawableBottom.setCallback(null);
- dr.mDrawableBottom = null;
+ if (dr.mShowing[Drawables.BOTTOM] != null) {
+ dr.mShowing[Drawables.BOTTOM].setCallback(null);
+ }
+ dr.mShowing[Drawables.BOTTOM] = null;
dr.mDrawableSizeStart = dr.mDrawableHeightStart = 0;
dr.mDrawableSizeEnd = dr.mDrawableHeightEnd = 0;
dr.mDrawableSizeTop = dr.mDrawableWidthTop = 0;
@@ -2238,20 +2282,20 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
}
dr.mDrawableStart = start;
- if (dr.mDrawableTop != top && dr.mDrawableTop != null) {
- dr.mDrawableTop.setCallback(null);
+ if (dr.mShowing[Drawables.TOP] != top && dr.mShowing[Drawables.TOP] != null) {
+ dr.mShowing[Drawables.TOP].setCallback(null);
}
- dr.mDrawableTop = top;
+ dr.mShowing[Drawables.TOP] = top;
if (dr.mDrawableEnd != end && dr.mDrawableEnd != null) {
dr.mDrawableEnd.setCallback(null);
}
dr.mDrawableEnd = end;
- if (dr.mDrawableBottom != bottom && dr.mDrawableBottom != null) {
- dr.mDrawableBottom.setCallback(null);
+ if (dr.mShowing[Drawables.BOTTOM] != bottom && dr.mShowing[Drawables.BOTTOM] != null) {
+ dr.mShowing[Drawables.BOTTOM].setCallback(null);
}
- dr.mDrawableBottom = bottom;
+ dr.mShowing[Drawables.BOTTOM] = bottom;
final Rect compoundRect = dr.mCompoundRect;
int[] state;
@@ -2377,9 +2421,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
public Drawable[] getCompoundDrawables() {
final Drawables dr = mDrawables;
if (dr != null) {
- return new Drawable[] {
- dr.mDrawableLeft, dr.mDrawableTop, dr.mDrawableRight, dr.mDrawableBottom
- };
+ return dr.mShowing.clone();
} else {
return new Drawable[] { null, null, null, null };
}
@@ -2398,7 +2440,8 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
final Drawables dr = mDrawables;
if (dr != null) {
return new Drawable[] {
- dr.mDrawableStart, dr.mDrawableTop, dr.mDrawableEnd, dr.mDrawableBottom
+ dr.mDrawableStart, dr.mShowing[Drawables.TOP],
+ dr.mDrawableEnd, dr.mShowing[Drawables.BOTTOM]
};
} else {
return new Drawable[] { null, null, null, null };
@@ -2439,6 +2482,118 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
return dr != null ? dr.mDrawablePadding : 0;
}
+ /**
+ * Applies a tint to the compound drawables. Does not modify the
+ * current tint mode, which is {@link PorterDuff.Mode#SRC_IN} by default.
+ * <p>
+ * Subsequent calls to
+ * {@link #setCompoundDrawables(Drawable, Drawable, Drawable, Drawable)}
+ * and related methods will automatically mutate the drawables and apply
+ * the specified tint and tint mode using
+ * {@link Drawable#setTintList(ColorStateList)}.
+ *
+ * @param tint the tint to apply, may be {@code null} to clear tint
+ *
+ * @attr ref android.R.styleable#TextView_drawableTint
+ * @see #getCompoundDrawableTintList()
+ * @see Drawable#setTintList(ColorStateList)
+ */
+ public void setCompoundDrawableTintList(@Nullable ColorStateList tint) {
+ if (mDrawables == null) {
+ mDrawables = new Drawables(getContext());
+ }
+ mDrawables.mTintList = tint;
+ mDrawables.mHasTint = true;
+
+ applyCompoundDrawableTint();
+ }
+
+ /**
+ * @return the tint applied to the compound drawables
+ * @attr ref android.R.styleable#TextView_drawableTint
+ * @see #setCompoundDrawableTintList(ColorStateList)
+ */
+ public ColorStateList getCompoundDrawableTintList() {
+ return mDrawables != null ? mDrawables.mTintList : null;
+ }
+
+ /**
+ * Specifies the blending mode used to apply the tint specified by
+ * {@link #setCompoundDrawableTintList(ColorStateList)} to the compound
+ * drawables. The default mode is {@link PorterDuff.Mode#SRC_IN}.
+ *
+ * @param tintMode the blending mode used to apply the tint, may be
+ * {@code null} to clear tint
+ * @attr ref android.R.styleable#TextView_drawableTintMode
+ * @see #setCompoundDrawableTintList(ColorStateList)
+ * @see Drawable#setTintMode(PorterDuff.Mode)
+ */
+ public void setCompoundDrawableTintMode(@Nullable PorterDuff.Mode tintMode) {
+ if (mDrawables == null) {
+ mDrawables = new Drawables(getContext());
+ }
+ mDrawables.mTintMode = tintMode;
+ mDrawables.mHasTintMode = true;
+
+ applyCompoundDrawableTint();
+ }
+
+ /**
+ * Returns the blending mode used to apply the tint to the compound
+ * drawables, if specified.
+ *
+ * @return the blending mode used to apply the tint to the compound
+ * drawables
+ * @attr ref android.R.styleable#TextView_drawableTintMode
+ * @see #setCompoundDrawableTintMode(PorterDuff.Mode)
+ */
+ public PorterDuff.Mode getCompoundDrawableTintMode() {
+ return mDrawables != null ? mDrawables.mTintMode : null;
+ }
+
+ private void applyCompoundDrawableTint() {
+ if (mDrawables == null) {
+ return;
+ }
+
+ if (mDrawables.mHasTint || mDrawables.mHasTintMode) {
+ final ColorStateList tintList = mDrawables.mTintList;
+ final PorterDuff.Mode tintMode = mDrawables.mTintMode;
+ final boolean hasTint = mDrawables.mHasTint;
+ final boolean hasTintMode = mDrawables.mHasTintMode;
+ final int[] state = getDrawableState();
+
+ for (Drawable dr : mDrawables.mShowing) {
+ if (dr == null) {
+ continue;
+ }
+
+ if (dr == mDrawables.mDrawableError) {
+ // From a developer's perspective, the error drawable isn't
+ // a compound drawable. Don't apply the generic compound
+ // drawable tint to it.
+ continue;
+ }
+
+ dr.mutate();
+
+ if (hasTint) {
+ dr.setTintList(tintList);
+ }
+
+ if (hasTintMode) {
+ dr.setTintMode(tintMode);
+ }
+
+ // The drawable (or one of its children) may not have been
+ // stateful before applying the tint, so let's try again.
+ if (dr.isStateful()) {
+ dr.setState(state);
+ }
+ }
+ }
+ }
+
@Override
public void setPadding(int left, int top, int right, int bottom) {
if (left != mPaddingLeft ||
@@ -2587,9 +2742,18 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
* @see Paint#setTextLocale
*/
public void setTextLocale(Locale locale) {
+ mLocaleChanged = true;
mTextPaint.setTextLocale(locale);
}
+ @Override
+ protected void onConfigurationChanged(Configuration newConfig) {
+ super.onConfigurationChanged(newConfig);
+ if (!mLocaleChanged) {
+ mTextPaint.setTextLocale(Locale.getDefault());
+ }
+ }
+
/**
* @return the size (in pixels) of the default text size in this TextView.
*/
@@ -3657,26 +3821,12 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
updateTextColors();
}
- final Drawables dr = mDrawables;
- if (dr != null) {
- int[] state = getDrawableState();
- if (dr.mDrawableTop != null && dr.mDrawableTop.isStateful()) {
- dr.mDrawableTop.setState(state);
- }
- if (dr.mDrawableBottom != null && dr.mDrawableBottom.isStateful()) {
- dr.mDrawableBottom.setState(state);
- }
- if (dr.mDrawableLeft != null && dr.mDrawableLeft.isStateful()) {
- dr.mDrawableLeft.setState(state);
- }
- if (dr.mDrawableRight != null && dr.mDrawableRight.isStateful()) {
- dr.mDrawableRight.setState(state);
- }
- if (dr.mDrawableStart != null && dr.mDrawableStart.isStateful()) {
- dr.mDrawableStart.setState(state);
- }
- if (dr.mDrawableEnd != null && dr.mDrawableEnd.isStateful()) {
- dr.mDrawableEnd.setState(state);
+ if (mDrawables != null) {
+ final int[] state = getDrawableState();
+ for (Drawable dr : mDrawables.mShowing) {
+ if (dr != null && dr.isStateful()) {
+ dr.setState(state);
+ }
}
}
}
@@ -3685,25 +3835,12 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
public void drawableHotspotChanged(float x, float y) {
super.drawableHotspotChanged(x, y);
- final Drawables dr = mDrawables;
- if (dr != null) {
- if (dr.mDrawableTop != null) {
- dr.mDrawableTop.setHotspot(x, y);
- }
- if (dr.mDrawableBottom != null) {
- dr.mDrawableBottom.setHotspot(x, y);
- }
- if (dr.mDrawableLeft != null) {
- dr.mDrawableLeft.setHotspot(x, y);
- }
- if (dr.mDrawableRight != null) {
- dr.mDrawableRight.setHotspot(x, y);
- }
- if (dr.mDrawableStart != null) {
- dr.mDrawableStart.setHotspot(x, y);
- }
- if (dr.mDrawableEnd != null) {
- dr.mDrawableEnd.setHotspot(x, y);
+ if (mDrawables != null) {
+ final int[] state = getDrawableState();
+ for (Drawable dr : mDrawables.mShowing) {
+ if (dr != null && dr.isStateful()) {
+ dr.setHotspot(x, y);
+ }
}
}
}
@@ -5034,9 +5171,11 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
protected boolean verifyDrawable(Drawable who) {
final boolean verified = super.verifyDrawable(who);
if (!verified && mDrawables != null) {
- return who == mDrawables.mDrawableLeft || who == mDrawables.mDrawableTop ||
- who == mDrawables.mDrawableRight || who == mDrawables.mDrawableBottom ||
- who == mDrawables.mDrawableStart || who == mDrawables.mDrawableEnd;
+ for (Drawable dr : mDrawables.mShowing) {
+ if (who == dr) {
+ return true;
+ }
+ }
}
return verified;
}
@@ -5045,23 +5184,10 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
public void jumpDrawablesToCurrentState() {
super.jumpDrawablesToCurrentState();
if (mDrawables != null) {
- if (mDrawables.mDrawableLeft != null) {
- mDrawables.mDrawableLeft.jumpToCurrentState();
- }
- if (mDrawables.mDrawableTop != null) {
- mDrawables.mDrawableTop.jumpToCurrentState();
- }
- if (mDrawables.mDrawableRight != null) {
- mDrawables.mDrawableRight.jumpToCurrentState();
- }
- if (mDrawables.mDrawableBottom != null) {
- mDrawables.mDrawableBottom.jumpToCurrentState();
- }
- if (mDrawables.mDrawableStart != null) {
- mDrawables.mDrawableStart.jumpToCurrentState();
- }
- if (mDrawables.mDrawableEnd != null) {
- mDrawables.mDrawableEnd.jumpToCurrentState();
+ for (Drawable dr : mDrawables.mShowing) {
+ if (dr != null) {
+ dr.jumpToCurrentState();
+ }
}
}
}
@@ -5080,7 +5206,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
// accordingly.
final TextView.Drawables drawables = mDrawables;
if (drawables != null) {
- if (drawable == drawables.mDrawableLeft) {
+ if (drawable == drawables.mShowing[Drawables.LEFT]) {
final int compoundPaddingTop = getCompoundPaddingTop();
final int compoundPaddingBottom = getCompoundPaddingBottom();
final int vspace = mBottom - mTop - compoundPaddingBottom - compoundPaddingTop;
@@ -5088,7 +5214,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
scrollX += mPaddingLeft;
scrollY += compoundPaddingTop + (vspace - drawables.mDrawableHeightLeft) / 2;
handled = true;
- } else if (drawable == drawables.mDrawableRight) {
+ } else if (drawable == drawables.mShowing[Drawables.RIGHT]) {
final int compoundPaddingTop = getCompoundPaddingTop();
final int compoundPaddingBottom = getCompoundPaddingBottom();
final int vspace = mBottom - mTop - compoundPaddingBottom - compoundPaddingTop;
@@ -5096,7 +5222,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
scrollX += (mRight - mLeft - mPaddingRight - drawables.mDrawableSizeRight);
scrollY += compoundPaddingTop + (vspace - drawables.mDrawableHeightRight) / 2;
handled = true;
- } else if (drawable == drawables.mDrawableTop) {
+ } else if (drawable == drawables.mShowing[Drawables.TOP]) {
final int compoundPaddingLeft = getCompoundPaddingLeft();
final int compoundPaddingRight = getCompoundPaddingRight();
final int hspace = mRight - mLeft - compoundPaddingRight - compoundPaddingLeft;
@@ -5104,7 +5230,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
scrollX += compoundPaddingLeft + (hspace - drawables.mDrawableWidthTop) / 2;
scrollY += mPaddingTop;
handled = true;
- } else if (drawable == drawables.mDrawableBottom) {
+ } else if (drawable == drawables.mShowing[Drawables.BOTTOM]) {
final int compoundPaddingLeft = getCompoundPaddingLeft();
final int compoundPaddingRight = getCompoundPaddingRight();
final int hspace = mRight - mLeft - compoundPaddingRight - compoundPaddingLeft;
@@ -5308,44 +5434,44 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
// IMPORTANT: The coordinates computed are also used in invalidateDrawable()
// Make sure to update invalidateDrawable() when changing this code.
- if (dr.mDrawableLeft != null) {
+ if (dr.mShowing[Drawables.LEFT] != null) {
canvas.save();
canvas.translate(scrollX + mPaddingLeft + leftOffset,
scrollY + compoundPaddingTop +
(vspace - dr.mDrawableHeightLeft) / 2);
- dr.mDrawableLeft.draw(canvas);
+ dr.mShowing[Drawables.LEFT].draw(canvas);
canvas.restore();
}
// IMPORTANT: The coordinates computed are also used in invalidateDrawable()
// Make sure to update invalidateDrawable() when changing this code.
- if (dr.mDrawableRight != null) {
+ if (dr.mShowing[Drawables.RIGHT] != null) {
canvas.save();
canvas.translate(scrollX + right - left - mPaddingRight
- dr.mDrawableSizeRight - rightOffset,
scrollY + compoundPaddingTop + (vspace - dr.mDrawableHeightRight) / 2);
- dr.mDrawableRight.draw(canvas);
+ dr.mShowing[Drawables.RIGHT].draw(canvas);
canvas.restore();
}
// IMPORTANT: The coordinates computed are also used in invalidateDrawable()
// Make sure to update invalidateDrawable() when changing this code.
- if (dr.mDrawableTop != null) {
+ if (dr.mShowing[Drawables.TOP] != null) {
canvas.save();
canvas.translate(scrollX + compoundPaddingLeft +
(hspace - dr.mDrawableWidthTop) / 2, scrollY + mPaddingTop);
- dr.mDrawableTop.draw(canvas);
+ dr.mShowing[Drawables.TOP].draw(canvas);
canvas.restore();
}
// IMPORTANT: The coordinates computed are also used in invalidateDrawable()
// Make sure to update invalidateDrawable() when changing this code.
- if (dr.mDrawableBottom != null) {
+ if (dr.mShowing[Drawables.BOTTOM] != null) {
canvas.save();
canvas.translate(scrollX + compoundPaddingLeft +
(hspace - dr.mDrawableWidthBottom) / 2,
scrollY + bottom - top - mPaddingBottom - dr.mDrawableSizeBottom);
- dr.mDrawableBottom.draw(canvas);
+ dr.mShowing[Drawables.BOTTOM].draw(canvas);
canvas.restore();
}
}
@@ -8376,9 +8502,10 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
}
}
+ /** @hide */
@Override
- public void onPopulateAccessibilityEvent(AccessibilityEvent event) {
- super.onPopulateAccessibilityEvent(event);
+ public void onPopulateAccessibilityEventInternal(AccessibilityEvent event) {
+ super.onPopulateAccessibilityEventInternal(event);
final boolean isPassword = hasPasswordTransformationMethod();
if (!isPassword || shouldSpeakPasswordsForAccessibility()) {
@@ -8399,9 +8526,10 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
UserHandle.USER_CURRENT_OR_SELF) == 1);
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
- super.onInitializeAccessibilityEvent(event);
+ public void onInitializeAccessibilityEventInternal(AccessibilityEvent event) {
+ super.onInitializeAccessibilityEventInternal(event);
event.setClassName(TextView.class.getName());
final boolean isPassword = hasPasswordTransformationMethod();
@@ -8414,9 +8542,10 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
}
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
- super.onInitializeAccessibilityNodeInfo(info);
+ public void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) {
+ super.onInitializeAccessibilityNodeInfoInternal(info);
info.setClassName(TextView.class.getName());
final boolean isPassword = hasPasswordTransformationMethod();
@@ -8574,15 +8703,16 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
}
}
+ /** @hide */
@Override
- public void sendAccessibilityEvent(int eventType) {
+ public void sendAccessibilityEventInternal(int eventType) {
// Do not send scroll events since first they are not interesting for
// accessibility and second such events a generated too frequently.
// For details see the implementation of bringTextIntoView().
if (eventType == AccessibilityEvent.TYPE_VIEW_SCROLLED) {
return;
}
- super.sendAccessibilityEvent(eventType);
+ super.sendAccessibilityEventInternal(eventType);
}
/**
diff --git a/core/java/android/widget/TextViewWithCircularIndicator.java b/core/java/android/widget/TextViewWithCircularIndicator.java
index 43c0843..d3c786c 100644
--- a/core/java/android/widget/TextViewWithCircularIndicator.java
+++ b/core/java/android/widget/TextViewWithCircularIndicator.java
@@ -18,7 +18,6 @@ package android.widget;
import android.content.Context;
import android.content.res.Resources;
-import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Typeface;
@@ -27,14 +26,8 @@ import android.util.AttributeSet;
import com.android.internal.R;
class TextViewWithCircularIndicator extends TextView {
-
- private static final int SELECTED_CIRCLE_ALPHA = 60;
-
private final Paint mCirclePaint = new Paint();
-
private final String mItemIsSelectedText;
- private int mCircleColor;
- private boolean mDrawIndicator;
public TextViewWithCircularIndicator(Context context) {
this(context, null);
@@ -50,22 +43,11 @@ class TextViewWithCircularIndicator extends TextView {
public TextViewWithCircularIndicator(Context context, AttributeSet attrs,
int defStyleAttr, int defStyleRes) {
- super(context, attrs);
-
-
- // Use Theme attributes if possible
- final TypedArray a = mContext.obtainStyledAttributes(attrs,
- R.styleable.DatePicker, defStyleAttr, defStyleRes);
- final int resId = a.getResourceId(R.styleable.DatePicker_yearListItemTextAppearance, -1);
- if (resId != -1) {
- setTextAppearance(context, resId);
- }
+ super(context, attrs, defStyleAttr, defStyleRes);
final Resources res = context.getResources();
mItemIsSelectedText = res.getString(R.string.item_is_selected);
- a.recycle();
-
init();
}
@@ -77,33 +59,26 @@ class TextViewWithCircularIndicator extends TextView {
}
public void setCircleColor(int color) {
- if (color != mCircleColor) {
- mCircleColor = color;
- mCirclePaint.setColor(mCircleColor);
- mCirclePaint.setAlpha(SELECTED_CIRCLE_ALPHA);
- requestLayout();
- }
- }
-
- public void setDrawIndicator(boolean drawIndicator) {
- mDrawIndicator = drawIndicator;
+ mCirclePaint.setColor(color);
+ invalidate();
}
@Override
public void onDraw(Canvas canvas) {
- super.onDraw(canvas);
- if (mDrawIndicator) {
+ if (isActivated()) {
final int width = getWidth();
final int height = getHeight();
- int radius = Math.min(width, height) / 2;
+ final int radius = Math.min(width, height) / 2;
canvas.drawCircle(width / 2, height / 2, radius, mCirclePaint);
}
+
+ super.onDraw(canvas);
}
@Override
public CharSequence getContentDescription() {
- CharSequence itemText = getText();
- if (mDrawIndicator) {
+ final CharSequence itemText = getText();
+ if (isActivated()) {
return String.format(mItemIsSelectedText, itemText);
} else {
return itemText;
diff --git a/core/java/android/widget/TimePicker.java b/core/java/android/widget/TimePicker.java
index 26e02f8..bbf5f53 100644
--- a/core/java/android/widget/TimePicker.java
+++ b/core/java/android/widget/TimePicker.java
@@ -195,26 +195,30 @@ public class TimePicker extends FrameLayout {
mDelegate.onRestoreInstanceState(ss);
}
+ /** @hide */
@Override
- public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
+ public boolean dispatchPopulateAccessibilityEventInternal(AccessibilityEvent event) {
return mDelegate.dispatchPopulateAccessibilityEvent(event);
}
+ /** @hide */
@Override
- public void onPopulateAccessibilityEvent(AccessibilityEvent event) {
- super.onPopulateAccessibilityEvent(event);
+ public void onPopulateAccessibilityEventInternal(AccessibilityEvent event) {
+ super.onPopulateAccessibilityEventInternal(event);
mDelegate.onPopulateAccessibilityEvent(event);
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
- super.onInitializeAccessibilityEvent(event);
+ public void onInitializeAccessibilityEventInternal(AccessibilityEvent event) {
+ super.onInitializeAccessibilityEventInternal(event);
mDelegate.onInitializeAccessibilityEvent(event);
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
- super.onInitializeAccessibilityNodeInfo(info);
+ public void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) {
+ super.onInitializeAccessibilityNodeInfoInternal(info);
mDelegate.onInitializeAccessibilityNodeInfo(info);
}
diff --git a/core/java/android/widget/ToggleButton.java b/core/java/android/widget/ToggleButton.java
index 28519d1..1b23778 100644
--- a/core/java/android/widget/ToggleButton.java
+++ b/core/java/android/widget/ToggleButton.java
@@ -153,15 +153,17 @@ public class ToggleButton extends CompoundButton {
}
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
- super.onInitializeAccessibilityEvent(event);
+ public void onInitializeAccessibilityEventInternal(AccessibilityEvent event) {
+ super.onInitializeAccessibilityEventInternal(event);
event.setClassName(ToggleButton.class.getName());
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
- super.onInitializeAccessibilityNodeInfo(info);
+ public void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) {
+ super.onInitializeAccessibilityNodeInfoInternal(info);
info.setClassName(ToggleButton.class.getName());
}
}
diff --git a/core/java/android/widget/TwoLineListItem.java b/core/java/android/widget/TwoLineListItem.java
index 5606c60..9035dbe 100644
--- a/core/java/android/widget/TwoLineListItem.java
+++ b/core/java/android/widget/TwoLineListItem.java
@@ -93,15 +93,17 @@ public class TwoLineListItem extends RelativeLayout {
return mText2;
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
- super.onInitializeAccessibilityEvent(event);
+ public void onInitializeAccessibilityEventInternal(AccessibilityEvent event) {
+ super.onInitializeAccessibilityEventInternal(event);
event.setClassName(TwoLineListItem.class.getName());
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
- super.onInitializeAccessibilityNodeInfo(info);
+ public void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) {
+ super.onInitializeAccessibilityNodeInfoInternal(info);
info.setClassName(TwoLineListItem.class.getName());
}
}
diff --git a/core/java/android/widget/VideoView.java b/core/java/android/widget/VideoView.java
index 572cca2..a240dc2 100644
--- a/core/java/android/widget/VideoView.java
+++ b/core/java/android/widget/VideoView.java
@@ -201,15 +201,17 @@ public class VideoView extends SurfaceView
setMeasuredDimension(width, height);
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
- super.onInitializeAccessibilityEvent(event);
+ public void onInitializeAccessibilityEventInternal(AccessibilityEvent event) {
+ super.onInitializeAccessibilityEventInternal(event);
event.setClassName(VideoView.class.getName());
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
- super.onInitializeAccessibilityNodeInfo(info);
+ public void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) {
+ super.onInitializeAccessibilityNodeInfoInternal(info);
info.setClassName(VideoView.class.getName());
}
diff --git a/core/java/android/widget/ViewAnimator.java b/core/java/android/widget/ViewAnimator.java
index eee914e..d31754b 100644
--- a/core/java/android/widget/ViewAnimator.java
+++ b/core/java/android/widget/ViewAnimator.java
@@ -357,15 +357,17 @@ public class ViewAnimator extends FrameLayout {
return (getCurrentView() != null) ? getCurrentView().getBaseline() : super.getBaseline();
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
- super.onInitializeAccessibilityEvent(event);
+ public void onInitializeAccessibilityEventInternal(AccessibilityEvent event) {
+ super.onInitializeAccessibilityEventInternal(event);
event.setClassName(ViewAnimator.class.getName());
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
- super.onInitializeAccessibilityNodeInfo(info);
+ public void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) {
+ super.onInitializeAccessibilityNodeInfoInternal(info);
info.setClassName(ViewAnimator.class.getName());
}
}
diff --git a/core/java/android/widget/ViewFlipper.java b/core/java/android/widget/ViewFlipper.java
index cf1f554..587f469 100644
--- a/core/java/android/widget/ViewFlipper.java
+++ b/core/java/android/widget/ViewFlipper.java
@@ -149,15 +149,17 @@ public class ViewFlipper extends ViewAnimator {
updateRunning();
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
- super.onInitializeAccessibilityEvent(event);
+ public void onInitializeAccessibilityEventInternal(AccessibilityEvent event) {
+ super.onInitializeAccessibilityEventInternal(event);
event.setClassName(ViewFlipper.class.getName());
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
- super.onInitializeAccessibilityNodeInfo(info);
+ public void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) {
+ super.onInitializeAccessibilityNodeInfoInternal(info);
info.setClassName(ViewFlipper.class.getName());
}
diff --git a/core/java/android/widget/ViewSwitcher.java b/core/java/android/widget/ViewSwitcher.java
index 0376918..c97770f 100644
--- a/core/java/android/widget/ViewSwitcher.java
+++ b/core/java/android/widget/ViewSwitcher.java
@@ -68,15 +68,17 @@ public class ViewSwitcher extends ViewAnimator {
super.addView(child, index, params);
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
- super.onInitializeAccessibilityEvent(event);
+ public void onInitializeAccessibilityEventInternal(AccessibilityEvent event) {
+ super.onInitializeAccessibilityEventInternal(event);
event.setClassName(ViewSwitcher.class.getName());
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
- super.onInitializeAccessibilityNodeInfo(info);
+ public void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) {
+ super.onInitializeAccessibilityNodeInfoInternal(info);
info.setClassName(ViewSwitcher.class.getName());
}
diff --git a/core/java/android/widget/YearPickerView.java b/core/java/android/widget/YearPickerView.java
index 24ed7ce..6f0465f 100644
--- a/core/java/android/widget/YearPickerView.java
+++ b/core/java/android/widget/YearPickerView.java
@@ -17,8 +17,10 @@
package android.widget;
import android.content.Context;
+import android.content.res.ColorStateList;
import android.content.res.Resources;
import android.util.AttributeSet;
+import android.util.StateSet;
import android.view.View;
import android.view.ViewGroup;
import android.view.accessibility.AccessibilityEvent;
@@ -42,7 +44,7 @@ class YearPickerView extends ListView implements AdapterView.OnItemClickListener
private DatePickerController mController;
private int mSelectedPosition = -1;
- private int mYearSelectedCircleColor;
+ private int mYearActivatedColor;
public YearPickerView(Context context) {
this(context, null);
@@ -97,15 +99,14 @@ class YearPickerView extends ListView implements AdapterView.OnItemClickListener
onDateChanged();
}
- public void setYearSelectedCircleColor(int color) {
- if (color != mYearSelectedCircleColor) {
- mYearSelectedCircleColor = color;
- }
- requestLayout();
+ public void setYearBackgroundColor(ColorStateList yearBackgroundColor) {
+ mYearActivatedColor = yearBackgroundColor.getColorForState(
+ StateSet.get(StateSet.VIEW_STATE_ENABLED | StateSet.VIEW_STATE_ACTIVATED), 0);
+ invalidate();
}
- public int getYearSelectedCircleColor() {
- return mYearSelectedCircleColor;
+ public void setYearTextAppearance(int resId) {
+ mAdapter.setItemTextAppearance(resId);
}
private void updateAdapterData() {
@@ -127,12 +128,8 @@ class YearPickerView extends ListView implements AdapterView.OnItemClickListener
mController.onYearSelected(mAdapter.getItem(position));
}
- void setItemTextAppearance(int resId) {
- mAdapter.setItemTextAppearance(resId);
- }
-
private class YearAdapter extends ArrayAdapter<Integer> {
- int mItemTextAppearanceResId;
+ private int mItemTextAppearanceResId;
public YearAdapter(Context context, int resource) {
super(context, resource);
@@ -140,16 +137,15 @@ class YearPickerView extends ListView implements AdapterView.OnItemClickListener
@Override
public View getView(int position, View convertView, ViewGroup parent) {
- TextViewWithCircularIndicator v = (TextViewWithCircularIndicator)
+ final TextViewWithCircularIndicator v = (TextViewWithCircularIndicator)
super.getView(position, convertView, parent);
- v.setTextAppearance(getContext(), mItemTextAppearanceResId);
- v.requestLayout();
- int year = getItem(position);
- boolean selected = mController.getSelectedDay().get(Calendar.YEAR) == year;
- v.setDrawIndicator(selected);
- if (selected) {
- v.setCircleColor(mYearSelectedCircleColor);
- }
+ v.setTextAppearance(v.getContext(), mItemTextAppearanceResId);
+ v.setCircleColor(mYearActivatedColor);
+
+ final int year = getItem(position);
+ final boolean selected = mController.getSelectedDay().get(Calendar.YEAR) == year;
+ v.setActivated(selected);
+
return v;
}
@@ -189,9 +185,10 @@ class YearPickerView extends ListView implements AdapterView.OnItemClickListener
mController.getSelectedDay().get(Calendar.YEAR) - mMinDate.get(Calendar.YEAR));
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
- super.onInitializeAccessibilityEvent(event);
+ public void onInitializeAccessibilityEventInternal(AccessibilityEvent event) {
+ super.onInitializeAccessibilityEventInternal(event);
if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_SCROLLED) {
event.setFromIndex(0);
diff --git a/core/java/android/widget/ZoomButton.java b/core/java/android/widget/ZoomButton.java
index 715e868..e0be0ab 100644
--- a/core/java/android/widget/ZoomButton.java
+++ b/core/java/android/widget/ZoomButton.java
@@ -103,15 +103,17 @@ public class ZoomButton extends ImageButton implements OnLongClickListener {
return super.dispatchUnhandledMove(focused, direction);
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
- super.onInitializeAccessibilityEvent(event);
+ public void onInitializeAccessibilityEventInternal(AccessibilityEvent event) {
+ super.onInitializeAccessibilityEventInternal(event);
event.setClassName(ZoomButton.class.getName());
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
- super.onInitializeAccessibilityNodeInfo(info);
+ public void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) {
+ super.onInitializeAccessibilityNodeInfoInternal(info);
info.setClassName(ZoomButton.class.getName());
}
}
diff --git a/core/java/android/widget/ZoomControls.java b/core/java/android/widget/ZoomControls.java
index 8897875..a0aacea 100644
--- a/core/java/android/widget/ZoomControls.java
+++ b/core/java/android/widget/ZoomControls.java
@@ -109,15 +109,17 @@ public class ZoomControls extends LinearLayout {
return mZoomIn.hasFocus() || mZoomOut.hasFocus();
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
- super.onInitializeAccessibilityEvent(event);
+ public void onInitializeAccessibilityEventInternal(AccessibilityEvent event) {
+ super.onInitializeAccessibilityEventInternal(event);
event.setClassName(ZoomControls.class.getName());
}
+ /** @hide */
@Override
- public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
- super.onInitializeAccessibilityNodeInfo(info);
+ public void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) {
+ super.onInitializeAccessibilityNodeInfoInternal(info);
info.setClassName(ZoomControls.class.getName());
}
}
diff --git a/core/java/com/android/internal/app/ResolverActivity.java b/core/java/com/android/internal/app/ResolverActivity.java
index 649a59f..144cc33 100644
--- a/core/java/com/android/internal/app/ResolverActivity.java
+++ b/core/java/com/android/internal/app/ResolverActivity.java
@@ -841,6 +841,8 @@ public class ResolverActivity extends Activity implements AdapterView.OnItemClic
Log.d(TAG, "Error calling setLastChosenActivity\n" + re);
}
+ // Clear the value of mOtherProfile from previous call.
+ mOtherProfile = null;
mList.clear();
if (mBaseResolveList != null) {
currentResolveList = mOrigResolveList = mBaseResolveList;
diff --git a/core/java/com/android/internal/util/UserIcons.java b/core/java/com/android/internal/util/UserIcons.java
index e1e9d5e..c69d14f 100644
--- a/core/java/com/android/internal/util/UserIcons.java
+++ b/core/java/com/android/internal/util/UserIcons.java
@@ -48,9 +48,12 @@ public class UserIcons {
if (icon == null) {
return null;
}
- Bitmap bitmap = Bitmap.createBitmap(icon.getIntrinsicWidth(), icon.getIntrinsicHeight(),
- Bitmap.Config.ARGB_8888);
- icon.draw(new Canvas(bitmap));
+ final int width = icon.getIntrinsicWidth();
+ final int height = icon.getIntrinsicHeight();
+ Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
+ Canvas canvas = new Canvas(bitmap);
+ icon.setBounds(0, 0, width, height);
+ icon.draw(canvas);
return bitmap;
}
diff --git a/core/java/com/android/internal/view/menu/ActionMenuItemView.java b/core/java/com/android/internal/view/menu/ActionMenuItemView.java
index 7eec392..f75b139 100644
--- a/core/java/com/android/internal/view/menu/ActionMenuItemView.java
+++ b/core/java/com/android/internal/view/menu/ActionMenuItemView.java
@@ -217,14 +217,14 @@ public class ActionMenuItemView extends TextView
}
@Override
- public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
+ public boolean dispatchPopulateAccessibilityEventInternal(AccessibilityEvent event) {
onPopulateAccessibilityEvent(event);
return true;
}
@Override
- public void onPopulateAccessibilityEvent(AccessibilityEvent event) {
- super.onPopulateAccessibilityEvent(event);
+ public void onPopulateAccessibilityEventInternal(AccessibilityEvent event) {
+ super.onPopulateAccessibilityEventInternal(event);
final CharSequence cdesc = getContentDescription();
if (!TextUtils.isEmpty(cdesc)) {
event.getText().add(cdesc);
diff --git a/core/java/com/android/internal/view/menu/ListMenuItemView.java b/core/java/com/android/internal/view/menu/ListMenuItemView.java
index 692bdac..29ac3f3 100644
--- a/core/java/com/android/internal/view/menu/ListMenuItemView.java
+++ b/core/java/com/android/internal/view/menu/ListMenuItemView.java
@@ -276,8 +276,8 @@ public class ListMenuItemView extends LinearLayout implements MenuView.ItemView
}
@Override
- public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
- super.onInitializeAccessibilityNodeInfo(info);
+ public void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) {
+ super.onInitializeAccessibilityNodeInfoInternal(info);
if (mItemData != null && mItemData.hasSubMenu()) {
info.setCanOpenPopup(true);
diff --git a/core/java/com/android/internal/view/menu/MenuPopupHelper.java b/core/java/com/android/internal/view/menu/MenuPopupHelper.java
index 99bb1ac..2b20b38 100644
--- a/core/java/com/android/internal/view/menu/MenuPopupHelper.java
+++ b/core/java/com/android/internal/view/menu/MenuPopupHelper.java
@@ -118,6 +118,10 @@ public class MenuPopupHelper implements AdapterView.OnItemClickListener, View.On
mDropDownGravity = gravity;
}
+ public int getGravity() {
+ return mDropDownGravity;
+ }
+
public void show() {
if (!tryShow()) {
throw new IllegalStateException("MenuPopupHelper cannot be used without an anchor");
@@ -135,7 +139,7 @@ public class MenuPopupHelper implements AdapterView.OnItemClickListener, View.On
mPopup.setAdapter(mAdapter);
mPopup.setModal(true);
- View anchor = mAnchorView;
+ final View anchor = mAnchorView;
if (anchor != null) {
final boolean addGlobalListener = mTreeObserver == null;
mTreeObserver = anchor.getViewTreeObserver(); // Refresh to latest
diff --git a/core/java/com/android/internal/widget/AccessibleDateAnimator.java b/core/java/com/android/internal/widget/AccessibleDateAnimator.java
index e91a55c..f97a5d1 100644
--- a/core/java/com/android/internal/widget/AccessibleDateAnimator.java
+++ b/core/java/com/android/internal/widget/AccessibleDateAnimator.java
@@ -40,7 +40,7 @@ public class AccessibleDateAnimator extends ViewAnimator {
* Announce the currently-selected date when launched.
*/
@Override
- public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
+ public boolean dispatchPopulateAccessibilityEventInternal(AccessibilityEvent event) {
if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {
// Clear the event's current text so that only the current date will be spoken.
event.getText().clear();
@@ -51,6 +51,6 @@ public class AccessibleDateAnimator extends ViewAnimator {
event.getText().add(dateString);
return true;
}
- return super.dispatchPopulateAccessibilityEvent(event);
+ return super.dispatchPopulateAccessibilityEventInternal(event);
}
}
diff --git a/core/java/com/android/internal/widget/ActionBarContextView.java b/core/java/com/android/internal/widget/ActionBarContextView.java
index 7c671e8..5d3f464 100644
--- a/core/java/com/android/internal/widget/ActionBarContextView.java
+++ b/core/java/com/android/internal/widget/ActionBarContextView.java
@@ -529,7 +529,7 @@ public class ActionBarContextView extends AbsActionBarView implements AnimatorLi
}
@Override
- public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
+ public void onInitializeAccessibilityEventInternal(AccessibilityEvent event) {
if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {
// Action mode started
event.setSource(this);
@@ -537,7 +537,7 @@ public class ActionBarContextView extends AbsActionBarView implements AnimatorLi
event.setPackageName(getContext().getPackageName());
event.setContentDescription(mTitle);
} else {
- super.onInitializeAccessibilityEvent(event);
+ super.onInitializeAccessibilityEventInternal(event);
}
}
diff --git a/core/java/com/android/internal/widget/ActionBarView.java b/core/java/com/android/internal/widget/ActionBarView.java
index 654d08b..88436f8 100644
--- a/core/java/com/android/internal/widget/ActionBarView.java
+++ b/core/java/com/android/internal/widget/ActionBarView.java
@@ -1463,14 +1463,14 @@ public class ActionBarView extends AbsActionBarView implements DecorToolbar {
}
@Override
- public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
+ public boolean dispatchPopulateAccessibilityEventInternal(AccessibilityEvent event) {
onPopulateAccessibilityEvent(event);
return true;
}
@Override
- public void onPopulateAccessibilityEvent(AccessibilityEvent event) {
- super.onPopulateAccessibilityEvent(event);
+ public void onPopulateAccessibilityEventInternal(AccessibilityEvent event) {
+ super.onPopulateAccessibilityEventInternal(event);
final CharSequence cdesc = getContentDescription();
if (!TextUtils.isEmpty(cdesc)) {
event.getText().add(cdesc);
diff --git a/core/java/com/android/internal/widget/ILockSettings.aidl b/core/java/com/android/internal/widget/ILockSettings.aidl
index 9501f92..0cb1f38 100644
--- a/core/java/com/android/internal/widget/ILockSettings.aidl
+++ b/core/java/com/android/internal/widget/ILockSettings.aidl
@@ -31,5 +31,4 @@ interface ILockSettings {
boolean checkVoldPassword(int userId);
boolean havePattern(int userId);
boolean havePassword(int userId);
- void removeUser(int userId);
}
diff --git a/core/java/com/android/internal/widget/LockPatternUtils.java b/core/java/com/android/internal/widget/LockPatternUtils.java
index 0afc651..ec01703 100644
--- a/core/java/com/android/internal/widget/LockPatternUtils.java
+++ b/core/java/com/android/internal/widget/LockPatternUtils.java
@@ -21,11 +21,9 @@ import android.app.ActivityManagerNative;
import android.app.AlarmManager;
import android.app.admin.DevicePolicyManager;
import android.app.trust.TrustManager;
-import android.appwidget.AppWidgetManager;
import android.content.ComponentName;
import android.content.ContentResolver;
import android.content.Context;
-import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.UserInfo;
import android.os.AsyncTask;
@@ -42,13 +40,12 @@ import android.provider.Settings;
import android.telecom.TelecomManager;
import android.text.TextUtils;
import android.util.Log;
-import android.view.IWindowManager;
import android.view.View;
import android.widget.Button;
import com.android.internal.R;
import com.google.android.collect.Lists;
-import java.io.ByteArrayOutputStream;
+
import java.nio.charset.StandardCharsets;
import libcore.util.HexEncoding;
@@ -109,46 +106,25 @@ public class LockPatternUtils {
*/
public static final int MIN_PATTERN_REGISTER_FAIL = MIN_LOCK_PATTERN_SIZE;
- /**
- * Tells the keyguard to show the user switcher when the keyguard is created.
- */
- public static final String KEYGUARD_SHOW_USER_SWITCHER = "showuserswitcher";
-
- /**
- * Tells the keyguard to show the security challenge when the keyguard is created.
- */
- public static final String KEYGUARD_SHOW_SECURITY_CHALLENGE = "showsecuritychallenge";
-
- /**
- * Tells the keyguard to show the widget with the specified id when the keyguard is created.
- */
- public static final String KEYGUARD_SHOW_APPWIDGET = "showappwidget";
-
- /**
- * The bit in LOCK_BIOMETRIC_WEAK_FLAGS to be used to indicate whether liveliness should
- * be used
- */
- public static final int FLAG_BIOMETRIC_WEAK_LIVELINESS = 0x1;
-
- /**
- * Pseudo-appwidget id we use to represent the default clock status widget
- */
- public static final int ID_DEFAULT_STATUS_WIDGET = -2;
-
+ @Deprecated
public final static String LOCKOUT_PERMANENT_KEY = "lockscreen.lockedoutpermanently";
public final static String LOCKOUT_ATTEMPT_DEADLINE = "lockscreen.lockoutattemptdeadline";
public final static String PATTERN_EVER_CHOSEN_KEY = "lockscreen.patterneverchosen";
public final static String PASSWORD_TYPE_KEY = "lockscreen.password_type";
- public static final String PASSWORD_TYPE_ALTERNATE_KEY = "lockscreen.password_type_alternate";
+ @Deprecated
+ public final static String PASSWORD_TYPE_ALTERNATE_KEY = "lockscreen.password_type_alternate";
public final static String LOCK_PASSWORD_SALT_KEY = "lockscreen.password_salt";
public final static String DISABLE_LOCKSCREEN_KEY = "lockscreen.disabled";
public final static String LOCKSCREEN_OPTIONS = "lockscreen.options";
+ @Deprecated
public final static String LOCKSCREEN_BIOMETRIC_WEAK_FALLBACK
= "lockscreen.biometric_weak_fallback";
+ @Deprecated
public final static String BIOMETRIC_WEAK_EVER_CHOSEN_KEY
= "lockscreen.biometricweakeverchosen";
public final static String LOCKSCREEN_POWER_BUTTON_INSTANTLY_LOCKS
= "lockscreen.power_button_instantly_locks";
+ @Deprecated
public final static String LOCKSCREEN_WIDGETS_ENABLED = "lockscreen.widgets_enabled";
public final static String PASSWORD_HISTORY_KEY = "lockscreen.passwordhistory";
@@ -227,7 +203,11 @@ public class LockPatternUtils {
}
public int getRequestedPasswordHistoryLength() {
- return getDevicePolicyManager().getPasswordHistoryLength(null, getCurrentOrCallingUserId());
+ return getRequestedPasswordHistoryLength(getCurrentOrCallingUserId());
+ }
+
+ private int getRequestedPasswordHistoryLength(int userId) {
+ return getDevicePolicyManager().getPasswordHistoryLength(null, userId);
}
public int getRequestedPasswordMinimumLetters() {
@@ -289,14 +269,6 @@ public class LockPatternUtils {
}
}
- public void removeUser(int userId) {
- try {
- getLockSettings().removeUser(userId);
- } catch (RemoteException re) {
- Log.e(TAG, "Couldn't remove lock settings for user " + userId);
- }
- }
-
private int getCurrentOrCallingUserId() {
if (mMultiUserMode) {
// TODO: This is a little inefficient. See if all users of this are able to
@@ -359,9 +331,10 @@ public class LockPatternUtils {
* @return Whether the password matches any in the history.
*/
public boolean checkPasswordHistory(String password) {
+ int userId = getCurrentOrCallingUserId();
String passwordHashString = new String(
- passwordToHash(password, getCurrentOrCallingUserId()), StandardCharsets.UTF_8);
- String passwordHistory = getString(PASSWORD_HISTORY_KEY);
+ passwordToHash(password, userId), StandardCharsets.UTF_8);
+ String passwordHistory = getString(PASSWORD_HISTORY_KEY, userId);
if (passwordHistory == null) {
return false;
}
@@ -383,15 +356,7 @@ public class LockPatternUtils {
* Check to see if the user has stored a lock pattern.
* @return Whether a saved pattern exists.
*/
- public boolean savedPatternExists() {
- return savedPatternExists(getCurrentOrCallingUserId());
- }
-
- /**
- * Check to see if the user has stored a lock pattern.
- * @return Whether a saved pattern exists.
- */
- public boolean savedPatternExists(int userId) {
+ private boolean savedPatternExists(int userId) {
try {
return getLockSettings().havePattern(userId);
} catch (RemoteException re) {
@@ -403,15 +368,7 @@ public class LockPatternUtils {
* Check to see if the user has stored a lock pattern.
* @return Whether a saved pattern exists.
*/
- public boolean savedPasswordExists() {
- return savedPasswordExists(getCurrentOrCallingUserId());
- }
-
- /**
- * Check to see if the user has stored a lock pattern.
- * @return Whether a saved pattern exists.
- */
- public boolean savedPasswordExists(int userId) {
+ private boolean savedPasswordExists(int userId) {
try {
return getLockSettings().havePassword(userId);
} catch (RemoteException re) {
@@ -426,86 +383,62 @@ public class LockPatternUtils {
* @return True if the user has ever chosen a pattern.
*/
public boolean isPatternEverChosen() {
- return getBoolean(PATTERN_EVER_CHOSEN_KEY, false);
+ return getBoolean(PATTERN_EVER_CHOSEN_KEY, false, getCurrentOrCallingUserId());
}
/**
- * Return true if the user has ever chosen biometric weak. This is true even if biometric
- * weak is not current set.
- *
- * @return True if the user has ever chosen biometric weak.
+ * Used by device policy manager to validate the current password
+ * information it has.
*/
- public boolean isBiometricWeakEverChosen() {
- return getBoolean(BIOMETRIC_WEAK_EVER_CHOSEN_KEY, false);
+ public int getActivePasswordQuality() {
+ return getActivePasswordQuality(getCurrentOrCallingUserId());
}
/**
* Used by device policy manager to validate the current password
* information it has.
*/
- public int getActivePasswordQuality() {
- int activePasswordQuality = DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED;
- // Note we don't want to use getKeyguardStoredPasswordQuality() because we want this to
- // return biometric_weak if that is being used instead of the backup
- int quality =
- (int) getLong(PASSWORD_TYPE_KEY, DevicePolicyManager.PASSWORD_QUALITY_SOMETHING);
- switch (quality) {
- case DevicePolicyManager.PASSWORD_QUALITY_SOMETHING:
- if (isLockPatternEnabled()) {
- activePasswordQuality = DevicePolicyManager.PASSWORD_QUALITY_SOMETHING;
- }
- break;
- case DevicePolicyManager.PASSWORD_QUALITY_BIOMETRIC_WEAK:
- if (isBiometricWeakInstalled()) {
- activePasswordQuality = DevicePolicyManager.PASSWORD_QUALITY_BIOMETRIC_WEAK;
- }
- break;
- case DevicePolicyManager.PASSWORD_QUALITY_NUMERIC:
- if (isLockPasswordEnabled()) {
- activePasswordQuality = DevicePolicyManager.PASSWORD_QUALITY_NUMERIC;
- }
- break;
- case DevicePolicyManager.PASSWORD_QUALITY_NUMERIC_COMPLEX:
- if (isLockPasswordEnabled()) {
- activePasswordQuality = DevicePolicyManager.PASSWORD_QUALITY_NUMERIC_COMPLEX;
- }
- break;
- case DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC:
- if (isLockPasswordEnabled()) {
- activePasswordQuality = DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC;
- }
- break;
- case DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC:
- if (isLockPasswordEnabled()) {
- activePasswordQuality = DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC;
- }
- break;
- case DevicePolicyManager.PASSWORD_QUALITY_COMPLEX:
- if (isLockPasswordEnabled()) {
- activePasswordQuality = DevicePolicyManager.PASSWORD_QUALITY_COMPLEX;
- }
- break;
+ public int getActivePasswordQuality(int userId) {
+ int quality = getKeyguardStoredPasswordQuality(userId);
+
+ if (isLockPasswordEnabled(quality, userId)) {
+ // Quality is a password and a password exists. Return the quality.
+ return quality;
+ }
+
+ if (isLockPatternEnabled(quality, userId)) {
+ // Quality is a pattern and a pattern exists. Return the quality.
+ return quality;
}
- return activePasswordQuality;
+ return DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED;
}
- public void clearLock(boolean isFallback) {
- clearLock(isFallback, getCurrentOrCallingUserId());
+ public void clearLock() {
+ clearLock(getCurrentOrCallingUserId());
}
/**
* Clear any lock pattern or password.
*/
- public void clearLock(boolean isFallback, int userHandle) {
- if(!isFallback) deleteGallery(userHandle);
- saveLockPassword(null, DevicePolicyManager.PASSWORD_QUALITY_SOMETHING, isFallback,
- userHandle);
- setLockPatternEnabled(false, userHandle);
- saveLockPattern(null, isFallback, userHandle);
+ public void clearLock(int userHandle) {
setLong(PASSWORD_TYPE_KEY, DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED, userHandle);
- setLong(PASSWORD_TYPE_ALTERNATE_KEY, DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED,
- userHandle);
+
+ try {
+ getLockSettings().setLockPassword(null, userHandle);
+ getLockSettings().setLockPattern(null, userHandle);
+ } catch (RemoteException e) {
+ // well, we tried...
+ }
+
+ if (userHandle == UserHandle.USER_OWNER) {
+ // Set the encryption password to default.
+ updateEncryptionPassword(StorageManager.CRYPT_TYPE_DEFAULT, null);
+ }
+
+ getDevicePolicyManager().setActivePasswordState(
+ DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED, 0, 0, 0, 0, 0, 0, 0, userHandle);
+
onAfterChangingPassword(userHandle);
}
@@ -516,7 +449,7 @@ public class LockPatternUtils {
* @param disable Disables lock screen when true
*/
public void setLockScreenDisabled(boolean disable) {
- setLong(DISABLE_LOCKSCREEN_KEY, disable ? 1 : 0);
+ setBoolean(DISABLE_LOCKSCREEN_KEY, disable, getCurrentOrCallingUserId());
}
/**
@@ -526,7 +459,7 @@ public class LockPatternUtils {
* @return true if lock screen is can be disabled
*/
public boolean isLockScreenDisabled() {
- if (!isSecure() && getLong(DISABLE_LOCKSCREEN_KEY, 0) != 0) {
+ if (!isSecure() && getBoolean(DISABLE_LOCKSCREEN_KEY, false, getCurrentOrCallingUserId())) {
// Check if the number of switchable users forces the lockscreen.
final List<UserInfo> users = UserManager.get(mContext).getUsers(true);
final int userCount = users.size();
@@ -542,96 +475,56 @@ public class LockPatternUtils {
}
/**
- * Calls back SetupFaceLock to delete the temporary gallery file
- */
- public void deleteTempGallery() {
- Intent intent = new Intent().setAction("com.android.facelock.DELETE_GALLERY");
- intent.putExtra("deleteTempGallery", true);
- mContext.sendBroadcast(intent);
- }
-
- /**
- * Calls back SetupFaceLock to delete the gallery file when the lock type is changed
- */
- void deleteGallery(int userId) {
- if(usingBiometricWeak(userId)) {
- Intent intent = new Intent().setAction("com.android.facelock.DELETE_GALLERY");
- intent.putExtra("deleteGallery", true);
- mContext.sendBroadcastAsUser(intent, new UserHandle(userId));
- }
- }
-
- /**
* Save a lock pattern.
* @param pattern The new pattern to save.
*/
public void saveLockPattern(List<LockPatternView.Cell> pattern) {
- this.saveLockPattern(pattern, false);
+ this.saveLockPattern(pattern, getCurrentOrCallingUserId());
}
/**
* Save a lock pattern.
* @param pattern The new pattern to save.
- */
- public void saveLockPattern(List<LockPatternView.Cell> pattern, boolean isFallback) {
- this.saveLockPattern(pattern, isFallback, getCurrentOrCallingUserId());
- }
-
- /**
- * Save a lock pattern.
- * @param pattern The new pattern to save.
- * @param isFallback Specifies if this is a fallback to biometric weak
* @param userId the user whose pattern is to be saved.
*/
- public void saveLockPattern(List<LockPatternView.Cell> pattern, boolean isFallback,
- int userId) {
+ public void saveLockPattern(List<LockPatternView.Cell> pattern, int userId) {
try {
+ if (pattern == null) {
+ throw new IllegalArgumentException("pattern must not be null");
+ }
+
getLockSettings().setLockPattern(patternToString(pattern), userId);
DevicePolicyManager dpm = getDevicePolicyManager();
- if (pattern != null) {
- // Update the device encryption password.
- if (userId == UserHandle.USER_OWNER
- && LockPatternUtils.isDeviceEncryptionEnabled()) {
- final boolean required = isCredentialRequiredToDecrypt(true);
- if (!required) {
- clearEncryptionPassword();
- } else {
- String stringPattern = patternToString(pattern);
- updateEncryptionPassword(StorageManager.CRYPT_TYPE_PATTERN, stringPattern);
- }
- }
- setBoolean(PATTERN_EVER_CHOSEN_KEY, true, userId);
- if (!isFallback) {
- deleteGallery(userId);
- setLong(PASSWORD_TYPE_KEY, DevicePolicyManager.PASSWORD_QUALITY_SOMETHING, userId);
- dpm.setActivePasswordState(DevicePolicyManager.PASSWORD_QUALITY_SOMETHING,
- pattern.size(), 0, 0, 0, 0, 0, 0, userId);
+ // Update the device encryption password.
+ if (userId == UserHandle.USER_OWNER
+ && LockPatternUtils.isDeviceEncryptionEnabled()) {
+ final boolean required = isCredentialRequiredToDecrypt(true);
+ if (!required) {
+ clearEncryptionPassword();
} else {
- setLong(PASSWORD_TYPE_KEY, DevicePolicyManager.PASSWORD_QUALITY_BIOMETRIC_WEAK, userId);
- setLong(PASSWORD_TYPE_ALTERNATE_KEY,
- DevicePolicyManager.PASSWORD_QUALITY_SOMETHING, userId);
- finishBiometricWeak(userId);
- dpm.setActivePasswordState(DevicePolicyManager.PASSWORD_QUALITY_BIOMETRIC_WEAK,
- 0, 0, 0, 0, 0, 0, 0, userId);
+ String stringPattern = patternToString(pattern);
+ updateEncryptionPassword(StorageManager.CRYPT_TYPE_PATTERN, stringPattern);
}
- } else {
- dpm.setActivePasswordState(DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED, 0, 0,
- 0, 0, 0, 0, 0, userId);
}
+
+ setBoolean(PATTERN_EVER_CHOSEN_KEY, true, userId);
+
+ setLong(PASSWORD_TYPE_KEY, DevicePolicyManager.PASSWORD_QUALITY_SOMETHING, userId);
+ dpm.setActivePasswordState(DevicePolicyManager.PASSWORD_QUALITY_SOMETHING,
+ pattern.size(), 0, 0, 0, 0, 0, 0, userId);
onAfterChangingPassword(userId);
} catch (RemoteException re) {
Log.e(TAG, "Couldn't save lock pattern " + re);
}
}
- private void updateCryptoUserInfo() {
- int userId = getCurrentOrCallingUserId();
+ private void updateCryptoUserInfo(int userId) {
if (userId != UserHandle.USER_OWNER) {
return;
}
- final String ownerInfo = isOwnerInfoEnabled() ? getOwnerInfo(userId) : "";
+ final String ownerInfo = isOwnerInfoEnabled(userId) ? getOwnerInfo(userId) : "";
IBinder service = ServiceManager.getService("mount");
if (service == null) {
@@ -650,20 +543,25 @@ public class LockPatternUtils {
public void setOwnerInfo(String info, int userId) {
setString(LOCK_SCREEN_OWNER_INFO, info, userId);
- updateCryptoUserInfo();
+ updateCryptoUserInfo(userId);
}
public void setOwnerInfoEnabled(boolean enabled) {
- setBoolean(LOCK_SCREEN_OWNER_INFO_ENABLED, enabled);
- updateCryptoUserInfo();
+ int userId = getCurrentOrCallingUserId();
+ setBoolean(LOCK_SCREEN_OWNER_INFO_ENABLED, enabled, userId);
+ updateCryptoUserInfo(userId);
}
public String getOwnerInfo(int userId) {
- return getString(LOCK_SCREEN_OWNER_INFO);
+ return getString(LOCK_SCREEN_OWNER_INFO, userId);
}
public boolean isOwnerInfoEnabled() {
- return getBoolean(LOCK_SCREEN_OWNER_INFO_ENABLED, false);
+ return isOwnerInfoEnabled(getCurrentOrCallingUserId());
+ }
+
+ private boolean isOwnerInfoEnabled(int userId) {
+ return getBoolean(LOCK_SCREEN_OWNER_INFO_ENABLED, false, userId);
}
/**
@@ -789,7 +687,7 @@ public class LockPatternUtils {
* @param quality {@see DevicePolicyManager#getPasswordQuality(android.content.ComponentName)}
*/
public void saveLockPassword(String password, int quality) {
- this.saveLockPassword(password, quality, false, getCurrentOrCallingUserId());
+ saveLockPassword(password, quality, getCurrentOrCallingUserId());
}
/**
@@ -798,120 +696,87 @@ public class LockPatternUtils {
* pattern.
* @param password The password to save
* @param quality {@see DevicePolicyManager#getPasswordQuality(android.content.ComponentName)}
- * @param isFallback Specifies if this is a fallback to biometric weak
- */
- public void saveLockPassword(String password, int quality, boolean isFallback) {
- saveLockPassword(password, quality, isFallback, getCurrentOrCallingUserId());
- }
-
- /**
- * Save a lock password. Does not ensure that the password is as good
- * as the requested mode, but will adjust the mode to be as good as the
- * pattern.
- * @param password The password to save
- * @param quality {@see DevicePolicyManager#getPasswordQuality(android.content.ComponentName)}
- * @param isFallback Specifies if this is a fallback to biometric weak
* @param userHandle The userId of the user to change the password for
*/
- public void saveLockPassword(String password, int quality, boolean isFallback, int userHandle) {
+ public void saveLockPassword(String password, int quality, int userHandle) {
try {
DevicePolicyManager dpm = getDevicePolicyManager();
- if (!TextUtils.isEmpty(password)) {
- getLockSettings().setLockPassword(password, userHandle);
- int computedQuality = computePasswordQuality(password);
-
- // Update the device encryption password.
- if (userHandle == UserHandle.USER_OWNER
- && LockPatternUtils.isDeviceEncryptionEnabled()) {
- if (!isCredentialRequiredToDecrypt(true)) {
- clearEncryptionPassword();
- } else {
- boolean numeric = computedQuality
- == DevicePolicyManager.PASSWORD_QUALITY_NUMERIC;
- boolean numericComplex = computedQuality
- == DevicePolicyManager.PASSWORD_QUALITY_NUMERIC_COMPLEX;
- int type = numeric || numericComplex ? StorageManager.CRYPT_TYPE_PIN
- : StorageManager.CRYPT_TYPE_PASSWORD;
- updateEncryptionPassword(type, password);
- }
+ if (TextUtils.isEmpty(password)) {
+ throw new IllegalArgumentException("password must not be null nor empty");
+ }
+
+ getLockSettings().setLockPassword(password, userHandle);
+ int computedQuality = computePasswordQuality(password);
+
+ // Update the device encryption password.
+ if (userHandle == UserHandle.USER_OWNER
+ && LockPatternUtils.isDeviceEncryptionEnabled()) {
+ if (!isCredentialRequiredToDecrypt(true)) {
+ clearEncryptionPassword();
+ } else {
+ boolean numeric = computedQuality
+ == DevicePolicyManager.PASSWORD_QUALITY_NUMERIC;
+ boolean numericComplex = computedQuality
+ == DevicePolicyManager.PASSWORD_QUALITY_NUMERIC_COMPLEX;
+ int type = numeric || numericComplex ? StorageManager.CRYPT_TYPE_PIN
+ : StorageManager.CRYPT_TYPE_PASSWORD;
+ updateEncryptionPassword(type, password);
}
+ }
- if (!isFallback) {
- deleteGallery(userHandle);
- setLong(PASSWORD_TYPE_KEY, Math.max(quality, computedQuality), userHandle);
- if (computedQuality != DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED) {
- int letters = 0;
- int uppercase = 0;
- int lowercase = 0;
- int numbers = 0;
- int symbols = 0;
- int nonletter = 0;
- for (int i = 0; i < password.length(); i++) {
- char c = password.charAt(i);
- if (c >= 'A' && c <= 'Z') {
- letters++;
- uppercase++;
- } else if (c >= 'a' && c <= 'z') {
- letters++;
- lowercase++;
- } else if (c >= '0' && c <= '9') {
- numbers++;
- nonletter++;
- } else {
- symbols++;
- nonletter++;
- }
- }
- dpm.setActivePasswordState(Math.max(quality, computedQuality),
- password.length(), letters, uppercase, lowercase,
- numbers, symbols, nonletter, userHandle);
+ setLong(PASSWORD_TYPE_KEY, Math.max(quality, computedQuality), userHandle);
+ if (computedQuality != DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED) {
+ int letters = 0;
+ int uppercase = 0;
+ int lowercase = 0;
+ int numbers = 0;
+ int symbols = 0;
+ int nonletter = 0;
+ for (int i = 0; i < password.length(); i++) {
+ char c = password.charAt(i);
+ if (c >= 'A' && c <= 'Z') {
+ letters++;
+ uppercase++;
+ } else if (c >= 'a' && c <= 'z') {
+ letters++;
+ lowercase++;
+ } else if (c >= '0' && c <= '9') {
+ numbers++;
+ nonletter++;
} else {
- // The password is not anything.
- dpm.setActivePasswordState(
- DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED,
- 0, 0, 0, 0, 0, 0, 0, userHandle);
+ symbols++;
+ nonletter++;
}
- } else {
- // Case where it's a fallback for biometric weak
- setLong(PASSWORD_TYPE_KEY, DevicePolicyManager.PASSWORD_QUALITY_BIOMETRIC_WEAK,
- userHandle);
- setLong(PASSWORD_TYPE_ALTERNATE_KEY, Math.max(quality, computedQuality),
- userHandle);
- finishBiometricWeak(userHandle);
- dpm.setActivePasswordState(DevicePolicyManager.PASSWORD_QUALITY_BIOMETRIC_WEAK,
- 0, 0, 0, 0, 0, 0, 0, userHandle);
}
- // Add the password to the password history. We assume all
- // password hashes have the same length for simplicity of implementation.
- String passwordHistory = getString(PASSWORD_HISTORY_KEY, userHandle);
- if (passwordHistory == null) {
- passwordHistory = "";
- }
- int passwordHistoryLength = getRequestedPasswordHistoryLength();
- if (passwordHistoryLength == 0) {
- passwordHistory = "";
- } else {
- byte[] hash = passwordToHash(password, userHandle);
- passwordHistory = new String(hash, StandardCharsets.UTF_8) + "," + passwordHistory;
- // Cut it to contain passwordHistoryLength hashes
- // and passwordHistoryLength -1 commas.
- passwordHistory = passwordHistory.substring(0, Math.min(hash.length
- * passwordHistoryLength + passwordHistoryLength - 1, passwordHistory
- .length()));
- }
- setString(PASSWORD_HISTORY_KEY, passwordHistory, userHandle);
+ dpm.setActivePasswordState(Math.max(quality, computedQuality),
+ password.length(), letters, uppercase, lowercase,
+ numbers, symbols, nonletter, userHandle);
} else {
- // Empty password
- getLockSettings().setLockPassword(null, userHandle);
- if (userHandle == UserHandle.USER_OWNER) {
- // Set the encryption password to default.
- updateEncryptionPassword(StorageManager.CRYPT_TYPE_DEFAULT, null);
- }
-
+ // The password is not anything.
dpm.setActivePasswordState(
- DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED, 0, 0, 0, 0, 0, 0, 0,
- userHandle);
+ DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED,
+ 0, 0, 0, 0, 0, 0, 0, userHandle);
+ }
+
+ // Add the password to the password history. We assume all
+ // password hashes have the same length for simplicity of implementation.
+ String passwordHistory = getString(PASSWORD_HISTORY_KEY, userHandle);
+ if (passwordHistory == null) {
+ passwordHistory = "";
+ }
+ int passwordHistoryLength = getRequestedPasswordHistoryLength(userHandle);
+ if (passwordHistoryLength == 0) {
+ passwordHistory = "";
+ } else {
+ byte[] hash = passwordToHash(password, userHandle);
+ passwordHistory = new String(hash, StandardCharsets.UTF_8) + "," + passwordHistory;
+ // Cut it to contain passwordHistoryLength hashes
+ // and passwordHistoryLength -1 commas.
+ passwordHistory = passwordHistory.substring(0, Math.min(hash.length
+ * passwordHistoryLength + passwordHistoryLength - 1, passwordHistory
+ .length()));
}
+ setString(PASSWORD_HISTORY_KEY, passwordHistory, userHandle);
onAfterChangingPassword(userHandle);
} catch (RemoteException re) {
// Cant do much
@@ -971,31 +836,8 @@ public class LockPatternUtils {
* @return stored password quality
*/
public int getKeyguardStoredPasswordQuality(int userHandle) {
- int quality = (int) getLong(PASSWORD_TYPE_KEY,
+ return (int) getLong(PASSWORD_TYPE_KEY,
DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED, userHandle);
- // If the user has chosen to use weak biometric sensor, then return the backup locking
- // method and treat biometric as a special case.
- if (quality == DevicePolicyManager.PASSWORD_QUALITY_BIOMETRIC_WEAK) {
- quality = (int) getLong(PASSWORD_TYPE_ALTERNATE_KEY,
- DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED, userHandle);
- }
- return quality;
- }
-
- /**
- * @return true if the lockscreen method is set to biometric weak
- */
- public boolean usingBiometricWeak() {
- return usingBiometricWeak(getCurrentOrCallingUserId());
- }
-
- /**
- * @return true if the lockscreen method is set to biometric weak
- */
- public boolean usingBiometricWeak(int userId) {
- int quality = (int) getLong(
- PASSWORD_TYPE_KEY, DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED, userId);
- return quality == DevicePolicyManager.PASSWORD_QUALITY_BIOMETRIC_WEAK;
}
/**
@@ -1004,6 +846,10 @@ public class LockPatternUtils {
* @return The pattern.
*/
public static List<LockPatternView.Cell> stringToPattern(String string) {
+ if (string == null) {
+ return null;
+ }
+
List<LockPatternView.Cell> result = Lists.newArrayList();
final byte[] bytes = string.getBytes();
@@ -1106,126 +952,73 @@ public class LockPatternUtils {
}
/**
- * @return Whether the lock password is enabled, or if it is set as a backup for biometric weak
+ * @return Whether the lock screen is secured.
*/
- public boolean isLockPasswordEnabled() {
- long mode = getLong(PASSWORD_TYPE_KEY, 0);
- long backupMode = getLong(PASSWORD_TYPE_ALTERNATE_KEY, 0);
- final boolean passwordEnabled = mode == DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC
- || mode == DevicePolicyManager.PASSWORD_QUALITY_NUMERIC
- || mode == DevicePolicyManager.PASSWORD_QUALITY_NUMERIC_COMPLEX
- || mode == DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC
- || mode == DevicePolicyManager.PASSWORD_QUALITY_COMPLEX;
- final boolean backupEnabled = backupMode == DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC
- || backupMode == DevicePolicyManager.PASSWORD_QUALITY_NUMERIC
- || backupMode == DevicePolicyManager.PASSWORD_QUALITY_NUMERIC_COMPLEX
- || backupMode == DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC
- || backupMode == DevicePolicyManager.PASSWORD_QUALITY_COMPLEX;
-
- return savedPasswordExists() && (passwordEnabled ||
- (usingBiometricWeak() && backupEnabled));
+ public boolean isSecure() {
+ return isSecure(getCurrentOrCallingUserId());
}
/**
- * @return Whether the lock pattern is enabled, or if it is set as a backup for biometric weak
+ * @param userId the user for which to report the value
+ * @return Whether the lock screen is secured.
*/
- public boolean isLockPatternEnabled() {
- return isLockPatternEnabled(getCurrentOrCallingUserId());
+ public boolean isSecure(int userId) {
+ int mode = getKeyguardStoredPasswordQuality(userId);
+ return isLockPatternEnabled(mode, userId) || isLockPasswordEnabled(mode, userId);
}
/**
- * @return Whether the lock pattern is enabled, or if it is set as a backup for biometric weak
+ * @return Whether the lock password is enabled
*/
- public boolean isLockPatternEnabled(int userId) {
- final boolean backupEnabled =
- getLong(PASSWORD_TYPE_ALTERNATE_KEY,
- DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED, userId)
- == DevicePolicyManager.PASSWORD_QUALITY_SOMETHING;
-
- return getBoolean(Settings.Secure.LOCK_PATTERN_ENABLED, false, userId)
- && (getLong(PASSWORD_TYPE_KEY, DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED,
- userId) == DevicePolicyManager.PASSWORD_QUALITY_SOMETHING
- || (usingBiometricWeak(userId) && backupEnabled));
+ public boolean isLockPasswordEnabled() {
+ return isLockPasswordEnabled(getCurrentOrCallingUserId());
}
- /**
- * @return Whether biometric weak lock is installed and that the front facing camera exists
- */
- public boolean isBiometricWeakInstalled() {
- // Check that it's installed
- PackageManager pm = mContext.getPackageManager();
- try {
- pm.getPackageInfo("com.android.facelock", PackageManager.GET_ACTIVITIES);
- } catch (PackageManager.NameNotFoundException e) {
- return false;
- }
-
- // Check that the camera is enabled
- if (!pm.hasSystemFeature(PackageManager.FEATURE_CAMERA_FRONT)) {
- return false;
- }
- if (getDevicePolicyManager().getCameraDisabled(null, getCurrentOrCallingUserId())) {
- return false;
- }
-
- // TODO: If we decide not to proceed with Face Unlock as a trustlet, this must be changed
- // back to returning true. If we become certain that Face Unlock will be a trustlet, this
- // entire function and a lot of other code can be removed.
- if (DEBUG) Log.d(TAG, "Forcing isBiometricWeakInstalled() to return false to disable it");
- return false;
+ public boolean isLockPasswordEnabled(int userId) {
+ return isLockPasswordEnabled(getKeyguardStoredPasswordQuality(userId), userId);
}
- /**
- * Set whether biometric weak liveliness is enabled.
- */
- public void setBiometricWeakLivelinessEnabled(boolean enabled) {
- long currentFlag = getLong(Settings.Secure.LOCK_BIOMETRIC_WEAK_FLAGS, 0L);
- long newFlag;
- if (enabled) {
- newFlag = currentFlag | FLAG_BIOMETRIC_WEAK_LIVELINESS;
- } else {
- newFlag = currentFlag & ~FLAG_BIOMETRIC_WEAK_LIVELINESS;
- }
- setLong(Settings.Secure.LOCK_BIOMETRIC_WEAK_FLAGS, newFlag);
+ private boolean isLockPasswordEnabled(int mode, int userId) {
+ final boolean passwordEnabled = mode == DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC
+ || mode == DevicePolicyManager.PASSWORD_QUALITY_NUMERIC
+ || mode == DevicePolicyManager.PASSWORD_QUALITY_NUMERIC_COMPLEX
+ || mode == DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC
+ || mode == DevicePolicyManager.PASSWORD_QUALITY_COMPLEX;
+ return passwordEnabled && savedPasswordExists(userId);
}
/**
- * @return Whether the biometric weak liveliness is enabled.
+ * @return Whether the lock pattern is enabled
*/
- public boolean isBiometricWeakLivelinessEnabled() {
- long currentFlag = getLong(Settings.Secure.LOCK_BIOMETRIC_WEAK_FLAGS, 0L);
- return ((currentFlag & FLAG_BIOMETRIC_WEAK_LIVELINESS) != 0);
+ public boolean isLockPatternEnabled() {
+ return isLockPatternEnabled(getCurrentOrCallingUserId());
}
- /**
- * Set whether the lock pattern is enabled.
- */
- public void setLockPatternEnabled(boolean enabled) {
- setLockPatternEnabled(enabled, getCurrentOrCallingUserId());
+ public boolean isLockPatternEnabled(int userId) {
+ return isLockPatternEnabled(getKeyguardStoredPasswordQuality(userId), userId);
}
- /**
- * Set whether the lock pattern is enabled.
- */
- public void setLockPatternEnabled(boolean enabled, int userHandle) {
- setBoolean(Settings.Secure.LOCK_PATTERN_ENABLED, enabled, userHandle);
+ private boolean isLockPatternEnabled(int mode, int userId) {
+ return mode == DevicePolicyManager.PASSWORD_QUALITY_SOMETHING
+ && savedPatternExists(userId);
}
/**
* @return Whether the visible pattern is enabled.
*/
public boolean isVisiblePatternEnabled() {
- return getBoolean(Settings.Secure.LOCK_PATTERN_VISIBLE, false);
+ return getBoolean(Settings.Secure.LOCK_PATTERN_VISIBLE, false, getCurrentOrCallingUserId());
}
/**
* Set whether the visible pattern is enabled.
*/
public void setVisiblePatternEnabled(boolean enabled) {
- setBoolean(Settings.Secure.LOCK_PATTERN_VISIBLE, enabled);
+ int userId = getCurrentOrCallingUserId();
+
+ setBoolean(Settings.Secure.LOCK_PATTERN_VISIBLE, enabled, userId);
// Update for crypto if owner
- int userId = getCurrentOrCallingUserId();
if (userId != UserHandle.USER_OWNER) {
return;
}
@@ -1259,7 +1052,7 @@ public class LockPatternUtils {
*/
public long setLockoutAttemptDeadline() {
final long deadline = SystemClock.elapsedRealtime() + FAILED_ATTEMPT_TIMEOUT_MS;
- setLong(LOCKOUT_ATTEMPT_DEADLINE, deadline);
+ setLong(LOCKOUT_ATTEMPT_DEADLINE, deadline, getCurrentOrCallingUserId());
return deadline;
}
@@ -1269,7 +1062,7 @@ public class LockPatternUtils {
* enter a pattern.
*/
public long getLockoutAttemptDeadline() {
- final long deadline = getLong(LOCKOUT_ATTEMPT_DEADLINE, 0L);
+ final long deadline = getLong(LOCKOUT_ATTEMPT_DEADLINE, 0L, getCurrentOrCallingUserId());
final long now = SystemClock.elapsedRealtime();
if (deadline < now || deadline > (now + FAILED_ATTEMPT_TIMEOUT_MS)) {
return 0L;
@@ -1277,27 +1070,6 @@ public class LockPatternUtils {
return deadline;
}
- /**
- * @return Whether the user is permanently locked out until they verify their
- * credentials. Occurs after {@link #FAILED_ATTEMPTS_BEFORE_RESET} failed
- * attempts.
- */
- public boolean isPermanentlyLocked() {
- return getBoolean(LOCKOUT_PERMANENT_KEY, false);
- }
-
- /**
- * Set the state of whether the device is permanently locked, meaning the user
- * must authenticate via other means.
- *
- * @param locked Whether the user is permanently locked out until they verify their
- * credentials. Occurs after {@link #FAILED_ATTEMPTS_BEFORE_RESET} failed
- * attempts.
- */
- public void setPermanentlyLocked(boolean locked) {
- setBoolean(LOCKOUT_PERMANENT_KEY, locked);
- }
-
public boolean isEmergencyCallCapable() {
return mContext.getResources().getBoolean(
com.android.internal.R.bool.config_voice_capable);
@@ -1313,15 +1085,6 @@ public class LockPatternUtils {
com.android.internal.R.bool.config_enable_emergency_call_while_sim_locked);
}
- /**
- * @return A formatted string of the next alarm (for showing on the lock screen),
- * or null if there is no next alarm.
- */
- public AlarmManager.AlarmClockInfo getNextAlarm() {
- AlarmManager alarmManager = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE);
- return alarmManager.getNextAlarmClock(UserHandle.USER_CURRENT);
- }
-
private boolean getBoolean(String secureSettingKey, boolean defaultValue, int userId) {
try {
return getLockSettings().getBoolean(secureSettingKey, defaultValue, userId);
@@ -1330,10 +1093,6 @@ public class LockPatternUtils {
}
}
- private boolean getBoolean(String secureSettingKey, boolean defaultValue) {
- return getBoolean(secureSettingKey, defaultValue, getCurrentOrCallingUserId());
- }
-
private void setBoolean(String secureSettingKey, boolean enabled, int userId) {
try {
getLockSettings().setBoolean(secureSettingKey, enabled, userId);
@@ -1343,144 +1102,6 @@ public class LockPatternUtils {
}
}
- private void setBoolean(String secureSettingKey, boolean enabled) {
- setBoolean(secureSettingKey, enabled, getCurrentOrCallingUserId());
- }
-
- public int[] getAppWidgets() {
- return getAppWidgets(UserHandle.USER_CURRENT);
- }
-
- private int[] getAppWidgets(int userId) {
- String appWidgetIdString = Settings.Secure.getStringForUser(
- mContentResolver, Settings.Secure.LOCK_SCREEN_APPWIDGET_IDS, userId);
- String delims = ",";
- if (appWidgetIdString != null && appWidgetIdString.length() > 0) {
- String[] appWidgetStringIds = appWidgetIdString.split(delims);
- int[] appWidgetIds = new int[appWidgetStringIds.length];
- for (int i = 0; i < appWidgetStringIds.length; i++) {
- String appWidget = appWidgetStringIds[i];
- try {
- appWidgetIds[i] = Integer.decode(appWidget);
- } catch (NumberFormatException e) {
- Log.d(TAG, "Error when parsing widget id " + appWidget);
- return null;
- }
- }
- return appWidgetIds;
- }
- return new int[0];
- }
-
- private static String combineStrings(int[] list, String separator) {
- int listLength = list.length;
-
- switch (listLength) {
- case 0: {
- return "";
- }
- case 1: {
- return Integer.toString(list[0]);
- }
- }
-
- int strLength = 0;
- int separatorLength = separator.length();
-
- String[] stringList = new String[list.length];
- for (int i = 0; i < listLength; i++) {
- stringList[i] = Integer.toString(list[i]);
- strLength += stringList[i].length();
- if (i < listLength - 1) {
- strLength += separatorLength;
- }
- }
-
- StringBuilder sb = new StringBuilder(strLength);
-
- for (int i = 0; i < listLength; i++) {
- sb.append(list[i]);
- if (i < listLength - 1) {
- sb.append(separator);
- }
- }
-
- return sb.toString();
- }
-
- // appwidget used when appwidgets are disabled (we make an exception for
- // default clock widget)
- public void writeFallbackAppWidgetId(int appWidgetId) {
- Settings.Secure.putIntForUser(mContentResolver,
- Settings.Secure.LOCK_SCREEN_FALLBACK_APPWIDGET_ID,
- appWidgetId,
- UserHandle.USER_CURRENT);
- }
-
- // appwidget used when appwidgets are disabled (we make an exception for
- // default clock widget)
- public int getFallbackAppWidgetId() {
- return Settings.Secure.getIntForUser(
- mContentResolver,
- Settings.Secure.LOCK_SCREEN_FALLBACK_APPWIDGET_ID,
- AppWidgetManager.INVALID_APPWIDGET_ID,
- UserHandle.USER_CURRENT);
- }
-
- private void writeAppWidgets(int[] appWidgetIds) {
- Settings.Secure.putStringForUser(mContentResolver,
- Settings.Secure.LOCK_SCREEN_APPWIDGET_IDS,
- combineStrings(appWidgetIds, ","),
- UserHandle.USER_CURRENT);
- }
-
- // TODO: log an error if this returns false
- public boolean addAppWidget(int widgetId, int index) {
- int[] widgets = getAppWidgets();
- if (widgets == null) {
- return false;
- }
- if (index < 0 || index > widgets.length) {
- return false;
- }
- int[] newWidgets = new int[widgets.length + 1];
- for (int i = 0, j = 0; i < newWidgets.length; i++) {
- if (index == i) {
- newWidgets[i] = widgetId;
- i++;
- }
- if (i < newWidgets.length) {
- newWidgets[i] = widgets[j];
- j++;
- }
- }
- writeAppWidgets(newWidgets);
- return true;
- }
-
- public boolean removeAppWidget(int widgetId) {
- int[] widgets = getAppWidgets();
-
- if (widgets.length == 0) {
- return false;
- }
-
- int[] newWidgets = new int[widgets.length - 1];
- for (int i = 0, j = 0; i < widgets.length; i++) {
- if (widgets[i] == widgetId) {
- // continue...
- } else if (j >= newWidgets.length) {
- // we couldn't find the widget
- return false;
- } else {
- newWidgets[j] = widgets[i];
- j++;
- }
- }
- writeAppWidgets(newWidgets);
- return true;
- }
-
private long getLong(String secureSettingKey, long defaultValue, int userHandle) {
try {
return getLockSettings().getLong(secureSettingKey, defaultValue, userHandle);
@@ -1489,19 +1110,6 @@ public class LockPatternUtils {
}
}
- private long getLong(String secureSettingKey, long defaultValue) {
- try {
- return getLockSettings().getLong(secureSettingKey, defaultValue,
- getCurrentOrCallingUserId());
- } catch (RemoteException re) {
- return defaultValue;
- }
- }
-
- private void setLong(String secureSettingKey, long value) {
- setLong(secureSettingKey, value, getCurrentOrCallingUserId());
- }
-
private void setLong(String secureSettingKey, long value, int userHandle) {
try {
getLockSettings().setLong(secureSettingKey, value, userHandle);
@@ -1511,10 +1119,6 @@ public class LockPatternUtils {
}
}
- private String getString(String secureSettingKey) {
- return getString(secureSettingKey, getCurrentOrCallingUserId());
- }
-
private String getString(String secureSettingKey, int userHandle) {
try {
return getLockSettings().getString(secureSettingKey, null, userHandle);
@@ -1532,24 +1136,6 @@ public class LockPatternUtils {
}
}
- public boolean isSecure() {
- return isSecure(getCurrentOrCallingUserId());
- }
-
- public boolean isSecure(int userId) {
- long mode = getKeyguardStoredPasswordQuality(userId);
- final boolean isPattern = mode == DevicePolicyManager.PASSWORD_QUALITY_SOMETHING;
- final boolean isPassword = mode == DevicePolicyManager.PASSWORD_QUALITY_NUMERIC
- || mode == DevicePolicyManager.PASSWORD_QUALITY_NUMERIC_COMPLEX
- || mode == DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC
- || mode == DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC
- || mode == DevicePolicyManager.PASSWORD_QUALITY_COMPLEX;
- final boolean secure =
- isPattern && isLockPatternEnabled(userId) && savedPatternExists(userId)
- || isPassword && savedPasswordExists(userId);
- return secure;
- }
-
/**
* Sets the emergency button visibility based on isEmergencyCallCapable().
*
@@ -1602,64 +1188,13 @@ public class LockPatternUtils {
return (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE);
}
- private void finishBiometricWeak(int userId) {
- setBoolean(BIOMETRIC_WEAK_EVER_CHOSEN_KEY, true, userId);
-
- // Launch intent to show final screen, this also
- // moves the temporary gallery to the actual gallery
- Intent intent = new Intent();
- intent.setClassName("com.android.facelock",
- "com.android.facelock.SetupEndScreen");
- mContext.startActivityAsUser(intent, new UserHandle(userId));
- }
-
public void setPowerButtonInstantlyLocks(boolean enabled) {
- setBoolean(LOCKSCREEN_POWER_BUTTON_INSTANTLY_LOCKS, enabled);
+ setBoolean(LOCKSCREEN_POWER_BUTTON_INSTANTLY_LOCKS, enabled, getCurrentOrCallingUserId());
}
public boolean getPowerButtonInstantlyLocks() {
- return getBoolean(LOCKSCREEN_POWER_BUTTON_INSTANTLY_LOCKS, true);
- }
-
- public static boolean isSafeModeEnabled() {
- try {
- return IWindowManager.Stub.asInterface(
- ServiceManager.getService("window")).isSafeModeEnabled();
- } catch (RemoteException e) {
- // Shouldn't happen!
- }
- return false;
- }
-
- /**
- * Determine whether the user has selected any non-system widgets in keyguard
- *
- * @return true if widgets have been selected
- */
- public boolean hasWidgetsEnabledInKeyguard(int userid) {
- int widgets[] = getAppWidgets(userid);
- for (int i = 0; i < widgets.length; i++) {
- if (widgets[i] > 0) {
- return true;
- }
- }
- return false;
- }
-
- public boolean getWidgetsEnabled() {
- return getWidgetsEnabled(getCurrentOrCallingUserId());
- }
-
- public boolean getWidgetsEnabled(int userId) {
- return getBoolean(LOCKSCREEN_WIDGETS_ENABLED, false, userId);
- }
-
- public void setWidgetsEnabled(boolean enabled) {
- setWidgetsEnabled(enabled, getCurrentOrCallingUserId());
- }
-
- public void setWidgetsEnabled(boolean enabled, int userId) {
- setBoolean(LOCKSCREEN_WIDGETS_ENABLED, enabled, userId);
+ return getBoolean(LOCKSCREEN_POWER_BUTTON_INSTANTLY_LOCKS, true,
+ getCurrentOrCallingUserId());
}
public void setEnabledTrustAgents(Collection<ComponentName> activeTrustAgents) {
diff --git a/core/java/com/android/internal/widget/LockPatternView.java b/core/java/com/android/internal/widget/LockPatternView.java
index 9fa6882..52bbabf 100644
--- a/core/java/com/android/internal/widget/LockPatternView.java
+++ b/core/java/com/android/internal/widget/LockPatternView.java
@@ -65,8 +65,8 @@ public class LockPatternView extends View {
private boolean mDrawingProfilingStarted = false;
- private Paint mPaint = new Paint();
- private Paint mPathPaint = new Paint();
+ private final Paint mPaint = new Paint();
+ private final Paint mPathPaint = new Paint();
/**
* How many milliseconds we spend animating each circle of a lock pattern
@@ -82,7 +82,7 @@ public class LockPatternView extends View {
private static final float DRAG_THRESHHOLD = 0.0f;
private OnPatternListener mOnPatternListener;
- private ArrayList<Cell> mPattern = new ArrayList<Cell>(9);
+ private final ArrayList<Cell> mPattern = new ArrayList<Cell>(9);
/**
* Lookup table for the circles of the pattern we are currently drawing.
@@ -90,7 +90,7 @@ public class LockPatternView extends View {
* in which case we use this to hold the cells we are drawing for the in
* progress animation.
*/
- private boolean[][] mPatternDrawLookup = new boolean[3][3];
+ private final boolean[][] mPatternDrawLookup = new boolean[3][3];
/**
* the in progress point:
@@ -122,24 +122,27 @@ public class LockPatternView extends View {
private int mErrorColor;
private int mSuccessColor;
- private Interpolator mFastOutSlowInInterpolator;
- private Interpolator mLinearOutSlowInInterpolator;
+ private final Interpolator mFastOutSlowInInterpolator;
+ private final Interpolator mLinearOutSlowInInterpolator;
/**
* Represents a cell in the 3 X 3 matrix of the unlock pattern view.
*/
- public static class Cell {
- int row;
- int column;
+ public static final class Cell {
+ final int row;
+ final int column;
// keep # objects limited to 9
- static Cell[][] sCells = new Cell[3][3];
- static {
+ private static final Cell[][] sCells = createCells();
+
+ private static Cell[][] createCells() {
+ Cell[][] res = new Cell[3][3];
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
- sCells[i][j] = new Cell(i, j);
+ res[i][j] = new Cell(i, j);
}
}
+ return res;
}
/**
@@ -160,11 +163,7 @@ public class LockPatternView extends View {
return column;
}
- /**
- * @param row The row of the cell.
- * @param column The column of the cell.
- */
- public static synchronized Cell of(int row, int column) {
+ public static Cell of(int row, int column) {
checkRange(row, column);
return sCells[row][column];
}
@@ -178,6 +177,7 @@ public class LockPatternView extends View {
}
}
+ @Override
public String toString() {
return "(row=" + row + ",clmn=" + column + ")";
}
@@ -722,7 +722,7 @@ public class LockPatternView extends View {
handleActionDown(event);
return true;
case MotionEvent.ACTION_UP:
- handleActionUp(event);
+ handleActionUp();
return true;
case MotionEvent.ACTION_MOVE:
handleActionMove(event);
@@ -812,7 +812,7 @@ public class LockPatternView extends View {
announceForAccessibility(mContext.getString(resId));
}
- private void handleActionUp(MotionEvent event) {
+ private void handleActionUp() {
// report pattern detected
if (!mPattern.isEmpty()) {
mPatternInProgress = false;
@@ -1119,12 +1119,15 @@ public class LockPatternView extends View {
dest.writeValue(mTactileFeedbackEnabled);
}
+ @SuppressWarnings({ "unused", "hiding" }) // Found using reflection
public static final Parcelable.Creator<SavedState> CREATOR =
new Creator<SavedState>() {
+ @Override
public SavedState createFromParcel(Parcel in) {
return new SavedState(in);
}
+ @Override
public SavedState[] newArray(int size) {
return new SavedState[size];
}
diff --git a/core/java/com/android/internal/widget/ScrollingTabContainerView.java b/core/java/com/android/internal/widget/ScrollingTabContainerView.java
index d6bd1d6..a306697 100644
--- a/core/java/com/android/internal/widget/ScrollingTabContainerView.java
+++ b/core/java/com/android/internal/widget/ScrollingTabContainerView.java
@@ -150,7 +150,9 @@ public class ScrollingTabContainerView extends HorizontalScrollView
addView(mTabSpinner, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.MATCH_PARENT));
if (mTabSpinner.getAdapter() == null) {
- mTabSpinner.setAdapter(new TabAdapter());
+ final TabAdapter adapter = new TabAdapter(mContext);
+ adapter.setDropDownViewContext(mTabSpinner.getPopupContext());
+ mTabSpinner.setAdapter(adapter);
}
if (mTabSelector != null) {
removeCallbacks(mTabSelector);
@@ -276,8 +278,8 @@ public class ScrollingTabContainerView extends HorizontalScrollView
}
}
- private TabView createTabView(ActionBar.Tab tab, boolean forAdapter) {
- final TabView tabView = new TabView(getContext(), tab, forAdapter);
+ private TabView createTabView(Context context, ActionBar.Tab tab, boolean forAdapter) {
+ final TabView tabView = new TabView(context, tab, forAdapter);
if (forAdapter) {
tabView.setBackgroundDrawable(null);
tabView.setLayoutParams(new ListView.LayoutParams(ListView.LayoutParams.MATCH_PARENT,
@@ -294,7 +296,7 @@ public class ScrollingTabContainerView extends HorizontalScrollView
}
public void addTab(ActionBar.Tab tab, boolean setSelected) {
- TabView tabView = createTabView(tab, false);
+ TabView tabView = createTabView(mContext, tab, false);
mTabLayout.addView(tabView, new LinearLayout.LayoutParams(0,
LayoutParams.MATCH_PARENT, 1));
if (mTabSpinner != null) {
@@ -309,7 +311,7 @@ public class ScrollingTabContainerView extends HorizontalScrollView
}
public void addTab(ActionBar.Tab tab, int position, boolean setSelected) {
- final TabView tabView = createTabView(tab, false);
+ final TabView tabView = createTabView(mContext, tab, false);
mTabLayout.addView(tabView, position, new LinearLayout.LayoutParams(
0, LayoutParams.MATCH_PARENT, 1));
if (mTabSpinner != null) {
@@ -391,15 +393,15 @@ public class ScrollingTabContainerView extends HorizontalScrollView
}
@Override
- public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
- super.onInitializeAccessibilityEvent(event);
+ public void onInitializeAccessibilityEventInternal(AccessibilityEvent event) {
+ super.onInitializeAccessibilityEventInternal(event);
// This view masquerades as an action bar tab.
event.setClassName(ActionBar.Tab.class.getName());
}
@Override
- public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
- super.onInitializeAccessibilityNodeInfo(info);
+ public void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) {
+ super.onInitializeAccessibilityNodeInfoInternal(info);
// This view masquerades as an action bar tab.
info.setClassName(ActionBar.Tab.class.getName());
}
@@ -514,6 +516,16 @@ public class ScrollingTabContainerView extends HorizontalScrollView
}
private class TabAdapter extends BaseAdapter {
+ private Context mDropDownContext;
+
+ public TabAdapter(Context context) {
+ setDropDownViewContext(context);
+ }
+
+ public void setDropDownViewContext(Context context) {
+ mDropDownContext = context;
+ }
+
@Override
public int getCount() {
return mTabLayout.getChildCount();
@@ -532,7 +544,18 @@ public class ScrollingTabContainerView extends HorizontalScrollView
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
- convertView = createTabView((ActionBar.Tab) getItem(position), true);
+ convertView = createTabView(mContext, (ActionBar.Tab) getItem(position), true);
+ } else {
+ ((TabView) convertView).bindTab((ActionBar.Tab) getItem(position));
+ }
+ return convertView;
+ }
+
+ @Override
+ public View getDropDownView(int position, View convertView, ViewGroup parent) {
+ if (convertView == null) {
+ convertView = createTabView(mDropDownContext,
+ (ActionBar.Tab) getItem(position), true);
} else {
((TabView) convertView).bindTab((ActionBar.Tab) getItem(position));
}
diff --git a/core/java/com/android/server/backup/AccountSyncSettingsBackupHelper.java b/core/java/com/android/server/backup/AccountSyncSettingsBackupHelper.java
new file mode 100644
index 0000000..3f4b980
--- /dev/null
+++ b/core/java/com/android/server/backup/AccountSyncSettingsBackupHelper.java
@@ -0,0 +1,380 @@
+/*
+ * Copyright (C) 2014 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 com.android.server.backup;
+
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
+
+import android.accounts.Account;
+import android.accounts.AccountManager;
+import android.app.backup.BackupDataInputStream;
+import android.app.backup.BackupDataOutput;
+import android.app.backup.BackupHelper;
+import android.content.ContentResolver;
+import android.content.Context;
+import android.content.SyncAdapterType;
+import android.content.SyncStatusObserver;
+import android.os.Bundle;
+import android.os.ParcelFileDescriptor;
+import android.util.Log;
+
+import java.io.BufferedOutputStream;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.EOFException;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Helper for backing up account sync settings (whether or not a service should be synced). The
+ * sync settings are backed up as a JSON object containing all the necessary information for
+ * restoring the sync settings later.
+ */
+public class AccountSyncSettingsBackupHelper implements BackupHelper {
+
+ private static final String TAG = "AccountSyncSettingsBackupHelper";
+ private static final boolean DEBUG = false;
+
+ private static final int STATE_VERSION = 1;
+ private static final int MD5_BYTE_SIZE = 16;
+ private static final int SYNC_REQUEST_LATCH_TIMEOUT_SECONDS = 1;
+
+ private static final String JSON_FORMAT_HEADER_KEY = "account_data";
+ private static final String JSON_FORMAT_ENCODING = "UTF-8";
+ private static final int JSON_FORMAT_VERSION = 1;
+
+ private static final String KEY_VERSION = "version";
+ private static final String KEY_MASTER_SYNC_ENABLED = "masterSyncEnabled";
+ private static final String KEY_ACCOUNTS = "accounts";
+ private static final String KEY_ACCOUNT_NAME = "name";
+ private static final String KEY_ACCOUNT_TYPE = "type";
+ private static final String KEY_ACCOUNT_AUTHORITIES = "authorities";
+ private static final String KEY_AUTHORITY_NAME = "name";
+ private static final String KEY_AUTHORITY_SYNC_STATE = "syncState";
+ private static final String KEY_AUTHORITY_SYNC_ENABLED = "syncEnabled";
+
+ private Context mContext;
+ private AccountManager mAccountManager;
+
+ public AccountSyncSettingsBackupHelper(Context context) {
+ mContext = context;
+ mAccountManager = AccountManager.get(mContext);
+ }
+
+ /**
+ * Take a snapshot of the current account sync settings and write them to the given output.
+ */
+ @Override
+ public void performBackup(ParcelFileDescriptor oldState, BackupDataOutput output,
+ ParcelFileDescriptor newState) {
+ try {
+ JSONObject dataJSON = serializeAccountSyncSettingsToJSON();
+
+ if (DEBUG) {
+ Log.d(TAG, "Account sync settings JSON: " + dataJSON);
+ }
+
+ // Encode JSON data to bytes.
+ byte[] dataBytes = dataJSON.toString().getBytes(JSON_FORMAT_ENCODING);
+ byte[] oldMd5Checksum = readOldMd5Checksum(oldState);
+ byte[] newMd5Checksum = generateMd5Checksum(dataBytes);
+ if (!Arrays.equals(oldMd5Checksum, newMd5Checksum)) {
+ int dataSize = dataBytes.length;
+ output.writeEntityHeader(JSON_FORMAT_HEADER_KEY, dataSize);
+ output.writeEntityData(dataBytes, dataSize);
+
+ Log.i(TAG, "Backup successful.");
+ } else {
+ Log.i(TAG, "Old and new MD5 checksums match. Skipping backup.");
+ }
+
+ writeNewMd5Checksum(newState, newMd5Checksum);
+ } catch (JSONException | IOException | NoSuchAlgorithmException e) {
+ Log.e(TAG, "Couldn't backup account sync settings\n" + e);
+ }
+ }
+
+ /**
+ * Fetch and serialize Account and authority information as a JSON Array.
+ */
+ private JSONObject serializeAccountSyncSettingsToJSON() throws JSONException {
+ Account[] accounts = mAccountManager.getAccounts();
+ SyncAdapterType[] syncAdapters = ContentResolver.getSyncAdapterTypesAsUser(
+ mContext.getUserId());
+
+ // Create a map of Account types to authorities. Later this will make it easier for us to
+ // generate our JSON.
+ HashMap<String, List<String>> accountTypeToAuthorities = new HashMap<String,
+ List<String>>();
+ for (SyncAdapterType syncAdapter : syncAdapters) {
+ // Skip adapters that aren’t visible to the user.
+ if (!syncAdapter.isUserVisible()) {
+ continue;
+ }
+ if (!accountTypeToAuthorities.containsKey(syncAdapter.accountType)) {
+ accountTypeToAuthorities.put(syncAdapter.accountType, new ArrayList<String>());
+ }
+ accountTypeToAuthorities.get(syncAdapter.accountType).add(syncAdapter.authority);
+ }
+
+ // Generate JSON.
+ JSONObject backupJSON = new JSONObject();
+ backupJSON.put(KEY_VERSION, JSON_FORMAT_VERSION);
+ backupJSON.put(KEY_MASTER_SYNC_ENABLED, ContentResolver.getMasterSyncAutomatically());
+
+ JSONArray accountJSONArray = new JSONArray();
+ for (Account account : accounts) {
+ List<String> authorities = accountTypeToAuthorities.get(account.type);
+
+ // We ignore Accounts that don't have any authorities because there would be no sync
+ // settings for us to restore.
+ if (authorities == null || authorities.isEmpty()) {
+ continue;
+ }
+
+ JSONObject accountJSON = new JSONObject();
+ accountJSON.put(KEY_ACCOUNT_NAME, account.name);
+ accountJSON.put(KEY_ACCOUNT_TYPE, account.type);
+
+ // Add authorities for this Account type and check whether or not sync is enabled.
+ JSONArray authoritiesJSONArray = new JSONArray();
+ for (String authority : authorities) {
+ int syncState = ContentResolver.getIsSyncable(account, authority);
+ boolean syncEnabled = ContentResolver.getSyncAutomatically(account, authority);
+
+ JSONObject authorityJSON = new JSONObject();
+ authorityJSON.put(KEY_AUTHORITY_NAME, authority);
+ authorityJSON.put(KEY_AUTHORITY_SYNC_STATE, syncState);
+ authorityJSON.put(KEY_AUTHORITY_SYNC_ENABLED, syncEnabled);
+ authoritiesJSONArray.put(authorityJSON);
+ }
+ accountJSON.put(KEY_ACCOUNT_AUTHORITIES, authoritiesJSONArray);
+
+ accountJSONArray.put(accountJSON);
+ }
+ backupJSON.put(KEY_ACCOUNTS, accountJSONArray);
+
+ return backupJSON;
+ }
+
+ /**
+ * Read the MD5 checksum from the old state.
+ *
+ * @return the old MD5 checksum
+ */
+ private byte[] readOldMd5Checksum(ParcelFileDescriptor oldState) throws IOException {
+ DataInputStream dataInput = new DataInputStream(
+ new FileInputStream(oldState.getFileDescriptor()));
+
+ byte[] oldMd5Checksum = new byte[MD5_BYTE_SIZE];
+ try {
+ int stateVersion = dataInput.readInt();
+ if (stateVersion <= STATE_VERSION) {
+ // If the state version is a version we can understand then read the MD5 sum,
+ // otherwise we return an empty byte array for the MD5 sum which will force a
+ // backup.
+ for (int i = 0; i < MD5_BYTE_SIZE; i++) {
+ oldMd5Checksum[i] = dataInput.readByte();
+ }
+ } else {
+ Log.i(TAG, "Backup state version is: " + stateVersion
+ + " (support only up to version " + STATE_VERSION + ")");
+ }
+ } catch (EOFException eof) {
+ // Initial state may be empty.
+ } finally {
+ dataInput.close();
+ }
+ return oldMd5Checksum;
+ }
+
+ /**
+ * Write the given checksum to the file descriptor.
+ */
+ private void writeNewMd5Checksum(ParcelFileDescriptor newState, byte[] md5Checksum)
+ throws IOException {
+ DataOutputStream dataOutput = new DataOutputStream(
+ new BufferedOutputStream(new FileOutputStream(newState.getFileDescriptor())));
+
+ dataOutput.writeInt(STATE_VERSION);
+ dataOutput.write(md5Checksum);
+ dataOutput.close();
+ }
+
+ private byte[] generateMd5Checksum(byte[] data) throws NoSuchAlgorithmException {
+ if (data == null) {
+ return null;
+ }
+
+ MessageDigest md5 = MessageDigest.getInstance("MD5");
+ return md5.digest(data);
+ }
+
+ /**
+ * Restore account sync settings from the given data input stream.
+ */
+ @Override
+ public void restoreEntity(BackupDataInputStream data) {
+ byte[] dataBytes = new byte[data.size()];
+ try {
+ // Read the data and convert it to a String.
+ data.read(dataBytes);
+ String dataString = new String(dataBytes, JSON_FORMAT_ENCODING);
+
+ // Convert data to a JSON object.
+ JSONObject dataJSON = new JSONObject(dataString);
+ boolean masterSyncEnabled = dataJSON.getBoolean(KEY_MASTER_SYNC_ENABLED);
+ JSONArray accountJSONArray = dataJSON.getJSONArray(KEY_ACCOUNTS);
+
+ boolean currentMasterSyncEnabled = ContentResolver.getMasterSyncAutomatically();
+ if (currentMasterSyncEnabled) {
+ // Disable master sync to prevent any syncs from running.
+ ContentResolver.setMasterSyncAutomatically(false);
+ }
+
+ try {
+ HashSet<Account> currentAccounts = getAccountsHashSet();
+ for (int i = 0; i < accountJSONArray.length(); i++) {
+ JSONObject accountJSON = (JSONObject) accountJSONArray.get(i);
+ String accountName = accountJSON.getString(KEY_ACCOUNT_NAME);
+ String accountType = accountJSON.getString(KEY_ACCOUNT_TYPE);
+
+ Account account = new Account(accountName, accountType);
+
+ // Check if the account already exists. Accounts that don't exist on the device
+ // yet won't be restored.
+ if (currentAccounts.contains(account)) {
+ restoreExistingAccountSyncSettingsFromJSON(accountJSON);
+ }
+ }
+ } finally {
+ // Set the master sync preference to the value from the backup set.
+ ContentResolver.setMasterSyncAutomatically(masterSyncEnabled);
+ }
+
+ Log.i(TAG, "Restore successful.");
+ } catch (IOException | JSONException e) {
+ Log.e(TAG, "Couldn't restore account sync settings\n" + e);
+ }
+ }
+
+ /**
+ * Helper method - fetch accounts and return them as a HashSet.
+ *
+ * @return Accounts in a HashSet.
+ */
+ private HashSet<Account> getAccountsHashSet() {
+ Account[] accounts = mAccountManager.getAccounts();
+ HashSet<Account> accountHashSet = new HashSet<Account>();
+ for (Account account : accounts) {
+ accountHashSet.add(account);
+ }
+ return accountHashSet;
+ }
+
+ /**
+ * Restore account sync settings using the given JSON. This function won't work if the account
+ * doesn't exist yet.
+ */
+ private void restoreExistingAccountSyncSettingsFromJSON(JSONObject accountJSON)
+ throws JSONException {
+ // Restore authorities.
+ JSONArray authorities = accountJSON.getJSONArray(KEY_ACCOUNT_AUTHORITIES);
+ String accountName = accountJSON.getString(KEY_ACCOUNT_NAME);
+ String accountType = accountJSON.getString(KEY_ACCOUNT_TYPE);
+ final Account account = new Account(accountName, accountType);
+ for (int i = 0; i < authorities.length(); i++) {
+ JSONObject authority = (JSONObject) authorities.get(i);
+ final String authorityName = authority.getString(KEY_AUTHORITY_NAME);
+ boolean syncEnabled = authority.getBoolean(KEY_AUTHORITY_SYNC_ENABLED);
+
+ // Cancel any active syncs.
+ if (ContentResolver.isSyncActive(account, authorityName)) {
+ ContentResolver.cancelSync(account, authorityName);
+ }
+
+ boolean overwriteSync = true;
+ Bundle initializationExtras = createSyncInitializationBundle();
+ int currentSyncState = ContentResolver.getIsSyncable(account, authorityName);
+ if (currentSyncState < 0) {
+ // Requesting a sync is an asynchronous operation, so we setup a countdown latch to
+ // wait for it to finish. Initialization syncs are generally very brief and
+ // shouldn't take too much time to finish.
+ final CountDownLatch latch = new CountDownLatch(1);
+ Object syncStatusObserverHandle = ContentResolver.addStatusChangeListener(
+ ContentResolver.SYNC_OBSERVER_TYPE_ACTIVE, new SyncStatusObserver() {
+ @Override
+ public void onStatusChanged(int which) {
+ if (!ContentResolver.isSyncActive(account, authorityName)) {
+ latch.countDown();
+ }
+ }
+ });
+
+ // If we set sync settings for a sync that hasn't been initialized yet, we run the
+ // risk of having our changes overwritten later on when the sync gets initialized.
+ // To prevent this from happening we will manually initiate the sync adapter. We
+ // also explicitly pass in a Bundle with SYNC_EXTRAS_INITIALIZE to prevent a data
+ // sync from running after the initialization sync. Two syncs will be scheduled, but
+ // the second one (data sync) will override the first one (initialization sync) and
+ // still behave as an initialization sync because of the Bundle.
+ ContentResolver.requestSync(account, authorityName, initializationExtras);
+
+ boolean done = false;
+ try {
+ done = latch.await(SYNC_REQUEST_LATCH_TIMEOUT_SECONDS, TimeUnit.SECONDS);
+ } catch (InterruptedException e) {
+ Log.e(TAG, "CountDownLatch interrupted\n" + e);
+ done = false;
+ }
+ if (!done) {
+ overwriteSync = false;
+ Log.i(TAG, "CountDownLatch timed out, skipping '" + authorityName
+ + "' authority.");
+ }
+ ContentResolver.removeStatusChangeListener(syncStatusObserverHandle);
+ }
+
+ if (overwriteSync) {
+ ContentResolver.setSyncAutomatically(account, authorityName, syncEnabled);
+ Log.i(TAG, "Set sync automatically for '" + authorityName + "': " + syncEnabled);
+ }
+ }
+ }
+
+ private Bundle createSyncInitializationBundle() {
+ Bundle extras = new Bundle();
+ extras.putBoolean(ContentResolver.SYNC_EXTRAS_INITIALIZE, true);
+ return extras;
+ }
+
+ @Override
+ public void writeNewStateDescription(ParcelFileDescriptor newState) {
+
+ }
+}
diff --git a/core/java/com/android/server/backup/SystemBackupAgent.java b/core/java/com/android/server/backup/SystemBackupAgent.java
index 35a1a5a..b5f2f37 100644
--- a/core/java/com/android/server/backup/SystemBackupAgent.java
+++ b/core/java/com/android/server/backup/SystemBackupAgent.java
@@ -86,6 +86,8 @@ public class SystemBackupAgent extends BackupAgentHelper {
}
addHelper("wallpaper", new WallpaperBackupHelper(SystemBackupAgent.this, files, keys));
addHelper("recents", new RecentsBackupHelper(SystemBackupAgent.this));
+ addHelper("account_sync_settings",
+ new AccountSyncSettingsBackupHelper(SystemBackupAgent.this));
super.onBackup(oldState, data, newState);
}
@@ -118,6 +120,8 @@ public class SystemBackupAgent extends BackupAgentHelper {
new String[] { WALLPAPER_IMAGE },
new String[] { WALLPAPER_IMAGE_KEY} ));
addHelper("recents", new RecentsBackupHelper(SystemBackupAgent.this));
+ addHelper("account_sync_settings",
+ new AccountSyncSettingsBackupHelper(SystemBackupAgent.this));
try {
super.onRestore(data, appVersionCode, newState);