44import android .app .AlertDialog ;
55import android .content .DialogInterface ;
66import android .content .Intent ;
7+ import android .graphics .Rect ;
78import android .text .Html ;
9+ import android .view .Gravity ;
810import android .view .Menu ;
911import android .view .View ;
1012import android .view .ViewGroup ;
13+ import android .view .Window ;
1114import android .webkit .WebView ;
15+ import android .widget .AdapterView ;
1216import android .widget .BaseAdapter ;
1317import android .widget .EditText ;
1418import android .widget .ImageView ;
2125import net .coding .program .MyApp ;
2226import net .coding .program .R ;
2327import net .coding .program .common .CustomDialog ;
28+ import net .coding .program .common .DialogUtil ;
2429import net .coding .program .common .Global ;
2530import net .coding .program .common .MyImageGetter ;
2631import net .coding .program .common .StartActivity ;
@@ -123,13 +128,63 @@ void onResultAt(int requestCode, Intent data) {
123128
124129 @ Override
125130 public boolean onCreateOptionsMenu (Menu menu ) {
126- if (owerGlobar .equals (MyApp .sUserObject .global_key )) {
127- getMenuInflater ().inflate (R .menu .topic_detail , menu );
128- }
131+ getMenuInflater ().inflate (R .menu .topic_detail , menu );
129132
130133 return super .onCreateOptionsMenu (menu );
131134 }
132135
136+ @ OptionsItem
137+ void action_more () {
138+ showRightTopPop ();
139+ }
140+
141+ private DialogUtil .RightTopPopupWindow mRightTopPopupWindow = null ;
142+
143+ private void initRightTopPop () {
144+ if (mRightTopPopupWindow == null ) {
145+ ArrayList <DialogUtil .RightTopPopupItem > popupItemArrayList = new ArrayList ();
146+ DialogUtil .RightTopPopupItem downloadItem = new DialogUtil .RightTopPopupItem (getString (R .string .copy_link ), R .drawable .ic_menu_link );
147+ popupItemArrayList .add (downloadItem );
148+ if (owerGlobar .equals (MyApp .sUserObject .global_key )) {
149+ DialogUtil .RightTopPopupItem deleteItem = new DialogUtil .RightTopPopupItem (getString (R .string .delete_topic ), R .drawable .ic_menu_delete_selector );
150+ popupItemArrayList .add (deleteItem );
151+ }
152+ mRightTopPopupWindow = DialogUtil .initRightTopPopupWindow (this , popupItemArrayList , onRightTopPopupItemClickListener );
153+ }
154+ }
155+
156+ private void showRightTopPop () {
157+ initRightTopPop ();
158+
159+ mRightTopPopupWindow .adapter .notifyDataSetChanged ();
160+
161+ Rect rectgle = new Rect ();
162+ Window window = getWindow ();
163+ window .getDecorView ().getWindowVisibleDisplayFrame (rectgle );
164+ int StatusBarHeight = rectgle .top ;
165+ int contentViewTop =
166+ window .findViewById (Window .ID_ANDROID_CONTENT ).getTop ();
167+ //int TitleBarHeight= contentViewTop - StatusBarHeight;
168+ mRightTopPopupWindow .adapter .notifyDataSetChanged ();
169+ mRightTopPopupWindow .setAnimationStyle (android .R .style .Animation_Dialog );
170+ mRightTopPopupWindow .showAtLocation (listView , Gravity .TOP | Gravity .RIGHT , 0 , contentViewTop );
171+ }
172+
173+ private AdapterView .OnItemClickListener onRightTopPopupItemClickListener = new AdapterView .OnItemClickListener () {
174+ @ Override
175+ public void onItemClick (AdapterView <?> adapterView , View view , int position , long id ) {
176+ switch (position ) {
177+ case 0 :
178+ action_copy ();
179+ break ;
180+ case 1 :
181+ action_delete ();
182+ break ;
183+ }
184+ mRightTopPopupWindow .dismiss ();
185+ }
186+ };
187+
133188 @ Override
134189 public void onBackPressed () {
135190 if (mResultData .getIntExtra ("child_count" , -1 ) == -1 ) {
@@ -143,8 +198,8 @@ public void onBackPressed() {
143198
144199 final String HOST_MAOPAO_DELETE = Global .HOST + "/api/topic/%s" ;
145200
146- @ OptionsItem ( R . id . action_delete )
147- void menuDeleteTopic () {
201+ @ OptionsItem
202+ void action_delete () {
148203 showDialog ("讨论" , "删除讨论?" , new DialogInterface .OnClickListener () {
149204 @ Override
150205 public void onClick (DialogInterface dialog , int which ) {
@@ -153,6 +208,13 @@ public void onClick(DialogInterface dialog, int which) {
153208 });
154209 }
155210
211+ void action_copy () {
212+ final String urlTemplate = Global .HOST + "/u/%s/p/%s/topic/%d" ;
213+ String url = String .format (urlTemplate , topicObject .project .owner_user_name , topicObject .project .name , topicObject .id );
214+ Global .copy (this , url );
215+ showButtomToast ("已复制 " + url );
216+ }
217+
156218 private TextView textViewCommentCount ;
157219
158220 void updateDisplayCommentCount () {
@@ -190,7 +252,7 @@ private void updateHeadData() {
190252 webView .setWebViewClient (new MaopaoDetailActivity .CustomWebViewClient (this ));
191253
192254 webView .getSettings ().setDefaultTextEncodingName ("UTF-8" );
193- webView .loadDataWithBaseURL (null , bubble .replace ("${webview_content}" , topicObject .content ), "text/html" , "UTF-8" , null );
255+ webView .loadDataWithBaseURL (Global . HOST , bubble .replace ("${webview_content}" , topicObject .content ), "text/html" , "UTF-8" , null );
194256
195257 textViewCommentCount = (TextView ) head .findViewById (R .id .commentCount );
196258 updateDisplayCommentCount ();
0 commit comments