Kernel Driver Not Installed (rc=-1908) on OpenSUSE 13.2

  

Jika mengalami kesulitan untuk menjalankan VirtualBox di openSUSE karena error berikut:

 Kernel Driver Not Installed (rc=-1908)

Mungkin solusi berikut ini dapat membantu:

  • Jalankan perintah berukut:
    sudo zypper in make gcc gcc-c++ kernel-source kernel-syms
  • Lanjutkan dengan perintah berikutnya:
    sudo /etc/init.d/vboxdrv setup
  • Jalankan VirtualBox.

Simpan Layout sebagai Image

   

 

Ketika kita membuat suatu aplikasi, terkadang membutuhkan dokumentasi berupa gambar (image).

Berikut adalah salah satu cara untuk membuat image dari layout yang telah dibuat.

Buat method untuk konversi dari view ke bitmap:

private Bitmap getBitmap(View view) {
    view.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED),
            View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
    view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight());
    view.buildDrawingCache(true);
    Bitmap bitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(),Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);

    Drawable background =view.getBackground();
    if (background!=null) {
        background.draw(canvas);
    }else{
        canvas.drawColor(Color.WHITE);
    }
    view.draw(canvas);
    
    return bitmap;
}

Buat method untuk simpan ke dalam bentuk file:

public void save(Bitmap image, String path) {
    try {
        FileOutputStream output = new FileOutputStream(path);
        image.compress(Bitmap.CompressFormat.PNG, 100, output);
        output.close();
        Toast.makeText(context,"File berhasil disimpan di: "+path+".",Toast.LENGTH_LONG).show();
    } catch (FileNotFoundException e) {
//        e.printStackTrace();
        Log.e(TAG, e.toString());
        Toast.makeText(context,"Gagal menyimpan file.",Toast.LENGTH_LONG).show();
    } catch (IOException e) {
//        e.printStackTrace();
        Log.e(TAG, e.toString());
        Toast.makeText(context,"Gagal menyimpan file.",Toast.LENGTH_LONG).show();
    }
}

Panggil method yang telah dibuat:

image = getBitmap(layout);

Buat fungsi untuk menyimpan image:

btnSave.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        String path = Environment.getExternalStorageDirectory()+"/image.png";
        save(image, path);
    }
});
 Buat fungsi untuk menampilkan image:
btnView.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        bmImage.setImageBitmap(image);
    }
});

 

Source code:
download


GDM dan LightDM pada Ubuntu 14.04

Ubuntu menggunakan LightDM sebagai default display manager. Tetapi, jika ingin kembali ke GDM bawaan gnome itu sangat mudah. Buka terminal, kemudian ketikkan perintah berikut:

sudo dpkg-reconfigure gdm

Akan dijumpai tampilan seperti berikut:

Pada tampilan selanjutnya, akan muncul pilihan display manager yang dapat digunakan.

Kemudian ok.


Custom Color Listview Selected

Pada res, buat file color_selector.xml

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

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

<TextView
    android:id="@+id/tv_list"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textColor="@color/color_selector"/>

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

list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        view.setSelected(true);
    }
});

 


Arduino command line syntax

SYNOPSIS

arduino [FILE.ino…]

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

 

DESCRIPTION

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 Arduino.app/Contents/MacOS/JavaApplicationStub instead of arduino.

 

OPTIONS

–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).
–verbose-build
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.
–verbose-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-prefs
Save any (changed) preferences to preferences.txt. In particular –board, –port, –pref, –verbose, –verbose-build and –verbose-upload may alter the current preferences.
–upload
Build and upload the sketch.
–verify
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).

PREFERENCES

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.

sketchbook.path
The path where sketches are (usually) stored. This path can also contain some special subdirectories (see FILES below).
update.check
When set to true, the IDE checks for a new version on startup.
editor.external
When set to true, use an external editor (the IDE does not allow editing and reloads each file before verifying).
build.path
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.

EXIT STATUS

0
Success
1
Build failed or upload failed
2
Sketch not found
3
Invalid (argument for) commandline option
4
Preference passed to –get-pref does not exist

FILES

~/.arduino15/preferences.txt
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
Libraries can be put inside this directory, one library per subdirectory.
hardware
Support for third-party hardware can be added through this directory.
tools
External code-processing tools (that can be run through the Tools menu of the IDE) can be added here.

EXAMPLES

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

 

HISTORY

1.5.2
Added initial commandline support. This introduced –verify, –upload, –board, –port, –verbose and -v.
1.5.5
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.
1.5.6
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.
1.5.8
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. 

Source:
github.com/arduino/Arduino

Download:
arduino.cc

Mirror:
Arduino 1.0.6
Arduino 1.5.8
Arduino 1.6.0

 


Menghapus Category Base dari URL pada WordPress

Jika ingin menghilangkan category pada url (misal: http://namawebsitesaya.com/category/android menjadi http://namawebsitesaya.com/android) 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/(.+)$ http://namawebsitesaya.com/$1 [R=301,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

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) {
    stopTimer();
    timer = new Timer();
    initTimerTask();
    timer.schedule(timerTask,time);
}

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

private void startRepeatTimer(int time) {
    stopTimer();
    timer = new Timer();
    initTimerTask();
    timer.schedule(timerTask,time,time);
}

Buat method stopTimer();

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

Buat method initTimerTask();

private void initTimerTask() {
    timerTask = new TimerTask() {
        @Override
        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() {
    @Override
    public void handleMessage(Message msg) {
        switch (msg.what) {
            case 0:
                textView.setText(msg.obj);
                break;
            default:
                break;
        }
    }
};

Gunakan sendMessage untuk menampilkan data.

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

 

Source code:
donwload


Android BroadcastReceiver

Untuk bagian broadcast:

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

Untuk bagian receiver:

// Buat receiver.
BroadcastReceiver bReceiver = new BroadcastReceiver() {
    @Override
    public void onReceive(Context context, Intent intent) {
        String str = intent.getStringExtra("pagi");
        Log.d(TAG,str);
    }
};
// Buat filter.
IntentFilter filter = new IntentFilter();
filter.addAction(receiver);
// Daftarkan receiver dan filter.
registerReceiver(bReceiver,filter);

 

Source code:
download


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() {
    @Override
        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" />

Android Speedometer 2

Pada kesempatan kali ini akan saya jelaskan cara membuat speedometer analog. Untuk membuat aplikasi ini, akan digunakan library dari cardiomood. Untuk pengguna eclipse, library tersebut dapat diunduh disini (link ini merupakan hasil convert yang dilakukan oleh penulis).

  1. Buat project android.
  2. Pada layout.xml, tambahkan program berikut:
    <com.cardiomood.android.speedometer.SpeedometerView
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    android:padding="8dp"
    android:id="@+id/speedometer" />
  3. Pada bagian activity, tambahkan program berikut:
    // Customize SpeedometerView
    SpeedometerView speedometer = (SpeedometerView) findViewById(R.id.speedometer);
    
    // Add label converter
    speedometer.setLabelConverter(new SpeedometerView.LabelConverter() {
         @Override
         public String getLabelFor(double progress, double maxProgress) {
             return String.valueOf((int) Math.round(progress));
         }
    });
            
    // configure value range and ticks
    speedometer.setMaxSpeed(300);
    speedometer.setMajorTickStep(30);
    speedometer.setMinorTicks(2);
    
    // Configure value range colors
    speedometer.addColoredRange(30, 140, Color.GREEN);
    speedometer.addColoredRange(140, 180, Color.YELLOW);
    speedometer.addColoredRange(180, 400, Color.RED);
            
    // Update value
    speedometer.setSpeed(100);
  4. Jalankan program.

Source code:
Download