com.airbnb.lottie.LottieCompositionFactory Java Examples

The following examples show how to use com.airbnb.lottie.LottieCompositionFactory. 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: NetworkFetcher.java    From lottie-android with Apache License 2.0 6 votes vote down vote up
/**
 * Returns null if the animation doesn't exist in the cache.
 */
@Nullable
@WorkerThread
private LottieComposition fetchFromCache() {
  if (networkCache == null) {
    return null;
  }
  Pair<FileExtension, InputStream> cacheResult = networkCache.fetch(url);
  if (cacheResult == null) {
    return null;
  }

  FileExtension extension = cacheResult.first;
  InputStream inputStream = cacheResult.second;
  LottieResult<LottieComposition> result;
  if (extension == FileExtension.ZIP) {
    result = LottieCompositionFactory.fromZipStreamSync(new ZipInputStream(inputStream), url);
  } else {
    result = LottieCompositionFactory.fromJsonInputStreamSync(inputStream, url);
  }
  if (result.getValue() != null) {
    return result.getValue();
  }
  return null;
}
 
Example #2
Source File: BlankFragment.java    From Injector with Apache License 2.0 5 votes vote down vote up
@Override
public void onViewCreated(@NonNull View view, Bundle savedInstanceState) {
	super.onViewCreated(view, savedInstanceState);
	final LottieAnimationView lottieAnimationView = view.findViewById(R.id.lottie_view);
	LottieCompositionFactory.fromAsset(getActivity(), "tick.json").addListener(result -> {
		System.out.println("Loaded!!!!!!!!!!!!!!");
		lottieAnimationView.setComposition(result);
		lottieAnimationView.playAnimation();
	}).addFailureListener(result -> result.printStackTrace());
	System.out.println("openning!!!!!!!!!!!!!!");
}
 
Example #3
Source File: NetworkFetcher.java    From lottie-android with Apache License 2.0 5 votes vote down vote up
@Nullable
private LottieResult<LottieComposition> getResultFromConnection(HttpURLConnection connection) throws IOException {
  File file;
  FileExtension extension;
  LottieResult<LottieComposition> result;
  String contentType = connection.getContentType();
  if (contentType == null) {
    // Assume JSON for best effort parsing. If it fails, it will just deliver the parse exception
    // in the result which is more useful than failing here.
    contentType = "application/json";
  }
  if (contentType.contains("application/zip")) {
    Logger.debug("Handling zip response.");
    extension = FileExtension.ZIP;
    if (networkCache == null) {
      result = LottieCompositionFactory.fromZipStreamSync(new ZipInputStream(connection.getInputStream()), null);
    } else {
      file = networkCache.writeTempCacheFile(url, connection.getInputStream(), extension);
      result = LottieCompositionFactory.fromZipStreamSync(new ZipInputStream(new FileInputStream(file)), url);
    }
  } else {
    Logger.debug("Received json response.");
    extension = FileExtension.JSON;
    if (networkCache == null) {
      result = LottieCompositionFactory.fromJsonInputStreamSync(connection.getInputStream(), null);
    } else {
      file = networkCache.writeTempCacheFile(url, connection.getInputStream(), extension);
      result = LottieCompositionFactory.fromJsonInputStreamSync(new FileInputStream(new File(file.getAbsolutePath())), url);
    }
  }

  if (networkCache != null && result.getValue() != null) {
    networkCache.renameTempFile(url, extension);
  }
  return result;
}
 
Example #4
Source File: TestApplication.java    From Android-Keyboard with Apache License 2.0 4 votes vote down vote up
private void addExternalThemeDefault() {

        Drawable keyboardBackgroundDrawable = ContextCompat.getDrawable(this, R.drawable.test_background_lxx_light);
        Drawable morekeysBackgroundDrawable = ContextCompat.getDrawable(this, R.drawable.test_theme_more_keyboard_background);
        Drawable keyPreviewDrwable = ContextCompat.getDrawable(this, R.drawable.test_theme_preview);
        Drawable emojiIcon = ContextCompat.getDrawable(this, R.drawable.test_icon_smiley);
        Drawable deleteIcon = ContextCompat.getDrawable(this, R.drawable.test_icon_delete);
        Drawable shiftIcon = ContextCompat.getDrawable(this, R.drawable.test_icon_shift);
        Drawable shiftLockIcon = ContextCompat.getDrawable(this, R.drawable.test_icon_shift_locked);
        Drawable enterIcon = ContextCompat.getDrawable(this, R.drawable.test_icon_enter);
        Drawable languageIcon = ContextCompat.getDrawable(this, R.drawable.test_icon_language);
        Drawable chineseSuggestionMorePageBackground = new ColorDrawable(Color.parseColor("#3c3c3c"));
        Drawable chineseSuggestionComposingViewBackground = new ColorDrawable(Color.parseColor("#AA000000"));
        Drawable suggestionStripViewBackground = new ColorDrawable(Color.BLACK);

        StateListDrawable keyBackgroundDrawable = new StateListDrawable();
        keyBackgroundDrawable.addState(new int[]{android.R.attr.state_pressed}, ContextCompat.getDrawable(this, R.drawable.test_theme_key_press));
        keyBackgroundDrawable.addState(new int[]{}, ContextCompat.getDrawable(this, R.drawable.test_theme_key_normal));

        StateListDrawable functionKeyBackgroundDrawable = new StateListDrawable();
        functionKeyBackgroundDrawable.addState(new int[]{android.R.attr.state_pressed}, ContextCompat.getDrawable(this, R.drawable.test_theme_key_press));
        functionKeyBackgroundDrawable.addState(new int[]{}, ContextCompat.getDrawable(this, R.drawable.test_theme_function_key_normal));

        StateListDrawable morekeyDrawable = new StateListDrawable();
        morekeyDrawable.addState(new int[]{android.R.attr.state_pressed}, ContextCompat.getDrawable(this, R.drawable.test_theme_more_key_press));
        morekeyDrawable.addState(new int[]{}, ContextCompat.getDrawable(this, R.drawable.test_theme_key_normal));

        StateListDrawable spacebarBackgroundDrawable = new StateListDrawable();
        spacebarBackgroundDrawable.addState(new int[]{android.R.attr.state_pressed}, ContextCompat.getDrawable(this, R.drawable.test_theme_space_key_press));
        spacebarBackgroundDrawable.addState(new int[]{}, ContextCompat.getDrawable(this, R.drawable.test_theme_space_key_normal));

        ExternalThemeInfo.LottieDrawableInfo lottieDrawableInfo = new ExternalThemeInfo.LottieDrawableInfo(() -> LottieCompositionFactory
                .fromAsset(this, "test_lottie_click_effect.json"), 1);

        int dividerW = DensityUtil.dp2px(this, 1);
        int dividerH = DensityUtil.dp2px(this, 20);
        Bitmap bitmap = Bitmap.createBitmap(dividerW, dividerH, Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(bitmap);
        Paint paint = new Paint();
        paint.setColor(Color.parseColor("#12f0e5"));
        canvas.drawRect(new Rect(0, 0, dividerW, dividerH), paint);
        Drawable suggestDivider = new BitmapDrawable(getResources(), bitmap);
        String color = String.format("#%06X", 0xFFFFFF & 0x12f0e5);
        String emojiColor = String.format("#%06X", 0xFFFFFF & 0x048f89);
        ExternalThemeInfo externalThemeInfo = new ExternalThemeInfo.Builder(TestApplication.getInstance(), "001", "Test Theme")
                .setKeyboardBackground(keyboardBackgroundDrawable)
                .setKeyBackground(keyBackgroundDrawable)
                .setFunctionKeyBackground(functionKeyBackgroundDrawable)
                .setSpacebarBackground(spacebarBackgroundDrawable)
                .setKeyPreviewBackground(keyPreviewDrwable)
                .setKeyLetterSizeRatio(0.4f)
                .setKeyTextColor(color)
                .setSearchKeyIcon(ContextCompat.getDrawable(this, R.drawable.test_icon_search))
                .setNextKeyIcon(ContextCompat.getDrawable(this, R.drawable.test_icon_next))
                .setPreviousKeyIcon(ContextCompat.getDrawable(this, R.drawable.test_icon_previous))
                .setKeyHintLetterColor(color)
                .setFunctionKeyTextColor(color)
                .setMoreKeysKeyboardBackground(morekeysBackgroundDrawable)
                .setMoreKeysKeyBackground(morekeyDrawable)
                .setKeyPreviewTextColor(color)
                .setGestureTrailColor(color)
                .setEmojiNormalKeyIcon(emojiIcon)
                .setEmojiActionKeyIcon(emojiIcon)
                .setDeleteKeyIcon(deleteIcon)
                .setShiftKeyIcon(shiftIcon)
                .setShiftKeyShiftedIcon(shiftLockIcon)
                .setEnterKeyIcon(enterIcon)
                .setLanguageSwitchKeyIcon(languageIcon)
                .setEmojiCategoryPageIndicatorBackgroundColor(emojiColor)
                .setEmojiCategoryPageIndicatorForegroundColor(emojiColor)
                .setEmojiSeparatorColor(emojiColor)
                .setUiIconColor(color)
                .setLanguageOnSpacebarTextColor(color)
                .setSuggestedAutoCorrectColor(color)
                .setSuggestedTextColor(color)
                .setSuggestedTypedWordColor(color)
                .setSuggestedValidTypedWordColor(color)
                .setSuggestionStripDivider(suggestDivider)
                .setSuggestionStripViewBackground(suggestionStripViewBackground)
                .setKeyboardClickedEffectLottieDrawable(lottieDrawableInfo)
                .setThemePreviewImage(ContextCompat.getDrawable(this, R.drawable.test_thumbnail))
                .setChineseSuggestionMorePageBackground(chineseSuggestionMorePageBackground)
                .setChineseSuggestionStripOpenMorePageButton(ContextCompat.getDrawable(this, R.drawable.ic_external_theme_rgb_cn_open_moepage))
                .setChineseSuggestionStripCloseMorePageButton(ContextCompat.getDrawable(this, R.drawable.ic_external_theme_rgb_cn_close_moepage))
                .setChineseSuggestionComposingViewBackground(chineseSuggestionComposingViewBackground)
                .setChineseSuggestionComposingTextColor("#009393")
                .setChineseSuggestionMorePageUpEnableButton(ContextCompat.getDrawable(this, R.drawable.ic_external_theme_rgb_cn_suggest_up_arrow_enable))
                .setChineseSuggestionMorePageUpDisableButton(ContextCompat.getDrawable(this, R.drawable.ic_external_theme_rgb_cn_suggest_up_arrow_disable))
                .setChineseSuggestionMorePageDownEnableButton(ContextCompat.getDrawable(this, R.drawable.ic_external_theme_rgb_cn_suggest_down_arrow_enable))
                .setChineseSuggestionMorePageDownDisableButton(ContextCompat.getDrawable(this, R.drawable.ic_external_theme_rgb_cn_suggest_down_arrow_disable))
                .setChineseSuggestionMorePageDeleteButton(ContextCompat.getDrawable(this, R.drawable.ic_external_theme_rgb_cn_suggest_delete))
                .setChineseSuggestionMorePageResetButton(ContextCompat.getDrawable(this, R.drawable.ic_external_theme_rgb_cn_suggest_retransfusion))
                .build();
        Agent.getInstance().addExternalThemes(this, externalThemeInfo);
    }