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.farmerbb.taskbar.activity.ContextMenuActivity.java

@SuppressWarnings("deprecation")
private void generateMenu() {
    if (isStartButton) {
        addPreferencesFromResource(R.xml.pref_context_menu_open_settings);
        findPreference("open_taskbar_settings").setOnPreferenceClickListener(this);
        findPreference("start_menu_apps").setOnPreferenceClickListener(this);

        if (U.launcherIsDefault(this) && FreeformHackHelper.getInstance().isInFreeformWorkspace()) {
            addPreferencesFromResource(R.xml.pref_context_menu_change_wallpaper);
            findPreference("change_wallpaper").setOnPreferenceClickListener(this);
        }//from   w  ww.  j  av  a2  s .co  m

        if (!getIntent().getBooleanExtra("dont_show_quit", false)) {
            addPreferencesFromResource(R.xml.pref_context_menu_quit);
            findPreference("quit_taskbar").setOnPreferenceClickListener(this);
        }
    } else if (isOverflowMenu) {
        if (getResources().getConfiguration().screenWidthDp >= 600
                && Build.VERSION.SDK_INT <= Build.VERSION_CODES.M)
            setTitle(R.string.tools);
        else {
            addPreferencesFromResource(R.xml.pref_context_menu_header);
            findPreference("header").setTitle(R.string.tools);
        }

        addPreferencesFromResource(R.xml.pref_context_menu_overflow);
        findPreference("volume").setOnPreferenceClickListener(this);
        findPreference("system_settings").setOnPreferenceClickListener(this);
        findPreference("lock_device").setOnPreferenceClickListener(this);
        findPreference("power_menu").setOnPreferenceClickListener(this);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
            findPreference("file_manager").setOnPreferenceClickListener(this);
        else
            getPreferenceScreen().removePreference(findPreference("file_manager"));
    } else {
        appName = getIntent().getStringExtra("app_name");
        packageName = getIntent().getStringExtra("package_name");
        componentName = getIntent().getStringExtra("component_name");
        userId = getIntent().getLongExtra("user_id", 0);

        if (getResources().getConfiguration().screenWidthDp >= 600
                && Build.VERSION.SDK_INT <= Build.VERSION_CODES.M)
            setTitle(appName);
        else {
            addPreferencesFromResource(R.xml.pref_context_menu_header);
            findPreference("header").setTitle(appName);
        }

        SharedPreferences pref = U.getSharedPreferences(this);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && pref.getBoolean("freeform_hack", false)
                && !U.isGame(this, packageName)) {
            addPreferencesFromResource(R.xml.pref_context_menu_show_window_sizes);
            findPreference("show_window_sizes").setOnPreferenceClickListener(this);
        }

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
            int shortcutCount = getLauncherShortcuts();

            if (shortcutCount > 1) {
                addPreferencesFromResource(R.xml.pref_context_menu_shortcuts);
                findPreference("app_shortcuts").setOnPreferenceClickListener(this);
            } else if (shortcutCount == 1)
                generateShortcuts();
        }

        final PackageManager pm = getPackageManager();
        Intent homeIntent = new Intent(Intent.ACTION_MAIN);
        homeIntent.addCategory(Intent.CATEGORY_HOME);
        ResolveInfo defaultLauncher = pm.resolveActivity(homeIntent, PackageManager.MATCH_DEFAULT_ONLY);

        if (!packageName.contains(BuildConfig.BASE_APPLICATION_ID)
                && !packageName.equals(defaultLauncher.activityInfo.packageName)) {
            PinnedBlockedApps pba = PinnedBlockedApps.getInstance(this);

            if (pba.isPinned(componentName)) {
                addPreferencesFromResource(R.xml.pref_context_menu_pin);
                findPreference("pin_app").setOnPreferenceClickListener(this);
                findPreference("pin_app").setTitle(R.string.unpin_app);
            } else if (pba.isBlocked(componentName)) {
                addPreferencesFromResource(R.xml.pref_context_menu_block);
                findPreference("block_app").setOnPreferenceClickListener(this);
                findPreference("block_app").setTitle(R.string.unblock_app);
            } else {
                final int MAX_NUM_OF_COLUMNS = U.getMaxNumOfEntries(this);

                if (pba.getPinnedApps().size() < MAX_NUM_OF_COLUMNS) {
                    addPreferencesFromResource(R.xml.pref_context_menu_pin);
                    findPreference("pin_app").setOnPreferenceClickListener(this);
                    findPreference("pin_app").setTitle(R.string.pin_app);
                }

                addPreferencesFromResource(R.xml.pref_context_menu_block);
                findPreference("block_app").setOnPreferenceClickListener(this);
                findPreference("block_app").setTitle(R.string.block_app);
            }
        }

        addPreferencesFromResource(R.xml.pref_context_menu);

        findPreference("app_info").setOnPreferenceClickListener(this);
        findPreference("uninstall").setOnPreferenceClickListener(this);
    }
}

From source file:com.rainmakerlabs.bleepsample.BleepService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    Log.d(TAG, "onStartCommand");
    String actionName = intent.getStringExtra("actionName");
    if (intent == null || intent.getExtras() == null) {//just removing these checks
    } else if (actionName.equalsIgnoreCase(BLEepService.INTENT_BLEEP_PROCESS)
            && intent.getExtras().containsKey(BLEepService.INTENT_BLEEP_PASSED_LIST)) {
        ArrayList<Bleep> bleeps = (ArrayList<Bleep>) intent.getExtras()
                .getSerializable(BLEepService.INTENT_BLEEP_PASSED_LIST);
        for (final Bleep bleep : bleeps) {
            String msgType = bleep.getType();
            String atts = bleep.getAtts();
            try {
                JSONObject objMsg = new JSONObject(atts);
                //thisBleepService.addExtraLog(bleep, "FEEDBACK", "good");//use this when you want to send a custom log to BMS. for instance, you could display a feedback dialog, and ask users to give a rating, and BMS will help you collate the information. put this where necessary, it's just here for example
                Log.d(TAG, "Message Received of Type: " + msgType);
                if (msgType.equalsIgnoreCase("image")) {
                    final String strImgUrl = objMsg.optString(APIKeyDefineCommand.MSG_IMG);
                    final String adAspect = objMsg.optString(APIKeyDefineCommand.MSG_IMGASP);
                    String strImgMsgTemp = objMsg.optString(APIKeyDefineCommand.MSG_NOTIF);
                    //putting the default message above would only work for missing key, not in case of empty string. empty string will prevent the notification, so fix below
                    if (strImgMsgTemp.equalsIgnoreCase(""))
                        strImgMsgTemp = "No Message";
                    final String strImgMsg = strImgMsgTemp;
                    if (checkIfClosed()) {
                        if (oldcodeon)
                            localNotification("", strImgMsg, 0);
                        continue;
                    }/*from  w ww.j a  va2 s  .  com*/
                    if (MainActivity.adlib.get(strImgMsg) == null && !strImgMsg.equalsIgnoreCase("No Message"))
                        Log.d(TAG, "image url start download for key: " + strImgMsg + ", url = " + strImgUrl);
                    else {
                        Log.d(TAG, "Image exists, or no message, not downloading..., key: " + strImgMsg);
                        continue;
                    }

                    if (strImgMsg.equalsIgnoreCase("$28")) {
                        Log.d("Portal", "Image exists, loading from cache");
                        imgShow(BitmapFactory.decodeResource(getResources(), R.drawable.singtel), strImgMsg);
                        continue;
                    } else if (strImgMsg.equalsIgnoreCase("$4.50")) {
                        Log.d("Portal", "Heineken Image exists, loading from cache");
                        imgShow(BitmapFactory.decodeResource(getResources(), R.drawable.heineken), strImgMsg);
                        continue;
                    }

                    ShutterbugManager.getSharedImageManager(BleepActivity.currentBleepActivity)
                            .download(strImgUrl, new ShutterbugManagerListener() {
                                @Override
                                public void onImageSuccess(ShutterbugManager imageManager, Bitmap bitmap,
                                        String url) {
                                    Log.d(TAG, "image url end download " + strImgUrl);
                                    if (strImgUrl.equalsIgnoreCase(AdDialog.getCurrentAdUrl()))
                                        return;
                                    if (AdDialog.howManyAdDialogsShowing == 1) {
                                        AdDialog.closeOnlyAdDialog();
                                    }
                                    final Bitmap bitmap2 = bitmap;

                                    imgShow(bitmap, strImgMsg);

                                    if (oldcodeon) {
                                        BleepActivity.currentBleepActivity.runOnUiThread(new Runnable() {
                                            public void run() {
                                                if (BleepActivity.isBackground)
                                                    localNotification("", strImgMsg, 0);
                                                AdDialog.showAdsDialog(BleepActivity.currentBleepActivity,
                                                        bitmap2, strImgUrl, adAspect);
                                            }
                                        });
                                    }
                                }

                                @Override
                                public void onImageFailure(ShutterbugManager imageManager, String url) {
                                    thisBleepService.eraseTriggerLog(bleep);//to cancel trigger log when trigger is cancelled
                                }
                            });
                } else if (oldcodeon == false) {//don't run anything else
                } else if (msgType.equalsIgnoreCase("alert") && oldcodeon) {

                    // show alert message
                    if (checkIfClosed() || BleepActivity.isBackground) {
                        localNotification(objMsg.optString(APIKeyDefineCommand.MSG_TITLE),
                                objMsg.optString(APIKeyDefineCommand.MSG_CONTENT), 1);
                    } else {
                        showAlert(objMsg.optString(APIKeyDefineCommand.MSG_TITLE),
                                objMsg.optString(APIKeyDefineCommand.MSG_CONTENT));
                    }
                } else if (msgType.equalsIgnoreCase("launch")) {
                    String intentAction = objMsg.optString(APIKeyDefineCommand.MSG_APP_INTENT);
                    String intentUri = objMsg.optString(APIKeyDefineCommand.MSG_APP_URI);
                    String intentType = "";
                    String intentExtras = objMsg.optString(APIKeyDefineCommand.MSG_APP_EXTRAS);
                    String cfmMsg = objMsg.optString(APIKeyDefineCommand.MSG_APP_CFM);
                    String failMsg = objMsg.optString(APIKeyDefineCommand.MSG_APP_FAIL);
                    processTypeLaunch(intentAction, intentUri, intentType, intentExtras, cfmMsg, failMsg, 2);
                } else if (msgType.equalsIgnoreCase("url")) {
                    String intentAction = Intent.ACTION_VIEW;
                    String intentUri = objMsg.optString(APIKeyDefineCommand.MSG_MEDIA_URL);
                    String intentType = "";
                    String intentExtras = "";
                    String cfmMsg = objMsg.optString(APIKeyDefineCommand.MSG_APP_CFM);
                    String failMsg = objMsg.optString(APIKeyDefineCommand.MSG_APP_FAIL);
                    processTypeLaunch(intentAction, intentUri, intentType, intentExtras, cfmMsg, failMsg, 3);
                } else if (msgType.equalsIgnoreCase("webview")) {
                    String intentAction = Intent.ACTION_VIEW;
                    String intentUri = objMsg.optString(APIKeyDefineCommand.MSG_MEDIA_URL);
                    String intentType = "";
                    String intentExtras = "";
                    String cfmMsg = objMsg.optString(APIKeyDefineCommand.MSG_NOTIF);
                    if (cfmMsg.equalsIgnoreCase(""))
                        cfmMsg = "View webpage?";
                    String failMsg = "";
                    processTypeLaunch(intentAction, intentUri, intentType, intentExtras, cfmMsg, failMsg, 4);
                } else if (msgType.equalsIgnoreCase("video")) {
                    String strVidUrl = objMsg.optString(APIKeyDefineCommand.MSG_MEDIA_URL);
                    Intent vidIntent = new Intent(this, VideoActivity.class);
                    vidIntent.putExtra("url", strVidUrl);
                    String notifMsg = objMsg.optString(APIKeyDefineCommand.MSG_NOTIF);
                    if (notifMsg.equalsIgnoreCase(""))
                        notifMsg = "Play video?";
                    if (!checkIfClosed() && BleepActivity.isVideoActivityOpen) {
                        thisBleepService.eraseTriggerLog(bleep);//to cancel trigger log when trigger is cancelled
                    } else if (checkIfClosed() || BleepActivity.isBackground) {
                        vidIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                        vidIntent.setAction(Intent.ACTION_MAIN);
                        vidIntent.addCategory(Intent.CATEGORY_LAUNCHER);
                        localNotification("", notifMsg, vidIntent, "Video opening failed!", 5);
                    } else {
                        BleepActivity.currentBleepActivity.startActivity(vidIntent);
                    }
                } else if (msgType.equalsIgnoreCase("audio")) {
                    String url = objMsg.optString(APIKeyDefineCommand.MSG_MEDIA_URL);
                    mediaPlayer = new MediaPlayer();
                    mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
                    try {
                        mediaPlayer.setDataSource(url);
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                    mediaPlayer.prepareAsync();
                    mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
                        @Override
                        public void onPrepared(MediaPlayer mp) {
                            mp.start();
                        }
                    });
                    mediaPlayer.setOnErrorListener(new MediaPlayer.OnErrorListener() {
                        @Override
                        public boolean onError(MediaPlayer mp, int what, int extra) {
                            return false;
                        }
                    });
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
        //      } else if (actionName.equalsIgnoreCase(BLEepService.INTENT_BLEEP_EXIT) && intent.getExtras().containsKey(BLEepService.INTENT_MSG_NAME)) {
        //         HashMap<String, Object> beaconOutInfo = (HashMap<String, Object>)intent.getSerializableExtra(BLEepService.INTENT_MSG_NAME);   
        //         //Log.d("debug!","debug! this beacon just went out "+beaconOutInfo.get("uuid")+" "+beaconOutInfo.get("major")+" "+beaconOutInfo.get("minor")+" "+beaconOutInfo.get("tag")+" "+beaconOutInfo.get("beaconID"));
    } else if (actionName.equalsIgnoreCase(BLEepService.INTENT_BLEEP_STATE)
            && intent.getExtras().containsKey(BLEepService.INTENT_MSG_NAME)) {
        int beaconState = intent.getIntExtra(BLEepService.INTENT_MSG_NAME, 99);
    }

    return START_NOT_STICKY;
}

From source file:cc.flydev.launcher.InstallShortcutReceiver.java

private static ShortcutInfo getShortcutInfo(Context context, Intent data, Intent launchIntent) {
    if (launchIntent.getAction() == null) {
        launchIntent.setAction(Intent.ACTION_VIEW);
    } else if (launchIntent.getAction().equals(Intent.ACTION_MAIN) && launchIntent.getCategories() != null
            && launchIntent.getCategories().contains(Intent.CATEGORY_LAUNCHER)) {
        launchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
    }/*from  ww  w . j  ava2s. c o m*/
    LauncherAppState app = LauncherAppState.getInstance();
    return app.getModel().infoFromShortcutIntent(context, data, null);
}

From source file:com.farmerbb.taskbar.MainActivity.java

private void proceedWithAppLaunch(Bundle savedInstanceState) {
    setContentView(R.layout.main);/*from   w w  w  .ja  v  a  2 s  . c o m*/

    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setCustomView(R.layout.switch_layout);
        actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_TITLE | ActionBar.DISPLAY_SHOW_CUSTOM);
    }

    theSwitch = (SwitchCompat) findViewById(R.id.the_switch);
    if (theSwitch != null) {
        final SharedPreferences pref = U.getSharedPreferences(this);
        theSwitch.setChecked(pref.getBoolean("taskbar_active", false));

        theSwitch.setOnCheckedChangeListener((compoundButton, b) -> {
            if (b) {
                if (U.canDrawOverlays(this)) {
                    boolean firstRun = pref.getBoolean("first_run", true);
                    startTaskbarService();

                    if (firstRun && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !U.isSystemApp(this)) {
                        ApplicationInfo applicationInfo = null;
                        try {
                            applicationInfo = getPackageManager().getApplicationInfo(BuildConfig.APPLICATION_ID,
                                    0);
                        } catch (PackageManager.NameNotFoundException e) {
                            /* Gracefully fail */ }

                        if (applicationInfo != null) {
                            AppOpsManager appOpsManager = (AppOpsManager) getSystemService(
                                    Context.APP_OPS_SERVICE);
                            int mode = appOpsManager.checkOpNoThrow(AppOpsManager.OPSTR_GET_USAGE_STATS,
                                    applicationInfo.uid, applicationInfo.packageName);

                            if (mode != AppOpsManager.MODE_ALLOWED) {
                                AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
                                builder.setTitle(R.string.pref_header_recent_apps)
                                        .setMessage(R.string.enable_recent_apps)
                                        .setPositiveButton(R.string.action_ok, (dialog, which) -> {
                                            try {
                                                startActivity(
                                                        new Intent(Settings.ACTION_USAGE_ACCESS_SETTINGS));
                                                U.showToastLong(MainActivity.this,
                                                        R.string.usage_stats_message);
                                            } catch (ActivityNotFoundException e) {
                                                U.showErrorDialog(MainActivity.this, "GET_USAGE_STATS");
                                            }
                                        }).setNegativeButton(R.string.action_cancel, null);

                                AlertDialog dialog = builder.create();
                                dialog.show();
                            }
                        }
                    }
                } else {
                    U.showPermissionDialog(MainActivity.this);
                    compoundButton.setChecked(false);
                }
            } else
                stopTaskbarService();
        });
    }

    if (savedInstanceState == null) {
        if (!getIntent().hasExtra("theme_change"))
            getFragmentManager().beginTransaction()
                    .replace(R.id.fragmentContainer, new AboutFragment(), "AboutFragment").commit();
        else
            getFragmentManager().beginTransaction()
                    .replace(R.id.fragmentContainer, new AppearanceFragment(), "AppearanceFragment").commit();
    }

    if (!BuildConfig.APPLICATION_ID.equals(BuildConfig.BASE_APPLICATION_ID) && freeVersionInstalled()) {
        final SharedPreferences pref = U.getSharedPreferences(this);
        if (!pref.getBoolean("dont_show_uninstall_dialog", false)) {
            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setTitle(R.string.settings_imported_successfully).setMessage(R.string.import_dialog_message)
                    .setPositiveButton(R.string.action_uninstall, (dialog, which) -> {
                        pref.edit().putBoolean("uninstall_dialog_shown", true).apply();

                        try {
                            startActivity(new Intent(Intent.ACTION_DELETE,
                                    Uri.parse("package:" + BuildConfig.BASE_APPLICATION_ID)));
                        } catch (ActivityNotFoundException e) {
                            /* Gracefully fail */ }
                    });

            if (pref.getBoolean("uninstall_dialog_shown", false))
                builder.setNegativeButton(R.string.action_dont_show_again, (dialogInterface, i) -> pref.edit()
                        .putBoolean("dont_show_uninstall_dialog", true).apply());

            AlertDialog dialog = builder.create();
            dialog.show();
            dialog.setCancelable(false);
        }

        if (!pref.getBoolean("uninstall_dialog_shown", false)) {
            if (theSwitch != null)
                theSwitch.setChecked(false);

            SharedPreferences.Editor editor = pref.edit();

            String iconPack = pref.getString("icon_pack", BuildConfig.BASE_APPLICATION_ID);
            if (iconPack.contains(BuildConfig.BASE_APPLICATION_ID)) {
                editor.putString("icon_pack", BuildConfig.APPLICATION_ID);
            } else {
                U.refreshPinnedIcons(this);
            }

            editor.putBoolean("first_run", true);
            editor.apply();
        }
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
        ShortcutManager shortcutManager = getSystemService(ShortcutManager.class);

        if (shortcutManager.getDynamicShortcuts().size() == 0) {
            Intent intent = new Intent(Intent.ACTION_MAIN);
            intent.setClass(this, StartTaskbarActivity.class);
            intent.putExtra("is_launching_shortcut", true);

            ShortcutInfo shortcut = new ShortcutInfo.Builder(this, "start_taskbar")
                    .setShortLabel(getString(R.string.start_taskbar))
                    .setIcon(Icon.createWithResource(this, R.drawable.shortcut_icon_start)).setIntent(intent)
                    .build();

            Intent intent2 = new Intent(Intent.ACTION_MAIN);
            intent2.setClass(this, ShortcutActivity.class);
            intent2.putExtra("is_launching_shortcut", true);

            ShortcutInfo shortcut2 = new ShortcutInfo.Builder(this, "freeform_mode")
                    .setShortLabel(getString(R.string.pref_header_freeform))
                    .setIcon(Icon.createWithResource(this, R.drawable.shortcut_icon_freeform))
                    .setIntent(intent2).build();

            shortcutManager.setDynamicShortcuts(Arrays.asList(shortcut, shortcut2));
        }
    }
}

From source file:com.android.launcher3.widget.DigitalAppWidgetProvider.java

private void updateClock(Context context, AppWidgetManager appWidgetManager, int appWidgetId, float ratio) {
    RemoteViews widget = new RemoteViews(context.getPackageName(), R.layout.digital_appwidget);

    // Launch setinngs when clicking on the time in the widget only if not a lock screen widget
    Bundle newOptions = appWidgetManager.getAppWidgetOptions(appWidgetId);
    if (newOptions != null && newOptions.getInt(AppWidgetManager.OPTION_APPWIDGET_HOST_CATEGORY,
            -1) != AppWidgetProviderInfo.WIDGET_CATEGORY_KEYGUARD) {
        Intent mIntent = new Intent(Intent.ACTION_MAIN);
        mIntent.addCategory(Intent.CATEGORY_LAUNCHER);
        ComponentName component = new ComponentName("com.android.settings", "com.android.settings.Settings");
        mIntent.setComponent(component);
        widget.setOnClickPendingIntent(R.id.digital_appwidget,
                PendingIntent.getActivity(context, 0, mIntent, 0));
    }/*from  w  w w. j a  va 2 s  .c o m*/

    //cg sai.pan begin
    refreshWifiStatus(context, widget);
    refreshBtStatus(context, widget);
    refreshAirplaneStatus(context, widget,
            Settings.Global.getInt(context.getContentResolver(), Settings.Global.AIRPLANE_MODE_ON, 0) != 0);
    mLocationManager = (LocationManager) context.getSystemService(context.LOCATION_SERVICE);
    refreshGpsStatus(context, widget, mLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER));
    //refreshDataStatus(context, widget, Settings.Global.getInt(context.getContentResolver(), Settings.Global.MOBILE_DATA, 0) != 0);
    requestLocation(context);
    //cg sai.pan end

    // SPRD for bug421127 add am/pm for widget
    WidgetUtils.setTimeFormat(widget, (int) context.getResources().getDimension(R.dimen.widget_label_font_size),
            R.id.the_clock);
    WidgetUtils.setClockSize(context, widget, ratio);

    // Set today's date format
    CharSequence dateFormat = DateFormat.getBestDateTimePattern(Locale.getDefault(),
            context.getString(R.string.abbrev_wday_month_day_no_year));
    widget.setCharSequence(R.id.date, "setFormat12Hour", dateFormat);
    widget.setCharSequence(R.id.date, "setFormat24Hour", dateFormat);

    appWidgetManager.updateAppWidget(appWidgetId, widget);
}

From source file:com.trellmor.berrytubechat.ChatActivity.java

private void loadPreferences() {
    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
    try {/*from   w  w  w  .j  a va 2 s .  com*/
        mScrollback = Integer.parseInt(settings.getString(MainActivity.KEY_SCROLLBACK, "100"));
    } catch (NumberFormatException e) {
        mScrollback = 100;
    }

    if (mScrollback <= 0)
        mScrollback = 100;

    if (mBinder != null)
        mBinder.getService().setChatMsgBufferSize(mScrollback);

    try {
        mFlair = Integer.parseInt(settings.getString(MainActivity.KEY_FLAIR, "0"));
    } catch (NumberFormatException e) {
        mFlair = 0;
    }

    if (settings.getBoolean(MainActivity.KEY_SQUEE, false)) {
        mNotification = new NotificationCompat.Builder(this);
        mNotification.setSmallIcon(R.drawable.ic_stat_notify_chat);
        mNotification.setLights(0xFF0000FF, 100, 2000);
        mNotification.setAutoCancel(true);

        Intent intent = new Intent(this, ChatActivity.class);
        intent.putExtra(MainActivity.KEY_USERNAME, mUsername);
        intent.putExtra(MainActivity.KEY_PASSWORD, mPassword);
        intent.setAction(Intent.ACTION_MAIN);
        intent.addCategory(Intent.CATEGORY_LAUNCHER);
        intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP
                | Intent.FLAG_ACTIVITY_PREVIOUS_IS_TOP | Intent.FLAG_ACTIVITY_NO_HISTORY);

        mNotification.setContentIntent(
                PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT));
        String squee = settings.getString(MainActivity.KEY_SQUEE_RINGTONE, "");
        if (!"".equals(squee)) {
            mNotification.setSound(Uri.parse(squee), AudioManager.STREAM_NOTIFICATION);
        }
        if (settings.getBoolean(MainActivity.KEY_SQUEE_VIBRATE, false)) {
            mNotification.setVibrate(new long[] { 0, 100 });
        }
    } else {
        mNotification = null;
    }

    boolean showVideo = settings.getBoolean(MainActivity.KEY_VIDEO, false);
    if (showVideo != mShowVideo) {
        // If the value has changed, act on it
        if (showVideo) {
            if (!mFirstPrefLoad) {
                Toast.makeText(this, R.string.toast_video_enabled, Toast.LENGTH_LONG).show();
            }
        } else {
            mBinder.getService().disableVideoMessages();
            setTextVideoVisible(false);
        }
    }
    mShowVideo = showVideo;

    mShowDrinkCount = settings.getBoolean(MainActivity.KEY_DRINKCOUNT, true);
    mPopupPoll = settings.getBoolean(MainActivity.KEY_POPUP_POLL, false);
    updateDrinkCount();

    mFirstPrefLoad = false;
}

From source file:com.spydiko.rotationmanager.MainActivity.java

public void updateApps() {
    //      if(AppSpecificOrientation.LOG) Log.d(TAG, "0");
    Intent localIntent = new Intent("android.intent.action.MAIN", null);
    localIntent.addCategory("android.intent.category.LAUNCHER");
    //      if(AppSpecificOrientation.LOG) Log.d(TAG, "1");
    packageManager = getPackageManager();
    //      if(AppSpecificOrientation.LOG) Log.d(TAG, "2");
    List<ResolveInfo> rInfo = packageManager.queryIntentActivities(localIntent, 1);
    //      if(AppSpecificOrientation.LOG) Log.d(TAG, "3");
    List<ApplicationInfo> packages = new ArrayList<ApplicationInfo>();
    //      if(AppSpecificOrientation.LOG) Log.d(TAG, "4");
    for (ResolveInfo info : rInfo) {
        packages.add(info.activityInfo.applicationInfo);
    }//from   w w w  . j a va 2 s.  c o m
    Model temp;
    for (ApplicationInfo packageInfo : packages) {
        //         if(AppSpecificOrientation.LOG) Log.d(TAG, "Installed package :" + packageInfo.packageName);
        if (names.contains(packageInfo.packageName)) {
            continue;
        }
        names.add(packageInfo.packageName);
        temp = new Model((String) packageManager.getApplicationLabel(packageInfo));
        temp.setPackageName(packageInfo.packageName);
        Drawable pic = packageInfo.loadIcon(packageManager);
        temp.setLabel(pic);
        //         if(AppSpecificOrientation.LOG) Log.d(TAG, "Installed package :" + temp.getName());
        //temp.put(IS_CHECKED, true);
        if (myapp.loadPreferences(packageInfo.packageName, true))
            temp.setSelectedPortrait(true);
        if (myapp.loadPreferences(packageInfo.packageName, false))
            temp.setSelectedLandscape(true);
        activities.add(temp);

        //         if(AppSpecificOrientation.LOG) Log.d(TAG, "Launch Activity :" + packageManager.getLaunchIntentForPackage(packageInfo.packageName));
    }
    // Search and show launchers
    final Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_HOME);
    final ResolveInfo res = packageManager.resolveActivity(intent, 0);
    if (res.activityInfo == null) {
        // should not happen. A home is always installed, isn't it?
    } else if (!names.contains(res.activityInfo.applicationInfo.packageName)) {
        names.add(res.activityInfo.applicationInfo.packageName);
        Model launcher = new Model(
                (String) packageManager.getApplicationLabel(res.activityInfo.applicationInfo));
        launcher.setPackageName(res.activityInfo.applicationInfo.packageName);
        Drawable launcher_pic = res.activityInfo.applicationInfo.loadIcon(packageManager);
        launcher.setLabel(launcher_pic);
        if (myapp.loadPreferences(res.activityInfo.applicationInfo.packageName, true))
            launcher.setSelectedPortrait(true);
        if (myapp.loadPreferences(res.activityInfo.applicationInfo.packageName, false))
            launcher.setSelectedLandscape(true);
        activities.add(launcher);
    }
    if (!names.contains("com.android.phone")) {
        names.add("com.android.phone");
        Model phone = new Model("Phone During Call");
        phone.setPackageName("com.android.phone");
        Drawable ic_phone = getResources().getDrawable(R.drawable.ic_phone);
        phone.setLabel(ic_phone);
        if (myapp.loadPreferences("com.android.phone", true))
            phone.setSelectedPortrait(true);
        if (myapp.loadPreferences("com.android.phone", false))
            phone.setSelectedLandscape(true);
        activities.add(phone);
    }

    Collections.sort(activities, new SortByString());

    Collections.sort(activities, new SortByCheck());

    //      if(AppSpecificOrientation.LOG) Log.d(TAG, "END");
}

From source file:net.ustyugov.jtalk.Notify.java

public static void imgurFileProgress(Status status, String text) {
    JTalkService service = JTalkService.getInstance();
    Intent i = new Intent(service, RosterActivity.class);
    i.setAction(Intent.ACTION_MAIN);
    i.addCategory(Intent.CATEGORY_LAUNCHER);
    i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent contentIntent = PendingIntent.getActivity(service, 0, i, 0);

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(service);
    mBuilder.setContentTitle(service.getString(R.string.SendPhoto));
    mBuilder.setContentText(text);/*from w  w w . j  a v a  2s .  c om*/
    mBuilder.setContentIntent(contentIntent);
    mBuilder.setProgress(0, 0, true);

    if (status == Status.in_progress) {
        mBuilder.setSmallIcon(android.R.drawable.stat_sys_upload);
        mBuilder.setTicker(service.getString(R.string.SendPhoto));
    } else if (status == Status.error) {
        mBuilder.setSmallIcon(android.R.drawable.stat_sys_warning);
        mBuilder.setTicker(service.getString(R.string.Error));
        mBuilder.setAutoCancel(true);
    }

    NotificationManager mng = (NotificationManager) service.getSystemService(Context.NOTIFICATION_SERVICE);
    mng.notify(NOTIFICATION_IMGUR, mBuilder.build());
}

From source file:com.androzic.location.LocationService.java

private Notification getNotification() {
    int msgId = R.string.notif_loc_started;
    int ntfId = R.drawable.ic_stat_locating;
    if (trackingEnabled) {
        msgId = R.string.notif_trk_started;
        ntfId = R.drawable.ic_stat_tracking;
    }//from w w  w  . j a  va 2s  . c  o  m
    if (gpsStatus != LocationService.GPS_OK) {
        msgId = R.string.notif_loc_waiting;
        ntfId = R.drawable.ic_stat_waiting;
    }
    if (gpsStatus == LocationService.GPS_OFF) {
        ntfId = R.drawable.ic_stat_off;
    }
    if (errorTime > 0) {
        msgId = R.string.notif_trk_failure;
        ntfId = R.drawable.ic_stat_failure;
    }

    NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
    builder.setWhen(errorTime);
    builder.setSmallIcon(ntfId);
    Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_LAUNCHER);
    intent.setComponent(new ComponentName(getApplicationContext(), Splash.class));
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
    PendingIntent contentIntent = PendingIntent.getActivity(this, NOTIFICATION_ID, intent, 0);
    builder.setContentIntent(contentIntent);
    builder.setContentTitle(getText(R.string.notif_loc_short));
    if (errorTime > 0 && DEBUG_ERRORS)
        builder.setContentText(errorMsg);
    else
        builder.setContentText(getText(msgId));
    builder.setOngoing(true);

    Notification notification = builder.getNotification();
    return notification;
}

From source file:com.nordicsemi.UART_UDP_PROXY.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);/* ww  w.j a  va2  s  . co  m*/
        showMessage("UART-UDP Proxy 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();
    }
}