类android.view.ContextThemeWrapper源码实例Demo

下面列出了怎么用android.view.ContextThemeWrapper的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: ans-android-sdk   文件: UIHelper.java
private static boolean isDialogBelongActivity(Context dialogContext, Context activityContext) {
    int limit = 0;
    while (true) {
        if (dialogContext == activityContext) {
            return true;
        }
        if (!(dialogContext instanceof ContextThemeWrapper)) {
            return false;
        }

        //防止极端情况
        if (limit++ > 10) {
            return false;
        }

        dialogContext = ((ContextThemeWrapper) dialogContext).getBaseContext();
    }

}
 
private void showLocalAppDialog() {
    ContextThemeWrapper wrapper = new ContextThemeWrapper(getContext(), R.style.DialogBaseTheme);
    final PaneledChoiceDialog chooseApp = new PaneledChoiceDialog(wrapper,
            Localization.get("install.choose.local.app"));

    DialogChoiceItem[] items = new DialogChoiceItem[mLocalApps.size()];
    int count = 0;
    for (final MicroNode.AppManifest app : mLocalApps) {
        DialogChoiceItem item = new DialogChoiceItem(app.getName(), -1, v -> {
            Activity currentActivity = getActivity();
            if (currentActivity instanceof CommCareSetupActivity) {
                ((CommCareSetupActivity)currentActivity).onURLChosen(app.getLocalUrl());
            }
            ((CommCareActivity)getActivity()).dismissAlertDialog();
        });
        items[count] = item;
        count++;
    }
    chooseApp.setChoiceItems(items);
    ((CommCareActivity)getActivity()).showAlertDialog(chooseApp);
}
 
源代码3 项目: javaide   文件: TreeNodeWrapperView.java
private void init() {
    setOrientation(LinearLayout.VERTICAL);

    nodeContainer = new RelativeLayout(getContext());
    nodeContainer.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
    nodeContainer.setId(R.id.node_header);

    ContextThemeWrapper newContext = new ContextThemeWrapper(getContext(), containerStyle);
    nodeItemsContainer = new LinearLayout(newContext, null, containerStyle);
    nodeItemsContainer.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
    nodeItemsContainer.setId(R.id.node_items);
    nodeItemsContainer.setOrientation(LinearLayout.VERTICAL);
    nodeItemsContainer.setVisibility(View.GONE);

    addView(nodeContainer);
    addView(nodeItemsContainer);
}
 
源代码4 项目: science-journal   文件: ActionController.java
/**
 * Updates the add note button for {@link TextNoteFragment} and {@link GalleryNoteFragment} when
 * a recording starts/stops.
 */
public void attachAddButton(FloatingActionButton button) {
  recordingStatus
      .takeUntil(RxView.detaches(button))
      .subscribe(
          status -> {
            Theme theme = button.getContext().getTheme();
            if (status.state.shouldShowStopButton()) {
              theme = new ContextThemeWrapper(
                  button.getContext(), R.style.RecordingProgressBarColor).getTheme();
            }
            button.setImageDrawable(
                ResourcesCompat.getDrawable(
                    button.getResources(), R.drawable.ic_send_24dp, theme));

            TypedValue iconColor = new TypedValue();
            theme.resolveAttribute(R.attr.icon_color, iconColor, true);

            TypedValue iconBackground = new TypedValue();
            theme.resolveAttribute(R.attr.icon_background, iconBackground, true);

            button.setBackgroundTintList(ColorStateList.valueOf(
                button.getResources().getColor(iconBackground.resourceId)));
            button.setRippleColor(button.getResources().getColor(iconColor.resourceId));
          });
}
 
源代码5 项目: leanback-showcase   文件: VideoCardPresenter.java
CardViewHolder(ImageCardView view, Context context) {
    super(view);
    mContext = context;
    Context wrapper = new ContextThemeWrapper(mContext, R.style.MyPopupMenu);
    mPopupMenu = new PopupMenu(wrapper, view);
    mPopupMenu.inflate(R.menu.popup_menu);

    mPopupMenu.setOnMenuItemClickListener(this);
    view.setOnLongClickListener(this);

    mOwner = (LifecycleOwner) mContext;

    mDefaultBackground = mContext.getResources().getDrawable(R.drawable.no_cache_no_internet, null);
    mDefaultPlaceHolder = new RequestOptions().
            placeholder(mDefaultBackground);

    mCardView = (ImageCardView) CardViewHolder.this.view;
    Resources resources = mCardView.getContext().getResources();
    mCardView.setMainImageDimensions(Math.round(
            resources.getDimensionPixelSize(R.dimen.card_width)),
            resources.getDimensionPixelSize(R.dimen.card_height));

    mFragmentActivity = (FragmentActivity) context;
    mViewModel = ViewModelProviders.of(mFragmentActivity).get(VideosViewModel.class);
}
 
private void init() {
    setOrientation(LinearLayout.VERTICAL);

    nodeContainer = new RelativeLayout(getContext());
    nodeContainer.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
    nodeContainer.setId(R.id.node_header);

    ContextThemeWrapper newContext = new ContextThemeWrapper(getContext(), containerStyle);
    nodeItemsContainer = new LinearLayout(newContext, null, containerStyle);
    nodeItemsContainer.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
    nodeItemsContainer.setId(R.id.node_items);
    nodeItemsContainer.setOrientation(LinearLayout.VERTICAL);
    nodeItemsContainer.setVisibility(View.GONE);

    addView(nodeContainer);
    addView(nodeItemsContainer);
}
 
源代码7 项目: talkback   文件: SetupWizardTicTacToeController.java
private void displayFinishDialog(String outcome) {
  setGameButtonsEnabled(false);
  resetButton.setEnabled(true);

  AlertDialog.Builder gameOverBuilder =
      new AlertDialog.Builder(
          new ContextThemeWrapper(context, R.style.SetupGuideAlertDialogStyle));
  gameOverBuilder.setTitle(outcome);
  gameOverBuilder.setMessage(context.getString(R.string.game_outcome_body_text));

  gameOverBuilder.setNegativeButton(
      context.getString(R.string.game_outcome_negative_response),
      (dialogInterface, viewId) -> {
        ((Activity) context).recreate();
        KeyAssignmentUtils.clearAllKeyPrefs(context);
        dialogInterface.cancel();
      });

  gameOverBuilder.setPositiveButton(
      context.getString(R.string.game_outcome_positive_response),
      (dialogInterface, viewId) -> dialogInterface.cancel());

  AlertDialog gameOverDialog = gameOverBuilder.create();
  gameOverDialog.show();
}
 
源代码8 项目: 1Rramp-Android   文件: DetailedActivity.java
private void showPopup() {
  int menu_res_id = R.menu.popup_post;
  String currentLoggedInUser = HaprampPreferenceManager.getInstance().getCurrentSteemUsername();
  ContextThemeWrapper contextThemeWrapper = new ContextThemeWrapper(this, R.style.PopupMenuOverlapAnchor);
  PopupMenu popup = new PopupMenu(contextThemeWrapper, overflowBtn);
  //customize menu items
  //add Share
  popup.getMenu().add(PostMenu.Share);
  popup.getMenu().add(PostMenu.Repost);
  popup.getMenuInflater().inflate(menu_res_id, popup.getMenu());
  popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
    @Override
    public boolean onMenuItemClick(MenuItem item) {
      if (item.getTitle().equals(PostMenu.Share)) {
        ShareUtils.shareMixedContent(DetailedActivity.this, post);
        return true;
      } else if (item.getTitle().equals(PostMenu.Repost)) {
        showAlertDialogForRepost();
      }
      return false;
    }
  });
  popup.show();
}
 
源代码9 项目: SAI   文件: ThemeView.java
public void setTheme(Theme.ThemeDescriptor theme) {
    mThemeTitle.setText(theme.getName(getContext()));

    Context themedContext = new ContextThemeWrapper(getContext(), theme.getTheme());
    setCardBackgroundColor(Utils.getThemeColor(themedContext, R.attr.colorPrimary));

    int accentColor = Utils.getThemeColor(themedContext, R.attr.colorAccent);
    setStrokeColor(accentColor);
    mThemeTitle.setTextColor(accentColor);

    if (Utils.apiIsAtLeast(Build.VERSION_CODES.M)) {
        setRippleColor(themedContext.getColorStateList(R.color.selector_theme_card_ripple));
    }

    mThemeMessage.setTextColor(Utils.getThemeColor(themedContext, android.R.attr.textColorPrimary));
}
 
源代码10 项目: DeviceInfo   文件: OSFragment.java
@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

        final Context contextThemeWrapper = new ContextThemeWrapper(getActivity(), R.style.OSTheme);
        LayoutInflater localInflater = inflater.cloneInContext(contextThemeWrapper);
        View view = localInflater.inflate(R.layout.fragment_os, container, false);
        unbinder = ButterKnife.bind(this, view);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            Window window = getActivity().getWindow();
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            window.setStatusBarColor(getResources().getColor(R.color.dark_blue));
            window.setNavigationBarColor(getResources().getColor(R.color.dark_blue));

        }

/*
        View view = inflater.inflate(R.layout.fragment_os, container, false);
        unbinder = ButterKnife.bind(this, view);
*/

        return view;
    }
 
/**
 * Inflates the layout.
 *
 * @param tabsOnly
 *         True, if only the tabs should be inflated, false otherwise
 */
public final void inflateLayout(final boolean tabsOnly) {
    int themeResourceId = style.getThemeHelper().getThemeResourceId(tabSwitcher.getLayout());
    LayoutInflater inflater =
            LayoutInflater.from(new ContextThemeWrapper(getContext(), themeResourceId));
    onInflateLayout(inflater, tabsOnly);
    registerEventHandlerCallbacks();
    adaptDecorator();
    adaptLogLevel();

    if (!tabsOnly) {
        adaptToolbarVisibility();
        adaptToolbarTitle();
        adaptToolbarNavigationIcon();
        inflateToolbarMenu();
    }
}
 
源代码12 项目: Carbon   文件: DropDown.java
private void initDropDown(AttributeSet attrs, @AttrRes int defStyleAttr, @StyleRes int defStyleRes) {
    TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.DropDown, defStyleAttr, defStyleRes);

    int theme = a.getResourceId(R.styleable.DropDown_carbon_popupTheme, -1);

    dropDownMenu = new DropDownMenu(new ContextThemeWrapper(getContext(), theme));
    dropDownMenu.setOnDismissListener(() -> isShowingPopup = false);
    dropDownMenu.setPopupMode(PopupMode.values()[a.getInt(R.styleable.DropDown_carbon_popupMode, PopupMode.Over.ordinal())]);
    setMode(Mode.values()[a.getInt(R.styleable.DropDown_carbon_mode, Mode.SingleSelect.ordinal())]);
    dropDownMenu.setOnItemClickedListener(onItemClickedListener);

    setButtonDrawable(Carbon.getDrawable(this, a, R.styleable.DropDown_android_button, R.drawable.carbon_dropdown));

    for (int i = 0; i < a.getIndexCount(); i++) {
        int attr = a.getIndex(i);
        if (attr == R.styleable.DropDown_android_drawablePadding) {
            drawablePadding = a.getDimension(attr, 0);
        } else if (attr == R.styleable.DropDown_carbon_buttonGravity) {
            buttonGravity = ButtonGravity.values()[a.getInt(attr, 0)];
        }
    }

    a.recycle();
}
 
源代码13 项目: SuntimesWidget   文件: WorldMapDialog.java
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup parent, @Nullable Bundle savedState)
{
    ContextThemeWrapper contextWrapper = new ContextThemeWrapper(getActivity(), AppSettings.loadTheme(getContext()));    // hack: contextWrapper required because base theme is not properly applied
    dialogContent = inflater.cloneInContext(contextWrapper).inflate(R.layout.layout_dialog_worldmap, parent, false);

    initLocale(getContext());
    initViews(getContext(), dialogContent);
    if (savedState != null)
    {
        Log.d(LOGTAG, "WorldMapDialog onCreate (restoreState)");
        worldmap.loadSettings(getContext(), savedState);
    }
    themeViews(dialogContent.getContext());

    return dialogContent;
}
 
源代码14 项目: LeafLoading   文件: LeafLoading.java
/**
 * 初始化
 *
 * @param context 上下文
 */
private void init(ContextThemeWrapper context) {
    initResources(context);
    initBitmap();
    initPaint();
    mLeafFactory = new LeafFactory();
    mLeafInfos = mLeafFactory.generateLeafs();
    mFan = new FanFactory().generateFan();
}
 
源代码15 项目: AndroidComponentPlugin   文件: ContextImpl.java
public Object createService(ContextImpl ctx) {
    final Context outerContext = ctx.getOuterContext();
    return new NotificationManager(
        new ContextThemeWrapper(outerContext,
                Resources.selectSystemTheme(0,
                        outerContext.getApplicationInfo().targetSdkVersion,
                        com.android.internal.R.style.Theme_Dialog,
                        com.android.internal.R.style.Theme_Holo_Dialog,
                        com.android.internal.R.style.Theme_DeviceDefault_Dialog)),
        ctx.mMainThread.getHandler());
}
 
源代码16 项目: DMusic   文件: AlertDialogFactory.java
/**
 * LoadingDialog
 */
public AlertDialog getLoadingDialog(String text) {
    final AlertDialog dlg = new AlertDialog
            .Builder(new ContextThemeWrapper(mContext, R.style.lib_pub_dialog_style))
            .create();
    if (mContext instanceof Activity && !((Activity) mContext).isFinishing()) {
        dlg.show();
    }
    dlg.setContentView(R.layout.lib_pub_dialog_loading);
    TextView tips = (TextView) dlg.findViewById(R.id.tv_tips);
    if (text != null) {
        tips.setText(text);
    }
    return dlg;
}
 
源代码17 项目: opensudoku   文件: ThemeUtils.java
public static void applyThemeToSudokuBoardViewFromContext(String theme, SudokuBoardView board, Context context) {
    if (theme.equals("custom") || theme.equals("custom_light")) {
        applyCustomThemeToSudokuBoardViewFromContext(board, context);
    } else {
        ContextThemeWrapper themeWrapper = new ContextThemeWrapper(context, getThemeResourceIdFromString(theme));

        int[] attributes = {
                R.attr.lineColor,
                R.attr.sectorLineColor,
                R.attr.textColor,
                R.attr.textColorReadOnly,
                R.attr.textColorNote,
                R.attr.backgroundColor,
                R.attr.backgroundColorSecondary,
                R.attr.backgroundColorReadOnly,
                R.attr.backgroundColorTouched,
                R.attr.backgroundColorSelected,
                R.attr.backgroundColorHighlighted
        };

        TypedArray themeColors = themeWrapper.getTheme().obtainStyledAttributes(attributes);
        board.setLineColor(themeColors.getColor(0, R.color.default_lineColor));
        board.setSectorLineColor(themeColors.getColor(1, R.color.default_sectorLineColor));
        board.setTextColor(themeColors.getColor(2, R.color.default_textColor));
        board.setTextColorReadOnly(themeColors.getColor(3, R.color.default_textColorReadOnly));
        board.setTextColorNote(themeColors.getColor(4, R.color.default_textColorNote));
        board.setBackgroundColor(themeColors.getColor(5, R.color.default_backgroundColor));
        board.setBackgroundColorSecondary(themeColors.getColor(6, R.color.default_backgroundColorSecondary));
        board.setBackgroundColorReadOnly(themeColors.getColor(7, R.color.default_backgroundColorReadOnly));
        board.setBackgroundColorTouched(themeColors.getColor(8, R.color.default_backgroundColorTouched));
        board.setBackgroundColorSelected(themeColors.getColor(9, R.color.default_backgroundColorSelected));
        board.setBackgroundColorHighlighted(themeColors.getColor(10, R.color.default_backgroundColorHighlighted));
    }
    board.invalidate();
}
 
源代码18 项目: AndroidComponentPlugin   文件: ContextImpl.java
public Object createService(ContextImpl ctx) {
    final Context outerContext = ctx.getOuterContext();
    return new NotificationManager(
        new ContextThemeWrapper(outerContext,
                Resources.selectSystemTheme(0,
                        outerContext.getApplicationInfo().targetSdkVersion,
                        com.android.internal.R.style.Theme_Dialog,
                        com.android.internal.R.style.Theme_Holo_Dialog,
                        com.android.internal.R.style.Theme_DeviceDefault_Dialog)),
        ctx.mMainThread.getHandler());
}
 
源代码19 项目: BetterWeather   文件: WeatherLocationPreference.java
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    Context layoutContext = new ContextThemeWrapper(getActivity(),
            android.R.style.Theme_DeviceDefault_Light_Dialog);

    LayoutInflater layoutInflater = LayoutInflater.from(layoutContext);
    View rootView = layoutInflater.inflate(R.layout.dialog_weather_location_chooser, null);
    TextView searchView = (TextView) rootView.findViewById(R.id.location_query);
    searchView.addTextChangedListener(this);

    // Set up apps
    mSearchResultsList = (ListView) rootView.findViewById(android.R.id.list);
    mSearchResultsList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> listView, View view,
                                int position, long itemId) {
            String value = mSearchResultsAdapter.getPrefValueAt(position);
            if (value == null || "".equals(value)) {
                if (ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED &&
                        ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
                    ActivityCompat.requestPermissions(getActivity(), new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, LOCATION_REQUEST_CODE);
                }
            }
            mPreference.setValue(value);
            dismiss();
        }
    });

    tryBindList();

    AlertDialog dialog = new AlertDialog.Builder(getActivity())
            .setView(rootView)
            .create();
    dialog.getWindow().setSoftInputMode(
            WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
    return dialog;
}
 
源代码20 项目: SuntimesWidget   文件: AboutDialog.java
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup parent, @Nullable Bundle savedState)
{
    ContextThemeWrapper contextWrapper = new ContextThemeWrapper(getActivity(), AppSettings.loadTheme(getContext()));    // hack: contextWrapper required because base theme is not properly applied
    View dialogContent = inflater.cloneInContext(contextWrapper).inflate(R.layout.layout_dialog_about, parent, false);

    if (savedState != null)
    {
        param_iconID = savedState.getInt(KEY_ICONID, param_iconID);
        param_appName = savedState.getInt(KEY_APPNAME, param_appName);
    }
    initViews(getActivity(), dialogContent);

    return dialogContent;
}
 
源代码21 项目: AtlasForAndroid   文件: AtlasHacks.java
public static void allFields() throws HackAssertionException {
    ActivityThread_mInstrumentation = ActivityThread.field("mInstrumentation").ofType(Instrumentation.class);
    ActivityThread_mAllApplications = ActivityThread.field("mAllApplications").ofGenericType(ArrayList.class);
    ActivityThread_mInitialApplication = ActivityThread.field("mInitialApplication").ofType(Application.class);
    ActivityThread_mPackages = ActivityThread.field("mPackages").ofGenericType(Map.class);
    ActivityThread_sPackageManager = ActivityThread.staticField("sPackageManager").ofType(IPackageManager.getmClass());
    LoadedApk_mApplication = LoadedApk.field("mApplication").ofType(Application.class);
    LoadedApk_mResources = LoadedApk.field("mResources").ofType(Resources.class);
    LoadedApk_mResDir = LoadedApk.field("mResDir").ofType(String.class);
    LoadedApk_mClassLoader = LoadedApk.field("mClassLoader").ofType(ClassLoader.class);
    LoadedApk_mBaseClassLoader = LoadedApk.field("mBaseClassLoader").ofType(ClassLoader.class);
    LoadedApk_mAppDir = LoadedApk.field("mAppDir").ofType(String.class);
    ContextImpl_mResources = ContextImpl.field("mResources").ofType(Resources.class);
    ContextImpl_mTheme = ContextImpl.field("mTheme").ofType(Theme.class);
    sIsIgnoreFailure = true;
    ContextThemeWrapper_mBase = ContextThemeWrapper.field("mBase").ofType(Context.class);
    sIsIgnoreFailure = false;
    ContextThemeWrapper_mTheme = ContextThemeWrapper.field("mTheme").ofType(Theme.class);
    try {
        if (VERSION.SDK_INT >= 17 && ContextThemeWrapper.getmClass().getDeclaredField("mResources") != null) {
            ContextThemeWrapper_mResources = ContextThemeWrapper.field("mResources").ofType(Resources.class);
        }
    } catch (NoSuchFieldException e) {
        log.warn("Not found ContextThemeWrapper.mResources on VERSION " + VERSION.SDK_INT);
    }
    ContextWrapper_mBase = ContextWrapper.field("mBase").ofType(Context.class);
    Resources_mAssets = Resources.field("mAssets");
}
 
源代码22 项目: 365browser   文件: AboutChromePreferences.java
@SuppressLint("ObsoleteSdkInt")
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getActivity().setTitle(R.string.prefs_about_chrome);
    PreferenceUtils.addPreferencesFromResource(this, R.xml.about_chrome_preferences);

    // TODO(crbug.com/635567): Fix this properly.
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
        ChromeBasePreference deprecationWarning = new ChromeBasePreference(
                new ContextThemeWrapper(getActivity(),
                        R.style.DeprecationWarningPreferenceTheme));
        deprecationWarning.setOrder(-1);
        deprecationWarning.setTitle(R.string.deprecation_warning);
        deprecationWarning.setIcon(R.drawable.exclamation_triangle);
        getPreferenceScreen().addPreference(deprecationWarning);
    }

    PrefServiceBridge prefServiceBridge = PrefServiceBridge.getInstance();
    AboutVersionStrings versionStrings = prefServiceBridge.getAboutVersionStrings();
    Preference p = findPreference(PREF_APPLICATION_VERSION);
    p.setSummary(getApplicationVersion(getActivity(), versionStrings.getApplicationVersion()));
    p = findPreference(PREF_OS_VERSION);
    p.setSummary(versionStrings.getOSVersion());
    p = findPreference(PREF_LEGAL_INFORMATION);
    int currentYear = Calendar.getInstance().get(Calendar.YEAR);
    p.setSummary(getString(R.string.legal_information_summary, currentYear));
}
 
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    if (mTheme > 0) {
        Context newContext = new ContextThemeWrapper(inflater.getContext(), mTheme);
        inflater = inflater.cloneInContext(newContext);
    }
    mInflater = inflater;

    mView = inflater.inflate(R.layout.mnd_list, container, false);
    mListView = (ListView) mView.findViewById(R.id.mnd_list);
    mPinnedContainer = (ViewGroup) mView.findViewById(R.id.mnd_section_pinned);
    mPinnedDivider = mView.findViewById(R.id.mnd_divider_pinned);
    return mView;
}
 
源代码24 项目: android_9.0.0_r45   文件: Presentation.java
private static Context createPresentationContext(
        Context outerContext, Display display, int theme) {
    if (outerContext == null) {
        throw new IllegalArgumentException("outerContext must not be null");
    }
    if (display == null) {
        throw new IllegalArgumentException("display must not be null");
    }

    Context displayContext = outerContext.createDisplayContext(display);
    if (theme == 0) {
        TypedValue outValue = new TypedValue();
        displayContext.getTheme().resolveAttribute(
                com.android.internal.R.attr.presentationTheme, outValue, true);
        theme = outValue.resourceId;
    }

    // Derive the display's window manager from the outer window manager.
    // We do this because the outer window manager have some extra information
    // such as the parent window, which is important if the presentation uses
    // an application window type.
    final WindowManagerImpl outerWindowManager =
            (WindowManagerImpl)outerContext.getSystemService(WINDOW_SERVICE);
    final WindowManagerImpl displayWindowManager =
            outerWindowManager.createPresentationWindowManager(displayContext);
    return new ContextThemeWrapper(displayContext, theme) {
        @Override
        public Object getSystemService(String name) {
            if (WINDOW_SERVICE.equals(name)) {
                return displayWindowManager;
            }
            return super.getSystemService(name);
        }
    };
}
 
源代码25 项目: android_9.0.0_r45   文件: ArrayAdapter.java
/**
 * Sets the {@link Resources.Theme} against which drop-down views are
 * inflated.
 * <p>
 * By default, drop-down views are inflated against the theme of the
 * {@link Context} passed to the adapter's constructor.
 *
 * @param theme the theme against which to inflate drop-down views or
 *              {@code null} to use the theme from the adapter's context
 * @see #getDropDownView(int, View, ViewGroup)
 */
@Override
public void setDropDownViewTheme(@Nullable Resources.Theme theme) {
    if (theme == null) {
        mDropDownInflater = null;
    } else if (theme == mInflater.getContext().getTheme()) {
        mDropDownInflater = mInflater;
    } else {
        final Context context = new ContextThemeWrapper(mContext, theme);
        mDropDownInflater = LayoutInflater.from(context);
    }
}
 
源代码26 项目: LeafLoading   文件: LeafLoading.java
/**
 * 初始化资源
 *
 * @param context 上下文
 */
private void initResources(ContextThemeWrapper context) {
    mResources = getResources();
    mLeafFloatTime = LEAF_FLOAT_TIME;
    mLeafRotateTime = LEAF_ROTATE_TIME;
    mDefaultWidth = UiUtils.dip2px(context, mDefaultWidth);
    mDefaultHeight = UiUtils.dip2px(context, mDefaultHeight);
}
 
源代码27 项目: android_9.0.0_r45   文件: SimpleAdapter.java
/**
 * Sets the {@link android.content.res.Resources.Theme} against which drop-down views are
 * inflated.
 * <p>
 * By default, drop-down views are inflated against the theme of the
 * {@link Context} passed to the adapter's constructor.
 *
 * @param theme the theme against which to inflate drop-down views or
 *              {@code null} to use the theme from the adapter's context
 * @see #getDropDownView(int, View, ViewGroup)
 */
@Override
public void setDropDownViewTheme(Resources.Theme theme) {
    if (theme == null) {
        mDropDownInflater = null;
    } else if (theme == mInflater.getContext().getTheme()) {
        mDropDownInflater = mInflater;
    } else {
        final Context context = new ContextThemeWrapper(mInflater.getContext(), theme);
        mDropDownInflater = LayoutInflater.from(context);
    }
}
 
源代码28 项目: SublimePicker   文件: SUtils.java
public static ContextThemeWrapper createThemeWrapper(Context context,
                                                     int parentStyleAttr, int parentDefaultStyle, int childStyleAttr,
                                                     int childDefaultStyle) {
    final TypedArray forParent = context.obtainStyledAttributes(
            new int[]{parentStyleAttr});
    int parentStyle = forParent.getResourceId(0, parentDefaultStyle);
    forParent.recycle();

    TypedArray forChild = context.obtainStyledAttributes(parentStyle,
            new int[]{childStyleAttr});
    int childStyleId = forChild.getResourceId(0, childDefaultStyle);
    forChild.recycle();

    return new ContextThemeWrapper(context, childStyleId);
}
 
源代码29 项目: SuntimesWidget   文件: TimeDateDialog.java
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup parent, @Nullable Bundle savedState)
{
    ContextThemeWrapper contextWrapper = new ContextThemeWrapper(getActivity(), AppSettings.loadTheme(getContext()));    // hack: contextWrapper required because base theme is not properly applied
    View dialogContent = inflater.cloneInContext(contextWrapper).inflate(R.layout.layout_dialog_date1, parent, false);

    initViews(getContext(), dialogContent);
    if (savedState != null) {
        loadSettings(savedState);
    } else {
        loadSettings(getActivity());
    }

    return dialogContent;
}
 
源代码30 项目: SuntimesWidget   文件: LocationConfigDialog.java
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup parent, @Nullable Bundle savedInstanceState)
{
    ContextThemeWrapper contextWrapper = new ContextThemeWrapper(getActivity(), AppSettings.loadTheme(getContext()));    // hack: contextWrapper required because base theme is not properly applied
    View view = inflater.cloneInContext(contextWrapper).inflate(R.layout.layout_dialog_location, parent, false);
    final FragmentActivity myParent = getActivity();

    dialogContent = (LocationConfigView) view.findViewById(R.id.locationConfig);
    dialogContent.setHideTitle(hideTitle);
    dialogContent.setHideMode(hideMode);
    dialogContent.init(myParent, false);

    Button btn_cancel = (Button) view.findViewById(R.id.dialog_button_cancel);
    btn_cancel.setOnClickListener(onDialogCancelClick);

    Button btn_accept = (Button) view.findViewById(R.id.dialog_button_accept);
    btn_accept.setOnClickListener(onDialogAcceptClick);

    if (savedInstanceState != null) {
        loadSettings(savedInstanceState);

    } else if (presetData != null) {
        dialogContent.loadSettings(myParent, presetData);

    } else if (presetLocation != null) {
        setLocation(getContext(), presetLocation);
    }
    return view;
}
 
 类所在包
 同包方法