Skip to content

Instantly share code, notes, and snippets.

Avatar
😎
code for food

Gianluca Pacchiella gipi

😎
code for food
View GitHub Profile
@gipi
gipi / gist:1267311
Created Oct 6, 2011
To launch a web page in a browser from an activity
View gist:1267311
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com"));
startActivity(browserIntent);
@gipi
gipi / gist:1267393
Created Oct 6, 2011
Retrieve an identification ID from an android device
View gist:1267393
// http://stackoverflow.com/questions/2785485/is-there-a-unique-android-device-id
final TelephonyManager tm = (TelephonyManager) getBaseContext().getSystemService(Context.TELEPHONY_SERVICE);
final String tmDevice, tmSerial, tmPhone, androidId;
tmDevice = "" + tm.getDeviceId();
tmSerial = "" + tm.getSimSerialNumber();
androidId = "" + android.provider.Settings.Secure.getString(getContentResolver(), android.provider.Settings.Secure.ANDROID_ID);
UUID deviceUuid = new UUID(androidId.hashCode(), ((long)tmDevice.hashCode() << 32) | tmSerial.hashCode());
String deviceId = deviceUuid.toString();
@gipi
gipi / SegmentedButton.java
Created Oct 7, 2011
Customized Segmented button
View SegmentedButton.java
/**
* Customization of the RadioButton in order to allow behaviour
* and appearance like the iOS ones.
*
* Inspired from http://blog.bookworm.at/2010/10/segmented-controls-in-android.html
*/
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.drawable.GradientDrawable;
import android.graphics.Canvas;
@gipi
gipi / gist:1289605
Created Oct 15, 2011
Simple shell routine to calculate dpi
View gist:1289605
function calcdpi() {
echo "sqrt($1^2+$2^2)/$3" | bc
}
@gipi
gipi / gist:1292237
Created Oct 17, 2011
Install an APK in all running emulators/devices
View gist:1292237
# ant clean && ant debug && adbInstallAll
adbInstallAll() {
adb devices | \
sed '1d;/^$/d;' | \
awk '{print $1}' | \
while read device;
do
adb -s $device install -r bin/*-debug.apk
done
@gipi
gipi / gist:1292453
Created Oct 17, 2011
Set term title
View gist:1292453
set_console_title() {
PROMPT_COMMAND='echo -ne "\033]0;"'$1'"\007"';
}
@gipi
gipi / gist:1292623
Created Oct 17, 2011
Add a documentation target to Android ant build file
View gist:1292623
<target name="docs">
<javadoc
sourcepath="src/"
destdir="docs/"
/>
</target>
@gipi
gipi / progress.xml
Created Oct 18, 2011
Customize progress bar colors in Android
View progress.xml
<ProgressBar
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@android:style/Widget.ProgressBar.Horizontal"
android:progressDrawable="@drawable/progress_horizontal"
/>
@gipi
gipi / gist:1298537
Created Oct 19, 2011
Pass paremeters between Activity
View gist:1298537
// calling activity
Intent i= new Intent(context, QRActivity.class);
i.putExtra("url", url);
startActivity(i);
// callee activity
Bundle extras = getIntent().getExtras();
if (extras != null) {
mUrl = extras.getString("url");
@gipi
gipi / singleton.py
Created Oct 19, 2011
Implementation of Singleton design pattern in Python (inspired from Alex Martelli talk)
View singleton.py
# python -m doctest singleton.py
class Singleton(object):
"""
>>> s = Singleton()
>>> s #doctest: +ELLIPSIS
<hidden.Singleton object at 0x...>
>>> p = Singleton()
>>> p == s
True
"""