pjsip视频通信开发(上层应用)之拨号界面整体界面功能实现
生活随笔
收集整理的這篇文章主要介紹了
pjsip视频通信开发(上层应用)之拨号界面整体界面功能实现
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
在前面的幾章里面寫了顯示、鍵盤、撥號、刪除功能,這里我將他們進行組合,形成一個撥號鍵盤全部功能。首先是布局
?
<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" ><RelativeLayoutandroid: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.DigitsEditTextandroid: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.Dialpadandroid: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" /><Viewandroid:layout_width="match_parent"android:layout_height="@dimen/dialpad_vertical_margin"android:background="#66000000" /><com.jwzhangjie.pjsip.widgets.DialerCallBarandroid: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();}}
最終的顯示效果如下:
?
輸入內容的界面:
刪除內容的界面:
?
轉載于:https://www.cnblogs.com/pangblog/p/3395189.html
總結
以上是生活随笔為你收集整理的pjsip视频通信开发(上层应用)之拨号界面整体界面功能实现的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: SQL Server存储过程(转载)
- 下一篇: selenium找不到元素