└── app
├── .gitignore
├── src
├── main6-7.rar
├── main
│ ├── res
│ │ ├── values
│ │ │ ├── strings.xml
│ │ │ ├── colors.xml
│ │ │ ├── styles.xml
│ │ │ └── attrs_custom.xml
│ │ ├── mipmap-hdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-mdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-xhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxxhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── drawable
│ │ │ ├── login_btn_normal.xml
│ │ │ ├── login_btn_press.xml
│ │ │ ├── messageboard_ll_bg.xml
│ │ │ ├── login_et_normal.xml
│ │ │ ├── login_et_press.xml
│ │ │ └── login_btn.xml
│ │ └── layout
│ │ │ ├── item_message_board.xml
│ │ │ ├── activity_main.xml
│ │ │ ├── layout_input_dialog.xml
│ │ │ ├── activity_message_board.xml
│ │ │ ├── layout_inputview.xml
│ │ │ ├── activity_login.xml
│ │ │ └── activity_register.xml
│ ├── java
│ │ └── zzw
│ │ │ └── bmobtest
│ │ │ ├── constant
│ │ │ └── Constant.java
│ │ │ ├── bean
│ │ │ ├── UserBean.java
│ │ │ └── MessageBean.java
│ │ │ ├── base
│ │ │ └── BaseActivity.java
│ │ │ ├── MyApplication.java
│ │ │ ├── adapter
│ │ │ └── MessageBoardAdapter.java
│ │ │ ├── activity
│ │ │ ├── MainActivity.java
│ │ │ ├── LoginActivity.java
│ │ │ ├── RegisterActivity.java
│ │ │ └── MessageBoardActivity.java
│ │ │ ├── util
│ │ │ ├── LogUtil.java
│ │ │ ├── ToastUtil.java
│ │ │ └── SPUtils.java
│ │ │ └── view
│ │ │ └── InputView.java
│ └── AndroidManifest.xml
├── test
│ └── java
│ │ └── zzw
│ │ └── bmobtest
│ │ └── ExampleUnitTest.java
└── androidTest
│ └── java
│ └── zzw
│ └── bmobtest
│ └── ExampleInstrumentedTest.java
├── build.gradle
└── app.iml
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/src/main6-7.rar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/979451341/BmobTest/HEAD/app/src/main6-7.rar
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | BmobTest
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/979451341/BmobTest/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/979451341/BmobTest/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/979451341/BmobTest/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/979451341/BmobTest/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/979451341/BmobTest/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/979451341/BmobTest/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/979451341/BmobTest/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/979451341/BmobTest/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/979451341/BmobTest/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/979451341/BmobTest/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/login_btn_normal.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/login_btn_press.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/messageboard_ll_bg.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 | #7e7e7e
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/login_et_normal.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/login_et_press.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/java/zzw/bmobtest/constant/Constant.java:
--------------------------------------------------------------------------------
1 | package zzw.bmobtest.constant;
2 |
3 | /**
4 | * Created by ASUS on 2018/6/6.
5 | */
6 |
7 | public class Constant {
8 |
9 | public static String USERNAME = "username";
10 | public static String PASSWORD = "password";
11 | public static String OBJECTID = "objectId";
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/login_btn.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | -
6 |
7 |
8 | -
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/app/src/test/java/zzw/bmobtest/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package zzw.bmobtest;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/app/src/main/java/zzw/bmobtest/bean/UserBean.java:
--------------------------------------------------------------------------------
1 | package zzw.bmobtest.bean;
2 |
3 | import cn.bmob.v3.BmobObject;
4 |
5 | /**
6 | * Created by ASUS on 2018/6/6.
7 | */
8 |
9 | public class UserBean extends BmobObject{
10 |
11 | private String name;
12 | private String password;
13 |
14 |
15 | public String getName() {
16 | return name;
17 | }
18 |
19 | public void setName(String name) {
20 | this.name = name;
21 | }
22 |
23 | public String getPassword() {
24 | return password;
25 | }
26 |
27 | public void setPassword(String password) {
28 | this.password = password;
29 | }
30 |
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/app/src/main/java/zzw/bmobtest/bean/MessageBean.java:
--------------------------------------------------------------------------------
1 | package zzw.bmobtest.bean;
2 |
3 | import cn.bmob.v3.BmobObject;
4 |
5 | /**
6 | * Created by ASUS on 2018/6/9.
7 | */
8 |
9 | public class MessageBean extends BmobObject{
10 |
11 | private String content;
12 | private String username;
13 |
14 |
15 | public String getContent() {
16 | return content;
17 | }
18 |
19 | public void setContent(String content) {
20 | this.content = content;
21 | }
22 |
23 | public String getUsername() {
24 | return username;
25 | }
26 |
27 | public void setUsername(String username) {
28 | this.username = username;
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/item_message_board.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
14 |
15 |
20 |
21 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/zzw/bmobtest/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package zzw.bmobtest;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumentation test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("zzw.bmobtest", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/java/zzw/bmobtest/base/BaseActivity.java:
--------------------------------------------------------------------------------
1 | package zzw.bmobtest.base;
2 |
3 | import android.app.Activity;
4 | import android.os.Bundle;
5 | import android.os.PersistableBundle;
6 | import android.support.annotation.Nullable;
7 |
8 | import com.zhy.autolayout.AutoLayoutActivity;
9 |
10 | import butterknife.ButterKnife;
11 |
12 | /**
13 | * Created by ASUS on 2018/6/3.
14 | */
15 |
16 | public abstract class BaseActivity extends AutoLayoutActivity {
17 |
18 |
19 | @Override
20 | protected void onCreate(@Nullable Bundle savedInstanceState) {
21 | super.onCreate(savedInstanceState);
22 | setContentView(getLayout());
23 | ButterKnife.bind(this);
24 | initView();
25 | initData();
26 | }
27 |
28 |
29 |
30 | public abstract int getLayout();
31 | public abstract void initView();
32 | public abstract void initData();
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/layout_input_dialog.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
16 |
17 |
26 |
27 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_message_board.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
13 |
14 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/app/src/main/java/zzw/bmobtest/MyApplication.java:
--------------------------------------------------------------------------------
1 | package zzw.bmobtest;
2 |
3 | import android.app.Application;
4 | import android.content.Context;
5 |
6 | import cn.bmob.v3.Bmob;
7 | import cn.bmob.v3.BmobConfig;
8 |
9 | /**
10 | * Created by ASUS on 2018/6/3.
11 | */
12 |
13 | public class MyApplication extends Application {
14 |
15 | private static Context context;
16 | @Override
17 | public void onCreate() {
18 | super.onCreate();
19 |
20 | //第二:自v3.4.7版本开始,设置BmobConfig,允许设置请求超时时间、文件分片上传时每片的大小、文件的过期时间(单位为秒),
21 | BmobConfig config =new BmobConfig.Builder(this)
22 | ////设置appkey
23 | .setApplicationId("55635d865b1609c2afce397d6617b6b8")
24 | ////请求超时时间(单位为秒):默认15s
25 | .setConnectTimeout(15)
26 | ////文件分片上传时每片的大小(单位字节),默认512*1024
27 | //.setUploadBlockSize(1024*1024)
28 | ////文件的过期时间(单位为秒):默认1800s
29 | //.setFileExpiration(2500)
30 | .build();
31 | Bmob.initialize(config);
32 |
33 | context = this;
34 | }
35 |
36 | public static Context getContext(){
37 | return context;
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/layout_inputview.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
10 |
11 |
19 |
20 |
31 |
32 |
--------------------------------------------------------------------------------
/app/src/main/java/zzw/bmobtest/adapter/MessageBoardAdapter.java:
--------------------------------------------------------------------------------
1 | package zzw.bmobtest.adapter;
2 |
3 | import android.support.annotation.LayoutRes;
4 | import android.support.annotation.Nullable;
5 |
6 | import com.chad.library.adapter.base.BaseQuickAdapter;
7 | import com.chad.library.adapter.base.BaseViewHolder;
8 |
9 | import java.util.List;
10 |
11 | import zzw.bmobtest.R;
12 | import zzw.bmobtest.bean.MessageBean;
13 |
14 | /**
15 | * Created by ASUS on 2018/6/9.
16 | */
17 |
18 | public class MessageBoardAdapter extends BaseQuickAdapter {
19 |
20 | public MessageBoardAdapter(@LayoutRes int layoutResId, @Nullable List data) {
21 | super(layoutResId, data);
22 | }
23 | @Override
24 | protected void convert(BaseViewHolder helper, MessageBean item) {
25 | /* //可链式调用赋值
26 | helper.setText(R.id.tv_title, item.getTitle())
27 | .setText(R.id.tv_content, item.getContent())
28 | .addOnClickListener(R.id.iv_img) //给图标添加点击事件
29 | .setImageResource(R.id.iv_img, R.mipmap.ic_launcher);
30 |
31 | //获取当前条目position
32 | //int position = helper.getLayoutPosition();*/
33 | helper.setText(R.id.tv_content, item.getContent());
34 | helper.setText(R.id.tv_username, item.getUsername());
35 |
36 |
37 |
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 | apply plugin: 'android-apt'
3 | android {
4 | compileSdkVersion 26
5 | buildToolsVersion "26.0.1"
6 | //**兼容Android6.0系统所需,如果这句话报错,可在dependencies标签下使用compile 'cn.bmob.android:http-legacy:1.0'**
7 | useLibrary 'org.apache.http.legacy'
8 | defaultConfig {
9 | applicationId "zzw.bmobtest"
10 | minSdkVersion 19
11 | targetSdkVersion 26
12 | versionCode 1
13 | versionName "1.0"
14 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
15 | }
16 | buildTypes {
17 | release {
18 | minifyEnabled false
19 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
20 | }
21 | }
22 | }
23 |
24 | dependencies {
25 | compile fileTree(dir: 'libs', include: ['*.jar'])
26 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
27 | exclude group: 'com.android.support', module: 'support-annotations'
28 | })
29 |
30 | //以下SDK开发者请根据需要自行选择
31 | //bmob-sdk:Bmob的android sdk包,包含了Bmob的数据存储、文件等服务,以下是最新的bmob-sdk:
32 | //3.5.5:请务必查看下面注释[1]
33 | //如果你想应用能够兼容Android6.0,请添加此依赖(org.apache.http.legacy.jar)
34 |
35 | //适配框架
36 |
37 | //依赖注入
38 | compile 'com.android.support:appcompat-v7:26.+'
39 | compile 'com.android.support:design:26.+'
40 | compile 'com.android.support.constraint:constraint-layout:1.0.2'
41 | compile 'cn.bmob.android:bmob-sdk:3.5.5'
42 | compile 'cn.bmob.android:http-legacy:1.0'
43 | compile 'com.zhy:autolayout:1.4.5'
44 | compile 'com.jakewharton:butterknife:8.6.0'
45 | testCompile 'junit:junit:4.12'
46 | apt 'com.jakewharton:butterknife-compiler:8.6.0'
47 |
48 | compile 'com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.22'
49 | }
50 |
--------------------------------------------------------------------------------
/app/src/main/java/zzw/bmobtest/activity/MainActivity.java:
--------------------------------------------------------------------------------
1 | package zzw.bmobtest.activity;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.support.v7.app.ActionBar;
6 | import android.view.MenuItem;
7 | import android.widget.Button;
8 |
9 | import butterknife.BindView;
10 | import butterknife.ButterKnife;
11 | import butterknife.OnClick;
12 | import zzw.bmobtest.R;
13 | import zzw.bmobtest.base.BaseActivity;
14 |
15 | public class MainActivity extends BaseActivity {
16 |
17 |
18 | @BindView(R.id.btn_message_board)
19 | Button btnMessageBoard;
20 |
21 | @Override
22 | public int getLayout() {
23 | return R.layout.activity_main;
24 | }
25 |
26 | @Override
27 | public void initView() {
28 | ActionBar actionBar = getSupportActionBar();
29 | if (actionBar != null) {
30 | actionBar.setHomeButtonEnabled(true);
31 | actionBar.setDisplayHomeAsUpEnabled(true);
32 | actionBar.setTitle("主界面");
33 | }
34 | }
35 |
36 | @Override
37 | public void initData() {
38 |
39 | }
40 |
41 | @Override
42 | public boolean onOptionsItemSelected(MenuItem item) {
43 | switch (item.getItemId()) {
44 | case android.R.id.home:
45 | this.finish(); // back button
46 | return true;
47 | }
48 | return super.onOptionsItemSelected(item);
49 | }
50 |
51 | @Override
52 | protected void onCreate(Bundle savedInstanceState) {
53 | super.onCreate(savedInstanceState);
54 | // TODO: add setContentView(...) invocation
55 | ButterKnife.bind(this);
56 | }
57 |
58 | @OnClick(R.id.btn_message_board)
59 | public void onViewClicked() {
60 | Intent intent = new Intent(MainActivity.this, MessageBoardActivity.class);
61 | startActivity(intent);
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_login.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
18 |
19 |
20 |
30 |
31 |
32 |
33 |
42 |
43 |
50 |
51 |
52 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
26 |
29 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
--------------------------------------------------------------------------------
/app/src/main/java/zzw/bmobtest/util/LogUtil.java:
--------------------------------------------------------------------------------
1 | package zzw.bmobtest.util;
2 |
3 | import android.util.Log;
4 |
5 | public class LogUtil
6 | {
7 |
8 | private static final String TAG = "LogUtil";
9 | // 是否显示Log消息
10 | private static boolean isShow = true;
11 |
12 | public static boolean isShow()
13 | {
14 | return isShow;
15 | }
16 |
17 | public static void setShow(boolean show)
18 | {
19 | isShow = show;
20 | }
21 |
22 | public static void i(String tag, String msg)
23 | {
24 | if (isShow)
25 | Log.i(tag, msg);
26 | }
27 |
28 | public static void w(String tag, String msg)
29 | {
30 | if (isShow)
31 | Log.w(tag, msg);
32 | }
33 |
34 | public static void e(String tag, String msg)
35 | {
36 | if (isShow)
37 | Log.e(tag, msg);
38 | }
39 |
40 | public static void all(String msg)
41 | {
42 | if (isShow)
43 | Log.e("all", msg);
44 | }
45 |
46 | public static void i(String msg)
47 | {
48 | if (isShow)
49 | Log.i(TAG, msg);
50 | }
51 |
52 | public static void w(String msg)
53 | {
54 | if (isShow)
55 | Log.w(TAG, msg);
56 | }
57 |
58 | public static void e(String msg)
59 | {
60 | if (isShow)
61 | Log.e(TAG, msg);
62 | }
63 |
64 | public static void v(String msg)
65 | {
66 | if (isShow)
67 | Log.v(TAG, msg);
68 | }
69 |
70 | public static void d(String msg)
71 | {
72 | if (isShow)
73 | Log.d(TAG, msg);
74 | }
75 |
76 | public static void d(String tag, String msg)
77 | {
78 | if (isShow)
79 | Log.d(tag, msg);
80 | }
81 |
82 | public static void w(String tag, String msg, Exception e)
83 | {
84 | if (isShow)
85 | Log.w(tag, msg, e);
86 | }
87 |
88 | public static void v(String tag, String msg)
89 | {
90 | if (isShow)
91 | Log.v(tag, msg);
92 | }
93 | }
94 |
--------------------------------------------------------------------------------
/app/src/main/res/values/attrs_custom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
57 |
58 |
59 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_register.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
18 |
19 |
29 |
30 |
31 |
41 |
42 |
43 |
52 |
53 |
54 |
--------------------------------------------------------------------------------
/app/src/main/java/zzw/bmobtest/view/InputView.java:
--------------------------------------------------------------------------------
1 | package zzw.bmobtest.view;
2 |
3 | import android.content.Context;
4 | import android.content.res.TypedArray;
5 | import android.text.InputType;
6 | import android.text.method.PasswordTransformationMethod;
7 | import android.util.AttributeSet;
8 | import android.view.View;
9 | import android.widget.EditText;
10 | import android.widget.LinearLayout;
11 | import android.widget.TextView;
12 |
13 | import com.zhy.autolayout.AutoFrameLayout;
14 | import com.zhy.autolayout.AutoLinearLayout;
15 | import com.zhy.autolayout.utils.AutoLayoutHelper;
16 |
17 | import zzw.bmobtest.R;
18 |
19 | /**
20 | * Created by lilingzhi on 2018/6/5.
21 | */
22 |
23 | public class InputView extends AutoLinearLayout {
24 |
25 |
26 | LinearLayout ll_input;
27 | TextView tv_input;
28 | EditText et_input;
29 |
30 |
31 |
32 | public InputView(Context context) {
33 | super(context);
34 | }
35 |
36 | public InputView(Context context, AttributeSet attrs) {
37 | super(context, attrs);
38 |
39 | // 加载当前这个组合控件的布局文件
40 | View.inflate(context, R.layout.layout_inputview, this);
41 |
42 |
43 | // 获取当前组合控件中所有的元素
44 | ll_input = (LinearLayout) findViewById(R.id.ll_input);
45 | tv_input = (TextView) findViewById(R.id.tv_input);
46 | et_input = (EditText) findViewById(R.id.et_input);
47 |
48 |
49 | // 加载自定义属性
50 | TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.InputView);
51 | // 获取自定义属性的值
52 | String leftText = a.getString(R.styleable.InputView_left_text);
53 | Boolean isPassword = a.getBoolean(R.styleable.InputView_is_password, false);
54 | Boolean isNumber = a.getBoolean(R.styleable.InputView_is_number, false);
55 | a.recycle();
56 |
57 | tv_input.setText(leftText);
58 | if (isPassword) {
59 | et_input.setTransformationMethod(PasswordTransformationMethod.getInstance()); //设置为密码输入框
60 | }
61 |
62 | if (isNumber) {
63 | et_input.setInputType(InputType.TYPE_CLASS_NUMBER);
64 |
65 | }
66 |
67 | et_input.setOnFocusChangeListener(new OnFocusChangeListener() {
68 | @Override
69 | public void onFocusChange(View view, boolean b) {
70 | if (b) {
71 | ll_input.setBackground(getContext().getResources().getDrawable(R.drawable.login_et_press) );
72 | } else {
73 |
74 | ll_input.setBackground(getContext().getResources().getDrawable(R.drawable.login_et_normal) );
75 | }
76 | }
77 | });
78 |
79 | }
80 |
81 | public String getInputString(){
82 | return et_input.getText().toString();
83 | }
84 |
85 | public void setInputString(String s) {
86 | et_input.setText(s);
87 | }
88 |
89 |
90 | }
--------------------------------------------------------------------------------
/app/src/main/java/zzw/bmobtest/util/ToastUtil.java:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | */
4 | package zzw.bmobtest.util;
5 |
6 |
7 | import android.content.Context;
8 | import android.os.Handler;
9 | import android.util.Log;
10 | import android.widget.Toast;
11 |
12 | import zzw.bmobtest.MyApplication;
13 |
14 | public class ToastUtil {
15 |
16 | /** 之前显示的内容 */
17 | private static String oldMsg ;
18 | /** Toast对象 */
19 | private static Toast toast = null ;
20 | /** 第一次时间 */
21 | private static long oneTime = 0 ;
22 | /** 第二次时间 */
23 | private static long twoTime = 0 ;
24 |
25 | public static void show(Context context, String info) {
26 | Toast.makeText(context, info, Toast.LENGTH_LONG).show();
27 | }
28 |
29 | public static void show(Context context, int info) {
30 | Toast.makeText(context, info, Toast.LENGTH_LONG).show();
31 | }
32 |
33 |
34 |
35 | private static void logError(String info, int errorCode) {
36 | print(LINE);//start
37 | print(" 错误信息 ");
38 | print(LINE);//title
39 | print(info);
40 | print("错误码: " + errorCode);
41 | print(" ");
42 | print("如果需要更多信息,请根据错误码到以下地址进行查询");
43 | print(" http://lbs.amap.com/api/android-sdk/guide/map-tools/error-code/");
44 | print("如若仍无法解决问题,请将全部log信息提交到工单系统,多谢合作");
45 | print(LINE);//end
46 | }
47 |
48 | //log
49 | public static final String TAG = "AMAP_ERROR";
50 | static final String LINE_CHAR="=";
51 | static final String BOARD_CHAR="|";
52 | static final int LENGTH = 80;
53 | static String LINE;
54 | static{
55 | StringBuilder sb = new StringBuilder();
56 | for(int i = 0;i Toast.LENGTH_SHORT){
97 | toast.show() ;
98 | }
99 | }else{
100 | oldMsg = msg ;
101 | toast.setText(msg) ;
102 | toast.show() ;
103 | }
104 | }
105 | oneTime = twoTime ;
106 | // if ("main".equalsIgnoreCase(Thread.currentThread().getName())) {
107 | // Toast.makeText(MyApplication.getContext(), msg, Toast.LENGTH_SHORT).show();
108 | // } else {
109 | // MyApplication.getHandler().post(new Runnable() {
110 | // @Override
111 | // public void run() {
112 | // Toast.makeText(MyApplication.getContext(), msg, Toast.LENGTH_SHORT).show();
113 | // }
114 | // });
115 | // }
116 | }
117 |
118 | }
119 |
--------------------------------------------------------------------------------
/app/src/main/java/zzw/bmobtest/activity/LoginActivity.java:
--------------------------------------------------------------------------------
1 | package zzw.bmobtest.activity;
2 |
3 | import android.Manifest;
4 | import android.content.Intent;
5 | import android.os.Build;
6 | import android.os.Bundle;
7 | import android.support.v7.app.ActionBar;
8 | import android.text.TextUtils;
9 | import android.util.Log;
10 | import android.view.View;
11 | import android.widget.Button;
12 | import android.widget.TextView;
13 |
14 | import java.util.List;
15 |
16 | import butterknife.BindView;
17 | import butterknife.ButterKnife;
18 | import butterknife.OnClick;
19 | import cn.bmob.v3.BmobQuery;
20 | import cn.bmob.v3.exception.BmobException;
21 | import cn.bmob.v3.listener.FindListener;
22 | import zzw.bmobtest.R;
23 | import zzw.bmobtest.base.BaseActivity;
24 | import zzw.bmobtest.bean.UserBean;
25 | import zzw.bmobtest.constant.Constant;
26 | import zzw.bmobtest.util.LogUtil;
27 | import zzw.bmobtest.util.SPUtils;
28 | import zzw.bmobtest.util.ToastUtil;
29 | import zzw.bmobtest.view.InputView;
30 |
31 | public class LoginActivity extends BaseActivity {
32 |
33 |
34 | @BindView(R.id.inputv_username)
35 | InputView inputvUsername;
36 | @BindView(R.id.inputv_password)
37 | InputView inputvPassword;
38 | @BindView(R.id.btn_login)
39 | Button btnLogin;
40 | @BindView(R.id.tv_register)
41 | TextView tvRegister;
42 |
43 |
44 | public static final int result_register = 1001;
45 | public static final int result_perm = 1002;
46 | @Override
47 | public int getLayout() {
48 | return R.layout.activity_login;
49 | }
50 |
51 | @Override
52 | public void initView() {
53 | ActionBar actionBar = getSupportActionBar();
54 | if(actionBar != null){
55 | actionBar.setTitle("登录");
56 | }
57 |
58 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
59 | requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE,
60 | Manifest.permission.READ_PHONE_STATE, Manifest.permission.WAKE_LOCK}, result_perm);
61 | }
62 |
63 | String username = (String)SPUtils.get(this, Constant.USERNAME, "");
64 | String password = (String)SPUtils.get(this, Constant.PASSWORD, "");
65 | inputvUsername.setInputString(username);;
66 | inputvPassword.setInputString(password);
67 |
68 |
69 |
70 | }
71 |
72 | @Override
73 | public void initData() {
74 |
75 | }
76 |
77 |
78 |
79 | @OnClick({R.id.btn_login, R.id.tv_register})
80 | public void onViewClicked(View view) {
81 | switch (view.getId()) {
82 | case R.id.btn_login:
83 | if (TextUtils.isEmpty(inputvUsername.getInputString()) ) {
84 | ToastUtil.showToast("账号不能为空");
85 | return ;
86 | }
87 | if (TextUtils.isEmpty(inputvPassword.getInputString()) ) {
88 | ToastUtil.showToast("密码不能为空");
89 | return ;
90 | }
91 | login();
92 | break;
93 | case R.id.tv_register:
94 | Intent intent = new Intent(LoginActivity.this, RegisterActivity.class);
95 |
96 | startActivityForResult(intent, result_register);
97 | break;
98 | }
99 | }
100 |
101 | private void login(){
102 | BmobQuery query = new BmobQuery();
103 | query.addWhereEqualTo("name", inputvUsername.getInputString());
104 | query.addWhereEqualTo("password", inputvPassword.getInputString());
105 | query.setLimit(1);
106 | query.findObjects(new FindListener() {
107 | @Override
108 | public void done(List object, BmobException e) {
109 | if(e==null){
110 | if (object == null || object.size() ==0) {
111 | //添加新用户
112 | ToastUtil.showToast("用户名或密码错误");
113 | } else {
114 | ToastUtil.showToast("成功登陆");
115 | Intent intent = new Intent(LoginActivity.this, MainActivity.class);
116 | startActivity(intent);
117 | }
118 | }else{
119 | LogUtil.i("bmob","失败:"+e.getMessage()+","+e.getErrorCode());
120 | }
121 | }
122 | });
123 | }
124 |
125 | @Override
126 | protected void onActivityResult(int requestCode, int resultCode, Intent data) {
127 | super.onActivityResult(requestCode, resultCode, data);
128 | if (resultCode != 1) {
129 | return ;
130 | }
131 |
132 | if (requestCode == result_register) {
133 | String username = data.getStringExtra(Constant.USERNAME);
134 | String password = data.getStringExtra(Constant.PASSWORD);
135 | inputvUsername.setInputString(username);
136 | inputvPassword.setInputString(password);
137 |
138 | }
139 |
140 | }
141 | }
142 |
--------------------------------------------------------------------------------
/app/src/main/java/zzw/bmobtest/activity/RegisterActivity.java:
--------------------------------------------------------------------------------
1 | package zzw.bmobtest.activity;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.support.v7.app.ActionBar;
6 | import android.text.TextUtils;
7 | import android.view.MenuItem;
8 | import android.widget.Button;
9 |
10 | import java.util.List;
11 |
12 | import butterknife.BindView;
13 | import butterknife.ButterKnife;
14 | import butterknife.OnClick;
15 | import cn.bmob.v3.BmobQuery;
16 | import cn.bmob.v3.exception.BmobException;
17 | import cn.bmob.v3.listener.FindListener;
18 | import cn.bmob.v3.listener.SaveListener;
19 | import zzw.bmobtest.R;
20 | import zzw.bmobtest.base.BaseActivity;
21 | import zzw.bmobtest.bean.UserBean;
22 | import zzw.bmobtest.constant.Constant;
23 | import zzw.bmobtest.util.LogUtil;
24 | import zzw.bmobtest.util.SPUtils;
25 | import zzw.bmobtest.util.ToastUtil;
26 | import zzw.bmobtest.view.InputView;
27 |
28 | public class RegisterActivity extends BaseActivity {
29 |
30 | @BindView(R.id.btn_login)
31 | Button btnLogin;
32 | @BindView(R.id.inputv_username)
33 | InputView inputvUsername;
34 | @BindView(R.id.inputv_password)
35 | InputView inputvPassword;
36 | @BindView(R.id.inputv_two_password)
37 | InputView inputvTwoPassword;
38 |
39 | @Override
40 | public int getLayout() {
41 | return R.layout.activity_register;
42 | }
43 |
44 | @Override
45 | public void initView() {
46 | ActionBar actionBar = getSupportActionBar();
47 | if (actionBar != null) {
48 | actionBar.setHomeButtonEnabled(true);
49 | actionBar.setDisplayHomeAsUpEnabled(true);
50 | actionBar.setTitle("注册");
51 | }
52 | }
53 |
54 | @Override
55 | public void initData() {
56 |
57 | }
58 |
59 |
60 | @Override
61 | public boolean onOptionsItemSelected(MenuItem item) {
62 | switch (item.getItemId()) {
63 | case android.R.id.home:
64 | this.finish(); // back button
65 | return true;
66 | }
67 | return super.onOptionsItemSelected(item);
68 | }
69 |
70 | @OnClick(R.id.btn_login)
71 | public void onViewClicked() {
72 |
73 | if (TextUtils.isEmpty(inputvUsername.getInputString()) ) {
74 | ToastUtil.showToast("账号不能为空");
75 | return ;
76 | }
77 | if (TextUtils.isEmpty(inputvPassword.getInputString()) ) {
78 | ToastUtil.showToast("密码不能为空");
79 | return ;
80 | }
81 | if (TextUtils.isEmpty(inputvTwoPassword.getInputString()) ) {
82 | ToastUtil.showToast("需要二次输入密码");
83 | return ;
84 | }
85 | if (!inputvPassword.getInputString().equals(inputvTwoPassword.getInputString())) {
86 | ToastUtil.showToast("两次输入密码不一致");
87 | return ;
88 | }
89 |
90 | //查询该用户名是否已经注册
91 | isRegistered();
92 |
93 |
94 |
95 | }
96 |
97 | private void isRegistered(){
98 | BmobQuery query = new BmobQuery();
99 | query.addWhereEqualTo("name", inputvUsername.getInputString());
100 | query.setLimit(1);
101 | query.findObjects(new FindListener() {
102 | @Override
103 | public void done(List object, BmobException e) {
104 | if(e==null){
105 | if (object == null || object.size() ==0) {
106 |
107 | addNewUser();
108 | } else {
109 | ToastUtil.showToast("该用户已注册");
110 | }
111 | }else{
112 | ToastUtil.showToast("注册失败");
113 | //添加新用户
114 | //addNewUser();
115 | // LogUtil.i("bmob","失败:"+e.getMessage()+","+e.getErrorCode());
116 | }
117 | }
118 | });
119 | }
120 |
121 | private void addNewUser(){
122 | UserBean p2 = new UserBean();
123 | p2.setName(inputvUsername.getInputString());
124 | p2.setPassword(inputvPassword.getInputString());
125 | p2.save(new SaveListener()
126 | {
127 | @Override
128 | public void done(String objectId, BmobException e)
129 | {
130 | if (e == null)
131 | {
132 | ToastUtil.showToast("添加用户成功" );
133 | SPUtils.put(RegisterActivity.this, Constant.USERNAME, inputvUsername.getInputString());
134 | SPUtils.put(RegisterActivity.this, Constant.PASSWORD, inputvPassword.getInputString());
135 | SPUtils.put(RegisterActivity.this, Constant.OBJECTID, objectId);
136 |
137 | Intent result = new Intent();
138 | result.putExtra(Constant.USERNAME, inputvUsername.getInputString());
139 | result.putExtra(Constant.PASSWORD, inputvPassword.getInputString());
140 | setResult(1, result);
141 | finish();
142 | }
143 | else
144 | {
145 | ToastUtil.showToast("添加用户失败:" + e.getMessage());
146 | }
147 | }
148 | });
149 | }
150 |
151 |
152 | @Override
153 | protected void onCreate(Bundle savedInstanceState) {
154 | super.onCreate(savedInstanceState);
155 | // TODO: add setContentView(...) invocation
156 | ButterKnife.bind(this);
157 | }
158 | }
159 |
--------------------------------------------------------------------------------
/app/src/main/java/zzw/bmobtest/util/SPUtils.java:
--------------------------------------------------------------------------------
1 | package zzw.bmobtest.util;
2 |
3 | import android.content.Context;
4 | import android.content.SharedPreferences;
5 |
6 | import java.lang.reflect.InvocationTargetException;
7 | import java.lang.reflect.Method;
8 | import java.util.Map;
9 |
10 | /**
11 | * Created by Wentong WANG on 2016/6/6.
12 | */
13 | public class SPUtils {
14 | /**
15 | * 保存在手机里面的文件名
16 | */
17 | public static final String FILE_NAME = "user_data";
18 |
19 | /**
20 | * 保存数据的方法,我们需要拿到保存数据的具体类型,然后根据类型调用不同的保存方法
21 | *
22 | * @param context
23 | * @param key
24 | * @param object
25 | */
26 | public static void put(Context context, String key, Object object)
27 | {
28 |
29 | SharedPreferences sp = context.getSharedPreferences(FILE_NAME,
30 | Context.MODE_PRIVATE);
31 | SharedPreferences.Editor editor = sp.edit();
32 |
33 | if (object instanceof String)
34 | {
35 | editor.putString(key, (String) object);
36 | } else if (object instanceof Integer)
37 | {
38 | editor.putInt(key, (Integer) object);
39 | } else if (object instanceof Boolean)
40 | {
41 | editor.putBoolean(key, (Boolean) object);
42 | } else if (object instanceof Float)
43 | {
44 | editor.putFloat(key, (Float) object);
45 | } else if (object instanceof Long)
46 | {
47 | editor.putLong(key, (Long) object);
48 | } else
49 | {
50 | editor.putString(key, object.toString());
51 | }
52 |
53 | SharedPreferencesCompat.apply(editor);
54 | }
55 |
56 | /**
57 | * 得到保存数据的方法,我们根据默认值得到保存的数据的具体类型,然后调用相对于的方法获取值
58 | *
59 | * @param context
60 | * @param key
61 | * @param defaultObject
62 | * @return
63 | */
64 | public static Object get(Context context, String key, Object defaultObject)
65 | {
66 | SharedPreferences sp = context.getSharedPreferences(FILE_NAME,
67 | Context.MODE_PRIVATE);
68 |
69 | if (defaultObject instanceof String)
70 | {
71 | return sp.getString(key, (String) defaultObject);
72 | } else if (defaultObject instanceof Integer)
73 | {
74 | return sp.getInt(key, (Integer) defaultObject);
75 | } else if (defaultObject instanceof Boolean)
76 | {
77 | return sp.getBoolean(key, (Boolean) defaultObject);
78 | } else if (defaultObject instanceof Float)
79 | {
80 | return sp.getFloat(key, (Float) defaultObject);
81 | } else if (defaultObject instanceof Long)
82 | {
83 | return sp.getLong(key, (Long) defaultObject);
84 | }
85 |
86 | return null;
87 | }
88 |
89 | /**
90 | * 移除某个key值已经对应的值
91 | * @param context
92 | * @param key
93 | */
94 | public static void remove(Context context, String key)
95 | {
96 | SharedPreferences sp = context.getSharedPreferences(FILE_NAME,
97 | Context.MODE_PRIVATE);
98 | SharedPreferences.Editor editor = sp.edit();
99 | editor.remove(key);
100 | SharedPreferencesCompat.apply(editor);
101 | }
102 |
103 | /**
104 | * 清除所有数据
105 | * @param context
106 | */
107 | public static void clear(Context context)
108 | {
109 | SharedPreferences sp = context.getSharedPreferences(FILE_NAME,
110 | Context.MODE_PRIVATE);
111 | SharedPreferences.Editor editor = sp.edit();
112 | editor.clear();
113 | SharedPreferencesCompat.apply(editor);
114 | }
115 |
116 | /**
117 | * 查询某个key是否已经存在
118 | * @param context
119 | * @param key
120 | * @return
121 | */
122 | public static boolean contains(Context context, String key)
123 | {
124 | SharedPreferences sp = context.getSharedPreferences(FILE_NAME,
125 | Context.MODE_PRIVATE);
126 | return sp.contains(key);
127 | }
128 |
129 | /**
130 | * 返回所有的键值对
131 | *
132 | * @param context
133 | * @return
134 | */
135 | public static Map getAll(Context context)
136 | {
137 | SharedPreferences sp = context.getSharedPreferences(FILE_NAME,
138 | Context.MODE_PRIVATE);
139 | return sp.getAll();
140 | }
141 |
142 | /**
143 | * 创建一个解决SharedPreferencesCompat.apply方法的一个兼容类
144 | *
145 | * @author zhy
146 | *
147 | */
148 | private static class SharedPreferencesCompat
149 | {
150 | private static final Method sApplyMethod = findApplyMethod();
151 |
152 | /**
153 | * 反射查找apply的方法
154 | *
155 | * @return
156 | */
157 | @SuppressWarnings({ "unchecked", "rawtypes" })
158 | private static Method findApplyMethod()
159 | {
160 | try
161 | {
162 | Class clz = SharedPreferences.Editor.class;
163 | return clz.getMethod("apply");
164 | } catch (NoSuchMethodException e)
165 | {
166 | }
167 |
168 | return null;
169 | }
170 |
171 | /**
172 | * 如果找到则使用apply执行,否则使用commit
173 | *
174 | * @param editor
175 | */
176 | public static void apply(SharedPreferences.Editor editor)
177 | {
178 | try
179 | {
180 | if (sApplyMethod != null)
181 | {
182 | sApplyMethod.invoke(editor);
183 | return;
184 | }
185 | } catch (IllegalArgumentException e)
186 | {
187 | } catch (IllegalAccessException e)
188 | {
189 | } catch (InvocationTargetException e)
190 | {
191 | }
192 | editor.commit();
193 | }
194 | }
195 | }
196 |
--------------------------------------------------------------------------------
/app/src/main/java/zzw/bmobtest/activity/MessageBoardActivity.java:
--------------------------------------------------------------------------------
1 | package zzw.bmobtest.activity;
2 |
3 | import android.app.Dialog;
4 | import android.os.Bundle;
5 | import android.support.design.widget.FloatingActionButton;
6 | import android.support.v7.app.ActionBar;
7 | import android.support.v7.app.AlertDialog;
8 | import android.support.v7.widget.LinearLayoutManager;
9 | import android.support.v7.widget.RecyclerView;
10 | import android.view.MenuItem;
11 | import android.view.View;
12 | import android.view.ViewGroup;
13 | import android.widget.Button;
14 | import android.widget.EditText;
15 | import android.widget.LinearLayout;
16 |
17 | import java.util.ArrayList;
18 | import java.util.List;
19 |
20 | import butterknife.BindView;
21 | import butterknife.ButterKnife;
22 | import cn.bmob.v3.BmobQuery;
23 | import cn.bmob.v3.exception.BmobException;
24 | import cn.bmob.v3.listener.FindListener;
25 | import cn.bmob.v3.listener.SaveListener;
26 | import zzw.bmobtest.R;
27 | import zzw.bmobtest.adapter.MessageBoardAdapter;
28 | import zzw.bmobtest.base.BaseActivity;
29 | import zzw.bmobtest.bean.MessageBean;
30 | import zzw.bmobtest.constant.Constant;
31 | import zzw.bmobtest.util.LogUtil;
32 | import zzw.bmobtest.util.SPUtils;
33 | import zzw.bmobtest.util.ToastUtil;
34 |
35 | public class MessageBoardActivity extends BaseActivity {
36 |
37 |
38 | @BindView(R.id.recyc)
39 | RecyclerView recyc;
40 |
41 | public static final String TAG = "MessageBoardActivity";
42 |
43 | RecyclerView.LayoutManager layoutManager;
44 | MessageBoardAdapter adapter;
45 |
46 | List dataList = new ArrayList<>();
47 | @BindView(R.id.fbtn)
48 | FloatingActionButton fbtn;
49 |
50 | AlertDialog.Builder builder;
51 | AlertDialog alertDialog ;
52 | EditText et;
53 | Button btn_send;
54 | View view;
55 | @Override
56 | public int getLayout() {
57 | return R.layout.activity_message_board;
58 | }
59 |
60 | @Override
61 | public void initView() {
62 | ActionBar actionBar = getSupportActionBar();
63 | if (actionBar != null) {
64 | actionBar.setHomeButtonEnabled(true);
65 | actionBar.setDisplayHomeAsUpEnabled(true);
66 | actionBar.setTitle("主界面");
67 | }
68 |
69 | //循环视图
70 | layoutManager = new LinearLayoutManager(MessageBoardActivity.this);
71 | adapter = new MessageBoardAdapter(R.layout.item_message_board, dataList);
72 | recyc.setLayoutManager(layoutManager);
73 | recyc.setAdapter(adapter);
74 |
75 | //输入对话框
76 | builder = new AlertDialog.Builder(MessageBoardActivity.this);
77 | alertDialog = builder.create();
78 | LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT
79 | , ViewGroup.LayoutParams.WRAP_CONTENT);
80 | view = View
81 | .inflate(MessageBoardActivity.this , R.layout.layout_input_dialog, null);
82 | alertDialog.setView(view);
83 | et = (EditText) view.findViewById(R.id.et);
84 | btn_send = (Button) view.findViewById(R.id.btn_send);
85 | btn_send.setOnClickListener(new View.OnClickListener() {
86 | @Override
87 | public void onClick(View view) {
88 | final MessageBean messageBean = new MessageBean();
89 | messageBean.setContent(et.getText().toString());
90 | messageBean.setUsername(SPUtils.get(MessageBoardActivity.this, Constant.USERNAME, "").toString());
91 |
92 | messageBean.save(new SaveListener()
93 | {
94 | @Override
95 | public void done(String objectId, BmobException e)
96 | {
97 | if (e == null)
98 | {
99 | addOne(messageBean);
100 | }
101 | else
102 | {
103 | ToastUtil.showToast("提交留言失败");
104 | }
105 | alertDialog.dismiss();
106 | }
107 | });
108 | }
109 | });
110 |
111 |
112 | fbtn.setOnClickListener(new View.OnClickListener() {
113 | @Override
114 | public void onClick(View view) {
115 |
116 | alertDialog.show();
117 | }
118 | });
119 |
120 | }
121 |
122 | @Override
123 | public void initData() {
124 |
125 | queryAll();
126 |
127 |
128 | }
129 |
130 | public void queryAll() {
131 | BmobQuery query = new BmobQuery();
132 | query.setLimit(100);
133 | query.findObjects(new FindListener() {
134 | @Override
135 | public void done(List list, BmobException e) {
136 | if (e == null) {
137 | if (list != null) {
138 | dataList.addAll(list);
139 | adapter.notifyDataSetChanged();
140 |
141 | }
142 | } else {
143 | LogUtil.i(TAG, "失败:" + e.getMessage() + "," + e.getErrorCode());
144 | }
145 | }
146 | });
147 |
148 |
149 | }
150 |
151 | public void addOne(MessageBean messageBean){
152 | dataList.add(messageBean);
153 | adapter.notifyDataSetChanged();
154 | }
155 |
156 | @Override
157 | public boolean onOptionsItemSelected(MenuItem item) {
158 | switch (item.getItemId()) {
159 | case android.R.id.home:
160 | this.finish(); // back button
161 | return true;
162 | }
163 | return super.onOptionsItemSelected(item);
164 | }
165 |
166 | @Override
167 | protected void onCreate(Bundle savedInstanceState) {
168 | super.onCreate(savedInstanceState);
169 | // TODO: add setContentView(...) invocation
170 | ButterKnife.bind(this);
171 | }
172 | }
173 |
--------------------------------------------------------------------------------
/app/app.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 | generateDebugSources
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
--------------------------------------------------------------------------------