Created
September 11, 2018 07:22
-
-
Save haerulmuttaqin/3d20a9127070451ccedd80c284649fd6 to your computer and use it in GitHub Desktop.
News App Utils
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.haerul.newsapps; | |
import android.graphics.Color; | |
import android.graphics.drawable.ColorDrawable; | |
import org.ocpsoft.prettytime.PrettyTime; | |
import java.text.ParseException; | |
import java.text.SimpleDateFormat; | |
import java.util.Date; | |
import java.util.Locale; | |
import java.util.Random; | |
public class Utils { | |
public static ColorDrawable[] vibrantLightColorList = | |
{ | |
new ColorDrawable(Color.parseColor("#ffeead")), | |
new ColorDrawable(Color.parseColor("#93cfb3")), | |
new ColorDrawable(Color.parseColor("#fd7a7a")), | |
new ColorDrawable(Color.parseColor("#faca5f")), | |
new ColorDrawable(Color.parseColor("#1ba798")), | |
new ColorDrawable(Color.parseColor("#6aa9ae")), | |
new ColorDrawable(Color.parseColor("#ffbf27")), | |
new ColorDrawable(Color.parseColor("#d93947")) | |
}; | |
public static ColorDrawable getRandomDrawbleColor() { | |
int idx = new Random().nextInt(vibrantLightColorList.length); | |
return vibrantLightColorList[idx]; | |
} | |
public static String DateToTimeFormat(String oldstringDate){ | |
PrettyTime p = new PrettyTime(new Locale(getCountry())); | |
String isTime = null; | |
try { | |
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", | |
Locale.ENGLISH); | |
Date date = sdf.parse(oldstringDate); | |
isTime = p.format(date); | |
} catch (ParseException e) { | |
e.printStackTrace(); | |
} | |
return isTime; | |
} | |
public static String DateFormat(String oldstringDate){ | |
String newDate; | |
SimpleDateFormat dateFormat = new SimpleDateFormat("E, d MMM yyyy", new Locale(getCountry())); | |
try { | |
Date date = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'").parse(oldstringDate); | |
newDate = dateFormat.format(date); | |
} catch (ParseException e) { | |
e.printStackTrace(); | |
newDate = oldstringDate; | |
} | |
return newDate; | |
} | |
public static String getCountry(){ | |
Locale locale = Locale.getDefault(); | |
String country = String.valueOf(locale.getCountry()); | |
return country.toLowerCase(); | |
} | |
} |
Where is getLanguage() method&?
For all who asks about getLanguage method :
public static String getLanguage(){
Locale locale = Locale.getDefault();
String language = String.valueOf(locale.getLanguage());
return language;
}
Thanks rAshraf-dev !
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Can't find the getLanguage ()