Skip to content

Commit

Permalink
整理项目
Browse files Browse the repository at this point in the history
  • Loading branch information
Edwin Wu committed Jun 16, 2017
1 parent 89efb9d commit d13304b
Show file tree
Hide file tree
Showing 21 changed files with 155 additions and 55 deletions.
13 changes: 11 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,26 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
testOptions {
unitTests.returnDefaultValues = true
unitTests.all {
// All the usual Gradle options.
jvmArgs '-XX:MaxPermSize=256m'
}
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
testCompile 'junit:junit:4.12'

testCompile 'org.mockito:mockito-core:1.9.5'
compile 'com.android.support.constraint:constraint-layout:1.0.2'

// support
compile "com.android.support:appcompat-v7:$rootProject.supportLibraryVersion"

compile project(':http-library')
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,22 @@
import android.view.View;
import android.widget.TextView;

import com.github.why168.androidhttputils.http.Call;
import com.github.why168.androidhttputils.http.Callback;
import com.github.why168.androidhttputils.http.GoHttp;
import com.github.why168.androidhttputils.http.Request;
import com.github.why168.http.Call;
import com.github.why168.http.Callback;
import com.github.why168.http.HttpUtils;
import com.github.why168.http.Request;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.IOException;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

public class HomeActivity extends AppCompatActivity {
private TextView tv_text;
private GoHttp goHttp;
private HttpUtils goHttp;

// 魂斗罗下载 http://124.193.230.12/imtt.dd.qq.com/16891/A1BFDC1BD905CEF01F3076509F920FD3.apk?mkey=59424b6446b6ee89&f=ae12&c=0&fsname=com.tencent.shootgame_1.2.33.7260_337260.apk&csr=1bbd&p=.apk

Expand All @@ -27,7 +31,7 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
tv_text = (TextView) findViewById(R.id.tv_text);
goHttp = new GoHttp();
goHttp = new HttpUtils();

}

Expand All @@ -38,12 +42,11 @@ public void getHttp() {

// http://jubi.com/api/v1/ticker?coin=mryc
Request request = new Request.Builder()
.url("http://www.aybrowser.com/sdk")
.url("http://www.jubi.com/api/v1/ticker?coin=mryc")
.method("GET")
.headers(headers)
.build();


Call call = goHttp.newCall(request);
call.enqueue(new Callback() {
@Override
Expand All @@ -52,8 +55,18 @@ public void onFailure(Exception e) {
}

@Override
public void onResponse(String results) throws IOException {
tv_text.setText("GET_" + results);
public void onSuccessful(String results) throws IOException {
try {
JSONObject jsonObject = new JSONObject(results);
String last = jsonObject.optString("last");
double i = Double.valueOf(last);
double def = 0.43;

Log.e("Edwin", "results = " + results + "\nlast = " + i + "\n"
+ "百分比 = " + new BigDecimal(((i - def) / def) * 100).floatValue() + "%");
} catch (JSONException e) {
e.printStackTrace();
}
}
});
}
Expand Down Expand Up @@ -82,7 +95,7 @@ public void onFailure(Exception e) {
}

@Override
public void onResponse(String results) throws IOException {
public void onSuccessful(String results) throws IOException {
tv_text.setText("POST_" + results);
}
});
Expand All @@ -92,8 +105,7 @@ public void onResponse(String results) throws IOException {

}

public void
getFileHttp() {
public void getFileHttp() {
Map<String, String> headers = new HashMap<>();
headers.put("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/603.2.4 (KHTML, like Gecko) Version/10.1.1 Safari/603.2.4");
headers.put("Content-Type", "application/octet-stream");
Expand All @@ -114,7 +126,7 @@ public void onFailure(Exception e) {
}

@Override
public void onResponse(String results) throws IOException {
public void onSuccessful(String results) throws IOException {
tv_text.setText("GET_" + results);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import org.junit.Test;

import static org.junit.Assert.*;
import java.math.BigDecimal;

import static org.junit.Assert.assertEquals;

/**
* Example local unit test, which will execute on the development machine (host).
Expand All @@ -14,4 +16,15 @@ public class ExampleUnitTest {
public void addition_isCorrect() throws Exception {
assertEquals(4, 2 + 2);
}
// 0.488 --13.49%

@Test
public void dd() {
System.out.println(0.488 / 1.1349);
System.out.println(0.43 * (1 + 0.1349));

System.out.println((0.488 - 0.43) / 0.43 * 100 + "%");

System.out.println(new BigDecimal((0.488 - 0.43) / 0.43 * 100).floatValue());
}
}
24 changes: 24 additions & 0 deletions http-library/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apply plugin: 'com.android.library'

android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion

defaultConfig {
minSdkVersion rootProject.minSdkVersion
targetSdkVersion rootProject.targetSdkVersion
versionCode 1
versionName "1.0"

}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
}
25 changes: 25 additions & 0 deletions http-library/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /Users/edwin/Library/Android/sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# Add any project specific keep options here:

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
10 changes: 10 additions & 0 deletions http-library/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"

package="com.github.why168.http">

<application android:allowBackup="true" android:label="@string/app_name"
android:supportsRtl="true">

</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.github.why168.http;

/**
* @author Edwin.Wu
* @version 2017/6/15 22:57
* @since JDK1.8
*/
public class BitmapCallback {
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.github.why168.androidhttputils.http;
package com.github.why168.http;

/**
* @author Edwin.Wu
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.github.why168.androidhttputils.http;
package com.github.why168.http;

import java.io.IOException;

Expand All @@ -10,6 +10,5 @@
public interface Callback {
void onFailure(Exception e);


void onResponse(String results) throws IOException;
void onSuccessful(String results) throws IOException;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.github.why168.androidhttputils.http;
package com.github.why168.http;

import java.io.IOException;

Expand All @@ -14,7 +14,7 @@ public void onFailure(Exception e) {
}

@Override
public void onResponse(String results) throws IOException {
public void onSuccessful(String results) throws IOException {

}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
package com.github.why168.androidhttputils.http;

import android.support.annotation.NonNull;
package com.github.why168.http;

import java.util.ArrayDeque;
import java.util.ArrayList;
Expand Down Expand Up @@ -118,7 +116,7 @@ public synchronized int runningCallsCount() {
private static ThreadFactory threadFactory(final String name, final boolean daemon) {
return new ThreadFactory() {
@Override
public Thread newThread(@NonNull Runnable runnable) {
public Thread newThread(Runnable runnable) {
Thread result = new Thread(runnable, name);
result.setDaemon(daemon);
return result;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
package com.github.why168.androidhttputils.http;
package com.github.why168.http;

/**
* @author Edwin.Wu
* @version 2017/6/13 16:23
* @since JDK1.8
*/
public class GoHttp implements Call.Factory {
public class HttpUtils implements Call.Factory {
private HttpDispatcher dispatcher;
private int connectTimeout;
private int readTimeout;
private int writeTimeout;

public GoHttp() {
public HttpUtils() {
this(new Builder());
}

private GoHttp(Builder builder) {
private HttpUtils(Builder builder) {
dispatcher = builder.dispatcher;
connectTimeout = builder.connectTimeout;
readTimeout = builder.readTimeout;
Expand All @@ -37,7 +37,7 @@ public static final class Builder {
int readTimeout;
int writeTimeout;

public Builder(GoHttp httpUtils) {
public Builder(HttpUtils httpUtils) {
dispatcher = httpUtils.dispatcher;
connectTimeout = httpUtils.connectTimeout;
readTimeout = httpUtils.readTimeout;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.github.why168.androidhttputils.http;
package com.github.why168.http;

import java.io.IOException;

Expand All @@ -14,7 +14,7 @@ public void onFailure(Exception e) {
}

@Override
public void onResponse(String results) throws IOException {
public void onSuccessful(String results) throws IOException {

}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.github.why168.androidhttputils.http;
package com.github.why168.http;


import java.util.Locale;
Expand Down
Loading

0 comments on commit d13304b

Please sign in to comment.