Skip to content

Instantly share code, notes, and snippets.

🚀
Pursuing Blockchain Development Nanodegree from Udacity

JW jaydeepw

View GitHub Profile
View DateUtils.java
/**
* Returns a string describing a day relative to the current day. For example if the day is
* today this function returns "Today", if the day was a week ago it returns "7 days ago", and
* if the day is in 2 weeks it returns "in 14 days".
*
* @param r the resources
* @param day the relative day to describe in UTC milliseconds
* @param today the current time in UTC milliseconds
*/
private static final String getRelativeDayString(Resources r, long day, long today) {
View DateUtils.java
/**
* Returns a string describing 'time' as a time relative to 'now'.
* <p>
* Time spans in the past are formatted like "42 minutes ago". Time spans in
* the future are formatted like "in 42 minutes".
* <p>
* Can use {@link #FORMAT_ABBREV_RELATIVE} flag to use abbreviated relative
* times, like "42 mins ago".
*
* @param time the time to describe, in milliseconds
@jaydeepw
jaydeepw / IUtils.java
Created Aug 10, 2015
Converting Retrofit Response to String.
View IUtils.java
@Nullable
/**
* Converts {@link retrofit.client.Response#body} to simple {@link java.lang.String} representation.
* This can be used to log message or manually parse JSON or any other purpose.
* @param response
* @return
*/
public static String toString(@NonNull Response response) {
if (response == null) {
@jaydeepw
jaydeepw / W3C-organizations-list.txt
Last active Aug 29, 2015
W3C working groups on github
View W3C-organizations-list.txt
https://github.com/w3c
https://github.com/w3c-webmob
@jaydeepw
jaydeepw / AntLaunchApp
Created Feb 3, 2014
Ant target to launch an Android app from Ant build script.
View AntLaunchApp
<target name="launchApp">
<!--
For e.g. adb shell am start -n com.myorg.packagename/com.myorg.activity.package.ActivityName
-->
<exec executable="adb">
<arg value="shell" />
<arg value="am" />
<arg value="start" />
<arg value="-n" />
<arg value="com.myorg.packagename/com.myorg.activity.package.ActivityName" />
@jaydeepw
jaydeepw / pick-capture-image-android.java
Last active Dec 27, 2015
To take a photograph using camera, gallery and other apps and receive the image data back in your activity.
View pick-capture-image-android.java
// For some help with the Utils class, you may want to take a look
// at the following android-utils library.
// https://github.com/jaydeepw/android-utils
private Uri mOutputFileUri;
private void openPhotoChooser() {
// Determine Uri of camera image to save
@jaydeepw
jaydeepw / wifi-wake-lock-android
Last active Jun 14, 2018
Holding and releasing WiFi wake locks in android.
View wifi-wake-lock-android
// create a class member variable.
WifiManager.WifiLock mWifiLock = null;
/***
* Calling this method will aquire the lock on wifi. This is avoid wifi
* from going to sleep as long as <code>releaseWifiLock</code> method is called.
**/
private void holdWifiLock() {
WifiManager wifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
@jaydeepw
jaydeepw / enableHTML5AppCache.java
Last active Apr 10, 2019
Enabling HTML5 AppCache in Android Webview programatically.
View enableHTML5AppCache.java
private void enableHTML5AppCache() {
webView.getSettings().setDomStorageEnabled(true);
// Set cache size to 8 mb by default. should be more than enough
webView.getSettings().setAppCacheMaxSize(1024*1024*8);
// This next one is crazy. It's the DEFAULT location for your app's cache
// But it didn't work for me without this line
webView.getSettings().setAppCachePath("/data/data/"+ getPackageName() +"/cache");
@jaydeepw
jaydeepw / is-android-service-running
Created May 15, 2012
Android: Checking if a Service is already running in the Android system.
View is-android-service-running
private boolean isMyServiceRunning() {
ActivityManager manager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
if ("com.example.MyService".equals(service.service.getClassName())) {
return true;
}
}
return false;
}
@jaydeepw
jaydeepw / blackberry-network-connection-string.java
Created Apr 24, 2012
Getting a connection string while making a network connection in BlackBerry.
View blackberry-network-connection-string.java
// Get most appropriate connection method
private String getConnectionString() {
String suffix = null;
if (CoverageInfo.isCoverageSufficient(CoverageInfo.COVERAGE_MDS))
{
// BES is available
suffix = ";deviceside=false";
}
You can’t perform that action at this time.