Преглед изворни кода

登录注册添加,游戏详情页面修改。

zhaoyi пре 8 година
родитељ
комит
47cb9f0474

+ 7 - 0
app/build.gradle

@@ -20,6 +20,12 @@ android {
     }
 }
 
+repositories {
+    flatDir {
+        dirs 'libs'
+    }
+}
+
 dependencies {
     /* compile fileTree(dir: 'libs', include: ['*.jar'])
          androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
@@ -37,6 +43,7 @@ dependencies {
     compile 'com.liulishuo.filedownloader:library:1.6.9'
     compile 'com.tencent.bugly:crashreport_upgrade:latest.release'
     compile 'com.tencent.mm.opensdk:wechat-sdk-android-with-mta:+'
+    compile(name: 'utils', ext: 'aar')
     debugCompile 'com.readystatesoftware.chuck:library:1.1.0'
     compile 'de.hdodenhof:circleimageview:2.2.0'
     releaseCompile 'com.readystatesoftware.chuck:library-no-op:1.1.0'

BIN
app/libs/utils.aar


+ 3 - 0
app/src/main/AndroidManifest.xml

@@ -88,6 +88,9 @@
             android:name=".page.BindWxActivity"
             android:screenOrientation="portrait"/>
         <activity
+            android:name=".page.RegisterActivity"
+            android:screenOrientation="portrait"/>
+        <activity
             android:name=".page.TaskRecordActivity"
             android:screenOrientation="portrait"/>
         <activity

+ 4 - 2
app/src/main/java/com/sheep/jiuyan/samllsheep/Config.java

@@ -15,8 +15,10 @@ public class Config {
         return mConfig;
     }
 
-        public String mBaseUrl = "http://10.8.220.213:8088";
-//    public String mBaseUrl = "http://api.task.bandaimi.com";
+    public String mBaseUrl = "http://10.8.220.213:8088";
+
+    public String mHaoWanBaseUrl = "http://10.8.220.132:8082";
+    //    public String mBaseUrl = "http://api.task.bandaimi.com";
     //    public String mBaseUrl = "http://test.ss.shouyouquan.com";
     public final static String WX_APPID = "wx3c0376c4fcc8b723";
     public final static String BUGLY_APPID = "0dd998212c";

+ 13 - 6
app/src/main/java/com/sheep/jiuyan/samllsheep/net/NetManager.java

@@ -3,12 +3,15 @@ package com.sheep.jiuyan.samllsheep.net;
 import android.content.Context;
 
 import com.readystatesoftware.chuck.ChuckInterceptor;
+import com.sheep.jiuyan.samllsheep.utils.AES;
+
+import org.json.JSONException;
+import org.json.JSONObject;
 
 import java.io.File;
 import java.util.Map;
 import java.util.concurrent.TimeUnit;
 
-import okhttp3.FormBody;
 import okhttp3.Headers;
 import okhttp3.MediaType;
 import okhttp3.MultipartBody;
@@ -54,11 +57,17 @@ public class NetManager {
     }
 
     public static void post(String url, Map<String, String> parma, Context context, SheepCallback callback) {
-        FormBody.Builder builder = new FormBody.Builder();
+        JSONObject object = new JSONObject();
         for (Map.Entry<String, String> el : parma.entrySet()) {
-            builder.add(el.getKey(), el.getValue());
+            try {
+                object.put(el.getKey(), el.getValue());
+            } catch (JSONException e) {
+                e.printStackTrace();
+            }
         }
-        FormBody body = builder.build();
+        AES aes = new AES("kengdiewanyimmmp");
+        byte[] encrypt = aes.encrypt(object.toString().getBytes());
+        RequestBody body = RequestBody.create(MediaType.parse("text/html"), encrypt);
         Request request = new Request.Builder().url(url).post(body).build();
         getInstancce(context).newCall(request).enqueue(callback);
     }
@@ -70,11 +79,9 @@ public class NetManager {
             param += "&";
         }
         url += "?" + param;
-
         MediaType type = MediaType.parse("application/octet-stream");
         RequestBody fileBody = RequestBody.create(type, file);
 
-
         RequestBody multipartBody = new MultipartBody.Builder()
                 .setType(MultipartBody.FORM)
                 .addPart(Headers.of(

+ 1 - 1
app/src/main/java/com/sheep/jiuyan/samllsheep/net/SheepCallback.java

@@ -67,7 +67,7 @@ public abstract class SheepCallback<T> implements Callback {
     }
 
     public void otherCode(int code, String string) {
-        Toast.makeText(SheepApp.mContext, string, Toast.LENGTH_SHORT).show();
+//        Toast.makeText(SheepApp.mContext, string, Toast.LENGTH_SHORT).show();
         failure(new IOException(string));
     }
 

+ 3 - 0
app/src/main/java/com/sheep/jiuyan/samllsheep/net/Url.java

@@ -29,5 +29,8 @@ public class Url {
     public static String BINGACCOUNT = Config.instance().mBaseUrl + "/v1/user/register";
     public static String REQUEST_HOOK = Config.instance().mBaseUrl + "/static/index.html";
     public static String ADD_CHILD_WX = Config.instance().mBaseUrl + "/static/apply3.html";
+    public static String LOGIN = Config.instance().mBaseUrl + "/v1/user/login";
+    public static String REGISTER_SHEEP = Config.instance().mBaseUrl + "/v1/user/register";
+    public static String REGISTER_HW = Config.instance().mBaseUrl + "/v1/user/registerHw";
 
 }

+ 138 - 0
app/src/main/java/com/sheep/jiuyan/samllsheep/page/GameDetailActivity.java

@@ -1,6 +1,12 @@
 package com.sheep.jiuyan.samllsheep.page;
 
+import android.app.Activity;
+import android.content.DialogInterface;
 import android.content.Intent;
+import android.database.Cursor;
+import android.net.Uri;
+import android.provider.MediaStore;
+import android.support.v7.app.AlertDialog;
 import android.text.Html;
 import android.text.TextUtils;
 import android.view.View;
@@ -13,6 +19,7 @@ import android.widget.ImageView;
 import android.widget.LinearLayout;
 import android.widget.RelativeLayout;
 import android.widget.TextView;
+import android.widget.Toast;
 
 import com.bumptech.glide.Glide;
 import com.sheep.jiuyan.samllsheep.R;
@@ -22,10 +29,13 @@ import com.sheep.jiuyan.samllsheep.net.NetManager;
 import com.sheep.jiuyan.samllsheep.net.SheepCallback;
 import com.sheep.jiuyan.samllsheep.net.Url;
 import com.sheep.jiuyan.samllsheep.page.entry.TaskPublish;
+import com.sheep.jiuyan.samllsheep.utils.DeviceUtils;
 import com.sheep.jiuyan.samllsheep.utils.PackageUtil;
 import com.sheep.jiuyan.samllsheep.utils.SpUtils;
 import com.sheep.jiuyan.samllsheep.utils.TitleBarUtils;
 
+import java.io.File;
+import java.io.IOException;
 import java.util.HashMap;
 
 /**
@@ -46,8 +56,11 @@ public class GameDetailActivity extends BaseActivity {
     private TextView mTvText1;
     private TextView mTvMoney;
     private Button mBtnTaskItem;
+    private Button mBtnUpImag;
     private WebView mWebText;
     private LinearLayout mLlInfos;
+    private AlertDialog mDialog;
+    private AlertDialog mReDialog;
 
     @Override
     protected int getLayoutId() {
@@ -70,8 +83,10 @@ public class GameDetailActivity extends BaseActivity {
         mTvText1 = (TextView) findViewById(R.id.tv_text1);
         mTvMoney = (TextView) findViewById(R.id.tv_money);
         mBtnTaskItem = (Button) findViewById(R.id.btn_task_item);
+        mBtnUpImag = (Button) findViewById(R.id.btn_up_imag);
         mWebText = (WebView) findViewById(R.id.web_text);
         mLlInfos = (LinearLayout) findViewById(R.id.ll_infos);
+
         TitleBarUtils.getInstance().setTitle(this, "任务详情")
                 .setTitleFinish(this);
         mWebText.setWebChromeClient(new WebChromeClient() {
@@ -101,6 +116,129 @@ public class GameDetailActivity extends BaseActivity {
                 }
             }
         });
+        mBtnUpImag.setOnClickListener(new View.OnClickListener() {
+            @Override
+            public void onClick(View v) {
+                checkIsRegisterTask();
+            }
+        });
+    }
+
+    private void checkIsRegisterTask() {
+        HashMap<String, String> map = new HashMap<>();
+        map.put("wx_open_id", SpUtils.getOpenId(this));
+        map.put("publish_id", mTask.getId() + "");
+        NetManager.get(Url.USER_CHECK_REGISTER, map, getApplicationContext(), new SheepCallback<String>(this) {
+            @Override
+            public void success(String ok) {
+                if (TextUtils.equals(ok, "ok")) {
+                    uploadImag();
+                } else {
+                    showRecommitDialog("用户同时只能领取一个任务,是否此领取任务?");
+                }
+            }
+        });
+    }
+
+    private void uploadImag() {
+        Intent intent = new Intent(Intent.ACTION_PICK,
+                android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
+        startActivityForResult(intent, 1);
+    }
+
+
+    private void startTask(final TaskPublish task) {
+        HashMap<String, String> map = new HashMap<>();
+        map.put("wx_open_id", SpUtils.getOpenId(this));
+        map.put("task_id", task.getId() + "");
+        map.put("imei", new DeviceUtils(getApplicationContext()).getIMEI());
+        NetManager.get(Url.USER_REGISTER_TASK, map, getApplicationContext(), new SheepCallback<String>(this) {
+            @Override
+            public void success(String o) {
+                String pkg = task.getTask().getPkg();
+                if (!TextUtils.isEmpty(pkg)) {
+                    boolean installed = PackageUtil.isAppInstalled(getApplicationContext(), pkg);
+                    if (installed) {
+                        PackageUtil.startApp(getApplicationContext(), pkg);
+                    } else {
+                        Intent intent = new Intent(GameDetailActivity.this, DownloadActivity.class);
+                        intent.putExtra("task", task.getTask());
+                        startActivity(intent);
+                    }
+                } else {
+                    Toast.makeText(GameDetailActivity.this, "任务已经领取,快去完成吧", Toast.LENGTH_SHORT).show();
+                }
+            }
+        });
+
+    }
+
+    private void showRecommitDialog(String s) {
+        if (mReDialog == null) {
+            mReDialog = new AlertDialog.Builder(GameDetailActivity.this)
+                    .setMessage(s)
+                    .setPositiveButton("确定", new DialogInterface.OnClickListener() {
+                        @Override
+                        public void onClick(DialogInterface dialog, int which) {
+                            startTask(mTask);
+                            mReDialog.dismiss();
+                        }
+                    }).setNegativeButton("取消", new DialogInterface.OnClickListener() {
+                        @Override
+                        public void onClick(DialogInterface dialog, int which) {
+                            mReDialog.dismiss();
+                        }
+                    }).create();
+        }
+        mReDialog.setMessage(s);
+        mReDialog.show();
+    }
+
+
+    @Override
+    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
+        super.onActivityResult(requestCode, resultCode, data);
+        //获取图片路径
+        if (requestCode == 1 && resultCode == Activity.RESULT_OK && data != null) {
+            Uri selectedImage = data.getData();
+            String[] filePathColumns = {MediaStore.Images.Media.DATA};
+            Cursor c = getContentResolver().query(selectedImage, filePathColumns, null, null, null);
+            c.moveToFirst();
+            int columnIndex = c.getColumnIndex(filePathColumns[0]);
+            String imagePath = c.getString(columnIndex);
+            commitTask(imagePath);
+            c.close();
+        }
+    }
+
+    private void commitTask(String path) {
+        String topApp = "";
+        Intent intent = getIntent();
+        if (intent != null) {
+            topApp = intent.getStringExtra("pkg");
+        }
+        HashMap<String, String> parma = new HashMap<>();
+        parma.put("task_pkg", topApp);
+        parma.put("task_pkg", topApp);
+        parma.put("wx_open_id", SpUtils.getOpenId(this));
+        NetManager.upload(Url.UPLOAD_IMG, parma, new File(path), getApplicationContext(), new SheepCallback<String>(this) {
+            @Override
+            public void success(String s) {
+                Toast.makeText(GameDetailActivity.this, s, Toast.LENGTH_SHORT).show();
+                finish();
+            }
+
+            @Override
+            public void otherCode(int code, String string) {
+                super.otherCode(code, string);
+                finish();
+            }
+
+            @Override
+            public void failure(IOException e) {
+                finish();
+            }
+        });
     }
 
     @Override

+ 70 - 16
app/src/main/java/com/sheep/jiuyan/samllsheep/page/LoginActivity.java

@@ -2,30 +2,34 @@ package com.sheep.jiuyan.samllsheep.page;
 
 import android.app.AlertDialog;
 import android.content.Intent;
-import android.os.Handler;
-import android.os.SystemClock;
 import android.support.design.widget.TextInputEditText;
 import android.text.TextUtils;
 import android.view.View;
+import android.widget.EditText;
 import android.widget.ImageView;
 import android.widget.RadioButton;
 import android.widget.RadioGroup;
 import android.widget.TextView;
+import android.widget.Toast;
 
 import com.sheep.jiuyan.samllsheep.BuildConfig;
 import com.sheep.jiuyan.samllsheep.Config;
 import com.sheep.jiuyan.samllsheep.R;
-import com.sheep.jiuyan.samllsheep.SheepApp;
 import com.sheep.jiuyan.samllsheep.base.BaseActivity;
+import com.sheep.jiuyan.samllsheep.net.NetManager;
+import com.sheep.jiuyan.samllsheep.net.SheepCallback;
+import com.sheep.jiuyan.samllsheep.net.Url;
+import com.sheep.jiuyan.samllsheep.page.entry.BindUserEntiey;
 import com.sheep.jiuyan.samllsheep.utils.SpUtils;
-import com.tencent.mm.opensdk.modelmsg.SendAuth;
+import com.sheep.jiuyan.samllsheep.utils.TitleBarUtils;
+
+import java.util.HashMap;
 
 /**
  * Created by kemllor on 2017/12/21.
  */
 
 public class LoginActivity extends BaseActivity {
-    private ImageView mImgLogin;
     private AlertDialog mDialog;
 
     @Override
@@ -36,14 +40,35 @@ public class LoginActivity extends BaseActivity {
 
     @Override
     public void initData() {
+        String openId = SpUtils.getOpenId(this);
+        if (!TextUtils.isEmpty(openId)) {
+            Intent intent = new Intent(LoginActivity.this, MainActivity.class);
+            startActivity(intent);
+            finish();
+        }
+    }
+
+    private EditText mEtAccount;
+    private EditText mEtPsw;
+    private ImageView mImgLogin;
+    private TextView mTvWx;
+    private TextView mTvRegister;
 
+    private void findViews() {
+        mEtAccount = (EditText) findViewById(R.id.et_account);
+        mEtPsw = (EditText) findViewById(R.id.et_psw);
+        mImgLogin = (ImageView) findViewById(R.id.img_login);
+        mTvWx = (TextView) findViewById(R.id.tv_wx);
+        mTvRegister = (TextView) findViewById(R.id.tv_register);
     }
 
+
     @Override
     public void initView() {
-        mImgLogin = (ImageView) findViewById(R.id.img_login);
-        loginFromWx();
-        new Thread(new Runnable() {
+        findViews();
+        TitleBarUtils.getInstance().setTitle(this, "登  录")
+                .setTitleFinish(this);
+       /* new Thread(new Runnable() {
             @Override
             public void run() {
                 SystemClock.sleep(3000);
@@ -51,22 +76,25 @@ public class LoginActivity extends BaseActivity {
                 startActivity(intent);
                 finish();
             }
-        }).start();
-
-
+        }).start();*/
     }
 
     @Override
     public void initListener() {
-        mImgLogin.setOnClickListener(new View.OnClickListener() {
+        mTvRegister.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
-                loginFromWx();
-                Intent intent = new Intent(LoginActivity.this, MainActivity.class);
+                Intent intent = new Intent(LoginActivity.this, RegisterActivity.class);
                 startActivity(intent);
                 finish();
             }
         });
+        mTvWx.setOnClickListener(new View.OnClickListener() {
+            @Override
+            public void onClick(View v) {
+                loginFromHw();
+            }
+        });
         if (BuildConfig.DEBUG)
             mImgLogin.setOnLongClickListener(new View.OnLongClickListener() {
                 @Override
@@ -112,13 +140,39 @@ public class LoginActivity extends BaseActivity {
         mDialog.show();
     }
 
-    private void loginFromWx() {
+    private void loginFromHw() {
+        String account = mEtAccount.getText().toString().trim();
+        String psw = mEtPsw.getText().toString().trim();
+        if (TextUtils.isEmpty(account) || TextUtils.isEmpty(psw)) {
+            Toast.makeText(this, "缺少参数", Toast.LENGTH_SHORT).show();
+            return;
+        }
+        HashMap<String, String> map = new HashMap<>();
+        map.put("account", account);
+        map.put("pwd", psw);
+        NetManager.post(Url.LOGIN, map, getApplicationContext(), new SheepCallback<String>(LoginActivity.this) {
+            @Override
+            public void success(String o) {
+                HashMap<String, String> map = new HashMap<>();
+                map.put("token", o);
+                NetManager.get(Url.REGISTER_SHEEP, map, getApplicationContext(), new SheepCallback<BindUserEntiey>(LoginActivity.this) {
+                    @Override
+                    public void success(BindUserEntiey o) {
+                        SpUtils.login(LoginActivity.this, o.getOpenId());
+                        Intent intent = new Intent(LoginActivity.this, MainActivity.class);
+                        startActivity(intent);
+                        finish();
+                    }
+                });
+            }
+        });
+
     /*    SendAuth.Req req = new SendAuth.Req();
         req.scope = "snsapi_userinfo";
         req.state = "small_sheep_auther";
         SheepApp.mWxapi.sendReq(req);*/
 
-        SpUtils.login(this, "529e87ad4e1b49ebfffbd673fff48e01");
+        //        SpUtils.login(this, "529e87ad4e1b49ebfffbd673fff48e01");
     }
 
 

+ 150 - 0
app/src/main/java/com/sheep/jiuyan/samllsheep/page/RegisterActivity.java

@@ -0,0 +1,150 @@
+package com.sheep.jiuyan.samllsheep.page;
+
+import android.content.Intent;
+import android.text.TextUtils;
+import android.view.View;
+import android.widget.EditText;
+import android.widget.TextView;
+import android.widget.Toast;
+
+import com.sheep.jiuyan.samllsheep.R;
+import com.sheep.jiuyan.samllsheep.base.BaseActivity;
+import com.sheep.jiuyan.samllsheep.net.NetManager;
+import com.sheep.jiuyan.samllsheep.net.SheepCallback;
+import com.sheep.jiuyan.samllsheep.net.Url;
+import com.sheep.jiuyan.samllsheep.page.entry.BindUserEntiey;
+import com.sheep.jiuyan.samllsheep.utils.SpUtils;
+import com.sheep.jiuyan.samllsheep.utils.TitleBarUtils;
+
+import java.io.IOException;
+import java.util.HashMap;
+
+import okhttp3.Call;
+
+/**
+ * Created by kemllor on 2018/1/22.
+ */
+
+public class RegisterActivity extends BaseActivity {
+
+    private EditText mEtAccount;
+    private EditText mEtCode;
+    private TextView mBtnCode;
+    private EditText mEtPsw;
+    private EditText mEtInvite;
+    private TextView mTvWx;
+
+
+    @Override
+    protected int getLayoutId() {
+        return R.layout.register_activity;
+    }
+
+    @Override
+    public void initView() {
+        findViews();
+        TitleBarUtils.getInstance().setTitle(this, "注 册")
+                .setTitleFinish(this);
+    }
+
+
+    private void findViews() {
+        mEtAccount = (EditText) findViewById(R.id.et_account);
+        mEtCode = (EditText) findViewById(R.id.et_code);
+        mBtnCode = (TextView) findViewById(R.id.btn_code);
+        mEtPsw = (EditText) findViewById(R.id.et_psw);
+        mEtInvite = (EditText) findViewById(R.id.et_invite);
+        mTvWx = (TextView) findViewById(R.id.tv_wx);
+    }
+
+
+    @Override
+    public void initListener() {
+        mTvWx.setOnClickListener(new View.OnClickListener() {
+            @Override
+            public void onClick(View v) {
+                register();
+                mTvWx.setEnabled(false);
+            }
+        });
+
+        mBtnCode.setOnClickListener(new View.OnClickListener() {
+            @Override
+            public void onClick(View v) {
+                getCode();
+            }
+        });
+    }
+
+    private void getCode() {
+        mBtnCode.setEnabled(false);
+        String moble = mEtAccount.getText().toString().trim();
+        if (TextUtils.isEmpty(moble)) {
+            Toast.makeText(this, "缺少参数", Toast.LENGTH_SHORT).show();
+            return;
+        }
+        HashMap<String, String> map = new HashMap<>();
+        map.put("mobile", moble);
+        map.put("step", "1");
+        NetManager.post(Url.REGISTER_HW, map, getApplicationContext(), new SheepCallback<String>(RegisterActivity.this) {
+            @Override
+            public void success(String o) {
+                Toast.makeText(RegisterActivity.this, "验证码已发送", Toast.LENGTH_SHORT).show();
+            }
+
+            @Override
+            public void failure(IOException e) {
+                mBtnCode.setEnabled(true);
+                Toast.makeText(RegisterActivity.this, e.getMessage(), Toast.LENGTH_SHORT).show();
+            }
+        });
+    }
+
+    private void register() {
+        String moble = mEtAccount.getText().toString().trim();
+        String psw = mEtPsw.getText().toString().trim();
+        String code = mEtCode.getText().toString().trim();
+        String inviteCode = mEtInvite.getText().toString().trim();
+        if (TextUtils.isEmpty(moble) || TextUtils.isEmpty(psw) || TextUtils.isEmpty(code)) {
+            Toast.makeText(this, "缺少参数", Toast.LENGTH_SHORT).show();
+            return;
+        }
+        HashMap<String, String> map = new HashMap<>();
+        map.put("mobile", moble);
+        map.put("psw", psw);
+        map.put("code", code);
+        map.put("step", "2");
+        map.put("invite", inviteCode);
+        NetManager.post(Url.REGISTER_HW, map, getApplicationContext(), new SheepCallback<String>(RegisterActivity.this) {
+            @Override
+            public void success(String token) {
+                loginAuto(token);
+            }
+
+            @Override
+            public void failure(IOException e) {
+                Toast.makeText(RegisterActivity.this, e.getMessage(), Toast.LENGTH_SHORT).show();
+                mTvWx.setEnabled(true);
+            }
+        });
+    }
+
+    private void loginAuto(String token) {
+        HashMap<String, String> map = new HashMap<>();
+        map.put("token", token);
+        NetManager.get(Url.REGISTER_SHEEP, map, getApplicationContext(), new SheepCallback<BindUserEntiey>(RegisterActivity.this) {
+            @Override
+            public void success(BindUserEntiey o) {
+                SpUtils.login(RegisterActivity.this, o.getOpenId());
+                Intent intent = new Intent(RegisterActivity.this, MainActivity.class);
+                startActivity(intent);
+                finish();
+            }
+        });
+    }
+
+    @Override
+    public void initData() {
+
+    }
+}

+ 43 - 0
app/src/main/java/com/sheep/jiuyan/samllsheep/page/entry/HaoWanMsg.java

@@ -0,0 +1,43 @@
+package com.sheep.jiuyan.samllsheep.page.entry;
+
+/**
+ * Created by kemllor on 2018/1/22.
+ */
+
+public class HaoWanMsg {
+
+
+    /**
+     * code : 430
+     * msg : 参数错误 参数错误
+     * data : null
+     */
+
+    private int code;
+    private String msg;
+    private Object data;
+
+    public int getCode() {
+        return code;
+    }
+
+    public void setCode(int code) {
+        this.code = code;
+    }
+
+    public String getMsg() {
+        return msg;
+    }
+
+    public void setMsg(String msg) {
+        this.msg = msg;
+    }
+
+    public Object getData() {
+        return data;
+    }
+
+    public void setData(Object data) {
+        this.data = data;
+    }
+}

+ 2 - 0
app/src/main/java/com/sheep/jiuyan/samllsheep/page/entry/User.java

@@ -105,6 +105,8 @@ public class User implements Serializable {
     }
 
     public String getBalance() {
+        if (Balance == null)
+            return "0";
         return Balance;
     }
 

+ 63 - 0
app/src/main/java/com/sheep/jiuyan/samllsheep/utils/AES.java

@@ -0,0 +1,63 @@
+package com.sheep.jiuyan.samllsheep.utils;
+
+import javax.crypto.Cipher;
+import javax.crypto.spec.SecretKeySpec;
+import javax.crypto.spec.IvParameterSpec;
+
+
+public class AES {
+    private IvParameterSpec ivSpec;
+    private SecretKeySpec keySpec;
+
+    public AES(String key) {
+        try {
+            byte[] keyBytes = key.getBytes();
+            byte[] buf = new byte[16];
+
+            for (int i = 0; i < keyBytes.length && i < buf.length; i++) {
+                buf[i] = keyBytes[i];
+            }
+
+            this.keySpec = new SecretKeySpec(buf, "AES");
+            this.ivSpec = new IvParameterSpec(keyBytes);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    public byte[] encrypt(byte[] origData) {
+        try {
+            Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
+            cipher.init(Cipher.ENCRYPT_MODE, this.keySpec, this.ivSpec);
+            return cipher.doFinal(origData);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return null;
+    }
+
+    public byte[] decrypt(byte[] crypted) {
+        try {
+            Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
+            cipher.init(Cipher.DECRYPT_MODE, this.keySpec, this.ivSpec);
+            return cipher.doFinal(crypted);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return null;
+    }
+
+    /**
+     * @param args
+     * @throws Exception
+     */
+    public static void main(String[] args) throws Exception {
+        AES aes = new AES("sfe023f_9fd&fwfl");
+        String data = "polaris@studygolang";
+        byte[] crypted = aes.encrypt(data.getBytes());
+        System.out.println(new String(aes.decrypt(crypted)));
+    }
+
+}
+
+

+ 82 - 0
app/src/main/java/com/sheep/jiuyan/samllsheep/utils/HexUtils.java

@@ -0,0 +1,82 @@
+package com.sheep.jiuyan.samllsheep.utils;
+
+/**
+ * Created by kemllor on 2018/1/22.
+ */
+
+public class HexUtils {
+    private static final String HEX_STR_POOL = "0123456789ABCDEF";
+    private static StringBuffer buf = new StringBuffer();
+
+    public static byte[] hexStr2Bytes(String hexStr) {
+        if (hexStr.length() < 1) {
+            return null;
+        } else {
+            byte[] result = new byte[hexStr.length() / 2];
+
+            for (int i = 0; i < hexStr.length() / 2; ++i) {
+                int high = Integer.parseInt(hexStr.substring(i * 2, i * 2 + 1), 16);
+                int low = Integer.parseInt(hexStr.substring(i * 2 + 1, i * 2 + 2), 16);
+                result[i] = (byte) (high * 16 + low);
+            }
+
+            return result;
+        }
+    }
+
+    public static byte[] hexStringToBytes(String hexString) {
+        if (hexString != null && !hexString.equals("")) {
+            hexString = hexString.toUpperCase();
+            int length = hexString.length() / 2;
+            char[] hexChars = hexString.toCharArray();
+            byte[] d = new byte[length];
+
+            for (int i = 0; i < length; ++i) {
+                int pos = i * 2;
+                byte h = charToByte(hexChars[pos]);
+                byte l = charToByte(hexChars[pos + 1]);
+                d[i] = (byte) (h << 4 | l);
+            }
+
+            return d;
+        } else {
+            return null;
+        }
+    }
+
+    private static byte charToByte(char c) {
+        return (byte) "0123456789ABCDEF".indexOf(c);
+    }
+
+    public static String bytes2HexStr(byte[] datas) {
+        if (datas != null && datas.length != 0) {
+            buf.setLength(0);
+
+            for (int i = 0; i < datas.length; ++i) {
+                if ((datas[i] & 255) < 16) {
+                    buf.append("0");
+                }
+
+                buf.append(Long.toHexString((long) (datas[i] & 255)));
+            }
+
+            return buf.toString();
+        } else {
+            return null;
+        }
+    }
+
+    public static String byte2HexStr(byte data) {
+        buf.setLength(0);
+        buf.append("0x");
+        if ((data & 255) < 16) {
+            buf.append("0");
+        }
+
+        buf.append(Long.toHexString((long) (data & 255)));
+        return buf.toString();
+    }
+
+    private HexUtils() {
+    }
+}

+ 174 - 0
app/src/main/java/com/sheep/jiuyan/samllsheep/utils/XXTea.java

@@ -0,0 +1,174 @@
+package com.sheep.jiuyan.samllsheep.utils;
+
+import java.math.BigInteger;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.nio.charset.Charset;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Created by kemllor on 2018/1/23.
+ */
+
+
+public class XXTea {
+    public static String Encrypt(String data, String key) {
+        return ToHexString(TEAEncrypt(
+                ToLongArray(PadRight(data, MIN_LENGTH).getBytes(
+                        Charset.forName("UTF8"))),
+                ToLongArray(PadRight(key, MIN_LENGTH).getBytes(
+                        Charset.forName("UTF8")))));
+    }
+
+    public static String Decrypt(String data, String key) {
+        if (data == null || data.length() < MIN_LENGTH) {
+            return data;
+        }
+        byte[] code = ToByteArray(TEADecrypt(
+                ToLongArray(data),
+                ToLongArray(PadRight(key, MIN_LENGTH).getBytes(
+                        Charset.forName("UTF8")))));
+        return new String(code, Charset.forName("UTF8"));
+    }
+
+    private static long[] TEAEncrypt(long[] data, long[] key) {
+        int n = data.length;
+        if (n < 1) {
+            return data;
+        }
+
+        long z = data[data.length - 1], y = data[0], sum = 0, e, p, q;
+        q = 6 + 52 / n;
+        while (q-- > 0) {
+            sum += DELTA;
+            e = (sum >> 2) & 3;
+            for (p = 0; p < n - 1; p++) {
+                y = data[(int) (p + 1)];
+                z = data[(int) p] += (z >> 5 ^ y << 2) + (y >> 3 ^ z << 4)
+                        ^ (sum ^ y) + (key[(int) (p & 3 ^ e)] ^ z);
+            }
+            y = data[0];
+            z = data[n - 1] += (z >> 5 ^ y << 2) + (y >> 3 ^ z << 4)
+                    ^ (sum ^ y) + (key[(int) (p & 3 ^ e)] ^ z);
+        }
+
+        return data;
+    }
+
+    private static long[] TEADecrypt(long[] data, long[] key) {
+        int n = data.length;
+        if (n < 1) {
+            return data;
+        }
+
+        long z = data[data.length - 1], y = data[0], sum = 0, e, p, q;
+        q = 6 + 52 / n;
+        sum = q * DELTA;
+        while (sum != 0) {
+            e = (sum >> 2) & 3;
+            for (p = n - 1; p > 0; p--) {
+                z = data[(int) (p - 1)];
+                y = data[(int) p] -= (z >> 5 ^ y << 2) + (y >> 3 ^ z << 4)
+                        ^ (sum ^ y) + (key[(int) (p & 3 ^ e)] ^ z);
+            }
+            z = data[n - 1];
+            y = data[0] -= (z >> 5 ^ y << 2) + (y >> 3 ^ z << 4) ^ (sum ^ y)
+                    + (key[(int) (p & 3 ^ e)] ^ z);
+            sum -= DELTA;
+        }
+
+        return data;
+    }
+
+    private static long[] ToLongArray(byte[] data) {
+        int n = (data.length % 8 == 0 ? 0 : 1) + data.length / 8;
+        long[] result = new long[n];
+
+        for (int i = 0; i < n - 1; i++) {
+            result[i] = bytes2long(data, i * 8);
+        }
+
+        byte[] buffer = new byte[8];
+        for (int i = 0, j = (n - 1) * 8; j < data.length; i++, j++) {
+            buffer[i] = data[j];
+        }
+        result[n - 1] = bytes2long(buffer, 0);
+
+        return result;
+    }
+
+    private static byte[] ToByteArray(long[] data) {
+        List<Byte> result = new ArrayList<Byte>();
+
+        for (int i = 0; i < data.length; i++) {
+            byte[] bs = long2bytes(data[i]);
+            for (int j = 0; j < 8; j++) {
+                result.add(bs[j]);
+            }
+        }
+
+        while (result.get(result.size() - 1) == SPECIAL_CHAR) {
+            result.remove(result.size() - 1);
+        }
+
+        byte[] ret = new byte[result.size()];
+        for (int i = 0; i < ret.length; i++) {
+            ret[i] = result.get(i);
+        }
+        return ret;
+    }
+
+    public static byte[] long2bytes(long num) {
+        ByteBuffer buffer = ByteBuffer.allocate(8).order(
+                ByteOrder.LITTLE_ENDIAN);
+        buffer.putLong(num);
+        return buffer.array();
+    }
+
+    public static long bytes2long(byte[] b, int index) {
+        ByteBuffer buffer = ByteBuffer.allocate(8).order(
+                ByteOrder.LITTLE_ENDIAN);
+        buffer.put(b, index, 8);
+        return buffer.getLong(0);
+    }
+
+    private static String ToHexString(long[] data) {
+        StringBuilder sb = new StringBuilder();
+        for (int i = 0; i < data.length; i++) {
+            sb.append(PadLeft(Long.toHexString(data[i]), 16));
+        }
+        return sb.toString();
+    }
+
+
+
+
+    private static long[] ToLongArray(String data) {
+        int len = data.length() / 16;
+        long[] result = new long[len];
+        for (int i = 0; i < len; i++) {
+            result[i] = new BigInteger(data.substring(i * 16, i * 16 + 16), 16)
+                    .longValue();
+        }
+        return result;
+    }
+
+    private static String PadRight(String source, int length) {
+        while (source.length() < length) {
+            source += SPECIAL_CHAR;
+        }
+        return source;
+    }
+
+    private static String PadLeft(String source, int length) {
+        while (source.length() < length) {
+            source = '0' + source;
+        }
+        return source;
+    }
+
+    private static long DELTA = 0x9E3779B9;
+    private static int MIN_LENGTH = 32;
+    private static char SPECIAL_CHAR = '\0';
+}

BIN
app/src/main/res/drawable-hdpi/close_password_eyes.png


+ 32 - 14
app/src/main/res/layout/game_detail_activity.xml

@@ -9,7 +9,8 @@
 
     <ScrollView
         android:layout_width="match_parent"
-        android:layout_height="match_parent">
+        android:layout_height="0dp"
+        android:layout_weight="1">
 
         <LinearLayout
             android:layout_width="match_parent"
@@ -46,7 +47,6 @@
                         android:layout_width="wrap_content"
                         android:layout_height="wrap_content"
                         android:gravity="center_vertical"
-                        android:text="title"
                         android:textColor="@color/black_text_deep"
                         android:textSize="@dimen/text_size_3"/>
 
@@ -57,7 +57,6 @@
                         android:layout_height="wrap_content"
                         android:layout_marginTop="@dimen/content_padding_small"
                         android:gravity="center_vertical"
-                        android:text="250/250"
                         android:textColor="@color/black_text_gray"
                         android:textSize="@dimen/text_size_2"/>
 
@@ -67,7 +66,6 @@
                         android:layout_height="wrap_content"
                         android:layout_marginTop="@dimen/content_padding_small"
                         android:gravity="center_vertical"
-                        android:text="截止时间:2018-1-1"
                         android:textColor="@color/black_text_gray"
                         android:textSize="@dimen/text_size_2"/>
                 </LinearLayout>
@@ -133,20 +131,10 @@
 
             </RelativeLayout>
 
-            <Button
-                android:id="@+id/btn_task_item"
-                style="@style/style_btn"
-                android:layout_width="wrap_content"
-                android:layout_height="wrap_content"
-                android:layout_gravity="right"
-                android:layout_marginBottom="20dp"
-                android:layout_marginRight="@dimen/content_padding"
-                android:text="下载游戏"/>
 
             <View
                 android:layout_width="match_parent"
                 android:layout_height="@dimen/content_padding"
-                android:layout_below="@id/btn_task_item"
                 android:background="@color/background_light_gray"/>
 
             <TextView
@@ -184,4 +172,34 @@
 
     </ScrollView>
 
+    <LinearLayout
+        android:layout_width="match_parent"
+        android:layout_height="@dimen/layout_heigh_default"
+        android:background="@color/background_light_gray"
+        android:orientation="horizontal"
+        android:padding="@dimen/content_padding_small">
+
+        <Button
+            android:id="@+id/btn_task_item"
+            style="@style/style_btn"
+            android:layout_width="0dp"
+            android:layout_height="match_parent"
+            android:layout_gravity="right"
+            android:layout_marginLeft="@dimen/content_padding_small"
+            android:layout_marginRight="@dimen/content_padding_small"
+            android:layout_weight="1"
+            android:text="下载游戏"/>
+
+        <Button
+            android:id="@+id/btn_up_imag"
+            style="@style/style_btn"
+            android:layout_width="0dp"
+            android:layout_height="match_parent"
+            android:layout_gravity="right"
+            android:layout_marginLeft="@dimen/content_padding_small"
+            android:layout_marginRight="@dimen/content_padding_small"
+            android:layout_weight="1"
+            android:text="上传截图"/>
+    </LinearLayout>
+
 </LinearLayout>

+ 59 - 13
app/src/main/res/layout/login_actvity.xml

@@ -1,24 +1,70 @@
 <?xml version="1.0" encoding="utf-8"?>
-<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
-                android:layout_width="match_parent"
-                android:layout_height="match_parent"
-                android:background="@color/theme"
-                android:orientation="vertical">
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+              android:layout_width="match_parent"
+              android:layout_height="match_parent"
+              android:focusableInTouchMode="true"
+              android:orientation="vertical">
+
+
+    <include
+        layout="@layout/title"/>
+
+    <View
+        android:layout_width="match_parent"
+        android:layout_height="50dp"/>
+
+    <EditText
+        android:id="@+id/et_account"
+        style="style_edt"
+        android:layout_width="match_parent"
+        android:layout_height="@dimen/layout_heigh_default"
+        android:layout_margin="@dimen/content_padding"
+        android:hint="请输入帐号"
+        android:textSize="@dimen/text_size_3"/>
+
+    <EditText
+        android:id="@+id/et_psw"
+        style="style_edt"
+        android:layout_width="match_parent"
+        android:layout_height="@dimen/layout_heigh_default"
+        android:layout_margin="@dimen/content_padding"
+        android:hint="请输入密码"
+        android:inputType="textPassword"
+        android:textSize="@dimen/text_size_3"/>
+
+    <TextView
+        android:id="@+id/tv_register"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:padding="@dimen/content_padding"
+        android:gravity="right"
+        android:text="注册新用户"
+        android:textColor="@color/orange_text_light"/>
 
     <ImageView
         android:id="@+id/img_login"
         android:layout_width="50dp"
         android:layout_height="50dp"
         android:layout_centerInParent="true"
+        android:layout_gravity="center"
         android:src="@drawable/wx_logo"/>
 
+    <View
+        android:layout_width="match_parent"
+        android:layout_height="0dp"
+        android:layout_weight="1"/>
+
+
     <TextView
-        android:layout_width="wrap_content"
-        android:layout_height="wrap_content"
-        android:layout_below="@id/img_login"
-        android:layout_centerHorizontal="true"
-        android:text="微信登录"
-        android:textColor="@color/white"
-        android:textSize="16sp"/>
+        android:id="@+id/tv_wx"
+        style="@style/style_btn"
+        android:layout_width="match_parent"
+        android:layout_height="35dp"
+        android:layout_marginBottom="@dimen/content_padding"
+        android:layout_marginLeft="@dimen/content_padding_big"
+        android:layout_marginRight="@dimen/content_padding_big"
+        android:gravity="center"
+        android:text="登 录"
+        android:textSize="@dimen/text_size_3"/>
 
-</RelativeLayout>
+</LinearLayout>

+ 93 - 0
app/src/main/res/layout/register_activity.xml

@@ -0,0 +1,93 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+              android:layout_width="match_parent"
+              android:layout_height="match_parent"
+              android:focusableInTouchMode="true"
+              android:orientation="vertical">
+
+    <include
+        layout="@layout/title"/>
+
+    <View
+        android:layout_width="match_parent"
+        android:layout_height="50dp"/>
+
+    <EditText
+        android:id="@+id/et_account"
+        style="style_edt"
+        android:layout_width="match_parent"
+        android:layout_height="@dimen/layout_heigh_default"
+        android:layout_margin="@dimen/content_padding"
+        android:hint="请输入手机号"
+        android:textSize="@dimen/text_size_3"/>
+
+    <LinearLayout
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:layout_margin="@dimen/content_padding"
+        android:orientation="horizontal"
+        >
+
+        <EditText
+            android:id="@+id/et_code"
+            style="style_edt"
+            android:layout_width="0dp"
+            android:layout_height="@dimen/layout_heigh_default"
+            android:layout_weight="2"
+            android:hint="请输入验证码"
+            android:textSize="@dimen/text_size_3"/>
+
+        <TextView
+            android:id="@+id/btn_code"
+            android:layout_width="0dp"
+            android:layout_height="wrap_content"
+            android:layout_gravity="center|center_vertical"
+            android:layout_weight="1"
+            android:background="@drawable/sp_btn_common"
+            android:gravity="center"
+            android:padding="@dimen/content_padding_small"
+            android:text="获取验证码"
+            android:textColor="@color/black_text_deep"
+            />
+
+    </LinearLayout>
+
+
+    <EditText
+        android:id="@+id/et_psw"
+        style="style_edt"
+        android:layout_width="match_parent"
+        android:layout_height="@dimen/layout_heigh_default"
+        android:layout_margin="@dimen/content_padding"
+        android:hint="请输入密码"
+        android:inputType="textPassword"
+        android:textSize="@dimen/text_size_3"/>
+
+    <EditText
+        android:id="@+id/et_invite"
+        style="style_edt"
+        android:layout_width="match_parent"
+        android:layout_height="@dimen/layout_heigh_default"
+        android:layout_margin="@dimen/content_padding"
+        android:hint="请输入邀请码(选填)"
+        android:inputType="textPassword"
+        android:textSize="@dimen/text_size_3"/>
+
+    <View
+        android:layout_width="match_parent"
+        android:layout_height="0dp"
+        android:layout_weight="1"/>
+
+    <TextView
+        android:id="@+id/tv_wx"
+        style="@style/style_btn"
+        android:layout_width="match_parent"
+        android:layout_height="35dp"
+        android:layout_marginBottom="@dimen/content_padding"
+        android:layout_marginLeft="@dimen/content_padding_big"
+        android:layout_marginRight="@dimen/content_padding_big"
+        android:gravity="center"
+        android:text="注 册"
+        android:textSize="@dimen/text_size_3"/>
+
+</LinearLayout>

+ 1 - 1
app/src/main/res/values/common.xml

@@ -39,7 +39,7 @@
         <item name="android:paddingRight">16dp</item>
         <item name="android:paddingTop">6dp</item>
         <item name="android:paddingBottom">6dp</item>
-        <item name="android:textSize">@dimen/text_size_2</item>
+        <item name="android:textSize">@dimen/text_size_3</item>
         <item name="android:textColor">@color/black_text_deep</item>
         <item name="android:background">@drawable/sp_btn_common</item>
     </style>