Specify Roboto font in Android

There is a pretty nice font in Android called Roboto. Introduced in version 4.1 and enhanced in 4.2 and 5.0. Specimen and download is available at android design guidelines. What’s kinda missing is the way how to use the Roboto font in your app.

android:fontFamily="sans-serif"           // roboto regular
android:fontFamily="sans-serif-light"     // roboto light
android:fontFamily="sans-serif-condensed" // roboto condensed
android:fontFamily="sans-serif-thin"      // roboto thin (android 4.2)
android:fontFamily="sans-serif-medium"    // roboto medium (android 5.0)

Combine above with font weight specification and you will get all the possible variants:

android:textStyle="normal|bold|italic"

Update PHP to 5.6 @ debian wheezy

I’ve just updated PHP version to 5.6. Check the migration guide for incompatibilities (no big thing there). You will get slightly better performance and some new features.

# sudo nano /etc/apt/sources.list.d/dotdeb.list

And insert these two lines:

deb http://packages.dotdeb.org wheezy-php56 all
deb-src http://packages.dotdeb.org wheezy-php56 all

And add the key:

# wget http://www.dotdeb.org/dotdeb.gpg -O- |apt-key add -

You are ready to go, just update & upgrade your system.

# apt-get update && apt-get upgrade

If you get The following packages have been kept back: you have to run:

# apt-get dist-upgrade

 

Giveaway – Avocode Beta Invite

I have one beta invite to Avocode and I would love to share it with you. Avocode is an awesome tool created by madebysource.com (you may know their other products – CSS Hat, PNG Hat or LESS Hat). And what is the Avocode?

If you code websites you will love it. It’s a way how to get rid of Photoshop because you are not going to need Photoshop anymore. You just open the psd file in Avocode and extract all needed resources simply by clicking the right buttons. And there is more. You will get resources for all resolutions, CSS file or even icon font. Check out the video below or the website wit all avocodes features:

How to get an invite?

Post comment to this article (with your email address). By the 7th September I am going to announce the winner (will be drawn from a hat) and I will send the invite to his/her email account.

Simple like that.

Note: Avocode is now available only for Mac, however even if you are not a Mac user, you are eligible to try to get the invite. But you will have to wait for Linux/Windows version .

7 tools every PHP developer should know

GIT | Bitbucket | GitHub

Distributed revision control and source code management system is what wikipedia says about GIT.  GIT is powerful tool giving you an opportunity to version your code and much more (for example deployment – try it and you’ll love it).

Bitbucket and GitHub are web based hosting services for your repos. Bitbucket gives you unlimited number of private repos (up to 5 users) and GitHub is mostly used for open sourced projects (public repos), so you are able to find there almost every source code you need.

Do you still use Subversion? It’s time to give a try to a GIT.  Are you not versioning your files? You should start with GIT right away!

FTP | Filezilla

GIT deployment is totally cool, but there’s sometimes situation you are not able to use it. For these moments there is the Filezilla – great FTP client supporting linux and windows. Go ahead.

IDE | PhpStorm

Of course you are going to need an IDE. And in my opinion the best one is PhpStorm. For a reasonable price you will get kick ass tool. Integrates GIT, FTP client and terminal, so you really don’t need to switch to other apps during the development. Really worth a try.

Framework | Nette Framework

There’s a lot of PHP frameworks. You probably know Symfony or Zend, but the slickest one is not so widely known framework called Nette. If nothing you should at least check out Tracy (debugging tool), Tester (do you write tests, right?) or Latte (amazing template engine).

Tracy in action
Tracy in action

Dependencies | Composer

You don’t know Composer? And how do you maintain your projects libraries? Go for it right now. This is the future of PHP development.

Hosting | Digital Ocean

If you are maintaining a lot of web apps or websites you should consider to buy a VPS. Just because it’s cheaper and you have the whole environment under your control. There’s no problem with old version PHP, the PHP is set up the way u want to and because you can set up the GIT deployment.

I recommend to try Digital Ocean – it’s working on SSD and servers are really fast and surprisingly cheap. Starts at $5/month, simply scalable.

Server & Database | Nginx + Postgresql

You are probably familiar with Apache (web server) and MySQL. Check out MariaDB (MySQL fork, for now it’s compatible) – it might be better match for your projects. Anyway there’s a lot of great stuff in web servers too. Earlier this year I was trying Lighty (lighttpd) but afterall, the nginx looks like true love for me and I am trying to use this one for all projects from now on. Why? It saves me a lot of server resources and it’s highly configurable.

And at last but not least the PostgreSQL. MySQL is great but not compared to PostgreSQL. If you need to work with JSONs or geodata and you still want to use object-relational database, this is the one.

 Resume

Lot of interesting tools were mentioned above but there’s still lot of them out there. Share your favorite tools in comments. Really looking forward for your opinions.

 

Android Tutorial – Square Layout

For the latest app I’ve developed, I needed to use squared layout. It would be easy with fixed size – I would put the height (width) dimension into the dimens.xml file and it would work. However that wasn’t what I needed.

The goal is to have layout which will be squared with width (or height) set up to match_parent.

And because this is not part of the Android SDK, we are going to create it. Firstly create new Java class in your project. I store these files in src/main/java/com.example.something/tools but you are free to choose your own destination 😉 Name it SquareLayout.java.  This file will be extending the LinearLayout, so I will just paste the complete code, it’s pretty simple to understand.

public class SquareLayout extends LinearLayout {

    public SquareLayout(Context context) {
        super(context);
    }

    public SquareLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        int width = MeasureSpec.getSize(widthMeasureSpec);
        int height = MeasureSpec.getSize(heightMeasureSpec);

        // this is the scale between width & height, for square should be == 1
        int scale = 1;

        if (width > (int)(scale * height + 0.5)) {
            width = (int)(scale * height + 0.5);
        } else {
            height = (int)(width / scale + 0.5);
        }

        super.onMeasure(
                MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY),
                MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY)
        );
    }
}

Well done. Now we can use this new layout in your layout files. And it works like this (don’t forget to change com.example.something to your namespace):

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_margin="60dp"
    android:layout_width="match_parent" android:layout_height="match_parent">

    <com.example.something.SquareLayout
        android:background="@color/pink"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        </com.example.something.SquareLayout>

</RelativeLayout>

And it should look like this screenshot:

android-square-layout-tutorial-example

Poker Incomes Reports – android app for casual poker players

Are you a non-pro poker player and do you want to track your winnings (or loses) in poker? This is the app for you. Poker Incomes Reports let’s you track your poker incomes and divide them into the three main categories – tournaments, cash games and online poker.

 

Upgrade from MySQL to MariaDB at Debian

Since I’ve decided to improve performance of my webservers (and migrate from Apache2 to Lighttpd) I wondered if I could do something with an MySQL. And after a research I made a decision that I am going to migrate my servers to MariaDB.
If you never heard about MariaDB you should probably know that MariaDB is a fork of MySQL because MySQL has been bought by an evil company and it’s not so much open sourced and the origin creators of MySQL have decided to do better db server and that’s MariaDB and so on and so on. Boring stuff mostly.Why to migrate?

  • open sourced
  • better engines (in my opinion)
  • performance might be slightly better
  • and it’s fully compatible with MySQL. For a now.

How to migrate?

Surprisingly simple. Python software properties are just for adding new repository by add-apt-repository, you don’t need to install this, if you know how to add repository.

# apt-get install python-software-properties

And add keys:

# apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 0xcbcb082a1bb943db

Add repository:

# add-apt-repository 'deb http://mirror.stshosting.co.uk/mariadb/repo/10.0/debian wheezy main'

Update packages:

apt-get update

And install MariaDB:

apt-get install mariadb-server

mysql_replace_mariadb.fw

That’s it. During installation will be stopped the MySQL server, installed MariaDB, you will be asked for root password and then will started mariaDB server. Service is still mysqld, actually for you  – nothing changed. Everything works the same way as with the MySQL.

And if have not used the latest mysql version, you should run

mysql_upgrade

after installation.

ButterKnife inject views in Fragment

I’ve lost a lot of time to figure it out. I had in onCreateView() in my Fragment:

 ButterKnife.inject(this, rootView);

and it wasn’t working (nullpointerexception), so I was testing what’s wrong and could not fixed it, because it looked allright. And the solution is simple as always. This is the solution for Android Studio (for Eclipse check this)

Open File -> Settings (ctrl + alt + s). Navigate to Compiler -> Annotation Processors and at the top of the window check the Enable annotation processing. That’s it.

butterknife-fragment-inject-android-studio

Android hackathon

Yesterday I was watching last episode of Sherlock and suddenly my phone rang. My friend called me to tell me that I have to join him in the pub to solve some sort of programmers problem. So I did. The problem was that he was suffering of lack of programmers.

Long story short, he asked me to help him with an android app. Firstly he had planned to use Titanium SDK but he found out that this is not working solution for him after all and he has to ship the app for iOS and Android asap. Actually the deadline has been missed already.

So we made a deal – I will try to develop an android app and he will be working on an iOS version at the same time. The latest possible deadline is 14 days.

So my android hackathon started. I got designs today and worked on the layouts and the basic functionality. And prepared most of the resources. Tomorrow (day 3) I would like to implement  something more complicated (there’s an augmented reality in the app, so I will be coding camera stuff).

Will post more about implementation later, there’s a lot of interesting things to share.