Java 类android.support.annotation.IntRange 实例源码
项目:Android-PickerDialog
文件:WheelTime.java
public void setEndDate(@IntRange(from = 0) long endTime) {
Calendar endDate = Calendar.getInstance();
endDate.setTime(new Date(endTime));
int year = endDate.get(Calendar.YEAR);
int month = endDate.get(Calendar.MONTH) + 1;
int day = endDate.get(Calendar.DAY_OF_MONTH);
if (year > startYear) {
this.endYear = year;
this.endMonth = month;
this.endDay = day;
} else if (year == startYear) {
if (month > startMonth) {
this.endYear = year;
this.endMonth = month;
this.endDay = day;
} else if (month == startMonth) {
if (day > startDay) {
this.endYear = year;
this.endMonth = month;
this.endDay = day;
}
}
}
}
项目:BWS-Android
文件:AsynchronousBackgroundHandler.java
@Override
public int runWithDelay(@NonNull final Runnable runnable, @IntRange(from = 0) long delayInMillis) {
final int taskId = getTaskId(scheduledTasks);
CountDownTimer scheduledTask = new CountDownTimer(delayInMillis, delayInMillis) {
@Override
public void onTick(long l) {
// do nothing (is disabled anyway because "countDownInterval" is set to "millisInFuture")
}
@Override
public void onFinish() {
scheduledTasks.remove(taskId);
runnable.run();
}
}.start();
scheduledTasks.put(taskId, scheduledTask);
return taskId;
}
项目:silly-android
文件:MainActivity.java
/**
* {@inheritDoc}
*/
@Override
protected void onPermissionsResult(@IntRange(from = 0, to = 127) final int code, @NonNull final Set<String> granted, @NonNull final Set<String> denied) {
super.onPermissionsResult(code, granted, denied);
switch (code) {
case 10: {
if (granted.contains(Manifest.permission.ACCESS_WIFI_STATE) && granted.contains(Manifest.permission.ACCESS_NETWORK_STATE)) {
printInfo();
} else {
toastLong(R.string.toast_permission_missing);
}
break;
}
default: {
Log.e(TAG, "onPermissionsResult: Unknown request code " + code);
break;
}
}
}
项目:Android-PickerDialog
文件:WheelTime.java
public void setRangeDate(@IntRange(from = 0) long startTime, @IntRange(from = 0) long endTime) {
if (startTime < endTime) {
Calendar startDate = Calendar.getInstance();
startDate.setTime(new Date(startTime));
Calendar endDate = Calendar.getInstance();
endDate.setTime(new Date(endTime));
this.startYear = startDate.get(Calendar.YEAR);
this.endYear = endDate.get(Calendar.YEAR);
this.startMonth = startDate.get(Calendar.MONTH) + 1;
this.endMonth = endDate.get(Calendar.MONTH) + 1;
this.startDay = startDate.get(Calendar.DAY_OF_MONTH);
this.endDay = endDate.get(Calendar.DAY_OF_MONTH);
}
}
项目:VRPlayer
文件: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);
}
}
项目:HeadlineNews
文件:BarUtils.java
/**
* 为DrawerLayout设置状态栏颜色
* <p>DrawLayout需设置 {@code android:fitsSystemWindows="true"}</p>
*
* @param activity activity
* @param drawer drawerLayout
* @param fakeStatusBar 伪造状态栏
* @param color 状态栏颜色值
* @param alpha 状态栏透明度,此透明度并非颜色中的透明度
* @param isTop drawerLayout是否在顶层
*/
public static void setStatusBarColor4Drawer(@NonNull final Activity activity,
@NonNull final DrawerLayout drawer,
@NonNull final View fakeStatusBar,
@ColorInt final int color,
@IntRange(from = 0, to = 255) final int alpha,
final boolean isTop) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) return;
drawer.setFitsSystemWindows(false);
transparentStatusBar(activity);
setStatusBarColor(fakeStatusBar, color, isTop ? alpha : 0);
for (int i = 0, len = drawer.getChildCount(); i < len; i++) {
drawer.getChildAt(i).setFitsSystemWindows(false);
}
if (isTop) {
hideAlphaView(activity);
} else {
addStatusBarAlpha(activity, alpha, false);
}
}
项目:ThreeExpandItem
文件:BaseQuickAdapter.java
/**
* Collapse an expandable item that has been expanded..
*
* @param position the position of the item, which includes the header layout count.
* @param animate collapse with animation or not.
* @param notify notify the recyclerView refresh UI or not.
* @return the number of subItems collapsed.
*/
public int collapse(@IntRange(from = 0) int position, boolean animate, boolean notify) {
position -= getHeaderLayoutCount();
IExpandable expandable = getExpandableItem(position);
if (expandable == null) {
return 0;
}
int subItemCount = recursiveCollapse(position);
expandable.setExpanded(false);
int parentPos = position + getHeaderLayoutCount();
if (notify) {
if (animate) {
notifyItemChanged(parentPos);
notifyItemRangeRemoved(parentPos + 1, subItemCount);
} else {
notifyDataSetChanged();
}
}
return subItemCount;
}
项目:HeadlineNews
文件:ImageUtils.java
/**
* 按质量压缩
*
* @param src 源图片
* @param quality 质量
* @param recycle 是否回收
* @return 质量压缩后的图片
*/
public static Bitmap compressByQuality(final Bitmap src, @IntRange(from = 0, to = 100) final int quality, final boolean recycle) {
if (isEmptyBitmap(src)) return null;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
src.compress(CompressFormat.JPEG, quality, baos);
byte[] bytes = baos.toByteArray();
if (recycle && !src.isRecycled()) src.recycle();
return BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
}
项目:FastTextView
文件:ItalicReplacementSpan.java
private void setHeightIfNeed(CharSequence text, @IntRange(from = 0) int start, @IntRange(from = 0) int end, @Nullable Paint.FontMetricsInt fm) {
if (fm != null && text.length() == end - start) {
// Extending classes can set the height of the span by updating
// attributes of {@link android.graphics.Paint.FontMetricsInt}. If the span covers the whole
// text, and the height is not set,
// {@link #draw(Canvas, CharSequence, int, int, float, int, int, int, Paint)} will not be
// called for the span.
fm.top = mRect.top;
fm.bottom = mRect.bottom;
}
}
项目:GitHub
文件:BarUtils.java
/**
* 设置状态栏透明度
*
* @param fakeStatusBar 伪造状态栏
* @param alpha 状态栏透明度
*/
public static void setStatusBarAlpha(@NonNull final View fakeStatusBar,
@IntRange(from = 0, to = 255) final int alpha) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) return;
fakeStatusBar.setVisibility(View.VISIBLE);
transparentStatusBar((Activity) fakeStatusBar.getContext());
ViewGroup.LayoutParams layoutParams = fakeStatusBar.getLayoutParams();
layoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT;
layoutParams.height = BarUtils.getStatusBarHeight();
fakeStatusBar.setBackgroundColor(Color.argb(alpha, 0, 0, 0));
}
项目:mapbox-plugins-android
文件:PlaceOptions.java
public PlaceOptions build(@IntRange(from = 1, to = 2) int mode) {
if (!countries.isEmpty()) {
country(TextUtils.join(",", countries.toArray()));
}
injectedPlaces(injectedPlaces);
viewMode(mode);
return autoBuild();
}
项目:webtrekk-android-sdk
文件:ProductListTracker.java
/**
* Register Recycler view for product list tracking. Please call {@link #unregisterView(RecyclerView)}
* after RecyclerView is hided
* @param view RecyclerView instance
* @param timeoutMilliseconds timeout that is used when list is scrolled. Position of product
* is tracked if list has this delay after scrolling or first show-up
* @param itemCallback - callback to provide information about product
*/
public void registerView(@NonNull RecyclerView view, @IntRange(from=0) final long timeoutMilliseconds, @NonNull final ProductListItemCallback itemCallback){
final RecyclerView.LayoutManager layoutManager = view.getLayoutManager();
//we not support others layout managers then LinearLayoutManager
if (!(layoutManager instanceof LinearLayoutManager)) {
WebtrekkLogging.log("Error: not LinearLayouManager isn't supported");
return;
}
mDelayHandler = new Handler();
mScrollListener = new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
if (newState == RecyclerView.SCROLL_STATE_IDLE){
initPendingList(recyclerView, timeoutMilliseconds, itemCallback);
}else{
clearPendingEvents();
}
}
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
//it equals zero on the first list start in that case start pending
if (dy == 0){
initPendingList(recyclerView, timeoutMilliseconds, itemCallback);
}
}
};
view.addOnScrollListener(mScrollListener);
mOnTouсhEventListener = new RecyclerItemClickListener(view.getContext(), view);
view.addOnItemTouchListener(mOnTouсhEventListener);
initPendingList(view, timeoutMilliseconds, itemCallback);
}
项目:HeadlineNews
文件:BarUtils.java
/**
* 设置状态栏颜色
*
* @param fakeStatusBar 伪造状态栏
* @param color 状态栏颜色值
* @param alpha 状态栏透明度,此透明度并非颜色中的透明度
*/
public static void setStatusBarColor(@NonNull final View fakeStatusBar,
@ColorInt final int color,
@IntRange(from = 0, to = 255) final int alpha) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) return;
fakeStatusBar.setVisibility(View.VISIBLE);
transparentStatusBar((Activity) fakeStatusBar.getContext());
ViewGroup.LayoutParams layoutParams = fakeStatusBar.getLayoutParams();
layoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT;
layoutParams.height = BarUtils.getStatusBarHeight();
fakeStatusBar.setBackgroundColor(getStatusBarColor(color, alpha));
}
项目:ucar-weex-core
文件:WXTimerModule.java
@JSMethod(uiThread = false)
public void clearInterval(@IntRange(from = 1) int funcId) {
if (funcId <= 0) {
return;
}
removeOrHoldMessage(MODULE_INTERVAL, funcId);
}
项目:GitHub
文件:ImageUtils.java
/**
* 按质量压缩
*
* @param src 源图片
* @param quality 质量
* @param recycle 是否回收
* @return 质量压缩后的图片
*/
public static Bitmap compressByQuality(final Bitmap src, @IntRange(from = 0, to = 100) final int quality, final boolean recycle) {
if (isEmptyBitmap(src)) return null;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
src.compress(Bitmap.CompressFormat.JPEG, quality, baos);
byte[] bytes = baos.toByteArray();
if (recycle && !src.isRecycled()) src.recycle();
return BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
}
项目:letv
文件:ColorUtils.java
public static void RGBToHSL(@IntRange(from = 0, to = 255) int r, @IntRange(from = 0, to = 255) int g, @IntRange(from = 0, to = 255) int b, @NonNull float[] outHsl) {
float s;
float h;
float rf = ((float) r) / 255.0f;
float gf = ((float) g) / 255.0f;
float bf = ((float) b) / 255.0f;
float max = Math.max(rf, Math.max(gf, bf));
float min = Math.min(rf, Math.min(gf, bf));
float deltaMaxMin = max - min;
float l = (max + min) / 2.0f;
if (max == min) {
s = 0.0f;
h = 0.0f;
} else {
if (max == rf) {
h = ((gf - bf) / deltaMaxMin) % 6.0f;
} else if (max == gf) {
h = ((bf - rf) / deltaMaxMin) + 2.0f;
} else {
h = ((rf - gf) / deltaMaxMin) + 4.0f;
}
s = deltaMaxMin / (1.0f - Math.abs((2.0f * l) - 1.0f));
}
h = (60.0f * h) % 360.0f;
if (h < 0.0f) {
h += 360.0f;
}
outHsl[0] = constrain(h, 0.0f, 360.0f);
outHsl[1] = constrain(s, 0.0f, 1.0f);
outHsl[2] = constrain(l, 0.0f, 1.0f);
}
项目:BilibiliClient
文件:StatusBarUtil.java
@IntRange(from = 0, to = 75)
public static int getNavigationBarOffsetPx(Context context) {
if (isLessKitkat()) {
return 0;
}
Context appContext = context.getApplicationContext();
int result = 0;
int resourceId =
appContext.getResources().getIdentifier("navigation_bar_height", "dimen", "android");
if (resourceId > 0) {
result = appContext.getResources().getDimensionPixelSize(resourceId);
}
return result;
}
项目:GitHub
文件:BaseQuickAdapter.java
/**
* Get the data item associated with the specified position in the data set.
*
* @param position Position of the item whose data we want within the adapter's
* data set.
* @return The data at the specified position.
*/
@Nullable
public T getItem(@IntRange(from = 0) int position) {
if (position < mData.size())
return mData.get(position);
else
return null;
}
项目:recyclerview-android
文件:DatasourceObservable.java
/**
* Notifies the registered observers that the data have been removed from the datasource.
* Note that method can be called multiple times.
*
* @param positionStart Position of the first data item that was removed.
* @param itemCount Number of the data items removed.
*/
public void notifyItemRangeRemoved(@IntRange(from = 0) final int positionStart,
@IntRange(from = 0) final int itemCount) {
final int size = mObservers.size();
for (int i = size - 1; i >= 0; i--) {
mObservers.get(i).onItemRangeRemoved(positionStart, itemCount);
}
}
项目:AndroidMuseumBleManager
文件:BleParamsOptions.java
/**
* usable only the reconnect strategy is ConnectConfig.RECONNECT_LINE_EXPONENT
* @param reconnectedLineToExponentTimes the times from linear to exponential, default is 5 times
* @return
*/
public Builder setReconnectedLineToExponentTimes(@IntRange(from = 1) int reconnectedLineToExponentTimes) {
if (reconnectedLineToExponentTimes < 1){
throw new IllegalArgumentException("reconnectedLineToExponentTimes value must >= 1, now is "+reconnectedLineToExponentTimes);
}
this.reconnectedLineToExponentTimes = reconnectedLineToExponentTimes;
return this;
}
项目:GitHub
文件:GlideRequest.java
/**
* @see GlideOptions#encodeQuality(int)
*/
@CheckResult
public GlideRequest<TranscodeType> encodeQuality(@IntRange(from = 0, to = 100) int arg0) {
if (getMutableOptions() instanceof GlideOptions) {
this.requestOptions = ((GlideOptions) getMutableOptions()).encodeQuality(arg0);
} else {
this.requestOptions = new GlideOptions().apply(this.requestOptions).encodeQuality(arg0);
}
return this;
}
项目:GitHub
文件:GlideRequest.java
/**
* @see GlideOptions#frame(long)
*/
@CheckResult
public GlideRequest<TranscodeType> frame(@IntRange(from = 0) long arg0) {
if (getMutableOptions() instanceof GlideOptions) {
this.requestOptions = ((GlideOptions) getMutableOptions()).frame(arg0);
} else {
this.requestOptions = new GlideOptions().apply(this.requestOptions).frame(arg0);
}
return this;
}
项目:recyclerview-android
文件:ListDatasource.java
/**
* Moves entity from one position to another.
*
* @param fromPosition an initial index.
* @param toPosition a new index.
*/
public void move(@IntRange(from = 0) final int fromPosition,
@IntRange(from = 0) final int toPosition) {
final E e = mItems.remove(fromPosition);
mItems.add(toPosition, e);
mDatasourceObservable.notifyItemMoved(fromPosition, toPosition);
}
项目:GitHub
文件:GlideRequest.java
/**
* @see GlideOptions#frame(long)
*/
@CheckResult
public GlideRequest<TranscodeType> frame(@IntRange(from = 0) long arg0) {
if (getMutableOptions() instanceof GlideOptions) {
this.requestOptions = ((GlideOptions) getMutableOptions()).frame(arg0);
} else {
this.requestOptions = new GlideOptions().apply(this.requestOptions).frame(arg0);
}
return this;
}
项目:silly-android
文件:SillyAndroid.java
/**
* Tries to get the status bar height for this device. Even if the value returned is larger than 0, that does not mean the status bar is visible.
*
* @param context A context to use to find the status bar height
* @return Height of the status bar on the running device, in pixels
*/
@IntRange(from = 0)
public static int getStatusBarHeight(@NonNull final Context context) {
int result = 0;
int resourceId = context.getResources().getIdentifier("status_bar_height", "dimen", "android");
if (resourceId > 0) {
result = context.getResources().getDimensionPixelSize(resourceId);
}
return result;
}
项目:gmlrva
文件:ViewUtils.java
/**
* Procedure meant to provide the device's screen height in pixels.
* @param context the application's current {@link Context}.
* @return an Integer value representing the device's screen height, in pixels.
*/
@IntRange(from = 0) public static int getDeviceScreenHeight(@NonNull final Context context) {
synchronized (ViewUtils.class) {
if (sDeviceScreenHeight == 0) {
final WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
if (windowManager != null) {
final Display display = windowManager.getDefaultDisplay();
final Point size = new Point();
display.getSize(size);
sDeviceScreenHeight = size.y;
}
}
}
return sDeviceScreenHeight;
}
项目:UltimateRecyclerView
文件:BaseMultiItemQuickAdapter.java
public void remove(@IntRange(from = 0L) int position) {
if (mDataList == null || position < 0 || position >= mDataList.size()) {
return;
}
T entity = mDataList.get(position);
if (entity instanceof IExpandable) {
removeAllChild((IExpandable) entity, position);
}
removeDataFromParent(entity);
}
项目:AndroidOCRFforID
文件:CropImageView.java
/**
* This method sets animation duration for image to wrap the crop bounds
*
* @param imageToWrapCropBoundsAnimDuration - duration in milliseconds
*/
public void setImageToWrapCropBoundsAnimDuration(@IntRange(from = 100) long imageToWrapCropBoundsAnimDuration) {
if (imageToWrapCropBoundsAnimDuration > 0) {
mImageToWrapCropBoundsAnimDuration = imageToWrapCropBoundsAnimDuration;
} else {
throw new IllegalArgumentException("Animation duration cannot be negative value.");
}
}
项目:GitHub
文件:BarUtils.java
/**
* 设置状态栏透明度
*
* @param activity activity
* @param alpha 状态栏透明度
* @param isDecor {@code true}: 设置在DecorView中<br>
* {@code false}: 设置在ContentView中
*/
public static void setStatusBarAlpha(@NonNull final Activity activity,
@IntRange(from = 0, to = 255) final int alpha,
final boolean isDecor) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) return;
hideColorView(activity);
transparentStatusBar(activity);
addStatusBarAlpha(activity, alpha, isDecor);
}
项目:gmlrva
文件:FakeDataProvider.java
/**
* Procedure meant to generate and return a {@link String} object containing randomly generated output.
* @param sizeOfRandomString the desired size of the resulting {@link String} object.
* @return the {@link String} object containing randomly generated output.
*/
@NonNull
private static String getRandomString(@IntRange(from = 0) final int sizeOfRandomString) {
final Random random = new Random();
final StringBuilder sb = new StringBuilder(sizeOfRandomString);
for (int i = 0; i < sizeOfRandomString; i++) {
sb.append(ALLOWED_CHARACTERS.charAt(random.nextInt(ALLOWED_CHARACTERS.length())));
}
return sb.toString();
}
项目:GitHub
文件:GlideOptions.java
/**
* @see RequestOptions#frameOf(long)
*/
@CheckResult
public static GlideOptions frameOf(@IntRange(from = 0) long arg0) {
return new GlideOptions().frame(arg0);
}
项目:VanGogh
文件:VanGoghBuilder.java
public VanGoghBuilder withResultSize(@IntRange(from = 100) int width, @IntRange(from = 100) int height) {
this.cropWidth = width;
this.cropHeight = height;
return this;
}
项目:GitHub
文件:GlideOptions.java
/**
* @see RequestOptions#overrideOf(int)
*/
@CheckResult
public static GlideOptions overrideOf(@IntRange(from = 0) int arg0) {
return new GlideOptions().override(arg0);
}
项目:recyclerview-android
文件:PersonsAdapter.java
@Override
public boolean isEnabled(@IntRange(from = 0) final int position) {
return !get(position).getFullName().contains("ad");
}
项目:GitHub
文件:GlideOptions.java
/**
* @see RequestOptions#timeoutOf(int)
*/
@CheckResult
public static GlideOptions timeoutOf(@IntRange(from = 0) int arg0) {
return new GlideOptions().timeout(arg0);
}
项目:GitHub
文件:GlideOptions.java
@Override
@CheckResult
public final GlideOptions frame(@IntRange(from = 0) long arg0) {
return (GlideOptions) super.frame(arg0);
}
项目:GitHub
文件:ResourcesManager.java
private EmptysManager empty(@IntRange(from = 0, to = 999) int type) {
return mEmptysManager = new EmptysManager(type);
}
项目:GitHub
文件:GlideOptions.java
@Override
@CheckResult
public final GlideOptions timeout(@IntRange(from = 0) int arg0) {
return (GlideOptions) super.timeout(arg0);
}
项目:AndroidOCRFforID
文件:UCrop.java
/**
* @param count - crop grid rows count.
*/
public void setCropGridRowCount(@IntRange(from = 0) int count) {
mOptionBundle.putInt(EXTRA_CROP_GRID_ROW_COUNT, count);
}
项目:silly-android
文件:EasyActivity.java
/**
* Returns the result from {@link SillyAndroid#countIntentHandlers(Context, Intent)}.
*/
@IntRange(from = 0)
protected final int countIntentHandlers(@Nullable final Intent intent) {
return SillyAndroid.countIntentHandlers(this, intent);
}