Search in sources :

Example 16 with Configuration

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

the class ActivityTestMain method onCreateOptionsMenu.

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    menu.add("Animate!").setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(MenuItem item) {
            AlertDialog.Builder builder = new AlertDialog.Builder(ActivityTestMain.this, R.style.SlowDialog);
            builder.setTitle("This is a title");
            builder.show();
            return true;
        }
    });
    menu.add("Bind!").setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(MenuItem item) {
            Intent intent = new Intent(ActivityTestMain.this, SingleUserService.class);
            ServiceConnection conn = new ServiceConnection() {

                @Override
                public void onServiceConnected(ComponentName name, IBinder service) {
                    Log.i(TAG, "Service connected " + name + " " + service);
                }

                @Override
                public void onServiceDisconnected(ComponentName name) {
                    Log.i(TAG, "Service disconnected " + name);
                }
            };
            if (bindService(intent, conn, Context.BIND_AUTO_CREATE)) {
                mConnections.add(conn);
            } else {
                Toast.makeText(ActivityTestMain.this, "Failed to bind", Toast.LENGTH_LONG).show();
            }
            return true;
        }
    });
    menu.add("Start!").setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(MenuItem item) {
            Intent intent = new Intent(ActivityTestMain.this, SingleUserService.class);
            startService(intent);
            return true;
        }
    });
    menu.add("Send!").setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(MenuItem item) {
            Intent intent = new Intent(ActivityTestMain.this, SingleUserReceiver.class);
            sendOrderedBroadcast(intent, null, new BroadcastResultReceiver(), null, Activity.RESULT_OK, null, null);
            return true;
        }
    });
    menu.add("Call!").setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(MenuItem item) {
            ContentProviderClient cpl = getContentResolver().acquireContentProviderClient(SingleUserProvider.AUTHORITY);
            Bundle res = null;
            try {
                res = cpl.call("getuser", null, null);
            } catch (RemoteException e) {
            }
            int user = res != null ? res.getInt("user", -1) : -1;
            Toast.makeText(ActivityTestMain.this, "Provider executed as user " + (user >= 0 ? Integer.toString(user) : "unknown"), Toast.LENGTH_LONG).show();
            cpl.release();
            return true;
        }
    });
    menu.add("Send to user 0!").setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(MenuItem item) {
            Intent intent = new Intent(ActivityTestMain.this, UserTarget.class);
            sendOrderedBroadcastAsUser(intent, new UserHandle(0), null, new BroadcastResultReceiver(), null, Activity.RESULT_OK, null, null);
            return true;
        }
    });
    menu.add("Send to user " + mSecondUser + "!").setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(MenuItem item) {
            Intent intent = new Intent(ActivityTestMain.this, UserTarget.class);
            sendOrderedBroadcastAsUser(intent, new UserHandle(mSecondUser), null, new BroadcastResultReceiver(), null, Activity.RESULT_OK, null, null);
            return true;
        }
    });
    menu.add("Bind to user 0!").setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(MenuItem item) {
            Intent intent = new Intent(ActivityTestMain.this, ServiceUserTarget.class);
            ServiceConnection conn = new ServiceConnection() {

                @Override
                public void onServiceConnected(ComponentName name, IBinder service) {
                    Log.i(TAG, "Service connected " + name + " " + service);
                }

                @Override
                public void onServiceDisconnected(ComponentName name) {
                    Log.i(TAG, "Service disconnected " + name);
                }
            };
            if (bindServiceAsUser(intent, conn, Context.BIND_AUTO_CREATE, UserHandle.OWNER)) {
                mConnections.add(conn);
            } else {
                Toast.makeText(ActivityTestMain.this, "Failed to bind", Toast.LENGTH_LONG).show();
            }
            return true;
        }
    });
    menu.add("Bind to user " + mSecondUser + "!").setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(MenuItem item) {
            Intent intent = new Intent(ActivityTestMain.this, ServiceUserTarget.class);
            ServiceConnection conn = new ServiceConnection() {

                @Override
                public void onServiceConnected(ComponentName name, IBinder service) {
                    Log.i(TAG, "Service connected " + name + " " + service);
                }

                @Override
                public void onServiceDisconnected(ComponentName name) {
                    Log.i(TAG, "Service disconnected " + name);
                }
            };
            if (bindServiceAsUser(intent, conn, Context.BIND_AUTO_CREATE, new UserHandle(mSecondUser))) {
                mConnections.add(conn);
            } else {
                Toast.makeText(ActivityTestMain.this, "Failed to bind", Toast.LENGTH_LONG).show();
            }
            return true;
        }
    });
    menu.add("Density!").setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(MenuItem item) {
            if (mOverrideConfig == null) {
                mOverrideConfig = new Configuration();
            }
            if (mOverrideConfig.densityDpi == Configuration.DENSITY_DPI_UNDEFINED) {
                mOverrideConfig.densityDpi = (getApplicationContext().getResources().getConfiguration().densityDpi * 2) / 3;
            } else {
                mOverrideConfig.densityDpi = Configuration.DENSITY_DPI_UNDEFINED;
            }
            recreate();
            return true;
        }
    });
    return true;
}
Also used : AlertDialog(android.app.AlertDialog) ServiceConnection(android.content.ServiceConnection) Configuration(android.content.res.Configuration) Bundle(android.os.Bundle) MenuItem(android.view.MenuItem) Intent(android.content.Intent) IBinder(android.os.IBinder) UserHandle(android.os.UserHandle) ComponentName(android.content.ComponentName) RemoteException(android.os.RemoteException) ContentProviderClient(android.content.ContentProviderClient)

Example 17 with Configuration

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

the class Summarizer method getWebKitVersionFromUserAgentString.

private String getWebKitVersionFromUserAgentString() {
    Resources resources = new Resources(new AssetManager(), new DisplayMetrics(), new Configuration());
    String userAgent = resources.getString(com.android.internal.R.string.web_user_agent);
    Matcher matcher = Pattern.compile("AppleWebKit/([0-9]+?\\.[0-9])").matcher(userAgent);
    if (matcher.find()) {
        return matcher.group(1);
    }
    return "unknown";
}
Also used : AssetManager(android.content.res.AssetManager) Configuration(android.content.res.Configuration) Matcher(java.util.regex.Matcher) Resources(android.content.res.Resources) DisplayMetrics(android.util.DisplayMetrics)

Example 18 with Configuration

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

the class ActivityManagerProxy method getConfiguration.

public Configuration getConfiguration() throws RemoteException {
    Parcel data = Parcel.obtain();
    Parcel reply = Parcel.obtain();
    data.writeInterfaceToken(IActivityManager.descriptor);
    mRemote.transact(GET_CONFIGURATION_TRANSACTION, data, reply, 0);
    reply.readException();
    Configuration res = Configuration.CREATOR.createFromParcel(reply);
    reply.recycle();
    data.recycle();
    return res;
}
Also used : Configuration(android.content.res.Configuration) Parcel(android.os.Parcel)

Example 19 with Configuration

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

the class ActivityThread method performLaunchActivity.

private Activity performLaunchActivity(ActivityClientRecord r, Intent customIntent) {
    // System.out.println("##### [" + System.currentTimeMillis() + "] ActivityThread.performLaunchActivity(" + r + ")");
    ActivityInfo aInfo = r.activityInfo;
    if (r.packageInfo == null) {
        r.packageInfo = getPackageInfo(aInfo.applicationInfo, r.compatInfo, Context.CONTEXT_INCLUDE_CODE);
    }
    ComponentName component = r.intent.getComponent();
    if (component == null) {
        component = r.intent.resolveActivity(mInitialApplication.getPackageManager());
        r.intent.setComponent(component);
    }
    if (r.activityInfo.targetActivity != null) {
        component = new ComponentName(r.activityInfo.packageName, r.activityInfo.targetActivity);
    }
    Activity activity = null;
    try {
        java.lang.ClassLoader cl = r.packageInfo.getClassLoader();
        activity = mInstrumentation.newActivity(cl, component.getClassName(), r.intent);
        StrictMode.incrementExpectedActivityCount(activity.getClass());
        r.intent.setExtrasClassLoader(cl);
        if (r.state != null) {
            r.state.setClassLoader(cl);
        }
    } catch (Exception e) {
        if (!mInstrumentation.onException(activity, e)) {
            throw new RuntimeException("Unable to instantiate activity " + component + ": " + e.toString(), e);
        }
    }
    try {
        Application app = r.packageInfo.makeApplication(false, mInstrumentation);
        if (localLOGV)
            Slog.v(TAG, "Performing launch of " + r);
        if (localLOGV)
            Slog.v(TAG, r + ": app=" + app + ", appName=" + app.getPackageName() + ", pkg=" + r.packageInfo.getPackageName() + ", comp=" + r.intent.getComponent().toShortString() + ", dir=" + r.packageInfo.getAppDir());
        if (activity != null) {
            Context appContext = createBaseContextForActivity(r, activity);
            CharSequence title = r.activityInfo.loadLabel(appContext.getPackageManager());
            Configuration config = new Configuration(mCompatConfiguration);
            if (DEBUG_CONFIGURATION)
                Slog.v(TAG, "Launching activity " + r.activityInfo.name + " with config " + config);
            activity.attach(appContext, this, getInstrumentation(), r.token, r.ident, app, r.intent, r.activityInfo, title, r.parent, r.embeddedID, r.lastNonConfigurationInstances, config);
            if (customIntent != null) {
                activity.mIntent = customIntent;
            }
            r.lastNonConfigurationInstances = null;
            activity.mStartedActivity = false;
            int theme = r.activityInfo.getThemeResource();
            if (theme != 0) {
                activity.setTheme(theme);
            }
            activity.mCalled = false;
            mInstrumentation.callActivityOnCreate(activity, r.state);
            if (!activity.mCalled) {
                throw new SuperNotCalledException("Activity " + r.intent.getComponent().toShortString() + " did not call through to super.onCreate()");
            }
            r.activity = activity;
            r.stopped = true;
            if (!r.activity.mFinished) {
                activity.performStart();
                r.stopped = false;
            }
            if (!r.activity.mFinished) {
                if (r.state != null) {
                    mInstrumentation.callActivityOnRestoreInstanceState(activity, r.state);
                }
            }
            if (!r.activity.mFinished) {
                activity.mCalled = false;
                mInstrumentation.callActivityOnPostCreate(activity, r.state);
                if (!activity.mCalled) {
                    throw new SuperNotCalledException("Activity " + r.intent.getComponent().toShortString() + " did not call through to super.onPostCreate()");
                }
            }
        }
        r.paused = true;
        mActivities.put(r.token, r);
    } catch (SuperNotCalledException e) {
        throw e;
    } catch (Exception e) {
        if (!mInstrumentation.onException(activity, e)) {
            if (e instanceof InflateException) {
                Log.e(TAG, "Failed to inflate", e);
                String pkg = null;
                if (r.packageInfo != null && !TextUtils.isEmpty(r.packageInfo.getPackageName())) {
                    pkg = r.packageInfo.getPackageName();
                }
                Intent intent = new Intent(Intent.ACTION_APP_LAUNCH_FAILURE, (pkg != null) ? Uri.fromParts("package", pkg, null) : null);
                getSystemContext().sendBroadcast(intent);
            }
            throw new RuntimeException("Unable to start activity " + component + ": " + e.toString(), e);
        }
    }
    return activity;
}
Also used : Context(android.content.Context) ActivityInfo(android.content.pm.ActivityInfo) Configuration(android.content.res.Configuration) Intent(android.content.Intent) InflateException(android.view.InflateException) RemoteException(android.os.RemoteException) IOException(java.io.IOException) AndroidRuntimeException(android.util.AndroidRuntimeException) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) AndroidRuntimeException(android.util.AndroidRuntimeException) InflateException(android.view.InflateException) ComponentName(android.content.ComponentName) java.lang(java.lang)

Example 20 with Configuration

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

the class ActivityThread method applyCompatConfiguration.

final Configuration applyCompatConfiguration(int displayDensity) {
    Configuration config = mConfiguration;
    if (mCompatConfiguration == null) {
        mCompatConfiguration = new Configuration();
    }
    mCompatConfiguration.setTo(mConfiguration);
    if (mResCompatibilityInfo != null && !mResCompatibilityInfo.supportsScreen()) {
        mResCompatibilityInfo.applyToConfiguration(displayDensity, mCompatConfiguration);
        config = mCompatConfiguration;
    }
    return config;
}
Also used : Configuration(android.content.res.Configuration)

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