Search in sources :

Example 31 with Configuration

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

the class ActivityStackSupervisor method resizeTaskLocked.

boolean resizeTaskLocked(TaskRecord task, Rect bounds, int resizeMode, boolean preserveWindow, boolean deferResume) {
    if (!task.isResizeable()) {
        Slog.w(TAG, "resizeTask: task " + task + " not resizeable.");
        return true;
    }
    // If this is a forced resize, let it go through even if the bounds is not changing,
    // as we might need a relayout due to surface size change (to/from fullscreen).
    final boolean forced = (resizeMode & RESIZE_MODE_FORCED) != 0;
    if (Objects.equals(task.mBounds, bounds) && !forced) {
        // Nothing to do here...
        return true;
    }
    bounds = TaskRecord.validateBounds(bounds);
    if (!mWindowManager.isValidTaskId(task.taskId)) {
        // Task doesn't exist in window manager yet (e.g. was restored from recents).
        // All we can do for now is update the bounds so it can be used when the task is
        // added to window manager.
        task.updateOverrideConfiguration(bounds);
        if (task.stack != null && task.stack.mStackId != FREEFORM_WORKSPACE_STACK_ID) {
            // re-restore the task so it can have the proper stack association.
            restoreRecentTaskLocked(task, FREEFORM_WORKSPACE_STACK_ID);
        }
        return true;
    }
    // Do not move the task to another stack here.
    // This method assumes that the task is already placed in the right stack.
    // we do not mess with that decision and we only do the resize!
    Trace.traceBegin(TRACE_TAG_ACTIVITY_MANAGER, "am.resizeTask_" + task.taskId);
    final Configuration overrideConfig = task.updateOverrideConfiguration(bounds);
    // This variable holds information whether the configuration didn't change in a significant
    // way and the activity was kept the way it was. If it's false, it means the activity had
    // to be relaunched due to configuration change.
    boolean kept = true;
    if (overrideConfig != null) {
        final ActivityRecord r = task.topRunningActivityLocked();
        if (r != null) {
            final ActivityStack stack = task.stack;
            kept = stack.ensureActivityConfigurationLocked(r, 0, preserveWindow);
            if (!deferResume) {
                // All other activities must be made visible with their correct configuration.
                ensureActivitiesVisibleLocked(r, 0, !PRESERVE_WINDOWS);
                if (!kept) {
                    resumeFocusedStackTopActivityLocked();
                }
            }
        }
    }
    mWindowManager.resizeTask(task.taskId, task.mBounds, task.mOverrideConfig, kept, forced);
    Trace.traceEnd(TRACE_TAG_ACTIVITY_MANAGER);
    return kept;
}
Also used : Configuration(android.content.res.Configuration)

Example 32 with Configuration

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

the class AccessibilityUtils method getTextForLocale.

/**
     * @return a localized version of the text resource specified by resId
     */
public static CharSequence getTextForLocale(Context context, Locale locale, int resId) {
    final Resources res = context.getResources();
    final Configuration config = new Configuration(res.getConfiguration());
    config.setLocale(locale);
    final Context langContext = context.createConfigurationContext(config);
    return langContext.getText(resId);
}
Also used : Context(android.content.Context) Configuration(android.content.res.Configuration) Resources(android.content.res.Resources)

Example 33 with Configuration

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

the class BugreportProgressService method onCreate.

@Override
public void onCreate() {
    mContext = getApplicationContext();
    mMainHandler = new ServiceHandler("BugreportProgressServiceMainThread");
    mScreenshotHandler = new ScreenshotHandler("BugreportProgressServiceScreenshotThread");
    mScreenshotsDir = new File(getFilesDir(), SCREENSHOT_DIR);
    if (!mScreenshotsDir.exists()) {
        Log.i(TAG, "Creating directory " + mScreenshotsDir + " to store temporary screenshots");
        if (!mScreenshotsDir.mkdir()) {
            Log.w(TAG, "Could not create directory " + mScreenshotsDir);
        }
    }
    final Configuration conf = mContext.getResources().getConfiguration();
    mIsWatch = (conf.uiMode & Configuration.UI_MODE_TYPE_MASK) == Configuration.UI_MODE_TYPE_WATCH;
}
Also used : Configuration(android.content.res.Configuration) ZipFile(java.util.zip.ZipFile) File(java.io.File)

Example 34 with Configuration

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

the class PhoneWindow method openPanel.

private void openPanel(final PanelFeatureState st, KeyEvent event) {
    // Already open, return
    if (st.isOpen || isDestroyed()) {
        return;
    }
    // (The app should be using an action bar for menu items.)
    if (st.featureId == FEATURE_OPTIONS_PANEL) {
        Context context = getContext();
        Configuration config = context.getResources().getConfiguration();
        boolean isXLarge = (config.screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_XLARGE;
        boolean isHoneycombApp = context.getApplicationInfo().targetSdkVersion >= android.os.Build.VERSION_CODES.HONEYCOMB;
        if (isXLarge && isHoneycombApp) {
            return;
        }
    }
    Callback cb = getCallback();
    if ((cb != null) && (!cb.onMenuOpened(st.featureId, st.menu))) {
        // Callback doesn't want the menu to open, reset any state
        closePanel(st, true);
        return;
    }
    final WindowManager wm = getWindowManager();
    if (wm == null) {
        return;
    }
    // Prepare panel (should have been done before, but just in case)
    if (!preparePanel(st, event)) {
        return;
    }
    int width = WRAP_CONTENT;
    if (st.decorView == null || st.refreshDecorView) {
        if (st.decorView == null) {
            // Initialize the panel decor, this will populate st.decorView
            if (!initializePanelDecor(st) || (st.decorView == null))
                return;
        } else if (st.refreshDecorView && (st.decorView.getChildCount() > 0)) {
            // Decor needs refreshing, so remove its views
            st.decorView.removeAllViews();
        }
        // This will populate st.shownPanelView
        if (!initializePanelContent(st) || !st.hasPanelItems()) {
            return;
        }
        ViewGroup.LayoutParams lp = st.shownPanelView.getLayoutParams();
        if (lp == null) {
            lp = new ViewGroup.LayoutParams(WRAP_CONTENT, WRAP_CONTENT);
        }
        int backgroundResId;
        if (lp.width == ViewGroup.LayoutParams.MATCH_PARENT) {
            // If the contents is fill parent for the width, set the
            // corresponding background
            backgroundResId = st.fullBackground;
            width = MATCH_PARENT;
        } else {
            // Otherwise, set the normal panel background
            backgroundResId = st.background;
        }
        st.decorView.setWindowBackground(getContext().getDrawable(backgroundResId));
        ViewParent shownPanelParent = st.shownPanelView.getParent();
        if (shownPanelParent != null && shownPanelParent instanceof ViewGroup) {
            ((ViewGroup) shownPanelParent).removeView(st.shownPanelView);
        }
        st.decorView.addView(st.shownPanelView, lp);
        /*
             * Give focus to the view, if it or one of its children does not
             * already have it.
             */
        if (!st.shownPanelView.hasFocus()) {
            st.shownPanelView.requestFocus();
        }
    } else if (!st.isInListMode()) {
        width = MATCH_PARENT;
    } else if (st.createdPanelView != null) {
        // If we already had a panel view, carry width=MATCH_PARENT through
        // as we did above when it was created.
        ViewGroup.LayoutParams lp = st.createdPanelView.getLayoutParams();
        if (lp != null && lp.width == ViewGroup.LayoutParams.MATCH_PARENT) {
            width = MATCH_PARENT;
        }
    }
    st.isHandled = false;
    WindowManager.LayoutParams lp = new WindowManager.LayoutParams(width, WRAP_CONTENT, st.x, st.y, WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG, WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH, st.decorView.mDefaultOpacity);
    if (st.isCompact) {
        lp.gravity = getOptionsPanelGravity();
        sRotationWatcher.addWindow(this);
    } else {
        lp.gravity = st.gravity;
    }
    lp.windowAnimations = st.windowAnimations;
    wm.addView(st.decorView, lp);
    st.isOpen = true;
// Log.v(TAG, "Adding main menu to window manager.");
}
Also used : Context(android.content.Context) LayoutParams(android.view.WindowManager.LayoutParams) ViewConfiguration(android.view.ViewConfiguration) Configuration(android.content.res.Configuration) ViewGroup(android.view.ViewGroup) ViewParent(android.view.ViewParent) LayoutParams(android.view.WindowManager.LayoutParams) WindowManager(android.view.WindowManager) IWindowManager(android.view.IWindowManager)

Example 35 with Configuration

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

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)

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