Blog

  • How to fix “Invalid command ‘Header’, perhaps misspelled or defined by a module not included in the server configuration” for apache2 in Ubuntu

    How to fix “Invalid command ‘Header’, perhaps misspelled or defined by a module not included in the server configuration” for apache2 in Ubuntu

    If you got:

    Invalid command 'Header', perhaps misspelled or defined by a module not included in the server configuration
    

    message in error log of your apache2 web server under Ubuntu you need to do next:

    Run this command in terminal with sudo

    cp -arp /etc/apache2/mods-available/headers.load  /etc/apache2/mods-enabled/headers.load  

    Restart Apache2:

    Also run with sudo

    /etc/init.d/apache2 restart
  • How to use embed font in your ActionScript Flash application

    How to use embed font in your ActionScript Flash application

    To use embed font in your Flash application you need to do next:

    1. Declare font and show TTF font location

    [Embed(source="../../../../../../assets/fonts/MyFont.ttf", fontFamily="MyFont",fontWeight="normal", mimeType="application/x-font-truetype", embedAsCFF="false")]
    private var MyFont:Class;

    take care about embedAsCFF=”false”. This is important part of code.

    2. Create TextFormat object and use embed font it in.

    var textFormat:TextFormat = new TextFormat();
    textFormat.font = "MyFont"; // Here is font attached
    textFormat.italic = false;
    textFormat.color = 0x000000;
    textFormat.size = 12;
    textFormat.bold = false;

    3. Create TextField object and start using TextFormat object BEFORE setting any text for TextField

    var textField:TextField = new TextField();
    textField.embedFonts = true;
    textField.antiAliasType=AntiAliasType.ADVANCED;
    textField.defaultTextFormat = textFormat;
    textField.selectable = false;
    textField.autoSize = TextFieldAutoSize.LEFT;
    textField.text = "Here is text with embed font"

    That’s all!

    Please tell me if you know better solution, thanks.

  • How to make fadein / fadeout effect for TextField using only ActionScript 3.0 in Flash

    How to make fadein / fadeout effect for TextField using only ActionScript 3.0 in Flash

    Hi, here I want to share you my first experience in Flash development.

    Recently I want to made fadein/fadeout effect for some TextField in my application.

    Below you can see code of Utils.as class. The code is pretty simple.

    package {
        import flash.events.TimerEvent;
        import flash.text.TextField;
        import flash.utils.Timer;
    
        public class Utils {
            public function Utils() {
            }
    
            static public function fadeInOut(obj: TextField, isFadeIn: Boolean): void {
                var timer: Timer;
                timer = new Timer(1, 20);
                timer.addEventListener(TimerEvent.TIMER, TimerTask);
                timer.addEventListener(TimerEvent.TIMER_COMPLETE, TimerCompleteTask);
                timer.start();
    
                function TimerTask(e: TimerEvent): void {
                    if (obj.alpha & lt; 0.9 & amp;& amp; isFadeIn) { obj.alpha += 0.15; } if (obj.alpha & gt; 0 & amp;& amp; !isFadeIn) {
                        obj.alpha -= 0.05;
                    }
                }
    
                function TimerCompleteTask(e: TimerEvent): void {
                    timer.stop();
                }
            }
        }
    }

    That’s all.
    NOTE: Please, tell me if you got the better solution. Thanks!

  • How to make opacity background for TextField in Flash or add alpha channel for background color

    How to make opacity background for TextField in Flash or add alpha channel for background color

    Hi, here I want to show you how to add alpha channel for TextField background color in Flash.

    You can do it using next source code below:

    textField = new TextField();
    textField.blendMode = BlendMode.LAYER;
    textField.alpha = .9; // opacity = 90%
    textField.background = true;
    textField.backgroundColor = 0x000000;

    Happy coding!

  • How to forward port into VirtualBox or How to connect with guest virtual machine via ssh

    How to forward port into VirtualBox or How to connect with guest virtual machine via ssh

    Let me describe my task.
    I have installed Linux Ubuntu Server in my VirtualBox. I use this virtual machine for some experiments. I don’t want do some tasks on my physical PC.

    To connect with this Virtual Machine I want to use SSH.

    It can be done via forwarding physical PC port in Virtual Machine.

    Here is how to do this.
    Run this commands in terminal:

    $ VBoxManage setextradata "YOUR_VM_NAME" \
    "VBoxInternal/Devices/pcnet/0/LUN#0/Config/ssh/Protocol" TCP
    
    $ VBoxManage setextradata "YOUR_VM_NAME" \
    "VBoxInternal/Devices/pcnet/0/LUN#0/Config/ssh/GuestPort" 22
    
    $ VBoxManage setextradata "YOUR_VM_NAME” \
    "VBoxInternal/Devices/pcnet/0/LUN#0/Config/ssh/HostPort" 2222

    Replace pcnet with e1000 if you are using Gigabit adapter

    Now if you connect to your PC via ssh with 2222 port you will forwarded in Virtual Machine

    ssh -p 2222 hudson@localhost

    Where hudson – username on Virtual Machine
    That’s all

  • How to write logcat from emulator (device) to external file. Or trick with Continuous Integration

    How to write logcat from emulator (device) to external file. Or trick with Continuous Integration

    Let me describe my problem.

    I have Android project which is under Continuous Integration (CI) server. In my case it is Jenkins.

    Then I run my tests I just can see JUnit output in Jenkins console.

    If some unexpected error happens I can’t see logcat from Android emulator.

    Here I want to show you how I grab logcat from Android emulator. Now If something strange happens I can see logcat from emulator.

    I made it using BASH script which is bellow. This script grab logcat and periodically check logcat filesize AND can create new file for logcat if it is greater than 5MB. Script can add time postfix to file if new one file was created.

    PLEASE, TELL ME IF YOU KNOW THE BETTER SOLUTION !!!

    HERE the BACH script:

    #!/bin/sh
    LOGCATFILE=$1/logcat.out
    touch $LOGCATFILE
    adb -s $2 logcat -v time > $LOGCATFILE&
    PID=$!
    
    while true; do
    FILESIZE=$(stat -c%s "$LOGCATFILE")
    echo "Size of $LOGCATFILE = $FILESIZE bytes."
    echo "PID = $PID"
    if [ "$FILESIZE" -gt 5242880 ]
    then
    echo "$LOGCATFILE is too large = $FILESIZE bytes."
    now=$(date +"%Y_%m_%d_%H_%M_%S")
    NEWLOGFILENAME=/home/igor/logcat_$now.out
    cp $LOGCATFILE $NEWLOGFILENAME
    kill -9 $PID
    adb -s $2 logcat -v time > $LOGCATFILE&
    PID=$!
    fi
    sleep 10
    done

    To run just create file with executable permission and as parameter to script write path to dir with log
    SECOND parameter is your device name which you can get when run adb devices in your terminal

    Example:

    igor@igor-laptop:~$ adb devices
    List of devices attached
    HT10WPL00853 device

    The script parameters in my case will be next:

    igor@igor-laptop:~$ ./write_logcat.sh ~/Temp HT10WPL00853

    Hope, It help you!

  • How to set View width (height) in percentage of parent View in Android

    How to set View width (height) in percentage of parent View in Android

    Example:
    I want to set child LinearLayout height = 50% of parrent LinearLayout in Android. Like in HTML.

    To set height in percents I do some trick with android:layout_weight and android:weightSum

    Here the screenshot:

    To do this you need do somethind like this. Look at code below:

    <?xml version="1.0" encoding="UTF-8"?>
    <linearlayout 
        xmlns:android="http://schemas.android.com/apk/res/android" 
        android:orientation="vertical" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:weightsum="100">
            <linearlayout 
                android:layout_weight="50" 
                android:layout_width="match_parent" 
                android:id="@+id/linearLayout1" 
                android:layout_height="wrap_content" 
                android:orientation="vertical" />
    </linearlayout>
  • Android application don’t fill all (screen) display area on HTC Sensation

    Android application don’t fill all (screen) display area on HTC Sensation

    Recently I wrote some app which looks good on HTC Desire and looks bad on HTC Sansation. The application didn’t fill all screen (display) area. And I see some black parts of display when I run my application.

    Here the screenshot:

    To fix this I made some changes in Android Manifest file. I’ve added next code in manifest node.

    <supports-screens android:smallScreens="true" android:normalScreens="true" android:largeScreens="true"/>
  • How to display route between two points (geopoints) on Google Maps in Android

    How to display route between two points (geopoints) on Google Maps in Android

    UPDATE: Now this is not working. Google API changed.

    Recently a have some task in my Android project.

    I needed to show route (directions) between two points (geopoins)on google maps in Android.

    I thought it can be simple task. But It was a lot of interesting things :).

    I’ve discovered a lot of topics of this problem.

    I find one usefull. This is IT

    But, it didn’t works for me.

    Here I want to show my changes of this project.

    Below you can download source code of sample Android project.

    Here is screenshot:

    The major changes is in KML parser. Here is this class:

    package com.hrupin.maproute.route;
    
    import java.io.InputStream;
    
    import javax.xml.parsers.DocumentBuilderFactory;
    import javax.xml.xpath.XPath;
    import javax.xml.xpath.XPathExpression;
    import javax.xml.xpath.XPathFactory;
    
    import org.w3c.dom.Document;
    
    public class RoadProvider {
    	private static Document xmlDocument;
    
    	public static Road getRoute(InputStream is) {
    		Road mRoad = new Road();
    		String expression = "string(//Placemark/GeometryCollection/LineString/coordinates)";
    		String expression2 = "string(//Placemark[contains(name, 'Route')]/description)";
    		try {
    			xmlDocument = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(is);
    			XPathFactory xPathFactory = XPathFactory.newInstance();
    			XPath xPath = xPathFactory.newXPath();
    			XPathExpression xPathExpression = xPath.compile(expression);
    			String result = xPathExpression.evaluate(xmlDocument);
    			String[] arr1 = result.split(" ");
    			for (String str : arr1) {
    				String[] coords = str.split(",");
    				if (coords.length == 3) {
    					double[] xy = new double[] {};
    					double x = Double.parseDouble(coords[0]);
    					double y = Double.parseDouble(coords[1]);
    
    					xy = addDouble(xy, x);
    					xy = addDouble(xy, y);
    					mRoad.mRoute = addDouble(mRoad.mRoute, xy);
    					System.out.println("PARSING ..... ");
    				}
    			}
    			
    			xPathExpression = xPath.compile(expression2);
    			String description = xPathExpression.evaluate(xmlDocument);
    			
    			mRoad.mDescription = cleanup(description);
    			
    			System.out.println("DESCRIPTION = " + mRoad.mDescription);
    			
    		} catch (Exception ex) {
    			ex.printStackTrace();
    		} 
    		return mRoad;
    	}
    
    	static double[][] addDouble(double[][] array, double[] element) {
    		int arrayLength = array.length;
    		double[][] result = new double[arrayLength + 1][];
    		for (int i = 0; i < arrayLength; i++) {
    			int elementLength = array[i].length;
    			result[i] = new double[elementLength];
    			for (int j = 0; j < elementLength; j++)
    				result[i][j] = array[i][j];
    		}
    		int newElementLength = element.length;
    		result[arrayLength] = new double[newElementLength];
    		for (int j = 0; j < newElementLength; j++)
    			result[arrayLength][j] = element[j];
    		return result;
    	}
    
    	static double[] addDouble(double[] array, double element) {
    		int arrayLength = array.length;
    		double[] result = new double[arrayLength + 1];
    		for (int i = 0; i < arrayLength; i++)
    			result[i] = array[i];
    		result[arrayLength] = element;
    		return result;
    	}
    
    	public static String getUrl(double fromLat, double fromLon, double toLat, double toLon) {
    		StringBuffer urlString = new StringBuffer();
    		urlString.append("http://maps.google.com/maps?f=d&hl=en");
    		urlString.append("&saddr=");
    		urlString.append(Double.toString(fromLat));
    		urlString.append(",");
    		urlString.append(Double.toString(fromLon));
    		urlString.append("&daddr=");
    		urlString.append(Double.toString(toLat));
    		urlString.append(",");
    		urlString.append(Double.toString(toLon));
    		urlString.append("&ie=UTF8&0&om=0&output=kml");
    		return urlString.toString();
    	}
    	
    	private static String cleanup(String value) {
    		String remove = "<br/>";
    		int index = value.indexOf(remove);
    		if (index != -1)
    			value = value.substring(0, index);
    		remove = "&#160;";
    		index = value.indexOf(remove);
    		int len = remove.length();
    		while (index != -1) {
    			value = value.substring(0, index).concat(value.substring(index + len, value.length()));
    			index = value.indexOf(remove);
    		}
    		return value;
    	}
    }

    Enjoy! 🙂

    Here you can download the source code of this Android Project.

    Download it from github
  • How to start Android adb server on startup in Ubuntu Linux from root

    How to start Android adb server on startup in Ubuntu Linux from root

    Hi, recently to make debug on real device I need to restart my adb server (Android Debug Bridge) manually.

    To use it I need restart it with root privileges.

    sudo adb kill-server
    sudo adb start-server

    Now I want to show you how to make it on startup your Linux OS.
    1. Create file with adb name
    2. Put it in /etc/init.d/ dir
    3. Add folowing content:

    #!/bin/sh
    case "$1" in
    start)
    # Start daemon.
    echo -n "Starting ADB: "
    /opt/android-sdk-linux/platform-tools/adb start-server
    ;;
    stop)
    # Stop daemons.
    echo -n "Shutting ADB: "
    /opt/android-sdk-linux/platform-tools/adb kill-server
    ;;
    restart)
    $0 stop
    $0 start
    ;;
    *)
    echo "Usage: $0 {start|stop|restart}"
    exit 1
    esac
    
    exit 0

    4. Run following commands

    cd /etc/init.d/
    sudo chown root:root adb
    sudo update-rc.d adb defaults
    sudo chmod +x adb

    5. reboot your Linux OS
    6. Plug your Android device to USB
    7. run

    adb devices

    8. Everythink is ok If you see something like this:

    List of devices attached
    YOUR_DEVICE_SERIAL_NUMBER device

    Enjoy codding!