Search in sources :

Example 31 with NameNotFoundException

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;
}
Also used : Rect(android.graphics.Rect) ViewGroup(android.view.ViewGroup) Canvas(android.graphics.Canvas) Drawable(android.graphics.drawable.Drawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) TransitionDrawable(android.graphics.drawable.TransitionDrawable) Paint(android.graphics.Paint) Notification(android.app.Notification) StatusBarNotification(android.service.notification.StatusBarNotification) ActivityNotFoundException(android.content.ActivityNotFoundException) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) RemoteException(android.os.RemoteException) Paint(android.graphics.Paint) Bitmap(android.graphics.Bitmap) PorterDuffXfermode(android.graphics.PorterDuffXfermode) FrameLayout(android.widget.FrameLayout) StatusBarIcon(com.android.internal.statusbar.StatusBarIcon)

Example 32 with NameNotFoundException

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();
}
Also used : Context(android.content.Context) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) LevelListDrawable(android.graphics.drawable.LevelListDrawable) Drawable(android.graphics.drawable.Drawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) UserInfo(android.content.pm.UserInfo) BitmapDrawable(android.graphics.drawable.BitmapDrawable) Cursor(android.database.Cursor) Bitmap(android.graphics.Bitmap) UserManager(android.os.UserManager) UserHandle(android.os.UserHandle) RemoteException(android.os.RemoteException) Pair(android.util.Pair)

Example 33 with NameNotFoundException

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);
        }
    }
}
Also used : IKlyphFragment(com.abewy.android.apps.klyph.fragment.IKlyphFragment) FragmentTransaction(android.app.FragmentTransaction) PackageManager(android.content.pm.PackageManager) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) Bundle(android.os.Bundle) Intent(android.content.Intent) LoginFragment(com.abewy.android.apps.klyph.fragment.LoginFragment) Fragment(android.app.Fragment) IKlyphFragment(com.abewy.android.apps.klyph.fragment.IKlyphFragment)

Example 34 with NameNotFoundException

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 &lt;meta-data&gt; 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;
}
Also used : NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent)

Example 35 with NameNotFoundException

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("?");
    }
}
Also used : NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) PackageInfo(android.content.pm.PackageInfo) Activity(android.app.Activity)

Aggregations

NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)1012 PackageManager (android.content.pm.PackageManager)358 PackageInfo (android.content.pm.PackageInfo)291 ApplicationInfo (android.content.pm.ApplicationInfo)235 Intent (android.content.Intent)143 ComponentName (android.content.ComponentName)134 ActivityInfo (android.content.pm.ActivityInfo)125 Resources (android.content.res.Resources)112 Context (android.content.Context)105 Drawable (android.graphics.drawable.Drawable)93 Bundle (android.os.Bundle)93 IOException (java.io.IOException)91 UserHandle (android.os.UserHandle)79 ResolveInfo (android.content.pm.ResolveInfo)72 ArrayList (java.util.ArrayList)68 RemoteException (android.os.RemoteException)63 File (java.io.File)57 TextView (android.widget.TextView)52 View (android.view.View)47 FileNotFoundException (java.io.FileNotFoundException)44