Friday, December 11, 2009

Hard Android vs Soft Keyboard

I'm now porting BlackBerry application to Android platform and had to use dialogs at this platform. You know, this is some of Dialog objects. Rather good popup windows, capable to carry some useful view payload. But...

I have encountered curious problem (not first, to be honest, during this project): if dialog shown, hidden and after that soft keyboard is shown - view will not be resized to make space for keyboard, instead keyboard will overlay on view.
So, there is possible situation, when editbox, which is located on bottom of view, will be obscured with keyboard. When it get focus, it will request self to be visible and view will be paned to make it visible. But with no way back, as view paned entirely!

I google'd and found this email (thanks to it's author, Oceanedge, which gived right digging direction). In this email written, that
android:windowSoftInputMode=adjustResize
will not help, but this is not correct.

It seems that main reason of my problem is that dialog sets "adjust pan" mode on window, while nobody setted "adjust resize" back again. So, problem was solved by adding code, which resets "adjust rezize" on activity window when dialog is dismissed:

_activity.getWindow()
.
setSoftInputMode(WindowManager.LayoutParams
.
SOFT_INPUT_ADJUST_RESIZE);


So, this is solution for problem with resize view/window for keyboard after dialog pops up. Hope this will help anyone.

Thursday, June 4, 2009

A bit about music sorting.

As man, who likes to listen music as background of my working, I encountered a problem with getting/sorting new music. Old good music is still good, but it still old....

I can't just listen every track before adding it to my playlist as this can really take forever. (:

As background of this story, imagine i have server with a lot of music of different styles/groups etc, but i don't know which group will be good for me or which music is totally crap from my POV.

Some time ago i encountered information about "union" filesystems, particulary funionfs, and this gave the direction for my subconsciousness to work on problem of sorting music. And this is solution i finally came to.

As i'm using the mocp player, there is no problem to obtain currently playing track information from script. This was the base.

Setup step 1, creating music sorting playground:

Using funionfs establishing "out" directory (entry from /etc/fstab):

funionfs#/home/elk/.music_sort/tmp   \
/home/elk/.music_sort/out \
fuse \
rw,allow_other,dirs=/home/elk/music=ro 0 0


So, after this, we will have "out" in /home/elk/.music_sort/out, where player should search for music and play music from. /home/elk/music is directory, where music is actually located (and where is symlink to server music).

So, now, if someone will delete some file in /home/elk/.music_sort/out, file will not be actually deleted, but will be marked as deleted in /home/elk/.music_sort/tmp.

But with deleting not all so easy, as i encountered some problems with "deleting" files on server. Server is cifs share mounted and in /home/elk/music is symbolic link to place, where this music is located, and any unification fs i have tried expirienced different troubles with
deleting in such circumstances.

So, instead of deleting files via funionfs, script creates deleted-markers in /home/elk/.music_sort/tmp.

Setup step 2, script to do "deleting":


#!/bin/bash

# this part obtains music file information
FILENAME=`mocp -i | grep -o "File:.*" | sed 's/File: //'`
TRACKNAME=`mocp -i | grep -o "SongTitle:.*" | sed 's/SongTitle: //'`
AUTHOR=`mocp -i | grep -o "Artist:.*" | sed 's/Artist: //'`

SORTDIR='/home/elk/.music_sort/out'

# this part produces dialog
POSITION="-G +950+28"

DIRNAME=`dirname "$FILENAME"`

# if file not in music directory, we should not be able to delete it, as
# this can lead to some unexpected behaviour

if [ "$SORTDIR" != "${FILENAME:0:25}" ] ; then
export MAIN_DIALOG="
<vbox>
<frame Track>
<text>
<label>\"$AUTHOR - $TRACKNAME\"</label>
</text>
</frame>
<frame File>
<text>
<label>\"$FILENAME\"</label>
</text>
</frame>
<frame Directory>
<text>
<label>\"$DIRNAME\"</label>
</text>
</frame>

<frame Can not be deleted>
<text>
<label>Not in music sorting dir, so can not be deleted.</label>
</text>
</frame>
<button ok></button>
</vbox>"


gtkdialog $POSITION --program MAIN_DIALOG
exit 1
fi

export MAIN_DIALOG="
<vbox>
<frame Track>
<text>
<label>\"$AUTHOR - $TRACKNAME\"</label>
</text>
</frame>
<frame File>
<text>
<label>\"$FILENAME\"</label>
</text>
</frame>
<frame Directory>
<text>
<label>\"$DIRNAME\"</label>
</text>
</frame>

<frame Actions:>
<hbox>
<button>
<label> Delete track </label>
<action type=\"exit\">track</action>
</button>
<button>
<label> Delete dir </label>
<action type=\"exit\">dir</action>
</button>
<button cancel></button>
</hbox>
</frame>
</vbox>
"


eval `gtkdialog $POSITION --program MAIN_DIALOG`
echo exit: $EXIT

# as format for deleting marker for funionfs is filename_DELETED~
# we should create this file instead of dir or file

if [ "$EXIT" == "track" ] ; then
DELETED_FN='/home/elk/.music_sort/tmp'/"${FILENAME:26}"_DELETED~
mkdir -p "`dirname "$DELETED_FN"`"
touch "$DELETED_FN"
mocp -f
elif [ "$EXIT" == "dir" ] ; then
DELETED_FN=`dirname '/home/elk/.music_sort/tmp'/"${FILENAME:26}"`_DELETED~
mkdir -p "`dirname "$DELETED_FN"`"
touch "$DELETED_FN"
mocp -f
fi


There is some comments in script, so there should be no problems to understand it.

So, finally, i added a button on toolbar, which calls this script.

So, looks like this:



So now every time as I want to never hear again track, which is played by now, i press button on toolbar, this dialog appears and i click to "delete dir" or "delete track".

Music is not actually deleted, but my player will not see it anymore.