Example usage for android.app Activity obtainStyledAttributes

List of usage examples for android.app Activity obtainStyledAttributes

Introduction

In this page you can find the example usage for android.app Activity obtainStyledAttributes.

Prototype

public final TypedArray obtainStyledAttributes(@StyleRes int resid, @StyleableRes int[] attrs)
        throws Resources.NotFoundException 

Source Link

Document

Retrieve styled attribute information in this Context's theme.

Usage

From source file:com.eutectoid.dosomething.picker.PickerFragment.java

@Override
public void onInflate(Activity activity, AttributeSet attrs, Bundle savedInstanceState) {
    super.onInflate(activity, attrs, savedInstanceState);
    TypedArray a = activity.obtainStyledAttributes(attrs, R.styleable.picker_fragment);

    setShowPictures(a.getBoolean(R.styleable.picker_fragment_show_pictures, showPictures));
    String extraFieldsString = a.getString(R.styleable.picker_fragment_extra_fields);
    if (extraFieldsString != null) {
        String[] strings = extraFieldsString.split(",");
        setExtraFields(Arrays.asList(strings));
    }// www . j a v  a  2s  . c  om

    showTitleBar = a.getBoolean(R.styleable.picker_fragment_show_title_bar, showTitleBar);
    titleText = a.getString(R.styleable.picker_fragment_title_text);
    doneButtonText = a.getString(R.styleable.picker_fragment_done_button_text);
    titleBarBackground = a.getDrawable(R.styleable.picker_fragment_title_bar_background);
    doneButtonBackground = a.getDrawable(R.styleable.picker_fragment_done_button_background);

    a.recycle();
}

From source file:android.app.FragmentState.java

/**
 * Called when a fragment is being created as part of a view layout
 * inflation, typically from setting the content view of an activity.  This
 * may be called immediately after the fragment is created from a <fragment>
 * tag in a layout file.  Note this is <em>before</em> the fragment's
 * {@link #onAttach(Activity)} has been called; all you should do here is
 * parse the attributes and save them away.
 *
 * <p>This is called every time the fragment is inflated, even if it is
 * being inflated into a new instance with saved state.  It typically makes
 * sense to re-parse the parameters each time, to allow them to change with
 * different configurations.</p>/*  w ww. j  a va  2 s.  c om*/
 *
 * <p>Here is a typical implementation of a fragment that can take parameters
 * both through attributes supplied here as well from {@link #getArguments()}:</p>
 *
 * {@sample development/samples/ApiDemos/src/com/example/android/apis/app/FragmentArguments.java
 *      fragment}
 *
 * <p>Note that parsing the XML attributes uses a "styleable" resource.  The
 * declaration for the styleable used here is:</p>
 *
 * {@sample development/samples/ApiDemos/res/values/attrs.xml fragment_arguments}
 * 
 * <p>The fragment can then be declared within its activity's content layout
 * through a tag like this:</p>
 *
 * {@sample development/samples/ApiDemos/res/layout/fragment_arguments.xml from_attributes}
 *
 * <p>This fragment can also be created dynamically from arguments given
 * at runtime in the arguments Bundle; here is an example of doing so at
 * creation of the containing activity:</p>
 *
 * {@sample development/samples/ApiDemos/src/com/example/android/apis/app/FragmentArguments.java
 *      create}
 *
 * @param activity The Activity that is inflating this fragment.
 * @param attrs The attributes at the tag where the fragment is
 * being created.
 * @param savedInstanceState If the fragment is being re-created from
 * a previous saved state, this is the state.
 */
public void onInflate(Activity activity, AttributeSet attrs, Bundle savedInstanceState) {
    onInflate(attrs, savedInstanceState);
    mCalled = true;

    TypedArray a = activity.obtainStyledAttributes(attrs, com.android.internal.R.styleable.Fragment);
    mEnterTransition = loadTransition(activity, a, mEnterTransition, null,
            com.android.internal.R.styleable.Fragment_fragmentEnterTransition);
    mReturnTransition = loadTransition(activity, a, mReturnTransition, USE_DEFAULT_TRANSITION,
            com.android.internal.R.styleable.Fragment_fragmentReturnTransition);
    mExitTransition = loadTransition(activity, a, mExitTransition, null,
            com.android.internal.R.styleable.Fragment_fragmentExitTransition);
    mReenterTransition = loadTransition(activity, a, mReenterTransition, USE_DEFAULT_TRANSITION,
            com.android.internal.R.styleable.Fragment_fragmentReenterTransition);
    mSharedElementEnterTransition = loadTransition(activity, a, mSharedElementEnterTransition, null,
            com.android.internal.R.styleable.Fragment_fragmentSharedElementEnterTransition);
    mSharedElementReturnTransition = loadTransition(activity, a, mSharedElementReturnTransition,
            USE_DEFAULT_TRANSITION,
            com.android.internal.R.styleable.Fragment_fragmentSharedElementReturnTransition);
    if (mAllowEnterTransitionOverlap == null) {
        mAllowEnterTransitionOverlap = a.getBoolean(
                com.android.internal.R.styleable.Fragment_fragmentAllowEnterTransitionOverlap, true);
    }
    if (mAllowReturnTransitionOverlap == null) {
        mAllowReturnTransitionOverlap = a.getBoolean(
                com.android.internal.R.styleable.Fragment_fragmentAllowReturnTransitionOverlap, true);
    }
    a.recycle();
}