友盟意见反馈——对话框改为单一的用户反馈

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);
	}
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值