/** * 获取登录信息 * * @return */ public User getLoginInfo() { User lu = new User(); lu.setUid(StringUtils.toInt(getProperty("user.uid"), 0)); lu.setName(getProperty("user.name")); lu.setFace(getProperty("user.face")); lu.setAccount(getProperty("user.account")); lu.setPwd(CyptoUtils.decode("oschinaApp", getProperty("user.pwd"))); lu.setLocation(getProperty("user.location")); lu.setFollowers(StringUtils.toInt(getProperty("user.followers"), 0)); lu.setFans(StringUtils.toInt(getProperty("user.fans"), 0)); lu.setScore(StringUtils.toInt(getProperty("user.score"), 0)); lu.setRememberMe(StringUtils.toBool(getProperty("user.isRememberMe"))); return lu; }
/** * 获取App唯一标识 * * @return */ public String getAppId() { String uniqueID = getProperty(AppConfig.CONF_APP_UNIQUEID); if (StringUtils.isEmpty(uniqueID)) { uniqueID = UUID.randomUUID().toString(); setProperty(AppConfig.CONF_APP_UNIQUEID, uniqueID); } return uniqueID; }
/** ListView Item设置 */ public View getView(int position, View convertView, ViewGroup parent) { // Log.d("method", "getView"); // 自定义视图 ListItemView listItemView = null; if (convertView == null) { // 获取list_item布局文件的视图 convertView = listContainer.inflate(this.itemViewResource, null); listItemView = new ListItemView(); // 获取控件对象 listItemView.title = (TextView) convertView.findViewById(R.id.cate_listitem_title); listItemView.author = (TextView) convertView.findViewById(R.id.cate_listitem_author); listItemView.count = (TextView) convertView.findViewById(R.id.cate_listitem_commentCount); listItemView.date = (TextView) convertView.findViewById(R.id.cate_listitem_date); listItemView.type = (ImageView) convertView.findViewById(R.id.cate_listitem_documentType); // 设置控件集到convertView convertView.setTag(listItemView); } else { listItemView = (ListItemView) convertView.getTag(); } // 设置文字和图片 Category cate = listItems.get(position); listItemView.title.setText(cate.getTitle()); listItemView.title.setTag(cate); // 设置隐藏参数(实体类) listItemView.date.setText(StringUtils.friendly_time(cate.getPubDate())); listItemView.count.setText(cate.getCommentCount() + ""); if (cate.getDocumentType() == cate.DOC_TYPE_ORIGINAL) listItemView.type.setImageResource(R.drawable.widget_original_icon); else listItemView.type.setImageResource(R.drawable.widget_repaste_icon); if (cateType == CategoryList.CATALOG_USER) { listItemView.author.setVisibility(View.GONE); } else { listItemView.author.setText(cate.getAuthor() + " 发表于"); } return convertView; }
/** * 获取用户信息个人专页(包含该用户的动态信息以及个人信息) * * @param uid 自己的uid * @param hisuid 被查看用户的uid * @param hisname 被查看用户的用户名 * @param pageIndex 页面索引 * @return * @throws AppException */ public UserInformation getInformation( int uid, int hisuid, String hisname, int pageIndex, boolean isRefresh) throws AppException { String _hisname = ""; if (!StringUtils.isEmpty(hisname)) { _hisname = hisname; } UserInformation userinfo = null; String key = "userinfo_" + uid + "_" + hisuid + "_" + (URLEncoder.encode(hisname)) + "_" + pageIndex + "_" + PAGE_SIZE; if (isNetworkConnected() && (!isReadDataCache(key) || isRefresh)) { try { userinfo = ApiClient.information(this, uid, hisuid, _hisname, pageIndex, PAGE_SIZE); if (userinfo != null && pageIndex == 0) { Notice notice = userinfo.getNotice(); userinfo.setNotice(null); userinfo.setCacheKey(key); saveObject(userinfo, key); userinfo.setNotice(notice); } } catch (AppException e) { userinfo = (UserInformation) readObject(key); if (userinfo == null) throw e; } } else { userinfo = (UserInformation) readObject(key); if (userinfo == null) userinfo = new UserInformation(); } return userinfo; }
/** * 获取当前网络类型 * * @return 0:没有网络 1:WIFI网络 2:WAP网络 3:NET网络 */ public int getNetworkType() { int netType = 0; ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo(); if (networkInfo == null) { return netType; } int nType = networkInfo.getType(); if (nType == ConnectivityManager.TYPE_MOBILE) { String extraInfo = networkInfo.getExtraInfo(); if (!StringUtils.isEmpty(extraInfo)) { if (extraInfo.toLowerCase().equals("cmnet")) { netType = NETTYPE_CMNET; } else { netType = NETTYPE_CMWAP; } } } else if (nType == ConnectivityManager.TYPE_WIFI) { netType = NETTYPE_WIFI; } return netType; }
public static BlogCommentList parse(InputStream inputStream) throws IOException, AppException { BlogCommentList commlist = new BlogCommentList(); Comment comm = null; Reply reply = null; Refer refer = null; // 获得XmlPullParser解析器 XmlPullParser xmlParser = Xml.newPullParser(); try { xmlParser.setInput(inputStream, UTF8); // 获得解析到的事件类别,这里有开始文档,结束文档,开始标签,结束标签,文本等等事件。 int evtType = xmlParser.getEventType(); // 一直循环,直到文档结束 while (evtType != XmlPullParser.END_DOCUMENT) { String tag = xmlParser.getName(); switch (evtType) { case XmlPullParser.START_TAG: if (tag.equalsIgnoreCase("allCount")) { commlist.allCount = StringUtils.toInt(xmlParser.nextText(), 0); } else if (tag.equalsIgnoreCase("pageSize")) { commlist.pageSize = StringUtils.toInt(xmlParser.nextText(), 0); } else if (tag.equalsIgnoreCase("comment")) { comm = new Comment(); } else if (comm != null) { if (tag.equalsIgnoreCase("id")) { comm.id = StringUtils.toInt(xmlParser.nextText(), 0); } else if (tag.equalsIgnoreCase("portrait")) { comm.setFace(xmlParser.nextText()); } else if (tag.equalsIgnoreCase("author")) { comm.setAuthor(xmlParser.nextText()); } else if (tag.equalsIgnoreCase("authorid")) { comm.setAuthorId(StringUtils.toInt(xmlParser.nextText(), 0)); } else if (tag.equalsIgnoreCase("content")) { comm.setContent(xmlParser.nextText()); } else if (tag.equalsIgnoreCase("pubDate")) { comm.setPubDate(xmlParser.nextText()); } else if (tag.equalsIgnoreCase("appclient")) { comm.setAppClient(StringUtils.toInt(xmlParser.nextText(), 0)); } else if (tag.equalsIgnoreCase("reply")) { reply = new Reply(); } else if (reply != null && tag.equalsIgnoreCase("rauthor")) { reply.rauthor = xmlParser.nextText(); } else if (reply != null && tag.equalsIgnoreCase("rpubDate")) { reply.rpubDate = xmlParser.nextText(); } else if (reply != null && tag.equalsIgnoreCase("rcontent")) { reply.rcontent = xmlParser.nextText(); } else if (tag.equalsIgnoreCase("refer")) { refer = new Refer(); } else if (refer != null && tag.equalsIgnoreCase("refertitle")) { refer.refertitle = xmlParser.nextText(); } else if (refer != null && tag.equalsIgnoreCase("referbody")) { refer.referbody = xmlParser.nextText(); } } // 通知信息 else if (tag.equalsIgnoreCase("notice")) { commlist.setNotice(new Notice()); } else if (commlist.getNotice() != null) { if (tag.equalsIgnoreCase("atmeCount")) { commlist.getNotice().setAtmeCount(StringUtils.toInt(xmlParser.nextText(), 0)); } else if (tag.equalsIgnoreCase("msgCount")) { commlist.getNotice().setMsgCount(StringUtils.toInt(xmlParser.nextText(), 0)); } else if (tag.equalsIgnoreCase("reviewCount")) { commlist.getNotice().setReviewCount(StringUtils.toInt(xmlParser.nextText(), 0)); } else if (tag.equalsIgnoreCase("newFansCount")) { commlist.getNotice().setNewFansCount(StringUtils.toInt(xmlParser.nextText(), 0)); } } break; case XmlPullParser.END_TAG: // 如果遇到标签结束,则把对象添加进集合中 if (tag.equalsIgnoreCase("comment") && comm != null) { commlist.getCommentlist().add(comm); comm = null; } else if (tag.equalsIgnoreCase("reply") && comm != null && reply != null) { comm.getReplies().add(reply); reply = null; } else if (tag.equalsIgnoreCase("refer") && comm != null && refer != null) { comm.getRefers().add(refer); refer = null; } break; } // 如果xml没有结束,则导航到下一个节点 evtType = xmlParser.next(); } } catch (XmlPullParserException e) { throw AppException.xml(e); } finally { inputStream.close(); } return commlist; }
/** * 是否Https登录 * * @return */ public boolean isHttpsLogin() { String perf_httpslogin = getProperty(AppConfig.CONF_HTTPS_LOGIN); // 默认是http if (StringUtils.isEmpty(perf_httpslogin)) return false; else return StringUtils.toBool(perf_httpslogin); }
/** * 是否左右滑动 * * @return */ public boolean isScroll() { String perf_scroll = getProperty(AppConfig.CONF_SCROLL); // 默认是关闭左右滑动 if (StringUtils.isEmpty(perf_scroll)) return false; else return StringUtils.toBool(perf_scroll); }
/** * 是否启动检查更新 * * @return */ public boolean isCheckUp() { String perf_checkup = getProperty(AppConfig.CONF_CHECKUP); // 默认是开启 if (StringUtils.isEmpty(perf_checkup)) return true; else return StringUtils.toBool(perf_checkup); }
/** * 是否发出提示音 * * @return */ public boolean isVoice() { String perf_voice = getProperty(AppConfig.CONF_VOICE); // 默认是开启提示声音 if (StringUtils.isEmpty(perf_voice)) return true; else return StringUtils.toBool(perf_voice); }
/** * 是否加载显示文章图片 * * @return */ public boolean isLoadImage() { String perf_loadimage = getProperty(AppConfig.CONF_LOAD_IMAGE); // 默认是加载的 if (StringUtils.isEmpty(perf_loadimage)) return true; else return StringUtils.toBool(perf_loadimage); }
public void onClick(View v) { _id = curId; if (curId == 0) { return; } _catalog = curCatalog; _content = mFootEditer.getText().toString(); if (StringUtils.isEmpty(_content)) { UIHelper.ToastMessage(v.getContext(), "请输入评论内容"); return; } final AppContext ac = (AppContext) getApplication(); if (!ac.isLogin()) { UIHelper.showLoginDialog(TweetDetail.this); return; } // if(mZone.isChecked()) // _isPostToMyZone = 1; _uid = ac.getLoginUid(); mProgress = ProgressDialog.show(v.getContext(), null, "发布中···", true, true); final Handler handler = new Handler() { public void handleMessage(Message msg) { if (mProgress != null) mProgress.dismiss(); if (msg.what == 1) { Result res = (Result) msg.obj; UIHelper.ToastMessage(TweetDetail.this, res.getErrorMessage()); if (res.OK()) { // 发送通知广播 if (res.getNotice() != null) { UIHelper.sendBroadCast(TweetDetail.this, res.getNotice()); } // 恢复初始底部栏 mFootViewSwitcher.setDisplayedChild(0); mFootEditer.clearFocus(); mFootEditer.setText(""); mFootEditer.setVisibility(View.GONE); // 更新评论列表 lvCommentData.add(0, res.getComment()); lvCommentAdapter.notifyDataSetChanged(); mLvComment.setSelection(0); // 清除之前保存的编辑内容 ac.removeProperty(tempCommentKey); } } else { ((AppException) msg.obj).makeToast(TweetDetail.this); } } }; new Thread() { public void run() { Message msg = new Message(); Result res = new Result(); try { // 发表评论 res = ac.pubComment(_catalog, _id, _uid, _content, _isPostToMyZone); msg.what = 1; msg.obj = res; } catch (AppException e) { e.printStackTrace(); msg.what = -1; msg.obj = e; } handler.sendMessage(msg); } }.start(); }
public static Tweet parse(InputStream inputStream) throws IOException, AppException { Tweet tweet = null; // 获得XmlPullParser解析器 XmlPullParser xmlParser = Xml.newPullParser(); try { xmlParser.setInput(inputStream, UTF8); // 获得解析到的事件类别,这里有开始文档,结束文档,开始标签,结束标签,文本等等事件。 int evtType = xmlParser.getEventType(); // 一直循环,直到文档结束 while (evtType != XmlPullParser.END_DOCUMENT) { String tag = xmlParser.getName(); switch (evtType) { case XmlPullParser.START_TAG: if (tag.equalsIgnoreCase(NODE_START)) { tweet = new Tweet(); } else if (tweet != null) { if (tag.equalsIgnoreCase(NODE_ID)) { tweet.id = StringUtils.toInt(xmlParser.nextText(), 0); } else if (tag.equalsIgnoreCase(NODE_FACE)) { tweet.setFace(xmlParser.nextText()); } else if (tag.equalsIgnoreCase(NODE_BODY)) { tweet.setBody(xmlParser.nextText()); } else if (tag.equalsIgnoreCase(NODE_AUTHOR)) { tweet.setAuthor(xmlParser.nextText()); } else if (tag.equalsIgnoreCase(NODE_AUTHORID)) { tweet.setAuthorId(StringUtils.toInt(xmlParser.nextText(), 0)); } else if (tag.equalsIgnoreCase(NODE_COMMENTCOUNT)) { tweet.setCommentCount(StringUtils.toInt(xmlParser.nextText(), 0)); } else if (tag.equalsIgnoreCase(NODE_PUBDATE)) { tweet.setPubDate(xmlParser.nextText()); } else if (tag.equalsIgnoreCase(NODE_IMGSMALL)) { tweet.setImgSmall(xmlParser.nextText()); } else if (tag.equalsIgnoreCase(NODE_IMGBIG)) { tweet.setImgBig(xmlParser.nextText()); } else if (tag.equalsIgnoreCase(NODE_ATTACH)) { tweet.setAttach(xmlParser.nextText()); } else if (tag.equalsIgnoreCase(NODE_APPCLIENT)) { tweet.setAppClient(StringUtils.toInt(xmlParser.nextText(), 0)); } // 通知信息 else if (tag.equalsIgnoreCase("notice")) { tweet.setNotice(new Notice()); } else if (tweet.getNotice() != null) { if (tag.equalsIgnoreCase("atmeCount")) { tweet.getNotice().setAtmeCount(StringUtils.toInt(xmlParser.nextText(), 0)); } else if (tag.equalsIgnoreCase("msgCount")) { tweet.getNotice().setMsgCount(StringUtils.toInt(xmlParser.nextText(), 0)); } else if (tag.equalsIgnoreCase("reviewCount")) { tweet.getNotice().setReviewCount(StringUtils.toInt(xmlParser.nextText(), 0)); } else if (tag.equalsIgnoreCase("newFansCount")) { tweet.getNotice().setNewFansCount(StringUtils.toInt(xmlParser.nextText(), 0)); } } } break; case XmlPullParser.END_TAG: break; } // 如果xml没有结束,则导航到下一个节点 evtType = xmlParser.next(); } } catch (XmlPullParserException e) { throw AppException.xml(e); } finally { inputStream.close(); } return tweet; }