Skip to content

Commit

Permalink
Merge pull request #15 from B515/WildHunter
Browse files Browse the repository at this point in the history
良心日更
  • Loading branch information
WHHunter authored Sep 1, 2017
2 parents 2000ed5 + 53fa9a2 commit c5387af
Show file tree
Hide file tree
Showing 18 changed files with 1,039 additions and 58 deletions.
4 changes: 3 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,16 @@ android {
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile fileTree(dir: 'libs', include: ['*.jar'])

compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:support-v4:25.3.1'
compile 'com.android.support:cardview-v7:25.3.1'
compile 'com.android.support:recyclerview-v7:25.3.1'
compile 'com.android.support:design:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.squareup.okhttp3:okhttp:3.8.0'
compile 'com.squareup.okio:okio:1.13.0'
compile 'com.jakewharton:butterknife:8.6.0'
testCompile 'junit:junit:4.12'

annotationProcessor 'com.jakewharton:butterknife-compiler:8.6.0'
}
4 changes: 3 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
</activity>
<activity android:name=".UI.InfoActivity" />
<activity android:name=".UI.HistoryActivity" />
<activity android:name=".UI.SettingActivity"></activity>
<activity android:name=".UI.SettingActivity" />
<activity android:name=".UI.TaskCreateActivity" />
<activity android:name=".UI.BalanceActivity"></activity>
</application>

</manifest>
84 changes: 84 additions & 0 deletions app/src/main/java/cn/chronoswap/chronoswap/UI/BalanceActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package cn.chronoswap.chronoswap.UI;

import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.telephony.TelephonyManager;
import android.widget.TextView;

import java.io.IOException;

import cn.chronoswap.chronoswap.R;
import cn.chronoswap.chronoswap.db.UserInfoManager;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.FormBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;

public class BalanceActivity extends AppCompatActivity {
private TextView tvTP, tvCP;
private Handler mHandler;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_balance);
tvTP = (TextView) findViewById(R.id.balance_tv_tp);
tvCP = (TextView) findViewById(R.id.balance_tv_cp);
getInfo();
mHandler = new Handler(Looper.getMainLooper()) {
@Override
public void handleMessage(Message msg) {
if (msg.what == 1) {
String[] userInfo = msg.obj.toString().split("&");
tvTP.setText(userInfo[7] + "TP");
tvCP.setText("信用积分" + userInfo[8]);
}
}
};
}

//从网络获取用户个人信息
private void getInfo() {
String id = UserInfoManager.getID(BalanceActivity.this);
TelephonyManager TelephonyMgr = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
String imei = TelephonyMgr.getDeviceId();
String path = "http://www.chronoswap.cn/userinfo_get.php";
//创建okHttpClient对象
OkHttpClient ohc = new OkHttpClient();
//表单数据
RequestBody fb = new FormBody.Builder()
.add("userid", id)
.add("session", imei)
.build();
//创建一个Request
Request req = new Request.Builder()
.url(path)
.post(fb)
.build();
Call call = ohc.newCall(req);
call.enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
}

@Override
public void onResponse(Call call, Response response) throws IOException {
String text = response.body().string();
Message msg = new Message();
if (text == null) {
msg.what = 0;
} else {
msg.what = 1;
msg.obj = text;
}
mHandler.sendMessage(msg);
}
});
}
}
Loading

0 comments on commit c5387af

Please sign in to comment.