Search in sources :

Example 61 with Vibrator

use of android.os.Vibrator in project LuaViewSDK by alibaba.

the class UDVibrator method vibrate.

/**
     * 震动
     *
     * @param patternTable
     * @param repeat
     * @return
     */
public UDVibrator vibrate(final LuaTable patternTable, final Integer repeat) {
    if (patternTable != null) {
        final Vibrator vibrator = getVibrator();
        if (vibrator != null) {
            if (patternTable.length() > 1) {
                long[] pattern = new long[patternTable.length()];
                for (int i = 0; i < patternTable.length(); i++) {
                    pattern[i] = (long) (patternTable.get((i + 1)).optdouble(1) * 1000);
                }
                vibrator.vibrate(pattern, repeat);
            } else {
                vibrator.vibrate((long) (patternTable.get(1).optdouble(1) * 1000));
            }
        }
    }
    return this;
}
Also used : Vibrator(android.os.Vibrator)

Example 62 with Vibrator

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

the class ConversationActivity method onRecorderFinished.

@Override
public void onRecorderFinished() {
    Vibrator vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
    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) {
            try {
                boolean forceSms = sendButton.isManualSelection() && sendButton.getSelectedTransport().isSms();
                int subscriptionId = sendButton.getSelectedTransport().getSimSubscriptionId().or(-1);
                long expiresIn = recipients.getExpireMessages() * 1000;
                AudioSlide audioSlide = new AudioSlide(ConversationActivity.this, result.first, result.second, ContentType.AUDIO_AAC);
                SlideDeck slideDeck = new SlideDeck();
                slideDeck.addSlide(audioSlide);
                sendMediaMessage(forceSms, "", slideDeck, expiresIn, subscriptionId).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(result.first);
                                return null;
                            }
                        }.execute();
                    }
                });
            } catch (InvalidMessageException e) {
                Log.w(TAG, e);
                Toast.makeText(ConversationActivity.this, R.string.ConversationActivity_error_sending_voice_message, Toast.LENGTH_LONG).show();
            }
        }

        @Override
        public void onFailure(ExecutionException e) {
            Toast.makeText(ConversationActivity.this, R.string.ConversationActivity_unable_to_record_audio, Toast.LENGTH_LONG).show();
        }
    });
}
Also used : InvalidMessageException(org.whispersystems.libsignal.InvalidMessageException) 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 63 with Vibrator

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

the class ConversationActivity method onRecorderStarted.

@Override
public void onRecorderStarted() {
    Vibrator vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
    vibrator.vibrate(20);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    audioRecorder.startRecording();
}
Also used : Vibrator(android.os.Vibrator)

Example 64 with Vibrator

use of android.os.Vibrator in project Carbon by ZieIony.

the class PowerMenuActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_powermenu);
    powerMenu = findViewById(R.id.powerMenu);
    final FrameLayout transitionLayout = (FrameLayout) findViewById(R.id.transition);
    findViewById(R.id.button).setOnClickListener(view -> {
        if (powerMenu.getVisibility() == View.VISIBLE)
            return;
        for (int i = 0; i < transitionLayout.getChildCount(); i++) transitionLayout.getChildAt(i).setVisibility(i == 0 ? View.VISIBLE : View.GONE);
        final List<View> viewsWithTag = ((LinearLayout) transitionLayout.getChildAt(0)).findViewsWithTag("animate");
        Stream.of(viewsWithTag).forEach(v -> v.setVisibility(View.INVISIBLE));
        powerMenu.setVisibility(View.VISIBLE);
        view.getHandler().postDelayed(() -> {
            Stream.of(viewsWithTag).forEach(v -> {
                v.getHandler().postDelayed(() -> {
                    v.setVisibility(View.VISIBLE);
                }, viewsWithTag.indexOf(v) * 40);
            });
        }, 200);
    });
    findViewById(R.id.powerOff).setOnClickListener(view -> {
        final List<View> viewsWithTag = ((FrameLayout) transitionLayout.getChildAt(1)).findViewsWithTag("animate");
        for (int i = 0; i < viewsWithTag.size(); i++) viewsWithTag.get(i).setVisibility(View.INVISIBLE);
        view.getHandler().postDelayed(() -> {
            for (int i = 0; i < viewsWithTag.size(); i++) {
                final int finalI = i;
                view.getHandler().postDelayed(() -> viewsWithTag.get(finalI).setVisibility(View.VISIBLE), i * 20);
            }
        }, 400);
        view.getHandler().postDelayed(() -> powerMenu.setVisibility(View.INVISIBLE), 3000);
    });
    findViewById(R.id.reboot).setOnClickListener(view -> {
        final List<View> viewsWithTag = ((FrameLayout) transitionLayout.getChildAt(2)).findViewsWithTag("animate");
        for (int i = 0; i < viewsWithTag.size(); i++) viewsWithTag.get(i).setVisibility(View.INVISIBLE);
        view.getHandler().postDelayed(() -> {
            for (int i = 0; i < viewsWithTag.size(); i++) {
                final int finalI = i;
                view.getHandler().postDelayed(() -> viewsWithTag.get(finalI).setVisibility(View.VISIBLE), i * 20);
            }
        }, 400);
        view.getHandler().postDelayed(() -> powerMenu.setVisibility(View.INVISIBLE), 3000);
    });
    findViewById(R.id.airplaneMode).setOnClickListener(view -> {
        final List<View> viewsWithTag = ((FrameLayout) transitionLayout.getChildAt(3)).findViewsWithTag("animate");
        for (int i = 0; i < viewsWithTag.size(); i++) viewsWithTag.get(i).setVisibility(View.INVISIBLE);
        view.getHandler().postDelayed(() -> {
            for (int i = 0; i < viewsWithTag.size(); i++) {
                final int finalI = i;
                view.getHandler().postDelayed(() -> viewsWithTag.get(finalI).setVisibility(View.VISIBLE), i * 20);
            }
        }, 400);
        view.getHandler().postDelayed(() -> {
            airplaneMode = !airplaneMode;
            TextView amStatus = (TextView) findViewById(R.id.airplaneModeStatus);
            amStatus.setText("Airplane Mode is " + (airplaneMode ? "on" : "off"));
            ImageView airplaneModeIcon = (ImageView) view.findViewById(R.id.airplaneModeIcon);
            airplaneModeIcon.setImageResource(airplaneMode ? R.raw.ic_airplanemode_on_24px : R.raw.ic_airplanemode_off_24px);
        }, 3000);
    });
    findViewById(R.id.vibration).setOnClickListener(view -> {
        if (vibration) {
            vibration = false;
            view.setBackgroundColor(0xffffffff);
            ((ImageView) view).setTint(getResources().getColor(R.color.carbon_black_54));
        } else {
            vibration = true;
            view.setBackgroundColor(0xff00695D);
            ((ImageView) view).setTint(0xffffffff);
            Vibrator vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
            vibrator.vibrate(500);
        }
        powerMenu.postInvalidate();
    });
    findViewById(R.id.volume).setOnClickListener(view -> {
        if (volume) {
            volume = false;
            view.setBackgroundColor(0xffffffff);
            ((ImageView) view).setTint(getResources().getColor(R.color.carbon_black_54));
        } else {
            volume = true;
            view.setBackgroundColor(0xff00695D);
            ((ImageView) view).setTint(0xffffffff);
            view.playSoundEffect(SoundEffectConstants.CLICK);
        }
        powerMenu.postInvalidate();
    });
}
Also used : FrameLayout(carbon.widget.FrameLayout) TextView(carbon.widget.TextView) ImageView(carbon.widget.ImageView) Vibrator(android.os.Vibrator) View(android.view.View) ImageView(carbon.widget.ImageView) TextView(carbon.widget.TextView) LinearLayout(carbon.widget.LinearLayout)

Example 65 with Vibrator

use of android.os.Vibrator in project jpHolo by teusink.

the class Vibration method vibrate.

//--------------------------------------------------------------------------
// LOCAL METHODS
//--------------------------------------------------------------------------
/**
     * Vibrates the device for a given amount of time.
     *
     * @param time      Time to vibrate in ms.
     */
public void vibrate(long time) {
    // Start the vibration, 0 defaults to half a second.
    if (time == 0) {
        time = 500;
    }
    Vibrator vibrator = (Vibrator) this.cordova.getActivity().getSystemService(Context.VIBRATOR_SERVICE);
    vibrator.vibrate(time);
}
Also used : Vibrator(android.os.Vibrator)

Aggregations

Vibrator (android.os.Vibrator)88 IOException (java.io.IOException)10 RemoteException (android.os.RemoteException)8 SettingNotFoundException (android.provider.Settings.SettingNotFoundException)6 InputDevice (android.view.InputDevice)6 NotificationManager (android.app.NotificationManager)5 Intent (android.content.Intent)5 Bitmap (android.graphics.Bitmap)5 SystemVibrator (android.os.SystemVibrator)5 FileOutputStream (java.io.FileOutputStream)5 Activity (android.app.Activity)4 Context (android.content.Context)4 AudioManager (android.media.AudioManager)4 PowerManager (android.os.PowerManager)4 NotificationCompat (android.support.v4.app.NotificationCompat)4 ErrnoException (android.system.ErrnoException)4 Uri (android.net.Uri)3 AlarmManager (android.app.AlarmManager)2 PendingIntent (android.app.PendingIntent)2 SearchManager (android.app.SearchManager)2