Search in sources :

Example 96 with Configuration

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

the class SettingsHelper method setLocaleData.

/**
     * Sets the locale specified. Input data is the byte representation of a
     * BCP-47 language tag. For backwards compatibility, strings of the form
     * {@code ll_CC} are also accepted, where {@code ll} is a two letter language
     * code and {@code CC} is a two letter country code.
     *
     * @param data the locale string in bytes.
     */
void setLocaleData(byte[] data, int size) {
    // Check if locale was set by the user:
    Configuration conf = mContext.getResources().getConfiguration();
    // Don't change if user set it in the SetupWizard
    if (conf.userSetLocale)
        return;
    final String[] availableLocales = mContext.getAssets().getLocales();
    // Replace "_" with "-" to deal with older backups.
    String localeCode = new String(data, 0, size).replace('_', '-');
    Locale loc = null;
    for (int i = 0; i < availableLocales.length; i++) {
        if (availableLocales[i].equals(localeCode)) {
            loc = Locale.forLanguageTag(localeCode);
            break;
        }
    }
    // Couldn't find the saved locale in this version of the software
    if (loc == null)
        return;
    try {
        IActivityManager am = ActivityManagerNative.getDefault();
        Configuration config = am.getConfiguration();
        config.locale = loc;
        // indicate this isn't some passing default - the user wants this remembered
        config.userSetLocale = true;
        am.updateConfiguration(config);
    } catch (RemoteException e) {
    // Intentionally left blank
    }
}
Also used : Locale(java.util.Locale) Configuration(android.content.res.Configuration) RemoteException(android.os.RemoteException) IActivityManager(android.app.IActivityManager)

Example 97 with Configuration

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

the class NavBarTuner method inflatePreview.

private void inflatePreview(ViewGroup view) {
    Display display = getActivity().getWindowManager().getDefaultDisplay();
    boolean isRotated = display.getRotation() == Surface.ROTATION_90 || display.getRotation() == Surface.ROTATION_270;
    Configuration config = new Configuration(getContext().getResources().getConfiguration());
    boolean isPhoneLandscape = isRotated && (config.smallestScreenWidthDp < 600);
    final float scale = isPhoneLandscape ? PREVIEW_SCALE_LANDSCAPE : PREVIEW_SCALE;
    config.densityDpi = (int) (config.densityDpi * scale);
    mPreview = (PreviewNavInflater) LayoutInflater.from(getContext().createConfigurationContext(config)).inflate(R.layout.nav_bar_tuner_inflater, view, false);
    final ViewGroup.LayoutParams layoutParams = mPreview.getLayoutParams();
    layoutParams.width = (int) ((isPhoneLandscape ? display.getHeight() : display.getWidth()) * scale);
    // Not sure why, but the height dimen is not being scaled with the dp, set it manually
    // for now.
    layoutParams.height = (int) (layoutParams.height * scale);
    if (isPhoneLandscape) {
        int width = layoutParams.width;
        layoutParams.width = layoutParams.height;
        layoutParams.height = width;
    }
    view.addView(mPreview);
    if (isRotated) {
        mPreview.findViewById(R.id.rot0).setVisibility(View.GONE);
        final View rot90 = mPreview.findViewById(R.id.rot90);
    } else {
        mPreview.findViewById(R.id.rot90).setVisibility(View.GONE);
        final View rot0 = mPreview.findViewById(R.id.rot0);
    }
}
Also used : Configuration(android.content.res.Configuration) ViewGroup(android.view.ViewGroup) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) RecyclerView(android.support.v7.widget.RecyclerView) Display(android.view.Display)

Example 98 with Configuration

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

the class AppWindowToken method freezeBounds.

/**
     * Freezes the task bounds. The size of this task reported the app will be fixed to the bounds
     * freezed by {@link Task#prepareFreezingBounds} until {@link #unfreezeBounds} gets called, even
     * if they change in the meantime. If the bounds are already frozen, the bounds will be frozen
     * with a queue.
     */
private void freezeBounds() {
    mFrozenBounds.offer(new Rect(mTask.mPreparedFrozenBounds));
    if (mTask.mPreparedFrozenMergedConfig.equals(Configuration.EMPTY)) {
        // We didn't call prepareFreezingBounds on the task, so use the current value.
        final Configuration config = new Configuration(service.mCurConfiguration);
        config.updateFrom(mTask.mOverrideConfig);
        mFrozenMergedConfig.offer(config);
    } else {
        mFrozenMergedConfig.offer(new Configuration(mTask.mPreparedFrozenMergedConfig));
    }
    mTask.mPreparedFrozenMergedConfig.setToDefaults();
}
Also used : Rect(android.graphics.Rect) Configuration(android.content.res.Configuration)

Example 99 with Configuration

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

the class DockedStackDividerController method initSnapAlgorithmForRotations.

private void initSnapAlgorithmForRotations() {
    final Configuration baseConfig = mService.mCurConfiguration;
    // Initialize the snap algorithms for all 4 screen orientations.
    final Configuration config = new Configuration();
    for (int rotation = 0; rotation < 4; rotation++) {
        final boolean rotated = (rotation == ROTATION_90 || rotation == ROTATION_270);
        final int dw = rotated ? mDisplayContent.mBaseDisplayHeight : mDisplayContent.mBaseDisplayWidth;
        final int dh = rotated ? mDisplayContent.mBaseDisplayWidth : mDisplayContent.mBaseDisplayHeight;
        mService.mPolicy.getStableInsetsLw(rotation, dw, dh, mTmpRect);
        config.setToDefaults();
        config.orientation = (dw <= dh) ? ORIENTATION_PORTRAIT : ORIENTATION_LANDSCAPE;
        config.screenWidthDp = (int) (mService.mPolicy.getConfigDisplayWidth(dw, dh, rotation, baseConfig.uiMode) / mDisplayContent.getDisplayMetrics().density);
        config.screenHeightDp = (int) (mService.mPolicy.getConfigDisplayHeight(dw, dh, rotation, baseConfig.uiMode) / mDisplayContent.getDisplayMetrics().density);
        final Context rotationContext = mService.mContext.createConfigurationContext(config);
        mSnapAlgorithmForRotation[rotation] = new DividerSnapAlgorithm(rotationContext.getResources(), dw, dh, getContentWidth(), config.orientation == ORIENTATION_PORTRAIT, mTmpRect);
    }
}
Also used : Context(android.content.Context) Configuration(android.content.res.Configuration) DividerSnapAlgorithm(com.android.internal.policy.DividerSnapAlgorithm)

Example 100 with Configuration

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

the class TaskStack method setBounds.

/**
     * Set the bounds of the stack and its containing tasks.
     * @param stackBounds New stack bounds. Passing in null sets the bounds to fullscreen.
     * @param configs Configuration for individual tasks, keyed by task id.
     * @param taskBounds Bounds for individual tasks, keyed by task id.
     * @return True if the stack bounds was changed.
     * */
boolean setBounds(Rect stackBounds, SparseArray<Configuration> configs, SparseArray<Rect> taskBounds, SparseArray<Rect> taskTempInsetBounds) {
    setBounds(stackBounds);
    // Update bounds of containing tasks.
    for (int taskNdx = mTasks.size() - 1; taskNdx >= 0; --taskNdx) {
        final Task task = mTasks.get(taskNdx);
        Configuration config = configs.get(task.mTaskId);
        if (config != null) {
            Rect bounds = taskBounds.get(task.mTaskId);
            if (task.isTwoFingerScrollMode()) {
                // This is a non-resizeable task that's docked (or side-by-side to the docked
                // stack). It might have been scrolled previously, and after the stack resizing,
                // it might no longer fully cover the stack area.
                // Save the old bounds and re-apply the scroll. This adjusts the bounds to
                // fit the new stack bounds.
                task.resizeLocked(bounds, config, false);
                task.getBounds(mTmpRect);
                task.scrollLocked(mTmpRect);
            } else {
                task.resizeLocked(bounds, config, false);
                task.setTempInsetBounds(taskTempInsetBounds != null ? taskTempInsetBounds.get(task.mTaskId) : null);
            }
        } else {
            Slog.wtf(TAG_WM, "No config for task: " + task + ", is there a mismatch with AM?");
        }
    }
    return true;
}
Also used : Rect(android.graphics.Rect) 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