Java Code Examples for android.content.res.TypedArray.getColor()

The following are Jave code examples for showing how to use getColor() of the android.content.res.TypedArray class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: FlickLauncher   File: IconCache.java   View Source Code Vote up 6 votes
public IconCache(Context context, InvariantDeviceProfile inv) {
    mContext = context;
    mPackageManager = context.getPackageManager();
    mUserManager = UserManagerCompat.getInstance(mContext);
    mLauncherApps = LauncherAppsCompat.getInstance(mContext);
    mIconDpi = inv.fillResIconDpi;
    mIconDb = new IconDB(context, inv.iconBitmapSize);
    mLowResCanvas = new Canvas();
    mLowResPaint = new Paint(Paint.FILTER_BITMAP_FLAG | Paint.ANTI_ALIAS_FLAG);

    mIconProvider = IconProvider.loadByName(context.getString(R.string.icon_provider_class),
            context);

    mWorkerHandler = new Handler(LauncherModel.getWorkerLooper());

    mActivityBgColor = context.getResources().getColor(R.color.quantum_panel_bg_color);
    TypedArray ta = context.obtainStyledAttributes(new int[]{R.attr.colorSecondary});
    mPackageBgColor = ta.getColor(0, 0);
    ta.recycle();
    mLowResOptions = new BitmapFactory.Options();
    // Always prefer RGB_565 config for low res. If the bitmap has transparency, it will
    // automatically be loaded as ALPHA_8888.
    mLowResOptions.inPreferredConfig = Bitmap.Config.RGB_565;
}
 
Example 2
Project: timelineview   File: TimeLineView.java   View Source Code Vote up 6 votes
private void initAttrs(AttributeSet paramAttributeSet) {
    if (paramAttributeSet != null) {
        TypedArray typedArray = getContext().obtainStyledAttributes(paramAttributeSet, R.styleable.TimeLineView);
        mStartedLineColor = typedArray.getColor(R.styleable.TimeLineView_startedLineColor, Color.BLUE);
        mPreLineColor = typedArray.getColor(R.styleable.TimeLineView_preLineColor, Color.GRAY);

        mStartedCircleColor = typedArray.getColor(R.styleable.TimeLineView_startedCircleColor, Color.BLUE);
        mUnderwayCircleColor = typedArray.getColor(R.styleable.TimeLineView_underwayCircleColor, Color.BLUE);
        mPreCircleColor = typedArray.getColor(R.styleable.TimeLineView_preCircleColor, Color.GRAY);

        mStartedStringColor = typedArray.getColor(R.styleable.TimeLineView_startedStringColor, Color.BLUE);
        mUnderwayStringColor = typedArray.getColor(R.styleable.TimeLineView_underwayStringColor, Color.BLUE);
        mPreStringColor = typedArray.getColor(R.styleable.TimeLineView_preStringColor, Color.GRAY);
        mTextSize = typedArray.getDimension(R.styleable.TimeLineView_textSize, 20);
        mRadius = (int) typedArray.getDimension(R.styleable.TimeLineView_radius, 10);
        mLineWidth = typedArray.getDimension(R.styleable.TimeLineView_lineWidth, 5);
        typedArray.recycle();
    }
}
 
Example 3
Project: bubble-layout   File: CircleImageView.java   View Source Code Vote up 6 votes
public CircleImageView(Context c, AttributeSet attrs, int defStyleAttr) {
    super(c, attrs, defStyleAttr);
    DisplayMetrics dm = getResources().getDisplayMetrics();

    // Set XML attributes
    TypedArray a = c.obtainStyledAttributes(attrs, R.styleable.CircleImageView);
    this.borderWidth = a.getDimensionPixelSize(R.styleable.CircleImageView_borderWidth, (int)(1f * dm.density)); // 1dp
    this.borderColor = a.getColor(R.styleable.CircleImageView_borderColor, ContextCompat.getColor(c, R.color.default_circle_border_color));
    this.backColor = a.getColor(R.styleable.CircleImageView_circleColor, ContextCompat.getColor(c, R.color.default_circle_text_color));
    a.recycle();

    // Setup border paint
    this.borderPaint.setStyle(Paint.Style.FILL);
    this.borderPaint.setColor(borderColor);

    // Setup main paint
    this.mainPaint.setColor(ContextCompat.getColor(c, R.color.default_circle_text_color));
    this.mainPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
}
 
Example 4
Project: VirtualHook   File: LoadingIndicatorView.java   View Source Code Vote up 6 votes
private void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    mMinWidth = 24;
    mMaxWidth = 48;
    mMinHeight = 24;
    mMaxHeight = 48;

    final TypedArray a = context.obtainStyledAttributes(
            attrs, R.styleable.LoadingIndicatorView, defStyleAttr, defStyleRes);

    mMinWidth = a.getDimensionPixelSize(R.styleable.LoadingIndicatorView_minWidth, mMinWidth);
    mMaxWidth = a.getDimensionPixelSize(R.styleable.LoadingIndicatorView_maxWidth, mMaxWidth);
    mMinHeight = a.getDimensionPixelSize(R.styleable.LoadingIndicatorView_minHeight, mMinHeight);
    mMaxHeight = a.getDimensionPixelSize(R.styleable.LoadingIndicatorView_maxHeight, mMaxHeight);
    String indicatorName = a.getString(R.styleable.LoadingIndicatorView_indicatorName);
    mIndicatorColor = a.getColor(R.styleable.LoadingIndicatorView_indicatorColor, Color.WHITE);
    setIndicator(indicatorName);
    if (mIndicator == null) {
        setIndicator(DEFAULT_INDICATOR);
    }
    a.recycle();
}
 
Example 5
Project: WaveLineView   File: WaveLineView.java   View Source Code Vote up 6 votes
private void initAttr(AttributeSet attrs) {
    TypedArray t = getContext().obtainStyledAttributes(attrs,R.styleable.WaveLineView);
    backGroundColor = t.getColor(R.styleable.WaveLineView_wlvBackgroundColor, Color.WHITE);
    samplingSize = t.getInt(R.styleable.WaveLineView_wlvSamplingSize, DEFAULT_SAMPLING_SIZE);
    lineColor = t.getColor(R.styleable.WaveLineView_wlvLineColor, Color.parseColor("#2ED184"));
    thickLineWidth = (int)t.getDimension(R.styleable.WaveLineView_wlvThickLineWidth, 6);
    fineLineWidth = (int)t.getDimension(R.styleable.WaveLineView_wlvFineLineWidth, 2);
    offsetSpeed = t.getFloat(R.styleable.WaveLineView_wlvMoveSpeed, DEFAULT_OFFSET_SPEED);
    sensibility = t.getInt(R.styleable.WaveLineView_wlvSensibility, DEFAULT_SENSIBILITY);
    isTransparentMode = backGroundColor == Color.TRANSPARENT;
    t.recycle();
    checkVolumeValue();
    checkSensibilityValue();
    //将RenderView放到最顶层
    setZOrderOnTop(true);
    if (getHolder() != null) {
        //使窗口支持透明度
        getHolder().setFormat(PixelFormat.TRANSLUCENT);
    }
}
 
Example 6
Project: JKApp   File: MLImageView.java   View Source Code Vote up 5 votes
private void init(Context context, AttributeSet attrs) {
    //初始化默认值
    mPressAlpha = 64;
    mPressColor = getResources().getColor(R.color.ml_gray);
    mRadius = 16;
    mShapeType = 1;
    mBorderWidth = 0;
    mBorderColor = getResources().getColor(R.color.ml_red);

    // 获取控件的属性值
    if (attrs != null) {
        TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.MLImageView);
        mPressColor = array.getColor(R.styleable.MLImageView_press_color, mPressColor);
        mPressAlpha = array.getInteger(R.styleable.MLImageView_press_alpha, mPressAlpha);
        mRadius = array.getDimensionPixelSize(R.styleable.MLImageView_radius, mRadius);
        mShapeType = array.getInteger(R.styleable.MLImageView_shape_type, mShapeType);
        mBorderWidth = array.getDimensionPixelOffset(R.styleable.MLImageView_border_width, mBorderWidth);
        mBorderColor = array.getColor(R.styleable.MLImageView_border_color, mBorderColor);
        array.recycle();
    }

    // 按下的画笔设置
    mPressPaint = new Paint();
    mPressPaint.setAntiAlias(true);
    mPressPaint.setStyle(Paint.Style.FILL);
    mPressPaint.setColor(mPressColor);
    mPressPaint.setAlpha(0);
    mPressPaint.setFlags(Paint.ANTI_ALIAS_FLAG);

    setClickable(true);
    setDrawingCacheEnabled(true);
    setWillNotDraw(false);
}
 
Example 7
Project: FakeWeather   File: StationIndicator.java   View Source Code Vote up 5 votes
public StationIndicator(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    paint = new Paint();
    TypedArray mTypedArray = context.obtainStyledAttributes(attrs, R.styleable.IndicatorItem);
    color = mTypedArray.getColor(R.styleable.IndicatorItem_indicatorColor, ThemeUtil.getThemeColor(context, R.attr.colorPrimary));
    roundWidth = mTypedArray.getDimension(R.styleable.IndicatorItem_indicatorRingWidth, SizeUtils.dp2px(context, 3));
    isChecked = mTypedArray.getBoolean(R.styleable.IndicatorItem_indicatorChecked, false);
    innerCircle = mTypedArray.getDimension(R.styleable.IndicatorItem_indicatorInnerCircle, SizeUtils.dp2px(context, 4));
    mTypedArray.recycle();

}
 
Example 8
Project: OpenHub   File: CodeWebView.java   View Source Code Vote up 5 votes
@SuppressLint("SetJavaScriptEnabled")
private void init(AttributeSet attrs) {
    if (attrs != null) {
        TypedArray tp = getContext().obtainStyledAttributes(attrs, R.styleable.CodeWebView);
        try {
            backgroundColor = tp.getColor(R.styleable.CodeWebView_webview_background,
                    ViewUtils.getWindowBackground(getContext()));
            setBackgroundColor(backgroundColor);
        } finally {
            tp.recycle();
        }
    }

    setWebChromeClient(new ChromeClient());
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        setWebViewClient(new WebClientN());
    } else {
        setWebViewClient(new WebClient());
    }
    WebSettings settings = getSettings();
    settings.setJavaScriptEnabled(true);
    settings.setAppCachePath(getContext().getCacheDir().getPath());
    settings.setAppCacheEnabled(true);
    settings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
    settings.setDefaultTextEncodingName("utf-8");
    settings.setLoadsImagesAutomatically(true);
    settings.setBlockNetworkImage(false);
    setOnLongClickListener(new OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            WebView.HitTestResult result = getHitTestResult();
            if (hitLinkResult(result) && !StringUtils.isBlank(result.getExtra())) {
                AppUtils.copyToClipboard(getContext(), result.getExtra());
                return true;
            }
            return false;
        }
    });
}
 
Example 9
Project: BiColorView   File: TriangleView.java   View Source Code Vote up 5 votes
private void init(AttributeSet attrs) {
    if (attrs != null) {
        TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.TriangleView);
        switch (a.getInt(R.styleable.TriangleView_tr_direction, 0)) {
            case 0:
                mDirection = Direction.LEFT;
                break;
            case 1:
                mDirection = Direction.UP;
                break;
            case 2:
                mDirection = Direction.RIGHT;
                break;
            case 3:
            default:
                mDirection = Direction.DOWN;
        }
        mColor = a.getColor(R.styleable.TriangleView_tr_color, DEFAULT_COLOR);
        a.recycle();
    } else {
        mDirection = DEFAULT_DIRECTION;
        mColor = DEFAULT_COLOR;
    }

    mPaint = new Paint();
    mPaint.setStyle(Paint.Style.FILL);
    mPaint.setColor(mColor);
    mPaint.setAntiAlias(true);

    LinearLayout.LayoutParams llParams = new LinearLayout.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    int margin = (int) getResources().getDimension(R.dimen._minus5sdp);

    // setPadding(margin, margin, margin, margin);
    llParams.setMargins(margin, margin, margin, margin);
    setLayoutParams(llParams);
}
 
Example 10
Project: simple-share-android   File: NumberProgressBar.java   View Source Code Vote up 5 votes
public NumberProgressBar(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    mContext = context;

    default_reached_bar_height = dp2px(10.5f);
    default_unreached_bar_height = dp2px(10.0f);
    default_text_size = sp2px(10);
    default_progress_text_offset = dp2px(3.0f);

    //load styled attributes.
    final TypedArray attributes = context.getTheme().obtainStyledAttributes(attrs, R.styleable.NumberProgressBar,
            defStyleAttr, 0);

    mReachedBarColor = attributes.getColor(R.styleable.NumberProgressBar_progress_reached_color, default_reached_color);
    mUnreachedBarColor = attributes.getColor(R.styleable.NumberProgressBar_progress_unreached_color,default_unreached_color);
    mTextColor = attributes.getColor(R.styleable.NumberProgressBar_progress_text_color,default_text_color);
    mTextSize = attributes.getDimension(R.styleable.NumberProgressBar_progress_text_size, default_text_size);

    mReachedBarHeight = attributes.getDimension(R.styleable.NumberProgressBar_progress_reached_bar_height,default_reached_bar_height);
    mUnreachedBarHeight = attributes.getDimension(R.styleable.NumberProgressBar_progress_unreached_bar_height,default_unreached_bar_height);
    mOffset = attributes.getDimension(R.styleable.NumberProgressBar_progress_text_offset,default_progress_text_offset);

    int textVisible = attributes.getInt(R.styleable.NumberProgressBar_progress_text_visibility,PROGRESS_TEXT_VISIBLE);
    if(textVisible != PROGRESS_TEXT_VISIBLE){
        mIfDrawText = false;
    }

    setProgress(attributes.getInt(R.styleable.NumberProgressBar_progress,0));
    setMax(attributes.getInt(R.styleable.NumberProgressBar_max, 100));
    //
    attributes.recycle();

    initializePainters();

}
 
Example 11
Project: GitHub   File: FloatingActionsMenu.java   View Source Code Vote up 5 votes
private void init(Context context, AttributeSet attributeSet) {
    mAddButtonPlusColor = getColor(android.R.color.white);
    mAddButtonColorNormal = getColor(android.R.color.holo_blue_dark);
    mAddButtonColorPressed = getColor(android.R.color.holo_blue_light);

    mButtonSpacing = (int) (getResources().getDimension(R.dimen.fab_actions_spacing) - getResources().getDimension(R.dimen.fab_shadow_radius) - getResources().getDimension(R.dimen.fab_shadow_offset));

    if (attributeSet != null) {
        TypedArray attr = context.obtainStyledAttributes(attributeSet, R.styleable.FloatingActionsMenu, 0, 0);
        if (attr != null) {
            try {
                mAddButtonPlusColor = attr.getColor(R.styleable.FloatingActionsMenu_addButtonPlusIconColor, getColor(android.R.color.white));
                mAddButtonColorNormal = attr.getColor(R.styleable.FloatingActionsMenu_addButtonColorNormal, getColor(android.R.color.holo_blue_dark));
                mAddButtonColorPressed = attr.getColor(R.styleable.FloatingActionsMenu_addButtonColorPressed, getColor(android.R.color.holo_blue_light));
                isHorizontal = attr.getBoolean(R.styleable.FloatingActionsMenu_addButtonIsHorizontal, false);
            } finally {
                attr.recycle();
            }
        }
    }
    WindowManager mWindowManager = (WindowManager)
            context.getSystemService(Context.WINDOW_SERVICE);
    Display display = mWindowManager.getDefaultDisplay();
    Point size = new Point();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
        display.getSize(size);
        mYHidden = size.y;
    } else mYHidden = display.getHeight();

    createAddButton(context);
}
 
Example 12
Project: JSSample   File: SLoading.java   View Source Code Vote up 5 votes
private void obtainData(AttributeSet attrs) {
    TypedArray a=getContext().obtainStyledAttributes(attrs, R.styleable.SLoading);
    radius=a.getDimension(R.styleable.SLoading_sradius,-1);
    gap=a.getDimension(R.styleable.SLoading_sgap,-1);
    num=a.getInt(R.styleable.SLoading_snum,-1);
    color=a.getColor(R.styleable.SLoading_scolor,0xff4070);
    a.recycle();
}
 
Example 13
Project: QiangHongBao   File: ResourcesUtils.java   View Source Code Vote up 5 votes
public static int[] getValueOfColorAttr(Context context, int defaultColor, int... attrs) {
    if (attrs.length == 0) {
        return attrs;
    }
    int[] colors = new int[attrs.length];
    TypedArray array = context.obtainStyledAttributes(attrs);
    for (int i = 0; i < attrs.length; i++) {
        colors[i] = array.getColor(i, defaultColor);
    }
    array.recycle();
    return colors;
}
 
Example 14
Project: SmartChart   File: WaveView.java   View Source Code Vote up 5 votes
public WaveView(Context context, AttributeSet attrs) {
    super(context, attrs);
    setOrientation(VERTICAL);
    //load styled attributes.
    final TypedArray attributes = context.getTheme().obtainStyledAttributes(attrs, R.styleable.WaveView, R.attr.waveViewStyle, 0);
    mAboveWaveColor = attributes.getColor(R.styleable.WaveView_above_wave_color, DEFAULT_ABOVE_WAVE_COLOR);
    mBlowWaveColor = attributes.getColor(R.styleable.WaveView_blow_wave_color, DEFAULT_BLOW_WAVE_COLOR);
    mProgress = attributes.getInt(R.styleable.WaveView_progress, DEFAULT_PROGRESS);
    mWaveHeight = attributes.getInt(R.styleable.WaveView_wave_height, MIDDLE);
    mWaveMultiple = attributes.getInt(R.styleable.WaveView_wave_length, LARGE);
    mWaveHz = attributes.getInt(R.styleable.WaveView_wave_hz, MIDDLE);
    attributes.recycle();

    mWave = new Wave(context, null);
    mWave.initializeWaveSize(mWaveMultiple, mWaveHeight, mWaveHz);
    mWave.setAboveWaveColor(mAboveWaveColor);
    mWave.setBlowWaveColor(mBlowWaveColor);
    mWave.initializePainters();

    mSolid = new Solid(context, null);
    mSolid.setAboveWavePaint(mWave.getAboveWavePaint());
    mSolid.setBlowWavePaint(mWave.getBlowWavePaint());

    addView(mWave);
    addView(mSolid);

    setProgress(mProgress);
}
 
Example 15
Project: Hitalk   File: CommentListView.java   View Source Code Vote up 5 votes
protected void initAttrs(AttributeSet attrs) {
    TypedArray typedArray = getContext().getTheme().obtainStyledAttributes(attrs, R.styleable.PraiseListView, 0, 0);
    try {
        //textview的默认颜色
        itemColor = typedArray.getColor(R.styleable.PraiseListView_item_color, getResources().getColor(R.color.praise_item_default));
        itemSelectorColor = typedArray.getColor(R.styleable.PraiseListView_item_selector_color, getResources().getColor(R.color.praise_item_selector_default));

    }finally {
        typedArray.recycle();
    }
}
 
Example 16
Project: hsv-alpha-color-picker   File: ColorPreference.java   View Source Code Vote up 5 votes
@Override
protected Object onGetDefaultValue(TypedArray a, int index) {
	if (a.peekValue(index) != null && a.peekValue(index).type == TypedValue.TYPE_STRING) {
		defaultColor = Color.parseColor(standardiseColorDigits(a.getString(index)));
	}
	else {
		defaultColor = a.getColor(index, Color.GRAY);
	}
	return defaultColor;
}
 
Example 17
Project: androidShader_rippleView_radarView   File: RadarView.java   View Source Code Vote up 5 votes
public void init(Context context, AttributeSet attrs){
    if (attrs != null){
        TypedArray ta = context.obtainStyledAttributes(attrs,R.styleable.RadarView);
        mRadarBackGroundColor = ta.getColor(R.styleable.RadarView_mRadarBackGroundColor,mRadarBackGroundColor);
        mRadarStartColor = ta.getColor(R.styleable.RadarView_mRadarStartColor,mRadarStartColor);
        mRadarEndColor = ta.getColor(R.styleable.RadarView_mRadarEndColor,mRadarEndColor);
        mRadarCircleColor = ta.getColor(R.styleable.RadarView_mRadarCircleColor,mRadarCircleColor);
        mRadarCircleNum = ta.getInteger(R.styleable.RadarView_mRadarCircleNum,mRadarCircleNum);
        ta.recycle();

    }

}
 
Example 18
Project: QiangHongBao   File: MaterialRippleLayout.java   View Source Code Vote up 5 votes
public MaterialRippleLayout(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    setWillNotDraw(false);
    gestureDetector = new GestureDetector(context, longClickListener);

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.MaterialRippleLayout);
    rippleColor = a.getColor(R.styleable.MaterialRippleLayout_mrl_rippleColor, DEFAULT_COLOR);
    rippleDiameter = a.getDimensionPixelSize(
        R.styleable.MaterialRippleLayout_mrl_rippleDimension,
        (int) dpToPx(getResources(), DEFAULT_DIAMETER_DP)
    );
    rippleOverlay = a.getBoolean(R.styleable.MaterialRippleLayout_mrl_rippleOverlay, DEFAULT_RIPPLE_OVERLAY);
    rippleHover = a.getBoolean(R.styleable.MaterialRippleLayout_mrl_rippleHover, DEFAULT_HOVER);
    rippleDuration = a.getInt(R.styleable.MaterialRippleLayout_mrl_rippleDuration, DEFAULT_DURATION);
    rippleAlpha = (int) (255 * a.getFloat(R.styleable.MaterialRippleLayout_mrl_rippleAlpha, DEFAULT_ALPHA));
    rippleDelayClick = a.getBoolean(R.styleable.MaterialRippleLayout_mrl_rippleDelayClick, DEFAULT_DELAY_CLICK);
    rippleFadeDuration = a.getInteger(R.styleable.MaterialRippleLayout_mrl_rippleFadeDuration, DEFAULT_FADE_DURATION);
    rippleBackground = new ColorDrawable(a.getColor(R.styleable.MaterialRippleLayout_mrl_rippleBackground, DEFAULT_BACKGROUND));
    ripplePersistent = a.getBoolean(R.styleable.MaterialRippleLayout_mrl_ripplePersistent, DEFAULT_PERSISTENT);
    rippleInAdapter = a.getBoolean(R.styleable.MaterialRippleLayout_mrl_rippleInAdapter, DEFAULT_SEARCH_ADAPTER);
    rippleRoundedCorners = a.getDimensionPixelSize(R.styleable.MaterialRippleLayout_mrl_rippleRoundedCorners, DEFAULT_ROUNDED_CORNERS);

    a.recycle();

    paint.setColor(rippleColor);
    paint.setAlpha(rippleAlpha);

    enableClipPathSupportIfNecessary();
}
 
Example 19
Project: ShadowKit-Android   File: ShadowLayout.java   View Source Code Vote up 5 votes
public ShadowLayout(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);

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

    try {
        mShadowDx = a.getDimensionPixelSize(R.styleable.ShadowLayout_skShadowDx, DEFAULT_SHADOW_DX);
        mShadowDy = a.getDimensionPixelSize(R.styleable.ShadowLayout_skShadowDy, DEFAULT_SHADOW_DY);
        mShadowColor = a.getColor(R.styleable.ShadowLayout_skShadowColor, DEFAULT_SHADOW_COLOR);
        mShadowAlpha = a.getFloat(R.styleable.ShadowLayout_skShadowAlpha, DEFAULT_SHADOW_ALPHA);
        mShadowRadius = a.getInteger(R.styleable.ShadowLayout_skShadowRadius, DEFAULT_SHADOW_RADIUS);
        mShadowScale = a.getFloat(R.styleable.ShadowLayout_skShadowScale, DEFAULT_SHADOW_SCALE);
        mReuseKey = a.getString(R.styleable.ShadowLayout_skReuseKey);
    } finally {
        a.recycle();
    }

    mImageView = new ImageView(context);
    mImageView.setLayoutParams(new FrameLayout.LayoutParams(0, 0));
    mImageView.setScaleType(ImageView.ScaleType.FIT_XY);
    addView(mImageView);

    setShadowDx(mShadowDx);
    setShadowDy(mShadowDy);
    setShadowColor(mShadowColor);
    setShadowAlpha(mShadowAlpha);
    setShadowRadius(mShadowRadius);
    setShadowScale(mShadowScale);

    getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            getViewTreeObserver().removeOnGlobalLayoutListener(this);
            refresh();
        }
    });
}
 
Example 20
Project: EsperantoRadio   File: PagerSlidingTabStrip.java   View Source Code Vote up 4 votes
public PagerSlidingTabStrip(Context context, AttributeSet attrs, int defStyle) {
  super(context, attrs, defStyle);

  setFillViewport(true);
  setWillNotDraw(false);

  tabsContainer = new LinearLayout(context);
  tabsContainer.setOrientation(LinearLayout.HORIZONTAL);
  tabsContainer.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
  addView(tabsContainer);

  DisplayMetrics dm = getResources().getDisplayMetrics();

  scrollOffset = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, scrollOffset, dm);
  indicatorHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, indicatorHeight, dm);
  underlineHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, underlineHeight, dm);
  dividerPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dividerPadding, dm);
  tabPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, tabPadding, dm);
  dividerWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dividerWidth, dm);
  tabTextSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, tabTextSize, dm);
  minBredde = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, minBredde, dm);

  // get system attrs (android:textSize and android:textColor)

  TypedArray a = context.obtainStyledAttributes(attrs, ATTRS);

  tabTextSize = a.getDimensionPixelSize(0, tabTextSize);
  //noinspection ResourceType
  tabTextColor = a.getColor(1, tabTextColor);

  a.recycle();

  // get custom attrs

  a = context.obtainStyledAttributes(attrs, R.styleable.PagerSlidingTabStrip);

  indicatorColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsIndicatorColor, indicatorColor);
  underlineColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsUnderlineColor, underlineColor);
  dividerColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsDividerColor, dividerColor);
  indicatorHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsIndicatorHeight, indicatorHeight);
  underlineHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsUnderlineHeight, underlineHeight);
  dividerPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsDividerPadding, dividerPadding);
  tabPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsTabPaddingLeftRight, tabPadding);
  tabBackgroundResId = a.getResourceId(R.styleable.PagerSlidingTabStrip_pstsTabBackground, tabBackgroundResId);
  shouldExpand = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsShouldExpand, shouldExpand);
  scrollOffset = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsScrollOffset, scrollOffset);
  textAllCaps = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsTextAllCaps, textAllCaps);

  a.recycle();

  rectPaint = new Paint();
  rectPaint.setAntiAlias(true);
  rectPaint.setStyle(Style.FILL);

  dividerPaint = new Paint();
  dividerPaint.setAntiAlias(true);
  dividerPaint.setStrokeWidth(dividerWidth);

  defaultTabLayoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
  expandedTabLayoutParams = new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT, 1.0f);

  if (locale == null) {
    locale = getResources().getConfiguration().locale;
  }
}