Example usage for android.content ComponentName ComponentName

List of usage examples for android.content ComponentName ComponentName

Introduction

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

Prototype

private ComponentName(String pkg, Parcel in) 

Source Link

Usage

From source file:com.eugene.fithealthmaingit.UI.NavFragments.FragmentJournalMainHome.java

/**
 * Equation for all of the Nutrition and Meal information
 */// ww w  . j  av  a 2 s . c  o m
private void equations() {
    double mCalorieGoal = Double.valueOf(sharedPreferences.getString(Globals.USER_CALORIES_TO_REACH_GOAL, ""));
    double mFatGoal = Double.valueOf(sharedPreferences.getString(Globals.USER_DAILY_FAT, ""));
    double mCarbGoal = Double.valueOf(sharedPreferences.getString(Globals.USER_DAILY_CARBOHYDRATES, ""));
    double mProteinGoal = Double.valueOf(sharedPreferences.getString(Globals.USER_DAILY_PROTEIN, ""));
    mCalorieGoalMeal = Double.valueOf(sharedPreferences.getString(Globals.USER_CALORIES_TO_REACH_GOAL, "")) / 4;

    icSnack = (ImageView) v.findViewById(R.id.icSnack);
    icBreakfast = (ImageView) v.findViewById(R.id.icBreakfast);
    icLunch = (ImageView) v.findViewById(R.id.icLunch);
    icDinner = (ImageView) v.findViewById(R.id.icDinner);

    // _________________________Calories Snack_____________________________
    double mCalConsumedSnack = 0;
    for (LogMeal logMeal : mLogSnackAdapter.getLogs()) {
        mCalConsumedSnack += logMeal.getCalorieCount();
    }
    mCalSnack.setText(df.format(mCalConsumedSnack));

    // Set icon visible and color based on calories consumed for meal.
    if (mCalConsumedSnack >= mCalorieGoalMeal + 100) {
        icSnack.setImageResource(R.mipmap.ic_check_circle);
        icSnack.setColorFilter(Color.parseColor("#F44336"), android.graphics.PorterDuff.Mode.MULTIPLY);
    } else if (mCalConsumedSnack > mCalorieGoalMeal - 100 && mCalConsumedSnack < mCalorieGoalMeal + 99) {
        icSnack.setImageResource(R.mipmap.ic_check_circle);
        icSnack.setColorFilter(Color.parseColor("#4CAF50"), android.graphics.PorterDuff.Mode.MULTIPLY);
    } else {
        icSnack.setImageResource(R.mipmap.ic_check);
        icSnack.setColorFilter(Color.parseColor("#6D6D6D"), android.graphics.PorterDuff.Mode.MULTIPLY);
    }

    // _________________________Calories Breakfast_____________________________
    double mCalConsumedBreakfast = 0;
    for (LogMeal logMeal : mLogBreakfastAdapter.getLogs()) {
        mCalConsumedBreakfast += logMeal.getCalorieCount();
    }
    mCalBreakfast.setText(df.format(mCalConsumedBreakfast));

    // Set icon visible and color based on calories consumed for meal.
    if (mCalConsumedBreakfast >= mCalorieGoalMeal + 100) {
        icBreakfast.setColorFilter(Color.parseColor("#F44336"), android.graphics.PorterDuff.Mode.MULTIPLY);
        icBreakfast.setImageResource(R.mipmap.ic_check_circle);
    } else if (mCalConsumedBreakfast > mCalorieGoalMeal - 100
            && mCalConsumedBreakfast < mCalorieGoalMeal + 99) {
        icBreakfast.setColorFilter(Color.parseColor("#4CAF50"), android.graphics.PorterDuff.Mode.MULTIPLY);
        icBreakfast.setImageResource(R.mipmap.ic_check_circle);
    } else {
        icBreakfast.setImageResource(R.mipmap.ic_check);
        icBreakfast.setColorFilter(Color.parseColor("#6D6D6D"), android.graphics.PorterDuff.Mode.MULTIPLY);
    }

    // _________________________Calories Lunch_____________________________
    double mCalConsumedLunch = 0;
    for (LogMeal logMeal : mLogLunchAdapter.getLogs()) {
        mCalConsumedLunch += logMeal.getCalorieCount();
    }
    mCalLunch.setText(df.format(mCalConsumedLunch));

    // Set icon visible and color based on calories consumed for meal.
    if (mCalConsumedLunch >= mCalorieGoalMeal + 100) {
        icLunch.setImageResource(R.mipmap.ic_check_circle);
        icLunch.setColorFilter(Color.parseColor("#F44336"), android.graphics.PorterDuff.Mode.MULTIPLY);
    } else if (mCalConsumedLunch > mCalorieGoalMeal - 100 && mCalConsumedLunch < mCalorieGoalMeal + 99) {
        icLunch.setImageResource(R.mipmap.ic_check_circle);
        icLunch.setColorFilter(Color.parseColor("#4CAF50"), android.graphics.PorterDuff.Mode.MULTIPLY);
    } else {
        icLunch.setImageResource(R.mipmap.ic_check);
        icLunch.setColorFilter(Color.parseColor("#6D6D6D"), android.graphics.PorterDuff.Mode.MULTIPLY);
    }

    // _________________________Calories Lunch_____________________________
    double mCalConsumedDinner = 0;
    for (LogMeal logMeal : mLogDinnerAdapter.getLogs()) {
        mCalConsumedDinner += logMeal.getCalorieCount();
    }
    mCalDinner.setText(df.format(mCalConsumedDinner));

    // Set icon visible and color based on calories consumed for meal.
    if (mCalConsumedDinner >= mCalorieGoalMeal + 100) {
        icDinner.setImageResource(R.mipmap.ic_check_circle);
        icDinner.setColorFilter(Color.parseColor("#F44336"), android.graphics.PorterDuff.Mode.MULTIPLY);
    } else if (mCalConsumedDinner > mCalorieGoalMeal - 100 && mCalConsumedDinner < mCalorieGoalMeal + 99) {
        icDinner.setImageResource(R.mipmap.ic_check_circle);
        icDinner.setColorFilter(Color.parseColor("#4CAF50"), android.graphics.PorterDuff.Mode.MULTIPLY);
    } else {
        icDinner.setImageResource(R.mipmap.ic_check);
        icDinner.setColorFilter(Color.parseColor("#6D6D6D"), android.graphics.PorterDuff.Mode.MULTIPLY);
    }

    // _________________________Calories, Fat, Carbs, Protein All_____________________________
    // Nutrition Consumed
    double mAllCaloriesConsumed = 0;
    double mAllFatConsumed = 0;
    double mAllCarbsConsumed = 0;
    double mAllProteinConsumed = 0;

    for (LogMeal logMeal : mLogAdapterAll.getLogs()) {
        mAllCaloriesConsumed += logMeal.getCalorieCount();
        mAllFatConsumed += logMeal.getFatCount();
        mAllCarbsConsumed += logMeal.getCarbCount();
        mAllProteinConsumed += logMeal.getProteinCount();
    }
    // Nutrition Goals
    // Remainder Nutrition
    mCaloriesRemainder.setText(df.format(mCalorieGoal - mAllCaloriesConsumed) + " Left");
    mFatRemainder.setText(df.format(mFatGoal - mAllFatConsumed) + " Left");
    mCarbRemainder.setText(df.format(mCarbGoal - mAllCarbsConsumed) + " Left");
    mProteinRemainder.setText(df.format(mProteinGoal - mAllProteinConsumed) + " Left");
    // Progress bars

    mPbCalories.setMax(Integer.valueOf(df.format(mCalorieGoal)));
    mPbCalories.setProgress(Integer.valueOf(df.format(mAllCaloriesConsumed)));
    mPbFat.setMax(Integer.valueOf(df.format(mFatGoal)));
    mPbFat.setProgress(Integer.valueOf(df.format(mAllFatConsumed)));
    mPbCarbs.setMax(Integer.valueOf(df.format(mCarbGoal)));
    mPbCarbs.setProgress(Integer.valueOf(df.format(mAllCarbsConsumed)));
    mPbProtein.setMax(Integer.valueOf(df.format(mProteinGoal)));
    mPbProtein.setProgress(Integer.valueOf(df.format(mAllProteinConsumed)));

    /**
     * Update Widget
     */
    Context context = getActivity();
    AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
    if (appWidgetManager != null) {
        RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.new_app_widget);
        ComponentName thisWidget = new ComponentName(context, FitHealthWidget.class);

        views.setProgressBar(R.id.pbCal, Integer.valueOf(df.format(mCalorieGoal)),
                Integer.valueOf(df.format(mAllCaloriesConsumed)), false);
        views.setProgressBar(R.id.pbFat, Integer.valueOf(df.format(mFatGoal)),
                Integer.valueOf(df.format(mAllFatConsumed)), false);
        views.setProgressBar(R.id.pbCarb, Integer.valueOf(df.format(mCarbGoal)),
                Integer.valueOf(df.format(mAllCarbsConsumed)), false);
        views.setProgressBar(R.id.pbPro, Integer.valueOf(df.format(mProteinGoal)),
                Integer.valueOf(df.format(mAllProteinConsumed)), false);

        views.setTextViewText(R.id.txtRemainderCal, df.format(mCalorieGoal - mAllCaloriesConsumed));
        views.setTextViewText(R.id.txtRemainderFat, df.format(mFatGoal - mAllFatConsumed));
        views.setTextViewText(R.id.txtRemainderCarb, df.format(mCarbGoal - mAllCarbsConsumed));
        views.setTextViewText(R.id.txtRemainderPro, df.format(mProteinGoal - mAllProteinConsumed));

        appWidgetManager.updateAppWidget(thisWidget, views);
    }
}

From source file:com.wojtechnology.sunami.TheBrain.java

private void registerAudio() {
    if (mHasAudioFocus || !mIsInit) {
        return;//  w w  w . j a  va2s .  co m
    }
    mHasAudioFocus = true;

    // Add audio focus change listener
    mAFChangeListener = new AudioManager.OnAudioFocusChangeListener() {
        public void onAudioFocusChange(int focusChange) {
            if (focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT) {
                pausePlayback();
                setUI(false);
            } else if (focusChange == AudioManager.AUDIOFOCUS_GAIN) {
                // Does nothing cause made me play music at work
            } else if (focusChange == AudioManager.AUDIOFOCUS_LOSS) {
                pausePlayback();
                unregisterAudio();
                setUI(false);
            }
        }
    };

    mAudioManager.requestAudioFocus(mAFChangeListener, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN);

    // Add headphone out listener
    registerReceiver(mNoisyAudioStreamReceiver, new IntentFilter(AudioManager.ACTION_AUDIO_BECOMING_NOISY));

    // Add notification and transport controls
    ComponentName eventReceiver = new ComponentName(getPackageName(),
            RemoteControlEventReceiver.class.getName());
    mSession = new MediaSessionCompat(this, "FireSession", eventReceiver, null);
    mSession.setFlags(
            MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS | MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS);
    mSession.setPlaybackToLocal(AudioManager.STREAM_MUSIC);
    mSession.setMetadata(new MediaMetadataCompat.Builder().putString(MediaMetadataCompat.METADATA_KEY_TITLE, "")
            .putString(MediaMetadataCompat.METADATA_KEY_ALBUM_ARTIST, "")
            .putLong(MediaMetadata.METADATA_KEY_DURATION, -1).build());

    mSession.setCallback(new MediaSessionCompat.Callback() {

        @Override
        public void onSeekTo(long pos) {
            super.onSeekTo(pos);
            setProgress((int) pos, isPlaying());
        }
    });
    mSession.setActive(true);
}

From source file:com.csipsimple.ui.dialpad.DialerFragment.java

public void placeVMCall() {
    Long accountToUse = SipProfile.INVALID_ID;
    SipProfile acc = null;/*from  w ww .  ja  v  a  2 s .c o m*/
    acc = accountChooserButton.getSelectedAccount();
    if (acc == null) {
        // Maybe we could inform user nothing will happen here?
        return;
    }

    accountToUse = acc.id;

    if (accountToUse >= 0) {
        SipProfile vmAcc = SipProfile.getProfileFromDbId(getActivity(), acc.id,
                new String[] { SipProfile.FIELD_VOICE_MAIL_NBR });
        if (!TextUtils.isEmpty(vmAcc.vm_nbr)) {
            // Account already have a VM number
            try {
                service.makeCall(vmAcc.vm_nbr, (int) acc.id);
            } catch (RemoteException e) {
                Log.e(THIS_FILE, "Service can't be called to make the call");
            }
        } else {
            // Account has no VM number, propose to create one
            final long editedAccId = acc.id;
            LayoutInflater factory = LayoutInflater.from(getActivity());
            final View textEntryView = factory.inflate(R.layout.alert_dialog_text_entry, null);

            missingVoicemailDialog = new AlertDialog.Builder(getActivity()).setTitle(acc.display_name)
                    .setView(textEntryView)
                    .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {

                            if (missingVoicemailDialog != null) {
                                TextView tf = (TextView) missingVoicemailDialog.findViewById(R.id.vmfield);
                                if (tf != null) {
                                    String vmNumber = tf.getText().toString();
                                    if (!TextUtils.isEmpty(vmNumber)) {
                                        ContentValues cv = new ContentValues();
                                        cv.put(SipProfile.FIELD_VOICE_MAIL_NBR, vmNumber);

                                        int updated = getActivity().getContentResolver()
                                                .update(ContentUris.withAppendedId(
                                                        SipProfile.ACCOUNT_ID_URI_BASE, editedAccId), cv, null,
                                                        null);
                                        Log.d(THIS_FILE, "Updated accounts " + updated);
                                    }
                                }
                                missingVoicemailDialog.hide();
                            }
                        }
                    }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            if (missingVoicemailDialog != null) {
                                missingVoicemailDialog.hide();
                            }
                        }
                    }).create();

            // When the dialog is up, completely hide the in-call UI
            // underneath (which is in a partially-constructed state).
            missingVoicemailDialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);

            missingVoicemailDialog.show();
        }
    } else if (accountToUse == CallHandlerPlugin.getAccountIdForCallHandler(getActivity(),
            (new ComponentName(getActivity(), com.csipsimple.plugins.telephony.CallHandler.class)
                    .flattenToString()))) {
        // Case gsm voice mail
        TelephonyManager tm = (TelephonyManager) getActivity().getSystemService(Context.TELEPHONY_SERVICE);
        String vmNumber = tm.getVoiceMailNumber();

        if (!TextUtils.isEmpty(vmNumber)) {
            if (service != null) {
                try {
                    service.ignoreNextOutgoingCallFor(vmNumber);
                } catch (RemoteException e) {
                    Log.e(THIS_FILE, "Not possible to ignore next");
                }
            }
            Intent intent = new Intent(Intent.ACTION_CALL, Uri.fromParts("tel", vmNumber, null));
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intent);
        } else {

            missingVoicemailDialog = new AlertDialog.Builder(getActivity()).setTitle(R.string.gsm)
                    .setMessage(R.string.no_voice_mail_configured)
                    .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {
                            if (missingVoicemailDialog != null) {
                                missingVoicemailDialog.hide();
                            }
                        }
                    }).create();

            // When the dialog is up, completely hide the in-call UI
            // underneath (which is in a partially-constructed state).
            missingVoicemailDialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);

            missingVoicemailDialog.show();
        }
    }
    // TODO : manage others ?... for now, no way to do so cause no vm stored
}

From source file:es.javocsoft.android.lib.toolbox.ToolBox.java

/**
 * Switches the component status of an Activity Alias. Use this to enable or disable it. If the
 * activity alias points to an Activity with android.intent.category.LAUNCHER intent, it will
 * remove/add the launcher icon in the applications menu.
 *
 * @param context           The application context
 * @param appClass          Class of the activity alias
 * @param appLaunchAlias    The android:name of the activity-alias entry in the manifest.
 */// w  ww.j a  v a 2 s  .c  o  m
public static void application_activityAliasSwitchStatus(Context context, Class appClass,
        String appLaunchAlias) {
    ComponentName component = new ComponentName(appClass.getPackage().getName(),
            appClass.getPackage().getName() + "." + appLaunchAlias);
    if (context.getPackageManager()
            .getComponentEnabledSetting(component) == PackageManager.COMPONENT_ENABLED_STATE_ENABLED) {
        application_activityAliasStatusSwitch(context, appClass, appLaunchAlias,
                PackageManager.COMPONENT_ENABLED_STATE_DISABLED);
    } else if (context.getPackageManager()
            .getComponentEnabledSetting(component) == PackageManager.COMPONENT_ENABLED_STATE_DISABLED) {
        application_activityAliasStatusSwitch(context, appClass, appLaunchAlias,
                PackageManager.COMPONENT_ENABLED_STATE_ENABLED);
    }
}

From source file:com.aimfire.main.MainActivity.java

/**
 * share only to certain apps. code based on "http://stackoverflow.com/questions/
 * 9730243/how-to-filter-specific-apps-for-action-send-intent-and-set-a-different-
 * text-for/18980872#18980872"//  w ww  .j  a  v a 2  s .c o  m
 *
 * "copy link" inspired by http://cketti.de/2016/06/15/share-url-to-clipboard/
 *
 * in general, "deep linking" is supported by the apps below. Facebook, Wechat,
 * Telegram are exceptions. click on the link would bring users to the landing
 * page.
 *
 * Facebook doesn't take our EXTRA_TEXT so user will have to "copy link" first
 * then paste the link
 */
private void inviteFriend() {
    mFirebaseAnalytics.logEvent(MainConsts.FIREBASE_CUSTOM_EVENT_INVITE, null);

    Resources resources = getResources();

    /*
     * construct link
     */
    String appLink = resources.getString(R.string.app_store_link);

    /*
     * message subject and text
     */
    String emailSubject, emailText, twitterText;

    emailSubject = resources.getString(R.string.emailSubjectInviteFriend);
    emailText = resources.getString(R.string.emailBodyInviteFriend) + appLink;
    twitterText = resources.getString(R.string.emailBodyInviteFriend) + appLink + ", "
            + resources.getString(R.string.app_hashtag);

    Intent emailIntent = new Intent();
    emailIntent.setAction(Intent.ACTION_SEND);
    // Native email client doesn't currently support HTML, but it doesn't hurt to try in case they fix it
    emailIntent.putExtra(Intent.EXTRA_SUBJECT, emailSubject);
    emailIntent.putExtra(Intent.EXTRA_TEXT, emailText);
    //emailIntent.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(resources.getString(R.string.share_email_native)));
    emailIntent.setType("message/rfc822");

    PackageManager pm = getPackageManager();
    Intent sendIntent = new Intent(Intent.ACTION_SEND);
    sendIntent.setType("text/plain");

    Intent openInChooser = Intent.createChooser(emailIntent, resources.getString(R.string.share_chooser_text));

    List<ResolveInfo> resInfo = pm.queryIntentActivities(sendIntent, 0);
    List<LabeledIntent> intentList = new ArrayList<LabeledIntent>();
    for (int i = 0; i < resInfo.size(); i++) {
        // Extract the label, append it, and repackage it in a LabeledIntent
        ResolveInfo ri = resInfo.get(i);
        String packageName = ri.activityInfo.packageName;
        if (packageName.contains("android.email")) {
            emailIntent.setPackage(packageName);
        } else if (packageName.contains("twitter") || packageName.contains("facebook")
                || packageName.contains("whatsapp") || packageName.contains("tencent.mm") || //wechat
                packageName.contains("line") || packageName.contains("skype") || packageName.contains("viber")
                || packageName.contains("kik") || packageName.contains("sgiggle") || //tango
                packageName.contains("kakao") || packageName.contains("telegram")
                || packageName.contains("nimbuzz") || packageName.contains("hike")
                || packageName.contains("imoim") || packageName.contains("bbm")
                || packageName.contains("threema") || packageName.contains("mms")
                || packageName.contains("android.apps.messaging") || //google messenger
                packageName.contains("android.talk") || //google hangouts
                packageName.contains("android.gm")) {
            Intent intent = new Intent();
            intent.setComponent(new ComponentName(packageName, ri.activityInfo.name));
            intent.setAction(Intent.ACTION_SEND);
            intent.setType("text/plain");
            if (packageName.contains("twitter")) {
                intent.putExtra(Intent.EXTRA_TEXT, twitterText);
            } else if (packageName.contains("facebook")) {
                /*
                 * the warning below is wrong! at least on GS5, Facebook client does take
                 * our text, however it seems it takes only the first hyperlink in the
                 * text.
                 *
                 * Warning: Facebook IGNORES our text. They say "These fields are intended
                 * for users to express themselves. Pre-filling these fields erodes the
                 * authenticity of the user voice."
                 * One workaround is to use the Facebook SDK to post, but that doesn't
                 * allow the user to choose how they want to share. We can also make a
                 * custom landing page, and the link will show the <meta content ="...">
                 * text from that page with our link in Facebook.
                 */
                intent.putExtra(Intent.EXTRA_TEXT, appLink);
            } else if (packageName.contains("tencent.mm")) //wechat
            {
                /*
                 * wechat appears to do this similar to Facebook
                 */
                intent.putExtra(Intent.EXTRA_TEXT, appLink);
            } else if (packageName.contains("android.gm")) {
                // If Gmail shows up twice, try removing this else-if clause and the reference to "android.gm" above
                intent.putExtra(Intent.EXTRA_SUBJECT, emailSubject);
                intent.putExtra(Intent.EXTRA_TEXT, emailText);
                //intent.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(resources.getString(R.string.share_email_gmail)));
                intent.setType("message/rfc822");
            } else if (packageName.contains("android.apps.docs")) {
                /*
                 * google drive - no reason to send link to it
                 */
                continue;
            } else {
                intent.putExtra(Intent.EXTRA_TEXT, emailText);
            }

            intentList.add(new LabeledIntent(intent, packageName, ri.loadLabel(pm), ri.icon));
        }
    }

    /*
     *  create "Copy Link To Clipboard" Intent
     */
    Intent clipboardIntent = new Intent(this, CopyToClipboardActivity.class);
    clipboardIntent.setData(Uri.parse(appLink));
    intentList.add(new LabeledIntent(clipboardIntent, getPackageName(),
            getResources().getString(R.string.clipboard_activity_name), R.drawable.ic_copy_link));

    // convert intentList to array
    LabeledIntent[] extraIntents = intentList.toArray(new LabeledIntent[intentList.size()]);

    openInChooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, extraIntents);
    startActivity(openInChooser);
}

From source file:cw.kop.autobackground.sources.SourceListFragment.java

protected void setWallpaper() {

    final Intent intent = new Intent();
    if (Build.VERSION.SDK_INT >= 16) {
        intent.setAction(WallpaperManager.ACTION_CHANGE_LIVE_WALLPAPER);
        final String packageName = LiveWallpaperService.class.getPackage().getName();
        final String className = LiveWallpaperService.class.getCanonicalName();
        intent.putExtra(WallpaperManager.EXTRA_LIVE_WALLPAPER_COMPONENT,
                new ComponentName(packageName, className));
    } else {// w  w w  .  jav a 2 s  .c o  m
        intent.setAction(WallpaperManager.ACTION_LIVE_WALLPAPER_CHOOSER);
    }

    startActivityForResult(intent, 0);
}

From source file:com.chummy.jezebel.material.dark.activities.Main.java

public boolean isLauncherIconEnabled() {
    PackageManager pm = getPackageManager();
    return (pm.getComponentEnabledSetting(new ComponentName(this,
            com.chummy.jezebel.material.dark.LauncherActivity.class)) != PackageManager.COMPONENT_ENABLED_STATE_DISABLED);
}

From source file:es.javocsoft.android.lib.toolbox.ToolBox.java

private static void application_activityAliasStatusSwitch(Context context, Class appClass,
        String appLaunchAlias, int status) {
    ComponentName component = new ComponentName(appClass.getPackage().getName(),
            appClass.getPackage().getName() + "." + appLaunchAlias);

    if (status == PackageManager.COMPONENT_ENABLED_STATE_DISABLED && (context.getPackageManager()
            .getComponentEnabledSetting(component) == PackageManager.COMPONENT_ENABLED_STATE_ENABLED
            || context.getPackageManager()
                    .getComponentEnabledSetting(component) == PackageManager.COMPONENT_ENABLED_STATE_DEFAULT)) {
        context.getPackageManager().setComponentEnabledSetting(component,
                PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);

    } else if (status == PackageManager.COMPONENT_ENABLED_STATE_ENABLED && (context.getPackageManager()
            .getComponentEnabledSetting(component) == PackageManager.COMPONENT_ENABLED_STATE_DISABLED
            || context.getPackageManager()
                    .getComponentEnabledSetting(component) == PackageManager.COMPONENT_ENABLED_STATE_DEFAULT)) {
        context.getPackageManager().setComponentEnabledSetting(component,
                PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
    }//from  w  ww . j a  v  a 2s . c om
}

From source file:com.chummy.jezebel.material.dark.activities.Main.java

public void setLauncherIconEnabled(boolean enabled) {
    int newState;
    PackageManager pm = getPackageManager();
    if (enabled) {
        newState = PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
    } else {/*from w  ww.ja va2 s .  c om*/
        newState = PackageManager.COMPONENT_ENABLED_STATE_DISABLED;
    }
    pm.setComponentEnabledSetting(
            new ComponentName(this, com.chummy.jezebel.material.dark.LauncherActivity.class), newState,
            PackageManager.DONT_KILL_APP);
}

From source file:com.thejoshwa.ultrasonic.androidapp.util.Util.java

public static void registerMediaButtonEventReceiver(Context context) {
    if (getMediaButtonsPreference(context)) {
        AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
        audioManager.registerMediaButtonEventReceiver(
                new ComponentName(context.getPackageName(), MediaButtonIntentReceiver.class.getName()));

    }//from   w ww .  j  av a  2s  . c o m
}