Skip to content

Commit

Permalink
MOD : 解决内存泄露问题,添加其他参数
Browse files Browse the repository at this point in the history
  • Loading branch information
liyuan committed May 5, 2017
1 parent d31df0e commit b8508a7
Show file tree
Hide file tree
Showing 16 changed files with 333 additions and 698 deletions.
38 changes: 9 additions & 29 deletions antcaves/antcaves.iml
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,6 @@
<sourceFolder url="file://$MODULE_DIR$/src/main/jni" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/shaders" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/test/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/shaders" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
Expand All @@ -83,15 +75,17 @@
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/shaders" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/annotations" />
<sourceFolder url="file://$MODULE_DIR$/src/test/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/shaders" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/blame" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/bundles" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support.test.espresso/espresso-core/2.2.2/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support.test.espresso/espresso-idling-resource/2.2.2/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support.test/exposed-instrumentation-api-publish/0.5/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support.test/rules/0.5/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support.test/runner/0.5/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental-safeguard" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jniLibs" />
Expand All @@ -100,25 +94,11 @@
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/shaders" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/transforms" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/typedefs.txt" />
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
<excludeFolder url="file://$MODULE_DIR$/build/tmp" />
</content>
<orderEntry type="jdk" jdkName="Android API 24 Platform (1)" jdkType="Android SDK" />
<orderEntry type="jdk" jdkName="Android API 24 Platform (2)" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" scope="TEST" name="espresso-core-2.2.2" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="runner-0.5" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="exposed-instrumentation-api-publish-0.5" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="espresso-idling-resource-2.2.2" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="rules-0.5" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="hamcrest-library-1.3" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="javax.annotation-api-1.2" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="javax.inject-1" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="hamcrest-integration-1.3" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="javawriter-2.1.1" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="hamcrest-core-1.3" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="junit-4.12" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="jsr305-2.0.1" level="project" />
<orderEntry type="module" module-name="annotation" exported="" />
</component>
</module>
4 changes: 0 additions & 4 deletions antcaves/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,5 @@ android {

dependencies {
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'
compile project(':annotation')
}
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
package com.antcaves;

import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;

import org.junit.Test;
import org.junit.runner.RunWith;

import static org.junit.Assert.*;

/**
* Instrumentation test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() throws Exception {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getTargetContext();

assertEquals("com.antcaves", appContext.getPackageName());
}
}
//package com.antcaves;
//
//import android.content.Context;
//import android.support.test.InstrumentationRegistry;
//import android.support.test.runner.AndroidJUnit4;
//
//import org.junit.Test;
//import org.junit.runner.RunWith;
//
//import static org.junit.Assert.*;
//
///**
// * Instrumentation test, which will execute on an Android device.
// *
// * @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
// */
//@RunWith(AndroidJUnit4.class)
//public class ExampleInstrumentedTest {
// @Test
// public void useAppContext() throws Exception {
// // Context of the app under test.
// Context appContext = InstrumentationRegistry.getTargetContext();
//
// assertEquals("com.antcaves", appContext.getPackageName());
// }
//}
223 changes: 223 additions & 0 deletions antcaves/src/main/java/com/antcaves/Ant.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,223 @@
package com.antcaves;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Parcelable;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
* @author liyuan
* @description 干活的小蚂蚁
* @email thisuper@qq.com
* @date 17/5/4 下午3:36
*/

public class Ant {
private Context mContext;
private Intent mIntent;
private boolean isInterceptor = false;
private String mPath;


public Ant(Context context, String path) {
this.mContext = context;
this.mPath = path;
initAnt(path);
}

private void initAnt(String path) {
String url[] = path.split("\\?");
mIntent = new Intent(mContext, AntCaves.getRouters().get(url[0]));
equipString("url", path);
parseUrl(path);
}

public Ant go() {
if (!isInterceptor)
mContext.startActivity(mIntent);
return this;
}

public Ant go(int requestCode) {
if (!isInterceptor)
((Activity) mContext).startActivityForResult(mIntent, requestCode);
return this;
}

public Ant cross() {
if (!isInterceptor) {
mIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mContext.startActivity(mIntent);
}
return this;
}

public Ant cross(int requestCode) {
if (!isInterceptor) {
mIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
((Activity) mContext).startActivityForResult(mIntent, requestCode);
}
return this;
}

public Ant addInterceptor(final Interceptor iInterceptor) {
if (iInterceptor != null)
iInterceptor.process(mContext, mPath, new IInterceptorCallBack() {
@Override
public void interceptor(String path) {
mPath = path;
initAnt(path);
}

@Override
public void interceptor() {
isInterceptor = true;
}
});
return this;
}

public Ant equipString(String key, String value) {
mIntent.putExtra(key, value);
return this;
}

public Ant equipInt(String key, int value) {
mIntent.putExtra(key, value);
return this;
}

public Ant equipLong(String key, long value) {
mIntent.putExtra(key, value);
return this;
}

public Ant equipDouble(String key, double value) {
mIntent.putExtra(key, value);
return this;
}

public Ant equipFloat(String key, float value) {
mIntent.putExtra(key, value);
return this;
}

public Ant equipBoolean(String key, boolean value) {
mIntent.putExtra(key, value);
return this;
}

public Ant equipChar(String key, char value) {
mIntent.putExtra(key, value);
return this;
}

public Ant equipExtra(String key, Bundle value) {
mIntent.putExtra(key, value);
return this;
}

public Ant equipExtra(String key, Serializable value) {
mIntent.putExtra(key, value);
return this;
}

public Ant equipExtra(String key, Parcelable value) {
mIntent.putExtra(key, value);
return this;
}

public Ant equipStringArrayList(String key, ArrayList<String> value) {
mIntent.putStringArrayListExtra(key, value);
return this;
}

private void parseUrl(String path) {
if (!checkPathRole(path)) {
ALogger.e("parseUrl", "Ant got lost: [reason] your path mismatch,please check again");
} else {
//第一步取出参数module://activity?name=''&value=123
String url[] = path.split("\\?");
if (url.length == 2) {
//取出path中的key值
String keys = AntCaves.getParams().get(url[0]);
String key[] = keys.split("@");
String params = url[1];//取出问号后面的字符串
String param[] = params.split("&");
Map<String, String> keyMap = new HashMap<>();
Map<String, String> paramMap = new HashMap<>();
if (key.length == param.length) {
for (int i = 0; i < key.length; i++) {
String kv[] = key[i].split("->");
String p_kv[] = param[i].split("=");
if (kv.length == 2) {
keyMap.put(kv[0], kv[1]);
paramMap.put(p_kv[0], p_kv[1]);
} else {
ALogger.e("failure:", "you lost some name or type(name->type)");
}
}

} else {
ALogger.e("failure:", "you lost some parameters");
}
Set<String> keySet = keyMap.keySet();
Set<String> paramSet = paramMap.keySet();
for (String keyStr : keySet) {
for (String paramKeyStr : paramSet) {
if (keyStr.equals(paramKeyStr)) {
if (keyMap.get(keyStr).equals("int")) {
equipInt(keyStr, Integer.parseInt(paramMap.get(paramKeyStr)));
}
if (keyMap.get(keyStr).equals("String")) {
equipString(keyStr, paramMap.get(paramKeyStr));
}
if (keyMap.get(keyStr).equals("double")) {
equipDouble(keyStr, Double.parseDouble(paramMap.get(paramKeyStr)));
}
if (keyMap.get(keyStr).equals("float")) {
equipFloat(keyStr, Float.parseFloat(paramMap.get(paramKeyStr)));
}
if (keyMap.get(keyStr).equals("long")) {
equipLong(keyStr, Long.parseLong(paramMap.get(paramKeyStr)));
}
if (keyMap.get(keyStr).equals("char")) {

}
if (keyMap.get(keyStr).equals("boolean")) {
equipBoolean(keyStr, Boolean.parseBoolean(paramMap.get(paramKeyStr)));
}
}

}

}
} else {
ALogger.e("success:", "there is no parameter ");
}
}

}

/**
* 检查path 是否规则有效
*
* @param path
* @return
*/
private boolean checkPathRole(String path) {
String MATCH_ROLE = "[a-zA-z]+://[^\\s]*";
Pattern pattern = Pattern.compile(MATCH_ROLE);
Matcher matcher = pattern.matcher(path);
return matcher.matches();
}
}
Loading

0 comments on commit b8508a7

Please sign in to comment.