Example usage for android.content Context getTheme

List of usage examples for android.content Context getTheme

Introduction

In this page you can find the example usage for android.content Context getTheme.

Prototype

@ViewDebug.ExportedProperty(deepExport = true)
public abstract Resources.Theme getTheme();

Source Link

Document

Return the Theme object associated with this Context.

Usage

From source file:com.libs.golomb.extendedrecyclerview.Scroller.FastScroller2.java

public FastScroller2(Context context, FastScrollRecyclerView2 recyclerView, AttributeSet attrs) {

    Resources resources = context.getResources();

    mRecyclerView = recyclerView;/*  w w  w . j  a v  a 2  s  .c  o m*/
    mPopup = new FastScrollPopup2(resources, recyclerView);

    mThumbHeight = Utils.toPixels(resources, 48);
    mWidth = Utils.toPixels(resources, 8);

    mTouchInset = Utils.toPixels(resources, -24);

    mThumb = new Paint(Paint.ANTI_ALIAS_FLAG);
    mTrack = new Paint(Paint.ANTI_ALIAS_FLAG);

    TypedArray typedArray = context.getTheme().obtainStyledAttributes(attrs, R.styleable.FastScrollRecyclerView,
            0, 0);
    try {
        mAutoHideEnabled = typedArray.getBoolean(R.styleable.FastScrollRecyclerView_fastScrollAutoHide, true);
        mAutoHideDelay = typedArray.getInteger(R.styleable.FastScrollRecyclerView_fastScrollAutoHideDelay,
                DEFAULT_AUTO_HIDE_DELAY);

        int trackColor = typedArray.getColor(R.styleable.FastScrollRecyclerView_fastScrollTrackColor,
                0x1f000000);
        int thumbColor = typedArray.getColor(R.styleable.FastScrollRecyclerView_fastScrollThumbColor,
                0xff000000);
        int popupBgColor = typedArray.getColor(R.styleable.FastScrollRecyclerView_fastScrollPopupBgColor,
                0xff000000);
        int popupTextColor = typedArray.getColor(R.styleable.FastScrollRecyclerView_fastScrollPopupTextColor,
                0xffffffff);
        int popupTextSize = typedArray.getDimensionPixelSize(
                R.styleable.FastScrollRecyclerView_fastScrollPopupTextSize,
                Utils.toScreenPixels(resources, 56));
        int popupBackgroundSize = typedArray.getDimensionPixelSize(
                R.styleable.FastScrollRecyclerView_fastScrollPopupBackgroundSize,
                Utils.toPixels(resources, 88));

        mTrack.setColor(trackColor);
        mThumb.setColor(thumbColor);
        mPopup.setBgColor(popupBgColor);
        mPopup.setTextColor(popupTextColor);
        mPopup.setTextSize(popupTextSize);
        mPopup.setBackgroundSize(popupBackgroundSize);
    } finally {
        typedArray.recycle();
    }

    mHideRunnable = new Runnable() {
        @Override
        public void run() {
            if (!mIsDragging) {
                if (mAutoHideAnimator != null) {
                    mAutoHideAnimator.cancel();
                }
                mAutoHideAnimator = ObjectAnimator.ofInt(FastScroller2.this, "offsetX",
                        (Utils.isRtl(mRecyclerView.getResources()) ? -1 : 1) * mWidth);
                mAutoHideAnimator.setInterpolator(new FastOutLinearInInterpolator());
                mAutoHideAnimator.setDuration(200);
                mAutoHideAnimator.start();
            }
        }
    };

    mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            //TODO
            Log.d("TGolomb", "onScrolled: " + scrollY.addAndGet(dy));
            show();
        }
    });

    if (mAutoHideEnabled) {
        postAutoHideDelayed();
    }
}

From source file:com.appunite.list.FastScroller.java

private void init(Context context) {
    // Get both the scrollbar states drawables
    TypedArray ta = context.getTheme().obtainStyledAttributes(ATTRS);
    useThumbDrawable(context, ta.getDrawable(THUMB_DRAWABLE));
    mTrackDrawable = ta.getDrawable(TRACK_DRAWABLE);

    mOverlayDrawableLeft = ta.getDrawable(PREVIEW_BACKGROUND_LEFT);
    mOverlayDrawableRight = ta.getDrawable(PREVIEW_BACKGROUND_RIGHT);
    mOverlayPosition = ta.getInt(OVERLAY_POSITION, OVERLAY_FLOATING);

    mScrollCompleted = true;// w  w  w .j ava  2 s . co m

    getSectionsFromIndexer();

    mOverlaySize = context.getResources().getDimensionPixelSize(R.dimen.fastscroll_overlay_size);
    mOverlayPos = new RectF();
    mScrollFade = new ScrollFade();
    mPaint = new Paint();
    mPaint.setAntiAlias(true);
    mPaint.setTextAlign(Paint.Align.CENTER);
    mPaint.setTextSize(mOverlaySize / 2);

    ColorStateList textColor = ta.getColorStateList(TEXT_COLOR);
    int textColorNormal = textColor.getDefaultColor();
    mPaint.setColor(textColorNormal);
    mPaint.setStyle(Paint.Style.FILL_AND_STROKE);

    // to show mOverlayDrawable properly
    if (mList.getWidth() > 0 && mList.getHeight() > 0) {
        onSizeChanged(mList.getWidth(), mList.getHeight(), 0, 0);
    }

    mState = STATE_NONE;
    refreshDrawableState();

    ta.recycle();

    mScaledTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();

    mMatchDragPosition = context
            .getApplicationInfo().targetSdkVersion >= android.os.Build.VERSION_CODES.HONEYCOMB;

    setScrollbarPosition(Compat.getVerticalScrollbarPosition(mList));
}

From source file:com.common.widget.hzlib.FastScroller.java

private void init(Context context) {
    // Get both the scrollbar states drawables
    TypedArray ta = context.getTheme().obtainStyledAttributes(ATTRS);
    useThumbDrawable(context, ta.getDrawable(THUMB_DRAWABLE));
    mTrackDrawable = ta.getDrawable(TRACK_DRAWABLE);

    mOverlayDrawableLeft = ta.getDrawable(PREVIEW_BACKGROUND_LEFT);
    mOverlayDrawableRight = ta.getDrawable(PREVIEW_BACKGROUND_RIGHT);
    mOverlayPosition = ta.getInt(OVERLAY_POSITION, OVERLAY_FLOATING);

    mScrollCompleted = true;//  w  w w . j  a v  a2  s . c o m

    getSectionsFromIndexer();

    mOverlaySize = context.getResources().getDimensionPixelSize(R.dimen.fastscroll_overlay_size);
    mOverlayPos = new RectF();
    mScrollFade = new ScrollFade();
    mPaint = new Paint();
    mPaint.setAntiAlias(true);
    mPaint.setTextAlign(Paint.Align.CENTER);
    mPaint.setTextSize(mOverlaySize / 2);

    ColorStateList textColor = ta.getColorStateList(TEXT_COLOR);
    int textColorNormal = textColor.getDefaultColor();
    mPaint.setColor(textColorNormal);
    mPaint.setStyle(Paint.Style.FILL_AND_STROKE);

    // to show mOverlayDrawable properly
    if (mList.getWidth() > 0 && mList.getHeight() > 0) {
        onSizeChanged(mList.getWidth(), mList.getHeight(), 0, 0);
    }

    mState = STATE_NONE;
    refreshDrawableState();

    ta.recycle();

    mScaledTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();

    mMatchDragPosition = context
            .getApplicationInfo().targetSdkVersion >= android.os.Build.VERSION_CODES.HONEYCOMB;

    setScrollbarPosition(mList.getVerticalScrollbarPosition());
}

From source file:com.dirkgassen.wator.ui.view.RangeSlider.java

/**
 * Constructor that is called when inflating a view from XML.
 * This is called when a view is being constructed from an XML file, supplying attributes that were specified in the
 * XML file. This version uses a default style of 0, so the only attribute values applied are those in the Context's
 * Theme and the given AttributeSet./*ww  w.jav  a2 s  .c om*/
 *
 * @param context context the view is running in, through which it can access the current theme, resources, etc.
 * @param attrs   the attributes of the XML tag that is inflating the vie
 */
public RangeSlider(Context context, AttributeSet attrs) {
    super(context, attrs);

    thumbPath.setFillType(Path.FillType.EVEN_ODD);
    displayDensity = getResources().getDisplayMetrics().density;

    TypedArray attributeArray = context.getTheme().obtainStyledAttributes(attrs, R.styleable.RangeSlider, 0, 0);
    try {
        setupAttributes(attributeArray);
    } finally {
        attributeArray.recycle();
    }

    calculateThumbSize();
}

From source file:com.melodigm.post.widget.swipelayout.SwipeRevealLayout.java

private void init(Context context, AttributeSet attrs) {
    if (attrs != null && context != null) {
        TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.SwipeRevealLayout, 0, 0);

        mDragEdge = a.getInteger(R.styleable.SwipeRevealLayout_dragEdge, DRAG_EDGE_LEFT);
        mMinFlingVelocity = a.getInteger(R.styleable.SwipeRevealLayout_flingVelocity,
                DEFAULT_MIN_FLING_VELOCITY);
        mMode = a.getInteger(R.styleable.SwipeRevealLayout_swipeMode, MODE_NORMAL);
    }/*from ww w  .  j  av a2s .  c  om*/

    mDragHelper = ViewDragHelper.create(this, 1.0f, mDragHelperCallback);
    mDragHelper.setEdgeTrackingEnabled(ViewDragHelper.EDGE_ALL);

    mGestureDetector = new GestureDetectorCompat(context, mGestureListener);
}

From source file:com.center.mycode.view.swipelayout.SwipeRevealLayout.java

private void init(Context context, AttributeSet attrs) {
    if (attrs != null && context != null) {
        TypedArray a = context.getTheme().obtainStyledAttributes(attrs,
                com.center.mycode.R.styleable.SwipeRevealLayout, 0, 0);

        mDragEdge = a.getInteger(com.center.mycode.R.styleable.SwipeRevealLayout_dragEdge, DRAG_EDGE_LEFT);
        mMinFlingVelocity = a.getInteger(com.center.mycode.R.styleable.SwipeRevealLayout_flingVelocity,
                DEFAULT_MIN_FLING_VELOCITY);
        mMode = a.getInteger(com.center.mycode.R.styleable.SwipeRevealLayout_mode, MODE_NORMAL);
    }// w w  w. j ava 2s .c o  m

    mDragHelper = ViewDragHelper.create(this, 1.0f, mDragHelperCallback);
    mDragHelper.setEdgeTrackingEnabled(ViewDragHelper.EDGE_ALL);

    mGestureDetector = new GestureDetectorCompat(context, mGestureListener);
}

From source file:im.ene.toro.exoplayer2.ExoVideoView.java

public ExoVideoView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    // By default, TextureView is used for Android 23 and below, and SurfaceView is for the rest
    boolean useTextureView = context.getResources().getBoolean(R.bool.use_texture_view);
    if (attrs != null) {
        TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.ExoVideoView, 0, 0);
        try {//from w w w.ja  va 2  s  .  c  o m
            int surfaceType = a.getInt(R.styleable.ExoVideoView_tx2_surfaceType, SURFACE_TYPE_DEFAULT);
            switch (surfaceType) {
            case SURFACE_TYPE_SURFACE_VIEW:
                useTextureView = false;
                break;
            case SURFACE_TYPE_TEXTURE_VIEW:
                useTextureView = true;
                break;
            case SURFACE_TYPE_DEFAULT:
            default:
                // Unchanged, so don't need to execute the line below
                // useTextureView = context.getResources().getBoolean(R.bool.use_texture_view);
                break;
            }

            resizeMode = a.getInt(R.styleable.ExoVideoView_tx2_resizeMode, RESIZE_MODE_FIXED_WIDTH);
        } finally {
            a.recycle();
        }
    }

    View view = useTextureView ? new TextureView(context) : new SurfaceView(context);
    ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT);
    view.setLayoutParams(params);
    surfaceView = view;
    addView(surfaceView, 0);

    shutterView = new View(context);
    ViewGroup.LayoutParams shutterViewParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT);
    shutterView.setLayoutParams(shutterViewParams);
    shutterView.setBackgroundColor(Color.BLACK);
    addView(shutterView);

    window = new Timeline.Window();

    componentListener = new ComponentListener();

    mediaDataSourceFactory = buildDataSourceFactory(true);
    mainHandler = new Handler();

    if (CookieHandler.getDefault() != DEFAULT_COOKIE_MANAGER) {
        CookieHandler.setDefault(DEFAULT_COOKIE_MANAGER);
    }

    requestFocus();
}

From source file:com.dirkgassen.wator.ui.view.RangeSlider.java

/**
 * Perform inflation from XML and apply a class-specific base style from a theme attribute or style resource.
 * This constructor of View allows subclasses to use their own base style when they are inflating.
 *
 * When determining the final value of a particular attribute, there are four inputs that come into play:
 * <ul>//from ww  w. ja  v  a2 s  .  c  o  m
 *   <li>Any attribute values in the given AttributeSet.</li>
 *   <li>The style resource specified in the {@code AttributeSet} (named "style").</li>
 *   <li>The default style specified by {@code defStyleAttr}.</li>
 *   <li>he default style specified by {@code defStyleRes}.</li>T
 *   <li>The base values in this theme.</li>
 * </ul>
 *
 * Each of these inputs is considered in-order, with the first listed taking precedence over the following ones.
 *
 * @param context      context the view is running in, through which it can access the current theme, resources, etc.
 * @param attrs        the attributes of the XML tag that is inflating the vie
 * @param defStyleAttr An attribute in the current theme that contains a reference to a style resource that supplies
 *                     default values for the view. Can be 0 to not look for defaults.
 * @param defStyleRes  A resource identifier of a style resource that supplies default values for the view, used
 *                     only if {@code defStyleAttr} is 0 or can not be found in the theme. Can be 0 to not look for
 *                     defaults.
 */
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public RangeSlider(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    super(context, attrs, defStyleAttr, defStyleRes);

    thumbPath.setFillType(Path.FillType.EVEN_ODD);
    displayDensity = getResources().getDisplayMetrics().density;

    TypedArray attributeArray = context.getTheme().obtainStyledAttributes(attrs, R.styleable.RangeSlider,
            defStyleAttr, defStyleRes);
    try {
        setupAttributes(attributeArray);
    } finally {
        attributeArray.recycle();
    }

    calculateThumbSize();
}

From source file:de.kuschku.quasseldroid_ng.ui.theme.ThemeUtil.java

public ThemeUtil(@NonNull Context ctx) {
    ContextThemeWrapper themeWrapper = new ContextThemeWrapper(ctx, ctx.getTheme());
    initColors(themeWrapper);/* w w  w.  j a v a2s.  c  o  m*/
    statusDrawables = new StatusDrawables(ctx, res, themeWrapper.getTheme());
    formatter = new DateTimeFormatHelper(ctx);
}

From source file:com.ninghoo.beta17ma27.weydio2.FastScrollView.FastScroller.java

public FastScroller(Context context, FastScrollRecyclerView recyclerView, AttributeSet attrs) {

    Resources resources = context.getResources();

    mRecyclerView = recyclerView;/*  w  w  w. java 2 s  .c om*/
    mPopup = new FastScrollPopup(resources, recyclerView);

    // fast?
    mThumbHeight = Utils.toPixels(resources, 310);
    mWidth = Utils.toPixels(resources, 3);

    // 2???fastscroll
    mTouchInset = Utils.toPixels(resources, -24);

    mThumb = new Paint(Paint.ANTI_ALIAS_FLAG);
    mTrack = new Paint(Paint.ANTI_ALIAS_FLAG);

    TypedArray typedArray = context.getTheme().obtainStyledAttributes(attrs, R.styleable.FastScrollRecyclerView,
            0, 0);
    try {
        mAutoHideEnabled = typedArray.getBoolean(R.styleable.FastScrollRecyclerView_fastScrollAutoHide, true);
        mAutoHideDelay = typedArray.getInteger(R.styleable.FastScrollRecyclerView_fastScrollAutoHideDelay,
                DEFAULT_AUTO_HIDE_DELAY);

        int trackColor = typedArray.getColor(R.styleable.FastScrollRecyclerView_fastScrollTrackColor,
                0x1f000000);
        int thumbColor = typedArray.getColor(R.styleable.FastScrollRecyclerView_fastScrollThumbColor,
                0xff000000);
        int popupBgColor = typedArray.getColor(R.styleable.FastScrollRecyclerView_fastScrollPopupBgColor,
                0xff000000);
        int popupTextColor = typedArray.getColor(R.styleable.FastScrollRecyclerView_fastScrollPopupTextColor,
                0xffffffff);
        int popupTextSize = typedArray.getDimensionPixelSize(
                R.styleable.FastScrollRecyclerView_fastScrollPopupTextSize,
                Utils.toScreenPixels(resources, 56));
        int popupBackgroundSize = typedArray.getDimensionPixelSize(
                R.styleable.FastScrollRecyclerView_fastScrollPopupBackgroundSize,
                Utils.toPixels(resources, 88));

        mTrack.setColor(trackColor);
        mThumb.setColor(thumbColor);
        mPopup.setBgColor(popupBgColor);
        mPopup.setTextColor(popupTextColor);
        mPopup.setTextSize(popupTextSize);
        mPopup.setBackgroundSize(popupBackgroundSize);
    } finally {
        typedArray.recycle();
    }

    mHideRunnable = new Runnable() {
        @Override
        public void run() {
            if (!mIsDragging) {
                if (mAutoHideAnimator != null) {
                    mAutoHideAnimator.cancel();
                }
                mAutoHideAnimator = ObjectAnimator.ofInt(FastScroller.this, "offsetX",
                        (Utils.isRtl(mRecyclerView.getResources()) ? -1 : 1) * mWidth);
                mAutoHideAnimator.setInterpolator(new FastOutLinearInInterpolator());
                // 
                mAutoHideAnimator.setDuration(200);
                mAutoHideAnimator.start();
            }
        }
    };

    mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            super.onScrolled(recyclerView, dx, dy);
            show();
        }
    });

    if (mAutoHideEnabled) {
        postAutoHideDelayed();
    }
}