public View getView(int position, View view, ViewGroup parent) { View convertView = view; // m.get(position); ViewHolder holder = null; if (convertView == null) { convertView = inflater.inflate(R.layout.relative_topic_list, null); TextView num = (TextView) convertView.findViewById(R.id.num); TextView title = (TextView) convertView.findViewById(R.id.title); TextView author = (TextView) convertView.findViewById(R.id.author); TextView lastReply = (TextView) convertView.findViewById(R.id.last_reply); holder = new ViewHolder(); holder.num = num; holder.title = title; holder.author = author; holder.lastReply = lastReply; convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); } ThemeManager cfg = ThemeManager.getInstance(); int colorId = cfg.getBackgroundColor(position); if (position == this.selected) { if (cfg.mode == ThemeManager.MODE_NIGHT) colorId = R.color.topiclist_selected_color; else colorId = R.color.holo_blue_light; ; } convertView.setBackgroundResource(colorId); handleJsonList(holder, position); return convertView; }
private void handleJsonList(ViewHolder holder, int position) { ThreadPageInfo entry = getEntry(position); // this.topicListInfo.getArticleEntryList().get(position); if (entry == null) { return; } Resources res = inflater.getContext().getResources(); ThemeManager theme = ThemeManager.getInstance(); boolean night = false; int nightLinkColor = res.getColor(R.color.night_link_color); if (theme.getMode() == ThemeManager.MODE_NIGHT) night = true; holder.author.setText(entry.getAuthor()); if (night) holder.author.setTextColor(nightLinkColor); String lastPoster = entry.getLastposter_org(); if (StringUtil.isEmpty(lastPoster)) lastPoster = entry.getLastposter(); holder.lastReply.setText(lastPoster); holder.num.setText("" + entry.getReplies()); if (night) { holder.lastReply.setTextColor(nightLinkColor); holder.num.setTextColor(nightLinkColor); } holder.title.setTextColor(res.getColor(theme.getForegroundColor())); float size = PhoneConfiguration.getInstance().getTextSize(); String titile = entry.getContent(); if (StringUtil.isEmpty(titile)) { titile = entry.getSubject(); holder.title.setText(StringUtil.unEscapeHtml(titile)); } else { holder.title.setText(StringUtil.removeBrTag(StringUtil.unEscapeHtml(titile))); } holder.title.setTextSize(size); final TextPaint tp = holder.title.getPaint(); tp.setFakeBoldText(false); if (!StringUtil.isEmpty(entry.getTitlefont())) { final String font = entry.getTitlefont(); if (font.equals("~1~~") || font.equals("~~~1")) { tp.setFakeBoldText(true); } else if (font.startsWith("green")) { holder.title.setTextColor(res.getColor(R.color.title_green)); } else if (font.startsWith("blue")) { holder.title.setTextColor(res.getColor(R.color.title_blue)); } else if (font.startsWith("red")) { holder.title.setTextColor(res.getColor(R.color.title_red)); } else if (font.startsWith("orange")) { holder.title.setTextColor(res.getColor(R.color.title_orange)); } } }
@Override public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); if (PhoneConfiguration.getInstance().HandSide == 1) { // lefthand int flag = PhoneConfiguration.getInstance().getUiFlag(); if (flag == 1 || flag == 3 || flag == 5 || flag == 7) { // 文章列表,UIFLAG为1或者1+2或者1+4或者1+2+4 inflater.inflate(R.menu.articlelist_menu_left, menu); } else { inflater.inflate(R.menu.articlelist_menu, menu); } } else { inflater.inflate(R.menu.articlelist_menu, menu); } final int flags = ThemeManager.ACTION_BAR_FLAG; MenuItem lock = menu.findItem(R.id.article_menuitem_lock); int orentation = ThemeManager.getInstance().screenOrentation; if (orentation == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE || orentation == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) { lock.setTitle(R.string.unlock_orientation); lock.setIcon(R.drawable.ic_menu_always_landscape_portrait); } ReflectionUtil.actionBar_setDisplayOption(this, flags); return super.onCreateOptionsMenu(menu); }
@Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { listview = new ListView(this.getActivity()); listview.setBackgroundResource(ThemeManager.getInstance().getBackgroundColor()); listview.setDivider(null); activeActionMode(); listview.setChoiceMode(ListView.CHOICE_MODE_SINGLE); listview.setOnItemLongClickListener( new OnItemLongClickListener() { @TargetApi(11) @Override public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { ListView lv = (ListView) parent; lv.setItemChecked(position, true); if (mActionModeCallback != null) { ((ActionBarActivity) getActivity()) .startSupportActionMode((Callback) mActionModeCallback); return true; } return false; } }); listview.setDescendantFocusability(ListView.FOCUS_AFTER_DESCENDANTS); return listview; }
private static String buildAttachment( ThreadRowInfo row, boolean showImage, int imageQuality, HashSet<String> imageURLSet) { if (row == null || row.getAttachs() == null || row.getAttachs().size() == 0) { return ""; } StringBuilder ret = new StringBuilder(); ThemeManager theme = ThemeManager.getInstance(); ret.append("<br/><br/>").append(attachment).append("<hr/><br/>"); // ret.append("<table style='background:#e1c8a7;border:1px solid #b9986e;margin:0px 0px 10px // 30px;padding:10px;color:#6b2d25;max-width:100%;'>"); if (theme.mode == theme.MODE_NIGHT) { ret.append( "<table style='background:#000000;border:1px solid #b9986e;padding:10px;color:#6b2d25;font-size:2'>"); } else { ret.append( "<table style='background:#e1c8a7;border:1px solid #b9986e;padding:10px;color:#6b2d25;font-size:2'>"); } ret.append("<tbody>"); Iterator<Entry<String, Attachment>> it = row.getAttachs().entrySet().iterator(); int attachmentCount = 0; while (it.hasNext()) { Entry<String, Attachment> entry = it.next(); if (imageURLSet != null && imageURLSet.size() > 0 && imageURLSet.contains(entry.getValue().getAttachurl())) { continue; } // String url = "http://img.nga.178.com/attachments/" + // entry.getValue().getAttachurl(); ret.append("<tr><td><a href='http://" + HttpUtil.NGA_ATTACHMENT_HOST + "/attachments/"); ret.append(entry.getValue().getAttachurl()); ret.append("'>"); if (showImage) { String attachURL = "http://" + HttpUtil.NGA_ATTACHMENT_HOST + "/attachments/" + entry.getValue().getAttachurl(); if ("1".equals(entry.getValue().getThumb())) { attachURL = attachURL + ".thumb.jpg"; // ret.append(entry.getValue().getExt()); } else { attachURL = StringUtil.buildOptimizedImageURL(attachURL, imageQuality); } ret.append("<img src='"); ret.append(attachURL); } else { ret.append("<img src='file:///android_asset/ic_offline_image.png"); } ret.append("' style= 'max-width:70%;'></a>"); ret.append("</td></tr>"); attachmentCount++; } ret.append("</tbody></table>"); if (attachmentCount == 0) return ""; else return ret.toString(); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ThemeManager.SetContextTheme(this); view = LayoutInflater.from(this).inflate(getLayoutId(), null); this.setContentView(view); updateThemeUI(); }
@Override protected void onResume() { int orentation = ThemeManager.getInstance().screenOrentation; if (orentation == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE || orentation == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) { setRequestedOrientation(orentation); } else { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); } super.onResume(); }
private void handleLockOrientation(MenuItem item) { int preOrentation = ThemeManager.getInstance().screenOrentation; int newOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; ImageButton compat_item = null; // getActionItem(R.id.actionbar_compat_item_lock); if (preOrentation == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE || preOrentation == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) { // restore // int newOrientation = ActivityInfo.SCREEN_ORIENTATION_USER; ThemeManager.getInstance().screenOrentation = newOrientation; setRequestedOrientation(newOrientation); item.setTitle(R.string.lock_orientation); item.setIcon(R.drawable.ic_lock_screen); if (compat_item != null) compat_item.setImageResource(R.drawable.ic_lock_screen); } else { newOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; Display dis = getWindowManager().getDefaultDisplay(); // Point p = new Point(); // dis.getSize(p); if (dis.getWidth() < dis.getHeight()) { newOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; } ThemeManager.getInstance().screenOrentation = newOrientation; setRequestedOrientation(newOrientation); item.setTitle(R.string.unlock_orientation); item.setIcon(R.drawable.ic_menu_always_landscape_portrait); if (compat_item != null) compat_item.setImageResource(R.drawable.ic_menu_always_landscape_portrait); } SharedPreferences share = getSharedPreferences(PERFERENCE, Activity.MODE_PRIVATE); Editor editor = share.edit(); editor.putInt(SCREEN_ORENTATION, newOrientation); editor.commit(); }
@Override protected void onResume() { int orentation = ThemeManager.getInstance().screenOrentation; if (orentation == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE || orentation == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) { setRequestedOrientation(orentation); } else { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); } if (asynTask != null) { asynTask.cancel(true); asynTask = null; } long now = System.currentTimeMillis(); PhoneConfiguration config = PhoneConfiguration.getInstance(); if (now - config.lastMessageCheck > 60 * 1000 && config.notification) { Log.d(TAG, "start to check Reply Notification"); asynTask = new CheckReplyNotificationTask(this); asynTask.execute(config.getCookie()); } super.onResume(); }
protected void updateThemeUI() { view.setBackgroundResource(ThemeManager.getInstance().getBackgroundColor()); }
/* * (non-Javadoc) * * @see android.app.Activity#onCreate(android.os.Bundle) */ @Override protected void onCreate(Bundle savedInstanceState) { int orentation = ThemeManager.getInstance().screenOrentation; if (orentation == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE || orentation == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) { setRequestedOrientation(orentation); } else { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); } super.onCreate(savedInstanceState); v = this.getLayoutInflater().inflate(R.layout.messagereply, null); v.setBackgroundColor(getResources().getColor(ThemeManager.getInstance().getBackgroundColor())); this.setContentView(v); if (PhoneConfiguration.getInstance().uploadLocation && PhoneConfiguration.getInstance().location == null) { ActivityUtil.reflushLocation(this); } Intent intent = this.getIntent(); prefix = intent.getStringExtra("prefix"); // if(prefix!=null){ // prefix=prefix.replaceAll("\\n\\n", "\n"); // } tousername = intent.getStringExtra("to"); action = intent.getStringExtra("action"); mid = intent.getIntExtra("mid", 0); String title = intent.getStringExtra("title"); titleText = (EditText) findViewById(R.id.reply_titile_edittext); toText = (EditText) findViewById(R.id.reply_titile_edittext_to); bodyText = (EditText) findViewById(R.id.reply_body_edittext); if (action.equals("new")) { getSupportActionBar().setTitle(R.string.new_message); } else if (action.equals("reply")) { getSupportActionBar().setTitle(R.string.reply_message); } titleText.setSelected(true); act = new MessagePostAction(mid, "", ""); act.setAction_(action); this.act.set__ngaClientChecksum(FunctionUtil.getngaClientChecksum(this)); loading = false; if (!StringUtil.isEmpty(tousername)) { toText.setText(tousername); if (!StringUtil.isEmpty(title)) { titleText.setText(title); } } else { if (!StringUtil.isEmpty(title)) { titleText.setText(title); } } if (prefix != null) { if (prefix.startsWith("[quote][pid=") && prefix.endsWith("[/quote]\n")) { SpannableString spanString = new SpannableString(prefix); spanString.setSpan( new BackgroundColorSpan(-1513240), 0, prefix.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); spanString.setSpan( new StyleSpan(android.graphics.Typeface.BOLD), prefix.indexOf("[b]Post by"), prefix.indexOf("):[/b]") + 5, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); bodyText.append(spanString); } else { bodyText.append(prefix); } bodyText.setSelection(prefix.length()); } ThemeManager tm = ThemeManager.getInstance(); if (tm.getMode() == ThemeManager.MODE_NIGHT) { bodyText.setBackgroundResource(tm.getBackgroundColor()); toText.setBackgroundResource(tm.getBackgroundColor()); titleText.setBackgroundResource(tm.getBackgroundColor()); int textColor = this.getResources().getColor(tm.getForegroundColor()); bodyText.setTextColor(textColor); titleText.setTextColor(textColor); toText.setTextColor(textColor); } }
public View getView(int position, View view, ViewGroup parent) { final ThreadRowInfo row = data.getRowList().get(position); int lou = -1; if (row != null) lou = row.getLou(); ViewHolder holder = null; boolean needin = false; SoftReference<View> ref = viewCache.get(position); View cachedView = null; if (ref != null) { cachedView = ref.get(); } if (cachedView != null) { if (((ViewHolder) cachedView.getTag()).position == position) { Log.d(TAG, "get view from cache ,floor " + lou); return cachedView; } else { view = LayoutInflater.from(activity).inflate(R.layout.relative_aritclelist, parent, false); holder = initHolder(view); holder.position = position; view.setTag(holder); viewCache.put(position, new SoftReference<View>(view)); } } else { view = LayoutInflater.from(activity).inflate(R.layout.relative_aritclelist, parent, false); holder = initHolder(view); holder.position = position; view.setTag(holder); viewCache.put(position, new SoftReference<View>(view)); } if (!PhoneConfiguration.getInstance().showReplyButton) { holder.viewBtn.setVisibility(View.GONE); } else { MyListenerForReply myListenerForReply = new MyListenerForReply(position, data, activity); holder.viewBtn.setOnClickListener(myListenerForReply); } ThemeManager theme = ThemeManager.getInstance(); int colorId = theme.getBackgroundColor(position); view.setBackgroundResource(colorId); // colorId = theme.getBackgroundColor(2); if (row == null) { return view; } handleAvatar(holder.avatarIV, row); int fgColorId = ThemeManager.getInstance().getForegroundColor(); final int fgColor = parent.getContext().getResources().getColor(fgColorId); FunctionUtil.handleNickName(row, fgColor, holder.nickNameTV, activity); final int bgColor = parent.getContext().getResources().getColor(colorId); final WebView contentTV = holder.contentTV; final String floor = String.valueOf(lou); TextView floorTV = holder.floorTV; floorTV.setText("[" + floor + " 楼]"); floorTV.setTextColor(fgColor); if (!StringUtil.isEmpty(row.getFromClientModel())) { MyListenerForClient myListenerForClient = new MyListenerForClient(position, data, activity, parent); String from_client_model = row.getFromClientModel(); if (from_client_model.equals("ios")) { holder.clientBtn.setImageResource(R.drawable.ios); // IOS } else if (from_client_model.equals("wp")) { holder.clientBtn.setImageResource(R.drawable.wp); // WP } else if (from_client_model.equals("unknown")) { holder.clientBtn.setImageResource(R.drawable.unkonwn); // 未知orBB } holder.clientBtn.setVisibility(View.VISIBLE); holder.clientBtn.setOnClickListener(myListenerForClient); } if (ActivityUtil.isLessThan_4_3()) { new Thread( new Runnable() { public void run() { FunctionUtil.handleContentTV( contentTV, row, bgColor, fgColor, activity, null, client); } }) .start(); } else if (ActivityUtil.isLessThan_4_4()) { ((Activity) parent.getContext()) .runOnUiThread( new Runnable() { public void run() { FunctionUtil.handleContentTV( contentTV, row, bgColor, fgColor, activity, null, client); } }); } else { FunctionUtil.handleContentTV(contentTV, row, bgColor, fgColor, activity, null, client); } TextView postTimeTV = holder.postTimeTV; postTimeTV.setText(row.getPostdate()); postTimeTV.setTextColor(fgColor); if (needin) { view.invalidate(); } return view; }