January 23, 2011

[SOLVED] Android: Set dynamically textview height


TextView tv = (TextView) findViewById(R.id.TextView01);
final int height_in_pixels = tv.getLineCount() * tv.getLineHeight()
* getResources().getDisplayMetrics().density;
//approx height text
tv
.setHeight(height_in_pixels);

Solved: stackoverflow.com

[SOLVED] Android: Override back button


@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
   
if (keyCode == KeyEvent.KEYCODE_BACK) {
        //do some stuff

       
return true;
   
}
   
return super.onKeyDown(keyCode, event);
}

 

Source: stackoverflow.com.

January 12, 2011

[SOLVED] Android: Handling gzipped content while downloading

On file download you can check the content type and if its gzipped - unzip it on the fly:

URLConnection connection = url.openConnection();
InputStream stream = connection.getInputStream();
if ("gzip".equals(connection.getContentEncoding())) {
stream = new GZIPInputStream(stream));
}


Source: stackoverflow.com

January 9, 2011

[SOLVED] Android: Get an string array from an array.xml resource

Here you can see how to retrieve values from array.xml
Log.i("test",getImageQualityAsString(1));

array.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="image_export_list_preference">
<item>480x320</item>
<item>800x480</item>
<item>1024x768</item>
</string-array>
<string-array name="entryvalues_image_export_list_preference">
<item>0</item>
<item>1</item>
<item>2</item>
</string-array>
</resources>

Function:
private String getImageQualityAsString(int sizeItem){

try {
String[] bases = getResources().getStringArray(R.array.image_export_list_preference);

return bases[sizeItem];

} catch (Exception e) {
return "";
}

}

Source: stackoverflow.com

January 4, 2011

[SOLVED] Share log via Browser

This guide assumes you have a remote server, called loghost.example.org that you are going to use to avoid any firewall issues.

First make sure you have netcat-openbsd and NOT netcat traditional installed.
sudo apt-get install netcat-openbsd

Then to ensure your system is working try the following basic netcat tip.

Now to share my logging output I run on my laptop:
tail -f /var/log/syslog | ssh loghost "nc -v -l 8000"

Now to share my log with a remote collegue, he simply runs:
curl http://loghost.example.org.org:8000

or http://loghost.example.org:8000 in a browser

Source: dabase.com

January 3, 2011

[GRAPHICS] My GTUG logo deviations

Here are some of my GTUG logo deviations (inspired by @aygul's bootcamp logo):





ASCII/HTML GTUG logo



                      ..::::..                       :::::::::::.
                 ::::::::::::::::::              :::::::::::::::::::             .COOOOOOOOOOOOOc
              ::::::::::::::::::::::::         :::::::::::::::::::::::        .OOOOOOOOOOOOOOOOOOOOC
           ::::::::::::::::CCCc:::::::::     .::::::O@@@@@@@@@@@@c::::::    .OOOOOOOOOOOOOOOOOOOOOOOOO      .ccccccccccccc:.
          :::::::::::::8@@@@@@@@@@o:::::::  .:::::::@@@@@@@@@@@@@C:::::::  OOOc:COOOOO    OOOOOOOOOOOOOc:cccccccccccccccccccccc
         ::::::::::::c@@@@@@CC8@@@@@::::::: ::::::::::::o@@@@:::::::::::::OOO   OOOOOC    OOOOOOOOOOOCccccccccccccccccccccccccccc:
        :::::::::::::@@@@@C:::::8@@@@:::::::::::::::::::o@@@@::::::::::::OOOc   OOOOOc    OOOOOOOOOCcccccccOO@@@OCccccccccccccccccc:
       ::::::::::::::@@@@@c:::::C@@@@:::::::::::::::::c:C@@@@::::::c::::oOOOc   OOOOOc    OOOOOOOOccccco@@@@@@@@@@@@occcccccccccccccc.
       ::::::::::::::@@@@@c:::::::::::::::::::::::::::::C@@@@:::::::::::COOO:   OOOOOc    OOOOOOOccccc8@@@@8OOO@@@@@@occcccccccccccccc.
      .::::::::::::::@@@@@c::::::::::::::::::::::c:::c::o@@@@:::::::::::COOO:  .OOOOOc    OOOOOOcccccO@@@@cccccc@@@@@@ccccccccccccccccc.
      .::::::::::::::@@@@@c::@@@@@@@@c::::::::::::::::::c@@@@:::::::::::oOOOc   OOOOOc    OOOOOoccccc@@@@8ccccccO@@@@@cccccccccccccccccc
       ::::::::::::::@@@@@c::@@@@@@@@::::::::::::::::::::@@@@::::c:::::: OOOc   OOOOOc    OOOOOcccccc@@@@Occcccccccccccccccccccccccccccc:
       ::::::::::::::@@@@@c:::::C@@@@::::::::  :::c:::c::@@@8::::::::::  .OOO   OOOOOc    OOOOCcccccc@@@@Occccccccccccccccccccccccccccccc
        :::::::::::::@@@@@C:::::8@@@@:::::::    .::::::::::::::::::::     .OOO           :OOOOCcccccc@@@@OccO@@@@@@@@@ccccccccccccccccccc
         :::::::::::::@@@@@@@8@@@@@@@::::::        .::::::::::::c:          COOO:      .OOOOOOCcccccc@@@@OccO@@@@@@@@@ccccccccccccccccccc
          :::::::::::::o@@@@@@@@@c@@C:::::                                    COOOOOOOOOOOOOOOOcccccc@@@@OccccccO@@@@@cccccccccccccccccc.
            ::::::::::::::::::::::::::::                                        .OOOOOOOOOOOOOOCccccc@@@@@ccccccO@@@@@cccccccccccccccccc
              ::::::::::::::::::::::::                                               .ccccccc   cccccc@@@@Occccc@@@@@@ccccccccccccccccc
                 ::::::::::::::::::                                                              cccccc@@@@@@@@@@@@@@@cccccccccccccccc
                       ......                                                                     :cccccc8@@@@@@@OC@@@ccccccccccccccc
                                                                                                    ccccccccccccccccccccccccccccccc
                                                                                                      :cccccccccccccccccccccccccc
                                                                                                         :cccccccccccccccccccc.
                                                                                                              .ccccccccc:.                            

                                                                                                                                                      


Original GTUG logo was created by @romannurik

Source: http://wiki.gtugs.org/logos

[SOLVED]Building CSS sprites with Bash & Imagemagick

If you want to automatically generate image sprites - css file just use this script
$ spriteit.sh button button '*.png'

Output:
Generating sprite file...
executing: convert button_disabled.png button_hover.png button.png button_selected.png -append button/button-sprite.png
Sprite complete! - Creating css & test output...
#1 done
#2 done
#3 done
#4 done

Complete! - 4 sprites created, css written & test page output.

Script source:
#!/bin/bash

# uses imagemagick to stich together all images in a folder and
# then writes a css file with the correct offsets along with a
# test html page for verification that its all good

if [ $# -gt 0 ]
then

if [ 'x' != 'x'$4 ]
then
ext2=.$4; # the extension to iterate over for input files
else
ext2=".png"; # the extension to iterate over for input files
fi

if [ 'x' != 'x'$3 ]
then
#ext="."$3; # the extension to iterate over for input files
ext=$3; # the extension to iterate over for input files
else
ext=".gif"; # the extension to iterate over for input files
fi

name=$1; # output will be placed in a folder named this

if [ $2 ]
then
classname=$2"-sprite";
else
classname=$1"-sprite";
fi
css="$name/$classname.css";
html="$name/test.html";

rm -fr $name;
mkdir $name;
touch $css $html;

echo "Generating sprite file...";
#echo convert *$ext -append $name/$classname$ext;
echo executing: convert $ext -append $name/$classname$ext2;
convert $ext -append $name/$classname$ext2;

echo "Sprite complete! - Creating css & test output...";

echo -e "<html>\n<head>\n\t<link rel=\"stylesheet\" href=\"`basename $css`\" />\n</head>\n<body>\n\t<h1>Sprite test page</h1>\n" >> $html

echo -e ".$classname {\n\tbackground:url('$classname$ext2') no-repeat top left; display:inline-block;\n}" >> $css;
counter=0;
offset=0;
for file in $ext
do
width=`identify -format "%[fx:w]" "$file"`;
height=`identify -format "%[fx:h]" "$file"`;
#idname=`basename "$file" $ext`;
idname=`basename "$file" $ext2`;

clean=${idname// /-}
echo ".$classname#$clean {" >> $css;
echo -e "\tbackground-position:0 -${offset}px;" >> $css;
echo -e "\twidth: ${width}px;" >> $css;
echo -e "\theight: ${height}px;\n}" >> $css;

echo -e "<a href=\"#\" class=\"$classname\" id=\"$clean\"></a>\n" >> $html;

let offset+=$height;
let counter+=1;
echo -e "\t#$counter done";
done

echo -e "<h2>Full sprite:</h2>\n<img src=\"$classname$ext2\" border=1/>" >> $html;
echo -e "</body>\n</html>" >> $html;

echo -e "\nComplete! - $counter sprites created, css written & test page output. @russenreaktor";

else

echo -e "There should be at least 1 argument!\n\tbuildSprite.sh output_folder classname input_pattern"
echo -e "\n\tbuildSprite.sh folder1 test '*.png' png"

fi

Source: jaymz.eu

[SOLVED] Save music played via browser as mp3 file

Problem: You hear nice music via your browser but you want download this music as mp3.

 

Solution: Use Freecorder - Powerful, Free Video Downloader, Audio Recorder & Converter - http://www.applian.com/freecorder4/