use of android.content.ContextWrapper in project XobotOS by xamarin.
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();
}
use of android.content.ContextWrapper in project platform_frameworks_base by android.
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();
}
use of android.content.ContextWrapper in project platform_frameworks_base by android.
the class RemoteViews method inflateView.
private View inflateView(Context context, RemoteViews rv, ViewGroup parent) {
// RemoteViews may be built by an application installed in another
// user. So build a context that loads resources from that user but
// still returns the current users userId so settings like data / time formats
// are loaded without requiring cross user persmissions.
final Context contextForResources = getContextForResources(context);
Context inflationContext = new ContextWrapper(context) {
@Override
public Resources getResources() {
return contextForResources.getResources();
}
@Override
public Resources.Theme getTheme() {
return contextForResources.getTheme();
}
@Override
public String getPackageName() {
return contextForResources.getPackageName();
}
};
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
// Clone inflater so we load resources from correct context and
// we don't add a filter to the static version returned by getSystemService.
inflater = inflater.cloneInContext(inflationContext);
inflater.setFilter(this);
View v = inflater.inflate(rv.getLayoutId(), parent, false);
v.setTagInternal(R.id.widget_frame, rv.getLayoutId());
return v;
}
use of android.content.ContextWrapper in project pictureapp by EyeSeeTea.
the class DatePickerFragment method onCreateDialog.
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
Context context = getActivity();
if (isBrokenSamsungDevice()) {
context = new ContextWrapper(getActivity()) {
private Resources wrappedResources;
@Override
public Resources getResources() {
Resources r = super.getResources();
if (wrappedResources == null) {
wrappedResources = new Resources(r.getAssets(), r.getDisplayMetrics(), r.getConfiguration()) {
@NonNull
@Override
public String getString(int id, Object... formatArgs) throws NotFoundException {
try {
return super.getString(id, formatArgs);
} catch (IllegalFormatConversionException ifce) {
Log.e("DatePickerDialogFix", "IllegalFormatConversionException Fixed!", ifce);
String template = super.getString(id);
template = template.replaceAll("%" + ifce.getConversion(), "%s");
return String.format(getConfiguration().locale, template, formatArgs);
}
}
};
}
return wrappedResources;
}
};
}
if (dateTime == null) {
// Use the current date as the default date in the picker
final Calendar c = Calendar.getInstance();
year = c.get(Calendar.YEAR);
month = c.get(Calendar.MONTH);
day = c.get(Calendar.DAY_OF_MONTH);
} else {
year = dateTime.getYear();
month = dateTime.getMonthOfYear() - 1;
day = dateTime.getDayOfMonth();
}
// Create a new instance of DatePickerDialog and return it
dialog = new DatePickerDialog(context, this, year, month, day);
return dialog;
}
use of android.content.ContextWrapper in project android_frameworks_base by crdroidandroid.
the class TestContext method createStorageTestContext.
/**
* Returns a Context configured with test provider for authority.
*/
static Context createStorageTestContext(Context context, String authority) {
final MockContentResolver testResolver = new MockContentResolver();
TestContentProvider provider = new TestContentProvider();
testResolver.addProvider(authority, provider);
return new ContextWrapper(context) {
@Override
public ContentResolver getContentResolver() {
return testResolver;
}
};
}
Aggregations