android.support.annotation.Size Java Examples

The following examples show how to use android.support.annotation.Size. 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: Tok-Android   Author: InsightIM   File: PermissionModel.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #2
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 #3
Source Project: androidthings-cameraCar   Author: sysolve   File: ColorToBitPatternConverter.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #4
Source Project: MiPushFramework   Author: MiPushFramework   File: CondomContext.java    License: GNU General Public License v3.0 6 votes vote down vote up
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);
}
 
Example #5
Source Project: BaseProject   Author: qyxxjd   File: EasyPermissions.java    License: MIT License 6 votes vote down vote up
/**
 * 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;
}
 
Example #6
Source Project: Tok-Android   Author: InsightIM   File: PermissionModel.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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);
}
 
Example #7
Source Project: InteractiveChart   Author: LLWenke   File: Utils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 检查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];
}
 
Example #8
Source Project: InteractiveChart   Author: LLWenke   File: GridTextMarker.java    License: Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example #9
Source Project: InteractiveChart   Author: LLWenke   File: AxisTextMarker.java    License: Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example #10
Source Project: graphhopper-navigation-android   Author: graphhopper   File: NavigationMapRoute.java    License: MIT License 5 votes vote down vote up
/**
 * 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();
}
 
Example #11
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 #12
Source Project: androidthings-cameraCar   Author: sysolve   File: TwelveBitIntToBitPatternMapper.java    License: Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example #13
Source Project: DebugOverlay-Android   Author: Manabu-GT   File: LogcatViewModule.java    License: Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #14
Source Project: Walrus   Author: TeamWalrus   File: MifareCardData.java    License: GNU General Public License v3.0 5 votes vote down vote up
public Block(@Size(SIZE) byte[] data) {
    if (data.length != SIZE) {
        throw new IllegalArgumentException("Invalid data length");
    }

    this.data = data;
}
 
Example #15
Source Project: Walrus   Author: TeamWalrus   File: MifareCardData.java    License: GNU General Public License v3.0 5 votes vote down vote up
public Key(@Size(6) byte[] key) {
    if (key.length != 6) {
        throw new IllegalArgumentException("Invalid key length");
    }

    this.key = key;
}
 
Example #16
Source Project: Walrus   Author: TeamWalrus   File: Proxmark3Command.java    License: GNU General Public License v3.0 5 votes vote down vote up
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);
}
 
Example #17
Source Project: BaseProject   Author: qyxxjd   File: PermissionRequest.java    License: MIT License 5 votes vote down vote up
/**
 * @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;
}
 
Example #18
Source Project: BaseProject   Author: qyxxjd   File: PermissionRequest.java    License: MIT License 5 votes vote down vote up
/**
 * @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;
}
 
Example #19
Source Project: BaseProject   Author: qyxxjd   File: EasyPermissions.java    License: MIT License 5 votes vote down vote up
/**
 * 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());
}
 
Example #20
Source Project: BaseProject   Author: qyxxjd   File: EasyPermissions.java    License: MIT License 5 votes vote down vote up
/**
 * 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());
}
 
Example #21
Source Project: BaseProject   Author: qyxxjd   File: EasyPermissions.java    License: MIT License 5 votes vote down vote up
/**
 * 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());
}
 
Example #22
Source Project: BaseProject   Author: qyxxjd   File: EasyPermissions.java    License: MIT License 5 votes vote down vote up
/**
 * @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());
}
 
Example #23
Source Project: px-android   Author: mercadopago   File: ReviewPaymentMethodsActivity.java    License: MIT License 5 votes vote down vote up
@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));
}
 
Example #24
Source Project: px-android   Author: mercadopago   File: CheckoutPreference.java    License: MIT License 5 votes vote down vote up
/**
 * 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;
}
 
Example #25
Source Project: px-android   Author: mercadopago   File: CheckoutPreference.java    License: MIT License 5 votes vote down vote up
/**
 * 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;
}
 
Example #26
Source Project: Muzesto   Author: rohanoid5   File: Ask.java    License: GNU General Public License v3.0 5 votes vote down vote up
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;
}
 
Example #27
Source Project: LearningAppAndroid   Author: salesforce-marketingcloud   File: ActivityPermissionDelegate.java    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public PermissionRequest(
        @NonNull String name,
        @NonNull PermissionCallback callback,
        @Size(min = 1) String...permissions) {
    this.name = name;
    this.callback = callback;
    this.permissions = permissions;
}
 
Example #28
Source Project: riiablo   Author: collinsmith   File: MappedKey.java    License: Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #29
Source Project: ColorCrossFade   Author: noties   File: CCFAnimator.java    License: Apache License 2.0 5 votes vote down vote up
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];
}
 
Example #30
Source Project: ExoMedia   Author: brianwernick   File: ExoMediaPlayer.java    License: Apache License 2.0 5 votes vote down vote up
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;
}