Monthly Archives: February 2015

Custom Color Listview Selected

Pada res, buat file color_selector.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="">
    <item android:state_pressed="true" android:color="#04b3d3" />
    <item android:state_selected="true" android:color="#048563" />
    <item android:color="#04b3d3" />

Pada textview property, tambahkan android:textColor=”@color/color_selector”.


Pada program java, tambahkan view.setSelected(true);.

list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {


Arduino command line syntax


arduino [FILE.ino…]

arduino [–verify|–upload] [–board package:arch:board[:parameters]] [–port portname] [–pref name=value] [-v|–verbose] [FILE.ino]



The arduino integrated development environment allows editing, compiling and uploading sketches (programs) for Arduino (and compatible) microcontroller boards.

Normally, running the arduino command starts the IDE, optionally loading any .ino files specified on the commandline.

Alternatively, if any of the following command line options is given, no graphical interface will be shown and instead a one-off verify (compile) or upload will be done. A single .ino file should be given. If the sketch contains multiple .ino files, any one can be specified on the commandline, but the entire sketch will be compiled.

When running in a one-off mode, it might be useful to set the build.path preference to allow keeping intermediate build results between multiple runs and only recompile the files that changed.

Note that on MacOS X, the main executable is instead of arduino.



–board package:arch:board[:parameters]
Select the board to compile for.

  • package is the identifier of the vendor (the first level folders inside the hardware directory). Default arduino boards use arduino.
  • architecture is the architecture of the board (second level folders inside the hardware directory). Default arduino boards use either arduino:avr for all AVR-based boards (like Uno, Mega or Leonardo) or arduino:sam for 32bit SAM-based boards (like Arduino Due).
  • board is the actual board to use, as defined in boards.txt contained in the architecture folder selected. For example, arduino:avr:uno for the Arduino Uno, arduino:avr:diecimila for the Arduino Duemilanove or Diecimila, or arduino:avr:mega for the Arduino Mega.
  • parameters is a comma-separated list of boards specific parameters that are normally shown under submenus of the “Tools” menu. For example arduino:avr:nano:cpu=atmega168 to Select the mega168 variant of the Arduino Nano board.
If this option is not passed, the value from the current preferences is used (e.g., the last board selected in the IDE).
–port portname
Select the serial port to perform upload of the sketch. On linux and MacOS X, this should be the path to a device file (e.g., /dev/ttyACM0). On Windows, this should be the name of the serial port (e.g., COM3).
If this option is not passed, the value from the current preferences is used (e.g., the last port selected in the IDE).
Enable verbose mode during build. If this option is not given, verbose mode during build is disabled regardless of the current preferences.
This option is only valid together with –verify or –upload.
Enable verbose mode during upload. If this option is not given, verbose mode during upload is disabled regardless of the current preferences.
This option is only valid together with –verify or –upload.
-v, –verbose
Enable verbose mode during build and upload. This option has the same effect of using both –verbose-build and –verbose-upload.
This option is only valid together with –verify or –upload.
–preferences-file filename
Read and store preferences from the specified filename instead of the default one.
–pref name=value
Sets the preference name to the given value.
Note that the preferences you set with this option are not validated: Invalid names will be set but never used, invalid values might lead to an error later on.
Save any (changed) preferences to preferences.txt. In particular –board, –port, –pref, –verbose, –verbose-build and –verbose-upload may alter the current preferences.
Build and upload the sketch.
Build the sketch.
–get-pref preference
Prints the value of the given preference to the standard output stream. When the value does not exist, nothing is printed and the exit status is set (see EXIT STATUS below).


Arduino keeps a list of preferences, as simple name and value pairs. Below, a few of them are documented but a lot more are available.

The path where sketches are (usually) stored. This path can also contain some special subdirectories (see FILES below).
When set to true, the IDE checks for a new version on startup.
When set to true, use an external editor (the IDE does not allow editing and reloads each file before verifying).
The path to use for building. This is where things like the preprocessed .cpp file, compiled .o files and the final .hex file go.
If set, this directory should already exist before running the arduino command.
If this preference is not set (which is normally the case), a new temporary build folder is created on every run and deleted again when the application is closed.


Build failed or upload failed
Sketch not found
Invalid (argument for) commandline option
Preference passed to –get-pref does not exist


This file stores the preferences used for the IDE, building and uploading sketches.
My Documents/Arduino/ (Windows)
~/Documents/Arduino/ (Mac OS X)
~/Arduino/ (Linux)
This directory is referred to as the “Sketchbook” and contains the user’s sketches. The path can be changed through the sketchbook.path preference.
Apart from sketches, three special directories can be inside the sketchbook:

Libraries can be put inside this directory, one library per subdirectory.
Support for third-party hardware can be added through this directory.
External code-processing tools (that can be run through the Tools menu of the IDE) can be added here.


Start the Arduino IDE, with two files open:

arduino /path/to/sketch/sketch.ino /path/to/sketch/extra.ino

Compile and upload a sketch using the last selected board and serial port

arduino --upload /path/to/sketch/sketch.ino

Compile and upload a sketch to an Arduino Nano, with an Atmega168 CPU, connected on port /dev/ttyACM0:

arduino --board arduino:avr:nano:cpu=atmega168 --port /dev/ttyACM0 --upload /path/to/sketch/sketch.ino

Compile a sketch, put the build results in the build directory an re-use any previous build results in that directory.

arduino --pref build.path=/path/to/sketch/build --verify /path/to/sketch/sketch.ino

Change the selected board and build path and do nothing else.

arduino --pref build.path=/path/to/sketch/build --board arduino:avr:uno --save-prefs



Added initial commandline support. This introduced –verify, –upload, –board, –port, –verbose and -v.
Added support for board-specific parameters to –board.
Sketch filenames are now interpreted relative to the current directory instead of the location of the arduino command itself.
Introduced –pref, –preferences-file, –verbose-build and –verbose-upload.
Preferences set through –pref are remembered, preferences set through –board, –port or the –verbose options are not.
When running with –verify or –upload, the full GUI is no longer shown. Error messages still use a graphical popup and on Windows, the splash screen is still shown.
Introduced –save-prefs.
–pref options are now not saved to the preferences file, just like –board and –port, unless –save-prefs is specified.
A path passed to –preferences-file, or set in the build.path, preferences.path or settings.path is now interpreted relative to the current directory instead of the location of the arduino command itself. 



Arduino 1.0.6
Arduino 1.5.8
Arduino 1.6.0


Menghapus Category Base dari URL pada WordPress 2

Jika ingin menghilangkan category pada url (misal: menjadi itu sangat mudah tanpa menggunakan plugin khusus.


Cara pertama:

Buka Setting > Permalinks, ganti Common Settings menjadi Custom Structure dengan parameter: “/%category%/%postname%” (tanpa danda petik dua) dan pada Category base isi dengan “.” (tanpa danda petik dua). Kemudian klik Save Change.

Cara kedua:

Selain cara diatas, dapat pula dilakukan dengan menambahkan script pada .htaccess.

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^category/(.+)$$1 [R=301,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

Android TimerTask

Pada kali ini akan dicontohkan penggunaan Timer dan TimerTask untuk sekali perhitungan timer maupun timer yang berulang-ulang (repeat) pada jeda waktu tertentu.

Buat variabel yang diperlukan pada program java.

private Timer timer;
private TimerTask timerTask;

Buat method startTimer(int time). Method ini digunakan untuk perhitungan timer yang bersifat sekali jalan.

private void startTimer(int time) {
    timer = new Timer();

Buat method startRepeatTimer(int time). Method ini digunakan untuk perhitungan timer yang berulang-ulang (repeat).

private void startRepeatTimer(int time) {
    timer = new Timer();

Buat method stopTimer();

private void stopTimer() {
    if(timer != null) {
    timer = null;

Buat method initTimerTask();

private void initTimerTask() {
    timerTask = new TimerTask() {
        public void run() {
            System.out.println("On Timer.");

Untuk menjalankan timer, tinggal panggil method startTimer(int timer) atau method startRepeatTImer(int timer).


Gunakan Handler jika ingin menampilkan data pada TextView maupun sejenisnya.

Buat object dari class Handler.

Handler timerHandler;
timerHandler = new Handler() {
    public void handleMessage(Message msg) {
        switch (msg.what) {
            case 0:

Gunakan sendMessage untuk menampilkan data.

private void initTimerTask() {
    timerTask = new TimerTask() {
        public void run() {
            Message msg = Message.obtain(null,0,"On Timer.");


Source code:

Android BroadcastReceiver

Untuk bagian broadcast:

Intent intent = new Intent();
intent.putExtra("pagi","Selamat pagi.");

Untuk bagian receiver:

// Buat receiver.
BroadcastReceiver bReceiver = new BroadcastReceiver() {
    public void onReceive(Context context, Intent intent) {
        String str = intent.getStringExtra("pagi");
// Buat filter.
IntentFilter filter = new IntentFilter();
// Daftarkan receiver dan filter.


Source code:

Detecting Internet Connection

Jika kita menggunakan koneksi internet pada program android, hal yang perlu diperhatikan adalah status dari koneksi internet tersebut. Jangan sampai program yang dibuat tidak mengetahui kalau internet telah terputus. Untuk mengatasi hal ini, dengan BroadcastReceiver.

context.registerReceiver(new BroadcastReceiver() {
        public void onReceive(Context context, Intent intent) {
            boolean noConnectivity = intent.getBooleanExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, false);
                if (noConnectivity) {
                    // Lakukan sesuatu jika tidak ada koneksi.
                } else {
            // Lakukan sesuatu jika tidak ada koneksi.
}, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));

Pada bagian manifest, tambahkan permissin berikut:

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />