短信ui--会话编辑界面(四)BottomPanel

来源:互联网 发布:windows编程视频教程 编辑:程序博客网 时间:2024/06/03 21:51
短信ui--会话编辑界面(四)BottomPanel

1、前言

     前面的文章简单介绍了接收者ui以及短信历史记录,下面讲解BottomPanel,该ui如下图所示
  

  该ui比较简单,ui主要是短信编辑框、短信模版按钮、以及sendbutton。

2、功能简析

2.1 ui布局

<LinearLayout                android:id="@+id/bottom_panel"                android:orientation="horizontal"                android:layout_width="match_parent"                android:layout_height="wrap_content"                android:paddingTop="5dip"                android:paddingBottom="5dip"                android:paddingLeft="5dip"                android:paddingRight="5dip"                android:background="@drawable/bottombar_landscape_565">                <RelativeLayout android:layout_height="match_parent"                     android:layout_width="wrap_content"                     android:layout_weight="1.0"                    android:orientation="horizontal"                    android:id="@+id/relativeLayout1">                    <EditText                        android:id="@+id/embedded_text_editor"                    android:layout_width="match_parent"                    android:layout_height="wrap_content"                    android:layout_weight="1.0"                   文本编辑框                    android:autoText="true"                    android:capitalize="sentences"                    android:nextFocusRight="@+id/send_button"                    android:hint="@string/type_to_compose_text_enter_to_send"                    android:maxLines="3"                    android:inputType="textShortMessage|textAutoCorrect|textCapSentences|textMultiLine"                    android:imeOptions="actionSend|flagNoEnterAction"                    android:background="@android:drawable/edit_text"                    android:maxLength="2000"                />                    <ImageButton                    android:id="@+id/smstemp_button"                    android:layout_marginTop="1dip"                    android:layout_marginBottom="3dip"      短信模版按钮                    android:layout_width="wrap_content"                    android:layout_height="wrap_content"                                           android:layout_alignRight="@id/embedded_text_editor"                                           android:src="@drawable/import_sms_template"                />                </RelativeLayout>                <LinearLayout                    android:id="@+id/button_with_counter"                    android:orientation="vertical"                    android:layout_width="wrap_content"                    android:layout_height="match_parent" >                    <Button                        android:id="@+id/send_button"                        android:layout_marginLeft="5dip"                        android:layout_width="wrap_content"                        android:layout_height="0dip"                        android:layout_weight="1.0"            发送按钮                        style="?android:attr/buttonStyle"                        android:nextFocusLeft="@+id/embedded_text_editor"                        android:text="@string/send"                    />                    <TextView                        android:id="@+id/text_counter"                        android:layout_width="match_parent"                        android:layout_height="wrap_content"                        android:gravity="center_horizontal|bottom"                        android:textColor="#ffffffff"                        android:textSize="11sp"             短信计数器                        android:textStyle="bold"                        android:paddingLeft="3dip"                        android:paddingRight="3dip"                        android:paddingBottom="5dip"                        android:visibility="gone"                    />                </LinearLayout>            </LinearLayout>
对于上述布局文件,没有太多可讲的。

2.2 功能分析

2.2.1 文本编辑框

initResourceRefs()初始化
     mTextEditor = (EditText) findViewById(R.id.embedded_text_editor);        mTextEditor.setOnEditorActionListener(this);        mTextEditor.addTextChangedListener(mTextEditorWatcher);        mTextEditor.setOnCreateContextMenuListener(mEditSMSMenuCreateListener);        mTextEditor.setFilters(new InputFilter[] {                new LengthFilter(MmsConfig.getMaxTextLimit())});

2.2.2 发送按钮

发送按钮点击事件,
   if ((v == mSendButton) && isPreparedForSending()) {            confirmSendMessageIfNeeded();        }
这里就开始了发送短彩信。

2.2.3 短信计数器

 这里要是更新计数器其核心代码如下
    private void updateCounter(CharSequence text, int start, int before, int count) {        WorkingMessage workingMessage = mWorkingMessage;        if (workingMessage.requiresMms()) {            // If we're not removing text (i.e. no chance of converting back to SMS            // because of this change) and we're in MMS mode, just bail out since we            // then won't have to calculate the length unnecessarily.            final boolean textRemoved = (before > count);            if (!textRemoved) {                setSendButtonText(workingMessage.requiresMms());                return;            }        }        String msg = text.toString();        SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);        if (sp.getBoolean("pref_key_enable_signature", false)) {            String signature = sp.getString("pref_key_edit_signature", "");            if (signature.trim().length() > 0) {                msg += " "+signature.trim();            }        }        int[] params = SmsMessage.calculateLength(msg, false);            /* SmsMessage.calculateLength returns an int[4] with:             *   int[0] being the number of SMS's required,             *   int[1] the number of code units used,             *   int[2] is the number of code units remaining until the next message.             *   int[3] is the encoding type that should be used for the message.             */        int msgCount = params[0];        int remainingInCurrentMessage = params[2];        if (!MmsConfig.getMultipartSmsEnabled()) {            mWorkingMessage.setLengthRequiresMms(                    msgCount >= MmsConfig.getSmsToMmsTextThreshold(), true);        }        // Show the counter only if:        // - We are not in MMS mode        // - We are going to send more than one message OR we are getting close        boolean showCounter = false;        if (!workingMessage.requiresMms() &&                (msgCount > 1 ||                 remainingInCurrentMessage <= CHARS_REMAINING_BEFORE_COUNTER_SHOWN)) {            showCounter = true;        }        setSendButtonText(workingMessage.requiresMms());        if (showCounter) {            // Update the remaining characters and number of messages required.            String counterText = msgCount > 1 ? remainingInCurrentMessage + " / " + msgCount                    : String.valueOf(remainingInCurrentMessage);            mTextCounter.setText(counterText);            mTextCounter.setVisibility(View.VISIBLE);        } else {            mTextCounter.setVisibility(View.GONE);        }    }

3、总结

      该ui没有太多内容,解析到现在为止,短信ui部分的难点还有一个就是短信附件编辑和添加,短信附件的难点以及它们实现的原理请关注下文。






  
原创粉丝点击