- Added Javadocs to the project
- All the
log
methods now can handleThrowable
objects, thanks @joelfernandes for the suggestion - Added
copyFile(fromFile, toFile)
to thesdcard
category - Added
copyFile(fromFileInputStream, toFileOutputStream)
to thesdcard
category - Added
getSDCardPath
to thesdcard
category - Added
web
category hasInternetConnection()
moved frommisc
toweb
category- Added
HTTPGetRequest()
to theweb
category - Added
degreesToRadians
,radiansTdoDegrees
,acos
,asin
,atan
,atan2
,tan
,max
,min
,abs
,logarithm
,exponencial
andisEven
to themath
category getCurrentTimeInSeconds()
andgetCurrentTimeInMilliseconds()
moved to thedate
category- Added
getDayAsString(int day, String format)
andgetDayAsDate(int day)
to thedate
category
- Checks if the app has connectivity to the Internet
getCurrentTime()
is now divided intogetCurrentTimeInSeconds()
andgetCurrentTimeInMilliseconds()
- public static long getCurrentTimeInSeconds()
sleep
method now accepts milliseconds instead of secondslog
now has a warning method- Updated max SDK version to 4.0.3
- Added
math
category - Get a random number between a given range
- Check if a number is odd
- Added
log
category - Added error log method
- Added information log method
- Added verbose log method
- Added debug log method
- Added
sdcard
category - Added isSDCardAvailable method
- Added isSDCardWritable method
- Added
misc
category - Added vibrate method
- Added sleep method
- Added toast method with custom lenght time
- Added get current time in miliseconds method
Really simple usage, you just need to specify the category and the method you want to use.
QuickUtils.__category__.__method__
With this methods you don't need to set the TAG variable in every class of your project and you can disable the logs everywhere without deleting/commenting the log lines by setting the debug mode to PRODUCTION (explained in the previous section).
QuickUtils.log.__method__
QuickUtils.log.e("error description");
QuickUtils.log.e("error description", throwable);
QuickUtils.log.v("verbose description");
QuickUtils.log.v("verbose description", throwable);
QuickUtils.log.i("information description");
QuickUtils.log.i("information description", throwable);
QuickUtils.log.w("warning description");
QuickUtils.log.w("warning description", throwable);
QuickUtils.log.d("debug description");
QuickUtils.log.d("debug description", throwable);
Date Utils
QuickUtils.date.__method__
QuickUtils.date.getCurrentTimeInMiliseconds();
QuickUtils.date.getCurrentTimeInSeconds();
They "day" parameter can be provided as:
QuickUtils.date.YESTERDAY
,QuickUtils.date.TODAY
orQuickUtils.date.TOMORROW
The format can be provided as e.g. "yyyy-MM-dd HH:mm:ss"
QuickUtils.date.getDayAsString(int day, String format);
They "day" parameter can be provided as:
QuickUtils.date.YESTERDAY
,QuickUtils.date.TODAY
orQuickUtils.date.TOMORROW
QuickUtils.date.getDayAsDate(int day);
Misc utils
QuickUtils.misc.__method__
QuickUtils.misc.toast(context, "This is a short toast");
Either Toast.LENGTH_SHORT
or Toast.LENGTH_LONG
QuickUtils.misc.toast(context, "This is a short toast", Toast.LENGTH_LONG);
Causes the thread which sent this message to sleep for the given interval of time (given in milliseconds). The precision is not guaranteed - the Thread may sleep more or less than requested.
QuickUtils.misc.sleep(durationInMilliseconds);
needed on onActivityResult(int requestCode, int resultCode, Intent data) to call getSpeechRecognitionResults() to get the results)
QuickUtils.misc.speechRecognition(final Activity activity, int maxResults, String text);
To be called onActivityResult() Return an ArrayList with all results or null if was not possible to get any results
QuickUtils.misc.getSpeechRecognitionResults(int requestCode, int resultCode, Intent data);
Get the first result that matches the Result List from Google Speech Recognition activity and the Dictionary given
To be called onActivityResult() Return a String with the first result matched or null if was not possible to get any result
QuickUtils.misc.getSpeechRecognitionResultFromDicionary(int requestCode, int resultCode, Intent data, ArrayList<String> array);
To be called onActivityResult() Return a string containing the first result of what was recognized
QuickUtils.misc.getSpeechRecognitionFirstResult(int requestCode, int resultCode, Intent data);
Math Utils.
QuickUtils.math.__method__
A random int between MIN inclusive and MAX exclusive.
QuickUtils.math.getRandomNumber(int min, int max);
True if the num is odd and false if it's even
QuickUtils.math.isOdd(int num);
True if the num is even and false if it's odd
QuickUtils.math.isEven(int num);
Returns the converted value
QuickUtils.math.degreesToRadians(float degrees);
Returns the converted value
QuickUtils.math.radiansTdoDegrees(float radians);
Returns the closest double approximation of the arc cosine of the argument within the range [0..pi]. The returned result is within 1 ulp (unit in the last place) of the real result.
QuickUtils.math.acos(float value);
Returns the closest double approximation of the arc sine of the argument within the range [-pi/2..pi/2]. The returned result is within 1 ulp (unit in the last place) of the real result.
QuickUtils.math.asin(float value);
Returns the closest double approximation of the arc tangent of the argument within the range [-pi/2..pi/2]. The returned result is within 1 ulp (unit in the last place) of the real result.
QuickUtils.math.atan(float value);
Returns the closest double approximation of the arc tangent of y/x within the range [-pi..pi]. This is the angle of the polar representation of the rectangular coordinates (x,y). The returned result is within 2 ulps (units in the last place) of the real result.
QuickUtils.math.atan2(float value);
Returns the tangent
QuickUtils.math.tan(float angle);
Returns the absolute value
QuickUtils.math.abs(float v);
Returns the closest double approximation of the natural logarithm of the argument. The returned result is within 1 ulp (unit in the last place) of the real result.
QuickUtils.math.logarithm(float number);
Returns the closest double approximation of the natural logarithm of the argument. The returned result is within 1 ulp (unit in the last place) of the real result.
QuickUtils.math.exponencial(float number);
the higher number between a and b
QuickUtils.math.max(float a, float b);
QuickUtils.math.max(int a, int b);
the lower number between a and b
QuickUtils.math.min(float a, float b);
QuickUtils.math.min(int a, int b);
Web Utils.
QuickUtils.web.__method__
also this method will need the permissions "android.permission.CHANGE_WIFI_STATE" and "android.permission.ACCESS_WIFI_STATE" true if was set successfully and false if it wasn't
QuickUtils.web.changeWirelessState(Context context, boolean state);
also this method will need the permissions "android.permission.INTERNET" true if the connection returned a successful code
QuickUtils.web.checkServerConnection(URL u);
also this method will need the permissions "android.permission.INTERNET" true if the connection returned a successful code
QuickUtils.web.checkServerConnection(String serverURL);
QuickUtils.web.hasInternetConnection(Context context);
Note: Please use this method on an AsyncTask in order not to freeze the application unnecessarely (http://developer.android.com/guide/practices/responsiveness.html)
QuickUtils.web.HTTPGetRequest(String url);
SDCard Utils.
QuickUtils.sdcard.__method__
True if the sd card is available and false if it is not
QuickUtils.sdcard.isSDCardAvailable();
True if the sd card is writable and false if it is not
QuickUtils.sdcard.isSDCardWritable();
Return the complete path to the SDCard
QuickUtils.sdcard.getSDCardPath();
boolean - if file exist on SDCard or not
QuickUtils.sdcard.checkIfFileExists(String filePath)
Creates the specified toFile
as a byte for byte copy of the fromFile
. If toFile
already exists, then it will be replaced with a copy of fromFile
. The name and path oftoFile
will be that of toFile
.
Note: fromFile
and toFile
will be closed by this function.
As Files
QuickUtils.sdcard.copyFile(fromFile, toFile);
or with Input and Output Streams:
QuickUtils.sdcard.copyFile(fromFileInputStream, toFileOutputStream);
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// SET ENVIRONMENT
QuickUtils.setDebugMode(QuickUtils.DEVELOPER_MODE); // can be omited
// SET THE DEBUG TAG
QuickUtils.setTAG("SAMPLE_APP");
QuickUtils.log.v(QuickUtils.math.logarithm(number) + "");
try {
QuickUtils.log.w("This is dangerous code");
// do DANGEROUS STUFF
// ...
// ...
QuickUtils.misc.toast(this, "The result of your dangerous calculations is: " + number);
} catch (Exception exception) {
QuickUtils.log.e("Exception thrown", exception);
}
// Check if you can write on your sdcard
if (QuickUtils.sdcard.isSDCardAvailable() && QuickUtils.sdcard.isSDCardWritable()) {
// you can write safely on your sdcard
File path = new File(QuickUtils.sdcard.getSDCardPath() + "/appName/");
File from = new File(path, "from.txt");
File to = new File(path, "to.txt");
try {
QuickUtils.sdcard.copyFile(from, to);
QuickUtils.log.i("Written to the sdcard");
} catch (IOException e) {
QuickUtils.log.e("IOException", e);
}
}
All the versions can be found here
As simple as going to your project's properties and include the QuickUtils.jar
library or add the QuickUtils project as a library as shown below.
Set the default TAG for logcat debug purposes
QuickUtils.setTAG("DESIRED_TAG");
To enable the log outputs (This is the default behavior of the library so you don't need to set this up).
QuickUtils.setDebugMode(QuickUtils.DEVELOPER_MODE);
When the application is ready to go and you want to disable the log outputs.
QuickUtils.setDebugMode(QuickUtils.PRODUCTION_MODE);
If you intend to use the vibration util don't forget to add the vibration permission, if you haven't already, in your <manifest>
:
<uses-permission android:name="android.permission.VIBRATE" />
If you intend to use the hasConnectivity
method don't forget to add the network state access permission, if you haven't already, in your <manifest>
:
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
If you intend to use the HTTPGetRequest
method, if you haven't already, in your <manifest>
:
<uses-permission android:name="android.permission.INTERNET" />
Want to contribute? Great!
- Fork it.
- Create a branch (
git checkout -b my_branch
) - Commit your changes (
git commit -am "Added changes"
) - Push to the branch (
git push origin my_branch
) - Create an Issue with a link to your branch
- Enjoy a refreshing Diet Coke and wait
Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0.html)
- César Ferreira (cesar.manuel.ferreira@gmail.com)
- César Ferreira (cesar.manuel.ferreira@gmail.com)
- Luís Pereira (luispereira268@gmail.com)