Search in sources :

Example 31 with Vibrator

use of android.os.Vibrator in project Signal-Android by signalapp.

the class ConversationActivity method onRecorderCanceled.

@Override
public void onRecorderCanceled() {
    Vibrator vibrator = ServiceUtil.getVibrator(this);
    vibrator.vibrate(50);
    getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    ListenableFuture<Pair<Uri, Long>> future = audioRecorder.stopRecording();
    future.addListener(new ListenableFuture.Listener<Pair<Uri, Long>>() {

        @Override
        public void onSuccess(final Pair<Uri, Long> result) {
            new AsyncTask<Void, Void, Void>() {

                @Override
                protected Void doInBackground(Void... params) {
                    PersistentBlobProvider.getInstance(ConversationActivity.this).delete(ConversationActivity.this, result.first);
                    return null;
                }
            }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        }

        @Override
        public void onFailure(ExecutionException e) {
        }
    });
}
Also used : AsyncTask(android.os.AsyncTask) ListenableFuture(org.thoughtcrime.securesms.util.concurrent.ListenableFuture) Vibrator(android.os.Vibrator) ExecutionException(java.util.concurrent.ExecutionException) Uri(android.net.Uri) Pair(android.util.Pair)

Example 32 with Vibrator

use of android.os.Vibrator in project Signal-Android by signalapp.

the class ConversationActivity method onRecorderFinished.

@Override
public void onRecorderFinished() {
    Vibrator vibrator = ServiceUtil.getVibrator(this);
    vibrator.vibrate(20);
    getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    ListenableFuture<Pair<Uri, Long>> future = audioRecorder.stopRecording();
    future.addListener(new ListenableFuture.Listener<Pair<Uri, Long>>() {

        @Override
        public void onSuccess(@NonNull final Pair<Uri, Long> result) {
            boolean forceSms = sendButton.isManualSelection() && sendButton.getSelectedTransport().isSms();
            int subscriptionId = sendButton.getSelectedTransport().getSimSubscriptionId().or(-1);
            long expiresIn = recipient.getExpireMessages() * 1000L;
            boolean initiating = threadId == -1;
            AudioSlide audioSlide = new AudioSlide(ConversationActivity.this, result.first, result.second, MediaUtil.AUDIO_AAC, true);
            SlideDeck slideDeck = new SlideDeck();
            slideDeck.addSlide(audioSlide);
            sendMediaMessage(forceSms, "", slideDeck, expiresIn, subscriptionId, initiating).addListener(new AssertedSuccessListener<Void>() {

                @Override
                public void onSuccess(Void nothing) {
                    new AsyncTask<Void, Void, Void>() {

                        @Override
                        protected Void doInBackground(Void... params) {
                            PersistentBlobProvider.getInstance(ConversationActivity.this).delete(ConversationActivity.this, result.first);
                            return null;
                        }
                    }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
                }
            });
        }

        @Override
        public void onFailure(ExecutionException e) {
            Toast.makeText(ConversationActivity.this, R.string.ConversationActivity_unable_to_record_audio, Toast.LENGTH_LONG).show();
        }
    });
}
Also used : AudioSlide(org.thoughtcrime.securesms.mms.AudioSlide) SlideDeck(org.thoughtcrime.securesms.mms.SlideDeck) Uri(android.net.Uri) AssertedSuccessListener(org.thoughtcrime.securesms.util.concurrent.AssertedSuccessListener) ListenableFuture(org.thoughtcrime.securesms.util.concurrent.ListenableFuture) Vibrator(android.os.Vibrator) ExecutionException(java.util.concurrent.ExecutionException) Pair(android.util.Pair)

Example 33 with Vibrator

use of android.os.Vibrator in project xDrip-plus by jamorham.

the class NFCReaderX method vibrate.

public static void vibrate(Context context, int pattern) {
    // 0 = scanning
    // 1 = scan ok
    // 2 = warning
    // 3 = lesser error
    final long[][] patterns = { { 0, 150 }, { 0, 150, 70, 150 }, { 0, 2000 }, { 0, 1000 }, { 0, 100 } };
    if (Pref.getBooleanDefaultFalse("nfc_scan_vibrate")) {
        final Vibrator vibrate = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
        if ((vibrate == null) || (!vibrate.hasVibrator()))
            return;
        vibrate.cancel();
        if (d)
            Log.d(TAG, "About to vibrate, pattern: " + pattern);
        try {
            vibrate.vibrate(patterns[pattern], -1);
        } catch (Exception e) {
            Log.d(TAG, "Exception in vibrate: " + e);
        }
    }
}
Also used : Vibrator(android.os.Vibrator) IOException(java.io.IOException)

Example 34 with Vibrator

use of android.os.Vibrator in project AndroidChromium by JackyAndroid.

the class FindToolbar method onFindResult.

@Override
public void onFindResult(FindNotificationDetails result) {
    if (mResultBar != null)
        mResultBar.mWaitingForActivateAck = false;
    assert mFindInPageBridge != null;
    if ((result.activeMatchOrdinal == -1 || result.numberOfMatches == 1) && !result.finalUpdate) {
        // at the start (see below for why we can't filter them out).
        return;
    }
    if (result.finalUpdate) {
        if (result.numberOfMatches > 0) {
            // TODO(johnme): Don't wait till end of find, stream rects live!
            mFindInPageBridge.requestFindMatchRects(mResultBar != null ? mResultBar.mRectsVersion : -1);
        } else {
            clearResults();
        }
        findResultSelected(result.rendererSelectionRect);
    }
    // Even though we wait above until activeMatchOrdinal is no longer -1,
    // it's possible for it to still be -1 (unknown) in the final find
    // notification. This happens very rarely, e.g. if the m_activeMatch
    // found by WebFrameImpl::find has been removed from the DOM by the time
    // WebFrameImpl::scopeStringMatches tries to find the ordinal of the
    // active match (while counting the matches), as in b/4147049. In such
    // cases it looks less broken to show 0 instead of -1 (as desktop does).
    Context context = getContext();
    String text = context.getResources().getString(R.string.find_in_page_count, Math.max(result.activeMatchOrdinal, 0), result.numberOfMatches);
    setStatus(text, result.numberOfMatches == 0);
    // The accessible version will be something like "Result 1 of 9".
    String accessibleText = getAccessibleStatusText(Math.max(result.activeMatchOrdinal, 0), result.numberOfMatches);
    mFindStatus.setContentDescription(accessibleText);
    announceStatusForAccessibility(accessibleText);
    // Vibrate when no results are found, unless you're just deleting chars.
    if (result.numberOfMatches == 0 && result.finalUpdate && !mFindInPageBridge.getPreviousFindText().startsWith(mFindQuery.getText().toString())) {
        final boolean hapticFeedbackEnabled = Settings.System.getInt(context.getContentResolver(), Settings.System.HAPTIC_FEEDBACK_ENABLED, 1) == 1;
        if (hapticFeedbackEnabled) {
            Vibrator v = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
            final long noResultsVibrateDurationMs = 50;
            v.vibrate(noResultsVibrateDurationMs);
        }
    }
}
Also used : Context(android.content.Context) Vibrator(android.os.Vibrator)

Example 35 with Vibrator

use of android.os.Vibrator in project SmartMesh_Android by SmartMeshFoundation.

the class BeepManager method playBeepSoundAndVibrate.

public void playBeepSoundAndVibrate() {
    if (playBeep && mediaPlayer != null) {
        mediaPlayer.start();
    }
    if (vibrate) {
        Vibrator vibrator = (Vibrator) activity.getSystemService(Context.VIBRATOR_SERVICE);
        vibrator.vibrate(VIBRATE_DURATION);
    }
}
Also used : Vibrator(android.os.Vibrator)

Aggregations

Vibrator (android.os.Vibrator)159 Intent (android.content.Intent)15 IOException (java.io.IOException)14 Uri (android.net.Uri)12 Context (android.content.Context)10 Handler (android.os.Handler)10 View (android.view.View)10 NotificationManager (android.app.NotificationManager)8 RemoteException (android.os.RemoteException)8 ImageView (android.widget.ImageView)8 AudioManager (android.media.AudioManager)7 SettingNotFoundException (android.provider.Settings.SettingNotFoundException)6 InputDevice (android.view.InputDevice)6 TextView (android.widget.TextView)6 Activity (android.app.Activity)5 Bitmap (android.graphics.Bitmap)5 FileOutputStream (java.io.FileOutputStream)5 ExecutionException (java.util.concurrent.ExecutionException)5 ListenableFuture (org.thoughtcrime.securesms.util.concurrent.ListenableFuture)5 SuppressLint (android.annotation.SuppressLint)4