Posted by: slworkthings | August 11, 2011

Make Android UI looks like iPhone UI

I made my Android app looks like iPhone app. See the image below.

iPhone UI on Android

iPhone UI on Android

Posted by: slworkthings | July 13, 2011

Make iOS UISwitch style in Qt4.

QSlider and UISwitch

This is how to write Qt stylesheet code to make QSlider just like iPhone UISwitch on/off toggle button.

1. In QDesigner, drag QSlider into your form.
2. Modify properties. Make “minimum” to be “0″, “maximum” to be “1″, “orientation” to be “Horizontal”, etc.
3. Insert following code into the stylesheet field.


QSlider {
min-width:80px;
min-height:27px;
max-width:80px;
max-height:27px;
}
QSlider::groove:horizontal {
background-image: url(:/images/slider_bg.png);
background-repeat: no-repeat;
background-position:center;
margin:0px;
border:0px;
padding:0px;
}

QSlider::sub-page:horizontal {
background-image: url(:/images/slider_on.png);
background-repeat: no-repeat;
background-position:left;
background-origin:content;
margin:0px;
border:0px;
padding-left:0px;
}

QSlider::add-page:horizontal {
background-image: url(:/images/slider_off.png);
background-repeat: no-repeat;
background-position:right;
background-origin:content;
margin:0px;
border:0px;
padding-right:0px;
}

QSlider::handle:horizontal {
background-image: url(:/images/slider_handle.png);
width:39px;
height:27px;
margin:0px;
border:0px;
padding:0px;
}

QSlider::sub-page:horizontal:disabled {
background-image: url(:/images/slider_on_disabled.png);
background-repeat: no-repeat;
background-position:left;
background-origin:content;
margin:0px;
border:0px;
padding-left:0px;
}

QSlider::add-page:horizontal:disabled {
background-image: url(:/images/slider_off_disabled.png);
background-repeat: no-repeat;
background-position:right;
background-origin:content;
margin:0px;
border:0px;
padding-right:0px;
}

QSlider::handle:horizontal:disabled {
background-image: url(:/images/slider_handle.png);
width:39px;
height:27px;
margin:0px;
border:0px;
padding:0px;
}

4. Create your own png files like following images.

slider_bg.png

 

slider_on.png

 

slider_off.png

 

slider_handle.png

 

5. Done.

Posted by: slworkthings | May 18, 2011

Recursively remove a directory in Qt4

Today I wrote a code to remove a directory and all its sub-directories and files.


bool MyUtil::removeDir(const QString& dirName)
{
    bool result = true;
    QDir dir(dirName);

    if (dir.exists(dirName))
    {
        Q_FOREACH(QFileInfo info, dir.entryInfoList(QDir::NoDotAndDotDot|QDir::AllDirs|QDir::Files, QDir::DirsFirst))
        {
            if (info.isDir())
                result = removeDir(info.absoluteFilePath());
            else
                result = QFile::remove(info.absoluteFilePath());

            if (!result)
                return result;
        }
        result = dir.rmdir(dirName);
    }
    else
    {
        QFile file(dirName);
        if (file.exists())
            result = file.remove();
    }

    return result;
}//removeDir()

Posted by: slworkthings | April 4, 2011

How to compile ffmpeg/x264 for Windows

Very good script that will checkout codes and compile libraries. Nice!

http://csbarn.blogspot.com/2011/02/how-to-compile-ffmpegx264-for-windows.html

Posted by: slworkthings | March 21, 2011

Android NDK with PThread

After spending several hours debugging, I finally figure out how to solve the crash in my native code while calling pthread_exit(). The log showed “thread exiting, not yet detached (count=0)“.

Scenario:

I have an Android java code which will call my JNI (NDK) native code. In my native code, I create a pthread and in my pthread loop, I called AttachCurrentThread() to the JVM in the beginning of the loop.

When my java code finish some jobs, I need to stop the pthread and it crashed at the end of pthread loop.

Solution:

So, before I exit my pthread loop (before calling pthread_exit), I need to make sure I do call DetachCurrentThread from JVM.

Older Posts »

Categories

Follow

Get every new post delivered to your Inbox.