Skip to content

Instantly share code, notes, and snippets.

View LarsEliasNielsen's full-sized avatar

Lars Nielsen LarsEliasNielsen

  • Autorola
  • Odense
  • 00:22 (UTC +02:00)
View GitHub Profile
@LarsEliasNielsen
LarsEliasNielsen / TextWatcherActivity.java
Created December 6, 2014 15:17
Playing with Android TextWatcher
package org.coursera.four;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.text.Editable;
import android.text.TextWatcher;
@LarsEliasNielsen
LarsEliasNielsen / MainActivty.java
Created November 22, 2014 13:19
Open navigation drawer when application opens
public class MainActivity extends Activity {
// Delay in millisec.
private static final int DRAWER_DELAY = 200;
// Member varaible for navigation drawer.
private DrawerLayout mNavigationDrawerLayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
// Get the navigation drawer and assign to member variable.
@LarsEliasNielsen
LarsEliasNielsen / MainActivity.java
Created November 7, 2014 15:05
Saving data in activity instance state
/**
* When the user changes orientation in the activity, the activity is redrawn.
* To prevent loss of my variables (like what question is active) I save a variable into
* the instance state of my activity.
* When this is done, I can prevent the user fron detecting the redraw of my activity.
*/
public class MainActivity extends Activity {
// My variable I want to keep.
public int currentQuestionNumber = 0;
@LarsEliasNielsen
LarsEliasNielsen / espn_news.module
Created March 19, 2014 13:27
Drupal 7 Module Development: Validate
<?php
/**
* Implements hook_validate().
*
* Validation for configuration form. Since we need a number in the
* limit-textfield, we check that the input is correct.
*
* @url: https://api.drupal.org/api/drupal/modules!node!node.api.php/function/hook_validate/7
*/
@LarsEliasNielsen
LarsEliasNielsen / espn_news.module
Created March 6, 2014 09:07
Drupal 7 Module Development: Content callback in block
<?php
/**
* Implements hook_block_view().
*
* Creates content for our block. It sets the title for the block, and returns
* our news (from our custom callback) as a ul-list, with the id 'espn-news'.
*
* @url: https://api.drupal.org/api/drupal/modules!block!block.api.php/function/hook_block_view/7
*/
@LarsEliasNielsen
LarsEliasNielsen / espn_news.module
Last active August 29, 2015 13:57
Drupal 7 Module Development: API content callback
<?php
/**
* Custom API content callback.
*
* This callback is a custom callback to get ESPN news data.
* Here we request the data, preprocesses it and creates a list of news. The
* array '$items' contains all the news, we'll display it as a unordered list
* later on.
*
@LarsEliasNielsen
LarsEliasNielsen / espn_news.module
Last active August 29, 2015 13:57
Drupal 7 Module Development: Config form
<?php
/**
* Implements hook_form().
*
* Creates a configuration form. See the API reference for info on different
* form inputs.
*
* From API Reference: https://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7
*
@LarsEliasNielsen
LarsEliasNielsen / espn_news.module
Created March 5, 2014 13:58
Drupal 7 Module Development: Menu to config page
<?php
/**
* Implements hook_menu().
*
* Defines paths to provide page callbacks and menu items for the site.
* Here it defines a configuration page with callback to a form, we'll
* create later on.
*
* @url: https://api.drupal.org/api/drupal/modules!system!system.api.php/function/hook_menu/7
@LarsEliasNielsen
LarsEliasNielsen / espn_news.info
Created March 4, 2014 14:07
Drupal 7 Module Development: Config in .info file
name = ESPN News
description = Provides a block with recent ESPN sport news.
core = 7.x
package = Custom
; Link to configuration page, set in espn_news.module: espn_news_menu()
configure = admin/config/content/espn_news
@LarsEliasNielsen
LarsEliasNielsen / espn_news.module
Created March 4, 2014 13:41
Drupal 7 Module Development: Block Content
<?php
/**
* Implements hook_block_view().
*
* Creates content for our block. It sets the title for the block, and the
* content.
*
* @url: https://api.drupal.org/api/drupal/modules!block!block.api.php/function/hook_block_view/7
*/