package com.example.myapplication; import android.content.Context; import android.content.Intent; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.media.MediaPlayer; import android.net.Uri; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.Gravity; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Button; import android.widget.TextView; import android.widget.Toast; public class MainActivity extends AppCompatActivity implements View.OnClickListener { private Button btn1,btn2; private MediaPlayer player;// MediaPlayer引用 private int i=0; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); btn1= (Button) findViewById(R.id.button); btn2= (Button) findViewById(R.id.button2); btn1.setOnClickListener(this); btn2.setOnClickListener(this); } public void boplay(){ if(player == null){ player =player.create(this, R.raw.i); } } public boolean checkApkExist(Context context, String packageName) { if (packageName == null || "".equals(packageName)) return false; try { ApplicationInfo info = context.getPackageManager().getApplicationInfo(packageName, PackageManager.GET_UNINSTALLED_PACKAGES); return true; } catch (PackageManager.NameNotFoundException e) { return false; } } @Override public void onClick(View v) { LayoutInflater inflater=getLayoutInflater(); View layout=inflater.inflate(R.layout.zdy, (ViewGroup) findViewById(R.id.zdy)); TextView text= (TextView) layout.findViewById(R.id.text); TextView text1= (TextView) layout.findViewById(R.id.text1); TextView text2= (TextView) layout.findViewById(R.id.text2); switch (v.getId()){ case R.id.button: if (checkApkExist(this, "com.tencent.mobileqq")){ startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("mqqwpa://im/chat?chat_type=wpa&uin="+292608602+"&version=1"))); Toast.makeText(MainActivity.this,"领取你的小哥哥",0).show(); }else{ Toast.makeText(this,"本机未安装QQ应用",Toast.LENGTH_SHORT).show(); } break; case R.id.button2: if(player == null){ boplay(); } player.setLooping(true); player.start(); if (i==0){ text.setText("一个喜欢你的狗子:"); text1.setText("房产证写你名字"); text2.setText("拒绝一次不够哦"); Toast toast=new Toast(getApplicationContext()); //设置Toast的位置 toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0); toast.setDuration(10000 ); //让Toast显示为我们自定义的样子 toast.setView(layout); toast.show(); i++; }else if(i==1){ text.setText("一个喜欢你的狗子:"); text1.setText("家务我全包"); text2.setText("拒绝两次也还不行"); Toast toast=new Toast(getApplicationContext()); //设置Toast的位置 toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0); toast.setDuration(10000 ); //让Toast显示为我们自定义的样子 toast.setView(layout); toast.show(); i++; }else if(i==2){ text.setText("一个喜欢你的狗子:"); text1.setText("我妈会游泳"); text2.setText("最后一次尝试一次"); Toast toast=new Toast(getApplicationContext()); //设置Toast的位置 toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0); toast.setDuration(10000 ); //让Toast显示为我们自定义的样子 toast.setView(layout); toast.show(); i++; }else if(i==3) { text.setText("一个喜欢你的狗子:"); text1.setText("保大"); text2.setText("真的最后一次,真不考虑一下"); Toast toast = new Toast(getApplicationContext()); //设置Toast的位置 toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0); toast.setDuration(10000); //让Toast显示为我们自定义的样子 toast.setView(layout); toast.show(); i++; }else { text1.setTextColor(0xFFa52a2a); text1.setText("如果可以,\n我会一直陪着你!"); text1.setTextSize(30); Toast toast = new Toast(getApplicationContext()); //设置Toast的位置 toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0); toast.setDuration(10000); //让Toast显示为我们自定义的样子 toast.setView(layout); toast.show(); } break; } } }
jfhdibrbfjd
相关分类