Search in sources :

Example 46 with ContextWrapper

use of android.content.ContextWrapper in project CameraKit-Android by flurgle.

the class CameraView method requestCameraPermission.

private void requestCameraPermission() {
    Activity activity = null;
    Context context = getContext();
    while (context instanceof ContextWrapper) {
        if (context instanceof Activity) {
            activity = (Activity) context;
        }
        context = ((ContextWrapper) context).getBaseContext();
    }
    if (activity != null) {
        ActivityCompat.requestPermissions(activity, new String[] { Manifest.permission.CAMERA, Manifest.permission.RECORD_AUDIO }, CameraKit.Constants.PERMISSION_REQUEST_CAMERA);
    }
}
Also used : Context(android.content.Context) Activity(android.app.Activity) ContextWrapper(android.content.ContextWrapper)

Example 47 with ContextWrapper

use of android.content.ContextWrapper in project remusic by aa112901.

the class MusicPlayer method bindToService.

public static final ServiceToken bindToService(final Context context, final ServiceConnection callback) {
    Activity realActivity = ((Activity) context).getParent();
    if (realActivity == null) {
        realActivity = (Activity) context;
    }
    final ContextWrapper contextWrapper = new ContextWrapper(realActivity);
    contextWrapper.startService(new Intent(contextWrapper, MediaService.class));
    final ServiceBinder binder = new ServiceBinder(callback, contextWrapper.getApplicationContext());
    if (contextWrapper.bindService(new Intent().setClass(contextWrapper, MediaService.class), binder, 0)) {
        mConnectionMap.put(contextWrapper, binder);
        return new ServiceToken(contextWrapper);
    }
    return null;
}
Also used : Activity(android.app.Activity) Intent(android.content.Intent) ContextWrapper(android.content.ContextWrapper)

Example 48 with ContextWrapper

use of android.content.ContextWrapper in project remusic by aa112901.

the class MusicPlayer method unbindFromService.

public static void unbindFromService(final ServiceToken token) {
    if (token == null) {
        return;
    }
    final ContextWrapper mContextWrapper = token.mWrappedContext;
    final ServiceBinder mBinder = mConnectionMap.remove(mContextWrapper);
    if (mBinder == null) {
        return;
    }
    mContextWrapper.unbindService(mBinder);
    if (mConnectionMap.isEmpty()) {
        mService = null;
    }
}
Also used : ContextWrapper(android.content.ContextWrapper)

Example 49 with ContextWrapper

use of android.content.ContextWrapper in project android_frameworks_base by ParanoidAndroid.

the class PhoneWindowManager method init.

/** {@inheritDoc} */
@Override
public void init(Context context, IWindowManager windowManager, WindowManagerFuncs windowManagerFuncs) {
    mContext = context;
    mWindowManager = windowManager;
    mWindowManagerFuncs = windowManagerFuncs;
    mHeadless = "1".equals(SystemProperties.get("ro.config.headless", "0"));
    if (!mHeadless) {
        // don't create KeyguardViewMediator if headless
        mKeyguardMediator = new KeyguardViewMediator(context, null);
    }
    mHandler = new PolicyHandler();
    mOrientationListener = new MyOrientationListener(mContext, mHandler);
    try {
        mOrientationListener.setCurrentRotation(windowManager.getRotation());
    } catch (RemoteException ex) {
    }
    updateHybridLayout();
    mSettingsObserver = new SettingsObserver(mHandler);
    mSettingsObserver.observe();
    // SystemUI reboot
    mContext.getContentResolver().registerContentObserver(Settings.System.getUriFor(Settings.System.USER_INTERFACE_STATE), false, new ContentObserver(new Handler()) {

        @Override
        public void onChange(boolean selfChange) {
            // Return for reset triggers
            if (Settings.System.getInt(mContext.getContentResolver(), Settings.System.USER_INTERFACE_STATE, 0) == 0) {
                return;
            }
            // Update layout
            update(true);
            // Reset trigger
            Settings.System.putInt(mContext.getContentResolver(), Settings.System.USER_INTERFACE_STATE, 0);
        }
    });
    // Expanded desktop
    mContext.getContentResolver().registerContentObserver(Settings.System.getUriFor(Settings.System.EXPANDED_DESKTOP_STATE), false, new ContentObserver(new Handler()) {

        @Override
        public void onChange(boolean selfChange) {
            updateHybridLayout();
            update(false);
        }
    });
    mShortcutManager = new ShortcutManager(context, mHandler);
    mShortcutManager.observe();
    mUiMode = context.getResources().getInteger(com.android.internal.R.integer.config_defaultUiModeType);
    mHomeIntent = new Intent(Intent.ACTION_MAIN, null);
    mHomeIntent.addCategory(Intent.CATEGORY_HOME);
    mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
    mCarDockIntent = new Intent(Intent.ACTION_MAIN, null);
    mCarDockIntent.addCategory(Intent.CATEGORY_CAR_DOCK);
    mCarDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
    mDeskDockIntent = new Intent(Intent.ACTION_MAIN, null);
    mDeskDockIntent.addCategory(Intent.CATEGORY_DESK_DOCK);
    mDeskDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
    mPowerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
    mBroadcastWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "PhoneWindowManager.mBroadcastWakeLock");
    mEnableShiftMenuBugReports = "1".equals(SystemProperties.get("ro.debuggable"));
    mLidOpenRotation = readRotation(com.android.internal.R.integer.config_lidOpenRotation);
    mCarDockRotation = readRotation(com.android.internal.R.integer.config_carDockRotation);
    mDeskDockRotation = readRotation(com.android.internal.R.integer.config_deskDockRotation);
    mUndockedHdmiRotation = readRotation(com.android.internal.R.integer.config_undockedHdmiRotation);
    mCarDockEnablesAccelerometer = mContext.getResources().getBoolean(com.android.internal.R.bool.config_carDockEnablesAccelerometer);
    mDeskDockEnablesAccelerometer = mContext.getResources().getBoolean(com.android.internal.R.bool.config_deskDockEnablesAccelerometer);
    mLidKeyboardAccessibility = mContext.getResources().getInteger(com.android.internal.R.integer.config_lidKeyboardAccessibility);
    mLidNavigationAccessibility = mContext.getResources().getInteger(com.android.internal.R.integer.config_lidNavigationAccessibility);
    mLidControlsSleep = mContext.getResources().getBoolean(com.android.internal.R.bool.config_lidControlsSleep);
    mHasRemovableLid = mContext.getResources().getBoolean(com.android.internal.R.bool.config_hasRemovableLid);
    mDeviceHardwareKeys = mContext.getResources().getInteger(com.android.internal.R.integer.config_deviceHardwareKeys);
    mHasHomeKey = ((mDeviceHardwareKeys & KEY_MASK_HOME) != 0);
    mHasMenuKey = ((mDeviceHardwareKeys & KEY_MASK_MENU) != 0);
    mHasAssistKey = ((mDeviceHardwareKeys & KEY_MASK_ASSIST) != 0);
    mHasAppSwitchKey = ((mDeviceHardwareKeys & KEY_MASK_APP_SWITCH) != 0);
    // register for dock events
    IntentFilter filter = new IntentFilter();
    filter.addAction(UiModeManager.ACTION_ENTER_CAR_MODE);
    filter.addAction(UiModeManager.ACTION_EXIT_CAR_MODE);
    filter.addAction(UiModeManager.ACTION_ENTER_DESK_MODE);
    filter.addAction(UiModeManager.ACTION_EXIT_DESK_MODE);
    filter.addAction(Intent.ACTION_DOCK_EVENT);
    Intent intent = context.registerReceiver(mDockReceiver, filter);
    if (intent != null) {
        // Retrieve current sticky dock event broadcast.
        mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE, Intent.EXTRA_DOCK_STATE_UNDOCKED);
    }
    // register for dream-related broadcasts
    filter = new IntentFilter();
    filter.addAction(Intent.ACTION_DREAMING_STARTED);
    filter.addAction(Intent.ACTION_DREAMING_STOPPED);
    context.registerReceiver(mDreamReceiver, filter);
    // register for multiuser-relevant broadcasts
    filter = new IntentFilter(Intent.ACTION_USER_SWITCHED);
    context.registerReceiver(mMultiuserReceiver, filter);
    mVibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
    mLongPressVibePattern = getLongIntArray(mContext.getResources(), com.android.internal.R.array.config_longPressVibePattern);
    mVirtualKeyVibePattern = getLongIntArray(mContext.getResources(), com.android.internal.R.array.config_virtualKeyVibePattern);
    mKeyboardTapVibePattern = getLongIntArray(mContext.getResources(), com.android.internal.R.array.config_keyboardTapVibePattern);
    mSafeModeDisabledVibePattern = getLongIntArray(mContext.getResources(), com.android.internal.R.array.config_safeModeDisabledVibePattern);
    mSafeModeEnabledVibePattern = getLongIntArray(mContext.getResources(), com.android.internal.R.array.config_safeModeEnabledVibePattern);
    mScreenshotChordEnabled = mContext.getResources().getBoolean(com.android.internal.R.bool.config_enableScreenshotChord);
    mGlobalKeyManager = new GlobalKeyManager(mContext);
    // Controls rotation and the like.
    initializeHdmiState();
    // Match current screen state.
    if (mPowerManager.isScreenOn()) {
        screenTurningOn(null);
    } else {
        screenTurnedOff(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
    }
    String deviceKeyHandlerLib = mContext.getResources().getString(com.android.internal.R.string.config_deviceKeyHandlerLib);
    String deviceKeyHandlerClass = mContext.getResources().getString(com.android.internal.R.string.config_deviceKeyHandlerClass);
    if (!deviceKeyHandlerLib.equals("") && !deviceKeyHandlerClass.equals("")) {
        DexClassLoader loader = new DexClassLoader(deviceKeyHandlerLib, new ContextWrapper(mContext).getCacheDir().getAbsolutePath(), null, ClassLoader.getSystemClassLoader());
        try {
            Class<?> klass = loader.loadClass(deviceKeyHandlerClass);
            Constructor<?> constructor = klass.getConstructor(Context.class);
            mDeviceKeyHandler = (DeviceKeyHandler) constructor.newInstance(mContext);
            if (DEBUG)
                Slog.d(TAG, "Device key handler loaded");
        } catch (Exception e) {
            Slog.w(TAG, "Could not instantiate device key handler " + deviceKeyHandlerClass + " from class " + deviceKeyHandlerLib, e);
        }
    }
}
Also used : IntentFilter(android.content.IntentFilter) KeyguardViewMediator(com.android.internal.policy.impl.keyguard.KeyguardViewMediator) DexClassLoader(dalvik.system.DexClassLoader) Handler(android.os.Handler) DeviceKeyHandler(com.android.internal.os.DeviceKeyHandler) Intent(android.content.Intent) RemoteException(android.os.RemoteException) IOException(java.io.IOException) ActivityNotFoundException(android.content.ActivityNotFoundException) RemoteException(android.os.RemoteException) ContextWrapper(android.content.ContextWrapper) ContentObserver(android.database.ContentObserver)

Example 50 with ContextWrapper

use of android.content.ContextWrapper in project android_frameworks_base by ParanoidAndroid.

the class Dialog method getAssociatedActivity.

/**
     * @return The activity associated with this dialog, or null if there is no associated activity.
     */
private ComponentName getAssociatedActivity() {
    Activity activity = mOwnerActivity;
    Context context = getContext();
    while (activity == null && context != null) {
        if (context instanceof Activity) {
            // found it!
            activity = (Activity) context;
        } else {
            context = (context instanceof ContextWrapper) ? // unwrap one level
            ((ContextWrapper) context).getBaseContext() : // done
            null;
        }
    }
    return activity == null ? null : activity.getComponentName();
}
Also used : Context(android.content.Context) ContextWrapper(android.content.ContextWrapper)

Aggregations

ContextWrapper (android.content.ContextWrapper)109 Context (android.content.Context)37 Activity (android.app.Activity)25 File (java.io.File)16 Test (org.junit.Test)13 Intent (android.content.Intent)11 MockContentResolver (android.test.mock.MockContentResolver)11 PackageManager (android.content.pm.PackageManager)10 View (android.view.View)10 Resources (android.content.res.Resources)9 IOException (java.io.IOException)8 Before (org.junit.Before)8 ContentResolver (android.content.ContentResolver)6 UserManager (android.os.UserManager)6 LayoutInflater (android.view.LayoutInflater)6 ThemePreferenceController (com.android.settings.display.ThemePreferenceController)6 OverlayManager (com.android.settings.display.ThemePreferenceController.OverlayManager)6 ArrayList (java.util.ArrayList)6 AppWidgetHostView (android.appwidget.AppWidgetHostView)5 JsonParser (com.google.gson.JsonParser)5