use of android.content.pm.PackageManager.NameNotFoundException in project android_frameworks_base by ParanoidAndroid.
the class BaseStatusBar method prepareHaloNotification.
public void prepareHaloNotification(NotificationData.Entry entry, StatusBarNotification notification, boolean update) {
Notification notif = notification.getNotification();
// Get the remote view
try {
if (!update) {
ViewGroup mainView = (ViewGroup) notif.contentView.apply(mContext, null, mOnClickHandler);
if (mainView instanceof FrameLayout) {
entry.haloContent = mainView.getChildAt(1);
mainView.removeViewAt(1);
} else {
entry.haloContent = mainView;
}
} else {
notif.contentView.reapply(mContext, entry.haloContent, mOnClickHandler);
}
} catch (Exception e) {
// Non uniform content?
android.util.Log.d("PARANOID", " Non uniform content?");
}
// Construct the round icon
final float haloSize = Settings.System.getFloat(mContext.getContentResolver(), Settings.System.HALO_SIZE, 1.0f);
int iconSize = (int) (mContext.getResources().getDimensionPixelSize(R.dimen.halo_bubble_size) * haloSize);
int smallIconSize = (int) (mContext.getResources().getDimensionPixelSize(R.dimen.status_bar_icon_size) * haloSize);
int largeIconWidth = notif.largeIcon != null ? (int) (notif.largeIcon.getWidth() * haloSize) : 0;
int largeIconHeight = notif.largeIcon != null ? (int) (notif.largeIcon.getHeight() * haloSize) : 0;
Bitmap roundIcon = Bitmap.createBitmap(iconSize, iconSize, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(roundIcon);
canvas.drawARGB(0, 0, 0, 0);
// halo-bubble, we'll use that one and cut it round
if (notif.largeIcon != null && largeIconWidth >= iconSize / 2) {
Paint smoothingPaint = new Paint();
smoothingPaint.setAntiAlias(true);
smoothingPaint.setFilterBitmap(true);
smoothingPaint.setDither(true);
canvas.drawCircle(iconSize / 2, iconSize / 2, iconSize / 2.3f, smoothingPaint);
smoothingPaint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
final int newWidth = iconSize;
final int newHeight = iconSize * largeIconWidth / largeIconHeight;
Bitmap scaledBitmap = Bitmap.createScaledBitmap(notif.largeIcon, newWidth, newHeight, true);
canvas.drawBitmap(scaledBitmap, null, new Rect(0, 0, iconSize, iconSize), smoothingPaint);
} else {
try {
Drawable icon = StatusBarIconView.getIcon(mContext, new StatusBarIcon(notification.getPackageName(), notification.getUser(), notif.icon, notif.iconLevel, notif.number, notif.tickerText));
if (icon == null)
icon = mContext.getPackageManager().getApplicationIcon(notification.getPackageName());
int margin = (iconSize - smallIconSize) / 2;
icon.setBounds(margin, margin, iconSize - margin, iconSize - margin);
icon.draw(canvas);
} catch (Exception e) {
// NameNotFoundException
}
}
entry.roundIcon = roundIcon;
}
use of android.content.pm.PackageManager.NameNotFoundException in project android_frameworks_base by ParanoidAndroid.
the class QuickSettings method queryForUserInformation.
private void queryForUserInformation() {
Context currentUserContext = null;
UserInfo userInfo = null;
try {
userInfo = ActivityManagerNative.getDefault().getCurrentUser();
currentUserContext = mContext.createPackageContextAsUser("android", 0, new UserHandle(userInfo.id));
} catch (NameNotFoundException e) {
Log.e(TAG, "Couldn't create user context", e);
throw new RuntimeException(e);
} catch (RemoteException e) {
Log.e(TAG, "Couldn't get user info", e);
}
final int userId = userInfo.id;
final String userName = userInfo.name;
final Context context = currentUserContext;
mUserInfoTask = new AsyncTask<Void, Void, Pair<String, Drawable>>() {
@Override
protected Pair<String, Drawable> doInBackground(Void... params) {
final UserManager um = UserManager.get(mContext);
// Fall back to the UserManager nickname if we can't read the name from the local
// profile below.
String name = userName;
Drawable avatar = null;
Bitmap rawAvatar = um.getUserIcon(userId);
if (rawAvatar != null) {
avatar = new BitmapDrawable(mContext.getResources(), rawAvatar);
} else {
avatar = mContext.getResources().getDrawable(R.drawable.ic_qs_default_user);
mUseDefaultAvatar = true;
}
// usually valid
if (um.getUsers().size() <= 1) {
// Try and read the display name from the local profile
final Cursor cursor = context.getContentResolver().query(Profile.CONTENT_URI, new String[] { Phone._ID, Phone.DISPLAY_NAME }, null, null, null);
if (cursor != null) {
try {
if (cursor.moveToFirst()) {
name = cursor.getString(cursor.getColumnIndex(Phone.DISPLAY_NAME));
}
} finally {
cursor.close();
}
}
}
return new Pair<String, Drawable>(name, avatar);
}
@Override
protected void onPostExecute(Pair<String, Drawable> result) {
super.onPostExecute(result);
mModel.setUserTileInfo(result.first, result.second);
mUserInfoTask = null;
}
};
mUserInfoTask.execute();
}
use of android.content.pm.PackageManager.NameNotFoundException in project Klyph by jonathangerbaud.
the class MainActivity method updateContent.
private void updateContent(int selection) {
if (selection != oldSelection) {
Bundle bundle = new Bundle();
bundle.putString(KlyphBundleExtras.ELEMENT_ID, KlyphSession.getSessionUserId());
String className = classes.get(selection);
if (className.equals("com.abewy.android.apps.klyph.fragment.Chat")) {
PackageManager pm = getPackageManager();
try {
pm.getPackageInfo(MESSENGER_PACKAGE_NAME, PackageManager.GET_ACTIVITIES);
Intent intent = getPackageManager().getLaunchIntentForPackage(MESSENGER_PACKAGE_NAME);
startActivity(intent);
} catch (NameNotFoundException e) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(MESSENGER_PLAY_STORE_URI));
intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
startActivity(intent);
}
} else {
if (selection < navAdapter.getCount())
setTitle(navAdapter.getItem(selection));
else
setTitle(KlyphSession.getSessionUserName());
Fragment fragment = Fragment.instantiate(MainActivity.this, className, bundle);
if (previousFragment != null)
previousFragment.onSetToBack(this);
FragmentTransaction tx = getFragmentManager().beginTransaction();
tx.replace(R.id.main, fragment, FRAGMENT_TAG);
tx.commitAllowingStateLoss();
((IKlyphFragment) fragment).onSetToFront(this);
previousFragment = (IKlyphFragment) fragment;
navAdapter.setSelectedPosition(selection);
navAdapter.notifyDataSetChanged();
oldSelection = selection;
if (notificationsFragment != null)
notificationsFragment.setHasOptionsMenu(false);
}
}
}
use of android.content.pm.PackageManager.NameNotFoundException in project android-support-v4-googlemaps by petedoyle.
the class TaskStackBuilder method addParentStack.
/**
* Add the activity parent chain as specified by manifest <meta-data> elements
* to the task stack builder.
*
* @param sourceActivityName Must specify an Activity component. All parents of
* this activity will be added
* @return This TaskStackBuilder for method chaining
*/
public TaskStackBuilder addParentStack(ComponentName sourceActivityName) {
final int insertAt = mIntents.size();
try {
Intent parent = NavUtils.getParentActivityIntent(mSourceContext, sourceActivityName);
while (parent != null) {
mIntents.add(insertAt, parent);
parent = NavUtils.getParentActivityIntent(mSourceContext, parent.getComponent());
}
} catch (NameNotFoundException e) {
Log.e(TAG, "Bad ComponentName while traversing activity parent metadata");
throw new IllegalArgumentException(e);
}
return this;
}
use of android.content.pm.PackageManager.NameNotFoundException in project Etar-Calendar by Etar-Group.
the class AboutPreferences method onCreate.
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
addPreferencesFromResource(R.xml.about_preferences);
final Activity activity = getActivity();
try {
final PackageInfo packageInfo = activity.getPackageManager().getPackageInfo(activity.getPackageName(), 0);
findPreference(BUILD_VERSION).setSummary(packageInfo.versionName);
} catch (NameNotFoundException e) {
findPreference(BUILD_VERSION).setSummary("?");
}
}
Aggregations