Skip to content

Instantly share code, notes, and snippets.

@granoeste
granoeste / gist:858063
Created Mar 7, 2011 — forked from aharisu/gist:857961
[Android][Layout] Tab on the bottom with TabView
View gist:858063
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<RelativeLayout
android:layout_width="fill_parent"
@granoeste
granoeste / gist:858096
Created Mar 7, 2011
[Android] Phone State Listener
View gist:858096
public class SignalStrengthListener extends PhoneStateListener {
@Override
public void onSignalStrengthsChanged(SignalStrength signalStrength) {
super.onSignalStrengthsChanged(signalStrength);
boolean isGsm = signalStrength.isGsm();
// Get the CDMA RSSI value in dBm
int iCdmaDbm = signalStrength.getCdmaDbm();
// Get the CDMA Ec/Io value in dB*10
@granoeste
granoeste / gist:870440
Created Mar 15, 2011
[Android] Modify contrast using a ColorMatrix
View gist:870440
ColorMatrixColorFilter setContrast(float contrast) {
float scale = contrast + 1.f;
float translate = (-.5f * scale + .5f) * 255.f;
float[] array = new float[] {
scale, 0, 0, 0, translate,
0, scale, 0, 0, translate,
0, 0, scale, 0, translate,
0, 0, 0, 1, 0};
ColorMatrix matrix = new ColorMatrix(array);
ColorMatrixColorFilter filter = new ColorMatrixColorFilter(matrix);
@granoeste
granoeste / gist:870445
Created Mar 15, 2011
[Android] RGB to YUV
View gist:870445
// from http://d.hatena.ne.jp/Superdry/20110130/1296405341
private int[] convertRGB2YUV(int color) {
ColorMatrix cm = new ColorMatrix();
cm.setRGB2YUV();
final float[] yuvArray = cm.getArray();
int r = Color.red(color);
int g = Color.green(color);
int b = Color.blue(color);
int[] result = new int[3];
@granoeste
granoeste / gist:895848
Created Mar 31, 2011
[Android]Getting the path of each directory
View gist:895848
File dir = context.getFilesDir(); // /data/data/package/files
File dir = context.getCacheDir(); // /data/data/package/cache
File dir = Environment.getDataDirectory(); // /data
File dir = Environment.getDownloadCacheDirectory(); // /cache
File dir = Environment.getExternalStorageDirectory(); // /sdcard
File dir = Environment.getRootDirectory(); // /system
@granoeste
granoeste / gist:895862
Created Mar 31, 2011
[Android]Cropped image
View gist:895862
private final int REQUEST_CROP_GALLERY=1;
private File mTempFile;
public void onClick(View v) {
try {
mTempFile = getTempFile();
// Launch picker to choose photo for selected contact
Intent intent = new Intent(Intent.ACTION_GET_CONTENT, null);
@granoeste
granoeste / ArraysTo.java
Last active Sep 30, 2020
[Java]Arrays.toString 配列とコレクションの変換
View ArraysTo.java
// 配列要素をカンマ区切の文字列に変換してくれる
Arrays.toString(配列要素)
// 指定された配列の「深層内容」の文字列表現を返す。
Arrays.deepToString(Object[] a)
// 配列をListに変換
List<String> list = Arrays.asList(strs);
//ListからStringの配列に変換
@granoeste
granoeste / gist:982578
Created May 20, 2011
[Android]Handler
View gist:982578
final private Handler mHandler = new Handler() {
@Override
public void handleMessage(final Message msg) {
switch (msg.what) {
case MESSAGE_ONE:
// TODO:
return;
case MESSAGE_TWO:
// TODO:
return;
@granoeste
granoeste / gist:1024384
Created Jun 14, 2011
[android][GPS]LocationManager
View gist:1024384
// copy from http://goo.gl/NxT8B
private LocationManager mLocationManager;
private String mBestProvider;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// 位置情報サービスマネージャを取得
@granoeste
granoeste / gist:1026558
Created Jun 15, 2011
[Android][WiFi]Wi-Fi Scan Results
View gist:1026558
final WifiManager mWifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
if(mWifiManager.getWifiState() == WifiManager.WIFI_STATE_ENABLED) {
// register WiFi scan results receiver
IntentFilter filter = new IntentFilter();
filter.addAction(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION);
registerReceiver(new BroadcastReceiver(){
@Override