6-软件源码页

  • 格式:docx
  • 大小:43.08 KB
  • 文档页数:7

文件名:MainActivity.java作用:软件主界面源码:package com.example.sorrow;import java.util.ArrayList;import java.util.Date;import java.util.List;import android.app.Activity;import android.content.Context;import android.os.Bundle;import android.os.Handler;import android.os.Message;import android.text.TextUtils;import android.view.View;import android.view.Window;import android.view.inputmethod.InputMethodManager;import android.widget.EditText;import android.widget.ListView;import android.widget.Toast;import com.example.sorrow.R;import com.example.sorrow.bean.ChatMessage;import com.example.sorrow.bean.ChatMessage.Type;import com.yz.utils.HttpUtils;public class MainActivity extends Activity{private EditText mMsg;private List<ChatMessage> mDatas = new ArrayList<ChatMessage>();private ListView mChatView;private ChatMessageAdapter mAdapter;private Handler mHandler = new Handler(){public void handleMessage(android.os.Message msg){ChatMessage from = (ChatMessage) msg.obj;mDatas.add(from);mAdapter.notifyDataSetChanged();mChatView.setSelection(mDatas.size() - 1);};};@Overrideprotected void onCreate(Bundle savedInstanceState){super.onCreate(savedInstanceState);requestWindowFeature(Window.FEATURE_NO_TITLE);setContentView(yout.main_chatting);initView();mAdapter = new ChatMessageAdapter(this, mDatas);mChatView.setAdapter(mAdapter);}private void initView(){mChatView = (ListView) findViewById(R.id.id_chat_listView);mMsg = (EditText) findViewById(R.id.id_chat_msg);mDatas.add(new ChatMessage(Type.INPUT, "哎呀────!你好阿鲁!"));}public void sendMessage(View view){final String msg = mMsg.getText().toString();if (TextUtils.isEmpty(msg)){Toast.makeText(this, "你还没有填写信息呢阿鲁。

",Toast.LENGTH_SHORT).show();return;}ChatMessage to = new ChatMessage(Type.OUTPUT, msg);to.setDate(new Date());mDatas.add(to);mAdapter.notifyDataSetChanged();mChatView.setSelection(mDatas.size() - 1);mMsg.setText("");InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);if (imm.isActive()){imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT,InputMethodManager.HIDE_NOT_ALWAYS);}new Thread(){public void run(){ChatMessage from = null;try{from = HttpUtils.sendMsg(msg);} catch (Exception e){from = new ChatMessage(Type.INPUT, "服务器挂了呢阿鲁...");}Message message = Message.obtain();message.obj = from;mHandler.sendMessage(message);};}.start();}}文件名:main_activity.xml作用:软件主界面配置文件源码:style="@style/chat_date_style"/><LinearLayoutandroid:layout_width="fill_parent"android:layout_height="wrap_content"android:orientation="horizontal"><LinearLayoutandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginLeft="10dp"android:orientation="vertical"><ImageViewandroid:id="@+id/chat_from_icon"android:layout_width="49dp"android:layout_height="49dp"android:background="@drawable/nini"/><TextViewandroid:id="@+id/chat_from_name"android:layout_width="wrap_content"android:layout_height="wrap_content"android:textColor="#000"android:layout_gravity="center"android:text="小耀"android:textSize="18sp"/></LinearLayout><TextViewandroid:id="@+id/chat_from_content"android:layout_width="wrap_content"android:layout_height="wrap_content"android:minHeight="50dp"android:background="@drawable/chat_from_msg"android:text="哎呀────!你好阿鲁!"android:textSize="18sp"android:textColor="#000"android:gravity="center_vertical"android:focusable="true"android:clickable="true"android:lineSpacingExtra="2dp"/></LinearLayout></LinearLayout><?xml version="1.0"encoding="utf-8"?><LinearLayoutxmlns:android="/apk/res/android"android:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="vertical"><TextViewandroid:id="@+id/chat_send_createDate"style="@style/chat_date_style"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="2012-09-01 18:30:21"/><RelativeLayoutandroid:layout_width="fill_parent"android:layout_height="wrap_content"><LinearLayoutandroid:id="@+id/ly_chat_icon"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignParentRight="true"android:layout_marginLeft="10dp"android:orientation="vertical"><ImageViewandroid:id="@+id/chat_send_icon"android:layout_width="49dp"android:layout_height="49dp"android:src="@drawable/my"/><TextViewandroid:id="@+id/chat_send_name"android:layout_width="wrap_content"android:layout_height="wrap_content"android:textColor="#000"android:layout_gravity="center"android:text="ヤンデレ"android:textSize="18sp"/></LinearLayout><TextViewandroid:id="@+id/chat_send_content"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_toLeftOf="@id/ly_chat_icon"android:background="@drawable/chat_send_msg"android:clickable="true"android:focusable="true"android:gravity="center_vertical"android:lineSpacingExtra="2dp"android:minHeight="50dp"android:text="小耀!!"android:textColor="#000"android:textSize="18sp"/></RelativeLayout></LinearLayout><?xml version="1.0"encoding="utf-8"?><RelativeLayoutxmlns:android="/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"android:background="@drawable/chat_bg_default"android:orientation="vertical"><RelativeLayoutandroid:id="@+id/ly_chat_title"android:layout_width="fill_parent"android:layout_height="45dp"android:background="@drawable/title_bar"><TextViewandroid:layout_width="fill_parent"android:layout_height="fill_parent"android:gravity="center"android:text="NiNi"android:textColor="#FF0000"android:textSize="20sp"android:textStyle="bold"/></RelativeLayout><RelativeLayoutandroid:id="@+id/ly_chat_bottom"android:layout_width="fill_parent"android:layout_height="55dp"android:layout_alignParentBottom="true"android:background="@drawable/title_bar"><Buttonandroid:id="@+id/id_chat_send"android:layout_width="60dp"android:layout_height="40dp"android:layout_alignParentRight="true"android:layout_centerVertical="true"android:layout_marginRight="10dp"android:background="@drawable/fs"android:onClick="sendMessage"android:text="发送"/><EditTextandroid:id="@+id/id_chat_msg"android:layout_width="fill_parent"android:layout_height="40dp"android:layout_centerVertical="true"android:layout_marginLeft="10dp"android:layout_marginRight="10dp"android:layout_toLeftOf="@id/id_chat_send"android:background="@drawable/login_edit_normal"android:singleLine="true"android:textSize="18sp"/></RelativeLayout><ListViewandroid:id="@+id/id_chat_listView"android:layout_width="fill_parent"android:layout_height="fill_parent"android:layout_above="@id/ly_chat_bottom"android:layout_below="@id/ly_chat_title"android:background="@drawable/beijing"android:cacheColorHint="#0000"android:divider="@null"android:dividerHeight="5dp"android:scrollbarStyle="outsideOverlay"> </ListView></RelativeLayout>。