List of usage examples for android.content.pm ResolveInfo loadLabel
public CharSequence loadLabel(PackageManager pm)
From source file:br.com.bioscada.apps.biotracks.fragments.ChooseActivityDialogFragment.java
/** * Gets the display info./*from ww w. j a v a 2s. c o m*/ */ private List<DisplayInfo> getDisplayInfos(FragmentActivity fragmentActivity) { List<DisplayInfo> displayInfos = new ArrayList<DisplayInfo>(); Intent intent = ShareCompat.IntentBuilder.from(fragmentActivity).setType(IntentUtils.TEXT_PLAIN_TYPE) .getIntent(); List<ResolveInfo> resolveInfos = packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); if (resolveInfos != null && resolveInfos.size() > 0) { int size = resolveInfos.size(); ResolveInfo firstResolveInfo = resolveInfos.get(0); for (int i = 1; i < size; i++) { ResolveInfo resolveInfo = resolveInfos.get(i); if (firstResolveInfo.priority != resolveInfo.priority || firstResolveInfo.isDefault != resolveInfo.isDefault) { while (i < size) { resolveInfos.remove(i); size--; } } } if (size > 1) { ResolveInfo.DisplayNameComparator displayNameComparator = new ResolveInfo.DisplayNameComparator( packageManager); Collections.sort(resolveInfos, displayNameComparator); } firstResolveInfo = resolveInfos.get(0); int start = 0; CharSequence firstLabel = firstResolveInfo.loadLabel(packageManager); for (int i = 1; i < size; i++) { if (firstLabel == null) { firstLabel = firstResolveInfo.activityInfo.packageName; } ResolveInfo resolveInfo = resolveInfos.get(i); CharSequence label = resolveInfo.loadLabel(packageManager); if (label == null) { label = resolveInfo.activityInfo.packageName; } if (label.equals(firstLabel)) { continue; } processGroup(resolveInfos, displayInfos, start, i - 1); firstResolveInfo = resolveInfo; firstLabel = label; start = i; } // Process last group processGroup(resolveInfos, displayInfos, start, size - 1); } return displayInfos; }
From source file:android.support.v7.internal.widget.ActivityChooserView.java
/** * Updates the buttons state./* ww w.j a va2 s .c om*/ */ private void updateAppearance() { // Expand overflow button. if (mAdapter.getCount() > 0) { mExpandActivityOverflowButton.setEnabled(true); } else { mExpandActivityOverflowButton.setEnabled(false); } // Default activity button. final int activityCount = mAdapter.getActivityCount(); final int historySize = mAdapter.getHistorySize(); if (activityCount == 1 || activityCount > 1 && historySize > 0) { mDefaultActivityButton.setVisibility(VISIBLE); ResolveInfo activity = mAdapter.getDefaultActivity(); PackageManager packageManager = getContext().getPackageManager(); mDefaultActivityButtonImage.setImageDrawable(activity.loadIcon(packageManager)); if (mDefaultActionButtonContentDescription != 0) { CharSequence label = activity.loadLabel(packageManager); String contentDescription = getContext().getString(mDefaultActionButtonContentDescription, label); mDefaultActivityButton.setContentDescription(contentDescription); } } else { mDefaultActivityButton.setVisibility(View.GONE); } // Activity chooser content. if (mDefaultActivityButton.getVisibility() == VISIBLE) { mActivityChooserContent.setBackgroundDrawable(mActivityChooserContentBackground); } else { mActivityChooserContent.setBackgroundDrawable(null); } }
From source file:org.cowboycoders.cyclisimo.fragments.ChooseActivityDialogFragment.java
/** * Gets the display info.// w w w .java 2 s . c om */ private List<DisplayInfo> getDisplayInfos() { List<DisplayInfo> displayInfos = new ArrayList<DisplayInfo>(); Intent intent = ShareCompat.IntentBuilder.from(activity).setType(IntentUtils.TEXT_PLAIN_TYPE).getIntent(); List<ResolveInfo> resolveInfos = packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); if (resolveInfos != null && resolveInfos.size() > 0) { int size = resolveInfos.size(); ResolveInfo firstResolveInfo = resolveInfos.get(0); for (int i = 1; i < size; i++) { ResolveInfo resolveInfo = resolveInfos.get(i); if (firstResolveInfo.priority != resolveInfo.priority || firstResolveInfo.isDefault != resolveInfo.isDefault) { while (i < size) { resolveInfos.remove(i); size--; } } } if (size > 1) { ResolveInfo.DisplayNameComparator displayNameComparator = new ResolveInfo.DisplayNameComparator( packageManager); Collections.sort(resolveInfos, displayNameComparator); } firstResolveInfo = resolveInfos.get(0); int start = 0; CharSequence firstLabel = firstResolveInfo.loadLabel(packageManager); for (int i = 1; i < size; i++) { if (firstLabel == null) { firstLabel = firstResolveInfo.activityInfo.packageName; } ResolveInfo resolveInfo = resolveInfos.get(i); CharSequence label = resolveInfo.loadLabel(packageManager); if (label == null) { label = resolveInfo.activityInfo.packageName; } if (label.equals(firstLabel)) { continue; } processGroup(resolveInfos, displayInfos, start, i - 1); firstResolveInfo = resolveInfo; firstLabel = label; start = i; } // Process last group processGroup(resolveInfos, displayInfos, start, size - 1); } return displayInfos; }
From source file:com.actionbarsherlock.widget.ActivityChooserView.java
/** * Updates the buttons state.//from w w w . j av a2 s .c om */ private void updateAppearance() { // Expand overflow button. if (mAdapter.getCount() > 0) { mExpandActivityOverflowButton.setEnabled(true); } else { mExpandActivityOverflowButton.setEnabled(false); } // Default activity button. final int activityCount = mAdapter.getActivityCount(); final int historySize = mAdapter.getHistorySize(); if (activityCount > 0 && historySize > 0) { mDefaultActivityButton.setVisibility(VISIBLE); ResolveInfo activity = mAdapter.getDefaultActivity(); PackageManager packageManager = mContext.getPackageManager(); mDefaultActivityButtonImage.setImageDrawable(activity.loadIcon(packageManager)); if (mDefaultActionButtonContentDescription != 0) { CharSequence label = activity.loadLabel(packageManager); String contentDescription = mContext.getString(mDefaultActionButtonContentDescription, label); mDefaultActivityButton.setContentDescription(contentDescription); } } else { mDefaultActivityButton.setVisibility(View.GONE); } // Activity chooser content. if (mDefaultActivityButton.getVisibility() == VISIBLE) { mActivityChooserContent.setBackgroundDrawable(mActivityChooserContentBackground); } else { mActivityChooserContent.setBackgroundDrawable(null); } }
From source file:de.baumann.thema.RequestActivity.java
@SuppressWarnings("unchecked") private void prepareData() // Sort the apps { ArrayList<AppInfo> arrayList = new ArrayList(); PackageManager pm = getPackageManager(); Intent intent = new Intent("android.intent.action.MAIN", null); intent.addCategory("android.intent.category.LAUNCHER"); List list = pm.queryIntentActivities(intent, 0); Iterator localIterator = list.iterator(); if (DEBUG)//from ww w . j a va 2s. c o m Log.v(TAG, "list.size(): " + list.size()); for (int i = 0; i < list.size(); i++) { ResolveInfo resolveInfo = (ResolveInfo) localIterator.next(); // This is the main part where the already styled apps are sorted out. if ((list_activities .indexOf(resolveInfo.activityInfo.packageName + "/" + resolveInfo.activityInfo.name) == -1)) { AppInfo tempAppInfo = new AppInfo( resolveInfo.activityInfo.packageName + "/" + resolveInfo.activityInfo.name, //Get package/activity resolveInfo.loadLabel(pm).toString(), //Get the app name getHighResIcon(pm, resolveInfo) //Loads xxxhdpi icon, returns normal if it on fail //Unselect icon per default ); arrayList.add(tempAppInfo); // This is just for debugging if (DEBUG) Log.i(TAG, "Added app: " + resolveInfo.loadLabel(pm)); } else { // This is just for debugging if (DEBUG) Log.v(TAG, "Removed app: " + resolveInfo.loadLabel(pm)); } } Collections.sort(arrayList, new Comparator<AppInfo>() { //Custom comparator to ensure correct sorting for characters like and apps starting with a small letter like iNex @Override public int compare(AppInfo object1, AppInfo object2) { Locale locale = Locale.getDefault(); Collator collator = Collator.getInstance(locale); collator.setStrength(Collator.TERTIARY); if (DEBUG) Log.v(TAG, "Comparing \"" + object1.getName() + "\" to \"" + object2.getName() + "\""); return collator.compare(object1.getName(), object2.getName()); } }); list_activities_final = arrayList; }
From source file:tv.piratemedia.lightcontroler.controller.java
private void setupApp() { mActionBarToolbar = (Toolbar) findViewById(R.id.toolbar_actionbar); setSupportActionBar(mActionBarToolbar); prefs = PreferenceManager.getDefaultSharedPreferences(this); if (!prefs.getBoolean("rgbw_enabled", false) && !prefs.getBoolean("white_enabled", false)) { askControlType();//from w w w .ja v a 2 s . co m } else { final ViewPager pager = (ViewPager) findViewById(R.id.pager); pager.setAdapter(new ControllerPager(getSupportFragmentManager(), this)); tabs = (PagerSlidingTabStrip) findViewById(R.id.pager_title_strip); tabs.setViewPager(pager); if (!prefs.getBoolean("navigation_tabs", false)) { drawer.setProfile(new DrawerProfile().setAvatar(getResources().getDrawable(R.drawable.icon)) .setBackground(getResources().getDrawable(R.drawable.drawer_profile_background)) .setName("Light Controller")); mActionBarToolbar = (Toolbar) findViewById(R.id.toolbar_actionbar); mActionBarToolbar.setNavigationIcon(R.drawable.ic_menu_white_24dp); pager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { } @Override public void onPageSelected(int position) { mActionBarToolbar.setTitle(pager.getAdapter().getPageTitle(position)); } @Override public void onPageScrollStateChanged(int state) { } }); this.setTitle(pager.getAdapter().getPageTitle(0)); mActionBarToolbar.setTitle(pager.getAdapter().getPageTitle(0)); tabs.setVisibility(View.GONE); for (int i = 0; i < pager.getAdapter().getCount(); i++) { if (i == 5) { drawer.addDivider(); } drawer.addItem(new DrawerItem().setTextMode(DrawerItem.SINGLE_LINE) .setTextPrimary(pager.getAdapter().getPageTitle(i).toString()) .setOnItemClickListener(new DrawerItem.OnItemClickListener() { @Override public void onClick(DrawerItem drawerItem, int i, int i2) { int item = i2; if (item > 4) { item--; } pager.setCurrentItem(item, true); drawer.closeDrawer(); } })); } drawer.addDivider(); drawer.addItem(new DrawerItem().setTextMode(DrawerItem.SINGLE_LINE) .setTextPrimary(getResources().getString(R.string.action_settings)) .setOnItemClickListener(new DrawerItem.OnItemClickListener() { @Override public void onClick(DrawerItem drawerItem, int i, int i2) { Intent intent = new Intent(getApplicationContext(), controlPreferences.class); startActivity(intent); finish(); drawer.closeDrawer(); } })); final PackageManager pm = getPackageManager(); Intent mainIntent = new Intent(Intent.ACTION_MAIN, null); mainIntent.addCategory("tv.piratemedia.lightcontroller.plugin"); List<ResolveInfo> resolveInfos = pm.queryIntentActivities(mainIntent, 0); if (resolveInfos.size() > 0) { drawer.addDivider(); for (final ResolveInfo info : resolveInfos) { drawer.addItem(new DrawerItem().setTextMode(DrawerItem.SINGLE_LINE) .setTextPrimary(info.loadLabel(pm).toString()).setImage(info.loadIcon(pm)) .setOnItemClickListener(new DrawerItem.OnItemClickListener() { @Override public void onClick(DrawerItem drawerItem, int i, int i2) { Intent intent = new Intent(Intent.ACTION_MAIN); Log.d("package", "pkg:" + info.resolvePackageName); intent.setComponent(new ComponentName(info.activityInfo.packageName, info.activityInfo.name)); startActivity(intent); drawer.closeDrawer(); } })); } } } else { drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED); } } }
From source file:com.saphion.stencilweather.activities.MainActivity.java
@Override public void onClick(final View view) { initiateActions(true);// ww w.ja v a 2 s .co m new Handler().postDelayed(new Runnable() { @Override public void run() { switch (view.getId()) { case R.id.fab_graph: slidingLayout.setPanelState(SlidingUpPanelLayout.PanelState.EXPANDED); materialMenu.animateIconState(MaterialMenuDrawable.IconState.X); toolbar.getMenu().clear(); actionBarContent(false); toolbar.setTitle(navAdapter.getItem(navSpinner.getSelectedItemPosition())); break; case R.id.fab_map: Intent mapIntent = new Intent(MainActivity.this, MapActivity.class); mapIntent.putExtra("position", navSpinner.getSelectedItemPosition()); startActivity(mapIntent); finish(); break; case R.id.fab_share: AlertDialog.Builder mBuilder = new AlertDialog.Builder(MainActivity.this); View mView = LayoutInflater.from(MainActivity.this).inflate(R.layout.share_weather_layout, null); mBuilder.setView(mView); shareContainer = mView.findViewById(R.id.shareableContainer); final List<Drawable> packageIcons = new ArrayList<>(); final List<String> appNames = new ArrayList<>(); final List<String> packageNames = new ArrayList<>(); final List<String> classNames = new ArrayList<>(); final RecyclerView shareRecyclerView = (RecyclerView) mView.findViewById(R.id.rvWeatherShare); final View flShareableApps = mView.findViewById(R.id.flShareableApps); flShareableApps.setAlpha(0); shareRecyclerView.setVisibility(View.VISIBLE); new AsyncTask<Void, Void, Void>() { @Override protected Void doInBackground(Void... voids) { Intent sendIntent = new Intent(); sendIntent.setAction(Intent.ACTION_SEND); sendIntent.setType("image/jpeg"); List<ResolveInfo> resolveInfoList = getPackageManager() .queryIntentActivities(sendIntent, 0); Collections.sort(resolveInfoList, new ResolveInfo.DisplayNameComparator(getPackageManager())); for (ResolveInfo resolveInfo : resolveInfoList) { Drawable icon = resolveInfo.loadIcon(getPackageManager()); String name = resolveInfo.loadLabel(getPackageManager()).toString(); packageIcons.add(icon); appNames.add(name); packageNames.add(resolveInfo.activityInfo.packageName); classNames.add(resolveInfo.activityInfo.name); } return null; } @Override protected void onPostExecute(Void aVoid) { super.onPostExecute(aVoid); ShareItemViewAdapter shareAdapter = new ShareItemViewAdapter(MainActivity.this, packageIcons, appNames, packageNames, classNames); LinearLayoutManager layoutManager = new LinearLayoutManager(MainActivity.this); layoutManager.setOrientation(LinearLayoutManager.HORIZONTAL); shareRecyclerView.setLayoutManager(layoutManager); shareRecyclerView.setAdapter(shareAdapter); YoYo.with(Techniques.SlideInDown).duration(500).interpolate(new OvershootInterpolator()) .playOn(flShareableApps); } }.execute(); mShareDialog = mBuilder.create(); mShareDialog.getWindow().setWindowAnimations(R.style.DialogAnimation); mShareDialog.getWindow() .setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT)); mShareDialog.show(); break; } } }, 200); }
From source file:com.actionbarsherlock.internal.view.menu.MenuBuilder.java
public int addIntentOptions(int group, int id, int categoryOrder, ComponentName caller, Intent[] specifics, Intent intent, int flags, android.view.MenuItem[] outSpecificItems) { PackageManager pm = mContext.getPackageManager(); final List<ResolveInfo> lri = pm.queryIntentActivityOptions(caller, specifics, intent, 0); final int N = lri != null ? lri.size() : 0; if ((flags & FLAG_APPEND_TO_GROUP) == 0) { removeGroup(group);/*w w w . j av a 2 s.c o m*/ } for (int i = 0; i < N; i++) { final ResolveInfo ri = lri.get(i); Intent rintent = new Intent(ri.specificIndex < 0 ? intent : specifics[ri.specificIndex]); rintent.setComponent( new ComponentName(ri.activityInfo.applicationInfo.packageName, ri.activityInfo.name)); final MenuItem item = add(group, id, categoryOrder, ri.loadLabel(pm)).setIcon(ri.loadIcon(pm)) .setIntent(rintent); if (outSpecificItems != null && ri.specificIndex >= 0) { outSpecificItems[ri.specificIndex] = item; } } return N; }
From source file:com.linkbubble.Settings.java
private boolean setDefaultLeftConsumeBubble(ResolveInfo resolveInfo, PackageManager packageManager) { if (resolveInfo != null) { setConsumeBubble(Constant.BubbleAction.ConsumeLeft, Constant.ActionType.Share, resolveInfo.loadLabel(packageManager).toString(), resolveInfo.activityInfo.packageName, resolveInfo.activityInfo.name); return true; }/*from w w w .j a va2 s . c o m*/ return false; }
From source file:android.support.v7.internal.view.menu.MenuBuilder.java
@Override public int addIntentOptions(int group, int id, int categoryOrder, ComponentName caller, Intent[] specifics, Intent intent, int flags, MenuItem[] outSpecificItems) { PackageManager pm = mContext.getPackageManager(); final List<ResolveInfo> lri = pm.queryIntentActivityOptions(caller, specifics, intent, 0); final int N = lri != null ? lri.size() : 0; if ((flags & FLAG_APPEND_TO_GROUP) == 0) { removeGroup(group);//from www. java2 s.c o m } for (int i = 0; i < N; i++) { final ResolveInfo ri = lri.get(i); Intent rintent = new Intent(ri.specificIndex < 0 ? intent : specifics[ri.specificIndex]); rintent.setComponent( new ComponentName(ri.activityInfo.applicationInfo.packageName, ri.activityInfo.name)); final MenuItem item = add(group, id, categoryOrder, ri.loadLabel(pm)).setIcon(ri.loadIcon(pm)) .setIntent(rintent); if (outSpecificItems != null && ri.specificIndex >= 0) { outSpecificItems[ri.specificIndex] = item; } } return N; }