Search in sources :

Example 36 with Configuration

use of android.content.res.Configuration in project android_frameworks_base by ResurrectionRemix.

the class UsageStatsXmlV1 method loadEvent.

private static void loadEvent(XmlPullParser parser, IntervalStats statsOut) throws XmlPullParserException, IOException {
    final String packageName = XmlUtils.readStringAttribute(parser, PACKAGE_ATTR);
    if (packageName == null) {
        throw new ProtocolException("no " + PACKAGE_ATTR + " attribute present");
    }
    final String className = XmlUtils.readStringAttribute(parser, CLASS_ATTR);
    final UsageEvents.Event event = statsOut.buildEvent(packageName, className);
    // Apply the offset to the beginTime to find the absolute time of this event.
    event.mTimeStamp = statsOut.beginTime + XmlUtils.readLongAttribute(parser, TIME_ATTR);
    event.mEventType = XmlUtils.readIntAttribute(parser, TYPE_ATTR);
    switch(event.mEventType) {
        case UsageEvents.Event.CONFIGURATION_CHANGE:
            event.mConfiguration = new Configuration();
            Configuration.readXmlAttrs(parser, event.mConfiguration);
            break;
        case UsageEvents.Event.SHORTCUT_INVOCATION:
            final String id = XmlUtils.readStringAttribute(parser, SHORTCUT_ID_ATTR);
            event.mShortcutId = (id != null) ? id.intern() : null;
            break;
    }
    if (statsOut.events == null) {
        statsOut.events = new TimeSparseArray<>();
    }
    statsOut.events.put(event.mTimeStamp, event);
}
Also used : ProtocolException(java.net.ProtocolException) Configuration(android.content.res.Configuration) UsageEvents(android.app.usage.UsageEvents)

Example 37 with Configuration

use of android.content.res.Configuration in project android_frameworks_base by ResurrectionRemix.

the class UsageStatsXmlV1 method loadConfigStats.

private static void loadConfigStats(XmlPullParser parser, IntervalStats statsOut) throws XmlPullParserException, IOException {
    final Configuration config = new Configuration();
    Configuration.readXmlAttrs(parser, config);
    final ConfigurationStats configStats = statsOut.getOrCreateConfigurationStats(config);
    // Apply the offset to the beginTime to find the absolute time.
    configStats.mLastTimeActive = statsOut.beginTime + XmlUtils.readLongAttribute(parser, LAST_TIME_ACTIVE_ATTR);
    configStats.mTotalTimeActive = XmlUtils.readLongAttribute(parser, TOTAL_TIME_ACTIVE_ATTR);
    configStats.mActivationCount = XmlUtils.readIntAttribute(parser, COUNT_ATTR);
    if (XmlUtils.readBooleanAttribute(parser, ACTIVE_ATTR)) {
        statsOut.activeConfiguration = configStats.mConfiguration;
    }
}
Also used : ConfigurationStats(android.app.usage.ConfigurationStats) Configuration(android.content.res.Configuration)

Example 38 with Configuration

use of android.content.res.Configuration in project android_frameworks_base by ResurrectionRemix.

the class RenderAction method getConfiguration.

// VisibleForTesting
public static Configuration getConfiguration(RenderParams params) {
    Configuration config = new Configuration();
    HardwareConfig hardwareConfig = params.getHardwareConfig();
    ScreenSize screenSize = hardwareConfig.getScreenSize();
    if (screenSize != null) {
        switch(screenSize) {
            case SMALL:
                config.screenLayout |= Configuration.SCREENLAYOUT_SIZE_SMALL;
                break;
            case NORMAL:
                config.screenLayout |= Configuration.SCREENLAYOUT_SIZE_NORMAL;
                break;
            case LARGE:
                config.screenLayout |= Configuration.SCREENLAYOUT_SIZE_LARGE;
                break;
            case XLARGE:
                config.screenLayout |= Configuration.SCREENLAYOUT_SIZE_XLARGE;
                break;
        }
    }
    Density density = hardwareConfig.getDensity();
    if (density == null) {
        density = Density.MEDIUM;
    }
    config.screenWidthDp = hardwareConfig.getScreenWidth() / density.getDpiValue();
    config.screenHeightDp = hardwareConfig.getScreenHeight() / density.getDpiValue();
    if (config.screenHeightDp < config.screenWidthDp) {
        //noinspection SuspiciousNameCombination
        config.smallestScreenWidthDp = config.screenHeightDp;
    } else {
        config.smallestScreenWidthDp = config.screenWidthDp;
    }
    config.densityDpi = density.getDpiValue();
    // never run in compat mode:
    config.compatScreenWidthDp = config.screenWidthDp;
    config.compatScreenHeightDp = config.screenHeightDp;
    ScreenOrientation orientation = hardwareConfig.getOrientation();
    if (orientation != null) {
        switch(orientation) {
            case PORTRAIT:
                config.orientation = Configuration.ORIENTATION_PORTRAIT;
                break;
            case LANDSCAPE:
                config.orientation = Configuration.ORIENTATION_LANDSCAPE;
                break;
            case SQUARE:
                //noinspection deprecation
                config.orientation = Configuration.ORIENTATION_SQUARE;
                break;
        }
    } else {
        config.orientation = Configuration.ORIENTATION_UNDEFINED;
    }
    ScreenRound roundness = hardwareConfig.getScreenRoundness();
    if (roundness != null) {
        switch(roundness) {
            case ROUND:
                config.screenLayout |= Configuration.SCREENLAYOUT_ROUND_YES;
                break;
            case NOTROUND:
                config.screenLayout |= Configuration.SCREENLAYOUT_ROUND_NO;
        }
    } else {
        config.screenLayout |= Configuration.SCREENLAYOUT_ROUND_UNDEFINED;
    }
    String locale = params.getLocale();
    if (locale != null && !locale.isEmpty())
        config.locale = new Locale(locale);
    return config;
}
Also used : ScreenOrientation(com.android.resources.ScreenOrientation) Locale(java.util.Locale) HardwareConfig(com.android.ide.common.rendering.api.HardwareConfig) Configuration(android.content.res.Configuration) ScreenSize(com.android.resources.ScreenSize) Density(com.android.resources.Density) ScreenRound(com.android.resources.ScreenRound)

Example 39 with Configuration

use of android.content.res.Configuration in project android_frameworks_base by ResurrectionRemix.

the class Instrumentation method newActivity.

/**
     * Perform instantiation of an {@link Activity} object.  This method is intended for use with
     * unit tests, such as android.test.ActivityUnitTestCase.  The activity will be useable
     * locally but will be missing some of the linkages necessary for use within the sytem.
     * 
     * @param clazz The Class of the desired Activity
     * @param context The base context for the activity to use
     * @param token The token for this activity to communicate with
     * @param application The application object (if any)
     * @param intent The intent that started this Activity
     * @param info ActivityInfo from the manifest
     * @param title The title, typically retrieved from the ActivityInfo record
     * @param parent The parent Activity (if any)
     * @param id The embedded Id (if any)
     * @param lastNonConfigurationInstance Arbitrary object that will be
     * available via {@link Activity#getLastNonConfigurationInstance()
     * Activity.getLastNonConfigurationInstance()}.
     * @return Returns the instantiated activity
     * @throws InstantiationException
     * @throws IllegalAccessException
     */
public Activity newActivity(Class<?> clazz, Context context, IBinder token, Application application, Intent intent, ActivityInfo info, CharSequence title, Activity parent, String id, Object lastNonConfigurationInstance) throws InstantiationException, IllegalAccessException {
    Activity activity = (Activity) clazz.newInstance();
    ActivityThread aThread = null;
    activity.attach(context, aThread, this, token, 0, application, intent, info, title, parent, id, (Activity.NonConfigurationInstances) lastNonConfigurationInstance, new Configuration(), null, null, null);
    return activity;
}
Also used : ViewConfiguration(android.view.ViewConfiguration) Configuration(android.content.res.Configuration)

Example 40 with Configuration

use of android.content.res.Configuration in project android_frameworks_base by ResurrectionRemix.

the class ConnectivityService method getProvisioningUrlBaseFromFile.

private String getProvisioningUrlBaseFromFile() {
    FileReader fileReader = null;
    XmlPullParser parser = null;
    Configuration config = mContext.getResources().getConfiguration();
    try {
        fileReader = new FileReader(mProvisioningUrlFile);
        parser = Xml.newPullParser();
        parser.setInput(fileReader);
        XmlUtils.beginDocument(parser, TAG_PROVISIONING_URLS);
        while (true) {
            XmlUtils.nextElement(parser);
            String element = parser.getName();
            if (element == null)
                break;
            if (element.equals(TAG_PROVISIONING_URL)) {
                String mcc = parser.getAttributeValue(null, ATTR_MCC);
                try {
                    if (mcc != null && Integer.parseInt(mcc) == config.mcc) {
                        String mnc = parser.getAttributeValue(null, ATTR_MNC);
                        if (mnc != null && Integer.parseInt(mnc) == config.mnc) {
                            parser.next();
                            if (parser.getEventType() == XmlPullParser.TEXT) {
                                return parser.getText();
                            }
                        }
                    }
                } catch (NumberFormatException e) {
                    loge("NumberFormatException in getProvisioningUrlBaseFromFile: " + e);
                }
            }
        }
        return null;
    } catch (FileNotFoundException e) {
        loge("Carrier Provisioning Urls file not found");
    } catch (XmlPullParserException e) {
        loge("Xml parser exception reading Carrier Provisioning Urls file: " + e);
    } catch (IOException e) {
        loge("I/O exception reading Carrier Provisioning Urls file: " + e);
    } finally {
        if (fileReader != null) {
            try {
                fileReader.close();
            } catch (IOException e) {
            }
        }
    }
    return null;
}
Also used : Configuration(android.content.res.Configuration) XmlPullParser(org.xmlpull.v1.XmlPullParser) FileNotFoundException(java.io.FileNotFoundException) FileReader(java.io.FileReader) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) NetworkPolicyManager.uidRulesToString(android.net.NetworkPolicyManager.uidRulesToString) IOException(java.io.IOException)

Aggregations

Configuration (android.content.res.Configuration)824 RemoteException (android.os.RemoteException)158 Resources (android.content.res.Resources)152 Locale (java.util.Locale)112 DisplayMetrics (android.util.DisplayMetrics)88 Intent (android.content.Intent)76 IOException (java.io.IOException)69 Context (android.content.Context)64 Point (android.graphics.Point)48 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)40 Rect (android.graphics.Rect)37 ArrayList (java.util.ArrayList)37 Test (org.junit.Test)29 AndroidRuntimeException (android.util.AndroidRuntimeException)28 View (android.view.View)27 ComponentName (android.content.ComponentName)25 Bundle (android.os.Bundle)25 IBinder (android.os.IBinder)24 WindowManager (android.view.WindowManager)24 Nullable (android.annotation.Nullable)22