Search in sources :

Example 21 with ContextWrapper

use of android.content.ContextWrapper in project android_packages_apps_Settings by crdroidandroid.

the class ThemePreferenceControllerTest method setup.

@Before
public void setup() {
    mMockOverlayManager = mock(OverlayManager.class);
    mMockPackageManager = mock(PackageManager.class);
    mContext = new ContextWrapper(InstrumentationRegistry.getTargetContext()) {

        @Override
        public PackageManager getPackageManager() {
            return mMockPackageManager;
        }
    };
    mPreferenceController = new ThemePreferenceController(mContext, mMockOverlayManager);
}
Also used : OverlayManager(com.android.settings.display.ThemePreferenceController.OverlayManager) ThemePreferenceController(com.android.settings.display.ThemePreferenceController) PackageManager(android.content.pm.PackageManager) ContextWrapper(android.content.ContextWrapper) Before(org.junit.Before)

Example 22 with ContextWrapper

use of android.content.ContextWrapper in project EssayJoke by qiyei2015.

the class SkinAppCompatViewInflater method checkOnClickListener.

/**
 * android:onClick doesn't handle views with a ContextWrapper context. This method
 * backports new framework functionality to traverse the Context wrappers to find a
 * suitable target.
 */
private void checkOnClickListener(View view, AttributeSet attrs) {
    final Context context = view.getContext();
    if (!ViewCompat.hasOnClickListeners(view) || !(context instanceof ContextWrapper)) {
        // or the Context isn't a ContextWrapper
        return;
    }
    final TypedArray a = context.obtainStyledAttributes(attrs, sOnClickAttrs);
    final String handlerName = a.getString(0);
    if (handlerName != null) {
        view.setOnClickListener(new DeclaredOnClickListener(view, handlerName));
    }
    a.recycle();
}
Also used : Context(android.content.Context) TypedArray(android.content.res.TypedArray) ContextWrapper(android.content.ContextWrapper)

Example 23 with ContextWrapper

use of android.content.ContextWrapper in project Phonograph by kabouzeid.

the class MusicPlayerRemote method unbindFromService.

public static void unbindFromService(@Nullable 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()) {
        musicService = null;
    }
}
Also used : ContextWrapper(android.content.ContextWrapper)

Example 24 with ContextWrapper

use of android.content.ContextWrapper in project Hyperion-Android by willowtreeapps.

the class ActivityUtil method findActivity.

@Nullable
static Activity findActivity(@NonNull Context context) {
    Context c = context;
    // keep unwrapping the context until you find a FragmentActivity
    while (!(c instanceof Activity)) {
        if (!(c instanceof ContextWrapper)) {
            // no activity at the bottom of the rabbit hole
            return null;
        }
        ContextWrapper contextWrapper = (ContextWrapper) c;
        if (contextWrapper == contextWrapper.getBaseContext()) {
            // found infinite rabbit hole
            return null;
        }
        // deeper down the rabbit hole we go
        c = contextWrapper.getBaseContext();
    }
    return (Activity) c;
}
Also used : Context(android.content.Context) Activity(android.app.Activity) ContextWrapper(android.content.ContextWrapper) Nullable(android.support.annotation.Nullable)

Example 25 with ContextWrapper

use of android.content.ContextWrapper in project AndFrameWorks by scwang90.

the class AfSharedPreference method setPreferencesPath.

private File setPreferencesPath(Context context, File file) {
    File oldfile = file;
    try {
        Field field;
        // 获取ContextWrapper对象中的mBase变量。该变量保存了ContextImpl对象
        field = ContextWrapper.class.getDeclaredField("mBase");
        field.setAccessible(true);
        // 获取mBase变量
        Object obj = field.get(context);
        // 获取ContextImpl.mPreferencesDir变量,该变量保存了数据文件的保存路径
        field = obj.getClass().getDeclaredField("mPreferencesDir");
        field.setAccessible(true);
        // 创建自定义路径
        // 修改mPreferencesDir变量的值
        oldfile = (File) field.get(obj);
        field.set(obj, file);
    } catch (Throwable e) {
        e.printStackTrace();
    }
    return oldfile;
}
Also used : Field(java.lang.reflect.Field) File(java.io.File) ContextWrapper(android.content.ContextWrapper)

Aggregations

ContextWrapper (android.content.ContextWrapper)108 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 Resources (android.content.res.Resources)9 View (android.view.View)9 IOException (java.io.IOException)8 Before (org.junit.Before)8 ContentResolver (android.content.ContentResolver)6 UserManager (android.os.UserManager)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 LayoutInflater (android.view.LayoutInflater)5 JsonParser (com.google.gson.JsonParser)5