Skip to content

Instantly share code, notes, and snippets.

View mstefanko's full-sized avatar

Mike Stefanko mstefanko

View GitHub Profile
@mstefanko
mstefanko / Hide the status bar and title bar
Created March 28, 2011 13:00
Hide the status bar and title bar
//for hide the status bar
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
//hide the title bar
@mstefanko
mstefanko / Calculate android screen size
Created March 28, 2011 13:15
calculates android screen size
Display display;
display = ((WindowManager)getSystemService(WINDOW_SERVICE)).getDefaultDisplay();
int height = display.getHeight();
int width = display.getWidth();
@mstefanko
mstefanko / Get tilt from accelerometer values
Created March 28, 2011 13:21
Get tilt from accelerometer values
double accX = -x/SensorManager.GRAVITY_EARTH;
double accY = -y/SensorManager.GRAVITY_EARTH;
double accZ = z/SensorManager.GRAVITY_EARTH;
double totAcc = Math.sqrt((accX*accX)+(accY*accY)+(accZ*accZ));
double tiltX = Math.asin(accX/totAcc);
double tiltY = Math.asin(accY/totAcc);
double tiltZ = Math.asin(accZ/totAcc);
@mstefanko
mstefanko / read .txt file
Created March 28, 2011 13:23
read .txt file from android
try{
File f = new File(Environment.getExternalStorageDirectory()+"/myFile.txt");
fileIS = new FileInputStream(f);
BufferedReader buf = new BufferedReader(new InputStreamReader(fileIS));
String readString = new String();
//just reading each line and pass it on the debugger
@mstefanko
mstefanko / Kill android app
Created March 28, 2011 13:23
Kill Android app
/* Way one */
android.os.Process.killProcess(android.os.Process.myPid())
/* Way Two */
System.exit(0);
@mstefanko
mstefanko / Android
Created March 28, 2011 13:25
Enable/disable wifi
WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
wifi.setWifiEnabled(enabled);
@mstefanko
mstefanko / gist:890440
Created March 28, 2011 13:25
Can app access internet
*@return boolean return true if the application can access the internet
*/
private boolean haveInternet(){
NetworkInfo info=(ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE).getActiveNetworkInfo();
if(info==null || !info.isConnected()){
return false;
}
if(info.isRoaming()){
//here is the roaming option you can change it if you want to disable internet while roaming, just return false
return true;
@mstefanko
mstefanko / gist:890441
Created March 28, 2011 13:26
Call a given number using Android Intent
//Present you with the dialler
Code: Select all
Uri telUri = Uri.parse("tel:100861");
returnIt = new Intent(Intent.ACTION_DIAL, telUri);
// Start the call
@mstefanko
mstefanko / gist:890443
Created March 28, 2011 13:27
Get your mobile number
private String getMyNumber(){
TelephonyManager mTelephonyMgr;
mTelephonyMgr = (TelephonyManager)
getSystemService(Context.TELEPHONY_SERVICE);
return mTelephonyMgr.getLine1Number();
}
@mstefanko
mstefanko / gist:890446
Created March 28, 2011 13:27
Distence calculation between two GPS points
private double gps2m(float lat_a, float lng_a, float lat_b, float lng_b) {
float pk = (float) (180/3.14169);
float a1 = lat_a / pk;
float a2 = lng_a / pk;
float b1 = lat_b / pk;
float b2 = lng_b / pk;
float t1 = FloatMath.cos(a1)*FloatMath.cos(a2)*FloatMath.cos(b1)*FloatMath.cos(b2);
float t2 = FloatMath.cos(a1)*FloatMath.sin(a2)*FloatMath.cos(b1)*FloatMath.sin(b2);