友盟意見反饋——對話框改爲單一的用戶反饋


友盟意見反饋——對話框改爲單一的用戶反饋


1.實現的效果:由自帶的左圖對話框的樣式變爲右圖單一的反饋形式,並把用戶信息放到同一個界面


2.佈局文件:

把umeng_fb_activity_contact.xml和umeng_fb_activity_conversation.xml合二爲一,如下:

[java] view plaincopy
  1. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  2.     xmlns:tools="http://schemas.android.com/tools"  
  3.     android:layout_width="fill_parent"  
  4.     android:layout_height="fill_parent"  
  5.     android:background="#ffffff"  
  6.     android:orientation="vertical"  
  7.     tools:context=".C onversationActivity" >  
  8.   
  9.     <EditText  
  10.         android:id="@+id/umeng_fb_replyContent"  
  11.         android:layout_width="match_parent"  
  12.         android:layout_height="150dp"  
  13.         android:layout_marginLeft="15dp"  
  14.         android:layout_marginRight="15dp"  
  15.         android:layout_marginTop="15dp"  
  16.         android:background="@drawable/feedback_bg"  
  17.         android:gravity="top"  
  18.         android:hint="@string/umeng_fb_reply_content_hint"  
  19.         android:paddingBottom="10dp"  
  20.         android:paddingLeft="15dp"  
  21.         android:paddingRight="10dp"  
  22.         android:paddingTop="10dp"  
  23.         android:textColorHint="#dbdbdb"  
  24.         android:textSize="15sp" >  
  25.   
  26.         <requestFocus />  
  27.     </EditText>  
  28.   
  29.     <TextView  
  30.         android:id="@+id/textView1"  
  31.         android:layout_width="wrap_content"  
  32.         android:layout_height="26dp"  
  33.         android:layout_alignLeft="@+id/umeng_fb_replyContent"  
  34.         android:layout_below="@+id/umeng_fb_replyContent"  
  35.         android:layout_marginTop="10dp"  
  36.         android:text="@string/umeng_fb_contact_info"  
  37.         android:textColorHighlight="#797979"  
  38.         android:textSize="15sp" />  
  39.   
  40.     <EditText  
  41.         android:id="@+id/umeng_fb_contactInfo"  
  42.         android:layout_width="fill_parent"  
  43.         android:layout_height="50dp"  
  44.         android:layout_alignLeft="@+id/textView1"  
  45.         android:layout_alignRight="@+id/umeng_fb_replyContent"  
  46.         android:layout_below="@+id/textView1"  
  47.         android:layout_marginTop="5dp"  
  48.         android:background="@drawable/ic_more_item_default"  
  49.         android:focusable="true"  
  50.         android:focusableInTouchMode="true"  
  51.         android:hint="@string/umeng_fb_contact_info_hint"  
  52.         android:paddingBottom="10dp"  
  53.         android:paddingLeft="15dp"  
  54.         android:paddingRight="10dp"  
  55.         android:paddingTop="10dp"  
  56.         android:textColorHint="#dbdbdb"  
  57.         android:textSize="15sp" >  
  58.     </EditText>  
  59.   
  60. </RelativeLayout>  

3.主要代碼:

把友盟官方提供的ConversationActivity和ContactActivity合二爲一,如下:

[java] view plaincopy
  1. public class ConversationActivity extends SherlockActivity {  
  2.   
  3.     // private static final String TAG = ConversationActivity.class.getName();  
  4.     private static final String KEY_UMENG_CONTACT_INFO_PLAIN_TEXT = "plain";  
  5.     private FeedbackAgent agent;  
  6.     private Conversation defaultConversation;  
  7.     EditText userReplyContentEdit, contactInfo;  
  8.     Button sendBtn;  
  9.     ImageButton backBtn;  
  10.   
  11.     private TextView tv_title;  
  12.     private RadioButton back_imbt;  
  13.   
  14.     private TextWatcher watcher = new TextWatcher() {  
  15.   
  16.         @Override  
  17.         public void onTextChanged(CharSequence s, int start, int before,  
  18.                 int count) {  
  19.         }  
  20.   
  21.         @Override  
  22.         public void beforeTextChanged(CharSequence s, int start, int count,  
  23.                 int after) {  
  24.         }  
  25.   
  26.         @Override  
  27.         public void afterTextChanged(Editable s) {  
  28.   
  29.             sendBtn.setClickable(true);  
  30.             sendBtn.setBackgroundColor(Color.parseColor("#ff0000"));  
  31.             sendBtn.setOnClickListener(new OnClickListener() {  
  32.   
  33.                 @Override  
  34.                 public void onClick(View v) {  
  35.   
  36.                     String content = userReplyContentEdit.getEditableText()  
  37.                             .toString().trim();  
  38.                     if (TextUtils.isEmpty(content))  
  39.                         return;  
  40.   
  41.                     if (content.length() < 10)  
  42.                         return;  
  43.   
  44.                     Toast.makeText(ConversationActivity.this,  
  45.                             "Thanks for your advice.", Toast.LENGTH_SHORT)  
  46.                             .show();  
  47.   
  48.                     userReplyContentEdit.getEditableText().clear();  
  49.                     defaultConversation.addUserReply(content);  
  50.                     sync();  
  51.   
  52.                     InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);  
  53.                     if (imm != null)  
  54.                         imm.hideSoftInputFromWindow(  
  55.                                 userReplyContentEdit.getWindowToken(), 0);  
  56.   
  57.                     UserInfo info = agent.getUserInfo();  
  58.                     if (info == null)  
  59.                         info = new UserInfo();  
  60.                     Map<String, String> contact = info.getContact();  
  61.                     if (contact == null)  
  62.                         contact = new HashMap<String, String>();  
  63.                     String contact_info = contactInfo.getEditableText()  
  64.                             .toString();  
  65.                     contact.put(KEY_UMENG_CONTACT_INFO_PLAIN_TEXT, contact_info);  
  66.                     info.setContact(contact);  
  67.                     agent.setUserInfo(info);  
  68.                     contactInfo.getEditableText().clear();  
  69.                 }  
  70.             });  
  71.         }  
  72.     };  
  73.   
  74.     @Override  
  75.     protected void onCreate(Bundle savedInstanceState) {  
  76.         super.onCreate(savedInstanceState);  
  77.         setContentView(R.layout.umeng_fb_activity_conversation);  
  78.         try {  
  79.             agent = new FeedbackAgent(this);  
  80.             defaultConversation = agent.getDefaultConversation();  
  81.             sync();  
  82.   
  83.             userReplyContentEdit = (EditText) findViewById(R.id.umeng_fb_replyContent);  
  84.             contactInfo = (EditText) findViewById(R.id.umeng_fb_contactInfo);  
  85.   
  86.             userReplyContentEdit.addTextChangedListener(watcher);  
  87.   
  88.         } catch (Exception e) {  
  89.             e.printStackTrace();  
  90.             this.finish();  
  91.         }  
  92.   
  93.     }  
  94.   
  95.     @Override  
  96.     protected void onStart() {  
  97.         super.onStart();  
  98.         getSupportActionBar().setDisplayHomeAsUpEnabled(false);  
  99.         getSupportActionBar().setDisplayShowHomeEnabled(false);  
  100.         getSupportActionBar().setDisplayShowTitleEnabled(false);  
  101.         getSupportActionBar().setBackgroundDrawable(  
  102.                 getResources().getDrawable(R.drawable.top1));  
  103.         initActionBar();  
  104.     }  
  105.   
  106.     private void initActionBar() {  
  107.         getSupportActionBar().setDisplayShowCustomEnabled(true);  
  108.         View actionbarLayout = LayoutInflater.from(this).inflate(  
  109.                 R.layout.jyx_actionbar_edit, null);  
  110.         getSupportActionBar().setCustomView(actionbarLayout);  
  111.         back_imbt = (RadioButton) actionbarLayout.findViewById(R.id.back_imbt);  
  112.         sendBtn = (Button) actionbarLayout.findViewById(R.id.edit_imbt);  
  113.         tv_title = (TextView) actionbarLayout.findViewById(R.id.tv_title);  
  114.         tv_title.setText("Advice");  
  115.         sendBtn.setText("Send");  
  116.         sendBtn.setClickable(false);  
  117.         back_imbt.setOnClickListener(new OnClickListener() {  
  118.   
  119.             @Override  
  120.             public void onClick(View view) {  
  121.                 finish();  
  122.             }  
  123.         });  
  124.     }  
  125.   
  126.     void sync() {  
  127.         Conversation.SyncListener listener = new Conversation.SyncListener() {  
  128.   
  129.             @Override  
  130.             public void onSendUserReply(List<Reply> replyList) {  
  131.             }  
  132.   
  133.             @Override  
  134.             public void onReceiveDevReply(List<DevReply> replyList) {  
  135.             }  
  136.         };  
  137.         defaultConversation.sync(listener);  
  138.     }  
  139. }  

發佈了12 篇原創文章 · 獲贊 4 · 訪問量 6萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章