Search in sources :

Example 26 with Observable

use of java.util.Observable in project android_frameworks_base by ParanoidAndroid.

the class ContentQueryMapTest method testContentQueryMap.

@MediumTest
public void testContentQueryMap() throws Throwable {
    LooperThread thread = new LooperThread() {

        void go() {
            ContentResolver r = getContext().getContentResolver();
            Settings.System.putString(r, "test", "Value");
            Cursor cursor = r.query(Settings.System.CONTENT_URI, new String[] { Settings.System.NAME, Settings.System.VALUE }, null, null, null);
            final ContentQueryMap cqm = new ContentQueryMap(cursor, Settings.System.NAME, true, null);
            // Get the current state of the CQM. This forces a requery and means that the
            // call to getValues() below won't do a requery().
            cqm.getRows();
            // The cache won't notice changes until the loop runs.
            Settings.System.putString(r, "test", "New Value");
            ContentValues v = cqm.getValues("test");
            String value = v.getAsString(Settings.System.VALUE);
            assertEquals("Value", value);
            // Use an Observer to find out when the cache does update.
            cqm.addObserver(new Observer() {

                public void update(Observable o, Object arg) {
                    // Should have the new values by now.
                    ContentValues v = cqm.getValues("test");
                    String value = v.getAsString(Settings.System.VALUE);
                    assertEquals("New Value", value);
                    Looper.myLooper().quit();
                    cqm.close();
                    mSuccess = true;
                }
            });
            // Give up after a few seconds, if it doesn't.
            new Handler().postDelayed(new Runnable() {

                public void run() {
                    fail("Timed out");
                }
            }, 5000);
        }
    };
    thread.start();
    thread.join();
    if (thread.mError != null)
        throw thread.mError;
    assertTrue(thread.mSuccess);
}
Also used : ContentValues(android.content.ContentValues) ContentQueryMap(android.content.ContentQueryMap) Observer(java.util.Observer) Handler(android.os.Handler) Cursor(android.database.Cursor) Observable(java.util.Observable) ContentResolver(android.content.ContentResolver) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Example 27 with Observable

use of java.util.Observable in project platform_frameworks_base by android.

the class ContentQueryMapTest method testContentQueryMap.

@MediumTest
public void testContentQueryMap() throws Throwable {
    LooperThread thread = new LooperThread() {

        void go() {
            ContentResolver r = getContext().getContentResolver();
            Settings.System.putString(r, "test", "Value");
            Cursor cursor = r.query(Settings.System.CONTENT_URI, new String[] { Settings.System.NAME, Settings.System.VALUE }, null, null, null);
            final ContentQueryMap cqm = new ContentQueryMap(cursor, Settings.System.NAME, true, null);
            // Get the current state of the CQM. This forces a requery and means that the
            // call to getValues() below won't do a requery().
            cqm.getRows();
            // The cache won't notice changes until the loop runs.
            Settings.System.putString(r, "test", "New Value");
            ContentValues v = cqm.getValues("test");
            String value = v.getAsString(Settings.System.VALUE);
            assertEquals("Value", value);
            // Use an Observer to find out when the cache does update.
            cqm.addObserver(new Observer() {

                public void update(Observable o, Object arg) {
                    // Should have the new values by now.
                    ContentValues v = cqm.getValues("test");
                    String value = v.getAsString(Settings.System.VALUE);
                    assertEquals("New Value", value);
                    Looper.myLooper().quit();
                    cqm.close();
                    mSuccess = true;
                }
            });
            // Give up after a few seconds, if it doesn't.
            new Handler().postDelayed(new Runnable() {

                public void run() {
                    fail("Timed out");
                }
            }, 5000);
        }
    };
    thread.start();
    thread.join();
    if (thread.mError != null)
        throw thread.mError;
    assertTrue(thread.mSuccess);
}
Also used : ContentValues(android.content.ContentValues) ContentQueryMap(android.content.ContentQueryMap) Observer(java.util.Observer) Handler(android.os.Handler) Cursor(android.database.Cursor) Observable(java.util.Observable) ContentResolver(android.content.ContentResolver) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Example 28 with Observable

use of java.util.Observable in project android_frameworks_base by AOSPA.

the class ContentQueryMapTest method testContentQueryMap.

@MediumTest
public void testContentQueryMap() throws Throwable {
    LooperThread thread = new LooperThread() {

        void go() {
            ContentResolver r = getContext().getContentResolver();
            Settings.System.putString(r, "test", "Value");
            Cursor cursor = r.query(Settings.System.CONTENT_URI, new String[] { Settings.System.NAME, Settings.System.VALUE }, null, null, null);
            final ContentQueryMap cqm = new ContentQueryMap(cursor, Settings.System.NAME, true, null);
            // Get the current state of the CQM. This forces a requery and means that the
            // call to getValues() below won't do a requery().
            cqm.getRows();
            // The cache won't notice changes until the loop runs.
            Settings.System.putString(r, "test", "New Value");
            ContentValues v = cqm.getValues("test");
            String value = v.getAsString(Settings.System.VALUE);
            assertEquals("Value", value);
            // Use an Observer to find out when the cache does update.
            cqm.addObserver(new Observer() {

                public void update(Observable o, Object arg) {
                    // Should have the new values by now.
                    ContentValues v = cqm.getValues("test");
                    String value = v.getAsString(Settings.System.VALUE);
                    assertEquals("New Value", value);
                    Looper.myLooper().quit();
                    cqm.close();
                    mSuccess = true;
                }
            });
            // Give up after a few seconds, if it doesn't.
            new Handler().postDelayed(new Runnable() {

                public void run() {
                    fail("Timed out");
                }
            }, 5000);
        }
    };
    thread.start();
    thread.join();
    if (thread.mError != null)
        throw thread.mError;
    assertTrue(thread.mSuccess);
}
Also used : ContentValues(android.content.ContentValues) ContentQueryMap(android.content.ContentQueryMap) Observer(java.util.Observer) Handler(android.os.Handler) Cursor(android.database.Cursor) Observable(java.util.Observable) ContentResolver(android.content.ContentResolver) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Example 29 with Observable

use of java.util.Observable in project android_frameworks_base by ResurrectionRemix.

the class ContentQueryMapTest method testContentQueryMap.

@MediumTest
public void testContentQueryMap() throws Throwable {
    LooperThread thread = new LooperThread() {

        void go() {
            ContentResolver r = getContext().getContentResolver();
            Settings.System.putString(r, "test", "Value");
            Cursor cursor = r.query(Settings.System.CONTENT_URI, new String[] { Settings.System.NAME, Settings.System.VALUE }, null, null, null);
            final ContentQueryMap cqm = new ContentQueryMap(cursor, Settings.System.NAME, true, null);
            // Get the current state of the CQM. This forces a requery and means that the
            // call to getValues() below won't do a requery().
            cqm.getRows();
            // The cache won't notice changes until the loop runs.
            Settings.System.putString(r, "test", "New Value");
            ContentValues v = cqm.getValues("test");
            String value = v.getAsString(Settings.System.VALUE);
            assertEquals("Value", value);
            // Use an Observer to find out when the cache does update.
            cqm.addObserver(new Observer() {

                public void update(Observable o, Object arg) {
                    // Should have the new values by now.
                    ContentValues v = cqm.getValues("test");
                    String value = v.getAsString(Settings.System.VALUE);
                    assertEquals("New Value", value);
                    Looper.myLooper().quit();
                    cqm.close();
                    mSuccess = true;
                }
            });
            // Give up after a few seconds, if it doesn't.
            new Handler().postDelayed(new Runnable() {

                public void run() {
                    fail("Timed out");
                }
            }, 5000);
        }
    };
    thread.start();
    thread.join();
    if (thread.mError != null)
        throw thread.mError;
    assertTrue(thread.mSuccess);
}
Also used : ContentValues(android.content.ContentValues) ContentQueryMap(android.content.ContentQueryMap) Observer(java.util.Observer) Handler(android.os.Handler) Cursor(android.database.Cursor) Observable(java.util.Observable) ContentResolver(android.content.ContentResolver) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Example 30 with Observable

use of java.util.Observable in project AutoRefactor by JnRouvignac.

the class SetRatherThanListSample method refactorWithMethod.

public boolean refactorWithMethod() {
    // Keep this comment
    java.util.HashSet<Observable> collection = new java.util.HashSet<Observable>();
    // Keep this comment too
    collection.add(new Observable());
    return collection.contains(new Observable());
}
Also used : Observable(java.util.Observable)

Aggregations

Observable (java.util.Observable)50 Observer (java.util.Observer)28 Test (org.junit.Test)8 ContentQueryMap (android.content.ContentQueryMap)6 ContentResolver (android.content.ContentResolver)6 ContentValues (android.content.ContentValues)6 Cursor (android.database.Cursor)6 Handler (android.os.Handler)6 MediumTest (android.test.suitebuilder.annotation.MediumTest)6 CountDownLatch (java.util.concurrent.CountDownLatch)4 LinkedList (java.util.LinkedList)3 MessagePanel (edu.ucsf.rbvi.clusterMaker2.internal.treeview.MessagePanel)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 Properties (java.util.Properties)2 TreeMap (java.util.TreeMap)2 IJobChangeEvent (org.eclipse.core.runtime.jobs.IJobChangeEvent)2 IJobChangeListener (org.eclipse.core.runtime.jobs.IJobChangeListener)2 Job (org.eclipse.core.runtime.jobs.Job)2