1.实现的效果:由自带的左图对话框的样式变为右图单一的反馈形式,并把用户信息放到同一个界面
2.布局文件:
把umeng_fb_activity_contact.xml和umeng_fb_activity_conversation.xml合二为一,如下:
- <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:tools="http://schemas.android.com/tools"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:background="#ffffff"
- android:orientation="vertical"
- tools:context=".C onversationActivity" >
- <EditText
- android:id="@+id/umeng_fb_replyContent"
- android:layout_width="match_parent"
- android:layout_height="150dp"
- android:layout_marginLeft="15dp"
- android:layout_marginRight="15dp"
- android:layout_marginTop="15dp"
- android:background="@drawable/feedback_bg"
- android:gravity="top"
- android:hint="@string/umeng_fb_reply_content_hint"
- android:paddingBottom="10dp"
- android:paddingLeft="15dp"
- android:paddingRight="10dp"
- android:paddingTop="10dp"
- android:textColorHint="#dbdbdb"
- android:textSize="15sp" >
- <requestFocus />
- </EditText>
- <TextView
- android:id="@+id/textView1"
- android:layout_width="wrap_content"
- android:layout_height="26dp"
- android:layout_alignLeft="@+id/umeng_fb_replyContent"
- android:layout_below="@+id/umeng_fb_replyContent"
- android:layout_marginTop="10dp"
- android:text="@string/umeng_fb_contact_info"
- android:textColorHighlight="#797979"
- android:textSize="15sp" />
- <EditText
- android:id="@+id/umeng_fb_contactInfo"
- android:layout_width="fill_parent"
- android:layout_height="50dp"
- android:layout_alignLeft="@+id/textView1"
- android:layout_alignRight="@+id/umeng_fb_replyContent"
- android:layout_below="@+id/textView1"
- android:layout_marginTop="5dp"
- android:background="@drawable/ic_more_item_default"
- android:focusable="true"
- android:focusableInTouchMode="true"
- android:hint="@string/umeng_fb_contact_info_hint"
- android:paddingBottom="10dp"
- android:paddingLeft="15dp"
- android:paddingRight="10dp"
- android:paddingTop="10dp"
- android:textColorHint="#dbdbdb"
- android:textSize="15sp" >
- </EditText>
- </RelativeLayout>
3.主要代码:
把友盟官方提供的ConversationActivity和ContactActivity合二为一,如下:
- public class ConversationActivity extends SherlockActivity {
- // private static final String TAG = ConversationActivity.class.getName();
- private static final String KEY_UMENG_CONTACT_INFO_PLAIN_TEXT = "plain";
- private FeedbackAgent agent;
- private Conversation defaultConversation;
- EditText userReplyContentEdit, contactInfo;
- Button sendBtn;
- ImageButton backBtn;
- private TextView tv_title;
- private RadioButton back_imbt;
- private TextWatcher watcher = new TextWatcher() {
- @Override
- public void onTextChanged(CharSequence s, int start, int before,
- int count) {
- }
- @Override
- public void beforeTextChanged(CharSequence s, int start, int count,
- int after) {
- }
- @Override
- public void afterTextChanged(Editable s) {
- sendBtn.setClickable(true);
- sendBtn.setBackgroundColor(Color.parseColor("#ff0000"));
- sendBtn.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View v) {
- String content = userReplyContentEdit.getEditableText()
- .toString().trim();
- if (TextUtils.isEmpty(content))
- return;
- if (content.length() < 10)
- return;
- Toast.makeText(ConversationActivity.this,
- "Thanks for your advice.", Toast.LENGTH_SHORT)
- .show();
- userReplyContentEdit.getEditableText().clear();
- defaultConversation.addUserReply(content);
- sync();
- InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
- if (imm != null)
- imm.hideSoftInputFromWindow(
- userReplyContentEdit.getWindowToken(), 0);
- UserInfo info = agent.getUserInfo();
- if (info == null)
- info = new UserInfo();
- Map<String, String> contact = info.getContact();
- if (contact == null)
- contact = new HashMap<String, String>();
- String contact_info = contactInfo.getEditableText()
- .toString();
- contact.put(KEY_UMENG_CONTACT_INFO_PLAIN_TEXT, contact_info);
- info.setContact(contact);
- agent.setUserInfo(info);
- contactInfo.getEditableText().clear();
- }
- });
- }
- };
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.umeng_fb_activity_conversation);
- try {
- agent = new FeedbackAgent(this);
- defaultConversation = agent.getDefaultConversation();
- sync();
- userReplyContentEdit = (EditText) findViewById(R.id.umeng_fb_replyContent);
- contactInfo = (EditText) findViewById(R.id.umeng_fb_contactInfo);
- userReplyContentEdit.addTextChangedListener(watcher);
- } catch (Exception e) {
- e.printStackTrace();
- this.finish();
- }
- }
- @Override
- protected void onStart() {
- super.onStart();
- getSupportActionBar().setDisplayHomeAsUpEnabled(false);
- getSupportActionBar().setDisplayShowHomeEnabled(false);
- getSupportActionBar().setDisplayShowTitleEnabled(false);
- getSupportActionBar().setBackgroundDrawable(
- getResources().getDrawable(R.drawable.top1));
- initActionBar();
- }
- private void initActionBar() {
- getSupportActionBar().setDisplayShowCustomEnabled(true);
- View actionbarLayout = LayoutInflater.from(this).inflate(
- R.layout.jyx_actionbar_edit, null);
- getSupportActionBar().setCustomView(actionbarLayout);
- back_imbt = (RadioButton) actionbarLayout.findViewById(R.id.back_imbt);
- sendBtn = (Button) actionbarLayout.findViewById(R.id.edit_imbt);
- tv_title = (TextView) actionbarLayout.findViewById(R.id.tv_title);
- tv_title.setText("Advice");
- sendBtn.setText("Send");
- sendBtn.setClickable(false);
- back_imbt.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View view) {
- finish();
- }
- });
- }
- void sync() {
- Conversation.SyncListener listener = new Conversation.SyncListener() {
- @Override
- public void onSendUserReply(List<Reply> replyList) {
- }
- @Override
- public void onReceiveDevReply(List<DevReply> replyList) {
- }
- };
- defaultConversation.sync(listener);
- }
- }