Search in sources :

Example 96 with Nullable

use of android.support.annotation.Nullable in project GalleryFinal by pengjianbo.

the class CropUtil method getFromMediaUriPfd.

@Nullable
private static File getFromMediaUriPfd(Context context, ContentResolver resolver, Uri uri) {
    if (uri == null)
        return null;
    FileInputStream input = null;
    FileOutputStream output = null;
    try {
        ParcelFileDescriptor pfd = resolver.openFileDescriptor(uri, "r");
        FileDescriptor fd = pfd.getFileDescriptor();
        input = new FileInputStream(fd);
        String tempFilename = getTempFilename(context);
        output = new FileOutputStream(tempFilename);
        int read;
        byte[] bytes = new byte[4096];
        while ((read = input.read(bytes)) != -1) {
            output.write(bytes, 0, read);
        }
        return new File(tempFilename);
    } catch (IOException ignored) {
    // Nothing we can do
    } finally {
        closeSilently(input);
        closeSilently(output);
    }
    return null;
}
Also used : FileOutputStream(java.io.FileOutputStream) ParcelFileDescriptor(android.os.ParcelFileDescriptor) IOException(java.io.IOException) File(java.io.File) FileInputStream(java.io.FileInputStream) ParcelFileDescriptor(android.os.ParcelFileDescriptor) FileDescriptor(java.io.FileDescriptor) Nullable(android.support.annotation.Nullable)

Example 97 with Nullable

use of android.support.annotation.Nullable in project storio by pushtorefresh.

the class DefaultStorIOContentResolverTest method getTypeMappingFinder.

@Nullable
private static TypeMappingFinder getTypeMappingFinder(@NonNull DefaultStorIOContentResolver storIOContentResolver) throws NoSuchFieldException, IllegalAccessException {
    Field field = DefaultStorIOContentResolver.LowLevelImpl.class.getDeclaredField("typeMappingFinder");
    field.setAccessible(true);
    return (TypeMappingFinder) field.get(storIOContentResolver.lowLevel());
}
Also used : Field(java.lang.reflect.Field) TypeMappingFinder(com.pushtorefresh.storio.TypeMappingFinder) Nullable(android.support.annotation.Nullable)

Example 98 with Nullable

use of android.support.annotation.Nullable in project storio by pushtorefresh.

the class PreparedGetObject method executeAsBlocking.

/**
     * Executes Prepared Operation immediately in current thread.
     * <p>
     * Notice: This is blocking I/O operation that should not be executed on the Main Thread,
     * it can cause ANR (Activity Not Responding dialog), block the UI and drop animations frames.
     * So please, call this method on some background thread. See {@link WorkerThread}.
     *
     *  @return single instance of mapped result. Can be {@code null}, if no items are found.
     */
@SuppressWarnings({ "ConstantConditions", "NullableProblems" })
@WorkerThread
@Nullable
@Override
public T executeAsBlocking() {
    try {
        final GetResolver<T> getResolver;
        if (explicitGetResolver != null) {
            getResolver = explicitGetResolver;
        } else {
            final ContentResolverTypeMapping<T> typeMapping = storIOContentResolver.lowLevel().typeMapping(type);
            if (typeMapping == null) {
                throw new IllegalStateException("This type does not have type mapping: " + "type = " + type + "," + "ContentProvider was not touched by this operation, please add type mapping for this type");
            }
            getResolver = typeMapping.getResolver();
        }
        final Cursor cursor = getResolver.performGet(storIOContentResolver, query);
        try {
            final int count = cursor.getCount();
            if (count == 0) {
                return null;
            }
            cursor.moveToFirst();
            return getResolver.mapFromCursor(cursor);
        } finally {
            cursor.close();
        }
    } catch (Exception exception) {
        throw new StorIOException("Error has occurred during Get operation. query = " + query, exception);
    }
}
Also used : StorIOException(com.pushtorefresh.storio.StorIOException) Cursor(android.database.Cursor) StorIOException(com.pushtorefresh.storio.StorIOException) WorkerThread(android.support.annotation.WorkerThread) Nullable(android.support.annotation.Nullable)

Example 99 with Nullable

use of android.support.annotation.Nullable in project storio by pushtorefresh.

the class PreparedGetObject method executeAsBlocking.

/**
     * Executes Get Operation immediately in current thread.
     * <p>
     * Notice: This is blocking I/O operation that should not be executed on the Main Thread,
     * it can cause ANR (Activity Not Responding dialog), block the UI and drop animations frames.
     * So please, call this method on some background thread. See {@link WorkerThread}.
     *
     * @return single instance of mapped result. Can be {@code null}, if no items are found.
     */
@Nullable
@SuppressWarnings({ "ConstantConditions", "NullableProblems" })
@WorkerThread
public T executeAsBlocking() {
    try {
        final GetResolver<T> getResolver;
        if (explicitGetResolver != null) {
            getResolver = explicitGetResolver;
        } else {
            final SQLiteTypeMapping<T> typeMapping = storIOSQLite.lowLevel().typeMapping(type);
            if (typeMapping == null) {
                throw new IllegalStateException("This type does not have type mapping: " + "type = " + type + "," + "db was not touched by this operation, please add type mapping for this type");
            }
            getResolver = typeMapping.getResolver();
        }
        final Cursor cursor;
        if (query != null) {
            cursor = getResolver.performGet(storIOSQLite, query);
        } else if (rawQuery != null) {
            cursor = getResolver.performGet(storIOSQLite, rawQuery);
        } else {
            throw new IllegalStateException("Please specify query");
        }
        try {
            final int count = cursor.getCount();
            if (count == 0) {
                return null;
            }
            cursor.moveToNext();
            return getResolver.mapFromCursor(cursor);
        } finally {
            cursor.close();
        }
    } catch (Exception exception) {
        throw new StorIOException("Error has occurred during Get operation. query = " + (query != null ? query : rawQuery), exception);
    }
}
Also used : StorIOException(com.pushtorefresh.storio.StorIOException) Cursor(android.database.Cursor) StorIOException(com.pushtorefresh.storio.StorIOException) WorkerThread(android.support.annotation.WorkerThread) Nullable(android.support.annotation.Nullable)

Example 100 with Nullable

use of android.support.annotation.Nullable in project RxJavaSamples by rengwuxian.

the class ElementaryFragment method onCreateView.

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_elementary, container, false);
    ButterKnife.bind(this, view);
    gridRv.setLayoutManager(new GridLayoutManager(getActivity(), 2));
    gridRv.setAdapter(adapter);
    swipeRefreshLayout.setColorSchemeColors(Color.BLUE, Color.GREEN, Color.RED, Color.YELLOW);
    swipeRefreshLayout.setEnabled(false);
    return view;
}
Also used : GridLayoutManager(android.support.v7.widget.GridLayoutManager) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View) Nullable(android.support.annotation.Nullable)

Aggregations

Nullable (android.support.annotation.Nullable)477 View (android.view.View)266 TextView (android.widget.TextView)131 RecyclerView (android.support.v7.widget.RecyclerView)70 ImageView (android.widget.ImageView)41 IOException (java.io.IOException)32 Intent (android.content.Intent)30 Bundle (android.os.Bundle)30 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)28 ViewGroup (android.view.ViewGroup)27 Uri (android.net.Uri)25 BindView (butterknife.BindView)25 ArrayList (java.util.ArrayList)25 Cursor (android.database.Cursor)23 File (java.io.File)22 AdapterView (android.widget.AdapterView)16 Bitmap (android.graphics.Bitmap)15 Context (android.content.Context)14 Drawable (android.graphics.drawable.Drawable)13 EditText (android.widget.EditText)13