jangwooning 发表于 2013-7-11 11:44:49

android 拨号器 可用于小号互打

给公司写的小程序,公司把座机取消了,同事之间用它拨打小号方便,反正挺简单的,大家误笑,高手指点,嘿嘿
1,拨号规则是可以自己定义,(目前不能拨打外线,因为写前缀码在里边了,可以自己删了),
2,小程序涉及button Edittext seletor选择器(用于按钮高亮)的简单使用
3,按输入的号码搜索通讯录,然后把联想的号码显示出来的功能还没写粗来,希望大家一起研究,有空弄出来一起分享

switch管理各个按钮的功能
public class MainActivity extends Activity {
       
        private EditText et1=null;
       
        protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.activity_main);
                et1=(EditText) findViewById(R.id.editText1);
                et1.setInputType(InputType.TYPE_NULL);
                Button bt1 =(Button) findViewById(R.id.Button1);
        }
       
       
        public void set(View view){
               
                switch (view.getId()) {
                        case R.id.Button1:
                                Editable editable1 = et1.getText();
                                editable1.insert(et1.getSelectionStart(), "1");
                                break;
                        case R.id.Button2:
                                Editable editable2 = et1.getText();
                                editable2.insert(et1.getSelectionStart(), "2");
                                break;
                        case R.id.Button3:
                                Editable editable3 = et1.getText();
                                editable3.insert(et1.getSelectionStart(), "3");
                                break;
                        case R.id.Button4:
                                Editable editable4 = et1.getText();
                                editable4.insert(et1.getSelectionStart(), "4");
                                break;
                        case R.id.Button5:
                                Editable editable5 = et1.getText();
                                editable5.insert(et1.getSelectionStart(), "5");
                                break;
                        case R.id.Button6:
                                Editable editable6 = et1.getText();
                                editable6.insert(et1.getSelectionStart(), "6");
                                break;
                        case R.id.Button7:
                                Editable editable7 = et1.getText();
                                editable7.insert(et1.getSelectionStart(), "7");
                                break;
                        case R.id.Button8:
                                Editable editable8 = et1.getText();
                                editable8.insert(et1.getSelectionStart(), "8");
                                break;
                        case R.id.Button9:
                                Editable editable9 = et1.getText();
                                editable9.insert(et1.getSelectionStart(), "9");
                                break;
                        case R.id.Button0:
                                Editable editable0 = et1.getText();
                                editable0.insert(et1.getSelectionStart(), "0");
                                break;
                        case R.id.ButtonXing:
                                Editable editableX = et1.getText();
                                editableX.insert(et1.getSelectionStart(), "*");
                                break;
                        case R.id.ButtonJing:
                                Editable editableJ = et1.getText();
                                editableJ.insert(et1.getSelectionStart(), "#");
                                break;
                        case R.id.ButtonDail:
                               
                                String mobile = et1.getText().toString();
                                if(mobile.equals("")||mobile==null){
                                        Toast.makeText(getApplicationContext(), "号码不能为空", Toast.LENGTH_LONG).show();
                                }else if(mobile.equals("9")){
                                        mobile = "51664400";
                                        Intent intent1 = new Intent(Intent.ACTION_CALL,Uri.parse("tel:"+mobile));
                                        MainActivity.this.startActivity(intent1);
                                }else{
                                // 参数1:动作。在这指打电话
                                // 参数2:提供给应用的数据。在这指电话号       
                                Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + "51664"+mobile));
                                // 将意图传给操作系统
                                // startActivity方法专门将意图传给操作系统
                                MainActivity.this.startActivity(intent);
                                }
                                break;
                        case R.id.ButtonDelete:
                                int index = et1.getSelectionStart();
                                if(et1.getText().length()!=0){
                                        Editable editable = et1.getText();
                                        editable.delete(index-1, index);
                                }else{
                                        break;
                                }
                        case R.id.ButtonKong:
                                break;
                        default:
                                break;
                }
               
        }

}

页面布局
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MainActivity" >

    <EditText
      android:id="@+id/editText1"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:layout_alignParentTop="true"
      android:layout_marginTop="26dp"
      android:ems="10"
      android:hint="请输入电话号码" />

    <LinearLayout
      android:layout_width="wrap_content"
      android:layout_height="75dp"
      android:layout_weight="0.32"
      android:background="@drawable/bg" >
    </LinearLayout>

    <LinearLayout
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:orientation="horizontal" >

      <Button
            android:id="@+id/Button1"
            android:layout_width="105dp"
            android:layout_height="60dp"
            android:background="@drawable/button_selector"
            android:onClick="set" />

      <Button
            android:id="@+id/Button2"
            android:layout_width="105dp"
            android:layout_height="60dp"
            android:background="@drawable/button2_selector"
            android:onClick="set" />

      <Button
            android:id="@+id/Button3"
            android:layout_width="match_parent"
            android:layout_height="60dp"
            android:background="@drawable/button3_selector"
            android:onClick="set" />
    </LinearLayout>

    <LinearLayout
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:orientation="horizontal" >

      <Button
            android:id="@+id/Button4"
            android:layout_width="105dp"
            android:layout_height="60dp"
            android:background="@drawable/button4_selector"
            android:onClick="set" />

      <Button
            android:id="@+id/Button5"
            android:layout_width="105dp"
            android:layout_height="60dp"
            android:background="@drawable/button5_selector"
            android:onClick="set" />

      <Button
            android:id="@+id/Button6"
            android:layout_width="match_parent"
            android:layout_height="60dp"
            android:background="@drawable/button6_selector"
            android:onClick="set" />
    </LinearLayout>

    <LinearLayout
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:orientation="horizontal" >

      <Button
            android:id="@+id/Button7"
            android:layout_width="105dp"
            android:layout_height="60dp"
            android:background="@drawable/button7_selector"
            android:onClick="set" />

      <Button
            android:id="@+id/Button8"
            android:layout_width="105dp"
            android:layout_height="60dp"
            android:background="@drawable/button8_selector"
            android:onClick="set" />

      <Button
            android:id="@+id/Button9"
            android:layout_width="match_parent"
            android:layout_height="60dp"
            android:background="@drawable/button9_selector"
            android:onClick="set" />
    </LinearLayout>

    <LinearLayout
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:orientation="horizontal" >

      <Button
            android:id="@+id/ButtonXing"
            android:layout_width="105dp"
            android:layout_height="60dp"
            android:background="@drawable/buttonx_selector"
            android:onClick="set" />

      <Button
            android:id="@+id/Button0"
            android:layout_width="105dp"
            android:layout_height="60dp"
            android:background="@drawable/button0_selector"
            android:onClick="set" />

      <Button
            android:id="@+id/ButtonJing"
            android:layout_width="match_parent"
            android:layout_height="60dp"
            android:background="@drawable/buttonj_selector"
            android:onClick="set" />
    </LinearLayout>

    <LinearLayout
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:orientation="horizontal" >

      <Button
            android:id="@+id/ButtonKong"
            android:layout_width="105dp"
            android:layout_height="60dp"
            android:background="@drawable/buttonl_selector"
            android:onClick="set" />

      <Button
            android:id="@+id/ButtonDail"
            android:layout_width="105dp"
            android:layout_height="60dp"
            android:background="@drawable/dail"
            android:onClick="set" />

      <Button
            android:id="@+id/ButtonDelete"
            android:layout_width="match_parent"
            android:layout_height="60dp"
            android:background="@drawable/buttond_selector"
            android:onClick="set" />
    </LinearLayout>

</LinearLayout>

selector选择器这是其中一个,有几个按钮我就写了几个selector,不知道怎么能用一个xml文件来控制所有按钮的高亮
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:drawable="@drawable/onel" android:state_pressed="true"/>
    <item android:drawable="@drawable/one" android:state_focused="false" android:state_pressed="false"/>
    <item android:drawable="@drawable/onel"android:state_focused="true"/>
    <item android:drawable="@drawable/one" android:state_focused="false"/>

</selector>

阎魔あい 发表于 2013-7-11 17:00:42

吾等渣渣只有仰望的份儿了。。。。

jangwooning 发表于 2013-7-11 17:05:58

阎魔あい 发表于 2013-7-11 17:00
吾等渣渣只有仰望的份儿了。。。。

嬛嬛 你埋汰我{:7_315:}

阎魔あい 发表于 2013-7-11 17:21:37

jangwooning 发表于 2013-7-11 17:05
嬛嬛 你埋汰我

我哪里埋汰你了 。。。。。。{:7_294:}冤枉我。。。。。

xywhere 发表于 2013-7-11 17:26:09

貌似你只写个界面规则只写了一个 9 是吗?
这你是想一键拨号吗? 一共就9个人?

terry 发表于 2013-7-11 18:30:51

貌似挺牛的样子,先膜拜下 {:6_194:}

terry 发表于 2013-7-11 18:31:39

貌似挺牛的样子,先膜拜下 {:6_194:}

jangwooning 发表于 2013-7-11 21:21:33

xywhere 发表于 2013-7-11 17:26
貌似你只写个界面规则只写了一个 9 是吗?
这你是想一键拨号吗? 一共就9个人?

我们这个是有个总机,总机只识别前缀码,为了不让我们记前缀码就写到里边了,先拨9就是拨打外线,其他的就是电话已经分配好的小号,直接按小号就行了,比如101是你,102是我。其他的 跟单位的座机一样

jangwooning 发表于 2013-7-11 21:39:29

xywhere 发表于 2013-7-11 17:26
貌似你只写个界面规则只写了一个 9 是吗?
这你是想一键拨号吗? 一共就9个人?

比如你的手机号1381111111然后总机那设定你的小号为101,我的手机号18111111111总机那设定小号为102,然后我们把手机系统拨号器刷成我们写的这个,这样直接 打外线就不可以了,必须打一个9然后等待总机语音提示才能拨打外线,内部的你给我打电话就按102 然后其实呼出的时候是XXXXXX前缀码+102总机就能识别是要给我打的,这样在工作的时候,单位内部的同时打电话是不花钱的,而且就算出了单位只要在北京市里都是免费的!

xywhere 发表于 2013-7-11 22:19:22

jangwooning 发表于 2013-7-11 21:39
比如你的手机号1381111111然后总机那设定你的小号为101,我的手机号18111111111总机那设定小号为102,然 ...

51664 这是 前缀码?
你这个程序已经完成所有功能了啊。。
你们公司还有总机啊。。

jangwooning 发表于 2013-7-12 08:59:52

xywhere 发表于 2013-7-11 22:19
51664 这是 前缀码?
你这个程序已经完成所有功能了啊。。
你们公司还有总机啊。。

对 那个就是前缀,恩呢有个铁通 ,电话簿搜索功能还没实现呢,就是比如你按一个1然后跟1相关的号码都显示出来那个功能

xywhere 发表于 2013-7-12 11:40:39

jangwooning 发表于 2013-7-12 08:59
对 那个就是前缀,恩呢有个铁通 ,电话簿搜索功能还没实现呢,就是比如你按一个1然后跟1相关的号码都显示 ...

那个搜索 是直接搜索name还是搜索number啊
搜通讯录?貌似有那么一个控件 能自动补全

jangwooning 发表于 2013-7-12 11:49:52

xywhere 发表于 2013-7-12 11:40
那个搜索 是直接搜索name还是搜索number啊
搜通讯录?貌似有那么一个控件 能自动补全

搜number就行,android自带一个通讯录的数据库表,里边有联系人的所有信息,我是按照这个思路来做的,现在能搜出来人, 但是显示的时候有问题,总死机!有专门找号码的控件是么?

xywhere 发表于 2013-7-12 19:50:53

jangwooning 发表于 2013-7-12 11:49
搜number就行,android自带一个通讯录的数据库表,里边有联系人的所有信息,我是按照这个思路来做的,现 ...

你意思是 只要自动补全 通讯录里面所有号码 就可以?

jangwooning 发表于 2013-7-12 21:21:01

xywhere 发表于 2013-7-12 19:50
你意思是 只要自动补全 通讯录里面所有号码 就可以?

有点模糊查询的意思,对 就是通讯录里边相关的号码和人名都显示出来

vo_ 发表于 2013-7-15 13:51:40

原来原创在这里~~~我来膜拜了~~{:6_205:}

jangwooning 发表于 2013-7-15 14:20:44

vo_ 发表于 2013-7-15 13:51
原来原创在这里~~~我来膜拜了~~

{:7_281:}表酱紫~~@vo_ 我都不好意思了,么么,爱你嬛嬛!

vo_ 发表于 2013-7-15 22:40:21

jangwooning 发表于 2013-7-15 14:20
表酱紫~~@vo_ 我都不好意思了,么么,爱你嬛嬛!

咦   你咋知道我还有个小名叫嬛嬛~~~看到你不发音乐突然来个技术贴瞬间闪亮了我的眼{:7_224:}

jangwooning 发表于 2013-7-16 09:27:22

vo_ 发表于 2013-7-15 22:40
咦   你咋知道我还有个小名叫嬛嬛~~~看到你不发音乐突然来个技术贴瞬间闪亮了我的眼

嬛嬛,你太让我心动了{:7_281:}我一发音乐帖 他们都不了解我的心情啊~就埋汰我说是水贴

vo_ 发表于 2013-7-16 12:25:21

jangwooning 发表于 2013-7-16 09:27
嬛嬛,你太让我心动了我一发音乐帖 他们都不了解我的心情啊~就埋汰我说是水贴

我不会告诉你我把你发的音乐听着还不错的都收到了我的音乐收藏列表里,{:6_189:}再接再厉    多发好音乐~~{:6_167:}

jangwooning 发表于 2013-7-16 15:00:25

vo_ 发表于 2013-7-16 12:25
我不会告诉你我把你发的音乐听着还不错的都收到了我的音乐收藏列表里,再接再厉    多发好音乐 ...

{:7_281:}嬛嬛,朕太爱你了~妥妥儿的了~不管那帮万恶的版主怎么说我 水贴了,我都要发 哇哈哈!么么给你个帅哥的香吻!嬛嬛 难道你也是电信的么?{:7_282:}

vo_ 发表于 2013-7-16 15:35:19

jangwooning 发表于 2013-7-16 15:00
嬛嬛,朕太爱你了~妥妥儿的了~不管那帮万恶的版主怎么说我 水贴了,我都要发 哇哈哈!么么给你 ...

J爱卿   你是一直在失忆中么。。还是你果然从来都认为我是男人。{:6_190:}。。俺一直是电信的啊。。从来没变过,不象你明明是电信的简介的入学年份居然还写着13软设。。叛徒啊叛徒。。要矢志不渝热爱大电信!{:7_276:}

jangwooning 发表于 2013-7-16 21:41:55

vo_ 发表于 2013-7-16 15:35
J爱卿   你是一直在失忆中么。。还是你果然从来都认为我是男人。。。俺一直是电信的啊。。从 ...

你也看 听见你的声音了么?嬛嬛,你是女的 我就不能爱了么?我恢复记忆以后发现你比@阎魔あい 嬷嬷好,所以现在我跟嬷嬷分手了,我跟你好了,我也很热爱电信的 好不好!{:7_278:}

vo_ 发表于 2013-7-17 10:09:28

jangwooning 发表于 2013-7-16 21:41
你也看 听见你的声音了么?嬛嬛,你是女的 我就不能爱了么?我恢复记忆以后发现你比@阎魔あい 嬷嬷好,所 ...

你是肿么知道的   很不错的剧情啊~~另外看你的头像和口味你好哈韩的样子啊~~~{:7_267:}你的头像是银赫不。。另外 嬷嬷阿姨看到你这么说该多桑心啊!!!{:7_264:}

jangwooning 发表于 2013-7-17 10:25:42

本帖最后由 jangwooning 于 2013-7-17 10:27 编辑

vo_ 发表于 2013-7-17 10:09
你是肿么知道的   很不错的剧情啊~~另外看你的头像和口味你好哈韩的样子啊~~~你的头像是银赫不 ...
{:7_274:}让你猜中了啊,俺们跳过佑赫的舞{:7_281:},他跟我爱好还挺像的,哈哈哈,我还哈毛呢~~~没事嬷嬷已经被我伤了他的心了!再伤一次也无妨!{:7_282:}为了你,这么做也是值得的

阎魔あい 发表于 2013-7-17 23:29:11

jangwooning 发表于 2013-7-16 21:41
你也看 听见你的声音了么?嬛嬛,你是女的 我就不能爱了么?我恢复记忆以后发现你比@阎魔あい 嬷嬷好,所 ...

见异思迁的东西!!!早就看透了你!!!!{:7_315:}

jangwooning 发表于 2013-7-18 09:15:47

阎魔あい 发表于 2013-7-17 23:29
见异思迁的东西!!!早就看透了你!!!!

谁让你不跟我好了,我苦苦央求你都 不原谅朕{:7_286:}

阎魔あい 发表于 2013-7-19 15:15:06

jangwooning 发表于 2013-7-18 09:15
谁让你不跟我好了,我苦苦央求你都 不原谅朕

央求了吗????我咋不知道。。。。。{:7_277:}

jangwooning 发表于 2013-7-20 13:34:06

阎魔あい 发表于 2013-7-19 15:15
央求了吗????我咋不知道。。。。。

{:7_280:}你看 帖子记录,你这个爱忘事的嬷嬷

阎魔あい 发表于 2013-7-20 15:50:51

jangwooning 发表于 2013-7-20 13:34
你看 帖子记录,你这个爱忘事的嬷嬷

哎呀呀~~~眼睛突然看不见了。。。。。。咋办{:7_303:}

runksun 发表于 2013-12-26 08:57:36

给楼主推荐一个网址好了~~http://www.oschina.net/code/list/43/android?show=time目测有楼主想要的东西`~~

jangwooning 发表于 2013-12-31 20:35:38

runksun 发表于 2013-12-26 08:57
给楼主推荐一个网址好了~~http://www.oschina.net/code/list/43/android?show=time目测有楼主想要的东西` ...

打不开网址啊 亲{:6_191:}

runksun 发表于 2014-1-6 01:09:25

jangwooning 发表于 2013-12-31 20:35
打不开网址啊 亲

囧不好意思啊   就是你去开源中国上,可以看一些这方面的源码。。已经开放了很多源码。。。没想到打不开(′Д`)
页: [1]
查看完整版本: android 拨号器 可用于小号互打