com.google.android.apps.muzei.api.Artwork Java Examples

The following examples show how to use com.google.android.apps.muzei.api.Artwork. 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: CandyBarMuzeiService.java    From candybar-library with Apache License 2.0 6 votes vote down vote up
@Override
protected void onTryUpdate(int reason) throws RetryException {
    try {
        if (!URLUtil.isValidUrl(getString(R.string.wallpaper_json)))
            return;

        Wallpaper wallpaper = MuzeiHelper.getRandomWallpaper(this);

        if (Preferences.get(this).isConnectedAsPreferred()) {
            if (wallpaper != null) {
                Uri uri = Uri.parse(wallpaper.getURL());

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

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

        Database.get(this).closeDatabase();
    } catch (Exception ignored) {}
}
 
Example #2
Source File: MysplashMuzeiArtSource.java    From Mysplash with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void publishPhoto(@NonNull Photo photo) {
    publishArtwork(
            new Artwork.Builder()
                    .title(getString(R.string.by) + " " + photo.user.name)
                    .byline(getString(R.string.on) + " " + photo.created_at.split("T")[0])
                    .imageUri(Uri.parse(photo.getDownloadUrl(getApplicationContext())))
                    .token(photo.id)
                    .viewIntent(
                            RoutingHelper.getWebActivityIntent(
                                    "https://unsplash.com/photos/" + photo.id)
                    ).build()
    );

    List<UserCommand> commands = new ArrayList<>();
    commands.add(new UserCommand(MuzeiArtSource.BUILTIN_COMMAND_ID_NEXT_ARTWORK));
    setUserCommands(commands);
}
 
Example #3
Source File: WeatherMuzeiSource.java    From Advanced_Android_Development with Apache License 2.0 6 votes vote down vote up
@Override
protected void onUpdate(int reason) {
    String location = Utility.getPreferredLocation(this);
    Uri weatherForLocationUri = WeatherContract.WeatherEntry.buildWeatherLocationWithStartDate(
            location, System.currentTimeMillis());
    Cursor cursor = getContentResolver().query(weatherForLocationUri, FORECAST_COLUMNS, null,
            null, WeatherContract.WeatherEntry.COLUMN_DATE + " ASC");
    if (cursor.moveToFirst()) {
        int weatherId = cursor.getInt(INDEX_WEATHER_ID);
        String desc = cursor.getString(INDEX_SHORT_DESC);

        String imageUrl = Utility.getImageUrlForWeatherCondition(weatherId);
        // Only publish a new wallpaper if we have a valid image
        if (imageUrl != null) {
            publishArtwork(new Artwork.Builder()
                    .imageUri(Uri.parse(imageUrl))
                    .title(desc)
                    .byline(location)
                    .viewIntent(new Intent(this, MainActivity.class))
                    .build());
        }
    }
    cursor.close();
}
 
Example #4
Source File: WallpaperBoardMuzeiService.java    From wallpaperboard with Apache License 2.0 5 votes vote down vote up
@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));
    }
}
 
Example #5
Source File: MysplashMuzeiArtSource.java    From Mysplash with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void onUpdateSucceed(@NonNull List<Photo> photoList) {
    Artwork art = getCurrentArtwork();
    String lastPhotoId = art == null ? null : art.getToken();
    for (Photo photo : photoList) {
        if (!photo.id.equals(lastPhotoId)) {
            publishPhoto(photo);
            scheduleUpdate(System.currentTimeMillis()
                    + MuzeiOptionManager.getInstance(this).getUpdateInterval() * HOUR);
            return;
        }
    }
    onUpdateFailed();
}
 
Example #6
Source File: BiliWallpaperSource.java    From muzei-bilibili with Apache License 2.0 5 votes vote down vote up
@Override
protected void onUpdate(int reason) {
    List<UserCommand> commands = new ArrayList<>();
    if (reason == UPDATE_REASON_INITIAL) {
        // Show initial picture
        final File file = getCacheFile("66138");
        saveInitialPicture(file);
        if (file.exists()) {
            publishArtwork(new Artwork.Builder()
                    .imageUri(Uri.fromFile(file))
                    .title("22&33")
                    .token("66138")
                    .byline("Bilibili壁纸娘\n动漫")
                    .viewIntent(new Intent(Intent.ACTION_VIEW,
                            Uri.parse("http://h.bilibili.com/wallpaper?action=detail&il_id=66138")))
                    .build());
            // show the latest photo in 15 minutes
            scheduleUpdate(System.currentTimeMillis() + 15 * 60 * 1000);
        } else {
            super.onUpdate(reason);
        }
    } else {
        super.onUpdate(reason);
    }

    commands.add(new UserCommand(BUILTIN_COMMAND_ID_NEXT_ARTWORK));
    commands.add(new UserCommand(COMMAND_ID_SHARE, getString(R.string.action_share)));
    commands.add(new UserCommand(COMMAND_ID_VIEW_MORE, getString(R.string.view_more_info)));
    setUserCommands(commands);
}
 
Example #7
Source File: MuzeiArtworkImageLoader.java    From FORMWatchFace with Apache License 2.0 5 votes vote down vote up
@Override
public MuzeiArtworkImageLoader.LoadedArtwork loadInBackground() {
    try {
        Bitmap bitmap = MuzeiContract.Artwork.getCurrentArtworkBitmap(getContext());
        if (bitmap == null) {
            return null;
        }
        Pair<Integer, Integer> p = extractColors(bitmap);
        return new LoadedArtwork(bitmap, p.first, p.second);
    } catch (FileNotFoundException e) {
        Log.e(MuzeiArtworkImageLoader.class.getSimpleName(), "Error getting artwork image", e);
    }
    return null;
}
 
Example #8
Source File: MuzeiImageGenerator.java    From AndroidDemoProjects with Apache License 2.0 5 votes vote down vote up
private void setMuzeiImage( String link ) {
	publishArtwork(new Artwork.Builder()
			.title(getApplication().getResources().getString(R.string.title))
			.imageUri(Uri.parse(link))
			.viewIntent( new Intent(Intent.ACTION_VIEW, Uri.parse( link ) ) )
			.build() );

	scheduleUpdate(System.currentTimeMillis() + ROTATE_TIME_MILLIS);
}
 
Example #9
Source File: MomentArtSource.java    From Moment with GNU General Public License v3.0 4 votes vote down vote up
private void setArtwork(List<Picture> pictures) {
    Random random = new Random();

    int index = random.nextInt(pictures.size());

    Picture picture = pictures.get(index);

    Uri imageUri = Uri.parse("http://ssyer.com" + picture.downloadUrl);

    publishArtwork(new Artwork.Builder()
            .imageUri(imageUri)
            .token(picture.downloadUrl)
            .build());

    int updateTime = PreferenceManager.getIntValue(getApplicationContext(),
            "hour", 6);

    scheduleUpdate(System.currentTimeMillis() + updateTime * 60 * 60 * 1000);
}
 
Example #10
Source File: BiliWallpaperSource.java    From muzei-bilibili with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCustomCommand(int id) {
    super.onCustomCommand(id);
    if (COMMAND_ID_SHARE == id) {
        Artwork currentArtwork = getCurrentArtwork();
        if (currentArtwork == null) {
            Log.w(TAG, "No current artwork, can't share.");
            new Handler(Looper.getMainLooper()).post(new Runnable() {
                @Override
                public void run() {
                    Toast.makeText(BiliWallpaperSource.this,
                            R.string.error_no_wallpaper_to_share,
                            Toast.LENGTH_SHORT).show();
                }
            });
            return;
        }

        String detailUrl = "http://h.bilibili.com/wallpaper?action=detail&il_id="
                + getCurrentArtwork().getToken();
        String artist = currentArtwork.getByline().split("\n")[0];

        Intent shareIntent = new Intent(Intent.ACTION_SEND);
        shareIntent.setType("text/plain");
        shareIntent.putExtra(Intent.EXTRA_TEXT, "#Muze# 分享我的壁纸 \""
                + currentArtwork.getTitle().trim()
                + "\" by " + artist
                + ". \n"
                + detailUrl);
        shareIntent = Intent.createChooser(shareIntent, "分享壁纸");
        shareIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(shareIntent);

    } else if (COMMAND_ID_VIEW_MORE == id) {
        Intent viewIntent = new Intent(Intent.ACTION_VIEW);
        viewIntent.setData(Uri.parse("http://h.bilibili.com/wallpaper?action=detail&il_id="
                + getCurrentArtwork().getToken()));
        viewIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

        try {
            startActivity(viewIntent);
        } catch (ActivityNotFoundException ignored) {
        }
    }
}
 
Example #11
Source File: BiliWallpaperSource.java    From muzei-bilibili with Apache License 2.0 4 votes vote down vote up
@Override
protected void onTryUpdate(int reason) throws RetryException {

    RestAdapter adapter = new RestAdapter.Builder()
            .setEndpoint("http://h.bilibili.com")
            .setExecutors(mExecutor, mMainExecutor)
            .setClient(new ApacheClient(mClient))
            .build();

    BiliWallpaperService service = adapter.create(BiliWallpaperService.class);
    List<Wallpaper> wallpapers = getWallpapers(service);
    if (wallpapers == null) {
        throw new RetryException();
    }
    if (wallpapers.isEmpty()) {
        Log.w(TAG, "No wallpapers returned from API.");
        scheduleUpdate(System.currentTimeMillis() + UPDATE_TIME_MILLIS);
        return;
    }
    wallpapers.remove(0); // first item is banner place holder
    final Wallpaper wallpaper = selectWallpaper(wallpapers);
    final Wallpaper selectedPaper = getDetail(service, wallpaper);
    if (selectedPaper == null) {
        Log.w(TAG, "No details returned for selected paper from API. id=" + wallpaper.il_id);
        throw new RetryException();
    }
    WallpaperManager manager = WallpaperManager.getInstance(getApplicationContext());
    int minimumHeight = manager.getDesiredMinimumHeight();
    final Resolution pic = selectResolution(selectedPaper, minimumHeight);

    publishArtwork(new Artwork.Builder()
            .imageUri((Uri.parse(pic.il_file.replaceFirst("_m\\.", "_l\\."))))
            .title(pic.title)
            .token(String.valueOf(wallpaper.il_id))
            .byline(wallpaper.author_name + ", "
                    + DateFormat.format("yyyy-MM-dd", wallpaper.posttime * 1000)
                    + "\n" + wallpaper.type)
            .viewIntent(new Intent(Intent.ACTION_VIEW,
                    Uri.parse(wallpaper.author_url)))
            .build());
    scheduleUpdate(System.currentTimeMillis() + UPDATE_TIME_MILLIS);
}
 
Example #12
Source File: MuzeiArtworkImageLoader.java    From FORMWatchFace with Apache License 2.0 4 votes vote down vote up
public static boolean hasMuzeiArtwork(Context context) {
    Artwork currentArtwork = MuzeiContract.Artwork.getCurrentArtwork(context);
    return currentArtwork != null;
}