List of usage examples for android.content ComponentName ComponentName
private ComponentName(String pkg, Parcel in)
From source file:com.actionbarsherlock.widget.ActivityChooserModel.java
/** * Sets the default activity. The default activity is set by adding a * historical record with weight high enough that this activity will * become the highest ranked. Such a strategy guarantees that the default * will eventually change if not used. Also the weight of the record for * setting a default is inflated with a constant amount to guarantee that * it will stay as default for awhile.// www. ja va 2 s . c o m * * @param index The index of the activity to set as default. */ public void setDefaultActivity(int index) { ActivityResolveInfo newDefaultActivity = mActivites.get(index); ActivityResolveInfo oldDefaultActivity = mActivites.get(0); final float weight; if (oldDefaultActivity != null) { // Add a record with weight enough to boost the chosen at the top. weight = oldDefaultActivity.weight - newDefaultActivity.weight + DEFAULT_ACTIVITY_INFLATION; } else { weight = DEFAULT_HISTORICAL_RECORD_WEIGHT; } ComponentName defaultName = new ComponentName(newDefaultActivity.resolveInfo.activityInfo.packageName, newDefaultActivity.resolveInfo.activityInfo.name); HistoricalRecord historicalRecord = new HistoricalRecord(defaultName, System.currentTimeMillis(), weight); addHisoricalRecord(historicalRecord); }
From source file:com.example.android.home.Home.java
/** * Loads the list of installed applications in mApplications. *///w w w. ja va 2 s. c om private void loadApplications(boolean isLaunching) { if (isLaunching && mApplications != null) { return; } PackageManager manager = getPackageManager(); Intent mainIntent = new Intent(Intent.ACTION_MAIN, null); mainIntent.addCategory(Intent.CATEGORY_LAUNCHER); final List<ResolveInfo> apps = manager.queryIntentActivities(mainIntent, 0); Collections.sort(apps, new ResolveInfo.DisplayNameComparator(manager)); if (apps != null) { final int count = apps.size(); if (mApplications == null) { mApplications = new ArrayList<ApplicationInfo>(count); } mApplications.clear(); for (int i = 0; i < count; i++) { //for (int i = 0; i < 6; i++) { // show only 6 apps ApplicationInfo application = new ApplicationInfo(); ResolveInfo info = apps.get(i); application.title = info.loadLabel(manager); application.setActivity( new ComponentName(info.activityInfo.applicationInfo.packageName, info.activityInfo.name), Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); Log.v("Home APP", "package neme= " + info.activityInfo.applicationInfo.packageName); Log.v("Home APP", "neme= " + info.activityInfo.name); Log.v("Home APP", "title= " + application.title); application.icon = info.activityInfo.loadIcon(manager); // TODO // Replace Icons //if((application.title+"").equals("Calculator")) application.icon = getResources().getDrawable(R.drawable.ic_launcher_home_big); // Add Application if ((application.title + "").equals("Browser")) mApplications.add(application); if ((application.title + "").equals("Phone")) mApplications.add(application); if ((application.title + "").equals("People")) mApplications.add(application); if ((application.title + "").equals("Messaging")) mApplications.add(application); if ((application.title + "").equals("Settings")) mApplications.add(application); } // Took from http://hi-android.info/src/index.html // ********************* ADD Call Log ApplicationInfo application = new ApplicationInfo(); application.title = "Call Log"; application.icon = getResources().getDrawable(R.drawable.ic_launcher_home); application.setActivity( new ComponentName("com.android.contacts", "com.android.contacts.RecentCallsListActivity"), Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); mApplications.add(application); } }
From source file:com.csipsimple.ui.SipHome.java
private void startSipService() { Thread t = new Thread("StartSip") { public void run() { Intent serviceIntent = new Intent(SipManager.INTENT_SIP_SERVICE); // Optional, but here we bundle so just ensure we are using csipsimple package serviceIntent.setPackage(SipHome.this.getPackageName()); serviceIntent.putExtra(SipManager.EXTRA_OUTGOING_ACTIVITY, new ComponentName(SipHome.this, SipHome.class)); startService(serviceIntent); postStartSipService();//from w w w .j a v a2s . c o m }; }; t.start(); }
From source file:com.android.settings.accessibility.AccessibilitySettings.java
private void updateServicePreferences() { // Since services category is auto generated we have to do a pass // to generate it since services can come and go and then based on // the global accessibility state to decided whether it is enabled. // Generate./*from w w w. j ava 2s . c o m*/ ArrayList<Preference> servicePreferences = new ArrayList<>( mServicePreferenceToPreferenceCategoryMap.keySet()); for (int i = 0; i < servicePreferences.size(); i++) { Preference service = servicePreferences.get(i); PreferenceCategory category = mServicePreferenceToPreferenceCategoryMap.get(service); category.removePreference(service); } initializePreBundledServicesMapFromArray(CATEGORY_SCREEN_READER, R.array.config_preinstalled_screen_reader_services); initializePreBundledServicesMapFromArray(CATEGORY_AUDIO_AND_CAPTIONS, R.array.config_preinstalled_audio_and_caption_services); initializePreBundledServicesMapFromArray(CATEGORY_DISPLAY, R.array.config_preinstalled_display_services); initializePreBundledServicesMapFromArray(CATEGORY_INTERACTION_CONTROL, R.array.config_preinstalled_interaction_control_services); AccessibilityManager accessibilityManager = AccessibilityManager.getInstance(getActivity()); List<AccessibilityServiceInfo> installedServices = accessibilityManager .getInstalledAccessibilityServiceList(); Set<ComponentName> enabledServices = AccessibilityUtils.getEnabledServicesFromSettings(getActivity()); List<String> permittedServices = mDpm.getPermittedAccessibilityServices(UserHandle.myUserId()); final boolean accessibilityEnabled = Settings.Secure.getInt(getContentResolver(), Settings.Secure.ACCESSIBILITY_ENABLED, 0) == 1; PreferenceCategory downloadedServicesCategory = mCategoryToPrefCategoryMap .get(CATEGORY_DOWNLOADED_SERVICES); // Temporarily add the downloaded services category back if it was previously removed. if (findPreference(CATEGORY_DOWNLOADED_SERVICES) == null) { getPreferenceScreen().addPreference(downloadedServicesCategory); } for (int i = 0, count = installedServices.size(); i < count; ++i) { AccessibilityServiceInfo info = installedServices.get(i); RestrictedPreference preference = new RestrictedPreference(downloadedServicesCategory.getContext()); String title = info.getResolveInfo().loadLabel(getPackageManager()).toString(); Drawable icon; if (info.getResolveInfo().getIconResource() == 0) { icon = ContextCompat.getDrawable(getContext(), R.mipmap.ic_accessibility_generic); } else { icon = info.getResolveInfo().loadIcon(getPackageManager()); } ServiceInfo serviceInfo = info.getResolveInfo().serviceInfo; String packageName = serviceInfo.packageName; ComponentName componentName = new ComponentName(packageName, serviceInfo.name); String componentNameKey = componentName.flattenToString(); preference.setKey(componentName.flattenToString()); preference.setTitle(title); preference.setIcon(icon); final boolean serviceEnabled = accessibilityEnabled && enabledServices.contains(componentName); final String serviceState = serviceEnabled ? getString(R.string.accessibility_summary_state_enabled) : getString(R.string.accessibility_summary_state_disabled); final CharSequence serviceSummary = info.loadSummary(getPackageManager()); final String stateSummaryCombo = getString(R.string.accessibility_summary_default_combination, serviceState, serviceSummary); preference.setSummary((TextUtils.isEmpty(serviceSummary)) ? serviceState : stateSummaryCombo); // Disable all accessibility services that are not permitted. boolean serviceAllowed = permittedServices == null || permittedServices.contains(packageName); if (!serviceAllowed && !serviceEnabled) { EnforcedAdmin admin = RestrictedLockUtils.checkIfAccessibilityServiceDisallowed(getActivity(), packageName, UserHandle.myUserId()); if (admin != null) { preference.setDisabledByAdmin(admin); } else { preference.setEnabled(false); } } else { preference.setEnabled(true); } preference.setFragment(ToggleAccessibilityServicePreferenceFragment.class.getName()); preference.setPersistent(true); Bundle extras = preference.getExtras(); extras.putString(EXTRA_PREFERENCE_KEY, preference.getKey()); extras.putBoolean(EXTRA_CHECKED, serviceEnabled); extras.putString(EXTRA_TITLE, title); String description = info.loadDescription(getPackageManager()); if (TextUtils.isEmpty(description)) { description = getString(R.string.accessibility_service_default_description); } extras.putString(EXTRA_SUMMARY, description); String settingsClassName = info.getSettingsActivityName(); if (!TextUtils.isEmpty(settingsClassName)) { extras.putString(EXTRA_SETTINGS_TITLE, getString(R.string.accessibility_menu_item_settings)); extras.putString(EXTRA_SETTINGS_COMPONENT_NAME, new ComponentName(packageName, settingsClassName).flattenToString()); } extras.putParcelable(EXTRA_COMPONENT_NAME, componentName); PreferenceCategory prefCategory = downloadedServicesCategory; // Set the appropriate category if the service comes pre-installed. if (mPreBundledServiceComponentToCategoryMap.containsKey(componentName)) { prefCategory = mPreBundledServiceComponentToCategoryMap.get(componentName); } preference.setOrder(FIRST_PREFERENCE_IN_CATEGORY_INDEX); prefCategory.addPreference(preference); mServicePreferenceToPreferenceCategoryMap.put(preference, prefCategory); } // If the user has not installed any additional services, hide the category. if (downloadedServicesCategory.getPreferenceCount() == 0) { PreferenceScreen screen = getPreferenceScreen(); screen.removePreference(downloadedServicesCategory); } }
From source file:com.andryr.musicplayer.PlaybackService.java
private void refreshAppWidgets() { AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(this); int appWidgetIds[] = appWidgetManager.getAppWidgetIds(new ComponentName(this, PlaybackWidget.class)); PlaybackWidget.updateAppWidget(this, appWidgetIds); }
From source file:com.andrew.apollo.MusicPlaybackService.java
private void initService() { // Initialize the favorites and recents databases mFavoritesCache = FavoritesStore.getInstance(this); mRecentsCache = RecentStore.getInstance(this); // Initialize the notification helper mNotificationHelper = new NotificationHelper(this); // Initialize the image fetcher mImageFetcher = ImageFetcher.getInstance(this); // Initialize the image cache mImageFetcher.setImageCache(ImageCache.getInstance(this)); // Start up the thread running the service. Note that we create a // separate thread because the service normally runs in the process's // main thread, which we don't want to block. We also make it // background priority so CPU-intensive work will not disrupt the UI. final HandlerThread thread = new HandlerThread("MusicPlayerHandler", android.os.Process.THREAD_PRIORITY_BACKGROUND); thread.start();// w w w . jav a2 s .c o m // Initialize the handler mPlayerHandler = new MusicPlayerHandler(this, thread.getLooper()); // Initialize the audio manager and register any headset controls for // playback mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); mMediaButtonReceiverComponent = new ComponentName(getPackageName(), MediaButtonIntentReceiver.class.getName()); try { if (mAudioManager != null) { mAudioManager.registerMediaButtonEventReceiver(mMediaButtonReceiverComponent); } } catch (SecurityException e) { e.printStackTrace(); // ignore // some times the phone does not grant the MODIFY_PHONE_STATE permission // this permission is for OMEs and we can't do anything about it } // Use the remote control APIs to set the playback state setUpRemoteControlClient(); // Initialize the preferences mPreferences = getSharedPreferences("Service", 0); mCardId = getCardId(); registerExternalStorageListener(); // Initialize the media player mPlayer = new MultiPlayer(this); mPlayer.setHandler(mPlayerHandler); ConfigurationManager CM = ConfigurationManager.instance(); // Load Repeat Mode setRepeatMode(CM.getInt(Constants.PREF_KEY_GUI_PLAYER_REPEAT_MODE)); // Load Shuffle Mode On/Off enableShuffle(CM.getBoolean(Constants.PREF_KEY_GUI_PLAYER_SHUFFLE_ENABLED)); MusicUtils.isShuffleEnabled(); // Initialize the intent filter and each action final IntentFilter filter = new IntentFilter(); filter.addAction(SERVICECMD); filter.addAction(TOGGLEPAUSE_ACTION); filter.addAction(PAUSE_ACTION); filter.addAction(STOP_ACTION); filter.addAction(NEXT_ACTION); filter.addAction(PREVIOUS_ACTION); filter.addAction(REPEAT_ACTION); filter.addAction(SHUFFLE_ACTION); // Attach the broadcast listener registerReceiver(mIntentReceiver, filter); // Initialize the wake lock final PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE); if (powerManager != null) { mWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, getClass().getName()); mWakeLock.setReferenceCounted(false); } // Initialize the delayed shutdown intent final Intent shutdownIntent = new Intent(this, MusicPlaybackService.class); shutdownIntent.setAction(SHUTDOWN_ACTION); mAlarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); mShutdownIntent = PendingIntent.getService(this, 0, shutdownIntent, 0); // Listen for the idle state scheduleDelayedShutdown(); // Bring the queue back reloadQueue(); notifyChange(QUEUE_CHANGED); notifyChange(META_CHANGED); updateNotification(); }
From source file:com.android.messaging.ui.UIIntentsImpl.java
@Override public Intent getWirelessAlertsIntent() { final Intent intent = new Intent(Intent.ACTION_MAIN); intent.setComponent(new ComponentName(CMAS_COMPONENT, CELL_BROADCAST_LIST_ACTIVITY)); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); return intent; }
From source file:com.abc.driver.PersonalActivity.java
private void doCrop() { Log.d(TAG, "doCrop()"); final ArrayList<CropOption> cropOptions = new ArrayList<CropOption>(); Intent intent = new Intent("com.android.camera.action.CROP"); intent.setType("image/*"); List<ResolveInfo> list = this.getPackageManager().queryIntentActivities(intent, 0); int size = list.size(); if (size == 0) { Log.d(TAG, " Crop activity is not found. List size is zero."); Bitmap tmpBmp = BitmapFactory.decodeFile(imageUri.getPath(), null); app.setPortaritBitmap(Bitmap.createScaledBitmap(tmpBmp, CellSiteConstants.IMAGE_WIDTH, CellSiteConstants.IMAGE_HEIGHT, false)); mUserPortraitIv.setImageBitmap(app.getPortaritBitmap()); isPortraitChanged = true;/*w w w . j av a 2 s. c om*/ Log.d(TAG, "set bitmap"); return; } else { Log.d(TAG, "found the crop activity."); intent.setData(imageUri); intent.putExtra("outputX", CellSiteConstants.IMAGE_WIDTH); intent.putExtra("outputY", CellSiteConstants.IMAGE_HEIGHT); intent.putExtra("aspectX", 1); intent.putExtra("aspectY", 1); intent.putExtra("scale", true); intent.putExtra("return-data", true); if (size == 1) { Log.d(TAG, "Just one as choose it as crop activity."); Intent i = new Intent(intent); ResolveInfo res = list.get(0); i.setComponent(new ComponentName(res.activityInfo.packageName, res.activityInfo.name)); startActivityForResult(i, CellSiteConstants.CROP_PICTURE); } else { Log.d(TAG, "More that one activity for crop is found . will chooose one"); for (ResolveInfo res : list) { final CropOption co = new CropOption(); co.title = getPackageManager().getApplicationLabel(res.activityInfo.applicationInfo); co.icon = getPackageManager().getApplicationIcon(res.activityInfo.applicationInfo); co.appIntent = new Intent(intent); co.appIntent .setComponent(new ComponentName(res.activityInfo.packageName, res.activityInfo.name)); cropOptions.add(co); } CropOptionAdapter adapter = new CropOptionAdapter(getApplicationContext(), cropOptions); AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("Choose Crop App"); builder.setAdapter(adapter, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) { startActivityForResult(cropOptions.get(item).appIntent, CellSiteConstants.CROP_PICTURE); } }); builder.setOnCancelListener(new DialogInterface.OnCancelListener() { // @Override public void onCancel(DialogInterface dialog) { if (imageUri != null) { getContentResolver().delete(imageUri, null, null); imageUri = null; isPortraitChanged = false; } } }); AlertDialog alert = builder.create(); alert.show(); } } }
From source file:net.sourceforge.kalimbaradio.androidapp.util.Util.java
public static void registerMediaButtonEventReceiver(Context context) { // Only do it if enabled in the settings. SharedPreferences prefs = getPreferences(context); boolean enabled = prefs.getBoolean(Constants.PREFERENCES_KEY_MEDIA_BUTTONS, true); if (enabled) { AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); ComponentName mediaButtonIntentReceiver = new ComponentName(context.getPackageName(), MediaButtonIntentReceiver.class.getName()); audioManager.registerMediaButtonEventReceiver(mediaButtonIntentReceiver); }//from w ww . ja va 2 s .co m }
From source file:com.ichi2.anki.PreferenceContext.java
/** * Code which is run when a SharedPreference change has been detected * @param prefs instance of SharedPreferences * @param key key in prefs which is being updated * @param listener PreferenceActivity of PreferenceFragment which is hosting the preference */// w w w .jav a2 s .com private void updatePreference(SharedPreferences prefs, String key, PreferenceContext listener) { try { PreferenceScreen screen = listener.getPreferenceScreen(); Preference pref = screen.findPreference(key); // Handle special cases switch (key) { case "timeoutAnswer": { CheckBoxPreference keepScreenOn = (CheckBoxPreference) screen.findPreference("keepScreenOn"); keepScreenOn.setChecked(((CheckBoxPreference) pref).isChecked()); break; } case LANGUAGE: closePreferences(); break; case "convertFenText": if (((CheckBoxPreference) pref).isChecked()) { ChessFilter.install(Hooks.getInstance(getApplicationContext())); } else { ChessFilter.uninstall(Hooks.getInstance(getApplicationContext())); } break; case "fixHebrewText": if (((CheckBoxPreference) pref).isChecked()) { HebrewFixFilter.install(Hooks.getInstance(getApplicationContext())); showDialog(DIALOG_HEBREW_FONT); } else { HebrewFixFilter.uninstall(Hooks.getInstance(getApplicationContext())); } break; case "showProgress": getCol().getConf().put("dueCounts", ((CheckBoxPreference) pref).isChecked()); getCol().setMod(); break; case "showEstimates": getCol().getConf().put("estTimes", ((CheckBoxPreference) pref).isChecked()); getCol().setMod(); break; case "newSpread": getCol().getConf().put("newSpread", Integer.parseInt(((ListPreference) pref).getValue())); getCol().setMod(); break; case "timeLimit": getCol().getConf().put("timeLim", ((NumberRangePreference) pref).getValue() * 60); getCol().setMod(); break; case "learnCutoff": getCol().getConf().put("collapseTime", ((NumberRangePreference) pref).getValue() * 60); getCol().setMod(); break; case "useCurrent": getCol().getConf().put("addToCur", ((ListPreference) pref).getValue().equals("0")); getCol().setMod(); break; case "dayOffset": { int hours = ((SeekBarPreference) pref).getValue(); Timestamp crtTime = new Timestamp(getCol().getCrt() * 1000); Calendar date = GregorianCalendar.getInstance(); date.setTimeInMillis(crtTime.getTime()); date.set(Calendar.HOUR_OF_DAY, hours); getCol().setCrt(date.getTimeInMillis() / 1000); getCol().setMod(); break; } case "minimumCardsDueForNotification": { ListPreference listpref = (ListPreference) screen.findPreference("minimumCardsDueForNotification"); if (listpref != null) { updateNotificationPreference(listpref); } break; } case "reportErrorMode": { String value = prefs.getString("reportErrorMode", ""); AnkiDroidApp.getInstance().setAcraReportingMode(value); break; } case "syncAccount": { SharedPreferences preferences = AnkiDroidApp.getSharedPrefs(getBaseContext()); String username = preferences.getString("username", ""); Preference syncAccount = screen.findPreference("syncAccount"); if (syncAccount != null) { if (TextUtils.isEmpty(username)) { syncAccount.setSummary(R.string.sync_account_summ_logged_out); } else { syncAccount.setSummary(getString(R.string.sync_account_summ_logged_in, username)); } } break; } case "providerEnabled": { ComponentName providerName = new ComponentName(this, "com.ichi2.anki.provider.CardContentProvider"); PackageManager pm = getPackageManager(); int state; if (((CheckBoxPreference) pref).isChecked()) { state = PackageManager.COMPONENT_ENABLED_STATE_ENABLED; Timber.i("AnkiDroid ContentProvider enabled by user"); } else { state = PackageManager.COMPONENT_ENABLED_STATE_DISABLED; Timber.i("AnkiDroid ContentProvider disabled by user"); } pm.setComponentEnabledSetting(providerName, state, PackageManager.DONT_KILL_APP); break; } } // Update the summary text to reflect new value updateSummary(pref); } catch (BadTokenException e) { Timber.e(e, "Preferences: BadTokenException on showDialog"); } catch (NumberFormatException | JSONException e) { throw new RuntimeException(); } }