pjsip视频通信开发(上层应用)之数字键盘的制作
在pjsip视频通信开发(上层应用)之EditText重写中我制作了一个显示输入内容的EditText,这里将制作一个数字键盘,其实跟计算器一样,最多的就是用TableLayout来实现,内部通过权重(weight)来实现布局的统一,上层实现按键事件触发回调实现内容的输出。
键盘布局:
<?xml version="1.0" encoding="utf-8"?> <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" > <TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" > <ImageButton
android:id="@+id/button1"
style="@style/DialtactsDialpadButtonStyle"
android:contentDescription="@string/description_image_button_one"
android:src="@drawable/dial_num_1" /> <ImageButton
android:id="@+id/button2"
style="@style/DialtactsDialpadButtonStyle"
android:contentDescription="@string/description_image_button_two"
android:src="@drawable/dial_num_2" /> <ImageButton
android:id="@+id/button3"
style="@style/DialtactsDialpadButtonStyle"
android:contentDescription="@string/description_image_button_three"
android:src="@drawable/dial_num_3" />
</TableRow> <TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" > <ImageButton
android:id="@+id/button4"
style="@style/DialtactsDialpadButtonStyle"
android:contentDescription="@string/description_image_button_four"
android:src="@drawable/dial_num_4" /> <ImageButton
android:id="@+id/button5"
style="@style/DialtactsDialpadButtonStyle"
android:contentDescription="@string/description_image_button_five"
android:src="@drawable/dial_num_5" /> <ImageButton
android:id="@+id/button6"
style="@style/DialtactsDialpadButtonStyle"
android:contentDescription="@string/description_image_button_six"
android:src="@drawable/dial_num_6" />
</TableRow> <TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" > <ImageButton
android:id="@+id/button7"
style="@style/DialtactsDialpadButtonStyle"
android:contentDescription="@string/description_image_button_seven"
android:src="@drawable/dial_num_7" /> <ImageButton
android:id="@+id/button8"
style="@style/DialtactsDialpadButtonStyle"
android:contentDescription="@string/description_image_button_eight"
android:src="@drawable/dial_num_8" /> <ImageButton
android:id="@+id/button9"
style="@style/DialtactsDialpadButtonStyle"
android:contentDescription="@string/description_image_button_nine"
android:src="@drawable/dial_num_9" />
</TableRow> <TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" > <ImageButton
android:id="@+id/buttonstar"
style="@style/DialtactsDialpadButtonStyle"
android:contentDescription="@string/description_image_button_star"
android:src="@drawable/dial_num_star" /> <ImageButton
android:id="@+id/button0"
style="@style/DialtactsDialpadButtonStyle"
android:contentDescription="@string/description_image_button_zero"
android:src="@drawable/dial_num_0" /> <ImageButton
android:id="@+id/buttonpound"
style="@style/DialtactsDialpadButtonStyle"
android:contentDescription="@string/description_image_button_pound"
android:src="@drawable/dial_num_pound" />
</TableRow> </TableLayout>
显示效果如下:
布局设置好之后,我们就要调用布局,设置监听实现回调。
package com.jwzhangjie.pjsip.widgets; import java.util.HashMap;
import java.util.Map; import com.jwzhangjie.pjsip.R; import android.annotation.SuppressLint;
import android.content.Context;
import android.media.ToneGenerator;
import android.util.AttributeSet;
import android.util.SparseArray;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.widget.FrameLayout;
import android.widget.ImageButton; public class Dialpad extends FrameLayout implements OnClickListener { private OnDialKeyListener onDialKeyListener; public Dialpad(Context context) {
super(context);
initLayout(context);
} public Dialpad(Context context, AttributeSet attrs) {
super(context, attrs);
initLayout(context);
} private void initLayout(Context context) {
LayoutInflater inflater = LayoutInflater.from(context);
inflater.inflate(R.layout.dialpad, this, true);
} // Here we need a map to quickly find if the clicked button id is in the map
// keys,之所以这里不用SparseArrays,因为下面取值的方便
@SuppressLint("UseSparseArrays")
private static final Map<Integer, int[]> DIGITS_BTNS = new HashMap<Integer, int[]>();
static {
DIGITS_BTNS.put(R.id.button0, new int[] { ToneGenerator.TONE_DTMF_0,
KeyEvent.KEYCODE_0 });
DIGITS_BTNS.put(R.id.button1, new int[] { ToneGenerator.TONE_DTMF_1,
KeyEvent.KEYCODE_1 });
DIGITS_BTNS.put(R.id.button2, new int[] { ToneGenerator.TONE_DTMF_2,
KeyEvent.KEYCODE_2 });
DIGITS_BTNS.put(R.id.button3, new int[] { ToneGenerator.TONE_DTMF_3,
KeyEvent.KEYCODE_3 });
DIGITS_BTNS.put(R.id.button4, new int[] { ToneGenerator.TONE_DTMF_4,
KeyEvent.KEYCODE_4 });
DIGITS_BTNS.put(R.id.button5, new int[] { ToneGenerator.TONE_DTMF_5,
KeyEvent.KEYCODE_5 });
DIGITS_BTNS.put(R.id.button6, new int[] { ToneGenerator.TONE_DTMF_6,
KeyEvent.KEYCODE_6 });
DIGITS_BTNS.put(R.id.button7, new int[] { ToneGenerator.TONE_DTMF_7,
KeyEvent.KEYCODE_7 });
DIGITS_BTNS.put(R.id.button8, new int[] { ToneGenerator.TONE_DTMF_8,
KeyEvent.KEYCODE_8 });
DIGITS_BTNS.put(R.id.button9, new int[] { ToneGenerator.TONE_DTMF_9,
KeyEvent.KEYCODE_9 });
DIGITS_BTNS.put(R.id.buttonpound, new int[] {
ToneGenerator.TONE_DTMF_P, KeyEvent.KEYCODE_POUND });
DIGITS_BTNS.put(R.id.buttonstar, new int[] { ToneGenerator.TONE_DTMF_S,
KeyEvent.KEYCODE_STAR });
}; /**
* SparseArray这个是android提供的,可以替换HashMap,来提高效率
*/
private static final SparseArray<String> DIGITS_NAMES = new SparseArray<String>(); static {
DIGITS_NAMES.put(R.id.button0, "0");
DIGITS_NAMES.put(R.id.button1, "1");
DIGITS_NAMES.put(R.id.button2, "2");
DIGITS_NAMES.put(R.id.button3, "3");
DIGITS_NAMES.put(R.id.button4, "4");
DIGITS_NAMES.put(R.id.button5, "5");
DIGITS_NAMES.put(R.id.button6, "6");
DIGITS_NAMES.put(R.id.button7, "7");
DIGITS_NAMES.put(R.id.button8, "8");
DIGITS_NAMES.put(R.id.button9, "9");
DIGITS_NAMES.put(R.id.buttonpound, "pound");
DIGITS_NAMES.put(R.id.buttonstar, "star");
}; public interface OnDialKeyListener { /**
* Called when the user make an action
*
* @param keyCode
* keyCode pressed
* @param dialTone
* corresponding dialtone
*/
void onTrigger(int keyCode, int dialTone);
} @Override
protected void onFinishInflate() {
super.onFinishInflate(); for (int buttonId : DIGITS_BTNS.keySet()) {
ImageButton button = (ImageButton) findViewById(buttonId);
if (button != null) {
button.setOnClickListener(this);
}
}
} /**
* Registers a callback to be invoked when the user triggers an event.
*
* @param listener
* the OnTriggerListener to attach to this view
*/
public void setOnDialKeyListener(OnDialKeyListener listener) {
onDialKeyListener = listener;
} private void dispatchDialKeyEvent(int buttonId) {
if (onDialKeyListener != null && DIGITS_BTNS.containsKey(buttonId)) {
int[] datas = DIGITS_BTNS.get(buttonId);
onDialKeyListener.onTrigger(datas[1], datas[0]);
}
} @Override
public void onClick(View v) {
dispatchDialKeyEvent(v.getId());
}
}
我们看看上面的代码:
1、initLayout来解析布局之后
2、onFinishInflate来设置按钮的点击事件
3、onClick处理点击事件,通过dispatchDialKeyEvent来实现分发事件
4、dispatchDialKeyEvent来根据不同的id,来设置回调onDialKeyListener.onTrigger,所以在实现Dialpad后,要实现OnDialKeyListener接口
pjsip视频通信开发(上层应用)之数字键盘的制作的更多相关文章
- pjsip视频通信开发(上层应用)之拨号键盘下部份拨号和删除功能
我们开发的是视频电话,所以既可以视频通话,可以只有音频的通话,所以底部含有两个按钮,最后一个就是删除功能,如果输入错误,我们可以删除输入的内容. 这里我们要通过重写LinearLayout来实现这部份 ...
- pjsip视频通信开发(上层应用)之拨号界面整体界面功能实现
在前面的几章里面写了显示.键盘.拨号.删除功能,这里我将他们进行组合,形成一个拨号键盘全部功能.首先是布局 <LinearLayout xmlns:android="http://sc ...
- pjsip视频通信开发(上层应用)之EditText重写
我们经常使用手机的打电话功能,当我们按键盘的时候,有一个地方显示我们按键的内容,当我们的手点击那个地方的时候,并没有弹出软件盘,所以我们再有数字键盘的时候,要屏蔽系统的软件盘. 我们分析一下,软件盘弹 ...
- pjsip视频通信开发(底层实现)之用户注册(1)
一.PJSIP简介 对于pjsip的介绍可以看http://www.cnblogs.com/my_life/articles/2175462.html 文章,里面详细介绍了它的组成框架以及各部份的组成 ...
- Android IOS WebRTC 音视频开发总结(七五)-- WebRTC视频通信中的错误恢复机制
本文主要介绍WebRTC视频通信中的错误恢复机制(我们翻译和整理的,译者:jiangpeng),最早发表在[这里] 支持原创,转载必须注明出处,欢迎关注我的微信公众号blacker(微信ID:blac ...
- Web实现音频、视频通信
Google开源实时通信项目WebRTC Google正式开源了WebRTC实时通信项目,希望浏览器厂商能够将该技术内建在浏览器中,从而使Web应用开发人员能够通过HTML标签和JavaScript ...
- 【转】基于V4L2的视频驱动开发
编写基于V4L2视频驱动主要涉及到以下几个知识点:1> 摄像头方面的知识 要了解选用的摄像头的特性,包括访问控制方法.各种参数的配置方法.信号输出类型等.2> Camera解码器.控制器 ...
- Android 串口蓝牙通信开发Java版本
Android串口BLE蓝牙通信Java版 0. 导语 Qt on Android 蓝牙通信开发 我们都知道,在物联网中,BLE蓝牙是通信设备的关键设备.在传统的物联网应用中,无线WIFI.蓝牙和Zi ...
- 基于V4L2的视频驱动开发【转】
转自:http://blog.chinaunix.net/uid-10747583-id-298573.html Tags:V4L2驱动框架.API.操作流程…… 原文地址:http://www.ee ...
随机推荐
- w3c盒子模型与ie盒子模型
盒子模型是css的专有名词,用来描述页面设置中的各种属性,如内容(content).填充(padding).边框(border).边界(margin),由于这些属性拼在一起,与日常生活中的“盒子”很相 ...
- delphi实现ado的高级功能
ADO是Microsoft存取通用数据源的标准引擎.ADO通过封装OLE DB而能够存取不同类型的数据,让应用程序能很方便地通过统一的接口处理各种数据库.ADO由一组COM对象组成,每一个不同的原生A ...
- Oracle数据库中的违规策略规则的修正
如笔者计算机上违规的策略与规则: 为了安全,可如下方式对齐进行修正:
- 《Python CookBook2》 第一章 文本 - 检查字符串中是否包含某字符集合中的字符 && 简化字符串的translate方法的使用
检查字符串中是否包含某字符集合中的字符 任务: 检查字符串中是否出现了某个字符集合中的字符 解决方案: 方案一: import itertools def containAny(seq,aset): ...
- 【转载】cocos2d-x教程 Mac系统下搭建Lua的编码环境
原文链接:http://blog.csdn.net/u012945598/article/details/17168831 在使用Lua写脚本的时候大家都会因为没有代码提示导致敲代码的效率有所下降 ...
- Python对象体系揭秘
Guido用C语言创造了Python,在Python的世界中一切皆为对象. 一.C视角中的Python对象 让我们一起追溯到源头,Python由C语言实现,且向外提供了C的API http://doc ...
- oc_转_类的数组的实现和操作
OC的数组对象的基本方法的使用:因为OC的数组中存储的为对象类型,所以我们可以新建一个Person类,通过Person生成对象进行操作. 其中Person.h中的代码为: 01.#import&l ...
- jQuery/CSS3大屏下拉菜单 自定义子菜单内容
这是一款样式很酷的jQuery/CSS3下拉菜单,首先这款CSS3菜单是宽屏的,主要是下拉菜单非常大气,更重要的是,下拉菜单的内容可以自己定义,也就是说,下拉菜单中可以定义菜单.图片等HTML元素,是 ...
- Ruby多字节字符的设计
Perl.Python的多字节字符处理方式是UCS(Universal Code Set),Ruby的多字节字符处理方式是CSI(Code Set Independent).UCS的做法是,不管你读取 ...
- Directory.GetCurrentDirectory
1.一个应用程序中,Directory.GetCurrentDirectory获得的当前工作目录是C:\Windows\System32,这是为什么呢?是如何设置的? 2.在WinXP下:System ...