您好,登錄后才能下訂單哦!
邊看世界杯,邊寫博客。記得小時(shí)候,去山上玩,翻了兩座山,到了一個(gè)叫克勞的地方。那里每到六月份,桃子,杏多的很,有時(shí)候你坐在樹上吃一下午都不會(huì)有人來,自然了,那里也就人煙稀少。我當(dāng)時(shí)渴急了,在玉米地邊上的牛踩出的蹄窩里喝了一口水,那水真是甘甜哪,忽然覺得腳底下什么在動(dòng),抬腳一看,一只螃蟹被我踩到了泥土中。那時(shí)候吃野棗,自制槍打野雞,用套套野兔,在河里捉螃蟹,釣魚,在洪水中游泳,上山挖藥,在山上烤紅薯,烤玉米,到了冬天,可以點(diǎn)荒,一盒火柴去見識(shí)燎原,這都是經(jīng)常的事。不知道現(xiàn)在我再去那地方還能不能可以去做這些事情,下周準(zhǔn)備回去玩玩,看這些地方是否依然還是那么美麗。
OK,今天我們來看一下如下這個(gè)消息管理界面
先上圖,看一下android版本的,先登錄,登陸界面美化之后還像這么回事
我們看一下短消息管理界面
在這里我們還是要首先看一下WebService端
public class MessageMng : System.Web.Services.WebService { [WebMethod] public List<MessageEntity> GetMessageEntity(string sendUser, string receiveUser, string title, string messageType, string startDate, string endDate) { try { return MessageMngBiz.GetInstance().GetMessageEntity(sendUser, receiveUser, title, messageType, startDate, endDate); } catch { return new List<MessageEntity>(); } } }
我們?cè)倏匆幌翨iz層
public class MessageMngBiz { static MessageMngBiz messageMngBiz = new MessageMngBiz(); private MessageMngBiz() { } public static MessageMngBiz GetInstance() { return messageMngBiz; } public List<MessageEntity> GetMessageEntity(string sendUser, string receiveUser, string title, string messageType, string startDateStr, string endDateStr) { DateTime startDate = DateTime.MinValue; DateTime endDate = DateTime.MinValue; if (!string.IsNullOrWhiteSpace(startDateStr)) { DateTime.TryParse(startDateStr.Trim(), out startDate); } if (!string.IsNullOrWhiteSpace(endDateStr)) { DateTime.TryParse(endDateStr.Trim(), out endDate); } return MessageMngDAL.GetInstance().GetMessageEntity(sendUser, receiveUser, title, messageType, startDate == DateTime.MinValue ? null : (DateTime?)startDate, endDate == DateTime.MinValue ? null : (DateTime?)endDate); } }
再看一下DAL
public class MessageMngDAL { static MessageMngDAL messageMngDAL = new MessageMngDAL(); private MessageMngDAL() { } public static MessageMngDAL GetInstance() { return messageMngDAL; } /// <summary> ///獲取短信息 /// </summary> /// <param name="sendUser">發(fā)送者</param> /// <param name="receiveUser">接收者</param> /// <param name="title">標(biāo)題</param> /// <param name="messageType">類型(未讀/已讀,已刪)</param> /// <param name="startDate">開始時(shí)間</param> /// <param name="endDate">結(jié)束時(shí)間</param> /// <returns></returns> public List<MessageEntity> GetMessageEntity(string sendUser, string receiveUser, string title, string messageType, DateTime? startDate, DateTime? endDate) { bool isDateSearch = startDate.HasValue && endDate.HasValue; DirectSpecification<Message> commonSpecification = new DirectSpecification<Message>(msg => (string.IsNullOrEmpty(sendUser) ? true : msg.CerateUser == sendUser) && (string.IsNullOrEmpty(title) ? true : msg.Title.Contains(title)) && (isDateSearch ? (msg.CreateDate >= startDate && msg.CreateDate <= endDate) : true) && msg.ReceiveUser.Equals(receiveUser)); MessageType messageTypeEnum = new MessageTypeIndexes()[messageType]; using (BonusEntities bonusEntities = new BonusEntities()) { if (messageTypeEnum == MessageType.READ) { DirectSpecification<Message> readMsgSpec = new DirectSpecification<Message>(msg => msg.IsDel == false); AndSpecification<Message> andSpecification = new AndSpecification<Message>(commonSpecification, readMsgSpec); IEnumerable<Message> messageList = bonusEntities.Message.Where(andSpecification.SatisfiedBy()); return messageList.AsEnumerable().Select(msg => new MessageEntity() { TransactionNumber = msg.TransactionNumber, Title = msg.Title, MessageContent = msg.MessageContent.Length>50? msg.MessageContent.Substring(0, 50):msg.MessageContent, CreateUser = msg.UserCreate.UerInfo != null ? msg.UserCreate.UerInfo.FirstOrDefault().Name : msg.UserCreate.UseNo, CreateDate = msg.CreateDate.ToString(), IsRead = msg.IsRead }).ToList(); } if (messageTypeEnum == MessageType.DELETE) { DirectSpecification<Message> delMsgSpec = new DirectSpecification<Message>(msg => msg.IsDel == true && msg.IsDestroy == false); AndSpecification<Message> andSpecification = new AndSpecification<Message>(commonSpecification, delMsgSpec); IQueryable<Message> messageList = bonusEntities.Message.Where(andSpecification.SatisfiedBy()); return messageList.AsEnumerable().Select(msg => new MessageEntity() { TransactionNumber = msg.TransactionNumber, Title = msg.Title, MessageContent = msg.MessageContent.Substring(0, 50), CreateUser = msg.UserCreate.UerInfo != null ? msg.UserCreate.UerInfo.FirstOrDefault().Name : msg.UserCreate.UseNo, CreateDate = msg.CreateDate.ToString(), DelDate = msg.DelDate.HasValue? msg.DelDate.ToString():string.Empty }).ToList(); } return new List<MessageEntity>(); } } } public enum MessageType { READ = 1, DELETE = 2 } public class MessageTypeIndexes { public Array MessageTypeEnumArray { get { return Enum.GetValues(typeof(MessageType)); } } public MessageType this[string msgType] { get { int messageType = int.Parse(msgType); return (MessageType)MessageTypeEnumArray.GetValue(--messageType); } } }
好了,都是些查詢,沒什么可說的。
OK,我們現(xiàn)在就來看一下android的實(shí)現(xiàn),我們先看一下前臺(tái)布局
<?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:scrollbars="vertical" android:fadingEdge="none"> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:background="@color/red1"> <LinearLayout android:layout_height="wrap_content" android:layout_width="fill_parent" android:orientation="vertical" android:background="@color/teal1" android:layout_margin="1dp"> <TableLayout android:layout_height="wrap_content" android:layout_width="wrap_content" android:shrinkColumns="1" android:stretchColumns="1" android:background="@color/teal" android:layout_margin="2dp"> <TableRow> <TextView android:text="@string/labSendUser" android:textSize="8pt" android:gravity="right" android:textColor="@color/white"> </TextView> <EditText android:id="@+id/txtSendUser" android:drawableLeft="@drawable/userhint" android:singleLine="true" android:maxLength="30" android:textSize="7pt"></EditText> </TableRow> <TableRow> <TextView android:text="@string/labTitle" android:gravity="right" android:textSize="8pt" android:layout_marginLeft="10pt" android:textColor="@color/white"> </TextView> <EditText android:id="@+id/txtTitle" android:drawableLeft="@drawable/pencil" android:singleLine="true" android:maxLength="50"></EditText> </TableRow> <TableRow> <CheckBox android:id="@+id/chkIsDateCheck" android:text="@string/chkSendDate" android:textSize="8pt" android:gravity="center_vertical" android:layout_gravity="center_vertical" android:layout_span="2"></CheckBox> </TableRow> <TableRow> <TextView android:text="@string/chkBeginDate" android:textSize="8pt" android:textColor="@color/white"></TextView> <EditText android:id="@+id/txtStartDate" android:singleLine="true" android:editable="false" android:drawableRight="@drawable/calander"></EditText> </TableRow> <TableRow> <TextView android:text="@string/chkEndDate" android:textSize="8pt" android:textColor="@color/white"></TextView> <EditText android:id="@+id/txtEndDate" android:singleLine="true" android:editable="false" android:drawableRight="@drawable/calander"></EditText> </TableRow> </TableLayout> <LinearLayout android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content"> <ImageButton android:id="@+id/imgBtnSearch" android:src="@drawable/search" android:layout_weight="1" android:layout_width="wrap_content" android:layout_height="60dp" android:scaleType="centerInside" android:layout_marginLeft="5dp" android:layout_marginBottom="1dp"></ImageButton> <ImageButton android:id="@+id/imgBtnReset" android:layout_gravity="center_horizontal" android:layout_weight="1" android:src="@drawable/undo" android:layout_width="wrap_content" android:layout_height="60dp" android:scaleType="centerInside" android:layout_marginLeft="10dp" android:layout_marginRight="5dp" android:layout_marginBottom="1dp"></ImageButton> </LinearLayout> </LinearLayout> <TabHost android:id="@+id/tabhost" android:layout_width="fill_parent" android:layout_height="wrap_content"> <LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <TabWidget android:id="@android:id/tabs" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content" /> <FrameLayout android:id="@android:id/tabcontent" android:layout_width="fill_parent" android:layout_height="fill_parent"> <HorizontalScrollView android:layout_height="fill_parent" android:layout_width="fill_parent" android:scrollbarAlwaysDrawHorizontalTrack="false"> <TableLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:stretchColumns="0"> <TableRow> <bruce.controls.CustomScrollViewer android:id="@+id/gvMessageInfo" android:layout_width="fill_parent" android:layout_height="fill_parent"> </bruce.controls.CustomScrollViewer> </TableRow> </TableLayout> </HorizontalScrollView> </FrameLayout> </LinearLayout> </TabHost> </LinearLayout> </ScrollView>
還是使用嵌套布局,在最后我們發(fā)現(xiàn)了一個(gè)tabHost,是的,這個(gè)就是來實(shí)現(xiàn)tab頁的。我們看到tab頁中有一個(gè)一行一列的table,里面放了一個(gè)bruce.controls.CustomScrollViewer。這個(gè)東西其實(shí)是我從網(wǎng)上粘出來的一個(gè)用于顯示表格的自定義控件,這個(gè)寫的里面還是有些問題,我對(duì)其進(jìn)行了一些修改。
今天主要不是針對(duì)這個(gè),所以這個(gè)東西等下次我在講查看短消息功能的時(shí)候再說吧。
OK,我們先看一下查詢條件,發(fā)送人和標(biāo)題就不看了,時(shí)間查詢的話,如果勾選了,就必須選擇日期
private Boolean CheckSearchCriteria(String startDateStr, String endDateStr) throws ParseException { if (this.chkIsDateCheck.isChecked()) { if (startDateStr.length() == 0) { this.ShowToast("請(qǐng)選擇開始日期!"); return false; } if (endDateStr.length() == 0) { this.ShowToast("請(qǐng)選擇開始日期!"); return false; } SimpleDateFormat dateFormat = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss"); Date startDate = dateFormat.parse(startDateStr + " 00:00:01"); Date endDate = dateFormat.parse(endDateStr + " 23:59:59"); if (startDate.after(endDate)) { this.ShowToast("開始日期不能大于結(jié)束日期!"); return false; } } return true; }
以前我們提示的時(shí)候都是使用Alert,現(xiàn)在的話,都是使用toast
private void ShowToast(String content) { Toast toast = Toast.makeText(getApplicationContext(), content, Toast.LENGTH_LONG); toast.setGravity(Gravity.CENTER, 0, 0); LinearLayout toastContentView = (LinearLayout) toast.getView(); ImageView imgToast = new ImageView(getApplicationContext()); imgToast.setAdjustViewBounds(true); imgToast.setImageResource(R.drawable.alert); toastContentView.addView(imgToast, 0); toast.show(); }
上次的時(shí)候我們選擇日期是使用Click事件,這次我們使用長(zhǎng)按事件。
txtStartDate.setOnLongClickListener(new OnLongClickListener() { public boolean onLongClick(android.view.View view) { if (chkIsDateCheck.isChecked()) { owner.ShowDatePicker(view); } return true; } }); txtEndDate.setOnLongClickListener(new OnLongClickListener() { public boolean onLongClick(android.view.View view) { if (chkIsDateCheck.isChecked()) { owner.ShowDatePicker(view); } return true; } });
如下是ShowDatePicker的代碼,這次將這個(gè)方法寫成公用的。
private void ShowDatePicker(final View view) { Calendar calendar = Calendar.getInstance(); DatePickerDialog dialog = new DatePickerDialog(owner, new DatePickerDialog.OnDateSetListener() { public void onDateSet(DatePicker dp, int year, int month, int dayOfMonth) { if (view instanceof EditText) { ((EditText) view).setText(year + "-" + month + "-" + dayOfMonth); } } }, calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH)); dialog.show(); }
OK,以上是查詢部分,接下來我們看一下查詢結(jié)果部分,先是構(gòu)造tab頁。
private void InitTabHost() { tabHost = (TabHost) this.findViewById(R.id.tabhost); tabHost.setup(); TabSpec specMessageNew = tabHost.newTabSpec("tabMessageNew"); specMessageNew.setContent(R.id.gvMessageInfo); specMessageNew.setIndicator("已讀/未讀", this.getResources().getDrawable( R.drawable.emailread)); TabSpec specMessageOld = tabHost.newTabSpec("tabMessageOld"); specMessageOld.setContent(R.id.gvMessageInfo); specMessageOld.setIndicator("已刪消息", this.getResources().getDrawable( R.drawable.emaildel)); tabHost.addTab(specMessageNew); tabHost.addTab(specMessageOld); }
在這里,我們加了兩個(gè)tab,setIndicator第一個(gè)參數(shù)是設(shè)置tab標(biāo)題,第二個(gè)參數(shù)是設(shè)置tab圖標(biāo)。
setContent是設(shè)置tab頁的內(nèi)容,這里我們?cè)O(shè)置的是剛才上面介紹的自定義控件。
好的,我們最后看一下查詢部分,調(diào)用WebService代碼如下
private void SearchMessage() throws ParseException { String startDateStr = this.txtStartDate.getText().toString().trim(); String endDateStr = this.txtEndDate.getText().toString().trim(); if (!this.CheckSearchCriteria(startDateStr, endDateStr)) return; String title = txtTitle.getText().toString().trim(); String sendUser = txtSendUser.getText().toString().trim(); if (this.chkIsDateCheck.isChecked()) { SimpleDateFormat dateFormat = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss"); startDateStr = startDateStr + " 00:00:01"; endDateStr = endDateStr + " 23:59:59"; } SoapObject response = this.GetMessageEntityList(title, sendUser, startDateStr, endDateStr, (String.valueOf(tabHost .getCurrentTab() + 1))); HashMap<String, Object> map = null; ArrayList<HashMap<String, Object>> mapList = new ArrayList<HashMap<String, Object>>(); for (int i = 0; i < response.getPropertyCount(); i++) { SoapObject soapObj = (SoapObject) response.getProperty(i); map = new HashMap<String, Object>(); map.put("Title", soapObj.getProperty("Title").toString()); map.put("MessageContent", soapObj.getProperty("MessageContent") .toString()); map.put("CreateUser", soapObj.getProperty("CreateUser").toString()); map.put("CreateDate", soapObj.getProperty("CreateDate").toString()); Object isReadObj = soapObj.getProperty("IsRead"); Boolean isRead = Boolean.valueOf(isReadObj.toString()); map.put("IsOpen", isRead ? R.drawable.folderopen : R.drawable.ckffolder); mapList.add(map); } this.BinData(mapList); }
在這里我們拿到了webservice返回的數(shù)據(jù),調(diào)用代碼如下
final static String NAMESPACE = "http://tempuri.org/"; final static String METHOD_NAME = "GetMessageEntity"; final static String SOAP_ACTION = "http://tempuri.org/GetMessageEntity"; final static String URL = main.baseIP + "/MessageMng.asmx?wsdl";
private SoapObject GetMessageEntityList(String title, String sendUser, String startDate, String endDate, String messageType) { SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); PropertyInfo pi = new PropertyInfo(); pi.setName("sendUser"); pi.setType(String.class); pi.setValue(sendUser); request.addProperty(pi); pi = new PropertyInfo(); pi.setName("receiveUser"); pi.setType(String.class); pi.setValue(userNo); request.addProperty(pi); pi = new PropertyInfo(); pi.setName("title"); pi.setType(String.class); pi.setValue(title); request.addProperty(pi); pi = new PropertyInfo(); pi.setName("messageType"); pi.setType(String.class); pi.setValue(messageType); request.addProperty(pi); pi = new PropertyInfo(); pi.setName("startDate"); pi.setType(String.class); pi.setValue(startDate); request.addProperty(pi); pi = new PropertyInfo(); pi.setName("endDate"); pi.setType(String.class); pi.setValue(endDate); request.addProperty(pi); SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope( SoapEnvelope.VER11); soapEnvelope.dotNet = true; HttpTransportSE httpTS = new HttpTransportSE(URL); soapEnvelope.bodyOut = httpTS; soapEnvelope.setOutputSoapObject(request);// 設(shè)置請(qǐng)求參數(shù) // new MarshalDate().register(soapEnvelope); try { httpTS.call(SOAP_ACTION, soapEnvelope); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (XmlPullParserException e) { // TODO Auto-generated catch block e.printStackTrace(); } SoapObject result = null; try { result = (SoapObject) soapEnvelope.getResponse(); } catch (SoapFault e) { // TODO Auto-generated catch block e.printStackTrace(); } return result; }
OK,這些代碼都是以前講過的,在這里就不多說了。我們主要看BinData這個(gè)方法
private void BinData(ArrayList<HashMap<String, Object>> mapList) { String[] headers = new String[] {}; if (mapList.size() > 0) { headers = mapList.get(0).keySet().toArray(headers); } gvMessage.setTableHeaders(this.TransferHeader(headers)); gvMessage.setTableCellMaxEms(5); int[] imgColums = {1}; gvMessage.setTableheadColor(R.color.teal); for (HashMap<String, Object> hm : mapList) { gvMessage.addNewRow(hm.values().toArray(), imgColums); } }
第一步先拿出列頭,再轉(zhuǎn)成漢字
private String[] TransferHeader(String[] headers) { String[] header=new String[]{}; List<String> convertHeaderList = new ArrayList<String>(); for (int i = 0; i < headers.length; i++) { if (headers[i] == "CreateUser") { convertHeaderList.add("發(fā)送人"); } if (headers[i] == "Title") { convertHeaderList.add("標(biāo)題"); } if (headers[i] == "IsOpen") { convertHeaderList.add("已讀/未讀"); } if (headers[i] == "CreateDate") { convertHeaderList.add("發(fā)送日期"); } if (headers[i] == "MessageContent") { convertHeaderList.add("消息內(nèi)容"); } } return convertHeaderList.toArray(header); }
然后再循環(huán)設(shè)置行內(nèi)容
for (HashMap<String, Object> hm : mapList) { gvMessage.addNewRow(hm.values().toArray(), imgColums); }
這里我們循環(huán)ArrayList<HashMap<String,Object>>,然后往表格控件中加數(shù)據(jù),第一個(gè)參數(shù)是內(nèi)容,第二個(gè)參數(shù)是圖片內(nèi)容所在的列的數(shù)組。OK,運(yùn)行一下,查詢?cè)囋?/p>
通過查詢check之后,我們看看結(jié)果
還行吧,OK,今天就到這里,下節(jié)我將給大家介紹這個(gè)自定義控件和實(shí)現(xiàn)
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。