package com.example.wang.testapp2;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import java.util.Random;
public class ZuoyeActivity extends AppCompatActivity {
Button bt_2;
Button bt_3;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_zuoye);
bt_2=(Button)findViewById(R.id.bt_2);
bt_3=(Button)findViewById(R.id.bt_3);
}
//
public void bt1_OnClick(View v)
{
String string="";
Random random = new Random();
final String[] str =new String[6];
for(int i=0;i<6;i++)
{
int t=random.nextInt(9);
str[i]=String.valueOf(t);
string=string+str[i];
}
if (str[0]=="0")
{
str[0]=String.valueOf(random.nextInt(9));
string=str[0]+str[1]+str[2]+str[3]+str[4]+str[5];
}
Log.e("TAG", "string=" + string);
View view=View.inflate(this,R.layout.activity_zuoye2,null);
final AlertDialog alertDialog = new AlertDialog.Builder(this)
.setTitle("生成最大值和最小值")
.setView(view)
.setPositiveButton("最小值", new DialogInterface.OnClickListener() {
String string1="";
@Override
public void onClick(DialogInterface dialog, int which) {
AlertDialog al =(AlertDialog)dialog;
int[] a = new int[6];
for (int i = 0; i < 6; i++) {
a[i] = Integer.parseInt(str[i]);
Log.e("TAG","a[}="+a[i]);
}
for (int i = 0; i < 6; i++) {
for (int j = 0; j < 5-i; j++) {
if (a[j] > a[j + 1]) {
int b = a[j];
a[j] = a[j + 1];
a[j + 1] = b;
}
}
}
for (int i = 0; i < 6; i++) {
str[i]=String.valueOf(a[i]);
string1=string1+str[i];
}
Intent intent=new Intent(ZuoyeActivity.this,ZuoyeActivity3.class);
//intent.setData(Uri.parse(string1));
intent.putExtra("jieguo",string1);
startActivity(intent);
// EditText et_jieguo=(EditText)al.findViewById(R.id.et_jieguo);
//
// et_jieguo.setText(string1);
}
})
.setNegativeButton("最大值", null)
.show();
EditText et_suiji=(EditText)alertDialog.findViewById(R.id.et_suiji);
et_suiji.setText(string);
}
public void bt2_OnClick(View v)
{
final AlertDialog alertDialog=new AlertDialog.Builder(this)
.setTitle("提示")
.setMessage("确定要删除吗?" + "\n" + "要删除,请点击“是”。")
.setNegativeButton("否", null)
.setPositiveButton("是", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(ZuoyeActivity.this, "删除成功" + which, Toast.LENGTH_SHORT).show();
}
})
.show();
}
public void bt3_OnClick(View v)
{
View view=View.inflate(this, R.layout.activity_zuoye1, null);
new AlertDialog.Builder(this)
.setTitle("请输入电话号码")
.setView(view)
.setNeutralButton("拨出此号码", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
AlertDialog al = (AlertDialog) dialog;
EditText et_1 = (EditText) al.findViewById(R.id.et_1);
String str = et_1.getText().toString();
Intent intent = new Intent(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:" + str));
try {
startActivity(intent);
} catch (Exception e) {
e.printStackTrace();
}
}
})
.setPositiveButton("向此号码发短信", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
AlertDialog al=(AlertDialog)dialog;
EditText et_1 = (EditText) al.findViewById(R.id.et_1);
String str = et_1.getText().toString();
Intent intent = new Intent(Intent.ACTION_SENDTO);
intent.setData(Uri.parse("smsto:"+str));
startActivity(intent);
}
})
.show();
}
}