2017년 9월 19일 화요일

c2 cordova plugin admob simple

 /*  
  * Licensed to the Apache Software Foundation (ASF) under one  
  * or more contributor license agreements. See the NOTICE file  
  * distributed with this work for additional information  
  * regarding copyright ownership. The ASF licenses this file  
  * to you under the Apache License, Version 2.0 (the  
  * "License"); you may not use this file except in compliance  
  * with the License. You may obtain a copy of the License at  
  *  
  * http://www.apache.org/licenses/LICENSE-2.0  
  *  
  * Unless required by applicable law or agreed to in writing,  
  * software distributed under the License is distributed on an  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY  
  * KIND, either express or implied. See the License for the  
  * specific language governing permissions and limitations  
  * under the License.  
  */  
 var app = {  
   // Application Constructor  
   initialize: function() {  
     document.addEventListener('deviceready', this.onDeviceReady.bind(this), false);  
   },  
   // deviceready Event Handler  
   //  
   // Bind any cordova events here. Common events are:  
   // 'pause', 'resume', etc.  
   onDeviceReady: function() {  
     this.receivedEvent('deviceready');  
   },  
   // Update DOM on a Received Event  
   receivedEvent: function(id) {  
     var parentElement = document.getElementById(id);  
 //    var listeningElement = parentElement.querySelector('.listening');  
 //    var receivedElement = parentElement.querySelector('.received');  
 //    listeningElement.setAttribute('style', 'display:none;');  
 //    receivedElement.setAttribute('style', 'display:block;');  
     initAd();  
     showBannerFunc();  
     showInterstitialFunc();  
     console.log('Received Event: ' + id);  
   }  
 };  
   //initialize the goodies  
   function initAd(){  
       if ( window.plugins && window.plugins.AdMob ) {  
         var ad_units = {  
           ios : {  
             banner: 'ca-app-pub-xxxxxxxxxxx/xxxxxxxxxxx',    //PUT ADMOB ADCODE HERE  
             interstitial: 'ca-app-pub-xxxxxxxxxxx/xxxxxxxxxxx'  //PUT ADMOB ADCODE HERE  
           },  
           android : {  
             banner: 'ca-app-pub-5187489598351901/8426966507',    //PUT ADMOB ADCODE HERE  
             interstitial: 'ca-app-pub-5187489598351901/1148269958'  //PUT ADMOB ADCODE HERE  
           }  
         };  
         var admobid = ( /(android)/i.test(navigator.userAgent) ) ? ad_units.android : ad_units.ios;  
         window.plugins.AdMob.setOptions( {  
           publisherId: admobid.banner,  
           interstitialAdId: admobid.interstitial,  
           adSize: window.plugins.AdMob.AD_SIZE.BANNER,  //use SMART_BANNER, BANNER, LARGE_BANNER, IAB_MRECT, IAB_BANNER, IAB_LEADERBOARD  
           bannerAtTop: false, // set to true, to put banner at top  
           overlap: true, // banner will overlap webview  
           offsetTopBar: true, // set to true to avoid ios7 status bar overlap  
           isTesting: true, // receiving test ad  
           autoShow: false // auto show interstitial ad when loaded  
         });  
         registerAdEvents();  
         window.plugins.AdMob.createInterstitialView();  //get the interstitials ready to be shown  
         window.plugins.AdMob.requestInterstitialAd();  
       } else {  
         alert( 'admob plugin not ready' );  
       }  
   }  
   //functions to allow you to know when ads are shown, etc.  
   function registerAdEvents() {  
       document.addEventListener('onReceiveAd', function(){});  
       document.addEventListener('onFailedToReceiveAd', function(data){});  
       document.addEventListener('onPresentAd', function(){});  
       document.addEventListener('onDismissAd', function(){ });  
       document.addEventListener('onLeaveToAd', function(){ });  
       document.addEventListener('onReceiveInterstitialAd', function(){ });  
       document.addEventListener('onPresentInterstitialAd', function(){ });  
       document.addEventListener('onDismissInterstitialAd', function(){  
       window.plugins.AdMob.createInterstitialView();      //REMOVE THESE 2 LINES IF USING AUTOSHOW  
       window.plugins.AdMob.requestInterstitialAd();      //get the next one ready only after the current one is closed  
       });  
     }  
 //display the banner  
   function showBannerFunc(){  
       window.plugins.AdMob.createBannerView();  
     }  
 //display the interstitial  
   function showInterstitialFunc(){  
       window.plugins.AdMob.showInterstitialAd();  
     }  
 app.initialize();  
 ==================================================================================  
 index.html  
 index.html  
 ==================================================================================  

2017년 9월 16일 토요일

1. 이클립스 옵션 조정


1. 이클립스 옵션 조정

우선 이클립스 폴더 안에 있는 eclipse.ini에 다음을 추가 하거나 수정해줍니다.

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

-Xverify:none

-XX:+UseParalleIGC

-Xms256M

-Xmx512M

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

-Xverify :

            초기 시동시 verfify체크를 하지 않습니다. 간혹 플러그인 features에 문제가 발생 할 수 있습니다.

            플러그인 변경 사항이 있을 경우에는 이걸 체크하시고, 별 문제 없으면 추가해서 사용하시면 됩니다.



-XX:+UseParalleIGC :

             ParalleI Collector를 사용 하도록 합니다.  패럴로 모아주니 빨라지는 느낌이 드실 겁니다.

             다중 프로세서를 사용하시는 분들은 필수입니다.



-Xms256M :

             이클립스가 시작시 잡는 메모리입니다.(256메가 바이트)



-Xmx512M :

             이클립스가 사용하는 최대 메모리입니다.(512메가 바이트) 메모리 여유가 되시면 늘려주시는게 좋지요.




2. 메모리를 정리해 줍시다.







Window > Perference > General 에 보면 Show heap status라는 옵션이 있습니다.  이걸 켜주시면, 화면 오른쪽 하단에 아이콘이 생깁니다.









사용하다가, 메모리가 많이 쌓였거나, 느리다 싶을때 옆에 휴지통 아이콘을 누르시면 메모리가 정리가 되면서 좀더 빠른 작업을 하실 수 있을 겁니다.



추가로 메모리는 좀 들긴 하지만 자동 가비지 컬렉션 해주는 플러그인을 설치 하셔도 됩니다.





3. 사용하지 않는 검사는 제외시켜 주세요.



필요 이상으로 많은 검사를 해서 느려지는 경우도 많습니다.  HTML이나 그외 기타등등 검사도 거기에 포함됩니다.  딱 필요한 검사만 하도록 하면 빨라지겠지요.

Window > Perferences > Validation 에서 자기가 사용하는 옵션을 켜 줍니다.







그리고 영어 스펠링 검사입니다.  별도움 안될 것 같아서 꺼 놓습니다.

Window > Preference > General > Editors >Spellings 에서 Enable spell checking를 과감하게 꺼 놓습니다.











4. 잘 사용하지 않는 기능과 사용 습관을 바뀌기



코딩하는 공간에서 잘 사용하지 않거나, 별 소용없는 기능은 꺼 주시는게 좋습니다.



Automatic folding 끄기

코드 옆에 더하기 표시 나와서 코드를 펼쳤다...닫았다 하는 기능입니다. 눈에도 안띄고 잘 안쓰는 기능이라서 꺼 놓습니다.

Window > Preferences > Java(또는 사용언어) > Editor > Folding 모든 옵션을 해제(disable)합니다.



Automatic Content  Assist 끄기

Window > Preferences > Java(또는 사용언어) > Editor > Content Assist 에서 Enable auto activation 항목을  해제(disable)합니다.  자동 기능은 꺼지지만, ctrl + space는 여전히 code assist를 사용할 수 있습니다.



사용하지 않는 플러그인 삭제 하기

이클립스를 패키지로 설치하면 사용하지 않는 기능도 많이 들어가게 됩니다. 그 중에서 필요 없는 플러그인은 삭제하는게 좋습니다.



사용하지 않는 프로젝트 닫아 주기

현재 작업과 관련 없는 프로젝트는 닫아 주시는게 좋습니다. 이클립스가 접근하는 파일의 갯수를 줄여 주기 때문입니다.



사용하지 않는 파일은 닫아주기

작업하다가 사용하지 안흔 창은 닫아 주시는게 좋습니다.  이클립스를 종료시 편집하던 문서를 모두 닫고 종료하는건 다음에 이클립스를 띄을때 좀 더 가볍게 띄을수 있기 때문입니다.

Window > Preference > General > Editors 에서 Close editors automatically를 켜주세요. 그럼 아래에 설정된 숫자만큼만 문서가 열립니다. 그 이상의 문서는 자동으로 닫아집니다.



사용하지 않는 플러그인을 start list에서 제외하기

Window > Preference > General > Startup and Shutdown에서, 불필요한 플러그인을 startup list에서 제외합니다. 이렇게 하면 이클립스가 실행시 좀더 빨라집니다.






5. 그래도 느릴경우



이클립스가 설치된 폴더에 바이러스 검사를 제외시켜주세요.

백신마다 제외시키는 설정이 있습니다. 이클립스가 설치된 폴더를 예외로 설정하시고 사용해 보세요.



작업하는 파일들과 이클립스 프로그램을 작은 파티션을 만들어서 관리해 보세요.

헤더의 움직임을 최소화 해주고 빨라집니다. 하드디스크에서 디스크 조각모음 하는것보다 훨씬 좋습니다.


출처: http://mobileandlife.tistory.com/entry/이클립스-속도-향상시키기-TIP [모바일 보물창고]

2017년 9월 15일 금요일

[01] OOP(Object Oriented Programming, 객체지향 프로그래밍)

[01] OOP(Object Oriented Programming, 객체지향 프로그래밍)

1. 객체 지향(콤포넌트, 부품)의 특징
   - 한번 개발자가 개발한 코드는 "적은 수정"으로 재사용이 가능하도록함.

   - 콤포넌트(완성된 소스)가 다른 콤포넌트와 결합하여 하나의 프로그램을 형성합니다.
     . A 프로그램 --> 모듈 --> 출력 --> 처리 종류
     . B 프로그램 --> 모듈 --> 출력 --> 처리 종류
                      │
                      ↓
                     (공통모듈)
     . A 프로그램 --> 콤포넌트 <-- b="" p="">       워드 패드  --> 파일 열기 <-- p="">  
   - OOP의 개념을 바탕으로 업무용 프로그램을 제작하면 관리비용이 절감될 수 있다.



Project type: Java Project
        name: oop




[02] 메소드
   - 메소드(함수)는 멤버 변수(데이터)를 조작하고 처리하는 역활을 합니다.

   - 2번이상 호출되는 로직이나 향후 호출될 가능성이 있는 로직은
     메소드의 대상이 됩니다.
    
   - 리턴값이 없는 메소드는 void(공허한, 비어있는) 형을 지정합니다.

   - 메소드가 받는 인수의 데이터 타입은 메소드를 호출하는 쪽과
     일치해야 합니다. 


1. 하나의 클래스에서 필드(변수)의 출력

[실행 화면]
객제지향
웹프로그램
개발프레임워크

>>>>> FieldTest.java
---------------------------------------------------------------------------------------
public class FieldTest {
  String java = "객체 지향";
  String jsp = "웹 프로그램";
  String spring = "개발 프레임워크(자동화 소스)";
 
  public static void main(String[] args) {
    FieldTest ft = new FieldTest();
    // ft: 객체명, new: 메모리 할당

    System.out.println(ft.java);
    System.out.println(ft.jsp);
    System.out.println(ft.spring);
   
    String summer="동해";
    System.out.println("summer: " + summer);
  }

}

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



2. 하나의 클래스에서 메소드 호출
   - public void print(){ ... } : 출력 메소드
   - public void line(){ ... }  : 라인 출력 메소드

[실행 화면]
──────────
* 국어: 80
* 영어: 90
* 총점: 170
* 평균: 85
──────────
* 국어: 95
* 영어: 100
* 총점: 195
* 평균: 97
──────────
* 국어: 60
* 영어: 70
* 총점: 130
* 평균: 65
──────────

>>>>> /src/Sungjuk1.java
---------------------------------------------------------------------------------------
public class Sungjuk1 {
  int kuk = 80; // 필드, 멤버 변수, 인스턴스 변수
  int eng = 90;
  int tot = 0; 
  int avg = 0; 
 
  public void print(){ // 메소드
    tot = kuk + eng;
    avg = tot / 2;
   
    System.out.println("* 국어: " + kuk);
    System.out.println("* 영어: " + eng);
    System.out.println("* 총점: " + tot);
    System.out.println("* 평균: " + avg);
  }
 
  public void line(){
    System.out.println("──────────");
  }
 
  public static void main(String[] args) {
    Sungjuk1 sj = new Sungjuk1();
   
    sj.line();
    sj.print();
   
    sj.line();
   
    sj.kuk = 95;
    sj.eng = 100;
    sj.print();
    sj.line();
   
    sj.kuk = 60;
    sj.eng = 70;
    sj.print();
    sj.line();
   
  }

}


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




3. 변수의 사용
   - public void total(){ ... }
   - public void point(){ ... }
   - public void print(){ ... }
   - public void line(){ ... }

[실행 화면]
영화명: Gravity <- p="" print="">성  인: 8000
학  생: 6000
합  계: 14000   <- p="" total="">포인트: 700     <- 5="" p="" point="">
>>>>> Movie.java

public class Movie {
  String movie = "그래비";  // 필드
  int price1 = 10000;
  int price2 = 8000;
  int tot = 0;
  int point = 0;
 
  public void total(){ // 합계 메소드
    tot = price1 + price2;
  }
 
  public void point(){ // 포인트 메소드
    point = (int)(tot * 0.05);
  }
 
  public void print(){ // 인쇄, 다른 메소드 호출 가능
    System.out.println("영화명: " + movie);
    System.out.println("성  인: " + price1);
    System.out.println("학  생: " + price2);
    total();
    System.out.println("합  계: " + tot);
    point();
    System.out.println("포인트: " + point);
  }
 
  public static void main(String[] args) {
    Movie movie = new Movie();
    movie.print();

  }

}




[03] 메소드로 데이터의 전달
     - 메소드가 실행될 때 처리할 데이터를 전달 받을 수 있습니다.

1. 메소드가 데이터를 전달받아 출력하는 메소드
   - public void print(String str){ ... }

[실행 화면]
1. 자바 개발자 과정
2. A
3. 1000
4. 10.5
5. false

>>>>> /src/TransferTest.java

public class TransferTest {
  public void printStr(String str){ // Call By value
    System.out.println("1. " + str);
  }
 
  public void printChar(char chr){
    System.out.println("2. " + chr);
  }
 
  public void printInt(int i){
    System.out.println("3. " + i);
  }

  public void printDouble(double d){
    System.out.println("4. " + d);
  }
 
  public void printBoolean(boolean bol){
    System.out.println("5. " + bol); 
  }
 
  public static void main(String[] args) {
    TransferTest tt = new TransferTest();
    tt.printStr("자바 개발자 과정");
    tt.printChar('A');
    tt.printInt(1000);
    tt.printDouble(10.5);
    tt.printBoolean(false);
  }

}




2. 메소드가 두개 이상의 데이터를 전달받아 출력하는 메소드
   - public void print(String str, int kuk){ ... }

[실행 화면]
자바 개발자 과정 A
자바 개발자 과정 A 1000
자바 개발자 과정 A 1000 10.5
자바 개발자 과정 A 1000 10.5 false

>>>>> /src/TransferTest2.java

public class TransferTest2 {
  public void print(String str, char chr){
    System.out.println(str + " " + chr);
  }

  public void print(String str, char chr, int i){
    System.out.println(str + " " + chr + " " + i);
  }

  public void print(String str, char chr, int i, double d){
    System.out.println(str + " " + chr + " " + i + " " + d);
  }

  public void print(String str, char chr, int i, double d, boolean bol){
    System.out.println(str + " " + chr + " " + i + " " + d + " " + bol);
  }
 
  public static void main(String[] args) {
    TransferTest2 tt = new TransferTest2();
    tt.print("자바 개발자 과정");
    tt.print("자바 개발자 과정", 'A');
    tt.print("자바 개발자 과정", 'A', 1000);
    tt.print("자바 개발자 과정", 'A', 1000, 10.5);
    tt.print("자바 개발자 과정", 'A', 1000, 10.5, false);
  }

}




[04] 콤포넌트 클래스의 분리
     - 자바는 기본적으로 클래스 분리 개발 및 실행 환경을 제공함.


1. 프로젝트를 새로 만들고 클래스를 분리하세요.

Project type: Java Project
        name: oop2


출처 : https://junghamin.blogspot.kr