diff --git a/.idea/modules.xml b/.idea/modules.xml index e0018f4005375e9be111bb3baeb3e77451802874..27876733a2c4f7caec5908019a199dc41235ec8f 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -3,6 +3,8 @@ + + diff --git a/app/src/main/java/com/example/wly/application_3_homework/MainActivity.java b/app/src/main/java/com/example/wly/application_3_homework/MainActivity.java index 1325b0cfbbb1593fad27f4a56152fb397a56d0f3..ba5bcecc47ae0215d8f0e4fbcae8d3cb210d6d6e 100644 --- a/app/src/main/java/com/example/wly/application_3_homework/MainActivity.java +++ b/app/src/main/java/com/example/wly/application_3_homework/MainActivity.java @@ -1,84 +1,79 @@ package com.example.wly.application_3_homework; - import android.Manifest; -import android.app.Activity; +import android.content.DialogInterface; import android.content.Intent; import android.net.Uri; +import android.support.v7.app.AlertDialog; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; +import android.text.TextUtils; import android.view.View; import android.widget.Button; import android.widget.EditText; - import java.util.HashMap; -import java.util.List; - import pub.devrel.easypermissions.EasyPermissions; - - -public class MainActivity extends AppCompatActivity{ - - HashMap phoneMap = new HashMap<>(); - EditText etnumber; - Button btncallphone; - Button btnaddnumber; - EditText etnewnumber; - EditText etnewcutnumber; - - @Override - +public class MainActivity extends AppCompatActivity { + HashMap Mapphone= new HashMap(); + String a = null; + String b = null; public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { super.onRequestPermissionsResult(requestCode, permissions, grantResults); EasyPermissions.onRequestPermissionsResult(requestCode, permissions, grantResults, this); } - + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - setContentView(R.layout.activity_main); - - etnumber = (EditText) findViewById(R.id.et_number); - etnewnumber = (EditText) findViewById(R.id.et_newnumber); - etnewcutnumber = (EditText) findViewById(R.id.et_newcutnumber); - btncallphone = (Button) findViewById(R.id.btn_callphone); - btnaddnumber = (Button) findViewById(R.id.btn_addNumber); - - requestMyappPermission(); + requesMyAppPermission(); initMapData(); - - btncallphone.setOnClickListener(new View.OnClickListener() { + setContentView(R.layout.activity_main); + Button btuphone = (Button)findViewById(R.id.bt_phone); + final EditText etphone = (EditText)findViewById(R.id.et_phone); + final EditText etphone1 = (EditText)findViewById(R.id.et_phone1); + Button btuphone2 = (Button)findViewById(R.id.bt_phone2); + final EditText etphone2 = (EditText)findViewById(R.id.et_phone2); + btuphone.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - Intent intent = new Intent(); - intent.setAction(intent.ACTION_CALL);//拨号 - String cutNumber = etnumber.getText().toString().trim(); - String phoneNumber = phoneMap.get(cutNumber); - intent.setData(Uri.parse("tel:" + phoneNumber)); + Intent intent= new Intent(); + intent.setAction(Intent.ACTION_CALL); + String enphone = etphone.getText().toString().trim(); + String emphone = Mapphone.get(enphone); + intent.setData(Uri.parse("tel:"+emphone)); startActivity(intent); } }); - btnaddnumber.setOnClickListener(new View.OnClickListener() { + btuphone2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - String key = etnewcutnumber.getText().toString(); - String value = etnewnumber.getText().toString(); - phoneMap.put(key,value); + if(!TextUtils.isEmpty(etphone1.getText())){ + if (!TextUtils.isEmpty(etphone2.getText())){ + Mapphone.put(etphone1.getText().toString().trim(),etphone2.getText().toString().trim()); + showDialog(); + } + } } }); } - - private void requestMyappPermission() { + private void initMapData() { + Mapphone.put("1","10086"); + Mapphone.put("3","99634"); + Mapphone.put("5","77231"); + } + private void requesMyAppPermission() { String[] perms = {Manifest.permission.CALL_PHONE}; if (!EasyPermissions.hasPermissions(getApplicationContext(), perms)) { EasyPermissions.requestPermissions(this,"call phone",1,perms); - //(当前应用,提示信息,请求码:1、2、3 ,权限数组) } } + public void showDialog(){ + AlertDialog.Builder builder=new AlertDialog.Builder(this); + builder.setTitle("标题"); + builder.setMessage("添加成功"); + builder.setPositiveButton("我知道了", new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int which) { - private void initMapData() { - phoneMap.put("1", "10086"); - phoneMap.put("2", "10010"); + } + }); + builder.show(); } - - - } diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 99b3544f3f856a3d144c8b6530cf16e657ad0d43..d4d247ed486af9d183261d846019bf1484d1ff82 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -8,72 +8,36 @@ android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" - tools:context="com.example.wly.application_3_homework.MainActivity" - android:orientation="vertical"> + android:orientation="vertical" + tools:context="com.example.wly.application_3_homework.MainActivity"> + android:hint="请输入拨打的电话号码的缩写" + android:inputType="number" + android:id="@+id/et_phone"/>