Search in sources :

Example 56 with ContextWrapper

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

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;
}
Also used : Context(android.content.Context) LayoutInflater(android.view.LayoutInflater) Resources(android.content.res.Resources) ContextWrapper(android.content.ContextWrapper) View(android.view.View) AppWidgetHostView(android.appwidget.AppWidgetHostView)

Example 57 with ContextWrapper

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

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;
        }
    };
}
Also used : MockContentResolver(android.test.mock.MockContentResolver) ContextWrapper(android.content.ContextWrapper)

Example 58 with ContextWrapper

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

the class ModelTest method setupTestContext.

private void setupTestContext() {
    final MockContentResolver resolver = new MockContentResolver();
    context = new ContextWrapper(getContext()) {

        @Override
        public ContentResolver getContentResolver() {
            return resolver;
        }
    };
    provider = new TestContentProvider();
    resolver.addProvider(AUTHORITY, provider);
}
Also used : MockContentResolver(android.test.mock.MockContentResolver) ContextWrapper(android.content.ContextWrapper) ContentResolver(android.content.ContentResolver) MockContentResolver(android.test.mock.MockContentResolver)

Example 59 with ContextWrapper

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

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;
}
Also used : Context(android.content.Context) LayoutInflater(android.view.LayoutInflater) Resources(android.content.res.Resources) ContextWrapper(android.content.ContextWrapper) View(android.view.View) AppWidgetHostView(android.appwidget.AppWidgetHostView)

Example 60 with ContextWrapper

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

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;
}
Also used : Context(android.content.Context) LayoutInflater(android.view.LayoutInflater) Resources(android.content.res.Resources) ContextWrapper(android.content.ContextWrapper) View(android.view.View) AppWidgetHostView(android.appwidget.AppWidgetHostView)

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