Wednesday, March 28, 2012

Drawing and erasing using touch on Android

Drawing/Erasing using touch is a common feature in many mobile phone/tablet based apps.
Writing code for this feature is pretty simple for android. Here are steps to do that:
  • add a custom view on which you will draw.
  • process touch event on view.
  • on touch event, record points where touch event occurred.
  • in onDraw method, draw points that were recorded.

Adding a custom view:

We will derive a class from View class for implementing drawing canvas.
And we will add this to UI tree. To add this to UITree, create a LinearLayout in which the
custom view will be added. The LinearLayout is declared in layout xml as:

...... read full blog post and get the code from here: http://blog.avabodh.com/2012/01/drawing-and-erasing-using-touch-on.html



 

Making the iOS text field/view visible which is located under keyboard.

The text view being hidden by keyboard is a very common issue faced by iPhone/iPad developers. When you touch a text view, the text view becomes first responder and keyboard automatically appears. If the text view is lying somewhere in lower part of the screen, most probably it will get hidden under the keyboard.
The solution is to scroll the text view up enough so that it comes above the keyboard. To do that, you need to add the text view in UIScrollView so that it can be scrolled up.

......... read the full blog post and get the code from here: http://blog.avabodh.com/2012/03/making-ios-text-fieldview-visible-which.html


Friday, September 9, 2011

Mounting remote file system using sshfs

sshfs is a tool which mounts remote file system on local machine. It internally uses SSH file transfer protocol. The current implementation of sshfs has dependcny on fuse.

following packages are required to be installed:
sshfs
fuse (fuse-utils on some Linux distros)

On my open suse, fuse package was pre-installed and I needed to install sshfs.

the fuse kernel module has to be loaded before using sshfs. Here is the command to do that
modprobe fuse

I did not require anything to do anything for this on my open suse box because the fuse module was already loaded. This can be easily checked whether a particular module is already loaded or not using lsmod command.

Command to mount remote file system:
sshfs remote-user@remote-server:/remote/directory local-mount-directory


Tuesday, July 19, 2011

/etc/alternatives/

Linux allows different implementation of a single command/utility co-exist. For example you can install both open JDK and sun JDK at a time on Linux and can also make one of them as default. The default selection is made using links in the file system. This works as:-

$which java
/usr/bin/java

$ls -l /usr/bin/java
/usr/bin/java -> /etc/alternatives/java

$ls -l /etc/alternatives/java
/etc/alternatives/java -> /usr/lib/jvm/jre-1.6.0-sun/bin/java

If we type command java on command prompt then /usr/bin/java is invoked. The /usr/java/bin points to /etc/alternatives/java and /etc/alternatives/java points to /usr/lib/jvm/jre-1.6.0-sun/bin/java. So the target of the command java becomes /usr/lib/jvm/jre-1.6.0-sun/bin/java


On Ubuntu, there is a graphical utility which lets you to change/configure the alternatives. But this is missing from the default install of openSUSE. But on the openSUSE this can be easily achieved by command line as -

update-alternatives --config java
 
This command will list all available options and will ask you to enter to select one of them.

Saturday, July 16, 2011

Mounting NTFS drive on openSUSE in read-write mode

Recently, I installed openSUSE 11.4 on my laptop. The laptop is dual boot with windows7. There was a minor issue. The NTFS drive was mounted read only by default. Editing /etc/fstab fixed the issue. Here was the original entry in the fstab:-

/dev/disk/by-id/ata-FUJITSU_MHV2080BH_PL_NW9ZT682CFW0-part2 /windows/D           ntfs-3g    users,gid=users,fmask=133,dmask=022,locale=en_US.UTF-8 0 0

I changed this to as below, to make it working
 
/dev/disk/by-id/ata-FUJITSU_MHV2080BH_PL_NW9ZT682CFW0-part2 /windows/D           ntfs-3g    defaults 0 0

Merging PDF files on Linux

There are many tools out there. gs is one of such command line tools to achieve this. Suppose there are two pdf files as file1.pdf and file2.pdf and we want to merge them into final.pdf, then the command will be -
gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=final.pdf file1.pdf file2.pdf

More than two pdf can also be merged by providing their names in the command line argument.

Sunday, May 22, 2011

Connecting to internet on Linux with Airtel GPRS and Nokia mobile phone

The Nokia phone comes with a software called Nokia PC Suite which provides many utilities including Internet connection on PC via phone. Unfortunately this software is not available for Linux operating system. But, as usual, a little bit of hack can enable Internet connection on Linux using Nokia phone.
Here is what I have tried and it worked for me with Nokia N79 and Airtel (in India) as service provider.
- Install wvdial. It was installed by default on my box (open suse).
- edit /etc/wvdial.conf as
[Dialer Defaults]
Init1 = AT+CGDCONT=1,"IP","airtelgprs.com"
Modem Type = USB Modem
Phone = *99***1#
Password =" "
Username = " "
Modem = /dev/ttyACM1
Baud = 460800
auto DNS = 1
- Now from command prompt, run the command wvdial
- The wvdial will block the command prompt. If want to disconnect, then type Ctrl+C on the command prompt.


Misc:
- I faced an issue. It was not automatically obtaining the DNS address. So Manually edited the /etc/resolve.conf as
nameserver 8.8.8.8
nameserver 8.8.4.4
These two nameservers are public nameserver by google.

- The user name and password here is blank string. There is no user name and password for Airtel. This should be changed accordingly if there is different service provider.

- While connecting the phone to PC, select PC Suite when asked in the phone as "Select USB Mode"

- /dev/ttyACM1 can be different on different machines. run the command dmesg as root just after connecting the phone to PC (by USB) and look for a line similar to

cdc_acm 1-1:1.1: ttyACM1: USB ACM device

Change the device name in the /etc/wvdial.conf to what it appears here