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);
}
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();
}
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;
}
}
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;
}
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;
}
Aggregations