Search in sources :

Example 61 with Message

use of android.os.Message in project android_frameworks_base by ParanoidAndroid.

the class LoaderTestCase method getLoaderResultSynchronously.

/**
     * Runs a Loader synchronously and returns the result of the load. The loader will
     * be started, stopped, and destroyed by this method so it cannot be reused.
     *
     * @param loader The loader to run synchronously
     * @return The result from the loader
     */
public <T> T getLoaderResultSynchronously(final Loader<T> loader) {
    // The test thread blocks on this queue until the loader puts it's result in
    final ArrayBlockingQueue<T> queue = new ArrayBlockingQueue<T>(1);
    // This callback runs on the "main" thread and unblocks the test thread
    // when it puts the result into the blocking queue
    final OnLoadCompleteListener<T> listener = new OnLoadCompleteListener<T>() {

        @Override
        public void onLoadComplete(Loader<T> completedLoader, T data) {
            // Shut the loader down
            completedLoader.unregisterListener(this);
            completedLoader.stopLoading();
            completedLoader.reset();
            // Store the result, unblocking the test thread
            queue.add(data);
        }
    };
    // This handler runs on the "main" thread of the process since AsyncTask
    // is documented as needing to run on the main thread and many Loaders use
    // AsyncTask
    final Handler mainThreadHandler = new Handler(Looper.getMainLooper()) {

        @Override
        public void handleMessage(Message msg) {
            loader.registerListener(0, listener);
            loader.startLoading();
        }
    };
    // Ask the main thread to start the loading process
    mainThreadHandler.sendEmptyMessage(0);
    // Block on the queue waiting for the result of the load to be inserted
    T result;
    while (true) {
        try {
            result = queue.take();
            break;
        } catch (InterruptedException e) {
            throw new RuntimeException("waiting thread interrupted", e);
        }
    }
    return result;
}
Also used : ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) Message(android.os.Message) OnLoadCompleteListener(android.content.Loader.OnLoadCompleteListener) Loader(android.content.Loader) Handler(android.os.Handler)

Example 62 with Message

use of android.os.Message in project android_frameworks_base by ParanoidAndroid.

the class PowerMeasurement method testPageLoadStaticNYTimes.

public void testPageLoadStaticNYTimes() throws Throwable {
    Instrumentation mInst = getInstrumentation();
    PowerTestActivity act = getActivity();
    Intent intent = new Intent(mInst.getContext(), PowerTestActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    long start = System.currentTimeMillis();
    PowerTestActivity activity = (PowerTestActivity) mInst.startActivitySync(intent);
    activity.reset();
    //send a message with the new URL
    Handler handler = activity.getHandler();
    Message msg = handler.obtainMessage(PowerTestActivity.MSG_NAVIGATE, TIME_OUT, DELAY);
    msg.getData().putString(PowerTestActivity.MSG_NAV_URL, TESTING_URL);
    msg.getData().putBoolean(PowerTestActivity.MSG_NAV_LOGTIME, true);
    handler.sendMessage(msg);
    boolean timeoutFlag = activity.waitUntilDone();
    long end = System.currentTimeMillis();
    assertFalse(TESTING_URL + " failed to load", timeoutFlag);
    boolean pageErrorFlag = activity.getPageError();
    assertFalse(TESTING_URL + " is not available, either network is down or the server is down", pageErrorFlag);
    Log.v(LOGTAG, "Page is loaded in " + activity.getPageLoadTime() + " ms.");
    // Force to clean up the cache dir so that it get back to the clean
    // state
    Runtime fileRemoval = Runtime.getRuntime();
    String cmdBecomeSu = "su";
    boolean clearCacheSuccess = false;
    try {
        Process runsum = fileRemoval.exec(cmdBecomeSu);
        int exitVal = runsum.waitFor();
        String rmfile = "rm -r /data/data/com.android.browserpowertest/cache";
        Process removal = fileRemoval.exec(rmfile);
        exitVal = removal.waitFor();
        if (exitVal == 0) {
            clearCacheSuccess = true;
        }
    } catch (Exception e) {
        assertTrue("Fails to clear the cahche", false);
    }
    assertTrue("Fails to clear the cahche", clearCacheSuccess);
    activity.finish();
}
Also used : Message(android.os.Message) Instrumentation(android.app.Instrumentation) Handler(android.os.Handler) Intent(android.content.Intent)

Example 63 with Message

use of android.os.Message in project android_frameworks_base by ParanoidAndroid.

the class PowerTestActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Log.v(LOGTAG, "onCreate, inst=" + Integer.toHexString(hashCode()));
    LinearLayout contentView = new LinearLayout(this);
    contentView.setOrientation(LinearLayout.VERTICAL);
    setContentView(contentView);
    setTitle("Idle");
    webView = new WebView(this);
    webView.getSettings().setJavaScriptEnabled(true);
    webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(false);
    webView.getSettings().setLayoutAlgorithm(LayoutAlgorithm.NORMAL);
    webViewClient = new SimpleWebViewClient();
    chromeClient = new SimpleChromeClient();
    webView.setWebViewClient(webViewClient);
    webView.setWebChromeClient(chromeClient);
    contentView.addView(webView, new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, 0.0f));
    handler = new Handler() {

        @Override
        public void handleMessage(Message msg) {
            switch(msg.what) {
                case MSG_TIMEOUT:
                    handleTimeout();
                    return;
                case MSG_NAVIGATE:
                    manualDelay = msg.arg2;
                    navigate(msg.getData().getString(MSG_NAV_URL), msg.arg1);
                    logTime = msg.getData().getBoolean(MSG_NAV_LOGTIME);
                    return;
            }
        }
    };
    pageDoneLock = new Object();
}
Also used : LayoutParams(android.widget.LinearLayout.LayoutParams) Message(android.os.Message) Handler(android.os.Handler) WebView(android.webkit.WebView) LinearLayout(android.widget.LinearLayout)

Example 64 with Message

use of android.os.Message in project android_frameworks_base by ParanoidAndroid.

the class ReliabilityTestActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Log.v(LOGTAG, "onCreate, inst=" + Integer.toHexString(hashCode()));
    LinearLayout contentView = new LinearLayout(this);
    contentView.setOrientation(LinearLayout.VERTICAL);
    setContentView(contentView);
    setTitle("Idle");
    webView = new WebView(this);
    webView.getSettings().setJavaScriptEnabled(true);
    webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(false);
    webView.getSettings().setLayoutAlgorithm(LayoutAlgorithm.NORMAL);
    webViewClient = new SimpleWebViewClient();
    chromeClient = new SimpleChromeClient();
    webView.setWebViewClient(webViewClient);
    webView.setWebChromeClient(chromeClient);
    contentView.addView(webView, new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, 0.0f));
    handler = new Handler() {

        @Override
        public void handleMessage(Message msg) {
            switch(msg.what) {
                case MSG_TIMEOUT:
                    handleTimeout();
                    return;
                case MSG_NAVIGATE:
                    manualDelay = msg.arg2;
                    navigate(msg.getData().getString(MSG_NAV_URL), msg.arg1);
                    logTime = msg.getData().getBoolean(MSG_NAV_LOGTIME);
                    return;
            }
        }
    };
    pageDoneLock = new Object();
}
Also used : LayoutParams(android.widget.LinearLayout.LayoutParams) Message(android.os.Message) SslErrorHandler(android.webkit.SslErrorHandler) Handler(android.os.Handler) HttpAuthHandler(android.webkit.HttpAuthHandler) WebView(android.webkit.WebView) LinearLayout(android.widget.LinearLayout)

Example 65 with Message

use of android.os.Message in project android_frameworks_base by ParanoidAndroid.

the class DirListActivity method showDir.

/**
     * Loads the contents of dir into the list view.
     *
     * @param dirPath
     *      directory to load into list view
     */
private void showDir(String dirPath) {
    mCurrentDirPath = dirPath;
    /** Show progress dialog with a delay */
    final Handler delayedDialogHandler = new Handler() {

        @Override
        public void handleMessage(Message msg) {
            if (msg.what == MSG_SHOW_PROGRESS_DIALOG) {
                if (sProgressDialog == null) {
                    sProgressDialog = new ProgressDialog(DirListActivity.this);
                    sProgressDialog.setCancelable(false);
                    sProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
                    sProgressDialog.setTitle(R.string.dialog_progress_title);
                    sProgressDialog.setMessage(getText(R.string.dialog_progress_msg));
                }
                sProgressDialog.show();
            }
        }
    };
    Message msgShowDialog = delayedDialogHandler.obtainMessage(MSG_SHOW_PROGRESS_DIALOG);
    delayedDialogHandler.sendMessageDelayed(msgShowDialog, PROGRESS_DIALOG_DELAY_MS);
    /** Delegate loading contents from SD card to a new thread */
    new LoadListItemsThread(mCurrentDirPath, new Handler() {

        @Override
        public void handleMessage(Message msg) {
            if (msg.what == MSG_LOADED_ITEMS) {
                setTitle(shortenTitle(mCurrentDirPath));
                delayedDialogHandler.removeMessages(MSG_SHOW_PROGRESS_DIALOG);
                if (sProgressDialog != null) {
                    sProgressDialog.dismiss();
                }
                if (msg.obj == null) {
                    Toast.makeText(DirListActivity.this, NO_RESPONSE_MESSAGE, Toast.LENGTH_LONG).show();
                } else {
                    setListAdapter(new DirListAdapter(DirListActivity.this, (ListItem[]) msg.obj));
                }
            }
        }
    }).start();
}
Also used : Message(android.os.Message) Handler(android.os.Handler) ProgressDialog(android.app.ProgressDialog)

Aggregations

Message (android.os.Message)3198 Handler (android.os.Handler)347 RemoteException (android.os.RemoteException)263 Bundle (android.os.Bundle)210 Test (org.junit.Test)144 Intent (android.content.Intent)130 IOException (java.io.IOException)124 Point (android.graphics.Point)86 HashMap (java.util.HashMap)77 SomeArgs (com.android.internal.os.SomeArgs)67 SmallTest (android.test.suitebuilder.annotation.SmallTest)64 Messenger (android.os.Messenger)63 ArrayList (java.util.ArrayList)59 View (android.view.View)52 File (java.io.File)50 MediumTest (android.test.suitebuilder.annotation.MediumTest)43 TextView (android.widget.TextView)41 IBinder (android.os.IBinder)38 Map (java.util.Map)37 PendingIntent (android.app.PendingIntent)33