Example usage for android.media AudioManager FLAG_SHOW_UI

List of usage examples for android.media AudioManager FLAG_SHOW_UI

Introduction

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

Prototype

int FLAG_SHOW_UI

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

Click Source Link

Document

Show a toast containing the current volume.

Usage

From source file:com.darly.im.ui.CCPActivityBase.java

/**
 *
 * @param keyCode/*from ww  w .  ja  v  a2 s  .  c  om*/
 * @param event
 * @return
 */
public boolean onKeyDown(int keyCode, KeyEvent event) {

    if ((event.getKeyCode() == KeyEvent.KEYCODE_VOLUME_UP) && mAudioManager != null) {
        int streamVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC);

        if (streamVolume >= mMusicMaxVolume) {
            LogUtil.d(LogUtil.getLogUtilsTag(BaseFragment.class), "has set the max volume");
            return true;
        }

        int mean = mMusicMaxVolume / 7;
        if (mean == 0) {
            mean = 1;
        }

        mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, streamVolume + mean,
                AudioManager.FLAG_PLAY_SOUND | AudioManager.FLAG_SHOW_UI);
    }
    if ((event.getKeyCode() == KeyEvent.KEYCODE_VOLUME_DOWN) && mAudioManager != null) {
        int streamVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
        int mean = mMusicMaxVolume / 7;
        if (mean == 0) {
            mean = 1;
        }

        mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, streamVolume - mean,
                AudioManager.FLAG_PLAY_SOUND | AudioManager.FLAG_SHOW_UI);
        return true;
    }
    return false;
}

From source file:com.lybeat.lilyplayer.widget.media.IjkVideoView.java

private void initGestureScanner(final Context context) {
    slop = ViewConfiguration.get(context).getScaledTouchSlop();
    screenWidth = ScreenUtil.getScreenWidth(context);
    gestureDetector = new GestureDetectorCompat(context, new LilyGestureListener());
    setOnTouchListener(new OnTouchListener() {
        @Override/*from  w  w w .j a  v  a 2s .  c om*/
        public boolean onTouch(View view, MotionEvent motionEvent) {
            switch (motionEvent.getAction()) {
            case MotionEvent.ACTION_UP:
                if (adjustProgress) {
                    adjustProgress = false;
                    int newPosition = (int) (getCurrentPosition() + scrollX / screenWidth * 1000 * 90);
                    if (newPosition < 0) {
                        seekTo(0);
                    } else {
                        seekTo(newPosition);
                    }
                    start();
                    mAdjustProgressView.setVisibility(GONE);
                    if (mMediaController.isShowing()) {
                        showAllBoard();
                    }
                }
                scrollX = 0;
                scrollY = 0;
                level = 0;
                adjustVolume = false;
                adjustBrightness = false;
                break;
            case MotionEvent.ACTION_DOWN:
                lastX = motionEvent.getRawX();
                lastY = motionEvent.getRawY();
                if (motionEvent.getRawX() > screenWidth / 2 + 150) {
                    adjustVolume = true;
                    adjustBrightness = false;
                } else if (motionEvent.getRawX() < screenWidth / 2 - 150) {
                    adjustBrightness = true;
                    adjustVolume = false;
                }
                break;
            case MotionEvent.ACTION_MOVE:
                if (adjustProgress) {
                    break;
                }
                if (Math.abs(motionEvent.getRawY() - lastY) > Math.abs(motionEvent.getRawX() - lastX)) {

                    AudioManager audioManager = (AudioManager) mAppContext
                            .getSystemService(Context.AUDIO_SERVICE);
                    if (motionEvent.getRawY() > lastY) {
                        level += motionEvent.getRawY() - lastY;
                        if (level > slop) {
                            if (adjustVolume) {
                                audioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC,
                                        AudioManager.ADJUST_LOWER, AudioManager.FLAG_SHOW_UI);
                            } else if (adjustBrightness) {
                                float brightness = ScreenUtil.getScreenBrightness((Activity) context);
                                if (brightness <= 0.1f) {
                                    ScreenUtil.setScreenBrightness((Activity) context, 0.0f);
                                } else {
                                    ScreenUtil.setScreenBrightness((Activity) context,
                                            ScreenUtil.getScreenBrightness((Activity) context) - 0.1f);
                                }
                            }
                            level = 0;
                        }
                    } else {
                        level += lastY - motionEvent.getRawY();
                        if (level > slop) {
                            if (adjustVolume) {
                                audioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC,
                                        AudioManager.ADJUST_RAISE, AudioManager.FLAG_SHOW_UI);
                            } else if (adjustBrightness) {
                                float brightness = ScreenUtil.getScreenBrightness((Activity) context);
                                if (brightness >= 0.9f) {
                                    ScreenUtil.setScreenBrightness((Activity) context, 1.0f);
                                } else {
                                    ScreenUtil.setScreenBrightness((Activity) context,
                                            ScreenUtil.getScreenBrightness((Activity) context) + 0.1f);
                                }
                            }
                            level = 0;
                        }
                    }
                }
                lastX = motionEvent.getRawX();
                lastY = motionEvent.getRawY();
                break;
            }

            return gestureDetector.onTouchEvent(motionEvent);
        }
    });
}

From source file:fm.feed.android.playersdk.view.PlayerView.java

private void initializeView() {
    RelativeLayout rootView = (RelativeLayout) inflate(getContext(), R.layout.view_player, this);
    mTitle = (TextView) rootView.findViewById(R.id.pu_title);
    mArtist = (TextView) rootView.findViewById(R.id.pu_artist);
    mAlbum = (TextView) rootView.findViewById(R.id.pu_album);
    mPrefix = (TextView) rootView.findViewById(R.id.pu_prefix);
    mSuffix = (TextView) rootView.findViewById(R.id.pu_suffix);
    mProgressBar = (ProgressBar) rootView.findViewById(R.id.pu_progress);

    LinearLayout topContainer = (LinearLayout) rootView.findViewById(R.id.pu_top_icons);
    LinearLayout bottomContainer = (LinearLayout) rootView.findViewById(R.id.pu_bottom_icons);

    // We need to create the SVGImageView instances and add them programmatically.
    mDislike = newSvgImage(1, ImageView.ScaleType.FIT_START);
    mLike = newSvgImage(2, ImageView.ScaleType.FIT_CENTER);
    mPlayPause = newSvgImage(2, ImageView.ScaleType.FIT_CENTER);
    mSkip = newSvgImage(1, ImageView.ScaleType.FIT_END);
    mVolume = newSvgImage(1, ImageView.ScaleType.FIT_START);
    mShare = newSvgImage(1, ImageView.ScaleType.FIT_END);

    // Set the SVG resource to the SVGImageView
    setSvgResource(mDislike, R.drawable.ic_thumbdown_faded, R.string.accessibility_dislike);
    setSvgResource(mLike, R.drawable.ic_thumbup_faded, R.string.accessibility_like);
    setSvgResource(mPlayPause, R.drawable.ic_play_faded, R.string.accessibility_play);
    setSvgResource(mSkip, R.drawable.ic_skip_disabled, R.string.accessibility_skip_disabled);
    setSvgResource(mVolume, R.drawable.ic_speakerhigh_faded, R.string.accessibility_volume_muted);
    setSvgResource(mShare, R.drawable.ic_share_faded, R.string.accessibility_share);

    // Add SVGImageViews to the layout.
    topContainer.addView(mDislike);//from  ww  w.j  ava 2  s .co m
    topContainer.addView(mLike);
    topContainer.addView(mPlayPause);
    topContainer.addView(mSkip);
    bottomContainer.addView(mVolume);
    bottomContainer.addView(mShare);

    mDislike.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (!mPlayer.hasPlay()) {
                return;
            }

            Play.LikeState likeState = mPlayer.getPlay().getLikeState();
            switch (likeState) {
            case NONE:
                setSvgResource(mDislike, R.drawable.ic_thumbdown_normal, R.string.accessibility_disliked);
                mPlayer.dislike();
                break;
            case LIKED:
                setSvgResource(mLike, R.drawable.ic_thumbup_faded, R.string.accessibility_like);
                mPlayer.unlike();
                break;
            case DISLIKED:
                // Do nothing
                break;
            }
        }
    });

    mLike.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (!mPlayer.hasPlay()) {
                return;
            }

            Play.LikeState likeState = mPlayer.getPlay().getLikeState();
            switch (likeState) {
            case NONE:
                setSvgResource(mLike, R.drawable.ic_thumbup_normal, R.string.accessibility_liked);
                mPlayer.like();
                break;
            case LIKED:
                // Do nothing
                break;
            case DISLIKED:
                setSvgResource(mDislike, R.drawable.ic_thumbdown_faded, R.string.accessibility_unlike);
                setSvgResource(mLike, R.drawable.ic_thumbup_normal, R.string.accessibility_liked);
                mPlayer.like();
                break;
            }
        }
    });
    mPlayPause.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (mPlayer.getState() == PlayInfo.State.PLAYING) {
                mPlayer.pause();
            } else {
                mPlayer.play();
            }
        }
    });
    mSkip.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (mPlayer.isSkippable()) {
                setSvgResource(mSkip, R.drawable.ic_skip_normal, R.string.accessibility_skipping);
                mPlayer.skip();
            }
        }
    });
    mShare.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (mPlayer == null || !mPlayer.hasPlay()) {
                Log.i(TAG, "Cannot share if not playing");
                return;
            }

            Intent intent = new Intent(Intent.ACTION_SEND);
            intent.setType("text/plain");
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);

            String subject = mShareSubject;
            String body = mShareBody;
            if (subject == null) {
                subject = getContext().getString(R.string.share_subject_template);
            }
            if (body == null) {
                Play play = mPlayer.getPlay();
                String title = play.getAudioFile().getTrack().getTitle();
                String artist = play.getAudioFile().getArtist().getName();
                String album = play.getAudioFile().getRelease().getTitle();

                body = getContext().getString(R.string.share_body_template, title, artist, album);
            }

            // Add data to the intent, the receiving app will decide what to do with it.
            intent.putExtra(Intent.EXTRA_SUBJECT, subject);
            intent.putExtra(Intent.EXTRA_TEXT, body);

            getContext()
                    .startActivity(Intent.createChooser(intent, getContext().getString(R.string.share_via)));
        }
    });

    mVolume.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            AudioManager am = (AudioManager) getContext().getSystemService(Context.AUDIO_SERVICE);
            int volume = mAudioSettingsContentObserver.getCurrentVolume();
            am.setStreamVolume(AudioManager.STREAM_MUSIC, volume, AudioManager.FLAG_SHOW_UI);
        }
    });

    updateSpeakerUI();
}

From source file:org.ulteo.ovd.AndRdpActivity.java

@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    AudioManager audioManager;/* ww w  . ja va  2  s  . co  m*/

    if (Config.DEBUG)
        Log.i(Config.TAG, "AndRdpActivity.dispatchKeyEvent " + event);

    // Disable keypress if it is from a mouse or touchpad.
    if (event.getDeviceId() >= 0) {
        InputDevice dev = InputDevice.getDevice(event.getDeviceId());
        if (dev.getSources() == InputDevice.SOURCE_MOUSE || dev.getSources() == InputDevice.SOURCE_TOUCHPAD)
            return true;
    }

    if (event.getAction() == KeyEvent.ACTION_DOWN) {
        switch (event.getKeyCode()) {
        case KeyEvent.KEYCODE_MENU:
            OnThreeFingers(null);
            return true;
        case KeyEvent.KEYCODE_BACK:
            Log.i(Config.TAG, "Back key pressed");
            askLogoutDialog();
            return true;
        case KeyEvent.KEYCODE_VOLUME_UP:
            audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
            audioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_RAISE,
                    AudioManager.FLAG_SHOW_UI);
            return true;
        case KeyEvent.KEYCODE_VOLUME_DOWN:
            audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
            audioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_LOWER,
                    AudioManager.FLAG_SHOW_UI);
            return true;
        }
    } else if (event.getAction() == KeyEvent.ACTION_UP) {
        switch (event.getKeyCode()) {
        case KeyEvent.KEYCODE_MENU:
        case KeyEvent.KEYCODE_BACK:
        case KeyEvent.KEYCODE_VOLUME_UP:
        case KeyEvent.KEYCODE_VOLUME_DOWN:
            return true;
        }
    }

    if (isLoggedIn() && rdp.dispatchKeyEvent(event))
        return true;

    return super.dispatchKeyEvent(event);
}

From source file:edu.stanford.mobisocial.dungbeetle.ui.fragments.AppsViewFragment.java

@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
    if (event.getKeyCode() == KeyEvent.KEYCODE_VOLUME_UP) {
        if (!event.isTracking()) {
            return true;
        }/* w w  w.  j  a  v a  2s. com*/
        if (!event.isLongPress()) {
            AudioManager audio = (AudioManager) getActivity().getSystemService(Context.AUDIO_SERVICE);
            audio.adjustVolume(AudioManager.ADJUST_RAISE,
                    AudioManager.FLAG_PLAY_SOUND | AudioManager.FLAG_SHOW_UI);
            return true;
        }
    }
    if (event.getKeyCode() == KeyEvent.KEYCODE_VOLUME_DOWN) {
        if (!event.isTracking()) {
            return true;
        }
        if (!event.isLongPress()) {
            AudioManager audio = (AudioManager) getActivity().getSystemService(Context.AUDIO_SERVICE);
            audio.adjustVolume(AudioManager.ADJUST_LOWER,
                    AudioManager.FLAG_PLAY_SOUND | AudioManager.FLAG_SHOW_UI);
            return true;
        }
    }
    return false;
}

From source file:pct.droid.fragments.VideoPlayerFragment.java

private void setAudioVolume(int vol) {
    mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, vol, 0);

    /* Since android 4.3, the safe volume warning dialog is displayed only with the FLAG_SHOW_UI flag.
     * We don't want to always show the default UI volume, so show it only when volume is not set. */
    int newVol = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
    if (vol != newVol)
        mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, vol, AudioManager.FLAG_SHOW_UI);

    mTouchAction = TOUCH_VOLUME;/*from   w w  w .  j  a  v  a 2  s .  c o  m*/
    showPlayerInfo(getString(R.string.volume) + '\u00A0' + Integer.toString(vol));
}

From source file:com.smc.tw.waltz.MainActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (DEBUG)//from w w  w  .  j  a  va  2  s  . c o m
        Log.d(TAG, "onKeyDown code:" + keyCode);

    switch (keyCode) {
    case KeyEvent.KEYCODE_VOLUME_UP: {
        mAudioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_RAISE,
                AudioManager.FLAG_SHOW_UI);

        return true;
    }

    case KeyEvent.KEYCODE_VOLUME_DOWN: {
        mAudioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_LOWER,
                AudioManager.FLAG_SHOW_UI);

        return true;
    }

    default:
        break;
    }

    return super.onKeyDown(keyCode, event);
}

From source file:com.google.android.exoplayer2.demo.MediaPlayerFragment.java

private void setAudioVolume(int vol, boolean up) {
    mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, vol, 0);

    /* Since android 4.3, the safe volume warning dialog is displayed only with the FLAG_SHOW_UI flag.
     * We don't want to always show the default UI volume, so show it only when volume is not set. */
    int newVol = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
    if (vol != newVol) {
        mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, vol, AudioManager.FLAG_SHOW_UI);
    }/* w w  w . j  av a 2s.  c o m*/

    mTouchAction = TOUCH_VOLUME;
    vol = vol * 100 / mAudioMax;
    int drawableId;
    if (newVol == 0) {
        drawableId = R.drawable.ic_volume_mute_white_36dp;
    } else if (up) {
        drawableId = R.drawable.ic_volume_up_white_36dp;
    } else {
        drawableId = R.drawable.ic_volume_down_white_36dp;
    }
    setVolumeOrBrightnessInfo(getContext().getString(R.string.volume_changing, vol), drawableId);
    //        showInfoWithVerticalBar(getString(R.string.volume) + "\n" + Integer.toString(vol) + '%', 1000, vol);
}

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

@SuppressWarnings("deprecation")
@TargetApi(Build.VERSION_CODES.N_MR1)// www. j  a v  a2 s.c  o 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:com.csipsimple.ui.incall.CallActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    Log.d(TAG, "Key down : " + keyCode);
    switch (keyCode) {
    case KeyEvent.KEYCODE_VOLUME_DOWN:
    case KeyEvent.KEYCODE_VOLUME_UP:
        ////w w w.  j  a  v  a2  s  .com
        // Volume has been adjusted by the user.
        //
        Log.d(TAG, "onKeyDown: Volume button pressed");
        int action = AudioManager.ADJUST_RAISE;
        if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
            action = AudioManager.ADJUST_LOWER;
        }

        // Detect if ringing
        SipCallSession currentCallInfo = getActiveCallInfo();
        // If not any active call active
        if (currentCallInfo == null && serviceConnected) {
            break;
        }

        //TODO: adjust volume here
        if (service != null) {
            try {
                service.adjustVolume(currentCallInfo, action, AudioManager.FLAG_SHOW_UI);
            } catch (RemoteException e) {
                Log.e(TAG, "Can't adjust volume", e);
            }
        }

        return true;
    case KeyEvent.KEYCODE_CALL:
    case KeyEvent.KEYCODE_ENDCALL:
        return inCallAnswerControls.onKeyDown(keyCode, event);
    case KeyEvent.KEYCODE_SEARCH:
        // Prevent search
        return true;
    default:
        // Nothing to do
    }
    return super.onKeyDown(keyCode, event);
}