android.support.annotation.IntRange Java Examples

The following examples show how to use android.support.annotation.IntRange. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: Focus   Author: ihewro   File: StatusBarUtil.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * 设置状态栏颜色
 *
 * @param activity       需要设置的activity
 * @param color          状态栏颜色值
 * @param statusBarAlpha 状态栏透明度
 */

public static void setColor(Activity activity, @ColorInt int color, @IntRange(from = 0, to = 255) int statusBarAlpha) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        activity.getWindow().setStatusBarColor(calculateStatusColor(color, statusBarAlpha));
    } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView();
        View fakeStatusBarView = decorView.findViewById(FAKE_STATUS_BAR_VIEW_ID);
        if (fakeStatusBarView != null) {
            if (fakeStatusBarView.getVisibility() == View.GONE) {
                fakeStatusBarView.setVisibility(View.VISIBLE);
            }
            fakeStatusBarView.setBackgroundColor(calculateStatusColor(color, statusBarAlpha));
        } else {
            decorView.addView(createStatusBarView(activity, color, statusBarAlpha));
        }
        setRootView(activity);
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        activity.getWindow().getDecorView().setSystemUiVisibility(
                View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
    }
}
 
Example #2
Source Project: DanDanPlayForAndroid   Author: xyoye   File: CommonUtils.java    License: MIT License 6 votes vote down vote up
/**
 * 获取加透明度的资源颜色
 */
@ColorInt
public static int getResColor(@IntRange(from = 0, to = 255) int alpha, @ColorRes int colorId) {
    int color = getResColor(colorId);

    int red = Color.red(color);
    int green = Color.green(color);
    int blue = Color.blue(color);

    return Color.argb(alpha, red, green, blue);
}
 
Example #3
Source Project: Android-utils   Author: Shouheng88   File: ImageUtils.java    License: Apache License 2.0 6 votes vote down vote up
private static Bitmap addBorder(final Bitmap src,
                                @IntRange(from = 1) final int borderSize,
                                @ColorInt final int color,
                                final boolean isCircle,
                                final float cornerRadius,
                                final boolean recycle) {
    if (isEmptyBitmap(src)) return null;
    Bitmap ret = recycle ? src : src.copy(src.getConfig(), true);
    int width = ret.getWidth();
    int height = ret.getHeight();
    Canvas canvas = new Canvas(ret);
    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setColor(color);
    paint.setStyle(Paint.Style.STROKE);
    paint.setStrokeWidth(borderSize);
    if (isCircle) {
        float radius = Math.min(width, height) / 2f - borderSize / 2f;
        canvas.drawCircle(width / 2f, height / 2f, radius, paint);
    } else {
        int halfBorderSize = borderSize >> 1;
        RectF rectF = new RectF(halfBorderSize, halfBorderSize,
                width - halfBorderSize, height - halfBorderSize);
        canvas.drawRoundRect(rectF, cornerRadius, cornerRadius, paint);
    }
    return ret;
}
 
Example #4
Source Project: MvpRoute   Author: TLocation   File: RxScheduler.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 倒计时
 *
 * @param view     倒计时所用到的view
 * @param second   倒计时时长  单位 秒
 * @param listener 倒计时回调
 * @param <T>
 * @return Disposable  返回 Disposable  在Activity的onDestroy方法中
 * disposable.dispose() 取消掉  防止内存泄漏
 * @see CountDownListener  回调接口
 */
public static <T extends View> Disposable countDown(final T view, @IntRange(from = 1) final int second, final CountDownListener<T> listener) {
	if (listener == null || second <= 0) return null;
	return Flowable.intervalRange(0, second + 1, 0, 1, TimeUnit.SECONDS).observeOn(AndroidSchedulers.mainThread())
			.doOnNext(new Consumer<Long>() {
				@Override
				public void accept(Long aLong) throws Exception {
					listener.onCountDownProgress(view, (int) (second - aLong));
				}
			}).doOnComplete(new Action() {
				@Override
				public void run() throws Exception {
					listener.onCountDownComplete(view);
				}
			}).doOnSubscribe(new Consumer<Subscription>() {
				@Override
				public void accept(Subscription subscription) throws Exception {
					listener.onBindCountDown(view);
				}
			}).subscribe();

}
 
Example #5
Source Project: v9porn   Author: ForLovelj   File: MainActivity.java    License: MIT License 6 votes vote down vote up
private void doOnFloatingActionButtonClick(@IntRange(from = 0, to = 4) int position) {
    switch (position) {
        case 0:
            showVideoBottomSheet(firstTagsArray.indexOf(firstTabShow));
            break;
        case 1:
            showPictureBottomSheet(secondTagsArray.indexOf(secondTabShow));
            break;
        case 2:
            showForumBottomSheet(0);
            break;
        case 3:

            break;
        case 4:
            break;
        default:
    }
}
 
Example #6
Source Project: RulerView   Author: zjun615   File: TimeRuleView.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 格式化时间 HH:mm:ss
 * @param timeValue 具体时间值
 * @return 格式化后的字符串,eg:3600 to 01:00:00
 */
public static String formatTimeHHmmss(@IntRange(from = 0, to = MAX_TIME_VALUE) int timeValue) {
    int hour = timeValue / 3600;
    int minute = timeValue % 3600 / 60;
    int second = timeValue % 3600 % 60;
    StringBuilder sb = new StringBuilder();

    if (hour < 10) {
        sb.append('0');
    }
    sb.append(hour).append(':');

    if (minute < 10) {
        sb.append('0');
    }
    sb.append(minute);
    sb.append(':');

    if (second < 10) {
        sb.append('0');
    }
    sb.append(second);
    return sb.toString();
}
 
Example #7
Source Project: androidthings-cameraCar   Author: sysolve   File: TwelveBitIntToBitPatternMapper.java    License: Apache License 2.0 6 votes vote down vote up
@Size(value = 4)
private byte[] calculateBitPatternByteArray(@IntRange(from = 0, to = BIGGEST_12_BIT_NUMBER) int twelveBitNumber) {
    List<Boolean> bitPatterns = new ArrayList<>();
    int highest12BitBitMask = 1 << 11;
    for (int i = 0; i < 12; i++) {
        if ((twelveBitNumber & highest12BitBitMask) == highest12BitBitMask){
            bitPatterns.addAll(BIT_PATTERN_FOR_ONE_BIT);
        }
        else{
            bitPatterns.addAll(BIT_PATTERN_FOR_ZERO_BIT);
        }
        twelveBitNumber = twelveBitNumber << 1;
    }
    bitPatterns = removePauseBits(bitPatterns);
    return convertBitPatternsToByteArray(bitPatterns);
}
 
Example #8
Source Project: Focus   Author: ihewro   File: StatusBarUtil.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * 为 DrawerLayout 布局设置状态栏透明
 *
 * @param activity     需要设置的activity
 * @param drawerLayout DrawerLayout
 */
public static void setTranslucentForDrawerLayout(Activity activity, DrawerLayout drawerLayout,
                                                 @IntRange(from = 0, to = 255) int statusBarAlpha) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
        return;
    }
    setTransparentForDrawerLayout(activity, drawerLayout);
    addTranslucentView(activity, statusBarAlpha);
}
 
Example #9
Source Project: Focus   Author: ihewro   File: StatusBarUtil.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * 为 DrawerLayout 布局设置状态栏透明
 *
 * @param activity     需要设置的activity
 * @param drawerLayout DrawerLayout
 */
public static void setTranslucentForDrawerLayout(Activity activity, DrawerLayout drawerLayout,
                                                 @IntRange(from = 0, to = 255) int statusBarAlpha) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
        return;
    }
    setTransparentForDrawerLayout(activity, drawerLayout);
    addTranslucentView(activity, statusBarAlpha);
}
 
Example #10
Source Project: Focus   Author: ihewro   File: StatusBarUtil.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * 为 fragment 头部是 ImageView 的设置状态栏透明
 *
 * @param activity       fragment 对应的 activity
 * @param statusBarAlpha 状态栏透明度
 * @param needOffsetView 需要向下偏移的 View
 */
public static void setTranslucentForImageViewInFragment(Activity activity, @IntRange(from = 0, to = 255) int statusBarAlpha,
                                                        View needOffsetView) {
    setTranslucentForImageView(activity, statusBarAlpha, needOffsetView);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        clearPreviousSetting(activity);
    }
}
 
Example #11
Source Project: star-zone-android   Author: bootsrc   File: PermissionHelper.java    License: Apache License 2.0 5 votes vote down vote up
private void requestPermissionsInternal(final @NonNull String[] permissions, final @IntRange(from = 0) int requestCode) {
    if (getActivity() != null) {
        ActivityCompat.requestPermissions(getActivity(), permissions, requestCode);
    } else if (getFragment() != null) {
        getFragment().requestPermissions(permissions, requestCode);
    }
}
 
Example #12
Source Project: star-zone-android   Author: bootsrc   File: BmobUrlUtil.java    License: Apache License 2.0 5 votes vote down vote up
public static String getThumbImageUrl(String url, @IntRange(from = 1, to = 1000) int scale) {
        // TODO 取消缩略图-2
//        if (StringUtil.noEmpty(url) && (url.endsWith(".jpg") || url.endsWith(".png"))) {
//            return String.format(Locale.getDefault(), scaleThumbImage, url, scale);
//        }
        return url;
    }
 
Example #13
Source Project: FlexItemDecoration   Author: ckrgithub   File: BaseItemDecoration.java    License: Apache License 2.0 5 votes vote down vote up
public BaseItemDecoration subDivider(@IntRange(from = 0) int startIndex, @IntRange(from = 1) int endIndex) {
	int subLen = endIndex - startIndex;
	if (subLen < 0) {
		throw new IndexOutOfBoundsException(startIndex + ">=" + endIndex);
	}
	this.mStartIndex = startIndex;
	this.mEndIndex = endIndex;
	this.isSubDivider = true;
	return this;
}
 
Example #14
Source Project: styT   Author: stytooldex   File: StatusBarUtil.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 为滑动返回界面设置状态栏颜色
 *
 * @param activity       需要设置的activity
 * @param color          状态栏颜色值
 * @param statusBarAlpha 状态栏透明度
 */
private static void setColorForSwipeBack(Activity activity, @ColorInt int color,
                                         @IntRange(from = 0, to = 255) int statusBarAlpha) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {

        ViewGroup contentView = ((ViewGroup) activity.findViewById(android.R.id.content));
        View rootView = contentView.getChildAt(0);
        int statusBarHeight = getStatusBarHeight(activity);
        if (rootView != null && rootView instanceof CoordinatorLayout) {
            final CoordinatorLayout coordinatorLayout = (CoordinatorLayout) rootView;
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
                coordinatorLayout.setFitsSystemWindows(false);
                contentView.setBackgroundColor(calculateStatusColor(color, statusBarAlpha));
                boolean isNeedRequestLayout = contentView.getPaddingTop() < statusBarHeight;
                if (isNeedRequestLayout) {
                    contentView.setPadding(0, statusBarHeight, 0, 0);
                    coordinatorLayout.post(new Runnable() {
                        @Override
                        public void run() {
                            coordinatorLayout.requestLayout();
                        }
                    });
                }
            } else {
                coordinatorLayout.setStatusBarBackgroundColor(calculateStatusColor(color, statusBarAlpha));
            }
        } else {
            contentView.setPadding(0, statusBarHeight, 0, 0);
            contentView.setBackgroundColor(calculateStatusColor(color, statusBarAlpha));
        }
        setTransparentForWindow(activity);
    }
}
 
Example #15
Source Project: sealrtc-android   Author: rongcloud   File: BaseRecyclerAdapter.java    License: MIT License 5 votes vote down vote up
/**
 * 移除特定位置的元素
 *
 * @param position
 */
public void remove(@IntRange(from = 0) int position) {
    if (isValidPosition(position)) {
        mData.remove(position);
        mSelectedItems.remove(position);
        notifyItemRemoved(position);
    }
}
 
Example #16
Source Project: Android-utils   Author: Shouheng88   File: ImageUtils.java    License: Apache License 2.0 5 votes vote down vote up
public static Bitmap addCornerBorder(final Bitmap src,
                                     @IntRange(from = 1) final int borderSize,
                                     @ColorInt final int color,
                                     @FloatRange(from = 0) final float cornerRadius,
                                     final boolean recycle) {
    return addBorder(src, borderSize, color, false, cornerRadius, recycle);
}
 
Example #17
Source Project: WheelViewDemo   Author: JustinRoom   File: DotView.java    License: Apache License 2.0 5 votes vote down vote up
public void setUnReadCount(@IntRange(from = 0) int unReadCount) {
    this.unReadCount = unReadCount;
    if (unReadCount > 99)
        setText("99+");
    else if (unReadCount > 0)
        setText(String.valueOf(unReadCount));
    else
        setText("");
}
 
Example #18
Source Project: v9porn   Author: ForLovelj   File: MainActivity.java    License: MIT License 5 votes vote down vote up
private void doOnTabSelected(@IntRange(from = 0, to = 4) int position) {
    switch (position) {
        case 0:
            handlerFirstTabClickToShow(firstTabShow, position, false);
            showFloatingActionButton(fabSearch);
            break;
        case 1:
            handlerSecondTabClickToShow(secondTabShow, position, false);
            showFloatingActionButton(fabSearch);
            break;
        case 2:
            if (presenter.haveNotSetF9pornAddress()) {
                showNeedSetAddressDialog();
                return;
            }
            if (mMain9ForumFragment == null) {
                mMain9ForumFragment = Main9ForumFragment.getInstance();
            }
            mCurrentFragment = FragmentUtils.switchContent(fragmentManager, mCurrentFragment, mMain9ForumFragment, contentFrameLayout.getId(), position, false);
            showFloatingActionButton(fabSearch);
            break;
        case 3:
            if (mMusicFragment == null) {
                mMusicFragment = MusicFragment.getInstance();
            }
            mCurrentFragment = FragmentUtils.switchContent(fragmentManager, mCurrentFragment, mMusicFragment, contentFrameLayout.getId(), position, false);
            hideFloatingActionButton(fabSearch);
            break;
        case 4:
            if (mMineFragment == null) {
                mMineFragment = MineFragment.getInstance();
            }
            mCurrentFragment = FragmentUtils.switchContent(fragmentManager, mCurrentFragment, mMineFragment, contentFrameLayout.getId(), position, false);
            hideFloatingActionButton(fabSearch);
            break;
        default:
    }
    selectIndex = position;
}
 
Example #19
Source Project: sealrtc-android   Author: rongcloud   File: BaseRecyclerAdapter.java    License: MIT License 5 votes vote down vote up
@Nullable
public T getItem(@IntRange(from = 0) int position) {
    if (isValidPosition(position)) {
        return mData.get(position);
    } else {
        return null;
    }
}
 
Example #20
Source Project: tysq-android   Author: tysqapp   File: StatusBarUtils.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * 为滑动返回界面设置状态栏颜色
 *
 * @param activity       需要设置的activity
 * @param color          状态栏颜色值
 * @param statusBarAlpha 状态栏透明度
 */
public static void setColorForSwipeBack(Activity activity, @ColorInt int color,
                                        @IntRange(from = 0, to = 255) int statusBarAlpha) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {

        ViewGroup contentView = ((ViewGroup) activity.findViewById(android.R.id.content));
        View rootView = contentView.getChildAt(0);
        int statusBarHeight = getStatusBarHeight(activity);
        if (rootView != null && rootView instanceof CoordinatorLayout) {
            final CoordinatorLayout coordinatorLayout = (CoordinatorLayout) rootView;
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
                coordinatorLayout.setFitsSystemWindows(false);
                contentView.setBackgroundColor(calculateStatusColor(color, statusBarAlpha));
                boolean isNeedRequestLayout = contentView.getPaddingTop() < statusBarHeight;
                if (isNeedRequestLayout) {
                    contentView.setPadding(0, statusBarHeight, 0, 0);
                    coordinatorLayout.post(new Runnable() {
                        @Override
                        public void run() {
                            coordinatorLayout.requestLayout();
                        }
                    });
                }
            } else {
                coordinatorLayout.setStatusBarBackgroundColor(calculateStatusColor(color, statusBarAlpha));
            }
        } else {
            contentView.setPadding(0, statusBarHeight, 0, 0);
            contentView.setBackgroundColor(calculateStatusColor(color, statusBarAlpha));
        }
        setTransparentForWindow(activity);
    }
}
 
Example #21
Source Project: tysq-android   Author: tysqapp   File: StatusBarUtils.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * 为DrawerLayout 布局设置状态栏变色
 *
 * @param activity       需要设置的activity
 * @param drawerLayout   DrawerLayout
 * @param color          状态栏颜色值
 * @param statusBarAlpha 状态栏透明度
 */
public static void setColorForDrawerLayout(Activity activity, DrawerLayout drawerLayout, @ColorInt int color,
                                           @IntRange(from = 0, to = 255) int statusBarAlpha) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
        return;
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        activity.getWindow().setStatusBarColor(Color.TRANSPARENT);
    } else {
        activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
    }
    // 生成一个状态栏大小的矩形
    // 添加 statusBarView 到布局中
    ViewGroup contentLayout = (ViewGroup) drawerLayout.getChildAt(0);
    View fakeStatusBarView = contentLayout.findViewById(FAKE_STATUS_BAR_VIEW_ID);
    if (fakeStatusBarView != null) {
        if (fakeStatusBarView.getVisibility() == View.GONE) {
            fakeStatusBarView.setVisibility(View.VISIBLE);
        }
        fakeStatusBarView.setBackgroundColor(color);
    } else {
        contentLayout.addView(createStatusBarView(activity, color), 0);
    }
    // 内容布局不是 LinearLayout 时,设置padding top
    if (!(contentLayout instanceof LinearLayout) && contentLayout.getChildAt(1) != null) {
        contentLayout.getChildAt(1)
                .setPadding(contentLayout.getPaddingLeft(), getStatusBarHeight(activity) + contentLayout.getPaddingTop(),
                        contentLayout.getPaddingRight(), contentLayout.getPaddingBottom());
    }
    // 设置属性
    setDrawerLayoutProperty(drawerLayout, contentLayout);
    addTranslucentView(activity, statusBarAlpha);
}
 
Example #22
Source Project: tysq-android   Author: tysqapp   File: StatusBarUtils.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * 为 DrawerLayout 布局设置状态栏透明
 *
 * @param activity     需要设置的activity
 * @param drawerLayout DrawerLayout
 */
public static void setTranslucentForDrawerLayout(Activity activity, DrawerLayout drawerLayout,
                                                 @IntRange(from = 0, to = 255) int statusBarAlpha) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
        return;
    }
    setTransparentForDrawerLayout(activity, drawerLayout);
    addTranslucentView(activity, statusBarAlpha);
}
 
Example #23
Source Project: Focus   Author: ihewro   File: StatusBarUtil.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * 为滑动返回界面设置状态栏颜色
 *
 * @param activity       需要设置的activity
 * @param color          状态栏颜色值
 * @param statusBarAlpha 状态栏透明度
 */
public static void setColorForSwipeBack(Activity activity, @ColorInt int color,
                                        @IntRange(from = 0, to = 255) int statusBarAlpha) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {

        ViewGroup contentView = ((ViewGroup) activity.findViewById(android.R.id.content));
        View rootView = contentView.getChildAt(0);
        int statusBarHeight = getStatusBarHeight(activity);
        if (rootView != null && rootView instanceof CoordinatorLayout) {
            final CoordinatorLayout coordinatorLayout = (CoordinatorLayout) rootView;
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
                coordinatorLayout.setFitsSystemWindows(false);
                contentView.setBackgroundColor(calculateStatusColor(color, statusBarAlpha));
                boolean isNeedRequestLayout = contentView.getPaddingTop() < statusBarHeight;
                if (isNeedRequestLayout) {
                    contentView.setPadding(0, statusBarHeight, 0, 0);
                    coordinatorLayout.post(new Runnable() {
                        @Override
                        public void run() {
                            coordinatorLayout.requestLayout();
                        }
                    });
                }
            } else {
                coordinatorLayout.setStatusBarBackgroundColor(calculateStatusColor(color, statusBarAlpha));
            }
        } else {
            contentView.setPadding(0, statusBarHeight, 0, 0);
            contentView.setBackgroundColor(calculateStatusColor(color, statusBarAlpha));
        }
        setTransparentForWindow(activity);
    }
}
 
Example #24
Source Project: tysq-android   Author: tysqapp   File: StatusBarUtils.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * 为 fragment 头部是 ImageView 的设置状态栏透明
 *
 * @param activity       fragment 对应的 activity
 * @param statusBarAlpha 状态栏透明度
 * @param needOffsetView 需要向下偏移的 View
 */
public static void setTranslucentForImageViewInFragment(Activity activity, @IntRange(from = 0, to = 255) int statusBarAlpha,
                                                        View needOffsetView) {
    setTranslucentForImageView(activity, statusBarAlpha, needOffsetView);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT
            && Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        clearPreviousSetting(activity);
    }
}
 
Example #25
Source Project: java-n-IDE-for-Android   Author: shenghuntianlang   File: BracketSpan.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void draw(@NonNull Canvas canvas, CharSequence text,
                 @IntRange(from = 0) int start, @IntRange(from = 0) int end,
                 float x, int top, int y, int bottom, @NonNull Paint paint) {

    RectF rect = new RectF(x, top, x + measureText(paint, text, start, end), bottom);
    canvas.drawRect(rect, mBackgroundPaint);
    canvas.drawText(text, start, end, x, y, paint);
}
 
Example #26
Source Project: imsdk-android   Author: qunarcorp   File: BaseQuickAdapter.java    License: MIT License 5 votes vote down vote up
/**
 * remove the item associated with the specified position of adapter
 *
 * @param position
 */
public void remove(@IntRange(from = 0) int position) {
    mData.remove(position);
    int internalPosition = position + getHeaderLayoutCount();
    notifyItemRemoved(internalPosition);
    compatibilityDataSizeChanged(0);
    notifyItemRangeChanged(internalPosition, mData.size() - internalPosition);
}
 
Example #27
Source Project: androidthings-cameraCar   Author: sysolve   File: TwelveBitIntToBitPatternMapper.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Returns for each possible 12 bit integer a corresponding sequence of bit pattern as byte array.
 * Throws an {@link IllegalArgumentException} if the integer is using more than 12 bit.
 *
 * @param twelveBitValue Any 12 bit integer (from 0 to 4095)
 * @return The corresponding bit pattern as 4 byte sized array
 */
@NonNull
@Size(value = 4)
byte[] getBitPattern(@IntRange(from = 0, to = BIGGEST_12_BIT_NUMBER) int twelveBitValue) {
    byte[] bitPatternByteArray = mSparseArray.get(twelveBitValue);
    if (bitPatternByteArray == null)
    {
        throw new IllegalArgumentException("Only values from 0 to " + BIGGEST_12_BIT_NUMBER + " are allowed. The passed input value was: " + twelveBitValue);
    }
    return bitPatternByteArray;
}
 
Example #28
Source Project: Common   Author: Dsiner   File: BrightnessUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Set window brightness
 *
 * @param window     Window
 * @param brightness Brightness value
 */
public static void setWindowBrightness(@NonNull final Window window,
                                       @IntRange(from = 0, to = 255) final int brightness) {
    WindowManager.LayoutParams lp = window.getAttributes();
    lp.screenBrightness = brightness / 255f;
    window.setAttributes(lp);
}
 
Example #29
Source Project: imsdk-android   Author: qunarcorp   File: BaseQuickAdapter.java    License: MIT License 5 votes vote down vote up
@SuppressWarnings("unchecked")
private int recursiveCollapse(@IntRange(from = 0) int position) {
    T item = getItem(position);
    if (!isExpandable(item)) {
        return 0;
    }
    IExpandable expandable = (IExpandable) item;
    int subItemCount = 0;
    if (expandable.isExpanded()) {
        List<T> subItems = expandable.getSubItems();
        if (null == subItems) return 0;

        for (int i = subItems.size() - 1; i >= 0; i--) {
            T subItem = subItems.get(i);
            int pos = getItemPosition(subItem);
            if (pos < 0) {
                continue;
            }
            if (subItem instanceof IExpandable) {
                subItemCount += recursiveCollapse(pos);
            }
            mData.remove(pos);
            subItemCount++;
        }
    }
    return subItemCount;
}
 
Example #30
Source Project: imsdk-android   Author: qunarcorp   File: StatusBarUtil.java    License: MIT License 5 votes vote down vote up
/**
 * 为DrawerLayout 布局设置状态栏变色
 *
 * @param activity       需要设置的activity
 * @param drawerLayout   DrawerLayout
 * @param color          状态栏颜色值
 * @param statusBarAlpha 状态栏透明度
 */
public static void setColorForDrawerLayout(Activity activity, DrawerLayout drawerLayout, @ColorInt int color,
                                           @IntRange(from = 0, to = 255) int statusBarAlpha) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
        return;
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        activity.getWindow().setStatusBarColor(Color.TRANSPARENT);
    } else {
        activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
    }
    // 生成一个状态栏大小的矩形
    // 添加 statusBarView 到布局中
    ViewGroup contentLayout = (ViewGroup) drawerLayout.getChildAt(0);
    View fakeStatusBarView = contentLayout.findViewById(FAKE_STATUS_BAR_VIEW_ID);
    if (fakeStatusBarView != null) {
        if (fakeStatusBarView.getVisibility() == View.GONE) {
            fakeStatusBarView.setVisibility(View.VISIBLE);
        }
        fakeStatusBarView.setBackgroundColor(color);
    } else {
        contentLayout.addView(createStatusBarView(activity, color), 0);
    }
    // 内容布局不是 LinearLayout 时,设置padding top
    if (!(contentLayout instanceof LinearLayout) && contentLayout.getChildAt(1) != null) {
        contentLayout.getChildAt(1)
            .setPadding(contentLayout.getPaddingLeft(), getStatusBarHeight(activity) + contentLayout.getPaddingTop(),
                contentLayout.getPaddingRight(), contentLayout.getPaddingBottom());
    }
    // 设置属性
    setDrawerLayoutProperty(drawerLayout, contentLayout);
    addTranslucentView(activity, statusBarAlpha);
}