短信ui-会话编辑界面(一) 初识

会话编辑界面(一)

1、前言

      与短信会话界面一样是短信UI中重要的部分,它比短信会话界面更复杂,由于它包含了短信和彩信两部分,虽然会话界面也是短彩信公共的,但由于新建会话界面涉及到彩信附件的添加、删除、替换以及短彩信的相互转换等等功能。基于该界面的复杂性,大致分为4快来讲解该界面,一是查询显示该会话已经存在的短彩信;二是添加新的短彩信;三是长按某短信息的长按menu;四是menu;要讲解这四块内容首先会介绍主界面的布局文件,以及涉及的类。

2、涉及的类


这里只列举了其中特别重要的几个类,没有完全列举.从上面的类来看有关幻灯片相关都是以Slid开头的类,下面简单的做了一个类图来说明它们的关系,关于Slide这块还有一些比较重要的类上面没有列表,在类图中分别作了做了简单介绍。

2.1 附件view的类图


2.2 主界面相关类图


从上图可以看到主界面要完成ui的绘制以及短信的添加、短彩信的发送功能,实际上还需要很多类协同工作。

2.3 Model 类

   这里还剩下一个特别重要的类图,那就是将附件中的元素如Image、vedio、audio等抽象成了一个model,这里就简单的看看这些类之间的关系,有助于我们队对彩信附件的理解。



这里有一个SlideShowModel、SlideModel,大家肯定奇怪了这两个长得这么像双胞胎,那其实他们的关系有点暧昧。SlideShowModel它代表的是所有的幻灯片,就是一个装幻灯片的容器;SlideModel一个幻灯片,一个幻灯片又可以添加image、audio、vedio等。

3、UI总体布局

   通过上述类图,我们可以大致了解到会话编辑界面涉及到的相关的类以及他们之间的复杂关系,会话编辑界面分为两种情况:一是新建一个会话,二是编辑已存在的会话,但他们的实现都是有ComposeMessageActivity类来完成的。
                  
                 图1,新建会话界面                                                                图2 ,打开已存在会话界面
    从上面的图片可以看出新建会话界面和打开已存在的会话界面区别在于:已存在的会话界面会去加载历史记录以及他们的发送者/接收者UI被隐藏,代替的使用title来显示发送者/接收者的号码,而新建回话需要用户编辑接收者。那从代码上是怎么区分的?实现的类都是一样。

3.1 接收者/发送者 UI

     ComposeMessageActivity是根据什么来判断当前是打开已存在的还是新建,这里有一点小的涉及技巧,首先在xml布局文件中声明该UI默认是gone,然后在ComposeMessageActivity的onCreate方法做以下判断:
  1. // Show the recipients editor if we don't have a valid thread. Hide it otherwise. 
  2.     if (mConversation.getThreadId() <= 0) { 
  3.         // Hide the recipients editor so the call to initRecipientsEditor won't get 
  4.         // short-circuited. 
  5.         hideRecipientEditor(); 
  6.         initRecipientsEditor(); 
  7.       
  8.         // Bring up the softkeyboard so the user can immediately enter recipients. This 
  9.         // call won't do anything on devices with a hard keyboard. 
  10.         getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE | 
  11.                 WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE); 
  12.     } else { 
  13.         hideRecipientEditor(); 
  14.     } 
    // Show the recipients editor if we don't have a valid thread. Hide it otherwise.
        if (mConversation.getThreadId() <= 0) {
            // Hide the recipients editor so the call to initRecipientsEditor won't get
            // short-circuited.
            hideRecipientEditor();
            initRecipientsEditor();
         
            // Bring up the softkeyboard so the user can immediately enter recipients. This
            // call won't do anything on devices with a hard keyboard.
            getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE |
                    WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
        } else {
            hideRecipientEditor();
        }
从上述代码你可以看到的是google工程师是通过判断当前会话的ThreadID,那如果是新建的threadId肯定小于0,如果是已存在的其id肯定大于0。可以看到的是小于0时,表示是新建,做了三个操作:一个是隐藏,接收者UI,然后重新初始化该UI,这里有一点小小的疑惑,为什么先要隐藏然后重新初始化?这个问题留给大家,最后了将输入键盘弹出来。然后大于0表示该会话存在,这里就是隐藏接收者UI。
         大家又要问了那当前activity的title什么时候设置的??
  1.   private void updateTitle(ContactList list) { 
  2.       String s; 
  3.       switch (list.size()) { 
  4.           case 0: { 
  5.               String recipient = ""; 
  6.               if (mRecipientsEditor != null) { 
  7.                   recipient = mRecipientsEditor.getText().toString(); 
  8.               } 
  9.               s = recipient; 
  10.               break; 
  11.           } 
  12.           case 1: { 
  13.               s = list.get(0).getNameAndNumber(); 
  14.               break; 
  15.           } 
  16.           default: { 
  17.               // Handle multiple recipients 
  18.               s = list.formatNames(", "); 
  19.               break; 
  20.           } 
  21.       } 
  22.       mDebugRecipients = list.serialize(); 
  23.       if(list.size()>1){ 
  24.       getWindow().setTitle(list.size()+":"+s); 
  25.       }else { 
  26.          getWindow().setTitle(s); 
  27.   } 
    private void updateTitle(ContactList list) {
        String s;
        switch (list.size()) {
            case 0: {
                String recipient = "";
                if (mRecipientsEditor != null) {
                    recipient = mRecipientsEditor.getText().toString();
                }
                s = recipient;
                break;
            }
            case 1: {
                s = list.get(0).getNameAndNumber();
                break;
            }
            default: {
                // Handle multiple recipients
                s = list.formatNames(", ");
                break;
            }
        }
        mDebugRecipients = list.serialize();
        if(list.size()>1){
        getWindow().setTitle(list.size()+":"+s);
        }else {
        	 getWindow().setTitle(s);
		}
    }
该方法是在onCreate方法中通过initialize来调用的
  1. // Let the working message know what conversation it belongs to 
  2.         mWorkingMessage.setConversation(mConversation); 
// Let the working message know what conversation it belongs to
        mWorkingMessage.setConversation(mConversation);
通过上面的解析,应该基本上清楚了新建和打开已存在的他们在接收者UI上的处理,非常精妙。

3.2 布局文件解析

    对于新建和打开已存在的会话关于接收者UI的不同显示做了一个简单的解析,下面了来看看该界面的布局文件。
    1)首先,再说明布局文件之前和大家来认识几个变量,不要认为几个变量无关紧要,读者要表达的是这些变量直接关系到你能否看懂它的整个实现,弄清楚这些变量是做什么的,来看布局文件你就大致清楚了。
  1. private View mTopPanel;                 // View containing the recipient and subject editors,该变量就是我们上面所说的接收者UI 
  2. private View mBottomPanel;              // View containing the text editor, send button, ec. 
  3. private EditText mTextEditor;           // Text editor to type your message into 
  4. private TextView mTextCounter;          // Shows the number of characters used in text editor 
  5. private Button mSendButton;             // Press to detonate 
  6. private EditText mSubjectTextEditor;    // Text editor for MMS subject 
  7.  
  8. private ImageView mAddRecipientButton;   添加接这button 
  9. private AttachmentEditor mAttachmentEditor;用于显示附件 
  10.  
  11. private MessageListView mMsgListView;        // ListView for messages in this conversation 
  12. public MessageListAdapter mMsgListAdapter;  // and its corresponding ListAdapter 
  13.  
  14. private ImageButton mSmsTemplateButton;      // Button used to import template message. 
  15. private RecipientsEditor mRecipientsEditor;  // UI control for editing recipients 
  16. private TextView mCountDownTimerText;   用于对字符的计数 
  17. private WorkingMessage mWorkingMessage; 用于存储一条当前短信的信息,包含接收者、短信内容等等 
  18. private Conversation mConversation; 表示当前编辑的会话 
    private View mTopPanel;                 // View containing the recipient and subject editors,该变量就是我们上面所说的接收者UI
    private View mBottomPanel;              // View containing the text editor, send button, ec.
    private EditText mTextEditor;           // Text editor to type your message into
    private TextView mTextCounter;          // Shows the number of characters used in text editor
    private Button mSendButton;             // Press to detonate
    private EditText mSubjectTextEditor;    // Text editor for MMS subject

    private ImageView mAddRecipientButton;   添加接这button
    private AttachmentEditor mAttachmentEditor;用于显示附件

    private MessageListView mMsgListView;        // ListView for messages in this conversation
    public MessageListAdapter mMsgListAdapter;  // and its corresponding ListAdapter

    private ImageButton mSmsTemplateButton;      // Button used to import template message.
    private RecipientsEditor mRecipientsEditor;  // UI control for editing recipients
    private TextView mCountDownTimerText;   用于对字符的计数
    private WorkingMessage mWorkingMessage; 用于存储一条当前短信的信息,包含接收者、短信内容等等
    private Conversation mConversation; 表示当前编辑的会话

     2)了解上面这些变量后,我们再来看布局文件,通过看布局文件我们可以很清楚清晰的明白这些ui组件怎么放置的

  1. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
  2.     android:layout_width="match_parent" 
  3.     android:layout_height="match_parent" 
  4.     android:background="@drawable/white_background" 
  5.     android:orientation="vertical"> 
  6. <!-----------接收者UI--------------------------------------------------> 
  7.     <LinearLayout 
  8.         android:id="@+id/recipients_subject_linear" 
  9.         android:layout_width="match_parent" 
  10.         android:layout_height="wrap_content" 
  11.         android:paddingTop="5dip" 
  12.         android:paddingBottom="5dip" 
  13.         android:paddingLeft="5dip" 
  14.         android:paddingRight="5dip" 
  15.         android:orientation="vertical" 
  16.         android:visibility="gone"> 
  17.  
  18.         <LinearLayout 
  19.             android:layout_width="match_parent" 
  20.             android:layout_height="wrap_content" 
  21.             android:orientation="horizontal"> 
  22.  
  23.             <ViewStub android:id="@+id/recipients_editor_stub"  
  24.                 android:layout="@layout/recipients_editor" 
  25.                 android:layout_width="0dip" 
  26.                 android:layout_height="wrap_content" 
  27.                 android:layout_weight="1.0" 
  28.             /> 
  29.  
  30.             <ViewStub android:id="@+id/add_recipients_bt_stub" 
  31.                 android:layout="@layout/add_recipients_bt" 
  32.                 android:layout_width="wrap_content" 
  33.                 android:layout_height="wrap_content" 
  34.                 android:layout_marginLeft="5dip" 
  35.             /> 
  36.         </LinearLayout> 
  37.  
  38.         <EditText android:id="@+id/subject"       彩信主题 
  39.             android:layout_width="match_parent" 
  40.             android:layout_height="wrap_content" 
  41.             android:capitalize="sentences" 
  42.             android:autoText="true" 
  43.             android:singleLine="true" 
  44.             android:maxLength="40" 
  45.             android:hint="@string/subject_hint" 
  46.             android:visibility="gone"/> 
  47.     </LinearLayout> 
  48. <!---------------------end----------------------------------------> 
  49.     <LinearLayout 
  50.         android:layout_width="match_parent" 
  51.         android:layout_height="match_parent" 
  52.         android:orientation="vertical" 
  53.         android:gravity="bottom"> 
  54. <!---------------------历史记录-----------------------------------------> 
  55.         <view class="com.android.mms.ui.MessageListView" 
  56.             style="?android:attr/listViewWhiteStyle" 
  57.             android:id="@+id/history" 
  58.             android:layout_width="match_parent" 
  59.             android:layout_height="0dip" 
  60.             android:layout_weight="1.0" 
  61.             android:listSelector="@drawable/chat_history_selector" 
  62.             android:drawSelectorOnTop="true" 
  63.             android:transcriptMode="alwaysScroll" 
  64.             android:scrollbarAlwaysDrawVerticalTrack="true" 
  65.             android:scrollbarStyle="insideInset" 
  66.             android:stackFromBottom="true" 
  67.             android:visibility="gone" 
  68.             android:fadingEdge="none" 
  69.             android:layout_marginBottom="1dip" 
  70.             android:cacheColorHint="@android:color/white" 
  71.         /> 
  72.  
  73.         <LinearLayout 
  74.             android:layout_width="match_parent" 
  75.             android:layout_height="wrap_content" 
  76.             android:orientation="vertical"> 
  77. <!-----------------------附件UI----------------------------------------------------------------> 
  78.             <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
  79.                 android:layout_weight="1.0" 
  80.                 android:layout_width="match_parent" 
  81.                 android:layout_height="0dip"> 
  82.  
  83.               <view class="com.android.mms.ui.AttachmentEditor" 
  84.                   android:id="@+id/attachment_editor" 
  85.                   android:layout_width="match_parent" 
  86.                   android:layout_height="wrap_content" 
  87.                   android:orientation="vertical"> 
  88.  
  89.                   <ViewStub android:id="@+id/image_attachment_view_portrait_stub" 
  90.                       android:layout="@layout/image_attachment_view_portrait" 
  91.                       android:layout_width="match_parent" 
  92.                       android:layout_height="wrap_content"/> 
  93.  
  94.                   <ViewStub android:id="@+id/video_attachment_view_portrait_stub" 
  95.                       android:layout="@layout/video_attachment_view_portrait" 
  96.                       android:layout_width="match_parent" 
  97.                       android:layout_height="wrap_content"/> 
  98.  
  99.                   <ViewStub android:id="@+id/audio_attachment_view_portrait_stub" 
  100.                       android:layout="@layout/audio_attachment_view_portrait" 
  101.                       android:layout_width="match_parent" 
  102.                       android:layout_height="wrap_content"/> 
  103.  
  104.                   <ViewStub android:id="@+id/slideshow_attachment_view_portrait_stub" 
  105.                       android:layout="@layout/slideshow_attachment_view_portrait" 
  106.                       android:layout_width="match_parent" 
  107.                       android:layout_height="wrap_content"/> 
  108.  
  109.                   <ViewStub android:id="@+id/image_attachment_view_landscape_stub"  图像附件 
  110.                       android:layout="@layout/image_attachment_view_landscape" 
  111.                       android:layout_width="match_parent" 
  112.                       android:layout_height="wrap_content"/> 
  113.  
  114.                   <ViewStub android:id="@+id/video_attachment_view_landscape_stub"  vedio附件 
  115.                       android:layout="@layout/video_attachment_view_landscape" 
  116.                       android:layout_width="match_parent" 
  117.                       android:layout_height="wrap_content"/> 
  118.  
  119.                   <ViewStub android:id="@+id/audio_attachment_view_landscape_stub" audio 附件 
  120.                       android:layout="@layout/audio_attachment_view_landscape" 
  121.                       android:layout_width="match_parent" 
  122.                       android:layout_height="wrap_content"/> 
  123.  
  124.                   <ViewStub android:id="@+id/slideshow_attachment_view_landscape_stub" 
  125.                       android:layout="@layout/slideshow_attachment_view_landscape" 
  126.                       android:layout_width="match_parent"           幻灯片附件 
  127.                       android:layout_height="wrap_content"/> 
  128.               </view> 
  129.             </ScrollView> 
  130. <!----------------------end-------------------------------------------------------> 
  131.             <LinearLayout 
  132.                 android:id="@+id/bottom_panel" 
  133.                 android:orientation="horizontal" 
  134.                 android:layout_width="match_parent" 
  135.                 android:layout_height="wrap_content" 
  136.                 android:paddingTop="5dip" 
  137.                 android:paddingBottom="5dip" 
  138.                 android:paddingLeft="5dip" 
  139.                 android:paddingRight="5dip" 
  140.                 android:background="@drawable/bottombar_landscape_565"> 
  141. <!-----------------------关于短信发送按钮、短信模版、短信内容编辑--UI-----------------> 
  142.                 <RelativeLayout android:layout_height="match_parent"  
  143.                     android:layout_width="wrap_content"  
  144.                     android:layout_weight="1.0" 
  145.                     android:orientation="horizontal" 
  146.                     android:id="@+id/relativeLayout1"> 
  147.                  
  148.                     <EditText 
  149.                         android:id="@+id/embedded_text_editor" 短信内容编辑框 
  150.                         android:layout_width="match_parent" 
  151.                         android:layout_height="wrap_content" 
  152.                         android:layout_weight="1.0" 
  153.                         android:autoText="true" 
  154.                         android:capitalize="sentences" 
  155.                         android:nextFocusRight="@+id/send_button" 
  156.                         android:hint="@string/type_to_compose_text_enter_to_send" 
  157.                         android:maxLines="3" 
  158.                         android:inputType="textShortMessage|textAutoCorrect|textCapSentences|textMultiLine" 
  159.                         android:imeOptions="actionSend|flagNoEnterAction" 
  160.                         android:background="@android:drawable/edit_text" 
  161.                         android:maxLength="2000" 
  162.                     /> 
  163.                  
  164.                     <ImageButton 
  165.                         android:id="@+id/smstemp_button"   短信模版按钮 
  166.                         android:layout_marginTop="1dip" 
  167.                         android:layout_marginBottom="3dip" 
  168.                         android:layout_width="wrap_content" 
  169.                         android:layout_height="wrap_content"                        
  170.                         android:layout_alignRight="@id/embedded_text_editor"                        
  171.                         android:src="@drawable/import_sms_template" 
  172.                     /> 
  173.                 </RelativeLayout> 
  174.  
  175.                 <LinearLayout 
  176.                     android:id="@+id/button_with_counter" 
  177.                     android:orientation="vertical" 
  178.                     android:layout_width="wrap_content" 
  179.                     android:layout_height="match_parent" > 
  180.  
  181.                     <Button 
  182.                         android:id="@+id/send_button"             发送按钮 
  183.                         android:layout_marginLeft="5dip" 
  184.                         android:layout_width="wrap_content" 
  185.                         android:layout_height="0dip" 
  186.                         android:layout_weight="1.0" 
  187.                         style="?android:attr/buttonStyle" 
  188.                         android:nextFocusLeft="@+id/embedded_text_editor" 
  189.                         android:text="@string/send" 
  190.                     /> 
  191.  
  192.                     <TextView 
  193.                         android:id="@+id/text_counter"       文本计数 
  194.                         android:layout_width="match_parent" 
  195.                         android:layout_height="wrap_content" 
  196.                         android:gravity="center_horizontal|bottom" 
  197.                         android:textColor="#ffffffff" 
  198.                         android:textSize="11sp" 
  199.                         android:textStyle="bold" 
  200.                         android:paddingLeft="3dip" 
  201.                         android:paddingRight="3dip" 
  202.                         android:paddingBottom="5dip" 
  203.                         android:visibility="gone" 
  204.                     /> 
  205.                 </LinearLayout> 
  206.             </LinearLayout> 
  207.         </LinearLayout> 
  208.     </LinearLayout> 
  209. </LinearLayout> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/white_background"
    android:orientation="vertical">
<!-----------接收者UI-------------------------------------------------->
    <LinearLayout
        android:id="@+id/recipients_subject_linear"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingTop="5dip"
        android:paddingBottom="5dip"
        android:paddingLeft="5dip"
        android:paddingRight="5dip"
        android:orientation="vertical"
        android:visibility="gone">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

            <ViewStub android:id="@+id/recipients_editor_stub" 
                android:layout="@layout/recipients_editor"
                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:layout_weight="1.0"
            />

            <ViewStub android:id="@+id/add_recipients_bt_stub"
                android:layout="@layout/add_recipients_bt"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="5dip"
            />
        </LinearLayout>

        <EditText android:id="@+id/subject"       彩信主题
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:capitalize="sentences"
            android:autoText="true"
            android:singleLine="true"
            android:maxLength="40"
            android:hint="@string/subject_hint"
            android:visibility="gone"/>
    </LinearLayout>
<!---------------------end---------------------------------------->
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:gravity="bottom">
<!---------------------历史记录----------------------------------------->
        <view class="com.android.mms.ui.MessageListView"
            style="?android:attr/listViewWhiteStyle"
            android:id="@+id/history"
            android:layout_width="match_parent"
            android:layout_height="0dip"
            android:layout_weight="1.0"
            android:listSelector="@drawable/chat_history_selector"
            android:drawSelectorOnTop="true"
            android:transcriptMode="alwaysScroll"
            android:scrollbarAlwaysDrawVerticalTrack="true"
            android:scrollbarStyle="insideInset"
            android:stackFromBottom="true"
            android:visibility="gone"
            android:fadingEdge="none"
            android:layout_marginBottom="1dip"
            android:cacheColorHint="@android:color/white"
        />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">
<!-----------------------附件UI---------------------------------------------------------------->
            <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_weight="1.0"
                android:layout_width="match_parent"
                android:layout_height="0dip">

              <view class="com.android.mms.ui.AttachmentEditor"
                  android:id="@+id/attachment_editor"
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:orientation="vertical">

                  <ViewStub android:id="@+id/image_attachment_view_portrait_stub"
                      android:layout="@layout/image_attachment_view_portrait"
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content"/>

                  <ViewStub android:id="@+id/video_attachment_view_portrait_stub"
                      android:layout="@layout/video_attachment_view_portrait"
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content"/>

                  <ViewStub android:id="@+id/audio_attachment_view_portrait_stub"
                      android:layout="@layout/audio_attachment_view_portrait"
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content"/>

                  <ViewStub android:id="@+id/slideshow_attachment_view_portrait_stub"
                      android:layout="@layout/slideshow_attachment_view_portrait"
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content"/>

                  <ViewStub android:id="@+id/image_attachment_view_landscape_stub"  图像附件
                      android:layout="@layout/image_attachment_view_landscape"
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content"/>

                  <ViewStub android:id="@+id/video_attachment_view_landscape_stub"  vedio附件
                      android:layout="@layout/video_attachment_view_landscape"
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content"/>

                  <ViewStub android:id="@+id/audio_attachment_view_landscape_stub" audio 附件
                      android:layout="@layout/audio_attachment_view_landscape"
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content"/>

                  <ViewStub android:id="@+id/slideshow_attachment_view_landscape_stub"
                      android:layout="@layout/slideshow_attachment_view_landscape"
                      android:layout_width="match_parent"           幻灯片附件
                      android:layout_height="wrap_content"/>
              </view>
            </ScrollView>
<!----------------------end------------------------------------------------------->
            <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">
<!-----------------------关于短信发送按钮、短信模版、短信内容编辑--UI----------------->
                <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>
        </LinearLayout>
    </LinearLayout>
</LinearLayout>
这里不给大家一个一个来讲解,我想只要知道一些android ui的同胞看上面的布局文件应该没有问题

3)对照关系

      那实际上对应上面的变量,就可以猜出在布局文件中所占的位置,这里以代码为证;

  1. mMsgListView = (MessageListView) findViewById(R.id.history); 
  2. mBottomPanel = findViewById(R.id.bottom_panel); 
  3. mTextEditor = (EditText) findViewById(R.id.embedded_text_editor); 
  4. mTextCounter = (TextView) findViewById(R.id.text_counter); 
  5. mSendButton = (Button) findViewById(R.id.send_button); 
  6. mTopPanel = findViewById(R.id.recipients_subject_linear); 
  7. mAttachmentEditor = (AttachmentEditor) findViewById(R.id.attachment_editor); 
  8. mSmsTemplateButton = (ImageButton)findViewById(R.id.smstemp_button); 
        mMsgListView = (MessageListView) findViewById(R.id.history);
        mBottomPanel = findViewById(R.id.bottom_panel);
        mTextEditor = (EditText) findViewById(R.id.embedded_text_editor);
        mTextCounter = (TextView) findViewById(R.id.text_counter);
        mSendButton = (Button) findViewById(R.id.send_button);
        mTopPanel = findViewById(R.id.recipients_subject_linear);
        mAttachmentEditor = (AttachmentEditor) findViewById(R.id.attachment_editor);
        mSmsTemplateButton = (ImageButton)findViewById(R.id.smstemp_button);

这里基本上列举了对上述变量的赋值。

4、小结

     这里大致讲解了一下整个界面的一些布局元素,以及相关类之间的关系。短信会话编辑界面的具体功能,这里对于该UI来说模块比较清晰了,大致分为4块:BottomPanel(发送按钮、短信编辑框、短信模版添加按钮)、TopPanel(包含接收者编辑框和从联系人添加按钮、以及彩信主题)、MsgListView(历史记录,非常重要这里有一些细节的东西)、AttachmentEditor(彩信附件UI),后面文章会继续对每个模块进行分析。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值