2011年4月30日 星期六

[Android] extend Gallery support Click/Zooming/Panning with scale limit/pan bounds and scroll

You can learnd some zooming/panning knowledge from link below.
http://www.zdnet.com/blog/burnette/how-to-use-multi-touch-in-android-2/1747

Then you will want to know how to add scale limit and pan bounds, and the answer is as follow link.
http://www.zdnet.com/blog/burnette/how-to-use-multi-touch-in-android-2-part-6-implementing-the-pinch-zoom-gesture/1847

Maybe you want to built-in the zooming/panning function in a ImageView.
http://code.google.com/p/4chan-image-browser/source/browse/src/se/robertfoss/MultiTouchZoom/TouchImageView.java?r=02836650d3b69dd6a2fce1304c34ded1531d6ad5

http://code.google.com/p/4chan-image-browser/source/browse/src/se/robertfoss/MultiTouchZoom/WrapMotionEvent.java?r=c1ea13ef76d6f3ec6024cecf4a6db68e42030916

We all want to watch pictures in a scroll view as Gallery, but the OnTouch event will conflict with OnScroll and OnFling event.
I try to work it out by evaluate if the image bound cross over the bound of container, then raise OnKeyDown event when reach the condition.
In order to avoid the TouchImageView intercept the OnTouch event, so built-in the multi-touch function in Gallery view.
Maybe we want to click on a image to retrieve original size, so I expend the multi-touch mode with "TAP" to reset the matrix.


The source code of "GalleryEx" as below
 ============================================
package com.example.twnin;

import android.content.Context;
import android.graphics.Matrix;
import android.graphics.PointF;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.util.FloatMath;
import android.util.Log;
import android.view.*;
import android.widget.Gallery;
import android.widget.ImageView;


public class GalleryEx extends Gallery
{
    private Context m_Context;
    private int m_horizontalMargin;
    private int m_verticalMargin;


    //variables for zoom limit and pan bounds   
    private float[] m_matrixValues = new float[9];
    private float m_maxZoom = 2f;
    private float m_minZoom = 0.75f;
    private RectF m_viewRect;


    //variables for multi-touch   
    private Matrix m_matrix = new Matrix();
    private Matrix m_savedMatrix = new Matrix();


    static final int NONE = 0;
    static final int TAP = 1;
    static final int DRAG = 2;
    static final int ZOOM = 3;
    int m_mode = NONE;


    private PointF m_start = new PointF();
    private PointF m_mid = new PointF();


    private float m_oldDist = 1f;

    private int m_eventPageIndex = 0;

    MotionEvent m_startEvent;

    public GalleryEx(Context context)
    {
        super(context);
        m_Context = context;
    }

    public void setImageHorizontalMargin(int horizontalMargin)
    {
        m_horizontalMargin = horizontalMargin;
    }

    public void setImageVerticalMargin(int verticalMargin)
    {
        m_verticalMargin = verticalMargin;
    }

    @Override   
    public boolean onTouchEvent(MotionEvent event)
    {
        ImageView myImageView = (ImageView) super.getSelectedView();
        m_viewRect = new RectF(0, 0, myImageView.getWidth(), myImageView.getHeight());

        switch (event.getAction() & MotionEvent.ACTION_MASK)
        {
            case MotionEvent.ACTION_DOWN:
                m_savedMatrix.set(m_matrix);
                m_start.set(event.getX(), event.getY());
                m_startEvent = MotionEvent.obtain(event);
                m_mode = TAP;
                m_eventPageIndex = myImageView.getId();
                break;

            case MotionEvent.ACTION_POINTER_DOWN:
                m_oldDist = spacing(event);
                if (m_oldDist > 10f)
                {
                    m_savedMatrix.set(m_matrix);
                    midPoint(m_mid, event);
                    m_mode = ZOOM;
                }
                break;

            case MotionEvent.ACTION_UP:
                if (m_mode == TAP)
                {
                    // do something when user click                   
                    m_matrix.reset();
                    m_mode = NONE;
                }
                onScroll(m_startEvent, event, myImageView.getLeft()-25, 0);
                break;

            case MotionEvent.ACTION_POINTER_UP:
                m_mode = NONE;
                break;

            case MotionEvent.ACTION_MOVE:
                if (m_mode == TAP || m_mode == DRAG)
                {
                    // if page changed then return                   
                     if (m_eventPageIndex != myImageView.getId())
                    {
                        m_matrix.reset();
                        this.setSelection(myImageView.getId());
                        return true;
                    }

                    m_mode = DRAG;
                    m_matrix.set(m_savedMatrix);

                    // limit pan boundary                   
                    m_matrix.getValues(m_matrixValues);
                    float currentY = m_matrixValues[Matrix.MTRANS_Y];
                    float currentX = m_matrixValues[Matrix.MTRANS_X];
                    float currentScale = m_matrixValues[Matrix.MSCALE_X];
                    float currentHeight = myImageView.getHeight() * currentScale;
                    float currentWidth = myImageView.getWidth() * currentScale;
                    float dx = event.getX() - m_start.x;
                    float dy = event.getY() - m_start.y;
                    float newX = currentX+dx;
                    float newY = currentY+dy;

                    RectF drawingRect = new RectF(newX, newY, newX+currentWidth, newY+currentHeight);
                    float diffUp = Math.min(m_viewRect.bottom-drawingRect.bottom, m_viewRect.top-drawingRect.top);
                    float diffDown = Math.max(m_viewRect.bottom-drawingRect.bottom, m_viewRect.top-drawingRect.top);
                    float diffLeft = Math.min(m_viewRect.left-drawingRect.left, m_viewRect.right-drawingRect.right);
                    float diffRight = Math.max(m_viewRect.left-drawingRect.left, m_viewRect.right-drawingRect.right);
                    if(diffUp > 0)
                    {
                        dy += diffUp;
                    }
                    if(diffDown < 0)
                    {
                        dy += diffDown;
                    }
                    if(diffLeft > 0)
                    {
                        dx += diffLeft;
                    }
                    if(diffRight < 0)
                    {
                        dx += diffRight;
                    }
                    m_matrix.postTranslate(dx, dy);

                    // if image exceed boundary then scroll, otherwise align center                
                     if(currentWidth < myImageView.getWidth())
                    {
                        if(newX < -m_horizontalMargin)
                        {
                            float offset = -newX - (600 - myImageView.getRight());
                            onScroll(m_startEvent, event, offset, 0);
                        }
                        else if (newX + currentWidth > myImageView.getWidth() + m_horizontalMargin)
                        {
                            float offset = -(newX + currentWidth - myImageView.getWidth()) - (0 - myImageView.getLeft());
                            onScroll(m_startEvent, event, offset, 0);
                        }
                        else
                        {
                            onScroll(m_startEvent, event, myImageView.getLeft() - m_horizontalMargin, 0);
                        }
                    }
                    else
                    {
                        if (newX + currentWidth <= myImageView.getWidth())
                        {
                            float offset = -(newX + currentWidth - myImageView.getWidth()) - (600 - myImageView.getRight());
                            onScroll(m_startEvent, event, offset, 0);
                        }
                        else if (newX > 0)
                        {
                            float offset = -newX - (0 - myImageView.getLeft());
                            onScroll(m_startEvent, event, offset, 0);
                        }
                        else
                        {
                            onScroll(m_startEvent, event, myImageView.getLeft() - m_horizontalMargin, 0);
                        }
                    }

                }
                else if (m_mode == ZOOM)
                {
                    float newDist = spacing(event);
                    if (newDist > 10f)
                    {
                        m_matrix.set(m_savedMatrix);
                        float scale = newDist / m_oldDist;
                        // limit zoom
                        m_matrix.getValues(m_matrixValues);
                        float currentScale = m_matrixValues[Matrix.MSCALE_X];
                        if (scale * currentScale > m_maxZoom)
                        {
                            scale = m_maxZoom / currentScale;
                        }
                        else if (scale * currentScale < m_minZoom)
                        {
                            scale = m_minZoom / currentScale;
                        }
                        m_matrix.postScale(scale, scale, m_mid.x, m_mid.y);
                    }
                }
        }
        myImageView.setImageMatrix(m_matrix);
        return true;
    }

    /** Determine the space between the first two fingers */   
    private float spacing(MotionEvent event)
    {
        float x = event.getX(0) - event.getX(1);
        float y = event.getY(0) - event.getY(1);
        return FloatMath.sqrt(x * x + y * y);
    }

    /** Calculate the mid point of the first two fingers */   
    private void midPoint(PointF point, MotionEvent event)
    {
        float x = event.getX(0) + event.getX(1);
        float y = event.getY(0) + event.getY(1);
        point.set(x / 2, y / 2);
    }
}

2011年4月22日 星期五

[Android] Ant: a simple target for echo build-in properties

      <target name="test">
          <echo message="basedir : ${basedir}"/>

          <echo message="ant.file : ${ant.file}"/>
          <echo message="ant.project.name : ${ant.project.name}"/>
          <echo message="ant.home : ${ant.home}"/>
          <echo message="ant.version : ${ant.version}"/>
          <echo message="ant.java.version : ${ant.java.version}"/>

          <echo message="java.version : ${java.version}"/>
          <echo message="java.vendor : ${java.vendor}"/>
          <echo message="java.vendor.url : ${java.vendor.url}"/>
          <echo message="java.home : ${java.home}"/>
          <echo message="java.vm.specification.version : ${java.vm.specification.version}"/>
          <echo message="java.vm.specification.vendor : ${java.vm.specification.vendor}"/>
          <echo message="java.vm.specification.name : ${java.vm.specification.name}"/>
          <echo message="java.vm.version : ${java.vm.version}"/>
          <echo message="java.vm.vendor : ${java.vm.vendor}"/>
          <echo message="java.vm.name : ${java.vm.name}"/>
          <echo message="java.specification.version : ${java.specification.version}"/>
          <echo message="java.specification.vendor : ${java.specification.vendor}"/>
          <echo message="java.specification.name : ${java.specification.name}"/>
          <echo message="java.class.version : ${java.class.version}"/>
          <echo message="java.class.path : ${java.class.path}"/>
          <echo message="java.ext.dirs : ${java.ext.dirs}"/>

          <echo message="os.name : ${os.name}"/>
          <echo message="os.arch : ${os.arch}"/>
          <echo message="os.version : ${os.version}"/>

          <echo message="file.separator : ${file.separator}"/>
          <echo message="path.separator : ${path.separator}"/>
          <echo message="line.separator : ${line.separator}"/>

          <echo message="user.home : ${user.home}"/>
          <echo message="user.name : ${user.name}"/>
          <echo message="user.dir : ${user.dir}"/>

          <echo message="Path: ${env.Path}"/>
          <echo message="Hostname: ${env.COMPUTERNAME}"/>
      </target>



Reference:
http://www.roseindia.net/tutorials/ant/built-in-properties.shtml

2011年4月21日 星期四

[Android] Build NDK by Ant

Sometimes, we would like to aotu-build by Ant, including the native code.
In past, we always use cygwin, enter the command 'ndk-build' then run the project to build.
Now, we could execute bash command in Build.xml as below.
So that Ant will automatically build the ndk part.

    <property name="bash" location="c:\cygwin\bin\bash.exe" />

    <target name="native-build">
        <exec executable="${bash}">
            <arg value="--login" />
            <arg value="-c"/>
            <arg value="cd /<project-path>/jni; ndk-build"/>
        </exec>
    </target>


If you don't want to regard the <project-path>, doing as below.
In this case, you have to set the make.exe path and ndk-build path in System Variable.

    <property name="bash" location="c:\cygwin\bin\bash.exe" />

    <target name="native-build"
        <exec executable="${bash}">
            <arg value="-c"/>
            <arg value="cd jni; ndk-build"/>
        </exec>
    </target>


Reference:
http://stackoverflow.com/questions/4279931/trouble-executing-bash-exe-from-an-ant-buildfile-in-eclipse

http://o0o.cse.tw/post/901059732/android
http://help.eclipse.org/helios/index.jsp?topic=/org.eclipse.platform.doc.user/gettingStarted/qs-81_basics.htm
http://www.coolsun.idv.tw/modules/xhnewbb/viewtopic.php?topic_id=1123&viewmode=thread

[Android] INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES

Problem:
When I build project and install on target.
IDE pop the message: INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES

Cause:
It's mean the target already have same program.
Installer try to uninstall old version from target but application signtures are not the same.

Solution:
Never mind what is application signtures.
Just uninstall the old version program in target then run again, problem will be solved.

2011年4月20日 星期三

Git Clone, Fetch, Pull from Local Area Network

Illustrate how to clone, pull or fetch through network.

If A share a folder GitShare include the project folder Zoo on computer with IP address 192.168.0.1
We could enter command below to clone the remote project folder.
git clone file:////192.168.0.1/GitShare/Zoo



In another way, we could establish the network drive named Z with \\192.168.0.1\GitShare
Then enter command below to clone.
git clone z:Zoo


Reference:

Git Create Patch

Follow by http://twnin.blogspot.com/2011/04/git-basic-manipulation.html

Mention in the link above, the B clone project files from A.
The B modify file content and A merge the change file from B.

Now, the B modify and commit again.







If directory A can't connect to directory B.
The B can produce a patch file, and mail it or give it to A.




















The A put the patch file into directory A then apply patch to project.



















Reference:
http://blog.longwin.com.tw/2009/05/git-send-patch-commit-use-email-2009/

Git Basic Manipulation

Assume here is a project name A and stores at directory C:\A.
We try to use Git to control the project source files.

We can execute Git Bash for operation.







Go to directory A then initial Git management.


Create a new file Hello.txt and input hello in file content.















Notify Git we have a new file in directory need to be managed.
git add .  mean add all file in directory.
git add <fileName> to add single file




Commit all changed in past operation.
git commit -am 'initial' 
    -a mean commit all changed files
    -m 'initial' mean plus commit memo.

Now, Assume someone B want to help develop project A at directory C:\B
B need to get project A's files.

B modify the Hello.txt content to 'hello by B'.

B commits his changed file.

Then B tell A that B has done his job, A can merge the changed file now.
A get file from B.

A compare the differenct between source file and new file.

A merge new file into source file.

Hello.txt of A has chenged
















If A modify again.






B can pull new version from A.




















Reference :

2011年4月15日 星期五

[Android] NDK: return IntArray from native code

p_Array is a int pointer contain 256 items.
If we want send it out to Java code, example as below.
jintArray Java_com_example_play_getIntArray( JNIEnv* env, jobject thiz )
{
    jintArray javaArray;         // output type is jintArray
    int size = 256;
    javaArray = (*env)->NewIntArray(env, size);   
    (*env)->SetIntArrayRegion(env, javaArray, 0, size, (jint *)p_Array);
     return javaArray;
}

2011年4月14日 星期四

How to get file size in C

We can use two function to achieve it.
Use fseek to set the file pointer at end of file.
Then use ftell get current relative position to beginning of file.
Finally, we should set file pointer back to beginning of file.

The code as below:
fseek(pFile, 0, SEEK_END); // seek to end of file
fileSize = ftell(pFile);               // get current file pointer
fseek(pFile, 0, SEEK_SET);  // seek back to beginning of file

[Android] NDK : convert jstring to char*

I try to send a jstring parameter into C native code, but it showing disorderly.
Here is convenient function help you convert the input parameter from jstring to char* .
char* jstringTostring(JNIEnv* env, jstring jstr)
{
    char* rtn = NULL;
    jclass clsstring = (*env)->FindClass(env, "java/lang/String");
    jstring strencode = (*env)->NewStringUTF(env, "utf-8");
    jmethodID mid = (*env)->GetMethodID(env, clsstring, "getBytes", "(Ljava/lang/String;)[B");
    jbyteArray barr= (jbyteArray)(*env)->CallObjectMethod(env, jstr, mid, strencode);
    jsize alen = (*env)->GetArrayLength(env, barr);
    jbyte* ba = (*env)->GetByteArrayElements(env, barr, JNI_FALSE);

    if (alen > 0)
    {
    rtn = (char*)malloc(alen + 1);

    memcpy(rtn, ba, alen);
    rtn[alen] = 0;
    }
    (*env)->ReleaseByteArrayElements(env, barr, ba, 0);

    return rtn;
}

2011年4月13日 星期三

[Android] Simnulate insert SD Card Into Android Emulator

> Create a SD card image file.

cd <Android SDK Path>\tools
mksdcard 128M sdcard.img

> Start Emulator with SD card.

emulator -avd Dalvik_10 -sdcard sdcard.img   (Dalvik_10 is name of emulator)

you can see the SD card infomation as below.




















> Copy file into SD card

adb push WAA.pdf /sdcard  (WAD.pdf is file name)


> Copy file from SD card

adb pull /sdcard



> Remove file from SD card

adb shell
cd sdcard
rm WDA.pdf









> Further more, you can read the file by NDK.....
/** file open */
jstring Java_com_example_Play_openFile( JNIEnv* env, jobject thiz )
{
    // Open file from SD card
    FILE *outfile;
    char dir[40] = "/sdcard/WAD.pdf";
    if((outfile = fopen(dir ,  "r")) == NULL )
    {
        return (*env)->NewStringUTF(env, "NULL");
    }

    fclose(outfile);
    return (*env)->NewStringUTF(env, "DONE");
}

[Android] NDK: Link to static library.

Situation:
I got a static library for develop android application incuding header file (lib.h) and static library file (lib.a).
But, I have no idea about how to use this stuff in NDK.
Finally I work it out...

Slove:
I show my code below

My native code (Native.c):

#include <jni.h>
#include "lib.h"      
// include header file

jint Java_com_example_Init( JNIEnv* env, jobject thiz )
{
    Result = Init();   // this is lib.Init()   

    return Result;
}

My make file (Android.mk):
LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)
LOCAL_MODULE := mylib
LOCAL_SRC_FILES := lib.a
include $(PREBUILT_STATIC_LIBRARY)


include $(CLEAR_VARS)
LOCAL_MODULE    := Native
LOCAL_SRC_FILES := Native.c
LOCAL_STATIC_LIBRARIES := mylib
include $(BUILD_SHARED_LIBRARY)

As you see, you have to prebuilt static library into module "mylib" then lick mylib to Native.c.

2011年4月12日 星期二

[Android] NDK: No implementation found for native

Problem:
I met an error when I build a simple ndk app.
error message as below:
04-12 14:35:30.009: WARN/dalvikvm(538): No implementation found for native Lcom/example/MyActivity;.stringFromJNI ()Ljava/lang/String;
04-12 14:35:30.018: DEBUG/AndroidRuntime(538): Shutting down VM
04-12 14:35:30.018: WARN/dalvikvm(538): threadid=1: thread exiting with uncaught exception (group=0x40015560)
04-12 14:35:30.048: ERROR/AndroidRuntime(538):
FATAL EXCEPTION: main
        java.lang.UnsatisfiedLinkError: stringFromJNI
        at com.example.MyActivity.stringFromJNI(Native Method)
        at com.example.MyActivity.onCreate(MyActivity.java:16)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
        at android.app.ActivityThread.access$1500(ActivityThread.java:117)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:123)
        at android.app.ActivityThread.main(ActivityThread.java:3683)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:507)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
        at dalvik.system.NativeStart.main(Native Method)

Solve:
It cause by wrong function name of native code.

my native code, shown that package is com.play.MyActivity
#include <string.h>
#include <jni.h>
jstring Java_com_play_MyActivity_stringFromJNI( JNIEnv* env, jobject thiz )
{
    return (*env)->NewStringUTF(env, "Hello from JNI by myself!");
}
my source code, shown that package is com.example.MyActivity
package com.example;
import ...

public class MyActivity extends Activity
{
    /** code **/
}

I modified the native code to correct package then problem is sloved.
#include <string.h>
#include <jni.h>
jstring Java_com_example_MyActivity_stringFromJNI( JNIEnv* env, jobject thiz )
{
    return (*env)->NewStringUTF(env, "Hello from JNI by myself!");
}

[Android] Use IntelliJ IDEA for Android Develop

Assume you already installed JDK and Android SDK.

You only need to download IntelliJ IDEA from it's official site then install it.
http://www.jetbrains.com/idea/download/index.html

Now, execute IntelliJ IDEA.













Click File->New Project
Select Create project from scratch and Click Next
Type "Hello IDEA" in Name.
Select appropriate Project files location.
Select "Android Module" as Project Type
Click Next



















Select Create source directory
Click Next


Click "Add" icon for select JDK

 

Select JSDK

Select JDK Path then Click Next


Then Click New and select Android SDK Path 

Select Android 2.3.3 as Android SDK build target then click Finish.



 Now, you'll see the familiar project structure in left docking window.




















Click Tool->Android->Android SDK and AVD Manager.
Create an Android 2.3.3 Emulator as you did in Eclipse.

Click Run->Run.

2011年4月11日 星期一

setjmp / longjmp

setjmp : Set a break point for get back.

longjmp:Go to break point where set up before.

01  #include <stdio.h>
02  #include <setjmp.h>
03 
04  jmp_buf _buffer;
05 
06  int main( int argc, char* argv[] )
07  {
08      if( setjmp( _buffer ) == 0 )
09      {
10          // do something11         
12          // longjmp will go to the break point, and set setjmp( _buffer ) to 1
13          longjmp( _buffer, 1 );
14          }
15      else
16      {
17          // do something
18      }
19  }

in the instance.
It will execute line number in turn 
01...08...13->08->15....19

If line 13 change to longjmp( _buffer, 0 );
It will execute line number in turn 
01...08...13->08->09....13->08->09....13->08->09....  (infinite loop)

2011年4月9日 星期六

Hello QT Creator (install QT Creator in windows XP)

Download IDE

We need an IDE for development. (Dev C++, VS .Net, QT Creator, Eclipse)
Here we choice QT Creator to achive this goal, so you have to download the QT Creator for windows in official site.
qt-creator-win-opensource-2.1.0.exe (included MinGW).
http://qt.nokia.com/downloads/qt-creator-binary-for-windows


Download QT Library

Also, you have to download the QT library for compile and make.
qt-win-opensource-4.7.2-mingw.exe  (compiler, qmake, QT library)
http://qt.nokia.com/downloads/windows-cpp

When you ready all materials, let work it out!


Install the QT Creator

Just click Next until it's done.
















Install the QT library

Only have to modify the MinGW install path to QT Creator install folder.
like C:\Qt\qtcreator-2.1.0\mingw

















Then just click Next until it's done.

















Setup Environment Variables

Add Path
C:\Qt\4.7.2\bin
C:\Qt\qtcreator-2.1.0\mingw\bin

Add Variable
QMAKESPEC = C:\Qt\4.7.2\mkspecs\win32-g++
QTDIR = C:\Qt\4.7.2



Hello QT

Create a test.cpp file in C:\QT\Work
#include <QApplication>
#include <QPushButton>

int main(int argc, char *argv[])
{
   QApplication app(argc, argv);
   QPushButton hello("Hello world!");
   hello.show();
   return app.exec();
}



Execute Cmd.exe for Compile and make
Chang directory to C:\QT\Work
Execute qmake -project in command line.
Execute qmake in command line.
Execute make in command line.

















Run it !



















Hello QT Creator

1. Execute Qt Creator
2. Select File->New File or Project on menu.
3. Choose Qt C++ Project and Qt Gui Application then click Choose.

















4. Input project name and folder location.
5. Decide the 'Main Window' class infomation, then click Next and Finish.
6. Select Debug->Start Debugging->Start Debugging on menu.


















Reference:
http://blogold.chinaunix.net/u3/94212/showart_2526345.html
http://qt.nokia.com/

2011年4月8日 星期五

Hello QT (install QT in linux)

Because my system OS is win xp, so I have to use VM for establish linux enviorment.

1. Install VM station.

Choice "Typical" way and just click "next" until it has done.
Sure, you guy should restart computer after installation compeleted.

















2. Install Ubuntu on Virtual Machine.

You can get lastest version of Ubuntu from official web site. (http://www.ubuntu.com/)
Create a new virtual machine in VM workstation and install from image file.

   

















Then completed the installation by yourself, because nothing special need to metion here.

















3. Make sure you can compile C/C++ file

Write a simple Hello.c file for test the function.
#include<stdio.h>
int main()
{
    printf("Hello Ubuntu!\n");
    return 0;
}


run it...
$ gcc -Wall Hello.c -o testc
$ ./testc
$ Hello Ubuntu!
If you can't done this....type the command in terminial for install gcc.
sudo apt-get install build-essential   (Recommand to do this whatever.)

4. Install QT 4 in Ubuntu

Type command below in terminal for QT 4 installation.
sudo apt-get install libqt4-dev         (necessary)
sudo apt-get install qt4-doc            (necessary)
sudo apt-get install qt4-designer     (necessary)
sudo apt-get install libqt4-dbg         (optional)
sudo apt-get install libqt4-gui          (optional)
sudo apt-get install libqt4-sql          (optional)
sudo apt-get install qt4-dev-tools    (optional)
sudo apt-get install qt4-qtconfig      (optional)








Wait about 20 minutes for download and setup automatically.

5. Write HelloQT.cpp file

#include <QApplication>
#include <QPushButton>

int main(int argc, char *argv[])
{
   QApplication app(argc, argv);
   QPushButton hello("Hello world!");
   hello.show();
   return app.exec();
}


6. Make and Run

Execute command below in turn for make files.
$ qmake -project
$ qmake
$ make


Then run it !
$ ./HelloQT













Reference
http://wallyjue.blogspot.com/2008/08/ubuntu-qt4.html
http://forum.ubuntu.org.cn/viewtopic.php?f=88&t=190878

2011年4月7日 星期四

Error 13 general error c101008a: Failed to save the updated manifest to the file ".\Debug\******.exe.embed.manifest". The parameter is incorrect. mt.exe

Error Message:
Error 13 general error c101008a: Failed to save the updated manifest to the file ".\Debug\******.exe.embed.manifest". The parameter is incorrect. mt.exe


Slove:
It's cause by you changed the Character Set from Unicode to Multi-Byte.
You shold rebuild solution or right click on project name then click "clean".


Building MFC application with /MD[d] (CRT dll version) requires MFC shared dll version. Please #define _AFXDLL or do not use /MD[d]

Error Message:
Error 1 fatal error C1189: #error :  Building MFC application with /MD[d] (CRT dll version) requires MFC shared dll version. Please #define _AFXDLL or do not use /MD[d] c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\afx.h 24 MFC_Foxit

Solve:

1. Right click on project and select "properties"



























2. Configuration Properties -> General -> Use of MFC
Chang selection to "Use MFC in a Shared DLL" if this is a SDI project, or to "Use MFC in a Static Library" if this is a MDI project.


















2011年4月4日 星期一

[Android] Preference

How to save preference or confign in a activity.



How to get preference in a activity.


You can also use SharedPreference to get and set preference inter activitys like this.

SharedPreferences setting = getSharedPreferences("PreferenceName", 0);

int value;
SharedPreferences setting = getPreferences(MODE_PRIVATE);
value = setting.getInt("Tag", 0);

int value = 0;
SharedPreferences setting = getPreferences(MODE_PRIVATE);
SharedPreferences.Editor prefEditor = setting.edit();
prefEditor.putInt(“Tag”, value);
prefEditor.commit();