Search in sources :

Example 41 with Resources

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

the class KeyguardHostView method shouldEnableMenuKey.

private boolean shouldEnableMenuKey() {
    final Resources res = getResources();
    final boolean configDisabled = res.getBoolean(com.android.internal.R.bool.config_disableMenuKeyInLockScreen);
    final boolean isTestHarness = ActivityManager.isRunningInTestHarness();
    final boolean fileOverride = (new File(ENABLE_MENU_KEY_FILE)).exists();
    return !configDisabled || isTestHarness || fileOverride;
}
Also used : Resources(android.content.res.Resources) File(java.io.File)

Example 42 with Resources

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

the class AssetRedirectionManagerService method generatePackageRedirectionMap.

private PackageRedirectionMap generatePackageRedirectionMap(RedirectionKey key) {
    AssetManager assets = new AssetManager();
    boolean frameworkAssets = key.targetPackageName.equals("android");
    if (!frameworkAssets) {
        PackageInfo pi = getPackageInfo(mContext, key.targetPackageName);
        if (pi == null || pi.applicationInfo == null || assets.addAssetPath(pi.applicationInfo.publicSourceDir) == 0) {
            Log.w(TAG, "Unable to attach target package assets for " + key.targetPackageName);
            return null;
        }
    }
    PackageInfo pi = getPackageInfo(mContext, key.themePackageName);
    if (pi == null || pi.applicationInfo == null || pi.themeInfos == null || assets.addAssetPath(pi.applicationInfo.publicSourceDir) == 0) {
        Log.w(TAG, "Unable to attach theme package assets from " + key.themePackageName);
        return null;
    }
    PackageRedirectionMap resMap = new PackageRedirectionMap();
    /*
         * Apply a special redirection hack for the highest level <style>
         * replacing @android:style/Theme.
         */
    if (frameworkAssets) {
        int themeResourceId = findThemeResourceId(pi.themeInfos, key.themeId);
        assets.generateStyleRedirections(resMap.getNativePointer(), android.R.style.Theme, themeResourceId);
    }
    Resources res = new Resources(assets, null, null);
    generateExplicitRedirections(resMap, res, key.themePackageName, key.targetPackageName);
    return resMap;
}
Also used : AssetManager(android.content.res.AssetManager) PackageInfo(android.content.pm.PackageInfo) PackageRedirectionMap(android.content.res.PackageRedirectionMap) Resources(android.content.res.Resources)

Example 43 with Resources

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

the class AssetRedirectionManagerService method dump.

@Override
protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
    synchronized (mRedirections) {
        final ArrayList<RedirectionKey> filteredKeySet = new ArrayList<RedirectionKey>();
        for (Map.Entry<RedirectionKey, PackageRedirectionMap> entry : mRedirections.entrySet()) {
            PackageRedirectionMap map = entry.getValue();
            if (map != null && map.getPackageId() != -1) {
                filteredKeySet.add(entry.getKey());
            }
        }
        Collections.sort(filteredKeySet, new Comparator<RedirectionKey>() {

            @Override
            public int compare(RedirectionKey a, RedirectionKey b) {
                int comp = a.themePackageName.compareTo(b.themePackageName);
                if (comp != 0) {
                    return comp;
                }
                comp = a.themeId.compareTo(b.themeId);
                if (comp != 0) {
                    return comp;
                }
                return a.targetPackageName.compareTo(b.targetPackageName);
            }
        });
        pw.println("Theme asset redirections:");
        String lastPackageName = null;
        String lastId = null;
        Resources themeRes = null;
        for (RedirectionKey key : filteredKeySet) {
            if (lastPackageName == null || !lastPackageName.equals(key.themePackageName)) {
                pw.println("* Theme package " + key.themePackageName + ":");
                lastPackageName = key.themePackageName;
                themeRes = getUnredirectedResourcesForPackage(mContext, key.themePackageName);
            }
            if (lastId == null || !lastId.equals(key.themeId)) {
                pw.println("  theme id #" + key.themeId + ":");
                lastId = key.themeId;
            }
            pw.println("    " + key.targetPackageName + ":");
            Resources targetRes = getUnredirectedResourcesForPackage(mContext, key.targetPackageName);
            PackageRedirectionMap resMap = mRedirections.get(key);
            int[] fromIdents = resMap.getRedirectionKeys();
            int N = fromIdents.length;
            for (int i = 0; i < N; i++) {
                int fromIdent = fromIdents[i];
                int toIdent = resMap.lookupRedirection(fromIdent);
                String fromName = targetRes != null ? targetRes.getResourceName(fromIdent) : null;
                String toName = themeRes != null ? themeRes.getResourceName(toIdent) : null;
                pw.println(String.format("      %s (0x%08x) => %s (0x%08x)", fromName, fromIdent, toName, toIdent));
            }
        }
    }
}
Also used : PackageRedirectionMap(android.content.res.PackageRedirectionMap) ArrayList(java.util.ArrayList) Resources(android.content.res.Resources) PackageRedirectionMap(android.content.res.PackageRedirectionMap) HashMap(java.util.HashMap) Map(java.util.Map)

Example 44 with Resources

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

the class AppWidgetServiceImpl method parseProviderInfoXml.

private Provider parseProviderInfoXml(ComponentName component, ResolveInfo ri) {
    Provider p = null;
    ActivityInfo activityInfo = ri.activityInfo;
    XmlResourceParser parser = null;
    try {
        parser = activityInfo.loadXmlMetaData(mContext.getPackageManager(), AppWidgetManager.META_DATA_APPWIDGET_PROVIDER);
        if (parser == null) {
            Slog.w(TAG, "No " + AppWidgetManager.META_DATA_APPWIDGET_PROVIDER + " meta-data for " + "AppWidget provider '" + component + '\'');
            return null;
        }
        AttributeSet attrs = Xml.asAttributeSet(parser);
        int type;
        while ((type = parser.next()) != XmlPullParser.END_DOCUMENT && type != XmlPullParser.START_TAG) {
        // drain whitespace, comments, etc.
        }
        String nodeName = parser.getName();
        if (!"appwidget-provider".equals(nodeName)) {
            Slog.w(TAG, "Meta-data does not start with appwidget-provider tag for" + " AppWidget provider '" + component + '\'');
            return null;
        }
        p = new Provider();
        AppWidgetProviderInfo info = p.info = new AppWidgetProviderInfo();
        info.provider = component;
        p.uid = activityInfo.applicationInfo.uid;
        Resources res = mContext.getPackageManager().getResourcesForApplicationAsUser(activityInfo.packageName, mUserId);
        TypedArray sa = res.obtainAttributes(attrs, com.android.internal.R.styleable.AppWidgetProviderInfo);
        // These dimensions has to be resolved in the application's context.
        // We simply send back the raw complex data, which will be
        // converted to dp in {@link AppWidgetManager#getAppWidgetInfo}.
        TypedValue value = sa.peekValue(com.android.internal.R.styleable.AppWidgetProviderInfo_minWidth);
        info.minWidth = value != null ? value.data : 0;
        value = sa.peekValue(com.android.internal.R.styleable.AppWidgetProviderInfo_minHeight);
        info.minHeight = value != null ? value.data : 0;
        value = sa.peekValue(com.android.internal.R.styleable.AppWidgetProviderInfo_minResizeWidth);
        info.minResizeWidth = value != null ? value.data : info.minWidth;
        value = sa.peekValue(com.android.internal.R.styleable.AppWidgetProviderInfo_minResizeHeight);
        info.minResizeHeight = value != null ? value.data : info.minHeight;
        info.updatePeriodMillis = sa.getInt(com.android.internal.R.styleable.AppWidgetProviderInfo_updatePeriodMillis, 0);
        info.initialLayout = sa.getResourceId(com.android.internal.R.styleable.AppWidgetProviderInfo_initialLayout, 0);
        info.initialKeyguardLayout = sa.getResourceId(com.android.internal.R.styleable.AppWidgetProviderInfo_initialKeyguardLayout, 0);
        String className = sa.getString(com.android.internal.R.styleable.AppWidgetProviderInfo_configure);
        if (className != null) {
            info.configure = new ComponentName(component.getPackageName(), className);
        }
        info.label = activityInfo.loadLabel(mContext.getPackageManager()).toString();
        info.icon = ri.getIconResource();
        info.previewImage = sa.getResourceId(com.android.internal.R.styleable.AppWidgetProviderInfo_previewImage, 0);
        info.autoAdvanceViewId = sa.getResourceId(com.android.internal.R.styleable.AppWidgetProviderInfo_autoAdvanceViewId, -1);
        info.resizeMode = sa.getInt(com.android.internal.R.styleable.AppWidgetProviderInfo_resizeMode, AppWidgetProviderInfo.RESIZE_NONE);
        info.widgetCategory = sa.getInt(com.android.internal.R.styleable.AppWidgetProviderInfo_widgetCategory, AppWidgetProviderInfo.WIDGET_CATEGORY_HOME_SCREEN);
        sa.recycle();
    } catch (Exception e) {
        // Ok to catch Exception here, because anything going wrong because
        // of what a client process passes to us should not be fatal for the
        // system process.
        Slog.w(TAG, "XML parsing failed for AppWidget provider '" + component + '\'', e);
        return null;
    } finally {
        if (parser != null)
            parser.close();
    }
    return p;
}
Also used : ActivityInfo(android.content.pm.ActivityInfo) XmlResourceParser(android.content.res.XmlResourceParser) AttributeSet(android.util.AttributeSet) TypedArray(android.content.res.TypedArray) AppWidgetProviderInfo(android.appwidget.AppWidgetProviderInfo) ComponentName(android.content.ComponentName) Resources(android.content.res.Resources) Point(android.graphics.Point) FileNotFoundException(java.io.FileNotFoundException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) RemoteException(android.os.RemoteException) IOException(java.io.IOException) TypedValue(android.util.TypedValue)

Example 45 with Resources

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

the class ConnectivityService method setProvNotificationVisible.

private void setProvNotificationVisible(boolean visible, int networkType, String extraInfo, String url) {
    if (DBG) {
        log("setProvNotificationVisible: E visible=" + visible + " networkType=" + networkType + " extraInfo=" + extraInfo + " url=" + url);
    }
    Resources r = Resources.getSystem();
    NotificationManager notificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
    if (visible) {
        CharSequence title;
        CharSequence details;
        int icon;
        Intent intent;
        Notification notification = new Notification();
        switch(networkType) {
            case ConnectivityManager.TYPE_WIFI:
                title = r.getString(R.string.wifi_available_sign_in, 0);
                details = r.getString(R.string.network_available_sign_in_detailed, extraInfo);
                icon = R.drawable.stat_notify_wifi_in_range;
                intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
                intent.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK);
                notification.contentIntent = PendingIntent.getActivity(mContext, 0, intent, 0);
                break;
            case ConnectivityManager.TYPE_MOBILE:
            case ConnectivityManager.TYPE_MOBILE_HIPRI:
                title = r.getString(R.string.network_available_sign_in, 0);
                // TODO: Change this to pull from NetworkInfo once a printable
                // name has been added to it
                details = mTelephonyManager.getNetworkOperatorName();
                icon = R.drawable.stat_notify_rssi_in_range;
                intent = new Intent(CONNECTED_TO_PROVISIONING_NETWORK_ACTION);
                intent.putExtra("EXTRA_URL", url);
                intent.setFlags(0);
                notification.contentIntent = PendingIntent.getBroadcast(mContext, 0, intent, 0);
                break;
            default:
                title = r.getString(R.string.network_available_sign_in, 0);
                details = r.getString(R.string.network_available_sign_in_detailed, extraInfo);
                icon = R.drawable.stat_notify_rssi_in_range;
                intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
                intent.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK);
                notification.contentIntent = PendingIntent.getActivity(mContext, 0, intent, 0);
                break;
        }
        notification.when = 0;
        notification.icon = icon;
        notification.flags = Notification.FLAG_AUTO_CANCEL;
        notification.tickerText = title;
        notification.setLatestEventInfo(mContext, title, details, notification.contentIntent);
        try {
            notificationManager.notify(NOTIFICATION_ID, 1, notification);
        } catch (NullPointerException npe) {
            loge("setNotificaitionVisible: visible notificationManager npe=" + npe);
            npe.printStackTrace();
        }
    } else {
        try {
            notificationManager.cancel(NOTIFICATION_ID, 1);
        } catch (NullPointerException npe) {
            loge("setNotificaitionVisible: cancel notificationManager npe=" + npe);
            npe.printStackTrace();
        }
    }
    mIsNotificationVisible = visible;
}
Also used : NotificationManager(android.app.NotificationManager) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) Resources(android.content.res.Resources) Notification(android.app.Notification)

Aggregations

Resources (android.content.res.Resources)3195 Context (android.content.Context)292 Intent (android.content.Intent)280 View (android.view.View)236 TextView (android.widget.TextView)214 IOException (java.io.IOException)209 PackageManager (android.content.pm.PackageManager)206 Drawable (android.graphics.drawable.Drawable)197 Paint (android.graphics.Paint)178 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)176 Bitmap (android.graphics.Bitmap)174 DisplayMetrics (android.util.DisplayMetrics)165 Configuration (android.content.res.Configuration)151 Point (android.graphics.Point)151 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)137 ArrayList (java.util.ArrayList)134 XmlResourceParser (android.content.res.XmlResourceParser)132 TypedArray (android.content.res.TypedArray)129 Test (org.junit.Test)126 PendingIntent (android.app.PendingIntent)122