728x90

출처 : http://www.supermind.org/blog/613/dom4j-xpath-tagsoup-namespaces-sweet
http://tomasblue.tistory.com/entry/Dom4j-XPath%EB%A5%BC-%EC%9D%B4%EC%9A%A9%ED%95%9C-%EC%BF%BC%EB%A6%AC-%EB%AC%B8%EC%A0%9C%EC%A0%90-%ED%95%B4%EA%B2%B0-Namespace%EA%B4%80%EB%A0%A8

//
XPath xpath = XPathFactory.newInstance().newXPath(); 

//
BufferedReader bis = new BufferedReader (new InputStreamReader ("index.html"), "UTF-8")); 

//
XMLReader tagsoup = new org.ccil.cowan.tagsoup.Parser(); 
SAXReader reader = new SAXReader(tagsoup);
Document doc = reader.read(bis); 
 
// 네임스페이스 제거 XPath를 이용하려면 네임스페이스를 제거해야 함
XMLUtils.fixNamespaces(doc);
//XMLUtils.generateXmlFile(doc, "index.xml");

//<li class="bar">하나
DefaultText han_mean_Node = (DefaultText)ajax_pron_dlNode.selectSingleNode("//li[@class='bar']/text()[1]");

//<span class="count"> 
//  <b>2</b>개
//</span>  
DefaultElement hanziCountNode = (DefaultElement)doc.selectSingleNode("//span[@class=\"count\"]/b");

//<div id="content"> 
//  <div id="detail">
//    <ul id="data1">1</ul>
//    <ul id="data2">2</ul>
List contentList = doc.selectNodes("//div[@id='content']/div[@id='detail']/node()");
XMLUtils.java
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.List;

import org.dom4j.Attribute;
import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.Namespace;
import org.dom4j.Node;
import org.dom4j.QName;
import org.dom4j.io.OutputFormat;
import org.dom4j.io.XMLWriter;

public class XMLUtils {
	/**
	 * @param doc DOM4J XML Document
	 * Generate XML File
	 */
	public static void generateXmlFile(Document doc, String xmlfile) {
		XMLWriter writer = null;
		try {
			OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream(new File(xmlfile)), "UTF-8");
			OutputFormat format = OutputFormat.createPrettyPrint();
			format.setEncoding("UTF-8");
			writer = new XMLWriter(osw,format);
			
			writer.write(doc);
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			if(writer != null) {
				try {
					writer.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
	
	} 
	
	/**
	 * @param doc DOM4J XML Document
	 * Generate XML File
	 */
	private static void generateXmlFile(Element doc, String xmlfile) {
		XMLWriter writer = null;
		try {
			OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream(new File(xmlfile)), "UTF-8");
			OutputFormat format = OutputFormat.createPrettyPrint();
			format.setEncoding("UTF-8");
			writer = new XMLWriter(osw,format);
			
			writer.write(doc);
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			if(writer != null) {
				try {
					writer.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
	}  			

	/**
	 * 네임스페이스 제거 XPath를 이용하려면 네임스페이스를 제거해야 함
	 */
	public static void fixNamespaces(Document doc) {
		Element root = doc.getRootElement();
		if (root.getNamespace() != Namespace.NO_NAMESPACE)
			removeNamespaces(root.content());
	}

	/**
	 * 네임스페이스 원복
	 */
	public static void unfixNamespaces(Document doc, Namespace original) {
		Element root = doc.getRootElement();
		if (original != null)
			setNamespaces(root.content(), original);
	}

	/**
	 * 목록내 모든 element의 네임스페이스 제거
	 */
	@SuppressWarnings("unchecked")
	private static void removeNamespaces(List l) {
		setNamespaces(l, Namespace.NO_NAMESPACE);
	}

	/**
	 * Element의 네임스페이스 설정(child포함)
	 */
	private static void setNamespaces(Element elem, Namespace ns) {
		setNamespace(elem, ns);
		setNamespaces(elem.content(), ns);
	}

	/**
	 * 목록내 node(child포함)의 네임스페이스 설정
	 */
	@SuppressWarnings("unchecked")
	private static void setNamespaces(List l, Namespace ns) {
		Node n = null;
		for (int i = 0; i < l.size(); i++) {
			n = (Node) l.get(i);
			if (n.getNodeType() == Node.ATTRIBUTE_NODE)
				((Attribute) n).setNamespace(ns);
			if (n.getNodeType() == Node.ELEMENT_NODE)
				setNamespaces((Element) n, ns);
		}
	}

	/**
	 * Elemnet의 네임스페이스 설정
	 */
	private static void setNamespace(Element elem, Namespace ns) {
		elem.setQName(QName.get(elem.getName(), ns, elem.getQualifiedName()));
	}
}
728x90
728x90
Android 에서 일본어 출력을 위해서 두가지 앱이 설치되어 합니다.

1. Classis Text To Speech - 무료
2. SVOX 일어 언어팩 - 2.99$

설치방법

1. 마켓에서 svox로 검색합니다.

2. 검색된 목록에서 Classis Text To Speech를 선택해서 설치합니다.


3. 다시 1번에서 검색목록에서 SVOX Japanese/日本을 선택해서 설치하십니다.


위에 2개의 앱을 설치 하셨다면 이제 환경 설정에서 TTS 엔진을 변경 하셔야 합니다.

환경설정

1. 환경설정에 들어 가셔서 음성 입력 & 출력을 선택합니다.


3. TTS(text-to-speech) 설정을 선택합니다.


4. SVOX Classic TTS의 체크 박스를 선택합니다.



5. 기본 엔진를 선택합니다.


6. 기본 엔진 목록에서 SVOX Classic TTS을 선택하시면 됩니다.



 

 

728x90
728x90
출처 : http://sotddi.tistory.com/tag/%EC%95%88%EB%93%9C%EB%A1%9C%EC%9D%B4%EB%93%9C%20opencv
http://triumphlsh.springnote.com/pages/6620993

1. cygwin 설치

Devel 확장 시킨후 gcc-core, gcc++, make, swig 를 선택하여 설치 한다.





2. Android NDK 설치

다운로드 : http://www.crystax.net/android/ndk-r4.php#download

C:\cygwin\home\[로그인계정] 폴더에
NDK파일(android-ndk-r4-windows-crystax-4.zip)을 다운받아서 압축을 푼다.


3. svn 클라이언트을 이용해서 opencv 파일을 내려받는다.

svn checkout http://android-opencv.googlecode.com/svn/trunk/


4. 빌드 환경 설정

C:\cygwin\home\[로그인계정]\.bashrc 파일 편집

export PATH=$PATH:/home/[로그인계정]/android-ndk-r4-crystax
export ANDROID_NDK_ROOT=/home/[로그인계정]/android-ndk-r4-crystax

 


5. opencv 컴파일




728x90
728x90
출처 : http://www.delphitricks.com/source-code/systeminfo/get_windows_system_temporary_directory.html

{ Getting the Temporary Directory } 

function GetTempDir: string; 
var 
  Buffer: array[0..MAX_PATH] of Char; 
begin 
  GetTempPath(SizeOf(Buffer) - 1, Buffer); 
  Result := StrPas(Buffer); 
end; 

function GetTempPath: string; 
var 
  TmpDir: PChar; 
begin 
  TmpDir := StrAlloc(MAX_PATH); 
  GetTempPath(TmpDir, MAX_PATH); 
  Result := string(TmpDir); 
  if Result[Length(Result)] <> '\' then 
    Result := Result + '\'; 
  StrDispose(TmpDir); 
end; 

function GetTempPath(var S: String): Boolean; 
var 
  Len: Integer; 
begin 
  Len := Windows.GetTempPath(0, nil); 
  if Len > 0 then 
  begin 
    SetLength(S, Len); 
    Len := Windows.GetTempPath(Len, PChar(S)); 
    SetLength(S, Len); 
    Result := Len > 0; 
  end else 
    Result := False; 
end; 
728x90
728x90
ListView 제어를 MVC 모델처럼 BaseAdapter 의 getCount, getView, getItem을 구현하여
List를 보여주는 예제입니다.

ListViewTest.java

ListView를 listview 로 생성하여
BaseAdapter 상속 받아서 구현한 ArrayAdapterExample 객체를
listview.setAdapter()호출하여 listview의 adapter로 설정합니다.
package com.shryu.test;

import android.app.Activity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

public class ListViewTest extends Activity implements OnClickListener {
	
  private TextView text; 

  private ArrayAdapterExample adapter;
	
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    //setContentView(R.layout.main);
    
    LayoutInflater inflate = LayoutInflater.from(this);
    LinearLayout layout = (LinearLayout)inflate.inflate(R.layout.main, null);
    this.setContentView(layout); 
    
    text = (TextView)findViewById(R.id.TextView02); 
    
    ListView listview = new ListView(this);
    listview.setLayoutParams(new LinearLayout.LayoutParams(
    		LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.FILL_PARENT)); 
    layout.addView(listview);
    
    adapter = new ArrayAdapterExample(this, R.layout.list_item_1);
    listview.setAdapter(adapter);
  }

  @Override
  public void onClick(View v) {
    Button btn = (Button)v;
    text.setText(btn.getText());
  }
}
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<TextView
    android:id="@+id/TextView02"  
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/hello"
    />
</LinearLayout>
ArrayAdapterExample.java
package com.shryu.test;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.Filter;
import android.widget.Filterable;
import android.widget.TextView;

public class ArrayAdapterExample extends BaseAdapter implements Filterable {

	private Context mContext; 
	private int mFieldId = 0;

	public ArrayAdapterExample(Context context, int textViewResourceId) {
		super();
		mContext = context;
		mFieldId = textViewResourceId;
	}

	@Override
	public int getCount() {
		return 100;
	}

	@Override
	public Object getItem(int position) {
		String result = new String(position+"");
		return result;
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View v = convertView; 
		if (v == null) { 
			LayoutInflater vi = LayoutInflater.from(mContext); 
			v = vi.inflate(R.layout.list_item_1, null);
		}
			
		String value = (String)this.getItem(position); 
		if (value != null) { 
			TextView tt = (TextView) v.findViewById(R.id.TextView01);  
			tt.setText("position = " + value);                        
			Button btn = (Button) v.findViewById(R.id.Button01);  
			btn.setText(value + " 선택"); 
			btn.setOnClickListener((OnClickListener)mContext);    
		}
		return v; 
	}

	@Override
	public Filter getFilter() {
		return null;
	}
}
list_item_1.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
	xmlns:android="http://schemas.android.com/apk/res/android"
	android:layout_width="fill_parent"
	android:layout_height="fill_parent">
<TextView android:text="@+id/TextView01" 
	android:id="@+id/TextView01"
	android:layout_width="wrap_content" 
	android:layout_height="wrap_content"/>
<Button android:text="@+id/Button01" 
	android:id="@+id/Button01"
	android:layout_width="wrap_content" 
	android:layout_height="30px"/>
</LinearLayout>
-end-
728x90
728x90

출처 : http://tigerwoods.tistory.com/12
http://vulpecula.tistory.com/3
http://nashorn.tistory.com/74
http://blog.vizpei.kr/94697746
http://www.jopenbusiness.com/tc/oss/entry/Android-ScrollView%EB%A1%9C-%ED%99%94%EB%A9%B4-%EC%8A%A4%ED%81%AC%EB%A1%A4-%EC%B2%98%EB%A6%AC
http://songdroid.blogspot.com/2009/12/linearlayout.html



main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<TextView  
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/hello"
    />
</LinearLayout>
ScrollViewTest.java

package com.shryu.test;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TextView;

public class ScrollViewTest extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //setContentView(R.layout.main);
        LayoutInflater inflate = LayoutInflater.from(this);
        LinearLayout layout = (LinearLayout)inflate.inflate(R.layout.main, null);
        this.setContentView(layout);
        
        //
        ScrollView sv = new ScrollView(this);
        sv.setLayoutParams(new RelativeLayout.LayoutParams(
             LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
        layout.addView(sv);
        
        LinearLayout subLayout = new LinearLayout(this);
        subLayout.setLayoutParams(new LinearLayout.LayoutParams(
        		LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT, 1.0f));
        subLayout.setOrientation(LinearLayout.VERTICAL);
        subLayout.setPadding(0, 0, 5, 0);
        sv.addView(subLayout);
        
        for (int i=0; i<20; i++) {
          TextView aa = new TextView(this);
          aa.setBackgroundColor(Color.BLUE);
          aa.setText("blue - " + i);
          subLayout.addView(aa);
         
          TextView aa2 = new TextView(this);
          aa2.setBackgroundColor(Color.BLACK);
          aa2.setText("black - " + i);
          subLayout.addView(aa2);
        }
    }
}

 
728x90
728x90

@header {
package xxx;
}

@members {
private AppBase appBase;

public void SetAppBase(AppBase appBase) {
  this.appBase = appBase;
}
}

@lexer::header {
package xxx;
}

packageDeclaration 
    :   'package' qualifiedName {
         System.out.println("--" + $qualifiedName.result.getLine() + "/" + $qualifiedName.result.getQualifiedName());
      }
        ';'
    ;

qualifiedName returns [AstQualifiedName result]
scope {
  AstQualifiedName current;
}
@init {
  $qualifiedName::current = new AstQualifiedName();
}

    :   IDENTIFIER {
          $qualifiedName::current.setLine($IDENTIFIER.getLine());
          $qualifiedName::current.addIdentifier($IDENTIFIER.getText());
      }
        ('.' IDENTIFIER {
          $qualifiedName::current.addIdentifier($IDENTIFIER.getText());
        }
        )* {
          $result = $qualifiedName::current;
        }
    ;

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

package xxx;

import xxx.AppBase;

import org.antlr.runtime.ANTLRFileStream;
import org.antlr.runtime.CommonTokenStream;
import org.antlr.runtime.RecognitionException;
import org.antlr.runtime.RuleReturnScope;
import org.antlr.runtime.Token;
import org.antlr.runtime.TokenStream;
import org.antlr.runtime.tree.CommonErrorNode;
import org.antlr.runtime.tree.CommonTreeAdaptor;
import org.antlr.runtime.tree.TreeAdaptor;

public class JavaTestMain {
 
 public static void main(String[] args) throws Exception {
  
  AppBase appBase = new AppBase();
  
  ANTLRFileStream fileStream = new ANTLRFileStream("ASTMain.java");
  JavaLexer lexer = new JavaLexer(fileStream);
  CommonTokenStream tokens = new CommonTokenStream(lexer);
  JavaParser parser = new JavaParser(tokens);
  parser.SetAppBase(appBase);
  parser.compilationUnit();
  }
}


728x90
728x90
- CustomDataSource 사용시 동적인 Count 사용
OptionsData.SmartLoad := True;

- 트리노드의 초기 + 표시
OptionsData.CheckHasChildren := false;
728x90

+ Recent posts