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

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

源代码1 项目: Tok-Android   文件: PermissionModel.java
/**
 * is have those permission?
 *
 * @param permissions permission list:at least 1
 * @return true:every permission granted; false:have one or more permission not granted
 */
public static boolean hasPermissions(@NonNull Context context,
    @Size(min = 1) @NonNull String... permissions) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M
        || permissions == null
        || permissions.length == 0) {
        return true;
    }
    if (context == null) {
        throw new IllegalArgumentException("Can't check permissions for null context");
    }
    for (String perm : permissions) {
        if (ContextCompat.checkSelfPermission(context, perm)
            != PackageManager.PERMISSION_GRANTED) {
            return false;
        }
    }
    return true;
}
 
@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);
}
 
/**
 * Converts the passed color array to a correlating byte array of bit patterns. These resulting
 * bit patterns are readable by a WS2812B LED strip if they are sent by a SPI device with the
 * right frequency.
 *
 * @param colors An array of color integers {@link ColorInt}
 * @return Returns a byte array of correlating bit patterns
 */
byte[] convertToBitPattern(@ColorInt @NonNull @Size(max = MAX_NUMBER_OF_SUPPORTED_LEDS) int[] colors) {
    if (colors.length > MAX_NUMBER_OF_SUPPORTED_LEDS) {
        throw new IllegalArgumentException("Only " + MAX_NUMBER_OF_SUPPORTED_LEDS + " LEDs are supported. A Greater Number (" + colors.length + ") will result in SPI errors!");
    }

    byte[] bitPatterns = new byte[colors.length * 8];

    int i = 0;
    for (int color : colors) {
        color = colorChannelSequencer.rearrangeColorChannels(color);
        int firstValue = (color & FIRST_TWELVE_BIT_BIT_MASK) >> 12;
        int secondValue = color & SECOND_TWELVE_BIT_BIT_MASK;

        System.arraycopy(mTwelveBitIntToBitPatternMapper.getBitPattern(firstValue), 0, bitPatterns, i, 4);
        i += 4;
        System.arraycopy(mTwelveBitIntToBitPatternMapper.getBitPattern(secondValue), 0, bitPatterns, i, 4);
        i += 4;
    }
    return bitPatterns;
}
 
源代码4 项目: MiPushFramework   文件: CondomContext.java
private CondomContext(final CondomCore condom, final @Nullable Context app_context, final @Nullable @Size(max=16) String tag) {
	super(condom.mBase);
	final Context base = condom.mBase;
	mCondom = condom;
	mApplicationContext = app_context != null ? app_context : this;
	mBaseContext = new Lazy<Context>() { @Override protected Context create() {
		return new PseudoContextImpl(CondomContext.this);
	}};
	mPackageManager = new Lazy<PackageManager>() { @Override protected PackageManager create() {
		return new CondomPackageManager(base.getPackageManager());
	}};
	mContentResolver = new Lazy<ContentResolver>() { @Override protected ContentResolver create() {
		return new CondomContentResolver(base, base.getContentResolver());
	}};
	final List<CondomKit> kits = condom.mKits;
	if (kits != null && ! kits.isEmpty()) {
		mKitManager = new KitManager();
		for (final CondomKit kit : kits)
			kit.onRegister(mKitManager);
	} else mKitManager = null;
	TAG = CondomCore.buildLogTag("Condom", "Condom.", tag);
}
 
源代码5 项目: BaseProject   文件: EasyPermissions.java
/**
 * Check if the calling context has a set of permissions.
 *
 * @param context the calling context.
 * @param perms   one ore more permissions, such as {@link Manifest.permission#CAMERA}.
 * @return true if all permissions are already granted, false if at least one permission is not
 * yet granted.
 * @see Manifest.permission
 */
public static boolean hasPermissions(@NonNull Context context,
                                     @Size(min = 1) @NonNull String... perms) {
    // Always return true for SDK < M, let the system deal with the permissions
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
        Log.w(TAG, "hasPermissions: API version < M, returning true by default");

        // DANGER ZONE!!! Changing this will break the library.
        return true;
    }

    // Null context may be passed if we have detected Low API (less than M) so getting
    // to this point with a null context should not be possible.
    if (context == null) {
        throw new IllegalArgumentException("Can't check permissions for null context");
    }

    for (String perm : perms) {
        if (ContextCompat.checkSelfPermission(context, perm)
                != PackageManager.PERMISSION_GRANTED) {
            return false;
        }
    }

    return true;
}
 
源代码6 项目: Tok-Android   文件: PermissionModel.java
/**
 * request permission, requestCode can be set,
 * if user refused,it will show dialog to guide the user open setting granted permission
 *
 * @param requestCode requestCode
 * @param permissions permission list
 * @param rationale the message show on the guide dialog
 * @param callBack callback
 */
public static void requestPermissions(int requestCode,
    @Size(min = 1) @NonNull String[] permissions, CharSequence rationale,
    PermissionCallBack callBack) {
    BasePermissionActivity activity = getTopPermissionActivity();
    if (hasPermissions(activity, permissions)) {
        notifyAlreadyHasPermissions(activity, requestCode, permissions);
        return;
    }
    activity.setPermissionsInfo(requestCode, permissions, rationale, callBack);
    PermissionHelper.requestPermissions(activity, requestCode, permissions);
}
 
源代码7 项目: InteractiveChart   文件: Utils.java
/**
 * 检查x y是否包含在opt数组中
 * (opt.length 必须为4)
 */
public static boolean contains(@NonNull @Size(value = 4) float[] opt, float x, float y) {
  if (opt.length < 4) {
    return false;
  }
  return opt[0] < opt[2] && opt[1] < opt[3]  // check for empty first
      && x >= opt[0] && x < opt[2] && y >= opt[1] && y < opt[3];
}
 
源代码8 项目: InteractiveChart   文件: GridTextMarker.java
@Override public void onMarkerViewMeasure(RectF viewRect, Matrix matrix, float highlightPointX,
    float highlightPointY, String[] markerText, @Size(min = 4) @NonNull float[] markerViewInfo) {
  if (viewRect.top > highlightPointY || highlightPointY > viewRect.bottom) {
    return;
  }
  markerTextPaint.getTextBounds(markerText[1], 0, markerText[1].length(), textRect);
  width = Math.max(width,
      textRect.width() + (attribute.markerBorderLRPadding - attribute.markerBorderWidth) * 2);
  height = Math.max(height,
      textRect.height() + (attribute.markerBorderTBPadding - attribute.markerBorderWidth) * 2);
  highlightPointY = highlightPointY - height / 2;
  if (highlightPointY < viewRect.top) {
    highlightPointY = viewRect.top + inset;
  }
  if (highlightPointY > viewRect.bottom - height) {
    highlightPointY = viewRect.bottom - height - inset;
  }

  if (yMarkerAlign == GridMarkerAlign.LEFT) {
    markerInsets.left = viewRect.left + inset;
  } else if (yMarkerAlign == GridMarkerAlign.RIGHT) {
    markerInsets.left = viewRect.right - width - inset;
  } else if (highlightPointX > viewRect.left + viewRect.width() / 2) {
    markerInsets.left = viewRect.right - width - inset;
  } else {
    markerInsets.left = viewRect.left + inset;
  }

  markerInsets.top = highlightPointY;
  markerInsets.right = markerInsets.left + width;
  markerInsets.bottom = markerInsets.top + height;

  markerViewInfo[0] = markerInsets.left - inset;
  markerViewInfo[2] = markerInsets.right + inset;
}
 
源代码9 项目: InteractiveChart   文件: AxisTextMarker.java
@Override public void onMarkerViewMeasure(RectF viewRect,
    Matrix matrix, float highlightPointX,
    float highlightPointY, String[] markerText, @Size(min = 4) @NonNull float[] markerViewInfo) {
  if (viewRect.left > highlightPointX || highlightPointX > viewRect.right) {
    return;
  }
  markerTextPaint.getTextBounds(markerText[0], 0,
      markerText[0].length(), textRect);
  width = Math.max(width,
      textRect.width() + (attribute.markerBorderLRPadding - attribute.markerBorderWidth) * 2);
  height = Math.max(height,
      textRect.height() + (attribute.markerBorderTBPadding - attribute.markerBorderWidth) * 2);

  highlightPointX = highlightPointX - width / 2;
  if (highlightPointX <= viewRect.left) {
    highlightPointX = viewRect.left + inset;
  }
  if (highlightPointX >= viewRect.right - width) {
    highlightPointX = viewRect.right - width - inset;
  }

  markerInsets.left = highlightPointX;

  if (xMarkerAlign == AxisMarkerAlign.TOP) {
    markerInsets.top = viewRect.top + inset;
  } else if (xMarkerAlign == AxisMarkerAlign.BOTTOM) {
    markerInsets.top = viewRect.bottom - height - inset;
  } else if (highlightPointY < viewRect.top + viewRect.height() / 2) {
    markerInsets.top = viewRect.bottom - height - inset;
  } else {
    markerInsets.top = viewRect.top + inset;
  }

  markerInsets.right = markerInsets.left + width;
  markerInsets.bottom = markerInsets.top + height;

  markerViewInfo[1] = markerInsets.top - inset;
  markerViewInfo[3] = markerInsets.bottom + inset;
}
 
/**
 * Provide a list of {@link DirectionsRoute}s, the primary route will default to the first route
 * in the directions route list. All other routes in the list will be drawn on the map using the
 * alternative route style.
 *
 * @param directionsRoutes a list of direction routes, first one being the primary and the rest of
 *                         the routes are considered alternatives.
 * @since 0.8.0
 */
public void addRoutes(@NonNull @Size(min = 1) List<DirectionsRoute> directionsRoutes) {
  clearRoutes();
  this.directionsRoutes.addAll(directionsRoutes);
  primaryRouteIndex = 0;
  alternativesVisible = directionsRoutes.size() > 1;
  generateFeatureCollectionList(directionsRoutes);
  drawRoutes();
  addDirectionWaypoints();
}
 
/**
 * 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;
}
 
@Size(value = 4)
private byte[] convertBitPatternsToByteArray(List<Boolean> bitPatterns) {

    if (bitPatterns.size() != 32)
    {
        throw new IllegalArgumentException("Undefined bit pattern size: Expected size is 32. Passed size: " + bitPatterns.size());
    }
    byte[] bitPatternsAsByteArray = new byte[4];
    bitPatternsAsByteArray [0] = convertBitPatternsToByte(bitPatterns.subList(0, 8));
    bitPatternsAsByteArray [1] = convertBitPatternsToByte(bitPatterns.subList(8, 16));
    bitPatternsAsByteArray [2] = convertBitPatternsToByte(bitPatterns.subList(16, 24));
    bitPatternsAsByteArray [3] = convertBitPatternsToByte(bitPatterns.subList(24, 32));
    return bitPatternsAsByteArray;
}
 
源代码13 项目: DebugOverlay-Android   文件: LogcatViewModule.java
public LogcatViewModule(@LayoutRes int layoutResId, @Size(min=1,max=100) int maxLines,
                         LogcatLineFilter lineFilter, LogcatLineColorScheme colorScheme) {
    super(layoutResId);
    this.maxLines = maxLines;
    this.lineFilter = lineFilter;
    this.colorScheme = colorScheme;
}
 
源代码14 项目: Walrus   文件: MifareCardData.java
public Block(@Size(SIZE) byte[] data) {
    if (data.length != SIZE) {
        throw new IllegalArgumentException("Invalid data length");
    }

    this.data = data;
}
 
源代码15 项目: Walrus   文件: MifareCardData.java
public Key(@Size(6) byte[] key) {
    if (key.length != 6) {
        throw new IllegalArgumentException("Invalid key length");
    }

    this.key = key;
}
 
源代码16 项目: Walrus   文件: Proxmark3Command.java
Proxmark3Command(@Opcode long op, @Size(3) long[] args, @Size(max = 512) byte[] data) {
    this.op = op;

    if (args.length != 3) {
        throw new IllegalArgumentException("Invalid number of args");
    }
    this.args = args;

    if (data.length > 512) {
        throw new IllegalArgumentException("Data too long");
    }
    this.data = Arrays.copyOf(data, 512);
}
 
源代码17 项目: BaseProject   文件: PermissionRequest.java
/**
 * @see #Builder(Activity, int, String...)
 */
public Builder(@NonNull Fragment fragment, int requestCode,
               @NonNull @Size(min = 1) String... perms) {
    mHelper = PermissionHelper.newInstance(fragment);
    mRequestCode = requestCode;
    mPerms = perms;
}
 
源代码18 项目: BaseProject   文件: PermissionRequest.java
/**
 * @see #Builder(Activity, int, String...)
 */
public Builder(@NonNull android.app.Fragment fragment, int requestCode,
               @NonNull @Size(min = 1) String... perms) {
    mHelper = PermissionHelper.newInstance(fragment);
    mRequestCode = requestCode;
    mPerms = perms;
}
 
源代码19 项目: BaseProject   文件: EasyPermissions.java
/**
 * Request permissions from a Support Fragment with standard OK/Cancel buttons.
 *
 * @see #requestPermissions(Activity, String, int, String...)
 */
public static void requestPermissions(
        @NonNull Fragment host, @NonNull String rationale,
        int requestCode, @Size(min = 1) @NonNull String... perms) {
    requestPermissions(
            new PermissionRequest.Builder(host, requestCode, perms)
                    .setRationale(rationale)
                    .build());
}
 
源代码20 项目: BaseProject   文件: EasyPermissions.java
/**
 * Request permissions from a standard Fragment with standard OK/Cancel buttons.
 *
 * @see #requestPermissions(Activity, String, int, String...)
 */
public static void requestPermissions(
        @NonNull android.app.Fragment host, @NonNull String rationale,
        int requestCode, @Size(min = 1) @NonNull String... perms) {
    requestPermissions(
            new PermissionRequest.Builder(host, requestCode, perms)
                    .setRationale(rationale)
                    .build());
}
 
源代码21 项目: BaseProject   文件: EasyPermissions.java
/**
 * Request permissions from a Support Fragment.
 *
 * @see #requestPermissions(Activity, String, int, int, int, String...)
 * @deprecated use {@link #requestPermissions(PermissionRequest)} instead
 */
@Deprecated
public static void requestPermissions(
        @NonNull Fragment host, @NonNull String rationale,
        @StringRes int positiveButton, @StringRes int negativeButton,
        int requestCode, @Size(min = 1) @NonNull String... perms) {
    requestPermissions(
            new PermissionRequest.Builder(host, requestCode, perms)
                    .setRationale(rationale)
                    .setPositiveButtonText(positiveButton)
                    .setNegativeButtonText(negativeButton)
                    .build());
}
 
源代码22 项目: BaseProject   文件: EasyPermissions.java
/**
 * @see #requestPermissions(Activity, String, int, int, int, String...)
 * @deprecated use {@link #requestPermissions(PermissionRequest)} instead
 */
@Deprecated
public static void requestPermissions(
        @NonNull android.app.Fragment host, @NonNull String rationale,
        @StringRes int positiveButton, @StringRes int negativeButton,
        int requestCode, @Size(min = 1) @NonNull String... perms) {
    requestPermissions(
            new PermissionRequest.Builder(host, requestCode, perms)
                    .setRationale(rationale)
                    .setPositiveButtonText(positiveButton)
                    .setNegativeButtonText(negativeButton)
                    .build());
}
 
源代码23 项目: px-android   文件: ReviewPaymentMethodsActivity.java
@Override
public void initializeSupportedPaymentMethods(
    @Size(min = 1) @NonNull final List<PaymentMethod> supportedPaymentMethods) {
    final ReviewPaymentMethodsAdapter mAdapter = new ReviewPaymentMethodsAdapter(supportedPaymentMethods);
    recyclerView.setAdapter(mAdapter);
    recyclerView.setLayoutManager(new LinearLayoutManager(this));
}
 
源代码24 项目: px-android   文件: CheckoutPreference.java
/**
 * Builder for custom CheckoutPreference construction. It should be only used if you are processing the payment
 * with a Payment processor. Otherwise you should use the ID constructor.
 *
 * @param site preference site {@link Sites#getById(String)}
 * @param payerEmail payer email
 * @param items items to pay
 */
public Builder(@NonNull final Site site, @NonNull final String payerEmail,
    @Size(min = 1) @NonNull final List<Item> items) {
    this.items = items;
    payer = new Payer();
    payer.setEmail(payerEmail);
    this.site = site;
    excludedPaymentMethods = new ArrayList<>();
    excludedPaymentTypes = new ArrayList<>();
    marketplace = DEFAULT_MARKETPLACE;
}
 
源代码25 项目: px-android   文件: CheckoutPreference.java
/**
 * Builder for custom CheckoutPreference construction. It should be only used if you are processing the payment
 * with a Payment processor. Otherwise you should use the ID constructor.
 *
 * @param site preference site {@link Sites#getById(String)}
 * @param payer payer
 * @param items items to pay
 */
@Deprecated
public Builder(@NonNull final Site site, @NonNull final OpenPayer payer,
    @Size(min = 1) @NonNull final List<Item> items) {
    this.items = items;
    this.payer = payer;
    this.site = site;
    excludedPaymentMethods = new ArrayList<>();
    excludedPaymentTypes = new ArrayList<>();
    marketplace = DEFAULT_MARKETPLACE;
}
 
源代码26 项目: Muzesto   文件: Ask.java
public Ask forPermissions(@NonNull @Size(min = 1) String... permissions) {
    if (permissions == null || permissions.length == 0) {
        throw new IllegalArgumentException("The permissions to request are missing");
    }
    this.permissions = permissions;
    return this;
}
 
public PermissionRequest(
        @NonNull String name,
        @NonNull PermissionCallback callback,
        @Size(min = 1) String...permissions) {
    this.name = name;
    this.callback = callback;
    this.permissions = permissions;
}
 
源代码28 项目: riiablo   文件: MappedKey.java
private int[] validateAssignments(@Keycode @Size(min = 2) int[] keycodes) {
  Validate.isTrue(keycodes.length >= 2, "keycodes.length must be >= 2");
  boolean forceUnmapped = false;
  for (int i = 0; i < keycodes.length; i++) {
    @Keycode int keycode = keycodes[i];
    if (keycode == NOT_MAPPED) {
      forceUnmapped = true;
    }

    for (int j = i + 1; j < keycodes.length; j++) {
      @Keycode int anotherKeycode = keycodes[j];
      if (anotherKeycode == NOT_MAPPED) {
        forceUnmapped = true;
      } else if (forceUnmapped || keycode == anotherKeycode) {
        throw new IllegalArgumentException(
            "mapped keys cannot contain any duplicates or mappings after the last unmapped index. " +
            "Key: " + getName() + " [" + getAlias() + "]");
      }
    }

    if (forceUnmapped) {
      break;
    }
  }

  return keycodes;
}
 
源代码29 项目: ColorCrossFade   文件: CCFAnimator.java
protected AbsHSVAnimator(
        @Nullable AlphaEvaluator alphaEvaluator,
        @ColorInt int fromColor,
        @ColorInt int toColor,
        @Size(3) float[] fromHSV,
        @Size(3) float[] toHSV
) {
    super(fromColor, toColor);
    this.mAlphaEvaluator = alphaEvaluator;
    this.mFrom = fromHSV;
    this.mTo = toHSV;
    this.mOut = new float[3];
}
 
源代码30 项目: ExoMedia   文件: ExoMediaPlayer.java
public boolean matchesHistory(@Size(min = 1, max = 4) int[] states, boolean ignorePlayWhenReady) {
    boolean flag = true;
    int andFlag = ignorePlayWhenReady ? ~FLAG_PLAY_WHEN_READY : ~0x0;
    int startIndex = prevStates.length - states.length;

    for (int i = startIndex; i < prevStates.length; i++) {
        flag &= (prevStates[i] & andFlag) == (states[i - startIndex] & andFlag);
    }

    return flag;
}
 
 同包方法