androidx.core.util.Preconditions Java Examples

The following examples show how to use androidx.core.util.Preconditions. 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 File: StickerPackDownloadJob.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
private StickerPackDownloadJob(@NonNull Parameters parameters,
                               @NonNull String packId,
                               @NonNull String packKey,
                               boolean isReferencePack,
                               boolean notify)
{
  super(parameters);

  Preconditions.checkNotNull(packId);
  Preconditions.checkNotNull(packKey);

  this.packId          = packId;
  this.packKey         = packKey;
  this.isReferencePack = isReferencePack;
  this.notify          = notify;
}
 
Example #2
Source File: CalendarItemStyle.java    From material-components-android with Apache License 2.0 6 votes vote down vote up
private CalendarItemStyle(
    ColorStateList backgroundColor,
    ColorStateList textColor,
    ColorStateList strokeColor,
    int strokeWidth,
    ShapeAppearanceModel itemShape,
    @NonNull Rect insets) {
  Preconditions.checkArgumentNonnegative(insets.left);
  Preconditions.checkArgumentNonnegative(insets.top);
  Preconditions.checkArgumentNonnegative(insets.right);
  Preconditions.checkArgumentNonnegative(insets.bottom);

  this.insets = insets;
  this.textColor = textColor;
  this.backgroundColor = backgroundColor;
  this.strokeColor = strokeColor;
  this.strokeWidth = strokeWidth;
  this.itemShape = itemShape;
}
 
Example #3
Source File: CreateKbsPinViewModel.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
@MainThread
public void confirm() {
  KbsPin          pin      = Preconditions.checkNotNull(this.getUserEntry().getValue());
  PinKeyboardType keyboard = Preconditions.checkNotNull(this.getKeyboard().getValue());

  if (PinValidityChecker.valid(pin.toString())) {
    events.setValue(new NavigationEvent(pin, keyboard));
  } else {
    errors.setValue(PinErrorEvent.WEAK_PIN);
  }
}
 
Example #4
Source File: CameraXModule.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
CameraXModule(CameraXView view) {
  mCameraXView = view;

  Futures.addCallback(ProcessCameraProvider.getInstance(view.getContext()),
      new FutureCallback<ProcessCameraProvider>() {
        // TODO(b/124269166): Rethink how we can handle permissions here.
        @SuppressLint("MissingPermission")
        @Override
        public void onSuccess(@Nullable ProcessCameraProvider provider) {
          Preconditions.checkNotNull(provider);
          mCameraProvider = provider;
          if (mCurrentLifecycle != null) {
            bindToLifecycle(mCurrentLifecycle);
          }
        }

        @Override
        public void onFailure(Throwable t) {
          throw new RuntimeException("CameraX failed to initialize.", t);
        }
      }, CameraXExecutors.mainThreadExecutor());

  mPreviewBuilder = new Preview.Builder().setTargetName("Preview");

  mImageCaptureBuilder = new ImageCapture.Builder().setTargetName("ImageCapture");

  // Begin Signal Custom Code Block
  mVideoCaptureConfigBuilder =
      new VideoCaptureConfig.Builder().setTargetName("VideoCapture")
                                      .setAudioBitRate(VideoUtil.AUDIO_BIT_RATE)
                                      .setVideoFrameRate(VideoUtil.VIDEO_FRAME_RATE)
                                      .setBitRate(VideoUtil.VIDEO_BIT_RATE);
  // End Signal Custom Code Block
}
 
Example #5
Source File: BaseMotionStrategy.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
@Override
public final MotionSpec getCurrentMotionSpec() {
  if (motionSpec != null) {
    return motionSpec;
  }

  if (defaultMotionSpec == null) {
    defaultMotionSpec =
        MotionSpec.createFromResource(
            context,
            getDefaultMotionSpecResource());
  }

  return Preconditions.checkNotNull(defaultMotionSpec);
}
 
Example #6
Source File: FloatingActionButtonImpl.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
void onPaddingUpdated(@NonNull Rect padding) {
  Preconditions.checkNotNull(contentBackground, "Didn't initialize content background");
  if (shouldAddPadding()) {
    InsetDrawable insetDrawable = new InsetDrawable(
        contentBackground, padding.left, padding.top, padding.right, padding.bottom);
    shadowViewDelegate.setBackgroundDrawable(insetDrawable);
  } else {
    shadowViewDelegate.setBackgroundDrawable(contentBackground);
  }
}
 
Example #7
Source File: RangeDateSelector.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
@Override
public void setSelection(@NonNull Pair<Long, Long> selection) {
  if (selection.first != null && selection.second != null) {
    Preconditions.checkArgument(isValidRange(selection.first, selection.second));
  }
  selectedStartItem =
      selection.first == null ? null : UtcDates.canonicalYearMonthDay(selection.first);
  selectedEndItem =
      selection.second == null ? null : UtcDates.canonicalYearMonthDay(selection.second);
}
 
Example #8
Source File: CreateKbsPinViewModel.java    From mollyim-android with GNU General Public License v3.0 4 votes vote down vote up
@Override
@MainThread
public void toggleAlphaNumeric() {
  this.keyboard.setValue(Preconditions.checkNotNull(this.keyboard.getValue()).getOther());
}
 
Example #9
Source File: Permissions.java    From permission-bitte with MIT License 4 votes vote down vote up
Permissions(Map<String, PermissionResult> map) {
  this.map = Preconditions.checkNotNull(map);
}
 
Example #10
Source File: Permission.java    From permission-bitte with MIT License 4 votes vote down vote up
Permission(String name, PermissionResult result) {
  this.name = Preconditions.checkNotNull(name);
  this.result = Preconditions.checkNotNull(result);
}
 
Example #11
Source File: Permission.java    From permission-bitte with MIT License 4 votes vote down vote up
protected Permission(Parcel in) {
  this.name = Preconditions.checkNotNull(in.readString());
  this.result = PermissionResult.values()[in.readInt()];
}
 
Example #12
Source File: CalendarItemStyle.java    From material-components-android with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a {@link CalendarItemStyle} using the provided {@link
 * R.styleable#MaterialCalendarItem}.
 */
@NonNull
static CalendarItemStyle create(
    @NonNull Context context, @StyleRes int materialCalendarItemStyle) {
  Preconditions.checkArgument(
      materialCalendarItemStyle != 0, "Cannot create a CalendarItemStyle with a styleResId of 0");

  TypedArray styleableArray =
      context.obtainStyledAttributes(materialCalendarItemStyle, R.styleable.MaterialCalendarItem);
  int insetLeft =
      styleableArray.getDimensionPixelOffset(
          R.styleable.MaterialCalendarItem_android_insetLeft, 0);
  int insetTop =
      styleableArray.getDimensionPixelOffset(
          R.styleable.MaterialCalendarItem_android_insetTop, 0);
  int insetRight =
      styleableArray.getDimensionPixelOffset(
          R.styleable.MaterialCalendarItem_android_insetRight, 0);
  int insetBottom =
      styleableArray.getDimensionPixelOffset(
          R.styleable.MaterialCalendarItem_android_insetBottom, 0);
  Rect insets = new Rect(insetLeft, insetTop, insetRight, insetBottom);

  ColorStateList backgroundColor =
      MaterialResources.getColorStateList(
          context, styleableArray, R.styleable.MaterialCalendarItem_itemFillColor);
  ColorStateList textColor =
      MaterialResources.getColorStateList(
          context, styleableArray, R.styleable.MaterialCalendarItem_itemTextColor);
  ColorStateList strokeColor =
      MaterialResources.getColorStateList(
          context, styleableArray, R.styleable.MaterialCalendarItem_itemStrokeColor);
  int strokeWidth =
      styleableArray.getDimensionPixelSize(R.styleable.MaterialCalendarItem_itemStrokeWidth, 0);

  int shapeAppearanceResId =
      styleableArray.getResourceId(R.styleable.MaterialCalendarItem_itemShapeAppearance, 0);
  int shapeAppearanceOverlayResId =
      styleableArray.getResourceId(
          R.styleable.MaterialCalendarItem_itemShapeAppearanceOverlay, 0);

  ShapeAppearanceModel itemShape =
      ShapeAppearanceModel.builder(context, shapeAppearanceResId, shapeAppearanceOverlayResId)
          .build();

  styleableArray.recycle();

  return new CalendarItemStyle(
      backgroundColor, textColor, strokeColor, strokeWidth, itemShape, insets);
}
 
Example #13
Source File: ResourcesCompat.java    From Carbon with Apache License 2.0 3 votes vote down vote up
/**
 * Returns a font Typeface associated with a particular resource ID asynchronously.
 * <p>
 * Prior to API level 23, font resources with more than one font in a family will only load the
 * font closest to a regular weight typeface.
 * </p>
 *
 * @param context      A context to retrieve the Resources from.
 * @param id           The desired resource identifier of a {@link Typeface}, as generated by the aapt
 *                     tool. This integer encodes the package, type, and resource entry. The value 0 is an
 *                     invalid identifier.
 * @param fontCallback A callback to receive async fetching of this font. The callback will be
 *                     triggered on the UI thread.
 * @param handler      A handler for the thread the callback should be called on. If null, the
 *                     callback will be called on the UI thread.
 * @throws NotFoundException Throws NotFoundException if the given ID does not exist.
 */
public static void getFont(@NonNull Context context, @FontRes int id,
                           @NonNull androidx.core.content.res.ResourcesCompat.FontCallback fontCallback, @Nullable Handler handler)
        throws NotFoundException {
    Preconditions.checkNotNull(fontCallback);
    if (context.isRestricted()) {
        fontCallback.callbackFailAsync(
                FontRequestCallback.FAIL_REASON_SECURITY_VIOLATION, handler);
        return;
    }
    loadFont(context, id, new TypedValue(), Typeface.NORMAL, 400, fontCallback, handler,
            false /* isXmlRequest */);
}