Search in sources :

Example 56 with NonNull

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

the class BaseTest method putUserBlocking.

@NonNull
User putUserBlocking(@NonNull final User user) {
    final PutResult putResult = storIOSQLite.put().object(user).prepare().executeAsBlocking();
    assertThat(putResult).isNotNull();
    assertThat(putResult.wasInserted()).isTrue();
    return user;
}
Also used : PutResult(com.pushtorefresh.storio.sqlite.operations.put.PutResult) NonNull(android.support.annotation.NonNull)

Example 57 with NonNull

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

the class DefaultDeleteResolverTest method performDelete.

@Test
public void performDelete() {
    final StorIOSQLite storIOSQLite = mock(StorIOSQLite.class);
    final StorIOSQLite.Internal internal = mock(StorIOSQLite.Internal.class);
    final String testTable = "test_table";
    final DeleteQuery deleteQuery = DeleteQuery.builder().table(testTable).build();
    when(storIOSQLite.lowLevel()).thenReturn(internal);
    when(internal.delete(deleteQuery)).thenReturn(1);
    final TestItem testItem = new TestItem();
    final DefaultDeleteResolver<TestItem> defaultDeleteResolver = new DefaultDeleteResolver<TestItem>() {

        @NonNull
        @Override
        public DeleteQuery mapToDeleteQuery(@NonNull TestItem testItem) {
            return deleteQuery;
        }
    };
    final DeleteResult deleteResult = defaultDeleteResolver.performDelete(storIOSQLite, testItem);
    verify(internal, times(1)).delete(any(DeleteQuery.class));
    verify(internal, times(1)).delete(deleteQuery);
    assertThat(deleteResult.numberOfRowsDeleted()).isEqualTo(1);
    assertThat(deleteResult.affectedTables()).isEqualTo(Collections.singleton(testTable));
}
Also used : NonNull(android.support.annotation.NonNull) DeleteQuery(com.pushtorefresh.storio.sqlite.queries.DeleteQuery) StorIOSQLite(com.pushtorefresh.storio.sqlite.StorIOSQLite) Test(org.junit.Test)

Example 58 with NonNull

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

the class DefaultGetResolverTest method rawQuery.

@Test
public void rawQuery() {
    final StorIOSQLite storIOSQLite = mock(StorIOSQLite.class);
    final StorIOSQLite.Internal internal = mock(StorIOSQLite.Internal.class);
    final RawQuery rawQuery = RawQuery.builder().query("test sql").build();
    final Cursor expectedCursor = mock(Cursor.class);
    when(storIOSQLite.lowLevel()).thenReturn(internal);
    when(internal.rawQuery(rawQuery)).thenReturn(expectedCursor);
    final DefaultGetResolver<TestItem> defaultGetResolver = new DefaultGetResolver<TestItem>() {

        @NonNull
        @Override
        public TestItem mapFromCursor(@NonNull Cursor cursor) {
            return mock(TestItem.class);
        }
    };
    final Cursor actualCursor = defaultGetResolver.performGet(storIOSQLite, rawQuery);
    // only one request should occur
    verify(internal, times(1)).rawQuery(any(RawQuery.class));
    // and this request should be equals to original
    verify(internal, times(1)).rawQuery(rawQuery);
    assertThat(actualCursor).isSameAs(expectedCursor);
}
Also used : NonNull(android.support.annotation.NonNull) RawQuery(com.pushtorefresh.storio.sqlite.queries.RawQuery) Cursor(android.database.Cursor) StorIOSQLite(com.pushtorefresh.storio.sqlite.StorIOSQLite) Test(org.junit.Test)

Example 59 with NonNull

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

the class DefaultPutResolverTest method insert.

/**
     * Verifies behavior of {@link DefaultPutResolver} for "insert"
     */
@Test
public void insert() {
    final StorIOSQLite storIOSQLite = mock(StorIOSQLite.class);
    final StorIOSQLite.Internal internal = mock(StorIOSQLite.Internal.class);
    // item without id, should be inserted
    final TestItem testItem = new TestItem(null);
    when(storIOSQLite.lowLevel()).thenReturn(internal);
    final Long expectedInsertedId = 24L;
    final Query expectedQuery = Query.builder().table(TestItem.TABLE).where(TestItem.COLUMN_ID + " = ?").whereArgs(testItem.getId()).build();
    final Cursor cursor = mock(Cursor.class);
    when(internal.query(eq(expectedQuery))).thenReturn(cursor);
    when(cursor.getCount()).thenReturn(// No results -> insert should be performed
    0);
    when(internal.insert(any(InsertQuery.class), any(ContentValues.class))).thenReturn(expectedInsertedId);
    final InsertQuery expectedInsertQuery = InsertQuery.builder().table(TestItem.TABLE).nullColumnHack(null).build();
    final PutResolver<TestItem> putResolver = new DefaultPutResolver<TestItem>() {

        @NonNull
        @Override
        protected InsertQuery mapToInsertQuery(@NonNull TestItem object) {
            return expectedInsertQuery;
        }

        @NonNull
        @Override
        protected UpdateQuery mapToUpdateQuery(@NonNull TestItem object) {
            return UpdateQuery.builder().table(TestItem.TABLE).where(TestItem.COLUMN_ID + " = ?").whereArgs(object.getId()).build();
        }

        @NonNull
        @Override
        protected ContentValues mapToContentValues(@NonNull TestItem object) {
            return TestItem.MAP_TO_CONTENT_VALUES.call(object);
        }
    };
    final ContentValues expectedContentValues = TestItem.MAP_TO_CONTENT_VALUES.call(testItem);
    // Performing Put that should "insert"
    final PutResult putResult = putResolver.performPut(storIOSQLite, testItem);
    verify(internal, times(1)).beginTransaction();
    verify(internal, times(1)).setTransactionSuccessful();
    verify(internal, times(1)).endTransaction();
    // checks that it asks db for results
    verify(internal, times(1)).query(eq(expectedQuery));
    // checks that cursor was closed
    verify(cursor, times(1)).close();
    // only one query should occur
    verify(internal, times(1)).query(any(Query.class));
    // checks that required insert was performed
    verify(internal, times(1)).insert(eq(expectedInsertQuery), eq(expectedContentValues));
    // only one insert should occur
    verify(internal, times(1)).insert(any(InsertQuery.class), any(ContentValues.class));
    // no updates should occur
    verify(internal, times(0)).update(any(UpdateQuery.class), any(ContentValues.class));
    // put result checks
    assertThat(putResult.wasInserted()).isTrue();
    assertThat(putResult.wasUpdated()).isFalse();
    assertThat(putResult.insertedId()).isEqualTo(expectedInsertedId);
    assertThat(putResult.numberOfRowsUpdated()).isNull();
}
Also used : ContentValues(android.content.ContentValues) Query(com.pushtorefresh.storio.sqlite.queries.Query) InsertQuery(com.pushtorefresh.storio.sqlite.queries.InsertQuery) UpdateQuery(com.pushtorefresh.storio.sqlite.queries.UpdateQuery) UpdateQuery(com.pushtorefresh.storio.sqlite.queries.UpdateQuery) Cursor(android.database.Cursor) InsertQuery(com.pushtorefresh.storio.sqlite.queries.InsertQuery) NonNull(android.support.annotation.NonNull) StorIOSQLite(com.pushtorefresh.storio.sqlite.StorIOSQLite) Test(org.junit.Test)

Example 60 with NonNull

use of android.support.annotation.NonNull in project android-vision by googlesamples.

the class GooglyEyesActivity method createFaceDetector.

//==============================================================================================
// Detector
//==============================================================================================
/**
     * Creates the face detector and associated processing pipeline to support either front facing
     * mode or rear facing mode.  Checks if the detector is ready to use, and displays a low storage
     * warning if it was not possible to download the face library.
     */
@NonNull
private FaceDetector createFaceDetector(Context context) {
    // For both front facing and rear facing modes, the detector is initialized to do landmark
    // detection (to find the eyes), classification (to determine if the eyes are open), and
    // tracking.
    //
    // Use of "fast mode" enables faster detection for frontward faces, at the expense of not
    // attempting to detect faces at more varied angles (e.g., faces in profile).  Therefore,
    // faces that are turned too far won't be detected under fast mode.
    //
    // For front facing mode only, the detector will use the "prominent face only" setting,
    // which is optimized for tracking a single relatively large face.  This setting allows the
    // detector to take some shortcuts to make tracking faster, at the expense of not being able
    // to track multiple faces.
    //
    // Setting the minimum face size not only controls how large faces must be in order to be
    // detected, it also affects performance.  Since it takes longer to scan for smaller faces,
    // we increase the minimum face size for the rear facing mode a little bit in order to make
    // tracking faster (at the expense of missing smaller faces).  But this optimization is less
    // important for the front facing case, because when "prominent face only" is enabled, the
    // detector stops scanning for faces after it has found the first (large) face.
    FaceDetector detector = new FaceDetector.Builder(context).setLandmarkType(FaceDetector.ALL_LANDMARKS).setClassificationType(FaceDetector.ALL_CLASSIFICATIONS).setTrackingEnabled(true).setMode(FaceDetector.FAST_MODE).setProminentFaceOnly(mIsFrontFacing).setMinFaceSize(mIsFrontFacing ? 0.35f : 0.15f).build();
    Detector.Processor<Face> processor;
    if (mIsFrontFacing) {
        // For front facing mode, a single tracker instance is used with an associated focusing
        // processor.  This configuration allows the face detector to take some shortcuts to
        // speed up detection, in that it can quit after finding a single face and can assume
        // that the nextIrisPosition face position is usually relatively close to the last seen
        // face position.
        Tracker<Face> tracker = new GooglyFaceTracker(mGraphicOverlay);
        processor = new LargestFaceFocusingProcessor.Builder(detector, tracker).build();
    } else {
        // For rear facing mode, a factory is used to create per-face tracker instances.  A
        // tracker is created for each face and is maintained as long as the same face is
        // visible, enabling per-face state to be maintained over time.  This is used to store
        // the iris position and velocity for each face independently, simulating the motion of
        // the eyes of any number of faces over time.
        //
        // Both the front facing mode and the rear facing mode use the same tracker
        // implementation, avoiding the need for any additional code.  The only difference
        // between these cases is the choice of Processor: one that is specialized for tracking
        // a single face or one that can handle multiple faces.  Here, we use MultiProcessor,
        // which is a standard component of the mobile vision API for managing multiple items.
        MultiProcessor.Factory<Face> factory = new MultiProcessor.Factory<Face>() {

            @Override
            public Tracker<Face> create(Face face) {
                return new GooglyFaceTracker(mGraphicOverlay);
            }
        };
        processor = new MultiProcessor.Builder<>(factory).build();
    }
    detector.setProcessor(processor);
    if (!detector.isOperational()) {
        // Note: The first time that an app using face API is installed on a device, GMS will
        // download a native library to the device in order to do detection.  Usually this
        // completes before the app is run for the first time.  But if that download has not yet
        // completed, then the above call will not detect any faces.
        //
        // isOperational() can be used to check if the required native library is currently
        // available.  The detector will automatically become operational once the library
        // download completes on device.
        Log.w(TAG, "Face detector dependencies are not yet available.");
        // Check for low storage.  If there is low storage, the native library will not be
        // downloaded, so detection will not become operational.
        IntentFilter lowStorageFilter = new IntentFilter(Intent.ACTION_DEVICE_STORAGE_LOW);
        boolean hasLowStorage = registerReceiver(null, lowStorageFilter) != null;
        if (hasLowStorage) {
            Toast.makeText(this, R.string.low_storage_error, Toast.LENGTH_LONG).show();
            Log.w(TAG, getString(R.string.low_storage_error));
        }
    }
    return detector;
}
Also used : IntentFilter(android.content.IntentFilter) MultiProcessor(com.google.android.gms.vision.MultiProcessor) FaceDetector(com.google.android.gms.vision.face.FaceDetector) Detector(com.google.android.gms.vision.Detector) FaceDetector(com.google.android.gms.vision.face.FaceDetector) Face(com.google.android.gms.vision.face.Face) NonNull(android.support.annotation.NonNull)

Aggregations

NonNull (android.support.annotation.NonNull)747 View (android.view.View)94 TextView (android.widget.TextView)90 ArrayList (java.util.ArrayList)83 Intent (android.content.Intent)53 ContentValues (android.content.ContentValues)46 Bundle (android.os.Bundle)46 Test (org.junit.Test)45 AlertDialog (android.support.v7.app.AlertDialog)41 Cursor (android.database.Cursor)38 List (java.util.List)34 IOException (java.io.IOException)32 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)31 LayoutInflater (android.view.LayoutInflater)29 RecyclerView (android.support.v7.widget.RecyclerView)28 ImageView (android.widget.ImageView)28 File (java.io.File)28 DialogAction (com.afollestad.materialdialogs.DialogAction)25 HashMap (java.util.HashMap)25 Bitmap (android.graphics.Bitmap)24