android.media.ToneGenerator Java Examples

The following examples show how to use android.media.ToneGenerator. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DialerActivity.java    From BaldPhone with Apache License 2.0 7 votes vote down vote up
private void setOnClickListeners() {
    for (char i = '0'; i <= '9'; i++)
        numpad[i - '0'].setOnClickListener(new DialerClickListener(i, i - '0'));
    b_sulamit.setOnClickListener(new DialerClickListener('*', ToneGenerator.TONE_DTMF_S));
    b_hash.setOnClickListener(new DialerClickListener('#', ToneGenerator.TONE_DTMF_P));

    b_call.setOnClickListener(v -> call(number, this, false));
    b_clear.setOnClickListener(v -> {
        number.setLength(0);
        tv_number.setText(number);
        searchForContact();
    });
    b_backspace.setOnClickListener(v -> {
        number.setLength(number.length() > 1 ? number.length() - 1 : 0);
        tv_number.setText(number);
        searchForContact();
    });
    empty_view.setOnClickListener(v -> {
        startActivity(new Intent(this, AddContactActivity.class)
                .putExtra(AddContactActivity.CONTACT_NUMBER, (CharSequence) number));
    });

}
 
Example #2
Source File: MqttSettingsCodeReaderFragment.java    From Bluefruit_LE_Connect_Android_V2 with MIT License 6 votes vote down vote up
@Override
public void onCodeScanned(String contents) {
    Log.d(TAG, "Code Scanned: " + contents);
    if (isCodeAlreadyScanned) {
        return;
    }       // To avoid double scans and pop 2 times the fragment
    isCodeAlreadyScanned = true;

    // Beep
    final ToneGenerator tg = new ToneGenerator(AudioManager.STREAM_NOTIFICATION, 100);
    tg.startTone(ToneGenerator.TONE_PROP_BEEP);

    //
    mListener.onPasswordUpdated(contents);

    // Pop current fragment
    FragmentActivity activity = getActivity();
    if (activity != null) {
        FragmentManager fragmentManager = activity.getSupportFragmentManager();
        fragmentManager.popBackStack();
    }
}
 
Example #3
Source File: BarcodeCaptureActivity.java    From google-authenticator-android with Apache License 2.0 6 votes vote down vote up
@Override
public void onNewDetection(int id, final Barcode barcode) {
  // The barcode detection happens in a different thread than the ui thread. If a barcode is
  // detected, return it on the UI thread to prevent race condition.

  runOnUiThread(new Runnable() {
    @Override
    public void run() {
      if (!mBarcodeDetected) {
        mBarcodeDetected = true;
        mCameraSourcePreview.stop();
        AudioManager audioService = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
        if (audioService.getRingerMode() == AudioManager.RINGER_MODE_NORMAL) {
          ToneGenerator toneGenerator
              = new ToneGenerator(AudioManager.STREAM_MUSIC, TONE_VOLUME);
          toneGenerator.startTone(ToneGenerator.TONE_CDMA_PIP, TONE_DURATION);
        }
        onBarcodeDetected(barcode);
      }
    }
  });
}
 
Example #4
Source File: CountdownWarning.java    From TwistyTimer with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onFinish() {
    if (vibrateEnabled)
        vibrator.vibrate(vibrateDuration);
    if (toneEnabled) {
        try {
            this.toneGenerator = new ToneGenerator(AudioManager.STREAM_MUSIC, 100);
            toneGenerator.startTone(toneCode, toneDuration);
            Handler handler = new Handler(Looper.getMainLooper());
            handler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    if (toneGenerator != null) {
                        Log.d("Countdown", "toneGenerator released");
                        toneGenerator.release();
                        toneGenerator = null;
                    }
                }

            }, toneDuration);
        } catch (Exception e) {
            Log.d("Countdown", "Exception while playing sound:" + e);
        }
    }
}
 
Example #5
Source File: HUDFragment.java    From RobotCA with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 'Warns' the user, where multiple warnings will cause the HUD to turn red in appearance and flash.
 */
public void warn()
{
    if (System.currentTimeMillis() - lastWarnTime > WARN_RATE) {
        lastWarnTime = System.currentTimeMillis();

        warnAmount = Math.min(1.0f, warnAmount + WARN_AMOUNT_INCR);
        lastWarn = System.currentTimeMillis();

        if (beepsEnabled && warnAmount > DANGER_WARN_AMOUNT && lastWarn - lastToneTime > TONE_DELAY
                && RobotController.getSpeed() > 0.01) {
            lastToneTime = lastWarn;

            toneGenerator.startTone(ToneGenerator.TONE_PROP_BEEP, (int) TONE_DELAY / 2);
        }
    }
}
 
Example #6
Source File: OpenFitService.java    From OpenFit with MIT License 6 votes vote down vote up
public void run() {
    long timeStart = Calendar.getInstance().getTimeInMillis();
    Log.d(LOG_TAG, "FindSound Start: "+timeStart);
    ToneGenerator toneG = new ToneGenerator(AudioManager.STREAM_ALARM, ToneGenerator.MAX_VOLUME);

    while(isFinding) {
        try {
            long timeDiff =  Calendar.getInstance().getTimeInMillis() - timeStart;
            Log.d(LOG_TAG, "Sound time: " + timeDiff/1000);

            toneG.startTone(ToneGenerator.TONE_CDMA_ALERT_CALL_GUARD, 200); // 200 ms tone
            Thread.sleep(600L);
        }
        catch(InterruptedException ie) {
            Thread.currentThread().interrupt();
            return;
        }
    }
}
 
Example #7
Source File: WebRtcPhone.java    From Yahala-Messenger with MIT License 6 votes vote down vote up
public void CallRequest(String roomId) {

        if (mSendCallRequest) {
            XMPPManager.getInstance().sendMessage(jid, 0, new CallParameter(roomId, videoCall, false));
          /*  audioManager = (AudioManager)ApplicationLoader.applicationContext.getSystemService(ApplicationLoader.applicationContext.AUDIO_SERVICE);
            audioManager.setSpeakerphoneOn(true);
           */
            Utilities.RunOnUIThread(new Runnable() {
                @Override
                public void run() {
                    tg = new ToneGenerator(AudioManager.STREAM_VOICE_CALL, 100);
                    tg.startTone(ToneGenerator.TONE_SUP_RINGTONE);
                }
            });

        }

    }
 
Example #8
Source File: MqttUartSettingsCodeReaderActivity.java    From Bluefruit_LE_Connect_Android with MIT License 5 votes vote down vote up
@Override
public void onCodeScanned(String contents) {
    Log.d(TAG, "Code Scanned: " + contents);

    // Beep
    final ToneGenerator tg = new ToneGenerator(AudioManager.STREAM_NOTIFICATION, 100);
    tg.startTone(ToneGenerator.TONE_PROP_BEEP);

    //
    Intent data = new Intent();
    data.putExtra(kActivityResult_ScannedContents, contents);
    setResult(RESULT_OK, data);
    finish();
}
 
Example #9
Source File: DialerActivity.java    From BaldPhone with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate(@Nullable final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (!checkPermissions(this, requiredPermissions()))
        return;
    setContentView(R.layout.dialer);
    contentResolver = getContentResolver();
    playDialSounds = BPrefs.get(this).getBoolean(BPrefs.DIALER_SOUNDS_KEY, BPrefs.DIALER_SOUNDS_DEFAULT_VALUE) && !testing;
    if (playDialSounds)
        dtmfGenerator = new ToneGenerator(STREAM_SYSTEM, TONE_VOLUME);
    attachXml();
    setOnClickListeners();
    setupYoutube(2);
    searchForContact();
}
 
Example #10
Source File: KeypadFragment.java    From restcomm-android-sdk with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState)
{
   Log.i(TAG, "%% onCreate");
   super.onCreate(savedInstanceState);
   if (getArguments() != null) {
      mParam1 = getArguments().getString(ARG_PARAM1);
      mParam2 = getArguments().getString(ARG_PARAM2);
   }

   toneGenerator = new ToneGenerator(AudioManager.STREAM_MUSIC, 100);
}
 
Example #11
Source File: BackgroundLocationUpdateService.java    From cordova-background-geolocation-services with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();
    Log.i(TAG, "OnCreate");

    toneGenerator           = new ToneGenerator(AudioManager.STREAM_NOTIFICATION, 100);
    notificationManager     = (NotificationManager)this.getSystemService(Context.NOTIFICATION_SERVICE);
    connectivityManager     = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);

    // Location Update PI
    Intent locationUpdateIntent = new Intent(Constants.LOCATION_UPDATE);
    locationUpdatePI = PendingIntent.getBroadcast(this, 9001, locationUpdateIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    registerReceiver(locationUpdateReceiver, new IntentFilter(Constants.LOCATION_UPDATE));

    Intent detectedActivitiesIntent = new Intent(Constants.DETECTED_ACTIVITY_UPDATE);
    detectedActivitiesPI = PendingIntent.getBroadcast(this, 9002, detectedActivitiesIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    registerReceiver(detectedActivitiesReceiver, new IntentFilter(Constants.DETECTED_ACTIVITY_UPDATE));

    // Receivers for start/stop recording
    registerReceiver(startRecordingReceiver, new IntentFilter(Constants.START_RECORDING));
    registerReceiver(stopRecordingReceiver, new IntentFilter(Constants.STOP_RECORDING));
    registerReceiver(startAggressiveReceiver, new IntentFilter(Constants.CHANGE_AGGRESSIVE));

    // Location criteria
    criteria = new Criteria();
    criteria.setAltitudeRequired(false);
    criteria.setBearingRequired(false);
    criteria.setSpeedRequired(true);
    criteria.setCostAllowed(true);
}
 
Example #12
Source File: CallActivity.java    From Yahala-Messenger with MIT License 5 votes vote down vote up
@Override
public void onCallHangUp() {
    WebRtcPhone.getInstance().AnswerCall();
    disconnect();

    ToneGenerator tg2 = new ToneGenerator(AudioManager.STREAM_VOICE_CALL, 100);
    tg2.startTone(ToneGenerator.TONE_PROP_BEEP2);
}
 
Example #13
Source File: DialPadView.java    From FamilyChat with Apache License 2.0 4 votes vote down vote up
private void keyPressed(int keyCode)
{
    switch (keyCode)
    {
        case KeyEvent.KEYCODE_1:
            triggerFeedBack(ToneGenerator.TONE_DTMF_1, TONE_LENGTH_INFINITE);
            break;
        case KeyEvent.KEYCODE_2:
            triggerFeedBack(ToneGenerator.TONE_DTMF_2, TONE_LENGTH_INFINITE);
            break;
        case KeyEvent.KEYCODE_3:
            triggerFeedBack(ToneGenerator.TONE_DTMF_3, TONE_LENGTH_INFINITE);
            break;
        case KeyEvent.KEYCODE_4:
            triggerFeedBack(ToneGenerator.TONE_DTMF_4, TONE_LENGTH_INFINITE);
            break;
        case KeyEvent.KEYCODE_5:
            triggerFeedBack(ToneGenerator.TONE_DTMF_5, TONE_LENGTH_INFINITE);
            break;
        case KeyEvent.KEYCODE_6:
            triggerFeedBack(ToneGenerator.TONE_DTMF_6, TONE_LENGTH_INFINITE);
            break;
        case KeyEvent.KEYCODE_7:
            triggerFeedBack(ToneGenerator.TONE_DTMF_7, TONE_LENGTH_INFINITE);
            break;
        case KeyEvent.KEYCODE_8:
            triggerFeedBack(ToneGenerator.TONE_DTMF_8, TONE_LENGTH_INFINITE);
            break;
        case KeyEvent.KEYCODE_9:
            triggerFeedBack(ToneGenerator.TONE_DTMF_9, TONE_LENGTH_INFINITE);
            break;
        case KeyEvent.KEYCODE_0:
            triggerFeedBack(ToneGenerator.TONE_DTMF_0, TONE_LENGTH_INFINITE);
            break;
        case KeyEvent.KEYCODE_POUND:
            triggerFeedBack(ToneGenerator.TONE_DTMF_P, TONE_LENGTH_INFINITE);
            break;
        case KeyEvent.KEYCODE_STAR:
            triggerFeedBack(ToneGenerator.TONE_DTMF_S, TONE_LENGTH_INFINITE);
            break;
        default:
            break;
    }

    KeyEvent event = new KeyEvent(KeyEvent.ACTION_DOWN, keyCode);
    mEdInput.onKeyDown(keyCode, event);

    // 如果光标在文本末尾就隐藏光标
    final int length = mEdInput.length();
    if (length == mEdInput.getSelectionStart() && length == mEdInput.getSelectionEnd())
        mEdInput.setCursorVisible(false);
}
 
Example #14
Source File: ToneManager.java    From Pix-Art-Messenger with GNU General Public License v3.0 4 votes vote down vote up
private void scheduleConnected() {
    this.currentTone = JingleConnectionManager.SCHEDULED_EXECUTOR_SERVICE.schedule(() -> {
        startTone(ToneGenerator.TONE_PROP_PROMPT, 200);
    }, 0, TimeUnit.SECONDS);
}
 
Example #15
Source File: ToneManager.java    From Pix-Art-Messenger with GNU General Public License v3.0 4 votes vote down vote up
private void scheduleEnding() {
    this.currentTone = JingleConnectionManager.SCHEDULED_EXECUTOR_SERVICE.schedule(() -> {
        startTone(ToneGenerator.TONE_CDMA_CALLDROP_LITE, 375);
    }, 0, TimeUnit.SECONDS);
    this.currentResetFuture = JingleConnectionManager.SCHEDULED_EXECUTOR_SERVICE.schedule(this::resetAudioManager, 375, TimeUnit.MILLISECONDS);
}
 
Example #16
Source File: ToneManager.java    From Pix-Art-Messenger with GNU General Public License v3.0 4 votes vote down vote up
private void scheduleBusy() {
    this.currentTone = JingleConnectionManager.SCHEDULED_EXECUTOR_SERVICE.schedule(() -> {
        startTone(ToneGenerator.TONE_CDMA_NETWORK_BUSY, 2500);
    }, 0, TimeUnit.SECONDS);
    this.currentResetFuture = JingleConnectionManager.SCHEDULED_EXECUTOR_SERVICE.schedule(this::resetAudioManager, 2500, TimeUnit.MILLISECONDS);
}
 
Example #17
Source File: ToneManager.java    From Pix-Art-Messenger with GNU General Public License v3.0 4 votes vote down vote up
private void scheduleWaitingTone() {
    this.currentTone = JingleConnectionManager.SCHEDULED_EXECUTOR_SERVICE.scheduleAtFixedRate(() -> {
        startTone(ToneGenerator.TONE_CDMA_DIAL_TONE_LITE, 750);
    }, 0, 3, TimeUnit.SECONDS);
}
 
Example #18
Source File: HUDFragment.java    From RobotCA with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Default Constructor.
 */
public HUDFragment() {
    toneGenerator = new ToneGenerator(AudioManager.STREAM_NOTIFICATION, 100);
}
 
Example #19
Source File: KeypadFragment.java    From restcomm-android-sdk with GNU Affero General Public License v3.0 4 votes vote down vote up
public boolean onTouch(View v, MotionEvent e)
{
   switch (e.getAction()) {
      case MotionEvent.ACTION_DOWN: {
         if (v.getId() == R.id.imageButton_1) {
            toneGenerator.startTone(ToneGenerator.TONE_DTMF_1, 300);
            connection.sendDigits("1");
         }
         else if (v.getId() == R.id.imageButton_2) {
            toneGenerator.startTone(ToneGenerator.TONE_DTMF_2, 300);
            connection.sendDigits("2");
         }
         else if (v.getId() == R.id.imageButton_3) {
            toneGenerator.startTone(ToneGenerator.TONE_DTMF_3, 300);
            connection.sendDigits("3");
         }
         else if (v.getId() == R.id.imageButton_4) {
            toneGenerator.startTone(ToneGenerator.TONE_DTMF_4, 300);
            connection.sendDigits("4");
         }
         else if (v.getId() == R.id.imageButton_5) {
            toneGenerator.startTone(ToneGenerator.TONE_DTMF_5, 300);
            connection.sendDigits("5");
         }
         else if (v.getId() == R.id.imageButton_6) {
            toneGenerator.startTone(ToneGenerator.TONE_DTMF_6, 300);
            connection.sendDigits("6");
         }
         else if (v.getId() == R.id.imageButton_7) {
            toneGenerator.startTone(ToneGenerator.TONE_DTMF_7, 300);
            connection.sendDigits("7");
         }
         else if (v.getId() == R.id.imageButton_8) {
            toneGenerator.startTone(ToneGenerator.TONE_DTMF_8, 300);
            connection.sendDigits("8");
         }
         else if (v.getId() == R.id.imageButton_9) {
            toneGenerator.startTone(ToneGenerator.TONE_DTMF_9, 300);
            connection.sendDigits("9");
         }
         else if (v.getId() == R.id.imageButton_0) {
            toneGenerator.startTone(ToneGenerator.TONE_DTMF_0, 300);
            connection.sendDigits("0");
         }
         else if (v.getId() == R.id.imageButton_star) {
            toneGenerator.startTone(ToneGenerator.TONE_DTMF_S, 300);
            connection.sendDigits("*");
         }
         else if (v.getId() == R.id.imageButton_hash) {
            toneGenerator.startTone(ToneGenerator.TONE_DTMF_P, 300);
            connection.sendDigits("#");
         }
         else if (v.getId() == R.id.button_cancel) {
            mListener.onFragmentInteraction("cancel");
         }

         // Add also visual feedback as long as the user keeps the button pressed
         v.setBackgroundResource(R.drawable.pressed_digit);
         v.invalidate();

         break;
      }
      case MotionEvent.ACTION_UP:
         // Your action here on button click
      case MotionEvent.ACTION_CANCEL: {
         final View view = v;

         // add small delay to make sure it is perceivable even for very fast touches
         new Handler().postDelayed(new Runnable() {
            @Override
            public void run()
            {
               view.setBackgroundResource(0);
               view.invalidate();
            }
         }, 100);
         break;
      }
   }




   return true;
}
 
Example #20
Source File: Utils.java    From jellyfin-androidtv with GNU General Public License v2.0 4 votes vote down vote up
public static void beep(int ms) {
    makeTone(ToneGenerator.TONE_CDMA_ALERT_CALL_GUARD, ms);
}
 
Example #21
Source File: ToneManager.java    From Conversations with GNU General Public License v3.0 4 votes vote down vote up
private void scheduleConnected() {
    this.currentTone = JingleConnectionManager.SCHEDULED_EXECUTOR_SERVICE.schedule(() -> {
        startTone(ToneGenerator.TONE_PROP_PROMPT, 200);
    }, 0, TimeUnit.SECONDS);
}
 
Example #22
Source File: ToneManager.java    From Conversations with GNU General Public License v3.0 4 votes vote down vote up
private void scheduleEnding() {
    this.currentTone = JingleConnectionManager.SCHEDULED_EXECUTOR_SERVICE.schedule(() -> {
        startTone(ToneGenerator.TONE_CDMA_CALLDROP_LITE, 375);
    }, 0, TimeUnit.SECONDS);
    this.currentResetFuture = JingleConnectionManager.SCHEDULED_EXECUTOR_SERVICE.schedule(this::resetAudioManager, 375, TimeUnit.MILLISECONDS);
}
 
Example #23
Source File: ToneManager.java    From Conversations with GNU General Public License v3.0 4 votes vote down vote up
private void scheduleBusy() {
    this.currentTone = JingleConnectionManager.SCHEDULED_EXECUTOR_SERVICE.schedule(() -> {
        startTone(ToneGenerator.TONE_CDMA_NETWORK_BUSY, 2500);
    }, 0, TimeUnit.SECONDS);
    this.currentResetFuture = JingleConnectionManager.SCHEDULED_EXECUTOR_SERVICE.schedule(this::resetAudioManager, 2500, TimeUnit.MILLISECONDS);
}
 
Example #24
Source File: ToneManager.java    From Conversations with GNU General Public License v3.0 4 votes vote down vote up
private void scheduleWaitingTone() {
    this.currentTone = JingleConnectionManager.SCHEDULED_EXECUTOR_SERVICE.scheduleAtFixedRate(() -> {
        startTone(ToneGenerator.TONE_CDMA_DIAL_TONE_LITE, 750);
    }, 0, 3, TimeUnit.SECONDS);
}
 
Example #25
Source File: DialpadFragment.java    From call_manage with MIT License 4 votes vote down vote up
/**
 * Act when a key is pressed (Plays tune and sets the text)
 *
 * @param keyCode
 */
private void keyPressed(int keyCode) {
    updatePreferences();
    if (getView().getTranslationY() != 0) {
        return;
    }
    if (!mIsSilent) {
        switch (keyCode) {
            case KeyEvent.KEYCODE_1:
                playTone(ToneGenerator.TONE_DTMF_1);
                break;
            case KeyEvent.KEYCODE_2:
                playTone(ToneGenerator.TONE_DTMF_2);
                break;
            case KeyEvent.KEYCODE_3:
                playTone(ToneGenerator.TONE_DTMF_3);
                break;
            case KeyEvent.KEYCODE_4:
                playTone(ToneGenerator.TONE_DTMF_4);
                break;
            case KeyEvent.KEYCODE_5:
                playTone(ToneGenerator.TONE_DTMF_5);
                break;
            case KeyEvent.KEYCODE_6:
                playTone(ToneGenerator.TONE_DTMF_6);
                break;
            case KeyEvent.KEYCODE_7:
                playTone(ToneGenerator.TONE_DTMF_7);
                break;
            case KeyEvent.KEYCODE_8:
                playTone(ToneGenerator.TONE_DTMF_8);
                break;
            case KeyEvent.KEYCODE_9:
                playTone(ToneGenerator.TONE_DTMF_9);
                break;
            case KeyEvent.KEYCODE_0:
                playTone(ToneGenerator.TONE_DTMF_0);
                break;
            case KeyEvent.KEYCODE_POUND:
                playTone(ToneGenerator.TONE_DTMF_P);
                break;
            case KeyEvent.KEYCODE_STAR:
                playTone(ToneGenerator.TONE_DTMF_S);
                break;
            default:
                break;
        }
    }
    vibrate();
    KeyEvent event = new KeyEvent(KeyEvent.ACTION_DOWN, keyCode);

    // Add the digit to mDigits
    mDigits.onKeyDown(keyCode, event);

    // An option for an outer response
    if (mOnKeyDownListener != null) mOnKeyDownListener.onKeyPressed(keyCode, event);

    // If the cursor is at the end of the text we hide it.
    final int length = mDigits.length();
    if (length == mDigits.getSelectionStart() && length == mDigits.getSelectionEnd()) {
        mDigits.setCursorVisible(false);
    }
}