List of usage examples for android.content.res TypedArray getLayoutDimension
public int getLayoutDimension(@StyleableRes int index, int defValue)
From source file:com.github.shareme.gwsmaterialuikit.library.material.app.Dialog.java
public Dialog applyStyle(int resId) { Context context = getContext(); TypedArray a = context.obtainStyledAttributes(resId, R.styleable.Dialog); int layout_width = mLayoutWidth; int layout_height = mLayoutHeight; boolean layoutParamsDefined = false; int titleTextAppearance = 0; int titleTextColor = 0; boolean titleTextColorDefined = false; int actionBackground = 0; int actionRipple = 0; int actionTextAppearance = 0; ColorStateList actionTextColors = null; int positiveActionBackground = 0; int positiveActionRipple = 0; int positiveActionTextAppearance = 0; ColorStateList positiveActionTextColors = null; int negativeActionBackground = 0; int negativeActionRipple = 0; int negativeActionTextAppearance = 0; ColorStateList negativeActionTextColors = null; int neutralActionBackground = 0; int neutralActionRipple = 0; int neutralActionTextAppearance = 0; ColorStateList neutralActionTextColors = null; for (int i = 0, count = a.getIndexCount(); i < count; i++) { int attr = a.getIndex(i); if (attr == R.styleable.Dialog_android_layout_width) { layout_width = a.getLayoutDimension(attr, ViewGroup.LayoutParams.WRAP_CONTENT); layoutParamsDefined = true;//from www . j a v a 2 s. c om } else if (attr == R.styleable.Dialog_android_layout_height) { layout_height = a.getLayoutDimension(attr, ViewGroup.LayoutParams.WRAP_CONTENT); layoutParamsDefined = true; } else if (attr == R.styleable.Dialog_di_maxWidth) maxWidth(a.getDimensionPixelOffset(attr, 0)); else if (attr == R.styleable.Dialog_di_maxHeight) maxHeight(a.getDimensionPixelOffset(attr, 0)); else if (attr == R.styleable.Dialog_di_dimAmount) dimAmount(a.getFloat(attr, 0)); else if (attr == R.styleable.Dialog_di_backgroundColor) backgroundColor(a.getColor(attr, 0)); else if (attr == R.styleable.Dialog_di_maxElevation) maxElevation(a.getDimensionPixelOffset(attr, 0)); else if (attr == R.styleable.Dialog_di_elevation) elevation(a.getDimensionPixelOffset(attr, 0)); else if (attr == R.styleable.Dialog_di_cornerRadius) cornerRadius(a.getDimensionPixelOffset(attr, 0)); else if (attr == R.styleable.Dialog_di_layoutDirection) layoutDirection(a.getInteger(attr, 0)); else if (attr == R.styleable.Dialog_di_titleTextAppearance) titleTextAppearance = a.getResourceId(attr, 0); else if (attr == R.styleable.Dialog_di_titleTextColor) { titleTextColor = a.getColor(attr, 0); titleTextColorDefined = true; } else if (attr == R.styleable.Dialog_di_actionBackground) actionBackground = a.getResourceId(attr, 0); else if (attr == R.styleable.Dialog_di_actionRipple) actionRipple = a.getResourceId(attr, 0); else if (attr == R.styleable.Dialog_di_actionTextAppearance) actionTextAppearance = a.getResourceId(attr, 0); else if (attr == R.styleable.Dialog_di_actionTextColor) actionTextColors = a.getColorStateList(attr); else if (attr == R.styleable.Dialog_di_positiveActionBackground) positiveActionBackground = a.getResourceId(attr, 0); else if (attr == R.styleable.Dialog_di_positiveActionRipple) positiveActionRipple = a.getResourceId(attr, 0); else if (attr == R.styleable.Dialog_di_positiveActionTextAppearance) positiveActionTextAppearance = a.getResourceId(attr, 0); else if (attr == R.styleable.Dialog_di_positiveActionTextColor) positiveActionTextColors = a.getColorStateList(attr); else if (attr == R.styleable.Dialog_di_negativeActionBackground) negativeActionBackground = a.getResourceId(attr, 0); else if (attr == R.styleable.Dialog_di_negativeActionRipple) negativeActionRipple = a.getResourceId(attr, 0); else if (attr == R.styleable.Dialog_di_negativeActionTextAppearance) negativeActionTextAppearance = a.getResourceId(attr, 0); else if (attr == R.styleable.Dialog_di_negativeActionTextColor) negativeActionTextColors = a.getColorStateList(attr); else if (attr == R.styleable.Dialog_di_neutralActionBackground) neutralActionBackground = a.getResourceId(attr, 0); else if (attr == R.styleable.Dialog_di_neutralActionRipple) neutralActionRipple = a.getResourceId(attr, 0); else if (attr == R.styleable.Dialog_di_neutralActionTextAppearance) neutralActionTextAppearance = a.getResourceId(attr, 0); else if (attr == R.styleable.Dialog_di_neutralActionTextColor) neutralActionTextColors = a.getColorStateList(attr); else if (attr == R.styleable.Dialog_di_inAnimation) inAnimation(a.getResourceId(attr, 0)); else if (attr == R.styleable.Dialog_di_outAnimation) outAnimation(a.getResourceId(attr, 0)); else if (attr == R.styleable.Dialog_di_dividerColor) dividerColor(a.getColor(attr, 0)); else if (attr == R.styleable.Dialog_di_dividerHeight) dividerHeight(a.getDimensionPixelOffset(attr, 0)); else if (attr == R.styleable.Dialog_di_cancelable) cancelable(a.getBoolean(attr, true)); else if (attr == R.styleable.Dialog_di_canceledOnTouchOutside) canceledOnTouchOutside(a.getBoolean(attr, true)); } a.recycle(); if (layoutParamsDefined) layoutParams(layout_width, layout_height); if (titleTextAppearance != 0) titleTextAppearance(titleTextAppearance); if (titleTextColorDefined) titleColor(titleTextColor); if (actionBackground != 0) actionBackground(actionBackground); if (actionRipple != 0) actionRipple(actionRipple); if (actionTextAppearance != 0) actionTextAppearance(actionTextAppearance); if (actionTextColors != null) actionTextColor(actionTextColors); if (positiveActionBackground != 0) positiveActionBackground(positiveActionBackground); if (positiveActionRipple != 0) positiveActionRipple(positiveActionRipple); if (positiveActionTextAppearance != 0) positiveActionTextAppearance(positiveActionTextAppearance); if (positiveActionTextColors != null) positiveActionTextColor(positiveActionTextColors); if (negativeActionBackground != 0) negativeActionBackground(negativeActionBackground); if (negativeActionRipple != 0) negativeActionRipple(negativeActionRipple); if (negativeActionTextAppearance != 0) negativeActionTextAppearance(negativeActionTextAppearance); if (negativeActionTextColors != null) negativeActionTextColor(negativeActionTextColors); if (neutralActionBackground != 0) neutralActionBackground(neutralActionBackground); if (neutralActionRipple != 0) neutralActionRipple(neutralActionRipple); if (neutralActionTextAppearance != 0) neutralActionTextAppearance(neutralActionTextAppearance); if (neutralActionTextColors != null) neutralActionTextColor(neutralActionTextColors); return this; }
From source file:android.support.v7.internal.widget.ActionBarView.java
public ActionBarView(Context context, AttributeSet attrs) { super(context, attrs); mContext = context;/*from ww w . ja v a2 s. c o 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_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_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)); 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); 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); 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.actionbarsherlock.internal.widget.ActionBarView.java
public ActionBarView(Context context, AttributeSet attrs) { super(context, attrs); // Background is always provided by the container. setBackgroundResource(0);/*w w w . ja v a2s .com*/ 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: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 a2 s .c o 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 }