List of usage examples for android.media AudioManager USE_DEFAULT_STREAM_TYPE
int USE_DEFAULT_STREAM_TYPE
To view the source code for android.media AudioManager USE_DEFAULT_STREAM_TYPE.
Click Source Link
From source file:net.hyx.app.volumenotification.factory.NotificationFactory.java
private int getStreamType(int id) { int index = id - 1; if (index >= 0 && index < STREAM_TYPES.length) { return STREAM_TYPES[index]; }/*from w w w . j ava2 s. c om*/ return AudioManager.USE_DEFAULT_STREAM_TYPE; }
From source file:androidx.media.MediaSession2ImplBase.java
private PlaybackInfo createPlaybackInfo(VolumeProviderCompat volumeProvider, AudioAttributesCompat attrs) { PlaybackInfo info;/* w w w. j a v a2 s. co m*/ if (volumeProvider == null) { int stream; if (attrs == null) { stream = AudioManager.STREAM_MUSIC; } else { stream = attrs.getVolumeControlStream(); if (stream == AudioManager.USE_DEFAULT_STREAM_TYPE) { // It may happen if the AudioAttributes doesn't have usage. // Change it to the STREAM_MUSIC because it's not supported by audio manager // for querying volume level. stream = AudioManager.STREAM_MUSIC; } } int controlType = VolumeProviderCompat.VOLUME_CONTROL_ABSOLUTE; if (Build.VERSION.SDK_INT >= 21 && mAudioManager.isVolumeFixed()) { controlType = VolumeProviderCompat.VOLUME_CONTROL_FIXED; } info = PlaybackInfo.createPlaybackInfo(PlaybackInfo.PLAYBACK_TYPE_LOCAL, attrs, controlType, mAudioManager.getStreamMaxVolume(stream), mAudioManager.getStreamVolume(stream)); } else { info = PlaybackInfo.createPlaybackInfo(PlaybackInfo.PLAYBACK_TYPE_REMOTE, attrs, volumeProvider.getVolumeControl(), volumeProvider.getMaxVolume(), volumeProvider.getCurrentVolume()); } return info; }
From source file:edu.sfsu.csc780.chathub.ui.activities.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); DesignUtils.applyColorfulTheme(this); setContentView(R.layout.activity_main); mProgressBar = (ProgressBar) findViewById(R.id.progressBar); mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); // Set default username is anonymous. mUsername = ANONYMOUS;/*from www . j a va 2 s . com*/ //Initialize Auth mAuth = FirebaseAuth.getInstance(); mUser = mAuth.getCurrentUser(); if (mUser == null) { startActivity(new Intent(this, SignInActivity.class)); finish(); return; } else { mUsername = mUser.getDisplayName(); if (mUser.getPhotoUrl() != null) { mPhotoUrl = mUser.getPhotoUrl().toString(); } } AudioUtil.startAudioListener(this); mSinchClient = Sinch.getSinchClientBuilder().context(getApplicationContext()) .applicationKey(APIKeys.SINCH_API_KEY).applicationSecret(APIKeys.SINCH_APP_SECRET) .environmentHost("sandbox.sinch.com") .userId(UserUtil.parseUsername(mSharedPreferences.getString("username", "anonymous"))).build(); mSinchClient.setSupportCalling(true); mCurrentChannel = mSharedPreferences.getString("currentChannel", "general"); mCurrChanTextView = (TextView) findViewById(R.id.currentChannelName); mCurrChanTextView.setText(ChannelUtil.getChannelDisplayName(mCurrentChannel, this)); mGoogleApiClient = new GoogleApiClient.Builder(this) .enableAutoManage(this /* FragmentActivity */, this /* OnConnectionFailedListener */) .addApi(Auth.GOOGLE_SIGN_IN_API).build(); // Initialize ProgressBar and RecyclerView. mMessageRecyclerView = (RecyclerView) findViewById(R.id.messageRecyclerView); mLinearLayoutManager = new LinearLayoutManager(this); mLinearLayoutManager.setStackFromEnd(true); mMessageRecyclerView.setLayoutManager(mLinearLayoutManager); mChannelAdd = (RelativeLayout) findViewById(R.id.channelAdd); mToolBar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(mToolBar); mToolBar.setTitleTextColor(Color.WHITE); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawerLayout); mDrawerLayout.setStatusBarBackgroundColor(ContextCompat.getColor(this, R.color.colorPrimary)); mFirebaseAdapter = MessageUtil.getFirebaseAdapter(this, this, /* MessageLoadListener */ mLinearLayoutManager, mMessageRecyclerView, mImageClickListener); mMessageRecyclerView.setAdapter(mFirebaseAdapter); mProgressBar.setVisibility(ProgressBar.INVISIBLE); mMessageEditText = (EditText) findViewById(R.id.messageEditText); mMessageEditText.setFilters(new InputFilter[] { new InputFilter.LengthFilter(MSG_LENGTH_LIMIT) }); mMessageEditText.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { } @Override public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { if (charSequence.toString().trim().length() > 0) { mSendButton.setEnabled(true); } else { mSendButton.setEnabled(false); } } @Override public void afterTextChanged(Editable editable) { } }); mSendButton = (FloatingActionButton) findViewById(R.id.sendButton); mSendButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { // Send messages on click. mMessageRecyclerView.scrollToPosition(0); ChatMessage chatMessage = new ChatMessage(mMessageEditText.getText().toString(), mUsername, mPhotoUrl, mCurrentChannel); MessageUtil.send(chatMessage, MainActivity.this); mMessageEditText.setText(""); } }); mImageButton = (ImageButton) findViewById(R.id.shareImageButton); mImageButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { pickImage(); } }); mPhotoButton = (ImageButton) findViewById(R.id.cameraButton); mPhotoButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { dispatchTakePhotoIntent(); } }); mLocationButton = (ImageButton) findViewById(R.id.locationButton); mLocationButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { loadMap(); } }); mChannelAdd.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent intent = new Intent(MainActivity.this, ChannelSearchActivity.class); startActivityForResult(intent, REQUEST_NEW_CHANNEL); } }); SearchView jumpSearchView = (SearchView) findViewById(R.id.jumpSearch); int id = jumpSearchView.getContext().getResources().getIdentifier("android:id/search_src_text", null, null); TextView textView = (TextView) jumpSearchView.findViewById(id); textView.setTextColor(Color.WHITE); textView.setHintTextColor(Color.WHITE); jumpSearchView.setIconified(false); jumpSearchView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Toast.makeText(MainActivity.this, "Not implemented", Toast.LENGTH_SHORT).show(); } }); mNavRecyclerView = (RecyclerView) findViewById(R.id.navRecyclerView); LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this); mNavRecyclerView.setLayoutManager(linearLayoutManager); mNavRecyclerView.setAdapter(ChannelUtil.getFirebaseAdapterForUserChannelList(mChannelClickListener, mAuth.getCurrentUser().getDisplayName())); RecyclerView userListRecyclerView = (RecyclerView) findViewById(R.id.userListRecyclerView); LinearLayoutManager linearLayoutManager2 = new LinearLayoutManager(this); userListRecyclerView.setLayoutManager(linearLayoutManager2); userListRecyclerView.setAdapter(UserUtil.getFirebaseAdapterForUserList(mChannelClickListener)); Button voiceCallButton = (Button) findViewById(R.id.voiceCall); mCallProgressTextView = (TextView) findViewById(R.id.callinprogress); final AudioManager audioManager = (AudioManager) getApplicationContext() .getSystemService(Context.AUDIO_SERVICE); voiceCallButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { CallClient callClient = mSinchClient.getCallClient(); if (canCall) { call = callClient.callConference("General"); call.addCallListener(new CallListener() { @Override public void onCallProgressing(Call call) { //setVolumeControlStream(AudioManager.STREAM_VOICE_CALL); audioManager.adjustStreamVolume(AudioManager.STREAM_VOICE_CALL, AudioManager.ADJUST_RAISE, 10); Log.d("Call", "Call progressing"); } @Override public void onCallEstablished(Call call) { setVolumeControlStream(AudioManager.STREAM_VOICE_CALL); mCallProgressTextView.setVisibility(View.VISIBLE); Log.d("Call", "Calling now"); } @Override public void onCallEnded(Call call) { setVolumeControlStream(AudioManager.USE_DEFAULT_STREAM_TYPE); Log.d("Call", "Stopped calling"); mCallProgressTextView.setVisibility(View.INVISIBLE); } @Override public void onShouldSendPushNotification(Call call, List<PushPair> list) { Log.d("Call", "Push"); } }); } } }); Button endCallButton = (Button) findViewById(R.id.endCall); endCallButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (call != null) { call.hangup(); call = null; } } }); }
From source file:com.farmerbb.taskbar.activity.ContextMenuActivity.java
@SuppressWarnings("deprecation") @TargetApi(Build.VERSION_CODES.N_MR1)/* w w w. ja v a 2 s.co m*/ @Override public boolean onPreferenceClick(Preference p) { UserManager userManager = (UserManager) getSystemService(USER_SERVICE); LauncherApps launcherApps = (LauncherApps) getSystemService(LAUNCHER_APPS_SERVICE); boolean appIsValid = isStartButton || isOverflowMenu || !launcherApps.getActivityList(getIntent().getStringExtra("package_name"), userManager.getUserForSerialNumber(userId)).isEmpty(); if (appIsValid) switch (p.getKey()) { case "app_info": startFreeformActivity(); launcherApps.startAppDetailsActivity(ComponentName.unflattenFromString(componentName), userManager.getUserForSerialNumber(userId), null, null); showStartMenu = false; shouldHideTaskbar = true; contextMenuFix = false; break; case "uninstall": if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && isInMultiWindowMode()) { Intent intent2 = new Intent(ContextMenuActivity.this, DummyActivity.class); intent2.putExtra("uninstall", packageName); intent2.putExtra("user_id", userId); startFreeformActivity(); startActivity(intent2); } else { startFreeformActivity(); Intent intent2 = new Intent(Intent.ACTION_DELETE, Uri.parse("package:" + packageName)); intent2.putExtra(Intent.EXTRA_USER, userManager.getUserForSerialNumber(userId)); try { startActivity(intent2); } catch (ActivityNotFoundException e) { /* Gracefully fail */ } } showStartMenu = false; shouldHideTaskbar = true; contextMenuFix = false; break; case "open_taskbar_settings": startFreeformActivity(); Intent intent2 = new Intent(this, MainActivity.class); intent2.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); startActivity(intent2); showStartMenu = false; shouldHideTaskbar = true; contextMenuFix = false; break; case "quit_taskbar": Intent quitIntent = new Intent("com.farmerbb.taskbar.QUIT"); quitIntent.setPackage(BuildConfig.APPLICATION_ID); sendBroadcast(quitIntent); showStartMenu = false; shouldHideTaskbar = true; contextMenuFix = false; break; case "pin_app": PinnedBlockedApps pba = PinnedBlockedApps.getInstance(this); if (pba.isPinned(componentName)) pba.removePinnedApp(this, componentName); else { Intent intent = new Intent(); intent.setComponent(ComponentName.unflattenFromString(componentName)); LauncherActivityInfo appInfo = launcherApps.resolveActivity(intent, userManager.getUserForSerialNumber(userId)); if (appInfo != null) { AppEntry newEntry = new AppEntry(packageName, componentName, appName, IconCache.getInstance(this).getIcon(this, getPackageManager(), appInfo), true); newEntry.setUserId(userId); pba.addPinnedApp(this, newEntry); } } break; case "block_app": PinnedBlockedApps pba2 = PinnedBlockedApps.getInstance(this); if (pba2.isBlocked(componentName)) pba2.removeBlockedApp(this, componentName); else { pba2.addBlockedApp(this, new AppEntry(packageName, componentName, appName, null, false)); } break; case "show_window_sizes": getPreferenceScreen().removeAll(); addPreferencesFromResource(R.xml.pref_context_menu_window_size_list); findPreference("window_size_standard").setOnPreferenceClickListener(this); findPreference("window_size_large").setOnPreferenceClickListener(this); findPreference("window_size_fullscreen").setOnPreferenceClickListener(this); findPreference("window_size_half_left").setOnPreferenceClickListener(this); findPreference("window_size_half_right").setOnPreferenceClickListener(this); findPreference("window_size_phone_size").setOnPreferenceClickListener(this); SharedPreferences pref = U.getSharedPreferences(this); if (pref.getBoolean("save_window_sizes", true)) { String windowSizePref = SavedWindowSizes.getInstance(this).getWindowSize(this, packageName); CharSequence title = findPreference("window_size_" + windowSizePref).getTitle(); findPreference("window_size_" + windowSizePref).setTitle('\u2713' + " " + title); } if (U.isOPreview()) { U.showToast(this, R.string.window_sizes_not_available); } secondaryMenu = true; break; case "window_size_standard": case "window_size_large": case "window_size_fullscreen": case "window_size_half_left": case "window_size_half_right": case "window_size_phone_size": String windowSize = p.getKey().replace("window_size_", ""); SharedPreferences pref2 = U.getSharedPreferences(this); if (pref2.getBoolean("save_window_sizes", true)) { SavedWindowSizes.getInstance(this).setWindowSize(this, packageName, windowSize); } startFreeformActivity(); U.launchApp(getApplicationContext(), packageName, componentName, userId, windowSize, false, true); showStartMenu = false; shouldHideTaskbar = true; contextMenuFix = false; break; case "app_shortcuts": getPreferenceScreen().removeAll(); generateShortcuts(); secondaryMenu = true; break; case "shortcut_1": case "shortcut_2": case "shortcut_3": case "shortcut_4": case "shortcut_5": U.startShortcut(getApplicationContext(), packageName, componentName, shortcuts.get(Integer.parseInt(p.getKey().replace("shortcut_", "")) - 1)); showStartMenu = false; shouldHideTaskbar = true; contextMenuFix = false; break; case "start_menu_apps": startFreeformActivity(); Intent intent = null; SharedPreferences pref3 = U.getSharedPreferences(this); switch (pref3.getString("theme", "light")) { case "light": intent = new Intent(this, SelectAppActivity.class); break; case "dark": intent = new Intent(this, SelectAppActivityDark.class); break; } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && pref3.getBoolean("freeform_hack", false) && intent != null && isInMultiWindowMode()) { intent.putExtra("no_shadow", true); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT); U.launchAppMaximized(getApplicationContext(), intent); } else startActivity(intent); showStartMenu = false; shouldHideTaskbar = true; contextMenuFix = false; break; case "volume": AudioManager audio = (AudioManager) getSystemService(AUDIO_SERVICE); audio.adjustSuggestedStreamVolume(AudioManager.ADJUST_SAME, AudioManager.USE_DEFAULT_STREAM_TYPE, AudioManager.FLAG_SHOW_UI); showStartMenu = false; shouldHideTaskbar = true; contextMenuFix = false; break; case "file_manager": Intent fileManagerIntent; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { startFreeformActivity(); fileManagerIntent = new Intent("android.provider.action.BROWSE"); } else { fileManagerIntent = new Intent("android.provider.action.BROWSE_DOCUMENT_ROOT"); fileManagerIntent.setComponent( ComponentName.unflattenFromString("com.android.documentsui/.DocumentsActivity")); } fileManagerIntent.addCategory(Intent.CATEGORY_DEFAULT); fileManagerIntent .setData(Uri.parse("content://com.android.externalstorage.documents/root/primary")); try { startActivity(fileManagerIntent); } catch (ActivityNotFoundException e) { U.showToast(this, R.string.lock_device_not_supported); } showStartMenu = false; shouldHideTaskbar = true; contextMenuFix = false; break; case "system_settings": startFreeformActivity(); Intent settingsIntent = new Intent(Settings.ACTION_SETTINGS); try { startActivity(settingsIntent); } catch (ActivityNotFoundException e) { U.showToast(this, R.string.lock_device_not_supported); } showStartMenu = false; shouldHideTaskbar = true; contextMenuFix = false; break; case "lock_device": U.lockDevice(this); showStartMenu = false; shouldHideTaskbar = true; contextMenuFix = false; break; case "power_menu": U.sendAccessibilityAction(this, AccessibilityService.GLOBAL_ACTION_POWER_DIALOG); showStartMenu = false; shouldHideTaskbar = true; contextMenuFix = false; break; case "change_wallpaper": Intent intent3 = Intent.createChooser(new Intent(Intent.ACTION_SET_WALLPAPER), getString(R.string.set_wallpaper)); intent3.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); U.launchAppMaximized(getApplicationContext(), intent3); showStartMenu = false; shouldHideTaskbar = true; contextMenuFix = false; break; } if (!secondaryMenu) finish(); return true; }
From source file:org.telegram.ui.Components.ChatActivityEnterView.java
@Override public void didReceivedNotification(int id, Object... args) { if (id == NotificationCenter.emojiDidLoaded) { if (emojiView != null) { emojiView.invalidateViews(); }/*from w w w.ja v a2 s .co m*/ if (botKeyboardView != null) { botKeyboardView.invalidateViews(); } } else if (id == NotificationCenter.recordProgressChanged) { long t = (Long) args[0]; Long time = t / 1000; int ms = (int) (t % 1000L) / 10; String str = String.format("%02d:%02d.%02d", time / 60, time % 60, ms); if (lastTimeString == null || !lastTimeString.equals(str)) { if (time % 5 == 0) { MessagesController.getInstance().sendTyping(dialog_id, 1, 0); } if (recordTimeText != null) { recordTimeText.setText(str); } } if (recordCircle != null) { recordCircle.setAmplitude((Double) args[1]); } } else if (id == NotificationCenter.closeChats) { if (messageEditText != null && messageEditText.isFocused()) { AndroidUtilities.hideKeyboard(messageEditText); } } else if (id == NotificationCenter.recordStartError || id == NotificationCenter.recordStopped) { if (recordingAudioVideo) { MessagesController.getInstance().sendTyping(dialog_id, 2, 0); recordingAudioVideo = false; updateRecordIntefrace(); } } else if (id == NotificationCenter.recordStarted) { if (!recordingAudioVideo) { recordingAudioVideo = true; updateRecordIntefrace(); } } else if (id == NotificationCenter.audioDidSent) { audioToSend = (TLRPC.TL_document) args[0]; audioToSendPath = (String) args[1]; if (audioToSend != null) { if (recordedAudioPanel == null) { return; } TLRPC.TL_message message = new TLRPC.TL_message(); message.out = true; message.id = 0; message.to_id = new TLRPC.TL_peerUser(); message.to_id.user_id = message.from_id = UserConfig.getClientUserId(); message.date = (int) (System.currentTimeMillis() / 1000); message.message = "-1"; message.attachPath = audioToSendPath; message.media = new TLRPC.TL_messageMediaDocument(); message.media.document = audioToSend; message.flags |= TLRPC.MESSAGE_FLAG_HAS_MEDIA | TLRPC.MESSAGE_FLAG_HAS_FROM_ID; audioToSendMessageObject = new MessageObject(message, null, false); recordedAudioPanel.setAlpha(1.0f); recordedAudioPanel.setVisibility(VISIBLE); int duration = 0; for (int a = 0; a < audioToSend.attributes.size(); a++) { TLRPC.DocumentAttribute attribute = audioToSend.attributes.get(a); if (attribute instanceof TLRPC.TL_documentAttributeAudio) { duration = attribute.duration; break; } } for (int a = 0; a < audioToSend.attributes.size(); a++) { TLRPC.DocumentAttribute attribute = audioToSend.attributes.get(a); if (attribute instanceof TLRPC.TL_documentAttributeAudio) { if (attribute.waveform == null || attribute.waveform.length == 0) { attribute.waveform = MediaController.getInstance().getWaveform(audioToSendPath); } recordedAudioSeekBar.setWaveform(attribute.waveform); break; } } recordedAudioTimeTextView.setText(String.format("%d:%02d", duration / 60, duration % 60)); closeKeyboard(); hidePopup(false); checkSendButton(false); } else { if (delegate != null) { delegate.onMessageSend(null); } } } else if (id == NotificationCenter.audioRouteChanged) { if (parentActivity != null) { boolean frontSpeaker = (Boolean) args[0]; parentActivity.setVolumeControlStream( frontSpeaker ? AudioManager.STREAM_VOICE_CALL : AudioManager.USE_DEFAULT_STREAM_TYPE); } } else if (id == NotificationCenter.audioDidReset) { if (audioToSendMessageObject != null && !MediaController.getInstance().isPlayingAudio(audioToSendMessageObject)) { recordedAudioPlayButton.setImageDrawable(playDrawable); recordedAudioSeekBar.setProgress(0); } } else if (id == NotificationCenter.audioProgressDidChanged) { Integer mid = (Integer) args[0]; if (audioToSendMessageObject != null && MediaController.getInstance().isPlayingAudio(audioToSendMessageObject)) { MessageObject player = MediaController.getInstance().getPlayingMessageObject(); audioToSendMessageObject.audioProgress = player.audioProgress; audioToSendMessageObject.audioProgressSec = player.audioProgressSec; if (!recordedAudioSeekBar.isDragging()) { recordedAudioSeekBar.setProgress(audioToSendMessageObject.audioProgress); } } } else if (id == NotificationCenter.featuredStickersDidLoaded) { if (emojiButton != null) { emojiButton.invalidate(); } } }