Search in sources :

Example 36 with NonNull

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);
}
Also used : ComponentName(android.content.ComponentName) PrinterId(android.print.PrinterId) NonNull(android.annotation.NonNull)

Example 37 with NonNull

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;
}
Also used : Point(android.graphics.Point) Point(android.graphics.Point) WindowManager(android.view.WindowManager) Display(android.view.Display) NonNull(android.annotation.NonNull)

Example 38 with NonNull

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;
}
Also used : ArrayList(java.util.ArrayList) UserInfo(android.content.pm.UserInfo) NonNull(android.annotation.NonNull)

Example 39 with NonNull

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;
}
Also used : XmlPullParser(org.xmlpull.v1.XmlPullParser) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) IOException(java.io.IOException) NonNull(android.annotation.NonNull)

Example 40 with NonNull

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) {
        }
    }
}
Also used : BufferedInputStream(java.io.BufferedInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) IOException(java.io.IOException) NonNull(android.annotation.NonNull)

Aggregations

NonNull (android.annotation.NonNull)322 ArrayList (java.util.ArrayList)46 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)45 IOException (java.io.IOException)35 ComponentName (android.content.ComponentName)25 File (java.io.File)22 XmlPullParser (org.xmlpull.v1.XmlPullParser)20 Intent (android.content.Intent)18 EphemeralResolveInfo (android.content.pm.EphemeralResolveInfo)16 ResolveInfo (android.content.pm.ResolveInfo)16 Bundle (android.os.Bundle)15 RemoteException (android.os.RemoteException)15 FileNotFoundException (java.io.FileNotFoundException)15 Paint (android.graphics.Paint)14 PackageParser (android.content.pm.PackageParser)12 ContentResolver (android.content.ContentResolver)10 UserInfo (android.content.pm.UserInfo)10 StorageManager (android.os.storage.StorageManager)10 VolumeInfo (android.os.storage.VolumeInfo)10 KeyCharacteristics (android.security.keymaster.KeyCharacteristics)10