类android.support.annotation.IntRange源码实例Demo

下面列出了怎么用android.support.annotation.IntRange的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: Focus   文件: StatusBarUtil.java
/**
 * 设置状态栏颜色
 *
 * @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);
    }
}
 
源代码2 项目: Android-utils   文件: ImageUtils.java
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;
}
 
源代码3 项目: MvpRoute   文件: RxScheduler.java
/**
 * 倒计时
 *
 * @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();

}
 
源代码4 项目: v9porn   文件: MainActivity.java
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:
    }
}
 
源代码5 项目: RulerView   文件: TimeRuleView.java
/**
 * 格式化时间 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();
}
 
@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);
}
 
源代码7 项目: Focus   文件: StatusBarUtil.java
/**
 * 为 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);
}
 
源代码8 项目: Focus   文件: StatusBarUtil.java
/**
 * 为 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);
}
 
源代码9 项目: Focus   文件: StatusBarUtil.java
/**
 * 为 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);
    }
}
 
源代码10 项目: star-zone-android   文件: PermissionHelper.java
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);
    }
}
 
源代码11 项目: star-zone-android   文件: BmobUrlUtil.java
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;
    }
 
源代码12 项目: DanDanPlayForAndroid   文件: CommonUtils.java
/**
 * 获取加透明度的资源颜色
 */
@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);
}
 
源代码13 项目: FlexItemDecoration   文件: BaseItemDecoration.java
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;
}
 
源代码14 项目: styT   文件: StatusBarUtil.java
/**
 * 为滑动返回界面设置状态栏颜色
 *
 * @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);
    }
}
 
源代码15 项目: sealrtc-android   文件: BaseRecyclerAdapter.java
/**
 * 移除特定位置的元素
 *
 * @param position
 */
public void remove(@IntRange(from = 0) int position) {
    if (isValidPosition(position)) {
        mData.remove(position);
        mSelectedItems.remove(position);
        notifyItemRemoved(position);
    }
}
 
源代码16 项目: Android-utils   文件: ImageUtils.java
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);
}
 
源代码17 项目: WheelViewDemo   文件: DotView.java
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("");
}
 
源代码18 项目: v9porn   文件: MainActivity.java
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;
}
 
源代码19 项目: sealrtc-android   文件: BaseRecyclerAdapter.java
@Nullable
public T getItem(@IntRange(from = 0) int position) {
    if (isValidPosition(position)) {
        return mData.get(position);
    } else {
        return null;
    }
}
 
源代码20 项目: tysq-android   文件: StatusBarUtils.java
/**
 * 为滑动返回界面设置状态栏颜色
 *
 * @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);
    }
}
 
源代码21 项目: tysq-android   文件: StatusBarUtils.java
/**
 * 为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);
}
 
源代码22 项目: tysq-android   文件: StatusBarUtils.java
/**
 * 为 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);
}
 
源代码23 项目: Focus   文件: StatusBarUtil.java
/**
 * 为滑动返回界面设置状态栏颜色
 *
 * @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);
    }
}
 
源代码24 项目: tysq-android   文件: StatusBarUtils.java
/**
 * 为 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);
    }
}
 
源代码25 项目: java-n-IDE-for-Android   文件: BracketSpan.java
@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);
}
 
源代码26 项目: imsdk-android   文件: BaseQuickAdapter.java
/**
 * 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);
}
 
/**
 * 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;
}
 
源代码28 项目: Common   文件: BrightnessUtils.java
/**
 * 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);
}
 
源代码29 项目: imsdk-android   文件: BaseQuickAdapter.java
@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;
}
 
源代码30 项目: imsdk-android   文件: StatusBarUtil.java
/**
 * 为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);
}
 
 同包方法