수요일, 10월 27, 2010

[Android] My Tip; RemoteService Example

RemoteService Example

Reference Source:
http://developer.android.com/guide/developing/tools/aidl.html
http://developer.android.com/reference/android/app/Service.html
http://www.androidpub.com/102370



// -----------------------------------------------
// more Activity
// AndroidManifest.xml
// -----------------------------------------------
<activity android:name=".MainActivity"
android:label="MainActivity"
android:configChanges="keyboardHidden|orientation"
android:theme="@android:style/Theme.NoTitleBar"
android:launchMode="singleTask"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".anotherActivity"
android:label="anotherActivity"
android:configChanges="keyboardHidden|orientation"
android:theme="@android:style/Theme.NoTitleBar"
android:launchMode="singleTask"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

// -----------------------------------------------
// RemoteService
// AndroidManifest.xml
// -----------------------------------------------
<service android:enabled="true" android:name=".testActivity">
</service>


// -----------------------------------------------
// RemoteService
// AndroidManifest.xml
// -----------------------------------------------


// -----------------------------------------------
// RemoteService
// Service.java
// -----------------------------------------------
package com.test.testActivity;

// Service
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Intent;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.IBinder;
import android.os.Looper;
import android.os.Message;
import android.os.RemoteCallbackList;

import android.util.Log;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.widget.MediaController;
import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.Toast;

/*
@Activity A (test)
startService( new Intent(test.testActivity, testService.class).putExtra("tag", "data") );

String[] strList = {
{"strList1"},
{"strList2"}
};
startService( new Intent(test.testActivity, testService.class).putExtra("tag2", strlist) );

@Service B (testService)
Bundle extras = getIntent().getExtras();
String[] strList = extras.getStringArray( "strlist" );
*/
public class testService extends Service {
private String TAG = "testService";

// Service
private NotificationManager mNM;
private Intent m_InvokeIntent;
private volatile Looper m_ServiceLooper;
private volatile ServiceHandler m_ServiceHandler;
public String m_Str = null;

final RemoteCallbackList m_Callbacks
= new RemoteCallbackList();

private final class ServiceHandler extends Handler {
public ServiceHandler(Looper looper) {
super(looper);
}

@Override
public void handleMessage(Message msg) {
Bundle extras = (Bundle)msg.obj;
String strTagValue = null;

/*
{
// Broadcast
strTagValue = extras.getString( "command" );
if( strTagValue != null ) {
if( strTagValue.equals("pause") ) {
stopSelf( msg.arg1 );
return;
}
else if( strTagValue.equals("stop") ) {
stopSelf( msg.arg1 );
return;
}
}
}
*/

strTagValue = null;
strTagValue = extras.getString( "tag" );
Log.d( TAG, "Message: " + msg + ", tagValue = " + strTagValue );

if( strTagValue != null ) {
if( strTagValue.equals("data") ) {
}
else if( strTagValue.equals("strlist") ) {
m_strPlayList = extras.getStringArray( "strlist" );
}
else {
Log.d( TAG, "QUIT" );
stopSelf( msg.arg1 );
return;
}
}
else {
stopSelf( msg.arg1 );
return;
}
}
};
  
@Override
public void onCreate() {
mNM = (NotificationManager)getSystemService( NOTIFICATION_SERVICE );
HandlerThread thread = new HandlerThread( "MediaServiceStart" );
thread.start();

m_ServiceLooper = thread.getLooper();
m_ServiceHandler = new ServiceHandler( m_ServiceLooper );
}

@Override
public void onStart(Intent intent, int startId) {
Log.d( TAG, "ServiceStartArguments: Starting #" + startId + ": " + intent.getExtras() );
{
Message msg = m_ServiceHandler.obtainMessage();
msg.arg1 = startId;
msg.obj = intent.getExtras();
m_ServiceHandler.sendMessage( msg );
Log.d( TAG, "ServiceStartArguments: Sending: " + msg );

// Test: Broadcast
/*
final int n = m_Callbacks.beginBroadcast();
Log.d( TAG, "n = " + n );
for( int i = 0; i < n; i++ )
Log.d( TAG, "item = " + m_Callbacks.getBroadcastItem(i) );
m_Callbacks.finishBroadcast();
*/
}
}

@Override
public void onDestroy() {
m_ServiceLooper.quit();
}

@Override
public IBinder onBind(Intent intent) {
return m_Binder;
}

// The IRemoteInterface is defined through IDL
private final IRemoteService.Stub m_Binder = new IRemoteService.Stub() {
public void registerCallback(IRemoteServiceCallback cb) {
if (cb != null) m_Callbacks.register(cb);
}

public void unregisterCallback(IRemoteServiceCallback cb) {
if (cb != null) m_Callbacks.unregister(cb);
}

public String getInfo() {
String str = "i'm service";
return str;
}
public String setInfo(String str) {
Log.d( TAG, "RECEIVED From Activity: " + str );
return str;
}
};
}


// -----------------------------------------------
// testActivity.java
// -----------------------------------------------
// Service
import android.content.ServiceConnection;
import android.content.ComponentName;
import android.os.IBinder;
import android.os.RemoteException;
public class testActivity extends Activity implements {
// Service
private IRemoteService m_Service = null;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

//setContentView(R.layout.main);
//Intent(testActivity.this, testService.class)
//Intent intt = new Intent( testActivity.this, Activity2.class );
//startActivity( intt );

//bindService( new Intent(testService.class.getName()), m_Connection, Context.BIND_AUTO_CREATE );
bindService( new Intent(testActivity.this, testService.class), m_Connection, Context.BIND_AUTO_CREATE );
startService( new Intent(testActivity.this, testService.class).putExtra("tag", "quit") );

/*
if( m_Service != null ) {
try {
m_Service.unregisterCallback( m_Callback );
} catch (RemoteException e) {
}
}

// Detach our existing connection.
unbindService( m_Connection );
stopService( new Intent(testActivity.this, testService.class) );
*/
}

@Override
protected void onDestroy() {
if( m_Service != null ) {
try {
m_Service.unregisterCallback( m_Callback );
} catch (RemoteException e) {
}
}

if( m_Connection != null ) {
// Detach our existing connection.
unbindService( m_Connection );
}
stopService( new Intent(testActivity.this, testService.class) );

super.onDestroy();
}

// Service
private ServiceConnection m_Connection = new ServiceConnection() {
public void onServiceConnected(ComponentName className, IBinder service) {
m_Service = IRemoteService.Stub.asInterface(service);
try {
m_Service.registerCallback(m_Callback);
Log.d( TAG, "RECEIVED From Service: " + m_Service.getInfo() );
m_Service.setInfo( "i'm activity" );
} catch (RemoteException e) {
}
Toast.makeText( testActivity.this, "Service Connected", Toast.LENGTH_SHORT ).show();
}

public void onServiceDisconnected(ComponentName className) {
m_Service = null;
Toast.makeText( testActivity.this, "Service Disconnected", Toast.LENGTH_SHORT ).show();
}
};

// This implementation is used to receive callbacks from the remote service.
private IRemoteServiceCallback m_Callback = new IRemoteServiceCallback.Stub() {
public void valueChanged(int value) {
//mHandler.sendMessage(mHandler.obtainMessage(BUMP_MSG, value, 0));
}
};
}

// -----------------------------------------------
// IRemoteService.aidl (default + method)
// Source (v1.6): C:/android-sdk-windows/platforms/android-4/samples/ApiDemos/src/com/example/android/apis/app
// -----------------------------------------------
package com.test.testActivity;
import com.test.testActivity.IRemoteServiceCallback;
interface IRemoteService {
void registerCallback(IRemoteServiceCallback cb);
void unregisterCallback(IRemoteServiceCallback cb);
// ADD
String getInfo();
String setInfo(String str);
}

// -----------------------------------------------
// IRemoteServiceCallback.aidl (default)
// Source (v1.6): C:/android-sdk-windows/platforms/android-4/samples/ApiDemos/src/com/example/android/apis/app
// -----------------------------------------------
default



-----
Cheers,
June

금요일, 10월 22, 2010

[Editor][Vim] Vim in Eclipse, Vrapper

Vrapper: Vim-like editing in Eclipse
Source: http://vrapper.sourceforge.net/home/

1. Eclipse: Help -> Install New Software
Add & Install: http://vrapper.sourceforge.net/update-site/stable

2. Window -> Preferences -> General -> Keys -> Select Vim's key bindings
Replace key:
 - Page Down: Ctrl+F
 - Page Up: Ctrl+B
 - Scroll Line Down: Ctrl+E
 - Scroll Line Up: Ctrl+Y

3. Apply & OK

4. Click Vim(Toggle Vrapper) button onto Toolbar when you need


-----
Cheers,
June

월요일, 10월 04, 2010

[Android] My Tip; Android Resolution Problem

Android Resolution Problem

Your App resolution wil be fixed 320x480(Portrait) if you missed the minSdkVersion.
so, you should be set it to 4(Android SDK Version 1.6) or higher.

Adds this into your AndroidManifest.xml:
Note: Change "(" to "<" and ")" to ">"
(manifest)
...
(uses-sdk android:minSdkVersion="4")(/uses-sdk)
(/manifest)

I've tested on Samsung Galaxy Tab.



-----
Cheers,
June

목요일, 9월 30, 2010

[Editor][Emacs] Emacs Manual

Emacs Manual


:: GNU Emacs Manual
 - Source: http://www.delorie.com/gnu/docs/emacs/emacs_toc.html#SEC_Contents



:: Quick EMACS Commands
 - Source: http://xkahn.zoned.net/help/emacs.html
---------------
[Quitting EMACS:]
Quit:    Ctrl-x Ctrl-c
I pushed the wrong key. Help!:    Ctrl-g
---------------
[Working with files:]
Load a file:    Ctrl-x Ctrl-f
Load a directory:    Ctrl-x Ctrl-f
New file:    Ctrl-x Ctrl-f
Save a file:    Ctrl-x Ctrl-s
Save all open files:    Ctrl-x s
Save the file with a new name    Ctrl-x Ctrl-w
---------------
[Dealing with Buffers]
Switch buffers:    Ctrl-x b
Close buffer:    Ctrl-x k
Split current buffer    Ctrl-x 2
Make current buffer the only one on screen    Ctrl-x 1
Switch between the buffers on-screen    Ctrl-x o
---------------
[Cutting and pasting]
Set mark:    Ctrl-[SPACE]
Cut and save text from here to mark:    Ctrl-w
Paste saved text:    Ctrl-y
Cut text from the cursor to the end of the line:    Ctrl-k
---------------



:: Emacs Command Summary
 - Source: http://www.cs.rutgers.edu/LCSR-Computing/some-docs/emacs-chart.html
---------------
Emacs Command Summary
Emacs command summary, Thu Jul 25.

C-SP     set-mark-command         C-q      quoted-insert
C-a      beginning-of-line         C-r      isearch-backward
C-b      backward-char             C-s      isearch-forward
C-c      exit-recursive-edit         C-t      transpose-chars
C-d      delete-char             C-u      universal-argument
C-e      end-of-line             C-v      scroll-up
C-f      forward-char             C-w      kill-region
C-h      help-command             C-x      Control-X-prefix
TAB      indent-for-tab-command         C-y      yank
LFD      newline-and-indent         C-z      suspend-emacs
C-k      kill-line             ESC      ESC-prefix
C-l      recenter             C-]      abort-recursive-edit
RET      newline             C-_      undo
C-n      next-line             SPC .. ~        self-insert-command
C-o      open-line             DEL      delete-backward-char
C-p      previous-line

C-h v    describe-variable         C-h d    describe-function
C-h w    where-is             C-h k    describe-key
C-h t    help-with-tutorial         C-h c    describe-key-briefly
C-h s    describe-syntax         C-h b    describe-bindings
C-h n    view-emacs-news         C-h a    command-apropos
C-h C-n  view-emacs-news         C-h C-d  describe-distribution
C-h m    describe-mode             C-h C-c  describe-copying
C-h l    view-lossage             C-h ?    help-for-help
C-h i    info                 C-h C-h  help-for-help
C-h f    describe-function

C-x C-a  add-mode-abbrev         C-x 5    split-window-horizontally
C-x C-b  list-buffers             C-x ;    set-comment-column
C-x C-c  save-buffers-kill-emacs     C-x <    scroll-left
C-x C-d  list-directory             C-x =    what-cursor-position
C-x C-e  eval-last-sexp             C-x >    scroll-right
C-x C-f  find-file             C-x [    backward-page
C-x C-h  inverse-add-mode-abbrev     C-x ]    forward-page
C-x TAB  indent-rigidly             C-x ^    enlarge-window
C-x C-l  downcase-region         C-x `    next-error
C-x C-n  set-goal-column         C-x a    append-to-buffer
C-x C-o  delete-blank-lines         C-x b    switch-to-buffer
C-x C-p  mark-page             C-x d    dired
C-x C-q  toggle-read-only         C-x e    call-last-kbd-macro
C-x C-r  find-file-read-only         C-x f    set-fill-column
C-x C-s  save-buffer             C-x g    insert-register
C-x C-t  transpose-lines         C-x h    mark-whole-buffer
C-x C-u  upcase-region             C-x i    insert-file
C-x C-v  find-alternate-file         C-x j    register-to-dot
C-x C-w  write-file             C-x k    kill-buffer
C-x C-x  exchange-dot-and-mark         C-x l    count-lines-page
C-x C-z  suspend-emacs             C-x m    mail
C-x ESC  repeat-complex-command         C-x n    narrow-to-region
C-x $    set-selective-display         C-x o    other-window
C-x (    start-kbd-macro         C-x p    narrow-to-page
C-x )    end-kbd-macro             C-x q    kbd-macro-query
C-x +    add-global-abbrev         C-x r    copy-rectangle-to-register
C-x -    inverse-add-global-abbrev     C-x s    save-some-buffers
C-x .    set-fill-prefix         C-x u    advertised-undo
C-x /    dot-to-register         C-x w    widen
C-x 0    delete-window             C-x x    copy-to-register
C-x 1    delete-other-windows         C-x {    shrink-window-horizontally
C-x 2    split-window-vertically     C-x }    enlarge-window-horizontally
C-x 4    ctl-x-4-prefix             C-x DEL  backward-kill-sentence

ESC C-SP mark-sexp             ESC =    count-lines-region
ESC C-a  beginning-of-defun         ESC >    end-of-buffer
ESC C-b  backward-sexp             ESC @    mark-word
ESC C-c  exit-recursive-edit         ESC O    ??
ESC C-d  down-list             ESC [    backward-paragraph
ESC C-e  end-of-defun             ESC \    delete-horizontal-space
ESC C-f  forward-sexp             ESC ]    forward-paragraph
ESC C-h  mark-defun             ESC ^    delete-indentation
ESC LFD  indent-new-comment-line     ESC a    backward-sentence
ESC C-k  kill-sexp             ESC b    backward-word
ESC C-n  forward-list             ESC c    capitalize-word
ESC C-o  split-line             ESC d    kill-word
ESC C-p  backward-list             ESC e    forward-sentence
ESC C-s  isearch-forward-regexp         ESC f    forward-word
ESC C-t  transpose-sexps         ESC g    fill-region
ESC C-u  backward-up-list         ESC h    mark-paragraph
ESC C-v  scroll-other-window         ESC i    tab-to-tab-stop
ESC C-w  append-next-kill         ESC j    indent-new-comment-line
ESC ESC  ??                 ESC k    kill-sentence
ESC C-\  indent-region             ESC l    downcase-word
ESC SPC  just-one-space             ESC m    back-to-indentation
ESC !    shell-command             ESC q    fill-paragraph
ESC $    spell-word             ESC r    move-to-window-line
ESC %    query-replace             ESC t    transpose-words
ESC '    abbrev-prefix-mark         ESC u    upcase-word
ESC (    insert-parentheses         ESC v    scroll-down
ESC )    move-past-close-and-reindent     ESC w    copy-region-as-kill
ESC ,    tags-loop-continue         ESC x    execute-extended-command
ESC -    negative-argument         ESC y    yank-pop
ESC .    find-tag             ESC z    zap-to-char
ESC 0 .. ESC 9  digit-argument         ESC |    shell-command-on-region
ESC ;    indent-for-comment         ESC ~    not-modified
ESC <    beginning-of-buffer         ESC DEL  backward-kill-word

C-x 4 C-f       find-file-other-window     C-x 4 d  dired-other-window
C-x 4 .  find-tag-other-window         C-x 4 f  find-file-other-window
C-x 4 b  pop-to-buffer             C-x 4 m  mail-other-window
---------------



:: Quick EMACS Commands
 - Source: http://en.opensuse.org/Emacs
---------------
Action     Key-sequence     Command
Open file     C-x C-f     find-file
Close     C-x C-c     save-buffers-kill-emacs
Save file     C-x C-s     save-buffer
Save as     C-x C-w     write-file
Page down     C-v     scroll-up
Page up     M-v     scroll-down
Goto top     M-<     beginning-of-buffer
Goto end     M->     end-of-buffer
Goto line     M-g g     goto-line
Goto start of line     C-a     beginning-of-line
Goto end of line     C-e     end-of-line
Search forwards     C-s search term     isearch-forward search term
Repeat last search forwards     C-s C-s     isearch-repeat-forward
Search backwards     C-r search term     isearch-backward search term
Repeat last search backwards     C-r C-r     isearch-repeat-backward
Cancel command     C-g     keyboard-quit
Kill line     C-k     kill-line
Kill sentence     M-k     kill-sentence
Yank last kill     C-y     yank
Yank previous kill     M-y     yank-pop
Split window horizontally     C-x 2   
Split window vertically     C-x 3   
Swap active window     C-x o   
Merge windows     C-x 1   
List buffers     C-x C-b     list-buffers
Switch to buffer     C-x b     switch-to-buffer
Switch active buffer left     C-x [LEFT]     previous-buffer
Switch active buffer right     C-x [RIGHT]     next-buffer
Kill Buffer     C-x f     kill-buffer
Spell-check current buffer    none     ispell-buffer
Spell-check current word    none     ispell-word
Indent code     C-M-\     indent-region
Goto matching closing bracket     C-M-f   
Goto matching opening bracket     C-M-b   
---------------


-----
Cheers,
June

수요일, 9월 29, 2010

[Scheme] MIT/GNU Scheme

[Scheme] MIT/GNU Scheme

:: MIT/GNU Sceme
http://groups.csail.mit.edu/mac/projects/scheme/
http://www.gnu.org/software/mit-scheme/

:: SICP (Structure and Interpretation of Computer Programs)
http://mitpress.mit.edu/sicp/full-text/book/book.html

:: A Beginner's Guide to Using EMACS
http://xkahn.zoned.net/help/emacs.html


-----------------------------------------------------

:: Quick EMACS Commands
 - Source: http://xkahn.zoned.net/help/emacs.html
---------------
[Quitting EMACS:]
Quit:    Ctrl-x Ctrl-c
I pushed the wrong key. Help!:    Ctrl-g
---------------
[Working with files:]
Load a file:    Ctrl-x Ctrl-f
Load a directory:    Ctrl-x Ctrl-f
New file:    Ctrl-x Ctrl-f
Save a file:    Ctrl-x Ctrl-s
Save all open files:    Ctrl-x s
Save the file with a new name    Ctrl-x Ctrl-w
---------------
[Dealing with Buffers]
Switch buffers:    Ctrl-x b
Close buffer:    Ctrl-x k
Split current buffer    Ctrl-x 2
Make current buffer the only one on screen    Ctrl-x 1
Switch between the buffers on-screen    Ctrl-x o
---------------
[Cutting and pasting]
Set mark:    Ctrl-[SPACE]
Cut and save text from here to mark:    Ctrl-w
Paste saved text:    Ctrl-y
Cut text from the cursor to the end of the line:    Ctrl-k
---------------



-----
Cheers,
June

[Android] My Tip; Android ant release error (-dex: apply)

[Android] My Tip; Android ant release error (-dex: apply)


// ----------------------------------
// :: Preset
// ----------------------------------
 - Source Path
    C:/Program Files/MyAPKTest
 - Android SDK Path
    C:/android/android-sdk-windows
 - Using Android SDK Version: 2.1
    C:/android/android-sdk-windows/platforms/android-6/

// ----------------------------------
// :: Problem
//
// - Caused by this into dx.bat
//    if "%params%"=="" goto endArgs
//
// - e.g.,
//    set params = "--dex C:/Program Files/MyAPKTest/bin/classes.dex" "..." "..." "..."
//    if "%params%" == ""
// - DOS Batch Interpreter does not parse duplicated double-quotation.
// ----------------------------------
C:/Program Files/MyAPKTest> ant clean [OK]
C:/Program Files/MyAPKTest> ant compile [OK]
C:/Program Files/MyAPKTest> ant release
...
-dex:
     [echo] Converting compiled files and external libraries into C:/Program Files/MyAPKTest/bin/classes.dex...
     [echo]
    [apply] =C:/Files""은(는) 예상되지 않았습니다. (Korean)
    or
    [apply] =C:/Files"" was unexpected at this time. (English)
C:/Program Files/My APK Test>



// ----------------------------------
// :: Solution
// - Condition: Does not needs options
// ----------------------------------

// ----------------------------------
// 1. Open a dx.bat
// ----------------------------------
C:/android/android-sdk-windows/platforms/android-6/tools/dx.bat

// ----------------------------------
// 2. and Adds this in the above the ":nextArg"
// ----------------------------------
...
echo ***** SKIP check the parameter *****
set args=%params%
goto endArgs

:nextArg
if "%params%"=="" goto endArgs
...

// ----------------------------------
// 3. That's it, so now run clean & compile & release
// ----------------------------------
C:/Program Files/MyAPKTest> ant clean && ant compile && ant release
...
BUILD SUCCESSFUL
Total time: x seconds
C:/Program Files/MyAPKTest>



-----
Cheers,
June

수요일, 9월 15, 2010

[Android] My Tip; Android and ProGuard

Android and ProGuard
How to set ProGuard to ANT script for Android

STEP #1
Create a build.xml for ANT
c:/> ant update project --path c:/my_src
Create a build.property for keystore

STEP #2
EDIT build.xml

STEP #3
SETS ProGuard

STEP #4
BUILD

STEP #5
TEST, that's it!



//
// build.property
//
#application-package=com.test.testApp
#sdk-location=C:/android/android-sdk-windows/platforms/android-6

# KeyStore/Alias
key.store=__MY_KEYSTORE__.keystore
key.alias=__MY_KETSTORE_ALIAS__
key.store.password=__PASSWORD__
key.alias.password=__PASSWORD__

//
// build.xml
//
// --------------------------------
// 1. replace <setup />
// --------------------------------
by
    <!-- <setup /> -->
    <setup import="false" />

// --------------------------------
// 2. Adds this in the below <setup import="false" />
// --------------------------------
<!-- ProGuard -->
    <property name="proguard-dir" value="proguard"/>
    <property name="unoptimized" value="${proguard-dir}/unoptimized.jar"/>
    <property name="optimized" value="${proguard-dir}/optimized.jar"/>

    <target name="optimize" unless="nooptimize">
        <jar basedir="${out.classes.dir}" destfile="${unoptimized}"/>

        <java jar="${proguard-dir}/proguard.jar" fork="true" failonerror="true">
            <jvmarg value="-Dmaximum.inlined.code.length=16"/>
            <arg value="@${proguard-dir}/config.txt"/>     
            <arg value="-injars ${unoptimized}"/>
            <arg value="-outjars ${optimized}"/>
            <!--<arg value="-libraryjars ${android.jar}"/>-->
<!-- ADDS Library -->
            <arg value="-libraryjars ${android.jar}" />
            <!-- <arg value="-libraryjars libs/xxx.jar; libs/yyy.jar"/> -->
<!-- ADDS Library -->
        </java>    

        <!-- Delete source pre-optimized jar -->    
        <!--delete file="${unoptimized}"/-->

        <!-- Unzip target optimization jar to original output, and delete optimized.jar -->
        <delete dir="${out.classes.dir}"/>
        <mkdir dir="${out.classes.dir}"/>
        <unzip src="${proguard-dir}/optimized.jar" dest="${out.classes.dir}"/>

        <!-- Delete optimized jar (now unzipped into bin directory) -->
        <delete file="optimized.jar"/>
    </target>
<!-- ProGuard -->
...
<!-- 3. Copy rule and paste into build.xml; see below -->
...
</project>

// --------------------------------
// 3. Copy rule and paste into build.xml
// --------------------------------
OPEN a rule xml file
<SDK_PATH>/platforms/<target_platform>/templates/android_rules.xml

COPY from in the below <project name="android_rules" default="debug">
to in the above </project>
then, PASTE this in the below ProGuard

// --------------------------------
// 4. Finds <target name="-dex" depends="compile">
// --------------------------------
then, adds ", optimize" beside "compile"

<!-- ProGuard -->
    <target name="-dex" depends="compile, optimize">
<!-- ProGuard -->
...



//
// ProGuard
//
// --------------------------------
// 1. Get latest version
// --------------------------------
Download: http://sourceforge.net/project/showfiles.php?group_id=54750

// --------------------------------
// 2. Copy proguard.jar where into downloaded zip archive to my project directory
// --------------------------------
create a directory "proguard" into my project source directory
then, copy proguard/lib/proguard.jar to c:/my_src/proguard

// --------------------------------
// 3. Create a config.txt into "my_src_dir/proguard"
// --------------------------------
# --------------------------------------------------
# ProGuard:
#    http://proguard.sourceforge.net/
# ProGuard Download:
#    http://sourceforge.net/project/showfiles.php?group_id=54750
#
# config.txt Source:
#    http://www.androidengineer.com/2010/07/optimizing-obfuscating-and-shrinking.html
# --------------------------------------------------

-target 1.6
-optimizationpasses 2
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
#-verbose
#-dump class_files.txt
#-printseeds seeds.txt
#-printusage unused.txt
#-printmapping mapping.txt

# The -optimizations option disables some arithmetic simplifications that Dalvik 1.0 and 1.5 can't handle.
-optimizations !code/simplification/arithmetic

-keep public class * extends android.app.Activity
#-keep public class * extends android.app.Application
#-keep public class * extends android.app.Service
#-keep public class * extends android.content.BroadcastReceiver
#-keep public class * extends android.content.ContentProvider

#-keep public class * extends View {
#public <init>(android.content.Context);
#public <init>(android.content.Context, android.util.AttributeSet);
#public <init>(android.content.Context, android.util.AttributeSet, int);
#public void set*(...);
#}
# --------------------------------------------------

// --------------------------------
// build
// --------------------------------
c:/my_src> ant compile
c:/my_src> ant release


-----
Cheers,
June

목요일, 9월 02, 2010

[Android] My Tip; How to increase Android Emulator's Internal Phone Storage and RAM ?

How to increase Android Emulator's Internal Phone Storage and RAM ?

Usage:
-partition-size [Sizeo of the Internal Phone Storage; MB]
-qemu -m [Sizeo of the Physical RAM; MB]

Run:
- Internal Phone Storage: 512MB
- Physical RAM: 128MB (default)
C:/android-sdk-windows/tools> emulator -partition-size 512 -avd MyAVDname -qemu -m 128

-----
Cheers,
June

목요일, 8월 26, 2010

[Android] QAEP (MSM/QSD Android Enablement Project)

QAEP (MSM/QSD Android Enablement Project)
Source: https://www.codeaurora.org/wiki/QAEP#Branch_Releases


-----
Cheers,
June

[CV][IP] DICOM

DICOM (Digital Imaging and Communications in Medicine)

[Link]
* DICOM@OFFIS
http://dicom.offis.de/dcmintro.php.en
* Sample DICOM (.dcm) file
http://filmandpaperdigitizers.com/samples/DICOM/
* Medical Image Samples
http://barre.nom.fr/medical/samples/



-----
Cheers,
June

[Algorithm][AI][Genetic]

AI: Genetic Algorithm

[Link]
* Genetic-Programming by John R. Koza
http://www.genetic-programming.com/johnkoza.html
* Father of the Genetic Programming, John R. Koza (Written in Korean)
http://popsci.hankooki.com/popsci_news/view.php?news1_id=2506&cate=14&page=78&keyword=



-----
Cheers,
June

목요일, 8월 19, 2010

[Android] Android

Android

* Android Open Source Project
Source: http://android.git.kernel.org/

* Android x86 Project (Porting Android to x86)
Source: http://www.android-x86.org/


* Content Provider
Reference: http://www.devx.com/wireless/Article/41133


{ // CContentProvider Example
http://code.google.com/p/listenmystory/source/browse/

//
// CContentProvider Example
//

#DB: DB_CPtest
#TABLE NAME: info
#TABLE DESCRIPTION:
_id | title | data | data2 (extra)

// Get all of data
Uri allTitles = Uri.parse( "content://com.android.myTest1/db_cptest" );
Cursor c = managedQuery( allTitles, null, null, null, "_id asc" );
if( c.moveToFirst() ) {
do {
//Toast.makeText(this,
// c.getString(c.getColumnIndex(CContentProvider._ID)) + ", " +
// c.getString(c.getColumnIndex(CContentProvider.TITLE)) + ", " +
// c.getString(c.getColumnIndex(CContentProvider.DATA)) + ", " +
// c.getString(c.getColumnIndex(CContentProvider.DATA2)),
//Toast.LENGTH_LONG).show();

String strId = c.getString( c.getColumnIndex(CContentProvider._ID) );
String strTitle = c.getString( c.getColumnIndex(CContentProvider.TITLE) );
String strData = c.getString( c.getColumnIndex(CContentProvider.DATA) );
String strData2 = c.getString( c.getColumnIndex(CContentProvider.DATA2) );
Log.d( TAG, "id = " + strId + ", title = " + strTitle + ", data = " + strData + ", data2 = " + strData2 );
} while( c.moveToNext() );
}

// INSERT
ContentValues values = new ContentValues();
values.put( "title", "title1" );
values.put( "data", "data" );
values.put( "data2", "extra" );
Uri uri = Uri.parse( "content://com.android.myTest1/db_cptest" );
Uri resUri = getContentResolver().insert( uri, values );

// UPDATE #1
ContentValues values = new ContentValues();
values.put( "data", "data" );
Uri uri = Uri.parse( "content://com.android.myTest1/db_cptest/1" );
int resRowCount = getContentResolver().update( uri, values, null, null );
if( resRowCount > 0 )
Log.d( TAG, "Updated [TRUE]" );
else
Log.d( TAG, "Updated [FALSE]" );

// UPDATE #2
ContentValues values = new ContentValues();
values.put( "data", "data" );
Uri uri = Uri.parse( "content://com.android.myTest1/db_cptest" );
String[] strParam = { "title1" };
int resRowCount = getContentResolver().update( uri, values, "title=?", strParam );
if( resRowCount > 0 )
Log.d( TAG, "Updated [TRUE]" );
else
Log.d( TAG, "Updated [FALSE]" );
} // end of CContentProvider Example

// -----------------------------------------------------------



-----
Cheers,
June

[Linux][Memory] User/Kernel Space

--------------------------------------
Q: How does Linux partition logical address space as far as User/Kernel space is concerned, especially when it comes to deciding what gets mapped to virtual versus physical RAM? - Questions
--------------------------------------
Source: http://fixunix.com/questions/14616-how-does-linux-partition-logical-address-space-far-user-kernel-space-concerned-especially-when-comes-deciding-what-gets-mapped-virtual-versus-physical-ram.html

The norm for a memory allocation scheme is to use physical memory before
dumping the overflow to disk. However with Linux it's unique in that
there's a set limit for user and kernel space (aka monolithic kernel).
Which leads me to believe that the logical address space is set aside
ahead of time. Meaning that if a person has 2GBs of physical RAM and
chooses option 3GBs/1GBS of user/kernel space, that either 1GB of kernel
space and 1GB of user space will be allocated to physical RAM; OR, 2 GBs
of user space will go to physical RAM while the remaining 2 GBs (1 user,
the other kernel) will be virtual. This seems rather asinine, so I
hardly believe this is how it works.

It was also proposed to me that the system only considers how much it -
will- give to either user or kernel space. Meaning that at boot up, if a
system only uses 2 MBs of Kernel space, only 2 MBs gets mapped from the
the total available memory for Kernel space (as there's a cap). Also
meaning that those first 2 MBs would be allocated to physical memory.
Then as more would be requested more would be allocated for either user
or kernel space, straight from physical memory, till it ran out. This
sounds like a more solid schema, but at the same time it seems silly to
do things on a first come, first serve basis. It seems more reasonable
that it would partition each application such that each has some
physical memory to work in, and then to use a memory map for anything
additional to disk.

So the question is, how does Linux delegate it's memory with regards to
user/kernel space? Does Linux treat User/Kernel space just as a hard
limit, allocating memory as it's needed until it hits the cap for a
particular "type" of memory? Or does it preordain that kernel space will
be in physical memory while user space will get the remainder, whether
it be physical or not? Is there possibly another partitioning scheme,
similar to the one I suggested above?

I'm beginning to believe it's a simple tallying scheme, checking to see
how much kernel space or user space has been allocated.

ie/
3GB/1GB of User/Kernel space is available.
2 MBs gets allocated at boot-time for the kernel and it's modules -
(1.000GBs-0.002GBs=NewAvailableKernelSpace)
50 MBs gets allocated to X in user space - (3.000GBs-
0.050GBs=NewAvailableUserSpace)
So on and so forth.

I imagine that the logical address space is just a series of pointers
telling the system where everything is. For example, the first logical
address might point to physical memory for kernel space, while the
second logical address unit might point to user space in virtual memory
(similar to the example above). I imagine that's the whole value of
logical address space - it provides the HAL.

Any reference material or solid answers surrounding the mysteries of
Linux's memory allocation would be appreciated.

Thanks,
Dustin
--------------------------------------

--------------------------------------
Q: Virtual memory - user space kernel space
--------------------------------------
Source: http://fixunix.com/linux/7872-virtual-memory-user-space-kernel-space.html

Hi,
I m having some questions in Linux memory management.
I m considering about 32 bit machine only.
If you have a 512 MB of memory, how it is divided between kernel space
and user space?

What is the link between this division and 3GB userspace and 1 GB
kernel space division.
Is the 3G/1G division is for virtual memory?
Is the total Virtual memory can be 4G only? I mean is it the maximum?

Thanks in advance.

regards
SaranJothy

Re: Virtual memory - user space kernel space
SaranJothy wrote:
> Hi,
> I m having some questions in Linux memory management.
> I m considering about 32 bit machine only.
> If you have a 512 MB of memory, how it is divided between kernel space
> and user space?


A (relatively) small part is statically allocated to hold the kernel 
code and static data. The rest is dynamically allocated to whatever is 
required (user, drivers, kernel, ...)

> What is the link between this division and 3GB userspace and 1 GB
> kernel space division.


None.

> Is the 3G/1G division is for virtual memory?


Yes.

> Is the total Virtual memory can be 4G only? I mean is it the maximum?


In 32 bit Linux: yes, you cannot address more than 4GB of virtual 
addresses with 32 bit pointers.

-- 
Josef Möllers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize
-- T. Pratchett


Re: Virtual memory - user space kernel space
On Feb 8, 1:45 pm, "SaranJothy" wrote:
> Hi,
> I m having some questions in Linux memory management.
> I m considering about 32 bit machine only.
> If you have a 512 MB of memory, how it is divided between kernel space
> and user space?


you bumble virtual and physical memory. kernel divides _only_ virtual
memory between kernel space and user space,
physical memory are share to both. so, if for example, I want to
allocate n mb from user space, i can get some virtual address p
associated with physical page g.
and if i after it will try to allocate n mb from kernel space i can
get some virtual address i, associated with the same physical page g.
it's normal.

>
> What is the link between this division and 3GB userspace and 1 GB
> kernel space division.
> Is the 3G/1G division is for virtual memory?


yep

> Is the total Virtual memory can be 4G only? I mean is it the maximum?
>


nope. intel, for example, support PAE feature, that performs 64G
virtual space.

> Thanks in advance.
>
> regards
> SaranJothy



Re: Virtual memory - user space kernel space
Thanks for the reply.
As said,
> A (relatively) small part is statically allocated to hold the kernel
> code and static data. The rest is dynamically allocated to whatever is
> required (user, drivers, kernel, ...)

So, It depends upon the total size of kernel code and static data.
Right?

I read like 1G is allocated for kernel and 3G is allocated for
userspace in Virtual memory.
So part of RAM is mapped to 1G Kernel space address.
If part of RAM where kernel resides is smaller(as in most cases) than
1G, how it is mapped to 1G?

how 3G /1G break is maintained for secondary storage having just
2 G of memory?

I m having some problems in co-relating Physical memory and VM. pls.,
correct me.

Regards,
Saran


Re: Virtual memory - user space kernel space
Hi,
Thanks for the replies.
As said,
> A (relatively) small part is statically allocated to hold the kernel
> code and static data. The rest is dynamically allocated to whatever is
> required (user, drivers, kernel, ...)


So, It depends upon the total size of kernel code and static data.
Right?


1G/3G division in virutal memory is nothing but a set of pointers to
have VM management.
Set of pointers for Kernel. -1G
Set of pointers for User space - 3G
Kernel space pointers are special such that they have direct mapping
to Physical memory.
User space pointers has to go via MMU to get the location in physical
memory. Just correct me with the above understanding?


The process (User space) memory is swapped in and out to Secondary
storage to meet memory requirements of new process required to
execute.
What happens when we dont have enough Secondary storage.
say we have 2G RAM and 1.5G application is currently running.(I hope
this is possible) We have 1G of secondary storage only.
Now a 1.5G application wants to run.
(How the currently executing 1.5G application gets swapped out?

My intention of qn. is what happens when we dont have enough Secondary
memory.

Thanks for your replies,
Saran

Re: Virtual memory - user space kernel space
"just.asgard" wrote in
news:1170938227.135204.298340@p10g2000cwp.googlegr oups.com:

>> Is the total Virtual memory can be 4G only? I mean is it the maximum?
>>

>
> nope. intel, for example, support PAE feature, that performs 64G
> virtual space.


This is incorrect. PAE provides 64G of _physical_ address space. It
doesn't change the 4GB of virtual address space. You still only have 32-
bit registers.

GH


Re: Virtual memory - user space kernel space
SaranJothy wrote:
> Thanks for the reply.
> As said,

>>A (relatively) small part is statically allocated to hold the kernel
>>code and static data. The rest is dynamically allocated to whatever is
>>required (user, drivers, kernel, ...)

>
> So, It depends upon the total size of kernel code and static data.
> Right?


Yes.

In the old days, all physical memory was mapped 1:1 to virtual addresses 
0xc0000000 upwards, so the kernel could access everything directly. If 
you had more than 1GB of physical memory, you could recompile the kernel 
to start at 0x80000000 or even (correct me if I'm wrong) 0x40000000, to 
accomodate up to 2 or 3 GB of physical memory.
Later, Hugemem and friends were introduced and you could have more than 
1GB of physical memory.

> I read like 1G is allocated for kernel and 3G is allocated for
> userspace in Virtual memory.
> So part of RAM is mapped to 1G Kernel space address.


Yes, the part which holds the kernel code and static data is mapped to 
the 1G kernel address space. Dynamically allocated kernel memory is also 
mapped to the space. Other pages (user pages, buffers, ...) can be 
mapped on demand.

> If part of RAM where kernel resides is smaller(as in most cases) than
> 1G, how it is mapped to 1G?


In general, there is no distinction between less than 1GB and more than 
1GB of physical memory.

> how 3G /1G break is maintained for secondary storage having just
> 2 G of memory?


??? "secondary storage" ???
You mean swap space? Linux uses swap space in addition to physical 
memory, so having 1GB of physical memory and 2GB of swap space would 
allow you to use 3GB of virtual memory, distributed amongst the kernel 
(a relatively small portion, locked to physical memory) and user processes.

> I m having some problems in co-relating Physical memory and VM. pls.,
> correct me.


Try to find a decent book on virtual memory.

An attempt of a very short explanation:
virtual memory is subdivided into "page frames", in ia32 these are 4KB.
Likewise, physical memory is subdivided into "pages", again 4KB in size.
There is a piece of hardware, the Memory Management Unit (MMU) which 
takes a virtual address coming out of the CPU and replaces this by a 
physical address, in the simplest case by a table-lookup: The upper 20 
bits (the page frame number) of a 32-bit virtual address selects one of 
the 1048576 slots in the table. This slot contains a bit "valid" and the 
upper 20 bits (the page number) of the physical address. If the "valid" 
bit is 0, then this virtual address is invalid and the access is aborted 
(SIGSEGV). If the "valid" bit is 1, the 20 bits "page frame number" is 
replaced by the 20 bits "page number",keeping the lower 12 bits of the 
(virtual) address. That 32 bit value is then used as the physical address.
When switching between processes, the kernel has to replace the low 
786432 entries in this table by the low 786432 entries of the new 
process' table. Also, you need two tables: one for kernel and one for 
the currently active user process, the kernel's low 786432 entries are 
identical to the user process' low 786432 entries. The upper 262144 of a 
user process' table _always_ have the "valid" bit cleared.

Does this help?

Josef
-- 
Josef Möllers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize
-- T. Pratchett

Re: Virtual memory - user space kernel space
SaranJothy wrote:

> Thanks for the reply.
> As said,
>> A (relatively) small part is statically allocated to hold the kernel
>> code and static data. The rest is dynamically allocated to whatever is
>> required (user, drivers, kernel, ...)

> So, It depends upon the total size of kernel code and static data.
> Right?
>
> I read like 1G is allocated for kernel and 3G is allocated for
> userspace in Virtual memory.
> So part of RAM is mapped to 1G Kernel space address.


If you have less than 1G of physical RAM, *all* physical RAM
is mapped into the top 1G kernel space.

The key is to understand that you can have more than one
virtual mapping for a physical RAM page. So, when userspace
requires a memory page, one of the already mapped (but unused)
pages in kernel space gets mapped into userspace as well.

> If part of RAM where kernel resides is smaller(as in most cases) than
> 1G, how it is mapped to 1G?


The kernel is typically loaded at the beginning of the physical RAM.
This, like all other RAM is then mapped to start at the 3GB boundary.

There is one exception - If you have 1GB or more of physical RAM,
the RAM which cannot be mapped into the top 1GB, gets managed as
high memory and only mapped on request.

>
> how 3G /1G break is maintained for secondary storage having just
> 2 G of memory?


It's unrelated. Of course, if you want to memory map a file, you
have to stay below the free virtual space.

Regards,

Iwo

Re: Virtual memory - user space kernel space
On Thu, 08 Feb 2007 14:06:26 +0000 Iwo Mergler wrote:

| The key is to understand that you can have more than one
| virtual mapping for a physical RAM page. So, when userspace
| requires a memory page, one of the already mapped (but unused)
| pages in kernel space gets mapped into userspace as well.

That's a feature used by VRB to make a ring buffer (provided the size
is an exact multiple of page size) that automatically wraps around
by having a mirror image mapping of the entire buffer immediately
following the first mapping in VM. That allows direct access via
tools that don't understand the ring buffer wraparound (e.g. strXXX
functions in stdlib or others) while avoiding any copy activities
to maintain both the data and empty space as contiguous areas.

See: http://vrb.slashusr.org/

--------------------------------------

-----
Cheers,
June