Java Code Examples for android.media.AudioManager

The following examples show how to use android.media.AudioManager. These examples are extracted from open source projects. 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 Project: hackerskeyboard   Source File: LatinIME.java    License: Apache License 2.0 6 votes vote down vote up
private void playKeyClick(int primaryCode) {
    // if mAudioManager is null, we don't have the ringer state yet
    // mAudioManager will be set by updateRingerMode
    if (mAudioManager == null) {
        if (mKeyboardSwitcher.getInputView() != null) {
            updateRingerMode();
        }
    }
    if (mSoundOn && !mSilentMode) {
        // FIXME: Volume and enable should come from UI settings
        // FIXME: These should be triggered after auto-repeat logic
        int sound = AudioManager.FX_KEYPRESS_STANDARD;
        switch (primaryCode) {
        case Keyboard.KEYCODE_DELETE:
            sound = AudioManager.FX_KEYPRESS_DELETE;
            break;
        case ASCII_ENTER:
            sound = AudioManager.FX_KEYPRESS_RETURN;
            break;
        case ASCII_SPACE:
            sound = AudioManager.FX_KEYPRESS_SPACEBAR;
            break;
        }
        mAudioManager.playSoundEffect(sound, getKeyClickVolume());
    }
}
 
Example 2
private boolean isBluetoothAvailable() {
    try {
        synchronized (LOCK) {
            AudioManager audioManager = AppUtil.INSTANCE.getAudioManager(context);

            if (bluetoothAdapter == null || !bluetoothAdapter.isEnabled()) {
                return false;
            }
            if (!audioManager.isBluetoothScoAvailableOffCall()) {
                return false;
            }

            return bluetoothHeadset != null && !bluetoothHeadset.getConnectedDevices().isEmpty();
        }
    } catch (Exception e) {
        Log.w(TAG, e);
        return false;
    }
}
 
Example 3
Source Project: PTVGlass   Source File: SetTimerActivity.java    License: MIT License 6 votes vote down vote up
@Override
public boolean onGesture(Gesture gesture) {
    if (gesture == Gesture.TAP) {
        int position = mView.getSelectedItemPosition();
        SetTimerScrollAdapter.TimeComponents component =
                (SetTimerScrollAdapter.TimeComponents) mAdapter.getItem(position);
        Intent selectValueIntent = new Intent(this, SelectValueActivity.class);

        selectValueIntent.putExtra(SelectValueActivity.EXTRA_COUNT, component.getMaxValue());
        selectValueIntent.putExtra(
                SelectValueActivity.EXTRA_INITIAL_VALUE,
                (int) mAdapter.getTimeComponent(component));
        startActivityForResult(selectValueIntent, SELECT_VALUE);
        mAudioManager.playSoundEffect(AudioManager.FX_KEY_CLICK);
        return true;
    }
    return false;
}
 
Example 4
Source Project: connectivity-samples   Source File: MainActivity.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void onStop() {
  mSensorManager.unregisterListener(this);

  // Restore the original volume.
  AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
  audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, mOriginalVolume, 0);
  setVolumeControlStream(AudioManager.USE_DEFAULT_STREAM_TYPE);

  if (isRecording()) {
    stopRecording();
  }
  if (isPlaying()) {
    stopPlaying();
  }

  setState(State.UNKNOWN);

  mUiHandler.removeCallbacksAndMessages(null);

  if (mCurrentAnimator != null && mCurrentAnimator.isRunning()) {
    mCurrentAnimator.cancel();
  }

  super.onStop();
}
 
Example 5
Source Project: Noyze   Source File: StatusBarPlusVolumePanel.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void onRingerModeChange(int ringerMode) {
    super.onRingerModeChange(ringerMode);
    if (null != mLastVolumeChange) {
        switch (mLastVolumeChange.mStreamType) {
            case AudioManager.STREAM_NOTIFICATION:
            case AudioManager.STREAM_RING:
                switch (ringerMode) {
                    case RINGER_MODE_VIBRATE:
                        icon.setImageResource(getVibrateIcon());
                        break;
                    case RINGER_MODE_SILENT:
                    default:
                        icon.setImageResource(getSilentIcon());
                        break;
                }
                break;
        }
    }
}
 
Example 6
Source Project: DeviceConnect-Android   Source File: HostPhoneProfile.java    License: MIT License 6 votes vote down vote up
private void setPhoneMode(Intent response, PhoneMode mode) {
    // AudioManager
    AudioManager mAudioManager = (AudioManager) getContext().getSystemService(Context.AUDIO_SERVICE);
    if (mode.equals(PhoneMode.SILENT)) {
        mAudioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT);
        setResult(response, DConnectMessage.RESULT_OK);
    } else if (mode.equals(PhoneMode.SOUND)) {
        mAudioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
        setResult(response, DConnectMessage.RESULT_OK);
    } else if (mode.equals(PhoneMode.MANNER)) {
        mAudioManager.setRingerMode(AudioManager.RINGER_MODE_VIBRATE);
        setResult(response, DConnectMessage.RESULT_OK);
    } else if (mode.equals(PhoneMode.UNKNOWN)) {
        MessageUtils.setInvalidRequestParameterError(response, "mode is invalid.");
    }
}
 
Example 7
private AudioSlidePlayer(@NonNull Context context,
                         @NonNull AudioSlide slide,
                         @NonNull Listener listener)
{
  this.context              = context;
  this.slide                = slide;
  this.listener             = new WeakReference<>(listener);
  this.progressEventHandler = new ProgressEventHandler(this);
  this.audioManager         = (AudioManager)context.getSystemService(Context.AUDIO_SERVICE);
  this.sensorManager        = (SensorManager)context.getSystemService(Context.SENSOR_SERVICE);
  this.proximitySensor      = sensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY);

  if (Build.VERSION.SDK_INT >= 21) {
    this.wakeLock = ServiceUtil.getPowerManager(context).newWakeLock(PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK, TAG);
  } else {
    this.wakeLock = null;
  }
}
 
Example 8
Source Project: Gojuon   Source File: PronounceService.java    License: MIT License 6 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    String charset = intent.getStringExtra(EXTRA_CHARSET);
    if (charset != null && charset.length() > 0) {
        try {
            AssetFileDescriptor pronounceFile = getPronounceAssetFile(charset);
            if (pronounceFile.getLength() > 0) {
                final int playId = mSoundPool.load(pronounceFile, 1);
                mSoundPool.setOnLoadCompleteListener(new SoundPool.OnLoadCompleteListener() {
                    @Override
                    public void onLoadComplete(SoundPool soundPool, int i, int i2) {
                        int volume = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
                        mSoundPool.play(playId, volume, volume, 1, 0, 1f);
                        mSoundPool.unload(playId);
                    }
                });
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
 
Example 9
Source Project: Noyze   Source File: AudioFlingerProxy.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Set the volume_3 of a calibrated stream.
 * @see {@link #setStreamVolume(int, float)}
 * @throws RemoteException
 */
public int adjustStreamVolume(int stream, int direction, int index, int max) throws RemoteException {
    LogUtils.LOGI("AudioFlingerProxy", "adjustStreamVolume(" + stream + ", " + direction + ")");
    if (null == mAudioFlinger || TextUtils.isEmpty(mInterfaceDescriptor) || !isCalibrated(stream)) {
        return BAD_VALUE;
    }

    float value = getStreamVolume(stream);
    float increment = getStreamIncrement(stream);

    float newValue = value;
    switch (direction) {
        case AudioManager.ADJUST_LOWER:
            newValue -= increment;
        case AudioManager.ADJUST_RAISE:
            newValue += increment;
    }
    newValue = Math.max(0, Math.min(newValue, max * increment));

    LogUtils.LOGI("AudioFlingerProxy", "adjustStreamVolume() increment = " + increment + ", newVolume = " + newValue);
    return setStreamVolume(stream, newValue);
}
 
Example 10
Source Project: kcanotify   Source File: KcaUtils.java    License: GNU General Public License v3.0 6 votes vote down vote up
public static void playNotificationSound(MediaPlayer mediaPlayer, Context context, Uri uri) {
    try {
        if (mediaPlayer.isPlaying()) {
            mediaPlayer.stop();
            mediaPlayer.reset();
        }
        if (uri != null && !Uri.EMPTY.equals(uri)) {
            mediaPlayer.setDataSource(context, uri);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                AudioAttributes attr = new AudioAttributes.Builder()
                        .setLegacyStreamType(AudioManager.STREAM_NOTIFICATION)
                        .build();
                mediaPlayer.setAudioAttributes(attr);
            } else {
                mediaPlayer.setAudioStreamType(AudioManager.STREAM_NOTIFICATION);
            }
            mediaPlayer.prepare();
            mediaPlayer.start();
        }
    } catch (IllegalArgumentException | SecurityException | IllegalStateException | IOException e) {
        e.printStackTrace();
    }
}
 
Example 11
Source Project: Audinaut   Source File: SubsonicActivity.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle bundle) {
    PackageManager pm = getPackageManager();
    if (!pm.hasSystemFeature(PackageManager.FEATURE_TOUCHSCREEN)) {
        touchscreen = false;
    }

    applyTheme();
    applyFullscreen();
    super.onCreate(bundle);
    startService(new Intent(this, DownloadService.class));
    setVolumeControlStream(AudioManager.STREAM_MUSIC);

    if (getIntent().hasExtra(Constants.FRAGMENT_POSITION)) {
        lastSelectedPosition = getIntent().getIntExtra(Constants.FRAGMENT_POSITION, 0);
    }

    if (preferencesListener == null) {
        Util.getPreferences(this).registerOnSharedPreferenceChangeListener(preferencesListener);
    }

    if (ContextCompat.checkSelfPermission(this, permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
        ActivityCompat.requestPermissions(this, new String[]{permission.WRITE_EXTERNAL_STORAGE}, PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE);
    }
}
 
Example 12
Source Project: AssistantBySDK   Source File: IflySynthesizer.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void onAudioFocusChange(int focusChange) {
    Log.e(TAG, "audioFocusChangeListener.onAudioFocusChange>>>>>>>>>>>>>>>>>>" + focusChange);
    switch (focusChange) {
        case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT:
        case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK:
            // pauseSpeaking();
            break;
        case AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK:
        case AudioManager.AUDIOFOCUS_GAIN_TRANSIENT:
            /*if (isSpeaking()) {
                synthesizer.resumeSpeaking();
            }*/
            break;
        default:
            break;
    }
}
 
Example 13
Source Project: Study_Android_Demo   Source File: DatabaseHelper.java    License: Apache License 2.0 6 votes vote down vote up
private void loadVibrateSetting(SQLiteDatabase db, boolean deleteOld) {
    if (deleteOld) {
        db.execSQL("DELETE FROM system WHERE name='" + Settings.System.VIBRATE_ON + "'");
    }

    SQLiteStatement stmt = null;
    try {
        stmt = db.compileStatement("INSERT OR IGNORE INTO system(name,value)"
                + " VALUES(?,?);");

        // Vibrate on by default for ringer, on for notification
        int vibrate = 0;
        vibrate = AudioSystem.getValueForVibrateSetting(vibrate,
                AudioManager.VIBRATE_TYPE_NOTIFICATION,
                AudioManager.VIBRATE_SETTING_ONLY_SILENT);
        vibrate |= AudioSystem.getValueForVibrateSetting(vibrate,
                AudioManager.VIBRATE_TYPE_RINGER, AudioManager.VIBRATE_SETTING_ONLY_SILENT);
        loadSetting(stmt, Settings.System.VIBRATE_ON, vibrate);
    } finally {
        if (stmt != null) stmt.close();
    }
}
 
Example 14
Source Project: MyHearts   Source File: CustomMediaController.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 声音高低
 *
 * @param percent
 */
private void onVolumeSlide(float percent) {
    if (mVolume == -1) {
        mVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
        if (mVolume < 0)
            mVolume = 0;

        mOperationBg.setImageResource(R.drawable.video_volumn_bg);
        mVolumeBrightnessLayout.setVisibility(View.VISIBLE);
    }

    int index = (int) (percent * mMaxVolume) + mVolume;
    if (index > mMaxVolume)
        index = mMaxVolume;
    else if (index < 0)
        index = 0;

    mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, index, 0);
    ViewGroup.LayoutParams lp = mOperationPercent.getLayoutParams();
    lp.width = findViewById(R.id.operation_full).getLayoutParams().width * index / mMaxVolume;
    mOperationPercent.setLayoutParams(lp);
}
 
Example 15
Source Project: PTVGlass   Source File: SelectValueActivity.java    License: MIT License 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);

    mAdapter = new SelectValueScrollAdapter(
            this, getIntent().getIntExtra(EXTRA_COUNT, DEFAULT_COUNT));

    mView = new CardScrollView(this) {
        @Override
        public final boolean dispatchGenericFocusedEvent(MotionEvent event) {
            if (mDetector.onMotionEvent(event)) {
                return true;
            }
            return super.dispatchGenericFocusedEvent(event);
        }
    };
    mView.setAdapter(mAdapter);
    setContentView(mView);

    mDetector = new GestureDetector(this).setBaseListener(this);
}
 
Example 16
Source Project: JCVideoPlayer   Source File: JCVideoPlayer.java    License: MIT License 6 votes vote down vote up
@Override
    public void onCompletion() {
        setUiWitStateAndScreen(CURRENT_STATE_NORMAL);
        if (textureViewContainer.getChildCount() > 0) {
            textureViewContainer.removeAllViews();
        }

        JCVideoPlayerManager.setListener(null);//这里还不完全,
//        JCVideoPlayerManager.setLastListener(null);
        JCMediaManager.instance().currentVideoWidth = 0;
        JCMediaManager.instance().currentVideoHeight = 0;

        AudioManager mAudioManager = (AudioManager) getContext().getSystemService(Context.AUDIO_SERVICE);
        mAudioManager.abandonAudioFocus(onAudioFocusChangeListener);
        JCUtils.scanForActivity(getContext()).getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
        clearFullscreenLayout();
    }
 
Example 17
Source Project: CameraV   Source File: VideoViewerActivity.java    License: GNU General Public License v3.0 6 votes vote down vote up
private void playVideo(Uri uri) {
doCleanUp();
try {


  // Create a new media player and set the listeners
  mMediaPlayer = new MediaPlayer();
  mMediaPlayer.setDataSource(this, uri);
  mMediaPlayer.setDisplay(holder);
  mMediaPlayer.prepare();
  mMediaPlayer.setOnBufferingUpdateListener(this);
  mMediaPlayer.setOnCompletionListener(this);
  mMediaPlayer.setOnPreparedListener(this);
  mMediaPlayer.setOnVideoSizeChangedListener(this);
  mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);

} catch (Exception e) {
  Log.e(TAG, "error: " + e.getMessage(), e);
}
}
 
Example 18
public void initBluetooth() {
	if (!ensureInit()) {
		Log.w("[Bluetooth] Manager tried to init bluetooth but LinphoneService not ready yet...");
		return;
	}
	
	IntentFilter filter = new IntentFilter();
	filter.addCategory(BluetoothHeadset.VENDOR_SPECIFIC_HEADSET_EVENT_COMPANY_ID_CATEGORY + "." + BluetoothAssignedNumbers.PLANTRONICS);
	filter.addAction(AudioManager.ACTION_SCO_AUDIO_STATE_UPDATED);
	filter.addAction(BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED);
	filter.addAction(BluetoothHeadset.ACTION_VENDOR_SPECIFIC_HEADSET_EVENT);
	mContext.registerReceiver(this,  filter);
	Log.d("[Bluetooth] Receiver started");
	
	startBluetooth();
}
 
Example 19
Source Project: jmessage-android-uikit   Source File: ListAdapter.java    License: MIT License 6 votes vote down vote up
public void setAudioPlayByEarPhone(int state) {
    AudioManager audioManager = (AudioManager) mContext
            .getSystemService(Context.AUDIO_SERVICE);
    int currVolume = audioManager.getStreamVolume(AudioManager.STREAM_VOICE_CALL);
    audioManager.setMode(AudioManager.MODE_IN_CALL);
    if (state == 0) {
        mIsEarPhoneOn = false;
        audioManager.setSpeakerphoneOn(true);
        audioManager.setStreamVolume(AudioManager.STREAM_VOICE_CALL,
                audioManager.getStreamMaxVolume(AudioManager.STREAM_VOICE_CALL),
                AudioManager.STREAM_VOICE_CALL);
        Log.i(TAG, "set SpeakerphoneOn true!");
    } else {
        mIsEarPhoneOn = true;
        audioManager.setSpeakerphoneOn(false);
        audioManager.setStreamVolume(AudioManager.STREAM_VOICE_CALL, currVolume,
                AudioManager.STREAM_VOICE_CALL);
        Log.i(TAG, "set SpeakerphoneOn false!");
    }
}
 
Example 20
Source Project: v9porn   Source File: ExoVideoView.java    License: MIT License 6 votes vote down vote up
/**
 * Requests to obtain the audio focus
 *
 * @return True if the focus was granted
 */
public boolean requestFocus() {
    if (!handleAudioFocus || currentFocus == AudioManager.AUDIOFOCUS_GAIN) {
        return true;
    }

    if (audioManager == null) {
        return false;
    }

    int status = audioManager.requestAudioFocus(this, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN);
    if (AudioManager.AUDIOFOCUS_REQUEST_GRANTED == status) {
        currentFocus = AudioManager.AUDIOFOCUS_GAIN;
        return true;
    }

    startRequested = true;
    return false;
}
 
Example 21
@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 22
Source Project: JieCaoVideoPlayer-develop   Source File: JCVideoPlayer.java    License: MIT License 5 votes vote down vote up
protected void prepareVideo() {
    Log.d(TAG, "prepareVideo [" + this.hashCode() + "] ");
    if (JCMediaManager.instance().listener != null) {
        JCMediaManager.instance().listener.onCompletion();
    }
    JCMediaManager.instance().listener = this;
    addTextureView();
    AudioManager mAudioManager = (AudioManager) getContext().getSystemService(Context.AUDIO_SERVICE);
    mAudioManager.requestAudioFocus(onAudioFocusChangeListener, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN_TRANSIENT);

    ((Activity) getContext()).getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    JCMediaManager.instance().prepare(mUrl, mMapHeadData, mLooping);
    setStateAndUi(CURRENT_STATE_PREPAREING);
}
 
Example 23
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Only 1 player activity should be open at a time
    // For some reason some launchers launch multiple
    if (!isTaskRoot()) {
        finish();
        return;
    }

    setContentView(R.layout.activity_player);

    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        setVolumeControlStream(AudioManager.STREAM_MUSIC);
    }

    stationListAdapter = new StationListAdapter(this);

    sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);

    bindPlayerService();

    initialisePlayerAttributesUi(savedInstanceState);
    initialiseStationListUi();

    if (savedInstanceState == null) {
        clearPlayerAttributes();

    } else {
        isRestartedInstance = true;
    }
}
 
Example 24
Source Project: BotLibre   Source File: ChatActivity.java    License: Eclipse Public License 1.0 5 votes vote down vote up
private void setStreamVolume() {
	AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
	int volume = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
	if (volume != 0) {
		debug("setStreamVolume:" + volume);
		Log.d("ChatActivity","The volume changed and saved to : " + volume);
		MainActivity.volume = volume;
	} 
}
 
Example 25
Source Project: xDrip-plus   Source File: SpeechUtil.java    License: GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("ConstantConditions")
private static boolean isOngoingCall() {
    final AudioManager manager = (AudioManager) xdrip.getAppContext().getSystemService(Context.AUDIO_SERVICE);
    try {
        return (manager.getMode() == AudioManager.MODE_IN_CALL);
    } catch (NullPointerException e) {
        return false;
    }
}
 
Example 26
Source Project: GravityBox   Source File: BatteryInfoManager.java    License: Apache License 2.0 5 votes vote down vote up
private void playSound(int type) {
    if (type < 0 || type > (mSounds.length-1) || mSounds[type] == null || 
            !isPhoneIdle() || quietHoursActive()) return;
    try {
        final Ringtone sfx = RingtoneManager.getRingtone(mContext, mSounds[type]);
        if (sfx != null) {
            sfx.setStreamType(AudioManager.STREAM_NOTIFICATION);
            sfx.play();
        }
    } catch (Throwable t) {
        XposedBridge.log(t);
    }
}
 
Example 27
Source Project: Noyze   Source File: ParanoidVolumePanel.java    License: Apache License 2.0 5 votes vote down vote up
protected int[] getStreamIcons(StreamControl sc) {
    if (sc.streamType == AudioManager.STREAM_NOTIFICATION ||
        sc.streamType == AudioManager.STREAM_RING) {
        switch (mRingerMode) {
            case AudioManager.RINGER_MODE_VIBRATE:
                return new int[] { sc.iconRes, getVibrateIcon() };
            case AudioManager.RINGER_MODE_SILENT:
                return new int[] { sc.iconRes, getSilentIcon() };
        }
    }
    return new int[] { sc.iconRes, sc.iconMuteRes }; // Default icons
}
 
Example 28
Source Project: Noyze   Source File: VolumePanel.java    License: Apache License 2.0 5 votes vote down vote up
public void setOneVolume(final boolean master) {
    oneVolume = master;
    // When we create this panel, sync all volumes from the get-go.sss
    if (oneVolume) {
        mVolumeManager.adjustVolumeSync(AudioManager.ADJUST_SAME);
    }
}
 
Example 29
Source Project: CSipSimple   Source File: MediaManager.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
     * Restore the state of the audio
     */
    @SuppressWarnings("deprecation")
	private final synchronized void restoreAudioState() {
		if( !prefs.getBoolean("isSavedAudioState", false) ) {
			//If we have NEVER set, do not try to reset !
			return;
		}
		
		ContentResolver ctntResolver = service.getContentResolver();
		Compatibility.setWifiSleepPolicy(ctntResolver, prefs.getInt("savedWifiPolicy", Compatibility.getWifiSleepPolicyDefault()));
//		audioManager.setVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER, prefs.getInt("savedVibrateRing", AudioManager.VIBRATE_SETTING_ONLY_SILENT));
//		audioManager.setVibrateSetting(AudioManager.VIBRATE_TYPE_NOTIFICATION, prefs.getInt("savedVibradeNotif", AudioManager.VIBRATE_SETTING_OFF));
//		audioManager.setRingerMode(prefs.getInt("savedRingerMode", AudioManager.RINGER_MODE_NORMAL));
		
		int inCallStream = Compatibility.getInCallStream(userWantBluetooth);
		setStreamVolume(inCallStream, prefs.getInt("savedVolume", (int)(audioManager.getStreamMaxVolume(inCallStream)*0.8) ), 0);
		
		int targetMode = getAudioTargetMode();
		if(service.getPrefs().useRoutingApi()) {
			audioManager.setRouting(targetMode, prefs.getInt("savedRoute", AudioManager.ROUTE_SPEAKER), AudioManager.ROUTE_ALL);
		}else {
			audioManager.setSpeakerphoneOn(prefs.getBoolean("savedSpeakerPhone", false));
		}
		audioManager.setMode(prefs.getInt("savedMode", AudioManager.MODE_NORMAL));
		

		Editor ed = prefs.edit();
		ed.putBoolean("isSavedAudioState", false);
		ed.commit();
	}
 
Example 30
Source Project: zapp   Source File: SwipeablePlayerView.java    License: MIT License 5 votes vote down vote up
private void init(Context context) {
	controlView = (PlayerControlView) getChildAt(2);
	window = ((Activity) context).getWindow();
	audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);

	volumeIndicator = new SwipeIndicatorView(context);
	volumeIndicator.setIconResId(R.drawable.ic_volume_up_white_24dp);
	addView(volumeIndicator, new LayoutParams(INDICATOR_WIDTH, ViewGroup.LayoutParams.MATCH_PARENT, Gravity.END));

	brightnessIndicator = new SwipeIndicatorView(context);
	brightnessIndicator.setIconResId(R.drawable.ic_brightness_6_white_24dp);
	addView(brightnessIndicator, new LayoutParams(INDICATOR_WIDTH, ViewGroup.LayoutParams.MATCH_PARENT, Gravity.START));

	gestureDetector = new GestureDetector(context.getApplicationContext(), new WipingControlGestureListener());
	gestureDetector.setIsLongpressEnabled(false);

	scaleGestureDetector = new ScaleGestureDetector(context.getApplicationContext(), new ScaleGestureListener());

	setOnTouchListener(this);
	setAspectRatioListener(this);

	setLayoutTransition(new LayoutTransition());

	settingsRepository = new SettingsRepository(getContext());
	if (settingsRepository.getIsPlayerZoomed()) {
		setZoomStateCropped();
	} else {
		setZoomStateBoxed();
	}
}