Skip to content

Instantly share code, notes, and snippets.

@mpaloulack
mpaloulack / gist:10472995
Created April 11, 2014 14:23
Handler ou comment utiliser un timer
Handler mHandler;
Runnable mRunnable = new Runnable() {
@Override
public void run() {
Log.v("Handlers", "Calls");
}
};
@mpaloulack
mpaloulack / gist:10472674
Last active August 29, 2015 13:59
Utilisation des fragment
Fragment frag;
//ajout d'un fragment
TonFragment newFragment = new TonFragment();
android.support.v4.app.FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.add(R.id.fragment_container, newFragment).addToBackStack("A_B_TAG");
transaction.commit();
//remplacement d'un fragment
@mpaloulack
mpaloulack / gist:9836709
Created March 28, 2014 16:19
hide keybord in start activity android
<!-- A ajouter dans l'activité de l'application -->
android:windowSoftInputMode="stateHidden"
@mpaloulack
mpaloulack / gist:9780046
Created March 26, 2014 10:00
Get distance between 2 locations
-(float)kilometersfromPlace:(CLLocationCoordinate2D)from andToPlace:(CLLocationCoordinate2D)to {
CLLocation *userloc = [[CLLocation alloc]initWithLatitude:from.latitude longitude:from.longitude];
CLLocation *dest = [[CLLocation alloc]initWithLatitude:to.latitude longitude:to.longitude];
CLLocationDistance dist = [userloc distanceFromLocation:dest]*4;
NSString *distance = [NSString stringWithFormat:@"%f",dist];
@mpaloulack
mpaloulack / gist:9765337
Created March 25, 2014 16:16
Get density of screen device
float density = getResources().getDisplayMetrics().density;
@mpaloulack
mpaloulack / gist:9765287
Last active August 29, 2015 13:57
Android Many font in button
final SpannableString textVidOTW = new SpannableString(Html.fromHtml("Video<br/>OF THE WEEK"));
textVidOTW.setSpan(new RelativeSizeSpan(0.7f*density), 0, 5, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
textVidOTW.setSpan(new TypefaceSpan(this, "fonts/Lighthouse_PersonalUse.ttf"), 0, 5,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
textVidOTW.setSpan(new RelativeSizeSpan(0.3f*density), 5, textVidOTW.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
//and add class
public class TypefaceSpan extends MetricAffectingSpan {
/** An <code>LruCache</code> for previously loaded typefaces. */