노무현 대통령 배너

Double-J's World

blog logo image

Double-J's World » Search » Results » Articles

Programming와 관련된 글 4개

  1. 2009.11.19 [Tips] Visual Studio 2008 Prof.(Kor) 설치시 DefFactory.dat 문제 2 / Double-J
  2. 2009.11.05 To create a status bar notification / Double-J
  3. 2009.10.31 Example ProgressDialog with a second thread / Double-J
  4. 2009.09.10 JNI 활용한 "Hello World" / Double-J

Double-J's World » Com...Tips!

[Tips] Visual Studio 2008 Prof.(Kor) 설치시 DefFactory.dat 문제

Double-J | 2009. 11. 19. 13:29

현재 제가 쓰고 있는 운영체제는 Windows7  입니다.

그런데 Visual Studio 2008 Professional Edition - KOR 을 설치하는데

(ko_visual_studio_2008_professional_x86_x64wow_dvd_X14-26331.iso)

다음과 같은 폴더에 DefFactory.dat 파일이 없다고 나오더군요.

c:\Users\DoubleJ\AppData\Local\Temp\SIT23032.tmp\

구글링 결과 해당 파일의 내용이 깨져서 인식이 안되는 문제 같았는데

저와 같은 문제를 가졌던 분들이 해당파일(DefFactory.dat)의  본래내용을 정상적으로 적는 방법으로

해결을 하였습니다. 다만 저와 다른점은 Professional Edition -KOR 이 아닌 거의 영문판이어서

그분들이 올려놓은 내용을 해당파일에 복사하는 방법이 잘 안되더라구요.

그래서 혹시나 해서 VS2008 Team Suite - KOR 안의 DefFactory.dat 파일의 내용을

Professional 버전에 맞게 수정해서 파일을 덮어쓰니 잘되었습니다.

저와같은 VS 2008 Professional Edition (kor)  에서 위와 같은 문제가 발생한다면 다음 내용을

해당 파일(DefFactory.dat)을 열어서 다음과 같이 적어주고 다시 시도해주세요.

DefFactory.dat 내용


아니면 첨부 파일로 올려드리는 파일을 아얘 덮어싀우셔도 됩니다.




(go to top)

Double-J's World » Programming/Android

To create a status bar notification

Double-J | 2009. 11. 5. 11:02

1. Get a reference to the NotificationManager:
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);


2. Instantiate the Notification:
int icon = R.drawable.notification_icon;
CharSequence tickerText = "Hello";
long when = System.currentTimeMillis();

Notification notification = new Notification(icon, tickerText, when);


3. Define the Notification's expanded message and Intent:
Context context = getApplicationContext();
CharSequence contentTitle = "My notification";
CharSequence contentText = "Hello World!";
Intent notificationIntent = new Intent(this, MyClass.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);

notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);


4. Pass the Notification to the NotificationManager:
private static final int HELLO_ID = 1;

mNotificationManager.notify(HELLO_ID, notification);
User 는 이제 Notification 을 통보 받는다.

출처 : http://developer.android.com/guide/topics/ui/notifiers/notifications.html


(go to top)

Double-J's World » Programming/Android

Example ProgressDialog with a second thread

Double-J | 2009. 10. 31. 11:19

진행 상태를 추적하기 위해 두 번재 thread 를 사용한다.

그 thread 는 진행이 이루어질 때마다 핸들러를 통해서 main activity  에게 message 를 보낸다.

메시지를 받은 activity 는 Progress Dialog 를 update 한다.



package com.example.progressdialog;

import android.app.Activity;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class NotificationTest extends Activity {
    static final int PROGRESS_DIALOG = 0;
    Button button;
    ProgressThread progressThread;
    ProgressDialog progressDialog;
   
    /** Called when the activity is first created. */
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        // Setup the button that starts the progress dialog
        button = (Button) findViewById(R.id.progressDialog);
        button.setOnClickListener(new OnClickListener(){
            public void onClick(View v) {
                showDialog(PROGRESS_DIALOG);
            }
        }); 
    }
   
    protected Dialog onCreateDialog(int id) {
        switch(id) {
        case PROGRESS_DIALOG:
            progressDialog = new ProgressDialog(NotificationTest.this);
            progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
            progressDialog.setMessage("Loading...");
            progressThread = new ProgressThread(handler);
            progressThread.start();
            return progressDialog;
        default:
            return null;
        }
    }

    // Define the Handler that receives messages from the thread and update the progress
    final Handler handler = new Handler() {
        public void handleMessage(Message msg) {
            int total = msg.getData().getInt("total");
            progressDialog.setProgress(total);
            if (total >= 100){
                dismissDialog(PROGRESS_DIALOG);
                progressThread.setState(ProgressThread.STATE_DONE);
            }
        }
    };

    /** Nested class that performs progress calculations (counting) */
    private class ProgressThread extends Thread {
        Handler mHandler;
        final static int STATE_DONE = 0;
        final static int STATE_RUNNING = 1;
        int mState;
        int total;
       
        ProgressThread(Handler h) {
            mHandler = h;
        }
       
        public void run() {
            mState = STATE_RUNNING;   
            total = 0;
            while (mState == STATE_RUNNING) {
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    Log.e("ERROR", "Thread Interrupted");
                }
                Message msg = mHandler.obtainMessage();
                Bundle b = new Bundle();
                b.putInt("total", total);
                msg.setData(b);
                mHandler.sendMessage(msg);
                total++;
            }
        }
        
        /* sets the current state for the thread,
         * used to stop the thread */
        public void setState(int state) {
            mState = state;
        }
    }
}
출처 : http://developer.android.com/guide/topics/ui/dialogs.html


(go to top)

Double-J's World » Programming/JAVA

JNI 활용한 "Hello World"

Double-J | 2009. 9. 10. 15:59

A1.jpg

 

Main Code 작성

 

패키지명   : jnitest
파일명      : JNITest

 

JNITest.java

package jnitest;

public class JNITest {

      static{
        System.loadLibrary("NativeHello");
    }

    public static void main(String[] args) {
        NativeHello obj = new NativeHello();
        obj.sayHello();  
    }

}

 

호출할 함수 원형 작성

패키지명 : jnitest
파일명    : NativeHello

NativeHello.java


package jnitest;

public class NativeHello {

     public native void sayHello();

}

 

위의 두 소스가 작성되었다면 메뉴에서 Run -> Build (혹은 Clean & Build) 실행.

제대로 빌드가 되었다면 "build/classes" 란 폴더 아래 패키지명과 동일한 폴더와 *.class 파일이 생성됨을 볼 수 있다. (아래의 캡쳐화면 참고)

a2_newnew.JPG

 

 

javah 로 c/c++ 형태의 헤더파일 생성하기

콘솔창에서 해당 프로젝트의 classes 폴더까지 이동 한후

javah  -jni  packagename.classname

위와 같은 명령어를 실행한다. 실행하면 *.h 파일이 생성된다. (아래 화면 참고)

 

a3_new.jpg

 

DLL 파일 생성

Visual Studio 을 통해 MFC DLL 프로젝트를 생성 후 "Solution Explorer" 에서 프로젝트명을 마우스 우클릭하여 (VS2008 기준)

Properties 에서 다음과같이 %JAVA_HOME%\include 와 %JAVA_HOME%\include\include\win32 폴더를 추가한다.

A4_NEW.jpg

 

include directory 작업을 완료한 후 좀전 작업에서 생성되었던 헤더파일의 내용을 생성된 프로젝트의 헤더파일에COPY-PASTE 를 한다. (파일 자체를 복사해도 큰 문제는 없는듯..) 기존의 내용은 가급적 주석처리.

프로젝트내의 헤더파일명과 동일한 *.cpp 파일에서 기본으로 생성된 필요 없는 내용은 주석처리를 한 후 헤더파일에 작성되어있는 함수를 실제로 구현해준다. (다음 그림참고)

a5.jpg

 

작성후 빌드 하면 *.dll 파일이 생성된다. 이 파일을 JAVA프로젝트에 복사한다. (다음 화면 참고)

a6_newnew.JPG

 

이제 Run 을 하면 실제 동작화면을 볼 수 있다.

 

 

이 글은 스프링노트에서 작성되었습니다.



(go to top)