├── .gitattributes ├── .gitignore ├── fuzzydateandroid-lib ├── AndroidManifest.xml ├── build.xml ├── proguard-project.txt ├── proguard.cfg ├── project.properties ├── res │ ├── drawable-hdpi │ │ └── ic_launcher.png │ ├── drawable-ldpi │ │ └── ic_launcher.png │ ├── drawable-mdpi │ │ └── ic_launcher.png │ └── values │ │ └── fuzzy_date_strings.xml └── src │ └── com │ └── fuzzydate │ └── android │ ├── FuzzingConfiguration.java │ ├── FuzzingStrength.java │ ├── FuzzyDateFormat.java │ ├── FuzzyDateFormatter.java │ └── impl │ ├── .svn │ ├── all-wcprops │ ├── entries │ ├── prop-base │ │ ├── DefaultFuzzingConfiguration.java.svn-base │ │ ├── FuzzyDateFormatterImpl.java.svn-base │ │ └── Range.java.svn-base │ └── text-base │ │ ├── DefaultFuzzingConfiguration.java.svn-base │ │ ├── FuzzyDateFormatterImpl.java.svn-base │ │ └── Range.java.svn-base │ ├── DefaultFuzzingConfiguration.java │ ├── FuzzyDateFormatterImpl.java │ └── Range.java ├── fuzzydateandroid-sample ├── AndroidManifest.xml ├── build.xml ├── libs │ ├── android-support-v4.jar │ └── junit-4.8.1.jar ├── proguard-project.txt ├── project.properties ├── res │ ├── drawable-hdpi │ │ ├── ic_action_search.png │ │ └── ic_launcher.png │ ├── drawable-mdpi │ │ ├── ic_action_search.png │ │ └── ic_launcher.png │ ├── drawable-xhdpi │ │ ├── ic_action_search.png │ │ └── ic_launcher.png │ ├── layout │ │ └── activity_test.xml │ ├── values-v11 │ │ └── styles.xml │ ├── values-v14 │ │ └── styles.xml │ └── values │ │ ├── strings.xml │ │ └── styles.xml └── src │ └── com │ └── fuzzydate │ └── android │ ├── sample │ ├── TestActivity.java │ └── Utils.java │ └── test │ └── FuzzyDateFormatImplTest.java └── readme /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | *.sln merge=union 7 | *.csproj merge=union 8 | *.vbproj merge=union 9 | *.fsproj merge=union 10 | *.dbproj merge=union 11 | 12 | # Standard to msysgit 13 | *.doc diff=astextplain 14 | *.DOC diff=astextplain 15 | *.docx diff=astextplain 16 | *.DOCX diff=astextplain 17 | *.dot diff=astextplain 18 | *.DOT diff=astextplain 19 | *.pdf diff=astextplain 20 | *.PDF diff=astextplain 21 | *.rtf diff=astextplain 22 | *.RTF diff=astextplain 23 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ################# 2 | ## Eclipse 3 | ################# 4 | 5 | *.pydevproject 6 | .project 7 | .metadata 8 | bin/ 9 | gen/ 10 | tmp/ 11 | *.tmp 12 | *.bak 13 | *.swp 14 | *~.nib 15 | local.properties 16 | .classpath 17 | .settings/ 18 | .loadpath 19 | 20 | # External tool builders 21 | .externalToolBuilders/ 22 | 23 | # Locally stored "Eclipse launch configurations" 24 | *.launch 25 | 26 | # CDT-specific 27 | .cproject 28 | 29 | # PDT-specific 30 | .buildpath 31 | 32 | 33 | ################# 34 | ## Visual Studio 35 | ################# 36 | 37 | ## Ignore Visual Studio temporary files, build results, and 38 | ## files generated by popular Visual Studio add-ons. 39 | 40 | # User-specific files 41 | *.suo 42 | *.user 43 | *.sln.docstates 44 | 45 | # Build results 46 | [Dd]ebug/ 47 | [Rr]elease/ 48 | *_i.c 49 | *_p.c 50 | *.ilk 51 | *.meta 52 | *.obj 53 | *.pch 54 | *.pdb 55 | *.pgc 56 | *.pgd 57 | *.rsp 58 | *.sbr 59 | *.tlb 60 | *.tli 61 | *.tlh 62 | *.tmp 63 | *.vspscc 64 | .builds 65 | *.dotCover 66 | 67 | ## TODO: If you have NuGet Package Restore enabled, uncomment this 68 | #packages/ 69 | 70 | # Visual C++ cache files 71 | ipch/ 72 | *.aps 73 | *.ncb 74 | *.opensdf 75 | *.sdf 76 | 77 | # Visual Studio profiler 78 | *.psess 79 | *.vsp 80 | 81 | # ReSharper is a .NET coding add-in 82 | _ReSharper* 83 | 84 | # Installshield output folder 85 | [Ee]xpress 86 | 87 | # DocProject is a documentation generator add-in 88 | DocProject/buildhelp/ 89 | DocProject/Help/*.HxT 90 | DocProject/Help/*.HxC 91 | DocProject/Help/*.hhc 92 | DocProject/Help/*.hhk 93 | DocProject/Help/*.hhp 94 | DocProject/Help/Html2 95 | DocProject/Help/html 96 | 97 | # Click-Once directory 98 | publish 99 | 100 | # Others 101 | [Bb]in 102 | [Oo]bj 103 | sql 104 | TestResults 105 | *.Cache 106 | ClientBin 107 | stylecop.* 108 | ~$* 109 | *.dbmdl 110 | Generated_Code #added for RIA/Silverlight projects 111 | 112 | # Backup & report files from converting an old project file to a newer 113 | # Visual Studio version. Backup files are not needed, because we have git ;-) 114 | _UpgradeReport_Files/ 115 | Backup*/ 116 | UpgradeLog*.XML 117 | 118 | 119 | 120 | ############ 121 | ## Windows 122 | ############ 123 | 124 | # Windows image file caches 125 | Thumbs.db 126 | 127 | # Folder config file 128 | Desktop.ini 129 | 130 | 131 | ############# 132 | ## Python 133 | ############# 134 | 135 | *.py[co] 136 | 137 | # Packages 138 | *.egg 139 | *.egg-info 140 | dist 141 | build 142 | eggs 143 | parts 144 | bin 145 | var 146 | sdist 147 | develop-eggs 148 | .installed.cfg 149 | 150 | # Installer logs 151 | pip-log.txt 152 | 153 | # Unit test / coverage reports 154 | .coverage 155 | .tox 156 | 157 | #Translations 158 | *.mo 159 | 160 | #Mr Developer 161 | .mr.developer.cfg 162 | 163 | # Mac crap 164 | .DS_Store 165 | -------------------------------------------------------------------------------- /fuzzydateandroid-lib/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /fuzzydateandroid-lib/build.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 9 | 29 | 30 | 31 | 35 | 36 | 37 | 38 | 39 | 40 | 49 | 50 | 51 | 52 | 56 | 57 | 69 | 70 | 71 | 89 | 90 | 91 | 92 | 93 | -------------------------------------------------------------------------------- /fuzzydateandroid-lib/proguard-project.txt: -------------------------------------------------------------------------------- 1 | # To enable ProGuard in your project, edit project.properties 2 | # to define the proguard.config property as described in that file. 3 | # 4 | # Add project specific ProGuard rules here. 5 | # By default, the flags in this file are appended to flags specified 6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt 7 | # You can edit the include path and order by changing the ProGuard 8 | # include property in project.properties. 9 | # 10 | # For more details, see 11 | # http://developer.android.com/guide/developing/tools/proguard.html 12 | 13 | # Add any project specific keep options here: 14 | 15 | # If your project uses WebView with JS, uncomment the following 16 | # and specify the fully qualified class name to the JavaScript interface 17 | # class: 18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 19 | # public *; 20 | #} 21 | -------------------------------------------------------------------------------- /fuzzydateandroid-lib/proguard.cfg: -------------------------------------------------------------------------------- 1 | -optimizationpasses 5 2 | -dontusemixedcaseclassnames 3 | -dontskipnonpubliclibraryclasses 4 | -dontpreverify 5 | -verbose 6 | -optimizations !code/simplification/arithmetic,!field/*,!class/merging/* 7 | 8 | -keep public class * extends android.app.Activity 9 | -keep public class * extends android.app.Application 10 | -keep public class * extends android.app.Service 11 | -keep public class * extends android.content.BroadcastReceiver 12 | -keep public class * extends android.content.ContentProvider 13 | -keep public class * extends android.app.backup.BackupAgentHelper 14 | -keep public class * extends android.preference.Preference 15 | -keep public class com.android.vending.licensing.ILicensingService 16 | 17 | -keepclasseswithmembernames class * { 18 | native ; 19 | } 20 | 21 | -keepclasseswithmembers class * { 22 | public (android.content.Context, android.util.AttributeSet); 23 | } 24 | 25 | -keepclasseswithmembers class * { 26 | public (android.content.Context, android.util.AttributeSet, int); 27 | } 28 | 29 | -keepclassmembers class * extends android.app.Activity { 30 | public void *(android.view.View); 31 | } 32 | 33 | -keepclassmembers enum * { 34 | public static **[] values(); 35 | public static ** valueOf(java.lang.String); 36 | } 37 | 38 | -keep class * implements android.os.Parcelable { 39 | public static final android.os.Parcelable$Creator *; 40 | } 41 | -------------------------------------------------------------------------------- /fuzzydateandroid-lib/project.properties: -------------------------------------------------------------------------------- 1 | # This file is automatically generated by Android Tools. 2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED! 3 | # 4 | # This file must be checked in Version Control Systems. 5 | # 6 | # To customize properties used by the Ant build system use, 7 | # "ant.properties", and override values to adapt the script to your 8 | # project structure. 9 | 10 | # Project target. 11 | target=android-8 12 | android.library=true 13 | -------------------------------------------------------------------------------- /fuzzydateandroid-lib/res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scottyab/FuzzyDateAndroid/b7955bb56f2efc2b6e33888c20f1348a8213d2ee/fuzzydateandroid-lib/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /fuzzydateandroid-lib/res/drawable-ldpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scottyab/FuzzyDateAndroid/b7955bb56f2efc2b6e33888c20f1348a8213d2ee/fuzzydateandroid-lib/res/drawable-ldpi/ic_launcher.png -------------------------------------------------------------------------------- /fuzzydateandroid-lib/res/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scottyab/FuzzyDateAndroid/b7955bb56f2efc2b6e33888c20f1348a8213d2ee/fuzzydateandroid-lib/res/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /fuzzydateandroid-lib/res/values/fuzzy_date_strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | FuzzyDateAndroid 5 | tomorrow 6 | the day after tomorrow 7 | yesterday 8 | a century 9 | two centuries 10 | %s centuries 11 | a day 12 | two days 13 | %s days 14 | long time 15 | in %s 16 | an hour 17 | two hours 18 | %s hours 19 | a minute 20 | two minutes 21 | %s minutes 22 | a month 23 | two months 24 | %s months 25 | %s ago 26 | a week 27 | two weeks 28 | %s weeks 29 | a year 30 | two years 31 | %s years 32 | a century 33 | two centuries 34 | %s centuries 35 | a day 36 | two days 37 | %s days 38 | eternal 39 | an hour 40 | two hours 41 | %s hours 42 | a minute 43 | two minutes 44 | %s minutes 45 | a month 46 | two months 47 | %s months 48 | a week 49 | two weeks 50 | %s weeks 51 | a year 52 | two years 53 | %s years 54 | twelve 55 | one 56 | ten 57 | eleven 58 | twelve 59 | thirteen 60 | fourteen 61 | fifteen 62 | sixteen 63 | seventeen 64 | six 65 | seven 66 | two 67 | eight 68 | nine 69 | ten 70 | eleven 71 | three 72 | four 73 | five 74 | six 75 | seven 76 | eight 77 | nine 78 | early morning 79 | 0 80 | morning 81 | 5 82 | noon 83 | 11 84 | afternoon 85 | 14 86 | evening 87 | 18 88 | night 89 | 21 90 | midnight 91 | 23.5 92 | %s o\'clock 93 | %s o\'clock 94 | quarter past %s 95 | half past %s 96 | half past %s 97 | quarter to %s 98 | quarter to %s 99 | this week 100 | next week 101 | %s weeks 102 | last week 103 | Cannot find fuzzy time 104 | -------------------------------------------------------------------------------- /fuzzydateandroid-lib/src/com/fuzzydate/android/FuzzingConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.fuzzydate.android; 2 | 3 | import android.content.Context; 4 | 5 | import com.fuzzydate.android.impl.Range; 6 | 7 | /** 8 | * An object that represents a configuration for date and duration fuzzing. 9 | * 10 | *

11 | * A fuzzing configuration is a set of ranges which are mapped to 12 | * internationalized strings (via String resources). Each of these ranges 13 | * represents a special human understanding of a distance of time or duration. 14 | * 15 | * @author ma� 16 | */ 17 | public interface FuzzingConfiguration { 18 | // ~ Methods 19 | // ---------------------------------------------------------------- 20 | 21 | /** 22 | * This method returns an array of range objects. These are used to map 23 | * ranges of relative distances of time to a string resource id. 24 | * 25 | * @param strenght 26 | * the fuzzing strength defining the granularity of ranges to 27 | * return. 28 | * 29 | * @return an array of ranges for distances of time. 30 | */ 31 | Range[] getDistanceRanges(FuzzingStrength strenght); 32 | 33 | /** 34 | * This method returns an array of range objects. These are used to map 35 | * ranges of relative durations of time to a string resource id. 36 | * 37 | * @param strenght 38 | * the fuzzing strength defining the granularity of ranges to 39 | * return. 40 | * 41 | * @return an array of ranges for duration of time. 42 | */ 43 | Range[] getDurationRanges(FuzzingStrength strenght); 44 | 45 | /** 46 | * This method returns an array of range objects. These are used to map 47 | * ranges of hours to a string resource id. 48 | * 49 | * @param strenght 50 | * the fuzzing strength defining the granularity of ranges to 51 | * return. 52 | * 53 | * @return an array of ranges for duration of time. 54 | */ 55 | Range[] getHourRanges(FuzzingStrength strenght); 56 | 57 | /** 58 | * Get a fuzzy string with a given range 59 | * 60 | * @param range 61 | * @param context 62 | * android context used to lookup resources 63 | * @param params 64 | * 65 | * @return 66 | */ 67 | String getFuzzyString(Range range, Context context, Object... params); 68 | 69 | /** 70 | * Get a fuzzy string with a given resource Id 71 | * 72 | * @param resId 73 | * Resource Id of the string to use 74 | * @param context 75 | * android context used to lookup resources 76 | * @param params 77 | * 78 | * @return 79 | */ 80 | String getFuzzyString(int resId, Context context, Object... params); 81 | } 82 | -------------------------------------------------------------------------------- /fuzzydateandroid-lib/src/com/fuzzydate/android/FuzzingStrength.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scottyab/FuzzyDateAndroid/b7955bb56f2efc2b6e33888c20f1348a8213d2ee/fuzzydateandroid-lib/src/com/fuzzydate/android/FuzzingStrength.java -------------------------------------------------------------------------------- /fuzzydateandroid-lib/src/com/fuzzydate/android/FuzzyDateFormat.java: -------------------------------------------------------------------------------- 1 | package com.fuzzydate.android; 2 | 3 | import android.content.Context; 4 | 5 | import com.fuzzydate.android.impl.DefaultFuzzingConfiguration; 6 | import com.fuzzydate.android.impl.FuzzyDateFormatterImpl; 7 | 8 | /** 9 | * FuzzyDateFormat is a factory for creating instances of fuzzy time/date 10 | * formatters. These formatters format time/date, distances of time and 11 | * durations to internationalized strings. 12 | * 13 | * @author amaasch 14 | */ 15 | public final class FuzzyDateFormat { 16 | /** 17 | * Creates a fuzzy date formatter instance with the static default 18 | * configuration. 19 | * 20 | * @return a fuzzy date formatter instance. 21 | */ 22 | public static final FuzzyDateFormatter getInstance(final Context context) { 23 | return new FuzzyDateFormatterImpl( 24 | DefaultFuzzingConfiguration.getInstance(), context); 25 | } 26 | 27 | /** 28 | * Creates a fuzzy date formatter instance with a given configuration. 29 | * 30 | * @param config 31 | * the configuration for the date formatter. 32 | * 33 | * @return a fuzzy date formatter instance. 34 | */ 35 | public static final FuzzyDateFormatter getInstance( 36 | final FuzzingConfiguration config, final Context context) { 37 | return new FuzzyDateFormatterImpl(config, context); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /fuzzydateandroid-lib/src/com/fuzzydate/android/FuzzyDateFormatter.java: -------------------------------------------------------------------------------- 1 | package com.fuzzydate.android; 2 | 3 | import java.util.Date; 4 | 5 | /** 6 | * Formatter for human readable dates, distances of time and durations. 7 | * 8 | *

9 | * Use the {@link #format(Date)} methods to create relative strings like 10 | * "today", "last friday". These dates are used to tell the a user when an event 11 | * has happened or will happen. The string will be built relative to the current 12 | * time/date. 13 | * 14 | *

15 | * Use the {@link #formatDistance(Date)} methods to create strings for distances 16 | * of time such as "in 5 days", "a month ago". This format is used to tell the 17 | * user how much time has passed since an event or how much time is left before 18 | * something happens. These strings will also be built relative to the current 19 | * date/time. 20 | * 21 | *

22 | * Use the {@link #formatDuration(long)} methods to create strings representing 23 | * the time between two events, like "5 minutes", "two centuries". These strings 24 | * are used for durations of processes. Calling this method with a single date 25 | * will calculate the duration from this date to the current time. 26 | * 27 | * 28 | * @author amaasch 29 | */ 30 | public interface FuzzyDateFormatter { 31 | 32 | /** 33 | * Creates a string representing a point in time in reference to the current 34 | * time/date. Use this method to tell the a user when an event has happened 35 | * or will happen. This method uses the strings resources to format the 36 | * string. 37 | * 38 | * @param date 39 | * the date to be formatted as fuzzy string. 40 | * 41 | * @return a fuzzy string representing a point in time. 42 | */ 43 | String format(Date date); 44 | 45 | /** 46 | * Creates a string representing a distance to a given date. Use this method 47 | * to tell the user how much time has passed since an event or how much time 48 | * is left before something happens. This method uses the strings resources 49 | * to format the string. 50 | * 51 | * @param date 52 | * the relative date to which the relative distance will be 53 | * formatted as fuzzy string. 54 | * 55 | * @return a fuzzy string representing the distance from the current time. 56 | */ 57 | String formatDistance(Date date); 58 | 59 | /** 60 | * Creates a string representing a duration. Use this method to tell the 61 | * user how much time has passes between two events. This method uses the 62 | * strings resources to format the string. 63 | * 64 | * @param milliSeconds 65 | * a duration specified by a number of milliseconds. 66 | * 67 | * @return a fuzzy string representing the duration between two events. 68 | */ 69 | String formatDuration(long milliSeconds); 70 | 71 | /** 72 | * Creates a string representing a duration. Use this method to tell the 73 | * user how much time has passes between two events. This method uses the 74 | * strings resources to format the string. 75 | * 76 | * @param relative 77 | * the given related date/time. 78 | * 79 | * @return a fuzzy string representing the duration between the given and 80 | * the current date/time. 81 | */ 82 | String formatDuration(Date relative); 83 | 84 | } 85 | -------------------------------------------------------------------------------- /fuzzydateandroid-lib/src/com/fuzzydate/android/impl/.svn/all-wcprops: -------------------------------------------------------------------------------- 1 | K 25 2 | svn:wc:ra_dav:version-url 3 | V 74 4 | /svnroot/jfuzzydate/!svn/ver/10/trunk/src/main/java/net/sf/jfuzzydate/impl 5 | END 6 | DefaultFuzzingConfiguration.java 7 | K 25 8 | svn:wc:ra_dav:version-url 9 | V 106 10 | /svnroot/jfuzzydate/!svn/ver/5/trunk/src/main/java/net/sf/jfuzzydate/impl/DefaultFuzzingConfiguration.java 11 | END 12 | FuzzyDateFormatterImpl.java 13 | K 25 14 | svn:wc:ra_dav:version-url 15 | V 102 16 | /svnroot/jfuzzydate/!svn/ver/10/trunk/src/main/java/net/sf/jfuzzydate/impl/FuzzyDateFormatterImpl.java 17 | END 18 | Range.java 19 | K 25 20 | svn:wc:ra_dav:version-url 21 | V 85 22 | /svnroot/jfuzzydate/!svn/ver/10/trunk/src/main/java/net/sf/jfuzzydate/impl/Range.java 23 | END 24 | -------------------------------------------------------------------------------- /fuzzydateandroid-lib/src/com/fuzzydate/android/impl/.svn/entries: -------------------------------------------------------------------------------- 1 | 10 2 | 3 | dir 4 | 40 5 | https://jfuzzydate.svn.sourceforge.net/svnroot/jfuzzydate/trunk/src/main/java/net/sf/jfuzzydate/impl 6 | https://jfuzzydate.svn.sourceforge.net/svnroot/jfuzzydate 7 | 8 | 9 | 10 | 2010-05-02T20:16:01.178418Z 11 | 10 12 | amaasch 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 304ab590-10bd-48d9-9485-c5c0298202dd 28 | 29 | DefaultFuzzingConfiguration.java 30 | file 31 | 32 | 33 | 34 | 35 | 2012-02-16T07:31:49.000000Z 36 | 694a847a2c6de3c69253e536fca480ff 37 | 2010-04-16T14:55:44.273276Z 38 | 5 39 | amaasch 40 | has-props 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 6458 62 | 63 | FuzzyDateFormatterImpl.java 64 | file 65 | 66 | 67 | 68 | 69 | 2012-02-16T07:31:49.000000Z 70 | 7f9d24994d2df8417517cecd99df43e2 71 | 2010-05-02T20:16:01.178418Z 72 | 10 73 | amaasch 74 | has-props 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 5936 96 | 97 | Range.java 98 | file 99 | 100 | 101 | 102 | 103 | 2012-02-16T07:31:49.000000Z 104 | 7ceed55bf9a296f2e61a8dfe8c888f9d 105 | 2010-05-02T20:16:01.178418Z 106 | 10 107 | amaasch 108 | has-props 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 1827 130 | 131 | -------------------------------------------------------------------------------- /fuzzydateandroid-lib/src/com/fuzzydate/android/impl/.svn/prop-base/DefaultFuzzingConfiguration.java.svn-base: -------------------------------------------------------------------------------- 1 | K 13 2 | svn:mime-type 3 | V 10 4 | text/plain 5 | END 6 | -------------------------------------------------------------------------------- /fuzzydateandroid-lib/src/com/fuzzydate/android/impl/.svn/prop-base/FuzzyDateFormatterImpl.java.svn-base: -------------------------------------------------------------------------------- 1 | K 13 2 | svn:mime-type 3 | V 10 4 | text/plain 5 | END 6 | -------------------------------------------------------------------------------- /fuzzydateandroid-lib/src/com/fuzzydate/android/impl/.svn/prop-base/Range.java.svn-base: -------------------------------------------------------------------------------- 1 | K 13 2 | svn:mime-type 3 | V 10 4 | text/plain 5 | END 6 | -------------------------------------------------------------------------------- /fuzzydateandroid-lib/src/com/fuzzydate/android/impl/.svn/text-base/DefaultFuzzingConfiguration.java.svn-base: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scottyab/FuzzyDateAndroid/b7955bb56f2efc2b6e33888c20f1348a8213d2ee/fuzzydateandroid-lib/src/com/fuzzydate/android/impl/.svn/text-base/DefaultFuzzingConfiguration.java.svn-base -------------------------------------------------------------------------------- /fuzzydateandroid-lib/src/com/fuzzydate/android/impl/.svn/text-base/FuzzyDateFormatterImpl.java.svn-base: -------------------------------------------------------------------------------- 1 | package net.sf.jfuzzydate.impl; 2 | 3 | import java.util.Date; 4 | import java.util.Locale; 5 | 6 | import net.sf.jfuzzydate.FuzzingConfiguration; 7 | import net.sf.jfuzzydate.FuzzingStrength; 8 | import net.sf.jfuzzydate.FuzzyDateFormatter; 9 | 10 | /** 11 | * Basic implementation for fuzzy date formatting. 12 | * 13 | * @author amaasch 14 | * 15 | * @see FuzzyDateFormatter 16 | */ 17 | public class FuzzyDateFormatterImpl implements FuzzyDateFormatter { 18 | 19 | /** 20 | * The fuzzing configuration. 21 | */ 22 | private final FuzzingConfiguration config; 23 | 24 | /** 25 | * Creates a new FuzzyDateFormatterImpl object with the specified 26 | * configuration. 27 | * 28 | * @param config 29 | * the given configuration. 30 | */ 31 | public FuzzyDateFormatterImpl(final FuzzingConfiguration config) { 32 | this.config = config; 33 | } 34 | 35 | /* 36 | * (non-Javadoc) 37 | * 38 | * @see net.sf.jfuzzydate.FuzzyDateFormatter#format(java.util.Date) 39 | */ 40 | public String format(final Date date) { 41 | return format(date, Locale.getDefault()); 42 | } 43 | 44 | /* 45 | * (non-Javadoc) 46 | * 47 | * @see net.sf.jfuzzydate.FuzzyDateFormatter#format(java.util.Date, 48 | * java.util.Locale) 49 | */ 50 | public String format(final Date date, final Locale locale) { 51 | return formatDate(date.getTime() - new Date().getTime(), 52 | FuzzingStrength.NORMAL, locale); 53 | } 54 | 55 | /** 56 | * Formats a point in time. Not yet implemented. 57 | * 58 | * @param distance 59 | * todo 60 | * @param strength 61 | * the strength of the fuzzyfication. 62 | * @param locale 63 | * the locale for formatting. 64 | * 65 | * @return a string representing a point in time in relation to the current 66 | * time. 67 | */ 68 | private String formatDate(final long distance, 69 | final FuzzingStrength strength, final Locale locale) { 70 | return "not implemented"; 71 | } 72 | 73 | /* 74 | * (non-Javadoc) 75 | * 76 | * @see net.sf.jfuzzydate.FuzzyDateFormatter#formatDistance(java.util.Date) 77 | */ 78 | public String formatDistance(final Date date) { 79 | return formatDistance(date, Locale.getDefault()); 80 | } 81 | 82 | /* 83 | * (non-Javadoc) 84 | * 85 | * @see net.sf.jfuzzydate.FuzzyDateFormatter#formatDistance(java.util.Date, 86 | * java.util.Locale) 87 | */ 88 | public String formatDistance(final Date date, final Locale locale) { 89 | return formatDistance(date.getTime() - new Date().getTime(), 90 | FuzzingStrength.NORMAL, locale); 91 | } 92 | 93 | /** 94 | * Formats a distance. 95 | * 96 | * @param distanceSec 97 | * a relative distance (number of milliseconds). Negative 98 | * distances are assumed to be past values. 99 | * @param strength 100 | * the strength of the fuzzyfication. 101 | * @param locale 102 | * the locale for formatting. 103 | * 104 | * @return a string representing a readable distance. 105 | */ 106 | private String formatDistance(final long distanceSec, 107 | final FuzzingStrength strength, final Locale locale) { 108 | String pattern; 109 | 110 | if (distanceSec <= 0) { 111 | pattern = "distance.past.pattern"; 112 | } else { 113 | pattern = "distance.future.pattern"; 114 | } 115 | 116 | final long absDistance = Math.abs(distanceSec); 117 | 118 | for (final Range range : config.getDistanceRanges(strength)) { 119 | if (absDistance < range.getUpperBound()) { 120 | if (range.hasDivisor()) { 121 | final int parameter = Math.round(absDistance 122 | / range.getParameterDivisor()); 123 | 124 | return config.getFuzzyString(pattern, locale, config 125 | .getFuzzyString(range, locale, Integer 126 | .valueOf(parameter))); 127 | } 128 | 129 | return config.getFuzzyString(pattern, locale, config 130 | .getFuzzyString(range, locale)); 131 | } 132 | } 133 | 134 | return config.getFuzzyString(pattern, locale, config.getFuzzyString( 135 | Range.ETERNAL, locale)); 136 | } 137 | 138 | /* 139 | * (non-Javadoc) 140 | * 141 | * @see net.sf.jfuzzydate.FuzzyDateFormatter#formatDuration(java.util.Date) 142 | */ 143 | public String formatDuration(final Date relative) { 144 | return formatDuration(relative, Locale.getDefault()); 145 | } 146 | 147 | /* 148 | * (non-Javadoc) 149 | * 150 | * @see net.sf.jfuzzydate.FuzzyDateFormatter#formatDuration(java.util.Date, 151 | * java.util.Date, java.util.Locale) 152 | */ 153 | public String formatDuration(final Date from, final Date to, 154 | final Locale locale) { 155 | return formatDuration(to.getTime() - from.getTime(), locale); 156 | } 157 | 158 | /* 159 | * (non-Javadoc) 160 | * 161 | * @see net.sf.jfuzzydate.FuzzyDateFormatter#formatDuration(java.util.Date, 162 | * java.util.Locale) 163 | */ 164 | public String formatDuration(final Date relative, final Locale locale) { 165 | return formatDuration(new Date().getTime() - relative.getTime(), locale); 166 | } 167 | 168 | /* 169 | * (non-Javadoc) 170 | * 171 | * @see net.sf.jfuzzydate.FuzzyDateFormatter#formatDuration(long) 172 | */ 173 | public String formatDuration(final long milliSeconds) { 174 | return formatDuration(milliSeconds, Locale.getDefault()); 175 | } 176 | 177 | /** 178 | * Formats a duration. 179 | * 180 | * @param milliSeconds 181 | * the duration defined by a number of milliseconds. Negative 182 | * distances are assumed to be past values. 183 | * @param strength 184 | * the strength of the fuzzyfication. 185 | * @param locale 186 | * the locale for formatting. 187 | * 188 | * @return a string representing a readable duration. 189 | */ 190 | private String formatDuration(final long milliSeconds, 191 | final FuzzingStrength strength, final Locale locale) { 192 | for (final Range range : config.getDurationRanges(strength)) { 193 | if (milliSeconds < range.getUpperBound()) { 194 | if (range.hasDivisor()) { 195 | final int parameter = Math.round(milliSeconds 196 | / range.getParameterDivisor()); 197 | 198 | return config.getFuzzyString(range, locale, Integer 199 | .valueOf(parameter)); 200 | } 201 | 202 | return config.getFuzzyString(range, locale); 203 | } 204 | } 205 | 206 | return config.getFuzzyString(Range.ETERNAL, locale); 207 | } 208 | 209 | /* 210 | * (non-Javadoc) 211 | * 212 | * @see net.sf.jfuzzydate.FuzzyDateFormatter#formatDuration(long, 213 | * java.util.Locale) 214 | */ 215 | public String formatDuration(final long milliSeconds, final Locale locale) { 216 | return formatDuration(milliSeconds, FuzzingStrength.NORMAL, locale); 217 | } 218 | } 219 | -------------------------------------------------------------------------------- /fuzzydateandroid-lib/src/com/fuzzydate/android/impl/.svn/text-base/Range.java.svn-base: -------------------------------------------------------------------------------- 1 | package net.sf.jfuzzydate.impl; 2 | 3 | /** 4 | * A date/time range mapping time values up to an upper bound to an externalized 5 | * string. 6 | * 7 | * @author amaasch 8 | */ 9 | public class Range { 10 | 11 | /** 12 | * 13 | */ 14 | public static final Range ETERNAL = new Range(Long.MAX_VALUE, 15 | "distance.eternal"); 16 | 17 | /** 18 | * 19 | */ 20 | private Long parameterDivisor; 21 | 22 | /** 23 | * The key for the externalized string. 24 | */ 25 | private final String bundleKey; 26 | 27 | /** 28 | * 29 | */ 30 | private final long upperBound; 31 | 32 | /** 33 | * Creates a new Range object with an upper binding and a reference to an 34 | * externalized string. 35 | * 36 | * @param upperBound 37 | * @param bundleKey 38 | */ 39 | public Range(final long upperBound, final String bundleKey) { 40 | this.upperBound = upperBound * 1000; 41 | this.bundleKey = bundleKey; 42 | } 43 | 44 | /** 45 | * Creates a new Range object with an upper binding and a reference to an 46 | * externalized string. This constructor method also sets a divisor, used to 47 | * define the calculation of number values included in fuzzy strings. 48 | * 49 | * @param upperBound 50 | * @param bundleKey 51 | * @param parameterDivisor 52 | */ 53 | public Range(final long upperBound, final String bundleKey, 54 | final long parameterDivisor) { 55 | this.upperBound = upperBound * 1000; 56 | this.bundleKey = bundleKey; 57 | this.parameterDivisor = parameterDivisor * 1000; 58 | } 59 | 60 | /** 61 | * 62 | * 63 | * @return the bundleKey 64 | */ 65 | public String getBundleKey() { 66 | return bundleKey; 67 | } 68 | 69 | /** 70 | * 71 | * 72 | * @return the parameterDivisor 73 | */ 74 | public long getParameterDivisor() { 75 | return parameterDivisor; 76 | } 77 | 78 | /** 79 | * 80 | * 81 | * @return the upperBound 82 | */ 83 | public long getUpperBound() { 84 | return upperBound; 85 | } 86 | 87 | /** 88 | * 89 | * 90 | * @return 91 | */ 92 | public boolean hasDivisor() { 93 | return parameterDivisor != null; 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /fuzzydateandroid-lib/src/com/fuzzydate/android/impl/DefaultFuzzingConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.fuzzydate.android.impl; 2 | 3 | import android.content.Context; 4 | 5 | import com.fuzzydate.android.FuzzingConfiguration; 6 | import com.fuzzydate.android.FuzzingStrength; 7 | import com.fuzzydate.android.R; 8 | 9 | /** 10 | * A very simple and static configuration for fuzzy date formatting_ 11 | * 12 | * 13 | * 14 | * @author ma� 15 | */ 16 | public final class DefaultFuzzingConfiguration implements FuzzingConfiguration { 17 | // ~ Static fields/initializers 18 | // --------------------------------------------- 19 | 20 | /** 21 | * The singleton instance_ 22 | */ 23 | private static DefaultFuzzingConfiguration instance; 24 | 25 | // ~ Instance fields 26 | // -------------------------------------------------------- 27 | 28 | /** 29 | * 30 | */ 31 | private final Range[] dist_normal; 32 | 33 | /** 34 | * 35 | */ 36 | private final Range[] dur_normal; 37 | 38 | private final Range[] hour_normal; 39 | 40 | // ~ Constructors 41 | // ----------------------------------------------------------- 42 | 43 | /** 44 | * Creates a new DefaultFuzzingConfiguration object_ 45 | */ 46 | private DefaultFuzzingConfiguration() { 47 | final int min = 60; 48 | final int hour = 60 * min; 49 | final int day = 24 * hour; 50 | final int week = 7 * day; 51 | final int month = 30 * day; 52 | 53 | dur_normal = new Range[] { 54 | new Range(80, R.string.fuzzy__duration_minute_1), 55 | new Range(140, R.string.fuzzy__duration_minute_2), 56 | new Range(40 * min, R.string.fuzzy__duration_minute_x, min), 57 | new Range(90 * min, R.string.fuzzy__duration_hour_1), 58 | new Range(150 * min, R.string.fuzzy__duration_hour_2), 59 | new Range(day, R.string.fuzzy__duration_hour_x, hour), 60 | new Range(36 * hour, R.string.fuzzy__duration_day_1), 61 | new Range(60 * hour, R.string.fuzzy__duration_day_2), 62 | new Range(week, R.string.fuzzy__duration_day_x, day), 63 | new Range(11 * day, R.string.fuzzy__duration_week_1), 64 | new Range(18 * day, R.string.fuzzy__duration_week_2), 65 | new Range(4 * week, R.string.fuzzy__duration_week_x, week), 66 | new Range(45 * day, R.string.fuzzy__duration_month_1), 67 | new Range(75 * day, R.string.fuzzy__duration_month_2), 68 | new Range(300 * day, R.string.fuzzy__duration_month_x, month), 69 | new Range(Long.MAX_VALUE, R.string.fuzzy__duration_eternal) }; 70 | 71 | dist_normal = new Range[] { 72 | new Range(80, R.string.fuzzy__distance_minute_1), 73 | new Range(140, R.string.fuzzy__distance_minute_2), 74 | new Range(40 * min, R.string.fuzzy__distance_minute_x, min), 75 | new Range(90 * min, R.string.fuzzy__distance_hour_1), 76 | new Range(150 * min, R.string.fuzzy__distance_hour_2), 77 | new Range(day, R.string.fuzzy__distance_hour_x, hour), 78 | new Range(36 * hour, R.string.fuzzy__distance_day_1), 79 | new Range(60 * hour, R.string.fuzzy__distance_day_2), 80 | new Range(week, R.string.fuzzy__distance_day_x, day), 81 | new Range(11 * day, R.string.fuzzy__distance_week_1), 82 | new Range(18 * day, R.string.fuzzy__distance_week_2), 83 | new Range(4 * week, R.string.fuzzy__distance_week_x, week), 84 | new Range(45 * day, R.string.fuzzy__distance_month_1), 85 | new Range(75 * day, R.string.fuzzy__distance_month_2), 86 | new Range(300 * day, R.string.fuzzy__distance_month_x, month), 87 | new Range(Long.MAX_VALUE, R.string.fuzzy__duration_eternal) }; 88 | 89 | hour_normal = new Range[] { new Range(0, R.string.fuzzy__hour_0), 90 | new Range(1, R.string.fuzzy__hour_1), 91 | new Range(2, R.string.fuzzy__hour_2), 92 | new Range(3, R.string.fuzzy__hour_3), 93 | new Range(4, R.string.fuzzy__hour_4), 94 | new Range(5, R.string.fuzzy__hour_5), 95 | new Range(6, R.string.fuzzy__hour_6), 96 | new Range(7, R.string.fuzzy__hour_7), 97 | new Range(8, R.string.fuzzy__hour_8), 98 | new Range(9, R.string.fuzzy__hour_9), 99 | new Range(10, R.string.fuzzy__hour_10), 100 | new Range(11, R.string.fuzzy__hour_11), 101 | new Range(12, R.string.fuzzy__hour_12), 102 | new Range(13, R.string.fuzzy__hour_13), 103 | new Range(14, R.string.fuzzy__hour_14), 104 | new Range(15, R.string.fuzzy__hour_15), 105 | new Range(16, R.string.fuzzy__hour_16), 106 | new Range(17, R.string.fuzzy__hour_17), 107 | new Range(18, R.string.fuzzy__hour_18), 108 | new Range(19, R.string.fuzzy__hour_19), 109 | new Range(20, R.string.fuzzy__hour_20), 110 | new Range(21, R.string.fuzzy__hour_21), 111 | new Range(22, R.string.fuzzy__hour_22), 112 | new Range(23, R.string.fuzzy__hour_23) }; 113 | 114 | } 115 | 116 | // ~ Methods 117 | // ---------------------------------------------------------------- 118 | 119 | /** 120 | * This static method returns a shared instance of this default 121 | * configuration class_ 122 | * 123 | * @return a DefaultFuzzingConfiguration istance_ 124 | */ 125 | public static DefaultFuzzingConfiguration getInstance() { 126 | if (instance == null) { 127 | instance = new DefaultFuzzingConfiguration(); 128 | } 129 | 130 | return instance; 131 | } 132 | 133 | /* 134 | * (non-Javadoc) 135 | * 136 | * @see 137 | * net_sf_jfuzzydate_FuzzingConfiguration#getDistanceRanges(net_sf_jfuzzydate 138 | * _FuzzingStrength) 139 | */ 140 | public Range[] getDistanceRanges(FuzzingStrength strenght) { 141 | final Range[] ranges; 142 | 143 | switch (strenght) { 144 | case NORMAL: 145 | ranges = dist_normal; 146 | 147 | break; 148 | 149 | case STRONG: 150 | // TODO 151 | ranges = dist_normal; 152 | 153 | break; 154 | 155 | case EXTREME: 156 | // TODO 157 | ranges = dist_normal; 158 | 159 | break; 160 | 161 | default: 162 | ranges = dist_normal; 163 | } 164 | 165 | return ranges; 166 | } 167 | 168 | public Range[] getHourRanges(FuzzingStrength strenght) { 169 | final Range[] ranges; 170 | 171 | switch (strenght) { 172 | case NORMAL: 173 | ranges = hour_normal; 174 | 175 | break; 176 | 177 | case STRONG: 178 | // TODO 179 | ranges = hour_normal; 180 | 181 | break; 182 | 183 | case EXTREME: 184 | // TODO 185 | ranges = hour_normal; 186 | 187 | break; 188 | 189 | default: 190 | ranges = hour_normal; 191 | } 192 | 193 | return ranges; 194 | } 195 | 196 | /* 197 | * (non-Javadoc) 198 | * 199 | * @see 200 | * net_sf_jfuzzydate_FuzzingConfiguration#getDurationRanges(net_sf_jfuzzydate 201 | * _FuzzingStrength) 202 | */ 203 | public Range[] getDurationRanges(FuzzingStrength strenght) { 204 | final Range[] ranges; 205 | 206 | switch (strenght) { 207 | case NORMAL: 208 | ranges = dur_normal; 209 | 210 | break; 211 | 212 | case STRONG: 213 | // TODO 214 | ranges = dur_normal; 215 | 216 | break; 217 | 218 | case EXTREME: 219 | // TODO 220 | ranges = dur_normal; 221 | 222 | break; 223 | 224 | default: 225 | ranges = dur_normal; 226 | } 227 | 228 | return ranges; 229 | } 230 | 231 | /* 232 | * (non-Javadoc) 233 | * 234 | * @see 235 | * net_sf_jfuzzydate_FuzzingConfiguration#getFuzzyString(net_sf_jfuzzydate 236 | * _impl_Range, java_util_Locale, java_lang_Object[]) 237 | */ 238 | public String getFuzzyString(final Range range, final Context context, 239 | final Object... params) { 240 | return context.getResources().getString(range.getLabelResId(), params); 241 | } 242 | 243 | /* 244 | * (non-Javadoc) 245 | * 246 | * @see 247 | * net_sf_jfuzzydate_FuzzingConfiguration#getFuzzyString(java_lang_String, 248 | * java_util_Locale, java_lang_Object[]) 249 | */ 250 | public String getFuzzyString(final int resId, final Context context, 251 | final Object... params) { 252 | 253 | // int resId = context.getResources().getIdentifier(pattern, "string", 254 | // context.getPackageName()); 255 | 256 | return context.getResources().getString(resId, params); 257 | } 258 | } 259 | -------------------------------------------------------------------------------- /fuzzydateandroid-lib/src/com/fuzzydate/android/impl/FuzzyDateFormatterImpl.java: -------------------------------------------------------------------------------- 1 | package com.fuzzydate.android.impl; 2 | 3 | import java.util.Calendar; 4 | import java.util.Date; 5 | 6 | import android.content.Context; 7 | 8 | import com.fuzzydate.android.FuzzingConfiguration; 9 | import com.fuzzydate.android.FuzzingStrength; 10 | import com.fuzzydate.android.FuzzyDateFormatter; 11 | import com.fuzzydate.android.R; 12 | 13 | /** 14 | * Basic implementation for fuzzy date formatting. 15 | * 16 | * @author amaasch 17 | * 18 | * @see FuzzyDateFormatter 19 | */ 20 | public class FuzzyDateFormatterImpl implements FuzzyDateFormatter { 21 | 22 | /** 23 | * The fuzzing configuration. 24 | */ 25 | private final FuzzingConfiguration config; 26 | private Context context; 27 | 28 | /** 29 | * Creates a new FuzzyDateFormatterImpl object with the specified 30 | * configuration. 31 | * 32 | * @param config 33 | * the given configuration. 34 | */ 35 | public FuzzyDateFormatterImpl(final FuzzingConfiguration config, 36 | Context context) { 37 | this.config = config; 38 | this.context = context; 39 | } 40 | 41 | /* 42 | * (non-Javadoc) 43 | * 44 | * @see net.sf.jfuzzydate.FuzzyDateFormatter#format(java.util.Date) 45 | */ 46 | public String format(final Date date) { 47 | return formatDate(date.getTime(), FuzzingStrength.NORMAL); 48 | } 49 | 50 | /** 51 | * Formats a point in time. 52 | * 53 | * e.g 15:15 becomes quarter past three 54 | * 55 | * TODO: add exceptions for midday, midnight 56 | * 57 | * @param time 58 | * a time to make fuzzy 59 | * 60 | * @param strength 61 | * the strength of the fuzzyfication. 62 | * 63 | * @return a string representing a point in time 64 | */ 65 | private String formatDate(final long time, final FuzzingStrength strength) { 66 | 67 | // e.g convert long of time to fuzzy six o'clock, quarter past six, 68 | // quarter to six 69 | Calendar cal = Calendar.getInstance(); 70 | cal.setTimeInMillis(time); 71 | 72 | int hour = cal.get(Calendar.HOUR_OF_DAY); 73 | int mins = cal.get(Calendar.MINUTE); 74 | 75 | // which pattern is it? 76 | int pattern = 0; 77 | if (mins <= 14) { 78 | pattern = R.string.fuzzy__quarters_0_singular; 79 | } else if (mins >= 15 && mins < 29) { 80 | pattern = R.string.fuzzy__quarters_1; 81 | } else if (mins >= 30 && mins < 44) { 82 | pattern = R.string.fuzzy__quarters_2_singular; 83 | } else if (mins > 45) { 84 | pattern = R.string.fuzzy__quarters_3_singular; 85 | // its now quart to so roll the date, and handle quarter to 1 86 | cal.roll(Calendar.HOUR_OF_DAY, true); 87 | hour = cal.get(Calendar.HOUR_OF_DAY); 88 | } 89 | 90 | // to match the upperbound and in with the ranges of dist/duration 91 | final int absHour = Math.abs(hour) * 1000; 92 | 93 | // pick the correct range based on the hour. 94 | for (final Range range : config.getHourRanges(strength)) { 95 | if (absHour == range.getUpperBound()) { 96 | return config.getFuzzyString(pattern, context, 97 | config.getFuzzyString(range, context, absHour)); 98 | } 99 | } 100 | return config.getFuzzyString(R.string.fuzzy__cannot_find_time, context); 101 | } 102 | 103 | /* 104 | * (non-Javadoc) 105 | * 106 | * @see net.sf.jfuzzydate.FuzzyDateFormatter#formatDistance(java.util.Date) 107 | */ 108 | public String formatDistance(final Date date) { 109 | return formatDistance(date.getTime() - new Date().getTime(), 110 | FuzzingStrength.NORMAL); 111 | } 112 | 113 | /** 114 | * Formats a distance. 115 | * 116 | * @param distanceSec 117 | * a relative distance (number of milliseconds). Negative 118 | * distances are assumed to be past values. 119 | * @param strength 120 | * the strength of the fuzzyfication. 121 | * @param locale 122 | * the locale for formatting. 123 | * 124 | * @return a string representing a readable distance. 125 | */ 126 | private String formatDistance(final long distanceSec, 127 | final FuzzingStrength strength) { 128 | int pattern; 129 | 130 | if (distanceSec <= 0) { 131 | pattern = R.string.fuzzy__distance_past_pattern; 132 | } else { 133 | pattern = R.string.fuzzy__distance_future_pattern; 134 | } 135 | 136 | final long absDistance = Math.abs(distanceSec); 137 | 138 | for (final Range range : config.getDistanceRanges(strength)) { 139 | if (absDistance < range.getUpperBound()) { 140 | if (range.hasDivisor()) { 141 | final int parameter = Math.round(absDistance 142 | / range.getParameterDivisor()); 143 | 144 | return config.getFuzzyString( 145 | pattern, 146 | context, 147 | config.getFuzzyString(range, context, 148 | Integer.valueOf(parameter))); 149 | } 150 | 151 | return config.getFuzzyString(pattern, context, 152 | config.getFuzzyString(range, context)); 153 | } 154 | } 155 | 156 | return config.getFuzzyString(pattern, context, 157 | config.getFuzzyString(Range.ETERNAL, context)); 158 | } 159 | 160 | /* 161 | * (non-Javadoc) 162 | * 163 | * @see net.sf.jfuzzydate.FuzzyDateFormatter#formatDuration(java.util.Date) 164 | */ 165 | public String formatDuration(final Date relative) { 166 | return formatDuration(relative.getTime(), FuzzingStrength.NORMAL); 167 | } 168 | 169 | /* 170 | * (non-Javadoc) 171 | * 172 | * @see net.sf.jfuzzydate.FuzzyDateFormatter#formatDuration(long) 173 | */ 174 | public String formatDuration(final long milliSeconds) { 175 | return formatDuration(milliSeconds, FuzzingStrength.NORMAL); 176 | } 177 | 178 | /** 179 | * Formats a duration. 180 | * 181 | * @param milliSeconds 182 | * the duration defined by a number of milliseconds. Negative 183 | * distances are assumed to be past values. 184 | * @param strength 185 | * the strength of the fuzzyfication. 186 | * 187 | * @return a string representing a readable duration. 188 | */ 189 | private String formatDuration(final long milliSeconds, 190 | final FuzzingStrength strength) { 191 | for (final Range range : config.getDurationRanges(strength)) { 192 | if (milliSeconds < range.getUpperBound()) { 193 | if (range.hasDivisor()) { 194 | final int parameter = Math.round(milliSeconds 195 | / range.getParameterDivisor()); 196 | 197 | return config.getFuzzyString(range, context, 198 | Integer.valueOf(parameter)); 199 | } 200 | 201 | return config.getFuzzyString(range, context); 202 | } 203 | } 204 | return config.getFuzzyString(Range.ETERNAL, context); 205 | } 206 | 207 | } 208 | -------------------------------------------------------------------------------- /fuzzydateandroid-lib/src/com/fuzzydate/android/impl/Range.java: -------------------------------------------------------------------------------- 1 | package com.fuzzydate.android.impl; 2 | 3 | import com.fuzzydate.android.R; 4 | 5 | /** 6 | * A date/time range mapping time values up to an upper bound to an externalized 7 | * string. 8 | * 9 | * @author amaasch (updated by scottyab) 10 | * 11 | */ 12 | public class Range { 13 | 14 | /** 15 | * 16 | */ 17 | public static final Range ETERNAL = new Range(Long.MAX_VALUE, 18 | R.string.fuzzy__distance_eternal); 19 | 20 | /** 21 | * 22 | */ 23 | private Long parameterDivisor; 24 | 25 | /** 26 | * Res id of the string label 27 | */ 28 | private final int labelResId; 29 | 30 | /** 31 | * 32 | */ 33 | private final long upperBound; 34 | 35 | /** 36 | * Creates a new Range object with an upper binding and a reference to an 37 | * externalized string. 38 | * 39 | * @param upperBound 40 | * @param bundleKey 41 | */ 42 | public Range(final long upperBound, final int bundleKey) { 43 | this.upperBound = upperBound * 1000; 44 | this.labelResId = bundleKey; 45 | } 46 | 47 | /** 48 | * Creates a new Range object with an upper binding and a reference to an 49 | * externalized string. This constructor method also sets a divisor, used to 50 | * define the calculation of number values included in fuzzy strings. 51 | * 52 | * @param upperBound 53 | * @param bundleKey 54 | * @param parameterDivisor 55 | */ 56 | public Range(final long upperBound, final int bundleKey, 57 | final long parameterDivisor) { 58 | this.upperBound = upperBound * 1000; 59 | this.labelResId = bundleKey; 60 | this.parameterDivisor = parameterDivisor * 1000; 61 | } 62 | 63 | /** 64 | * 65 | * 66 | * @return the bundleKey 67 | */ 68 | public int getLabelResId() { 69 | return labelResId; 70 | } 71 | 72 | /** 73 | * 74 | * 75 | * @return the parameterDivisor 76 | */ 77 | public long getParameterDivisor() { 78 | return parameterDivisor; 79 | } 80 | 81 | /** 82 | * 83 | * 84 | * @return the upperBound 85 | */ 86 | public long getUpperBound() { 87 | return upperBound; 88 | } 89 | 90 | /** 91 | * 92 | * 93 | * @return 94 | */ 95 | public boolean hasDivisor() { 96 | return parameterDivisor != null; 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /fuzzydateandroid-sample/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | 8 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /fuzzydateandroid-sample/build.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 9 | 29 | 30 | 31 | 35 | 36 | 37 | 38 | 39 | 40 | 49 | 50 | 51 | 52 | 56 | 57 | 69 | 70 | 71 | 89 | 90 | 91 | 92 | 93 | -------------------------------------------------------------------------------- /fuzzydateandroid-sample/libs/android-support-v4.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scottyab/FuzzyDateAndroid/b7955bb56f2efc2b6e33888c20f1348a8213d2ee/fuzzydateandroid-sample/libs/android-support-v4.jar -------------------------------------------------------------------------------- /fuzzydateandroid-sample/libs/junit-4.8.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scottyab/FuzzyDateAndroid/b7955bb56f2efc2b6e33888c20f1348a8213d2ee/fuzzydateandroid-sample/libs/junit-4.8.1.jar -------------------------------------------------------------------------------- /fuzzydateandroid-sample/proguard-project.txt: -------------------------------------------------------------------------------- 1 | # To enable ProGuard in your project, edit project.properties 2 | # to define the proguard.config property as described in that file. 3 | # 4 | # Add project specific ProGuard rules here. 5 | # By default, the flags in this file are appended to flags specified 6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt 7 | # You can edit the include path and order by changing the ProGuard 8 | # include property in project.properties. 9 | # 10 | # For more details, see 11 | # http://developer.android.com/guide/developing/tools/proguard.html 12 | 13 | # Add any project specific keep options here: 14 | 15 | # If your project uses WebView with JS, uncomment the following 16 | # and specify the fully qualified class name to the JavaScript interface 17 | # class: 18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 19 | # public *; 20 | #} 21 | -------------------------------------------------------------------------------- /fuzzydateandroid-sample/project.properties: -------------------------------------------------------------------------------- 1 | # This file is automatically generated by Android Tools. 2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED! 3 | # 4 | # This file must be checked in Version Control Systems. 5 | # 6 | # To customize properties used by the Ant build system edit 7 | # "ant.properties", and override values to adapt the script to your 8 | # project structure. 9 | # 10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): 11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt 12 | 13 | # Project target. 14 | target=android-17 15 | android.library.reference.1=../fuzzydateandroid-lib 16 | -------------------------------------------------------------------------------- /fuzzydateandroid-sample/res/drawable-hdpi/ic_action_search.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scottyab/FuzzyDateAndroid/b7955bb56f2efc2b6e33888c20f1348a8213d2ee/fuzzydateandroid-sample/res/drawable-hdpi/ic_action_search.png -------------------------------------------------------------------------------- /fuzzydateandroid-sample/res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scottyab/FuzzyDateAndroid/b7955bb56f2efc2b6e33888c20f1348a8213d2ee/fuzzydateandroid-sample/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /fuzzydateandroid-sample/res/drawable-mdpi/ic_action_search.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scottyab/FuzzyDateAndroid/b7955bb56f2efc2b6e33888c20f1348a8213d2ee/fuzzydateandroid-sample/res/drawable-mdpi/ic_action_search.png -------------------------------------------------------------------------------- /fuzzydateandroid-sample/res/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scottyab/FuzzyDateAndroid/b7955bb56f2efc2b6e33888c20f1348a8213d2ee/fuzzydateandroid-sample/res/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /fuzzydateandroid-sample/res/drawable-xhdpi/ic_action_search.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scottyab/FuzzyDateAndroid/b7955bb56f2efc2b6e33888c20f1348a8213d2ee/fuzzydateandroid-sample/res/drawable-xhdpi/ic_action_search.png -------------------------------------------------------------------------------- /fuzzydateandroid-sample/res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scottyab/FuzzyDateAndroid/b7955bb56f2efc2b6e33888c20f1348a8213d2ee/fuzzydateandroid-sample/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /fuzzydateandroid-sample/res/layout/activity_test.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 12 | 13 | 17 | 18 | 26 | 27 | 28 | 29 | 30 |