1 /* 2 * Copyright (C) 2017 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package com.android.wallpaper.picker; 17 18 import android.content.Context; 19 import android.content.res.Resources; 20 import android.util.Log; 21 22 import com.android.wallpaper.R; 23 import com.android.wallpaper.model.WallpaperInfo; 24 import com.android.wallpaper.module.WallpaperPreferences; 25 import com.android.wallpaper.module.WallpaperPreferences.PresentationMode; 26 27 import java.util.List; 28 29 /** 30 * Methods for formatting attribution-related strings. 31 */ 32 public class AttributionFormatter { 33 private static final String TAG = "AttributionFormatter"; 34 35 /** 36 * Returns human-readable subtitle based on 2nd and 3rd items in wallpaper attributions or an 37 * empty string if neither attribution line is available. 38 */ formatWallpaperSubtitle(Context context, WallpaperInfo wallpaper)39 public static String formatWallpaperSubtitle(Context context, WallpaperInfo wallpaper) { 40 List<String> attributions = wallpaper.getAttributions(context); 41 String subtitle = ""; 42 if (attributions.size() > 1 && attributions.get(1) != null) { 43 subtitle += attributions.get(1); 44 } 45 if (attributions.size() > 2 && attributions.get(2) != null) { 46 subtitle += " • " + attributions.get(2); 47 } 48 return subtitle; 49 } 50 51 /** 52 * Returns human-readable string for the given wallpaper presentation mode. 53 */ getHumanReadableWallpaperPresentationMode( Context context, @PresentationMode int presentationMode)54 public static String getHumanReadableWallpaperPresentationMode( 55 Context context, @PresentationMode int presentationMode) { 56 57 Resources resources = context.getResources(); 58 59 switch (presentationMode) { 60 case WallpaperPreferences.PRESENTATION_MODE_STATIC: 61 return ""; 62 case WallpaperPreferences.PRESENTATION_MODE_ROTATING: 63 return resources.getString(R.string.rotating_wallpaper_presentation_mode_message); 64 default: 65 Log.e(TAG, "No matching human-readable string for wallpaper presentation mode: " 66 + presentationMode); 67 return ""; 68 } 69 } 70 } 71