Search in sources :

Example 81 with HandlerThread

use of android.os.HandlerThread in project android_frameworks_base by ResurrectionRemix.

the class CameraTooActivity method onResume.

/**
     * Called when our {@code Activity} gains focus. <p>Starts initializing the camera.</p>
     */
@Override
protected void onResume() {
    super.onResume();
    // Start a background thread to manage camera requests
    mBackgroundThread = new HandlerThread("background");
    mBackgroundThread.start();
    mBackgroundHandler = new Handler(mBackgroundThread.getLooper());
    mForegroundHandler = new Handler(getMainLooper());
    mCameraManager = (CameraManager) getSystemService(CAMERA_SERVICE);
    // Inflate the SurfaceView, set it as the main layout, and attach a listener
    View layout = getLayoutInflater().inflate(R.layout.mainactivity, null);
    mSurfaceView = (SurfaceView) layout.findViewById(R.id.mainSurfaceView);
    mSurfaceView.getHolder().addCallback(mSurfaceHolderCallback);
    setContentView(mSurfaceView);
// Control flow continues in mSurfaceHolderCallback.surfaceChanged()
}
Also used : HandlerThread(android.os.HandlerThread) Handler(android.os.Handler) SurfaceView(android.view.SurfaceView) View(android.view.View)

Example 82 with HandlerThread

use of android.os.HandlerThread in project android_frameworks_base by ResurrectionRemix.

the class MffTestCase method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    // MffContext needs to be created on a separate thread to allow MFF to post Runnable's.
    mMffContextHandlerThread = new HandlerThread("MffContextThread");
    mMffContextHandlerThread.start();
    Handler handler = new Handler(mMffContextHandlerThread.getLooper());
    FutureTask<MffContext> task = new FutureTask<MffContext>(new Callable<MffContext>() {

        @Override
        public MffContext call() throws Exception {
            MffContext.Config config = new MffContext.Config();
            config.requireCamera = false;
            config.requireOpenGL = false;
            config.forceNoGL = true;
            return new MffContext(getContext(), config);
        }
    });
    handler.post(task);
    // Wait for the context to be created on the handler thread.
    mMffContext = task.get();
}
Also used : HandlerThread(android.os.HandlerThread) FutureTask(java.util.concurrent.FutureTask) Handler(android.os.Handler)

Example 83 with HandlerThread

use of android.os.HandlerThread in project android_frameworks_base by ResurrectionRemix.

the class ConnectivityServiceTest method testMobileDataAlwaysOn.

@SmallTest
public void testMobileDataAlwaysOn() throws Exception {
    final TestNetworkCallback cellNetworkCallback = new TestNetworkCallback();
    final NetworkRequest cellRequest = new NetworkRequest.Builder().addTransportType(TRANSPORT_CELLULAR).build();
    mCm.registerNetworkCallback(cellRequest, cellNetworkCallback);
    final HandlerThread handlerThread = new HandlerThread("MobileDataAlwaysOnFactory");
    handlerThread.start();
    NetworkCapabilities filter = new NetworkCapabilities().addTransportType(TRANSPORT_CELLULAR).addCapability(NET_CAPABILITY_INTERNET);
    final MockNetworkFactory testFactory = new MockNetworkFactory(handlerThread.getLooper(), mServiceContext, "testFactory", filter);
    testFactory.setScoreFilter(40);
    // Register the factory and expect it to start looking for a network.
    testFactory.expectAddRequests(1);
    testFactory.register();
    testFactory.waitForNetworkRequests(1);
    assertTrue(testFactory.getMyStartRequested());
    // Bring up wifi. The factory stops looking for a network.
    mWiFiNetworkAgent = new MockNetworkAgent(TRANSPORT_WIFI);
    // Because the default request changes score twice.
    testFactory.expectAddRequests(2);
    mWiFiNetworkAgent.connect(true);
    testFactory.waitForNetworkRequests(1);
    assertFalse(testFactory.getMyStartRequested());
    ContentResolver cr = mServiceContext.getContentResolver();
    // Turn on mobile data always on. The factory starts looking again.
    testFactory.expectAddRequests(1);
    setMobileDataAlwaysOn(true);
    testFactory.waitForNetworkRequests(2);
    assertTrue(testFactory.getMyStartRequested());
    // Bring up cell data and check that the factory stops looking.
    assertEquals(1, mCm.getAllNetworks().length);
    mCellNetworkAgent = new MockNetworkAgent(TRANSPORT_CELLULAR);
    // Because the cell request changes score twice.
    testFactory.expectAddRequests(2);
    mCellNetworkAgent.connect(true);
    cellNetworkCallback.expectCallback(CallbackState.AVAILABLE, mCellNetworkAgent);
    testFactory.waitForNetworkRequests(2);
    // Because the cell network outscores us.
    assertFalse(testFactory.getMyStartRequested());
    // Check that cell data stays up.
    mService.waitForIdle();
    verifyActiveNetwork(TRANSPORT_WIFI);
    assertEquals(2, mCm.getAllNetworks().length);
    // Turn off mobile data always on and expect the request to disappear...
    testFactory.expectRemoveRequests(1);
    setMobileDataAlwaysOn(false);
    testFactory.waitForNetworkRequests(1);
    // ...  and cell data to be torn down.
    cellNetworkCallback.expectCallback(CallbackState.LOST, mCellNetworkAgent);
    assertEquals(1, mCm.getAllNetworks().length);
    testFactory.unregister();
    mCm.unregisterNetworkCallback(cellNetworkCallback);
    handlerThread.quit();
}
Also used : HandlerThread(android.os.HandlerThread) NetworkRequest(android.net.NetworkRequest) NetworkCapabilities(android.net.NetworkCapabilities) ContentResolver(android.content.ContentResolver) MockContentResolver(android.test.mock.MockContentResolver) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 84 with HandlerThread

use of android.os.HandlerThread in project android_frameworks_base by ResurrectionRemix.

the class Filter method filter.

/**
     * <p>Starts an asynchronous filtering operation. Calling this method
     * cancels all previous non-executed filtering requests and posts a new
     * filtering request that will be executed later.</p>
     *
     * <p>Upon completion, the listener is notified.</p>
     *
     * @param constraint the constraint used to filter the data
     * @param listener a listener notified upon completion of the operation
     *
     * @see #filter(CharSequence)
     * @see #performFiltering(CharSequence)
     * @see #publishResults(CharSequence, android.widget.Filter.FilterResults)
     */
public final void filter(CharSequence constraint, FilterListener listener) {
    synchronized (mLock) {
        if (mThreadHandler == null) {
            HandlerThread thread = new HandlerThread(THREAD_NAME, android.os.Process.THREAD_PRIORITY_BACKGROUND);
            thread.start();
            mThreadHandler = new RequestHandler(thread.getLooper());
        }
        final long delay = (mDelayer == null) ? 0 : mDelayer.getPostingDelay(constraint);
        Message message = mThreadHandler.obtainMessage(FILTER_TOKEN);
        RequestArguments args = new RequestArguments();
        // make sure we use an immutable copy of the constraint, so that
        // it doesn't change while the filter operation is in progress
        args.constraint = constraint != null ? constraint.toString() : null;
        args.listener = listener;
        message.obj = args;
        mThreadHandler.removeMessages(FILTER_TOKEN);
        mThreadHandler.removeMessages(FINISH_TOKEN);
        mThreadHandler.sendMessageDelayed(message, delay);
    }
}
Also used : HandlerThread(android.os.HandlerThread) Message(android.os.Message)

Example 85 with HandlerThread

use of android.os.HandlerThread in project Bitocle by mthli.

the class LoginActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.login);
    /*
         * 检测用户登陆状态
         *
         * 如果SharedPreferences中存在用户信息,
         * 则说明用户已经登陆,此时直接跳转到MainActivity即可;
         * 否则进入登陆界面
         */
    sharedPreferences = getSharedPreferences(getString(R.string.login_sp), MODE_PRIVATE);
    String oAuth = sharedPreferences.getString(getString(R.string.login_sp_oauth), null);
    if (oAuth != null) {
        Intent intent = new Intent(LoginActivity.this, MainActivity.class);
        intent.putExtra(getString(R.string.login_intent), false);
        startActivity(intent);
        finish();
    }
    getActionBar().setDisplayShowHomeEnabled(false);
    final EditText userText = (EditText) findViewById(R.id.login_username);
    final EditText passText = (EditText) findViewById(R.id.login_password);
    /* 保持EditText字体的一致性 */
    passText.setTypeface(Typeface.DEFAULT);
    passText.setTransformationMethod(new PasswordTransformationMethod());
    Button button = (Button) findViewById(R.id.login_button);
    button.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            username = userText.getText().toString();
            password = passText.getText().toString();
            /* 给出相应的错误提示 */
            if (username.length() == 0 && password.length() == 0) {
                SuperToast.create(LoginActivity.this, getString(R.string.login_message_miss_both), SuperToast.Duration.SHORT, Style.getStyle(Style.RED)).show();
            } else if (username.length() != 0 && password.length() == 0) {
                SuperToast.create(LoginActivity.this, getString(R.string.login_message_miss_password), SuperToast.Duration.SHORT, Style.getStyle(Style.RED)).show();
            } else if (username.length() == 0 && password.length() != 0) {
                SuperToast.create(LoginActivity.this, getString(R.string.login_message_miss_username), SuperToast.Duration.SHORT, Style.getStyle(Style.RED)).show();
            } else {
                /* ProgressDialog显示当前正在运行的状态 */
                progressDialog = new ProgressDialog(LoginActivity.this);
                progressDialog.setMessage(getString(R.string.login_message_authoring));
                progressDialog.setCancelable(false);
                progressDialog.show();
                /* 开启新的线程用于认证 */
                HandlerThread handlerThread = new HandlerThread(getString(R.string.login_thread));
                handlerThread.start();
                Handler handler = new Handler(handlerThread.getLooper());
                handler.post(authorizationThread);
            }
        }
    });
}
Also used : EditText(android.widget.EditText) PasswordTransformationMethod(android.text.method.PasswordTransformationMethod) HandlerThread(android.os.HandlerThread) Button(android.widget.Button) Handler(android.os.Handler) Intent(android.content.Intent) ProgressDialog(android.app.ProgressDialog) View(android.view.View) WebView(android.webkit.WebView)

Aggregations

HandlerThread (android.os.HandlerThread)313 Handler (android.os.Handler)149 IntentFilter (android.content.IntentFilter)34 Message (android.os.Message)26 PowerManager (android.os.PowerManager)26 Intent (android.content.Intent)25 Context (android.content.Context)22 Test (org.junit.Test)20 Runnable (java.lang.Runnable)15 ComponentName (android.content.ComponentName)14 View (android.view.View)14 Looper (android.os.Looper)13 PendingIntent (android.app.PendingIntent)12 MediumTest (android.test.suitebuilder.annotation.MediumTest)12 RemoteException (android.os.RemoteException)11 MediaFormat (android.media.MediaFormat)10 Uri (android.net.Uri)10 Pair (android.util.Pair)10 SmallTest (android.test.suitebuilder.annotation.SmallTest)9 Bundle (android.os.Bundle)8