Example usage for android.media AudioManager ADJUST_SAME

List of usage examples for android.media AudioManager ADJUST_SAME

Introduction

In this page you can find the example usage for android.media AudioManager ADJUST_SAME.

Prototype

int ADJUST_SAME

To view the source code for android.media AudioManager ADJUST_SAME.

Click Source Link

Document

Maintain the previous ringer volume.

Usage

From source file:Main.java

public static void adjustVoiceToSystemSame(Context context) {
    AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
    audioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_SAME, 0);
}

From source file:net.hyx.app.volumenotification.NotificationFactory.java

void setVolume(int position) {
    int selection = settings.getButtonSelection(position);
    int direction = AudioManager.ADJUST_SAME;
    int type = STREAM_TYPES[selection];

    if (type == AudioManager.STREAM_MUSIC && settings.getToggleMute()) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            direction = AudioManager.ADJUST_TOGGLE_MUTE;
        } else {/*ww  w .jav  a  2  s  . com*/
            _mute = !_mute;
            audio.setStreamMute(type, _mute);
        }
    } else if (type == AudioManager.STREAM_RING && settings.getToggleSilent()) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            direction = AudioManager.ADJUST_TOGGLE_MUTE;
        } else {
            _silent = !_silent;
            audio.setStreamMute(type, _silent);
        }
    }
    audio.adjustStreamVolume(type, direction, AudioManager.FLAG_SHOW_UI);
}

From source file:net.hyx.app.volumenotification.factory.NotificationFactory.java

private int getStreamFlag(int type) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        if ((type == AudioManager.STREAM_MUSIC && settings.getToggleMute())
                || (type == AudioManager.STREAM_RING && settings.getToggleSilent())) {
            return AudioManager.ADJUST_TOGGLE_MUTE;
        }/* www  . j  a  va 2 s .  c  o m*/
    }
    return AudioManager.ADJUST_SAME;
}

From source file:com.kaku.weac.fragment.AlarmClockOntimeFragment.java

@Override
public void onDestroy() {
    LogUtil.d(LOG_TAG, getActivity().toString() + "onDestroy");
    super.onDestroy();
    // ??//from ww  w. ja  v a  2  s . c  o  m
    mIsRun = false;

    // ??????
    if (!mIsOnclick) {
        // ??
        nap();
    }

    // ??Activity
    if (WeacStatus.sActivityNumber <= 1) {
        // ?
        AudioPlayer.getInstance(getActivity()).stop();
    }

    // ?Activity?
    WeacStatus.sActivityNumber--;

    // If null, all callbacks and messages will be removed.
    if (mShowTimeHandler != null) {
        mShowTimeHandler.removeCallbacksAndMessages(null);
    }

    // ??
    mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, mCurrentVolume, AudioManager.ADJUST_SAME);
}

From source file:com.kaku.weac.fragment.AlarmClockOntimeFragment.java

/**
 * //from   w  ww .ja  va  2  s  .  c o  m
 */
private void playRing() {
    mAudioManager = (AudioManager) getActivity().getSystemService(Context.AUDIO_SERVICE);

    mCurrentVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
    // ?
    mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, mAlarmClock.getVolume(), AudioManager.ADJUST_SAME);

    // 
    if (mAlarmClock.getRingUrl().equals(WeacConstants.DEFAULT_RING_URL)
            || TextUtils.isEmpty(mAlarmClock.getRingUrl())) {
        // ?
        if (mAlarmClock.isVibrate()) {
            // 
            AudioPlayer.getInstance(getActivity()).playRaw(R.raw.ring_weac_alarm_clock_default, true, true);
        } else {
            AudioPlayer.getInstance(getActivity()).playRaw(R.raw.ring_weac_alarm_clock_default, true, false);
        }

        // 
    } else if (mAlarmClock.getRingUrl().equals(WeacConstants.NO_RING_URL)) {
        // ?
        if (mAlarmClock.isVibrate()) {
            AudioPlayer.getInstance(getActivity()).stop();
            AudioPlayer.getInstance(getActivity()).vibrate();
        } else {
            AudioPlayer.getInstance(getActivity()).stop();
        }
    } else {
        // ?
        if (mAlarmClock.isVibrate()) {
            AudioPlayer.getInstance(getActivity()).play(mAlarmClock.getRingUrl(), true, true);
        } else {
            AudioPlayer.getInstance(getActivity()).play(mAlarmClock.getRingUrl(), true, false);
        }
    }
}

From source file:com.farmerbb.taskbar.activity.ContextMenuActivity.java

@SuppressWarnings("deprecation")
@TargetApi(Build.VERSION_CODES.N_MR1)//from   ww  w  . java2  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;
}