Skip to content

Commit

Permalink
项目实战:优雅的实现专车意见反馈
Browse files Browse the repository at this point in the history
  • Loading branch information
HXQWill authored and xingquan.he committed Jun 7, 2017
1 parent f8a32ae commit f489374
Show file tree
Hide file tree
Showing 13 changed files with 290 additions and 17 deletions.
5 changes: 5 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@
android:screenOrientation="portrait"
android:theme="@style/PopActivityTheme"
></activity>
<activity
android:name=".ucar.usercenter.FeedBackActivity"
android:screenOrientation="portrait"
android:theme="@style/BaseActivityTheme"
></activity>
</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public void onClick(View v) {
gotoNextActivity(MainDesignActivity.class);
break;
case R.id.ucar_btn_main:
M.monitor().onEvent(context, Keys.MAIN_UCAR);
M.monitor().onEvent(mContext, Keys.MAIN_UCAR);
gotoNextActivity(MainUcarActivity.class);
break;
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.ImageView;
import android.widget.TextView;

Expand All @@ -21,17 +22,17 @@
* Created by xq.he on 2017/3/13.
*/

public abstract class BaseActivity extends Activity implements View.OnClickListener{
public abstract class BaseActivity extends Activity implements View.OnClickListener {

public Context context;
public Context mContext;

private MoreWidget more_widget;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
M.monitor().enableEncrypt(true);
context = this;
mContext = this;
setContentView(getLayoutId());
initView();
LogUtil.d(getClass().getName());
Expand All @@ -42,13 +43,13 @@ protected void onCreate(Bundle savedInstanceState) {
@Override
protected void onPause() {
super.onPause();
M.monitor().onPause(context);
M.monitor().onPause(mContext);
}

@Override
protected void onResume() {
super.onResume();
M.monitor().onResume(context);
M.monitor().onResume(mContext);
}

@Override
Expand Down Expand Up @@ -94,7 +95,7 @@ public void onClick(View v) {
}
}

public void removeAllMoreItem(){
public void removeAllMoreItem() {
if (more_widget != null) {
more_widget.removeAllItems();
}
Expand All @@ -112,5 +113,14 @@ public void addTitleMoreItem(int iconId, String content, MoreWidget.ClickCallbac
}
}

/**
* 隐藏软键盘
*/
public void hideInputMethod() {
InputMethodManager imm = (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
if (imm != null && this.getCurrentFocus() != null) {
imm.hideSoftInputFromWindow(this.getCurrentFocus().getWindowToken(), 0);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.example.quan.quanstudy.R;
import com.example.quan.quanstudy.base.BaseActivity;
import com.example.quan.quanstudy.ucar.trip.TripFeeDetailActivity;
import com.example.quan.quanstudy.ucar.usercenter.FeedBackActivity;

import monitor.M;
import monitor.Keys;
Expand All @@ -18,7 +19,8 @@

public class MainUcarActivity extends BaseActivity {

private Button mTripDemo;
private Button mTripFeeDemo;
private Button mFeedBackDemo;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -34,23 +36,28 @@ public int getLayoutId() {

@Override
public void initView() {
mTripDemo = (Button) findViewById(R.id.trip_btn_ucar);
mTripFeeDemo = (Button) findViewById(R.id.tripfee_btn_ucar);
mFeedBackDemo = (Button) findViewById(R.id.feedback_btn_ucar);
initTitle(R.string.ucar);
findViewById(R.id.back_title).setOnClickListener(this);
}

private void initOnClickListener() {
mTripDemo.setOnClickListener(this);
mTripFeeDemo.setOnClickListener(this);
mFeedBackDemo.setOnClickListener(this);
}

@Override
public void onClick(View v) {
super.onClick(v);
switch (v.getId()) {
case R.id.trip_btn_ucar:
M.monitor().onEvent(context, Keys.UCAR_TRIPFEEDETAIL);
case R.id.tripfee_btn_ucar:
M.monitor().onEvent(mContext, Keys.UCAR_TRIPFEEDETAIL);
gotoNextActivity(TripFeeDetailActivity.class);
break;
case R.id.feedback_btn_ucar:
gotoNextActivity(FeedBackActivity.class);
break;
case R.id.back_title:
finish();
default:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package com.example.quan.quanstudy.ucar.usercenter;

import android.os.Bundle;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.example.quan.quanstudy.R;
import com.example.quan.quanstudy.base.BaseActivity;
import com.example.quan.quanstudy.util.Utils;

/**
* Created by xingquan.he on 2017/6/2.
* 意见反馈
*/

public class FeedBackActivity extends BaseActivity {
private EditText mContentEt;
private TextView mWatchWordsTv;
private static final String DEFAULTNUM = "200";
private static final int MAXNUM = 200;
private TextView mCommitTv;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

initOnClickListener();
}

@Override
public int getLayoutId() {
return R.layout.activity_ucar_feedback;
}

@Override
public void initView() {
mCommitTv = (TextView) findViewById(R.id.commit_tv_feedback);
mCommitTv.setEnabled(false);
mContentEt = (EditText) findViewById(R.id.content_et_feedback);
mContentEt.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {

}

@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if (TextUtils.isEmpty(mContentEt.getText().toString())) {
mCommitTv.setEnabled(false);
} else {
mCommitTv.setEnabled(true);
}
}

@Override
public void afterTextChanged(Editable s) {
int length = mContentEt.getText().length();
if (length > MAXNUM) {
Toast.makeText(mContext, getString(R.string.input_feedback_content_long), Toast.LENGTH_SHORT).show();
String text = mContentEt.getText().toString()
.substring(0, MAXNUM - 1);
mContentEt.setText(text);
length = MAXNUM;
}
int left = MAXNUM - length;
mWatchWordsTv.setText(String.format(getResources().getString(R.string.default_feedback_words), Integer.toString(left)));
}
});
mWatchWordsTv = (TextView) findViewById(R.id.watchWords_tv_feedback);
mWatchWordsTv.setText(String.format(getResources().getString(R.string.default_feedback_words), DEFAULTNUM));
initTitle(R.string.feedback);
findViewById(R.id.back_title).setOnClickListener(this);
}

private void initOnClickListener() {
mCommitTv.setOnClickListener(this);
}

@Override
public void onClick(View v) {
super.onClick(v);
switch (v.getId()) {
case R.id.commit_tv_feedback:
Utils.stringFilter(mContentEt.getText().toString());
//网络请求,成功后往下走;若失败,提示并留在当前页面
Toast.makeText(mContext, getString(R.string.feedback_success), Toast.LENGTH_SHORT).show();
hideInputMethod();
finish();
break;
case R.id.back_title:
finish();
default:
break;
}
}

}
17 changes: 15 additions & 2 deletions app/src/main/res/layout/activity_ucar.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
layout="@layout/base_title_layout" />

<Button
android:id="@+id/trip_btn_ucar"
android:id="@+id/tripfee_btn_ucar"
android:layout_width="match_parent"
android:layout_height="@dimen/dd_dimen_76px"
android:text="费用明细"
Expand All @@ -27,7 +27,20 @@
android:layout_marginTop="@dimen/dd_dimen_45px"
android:layout_below="@id/ucar_title"
android:gravity="center"

/>
<Button
android:id="@+id/feedback_btn_ucar"
android:layout_width="match_parent"
android:layout_height="@dimen/dd_dimen_76px"
android:text="意见反馈"
android:textColor="@drawable/common_button_textcolor_selector"
android:textSize="@dimen/dd_dimen_32px"
android:background="@drawable/common_button_selector"
android:layout_marginBottom="@dimen/dd_dimen_10px"
android:layout_marginLeft="@dimen/dd_dimen_36px"
android:layout_marginRight="@dimen/dd_dimen_36px"
android:layout_marginTop="@dimen/dd_dimen_45px"
android:gravity="center"
/>

</LinearLayout>
76 changes: 76 additions & 0 deletions app/src/main/res/layout/activity_ucar_feedback.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/color_f5f4f2" >

<!-- Title layout -->

<include
android:id="@+id/base_title_layout"
layout="@layout/base_title_layout" />

<!-- Content layout -->

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/base_title_layout"
android:gravity="center_horizontal"
android:orientation="vertical" >

<LinearLayout
android:layout_width="match_parent"
android:layout_height="@dimen/dd_dimen_230px"
android:layout_marginTop="@dimen/dd_dimen_30px"
android:layout_marginRight="@dimen/dd_dimen_30px"
android:layout_marginLeft="@dimen/dd_dimen_30px"
android:background="@drawable/common_radius_rectangle"
android:orientation="vertical" >

<EditText
android:id="@+id/content_et_feedback"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:gravity="left"
android:hint="@string/input_feedback_hint"
android:layout_weight="1"
android:maxLength="200"
android:minHeight="@dimen/dd_dimen_300px"
android:paddingBottom="@dimen/dd_dimen_20px"
android:paddingLeft="@dimen/dd_dimen_20px"
android:paddingRight="@dimen/dd_dimen_20px"
android:paddingTop="@dimen/dd_dimen_20px"
android:textColor="@color/color_333333"
android:textColorHint="@color/color_999999"
android:textSize="@dimen/dd_dimen_28px" />

<TextView
android:id="@+id/watchWords_tv_feedback"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:gravity="center_vertical|right"
android:paddingBottom="@dimen/dd_dimen_12px"
android:paddingRight="@dimen/dd_dimen_12px"
android:textColor="@color/color_999999"
android:textSize="@dimen/dd_dimen_24px" />
</LinearLayout>

<TextView
android:id="@+id/commit_tv_feedback"
android:layout_width="match_parent"
android:layout_height="@dimen/dd_dimen_87px"
android:layout_marginBottom="@dimen/dd_dimen_30px"
android:layout_marginLeft="@dimen/dd_dimen_30px"
android:layout_marginRight="@dimen/dd_dimen_30px"
android:layout_marginTop="@dimen/dd_dimen_30px"
android:background="@drawable/common_button_enable"
android:gravity="center"
android:text="提交"
android:textColor="@color/white"
android:textSize="@dimen/dd_dimen_30px" />
</LinearLayout>

</RelativeLayout>
7 changes: 7 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,11 @@
<string name="ucar">神州专车</string>
<string name="trip_feedetail">费用明细</string>
<string name="trip_doubt">账单疑义</string>
<string name="feedback">意见反馈</string>

<string name="input_feedback_hint">您的要求是我们努力的方向,期待听到您的声音</string>
<string name="default_feedback_words">%s/200</string>
<string name="please_input_feedback_tip">请输入反馈信息</string>
<string name="feedback_success">提交成功</string>
<string name="input_feedback_content_long">您的输入已经超过限制!</string>
</resources>

0 comments on commit f489374

Please sign in to comment.