当前位置: 首页>>代码示例>>Java>>正文


Java RemoteMuzeiArtSource类代码示例

本文整理汇总了Java中com.google.android.apps.muzei.api.RemoteMuzeiArtSource的典型用法代码示例。如果您正苦于以下问题:Java RemoteMuzeiArtSource类的具体用法?Java RemoteMuzeiArtSource怎么用?Java RemoteMuzeiArtSource使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


RemoteMuzeiArtSource类属于com.google.android.apps.muzei.api包,在下文中一共展示了RemoteMuzeiArtSource类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: handleError

import com.google.android.apps.muzei.api.RemoteMuzeiArtSource; //导入依赖的package包/类
private UpdateArtResponse handleError() throws RemoteMuzeiArtSource.RetryException {
    int retryCount = preferences.getRetryCount();
    if (retryCount < 4) {
        throw new RemoteMuzeiArtSource.RetryException();
    } else {
        int nextRetryFromNow = random.nextInt(FIVE_MINS_IN_MILLI_SECONDS) * 5;
        if (retryCount > 11) {
            nextRetryFromNow = TWELVE_HRS_IN_MILLI_SECONDS * 2; // 24 hours
        } else if (retryCount > 7) {
            nextRetryFromNow = TWELVE_HRS_IN_MILLI_SECONDS;
        }

        return UpdateArtResponse.builder()
                .nextUpdateTime(clock.currentTimeMillis() + nextRetryFromNow)
                .build();
    }
}
 
开发者ID:mainthread-technology,项目名称:grand-maps-for-muzei,代码行数:18,代码来源:GrandMapsArtSourceService.java

示例2: onTryUpdate

import com.google.android.apps.muzei.api.RemoteMuzeiArtSource; //导入依赖的package包/类
@Override
protected void onTryUpdate(int reason) throws RemoteMuzeiArtSource.RetryException {
    try {
        if (Preferences.get(this).isConnectedAsPreferred()) {
            Wallpaper wallpaper = MuzeiHelper.getRandomWallpaper(this);

            if (wallpaper != null) {
                Uri uri = Uri.parse(wallpaper.getUrl());

                Intent intent = new Intent(this, WallpaperBoardPreviewActivity.class);
                intent.putExtra(Extras.EXTRA_URL, wallpaper.getUrl());
                intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
                intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

                publishArtwork(new Artwork.Builder()
                        .title(wallpaper.getName())
                        .byline(wallpaper.getAuthor())
                        .imageUri(uri)
                        .viewIntent(intent)
                        .build());

                scheduleUpdate(System.currentTimeMillis() +
                        Preferences.get(this).getRotateTime());
            }

            Database.get(this).closeDatabase();
        }
    } catch (Exception e) {
        LogUtil.e(Log.getStackTraceString(e));
    }
}
 
开发者ID:danimahardhika,项目名称:wallpaperboard,代码行数:32,代码来源:WallpaperBoardMuzeiService.java

示例3: updateArtThrowsWhenResponseIsNull

import com.google.android.apps.muzei.api.RemoteMuzeiArtSource; //导入依赖的package包/类
@Test(expected = RemoteMuzeiArtSource.RetryException.class)
public void updateArtThrowsWhenResponseIsNull() throws Exception {
    // Given
    when(preferences.getRetryCount()).thenReturn(0);
    when(retrofitCall.execute()).thenReturn(Response.<ImageListResponse>success(null));

    // When
    sut.updateArt(MuzeiArtSource.UPDATE_REASON_OTHER);
}
 
开发者ID:mainthread-technology,项目名称:grand-maps-for-muzei,代码行数:10,代码来源:GrandMapsArtSourceServiceTest.java

示例4: updateArtThrowsWhenImagesNull

import com.google.android.apps.muzei.api.RemoteMuzeiArtSource; //导入依赖的package包/类
@Test(expected = RemoteMuzeiArtSource.RetryException.class)
public void updateArtThrowsWhenImagesNull() throws Exception {
    // Given
    when(preferences.getRetryCount()).thenReturn(0);
    when(retrofitCall.execute()).thenReturn(Response.success(ImageListResponse.builder().build()));

    // When
    sut.updateArt(MuzeiArtSource.UPDATE_REASON_OTHER);
}
 
开发者ID:mainthread-technology,项目名称:grand-maps-for-muzei,代码行数:10,代码来源:GrandMapsArtSourceServiceTest.java

示例5: updateArtThrowsWhenImagesEmpty

import com.google.android.apps.muzei.api.RemoteMuzeiArtSource; //导入依赖的package包/类
@Test(expected = RemoteMuzeiArtSource.RetryException.class)
public void updateArtThrowsWhenImagesEmpty() throws Exception {
    // Given
    when(preferences.getRetryCount()).thenReturn(0);
    when(retrofitCall.execute()).thenReturn(Response.success(ImageListResponse.builder().images(Collections.<ImageResponse>emptyList()).build()));

    // When
    sut.updateArt(MuzeiArtSource.UPDATE_REASON_OTHER);
}
 
开发者ID:mainthread-technology,项目名称:grand-maps-for-muzei,代码行数:10,代码来源:GrandMapsArtSourceServiceTest.java

示例6: updateArtThrowsWhen0Retries

import com.google.android.apps.muzei.api.RemoteMuzeiArtSource; //导入依赖的package包/类
@Test(expected = RemoteMuzeiArtSource.RetryException.class)
public void updateArtThrowsWhen0Retries() throws Exception {
    // Given
    when(preferences.getRetryCount()).thenReturn(0);
    Response<ImageListResponse> error = Response.error(500, ResponseBody.create(MediaType.parse("text/plain"), ""));
    when(retrofitCall.execute()).thenReturn(error);

    // When
    sut.updateArt(MuzeiArtSource.UPDATE_REASON_OTHER);
}
 
开发者ID:mainthread-technology,项目名称:grand-maps-for-muzei,代码行数:11,代码来源:GrandMapsArtSourceServiceTest.java

示例7: updateArtThrowsWhen3Retries

import com.google.android.apps.muzei.api.RemoteMuzeiArtSource; //导入依赖的package包/类
@Test(expected = RemoteMuzeiArtSource.RetryException.class)
public void updateArtThrowsWhen3Retries() throws Exception {
    // Given
    when(preferences.getRetryCount()).thenReturn(3);
    Response<ImageListResponse> error = Response.error(400, ResponseBody.create(MediaType.parse("text/plain"), ""));
    when(retrofitCall.execute()).thenReturn(error);

    // When
    sut.updateArt(MuzeiArtSource.UPDATE_REASON_OTHER);
}
 
开发者ID:mainthread-technology,项目名称:grand-maps-for-muzei,代码行数:11,代码来源:GrandMapsArtSourceServiceTest.java

示例8: onTryUpdate

import com.google.android.apps.muzei.api.RemoteMuzeiArtSource; //导入依赖的package包/类
@Override
protected void onTryUpdate(int reason) throws RetryException {
    // Allow getting the next artwork
    this.setUserCommands(RemoteMuzeiArtSource.BUILTIN_COMMAND_ID_NEXT_ARTWORK);

    // Get the current picture ID. As 10 pictures are published every 10 days, we can just count
    // and wrap around when we have reached the end of all pictures.
    SharedPreferences settings = this.getSharedPreferences(PREFS_NAME, MODE_PRIVATE);
    int pictureID = settings.getInt("pictureID", 0);

    // Retrieve the picture items from the interwebs,
    try {
        RssReader reader = new RssReader(RSS_SOURCE);
        List<RssItem> items = reader.getItems();

        // We expect at least RECENT_PICTURES pictures. However, we may have retrieved less
        // this is a quick fix to rotate anyway, but if eg 9 items are retrieved, we get item 0
        // twice.
        if (pictureID >= items.size()) {
            pictureID %= items.size();
        }

        RssItem item = items.get(pictureID);

        // Do some magic to retrieve the author
        String author = null;
        int authorPos = item.getTitle().indexOf("By");
        if (authorPos >= 0) {
            author = item.getTitle().substring(authorPos + 3);
        }

        // Do some magic to retrieve the url from the post
        String url = null;
        int srcPos = item.getDescription().indexOf("src=\"");
        if (srcPos >= 0) {
            int srcEndPos = item.getDescription().substring(srcPos + 5).indexOf("\"");
            if (srcEndPos >= 0) {
                url = item.getDescription().substring(srcPos + 5, srcPos + srcEndPos + 5);
                url = url.replace("&amp;", "&");
            }
        }
        // If we are on wifi, we get it from the download url
        if (url == null || this.isOnWifi()) {
            url = item.getLink() + "/download";
        }
        Log.d("UnsplashArtSource", "Retrieving from " + url);

        // Publish artwork
        this.publishArtwork(new Artwork.Builder()
                .imageUri(Uri.parse(url))
                .byline(author)
                .viewIntent(new Intent(Intent.ACTION_VIEW, item.getLink()))
                .build());

        // Schedule new update
        this.scheduleUpdate(System.currentTimeMillis() + ROTATE_TIME_MILLIS);

        // Do the picture id + 1 mod 10
        SharedPreferences.Editor editor = settings.edit();
        editor.putInt("pictureID", (pictureID + 1) % RECENT_PICTURES);
        editor.apply();

    } catch (ParserConfigurationException | SAXException | IOException e) {
        throw new RetryException();
    }

}
 
开发者ID:ralphje,项目名称:muzei-unsplash,代码行数:68,代码来源:UnsplashArtSource.java

示例9: updateArt

import com.google.android.apps.muzei.api.RemoteMuzeiArtSource; //导入依赖的package包/类
/**
 * Updates the next map
 *
 * @param reason         muzei reason for updating
 * @return {@link UpdateArtResponse} - container object
 */
UpdateArtResponse updateArt(int reason) throws RemoteMuzeiArtSource.RetryException;
 
开发者ID:mainthread-technology,项目名称:grand-maps-for-muzei,代码行数:8,代码来源:ArtSourceService.java


注:本文中的com.google.android.apps.muzei.api.RemoteMuzeiArtSource类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。