Search in sources :

Example 6 with Configuration

use of android.content.res.Configuration in project AndroidTraining by mixi-inc.

the class ProtonService method onConfigurationChanged.

@Override
public void onConfigurationChanged(Configuration newConfig) {
    Configuration oldConfig = getResources().getConfiguration();
    super.onConfigurationChanged(newConfig);
    mObserverManager.fire(new OnConfigurationChangedEvent(oldConfig, newConfig));
}
Also used : Configuration(android.content.res.Configuration) OnConfigurationChangedEvent(proton.inject.observer.event.OnConfigurationChangedEvent)

Example 7 with Configuration

use of android.content.res.Configuration in project LollipopShowcase by mikepenz.

the class AppInfo method getEnglishRessources.

public Resources getEnglishRessources(Resources standardResources) {
    AssetManager assets = standardResources.getAssets();
    DisplayMetrics metrics = standardResources.getDisplayMetrics();
    Configuration config = new Configuration(standardResources.getConfiguration());
    config.locale = Locale.US;
    return new Resources(assets, metrics, config);
}
Also used : AssetManager(android.content.res.AssetManager) Configuration(android.content.res.Configuration) Resources(android.content.res.Resources) DisplayMetrics(android.util.DisplayMetrics)

Example 8 with Configuration

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

the class PhoneFallbackEventHandler method onKeyDown.

boolean onKeyDown(int keyCode, KeyEvent event) {
    /* ****************************************************************************
         * HOW TO DECIDE WHERE YOUR KEY HANDLING GOES.
         * See the comment in PhoneWindow.onKeyDown
         * ****************************************************************************/
    final KeyEvent.DispatcherState dispatcher = mView.getKeyDispatcherState();
    switch(keyCode) {
        case KeyEvent.KEYCODE_VOLUME_UP:
        case KeyEvent.KEYCODE_VOLUME_DOWN:
        case KeyEvent.KEYCODE_VOLUME_MUTE:
            {
                getAudioManager().handleKeyDown(event, AudioManager.USE_DEFAULT_STREAM_TYPE);
                return true;
            }
        case KeyEvent.KEYCODE_MEDIA_PLAY:
        case KeyEvent.KEYCODE_MEDIA_PAUSE:
        case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
            /* Suppress PLAY/PAUSE toggle when phone is ringing or in-call
                 * to avoid music playback */
            if (getTelephonyManager().getCallState() != TelephonyManager.CALL_STATE_IDLE) {
                // suppress key event
                return true;
            }
        case KeyEvent.KEYCODE_MUTE:
        case KeyEvent.KEYCODE_HEADSETHOOK:
        case KeyEvent.KEYCODE_MEDIA_STOP:
        case KeyEvent.KEYCODE_MEDIA_NEXT:
        case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
        case KeyEvent.KEYCODE_MEDIA_REWIND:
        case KeyEvent.KEYCODE_MEDIA_RECORD:
        case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
            {
                handleMediaKeyEvent(event);
                return true;
            }
        case KeyEvent.KEYCODE_CALL:
            {
                if (getKeyguardManager().inKeyguardRestrictedInputMode() || dispatcher == null) {
                    break;
                }
                if (event.getRepeatCount() == 0) {
                    dispatcher.startTracking(event, this);
                } else if (event.isLongPress() && dispatcher.isTracking(event)) {
                    dispatcher.performedLongPress(event);
                    mView.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
                    // launch the VoiceDialer
                    Intent intent = new Intent(Intent.ACTION_VOICE_COMMAND);
                    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    try {
                        sendCloseSystemWindows();
                        mContext.startActivity(intent);
                    } catch (ActivityNotFoundException e) {
                        startCallActivity();
                    }
                }
                return true;
            }
        case KeyEvent.KEYCODE_CAMERA:
            {
                if (getKeyguardManager().inKeyguardRestrictedInputMode() || dispatcher == null) {
                    break;
                }
                if (event.getRepeatCount() == 0) {
                    dispatcher.startTracking(event, this);
                } else if (event.isLongPress() && dispatcher.isTracking(event)) {
                    dispatcher.performedLongPress(event);
                    mView.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
                    sendCloseSystemWindows();
                    // Broadcast an intent that the Camera button was longpressed
                    Intent intent = new Intent(Intent.ACTION_CAMERA_BUTTON, null);
                    intent.putExtra(Intent.EXTRA_KEY_EVENT, event);
                    mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT_OR_SELF, null, null, null, 0, null, null);
                }
                return true;
            }
        case KeyEvent.KEYCODE_SEARCH:
            {
                if (getKeyguardManager().inKeyguardRestrictedInputMode() || dispatcher == null) {
                    break;
                }
                if (event.getRepeatCount() == 0) {
                    dispatcher.startTracking(event, this);
                } else if (event.isLongPress() && dispatcher.isTracking(event)) {
                    Configuration config = mContext.getResources().getConfiguration();
                    if (config.keyboard == Configuration.KEYBOARD_NOKEYS || config.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_YES) {
                        // launch the search activity
                        Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS);
                        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                        try {
                            mView.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
                            sendCloseSystemWindows();
                            getSearchManager().stopSearch();
                            mContext.startActivity(intent);
                            // Only clear this if we successfully start the
                            // activity; otherwise we will allow the normal short
                            // press action to be performed.
                            dispatcher.performedLongPress(event);
                            return true;
                        } catch (ActivityNotFoundException e) {
                        // Ignore
                        }
                    }
                }
                break;
            }
    }
    return false;
}
Also used : KeyEvent(android.view.KeyEvent) Configuration(android.content.res.Configuration) ActivityNotFoundException(android.content.ActivityNotFoundException) Intent(android.content.Intent)

Example 9 with Configuration

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

the class PhoneWindow method openPanel.

private void openPanel(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().getResources().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.isOpen = true;
    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);
// Log.v(TAG, "Adding main menu to window manager.");
}
Also used : Context(android.content.Context) LayoutParams(android.view.WindowManager.LayoutParams) 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 10 with Configuration

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

the class AppsLaunchFailureReceiver method onReceive.

// This function implements the following logic.
// If after a theme was applied the number of application launch failures
// at any moment was equal to FAILURES_THRESHOLD
// in less than EXPIRATION_TIME_IN_MILLISECONDS
// the default theme is applied unconditionally.
@Override
public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();
    if (action.equals(Intent.ACTION_APP_LAUNCH_FAILURE)) {
        long currentTime = SystemClock.uptimeMillis();
        if (currentTime - mStartTime > EXPIRATION_TIME_IN_MILLISECONDS) {
            // reset both the count and the timer
            mStartTime = currentTime;
            mFailuresCount = 0;
        }
        if (mFailuresCount <= FAILURES_THRESHOLD) {
            mFailuresCount++;
            if (mFailuresCount == FAILURES_THRESHOLD) {
                CustomTheme defaultTheme = CustomTheme.getSystemTheme();
                ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
                Configuration currentConfig = am.getConfiguration();
                currentConfig.customTheme = new CustomTheme(defaultTheme.getThemeId(), defaultTheme.getThemePackageName());
                am.updateConfiguration(currentConfig);
            }
        }
    } else if (action.equals(Intent.ACTION_APP_LAUNCH_FAILURE_RESET)) {
        mFailuresCount = 0;
        mStartTime = SystemClock.uptimeMillis();
    } else if (action.equals(Intent.ACTION_PACKAGE_ADDED) || action.equals(Intent.ACTION_PACKAGE_REMOVED)) {
        mFailuresCount = 0;
        mStartTime = SystemClock.uptimeMillis();
    }
}
Also used : Configuration(android.content.res.Configuration) ActivityManager(android.app.ActivityManager) CustomTheme(android.content.res.CustomTheme)

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