{"id":344,"date":"2015-01-17T17:50:05","date_gmt":"2015-01-17T08:50:05","guid":{"rendered":"http:\/\/morishige.jp\/blog\/?p=344"},"modified":"2015-01-29T04:28:24","modified_gmt":"2015-01-28T19:28:24","slug":"android-tv-recommendation-%e3%81%ae%e8%83%8c%e6%99%afbackground-image%e3%81%ab%e3%81%a4%e3%81%84%e3%81%a6","status":"publish","type":"post","link":"https:\/\/morishige.jp\/blog\/archives\/344","title":{"rendered":"[Android TV] recommendation \u306e\u80cc\u666fbackground image\u306b\u3064\u3044\u3066"},"content":{"rendered":"<blockquote><p>\n2015\/1\/29 \u8ffd\u8a18<br \/>\n\u80cc\u666f\u753b\u50cf\u306e\u30d5\u30a1\u30a4\u30eb\u30b5\u30a4\u30ba\u304c\u5927\u304d\u3044\u3068\u30bf\u30a4\u30e0\u30a2\u30a6\u30c8\u3057\u3066\u80cc\u666f\u8868\u793a\u306b\u5931\u6557\u3057\u307e\u3059\u3002<br \/>\nrecommendation\u3092\u4f5c\u6210\u3059\u308b\u3068\u304d\u306b\u3001\u4e8b\u524d\u306b\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3057\u3066\u30c7\u30a3\u30b9\u30af\u30ad\u30e3\u30c3\u30b7\u30e5\u3057\u307e\u3057\u305f\u3002ContentProvider \u3067\u306f\u3001\u30ad\u30c3\u30b7\u30e5\u3092\u30c1\u30a7\u30c3\u30af\u3057\u3066\u8868\u793a\u3059\u308b\u3053\u3068\u3067\u89e3\u6c7a\u3057\u307e\u3057\u305f\u3002<br \/>\n\u30ad\u30e3\u30c3\u30b7\u30e5\u306b\u306f<a href=\"https:\/\/github.com\/JakeWharton\/DiskLruCache\">DiskLruCache<\/a>\u3092\u4f7f\u7528\u3057\u307e\u3057\u305f\u3002\n<\/p><\/blockquote>\n<p>Android TV \u306e recommendation\u3067\u80cc\u666f\u3092\u8868\u793a\u3059\u308b\u65b9\u6cd5\u304c\u3001\u307b\u307c\u60c5\u5831\u7121\u3057\u72b6\u614b\u3067\u3059\u3002<br \/>\n\u4ed5\u69d8\u5909\u66f4\u304c\u3042\u3063\u305f\u3088\u3046\u3067\u3001sdk\u4ed8\u5c5e\u306e\u30b5\u30f3\u30d7\u30eb\u30b3\u30fc\u30c9\u3082\u80cc\u666f\u53d6\u5f97\u3067\u304d\u306a\u3044\u3042\u308a\u3055\u307e\u3002<br \/>\n\u305d\u3093\u306a\u308f\u3051\u3067\u3001\u30b0\u30b0\u3063\u305f\u308a\u3057\u3064\u3064\u3067\u89e3\u6c7a\u3057\u305f\u306e\u3067\u30e1\u30e2\u3057\u3066\u304a\u304d\u307e\u3059\u3002<br \/>\n\u80cc\u666f\u753b\u50cf\u306f\u3001http:\/\/ \u3067\u53d6\u5f97\u3057\u3066\u8868\u793a\u3059\u308b\u65b9\u6cd5\u3067\u3059\u3002<\/p>\n<p><a href=\"https:\/\/plus.google.com\/100427843958963974912\/posts\/D22DJZkKhDo\">https:\/\/plus.google.com\/100427843958963974912\/posts\/D22DJZkKhDo<\/a><br \/>\n\u304c\u3068\u3066\u3082\u53c2\u8003\u306b\u306a\u308a\u307e\u3057\u305f\u3002Thanks!!<\/p>\n<p>\u307e\u305a\u3001ContentProvider \u3092\u7528\u610f\u3057\u307e\u3059\u3002openFile()\u306e\u307f\u5fc5\u8981\u3067\u3042\u3068\u306f\u7a7a\u3063\u307d\u3067\u5927\u4e08\u592b\u3067\u3059\u3002<br \/>\nurl.openStream()\u3092\u6e21\u3059\u3068\u3053\u308d\u306f\u3053\u308c\u3067\u826f\u3044\u306e\u304b\uff1f\u3068\u601d\u3063\u305f\u3051\u3069\u3001\u307e\u3042\u52d5\u3044\u3066\u307e\u3059 \ud83d\ude00<\/p>\n<p><code><\/p>\n<pre>\r\npublic class RecommendationContentProvider extends ContentProvider {\r\n\t\r\n\tpublic static String AUTHORITY = \"your unique authority here\";\r\n\tpublic static String CONTENT_URI = \"content:\/\/\" + AUTHORITY + \"\/\";\r\n\t\r\n\t@Override\r\n\tpublic ParcelFileDescriptor openFile(Uri uri, String mode) throws FileNotFoundException {\r\n\t\tParcelFileDescriptor[] pipe = null;\r\n\t\tString path = uri.getPath();\r\n\t\ttry {\r\n\t\t\tString decodedUrl = URLDecoder.decode(path.replaceFirst(\"\/\", \"\"), HTTP.UTF_8);\r\n\t\t\tpipe = ParcelFileDescriptor.createPipe();\r\n\t\t\tURL url = new URL(decodedUrl);\r\n\t\t\tnew TransferThread(url.openStream(),\r\n\t\t\t\tnew ParcelFileDescriptor.AutoCloseOutputStream(pipe[1])).start();\r\n\t\t} catch (UnsupportedEncodingException e) {\r\n\t\t\te.printStackTrace();\r\n\t\t} catch (IOException e) {\r\n\t\t\te.printStackTrace();\r\n\t\t}\r\n\t\treturn pipe[0];\r\n\t}\r\n\t\r\n\tstatic class TransferThread extends Thread {\r\n\t\tInputStream in;\r\n\t\tOutputStream out;\r\n\t\t\r\n\t\tpublic TransferThread(InputStream in, OutputStream out) {\r\n\t\t\tthis.in = in;\r\n\t\t\tthis.out = out;\r\n\t\t}\r\n\t\t\r\n\t\t@Override\r\n\t\tpublic void run() {\r\n\t\t\tbyte[] buf = new byte[8192];\r\n\t\t\tint len;\r\n\t\t\t\r\n\t\t\ttry {\r\n\t\t\t\twhile ((len = in.read(buf)) > 0) {\r\n\t\t\t\t\tout.write(buf, 0, len);\r\n\t\t\t\t}\r\n\t\t\t\tin.close();\r\n\t\t\t\tout.flush();\r\n\t\t\t\tout.close();\r\n\t\t\t} catch (IOException e) {\r\n\t\t\t\te.printStackTrace();\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\t\r\n\t@Override\r\n\tpublic boolean onCreate() {\r\n\t\treturn true;\r\n\t}\r\n\r\n\t@Override\r\n\tpublic Cursor query(Uri uri, String[] projection,\r\n\t\t\tString selection, String[] selectionArgs, String sortOrder) {\r\n\t\treturn null;\r\n\t}\r\n\r\n\t@Override\r\n\tpublic String getType(Uri uri) {\r\n\t\treturn \"image\/*\";\r\n\t}\r\n\r\n\t@Override\r\n\tpublic Uri insert(Uri uri, ContentValues values) {\r\n\t\treturn null;\r\n\t}\r\n\r\n\t@Override\r\n\tpublic int delete(Uri uri, String selection, String[] selectionArgs) {\r\n\t\treturn 0;\r\n\t}\r\n\r\n\t@Override\r\n\tpublic int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {\r\n\t\treturn 0;\r\n\t}\r\n}\r\n<\/pre>\n<p><\/code><\/p>\n<p>ContentProvider\u306f\u3001AndroidManifest.xml \u306b\u8a18\u8f09\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<br \/>\n<code><\/p>\n<pre>\r\n\t&lt;application&gt;\r\n\t\t...snip...\r\n\t\t&lt;provider\r\n\t\t\tandroid:name=\"packagename.RecommendationContentProvider\"\r\n\t\t\tandroid:authorities=\"your unique authority here\"\r\n\t\t\tandroid:exported=\"true\"&gt;\r\n\t\t&lt;\/provider&gt;\r\n<\/pre>\n<p><\/code><\/p>\n<p>\u3042\u3068\u306f\u3001Notification\u306e\u4f5c\u6210\u3060\u3051\u3067\u3059\u3002<br \/>\n<code><\/p>\n<pre>\r\n\tBundle extras = new Bundle();\r\n\textras.putString(\r\n\t\tNotification.EXTRA_BACKGROUND_IMAGE_URI,\r\n\t\tRecommendationContentProvider.CONTENT_URI + URLEncoder.encode(data.getBgImageUrl(), HTTP.UTF_8));\r\n\r\n\tNotification notification = new NotificationCompat.BigPictureStyle(\r\n\t\t\tnew NotificationCompat.Builder(context)\r\n\t\t\t.setContentTitle(data.getTitle())\r\n\t\t\t.setContentText(data.getBody())\r\n\t\t\t...snip...\r\n\t\t\t.setExtras(extras)\r\n\t).build();\r\n<\/pre>\n<p><\/code><\/p>\n<p>\u4ee5\u4e0a<\/p>\n","protected":false},"excerpt":{"rendered":"<p>2015\/1\/29 \u8ffd\u8a18 \u80cc\u666f\u753b\u50cf\u306e\u30d5\u30a1\u30a4\u30eb\u30b5\u30a4\u30ba\u304c\u5927\u304d\u3044\u3068\u30bf\u30a4\u30e0\u30a2\u30a6\u30c8\u3057\u3066\u80cc\u666f\u8868\u793a\u306b\u5931\u6557\u3057\u307e\u3059\u3002 recommendation\u3092\u4f5c\u6210\u3059\u308b\u3068\u304d\u306b\u3001\u4e8b\u524d\u306b\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3057\u3066\u30c7\u30a3\u30b9\u30af\u30ad\u30e3\u30c3\u30b7\u30e5\u3057\u307e\u3057\u305f\u3002ContentProvi [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,6],"tags":[],"class_list":["post-344","post","type-post","status-publish","format-standard","hentry","category-java","category-dev"],"_links":{"self":[{"href":"https:\/\/morishige.jp\/blog\/wp-json\/wp\/v2\/posts\/344","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/morishige.jp\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/morishige.jp\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/morishige.jp\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/morishige.jp\/blog\/wp-json\/wp\/v2\/comments?post=344"}],"version-history":[{"count":8,"href":"https:\/\/morishige.jp\/blog\/wp-json\/wp\/v2\/posts\/344\/revisions"}],"predecessor-version":[{"id":353,"href":"https:\/\/morishige.jp\/blog\/wp-json\/wp\/v2\/posts\/344\/revisions\/353"}],"wp:attachment":[{"href":"https:\/\/morishige.jp\/blog\/wp-json\/wp\/v2\/media?parent=344"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/morishige.jp\/blog\/wp-json\/wp\/v2\/categories?post=344"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/morishige.jp\/blog\/wp-json\/wp\/v2\/tags?post=344"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}