Example usage for android.content.res TypedArray getText

List of usage examples for android.content.res TypedArray getText

Introduction

In this page you can find the example usage for android.content.res TypedArray getText.

Prototype

public CharSequence getText(@StyleableRes int index) 

Source Link

Document

Retrieves the styled string value for the attribute at index.

Usage

From source file:android.support.design.widget.CollapsingToolbarLayout.java

public CollapsingToolbarLayout(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    ThemeUtils.checkAppCompatTheme(context);

    mCollapsingTextHelper = new CollapsingTextHelper(this);
    mCollapsingTextHelper.setTextSizeInterpolator(AnimationUtils.DECELERATE_INTERPOLATOR);

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CollapsingToolbarLayout, defStyleAttr,
            R.style.Widget_Design_CollapsingToolbar);

    mCollapsingTextHelper.setExpandedTextGravity(a.getInt(
            R.styleable.CollapsingToolbarLayout_expandedTitleGravity, GravityCompat.START | Gravity.BOTTOM));
    mCollapsingTextHelper//  w  w w . j  a v a 2s.  c o  m
            .setCollapsedTextGravity(a.getInt(R.styleable.CollapsingToolbarLayout_collapsedTitleGravity,
                    GravityCompat.START | Gravity.CENTER_VERTICAL));

    mExpandedMarginStart = mExpandedMarginTop = mExpandedMarginEnd = mExpandedMarginBottom = a
            .getDimensionPixelSize(R.styleable.CollapsingToolbarLayout_expandedTitleMargin, 0);

    if (a.hasValue(R.styleable.CollapsingToolbarLayout_expandedTitleMarginStart)) {
        mExpandedMarginStart = a
                .getDimensionPixelSize(R.styleable.CollapsingToolbarLayout_expandedTitleMarginStart, 0);
    }
    if (a.hasValue(R.styleable.CollapsingToolbarLayout_expandedTitleMarginEnd)) {
        mExpandedMarginEnd = a.getDimensionPixelSize(R.styleable.CollapsingToolbarLayout_expandedTitleMarginEnd,
                0);
    }
    if (a.hasValue(R.styleable.CollapsingToolbarLayout_expandedTitleMarginTop)) {
        mExpandedMarginTop = a.getDimensionPixelSize(R.styleable.CollapsingToolbarLayout_expandedTitleMarginTop,
                0);
    }
    if (a.hasValue(R.styleable.CollapsingToolbarLayout_expandedTitleMarginBottom)) {
        mExpandedMarginBottom = a
                .getDimensionPixelSize(R.styleable.CollapsingToolbarLayout_expandedTitleMarginBottom, 0);
    }

    mCollapsingTitleEnabled = a.getBoolean(R.styleable.CollapsingToolbarLayout_titleEnabled, true);
    setTitle(a.getText(R.styleable.CollapsingToolbarLayout_title));

    // First load the default text appearances
    mCollapsingTextHelper.setExpandedTextAppearance(R.style.TextAppearance_Design_CollapsingToolbar_Expanded);
    mCollapsingTextHelper.setCollapsedTextAppearance(
            android.support.v7.appcompat.R.style.TextAppearance_AppCompat_Widget_ActionBar_Title);

    // Now overlay any custom text appearances
    if (a.hasValue(R.styleable.CollapsingToolbarLayout_expandedTitleTextAppearance)) {
        mCollapsingTextHelper.setExpandedTextAppearance(
                a.getResourceId(R.styleable.CollapsingToolbarLayout_expandedTitleTextAppearance, 0));
    }
    if (a.hasValue(R.styleable.CollapsingToolbarLayout_collapsedTitleTextAppearance)) {
        mCollapsingTextHelper.setCollapsedTextAppearance(
                a.getResourceId(R.styleable.CollapsingToolbarLayout_collapsedTitleTextAppearance, 0));
    }

    mScrimVisibleHeightTrigger = a
            .getDimensionPixelSize(R.styleable.CollapsingToolbarLayout_scrimVisibleHeightTrigger, -1);

    mScrimAnimationDuration = a.getInt(R.styleable.CollapsingToolbarLayout_scrimAnimationDuration,
            DEFAULT_SCRIM_ANIMATION_DURATION);

    setContentScrim(a.getDrawable(R.styleable.CollapsingToolbarLayout_contentScrim));
    setStatusBarScrim(a.getDrawable(R.styleable.CollapsingToolbarLayout_statusBarScrim));

    mToolbarId = a.getResourceId(R.styleable.CollapsingToolbarLayout_toolbarId, -1);

    a.recycle();

    setWillNotDraw(false);

    ViewCompat.setOnApplyWindowInsetsListener(this, new android.support.v4.view.OnApplyWindowInsetsListener() {
        @Override
        public WindowInsetsCompat onApplyWindowInsets(View v, WindowInsetsCompat insets) {
            return onWindowInsetChanged(insets);
        }
    });
}

From source file:com.muzakki.ahmad.widget.CollapsingToolbarLayout.java

public CollapsingToolbarLayout(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    ThemeUtils.checkAppCompatTheme(context);

    mCollapsingTextHelper = new CollapsingTextHelper(this);
    mCollapsingTextHelper.setTextSizeInterpolator(AnimationUtils.DECELERATE_INTERPOLATOR);

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CollapsingToolbarLayout, defStyleAttr,
            R.style.Widget_Design_CollapsingToolbar);

    mCollapsingTextHelper.setExpandedTextGravity(a.getInt(
            R.styleable.CollapsingToolbarLayout_expandedTitleGravity, GravityCompat.START | Gravity.BOTTOM));
    mCollapsingTextHelper//w  w  w  .  jav  a  2 s.c  o  m
            .setCollapsedTextGravity(a.getInt(R.styleable.CollapsingToolbarLayout_collapsedTitleGravity,
                    GravityCompat.START | Gravity.CENTER_VERTICAL));

    mExpandedMarginStart = mExpandedMarginTop = mExpandedMarginEnd = mExpandedMarginBottom = a
            .getDimensionPixelSize(R.styleable.CollapsingToolbarLayout_expandedTitleMargin, 0);

    if (a.hasValue(R.styleable.CollapsingToolbarLayout_expandedTitleMarginStart)) {
        mExpandedMarginStart = a
                .getDimensionPixelSize(R.styleable.CollapsingToolbarLayout_expandedTitleMarginStart, 0);
    }
    if (a.hasValue(R.styleable.CollapsingToolbarLayout_expandedTitleMarginEnd)) {
        mExpandedMarginEnd = a.getDimensionPixelSize(R.styleable.CollapsingToolbarLayout_expandedTitleMarginEnd,
                0);
    }
    if (a.hasValue(R.styleable.CollapsingToolbarLayout_expandedTitleMarginTop)) {
        mExpandedMarginTop = a.getDimensionPixelSize(R.styleable.CollapsingToolbarLayout_expandedTitleMarginTop,
                0);
    }
    if (a.hasValue(R.styleable.CollapsingToolbarLayout_expandedTitleMarginBottom)) {
        mExpandedMarginBottom = a
                .getDimensionPixelSize(R.styleable.CollapsingToolbarLayout_expandedTitleMarginBottom, 0);
    }

    mCollapsingTitleEnabled = a.getBoolean(R.styleable.CollapsingToolbarLayout_titleEnabled, true);
    setTitle(a.getText(R.styleable.CollapsingToolbarLayout_title));

    // begin modification
    TypedArray mStyle = context.obtainStyledAttributes(attrs, R.styleable.SubtitleCollapsingToolbar,
            defStyleAttr, R.style.SubtitleCollapsingToolbar);
    if (mStyle.hasValue(R.styleable.SubtitleCollapsingToolbar_subtitle))
        setSubtitle(mStyle.getText(R.styleable.SubtitleCollapsingToolbar_subtitle).toString());

    //load default appearances first
    mCollapsingTextHelper.setCollapsedSubAppearance(R.style.CollapsedSubtitleAppearance);
    mCollapsingTextHelper.setExpandedSubAppearance(R.style.ExpandedSubtitleAppearance);

    // now apply custom sub appearance
    if (mStyle.hasValue(R.styleable.SubtitleCollapsingToolbar_collapsedSubtitleAppearance)) {
        mCollapsingTextHelper.setCollapsedSubAppearance(
                mStyle.getResourceId(R.styleable.SubtitleCollapsingToolbar_collapsedSubtitleAppearance, 0));
    }

    if (mStyle.hasValue(R.styleable.SubtitleCollapsingToolbar_expandedSubtitleAppearance)) {
        mCollapsingTextHelper.setExpandedSubAppearance(
                mStyle.getResourceId(R.styleable.SubtitleCollapsingToolbar_expandedSubtitleAppearance, 0));
    }
    // end

    // First load the default text appearances
    mCollapsingTextHelper.setExpandedTextAppearance(R.style.TextAppearance_Design_CollapsingToolbar_Expanded);
    mCollapsingTextHelper.setCollapsedTextAppearance(
            android.support.v7.appcompat.R.style.TextAppearance_AppCompat_Widget_ActionBar_Title);

    // Now overlay any custom text appearances
    if (a.hasValue(R.styleable.CollapsingToolbarLayout_expandedTitleTextAppearance)) {
        mCollapsingTextHelper.setExpandedTextAppearance(
                a.getResourceId(R.styleable.CollapsingToolbarLayout_expandedTitleTextAppearance, 0));
    }
    if (a.hasValue(R.styleable.CollapsingToolbarLayout_collapsedTitleTextAppearance)) {
        mCollapsingTextHelper.setCollapsedTextAppearance(
                a.getResourceId(R.styleable.CollapsingToolbarLayout_collapsedTitleTextAppearance, 0));
    }

    mScrimVisibleHeightTrigger = a
            .getDimensionPixelSize(R.styleable.CollapsingToolbarLayout_scrimVisibleHeightTrigger, -1);

    mScrimAnimationDuration = a.getInt(R.styleable.CollapsingToolbarLayout_scrimAnimationDuration,
            DEFAULT_SCRIM_ANIMATION_DURATION);

    setContentScrim(a.getDrawable(R.styleable.CollapsingToolbarLayout_contentScrim));
    setStatusBarScrim(a.getDrawable(R.styleable.CollapsingToolbarLayout_statusBarScrim));

    mToolbarId = a.getResourceId(R.styleable.CollapsingToolbarLayout_toolbarId, -1);

    a.recycle();

    setWillNotDraw(false);

    ViewCompat.setOnApplyWindowInsetsListener(this, new android.support.v4.view.OnApplyWindowInsetsListener() {
        @Override
        public WindowInsetsCompat onApplyWindowInsets(View v, WindowInsetsCompat insets) {
            return onWindowInsetChanged(insets);
        }
    });
}

From source file:net.opacapp.multilinecollapsingtoolbar.CollapsingToolbarLayout.java

public CollapsingToolbarLayout(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    ThemeUtils.checkAppCompatTheme(context);

    mCollapsingTextHelper = new CollapsingTextHelper(this);
    mCollapsingTextHelper.setTextSizeInterpolator(AnimationUtils.DECELERATE_INTERPOLATOR);

    // BEGIN MODIFICATION: use own default style
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CollapsingToolbarLayout, defStyleAttr,
            net.opacapp.multilinecollapsingtoolbar.R.style.Widget_Design_MultilineCollapsingToolbar);
    // END MODIFICATION

    mCollapsingTextHelper.setExpandedTextGravity(a.getInt(
            R.styleable.CollapsingToolbarLayout_expandedTitleGravity, GravityCompat.START | Gravity.BOTTOM));
    mCollapsingTextHelper/*w  w w.  j  av  a 2 s . co m*/
            .setCollapsedTextGravity(a.getInt(R.styleable.CollapsingToolbarLayout_collapsedTitleGravity,
                    GravityCompat.START | Gravity.CENTER_VERTICAL));

    mExpandedMarginStart = mExpandedMarginTop = mExpandedMarginEnd = mExpandedMarginBottom = a
            .getDimensionPixelSize(R.styleable.CollapsingToolbarLayout_expandedTitleMargin, 0);

    if (a.hasValue(R.styleable.CollapsingToolbarLayout_expandedTitleMarginStart)) {
        mExpandedMarginStart = a
                .getDimensionPixelSize(R.styleable.CollapsingToolbarLayout_expandedTitleMarginStart, 0);
    }
    if (a.hasValue(R.styleable.CollapsingToolbarLayout_expandedTitleMarginEnd)) {
        mExpandedMarginEnd = a.getDimensionPixelSize(R.styleable.CollapsingToolbarLayout_expandedTitleMarginEnd,
                0);
    }
    if (a.hasValue(R.styleable.CollapsingToolbarLayout_expandedTitleMarginTop)) {
        mExpandedMarginTop = a.getDimensionPixelSize(R.styleable.CollapsingToolbarLayout_expandedTitleMarginTop,
                0);
    }
    if (a.hasValue(R.styleable.CollapsingToolbarLayout_expandedTitleMarginBottom)) {
        mExpandedMarginBottom = a
                .getDimensionPixelSize(R.styleable.CollapsingToolbarLayout_expandedTitleMarginBottom, 0);
    }

    mCollapsingTitleEnabled = a.getBoolean(R.styleable.CollapsingToolbarLayout_titleEnabled, true);
    setTitle(a.getText(R.styleable.CollapsingToolbarLayout_title));

    // First load the default text appearances
    mCollapsingTextHelper.setExpandedTextAppearance(R.style.TextAppearance_Design_CollapsingToolbar_Expanded);
    // BEGIN MODIFICATION: use own default style
    mCollapsingTextHelper
            .setCollapsedTextAppearance(net.opacapp.multilinecollapsingtoolbar.R.style.ActionBar_Title);
    // END MODIFICATION

    // Now overlay any custom text appearances
    if (a.hasValue(R.styleable.CollapsingToolbarLayout_expandedTitleTextAppearance)) {
        mCollapsingTextHelper.setExpandedTextAppearance(
                a.getResourceId(R.styleable.CollapsingToolbarLayout_expandedTitleTextAppearance, 0));
    }
    if (a.hasValue(R.styleable.CollapsingToolbarLayout_collapsedTitleTextAppearance)) {
        mCollapsingTextHelper.setCollapsedTextAppearance(
                a.getResourceId(R.styleable.CollapsingToolbarLayout_collapsedTitleTextAppearance, 0));
    }

    mScrimVisibleHeightTrigger = a.getInt(R.styleable.CollapsingToolbarLayout_scrimVisibleHeightTrigger, -1);

    mScrimAnimationDuration = a.getInt(R.styleable.CollapsingToolbarLayout_scrimAnimationDuration,
            DEFAULT_SCRIM_ANIMATION_DURATION);

    setContentScrim(a.getDrawable(R.styleable.CollapsingToolbarLayout_contentScrim));
    setStatusBarScrim(a.getDrawable(R.styleable.CollapsingToolbarLayout_statusBarScrim));

    mToolbarId = a.getResourceId(R.styleable.CollapsingToolbarLayout_toolbarId, -1);

    a.recycle();

    setWillNotDraw(false);

    ViewCompat.setOnApplyWindowInsetsListener(this, new android.support.v4.view.OnApplyWindowInsetsListener() {
        @Override
        public WindowInsetsCompat onApplyWindowInsets(View v, WindowInsetsCompat insets) {
            return setWindowInsets(insets);
        }
    });

    // BEGIN MODIFICATION: set the value of maxNumberOfLines attribute to the mCollapsingTextHelper
    TypedArray typedArray = context.obtainStyledAttributes(attrs,
            net.opacapp.multilinecollapsingtoolbar.R.styleable.CollapsingToolbarLayoutExtension, defStyleAttr,
            0);
    mCollapsingTextHelper.setMaxLines(typedArray.getInteger(
            net.opacapp.multilinecollapsingtoolbar.R.styleable.CollapsingToolbarLayoutExtension_maxLines, 3));
    // END MODIFICATION
}

From source file:com.tandong.sa.sherlock.widget.SearchView.java

public SearchView(Context context, AttributeSet attrs) {
    super(context, attrs);
    this.c = context;

    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.FROYO) {
        throw new IllegalStateException("SearchView is API 8+ only.");
    }/*  w  w w .j  av  a2  s . c o  m*/

    LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    inflater.inflate(getResources().getIdentifier("abs__search_view", "layout", context.getPackageName()), this,
            true);
    // inflater.inflate(R.layout.abs__search_view, this, true);

    mSearchButton = findViewById(
            getResources().getIdentifier("abs__search_button", "id", context.getPackageName()));
    // mSearchButton = findViewById(R.id.abs__search_button);
    mQueryTextView = (SearchAutoComplete) findViewById(
            getResources().getIdentifier("abs__search_src_text", "id", context.getPackageName()));
    // mQueryTextView = (SearchAutoComplete)
    // findViewById(R.id.abs__search_src_text);
    mQueryTextView.setSearchView(this);

    mSearchEditFrame = findViewById(
            getResources().getIdentifier("abs__search_edit_frame", "id", context.getPackageName()));
    // mSearchEditFrame = findViewById(R.id.abs__search_edit_frame);
    mSearchPlate = findViewById(
            getResources().getIdentifier("abs__search_plate", "id", context.getPackageName()));
    // mSearchPlate = findViewById(R.id.abs__search_plate);
    mSubmitArea = findViewById(
            getResources().getIdentifier("abs__submit_area", "id", context.getPackageName()));
    // mSubmitArea = findViewById(R.id.abs__submit_area);
    mSubmitButton = findViewById(
            getResources().getIdentifier("abs__search_go_btn", "id", context.getPackageName()));
    // mSubmitButton = findViewById(R.id.abs__search_go_btn);
    mCloseButton = (ImageView) findViewById(
            getResources().getIdentifier("abs__search_close_btn", "id", context.getPackageName()));
    // mCloseButton = (ImageView) findViewById(R.id.abs__search_close_btn);
    mVoiceButton = findViewById(
            getResources().getIdentifier("abs__search_voice_btn", "id", context.getPackageName()));
    // mVoiceButton = findViewById(R.id.abs__search_voice_btn);
    mSearchHintIcon = (ImageView) findViewById(
            getResources().getIdentifier("abs__search_mag_icon", "id", context.getPackageName()));
    // mSearchHintIcon = (ImageView)
    // findViewById(R.id.abs__search_mag_icon);

    mSearchButton.setOnClickListener(mOnClickListener);
    mCloseButton.setOnClickListener(mOnClickListener);
    mSubmitButton.setOnClickListener(mOnClickListener);
    mVoiceButton.setOnClickListener(mOnClickListener);
    mQueryTextView.setOnClickListener(mOnClickListener);

    mQueryTextView.addTextChangedListener(mTextWatcher);
    mQueryTextView.setOnEditorActionListener(mOnEditorActionListener);
    mQueryTextView.setOnItemClickListener(mOnItemClickListener);
    mQueryTextView.setOnItemSelectedListener(mOnItemSelectedListener);
    mQueryTextView.setOnKeyListener(mTextKeyListener);
    // Inform any listener of focus changes
    mQueryTextView.setOnFocusChangeListener(new OnFocusChangeListener() {

        public void onFocusChange(View v, boolean hasFocus) {
            if (mOnQueryTextFocusChangeListener != null) {
                mOnQueryTextFocusChangeListener.onFocusChange(SearchView.this, hasFocus);
            }
        }
    });

    TypedArray a = context.obtainStyledAttributes(attrs,
            new int[] {
                    getResources().getIdentifier("SherlockSearchView", "styleable", context.getPackageName()) },
            0, 0);
    // R.styleable.SherlockSearchView, 0, 0);
    setIconifiedByDefault(a.getBoolean(getResources().getIdentifier("SherlockSearchView_iconifiedByDefault",
            "styleable", context.getPackageName()), true));
    // R.styleable.SherlockSearchView_iconifiedByDefault, true));
    int maxWidth = a.getDimensionPixelSize(getResources().getIdentifier("SherlockSearchView_android_maxWidth",
            "styleable", context.getPackageName()), -1);
    // R.styleable.SherlockSearchView_android_maxWidth, -1);
    if (maxWidth != -1) {
        setMaxWidth(maxWidth);
    }
    CharSequence queryHint = a.getText(getResources().getIdentifier("SherlockSearchView_queryHint", "styleable",
            context.getPackageName()));
    // .getText(R.styleable.SherlockSearchView_queryHint);
    if (!TextUtils.isEmpty(queryHint)) {
        setQueryHint(queryHint);
    }
    int imeOptions = a.getInt(getResources().getIdentifier("SherlockSearchView_android_imeOptions", "styleable",
            context.getPackageName()), -1);
    // R.styleable.SherlockSearchView_android_imeOptions, -1);
    if (imeOptions != -1) {
        setImeOptions(imeOptions);
    }
    int inputType = a.getInt(getResources().getIdentifier("SherlockSearchView_android_inputType", "styleable",
            context.getPackageName()), -1);
    // R.styleable.SherlockSearchView_android_inputType, -1);
    if (inputType != -1) {
        setInputType(inputType);
    }

    a.recycle();

    boolean focusable = true;

    a = context.obtainStyledAttributes(attrs,
            new int[] { getResources().getIdentifier("SherlockView", "styleable", context.getPackageName()) },
            0,
            // a = context.obtainStyledAttributes(attrs,
            // R.styleable.SherlockView, 0,
            0);
    focusable = a.getBoolean(
            getResources().getIdentifier("SherlockView_android_focusable", "styleable",
                    context.getPackageName()),
            // focusable =
            // a.getBoolean(R.styleable.SherlockView_android_focusable,
            focusable);
    a.recycle();
    setFocusable(focusable);

    // Save voice intent for later queries/launching
    mVoiceWebSearchIntent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
    mVoiceWebSearchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    mVoiceWebSearchIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
            RecognizerIntent.LANGUAGE_MODEL_WEB_SEARCH);

    mVoiceAppSearchIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    mVoiceAppSearchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    mDropDownAnchor = findViewById(mQueryTextView.getDropDownAnchor());
    if (mDropDownAnchor != null) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            mDropDownAnchor.addOnLayoutChangeListener(new OnLayoutChangeListener() {
                @Override
                public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft,
                        int oldTop, int oldRight, int oldBottom) {
                    adjustDropDownSizeAndPosition();
                }
            });
        } else {
            mDropDownAnchor.getViewTreeObserver()
                    .addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
                        @Override
                        public void onGlobalLayout() {
                            adjustDropDownSizeAndPosition();
                        }
                    });
        }
    }

    updateViewsVisibility(mIconifiedByDefault);
    updateQueryHint();
}

From source file:com.tr4android.support.extension.widget.FlexibleToolbarLayout.java

public FlexibleToolbarLayout(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    mTitleCollapsingTextHelper = new CollapsingTextHelper(this);
    mTitleCollapsingTextHelper.setTextSizeInterpolator(AnimationUtils.LINEAR_INTERPOLATOR);
    mSubtitleCollapsingTextHelper = new CollapsingTextHelper(this);
    mSubtitleCollapsingTextHelper.setTextSizeInterpolator(AnimationUtils.LINEAR_INTERPOLATOR);
    mIconCollapsingHelper = new CollapsingDrawableHelper(this);
    mIconCollapsingHelper.setIconSizeInterpolator(AnimationUtils.LINEAR_INTERPOLATOR);

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.FlexibleToolbarLayout, defStyleAttr,
            R.style.Widget_Design_FlexibleToolbarLayout);

    int expandedVerticalGravity = a.getInt(R.styleable.FlexibleToolbarLayout_expandedGravity,
            Gravity.CENTER_VERTICAL);//from   www  .  j  a  va 2 s. com

    mTitleCollapsingTextHelper.setExpandedTextGravity(GravityCompat.START | expandedVerticalGravity);
    mTitleCollapsingTextHelper.setCollapsedTextGravity(GravityCompat.START | Gravity.CENTER_VERTICAL);
    mSubtitleCollapsingTextHelper.setExpandedTextGravity(GravityCompat.START | expandedVerticalGravity);
    mSubtitleCollapsingTextHelper.setCollapsedTextGravity(GravityCompat.START | Gravity.CENTER_VERTICAL);

    mExpandedMarginLeft = mExpandedMarginTop = mExpandedMarginRight = mExpandedMarginBottom = a
            .getDimensionPixelSize(R.styleable.FlexibleToolbarLayout_expandedMargin, 0);

    final boolean isRtl = ViewCompat.getLayoutDirection(this) == ViewCompat.LAYOUT_DIRECTION_RTL;
    if (a.hasValue(R.styleable.FlexibleToolbarLayout_expandedMarginStart)) {
        final int marginStart = a.getDimensionPixelSize(R.styleable.FlexibleToolbarLayout_expandedMarginStart,
                0);
        if (isRtl) {
            mExpandedMarginRight = marginStart;
        } else {
            mExpandedMarginLeft = marginStart;
        }
    }
    if (a.hasValue(R.styleable.FlexibleToolbarLayout_expandedMarginEnd)) {
        final int marginEnd = a.getDimensionPixelSize(R.styleable.FlexibleToolbarLayout_expandedMarginEnd, 0);
        if (isRtl) {
            mExpandedMarginLeft = marginEnd;
        } else {
            mExpandedMarginRight = marginEnd;
        }
    }
    if (a.hasValue(R.styleable.FlexibleToolbarLayout_expandedMarginTop)) {
        mExpandedMarginTop = a.getDimensionPixelSize(R.styleable.FlexibleToolbarLayout_expandedMarginTop, 0);
    }
    if (a.hasValue(R.styleable.FlexibleToolbarLayout_expandedMarginBottom)) {
        mExpandedMarginBottom = a.getDimensionPixelSize(R.styleable.FlexibleToolbarLayout_expandedMarginBottom,
                0);
    }

    mCollapsingTitleEnabled = a.getBoolean(R.styleable.FlexibleToolbarLayout_titleFlexibleEnabled, true);
    setTitle(a.getText(R.styleable.FlexibleToolbarLayout_title));
    mCollapsingSubtitleEnabled = a.getBoolean(R.styleable.FlexibleToolbarLayout_subtitleFlexibleEnabled, true);
    setSubtitle(a.getText(R.styleable.FlexibleToolbarLayout_subtitle));
    mCollapsingIconEnabled = a.getBoolean(R.styleable.FlexibleToolbarLayout_iconFlexibleEnabled, true);
    setIcon(a.getDrawable(R.styleable.FlexibleToolbarLayout_icon));

    // First load the default text appearances
    mTitleCollapsingTextHelper
            .setExpandedTextAppearance(R.style.TextAppearance_Design_FlexibleToolbarLayout_ExpandedTitle);
    mTitleCollapsingTextHelper
            .setCollapsedTextAppearance(R.style.TextAppearance_Design_FlexibleToolbarLayout_CollapsedTitle);
    mSubtitleCollapsingTextHelper
            .setExpandedTextAppearance(R.style.TextAppearance_Design_FlexibleToolbarLayout_Subtitle);
    mSubtitleCollapsingTextHelper
            .setCollapsedTextAppearance(R.style.TextAppearance_Design_FlexibleToolbarLayout_Subtitle);

    // Now overlay any custom text appearances
    if (a.hasValue(R.styleable.FlexibleToolbarLayout_titleExpandedTextAppearance)) {
        mTitleCollapsingTextHelper.setExpandedTextAppearance(
                a.getResourceId(R.styleable.FlexibleToolbarLayout_titleExpandedTextAppearance, 0));
    }
    if (a.hasValue(R.styleable.FlexibleToolbarLayout_titleCollapsedTextAppearance)) {
        mTitleCollapsingTextHelper.setCollapsedTextAppearance(
                a.getResourceId(R.styleable.FlexibleToolbarLayout_titleCollapsedTextAppearance, 0));

    }
    if (a.hasValue(R.styleable.FlexibleToolbarLayout_subtitleExpandedTextAppearance)) {
        mSubtitleCollapsingTextHelper.setExpandedTextAppearance(
                a.getResourceId(R.styleable.FlexibleToolbarLayout_subtitleExpandedTextAppearance, 0));
    }
    if (a.hasValue(R.styleable.FlexibleToolbarLayout_subtitleCollapsedTextAppearance)) {
        mSubtitleCollapsingTextHelper.setCollapsedTextAppearance(
                a.getResourceId(R.styleable.FlexibleToolbarLayout_subtitleCollapsedTextAppearance, 0));

    }

    // Load the icon sizes
    mIconCollapsingHelper.setCollapsedIconSize(
            a.getDimensionPixelSize(R.styleable.FlexibleToolbarLayout_iconCollapsedSize, 0));
    mIconCollapsingHelper.setExpandedIconSize(
            a.getDimensionPixelSize(R.styleable.FlexibleToolbarLayout_iconExpandedSize, 0));

    mSpaceTitleSubtitle = a.getDimensionPixelSize(R.styleable.FlexibleToolbarLayout_spaceTitleSubtitle, 0);
    mSpaceIconTitles = a.getDimensionPixelSize(R.styleable.FlexibleToolbarLayout_spaceIconTitles, 0);

    setContentScrim(a.getDrawable(R.styleable.FlexibleToolbarLayout_contentScrimColor));
    setStatusBarScrim(a.getDrawable(R.styleable.FlexibleToolbarLayout_statusBarScrimColor));

    mToolbarId = a.getResourceId(R.styleable.FlexibleToolbarLayout_toolbarRefId, -1);

    a.recycle();

    setWillNotDraw(false);

    ViewCompat.setOnApplyWindowInsetsListener(this, new android.support.v4.view.OnApplyWindowInsetsListener() {
        @Override
        public WindowInsetsCompat onApplyWindowInsets(View v, WindowInsetsCompat insets) {
            mLastInsets = insets;
            requestLayout();
            return insets.consumeSystemWindowInsets();
        }
    });
}

From source file:com.android.server.MountService.java

private void readStorageListLocked() {
    mVolumes.clear();/*from  w ww . j  a v a2 s .  co m*/
    mVolumeStates.clear();

    Resources resources = mContext.getResources();

    int id = com.android.internal.R.xml.storage_list;
    XmlResourceParser parser = resources.getXml(id);
    AttributeSet attrs = Xml.asAttributeSet(parser);

    try {
        XmlUtils.beginDocument(parser, TAG_STORAGE_LIST);
        while (true) {
            XmlUtils.nextElement(parser);

            String element = parser.getName();
            if (element == null)
                break;

            if (TAG_STORAGE.equals(element)) {
                TypedArray a = resources.obtainAttributes(attrs, com.android.internal.R.styleable.Storage);

                String path = a.getString(com.android.internal.R.styleable.Storage_mountPoint);
                int descriptionId = a.getResourceId(com.android.internal.R.styleable.Storage_storageDescription,
                        -1);
                CharSequence description = a
                        .getText(com.android.internal.R.styleable.Storage_storageDescription);
                boolean primary = a.getBoolean(com.android.internal.R.styleable.Storage_primary, false);
                boolean removable = a.getBoolean(com.android.internal.R.styleable.Storage_removable, false);
                boolean emulated = a.getBoolean(com.android.internal.R.styleable.Storage_emulated, false);
                int mtpReserve = a.getInt(com.android.internal.R.styleable.Storage_mtpReserve, 0);
                boolean allowMassStorage = a
                        .getBoolean(com.android.internal.R.styleable.Storage_allowMassStorage, false);
                boolean allowMtp = a.getBoolean(com.android.internal.R.styleable.Storage_allowMtp, true);
                // resource parser does not support longs, so XML value is in megabytes
                long maxFileSize = a.getInt(com.android.internal.R.styleable.Storage_maxFileSize, 0) * 1024L
                        * 1024L;

                Slog.d(TAG,
                        "got storage path: " + path + " description: " + description + " primary: " + primary
                                + " removable: " + removable + " emulated: " + emulated + " mtpReserve: "
                                + mtpReserve + " allowMassStorage: " + allowMassStorage + " maxFileSize: "
                                + maxFileSize + " allowMtp: " + allowMtp);

                if (emulated) {
                    // For devices with emulated storage, we create separate
                    // volumes for each known user.
                    mEmulatedTemplate = new StorageVolume(null, descriptionId, true, false, true, mtpReserve,
                            false, maxFileSize, null, allowMtp);

                    final UserManagerService userManager = UserManagerService.getInstance();
                    for (UserInfo user : userManager.getUsers(false)) {
                        createEmulatedVolumeForUserLocked(user.getUserHandle());
                    }

                } else {
                    if (path == null || description == null) {
                        Slog.e(TAG, "Missing storage path or description in readStorageList");
                    } else {
                        final StorageVolume volume = new StorageVolume(new File(path), descriptionId, primary,
                                removable, emulated, mtpReserve, allowMassStorage, maxFileSize, null, allowMtp);
                        addVolumeLocked(volume);

                        // Until we hear otherwise, treat as unmounted
                        mVolumeStates.put(volume.getPath(), Environment.MEDIA_UNMOUNTED);
                        volume.setState(Environment.MEDIA_UNMOUNTED);
                    }
                }

                a.recycle();
            }
        }
    } catch (XmlPullParserException e) {
        throw new RuntimeException(e);
    } catch (IOException e) {
        throw new RuntimeException(e);
    } finally {
        // Compute storage ID for each physical volume; emulated storage is
        // always 0 when defined.
        int index = isExternalStorageEmulated() ? 1 : 0;
        for (StorageVolume volume : mVolumes) {
            if (!volume.isEmulated()) {
                volume.setStorageId(index++);
            }
        }
        parser.close();
    }
}

From source file:org.kde.necessitas.ministro.ExtractStyle.java

public JSONObject extractTextAppearanceInformations(String styleName, String qtClass, AttributeSet attribSet,
        int textAppearance) {
    JSONObject json = new JSONObject();
    try {//from  w w  w.jav a 2s  .c om
        int textColorHighlight = 0; //
        ColorStateList textColor = null; //
        ColorStateList textColorHint = null; //
        ColorStateList textColorLink = null; //
        int textSize = 15; //
        int typefaceIndex = -1; //
        int styleIndex = -1;
        boolean allCaps = false;

        Class<?> attrClass = Class.forName("android.R$attr");
        int styleId = attrClass.getDeclaredField(styleName).getInt(null);

        extractViewInformations(styleName, styleId, json, qtClass, attribSet);

        int[] textViewAttrs = (int[]) styleableClass.getDeclaredField("TextView").get(null);
        TypedArray a = m_theme.obtainStyledAttributes(null, textViewAttrs, styleId, 0);

        TypedArray appearance = null;
        if (-1 == textAppearance)
            textAppearance = a
                    .getResourceId(styleableClass.getDeclaredField("TextView_textAppearance").getInt(null), -1);

        if (textAppearance != -1)
            appearance = m_theme.obtainStyledAttributes(textAppearance,
                    (int[]) styleableClass.getDeclaredField("TextAppearance").get(null));

        if (appearance != null) {
            int n = appearance.getIndexCount();
            for (int i = 0; i < n; i++) {
                int attr = appearance.getIndex(i);
                if (attr == TextAppearance_textColorHighlight)
                    textColorHighlight = appearance.getColor(attr, textColorHighlight);
                else if (attr == TextAppearance_textColor)
                    textColor = appearance.getColorStateList(attr);
                else if (attr == TextAppearance_textColorHint)
                    textColorHint = appearance.getColorStateList(attr);
                else if (attr == TextAppearance_textColorLink)
                    textColorLink = appearance.getColorStateList(attr);
                else if (attr == TextAppearance_textSize)
                    textSize = appearance.getDimensionPixelSize(attr, textSize);
                else if (attr == TextAppearance_typeface)
                    typefaceIndex = appearance.getInt(attr, -1);
                else if (attr == TextAppearance_textStyle)
                    styleIndex = appearance.getInt(attr, -1);
                else if (attr == TextAppearance_textAllCaps)
                    allCaps = appearance.getBoolean(attr, false);
            }
            appearance.recycle();
        }

        int n = a.getIndexCount();

        for (int i = 0; i < n; i++) {
            int attr = a.getIndex(i);

            if (attr == TextView_editable)
                json.put("TextView_editable", a.getBoolean(attr, false));
            else if (attr == TextView_inputMethod)
                json.put("TextView_inputMethod", a.getText(attr));
            else if (attr == TextView_numeric)
                json.put("TextView_numeric", a.getInt(attr, 0));
            else if (attr == TextView_digits)
                json.put("TextView_digits", a.getText(attr));
            else if (attr == TextView_phoneNumber)
                json.put("TextView_phoneNumber", a.getBoolean(attr, false));
            else if (attr == TextView_autoText)
                json.put("TextView_autoText", a.getBoolean(attr, false));
            else if (attr == TextView_capitalize)
                json.put("TextView_capitalize", a.getInt(attr, -1));
            else if (attr == TextView_bufferType)
                json.put("TextView_bufferType", a.getInt(attr, 0));
            else if (attr == TextView_selectAllOnFocus)
                json.put("TextView_selectAllOnFocus", a.getBoolean(attr, false));
            else if (attr == TextView_autoLink)
                json.put("TextView_autoLink", a.getInt(attr, 0));
            else if (attr == TextView_linksClickable)
                json.put("TextView_linksClickable", a.getBoolean(attr, true));
            else if (attr == TextView_linksClickable)
                json.put("TextView_linksClickable", a.getBoolean(attr, true));
            else if (attr == TextView_drawableLeft)
                json.put("TextView_drawableLeft",
                        getDrawable(a.getDrawable(attr), styleName + "_TextView_drawableLeft"));
            else if (attr == TextView_drawableTop)
                json.put("TextView_drawableTop",
                        getDrawable(a.getDrawable(attr), styleName + "_TextView_drawableTop"));
            else if (attr == TextView_drawableRight)
                json.put("TextView_drawableRight",
                        getDrawable(a.getDrawable(attr), styleName + "_TextView_drawableRight"));
            else if (attr == TextView_drawableBottom)
                json.put("TextView_drawableBottom",
                        getDrawable(a.getDrawable(attr), styleName + "_TextView_drawableBottom"));
            else if (attr == TextView_drawableStart)
                json.put("TextView_drawableStart",
                        getDrawable(a.getDrawable(attr), styleName + "_TextView_drawableStart"));
            else if (attr == TextView_drawableEnd)
                json.put("TextView_drawableEnd",
                        getDrawable(a.getDrawable(attr), styleName + "_TextView_drawableEnd"));
            else if (attr == TextView_drawablePadding)
                json.put("TextView_drawablePadding", a.getDimensionPixelSize(attr, 0));
            else if (attr == TextView_textCursorDrawable)
                json.put("TextView_textCursorDrawable",
                        getDrawable(m_context.getResources().getDrawable(a.getResourceId(attr, 0)),
                                styleName + "_TextView_textCursorDrawable"));
            else if (attr == TextView_maxLines)
                json.put("TextView_maxLines", a.getInt(attr, -1));
            else if (attr == TextView_maxHeight)
                json.put("TextView_maxHeight", a.getDimensionPixelSize(attr, -1));
            else if (attr == TextView_lines)
                json.put("TextView_lines", a.getInt(attr, -1));
            else if (attr == TextView_height)
                json.put("TextView_height", a.getDimensionPixelSize(attr, -1));
            else if (attr == TextView_minLines)
                json.put("TextView_minLines", a.getInt(attr, -1));
            else if (attr == TextView_minHeight)
                json.put("TextView_minHeight", a.getDimensionPixelSize(attr, -1));
            else if (attr == TextView_maxEms)
                json.put("TextView_maxEms", a.getInt(attr, -1));
            else if (attr == TextView_maxWidth)
                json.put("TextView_maxWidth", a.getDimensionPixelSize(attr, -1));
            else if (attr == TextView_ems)
                json.put("TextView_ems", a.getInt(attr, -1));
            else if (attr == TextView_width)
                json.put("TextView_width", a.getDimensionPixelSize(attr, -1));
            else if (attr == TextView_minEms)
                json.put("TextView_minEms", a.getInt(attr, -1));
            else if (attr == TextView_minWidth)
                json.put("TextView_minWidth", a.getDimensionPixelSize(attr, -1));
            else if (attr == TextView_gravity)
                json.put("TextView_gravity", a.getInt(attr, -1));
            else if (attr == TextView_hint)
                json.put("TextView_hint", a.getText(attr));
            else if (attr == TextView_text)
                json.put("TextView_text", a.getText(attr));
            else if (attr == TextView_scrollHorizontally)
                json.put("TextView_scrollHorizontally", a.getBoolean(attr, false));
            else if (attr == TextView_singleLine)
                json.put("TextView_singleLine", a.getBoolean(attr, false));
            else if (attr == TextView_ellipsize)
                json.put("TextView_ellipsize", a.getInt(attr, -1));
            else if (attr == TextView_marqueeRepeatLimit)
                json.put("TextView_marqueeRepeatLimit", a.getInt(attr, 3));
            else if (attr == TextView_includeFontPadding)
                json.put("TextView_includeFontPadding", a.getBoolean(attr, true));
            else if (attr == TextView_cursorVisible)
                json.put("TextView_cursorVisible", a.getBoolean(attr, true));
            else if (attr == TextView_maxLength)
                json.put("TextView_maxLength", a.getInt(attr, -1));
            else if (attr == TextView_textScaleX)
                json.put("TextView_textScaleX", a.getFloat(attr, 1.0f));
            else if (attr == TextView_freezesText)
                json.put("TextView_freezesText", a.getBoolean(attr, false));
            else if (attr == TextView_shadowColor)
                json.put("TextView_shadowColor", a.getInt(attr, 0));
            else if (attr == TextView_shadowDx)
                json.put("TextView_shadowDx", a.getFloat(attr, 0));
            else if (attr == TextView_shadowDy)
                json.put("TextView_shadowDy", a.getFloat(attr, 0));
            else if (attr == TextView_shadowRadius)
                json.put("TextView_shadowRadius", a.getFloat(attr, 0));
            else if (attr == TextView_enabled)
                json.put("TextView_enabled", a.getBoolean(attr, true));
            else if (attr == TextView_textColorHighlight)
                textColorHighlight = a.getColor(attr, textColorHighlight);
            else if (attr == TextView_textColor)
                textColor = a.getColorStateList(attr);
            else if (attr == TextView_textColorHint)
                textColorHint = a.getColorStateList(attr);
            else if (attr == TextView_textColorLink)
                textColorLink = a.getColorStateList(attr);
            else if (attr == TextView_textSize)
                textSize = a.getDimensionPixelSize(attr, textSize);
            else if (attr == TextView_typeface)
                typefaceIndex = a.getInt(attr, typefaceIndex);
            else if (attr == TextView_textStyle)
                styleIndex = a.getInt(attr, styleIndex);
            else if (attr == TextView_password)
                json.put("TextView_password", a.getBoolean(attr, false));
            else if (attr == TextView_lineSpacingExtra)
                json.put("TextView_lineSpacingExtra", a.getDimensionPixelSize(attr, 0));
            else if (attr == TextView_lineSpacingMultiplier)
                json.put("TextView_lineSpacingMultiplier", a.getFloat(attr, 1.0f));
            else if (attr == TextView_inputType)
                json.put("TextView_inputType", a.getInt(attr, EditorInfo.TYPE_NULL));
            else if (attr == TextView_imeOptions)
                json.put("TextView_imeOptions", a.getInt(attr, EditorInfo.IME_NULL));
            else if (attr == TextView_imeActionLabel)
                json.put("TextView_imeActionLabel", a.getText(attr));
            else if (attr == TextView_imeActionId)
                json.put("TextView_imeActionId", a.getInt(attr, 0));
            else if (attr == TextView_privateImeOptions)
                json.put("TextView_privateImeOptions", a.getString(attr));
            else if (attr == TextView_textSelectHandleLeft && styleName.equals("textViewStyle"))
                json.put("TextView_textSelectHandleLeft",
                        getDrawable(m_context.getResources().getDrawable(a.getResourceId(attr, 0)),
                                styleName + "_TextView_textSelectHandleLeft"));
            else if (attr == TextView_textSelectHandleRight && styleName.equals("textViewStyle"))
                json.put("TextView_textSelectHandleRight",
                        getDrawable(m_context.getResources().getDrawable(a.getResourceId(attr, 0)),
                                styleName + "_TextView_textSelectHandleRight"));
            else if (attr == TextView_textSelectHandle && styleName.equals("textViewStyle"))
                json.put("TextView_textSelectHandle",
                        getDrawable(m_context.getResources().getDrawable(a.getResourceId(attr, 0)),
                                styleName + "_TextView_textSelectHandle"));
            else if (attr == TextView_textIsSelectable)
                json.put("TextView_textIsSelectable", a.getBoolean(attr, false));
            else if (attr == TextView_textAllCaps)
                allCaps = a.getBoolean(attr, false);
        }
        a.recycle();

        json.put("TextAppearance_textColorHighlight", textColorHighlight);
        json.put("TextAppearance_textColor", getColorStateList(textColor));
        json.put("TextAppearance_textColorHint", getColorStateList(textColorHint));
        json.put("TextAppearance_textColorLink", getColorStateList(textColorLink));
        json.put("TextAppearance_textSize", textSize);
        json.put("TextAppearance_typeface", typefaceIndex);
        json.put("TextAppearance_textStyle", styleIndex);
        json.put("TextAppearance_textAllCaps", allCaps);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return json;
}