Example usage for android.content Intent FLAG_ACTIVITY_BROUGHT_TO_FRONT

List of usage examples for android.content Intent FLAG_ACTIVITY_BROUGHT_TO_FRONT

Introduction

In this page you can find the example usage for android.content Intent FLAG_ACTIVITY_BROUGHT_TO_FRONT.

Prototype

int FLAG_ACTIVITY_BROUGHT_TO_FRONT

To view the source code for android.content Intent FLAG_ACTIVITY_BROUGHT_TO_FRONT.

Click Source Link

Document

This flag is not normally set by application code, but set for you by the system as described in the android.R.styleable#AndroidManifestActivity_launchMode launchMode documentation for the singleTask mode.

Usage

From source file:com.gxapplications.android.gxsuite.launcher.Launcher.java

@Override
protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);

    // Close the menu
    if (Intent.ACTION_MAIN.equals(intent.getAction())) {
        // also will cancel mWaitingForResult.
        closeSystemDialogs();/*from   w w  w.j a v  a 2  s.com*/

        final boolean alreadyOnHome = ((intent.getFlags()
                & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);

        Runnable processIntent = new Runnable() {
            public void run() {
                Folder openFolder = mWorkspace.getOpenFolder();
                // In all these cases, only animate if we're already on home
                mWorkspace.exitWidgetResizeMode();
                if (alreadyOnHome && mState == State.WORKSPACE && !mWorkspace.isTouchActive()
                        && openFolder == null) {
                    mWorkspace.moveToDefaultScreen(true);
                }

                closeFolder();
                exitSpringLoadedDragMode();

                // If we are already on home, then just animate back to the workspace,
                // otherwise, just wait until onResume to set the state back to Workspace
                if (alreadyOnHome) {
                    showWorkspace(true);
                } else {
                    mOnResumeState = State.WORKSPACE;
                }

                final View v = getWindow().peekDecorView();
                if (v != null && v.getWindowToken() != null) {
                    InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
                    imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
                }

                // Reset AllApps to its initial state
                if (!alreadyOnHome && mAppsCustomizeTabHost != null) {
                    mAppsCustomizeTabHost.reset();
                }
            }
        };

        if (alreadyOnHome && !mWorkspace.hasWindowFocus()) {
            // Delay processing of the intent to allow the status bar animation to finish
            // first in order to avoid janky animations.
            mWorkspace.postDelayed(processIntent, 350);
        } else {
            // Process the intent immediately.
            processIntent.run();
        }

    }
}

From source file:com.cognizant.trumobi.PersonaLauncher.java

@Override
protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);

    // Close the menu
    if (Intent.ACTION_MAIN.equals(intent.getAction())) {
        closeSystemDialogs();//ww w .jav a2 s . co  m

        // Set this flag so that onResume knows to close the search dialog
        // if it's open,
        // because this was a new intent (thus a press of 'home' or some
        // such) rather than
        // for example onResume being called when the user pressed the
        // 'back' button.
        mIsNewIntent = true;

        if ((intent.getFlags()
                & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) {
            if (!isAllAppsVisible() || mHomeBinding == BIND_APPS)
                fireHomeBinding(mHomeBinding, 1);
            if (mHomeBinding != BIND_APPS) {
                closeDrawer(true);

            }
            final View v = getWindow().peekDecorView();
            if (v != null && v.getWindowToken() != null) {
                InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
            }
        } else {
            closeDrawer(false);
        }
    }
}

From source file:com.android.soma.Launcher.java

@Override
protected void onNewIntent(Intent intent) {
    long startTime = 0;
    if (DEBUG_RESUME_TIME) {
        startTime = System.currentTimeMillis();
    }//from   w  ww  .j  a v a 2 s .co m
    super.onNewIntent(intent);

    // Close the menu
    if (Intent.ACTION_MAIN.equals(intent.getAction())) {
        // also will cancel mWaitingForResult.
        closeSystemDialogs();

        final boolean alreadyOnHome = mHasFocus && ((intent.getFlags()
                & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);

        if (mWorkspace == null) {
            // Can be cases where mWorkspace is null, this prevents a NPE
            return;
        }
        Folder openFolder = mWorkspace.getOpenFolder();
        // In all these cases, only animate if we're already on home
        mWorkspace.exitWidgetResizeMode();
        if (alreadyOnHome && mState == State.WORKSPACE && !mWorkspace.isTouchActive() && openFolder == null) {
            mWorkspace.moveToDefaultScreen(true);
        }

        closeFolder();
        exitSpringLoadedDragMode();

        // If we are already on home, then just animate back to the workspace,
        // otherwise, just wait until onResume to set the state back to Workspace
        if (alreadyOnHome) {
            showWorkspace(true);
        } else {
            mOnResumeState = State.WORKSPACE;
        }

        final View v = getWindow().peekDecorView();
        if (v != null && v.getWindowToken() != null) {
            InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
        }

        // Reset the apps customize page
        if (mAppsCustomizeTabHost != null) {
            mAppsCustomizeTabHost.reset();
        }
    }

    if (DEBUG_RESUME_TIME) {
        Log.d(TAG, "Time spent in onNewIntent: " + (System.currentTimeMillis() - startTime));
    }
}

From source file:xyz.klinker.blur.launcher3.Launcher.java

@Override
protected void onNewIntent(Intent intent) {
    long startTime = 0;
    if (DEBUG_RESUME_TIME) {
        startTime = System.currentTimeMillis();
    }/*from w w  w  . j  av  a  2s .  com*/
    super.onNewIntent(intent);

    // Close the menu
    if (Intent.ACTION_MAIN.equals(intent.getAction())) {
        final boolean alreadyOnHome = mHasFocus && ((intent.getFlags()
                & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);

        if (mLauncherDrawer.isDrawerOpen(Gravity.LEFT)) {
            new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    mLauncherDrawer.closeDrawer(Gravity.LEFT);
                }
            }, 300);

            return;
        } else if (mLauncherDrawer.isDrawerOpen(Gravity.RIGHT)) {
            new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    mLauncherDrawer.closeDrawer(Gravity.RIGHT);
                }
            }, 300);

            return;
        } else if (!isAllAppsVisible() && alreadyOnHome && mWorkspace.getCurrentPage() == 0
                && !mWorkspace.isInOverviewMode()) {
            new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    GestureUtils.runGesture(Launcher.this, Launcher.this, AppSettings.HOME_BUTTON);
                }
            }, 300);

            return;
        }

        // also will cancel mWaitingForResult.
        closeSystemDialogs();

        if (mWorkspace == null) {
            // Can be cases where mWorkspace is null, this prevents a NPE
            return;
        }
        // In all these cases, only animate if we're already on home
        mWorkspace.exitWidgetResizeMode();

        closeFolder(alreadyOnHome);
        exitSpringLoadedDragMode();

        // If we are already on home, then just animate back to the workspace,
        // otherwise, just wait until onResume to set the state back to Workspace
        if (alreadyOnHome) {
            showWorkspace(true);
        } else {
            mOnResumeState = State.WORKSPACE;
        }

        final View v = getWindow().peekDecorView();
        if (v != null && v.getWindowToken() != null) {
            InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
        }

        // Reset the apps view
        if (!alreadyOnHome && mAppsView != null) {
            mAppsView.scrollToTop();
        }

        // Reset the widgets view
        if (!alreadyOnHome && mWidgetsView != null) {
            mWidgetsView.scrollToTop();
        }

        if (mLauncherCallbacks != null) {
            mLauncherCallbacks.onHomeIntent();
        }
    }

    if (mLauncherCallbacks != null) {
        mLauncherCallbacks.onNewIntent(intent);
    }

    if (DEBUG_RESUME_TIME) {
        Log.d(TAG, "Time spent in onNewIntent: " + (System.currentTimeMillis() - startTime));
    }
}

From source file:com.klinker.android.launcher.launcher3.Launcher.java

@Override
protected void onNewIntent(Intent intent) {
    long startTime = 0;
    if (DEBUG_RESUME_TIME) {
        startTime = System.currentTimeMillis();
    }//from w ww.  j ava 2s .  c  om
    super.onNewIntent(intent);

    // Close the menu
    if (Intent.ACTION_MAIN.equals(intent.getAction())) {
        final boolean alreadyOnHome = mHasFocus && ((intent.getFlags()
                & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);

        if (mLauncherDrawer.isDrawerOpen(Gravity.LEFT)) {
            new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    mLauncherDrawer.closeDrawer(Gravity.LEFT);
                }
            }, 300);

            return;
        } else if (mLauncherDrawer.isDrawerOpen(Gravity.RIGHT)) {
            new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    mLauncherDrawer.closeDrawer(Gravity.RIGHT);
                }
            }, 300);

            return;
        } else if (!isAllAppsVisible() && alreadyOnHome && mWorkspace.getCurrentPage() == 0
                && !mWorkspace.isInOverviewMode()) {
            new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    GestureUtils.runGesture(Launcher.this, Launcher.this, AppSettings.HOME_BUTTON);
                }
            }, 300);

            return;
        }

        // also will cancel mWaitingForResult.
        closeSystemDialogs();

        if (mWorkspace == null) {
            // Can be cases where mWorkspace is null, this prevents a NPE
            return;
        }
        Folder openFolder = mWorkspace.getOpenFolder();
        // In all these cases, only animate if we're already on home
        mWorkspace.exitWidgetResizeMode();

        boolean moveToDefaultScreen = mLauncherCallbacks != null
                ? mLauncherCallbacks.shouldMoveToDefaultScreenOnHomeIntent()
                : true;
        if (alreadyOnHome && mState == State.WORKSPACE && !mWorkspace.isTouchActive() && openFolder == null
                && moveToDefaultScreen) {
            mWorkspace.moveToDefaultScreen(true);
        }

        closeFolder();
        exitSpringLoadedDragMode();

        // If we are already on home, then just animate back to the workspace,
        // otherwise, just wait until onResume to set the state back to Workspace
        if (alreadyOnHome) {
            showWorkspace(true);
        } else {
            mOnResumeState = State.WORKSPACE;
        }

        final View v = getWindow().peekDecorView();
        if (v != null && v.getWindowToken() != null) {
            InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
        }

        // Reset the apps view
        if (!alreadyOnHome && mAppsView != null) {
            mAppsView.scrollToTop();
        }

        // Reset the widgets view
        if (!alreadyOnHome && mWidgetsView != null) {
            mWidgetsView.scrollToTop();
        }

        if (mLauncherCallbacks != null) {
            mLauncherCallbacks.onHomeIntent();
        }
    }

    if (DEBUG_RESUME_TIME) {
        Log.d(TAG, "Time spent in onNewIntent: " + (System.currentTimeMillis() - startTime));
    }

    if (mLauncherCallbacks != null) {
        mLauncherCallbacks.onNewIntent(intent);
    }
}

From source file:com.android.launcher3.Launcher.java

@Override
protected void onNewIntent(Intent intent) {
    long startTime = 0;
    if (DEBUG_RESUME_TIME) {
        startTime = System.currentTimeMillis();
    }//from w w  w .java 2 s .  com
    super.onNewIntent(intent);

    boolean alreadyOnHome = mHasFocus && ((intent.getFlags()
            & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);

    // Check this condition before handling isActionMain, as this will get reset.
    boolean shouldMoveToDefaultScreen = alreadyOnHome && mState == State.WORKSPACE
            && getTopFloatingView() == null;

    boolean isActionMain = Intent.ACTION_MAIN.equals(intent.getAction());
    if (isActionMain) {
        // also will cancel mWaitingForResult.
        closeSystemDialogs();

        if (mWorkspace == null) {
            // Can be cases where mWorkspace is null, this prevents a NPE
            return;
        }
        // In all these cases, only animate if we're already on home
        mWorkspace.exitWidgetResizeMode();

        closeFolder(alreadyOnHome);
        closeShortcutsContainer(alreadyOnHome);
        exitSpringLoadedDragMode();

        // If we are already on home, then just animate back to the workspace,
        // otherwise, just wait until onResume to set the state back to Workspace
        if (alreadyOnHome) {
            showWorkspace(true);
        } else {
            mOnResumeState = State.WORKSPACE;
        }

        final View v = getWindow().peekDecorView();
        if (v != null && v.getWindowToken() != null) {
            InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
        }

        // Reset the apps view
        if (!alreadyOnHome && mAppsView != null) {
            mAppsView.scrollToTop();
        }

        // Reset the widgets view
        if (!alreadyOnHome && mWidgetsView != null) {
            mWidgetsView.scrollToTop();
        }

        if (mLauncherCallbacks != null) {
            mLauncherCallbacks.onHomeIntent();
        }
    }

    if (mLauncherCallbacks != null) {
        mLauncherCallbacks.onNewIntent(intent);
    }

    // Defer moving to the default screen until after we callback to the LauncherCallbacks
    // as slow logic in the callbacks eat into the time the scroller expects for the snapToPage
    // animation.
    if (isActionMain) {
        boolean callbackAllowsMoveToDefaultScreen = mLauncherCallbacks != null
                ? mLauncherCallbacks.shouldMoveToDefaultScreenOnHomeIntent()
                : true;
        if (shouldMoveToDefaultScreen && !mWorkspace.isTouchActive() && callbackAllowsMoveToDefaultScreen) {

            // We use this flag to suppress noisy callbacks above custom content state
            // from onResume.
            mMoveToDefaultScreenFromNewIntent = true;
            mWorkspace.post(new Runnable() {
                @Override
                public void run() {
                    if (mWorkspace != null) {
                        mWorkspace.moveToDefaultScreen(true);
                    }
                }
            });
        }
    }

    if (DEBUG_RESUME_TIME) {
        Log.d(TAG, "Time spent in onNewIntent: " + (System.currentTimeMillis() - startTime));
    }
}

From source file:g7.bluesky.launcher3.Launcher.java

@Override
protected void onNewIntent(Intent intent) {
    long startTime = 0;
    if (DEBUG_RESUME_TIME) {
        startTime = System.currentTimeMillis();
    }//ww  w.j a  v  a2s.  co m
    super.onNewIntent(intent);

    // Close the menu
    if (Intent.ACTION_MAIN.equals(intent.getAction())) {
        // also will cancel mWaitingForResult.
        closeSystemDialogs();

        final boolean alreadyOnHome = mHasFocus && ((intent.getFlags()
                & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);

        if (mWorkspace == null) {
            // Can be cases where mWorkspace is null, this prevents a NPE
            return;
        }
        Folder openFolder = mWorkspace.getOpenFolder();
        // In all these cases, only animate if we're already on home
        mWorkspace.exitWidgetResizeMode();

        boolean moveToDefaultScreen = mLauncherCallbacks != null
                ? mLauncherCallbacks.shouldMoveToDefaultScreenOnHomeIntent()
                : true;
        if (alreadyOnHome && mState == State.WORKSPACE && !mWorkspace.isTouchActive() && openFolder == null
                && moveToDefaultScreen) {
            mWorkspace.moveToDefaultScreen(true);
        }

        closeFolder();
        exitSpringLoadedDragMode();

        // If we are already on home, then just animate back to the workspace,
        // otherwise, just wait until onResume to set the state back to Workspace
        if (alreadyOnHome) {
            showWorkspace(true);
        } else {
            mOnResumeState = State.WORKSPACE;
        }

        final View v = getWindow().peekDecorView();
        if (v != null && v.getWindowToken() != null) {
            InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
        }

        // Reset the apps customize page
        if (!alreadyOnHome && mAppsCustomizeTabHost != null) {
            mAppsCustomizeTabHost.reset();
        }

        if (mLauncherCallbacks != null) {
            mLauncherCallbacks.onHomeIntent();
        }
    }

    if (DEBUG_RESUME_TIME) {
        Log.d(TAG, "Time spent in onNewIntent: " + (System.currentTimeMillis() - startTime));
    }

    if (mLauncherCallbacks != null) {
        mLauncherCallbacks.onNewIntent(intent);
    }
}