Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(24)

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/download/DownloadUtils.java

Issue 2721043002: [NTP::Downloads] Scale up type based icons. (Closed)
Patch Set: clean rebase. Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.chrome.browser.download; 5 package org.chromium.chrome.browser.download;
6 6
7 import android.app.Activity; 7 import android.app.Activity;
8 import android.app.PendingIntent; 8 import android.app.PendingIntent;
9 import android.content.ActivityNotFoundException; 9 import android.content.ActivityNotFoundException;
10 import android.content.Context; 10 import android.content.Context;
(...skipping 631 matching lines...) Expand 10 before | Expand all | Expand 10 after
642 } else { 642 } else {
643 resourceId = stringSet[2]; 643 resourceId = stringSet[2];
644 bytesInCorrectUnits = bytes / (float) BYTES_PER_GIGABYTE; 644 bytesInCorrectUnits = bytes / (float) BYTES_PER_GIGABYTE;
645 } 645 }
646 646
647 return context.getResources().getString(resourceId, bytesInCorrectUnits) ; 647 return context.getResources().getString(resourceId, bytesInCorrectUnits) ;
648 } 648 }
649 649
650 /** 650 /**
651 * Abbreviate a file name into a given number of characters with ellipses. 651 * Abbreviate a file name into a given number of characters with ellipses.
652 * e.g. thisisaverylongfilename.txt => thisisave....txt 652 * e.g. thisisaverylongfilename.txt => thisisave....txt.
gone 2017/02/28 18:46:25 I'd remove this period; it makes the example ambig
vitaliii 2017/03/01 09:08:30 Done. "thisisaverylongfilename.txt" => "thisisave
653 * @param fileName File name to abbreviate 653 * @param fileName File name to abbreviate.
654 * @param limit Character limit 654 * @param limit Character limit.
655 * @return Abbreviated file name 655 * @return Abbreviated file name.
656 */ 656 */
657 public static String getAbbreviatedFileName(String fileName, int limit) { 657 public static String getAbbreviatedFileName(String fileName, int limit) {
658 assert limit >= 1; // Abbreviated file name should at least be 1 charac ters (a...) 658 assert limit >= 1; // Abbreviated file name should at least be 1 charac ters (a...)
659 659
660 if (TextUtils.isEmpty(fileName)) return fileName; 660 if (TextUtils.isEmpty(fileName)) return fileName;
661 661
662 if (fileName.length() <= limit) return fileName; 662 if (fileName.length() <= limit) return fileName;
663 663
664 // Find the file name extension 664 // Find the file name extension
665 int index = fileName.lastIndexOf("."); 665 int index = fileName.lastIndexOf(".");
666 int extensionLength = fileName.length() - index; 666 int extensionLength = fileName.length() - index;
667 667
668 // If the extension is too long, just use truncate the string from begin ning. 668 // If the extension is too long, just use truncate the string from begin ning.
669 if (extensionLength >= limit) { 669 if (extensionLength >= limit) {
670 return fileName.substring(0, limit) + ELLIPSIS; 670 return fileName.substring(0, limit) + ELLIPSIS;
671 } 671 }
672 int remainingLength = limit - extensionLength; 672 int remainingLength = limit - extensionLength;
673 return fileName.substring(0, remainingLength) + ELLIPSIS + fileName.subs tring(index); 673 return fileName.substring(0, remainingLength) + ELLIPSIS + fileName.subs tring(index);
674 } 674 }
675 675
676 /** 676 /**
677 * Return an icon for a given file type. 677 * Return an icon for a given file type.
678 * @param fileType Type of the file as returned by DownloadFilter 678 * @param fileType Type of the file as returned by DownloadFilter.
679 * @return Resource ID of the corresponding icon 679 * @param sizeDp Size in device pixels of the returned icon.
680 * @return Resource ID of the corresponding icon.
680 */ 681 */
681 public static int getIconResId(int fileType) { 682 public static int getIconResId(int fileType, int sizeDp) {
683 assert sizeDp == 24 || sizeDp == 36;
dgn 2017/02/28 18:30:16 nit: use 2 @IntDef constants to make clear through
vitaliii 2017/03/01 09:08:30 Done.
682 switch (fileType) { 684 switch (fileType) {
683 case DownloadFilter.FILTER_PAGE: 685 case DownloadFilter.FILTER_PAGE:
684 return R.drawable.ic_drive_site_white_24dp; 686 return sizeDp == 24 ? R.drawable.ic_drive_site_white_24dp
687 : R.drawable.ic_drive_site_white_36dp;
685 case DownloadFilter.FILTER_VIDEO: 688 case DownloadFilter.FILTER_VIDEO:
686 return R.drawable.ic_play_arrow_white_24dp; 689 return sizeDp == 24 ? R.drawable.ic_play_arrow_white_24dp
690 : R.drawable.ic_play_arrow_white_36dp;
687 case DownloadFilter.FILTER_AUDIO: 691 case DownloadFilter.FILTER_AUDIO:
688 return R.drawable.ic_music_note_white_24dp; 692 return sizeDp == 24 ? R.drawable.ic_music_note_white_24dp
693 : R.drawable.ic_music_note_white_36dp;
689 case DownloadFilter.FILTER_IMAGE: 694 case DownloadFilter.FILTER_IMAGE:
690 return R.drawable.ic_image_white_24dp; 695 return sizeDp == 24 ? R.drawable.ic_image_white_24dp
696 : R.drawable.ic_image_white_36dp;
691 case DownloadFilter.FILTER_DOCUMENT: 697 case DownloadFilter.FILTER_DOCUMENT:
692 return R.drawable.ic_drive_text_white_24dp; 698 return sizeDp == 24 ? R.drawable.ic_drive_text_white_24dp
699 : R.drawable.ic_drive_text_white_36dp;
693 default: 700 default:
694 return R.drawable.ic_drive_file_white_24dp; 701 return sizeDp == 24 ? R.drawable.ic_drive_file_white_24dp
702 : R.drawable.ic_drive_text_white_36dp;
695 } 703 }
696 } 704 }
697 705
698 /** 706 /**
699 * Return a background color for the file type icon. 707 * Return a background color for the file type icon.
700 * @param context Context from which to extract the resources 708 * @param context Context from which to extract the resources.
701 * @return Background color 709 * @return Background color.
702 */ 710 */
703 public static int getIconBackgroundColor(Context context) { 711 public static int getIconBackgroundColor(Context context) {
704 return ApiCompatibilityUtils.getColor(context.getResources(), R.color.li ght_active_color); 712 return ApiCompatibilityUtils.getColor(context.getResources(), R.color.li ght_active_color);
705 } 713 }
706 714
707 /** 715 /**
708 * Return a foreground color list for the file type icon. 716 * Return a foreground color list for the file type icon.
709 * @param context Context from which to extract the resources 717 * @param context Context from which to extract the resources.
710 * @return a foreground color list 718 * @return a foreground color list.
711 */ 719 */
712 public static ColorStateList getIconForegroundColorList(Context context) { 720 public static ColorStateList getIconForegroundColorList(Context context) {
713 return ApiCompatibilityUtils.getColorStateList( 721 return ApiCompatibilityUtils.getColorStateList(
714 context.getResources(), R.color.white_mode_tint); 722 context.getResources(), R.color.white_mode_tint);
715 } 723 }
716 724
717 private static boolean isMimeTypeVideo(String mimeType) { 725 private static boolean isMimeTypeVideo(String mimeType) {
718 if (TextUtils.isEmpty(mimeType)) return false; 726 if (TextUtils.isEmpty(mimeType)) return false;
719 727
720 String[] pieces = mimeType.split(MIME_TYPE_DELIMITER); 728 String[] pieces = mimeType.split(MIME_TYPE_DELIMITER);
721 if (pieces.length != 2) return false; 729 if (pieces.length != 2) return false;
722 730
723 return MIME_TYPE_VIDEO.equals(pieces[0]); 731 return MIME_TYPE_VIDEO.equals(pieces[0]);
724 } 732 }
725 } 733 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698