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:com.actionbarsherlock.internal.widget.ActionBarView.java

public ActionBarView(Context context, AttributeSet attrs) {
    super(context, attrs);

    // Background is always provided by the container.
    setBackgroundResource(0);/*from  www . ja  v  a 2  s  . c o  m*/

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SherlockActionBar, R.attr.actionBarStyle,
            0);

    ApplicationInfo appInfo = context.getApplicationInfo();
    PackageManager pm = context.getPackageManager();
    mNavigationMode = a.getInt(R.styleable.SherlockActionBar_navigationMode,
            ActionBar.NAVIGATION_MODE_STANDARD);
    mTitle = a.getText(R.styleable.SherlockActionBar_title);
    mSubtitle = a.getText(R.styleable.SherlockActionBar_subtitle);

    mLogo = a.getDrawable(R.styleable.SherlockActionBar_logo);
    if (mLogo == null) {
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
            if (context instanceof Activity) {
                //Even though native methods existed in API 9 and 10 they don't work
                //so just parse the manifest to look for the logo pre-Honeycomb
                final int resId = loadLogoFromManifest((Activity) context);
                if (resId != 0) {
                    mLogo = context.getResources().getDrawable(resId);
                }
            }
        } else {
            if (context instanceof Activity) {
                try {
                    mLogo = pm.getActivityLogo(((Activity) context).getComponentName());
                } catch (NameNotFoundException e) {
                    Log.e(TAG, "Activity component name not found!", e);
                }
            }
            if (mLogo == null) {
                mLogo = appInfo.loadLogo(pm);
            }
        }
    }

    mIcon = a.getDrawable(R.styleable.SherlockActionBar_icon);
    if (mIcon == null) {
        if (context instanceof Activity) {
            try {
                mIcon = pm.getActivityIcon(((Activity) context).getComponentName());
            } catch (NameNotFoundException e) {
                Log.e(TAG, "Activity component name not found!", e);
            }
        }
        if (mIcon == null) {
            mIcon = appInfo.loadIcon(pm);
        }
    }

    final LayoutInflater inflater = LayoutInflater.from(context);

    final int homeResId = a.getResourceId(R.styleable.SherlockActionBar_homeLayout,
            R.layout.abs__action_bar_home);

    mHomeLayout = (HomeView) inflater.inflate(homeResId, this, false);

    mExpandedHomeLayout = (HomeView) inflater.inflate(homeResId, this, false);
    mExpandedHomeLayout.setUp(true);
    mExpandedHomeLayout.setOnClickListener(mExpandedActionViewUpListener);
    mExpandedHomeLayout.setContentDescription(getResources().getText(R.string.abs__action_bar_up_description));

    mTitleStyleRes = a.getResourceId(R.styleable.SherlockActionBar_titleTextStyle, 0);
    mSubtitleStyleRes = a.getResourceId(R.styleable.SherlockActionBar_subtitleTextStyle, 0);
    mProgressStyle = a.getResourceId(R.styleable.SherlockActionBar_progressBarStyle, 0);
    mIndeterminateProgressStyle = a.getResourceId(R.styleable.SherlockActionBar_indeterminateProgressStyle, 0);

    mProgressBarPadding = a.getDimensionPixelOffset(R.styleable.SherlockActionBar_progressBarPadding, 0);
    mItemPadding = a.getDimensionPixelOffset(R.styleable.SherlockActionBar_itemPadding, 0);

    setDisplayOptions(a.getInt(R.styleable.SherlockActionBar_displayOptions, DISPLAY_DEFAULT));

    final int customNavId = a.getResourceId(R.styleable.SherlockActionBar_customNavigationLayout, 0);
    if (customNavId != 0) {
        mCustomNavView = inflater.inflate(customNavId, this, false);
        mNavigationMode = ActionBar.NAVIGATION_MODE_STANDARD;
        setDisplayOptions(mDisplayOptions | ActionBar.DISPLAY_SHOW_CUSTOM);
    }

    mContentHeight = a.getLayoutDimension(R.styleable.SherlockActionBar_height, 0);

    a.recycle();

    mLogoNavItem = new ActionMenuItem(context, 0, android.R.id.home, 0, 0, mTitle);
    mHomeLayout.setOnClickListener(mUpClickListener);
    mHomeLayout.setClickable(true);
    mHomeLayout.setFocusable(true);
}

From source file:com.wanderingcan.persistentsearch.PersistentSearchView.java

@SuppressWarnings("deprecation")
private void initialize(Context context, AttributeSet attrs, int defStyleAttr) {
    mNavIcon = new ImageButton(context);
    mEndIcon = new ImageButton(context);
    mSearchText = new EditText(context);
    mSearchMenuView = new SearchMenuView(context);
    mDivider = new View(context);
    mDivider.setVisibility(GONE);//from  w  w w .  j av a2s .co m

    mPresenter = new SearchMenuPresenter(context, new SearchMenuListener());

    mSearchMenuView.setAdapter(mPresenter.mAdapter);
    mSearchMenuView.addItemDecoration(new DividerItemDecoration(context, attrs));

    int[] attr = { android.R.attr.listDivider };
    TypedArray ta = context.obtainStyledAttributes(attr);
    Drawable divider = ta.getDrawable(0);
    ta.recycle();

    mOpened = false;
    mShowClearDrawable = false;
    mShowMenu = true;

    //Set up CardView
    setUseCompatPadding(true);
    setFocusable(true);
    setFocusableInTouchMode(true);

    //Set up TextView
    if (Build.VERSION.SDK_INT >= 16) {
        mSearchText.setBackground(null);
        mNavIcon.setBackground(null);
        mEndIcon.setBackground(null);
        mDivider.setBackground(divider);
    } else {
        mSearchText.setBackgroundDrawable(null);
        mNavIcon.setBackgroundDrawable(null);
        mEndIcon.setBackgroundDrawable(null);
        mDivider.setBackgroundDrawable(divider);
    }
    mSearchText.setSingleLine();
    mHintVisible = false;
    mSearchText.setOnFocusChangeListener(new SearchFocusListener());
    mSearchText.setOnEditorActionListener(new EditTextEditorAction());
    mSearchText.setImeOptions(EditorInfo.IME_ACTION_SEARCH);
    mSearchText.addTextChangedListener(new EditTextTextWatcher());

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.PersistentSearchView, defStyleAttr, 0);
    Drawable drawable = a.getDrawable(R.styleable.PersistentSearchView_navSrc);
    setNavigationDrawable(drawable);
    mNavIcon.setScaleType(ImageView.ScaleType.FIT_CENTER);
    mNavIcon.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (mIconListener != null) {
                mIconListener.OnNavigationIconClick();
            }
        }
    });

    drawable = a.getDrawable(R.styleable.PersistentSearchView_endSrc);
    setEndDrawable(drawable);
    mClearDrawable = ContextCompat.getDrawable(getContext(), R.drawable.ic_action_cancel);
    mEndIcon.setScaleType(ImageView.ScaleType.FIT_CENTER);
    mEndIcon.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (mShowClearDrawable) {
                //Clears the text
                mSearchText.setText(EMPTY);
            } else {
                if (mIconListener != null) {
                    mIconListener.OnEndIconClick();
                }
            }
        }
    });

    mHint = a.getText(R.styleable.PersistentSearchView_hint);
    mHintAlwaysVisible = a.getBoolean(R.styleable.PersistentSearchView_hintAlwaysActive, false);
    if (mHintAlwaysVisible) {
        mSearchText.setHint(mHint);
    }
    a.recycle();

    Resources res = context.getResources();
    int imageDimen = res.getDimensionPixelSize(R.dimen.persistent_search_view_image_dimen);
    mImageMargin = res.getDimensionPixelSize(R.dimen.persistent_search_view_image_side_margin);
    int imageTopMargin = res.getDimensionPixelSize(R.dimen.persistent_search_view_image_top_margin);

    //Sets all of the locations of the views
    CardView.LayoutParams lpNav = generateDefaultLayoutParams();
    lpNav.width = lpNav.height = imageDimen;

    CardView.LayoutParams lpEnd = (LayoutParams) generateLayoutParams(lpNav);

    lpNav.gravity = Gravity.START;
    lpEnd.gravity = Gravity.END;

    if (Build.VERSION.SDK_INT >= 17) {
        mNavIcon.setPaddingRelative(mImageMargin, imageTopMargin, mImageMargin / 2, imageTopMargin);
        mEndIcon.setPaddingRelative(mImageMargin / 2, imageTopMargin, mImageMargin, imageTopMargin);
    } else {
        mNavIcon.setPadding(mImageMargin, imageTopMargin, mImageMargin / 2, imageTopMargin);
        mEndIcon.setPadding(mImageMargin / 2, imageTopMargin, mImageMargin, imageTopMargin);
    }

    CardView.LayoutParams lpText = generateDefaultLayoutParams();
    lpText.gravity = Gravity.TOP;
    lpText.height = lpNav.topMargin + lpNav.height;
    mTextMargin = res.getDimensionPixelSize(R.dimen.persistent_search_view_text_margin);
    if (Build.VERSION.SDK_INT >= 17) {
        lpText.setMarginStart(mTextMargin);
        lpText.setMarginEnd(mTextMargin);
    } else {
        lpText.leftMargin = lpText.rightMargin = mTextMargin;
    }
    lpText = setupSearchTextMargin(lpText);

    CardView.LayoutParams lpMenu = generateDefaultLayoutParams();
    lpMenu.topMargin = lpNav.topMargin + lpNav.height;
    lpMenu.height = RecyclerView.LayoutParams.WRAP_CONTENT;

    CardView.LayoutParams lpDivider = generateDefaultLayoutParams();
    if (divider != null) {
        lpDivider.height = divider.getIntrinsicHeight();
    }
    lpDivider.topMargin = lpNav.topMargin + lpNav.height;

    //Adds the views to the PersistentSearchView
    addView(mNavIcon, lpNav);
    addView(mEndIcon, lpEnd);
    addView(mSearchText, lpText);
    addView(mSearchMenuView, lpMenu);
    addView(mDivider, lpDivider);
}

From source file:io.github.vomitcuddle.SearchViewAllowEmpty.SearchView.java

public SearchView(Context context, AttributeSet attrs) {
    super(context, attrs);

    LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    inflater.inflate(R.layout.cba_search_view, this, true);

    mSearchButton = findViewById(R.id.search_button);
    mQueryTextView = (SearchAutoComplete) findViewById(R.id.search_src_text);
    mQueryTextView.setSearchView(this);

    mSearchEditFrame = findViewById(R.id.search_edit_frame);
    mSearchPlate = findViewById(R.id.search_plate);
    mSubmitArea = findViewById(R.id.submit_area);
    mSubmitButton = findViewById(R.id.search_go_btn);
    mCloseButton = (ImageView) findViewById(R.id.search_close_btn);
    mVoiceButton = findViewById(R.id.search_voice_btn);
    mSearchHintIcon = (ImageView) findViewById(R.id.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);
            }/*  w w  w  .  ja v  a2  s .  c o  m*/
        }
    });

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SearchView, 0, 0);
    setIconifiedByDefault(a.getBoolean(R.styleable.SearchView_iconifiedByDefault, true));
    int maxWidth = a.getDimensionPixelSize(R.styleable.SearchView_android_maxWidth, -1);
    if (maxWidth != -1) {
        setMaxWidth(maxWidth);
    }
    CharSequence queryHint = a.getText(R.styleable.SearchView_queryHint);
    if (!TextUtils.isEmpty(queryHint)) {
        setQueryHint(queryHint);
    }
    int imeOptions = a.getInt(R.styleable.SearchView_android_imeOptions, -1);
    if (imeOptions != -1) {
        setImeOptions(imeOptions);
    }
    int inputType = a.getInt(R.styleable.SearchView_android_inputType, -1);
    if (inputType != -1) {
        setInputType(inputType);
    }

    a.recycle();

    boolean focusable = true;

    a = context.obtainStyledAttributes(attrs, R.styleable.View, 0, 0);
    focusable = a.getBoolean(R.styleable.View_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) {
            addOnLayoutChangeListenerToDropDownAnchorSDK11();
        } else {
            addOnLayoutChangeListenerToDropDownAnchorBase();
        }
    }

    updateViewsVisibility(mIconifiedByDefault);
    updateQueryHint();
}

From source file:cm.aptoide.com.actionbarsherlock.widget.SearchView.java

public SearchView(Context context, AttributeSet attrs) {
    super(context, attrs);

    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.FROYO) {
        throw new IllegalStateException("SearchView is API 8+ only.");
    }//  www  . jav a  2  s  .  co  m

    LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    inflater.inflate(R.layout.abs__search_view, this, true);

    mSearchButton = findViewById(R.id.abs__search_button);
    mQueryTextView = (SearchAutoComplete) findViewById(R.id.abs__search_src_text);
    mQueryTextView.setSearchView(this);

    mSearchEditFrame = findViewById(R.id.abs__search_edit_frame);
    mSearchPlate = findViewById(R.id.abs__search_plate);
    mSubmitArea = findViewById(R.id.abs__submit_area);
    mSubmitButton = findViewById(R.id.abs__search_go_btn);
    mCloseButton = (ImageView) findViewById(R.id.abs__search_close_btn);
    mVoiceButton = findViewById(R.id.abs__search_voice_btn);
    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, R.styleable.SherlockSearchView, 0, 0);
    setIconifiedByDefault(a.getBoolean(R.styleable.SherlockSearchView_iconifiedByDefault, true));
    int maxWidth = a.getDimensionPixelSize(R.styleable.SherlockSearchView_android_maxWidth, -1);
    if (maxWidth != -1) {
        setMaxWidth(maxWidth);
    }
    CharSequence queryHint = a.getText(R.styleable.SherlockSearchView_queryHint);
    if (!TextUtils.isEmpty(queryHint)) {
        setQueryHint(queryHint);
    }
    int imeOptions = a.getInt(R.styleable.SherlockSearchView_android_imeOptions, -1);
    if (imeOptions != -1) {
        setImeOptions(imeOptions);
    }
    int inputType = a.getInt(R.styleable.SherlockSearchView_android_inputType, -1);
    if (inputType != -1) {
        setInputType(inputType);
    }

    a.recycle();

    boolean focusable = true;

    a = context.obtainStyledAttributes(attrs, R.styleable.SherlockView, 0, 0);
    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:lewa.support.v7.widget.SearchView.java

public SearchView(Context context, AttributeSet attrs) {
    super(context, attrs);

    LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    inflater.inflate(R.layout.abc_search_view, this, true);

    mSearchButton = findViewById(R.id.search_button);
    mQueryTextView = (SearchAutoComplete) findViewById(R.id.search_src_text);
    mQueryTextView.setSearchView(this);

    mSearchEditFrame = findViewById(R.id.search_edit_frame);
    mSearchPlate = findViewById(R.id.search_plate);
    mSubmitArea = findViewById(R.id.submit_area);
    mSubmitButton = findViewById(R.id.search_go_btn);
    mCloseButton = (ImageView) findViewById(R.id.search_close_btn);
    mVoiceButton = findViewById(R.id.search_voice_btn);
    mSearchHintIcon = (ImageView) findViewById(R.id.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);
            }//  w w  w . j  a v a2s  .c  o  m
        }
    });

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SearchView, 0, 0);

    mSearchIconResId = a.getResourceId(R.styleable.SearchView_searchIcon, 0);

    setIconifiedByDefault(a.getBoolean(R.styleable.SearchView_iconifiedByDefault, true));
    int maxWidth = a.getDimensionPixelSize(R.styleable.SearchView_android_maxWidth, -1);
    if (maxWidth != -1) {
        setMaxWidth(maxWidth);
    }
    CharSequence queryHint = a.getText(R.styleable.SearchView_queryHint);
    if (!TextUtils.isEmpty(queryHint)) {
        setQueryHint(queryHint);
    }
    int imeOptions = a.getInt(R.styleable.SearchView_android_imeOptions, -1);
    if (imeOptions != -1) {
        setImeOptions(imeOptions);
    }
    int inputType = a.getInt(R.styleable.SearchView_android_inputType, -1);
    if (inputType != -1) {
        setInputType(inputType);
    }

    a.recycle();

    boolean focusable = true;

    a = context.obtainStyledAttributes(attrs, R.styleable.View, 0, 0);
    focusable = a.getBoolean(R.styleable.View_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) {
            addOnLayoutChangeListenerToDropDownAnchorSDK11();
        } else {
            addOnLayoutChangeListenerToDropDownAnchorBase();
        }
    }

    updateViewsVisibility(mIconifiedByDefault);
    updateQueryHint();
}

From source file:lewa.support.v7.internal.widget.ActionBarView.java

public ActionBarView(Context context, AttributeSet attrs) {
    super(context, attrs);

    mContext = context;//from w  w  w. j  a  v a 2 s  .  co m

    // Background is always provided by the container.
    setBackgroundResource(0);

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ActionBar, R.attr.actionBarStyle, 0);

    ApplicationInfo appInfo = context.getApplicationInfo();
    PackageManager pm = context.getPackageManager();
    mNavigationMode = a.getInt(R.styleable.ActionBar_navigationMode, ActionBar.NAVIGATION_MODE_STANDARD);
    mTitle = a.getText(R.styleable.ActionBar_lewa_title);
    mSubtitle = a.getText(R.styleable.ActionBar_subtitle);
    mLogo = a.getDrawable(R.styleable.ActionBar_logo);
    if (mLogo == null) {
        if (Build.VERSION.SDK_INT >= 9) {
            if (context instanceof Activity) {
                try {
                    mLogo = pm.getActivityLogo(((Activity) context).getComponentName());
                } catch (NameNotFoundException e) {
                    Log.e(TAG, "Activity component name not found!", e);
                }
            }
            if (mLogo == null) {
                mLogo = appInfo.loadLogo(pm);
            }
        }
    }

    // TODO(trevorjohns): Should these use the android namespace
    mIcon = a.getDrawable(R.styleable.ActionBar_lewa_icon);
    if (mIcon == null) {
        if (context instanceof Activity) {
            try {
                mIcon = pm.getActivityIcon(((Activity) context).getComponentName());
            } catch (NameNotFoundException e) {
                Log.e(TAG, "Activity component name not found!", e);
            }
        }
        if (mIcon == null) {
            mIcon = appInfo.loadIcon(pm);
        }
    }

    final LayoutInflater inflater = LayoutInflater.from(context);

    final int homeResId = a.getResourceId(R.styleable.ActionBar_homeLayout, R.layout.abc_action_bar_home);

    mHomeLayout = (HomeView) inflater.inflate(homeResId, this, false);

    mExpandedHomeLayout = (HomeView) inflater.inflate(homeResId, this, false);
    mExpandedHomeLayout.setUp(true);
    mExpandedHomeLayout.setOnClickListener(mExpandedActionViewUpListener);
    mExpandedHomeLayout.setContentDescription(getResources().getText(R.string.abc_action_bar_up_description));
    mExpandedHomeLayout.setEnabled(true);
    mExpandedHomeLayout.setFocusable(true);

    mTitleStyleRes = a.getResourceId(R.styleable.ActionBar_titleTextStyle, 0);
    mSubtitleStyleRes = a.getResourceId(R.styleable.ActionBar_subtitleTextStyle, 0);
    mProgressStyle = a.getResourceId(R.styleable.ActionBar_progressBarStyle, 0);
    mIndeterminateProgressStyle = a.getResourceId(R.styleable.ActionBar_indeterminateProgressStyle, 0);

    mProgressBarPadding = a.getDimensionPixelOffset(R.styleable.ActionBar_progressBarPadding, 0);
    mItemPadding = a.getDimensionPixelOffset(R.styleable.ActionBar_itemPadding, 0);
    ///LEWA BEGIN
    mStatusbarHeight = (int) context.getResources().getDimension(R.dimen.android_status_bar_height);
    ///LEWA END

    setDisplayOptions(a.getInt(R.styleable.ActionBar_displayOptions, DISPLAY_DEFAULT));

    final int customNavId = a.getResourceId(R.styleable.ActionBar_customNavigationLayout, 0);
    if (customNavId != 0) {
        mCustomNavView = (View) inflater.inflate(customNavId, this, false);
        mNavigationMode = ActionBar.NAVIGATION_MODE_STANDARD;
        setDisplayOptions(mDisplayOptions | ActionBar.DISPLAY_SHOW_CUSTOM);
    }

    mContentHeight = a.getLayoutDimension(R.styleable.ActionBar_height, 0);
    //            mContentHeight = Math.max(mContentHeight,
    //                    r.getDimensionPixelSize(R.dimen.abc_action_bar_stacked_max_height));
    mContentHeight = ActionBarPolicy.get(mContext).getTabContainerHeight();
    a.recycle();
    mLogoNavItem = new ActionMenuItem(context, 0, android.R.id.home, 0, 0, mTitle);
    mHomeLayout.setOnClickListener(mUpClickListener);
    mHomeLayout.setClickable(true);
    mHomeLayout.setFocusable(true);
    ///LEWA BEGIN
    mMaxHomeSlop = (int) (MAX_HOME_SLOP * context.getResources().getDisplayMetrics().density + 0.5f);
    ///LEWA END

    ///LEWA BEGIN
    Injector.initilize(context, this);
    ///LEWA END
}

From source file:ticwear.design.widget.StretchingLayout.java

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

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

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

    mCollapsingTextHelper/* w ww .j  ava  2  s.  com*/
            .setExpandedTextGravity(a.getInt(R.styleable.CollapsingToolbarLayout_tic_expandedTitleGravity,
                    GravityCompat.START | Gravity.BOTTOM));
    mCollapsingTextHelper
            .setCollapsedTextGravity(a.getInt(R.styleable.CollapsingToolbarLayout_tic_collapsedTitleGravity,
                    GravityCompat.START | Gravity.CENTER_VERTICAL));

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

    if (a.hasValue(R.styleable.CollapsingToolbarLayout_tic_expandedTitleMarginStart)) {
        mExpandedMarginStart = a
                .getDimensionPixelSize(R.styleable.CollapsingToolbarLayout_tic_expandedTitleMarginStart, 0);
    }
    if (a.hasValue(R.styleable.CollapsingToolbarLayout_tic_expandedTitleMarginEnd)) {
        mExpandedMarginEnd = a
                .getDimensionPixelSize(R.styleable.CollapsingToolbarLayout_tic_expandedTitleMarginEnd, 0);
    }
    if (a.hasValue(R.styleable.CollapsingToolbarLayout_tic_expandedTitleMarginTop)) {
        mExpandedMarginTop = a
                .getDimensionPixelSize(R.styleable.CollapsingToolbarLayout_tic_expandedTitleMarginTop, 0);
    }
    if (a.hasValue(R.styleable.CollapsingToolbarLayout_tic_expandedTitleMarginBottom)) {
        mExpandedMarginBottom = a
                .getDimensionPixelSize(R.styleable.CollapsingToolbarLayout_tic_expandedTitleMarginBottom, 0);
    }

    mCollapsingTitleEnabled = a.getBoolean(R.styleable.CollapsingToolbarLayout_tic_titleEnabled, true);
    setTitle(a.getText(R.styleable.CollapsingToolbarLayout_android_title));

    // First load the default text appearances
    mCollapsingTextHelper.setExpandedTextAppearance(R.style.TextAppearance_Ticwear_CollapsingToolbar_Expanded);
    mCollapsingTextHelper.setCollapsedTextAppearance(R.style.TextAppearance_Ticwear_TitleBar_Title);

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

    a.recycle();

    setWillNotDraw(false);

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

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

public void extractViewInformations(String styleName, int styleId, JSONObject json, String qtClassName,
        AttributeSet attribSet) {
    try {//from  w  w w . j  a va  2  s . c  o m
        int[] viewAttrs;
        viewAttrs = (int[]) styleableClass.getDeclaredField("View").get(null);
        TypedArray a = m_theme.obtainStyledAttributes(attribSet, viewAttrs, styleId, 0);

        if (null != qtClassName)
            json.put("qtClass", qtClassName);

        final int N = a.getIndexCount();
        for (int i = 0; i < N; i++) {
            int attr = a.getIndex(i);
            if (attr == View_background)
                json.put("View_background", getDrawable(a.getDrawable(attr), styleName + "_View_background"));
            else if (attr == View_padding)
                json.put("View_padding", a.getDimensionPixelSize(attr, -1));
            else if (attr == View_paddingLeft)
                json.put("View_paddingLeft", a.getDimensionPixelSize(attr, -1));
            else if (attr == View_paddingTop)
                json.put("View_paddingTop", a.getDimensionPixelSize(attr, -1));
            else if (attr == View_paddingRight)
                json.put("View_paddingRight", a.getDimensionPixelSize(attr, -1));
            else if (attr == View_paddingBottom)
                json.put("View_paddingBottom", a.getDimensionPixelSize(attr, -1));
            else if (attr == View_scrollX)
                json.put("View_paddingBottom", a.getDimensionPixelOffset(attr, 0));
            else if (attr == View_scrollY)
                json.put("View_scrollY", a.getDimensionPixelOffset(attr, 0));
            else if (attr == View_id)
                json.put("View_id", a.getResourceId(attr, -1));
            else if (attr == View_tag)
                json.put("View_tag", a.getText(attr));
            else if (attr == View_fitsSystemWindows)
                json.put("View_fitsSystemWindows", a.getBoolean(attr, false));
            else if (attr == View_focusable)
                json.put("View_focusable", a.getBoolean(attr, false));
            else if (attr == View_focusableInTouchMode)
                json.put("View_focusableInTouchMode", a.getBoolean(attr, false));
            else if (attr == View_clickable)
                json.put("View_clickable", a.getBoolean(attr, false));
            else if (attr == View_longClickable)
                json.put("View_longClickable", a.getBoolean(attr, false));
            else if (attr == View_saveEnabled)
                json.put("View_saveEnabled", a.getBoolean(attr, true));
            else if (attr == View_duplicateParentState)
                json.put("View_duplicateParentState", a.getBoolean(attr, false));
            else if (attr == View_visibility)
                json.put("View_visibility", a.getInt(attr, 0));
            else if (attr == View_drawingCacheQuality)
                json.put("View_drawingCacheQuality", a.getInt(attr, 0));
            else if (attr == View_drawingCacheQuality)
                json.put("View_contentDescription", a.getString(attr));
            else if (attr == View_soundEffectsEnabled)
                json.put("View_soundEffectsEnabled", a.getBoolean(attr, true));
            else if (attr == View_hapticFeedbackEnabled)
                json.put("View_hapticFeedbackEnabled", a.getBoolean(attr, true));
            else if (attr == View_scrollbars)
                json.put("View_scrollbars", a.getInt(attr, 0));
            else if (attr == View_fadingEdge)
                json.put("View_fadingEdge", a.getInt(attr, 0));
            else if (attr == View_scrollbarStyle)
                json.put("View_scrollbarStyle", a.getInt(attr, 0));
            else if (attr == View_isScrollContainer)
                json.put("View_isScrollContainer", a.getBoolean(attr, false));
            else if (attr == View_keepScreenOn)
                json.put("View_keepScreenOn", a.getBoolean(attr, false));
            else if (attr == View_filterTouchesWhenObscured)
                json.put("View_filterTouchesWhenObscured", a.getBoolean(attr, false));
            else if (attr == View_nextFocusLeft)
                json.put("View_nextFocusLeft", a.getResourceId(attr, -1));
            else if (attr == View_nextFocusRight)
                json.put("View_nextFocusRight", a.getResourceId(attr, -1));
            else if (attr == View_nextFocusUp)
                json.put("View_nextFocusUp", a.getResourceId(attr, -1));
            else if (attr == View_nextFocusDown)
                json.put("View_nextFocusDown", a.getResourceId(attr, -1));
            else if (attr == View_minWidth)
                json.put("View_minWidth", a.getDimensionPixelSize(attr, 0));
            else if (attr == View_minHeight)
                json.put("View_minHeight", a.getDimensionPixelSize(attr, 0));
            else if (attr == View_onClick)
                json.put("View_onClick", a.getString(attr));
            else if (attr == View_overScrollMode)
                json.put("View_overScrollMode", a.getInt(attr, 1));
        }
        a.recycle();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:ticwear.design.widget.CollapsingToolbarLayout.java

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

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

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

    mCollapsingTextHelper/*from  w  w  w  .  ja va2  s  . c om*/
            .setExpandedTextGravity(a.getInt(R.styleable.CollapsingToolbarLayout_tic_expandedTitleGravity,
                    GravityCompat.START | Gravity.BOTTOM));
    mCollapsingTextHelper
            .setCollapsedTextGravity(a.getInt(R.styleable.CollapsingToolbarLayout_tic_collapsedTitleGravity,
                    GravityCompat.START | Gravity.CENTER_VERTICAL));

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

    if (a.hasValue(R.styleable.CollapsingToolbarLayout_tic_expandedTitleMarginStart)) {
        mExpandedMarginStart = a
                .getDimensionPixelSize(R.styleable.CollapsingToolbarLayout_tic_expandedTitleMarginStart, 0);
    }
    if (a.hasValue(R.styleable.CollapsingToolbarLayout_tic_expandedTitleMarginEnd)) {
        mExpandedMarginEnd = a
                .getDimensionPixelSize(R.styleable.CollapsingToolbarLayout_tic_expandedTitleMarginEnd, 0);
    }
    if (a.hasValue(R.styleable.CollapsingToolbarLayout_tic_expandedTitleMarginTop)) {
        mExpandedMarginTop = a
                .getDimensionPixelSize(R.styleable.CollapsingToolbarLayout_tic_expandedTitleMarginTop, 0);
    }
    if (a.hasValue(R.styleable.CollapsingToolbarLayout_tic_expandedTitleMarginBottom)) {
        mExpandedMarginBottom = a
                .getDimensionPixelSize(R.styleable.CollapsingToolbarLayout_tic_expandedTitleMarginBottom, 0);
    }

    mCollapsingTitleEnabled = a.getBoolean(R.styleable.CollapsingToolbarLayout_tic_titleEnabled, true);
    setTitle(a.getText(R.styleable.CollapsingToolbarLayout_android_title));

    // First load the default text appearances
    mCollapsingTextHelper.setExpandedTextAppearance(R.style.TextAppearance_Ticwear_CollapsingToolbar_Expanded);
    mCollapsingTextHelper.setCollapsedTextAppearance(R.style.TextAppearance_Ticwear_TitleBar_Title);

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

    setContentScrim(a.getDrawable(R.styleable.CollapsingToolbarLayout_tic_contentScrim));
    setStatusBarScrim(a.getDrawable(R.styleable.CollapsingToolbarLayout_tic_statusBarScrim));

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

    a.recycle();

    setWillNotDraw(false);

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

From source file:android.support.designox.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//from w w w. j a  v a2s  .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(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));
    }

    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.v4ox.view.OnApplyWindowInsetsListener() {
                @Override
                public WindowInsetsCompat onApplyWindowInsets(View v, WindowInsetsCompat insets) {
                    return setWindowInsets(insets);
                }
            });
}