Skip to content

Commit f489374

Browse files
HXQWillxingquan.he
authored andcommittedJun 7, 2017
项目实战:优雅的实现专车意见反馈
1 parent f8a32ae commit f489374

File tree

13 files changed

+290
-17
lines changed

13 files changed

+290
-17
lines changed
 

‎app/src/main/AndroidManifest.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@
4646
android:screenOrientation="portrait"
4747
android:theme="@style/PopActivityTheme"
4848
></activity>
49+
<activity
50+
android:name=".ucar.usercenter.FeedBackActivity"
51+
android:screenOrientation="portrait"
52+
android:theme="@style/BaseActivityTheme"
53+
></activity>
4954
</application>
5055

5156
</manifest>

‎app/src/main/java/com/example/quan/quanstudy/MainActivity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public void onClick(View v) {
7979
gotoNextActivity(MainDesignActivity.class);
8080
break;
8181
case R.id.ucar_btn_main:
82-
M.monitor().onEvent(context, Keys.MAIN_UCAR);
82+
M.monitor().onEvent(mContext, Keys.MAIN_UCAR);
8383
gotoNextActivity(MainUcarActivity.class);
8484
break;
8585
default:

‎app/src/main/java/com/example/quan/quanstudy/base/BaseActivity.java

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import android.content.Intent;
66
import android.os.Bundle;
77
import android.view.View;
8+
import android.view.inputmethod.InputMethodManager;
89
import android.widget.ImageView;
910
import android.widget.TextView;
1011

@@ -21,17 +22,17 @@
2122
* Created by xq.he on 2017/3/13.
2223
*/
2324

24-
public abstract class BaseActivity extends Activity implements View.OnClickListener{
25+
public abstract class BaseActivity extends Activity implements View.OnClickListener {
2526

26-
public Context context;
27+
public Context mContext;
2728

2829
private MoreWidget more_widget;
2930

3031
@Override
3132
protected void onCreate(Bundle savedInstanceState) {
3233
super.onCreate(savedInstanceState);
3334
M.monitor().enableEncrypt(true);
34-
context = this;
35+
mContext = this;
3536
setContentView(getLayoutId());
3637
initView();
3738
LogUtil.d(getClass().getName());
@@ -42,13 +43,13 @@ protected void onCreate(Bundle savedInstanceState) {
4243
@Override
4344
protected void onPause() {
4445
super.onPause();
45-
M.monitor().onPause(context);
46+
M.monitor().onPause(mContext);
4647
}
4748

4849
@Override
4950
protected void onResume() {
5051
super.onResume();
51-
M.monitor().onResume(context);
52+
M.monitor().onResume(mContext);
5253
}
5354

5455
@Override
@@ -94,7 +95,7 @@ public void onClick(View v) {
9495
}
9596
}
9697

97-
public void removeAllMoreItem(){
98+
public void removeAllMoreItem() {
9899
if (more_widget != null) {
99100
more_widget.removeAllItems();
100101
}
@@ -112,5 +113,14 @@ public void addTitleMoreItem(int iconId, String content, MoreWidget.ClickCallbac
112113
}
113114
}
114115

116+
/**
117+
* 隐藏软键盘
118+
*/
119+
public void hideInputMethod() {
120+
InputMethodManager imm = (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
121+
if (imm != null && this.getCurrentFocus() != null) {
122+
imm.hideSoftInputFromWindow(this.getCurrentFocus().getWindowToken(), 0);
123+
}
124+
}
115125

116126
}

‎app/src/main/java/com/example/quan/quanstudy/ucar/MainUcarActivity.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import com.example.quan.quanstudy.R;
88
import com.example.quan.quanstudy.base.BaseActivity;
99
import com.example.quan.quanstudy.ucar.trip.TripFeeDetailActivity;
10+
import com.example.quan.quanstudy.ucar.usercenter.FeedBackActivity;
1011

1112
import monitor.M;
1213
import monitor.Keys;
@@ -18,7 +19,8 @@
1819

1920
public class MainUcarActivity extends BaseActivity {
2021

21-
private Button mTripDemo;
22+
private Button mTripFeeDemo;
23+
private Button mFeedBackDemo;
2224

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

3537
@Override
3638
public void initView() {
37-
mTripDemo = (Button) findViewById(R.id.trip_btn_ucar);
39+
mTripFeeDemo = (Button) findViewById(R.id.tripfee_btn_ucar);
40+
mFeedBackDemo = (Button) findViewById(R.id.feedback_btn_ucar);
3841
initTitle(R.string.ucar);
3942
findViewById(R.id.back_title).setOnClickListener(this);
4043
}
4144

4245
private void initOnClickListener() {
43-
mTripDemo.setOnClickListener(this);
46+
mTripFeeDemo.setOnClickListener(this);
47+
mFeedBackDemo.setOnClickListener(this);
4448
}
4549

4650
@Override
4751
public void onClick(View v) {
4852
super.onClick(v);
4953
switch (v.getId()) {
50-
case R.id.trip_btn_ucar:
51-
M.monitor().onEvent(context, Keys.UCAR_TRIPFEEDETAIL);
54+
case R.id.tripfee_btn_ucar:
55+
M.monitor().onEvent(mContext, Keys.UCAR_TRIPFEEDETAIL);
5256
gotoNextActivity(TripFeeDetailActivity.class);
5357
break;
58+
case R.id.feedback_btn_ucar:
59+
gotoNextActivity(FeedBackActivity.class);
60+
break;
5461
case R.id.back_title:
5562
finish();
5663
default:
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
package com.example.quan.quanstudy.ucar.usercenter;
2+
3+
import android.os.Bundle;
4+
import android.text.Editable;
5+
import android.text.TextUtils;
6+
import android.text.TextWatcher;
7+
import android.view.View;
8+
import android.widget.EditText;
9+
import android.widget.TextView;
10+
import android.widget.Toast;
11+
12+
import com.example.quan.quanstudy.R;
13+
import com.example.quan.quanstudy.base.BaseActivity;
14+
import com.example.quan.quanstudy.util.Utils;
15+
16+
/**
17+
* Created by xingquan.he on 2017/6/2.
18+
* 意见反馈
19+
*/
20+
21+
public class FeedBackActivity extends BaseActivity {
22+
private EditText mContentEt;
23+
private TextView mWatchWordsTv;
24+
private static final String DEFAULTNUM = "200";
25+
private static final int MAXNUM = 200;
26+
private TextView mCommitTv;
27+
28+
@Override
29+
protected void onCreate(Bundle savedInstanceState) {
30+
super.onCreate(savedInstanceState);
31+
32+
initOnClickListener();
33+
}
34+
35+
@Override
36+
public int getLayoutId() {
37+
return R.layout.activity_ucar_feedback;
38+
}
39+
40+
@Override
41+
public void initView() {
42+
mCommitTv = (TextView) findViewById(R.id.commit_tv_feedback);
43+
mCommitTv.setEnabled(false);
44+
mContentEt = (EditText) findViewById(R.id.content_et_feedback);
45+
mContentEt.addTextChangedListener(new TextWatcher() {
46+
@Override
47+
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
48+
49+
}
50+
51+
@Override
52+
public void onTextChanged(CharSequence s, int start, int before, int count) {
53+
if (TextUtils.isEmpty(mContentEt.getText().toString())) {
54+
mCommitTv.setEnabled(false);
55+
} else {
56+
mCommitTv.setEnabled(true);
57+
}
58+
}
59+
60+
@Override
61+
public void afterTextChanged(Editable s) {
62+
int length = mContentEt.getText().length();
63+
if (length > MAXNUM) {
64+
Toast.makeText(mContext, getString(R.string.input_feedback_content_long), Toast.LENGTH_SHORT).show();
65+
String text = mContentEt.getText().toString()
66+
.substring(0, MAXNUM - 1);
67+
mContentEt.setText(text);
68+
length = MAXNUM;
69+
}
70+
int left = MAXNUM - length;
71+
mWatchWordsTv.setText(String.format(getResources().getString(R.string.default_feedback_words), Integer.toString(left)));
72+
}
73+
});
74+
mWatchWordsTv = (TextView) findViewById(R.id.watchWords_tv_feedback);
75+
mWatchWordsTv.setText(String.format(getResources().getString(R.string.default_feedback_words), DEFAULTNUM));
76+
initTitle(R.string.feedback);
77+
findViewById(R.id.back_title).setOnClickListener(this);
78+
}
79+
80+
private void initOnClickListener() {
81+
mCommitTv.setOnClickListener(this);
82+
}
83+
84+
@Override
85+
public void onClick(View v) {
86+
super.onClick(v);
87+
switch (v.getId()) {
88+
case R.id.commit_tv_feedback:
89+
Utils.stringFilter(mContentEt.getText().toString());
90+
//网络请求,成功后往下走;若失败,提示并留在当前页面
91+
Toast.makeText(mContext, getString(R.string.feedback_success), Toast.LENGTH_SHORT).show();
92+
hideInputMethod();
93+
finish();
94+
break;
95+
case R.id.back_title:
96+
finish();
97+
default:
98+
break;
99+
}
100+
}
101+
102+
}

‎app/src/main/res/layout/activity_ucar.xml

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
layout="@layout/base_title_layout" />
1515

1616
<Button
17-
android:id="@+id/trip_btn_ucar"
17+
android:id="@+id/tripfee_btn_ucar"
1818
android:layout_width="match_parent"
1919
android:layout_height="@dimen/dd_dimen_76px"
2020
android:text="费用明细"
@@ -27,7 +27,20 @@
2727
android:layout_marginTop="@dimen/dd_dimen_45px"
2828
android:layout_below="@id/ucar_title"
2929
android:gravity="center"
30-
30+
/>
31+
<Button
32+
android:id="@+id/feedback_btn_ucar"
33+
android:layout_width="match_parent"
34+
android:layout_height="@dimen/dd_dimen_76px"
35+
android:text="意见反馈"
36+
android:textColor="@drawable/common_button_textcolor_selector"
37+
android:textSize="@dimen/dd_dimen_32px"
38+
android:background="@drawable/common_button_selector"
39+
android:layout_marginBottom="@dimen/dd_dimen_10px"
40+
android:layout_marginLeft="@dimen/dd_dimen_36px"
41+
android:layout_marginRight="@dimen/dd_dimen_36px"
42+
android:layout_marginTop="@dimen/dd_dimen_45px"
43+
android:gravity="center"
3144
/>
3245

3346
</LinearLayout>
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
2+
xmlns:tools="http://schemas.android.com/tools"
3+
android:layout_width="match_parent"
4+
android:layout_height="match_parent"
5+
android:background="@color/color_f5f4f2" >
6+
7+
<!-- Title layout -->
8+
9+
<include
10+
android:id="@+id/base_title_layout"
11+
layout="@layout/base_title_layout" />
12+
13+
<!-- Content layout -->
14+
15+
<LinearLayout
16+
android:layout_width="match_parent"
17+
android:layout_height="match_parent"
18+
android:layout_below="@+id/base_title_layout"
19+
android:gravity="center_horizontal"
20+
android:orientation="vertical" >
21+
22+
<LinearLayout
23+
android:layout_width="match_parent"
24+
android:layout_height="@dimen/dd_dimen_230px"
25+
android:layout_marginTop="@dimen/dd_dimen_30px"
26+
android:layout_marginRight="@dimen/dd_dimen_30px"
27+
android:layout_marginLeft="@dimen/dd_dimen_30px"
28+
android:background="@drawable/common_radius_rectangle"
29+
android:orientation="vertical" >
30+
31+
<EditText
32+
android:id="@+id/content_et_feedback"
33+
android:layout_width="match_parent"
34+
android:layout_height="wrap_content"
35+
android:background="@android:color/transparent"
36+
android:gravity="left"
37+
android:hint="@string/input_feedback_hint"
38+
android:layout_weight="1"
39+
android:maxLength="200"
40+
android:minHeight="@dimen/dd_dimen_300px"
41+
android:paddingBottom="@dimen/dd_dimen_20px"
42+
android:paddingLeft="@dimen/dd_dimen_20px"
43+
android:paddingRight="@dimen/dd_dimen_20px"
44+
android:paddingTop="@dimen/dd_dimen_20px"
45+
android:textColor="@color/color_333333"
46+
android:textColorHint="@color/color_999999"
47+
android:textSize="@dimen/dd_dimen_28px" />
48+
49+
<TextView
50+
android:id="@+id/watchWords_tv_feedback"
51+
android:layout_width="match_parent"
52+
android:layout_height="wrap_content"
53+
android:layout_gravity="right"
54+
android:gravity="center_vertical|right"
55+
android:paddingBottom="@dimen/dd_dimen_12px"
56+
android:paddingRight="@dimen/dd_dimen_12px"
57+
android:textColor="@color/color_999999"
58+
android:textSize="@dimen/dd_dimen_24px" />
59+
</LinearLayout>
60+
61+
<TextView
62+
android:id="@+id/commit_tv_feedback"
63+
android:layout_width="match_parent"
64+
android:layout_height="@dimen/dd_dimen_87px"
65+
android:layout_marginBottom="@dimen/dd_dimen_30px"
66+
android:layout_marginLeft="@dimen/dd_dimen_30px"
67+
android:layout_marginRight="@dimen/dd_dimen_30px"
68+
android:layout_marginTop="@dimen/dd_dimen_30px"
69+
android:background="@drawable/common_button_enable"
70+
android:gravity="center"
71+
android:text="提交"
72+
android:textColor="@color/white"
73+
android:textSize="@dimen/dd_dimen_30px" />
74+
</LinearLayout>
75+
76+
</RelativeLayout>

‎app/src/main/res/values/strings.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,11 @@
99
<string name="ucar">神州专车</string>
1010
<string name="trip_feedetail">费用明细</string>
1111
<string name="trip_doubt">账单疑义</string>
12+
<string name="feedback">意见反馈</string>
13+
14+
<string name="input_feedback_hint">您的要求是我们努力的方向,期待听到您的声音</string>
15+
<string name="default_feedback_words">%s/200</string>
16+
<string name="please_input_feedback_tip">请输入反馈信息</string>
17+
<string name="feedback_success">提交成功</string>
18+
<string name="input_feedback_content_long">您的输入已经超过限制!</string>
1219
</resources>

‎quanlibrary/src/main/java/com/example/quan/quanstudy/util/Utils.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
package com.example.quan.quanstudy.util;
22

3+
import android.text.TextUtils;
4+
5+
import java.util.regex.Matcher;
6+
import java.util.regex.Pattern;
7+
38
/**
49
* Created by xingquan.he on 2017/3/31.
510
* Mr.Quan
@@ -17,4 +22,23 @@ public static boolean isFastClick() {
1722
lastClickTime = time;
1823
return false;
1924
}
25+
26+
/**
27+
* 过滤特殊字符
28+
*/
29+
public static String stringFilter(String str) {
30+
if (TextUtils.isEmpty(str)) {
31+
return "";
32+
}
33+
String regEx = "[<>'\"]";
34+
str = str.replaceAll("&nbsp;", "").replaceAll("&amp;", "")
35+
.replaceAll("#160;", "").replaceAll("&lt;", "")
36+
.replaceAll("&gt;", "").replaceAll("&quot;", "")
37+
.replaceAll("&#60;", "").replaceAll("&#62;", "")
38+
.replaceAll("&#38;", "").replaceAll("&#34;", "");
39+
Pattern p = Pattern.compile(regEx);
40+
Matcher m = p.matcher(str);
41+
return m.replaceAll("").trim();
42+
}
43+
2044
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<selector xmlns:android="http://schemas.android.com/apk/res/android">
3+
4+
<item android:drawable="@drawable/common_button_pressed" android:state_enabled="true"/>
5+
<item android:drawable="@drawable/common_button_unpressed" android:state_enabled="false"/>
6+
7+
</selector>
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<selector xmlns:android="http://schemas.android.com/apk/res/android">
33

4-
<item android:drawable="@drawable/common_button_pressed" android:state_pressed="true"/>
5-
<item android:drawable="@drawable/common_button_unpressed" android:state_pressed="false"/>
4+
<item android:drawable="@drawable/common_button_pressed" android:state_pressed="true" android:state_enabled="true"/>
5+
<item android:drawable="@drawable/common_button_unpressed" android:state_pressed="false" android:state_enabled="false"/>
66

77
</selector>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<shape
3+
xmlns:android="http://schemas.android.com/apk/res/android"
4+
android:shape="rectangle" >
5+
6+
<!-- 圆角 -->
7+
<corners
8+
android:radius="@dimen/dd_dimen_6px" />
9+
10+
<!-- 描边 -->
11+
<stroke
12+
android:width="1px"
13+
android:color="@color/color_e5e5e5" />
14+
15+
<!-- 实心 填充 -->
16+
<solid
17+
android:color="@color/white" />
18+
19+
</shape>

‎quanlibrary/src/main/res/values/colors.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,14 @@
77
<color name="color_dbac6f">#dbac6f</color>
88
<color name="color_d9d9d9">#d9d9d9</color>
99
<color name="color_fef7ed">#fef7ed</color>
10-
<color name="white">#FFFFFF</color>
1110
<color name="color_373635">#373635</color>
1211
<color name="color_deb682">#deb682</color>
1312
<color name="color_434241">#434241</color>
1413
<color name="color_f5f4f2">#f5f4f2</color>
14+
<color name="color_e5e5e5">#e5e5e5</color>
15+
<color name="color_333333">#333333</color>
16+
<color name="color_999999">#999999</color>
1517

18+
<color name="white">#FFFFFF</color>
1619
<color name="login_divider">#dcdcdc</color>
1720
</resources>

0 commit comments

Comments
 (0)
Please sign in to comment.