Search in sources :

Example 1 with NonNull

use of android.annotation.NonNull in project android_frameworks_base by ResurrectionRemix.

the class DrawableInflater method inflateFromClass.

@NonNull
private Drawable inflateFromClass(@NonNull String className) {
    try {
        Constructor<? extends Drawable> constructor;
        synchronized (CONSTRUCTOR_MAP) {
            constructor = CONSTRUCTOR_MAP.get(className);
            if (constructor == null) {
                final Class<? extends Drawable> clazz = mClassLoader.loadClass(className).asSubclass(Drawable.class);
                constructor = clazz.getConstructor();
                CONSTRUCTOR_MAP.put(className, constructor);
            }
        }
        return constructor.newInstance();
    } catch (NoSuchMethodException e) {
        final InflateException ie = new InflateException("Error inflating class " + className);
        ie.initCause(e);
        throw ie;
    } catch (ClassCastException e) {
        // If loaded class is not a Drawable subclass.
        final InflateException ie = new InflateException("Class is not a Drawable " + className);
        ie.initCause(e);
        throw ie;
    } catch (ClassNotFoundException e) {
        // If loadClass fails, we should propagate the exception.
        final InflateException ie = new InflateException("Class not found " + className);
        ie.initCause(e);
        throw ie;
    } catch (Exception e) {
        final InflateException ie = new InflateException("Error inflating class " + className);
        ie.initCause(e);
        throw ie;
    }
}
Also used : InflateException(android.view.InflateException) IOException(java.io.IOException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) InflateException(android.view.InflateException) NonNull(android.annotation.NonNull)

Example 2 with NonNull

use of android.annotation.NonNull in project android_frameworks_base by ResurrectionRemix.

the class PrintManager method print.

/**
     * Creates a print job for printing a {@link PrintDocumentAdapter} with
     * default print attributes.
     * <p>
     * Calling this method brings the print UI allowing the user to customize
     * the print job and returns a {@link PrintJob} object without waiting for the
     * user to customize or confirm the print job. The returned print job instance
     * is in a {@link PrintJobInfo#STATE_CREATED created} state.
     * <p>
     * This method can be called only from an {@link Activity}. The rationale is that
     * printing from a service will create an inconsistent user experience as the print
     * UI would appear without any context.
     * </p>
     * <p>
     * Also the passed in {@link PrintDocumentAdapter} will be considered invalid if
     * your activity is finished. The rationale is that once the activity that
     * initiated printing is finished, the provided adapter may be in an inconsistent
     * state as it may depend on the UI presented by the activity.
     * </p>
     * <p>
     * The default print attributes are a hint to the system how the data is to
     * be printed. For example, a photo editor may look at the photo aspect ratio
     * to determine the default orientation and provide a hint whether the printing
     * should be in portrait or landscape. The system will do a best effort to
     * selected the hinted options in the print dialog, given the current printer
     * supports them.
     * </p>
     * <p>
     * <strong>Note:</strong> Calling this method will bring the print dialog and
     * the system will connect to the provided {@link PrintDocumentAdapter}. If a
     * configuration change occurs that you application does not handle, for example
     * a rotation change, the system will drop the connection to the adapter as the
     * activity has to be recreated and the old adapter may be invalid in this context,
     * hence a new adapter instance is required. As a consequence, if your activity
     * does not handle configuration changes (default behavior), you have to save the
     * state that you were printing and call this method again when your activity
     * is recreated.
     * </p>
     *
     * @param printJobName A name for the new print job which is shown to the user.
     * @param documentAdapter An adapter that emits the document to print.
     * @param attributes The default print job attributes or <code>null</code>.
     * @return The created print job on success or null on failure.
     * @throws IllegalStateException If not called from an {@link Activity}.
     * @throws IllegalArgumentException If the print job name is empty or the
     * document adapter is null.
     *
     * @see PrintJob
     */
@NonNull
public PrintJob print(@NonNull String printJobName, @NonNull PrintDocumentAdapter documentAdapter, @Nullable PrintAttributes attributes) {
    if (mService == null) {
        Log.w(LOG_TAG, "Feature android.software.print not available");
        return null;
    }
    if (!(mContext instanceof Activity)) {
        throw new IllegalStateException("Can print only from an activity");
    }
    if (TextUtils.isEmpty(printJobName)) {
        throw new IllegalArgumentException("printJobName cannot be empty");
    }
    if (documentAdapter == null) {
        throw new IllegalArgumentException("documentAdapter cannot be null");
    }
    PrintDocumentAdapterDelegate delegate = new PrintDocumentAdapterDelegate((Activity) mContext, documentAdapter);
    try {
        Bundle result = mService.print(printJobName, delegate, attributes, mContext.getPackageName(), mAppId, mUserId);
        if (result != null) {
            PrintJobInfo printJob = result.getParcelable(EXTRA_PRINT_JOB);
            IntentSender intent = result.getParcelable(EXTRA_PRINT_DIALOG_INTENT);
            if (printJob == null || intent == null) {
                return null;
            }
            try {
                mContext.startIntentSender(intent, null, 0, 0, 0);
                return new PrintJob(printJob, this);
            } catch (SendIntentException sie) {
                Log.e(LOG_TAG, "Couldn't start print job config activity.", sie);
            }
        }
    } catch (RemoteException re) {
        throw re.rethrowFromSystemServer();
    }
    return null;
}
Also used : Bundle(android.os.Bundle) Activity(android.app.Activity) IntentSender(android.content.IntentSender) RemoteException(android.os.RemoteException) SendIntentException(android.content.IntentSender.SendIntentException) NonNull(android.annotation.NonNull)

Example 3 with NonNull

use of android.annotation.NonNull in project android_frameworks_base by ResurrectionRemix.

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 4 with NonNull

use of android.annotation.NonNull in project android_frameworks_base by ResurrectionRemix.

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 5 with NonNull

use of android.annotation.NonNull in project android_frameworks_base by ResurrectionRemix.

the class Layout method createTitleBar.

@NonNull
private TitleBar createTitleBar(BridgeContext context, String title, int simulatedPlatformVersion) {
    TitleBar titleBar = new TitleBar(context, title, simulatedPlatformVersion);
    LayoutParams params = createLayoutParams(MATCH_PARENT, mBuilder.mTitleBarSize);
    if (mBuilder.hasStatusBar() && mBuilder.solidBars()) {
        params.addRule(BELOW, getId(ID_STATUS_BAR));
    }
    if (mBuilder.isNavBarVertical() && mBuilder.solidBars()) {
        params.addRule(START_OF, getId(ID_NAV_BAR));
    }
    titleBar.setLayoutParams(params);
    titleBar.setId(getId(ID_TITLE_BAR));
    return titleBar;
}
Also used : TitleBar(com.android.layoutlib.bridge.bars.TitleBar) NonNull(android.annotation.NonNull)

Aggregations

NonNull (android.annotation.NonNull)342 ArrayList (java.util.ArrayList)56 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)46 IOException (java.io.IOException)37 ComponentName (android.content.ComponentName)25 File (java.io.File)23 XmlPullParser (org.xmlpull.v1.XmlPullParser)20 Intent (android.content.Intent)18 Bundle (android.os.Bundle)17 EphemeralResolveInfo (android.content.pm.EphemeralResolveInfo)16 ResolveInfo (android.content.pm.ResolveInfo)16 FileNotFoundException (java.io.FileNotFoundException)16 RemoteException (android.os.RemoteException)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