Skip to content

Instantly share code, notes, and snippets.

View bouchtaoui-dev's full-sized avatar

Nordin-010 bouchtaoui-dev

  • Netherlands, Rotterdam
View GitHub Profile
public class MyFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bundle) {
View view = inflater.inflate(R.layout.my_fragment, container, false);
// Find your buttons in view, set up onclicks, set up callbacks to your parent fragment or activity here.
// You can create ViewHolder or separate method for that.
// example of accessing views: TextView textViewExample = (TextView) view.findViewById(R.id.text_view_example);
// textViewExample.setText("example");
@bouchtaoui-dev
bouchtaoui-dev / gist:780a9a5d189d56a2a3f6
Last active August 29, 2015 14:14
A simple class that makes a view blink, without the need of Thread or Timer objects. The rest is self explanatory.
import android.content.Context;
import android.graphics.drawable.AnimationDrawable;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.widget.ImageView;
/**
*
* @author Andaluz
* It's free like freedom, but with respect to each other :)'
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<rotate
android:duration="70"
android:fromDegrees="-5"
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="5"
android:repeatMode="reverse"

Intro

Recently, I had to implement an offline mapping solution for an iOS application. Here's a walkthrough of how to do it.

Summary

I generated a tile database using TileMill. I used the Route-Me iOS library which provides a map view that supports offline tile sources.

TileMill

NSString *str = <#some string#>;
CGSize size;
CGSize maxSize = CGSizeMake(<#width#>, <#height#>);
UIFont *font = <#font#>;
if ([str respondsToSelector:@selector(boundingRectWithSize:options:attributes:context:)]) {
NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
[style setLineBreakMode:<#Line break mode#>];
[style setAlignment:<#String alignment#>];
NSDictionary *attributes = @{ NSFontAttributeName:font,
NSParagraphStyleAttributeName:style
NSString* string = @"Hello World";
UIFont *font = [UIFont fontWithName:@"Helvetica-BoldOblique" size:21];
CGSize constraint = CGSizeMake(300,NSUIntegerMax);
NSDictionary *attributes = @{NSFontAttributeName: font};
CGRect rect = [string boundingRectWithSize:constraint
options:(NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading)
@bouchtaoui-dev
bouchtaoui-dev / BtOsx.m
Created December 23, 2015 15:18 — forked from crazycoder1999/BtOsx.m
BT Communication On OSX
//sample of a bluetooth RfComm COmmunication between a GPS and OSX.
//more information on: http://pestohacks.blogspot.it/2012/07/make-osx-talks-with-bluetooth-gps.html
//let's go on.
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
NSLog(@"ok, go on"); //
btDevice = nil;
IOBluetoothDeviceInquiry *ibdi = [IOBluetoothDeviceInquiry inquiryWithDelegate:self]; //inquiry, have delegates methoeds
[ibdi setUpdateNewDeviceNames:YES]; //Yes, I want also names for the bt devices found.
- (IBAction)btnExit:(id)sender {
UIAlertView *messageBox = [[UIAlertView alloc] initWithTitle:@"Exit"
message:@"Are you sure?"
delegate:self
cancelButtonTitle:@"No"
otherButtonTitles:@"Yes", nil];
[messageBox show];
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
- (void) startTimer {
NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval: 0.1 target:self selector:@selector(fireMe) userInfo:nil repeats:YES];
}
- (void) fireMe {
NSLog(@"I'm fired!");
}
// By setting the repeats on YES, makes the timer execute every 0.1 sec which is 100 ms.
// By setting it to NO, will execute the timer just once.
- (void) startTimer {
NSTimer *timer = [[ NSTimer alloc ] initWithFireDate: [NSDate dateWithTimeIntervalSinceNow: 0.0
interval: 0.1
target: self
selector: @selector(fireMe)
userInfo: nil
repeats: NO];
}