2017年2月28日火曜日

Java CallBack 练习

Java CallBack 练习

https://paiza.io/projects/J4kb3mqHFWTylgPFh_q-sw

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws Exception {
        Text1 tt1 = new Text1();
        tt1.t1(new Text1.CallBack(){
            public void gets(String x){
                System.out.println(x);
            }
            public void gety(String y){
                System.out.println(y);
            }
        });
    }
}

class Text1{
    interface CallBack{
        public void gets(String x);
        public void gety(String y);
    }

    public void t1( CallBack cb){
        int i = 6;
        for(; i < 200; i++){
        }
        if(i%2 == 0){
            cb.gets("x" + i + "");
        }else{
            cb.gety("y" + i + "");
        }
    }
}

2017年2月25日土曜日

Android AdMob広告

Android AdMob広告

    protected void admo() {
//        xmlns:ads="http://schemas.android.com/apk/res-auto"
        ViewGroup viewGroup = (ViewGroup) findViewById(R.id.activity_main);
        RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
        AdView adView = new AdView(this);
        adView.setBackgroundColor(ContextCompat.getColor(this, R.color.colorAccent));
        adView.setLayoutParams(layoutParams);
        layoutParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
        layoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
        adView.setAdSize(AdSize.BANNER);
        adView.setAdUnitId("ca-app-pub-3940256099942544/6300978111");
        AdRequest adRequest = new AdRequest.Builder().build();
        adView.loadAd(adRequest);
        viewGroup.addView(adView);
    }


https://developers.google.com/admob/android/banner



2017年2月24日金曜日

Android MediaPlayer

Android MediaPlayer

    protected void t1() {
        try {
            String url = "http://www.ne.jp/asahi/music/myuu/wave/menuettm.mp3";
//          Uri mu = Uri.parse("http://www.ne.jp/asahi/music/myuu/wave/menuettm.mp3");
            MediaPlayer mediaPlayer = new MediaPlayer();
            mediaPlayer.setAudioStreamType(AudioManager.STREAM_RING);
//          mediaPlayer.setDataSource(getApplicationContext(), mu);
            mediaPlayer.prepare();
            mediaPlayer.start();
            mediaPlayer.setDataSource(url);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }