Example usage for android.content Intent ACTION_MAIN

List of usage examples for android.content Intent ACTION_MAIN

Introduction

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

Prototype

String ACTION_MAIN

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

Click Source Link

Document

Activity Action: Start as a main entry point, does not expect to receive data.

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();/*  w w  w .j  av  a2s. c  om*/

        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:co.taqat.call.LinphoneActivity.java

public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK) {
        if (currentFragment == FragmentsAvailable.DIALER || currentFragment == FragmentsAvailable.CONTACTS_LIST
                || currentFragment == FragmentsAvailable.HISTORY_LIST
                || currentFragment == FragmentsAvailable.CHAT_LIST) {
            boolean isBackgroundModeActive = LinphonePreferences.instance().isBackgroundModeEnabled();
            if (!isBackgroundModeActive) {
                stopService(new Intent(Intent.ACTION_MAIN).setClass(this, LinphoneService.class));
                finish();//ww  w  .j a  v a  2s. c o m
            } else if (LinphoneUtils.onKeyBackGoHome(this, keyCode, event)) {
                return true;
            }
        }
    }
    return super.onKeyDown(keyCode, event);
}

From source file:com.sim2dial.dialer.LinphoneActivity.java

public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK) {
        if (currentFragment == FragmentsAvailable.DIALER) {
            boolean isBackgroundModeActive = Engine.getPref().getBoolean(
                    getString(R.string.pref_background_mode_key),
                    getResources().getBoolean(R.bool.pref_background_mode_default));
            if (!isBackgroundModeActive) {
                stopService(new Intent(Intent.ACTION_MAIN).setClass(this, LinphoneService.class));
                finish();/*  w  w w .j a v a 2s .c o  m*/
            } else if (LinphoneUtils.onKeyBackGoHome(this, keyCode, event)) {
                return true;
            }
        } else if (!isTablet()) {
            int backStackEntryCount = getSupportFragmentManager().getBackStackEntryCount();
            if (backStackEntryCount <= 1) {
                showStatusBar();
                // hideStatusBar();
            }

            if (currentFragment == FragmentsAvailable.SETTINGS) {
                // showStatusBar();
                hideStatusBar();
                reloadConfig();
                updateAnimationsState();
            }
        }
    } else if (keyCode == KeyEvent.KEYCODE_MENU && statusFragment != null) {
        if (event.getRepeatCount() < 1) {
            // statusFragment.openOrCloseStatusBar(true);

        }
    }
    return super.onKeyDown(keyCode, event);
}

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();/*from  www  .ja  v a  2  s.  com*/

        // 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.codename1.impl.android.AndroidImplementation.java

@Override
public boolean minimizeApplication() {
    Intent startMain = new Intent(Intent.ACTION_MAIN);
    startMain.addCategory(Intent.CATEGORY_HOME);
    startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    startMain.putExtra("WaitForResult", Boolean.FALSE);
    getContext().startActivity(startMain);
    return true;//from   ww  w.  ja  va2s .  c o  m
}

From source file:com.codename1.impl.android.AndroidImplementation.java

@Override
public void restoreMinimizedApplication() {
    if (getActivity() != null) {
        Intent i = new Intent(getActivity(), getActivity().getClass());
        i.setAction(Intent.ACTION_MAIN);
        i.addCategory(Intent.CATEGORY_LAUNCHER);
        getContext().startActivity(i);//from   w ww.  j a  v  a 2s .co  m
    }
}

From source file:com.amaze.filemanager.fragments.MainFragment.java

private void addShortcut(LayoutElementParcelable path) {
    //Adding shortcut for MainActivity
    //on Home screen
    final Context ctx = getContext();

    if (!ShortcutManagerCompat.isRequestPinShortcutSupported(ctx)) {
        Toast.makeText(getActivity(), getString(R.string.addshortcut_not_supported_by_launcher),
                Toast.LENGTH_SHORT).show();
        return;//from ww w.  ja  v  a2s. c  o m
    }

    Intent shortcutIntent = new Intent(ctx, MainActivity.class);
    shortcutIntent.putExtra("path", path.desc);
    shortcutIntent.setAction(Intent.ACTION_MAIN);
    shortcutIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);

    // Using file path as shortcut id.
    ShortcutInfoCompat info = new ShortcutInfoCompat.Builder(ctx, path.desc)
            .setActivity(getMainActivity().getComponentName())
            .setIcon(IconCompat.createWithResource(ctx, R.mipmap.ic_launcher)).setIntent(shortcutIntent)
            .setLongLabel(path.desc).setShortLabel(new File(path.desc).getName()).build();

    ShortcutManagerCompat.requestPinShortcut(ctx, info, null);
}

From source file:org.xingjitong.LinphoneActivity.java

@SuppressLint("NewApi")
private void initPopupWindow() {
    Log.v("yyppdebug", "yyppoption init 000");
    view = getLayoutInflater().inflate(R.layout.option_menu, null);
    pop = new PopupWindow(view, ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    pop.setOutsideTouchable(true);/*from w w w  .  jav  a2 s . c  om*/

    // ??
    mlayout_setting = (LinearLayout) view.findViewById(R.id.option_menu_aaa);
    mlayout_about = (LinearLayout) view.findViewById(R.id.option_menu_bbb);
    mlayout_exit = (LinearLayout) view.findViewById(R.id.option_menu_ccc);

    mlayout_setting.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            if (pop.isShowing()) {
                pop.dismiss();

                isPopShowing = false;
            }
            //do somethiing
            LinphoneActivity.instance().changeCurrentFragment(FragmentsAvailable.TITTLE_SETTINGS, null);
            //-----------------

        }
    });

    mlayout_about.setOnClickListener(new View.OnClickListener() {

        @SuppressLint("NewApi")
        public void onClick(View v) {
            if (pop.isShowing()) {
                pop.dismiss();
                isPopShowing = false;

            }
            //do something...

            AlertDialog.Builder buildernew = new AlertDialog.Builder(LinphoneActivity.instance(),
                    AlertDialog.THEME_DEVICE_DEFAULT_LIGHT);
            String tmpmsg = "?????????www.wecare200.com";
            buildernew.setIconAttribute(android.R.attr.alertDialogIcon);
            buildernew.setTitle("?");
            buildernew.setMessage(tmpmsg);

            buildernew.setNegativeButton("?", new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    // TODO Auto-generated method stub

                }
            });

            buildernew.create().show();

            //---------------------------------------------------------

        }
    });

    mlayout_exit.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            if (pop.isShowing()) {
                pop.dismiss();
                isPopShowing = false;
            }
            //do something...

            //LinphoneActivity.instance().exit();
            //----------------------------------
            startActivity(new Intent().setAction(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_HOME));

        }
    });
}

From source file:org.mozilla.gecko.GeckoApp.java

private void initialize() {
    mInitialized = true;//from  w  ww . j a  v a2 s .c o m

    Intent intent = getIntent();
    String args = intent.getStringExtra("args");
    if (args != null && args.contains("-profile")) {
        Pattern p = Pattern.compile("(?:-profile\\s*)(\\w*)(\\s*)");
        Matcher m = p.matcher(args);
        if (m.find()) {
            mProfile = GeckoProfile.get(this, m.group(1));
            mLastTitle = null;
            mLastViewport = null;
            mLastScreen = null;
        }
    }

    if (ACTION_UPDATE.equals(intent.getAction()) || args != null && args.contains("-alert update-app")) {
        Log.i(LOGTAG, "onCreate: Update request");
        checkAndLaunchUpdate();
    }

    mBrowserToolbar.init();
    mBrowserToolbar.setTitle(mLastTitle);

    String passedUri = null;
    String uri = getURIFromIntent(intent);
    if (uri != null && uri.length() > 0)
        passedUri = mLastTitle = uri;

    if (passedUri == null || passedUri.equals("about:home")) {
        // show about:home if we aren't restoring previous session
        if (!getProfile().hasSession()) {
            mBrowserToolbar.updateTabCount(1);
            showAboutHome();
        }
    } else {
        mBrowserToolbar.updateTabCount(1);
    }

    if (sGREDir == null)
        sGREDir = new File(this.getApplicationInfo().dataDir);

    Uri data = intent.getData();
    if (data != null && "http".equals(data.getScheme()) && isHostOnPrefetchWhitelist(data.getHost())) {
        Intent copy = new Intent(intent);
        copy.setAction(ACTION_LOAD);
        GeckoAppShell.getHandler().post(new RedirectorRunnable(copy));
        // We're going to handle this uri with the redirector, so setting
        // the action to MAIN and clearing the uri data prevents us from
        // loading it twice
        intent.setAction(Intent.ACTION_MAIN);
        intent.setData(null);
        passedUri = null;
    }

    sGeckoThread = new GeckoThread(intent, passedUri, mRestoreSession);
    if (!ACTION_DEBUG.equals(intent.getAction())
            && checkAndSetLaunchState(LaunchState.Launching, LaunchState.Launched))
        sGeckoThread.start();

    mFavicons = new Favicons(this);

    Tabs.getInstance().setContentResolver(getContentResolver());

    if (cameraView == null) {
        cameraView = new SurfaceView(this);
        cameraView.getHolder().setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
    }

    if (mLayerController == null) {
        /*
         * Create a layer client so that Gecko will have a buffer to draw into, but don't hook
         * it up to the layer controller yet.
         */
        mSoftwareLayerClient = new GeckoSoftwareLayerClient(this);

        /*
         * Hook a placeholder layer client up to the layer controller so that the user can pan
         * and zoom a cached screenshot of the previous page. This call will return null if
         * there is no cached screenshot; in that case, we have no choice but to display a
         * checkerboard.
         *
         * TODO: Fall back to a built-in screenshot of the Fennec Start page for a nice first-
         * run experience, perhaps?
         */
        mLayerController = new LayerController(this);
        mPlaceholderLayerClient = PlaceholderLayerClient.createInstance(this);
        mLayerController.setLayerClient(mPlaceholderLayerClient);

        mGeckoLayout.addView(mLayerController.getView(), 0);
    }

    mPluginContainer = (AbsoluteLayout) findViewById(R.id.plugin_container);

    mDoorHangerPopup = new DoorHangerPopup(this);
    mAutoCompletePopup = (AutoCompletePopup) findViewById(R.id.autocomplete_popup);

    Log.w(LOGTAG, "zerdatime " + SystemClock.uptimeMillis() + " - UI almost up");

    if (!sTryCatchAttached) {
        sTryCatchAttached = true;
        mMainHandler.post(new Runnable() {
            public void run() {
                try {
                    Looper.loop();
                } catch (Exception e) {
                    GeckoAppShell.reportJavaCrash(e);
                }
                // resetting this is kinda pointless, but oh well
                sTryCatchAttached = false;
            }
        });
    }

    //register for events
    GeckoAppShell.registerGeckoEventListener("DOMContentLoaded", GeckoApp.mAppContext);
    GeckoAppShell.registerGeckoEventListener("DOMTitleChanged", GeckoApp.mAppContext);
    GeckoAppShell.registerGeckoEventListener("DOMLinkAdded", GeckoApp.mAppContext);
    GeckoAppShell.registerGeckoEventListener("DOMWindowClose", GeckoApp.mAppContext);
    GeckoAppShell.registerGeckoEventListener("log", GeckoApp.mAppContext);
    GeckoAppShell.registerGeckoEventListener("Content:LocationChange", GeckoApp.mAppContext);
    GeckoAppShell.registerGeckoEventListener("Content:SecurityChange", GeckoApp.mAppContext);
    GeckoAppShell.registerGeckoEventListener("Content:StateChange", GeckoApp.mAppContext);
    GeckoAppShell.registerGeckoEventListener("Content:LoadError", GeckoApp.mAppContext);
    GeckoAppShell.registerGeckoEventListener("onCameraCapture", GeckoApp.mAppContext);
    GeckoAppShell.registerGeckoEventListener("Doorhanger:Add", GeckoApp.mAppContext);
    GeckoAppShell.registerGeckoEventListener("Doorhanger:Remove", GeckoApp.mAppContext);
    GeckoAppShell.registerGeckoEventListener("Menu:Add", GeckoApp.mAppContext);
    GeckoAppShell.registerGeckoEventListener("Menu:Remove", GeckoApp.mAppContext);
    GeckoAppShell.registerGeckoEventListener("Gecko:Ready", GeckoApp.mAppContext);
    GeckoAppShell.registerGeckoEventListener("Toast:Show", GeckoApp.mAppContext);
    GeckoAppShell.registerGeckoEventListener("DOMFullScreen:Start", GeckoApp.mAppContext);
    GeckoAppShell.registerGeckoEventListener("DOMFullScreen:Stop", GeckoApp.mAppContext);
    GeckoAppShell.registerGeckoEventListener("ToggleChrome:Hide", GeckoApp.mAppContext);
    GeckoAppShell.registerGeckoEventListener("ToggleChrome:Show", GeckoApp.mAppContext);
    GeckoAppShell.registerGeckoEventListener("FormAssist:AutoComplete", GeckoApp.mAppContext);
    GeckoAppShell.registerGeckoEventListener("Permissions:Data", GeckoApp.mAppContext);
    GeckoAppShell.registerGeckoEventListener("Downloads:Done", GeckoApp.mAppContext);
    GeckoAppShell.registerGeckoEventListener("CharEncoding:Data", GeckoApp.mAppContext);
    GeckoAppShell.registerGeckoEventListener("CharEncoding:State", GeckoApp.mAppContext);
    GeckoAppShell.registerGeckoEventListener("Update:Restart", GeckoApp.mAppContext);
    GeckoAppShell.registerGeckoEventListener("Tab:HasTouchListener", GeckoApp.mAppContext);
    GeckoAppShell.registerGeckoEventListener("Session:StatePurged", GeckoApp.mAppContext);
    GeckoAppShell.registerGeckoEventListener("Bookmark:Insert", GeckoApp.mAppContext);

    IntentFilter batteryFilter = new IntentFilter();
    batteryFilter.addAction(Intent.ACTION_BATTERY_CHANGED);
    mBatteryReceiver = new GeckoBatteryManager();
    registerReceiver(mBatteryReceiver, batteryFilter);

    if (SmsManager.getInstance() != null) {
        SmsManager.getInstance().start();
    }

    GeckoNetworkManager.getInstance().init();

    final GeckoApp self = this;

    GeckoAppShell.getHandler().postDelayed(new Runnable() {
        public void run() {
            Log.w(LOGTAG, "zerdatime " + SystemClock.uptimeMillis() + " - pre checkLaunchState");

            /*
              XXXX see bug 635342
               We want to disable this code if possible.  It is about 145ms in runtime
            SharedPreferences settings = getPreferences(Activity.MODE_PRIVATE);
            String localeCode = settings.getString(getPackageName() + ".locale", "");
            if (localeCode != null && localeCode.length() > 0)
            GeckoAppShell.setSelectedLocale(localeCode);
            */

            if (!checkLaunchState(LaunchState.Launched)) {
                return;
            }

            checkMigrateProfile();
        }
    }, 50);
}

From source file:com.amaze.carbonfilemanager.fragments.MainFragment.java

private void addShortcut(LayoutElement path) {
    //Adding shortcut for MainActivity
    //on Home screen
    Intent shortcutIntent = new Intent(getActivity().getApplicationContext(), MainActivity.class);
    shortcutIntent.putExtra("path", path.getDesc());
    shortcutIntent.setAction(Intent.ACTION_MAIN);
    shortcutIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    Intent addIntent = new Intent();
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, new File(path.getDesc()).getName());

    addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
            Intent.ShortcutIconResource.fromContext(getActivity(), R.mipmap.ic_launcher));

    addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
    getActivity().sendBroadcast(addIntent);
}