Skip to content

Instantly share code, notes, and snippets.

View scruffyfox's full-sized avatar
🏳️‍🌈
+++

ScruffyFox scruffyfox

🏳️‍🌈
+++
View GitHub Profile
@scruffyfox
scruffyfox / gist:2420041
Created April 19, 2012 09:56
Get image from gallery in onActivityResult
try
{
Uri selectedUri = data.getData();
// can post image
String[] proj = {MediaStore.Images.Media.DATA};
Cursor cursor = managedQuery(selectedUri, proj, null, null, null);
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
@scruffyfox
scruffyfox / gist:2469954
Created April 23, 2012 09:57
Share activity
package com.cube.bec;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Window;
public class BECShareApp extends Activity
{
@Override protected void onCreate(Bundle savedInstanceState)
@scruffyfox
scruffyfox / gist:2634195
Created May 8, 2012 10:50
Removing "cache_" from filenames in a folder
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <dirent.h>
int main();
char *str_replace(char *search , char *replace , char *subject);
int main()
{
@scruffyfox
scruffyfox / gist:2888217
Created June 7, 2012 11:00
Min and max location
maxLatitude = Math.max((int)(lat * 1E6), maxLatitude);
minLatitude = Math.min((int)(lat * 1E6), minLatitude);
maxLongitude = Math.max((int)(lng * 1E6), maxLongitude);
minLongitude = Math.min((int)(lng * 1E6), minLongitude);
@scruffyfox
scruffyfox / gist:3039716
Created July 3, 2012 13:32
Restart app
Intent splashScreen = new Intent(mContext, FASplashView.class);
splashScreen.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
splashScreen.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
splashScreen.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
splashScreen.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(splashScreen);
@scruffyfox
scruffyfox / gist:3052968
Created July 5, 2012 10:57
Fit all points on a map
//====== GLOBAL VARIABLES ======
protected int minLatitude = Integer.MAX_VALUE;
protected int maxLatitude = Integer.MIN_VALUE;
protected int minLongitude = Integer.MAX_VALUE;
protected int maxLongitude = Integer.MIN_VALUE;
//====== WHEN LOOPING THROUGH EACH POINT ======
maxLatitude = Math.max((int)(point.getDouble("lat") * 1E6), maxLatitude);
minLatitude = Math.min((int)(point.getDouble("lat") * 1E6), minLatitude);
maxLongitude = Math.max((int)(point.getDouble("long") * 1E6), maxLongitude);
// Create re-hashable password for the device
String deviceId = Secure.getString(context.getContentResolver(), Secure.ANDROID_ID);
deviceId = deviceId == null ? "NOID" + System.currentTimeMillis() : deviceId;
// Now we hash it and b64 it
String deviceHash = CacheManager.getHash(deviceId);
@scruffyfox
scruffyfox / gist:3070725
Created July 8, 2012 12:29
maps directions
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("http://maps.google.com/maps?saddr=20.344,34.34&daddr=20.5666,45.345"));
startActivity(intent);
@scruffyfox
scruffyfox / gist:3128925
Created July 17, 2012 11:34
Example tab with ViewPager
public abstract class ARCMainView extends ARCFragmentActivity implements OnDownloadListener
{
private ViewPager mViewPager;
private TabsAdapter mTabsAdapter;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
@scruffyfox
scruffyfox / gist:3181280
Created July 26, 2012 09:54
Set debuggable
boolean isDebuggable = (0 != (getApplicationInfo().flags &= ApplicationInfo.FLAG_DEBUGGABLE));
Debug.setDebugMode(isDebuggable);