2015년 7월 15일 수요일

Android LinearLayout(리니어레이아웃) vs RelativeLayout(릴레이티브레이아웃) 활용

 안드로이드 어플리케이션 레이아웃을 짜다가 문득 LinearLayout 과 RelativeLayout 중 무엇을 써야 하는 지에 대한 의문이 생겼다. 이때까지는 무의식적으로 처음에 익혔던 LinearLayout을 써왔다. 이번 기회에 둘의 활용을 정리하고 앞으로는 더욱 적합하게 활용할 수 있도록 하여야 겠다.
우선 각 레이아웃의 정의는 다음과 같다.

1)FrameLayout — The Frame Layout pins each child view within its frame. The default position is the top-left corner, though you can use the gravity attribute to alter its location.
Adding multiple children stacks each new child on top of the one before, ie with each new View potentially hiding the previous ones.
2)LinearLayout — A Linear Layout aligns each child View in either a vertical or a horizontal line. A vertical layout has a column of Views, whereas a horizontal layout has a row of Views. The Linear Layout supports a weight attribute for each child View that can control the relative size of each child View within the available space.
3)RelativeLayout — The Relative Layout lets you define the positions of each child View relative to the others and to the screen boundaries.
4)GridLayout — Introduced in Android 4.0 (API level 14), the Grid Layout uses a rectangular grids to layout Views in a series of rows and columns.

쉽게 생각하여 LinearLayout 으로 작성하는 것이 간편하다. 하지만 각 차일드 뷰들을 리니어하게 배치하는 것이 아니라, 겹치거나 상호적인 규칙을 가지고 배치를 하고자 하는 경우에 RelativeLayout 이나 FrameLayout을 활용해야 한다.  
 자세한 활용 예는 아래 블로그를 참고 하도록 하자.
http://android-developers.blogspot.kr/2009/02/android-layout-tricks-1.html
이 블로그의 설명을 보면, 똑같은 리스트뷰의 아이템 하나를 구성한다고 하더라도 RelativeLayout 을 활용하면 낭비를 막을 수 있다고 한다. 화면 구성시 뷰들의 위계 관계에 의해 LinearLayout은 단계를 하나 더 가지게 된다. 각 리스트뷰 아이템들이 생성될때 하나의 단계를 거치는 것이 리스트뷰 안에서의 경우에는 상당한 비효율을 초래할 수 있다. 

http://lsit81.tistory.com/92

2015년 7월 13일 월요일

LG QRemote SDK 활용

- LG QRemote SDK
LG QRemote SDK는 스마트폰을 TV,  DVD, 에어컨 등을 적외선 컨트롤 하는 장치로 작동할 수 있도록 한다.
LG QRemote SDK 는 Library(Open APIs which provide functions of LG QRemote), Documentation(API reference documentation), Samples(Sample application and source codes written using the LG QRemote SDK)

Functions and working principle of the SDK
The LG QRemote SDK supports the following functions:
 ·    Configuring devices through LG QRemote
 ·    Getting the device list configured by LG QRemote
 ·    Getting the brand, name, model, and category of configured devices
 ·    Getting functions supported by configured devices
 ·    Sending IR signals for processing the functions
 ·    Sending raw IR data (Android 4.4.2 or higher)
 ·    Learning IR data (Android 4.4.2 or higher)
 ·    Creating new devices with learned IR data (Android 4.4.2 or higher)
 ·    Sharing learned IR data (Android 5.0 or higher)

The following figure shows how the application using the LG QRemote SDK works.











The 3rd party application in the figure is the application created by developers. It communicates with the following modules:
·     LG QRemote library: The library includes the LG QRemote APIs.
·     LG QRemote: LG QRemote installed in the target device.
·     IR Services: The background services. These services are in charge of setting up IR-controlled devices and controlling the IR Blaster of the device.
·     IR Blaster: The device driver that emulates an IR remote control.  

출처: LG Developer center(http://developer.lge.com/resource/mobile/RetrieveOverview.dev?categoryTypeCode=ANRS)








2015년 7월 10일 금요일

Critical thinking mid-term

 Argument
  -  Logic 
  - Argument 
    - A group of statement
    - Composed of premises and conclusion
    - The premises are supposed to support the conclusion
  - Deductive argument and inductive argument
    - The premises of deductive argument are intended to provide complete and unfailing support for the conclusion
    - Whereas the premises of inductive arguments are only meant to provide probable evidence that the conclusion is true.
    - Example 
      Ex1) Every raven that has been observed so far was black. So, all ravens are black.
      > Inductive
      Ex2) All men are mortal and Socrates is a man. Hence, Socrates is mortal.
      > Deductive
      Ex3) Jon W. has been clutching his head, and he just took some aspirin. He must have a headache.
      > Deductive? Inductive?
        - Reason for inductive : the premises don't actually guarantee the conclusion.
        - Reason for deductive : the premises are being put forward ad if they guarantee the conclusion

 Validity
  - Validity : the criterion used to evaluate the inferential claim of deductive arguments
    - Valid Argument : a deductive argument in which it is impossible for the premises to be true and the conclusion false. 
    - Invalid Argument : a deductive argument in which it is possible for the premises to be true and the conclusion false.

 Soundness 
  - Evaluation of the factual claim of an argument is also important.
    - A sound argument is valid and has all true premises. 
    - An unsound argument is either invalid, or has at least one false premise.

 Strength
  - An inductive argument is strong when the conclusion is probably true, given the truth of the premises.
  - If the conclusion is not likely to be true (or probably false) despite the truth of the premises, then it is weak.

 Cogency 
  - An inductive argument is cogent when it is strong and has actually true premises.
  - An inductive argument that is weak or has false premises is uncogent.

 *Exercises 
  - All sound argument are valid. -> True
  - All unsound argument are invalid. -> False
  - No cogent is a weak argument. -> True
  - Every uncogent argument has at least one false premise. -> False
  - All sound arguments have true premises and true conclusion. ->True.

 Forms of an Argument
  - Form and Contents
    - We can't always determine whether a given argument is valid or not merely from the truth values of the premises. This is because, validity is essentially a matter of form and not content.
    - Form: Underlying logical structure of an argument
    - Content: (roughly) what the argument is about
    - Examples
     Ex1) Either Jones or Smith is a murderer. Smith is a murderer. Therefore, Jones is not a murderer.
     - Content : What is this argument about?
     - Form : Either A or B.
                              B.
                    Therefore, not-A.
  - Valid Forms
    - Valid form: the truth of the premises guarantees the truth of the conclusion.
    - If a deductive argument has a valid form, then it is valid, regardless of its content.
  - Invalid Forms
    - If a deductive argument does not have a valid form, then it has an invalid form.
    - If a deductive argument has invalid form, then it is invalid, regardless of its content
  - Substitution Instances
    - Substitution instances: the result of the procedure where you uniformly replace the variable letters with specific statements in a given argument form

 How to Construct Counterexamples
  - Any invalid argument has an invalid argument form underlying it. To show an argument is invalid, we isolate its form and give it new content, such that the premises are obviously true, and the conclusion is clearly false. This is called the counterexample method.

 Counterexample Exercises
  - Counterexample Method
    - Procedure:
      1. Identify the form of the argument.
      2. Replace the substitution letters with well-known truths as the premises and a well-known falsity as the conclusion.

 Diagramming Argument
  - Diagramming Arguments
    - A. Since we often encounter sufficiently complex arguement, it is useful to be able to pictorially represent an argument.
    - B. Procedure ;
      - i. Assign a number to each statement.
      - ii. Identify the premises and the conclusion.
        a. General tip
          1) Start from the conclusion.
          2) Use indicators, if applicable.
      - iii. Clarify the patterns of inferential support.
        a. Specify missing premise(s), if necessary.
        b. Eliminate fillers.
  - Diagramming Various Argument Patterns
    - A. Vertical Pattern
      - i. Sometimes we are led to a conclusion by a single premise which itself can be the conclusion of another argument.
    - B. Horizontal Pattern
      - i. Sometimes many premises can each provide independent support for a given conclusion.
    - C. Conjoint premises
      - i. Sometimes a conclusion is supported by more than one premise neither of which provides independent support for it.
    - D. Sub-Arguments
    - E. Filer-Statements
      - i. Some statements play no actual role in the argument structure. Such a statement is simply filler material.
      - ii. Filler statements are numbered, but will not appear in the diagram.
    - F. Missing Premises
      - i. Some arguments contain missing premises.

 Fallacies
  - What's A Fallacy?
    - A. Fallacies are errors in reasoning.
    - B. Some fallacies are common and can be psychologically persuasive.
    - C. Two categories:
      i. Formal fallacies
      ii. Informal fallacies
  Fallacies Involving Irrelevant Premises
    - Fallacies Involving Irrelevant Premises
      - A. Argument against the person (ad hominem)
      - B. Circumstantial Ad Hominem
      - C. Ad Hominem Tu Quoque
      - D. Straw Man
      - E. Appeal to the Force
      - F. Appeal to the People
      - G. Appeal to Pity
      - H. Appeal to Ignorance

 Fallacies Involving Ambiguity
  - Equivocation
    - i. Premises : contain an ambiguous word
    - ii. Conclusion : is reached by trading on the ambiguity
  - Amphiboly
    - i. Premises : contain a sentence with an ambiguous structure
    - ii. Conclusion : is reached by trading on the ambiguity
  - Composition
    - i. Premises : the parts (or members) have attribute X
    - ii. Conclusion : the whole (or group) has attribute X
  - Division
    - i. Premises : the whole (or group) has attribute X
    - ii. Conclusion : the parts (or members) have attribute X
 









2015년 7월 7일 화요일

Java study _day5 (교재: java200제)

JavaStudy day5
주제
041 1부터 100까지 합 구하기
 메서드를 선언하고 호출하는 방법을 확인한다.
- ScannerInput.java
import java.util.Scanner;
public class ScannerInput {
final static String help1 = 
“Please Input int type One number:”;
public static int readInt(){
System.out.print(help1);
Scanner input = new Scanner(System.in);
return input.nextInt();
}
}

- ForOneToHundred41.java
package kr.co.infopub.chap041;
public class ForOneToHundred41 {

public static void main(String[] args) {
int toNum=100;
try{   
toNum=ScannerInput.readInt();
}catch(Exception e){
System.out.println("예외: 타입확인 요망"+e);
System.exit(1);//프로그램 끝
}
//main
int summs=0;
for(int i=1;i<=toNum;i++){
summs+=i;
}
System.out.println("1 to "+toNum+" summation="+summs);
//메서드 1
int sum=summation(1,toNum);
System.out.println("1 to "+toNum+" summation="+sum);
//메서드 2
int sum2=summation(toNum);
System.out.println("1 to "+toNum+" summation="+sum2);
}

public static int summation(int start, int end){
if(start>end ){return -1;}
int sum=0;
for(int i=start;i<=end;i++){
sum+=i;
}
return sum;
}
public static int summation(int end){
return summation(1,end);
}
}

042 1부터 100까지 홀수 합, 짝수 합 구하기 
- 메서드를 선언하고 호출하는 방법을 확인한다. 
- ForOddEvenSum42.java
package kr.co.infopub.chap042;
public class ForOddEvenSum42 {

public static void main(String[] args) {
int toNum=100;
try{   
toNum=ScannerInput.readInt();
}catch(Exception e){
System.out.println("예외: 타입확인 요망"+e);
System.exit(1);//프로그램 끝
}
int sumOdd=0;
int sumEven=0;

sumEven=summEven(1,toNum);
System.out.println("1 to "+toNum+" even sum "+sumEven);

sumOdd=summOdd(1,toNum);
System.out.println("1 to "+toNum+" odd sum "+sumOdd);
}
public static int summEven(int start, int end){
int sumEven=0;
//짝수합
for( int i=1; i<=end;i++){
if(i%2!=0){
continue;
}
sumEven+=i;
}
return sumEven;
}
public static int summOdd(int start, int end){
int sumOdd=0;
//짝수합
for( int i=1; i<=end;i++){
if(i%2==0){
continue;
}
sumOdd+=i;
}
return sumOdd;
}
}

043 규칙이 있는 수의 홀수 합, 짝수 합 구하기 
- 등차수열, 등비수열, 점화식을 이해한다.
- NumberAn43.java
package kr.co.infopub.chap043;
public class NumberAn43 {

public static void main(String[] args) {
int toNum=10;
try{   
toNum=ScannerInput.readInt();
}catch(Exception e){
System.out.println("예외: 타입확인 요망"+e);
System.exit(1);//프로그램 끝
}
int sum=sumAn(toNum,1,2);  //등차수열
System.out.println("sum = "+sum);

int sum2=sumBn(toNum,1,2); //등비수열
System.out.println("sum = "+sum2);

int sum3=sumCn(toNum,2,3,-2);//점화식
System.out.println("sum = "+sum3);
}

public static int numAn(int start, int n, int d){
return (start+n*d);
}
public static int sumAn(int n,int start, int d){
int sum=0;
for( int i=0; i<n;i++){
System.out.print("["+numAn(start,i,d)+"] ");
sum+=numAn(start,i,d);
}
return sum;
}
public static int numBn(int start, int n, int r){
int nums=1;
for( int i=0; i<n;i++){

nums*=start*r;
}
return nums;
}
public static int sumBn(int n,int start, int r){
int sum=0;
for( int i=0; i<n;i++){
System.out.print("["+numBn(start,i,r)+"] ");
sum+=numBn(start,i,r);
}
return sum;
}
public static int numCn(int n,int start,int a, int d){
//An+1 = a*An+d 점화식 
for( int i=0; i<n;i++){
start=a*start+d;
}
return start;
}
public static int sumCn(int n,int start, int a, int d){
int sum=0;
for( int i=0; i<n;i++){
System.out.print("["+numCn(i,start,a,d)+"] ");
sum+=numCn(i,start,a,d);
}
return sum;
}
}

044 규칙이 있는 수의 합 구하기 
 일정한 규칙을 찾는 연습을 한다. 
- NumberAn44.java
package kr.co.infopub.chap044;

import kr.co.infopub.chap043.ScannerInput;

public class NumberAn44 {

public static void main(String[] args) {
int toNum=10;
try{   
toNum=ScannerInput.readInt();
}catch(Exception e){
System.out.println("예외: 타입확인 요망"+e);
System.exit(1);//프로그램 끝
}
int sum=sumAn(toNum,1,2,true);  
System.out.println("sum = "+sum);
int sum2=sumAn(toNum,1,2,false);  
System.out.println("sum = "+sum2);
}

public static int numAn(int start, int n, int d){
return (start+n*d);
}
public static int posiNega(int start, int n, int d){
int oper=(n%2)==0?-1:1;
return oper*numAn(start,n,d);
}
public static int posiNega(int start, int n, int d, boolean isEvenNega){
int oper=isEvenNega?1:-1;
return oper*posiNega(start,n,d);
}
public static int sumAn(int n,int start, int d,boolean isEvenNega){
int sum=0;
for( int i=0; i<n;i++){
System.out.print("["+posiNega(start,i,d,isEvenNega)+"] ");
sum+=posiNega(start,i,d,isEvenNega);
}
return sum;
}
}

045 규칙이 있는 수의 합 구하기 2
 일정한 규칙을 찾는 연습을 한다.
-  NumberAn45.java
package kr.co.infopub.chap045;
public class NumberAn45 {

public static void main(String[] args) {
int toNum=10;
try{
toNum=ScannerInput.readInt();
}catch(Exception e){
System.out.println("예외: 타입확인 요망");
//System.exit(1);//프로그램 끝
}
double sum=sumAn(1,toNum,1);
System.out.println("\n1 to "+toNum+" summation="+sum);
double sum2=sumAn(1,toNum,2);
System.out.println("\n1 to "+toNum+" 1/odd summation="+sum2);
}
public static int numAn(int start, int n, int d){
return (start+n*d);
}
public static double divNum(int start, int n, int d){
return 1.0/numAn(start, n, d);
}
public static double sumAn(int start,int n, int d){
double sum=0;
for( int i=0; i<n;i++){
System.out.print("["+divNum(start,i,d)+"] ");
sum+=divNum(start,i,d);
}
return sum;
}
}

046  규칙이 있는 수의 합 구하기 3
 일정한 규칙을 찾는 연습을 한다.
- NumberAn46.java
package kr.co.infopub.chap046;
public class NumberAn46 {

public static void main(String[] args) {
int toNum=10;//50이하입력
try{
toNum=ScannerInput.readInt();
}catch(Exception e){
System.out.println("예외: 타입확인 요망");
System.exit(1);//프로그램 끝
}
double sum=sumAn(1,toNum,1);
System.out.println("\n1 to "+toNum+" :="+sum);
double sum2=sumAn(1,toNum,2);
System.out.println("\n1 to "+toNum+" :="+sum2);
}
public static int numAn(int start, int n, int d){
return (start+n*d);
}
public static double divNum(int n){
return 1.0/fact(n);
}
public static double fact(int m){
double temp=1;
if(m<=0){
temp=1;
}
for(int i=m;i>0;i--){
temp*=i;
}
return temp;
}
public static double sumAn(int start,int n, int d){
double sum=0;
for( int i=0; i<n;i++){
System.out.print("["+divNum(numAn(start,i,d))+"] ");
sum+=divNum(numAn(start,i,d));
}
return sum;
}
}
047 사각형 안의 Hello 만들기 
 char와 int  간의 캐스팅을 이해하고, for문의 사용 방법을 익힌다. 
- RectHellos47.java
package kr.co.infopub.chap047;

public class RectHellos47 {

public static void main(String[] args) {
printRectString("Hello",false);//영어는 공백 홀수개포함
printRectString("GO JAVA7",false);//영어는 공백 홀수개포함
printRectString("Hello my name is honny",false);
printRectString("반갑습니다",true);
System.out.println("Hello".length());
System.out.println("반갑습니다".length());
System.out.println();
System.out.println((int)'┐');//9488
System.out.println((int)'─');//9472
System.out.println((int)'│');//9474
System.out.println((int)'┌');//9484
System.out.println((int)'┘');//9496
System.out.println((int)'└');//9492

}
public static void printRectString(String str,boolean isE){
int count=str.length();  //String의 길이 
//System.out.println(count);
int width=count;
if(!isE){
width=count+2;
}else{
width=count%2==0?count+3:count+4;
}
//┌────────────────────────┐ 9484 9472 9488
//System.out.print('\1'); //┌ 1 java2
System.out.print((char)9484); //┌ 9484 java7
for(int i=0;i<width;i++){
System.out.print((char)9472);//─ java7
//System.out.print('\6');//─ java2
}
//System.out.println('\2');//┐ java2
System.out.println((char)9488);//┐ 9488
//│                        │  9474
//System.out.print('\5');//│ java2
System.out.print((char)9474);
if(!isE){
System.out.print(" "+str+" ");//str
}else{
System.out.print(" "+str+" ");//str
}
System.out.println((char)9474);//│ 9474
//System.out.println('\5');//│ 9474
//└─────────────────────┘9492 9472 9496
//System.out.print('\3');  //└ java 2  3
System.out.print((char)9492);//└ 9492
for(int i=0;i<width;i++){
//System.out.print('\6');//─ 6
System.out.print((char)9472);//─ 9472
}
//System.out.println('\4');//┘ 4
System.out.println((char)9496);//┘ 9496
}

}

048 구구단 작성
 중첩 for 문의 사용 방법을 익힌다. 멤버 메서드와 static 메서드의 사용상 차이점을 이해한다.
- GuGuDan.java
package kr.co.infopub.chap048;
public class GuGuDan48 {

public static void main(String[] args) {
//using method
printGuGu();
System.out.println("-----------------------------");

GuGu gu=new GuGu();
gu.printGu();
System.out.println("-----------------------------");

GuGu.printGuGu();
}
public static void printGuGu(){
for(int i=1; i<=9;i++){
for(int j=1; j<=9;j++){
System.out.printf("%d*%d=%d\t",j,i,i*j);
}
System.out.println();
}
}
}

class GuGu
{
public void printGu(){
for(int i=1; i<=9;i++){
for(int j=1; j<=9;j++){
System.out.printf("%d*%d=%d\t",j,i,i*j);
}
System.out.println();
}
}
public static void printGuGu(){
for(int i=1; i<=9;i++){
for(int j=1; j<=9;j++){
System.out.printf("%d*%d=%d\t",j,i,i*j);
}
System.out.println();
}
}
}

049 주사기 던지기 
 멤버 메서드와 static 메서드의 사용상 차이점을 이해한다.
- Die49.java
package kr.co.infopub.chap049;
public class Die49 {

public static void main(String[] args) {
Die.printAddDie();
Die.printMultiDie();
//non-static
Die die=new Die();
die.printnAddDie();
die.printnMultiDie();
}
}

class Die
{
public static void printAddDie(){
for(int i=1; i<=6;i++){
for(int j=1; j<=6;j++){
System.out.printf("%d+%d=%d\t",i,j,i+j);
}
System.out.println();
}
System.out.println("-----------------------------");
}
public void printnAddDie(){
for(int i=1; i<=6;i++){
for(int j=1; j<=6;j++){
System.out.printf("%d+%d=%d\t",i,j,i+j);
}
System.out.println();
}
System.out.println("-----------------------------");
}
public static void printMultiDie(){
for(int i=1; i<=6;i++){
for(int j=1; j<=6;j++){
System.out.printf("%d*%d=%d\t",i,j,i*j);
}
System.out.println();
}
System.out.println("-----------------------------");
}
public void printnMultiDie(){
for(int i=1; i<=6;i++){
for(int j=1; j<=6;j++){
System.out.printf("%d*%d=%d\t",i,j,i*j);
}
System.out.println();
}
System.out.println("-----------------------------");
}
}

050 여러 가지 모양 출력하기 
 규칙을 이끌어내는 방법을 익힌다.
- StarPoint50.java
package kr.co.infopub.chap050;
public class StarPoint50 {

public static void main(String[] args) {
printButterfly(5);
System.out.println("------------------");
printDiamond(5);
}
public static void printStarDecrease(int n){
for(int i=0; i<n;i++){
for(int j=0; j<i;j++){
System.out.print(" ");
}
for(int k=1; k<2*(n-i);k++){
System.out.print("*");
}
System.out.println();
}
}
public static void printStarIncrease(int n){
for(int i=n-1; i>=0;i--){
for(int j=0; j<i;j++){
System.out.print(" ");
}
for(int k=1; k<2*(n-i);k++){
System.out.print("*");
}
System.out.println();
}
}
public static void printButterfly(int n){
printStarDecrease(n);
printStarIncrease(n);
}
public static void printDiamond(int n){
printStarIncrease(n);
printStarDecrease(n);
}
}