Search in sources :

Example 46 with Resources

use of android.content.res.Resources in project android_frameworks_base by ParanoidAndroid.

the class NotificationManagerService method idDebugString.

private static String idDebugString(Context baseContext, String packageName, int id) {
    Context c = null;
    if (packageName != null) {
        try {
            c = baseContext.createPackageContext(packageName, 0);
        } catch (NameNotFoundException e) {
            c = baseContext;
        }
    } else {
        c = baseContext;
    }
    String pkg;
    String type;
    String name;
    Resources r = c.getResources();
    try {
        return r.getResourceName(id);
    } catch (Resources.NotFoundException e) {
        return "<name unknown>";
    }
}
Also used : Context(android.content.Context) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) Resources(android.content.res.Resources)

Example 47 with Resources

use of android.content.res.Resources in project android_frameworks_base by ParanoidAndroid.

the class Tethering method showTetheredNotification.

private void showTetheredNotification(int icon) {
    NotificationManager notificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
    if (notificationManager == null) {
        return;
    }
    if (mTetheredNotification != null) {
        if (mTetheredNotification.icon == icon) {
            return;
        }
        notificationManager.cancelAsUser(null, mTetheredNotification.icon, UserHandle.ALL);
    }
    Intent intent = new Intent();
    intent.setClassName("com.android.settings", "com.android.settings.TetherSettings");
    intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
    PendingIntent pi = PendingIntent.getActivityAsUser(mContext, 0, intent, 0, null, UserHandle.CURRENT);
    Resources r = Resources.getSystem();
    CharSequence title = r.getText(com.android.internal.R.string.tethered_notification_title);
    CharSequence message = r.getText(com.android.internal.R.string.tethered_notification_message);
    if (mTetheredNotification == null) {
        mTetheredNotification = new Notification();
        mTetheredNotification.when = 0;
    }
    mTetheredNotification.icon = icon;
    mTetheredNotification.defaults &= ~Notification.DEFAULT_SOUND;
    mTetheredNotification.flags = Notification.FLAG_ONGOING_EVENT;
    mTetheredNotification.tickerText = title;
    mTetheredNotification.setLatestEventInfo(getUiContext(), title, message, pi);
    notificationManager.notifyAsUser(null, mTetheredNotification.icon, mTetheredNotification, UserHandle.ALL);
}
Also used : NotificationManager(android.app.NotificationManager) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent) Resources(android.content.res.Resources) Notification(android.app.Notification)

Example 48 with Resources

use of android.content.res.Resources in project android_frameworks_base by ParanoidAndroid.

the class ActivityStack method screenshotActivities.

public final Bitmap screenshotActivities(ActivityRecord who) {
    if (who.noDisplay) {
        return null;
    }
    Resources res = mService.mContext.getResources();
    int w = mThumbnailWidth;
    int h = mThumbnailHeight;
    if (w < 0) {
        int mAndroidDpi = ExtendedPropertiesUtils.getActualProperty("android.dpi");
        mThumbnailWidth = w = Math.round((float) res.getDimensionPixelSize(com.android.internal.R.dimen.thumbnail_width) * DisplayMetrics.DENSITY_DEVICE / mAndroidDpi);
        mThumbnailHeight = h = Math.round((float) res.getDimensionPixelSize(com.android.internal.R.dimen.thumbnail_height) * DisplayMetrics.DENSITY_DEVICE / mAndroidDpi);
    }
    if (w > 0) {
        if (who != mLastScreenshotActivity || mLastScreenshotBitmap == null || mLastScreenshotBitmap.getWidth() != w || mLastScreenshotBitmap.getHeight() != h) {
            mLastScreenshotActivity = who;
            mLastScreenshotBitmap = mService.mWindowManager.screenshotApplications(who.appToken, Display.DEFAULT_DISPLAY, w, h);
        }
        if (mLastScreenshotBitmap != null) {
            return mLastScreenshotBitmap.copy(Config.ARGB_8888, true);
        }
    }
    return null;
}
Also used : Resources(android.content.res.Resources)

Example 49 with Resources

use of android.content.res.Resources in project android_frameworks_base by ParanoidAndroid.

the class InputManagerService method visitKeyboardLayoutsInPackage.

private void visitKeyboardLayoutsInPackage(PackageManager pm, ActivityInfo receiver, String keyboardName, KeyboardLayoutVisitor visitor) {
    Bundle metaData = receiver.metaData;
    if (metaData == null) {
        return;
    }
    int configResId = metaData.getInt(InputManager.META_DATA_KEYBOARD_LAYOUTS);
    if (configResId == 0) {
        Log.w(TAG, "Missing meta-data '" + InputManager.META_DATA_KEYBOARD_LAYOUTS + "' on receiver " + receiver.packageName + "/" + receiver.name);
        return;
    }
    CharSequence receiverLabel = receiver.loadLabel(pm);
    String collection = receiverLabel != null ? receiverLabel.toString() : "";
    try {
        Resources resources = pm.getResourcesForApplication(receiver.applicationInfo);
        XmlResourceParser parser = resources.getXml(configResId);
        try {
            XmlUtils.beginDocument(parser, "keyboard-layouts");
            for (; ; ) {
                XmlUtils.nextElement(parser);
                String element = parser.getName();
                if (element == null) {
                    break;
                }
                if (element.equals("keyboard-layout")) {
                    TypedArray a = resources.obtainAttributes(parser, com.android.internal.R.styleable.KeyboardLayout);
                    try {
                        String name = a.getString(com.android.internal.R.styleable.KeyboardLayout_name);
                        String label = a.getString(com.android.internal.R.styleable.KeyboardLayout_label);
                        int keyboardLayoutResId = a.getResourceId(com.android.internal.R.styleable.KeyboardLayout_keyboardLayout, 0);
                        if (name == null || label == null || keyboardLayoutResId == 0) {
                            Log.w(TAG, "Missing required 'name', 'label' or 'keyboardLayout' " + "attributes in keyboard layout " + "resource from receiver " + receiver.packageName + "/" + receiver.name);
                        } else {
                            String descriptor = KeyboardLayoutDescriptor.format(receiver.packageName, receiver.name, name);
                            if (keyboardName == null || name.equals(keyboardName)) {
                                visitor.visitKeyboardLayout(resources, descriptor, label, collection, keyboardLayoutResId);
                            }
                        }
                    } finally {
                        a.recycle();
                    }
                } else {
                    Log.w(TAG, "Skipping unrecognized element '" + element + "' in keyboard layout resource from receiver " + receiver.packageName + "/" + receiver.name);
                }
            }
        } finally {
            parser.close();
        }
    } catch (Exception ex) {
        Log.w(TAG, "Could not parse keyboard layout resource from receiver " + receiver.packageName + "/" + receiver.name, ex);
    }
}
Also used : XmlResourceParser(android.content.res.XmlResourceParser) Bundle(android.os.Bundle) TypedArray(android.content.res.TypedArray) Resources(android.content.res.Resources) SettingNotFoundException(android.provider.Settings.SettingNotFoundException) FileNotFoundException(java.io.FileNotFoundException) NotFoundException(android.content.res.Resources.NotFoundException) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) RemoteException(android.os.RemoteException) IOException(java.io.IOException)

Example 50 with Resources

use of android.content.res.Resources in project android_frameworks_base by ParanoidAndroid.

the class InputManagerService method getKeyboardLayoutOverlay.

// Native callback.
private String[] getKeyboardLayoutOverlay(String inputDeviceDescriptor) {
    if (!mSystemReady) {
        return null;
    }
    String keyboardLayoutDescriptor = getCurrentKeyboardLayoutForInputDevice(inputDeviceDescriptor);
    if (keyboardLayoutDescriptor == null) {
        return null;
    }
    final String[] result = new String[2];
    visitKeyboardLayout(keyboardLayoutDescriptor, new KeyboardLayoutVisitor() {

        @Override
        public void visitKeyboardLayout(Resources resources, String descriptor, String label, String collection, int keyboardLayoutResId) {
            try {
                result[0] = descriptor;
                result[1] = Streams.readFully(new InputStreamReader(resources.openRawResource(keyboardLayoutResId)));
            } catch (IOException ex) {
            } catch (NotFoundException ex) {
            }
        }
    });
    if (result[0] == null) {
        Log.w(TAG, "Could not get keyboard layout with descriptor '" + keyboardLayoutDescriptor + "'.");
        return null;
    }
    return result;
}
Also used : InputStreamReader(java.io.InputStreamReader) SettingNotFoundException(android.provider.Settings.SettingNotFoundException) FileNotFoundException(java.io.FileNotFoundException) NotFoundException(android.content.res.Resources.NotFoundException) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) Resources(android.content.res.Resources) IOException(java.io.IOException)

Aggregations

Resources (android.content.res.Resources)3268 Context (android.content.Context)304 Intent (android.content.Intent)286 View (android.view.View)239 TextView (android.widget.TextView)217 PackageManager (android.content.pm.PackageManager)216 IOException (java.io.IOException)212 Drawable (android.graphics.drawable.Drawable)199 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)179 Paint (android.graphics.Paint)179 DisplayMetrics (android.util.DisplayMetrics)175 Bitmap (android.graphics.Bitmap)174 Configuration (android.content.res.Configuration)154 Point (android.graphics.Point)153 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)139 ArrayList (java.util.ArrayList)137 XmlResourceParser (android.content.res.XmlResourceParser)133 TypedArray (android.content.res.TypedArray)132 Test (org.junit.Test)127 PendingIntent (android.app.PendingIntent)123