use of android.annotation.NonNull in project platform_frameworks_base by android.
the class PrintService method generatePrinterId.
/**
* Generates a global printer id given the printer's locally unique one.
*
* @param localId A locally unique id in the context of your print service.
* @return Global printer id.
*/
@NonNull
public final PrinterId generatePrinterId(String localId) {
throwIfNotCalledOnMainThread();
localId = Preconditions.checkNotNull(localId, "localId cannot be null");
return new PrinterId(new ComponentName(getPackageName(), getClass().getName()), localId);
}
use of android.annotation.NonNull in project platform_frameworks_base by android.
the class MenuPopupHelper method createPopup.
/**
* Creates the popup and assigns cached properties.
*
* @return an initialized popup
*/
@NonNull
private MenuPopup createPopup() {
final WindowManager windowManager = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
final Display display = windowManager.getDefaultDisplay();
final Point displaySize = new Point();
display.getRealSize(displaySize);
final int smallestWidth = Math.min(displaySize.x, displaySize.y);
final int minSmallestWidthCascading = mContext.getResources().getDimensionPixelSize(com.android.internal.R.dimen.cascading_menus_min_smallest_width);
final boolean enableCascadingSubmenus = smallestWidth >= minSmallestWidthCascading;
final MenuPopup popup;
if (enableCascadingSubmenus) {
popup = new CascadingMenuPopup(mContext, mAnchorView, mPopupStyleAttr, mPopupStyleRes, mOverflowOnly);
} else {
popup = new StandardMenuPopup(mContext, mMenu, mAnchorView, mPopupStyleAttr, mPopupStyleRes, mOverflowOnly);
}
// Assign immutable properties.
popup.addMenu(mMenu);
popup.setOnDismissListener(mInternalOnDismissListener);
// Assign mutable properties. These may be reassigned later.
popup.setAnchorView(mAnchorView);
popup.setCallback(mPresenterCallback);
popup.setForceShowIcon(mForceShowIcon);
popup.setGravity(mDropDownGravity);
return popup;
}
use of android.annotation.NonNull in project android_frameworks_base by DirtyUnicorns.
the class PackageManagerSettingsTests method createFakeUsers.
@NonNull
private List<UserInfo> createFakeUsers() {
ArrayList<UserInfo> users = new ArrayList<>();
users.add(new UserInfo(UserHandle.USER_SYSTEM, "test user", UserInfo.FLAG_INITIALIZED));
return users;
}
use of android.annotation.NonNull in project android_frameworks_base by DirtyUnicorns.
the class ParserFactory method create.
@NonNull
private static XmlPullParser create(@NonNull InputStream stream, @Nullable String name, long size, boolean isLayout) throws XmlPullParserException {
XmlPullParser parser = instantiateParser(name);
stream = readAndClose(stream, name, size);
parser.setInput(stream, ENCODING);
if (isLayout) {
try {
return new LayoutParserWrapper(parser).peekTillLayoutStart();
} catch (IOException e) {
throw new XmlPullParserException(null, parser, e);
}
}
return parser;
}
use of android.annotation.NonNull in project android_frameworks_base by DirtyUnicorns.
the class ParserFactory method readAndClose.
@NonNull
private static InputStream readAndClose(@NonNull InputStream stream, @Nullable String name, long size) throws XmlPullParserException {
// just a sanity check. It's doubtful we'll have such big files!
if (size > Integer.MAX_VALUE) {
throw new XmlPullParserException("File " + name + " is too big to be parsed");
}
int intSize = (int) size;
// create a buffered reader to facilitate reading.
BufferedInputStream bufferedStream = new BufferedInputStream(stream);
try {
int avail;
if (intSize != -1) {
avail = intSize;
} else {
// get the size to read.
avail = bufferedStream.available();
}
// create the initial buffer and read it.
byte[] buffer = new byte[avail];
int read = stream.read(buffer);
// this is the easy case.
if (read == intSize) {
return new ByteArrayInputStream(buffer);
}
// available() returned!)
while ((avail = bufferedStream.available()) > 0) {
if (read + avail > buffer.length) {
// just allocate what is needed. We're mostly reading small files
// so it shouldn't be too problematic.
byte[] moreBuffer = new byte[read + avail];
System.arraycopy(buffer, 0, moreBuffer, 0, read);
buffer = moreBuffer;
}
read += stream.read(buffer, read, avail);
}
// return a new stream encapsulating this buffer.
return new ByteArrayInputStream(buffer);
} catch (IOException e) {
throw new XmlPullParserException("Failed to read " + name, null, e);
} finally {
try {
bufferedStream.close();
} catch (IOException ignored) {
}
}
}
Aggregations