我们开发的是视频电话,所以既可以视频通话,可以只有音频的通话,所以底部含有两个按钮,最后一个就是删除功能,如果输入错误,我们可以删除输入的内容。

这里我们要通过重写LinearLayout来实现这部份,对应着上面的功能我们可以写一个接口来实现这些功能,如下:

  1. public interface OnDialActionListener {
  2. /**
  3. * The make call button has been pressed
  4. */
  5. void placeCall();
  6.  
  7. /**
  8. * The video button has been pressed
  9. */
  10. void placeVideoCall();
  11. /**
  12. * The delete button has been pressed
  13. */
  14. void deleteChar();
  15. /**
  16. * The delete button has been long pressed
  17. */
  18. void deleteAll();
  19. }

通过回调来在主界面实现这些功能。例如在OnClick函数中

  1. @Override
  2. public void onClick(View v) {
  3. if (actionListener != null) {
  4. int viewId = v.getId();
  5. if (viewId == R.id.dialVideoButton) {
  6. actionListener.placeVideoCall();
  7. }else if(viewId == R.id.dialButton) {
  8. actionListener.placeCall();
  9. }else if(viewId == R.id.deleteButton) {
  10. actionListener.deleteChar();
  11. }
  12. }
  13. }

我们可以通过本地的接口来实现内部函数,然后在主界面实例化这个接口并填写接口的实现方式。整体的代码如下:

  1. package com.jwzhangjie.pjsip.widgets;
  2.  
  3. import com.jwzhangjie.pjsip.R;
  4.  
  5. import android.content.Context;
  6. import android.util.AttributeSet;
  7. import android.view.Gravity;
  8. import android.view.LayoutInflater;
  9. import android.view.View;
  10. import android.view.View.OnClickListener;
  11. import android.view.View.OnLongClickListener;
  12. import android.widget.LinearLayout;
  13.  
  14. public class DialerCallBar extends LinearLayout implements OnClickListener, OnLongClickListener {
  15.  
  16. public interface OnDialActionListener {
  17. /**
  18. * The make call button has been pressed
  19. */
  20. void placeCall();
  21.  
  22. /**
  23. * The video button has been pressed
  24. */
  25. void placeVideoCall();
  26. /**
  27. * The delete button has been pressed
  28. */
  29. void deleteChar();
  30. /**
  31. * The delete button has been long pressed
  32. */
  33. void deleteAll();
  34. }
  35.  
  36. private OnDialActionListener actionListener;
  37.  
  38. public DialerCallBar(Context context) {
  39. this(context, null, 0);
  40. }
  41.  
  42. public DialerCallBar(Context context, AttributeSet attrs) {
  43. this(context, attrs, 0);
  44. }
  45.  
  46. public DialerCallBar(Context context, AttributeSet attrs, int style) {
  47. super(context, attrs);
  48. LayoutInflater inflater = LayoutInflater.from(context);
  49. inflater.inflate(R.layout.dialpad_additional_buttons, this, true);
  50. findViewById(R.id.dialVideoButton).setOnClickListener(this);
  51. findViewById(R.id.dialButton).setOnClickListener(this);
  52. findViewById(R.id.deleteButton).setOnClickListener(this);
  53. findViewById(R.id.deleteButton).setOnLongClickListener(this);
  54.  
  55. if(getOrientation() == LinearLayout.VERTICAL) {
  56. LayoutParams lp;
  57. for(int i=0; i < getChildCount(); i++) {
  58. lp = (LayoutParams) getChildAt(i).getLayoutParams();
  59. int w = lp.width;
  60. lp.width = lp.height;
  61. lp.height = w;
  62. lp.gravity = Gravity.CENTER_HORIZONTAL;
  63. // Added for clarity but not necessary
  64. getChildAt(i).setLayoutParams(lp);
  65.  
  66. }
  67. }
  68. }
  69.  
  70. /**
  71. * Set a listener for this widget actions
  72. * @param l the listener called back when some user action is done on this widget
  73. */
  74. public void setOnDialActionListener(OnDialActionListener l) {
  75. actionListener = l;
  76. }
  77.  
  78. /**
  79. * Set the action buttons enabled or not
  80. */
  81. public void setEnabled(boolean enabled) {
  82. findViewById(R.id.dialButton).setEnabled(enabled);
  83. findViewById(R.id.dialVideoButton).setEnabled(enabled);
  84. findViewById(R.id.deleteButton).setEnabled(enabled);
  85. }
  86.  
  87. @Override
  88. public void onClick(View v) {
  89. if (actionListener != null) {
  90. int viewId = v.getId();
  91. if (viewId == R.id.dialVideoButton) {
  92. actionListener.placeVideoCall();
  93. }else if(viewId == R.id.dialButton) {
  94. actionListener.placeCall();
  95. }else if(viewId == R.id.deleteButton) {
  96. actionListener.deleteChar();
  97. }
  98. }
  99. }
  100.  
  101. @Override
  102. public boolean onLongClick(View v) {
  103. if (actionListener != null) {
  104. int viewId = v.getId();
  105. if(viewId == R.id.deleteButton) {
  106. actionListener.deleteAll();
  107. v.setPressed(false);
  108. return true;
  109. }
  110. }
  111. return false;
  112. }
  113.  
  114. }

pjsip视频通信开发(上层应用)之拨号键盘下部份拨号和删除功能的更多相关文章

  1. pjsip视频通信开发(上层应用)之数字键盘的制作

    在pjsip视频通信开发(上层应用)之EditText重写中我制作了一个显示输入内容的EditText,这里将制作一个数字键盘,其实跟计算器一样,最多的就是用TableLayout来实现,内部通过权重 ...

  2. pjsip视频通信开发(上层应用)之拨号界面整体界面功能实现

    在前面的几章里面写了显示.键盘.拨号.删除功能,这里我将他们进行组合,形成一个拨号键盘全部功能.首先是布局 <LinearLayout xmlns:android="http://sc ...

  3. pjsip视频通信开发(上层应用)之EditText重写

    我们经常使用手机的打电话功能,当我们按键盘的时候,有一个地方显示我们按键的内容,当我们的手点击那个地方的时候,并没有弹出软件盘,所以我们再有数字键盘的时候,要屏蔽系统的软件盘. 我们分析一下,软件盘弹 ...

  4. pjsip视频通信开发(底层实现)之用户注册(1)

    一.PJSIP简介 对于pjsip的介绍可以看http://www.cnblogs.com/my_life/articles/2175462.html 文章,里面详细介绍了它的组成框架以及各部份的组成 ...

  5. Android IOS WebRTC 音视频开发总结(七五)-- WebRTC视频通信中的错误恢复机制

    本文主要介绍WebRTC视频通信中的错误恢复机制(我们翻译和整理的,译者:jiangpeng),最早发表在[这里] 支持原创,转载必须注明出处,欢迎关注我的微信公众号blacker(微信ID:blac ...

  6. Web实现音频、视频通信

    Google开源实时通信项目WebRTC Google正式开源了WebRTC实时通信项目,希望浏览器厂商能够将该技术内建在浏览器中,从而使Web应用开发人员能够通过HTML标签和JavaScript ...

  7. Android 串口蓝牙通信开发Java版本

    Android串口BLE蓝牙通信Java版 0. 导语 Qt on Android 蓝牙通信开发 我们都知道,在物联网中,BLE蓝牙是通信设备的关键设备.在传统的物联网应用中,无线WIFI.蓝牙和Zi ...

  8. p2p音视频通信

    今年音频没事干了,根据业务需求,调研音视频p2p通信,减小服务器压力,一切从0开始. 需要信令服务器,打洞服务器,帮助链接打通双方,实现p2p音视频通信. 服务器和客服端交互等都需要实现. 谷歌web ...

  9. 《转》iOS音频视频初级开发

    代码改变世界 Posts - 73, Articles - 0, Comments - 1539 Cnblogs Dashboard Logout HOME CONTACT GALLERY RSS   ...

随机推荐

  1. Delphi or函数的用法

    function GetFlag(a: string): Integer;var I: Integer;begin Result := 0; for I := 0 to 3 - 1 do begin ...

  2. 锋利的jQuery读书笔记---jQuery中的事件

    jQuery中的事件: 1.加载DOM:注意window.onload和$(document).ready()的不同 2.事件绑定 3.合成事件 --2和3的详细信息见代码- <!DOCTYPE ...

  3. View.VISIBLE、INVISIBLE、GONE的区别

    android中UI应用的开发中经常会使用view.setVisibility()来设置控件的可见性,其中该函数有3个可选值,他们有着不同的含义: View.VISIBLE--->可见View. ...

  4. 《Python CookBook2》 第一章 文本 - 检查字符串中是否包含某字符集合中的字符 && 简化字符串的translate方法的使用

    检查字符串中是否包含某字符集合中的字符  任务: 检查字符串中是否出现了某个字符集合中的字符 解决方案: 方案一: import itertools def containAny(seq,aset): ...

  5. Windows安装pomelo过程

    安装总要出点状况的.操作系统是win7 64bit. 为了保证顺利,打开的是VS2012命令行提示.运行 npm install -g pomelo 经过一系列输出,最后安装提示完成了.但是输入 po ...

  6. oracle检查点checkpoint信息

    1.关于checkpoint的概述 checkpoint是oracle在数据库一致性关闭.实例恢复和oracle基本操作中不可缺少的机制,包含以下相关的含义: A.检查点的位置(checkpoint ...

  7. c++ 概念及学习/c++ concept&learning(三)

    这一篇继续说说程序设计中的基本语句:控制块 一 if类控制语句 if if else if  , else if ,else if(条件语句){如果条件为真,要做的一些事情}  if(条件语句) {如 ...

  8. python编码问题的理解与解决

    错误:'ascii' codec can't encode characters in position 0-1: ordinal not in range(128) 看到网上很多都不清楚,做了一天的 ...

  9. as3 中trace() 函数对效率的影响

    进行页游开发的过程中,很多开发者都有一个习惯,在数据输出中添加trace()函数来跟踪数值 - 不进行条件编译,发布的时候也不删除.实际上大量的trace函数会降低程序的效率,我们可以用一个简单的例子 ...

  10. URL的格式scheme

    url scheme: scheme + (://) + userinfo + (@) + hostname + (:) + port + path + (?) + query + (#) + fra ...