Skip to content

Instantly share code, notes, and snippets.

View slightfoot's full-sized avatar
💙
Fluttering

Simon Lightfoot slightfoot

💙
Fluttering
View GitHub Profile
@slightfoot
slightfoot / DateTimeTest.java
Last active August 29, 2015 13:56
Date time with TimeZone
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.TimeZone;
import java.text.ParsePosition;
import java.text.DateFormat;
import java.util.Date;
public class DateTimeTest
{
@slightfoot
slightfoot / gist:9058579
Created February 17, 2014 20:35
getContactName function to get a Contacts Name from their Phone Number
private String getContactName(String phoneNumber)
{
String name = null;
ContentResolver cr = getContentResolver();
Cursor cur = cr.query(Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI,
Uri.encode(phoneNumber)), new String[]{ PhoneLookup.DISPLAY_NAME }, null, null, null);
if(cur != null){
try{
if(cur.getCount() > 0){
if(cur.moveToFirst()){
/*
new CountDownUpdate((TextView)findViewById(R.id.accept_text), 90,
new CountDownUpdate.Callback(){
@Override
public void onCountDownComplete(TextView textView)
{
Toast.makeText(getApplicationContext(), "BOOM!", Toast.LENGTH_LONG).show();
}
});
*/
@slightfoot
slightfoot / ActivityA.java
Last active August 29, 2015 13:56
Example of interaction between two activities.
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
public class ActivityA extends Activity
{
private static final int REQUEST_CODE_INFO = 1000;
@slightfoot
slightfoot / MainActivity.java
Created April 26, 2014 17:15
Sharing as a Sub Menu Example
package com.example.sharesubmenu;
import java.util.List;
import android.support.v4.app.FragmentActivity;
import android.content.ComponentName;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.os.Bundle;
@slightfoot
slightfoot / MainActivity.java
Last active August 29, 2015 14:00
Example of DialogFragment and HeadlessFragment's linked
package bbc.mobile.news.mps;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
@slightfoot
slightfoot / readTextFromUri.java
Last active August 29, 2015 14:00
Read Text From Uri
private String readTextFromUri(Uri uri) throws IOException
{
InputStream in = null;
try{
in = getContentResolver().openInputStream(uri);
StringBuilder sb = new StringBuilder(in.available());
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
char[] buffer = new char[1024];
int len;
while((len = reader.read(buffer)) != -1){
@slightfoot
slightfoot / getThemeAttributeDimensionSize.java
Created June 14, 2014 18:54
getThemeAttributeDimensionSize
public static int getThemeAttributeDimensionSize(Context context, int attr)
{
TypedArray a = null;
try{
a = context.getTheme().obtainStyledAttributes(new int[] { attr });
return a.getDimensionPixelSize(0, 0);
}finally{
if(a != null){
a.recycle();
}
@slightfoot
slightfoot / reverse_id.php
Created July 10, 2014 22:57
Android Reverse ID Lookup Util... for those crash bugs you just hate.
<?php
/*
Android Reverse ID Lookup Util
------------------------------
Use ApkTool to extract resources: apktool d -s filename.apk
then go into res\values or copy public.xml and run with this script.
Copyright 2014 Simon Lightfoot <simon@demondevelopers.com>
Licensed under the Apache License, Version 2.0 (the "License");
package com.demondevelopers.githubclient;
import java.util.List;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.v4.app.ListFragment;
import android.support.v4.app.LoaderManager.LoaderCallbacks;