Example usage for android.view LayoutInflater cloneInContext

List of usage examples for android.view LayoutInflater cloneInContext

Introduction

In this page you can find the example usage for android.view LayoutInflater cloneInContext.

Prototype

public abstract LayoutInflater cloneInContext(Context newContext);

Source Link

Document

Create a copy of the existing LayoutInflater object, with the copy pointing to a different Context than the original.

Usage

From source file:com.serenegiant.aceparrot.BaseFragment.java

protected LayoutInflater getThemedLayoutInflater(final LayoutInflater inflater) {
    final Activity context = getActivity();
    final SharedPreferences pref = context.getPreferences(0);
    final int layout_style = getLayoutStyle(pref.getInt(AppConst.KEY_ICON_TYPE, 0));
    // create ContextThemeWrapper from the original Activity Context with the custom theme
    final Context contextThemeWrapper = new ContextThemeWrapper(context, layout_style);
    // clone the inflater using the ContextThemeWrapper
    return inflater.cloneInContext(contextThemeWrapper);
}

From source file:android.support.v17.leanback.app.GuidedStepFragment.java

private LayoutInflater getThemeInflater(LayoutInflater inflater) {
    if (mTheme == -1) {
        return inflater;
    } else {//from   w w w . j  av a  2s.co m
        return inflater.cloneInContext(mThemeWrapper);
    }
}

From source file:com.binomed.showtime.android.screen.search.CineShowTimeSearchFragment.java

/** Called when the activity is first created. */
@Override/*from   ww  w.ja  v  a 2 s.c om*/
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // super.onCreate(savedInstanceState);
    tracker = fragmentInteraction.getTracker();

    // Bug fix do to pb of theme. Was forced to set manually the theme.
    SharedPreferences pref = PreferenceManager
            .getDefaultSharedPreferences(fragmentInteraction.getMainContext());
    String defaultTheme = fragmentInteraction.getMainContext().getResources()
            .getString(R.string.preference_gen_default_theme);
    String theme = pref.getString(
            fragmentInteraction.getMainContext().getResources().getString(R.string.preference_gen_key_theme),
            defaultTheme);
    int themeRessource = R.style.Theme_Dark_Night;
    if (!theme.equals(defaultTheme)) {
        themeRessource = R.style.Theme_Shine_the_lite;
    }

    LayoutInflater newInflater = inflater
            .cloneInContext(new ContextThemeWrapper(fragmentInteraction.getMainContext(), themeRessource));
    View mainView = newInflater.inflate(R.layout.fragment_search, container, false);

    getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

    model = fragmentInteraction.getModelActivity();

    initViews(mainView);
    initDB();

    display();

    return mainView;
}

From source file:layout.FragmentBoardItemList.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // cargamos la instancia si esta guardada
    if (savedInstanceState != null) {
        recentPostMode = savedInstanceState.getBoolean(RECENT_POST_MODE);
        currentBoard = savedInstanceState.getParcelable(ARG_CURRENTBOARD);
        currentThread = savedInstanceState.getParcelable(ARG_CURRENT_THREAD);
        boardItems = savedInstanceState.getParcelableArrayList(SAVED_BOARDITEMS);
    }/*from  w  w  w .ja va 2  s.  co  m*/

    // Aplicacin del Tema
    settings = PreferenceManager.getDefaultSharedPreferences(this.getContext());
    int themeResId = tm.getCurrentThemeId();
    Context context = new ContextThemeWrapper(getActivity(), themeResId);
    LayoutInflater localInflater = inflater.cloneInContext(context);
    View v = localInflater.inflate(R.layout.fragment_fragment_thread_list, container, false);
    themedContext = v;
    this.rootView = (ViewGroup) v;

    // Seteamos los controles que son guardados globalmente
    listViewBoardItems = (ListView) v.findViewById(R.id.lvThreadList);
    //        barThreadProcess = (ProgressBar)rootView.findViewById(R.id.barThreadProcess);
    layoutThreadProcess = (LinearLayout) rootView.findViewById(R.id.layoutThreadProcess);
    txtThreadProcess = (TextView) rootView.findViewById(R.id.txtThreadError);
    this.loadingBar = (ProgressBar) rootView.findViewById(R.id.progressBar);

    // Agregamos color al divider del listview
    ColorDrawable cd = new ColorDrawable(tm.getMarginColor());
    listViewBoardItems.setDivider(cd);
    listViewBoardItems.setDividerHeight(1);

    // registramos los menus del listview
    registerForContextMenu(listViewBoardItems);
    // Creamos los dos adaptadores y los seteamos dependiendo del modo del fragmento
    listViewAdapter = new ThreadListAdapter(v.getContext(), boardItems, tm);
    recentPostAdapter = new RecentPostAdapter(v.getContext(), boardItems);
    if (recentPostMode) {
        listViewBoardItems.setAdapter(recentPostAdapter);
    } else {
        listViewBoardItems.setAdapter(listViewAdapter);
    }

    if (!imMainFragment) {
        listViewAdapter.listThreads = true;
    }

    listViewBoardItems.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            if (imMainFragment && !recentPostMode) {
                BoardItem bi = listViewAdapter.getItem(position);
                mListener.showThread(currentBoard, bi);
            } else if (imMainFragment && recentPostMode) {
                BoardItem bi = boardItems.get(position);
                mListener.showThread(bi.getParentBoard(), bi);
            }
        }
    });

    listViewBoardItems.setOnScrollListener(new AbsListView.OnScrollListener() {
        private int lastFirstVisibleItem = 0;

        @Override
        public void onScrollStateChanged(AbsListView view, int scrollState) {

        }

        @Override
        public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
            if (lastFirstVisibleItem < firstVisibleItem) { // Scrolling down
                mListener.hideActionButton();
            } else if (lastFirstVisibleItem > firstVisibleItem) { // Scrolling Up
                mListener.showActionButton();
            }
            lastFirstVisibleItem = firstVisibleItem;
            for (int i = firstVisibleItem; i < firstVisibleItem + visibleItemCount; i++) {
                if (!recentPostMode) {
                    BoardItem bi = listViewAdapter.getItem(i);
                    if (!bi.getThumb().isEmpty() && bi.getThumbBitmap() == null && !bi.downloadingThumb) {
                        getThumbnail(bi);
                    }
                }
            }
            if (totalItemCount == firstVisibleItem + visibleItemCount && !loadingMoreThreads && imMainFragment
                    && totalItemCount != 0 && !recentPostMode) {
                loadingMoreThreads = true;
                currentOffset += 10;
                System.out.println("[Scroll] loading more threads! currentThreadCount " + totalItemCount);
                getThreadList(currentOffset); // TODO: Offset incorrecto
            }
        }
    });
    hideProgressBar();
    if (boardItems.isEmpty()) {
        if (currentBoard == null && currentThread == null && imMainFragment) {
            loadRecentPost();
        } else {
            updateBoardItems(currentBoard, currentThread);
        }
    } else {
        listViewAdapter.notifyDataSetChanged();
        recentPostAdapter.notifyDataSetChanged();
    }
    return v;
}

From source file:rikka.materialpreference.PreferenceFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    TypedArray a = mStyledContext.obtainStyledAttributes(null, R.styleable.PreferenceFragment,
            R.attr.preferenceFragmentStyle, 0);

    mLayoutResId = a.getResourceId(R.styleable.PreferenceFragment_android_layout, mLayoutResId);

    final Drawable divider = a.getDrawable(R.styleable.PreferenceFragment_android_divider);
    final int dividerHeight = a.getInt(R.styleable.PreferenceFragment_android_dividerHeight, -1);

    a.recycle();/* w w w  .  j a v a  2  s .  c  o m*/

    // Need to theme the inflater to pick up the preferenceFragmentListStyle
    final TypedValue tv = new TypedValue();
    getActivity().getTheme().resolveAttribute(R.attr.preferenceTheme, tv, true);
    final int theme = tv.resourceId;

    final Context themedContext = new ContextThemeWrapper(inflater.getContext(), theme);
    final LayoutInflater themedInflater = inflater.cloneInContext(themedContext);

    final View view = themedInflater.inflate(mLayoutResId, container, false);

    final View rawListContainer = view.findViewById(R.id.list_container);
    if (!(rawListContainer instanceof ViewGroup)) {
        throw new RuntimeException(
                "Content has view with id attribute 'R.id.list_container' " + "that is not a ViewGroup class");
    }

    final ViewGroup listContainer = (ViewGroup) rawListContainer;

    final RecyclerView listView = onCreateRecyclerView(themedInflater, listContainer, savedInstanceState);
    if (listView == null) {
        throw new RuntimeException("Could not create RecyclerView");
    }

    mList = listView;

    mDividerDecoration = onCreateItemDecoration();
    if (mDividerDecoration != null) {
        mList.addItemDecoration(mDividerDecoration);
    }

    setDivider(divider);
    if (dividerHeight != -1) {
        setDividerHeight(dividerHeight);
    }

    listContainer.addView(mList);
    mHandler.post(mRequestFocus);
    return view;
}

From source file:android.support.v7.preference.PreferenceFragmentCompat.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    TypedArray a = mStyledContext.obtainStyledAttributes(null, R.styleable.PreferenceFragmentCompat,
            R.attr.preferenceFragmentCompatStyle, 0);

    mLayoutResId = a.getResourceId(R.styleable.PreferenceFragmentCompat_android_layout, mLayoutResId);

    final Drawable divider = a.getDrawable(R.styleable.PreferenceFragmentCompat_android_divider);
    final int dividerHeight = a
            .getDimensionPixelSize(R.styleable.PreferenceFragmentCompat_android_dividerHeight, -1);

    a.recycle();/*from   www .  ja  va  2s  .c om*/

    // Need to theme the inflater to pick up the preferenceFragmentListStyle
    final TypedValue tv = new TypedValue();
    getActivity().getTheme().resolveAttribute(R.attr.preferenceTheme, tv, true);
    final int theme = tv.resourceId;

    final Context themedContext = new ContextThemeWrapper(inflater.getContext(), theme);
    final LayoutInflater themedInflater = inflater.cloneInContext(themedContext);

    final View view = themedInflater.inflate(mLayoutResId, container, false);

    final View rawListContainer = view.findViewById(AndroidResources.ANDROID_R_LIST_CONTAINER);
    if (!(rawListContainer instanceof ViewGroup)) {
        throw new RuntimeException("Content has view with id attribute "
                + "'android.R.id.list_container' that is not a ViewGroup class");
    }

    final ViewGroup listContainer = (ViewGroup) rawListContainer;

    final RecyclerView listView = onCreateRecyclerView(themedInflater, listContainer, savedInstanceState);
    if (listView == null) {
        throw new RuntimeException("Could not create RecyclerView");
    }

    mList = listView;

    listView.addItemDecoration(mDividerDecoration);
    setDivider(divider);
    if (dividerHeight != -1) {
        setDividerHeight(dividerHeight);
    }

    listContainer.addView(mList);
    mHandler.post(mRequestFocus);

    return view;
}

From source file:android.support.v14.preference.PreferenceFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    TypedArray a = mStyledContext.obtainStyledAttributes(null, R.styleable.PreferenceFragment,
            TypedArrayUtils.getAttr(mStyledContext,
                    android.support.v7.preference.R.attr.preferenceFragmentStyle,
                    AndroidResources.ANDROID_R_PREFERENCE_FRAGMENT_STYLE),
            0);/*from   ww  w.  j ava2s .c o m*/

    mLayoutResId = a.getResourceId(R.styleable.PreferenceFragment_android_layout, mLayoutResId);

    final Drawable divider = a.getDrawable(R.styleable.PreferenceFragment_android_divider);
    final int dividerHeight = a.getDimensionPixelSize(R.styleable.PreferenceFragment_android_dividerHeight, -1);

    a.recycle();

    // Need to theme the inflater to pick up the preferenceFragmentListStyle
    final TypedValue tv = new TypedValue();
    getActivity().getTheme().resolveAttribute(android.support.v7.preference.R.attr.preferenceTheme, tv, true);
    final int theme = tv.resourceId;

    final Context themedContext = new ContextThemeWrapper(inflater.getContext(), theme);
    final LayoutInflater themedInflater = inflater.cloneInContext(themedContext);

    final View view = themedInflater.inflate(mLayoutResId, container, false);

    final View rawListContainer = view.findViewById(AndroidResources.ANDROID_R_LIST_CONTAINER);
    if (!(rawListContainer instanceof ViewGroup)) {
        throw new RuntimeException("Content has view with id attribute "
                + "'android.R.id.list_container' that is not a ViewGroup class");
    }

    final ViewGroup listContainer = (ViewGroup) rawListContainer;

    final RecyclerView listView = onCreateRecyclerView(themedInflater, listContainer, savedInstanceState);
    if (listView == null) {
        throw new RuntimeException("Could not create RecyclerView");
    }

    mList = listView;

    listView.addItemDecoration(mDividerDecoration);
    setDivider(divider);
    if (dividerHeight != -1) {
        setDividerHeight(dividerHeight);
    }

    listContainer.addView(mList);
    mHandler.post(mRequestFocus);

    return view;
}

From source file:android.support.v7.preference.PreferenceController.java

@Override
@NonNull//w ww. j a v  a 2s.co m
public View onCreateView(@NonNull LayoutInflater inflater, @NonNull ViewGroup container,
        @Nullable Bundle savedInstanceState) {
    mInitDone = false;
    mHavePrefs = false;

    final TypedValue tv = new TypedValue();
    getActivity().getTheme().resolveAttribute(R.attr.preferenceTheme, tv, true);
    final int theme = tv.resourceId;
    if (theme == 0) {
        throw new IllegalStateException("Must specify preferenceTheme in theme");
    }
    mStyledContext = new ContextThemeWrapper(getActivity(), theme);

    mPreferenceManager = new PreferenceManager(mStyledContext);
    final String rootKey = getArgs().getString(ARG_PREFERENCE_ROOT);
    onCreatePreferences(savedInstanceState, rootKey);

    TypedArray a = mStyledContext.obtainStyledAttributes(null, R.styleable.PreferenceFragmentCompat,
            R.attr.preferenceFragmentCompatStyle, 0);

    mLayoutResId = a.getResourceId(R.styleable.PreferenceFragmentCompat_android_layout, mLayoutResId);

    mDividerDecoration = new DividerDecoration();
    final Drawable divider = a.getDrawable(R.styleable.PreferenceFragmentCompat_android_divider);
    final int dividerHeight = a
            .getDimensionPixelSize(R.styleable.PreferenceFragmentCompat_android_dividerHeight, -1);
    final boolean allowDividerAfterLastItem = a
            .getBoolean(R.styleable.PreferenceFragmentCompat_allowDividerAfterLastItem, true);

    a.recycle();

    final Context themedContext = new ContextThemeWrapper(inflater.getContext(), theme);
    final LayoutInflater themedInflater = inflater.cloneInContext(themedContext);

    final View view = themedInflater.inflate(mLayoutResId, container, false);

    final View rawListContainer = view.findViewById(AndroidResources.ANDROID_R_LIST_CONTAINER);
    if (!(rawListContainer instanceof ViewGroup)) {
        throw new RuntimeException("Content has view with id attribute "
                + "'android.R.id.list_container' that is not a ViewGroup class");
    }

    final ViewGroup listContainer = (ViewGroup) rawListContainer;

    final RecyclerView listView = onCreateRecyclerView(themedInflater, listContainer, savedInstanceState);
    if (listView == null) {
        throw new RuntimeException("Could not create RecyclerView");
    }

    mList = listView;

    listView.addItemDecoration(mDividerDecoration);
    setDivider(divider);
    if (dividerHeight != -1) {
        setDividerHeight(dividerHeight);
    }
    mDividerDecoration.setAllowDividerAfterLastItem(allowDividerAfterLastItem);

    listContainer.addView(mList);
    mHandler.post(mRequestFocus);

    onViewCreated(view, savedInstanceState);

    return view;
}