com.stringsandints.inventium.khlrooster
Class Utils

java.lang.Object
  extended by com.stringsandints.inventium.khlrooster.Utils

public class Utils
extends java.lang.Object


Nested Class Summary
static class Utils.ConnectionStatus
          ConnectionStatus
static class Utils.SyncStatus
          SyncStatus values
 
Field Summary
static long CONNECTION_TIMEOUT
           
private static boolean USER_PREFERENCE_SET
           
private static boolean WAS_WIFI_ENABLED
           
 
Constructor Summary
Utils()
           
 
Method Summary
static java.lang.String adjustMinutes(int minutes)
          Method to format the minutes.
static boolean checkForValidStream(java.lang.String input)
          This checks if the String is a valid stream.
static int checkInternetConnection(Context context)
          This method checks if there is an internet connection available.
static java.lang.String convertDateToString(java.util.GregorianCalendar gc)
          Converts a GregorianCalendar date to a formatted datetime string
static int convertDpToPx(float dp, float scale)
          Make screens usable across different screens with this method.
static java.lang.String convertMonth(Resources res, int i)
          Get the name for a month in correct language.
static java.lang.String convertWeekDay(Resources res, int i)
          Method to find the corresponding day name.
static void disableNetwork(Context context)
           
static java.util.GregorianCalendar getCalendarInstance()
          Attempts to return a GregorianCalendar instance with the correct locale
static
<T,E> java.util.Set<T>
getKeysByValue(java.util.Map<T,E> map, E value)
          Gives the keys that belong with a given value.
static int GetSDKVersion()
           
static java.lang.String getSubStringWithDelimiter(java.lang.String inputString, java.lang.String delimiter, int endPosition)
          Divides the inputString by using a delimiter and the chosen endPosition.
static int getSyncStatus(Context c)
          This method gets the sync status
static int randomPositiveRotationBetween(int negativeOffset, int positiveOffset)
          This is a handy method if some elements should be turned for a random amount of degrees but between a certain limit.
static void setSyncStatus(int s, Context c)
          This method sets the sync status
static java.lang.String urlDecode(java.lang.String input)
          Returns a string with URL encoding removed
static java.lang.String urlEncode(java.lang.String input)
          Returns a string that is URL-encoded
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CONNECTION_TIMEOUT

public static final long CONNECTION_TIMEOUT
See Also:
Constant Field Values

WAS_WIFI_ENABLED

private static boolean WAS_WIFI_ENABLED

USER_PREFERENCE_SET

private static boolean USER_PREFERENCE_SET
Constructor Detail

Utils

public Utils()
Method Detail

convertDpToPx

public static int convertDpToPx(float dp,
                                float scale)
Make screens usable across different screens with this method. To make good use of this method, convert as fast as possible to px and then start making calculations. If you build a layout that calculates with dp and must make a lot of conversions this will generate faults.

Parameters:
dp - the size in dp (resolution and density independent
scale - the density scale needed to apply (retrieve with context.getResources().getDisplayMetrics().density)
Returns:
the size in px

convertMonth

public static java.lang.String convertMonth(Resources res,
                                            int i)
Get the name for a month in correct language. Resources must be given to access the string-resources.

Parameters:
res -
i -
Returns:

convertWeekDay

public static java.lang.String convertWeekDay(Resources res,
                                              int i)
Method to find the corresponding day name. Resources must be given to access the string-resources.

Parameters:
res -
i -
Returns:
a String with the right day name.

adjustMinutes

public static java.lang.String adjustMinutes(int minutes)
Method to format the minutes. When smaller than 10, a '0' has to be added in front of the number.

Parameters:
minutes -
Returns:
a String with the formatted minutes.

randomPositiveRotationBetween

public static int randomPositiveRotationBetween(int negativeOffset,
                                                int positiveOffset)
This is a handy method if some elements should be turned for a random amount of degrees but between a certain limit. The negativeOffset should always be smaller then the positiveOffset

Parameters:
negativeOffset - The most negative corner
positiveOffset - The most positive corner
Returns:
a random corner inside the limits

getKeysByValue

public static <T,E> java.util.Set<T> getKeysByValue(java.util.Map<T,E> map,
                                                    E value)
Gives the keys that belong with a given value.

Parameters:
map -
value: - the value of which you want to find the corresponding keys.
Returns:
a Set with the found keys.

getSubStringWithDelimiter

public static java.lang.String getSubStringWithDelimiter(java.lang.String inputString,
                                                         java.lang.String delimiter,
                                                         int endPosition)
Divides the inputString by using a delimiter and the chosen endPosition.

Parameters:
inputString -
delimiter -
endPosition -
Returns:

checkForValidStream

public static boolean checkForValidStream(java.lang.String input)
This checks if the String is a valid stream. This means it has to contain http:// We start a new MediaPlayer to check if the stream is in fact an existing stream. Unless exceptions are caught, we can safely assume the given stream is valid.

Parameters:
input: - stream the user entered
Returns:
boolean: true = valid, false = invalid

urlEncode

public static java.lang.String urlEncode(java.lang.String input)
Returns a string that is URL-encoded


urlDecode

public static java.lang.String urlDecode(java.lang.String input)
Returns a string with URL encoding removed

Parameters:
input -
Returns:

checkInternetConnection

public static int checkInternetConnection(Context context)
This method checks if there is an internet connection available.

Parameters:
context -

disableNetwork

public static void disableNetwork(Context context)

convertDateToString

public static java.lang.String convertDateToString(java.util.GregorianCalendar gc)
Converts a GregorianCalendar date to a formatted datetime string


getCalendarInstance

public static java.util.GregorianCalendar getCalendarInstance()
Attempts to return a GregorianCalendar instance with the correct locale


setSyncStatus

public static void setSyncStatus(int s,
                                 Context c)
This method sets the sync status

Parameters:
s -
c -

getSyncStatus

public static int getSyncStatus(Context c)
This method gets the sync status

Parameters:
c -
Returns:

GetSDKVersion

public static int GetSDKVersion()