Example usage for android.content Intent CATEGORY_HOME

List of usage examples for android.content Intent CATEGORY_HOME

Introduction

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

Prototype

String CATEGORY_HOME

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

Click Source Link

Document

This is the home activity, that is the first activity that is displayed when the device boots.

Usage

From source file:com.jedi.setupwizard.ui.SetupWizardActivity.java

private void finalizeSetup() {
    Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_HOME);
    disableSetupWizards(intent);/* w  ww.j  a  va  2 s . c  o  m*/
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
    startActivity(intent);
    finish();
}

From source file:com.gizwits.framework.activity.BaseActivity.java

/**
 * ??app//from w w w.ja v  a  2  s  . c o m
 */
public void exit() {
    if (!isExit) {
        isExit = true;
        Toast.makeText(getApplicationContext(), getString(R.string.tip_exit), Toast.LENGTH_SHORT).show();
        handler.sendEmptyMessageDelayed(0, 2000);
    } else {

        Intent intent = new Intent(Intent.ACTION_MAIN);
        intent.addCategory(Intent.CATEGORY_HOME);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        this.startActivity(intent);
        Historys.exit();
    }
}

From source file:com.nbplus.vbroadlauncher.HomeLauncherActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    boolean isTablet = DisplayUtils.isTabletDevice(this);
    LauncherSettings.getInstance(this).setIsSmartPhone(!isTablet);
    overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
    setContentView(R.layout.activity_home_launcher);

    DeviceUtils.showDeviceInformation();

    Log.d(TAG, ">>>DisplayUtils.getScreenDensity(this) = " + DisplayUtils.getScreenDensity(this));

    // vitamio library load
    if (!LibsChecker.checkVitamioLibs(this)) {
        AlertDialog.Builder alert = new AlertDialog.Builder(this);
        alert.setPositiveButton(R.string.alert_ok, new DialogInterface.OnClickListener() {
            @Override/*w  ww. j av  a2  s  . c om*/
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
                finish();
            }
        });
        alert.setMessage(R.string.alert_media_message);
        alert.show();
        return;
    }

    mCurrentLocale = getResources().getConfiguration().locale;
    if (BuildConfig.DEBUG) {
        Point p = DisplayUtils.getScreenSize(this);
        Log.d(TAG, "Screen size px = " + p.x + ", py = " + p.y);
        Point screen = p;
        p = DisplayUtils.getScreenDp(this);
        Log.d(TAG, "Screen dp x = " + p.x + ", y = " + p.y);
        int density = DisplayUtils.getScreenDensity(this);
        Log.d(TAG, "Screen density = " + density);
    }

    if (isTablet) {
        //is tablet
        Log.d(TAG, "Tablet");
    } else {
        //is phone
        Log.d(TAG, "isTabletDevice() returns Phone.. now check display inches");
        double diagonalInches = DisplayUtils.getDisplayInches(this);
        if (diagonalInches >= 6.4) {
            // 800x400 ? portrait ? 6.43 ? .
            // 6.5inch device or bigger
            Log.d(TAG, "DisplayUtils.getDisplayInches() bigger than 6.5");
        } else {
            if (!Constants.OPEN_BETA_PHONE) {
                // smaller device
                Log.d(TAG, "DisplayUtils.getDisplayInches() smaller than 6.5");
                AlertDialog.Builder alert = new AlertDialog.Builder(this);
                alert.setPositiveButton(R.string.alert_ok, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                        finish();
                    }
                });
                alert.setMessage(R.string.alert_phone_message);
                alert.show();

                return;
            }
        }
    }

    if (!Constants.OPEN_BETA_PHONE || !LauncherSettings.getInstance(this).isSmartPhone()) {
        if (isMyLauncherDefault()) {
            Log.d(TAG, "isMyLauncherDefault() == true");
            // fake home key event.
            Intent fakeIntent = new Intent();
            fakeIntent.setAction(Intent.ACTION_MAIN);
            fakeIntent.addCategory(Intent.CATEGORY_HOME);
            fakeIntent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS | Intent.FLAG_ACTIVITY_FORWARD_RESULT
                    | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_PREVIOUS_IS_TOP
                    | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
            startActivity(fakeIntent);
        } else {
            Log.d(TAG, "Constants.OPEN_BETA_PHONE == false || isMyLauncherDefault() == false");
            //resetPreferredLauncherAndOpenChooser();
        }
    }

    // ?  .. ?   ?   ?.
    // ?  ?.
    IntentFilter filter = new IntentFilter();
    filter.addAction(Constants.ACTION_LAUNCHER_ACTIVITY_RUNNING);
    filter.addAction(IoTConstants.ACTION_RECEIVE_EMERGENCY_CALL_DEVICE_BROADCAST);
    LocalBroadcastManager.getInstance(this).registerReceiver(mBroadcastReceiver, filter);

    Intent intent = new Intent(Constants.ACTION_LAUNCHER_ACTIVITY_RUNNING);
    mActivityRunningTime = System.currentTimeMillis();
    intent.putExtra(Constants.EXTRA_LAUNCHER_ACTIVITY_RUNNING, mActivityRunningTime);
    LocalBroadcastManager.getInstance(this).sendBroadcast(intent);

    // set background image
    setContentViewByOrientation();
    if (LauncherSettings.getInstance(this).getPreferredUserLocation() == null) {
        Location defaultLocation = new Location("stub");

        defaultLocation.setLongitude(126.929810);
        defaultLocation.setLatitude(37.488201);

        LauncherSettings.getInstance(this).setPreferredUserLocation(defaultLocation);
    }

    // First we need to check availability of play services
    mResultReceiver = new AddressResultReceiver(mActivityHandler);
    // Set defaults, then update using values stored in the Bundle.
    mAddressRequested = false;
    mAddressOutput = null;

    // Update values using data stored in the Bundle.
    updateValuesFromBundle(savedInstanceState);

    /**
     *   ?  ??? ?  .
     * ?? ? .
     */
    mBroadcastFramelayout = (FrameLayout) findViewById(R.id.realtimeBroadcastFragment);
    if (mBroadcastFramelayout != null) {
        mBroadcastFramelayout.setVisibility(View.GONE);
    }
    FragmentManager fragmentManager = getSupportFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    Bundle bundle;

    // check installation or bind to service
    VBroadcastServer serverInfo = LauncherSettings.getInstance(this).getServerInformation();
    if (serverInfo == null || !Constants.VBROAD_INITIAL_PAGE.equals(serverInfo.getInitialServerPage())) {
        // ?   ?.
        //  ?  Registration ?  .
        LauncherSettings.getInstance(this).setServerInformation(null);
        LauncherSettings.getInstance(this).setIsCompletedSetup(false);
        // open user register fragment
        RegisterFragment registerFragment = new RegisterFragment();
        bundle = new Bundle();
        registerFragment.setArguments(bundle);

        fragmentTransaction.replace(R.id.launcherFragment, registerFragment);
    } else {
        if (LauncherSettings.getInstance(this).isCompletedSetup() == false) {

            LauncherSettings.getInstance(this).setServerInformation(null);
            // open user register fragment
            RegisterFragment registerFragment = new RegisterFragment();
            bundle = new Bundle();
            registerFragment.setArguments(bundle);

            fragmentTransaction.replace(R.id.launcherFragment, registerFragment);
        } else {
            // open main launcher fragment
            LauncherFragment launcherFragment = new LauncherFragment();
            bundle = new Bundle();
            launcherFragment.setArguments(bundle);

            fragmentTransaction.replace(R.id.launcherFragment, launcherFragment);
        }
    }
    fragmentTransaction.commit();

    // initialize iot interface.
    String collectServerAddress = null;
    if (serverInfo != null) {
        String apiServer = serverInfo.getApiServer();
        if (StringUtils.isEmptyString(apiServer)) {
            collectServerAddress = null;
        } else {
            collectServerAddress = apiServer + Constants.API_COLLECTED_IOT_DATA_CONTEXT;
        }
    }
    IoTResultCodes resCode = IoTInterface.getInstance().initialize(this,
            LauncherSettings.getInstance(this).getDeviceID(), collectServerAddress);
    if (!resCode.equals(IoTResultCodes.SUCCESS)) {
        if (resCode.equals(IoTResultCodes.BIND_SERVICE_FAILED)) {
            Toast.makeText(getApplicationContext(), "Bind IoT Service failed!!!", Toast.LENGTH_SHORT).show();
        }
    }
}

From source file:org.wso2.app.catalog.AppListActivity.java

/**
 * Load device home screen.//from ww w.j a va 2s  .  c o  m
 */
private void loadHomeScreen() {
    Intent i = new Intent();
    i.setAction(Intent.ACTION_MAIN);
    i.addCategory(Intent.CATEGORY_HOME);
    this.startActivity(i);
    super.onBackPressed();
}

From source file:org.eyeseetea.malariacare.DashboardActivity.java

public void confirmExitApp() {
    Log.d(TAG, "back pressed");
    new AlertDialog.Builder(this).setTitle(R.string.confirmation_really_exit_title)
            .setMessage(R.string.confirmation_really_exit).setNegativeButton(android.R.string.no, null)
            .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface arg0, int arg1) {
                    Intent intent = new Intent(Intent.ACTION_MAIN);
                    intent.addCategory(Intent.CATEGORY_HOME);
                    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    startActivity(intent);
                }// w  ww .j a  v a  2s.  c o m
            }).create().show();
}

From source file:com.sdingba.su.lanya.MainActivity.java

@Override
public void onBackPressed() {
    if (mState == UART_PROFILE_CONNECTED) {
        Intent startMain = new Intent(Intent.ACTION_MAIN);
        startMain.addCategory(Intent.CATEGORY_HOME);
        startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(startMain);//from ww w  . j a  v  a 2  s . c o m
        showMessage("onBackPressed : nRFUART's running in background.\n " + " Disconnect to exit");
    } else {
        new AlertDialog.Builder(this).setIcon(android.R.drawable.ic_dialog_alert).setTitle(R.string.popup_title)
                .setMessage(R.string.popup_message)
                .setPositiveButton(R.string.popup_yes, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        finish();
                    }
                }).setNegativeButton(R.string.popup_no, null).show();
    }
}

From source file:com.amrutpatil.makeanote.NotesActivity.java

@Override
public void onBackPressed() {

    Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_HOME);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(intent);/*from   w  w  w.  j a  v  a2 s .  c  om*/
}

From source file:com.battlelancer.seriesguide.ui.ShowFragment.java

private void createShortcut() {
    if (!Utils.hasAccessToX(getActivity())) {
        Utils.advertiseSubscription(getActivity());
        return;/*from   ww w .  j av  a  2s.  co  m*/
    }

    if (mShowCursor == null) {
        return;
    }

    // create the shortcut
    ShortcutUtils.createShortcut(getActivity(), mShowTitle, mShowPoster, getShowTvdbId());

    // drop to home screen
    startActivity(new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_HOME)
            .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK));

    // Analytics
    fireTrackerEvent("Add to Homescreen");
}

From source file:org.smilec.smile.ui.GeneralActivity.java

@SuppressWarnings("deprecation")
@Override//w  ww  .j av  a2s .  co m
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.bt_restart:
        AlertDialog.Builder builderRestart = new AlertDialog.Builder(this);
        builderRestart.setMessage(R.string.restart_game).setCancelable(false)
                .setPositiveButton("Yes", new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int id) {

                        try {
                            //new SmilePlugServerManager().connect(ip, GeneralActivity.this);
                            new SmilePlugServerManager().resetGame(ip, GeneralActivity.this);
                            // QuestionsManager.resetListOfDeletedQuestions(GeneralActivity.this);
                            GeneralActivity.this.finish();
                        } catch (NetworkErrorException e) {
                            ActivityUtil.showLongToast(GeneralActivity.this,
                                    R.string.toast_down_or_unavailable);
                            Log.e(Constants.LOG_CATEGORY, "Error: ", e);
                        }
                    }

                }).setNegativeButton("No", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {
                        dialog.cancel();
                    }
                });
        AlertDialog alertRestart = builderRestart.create();
        alertRestart.show();
        break;
    case R.id.bt_retake:
        AlertDialog.Builder builderRetake = new AlertDialog.Builder(this);
        builderRetake.setMessage(R.string.retake_game).setCancelable(false)
                .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {
                        try {
                            new SmilePlugServerManager().startRetakeQuestions(ip, GeneralActivity.this, board);
                            ActivityUtil.showLongToast(GeneralActivity.this, R.string.toast_retaking);

                            Intent intent = new Intent(GeneralActivity.this,
                                    org.smilec.smile.ui.UsePreparedQuestionsActivity.class);
                            intent.putExtra(GeneralActivity.PARAM_IP, ip);
                            status = CurrentMessageStatus.RE_TAKE.name();
                            intent.putExtra(GeneralActivity.PARAM_STATUS, status);
                            startActivity(intent);

                        } catch (NetworkErrorException e) {
                            Log.e(Constants.LOG_CATEGORY, "Error: ", e);
                        }
                    }
                }).setNegativeButton("No", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {
                        dialog.cancel();
                    }
                });
        AlertDialog alertRetake = builderRetake.create();
        alertRetake.show();
        break;
    case R.id.bt_about:
        Dialog aboutDialog = new Dialog(this, R.style.Dialog);
        aboutDialog.setContentView(R.layout.about);
        Display displaySize = ActivityUtil.getDisplaySize(getApplicationContext());
        aboutDialog.getWindow().setLayout(displaySize.getWidth(), displaySize.getHeight());
        aboutDialog.show();
        break;
    case R.id.bt_exit:
        AlertDialog.Builder builderExit = new AlertDialog.Builder(this);
        builderExit.setMessage(R.string.exit).setCancelable(false)
                .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {
                        Intent intent = new Intent(Intent.ACTION_MAIN);
                        intent.addCategory(Intent.CATEGORY_HOME);
                        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                        startActivity(intent);

                        try {
                            new SmilePlugServerManager().resetGame(ip, GeneralActivity.this);
                        } catch (NetworkErrorException e) {
                            Log.e(Constants.LOG_CATEGORY, "Error: ", e);
                        }

                        // QuestionsManager.resetListOfDeletedQuestions(GeneralActivity.this);
                        GeneralActivity.this.finish();
                    }
                }).setNegativeButton("No", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {
                        dialog.cancel();
                    }
                });
        AlertDialog alertExit = builderExit.create();
        alertExit.show();
        break;
    }
    return true;
}

From source file:de.blinkt.openvpn.ActivityDashboard.java

public void handleMessage(Message msg) {
    Bundle data = msg.getData();/*from w  w  w .jav a2 s .  co m*/
    switch (msg.what) {
    case RemoteAPI.MessageType: {
        String method = data.getString("method");
        String code = data.getString("code");
        String message = data.getString("message");

        if (method.equalsIgnoreCase("getUserServices")) {
            m_waitdlg.cancel();
            if (!(code.equalsIgnoreCase("0") || code.equalsIgnoreCase("4") || code.equalsIgnoreCase("5"))) {
                Toast toast = Toast.makeText(this, "getUserServices failed, " + message, Toast.LENGTH_LONG);
                toast.setGravity(Gravity.CENTER, 0, 0);
                toast.show();
                return;
            }
            m_package = data.getString("packages");
            m_username = data.getString("username");
            m_password = data.getString("vpnpassword"); // update login password to vpnpassword.
            updatePackage(m_package.trim());
        }
        break;
    }

    //            case VpnStatus.StateListener: {
    //                    String log = data.getString("log");
    //                    if(log == null)
    //                        return;
    //                    // get openvpn state from the log.
    //                    if(log.contains("AUTH_FAILED")) {
    //                        Toast toast = Toast.makeText(this, "Username or password error.", Toast.LENGTH_SHORT);
    //                        toast.setGravity(Gravity.CENTER, 0, 0);
    //                        toast.show();
    //                        setStatus(Status.Disconnected);
    //                        return;
    //                    }
    //                    if(log.contains("SIGTERM") || log.contains("exiting")) {
    //                        Toast toast = Toast.makeText(this, "Disconnected from server.", Toast.LENGTH_SHORT);
    //                        toast.setGravity(Gravity.CENTER, 0, 0);
    //                        toast.show();
    //
    //                        setStatus(Status.Disconnected);
    //                        return;
    //                    }
    //                    if(log.contains("Initialization Sequence Completed")) {
    //                        if(m_status == Status.Connecting)
    //                            setStatus(Status.Connected);
    //                        return;
    //                    }
    //                    break; }

    case HandlerDialogClickListener.MessageType: {
        switch (msg.arg1) {
        case AlertDialogExitNotify: {
            switch (msg.arg2) {
            case AlertDialog.BUTTON_POSITIVE: {
                Intent intent = new Intent();
                intent.setAction(Intent.ACTION_MAIN);
                intent.addCategory(Intent.CATEGORY_HOME);
                startActivity(intent);
                break;
            }
            case AlertDialog.BUTTON_NEGATIVE: {
                break;
            }
            case AlertDialog.BUTTON_NEUTRAL: {
                if (VpnStatus.isVPNActive()) {
                    if (mService != null) {
                        try {
                            mService.stopVPN(false);
                        } catch (RemoteException e) {
                            VpnStatus.logException(e);
                        }
                    }
                }
                setStatus(Status.Disconnected);
                finish();
                break;
            }
            }
            break;
        }
        }
        break;
    }

    case NetDisconnectedNotify: {
        Log.d("ibVPN", "Disconnected by internet lose.");
        Toast toast = Toast.makeText(this,
                "VPN connection was lost, please reconnect Wi-Fi/Mobile Data connection.", Toast.LENGTH_SHORT);
        toast.setGravity(Gravity.CENTER, 0, 0);
        toast.show();

        Button button = (Button) findViewById(R.id.button_dashboard_connect);
        if (button.getText().toString().equalsIgnoreCase(getString(R.string.text_cancel))) {
            //                m_openvpn.cancel();
            setStatus(Status.Disconnected);
        } else if (button.getText().toString().equalsIgnoreCase(getString(R.string.text_disconnect))) {
            //                m_openvpn.disconnect();
            setStatus(Status.Disconnected);
        }
        break;
    }

    default: {
        Log.d("ibVPN", "Message From Unknown Thread. :)");
        break;
    }
    }

}