Skip to content

Instantly share code, notes, and snippets.

View darwind's full-sized avatar

Kasper Rugård Thomsen darwind

  • rugaard.it
  • Copenhagen
View GitHub Profile
@darwind
darwind / snippet
Created February 24, 2015 20:59
Android - open Language settings directly from an app.
startActivity(new Intent(Settings.ACTION_LOCALE_SETTINGS));
@darwind
darwind / MainActivity.java
Last active August 29, 2015 14:14
Implementing the new ToolBar instead of the ActionBar
package com.example.toolbarexample;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
public class MainActivity extends ActionBarActivity {
@darwind
darwind / gist:08241d74d01fef0dfb69
Last active August 29, 2015 14:05
Show/hide Navigation Bar in iOS
To hide the navigation bar:
[[self navigationController] setNavigationBarHidden:YES animated:YES];
To show it:
[[self navigationController] setNavigationBarHidden:NO animated:YES];
See: http://stackoverflow.com/questions/2926914/navigation-bar-show-hide
@darwind
darwind / AndroidVersionCode.java
Created August 7, 2014 13:19
Gets the versioncode of the current app.
public int getVersionCode() {
int versionCode = 0;
try {
versionCode = getPackageManager().getPackageInfo(getPackageName(), 0).versionCode;
} catch (PackageManager.NameNotFoundException e) {
// Huh? Really?
}
return versionCode;
}
@darwind
darwind / date-to-string-and-string-to-date
Last active August 29, 2015 14:02
Formatting NSDate to NSString and vice versa...
---- NSDate -> NSString ----
NSDateFormatter *formatter;
NSString *dateString;
formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"dd-MM-yyyy HH:mm"]; // Change accordingly.
dateString = [formatter stringFromDate:[NSDate date]];
@darwind
darwind / passing_data_ios
Created June 15, 2014 17:58
Passing data between ViewControllers in Objective-C
- (void) prepareForSegue:(UIStoryboardSegue *) segue sender:(id)sender
{
NextViewController *controller = (NextViewController *)segue.destinationViewController;
if([segue.identifier isEqualToString:@"mySegueIdentifier"]) {
controller.parameter = @"My value to pass to the next controller!";
} else {
// Else do something else.
}
}
@darwind
darwind / onkeypressup-javascript.html
Last active August 29, 2015 14:01
Pure JavaScript: onKeyPressUp change element on page.
<!DOCTYPE html>
<html>
<head>
<script>
function myFunction(e) {
if(e.keyCode == 97 || e.keyCode == 65) {
document.getElementById("textChange").innerHTML = "A or a was pressed!";
} else if (e.keyCode == 66 || e.keyCode == 98) {
document.getElementById("textChange").innerHTML = "B or b was pressed!";
} else {
@darwind
darwind / Screenwidth
Created May 5, 2014 14:27
Get screenwidth
private int getScreenWidth(Context context) {
WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();
DisplayMetrics metrics = new DisplayMetrics();
display.getMetrics(metrics);
int width = metrics.widthPixels;
return width;
}
@darwind
darwind / noselectors
Created April 3, 2014 11:36
Android: no selectors in ListView
In XML add this to the ListView:
android:listSelector="@android:color/transparent"
In code add this to the ListView:
myListView.setSelector(android.R.color.transparent);
@darwind
darwind / remove_dividers
Created April 2, 2014 22:56
Android: remove dividers between ListView items
In code:
getListView().setDivider(null);
getListView().setDividerHeight(0);
In XML:
android:divider="@null"
android:dividerHeight="0dp"