Skip to content

Instantly share code, notes, and snippets.

View Kursulla's full-sized avatar

Nebojsa Bozic Kursulla

View GitHub Profile
@Kursulla
Kursulla / gist:9288652
Created March 1, 2014 11:34
[Android] Remove status bar
private void removeStatusBar() {
if (Build.VERSION.SDK_INT < 16) {
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
} else {
View decorView = getWindow().getDecorView();
// Hide the status bar.
int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);
}
}
@Kursulla
Kursulla / gist:9408501
Created March 7, 2014 09:38
Twice Back Button Exit [Android]
//Define as Actviity properties
private long backPressTime;
private static final int DOUBLE_BACK_TIME_LIMIT = 800;
//Define method that will perform the "magic"
private void doubleBackPressTrigger() {
if (backPressTime + DOUBLE_BACK_TIME_LIMIT > System.currentTimeMillis()) {
super.onBackPressed();
}else {
Toast.makeText(getBaseContext(), "Press \"Back\" twice to get out of the application!", Toast.LENGTH_SHORT).show();
@Kursulla
Kursulla / gist:9530370
Created March 13, 2014 15:15
Small utils for Android
import android.app.Activity;
import android.content.Context;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
/**
* Created by kursulla on 3/13/14.
*/
public class AndroidUtil {
public static boolean isTablet(Context context) {
package rs.webnet.locmar.util;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.util.Log;
/**
* Created by kursulla on 2/10/14.
* <p/>
@Kursulla
Kursulla / 0_reuse_code.js
Created May 31, 2014 21:55
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@Kursulla
Kursulla / gist:d9e504ae9730301ec5e1
Created May 15, 2015 13:48
Rails - unauthorised
render json:{error:'401 Unauthorized!'},status: 401
@Kursulla
Kursulla / gist:5656006
Last active December 17, 2015 18:49
Create screenshot in iOS. [Objective-C,ios,xcode]
CGSize screenSize = [[UIScreen mainScreen] applicationFrame].size;
CGColorSpaceRef colorSpaceRef = CGColorSpaceCreateDeviceRGB();
CGContextRef ctx = CGBitmapContextCreate(nil, screenSize.width, screenSize.height, 8, 4*(int)screenSize.width, colorSpaceRef, kCGImageAlphaPremultipliedLast);
CGContextTranslateCTM(ctx, 0.0, screenSize.height);
CGContextScaleCTM(ctx, 1.0, -1.0);
[(CALayer*)self.view.layer renderInContext:ctx];
@Kursulla
Kursulla / gist:5656038
Last active December 17, 2015 18:49
Split one image into two images and place them into separated containers [Objective-C, objc, xcode, ios]
UIImage *image = [UIImage imageNamed:@"some_image.png"];
CGImageRef tmpImgRef = image.CGImage;
//Taking left part of image from 0 to half of width
CGImageRef leftImgRef = CGImageCreateWithImageInRect(tmpImgRef, CGRectMake(0, 0, image.size.width/2.0, image.size.height ));
UIImage *leftUIImage = [UIImage imageWithCGImage:leftImgRef];
CGImageRelease(leftImgRef);
//Taking right of image from half of width to full width
CGImageRef rightImgRef = CGImageCreateWithImageInRect(tmpImgRef, CGRectMake(image.size.width / 2.0, 0, image.size.width/2.0, image.size.height));
@Kursulla
Kursulla / gist:5656058
Created May 27, 2013 09:20
Animate UI changes [Objective-C,ios,xcode,objc, animation, animate]
CGRect someUIElementFrame = _someUIElement.frame;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.3];
// [UIView setAnimationDelay:1.0];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
someUIElementFrame.origin.x=-120;
[_someUIElement setFrame:leftsomeUIElementFrameImageFrame];
@Kursulla
Kursulla / gist:5656460
Created May 27, 2013 10:51
Break NSDate into components (dat, month, hour,....) [Objective-C,ios,xcode,NSDate, NSDateComponents]
NSDateComponents *components = [[NSCalendar currentCalendar] components:NSDayCalendarUnit | NSMonthCalendarUnit | NSYearCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit fromDate:[NSDate date]];
long showMonth=(long)[components month];
long showDay=(long)[components day];
long showYear=(long)[components year];
long showHours=[[partsOfTime objectAtIndex:0] longLongValue];
long showMinutes=[[partsOfTime objectAtIndex:1] longLongValue];