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

来源:互联网 发布:appstore日本福利软件 编辑:程序博客网 时间:2024/05/20 23:05

在前面的几章里面写了显示、键盘、拨号、删除功能,这里我将他们进行组合,形成一个拨号键盘全部功能。首先是布局

<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=".SipHome" > <RelativeLayout        android:id="@+id/topField"        android:layout_width="fill_parent"        android:layout_height="0dip"        android:layout_marginBottom="0dip"        android:layout_weight="@integer/dialpad_layout_weight_digits"        android:background="@drawable/dialpad_background"        android:orientation="horizontal"        android:padding="0dip" >        <com.jwzhangjie.pjsip.ui.dialpad.DigitsEditText            android:id="@+id/digitsText"            android:layout_width="match_parent"            android:layout_height="match_parent"            android:background="@android:color/transparent"            android:contentDescription="@string/description_digits_edittext"            android:gravity="center"            android:imeActionLabel="@string/call"            android:imeOptions="actionGo"            android:nextFocusRight="@+id/accountChooserButton"            android:textAppearance="@style/DialtactsDigitsTextAppearance"            android:textColor="@android:color/white" />    </RelativeLayout>    <include layout="@layout/dialpad_compose_3x5" /></LinearLayout>

dialpad_compose_3x5:

<?xml version="1.0" encoding="utf-8"?><merge xmlns:android="http://schemas.android.com/apk/res/android" >    <com.jwzhangjie.pjsip.widgets.Dialpad        android:id="@+id/dialPad"        android:layout_width="match_parent"        android:layout_height="0dip"        android:layout_gravity="center_horizontal"        android:layout_weight="@integer/dialpad_layout_weight_dialpad"        android:background="@drawable/dialpad_background"        android:paddingBottom="10dip"        android:paddingLeft="5dip"        android:paddingRight="5dip" />    <View        android:layout_width="match_parent"        android:layout_height="@dimen/dialpad_vertical_margin"        android:background="#66000000" />    <com.jwzhangjie.pjsip.widgets.DialerCallBar        android:id="@+id/dialerCallBar"        android:layout_width="match_parent"        android:layout_height="0dip"        android:layout_gravity="center_horizontal"        android:layout_weight="@integer/dialpad_layout_weight_additional_buttons"        android:background="@drawable/dialpad_background"        android:orientation="horizontal" /></merge>
代码如下:
package com.jwzhangjie.pjsip.ui;import com.jwzhangjie.pjsip.R;import com.jwzhangjie.pjsip.ui.dialpad.DigitsEditText;import com.jwzhangjie.pjsip.widgets.DialerCallBar;import com.jwzhangjie.pjsip.widgets.DialerCallBar.OnDialActionListener;import com.jwzhangjie.pjsip.widgets.Dialpad;import com.jwzhangjie.pjsip.widgets.Dialpad.OnDialKeyListener;import android.os.Bundle;import android.text.Editable;import android.text.Selection;import android.text.TextWatcher;import android.text.method.DialerKeyListener;import android.view.KeyEvent;import android.view.Menu;import android.view.View;import android.view.View.OnClickListener;import android.view.View.OnLongClickListener;import android.view.inputmethod.EditorInfo;import android.widget.ImageButton;import android.widget.TextView;import android.widget.TextView.OnEditorActionListener;public class SipHome extends SipBase implements OnClickListener,OnLongClickListener, OnDialKeyListener, TextWatcher,OnDialActionListener {private DigitsEditText digits;//显示数字private String initText = null;private Dialpad dialPad;//数字键盘private DialerCallBar callBar;//数字键盘下面的,视频电话拨号,电话拨号,删除拨号内容private final int[] buttonsToLongAttach = new int[] { R.id.button0,R.id.button1 };@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_sip_home);initCompontent();initListener();}private void initCompontent() {digits = (DigitsEditText) findViewById(R.id.digitsText);dialPad = (Dialpad) findViewById(R.id.dialPad);callBar = (DialerCallBar) findViewById(R.id.dialerCallBar);}private void initListener() {digits.setKeyListener(DialerKeyListener.getInstance());digits.addTextChangedListener(this);digits.setCursorVisible(false);dialPad.setOnDialKeyListener(this);digits.setOnEditorActionListener(keyboardActionListener);for (int buttonId : buttonsToLongAttach) {attachButtonListener(buttonId, true);}callBar.setOnDialActionListener(this);}@Overridepublic boolean onCreateOptionsMenu(Menu menu) {getMenuInflater().inflate(R.menu.sip_home, menu);return true;}/** * Set the value of the text field and put caret at the end * @param value *            the new text to see in the text field */public void setTextFieldValue(CharSequence value) {if (digits == null) {initText = value.toString();return;}digits.setText(value);// make sure we keep the caret at the end of the text viewEditable spannable = digits.getText();Selection.setSelection(spannable, spannable.length());}/* *  数字键盘的回调函数 *  * @see com.jwzhangjie.pjsip.widgets.Dialpad.OnDialKeyListener#onTrigger(int, int) */@Overridepublic void onTrigger(int keyCode, int dialTone) {keyPressed(keyCode);}/** * 将键盘内容输入到显示框中 * @param keyCode */private void keyPressed(int keyCode) {KeyEvent event = new KeyEvent(KeyEvent.ACTION_DOWN, keyCode);digits.onKeyDown(keyCode, event);}@Overridepublic boolean onLongClick(View v) {int vId = v.getId();if (vId == R.id.button0) {//删除键盘按键的内容,长按一次性删除keyPressed(KeyEvent.KEYCODE_PLUS);return true;} else if (vId == R.id.button1) {if (digits.length() == 0) {return true;}}return false;}@Overridepublic void onClick(View v) {switch (v.getId()) {case R.id.button0:break;case R.id.button1:digits.setText(null);break;}}private void attachButtonListener(int id, boolean longAttach) {ImageButton button = (ImageButton) findViewById(id);if (button == null) {return;}if (longAttach) {button.setOnLongClickListener(this);} else {button.setOnClickListener(this);}}private OnEditorActionListener keyboardActionListener = new OnEditorActionListener() {@Overridepublic boolean onEditorAction(TextView tv, int action, KeyEvent arg2) {if (action == EditorInfo.IME_ACTION_GO) {return true;}return false;}};@Overridepublic void afterTextChanged(Editable arg0) {}@Overridepublic void beforeTextChanged(CharSequence arg0, int arg1, int arg2,int arg3) {}@Overridepublic void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {afterTextChanged(digits.getText());}/** * 不含视频的通话 */@Overridepublic void placeCall() {}/** * 含有视频的通话 */@Overridepublic void placeVideoCall() {}/** * 删除一个字符 */@Overridepublic void deleteChar() {keyPressed(KeyEvent.KEYCODE_DEL);}/** * 删除所有的字符 */@Overridepublic void deleteAll() {digits.getText().clear();}}

最终的显示效果如下:


输入内容的界面:


删除内容的界面:



原创粉丝点击