diff --git a/README.md b/README.md index a22ecdd..2d20b8b 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,15 @@ -# TcStatInterface +# Sky Monitoring 天眼 #Android StaticFrameWork 自定义统计SDK, 完全放弃第三方平台,让app拥有自主的数据统计功能 ->支持页面统计 + +>支持Activity统计 + >自定义事件统计 ->APP启动退出统计,不同渠道统计 + +>APP启动退出唤醒自动统计 + +>crsah日志统计 + @@ -16,13 +22,13 @@ SDK所有的接口都封装在TcStatInterface抽象类的静态方法中,主要功能接口请参考第3节API说明。应用在启动时,需要调用initialize方法来初始化统计服务,之后便可按照统计的业务需求,调用统计数据上报接口上报统计打点。 SDK提供了接口给开发者来设置向统计统计服务器上报统计数据的策略,开发者可以在任意时候调用修改策略。客户端SDK上报的数据包括默认事件统计、应用全局(AppAction)统计(用于统计app的唤醒、打开关闭频率、使用时长等)、页面访问统计(Page)和自定义事件统计(Event)。 -统计SDK提供app的崩溃日志收集功能(统计SDK2.0 将会新增)。功能开启后,对于app在使用过程中的崩溃,SDK将自动采集崩溃日志,并上传到统计后台;统计后台会根据app版本,对崩溃进行聚合、展示。开发者可以根据app实际情况情况,将该崩溃标记成已处理或者忽略状态。 +统计SDK提供app的崩溃日志收集功能(统计SDK2.0 将会新增)。功能开启后,对于app在使用过程中的崩溃,SDK将自动采集崩溃日志,并上传到统计后台;统计后台会根据app版本,对崩溃进行聚合、展示。 SDK使用配置 ---- -本节主要介绍使用好房统计SDK前的准备工作,开发者也可以参照SDK中的demo来配置。 +本节主要介绍使用统计SDK前的准备工作,开发者也可以参照SDK中的demo来配置。 2.1. 配置AndroidManifest.xml文件 SDK支持的最低安卓版本为2.2。 @@ -84,51 +90,154 @@ APP常规数据统计 设置上报策略的代码示例如下: - // 设置策略模式 第一个是策略模式 ,第二是是时间(单位/分) + + // 设置策略模式 第一个是策略模式 ,第二是是时间(单位/分) TcStatInterface.setUploadPolicy(TcStatInterface.UploadPolicy.UPLOAD_POLICY_INTERVA, 3); + - - - -API说明 +## API说明 -- 4.1. API细节 - 请具体看demo 注释 + + 请具体看demo 注释 + -5. 集成步骤 -4.1 依赖项目 +## 集成步骤 - gradle中配置依赖module, 将项目增加为自己的子模块 +5.1 依赖项目 - dependencies { - - compile project(':StatInterface') - } + **Gradle:** + +root: + + repositories { + maven { url "https://jitpack.io" } + jcenter() + } - 4.2 配置Settings.gradle +Module: + + dependencies { + compile 'com.tamic:StatInterface:2.1' + + } - include ':app' ,':StatInterface' - 4.3 加入权限 +5.3 加入权限 + 见2.1的说明。 - 4.4 初始化 - 见2.3说明 具体见demo - 4.5 其他 - 如果你还在用Eclispe,直接用源码或者依赖jar - TcStatSdk_1.0.jar +5.4 初始化 + + Application的onCreate(): + + // assets + String fileName = "stat_id.json"; -注意 --- - 目前服务端代码需要你自我实现,数据结结构按客户端数据Modle实现即可。 + String url = "http://www.baidu.com"; + + // init statSdk + TcStatInterface.initialize(this, appId, "you app chanel", fileName); + // set upload url + TcStatInterface.setUrl(url); + +   见Wiki说明 参见demo + +5.5 AppAction + + 此统计包含是三个类型 + +1. App启动 + + + TcStatInterface.recordAppStart(); + +2. App退出 + + TcStatInterface.recordAppEnd(); +3. APP唤醒 -> 作者:Tamic : http://www.jianshu.com/p/cd83e81b78aa + 无需开发者上层使用,sdk会自动打点记录 -> 统计数据存储前期:Zhangliang + + +5.6 事件统计 + +   记录某个动作,并包含事件参数时, + + + findViewById(R.id.id_button).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + TcStatInterface.onEvent("main", "onlick", "send data"); + //reportData + TcStatInterface.reportData(); + + } + + }); + + + findViewById(R.id.id_button2).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + + // test + HashMap map = new HashMap<>(); + map.put("id1", "xxx"); + map.put("id2", "yyy"); + + TcStatInterface.onEvent("openNext", map); + + Intent intent = new Intent(MainActivity.this, SecondActivity.class); + startActivity(intent); + + } + + }); + + + + +5.7 Activity统计 + + +  统计activity启动时间,从哪个地方跳过来,业务开发者可以自己写一个base,让其他activity继承Base就行,就可完成自动搜集功能 +         + + public class BaseActivity extends Activity { + + @override + protected void onResume() { + super.onResume(); + //可以直接传this + TcStatInterface.recordPageStart(“ID”); + } + + protected void onPause() { + super.onPause(); + TcStatInterface.recordPageEnd(); + } + } + + + +注意 +-- + + 目前服务端代码需要你自我实现,数据结结构按客户端数据Model实现即可。收到数据落地到数据库,需要查看的时候即可查看,如果后端有可视化界面,那么更好不过。 + +  客户端:搜集,存储,上报。 +  服务端:接受数据,落地数据库,最后做大数据处理。 + +> 作者: +>  FramWork [@Tamic](https://github.com/Jianglei0716) : http://www.jianshu.com/p/cd83e81b78aa + +>crash:[@jianglei0716](https://github.com/Jianglei0716) diff --git a/StatInterface/build.gradle b/StatInterface/build.gradle deleted file mode 100644 index 3f9a105..0000000 --- a/StatInterface/build.gradle +++ /dev/null @@ -1,26 +0,0 @@ -apply plugin: 'com.android.library' - -android { - compileSdkVersion 23 - buildToolsVersion '23.0.2' - - defaultConfig { - minSdkVersion 14 - targetSdkVersion 23 - versionCode 1 - versionName "1.0" - } - buildTypes { - release { - minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' - } - } -} - -dependencies { - compile fileTree(dir: 'libs', include: ['*.jar']) - compile 'de.greenrobot:greendao:2.1.0' - compile 'com.alibaba:fastjson:1.2.8+' - compile 'com.loopj.android:android-async-http:1.4.9' -} diff --git a/StatInterface/build/generated/source/buildConfig/androidTest/debug/com/tamic/statInterface/statsdk/test/BuildConfig.java b/StatInterface/build/generated/source/buildConfig/androidTest/debug/com/tamic/statInterface/statsdk/test/BuildConfig.java deleted file mode 100644 index 1af0a1d..0000000 --- a/StatInterface/build/generated/source/buildConfig/androidTest/debug/com/tamic/statInterface/statsdk/test/BuildConfig.java +++ /dev/null @@ -1,13 +0,0 @@ -/** - * Automatically generated file. DO NOT MODIFY - */ -package com.tamic.statInterface.statsdk.test; - -public final class BuildConfig { - public static final boolean DEBUG = Boolean.parseBoolean("true"); - public static final String APPLICATION_ID = "com.tamic.statInterface.statsdk.test"; - public static final String BUILD_TYPE = "debug"; - public static final String FLAVOR = ""; - public static final int VERSION_CODE = 1; - public static final String VERSION_NAME = "1.0"; -} diff --git a/StatInterface/build/generated/source/buildConfig/debug/com/tamic/statInterface/statsdk/BuildConfig.java b/StatInterface/build/generated/source/buildConfig/debug/com/tamic/statInterface/statsdk/BuildConfig.java deleted file mode 100644 index b24282c..0000000 --- a/StatInterface/build/generated/source/buildConfig/debug/com/tamic/statInterface/statsdk/BuildConfig.java +++ /dev/null @@ -1,13 +0,0 @@ -/** - * Automatically generated file. DO NOT MODIFY - */ -package com.tamic.statInterface.statsdk; - -public final class BuildConfig { - public static final boolean DEBUG = Boolean.parseBoolean("true"); - public static final String APPLICATION_ID = "com.tamic.statInterface.statsdk"; - public static final String BUILD_TYPE = "debug"; - public static final String FLAVOR = ""; - public static final int VERSION_CODE = 1; - public static final String VERSION_NAME = "1.0"; -} diff --git a/StatInterface/build/generated/source/buildConfig/release/com/tamic/statInterface/statsdk/BuildConfig.java b/StatInterface/build/generated/source/buildConfig/release/com/tamic/statInterface/statsdk/BuildConfig.java deleted file mode 100644 index b73fd18..0000000 --- a/StatInterface/build/generated/source/buildConfig/release/com/tamic/statInterface/statsdk/BuildConfig.java +++ /dev/null @@ -1,13 +0,0 @@ -/** - * Automatically generated file. DO NOT MODIFY - */ -package com.tamic.statInterface.statsdk; - -public final class BuildConfig { - public static final boolean DEBUG = false; - public static final String APPLICATION_ID = "com.tamic.statInterface.statsdk"; - public static final String BUILD_TYPE = "release"; - public static final String FLAVOR = ""; - public static final int VERSION_CODE = 1; - public static final String VERSION_NAME = "1.0"; -} diff --git a/StatInterface/build/generated/source/r/androidTest/debug/com/tamic/statInterface/statsdk/R.java b/StatInterface/build/generated/source/r/androidTest/debug/com/tamic/statInterface/statsdk/R.java deleted file mode 100644 index 8d38c7e..0000000 --- a/StatInterface/build/generated/source/r/androidTest/debug/com/tamic/statInterface/statsdk/R.java +++ /dev/null @@ -1,13 +0,0 @@ -/* AUTO-GENERATED FILE. DO NOT MODIFY. - * - * This class was automatically generated by the - * aapt tool from the resource data it found. It - * should not be modified by hand. - */ -package com.tamic.statInterface.statsdk; - -public final class R { - public static final class string { - public static final int app_name = 0x7f020000; - } -} diff --git a/StatInterface/build/generated/source/r/androidTest/debug/com/tamic/statInterface/statsdk/test/R.java b/StatInterface/build/generated/source/r/androidTest/debug/com/tamic/statInterface/statsdk/test/R.java deleted file mode 100644 index 6c60325..0000000 --- a/StatInterface/build/generated/source/r/androidTest/debug/com/tamic/statInterface/statsdk/test/R.java +++ /dev/null @@ -1,16 +0,0 @@ -/* AUTO-GENERATED FILE. DO NOT MODIFY. - * - * This class was automatically generated by the - * aapt tool from the resource data it found. It - * should not be modified by hand. - */ - -package com.tamic.statInterface.statsdk.test; - -public final class R { - public static final class attr { - } - public static final class string { - public static final int app_name=0x7f020000; - } -} diff --git a/StatInterface/build/generated/source/r/debug/com/tamic/statInterface/statsdk/R.java b/StatInterface/build/generated/source/r/debug/com/tamic/statInterface/statsdk/R.java deleted file mode 100644 index 02c3ca0..0000000 --- a/StatInterface/build/generated/source/r/debug/com/tamic/statInterface/statsdk/R.java +++ /dev/null @@ -1,16 +0,0 @@ -/* AUTO-GENERATED FILE. DO NOT MODIFY. - * - * This class was automatically generated by the - * aapt tool from the resource data it found. It - * should not be modified by hand. - */ - -package com.tamic.statInterface.statsdk; - -public final class R { - public static final class attr { - } - public static final class string { - public static int app_name=0x7f020000; - } -} diff --git a/StatInterface/build/generated/source/r/release/com/tamic/statInterface/statsdk/R.java b/StatInterface/build/generated/source/r/release/com/tamic/statInterface/statsdk/R.java deleted file mode 100644 index 02c3ca0..0000000 --- a/StatInterface/build/generated/source/r/release/com/tamic/statInterface/statsdk/R.java +++ /dev/null @@ -1,16 +0,0 @@ -/* AUTO-GENERATED FILE. DO NOT MODIFY. - * - * This class was automatically generated by the - * aapt tool from the resource data it found. It - * should not be modified by hand. - */ - -package com.tamic.statInterface.statsdk; - -public final class R { - public static final class attr { - } - public static final class string { - public static int app_name=0x7f020000; - } -} diff --git a/StatInterface/build/intermediates/bundles/debug/AndroidManifest.xml b/StatInterface/build/intermediates/bundles/debug/AndroidManifest.xml deleted file mode 100644 index 27561f8..0000000 --- a/StatInterface/build/intermediates/bundles/debug/AndroidManifest.xml +++ /dev/null @@ -1,32 +0,0 @@ - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/StatInterface/build/intermediates/bundles/debug/R.txt b/StatInterface/build/intermediates/bundles/debug/R.txt deleted file mode 100644 index a80644b..0000000 --- a/StatInterface/build/intermediates/bundles/debug/R.txt +++ /dev/null @@ -1 +0,0 @@ -int string app_name 0x7f020000 diff --git a/StatInterface/build/intermediates/bundles/debug/aapt/AndroidManifest.xml b/StatInterface/build/intermediates/bundles/debug/aapt/AndroidManifest.xml deleted file mode 100644 index 27561f8..0000000 --- a/StatInterface/build/intermediates/bundles/debug/aapt/AndroidManifest.xml +++ /dev/null @@ -1,32 +0,0 @@ - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/StatInterface/build/intermediates/bundles/debug/classes.jar b/StatInterface/build/intermediates/bundles/debug/classes.jar deleted file mode 100644 index b865168..0000000 Binary files a/StatInterface/build/intermediates/bundles/debug/classes.jar and /dev/null differ diff --git a/StatInterface/build/intermediates/bundles/debug/res/values/values.xml b/StatInterface/build/intermediates/bundles/debug/res/values/values.xml deleted file mode 100644 index 7f658ad..0000000 --- a/StatInterface/build/intermediates/bundles/debug/res/values/values.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - statLibrary - \ No newline at end of file diff --git a/StatInterface/build/intermediates/bundles/release/AndroidManifest.xml b/StatInterface/build/intermediates/bundles/release/AndroidManifest.xml deleted file mode 100644 index 15eb723..0000000 --- a/StatInterface/build/intermediates/bundles/release/AndroidManifest.xml +++ /dev/null @@ -1,32 +0,0 @@ - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/StatInterface/build/intermediates/bundles/release/R.txt b/StatInterface/build/intermediates/bundles/release/R.txt deleted file mode 100644 index a80644b..0000000 --- a/StatInterface/build/intermediates/bundles/release/R.txt +++ /dev/null @@ -1 +0,0 @@ -int string app_name 0x7f020000 diff --git a/StatInterface/build/intermediates/bundles/release/aapt/AndroidManifest.xml b/StatInterface/build/intermediates/bundles/release/aapt/AndroidManifest.xml deleted file mode 100644 index 15eb723..0000000 --- a/StatInterface/build/intermediates/bundles/release/aapt/AndroidManifest.xml +++ /dev/null @@ -1,32 +0,0 @@ - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/StatInterface/build/intermediates/bundles/release/classes.jar b/StatInterface/build/intermediates/bundles/release/classes.jar deleted file mode 100644 index 3704027..0000000 Binary files a/StatInterface/build/intermediates/bundles/release/classes.jar and /dev/null differ diff --git a/StatInterface/build/intermediates/bundles/release/res/values/values.xml b/StatInterface/build/intermediates/bundles/release/res/values/values.xml deleted file mode 100644 index aed9459..0000000 --- a/StatInterface/build/intermediates/bundles/release/res/values/values.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - statLibrary - \ No newline at end of file diff --git a/StatInterface/build/intermediates/manifests/androidTest/debug/AndroidManifest.xml b/StatInterface/build/intermediates/manifests/androidTest/debug/AndroidManifest.xml deleted file mode 100644 index 97289eb..0000000 --- a/StatInterface/build/intermediates/manifests/androidTest/debug/AndroidManifest.xml +++ /dev/null @@ -1,39 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/StatInterface/build/intermediates/manifests/tmp/manifestMerger7085977054703475003.xml b/StatInterface/build/intermediates/manifests/tmp/manifestMerger7085977054703475003.xml deleted file mode 100644 index 0c748ad..0000000 --- a/StatInterface/build/intermediates/manifests/tmp/manifestMerger7085977054703475003.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - - - diff --git a/StatInterface/build/intermediates/res/androidTest/debug/values/values.xml b/StatInterface/build/intermediates/res/androidTest/debug/values/values.xml deleted file mode 100644 index 7730988..0000000 --- a/StatInterface/build/intermediates/res/androidTest/debug/values/values.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - statLibrary - \ No newline at end of file diff --git a/StatInterface/build/tmp/packageDebugJar/MANIFEST.MF b/StatInterface/build/tmp/packageDebugJar/MANIFEST.MF deleted file mode 100644 index 59499bc..0000000 --- a/StatInterface/build/tmp/packageDebugJar/MANIFEST.MF +++ /dev/null @@ -1,2 +0,0 @@ -Manifest-Version: 1.0 - diff --git a/StatInterface/build/tmp/packageReleaseJar/MANIFEST.MF b/StatInterface/build/tmp/packageReleaseJar/MANIFEST.MF deleted file mode 100644 index 59499bc..0000000 --- a/StatInterface/build/tmp/packageReleaseJar/MANIFEST.MF +++ /dev/null @@ -1,2 +0,0 @@ -Manifest-Version: 1.0 - diff --git a/StatInterface/src/main/AndroidManifest.xml b/StatInterface/src/main/AndroidManifest.xml deleted file mode 100644 index 4238b43..0000000 --- a/StatInterface/src/main/AndroidManifest.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - - - - - - - - - - - - - - diff --git a/StatInterface/src/main/java/com/tamic/statInterface/statsdk/constants/NetConfig.java b/StatInterface/src/main/java/com/tamic/statInterface/statsdk/constants/NetConfig.java deleted file mode 100644 index e724a85..0000000 --- a/StatInterface/src/main/java/com/tamic/statInterface/statsdk/constants/NetConfig.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.tamic.statInterface.statsdk.constants; - -/** - * Created by Tc on 2016-03-25. - */ -public class NetConfig { - - /** - * constructor - */ - private NetConfig() { - - } - - /** - * You Url - */ - public static String ONLINE_URL ="http://www.baidu.com"; - - /** - * 数据上报Debug Url - */ - public static final String URL ="http://www.baidu.com"; - - /** - * 请求超时时间 - */ - public static final int TIME_OUT = 1000 * 50 * 1; - - /** 重新请求时间 */ - public static final int RETRY_TIMES = 3; - - /** HEADERS_KEY */ - public static final String HEADERS_KEY = "data_head"; - - /** key*/ - public static final String PARAMS_KEY = "data_body"; - - -} diff --git a/StatInterface/src/main/java/com/tamic/statInterface/statsdk/constants/StaticsConfig.java b/StatInterface/src/main/java/com/tamic/statInterface/statsdk/constants/StaticsConfig.java deleted file mode 100644 index e22199f..0000000 --- a/StatInterface/src/main/java/com/tamic/statInterface/statsdk/constants/StaticsConfig.java +++ /dev/null @@ -1,46 +0,0 @@ -package com.tamic.statInterface.statsdk.constants; - -import de.greenrobot.dao.Property; - -/** - * StaticsConfig - * Created by Tamic on 2016-03-30. - */ -public class StaticsConfig { - - /** - * constructor - */ - private StaticsConfig() { - - } - - public static final String SDK_TABLE_NAME = "TcStats_NOTE"; - - public final static String APPACTION_INFO = "pageInfo"; - public final static String PAGE_INFO = "appActionInfo"; - public final static String ENVENT_INFO = "enventInfo"; - public final static String CRASH_INFO = "crashInfo"; - - /**1*/ - public static final int APP_ID_HF = 100; - /**1*/ - public static final int APP_ID_AAZ = 200; - /**1)*/ - public static final int APP_ID_HFT = 300; - /***/ - public static final int APP_ID_HGJ = 400; - /***/ - public static final int APP_ID_HSH = 500; - - /* 1分钟,5分钟,10分钟,20分钟,30分钟发送 - - - /** 统计sdk版本号 */ - public static final int SDK_VERSION_CODE = 2; - - /** 统计sdk版本名称 */ - public static final String SDK_VERSION_NAME = "1.0.3"; - /** 是否是debug版本 */ - public static boolean DEBUG = true; -} diff --git a/StatInterface/src/main/java/com/tamic/statInterface/statsdk/core/IUpLoadlistener.java b/StatInterface/src/main/java/com/tamic/statInterface/statsdk/core/IUpLoadlistener.java deleted file mode 100644 index 04653fc..0000000 --- a/StatInterface/src/main/java/com/tamic/statInterface/statsdk/core/IUpLoadlistener.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.tamic.statInterface.statsdk.core; - -/** - * 上报状态接口 - * Created by LIUYONGKUI726 on 2016-03-25. - */ -public interface IUpLoadlistener { - - void onStart(); - - void onUpLoad(); - - void onSucess(); - - void onFailure(); - - void onCancell(); -} diff --git a/StatInterface/src/main/java/com/tamic/statInterface/statsdk/core/StaticsListener.java b/StatInterface/src/main/java/com/tamic/statInterface/statsdk/core/StaticsListener.java deleted file mode 100644 index c45f5f3..0000000 --- a/StatInterface/src/main/java/com/tamic/statInterface/statsdk/core/StaticsListener.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.tamic.statInterface.statsdk.core; - -import java.util.HashMap; - -/** - * Created by ZHANGLIANG098 on 2016-04-12. - */ -public interface StaticsListener { - - HashMap getStatIdMaps(); -} diff --git a/StatInterface/src/main/java/com/tamic/statInterface/statsdk/core/TcHeadrHandle.java b/StatInterface/src/main/java/com/tamic/statInterface/statsdk/core/TcHeadrHandle.java deleted file mode 100644 index 39dac9f..0000000 --- a/StatInterface/src/main/java/com/tamic/statInterface/statsdk/core/TcHeadrHandle.java +++ /dev/null @@ -1,216 +0,0 @@ -package com.tamic.statInterface.statsdk.core; - -import android.content.Context; -import android.content.pm.PackageInfo; -import android.content.pm.PackageManager; -import android.location.Location; -import android.location.LocationManager; -import android.provider.Settings; -import android.telephony.TelephonyManager; -import android.text.TextUtils; - -import com.tamic.statInterface.statsdk.model.header.AppInfo; -import com.tamic.statInterface.statsdk.model.header.DeviceInfo; -import com.tamic.statInterface.statsdk.model.header.HeaderInfo; -import com.tamic.statInterface.statsdk.model.header.NetworkInfo; -import com.tamic.statInterface.statsdk.util.DeviceUtil; -import com.tamic.statInterface.statsdk.util.NetworkUtil; - -import java.util.List; -import java.util.Locale; - -/** - * 头部句柄 初始化Header信息 - * Created by LIUYONGKUI726 on 2016-04-05. - */ -public class TcHeadrHandle { - - private static AppInfo appinfo; - - private static DeviceInfo deviceinfo; - - private static NetworkInfo networkinfo; - - private static TelephonyManager mTelephonyMgr; - - private static HeaderInfo headerInfo; - - private static boolean isInit ; - - private static int appId; - - private static String mChannel; - - - protected static boolean initHeader(Context context, int AppId, String channel) { - - - if (headerInfo == null) { - appId = AppId; - mChannel= channel; - networkinfo = new NetworkInfo(); - headerInfo = new HeaderInfo(getAppInfo(context), getDeviceInfo(context), getNetWorkInfo(context)); - isInit = true; - } - - return isInit; - - } - - public static boolean isInit() { - return isInit; - } - - - protected static HeaderInfo getHeader(Context context) { - - - if (headerInfo == null) { - return new HeaderInfo(getAppInfo(context), getDeviceInfo(context), getNetWorkInfo(context)); - } - - return headerInfo; - - } - - /** get AppInfo - * @param context - */ - private static AppInfo getAppInfo(Context context) { - - if (appinfo != null) { - return appinfo; - } - - appinfo = new AppInfo(); - PackageManager manager = context.getPackageManager(); - PackageInfo info = null; - String appLabel = ""; - - try { - info = manager.getPackageInfo(context.getPackageName(), 0); - appinfo.setApp_id(String.valueOf(appId)); - - if (info != null) { - appinfo.setApp_version(info.versionName); - } - appinfo.setApp_id(String.valueOf(appId)); - appinfo.setChannel(mChannel); - appinfo.setSdk_version(DeviceUtil.getSdkCode()); - appinfo.setSdk_verson_name(DeviceUtil.getSdkName()); - - return appinfo; - }catch (PackageManager.NameNotFoundException e1) { - e1.printStackTrace(); - return null; - } - } - - /** get Device Info - * @param context - */ - private static DeviceInfo getDeviceInfo(Context context) { - - if (deviceinfo != null) { - return deviceinfo; - } - deviceinfo = new DeviceInfo(); - - // 设备ID, - - mTelephonyMgr = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); - if (mTelephonyMgr != null) { - - deviceinfo.setDevice_id(mTelephonyMgr.getDeviceId()); - // android Imei - deviceinfo.setImei(mTelephonyMgr.getDeviceId()); - } - - // AndroidId - try { - String androidId = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID); - deviceinfo.setAndroid_id(androidId); - if (TextUtils.isEmpty(deviceinfo.getImei())) { - deviceinfo.setImei(androidId); - } - } catch (Exception e) { - // do nothing. not use the data - } - - deviceinfo.setMac(DeviceUtil.getMacAddress(context)); - - deviceinfo.setModel(android.os.Build.MODEL); - - deviceinfo.setOs("Android"); - - deviceinfo.setOs_version(android.os.Build.VERSION.RELEASE); - - // UniqueId - String openId = deviceinfo.getDevice_id(); - if (openId == null || openId.trim().length() == 0) { - openId = deviceinfo.getAndroid_id(); - } - if (openId == null || openId.trim().length() == 0) { - openId = deviceinfo.getMac(); - } - - deviceinfo.setOpenudid(openId); - deviceinfo.setResolution(DeviceUtil.getScreenWidth(context) + "*" + DeviceUtil.getScreenHeight(context)); - deviceinfo.setDensity(String.valueOf(DeviceUtil.getScreenDensity(context))); - deviceinfo.setLocale(Locale.getDefault().getLanguage()); - - return deviceinfo; - - } - - /** get NetWork Info - * @param context - */ - protected static NetworkInfo getNetWorkInfo(Context context) { - - if (networkinfo == null) { - - networkinfo = new NetworkInfo(); - } - networkinfo.setIp_addr(NetworkUtil.getLocalIpAddress()); - - networkinfo.setWifi_ind(NetworkUtil.isWifi(context)); - - if(mTelephonyMgr.getSimState() == TelephonyManager.SIM_STATE_READY) { - networkinfo.setCarrier(mTelephonyMgr.getSimOperatorName()); - } - - Location location = getLocation(context); - if(location != null){ - networkinfo.setLatitude(String.valueOf(location.getLatitude())); - networkinfo.setLongitude(String.valueOf(location.getLongitude())); - } - - return networkinfo; - } - - /** - * 获取Location - * @param context - * @return - */ - private static Location getLocation(Context context) { - //获取地理位置管理器 - LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); - - List providers = locationManager.getProviders(true); - String locationProvider; - if (providers.contains(LocationManager.GPS_PROVIDER)) { - //如果是GPS - locationProvider = LocationManager.GPS_PROVIDER; - } else if (providers.contains(LocationManager.NETWORK_PROVIDER)) { - //如果是Network - locationProvider = LocationManager.NETWORK_PROVIDER; - } else { - - locationProvider = LocationManager.GPS_PROVIDER;; - } - return locationManager.getLastKnownLocation(locationProvider); - } - -} diff --git a/StatInterface/src/main/java/com/tamic/statInterface/statsdk/core/TcIntentManager.java b/StatInterface/src/main/java/com/tamic/statInterface/statsdk/core/TcIntentManager.java deleted file mode 100644 index c4b0272..0000000 --- a/StatInterface/src/main/java/com/tamic/statInterface/statsdk/core/TcIntentManager.java +++ /dev/null @@ -1,219 +0,0 @@ - -package com.tamic.statInterface.statsdk.core; - -import android.content.Intent; -import android.net.ConnectivityManager; -import android.text.TextUtils; - - -import java.util.Set; - - -/** - * Intent Manager - * Created by Tamic on 2016-04-15. - * @author Tamic - */ -public final class TcIntentManager { - /** is normal start*/ - private boolean mNotMainIntent; - /** instance */ - private static TcIntentManager sInstance; - - /** - * @return instance - */ - public static synchronized TcIntentManager getInstance() { - if (sInstance == null) { - sInstance = new TcIntentManager(); - } - return sInstance; - } - - /** - * private constructor - */ - private TcIntentManager() { - - } - - /** - * @return true表示不是通过程序icon进入程序 - */ - public boolean isNotMainIntent() { - return mNotMainIntent; - } - - /** - * 设置是否是通过程序icon进入程序 - * @param aFlag true表示不是通过程序icon进入程序 - */ - public void setNotMainIntent(boolean aFlag) { - mNotMainIntent = aFlag; - } - - /** - * isActionValidate - * @param aIntent intent - * @return action Validate - */ - public static boolean isActionValidate(final Intent aIntent) { - return ((aIntent != null) && (!TextUtils.isEmpty(aIntent.getAction()))); - } - - /** - * @param aIntent intent - * @return intent类型是否是ACTION_MAIN - */ - public boolean isMainIntent(final Intent aIntent) { - return isActionAs(aIntent, Intent.ACTION_MAIN); - } - - /** - * @param aIntent intent - * @return intent类型是否是view - */ - public boolean isViewIntent(final Intent aIntent) { - return isActionAs(aIntent, Intent.ACTION_VIEW); - } - - /** - * @param aIntent intent - * @return intent类型是否是search - */ - public boolean isSearchIntent(final Intent aIntent) { - return isActionAs(aIntent, Intent.ACTION_SEARCH); - } - - /** - * @param aIntent intent - * @return intent类型是否是web search - */ - public boolean isWebSearchIntent(final Intent aIntent) { - return isActionAs(aIntent, Intent.ACTION_WEB_SEARCH); - } - - /** - * @param aIntent intent - * @return intent类型是否是ACTION_DATE_CHANGED - */ - public boolean isDateChangedIntent(final Intent aIntent) { - return isActionAs(aIntent, Intent.ACTION_DATE_CHANGED); - } - - /** - * @param aIntent intent - * @return intent类型是否是ACTION_USER_PRESENT - */ - public boolean isUserPresentIntent(final Intent aIntent) { - return isActionAs(aIntent, Intent.ACTION_USER_PRESENT); - } - - /** - * @param aIntent intent - * @return intent类型是否是ACTION_SCREEN_ON - */ - public boolean isScreenOnIntent(final Intent aIntent) { - return isActionAs(aIntent, Intent.ACTION_SCREEN_ON); - } - - /** - * @param aIntent intent - * @return intent类型是否是ACTION_SCREEN_OFF - */ - public boolean isScreenOffIntent(final Intent aIntent) { - return isActionAs(aIntent, Intent.ACTION_SCREEN_OFF); - } - - /** - * @param aIntent intent - * @return intent类型是否是ACTION_DEVICE_STORAGE_LOW - */ - public boolean isDeviceStorageLowIntent(final Intent aIntent) { - return isActionAs(aIntent, Intent.ACTION_DEVICE_STORAGE_LOW); - } - - /** - * @param aIntent intent - * @return intent类型是否是ACTION_CLOSE_SYSTEM_DIALOGS - */ - public boolean isCloseSystemDialogsIntent(final Intent aIntent) { - return isActionAs(aIntent, Intent.ACTION_CLOSE_SYSTEM_DIALOGS); - } - - /** - * @param aIntent intent - * @return intent类型是否是ACTION_BATTERY_CHANGED - */ - public boolean isBatteryChangedIntent(final Intent aIntent) { - return isActionAs(aIntent, Intent.ACTION_BATTERY_CHANGED); - } - - /** - * @param aIntent intent - * @return intent类型是否是ACTION_HEADSET_PLUG - */ - public boolean isHeadsetPlugIntent(final Intent aIntent) { - return isActionAs(aIntent, Intent.ACTION_HEADSET_PLUG); - } - - /** - * @param aIntent intent - * @return intent类型是否是ACTION_BOOT_COMPLETED - */ - public boolean isBootCompletedIntent(final Intent aIntent) { - return isActionAs(aIntent, Intent.ACTION_BOOT_COMPLETED); - } - - /** - * @param aIntent intent - * @return intent类型是否是CONNECTIVITY_ACTION - */ - public boolean isConnectivityIntent(final Intent aIntent) { - return isActionAs(aIntent, ConnectivityManager.CONNECTIVITY_ACTION); - } - - /** - * @param aIntent intent - * @param aAction action - * @return intent的action类型是否是给定的action - */ - private boolean isActionAs(final Intent aIntent, final String aAction) { - final String action = getAction(aIntent); - return ((action != null) && (aAction != null) && (action.equals(aAction))); - } - - /** - * 从intent获取action - * @param aIntent intent - * @return action - */ - private static String getAction(final Intent aIntent) { - if (aIntent == null) { - return null; - } - return aIntent.getAction(); - } - - /** - * @param aIntent intent - * @param aCategory category - * @return 是否包含指定category类型 - */ - private static boolean isCategoryAs(final Intent aIntent, final String aCategory) { - final Set categories = getCategories(aIntent); - return ((categories != null) && (aCategory != null) && (categories.contains(aCategory))); - } - - /** - * @param aIntent intent - * @return categories - */ - private static Set getCategories(final Intent aIntent) { - if (aIntent == null) { - return null; - } - return aIntent.getCategories(); - } - -} diff --git a/StatInterface/src/main/java/com/tamic/statInterface/statsdk/core/TcNetEngine.java b/StatInterface/src/main/java/com/tamic/statInterface/statsdk/core/TcNetEngine.java deleted file mode 100644 index 4fb72ac..0000000 --- a/StatInterface/src/main/java/com/tamic/statInterface/statsdk/core/TcNetEngine.java +++ /dev/null @@ -1,189 +0,0 @@ -package com.tamic.statInterface.statsdk.core; - -import android.content.Context; -import android.os.Looper; - -import com.loopj.android.http.AsyncHttpResponseHandler; -import com.loopj.android.http.RequestParams; -import com.tamic.statInterface.statsdk.constants.NetConfig; -import com.tamic.statInterface.statsdk.constants.StaticsConfig; -import com.tamic.statInterface.statsdk.http.TcHttpClient; -import com.tamic.statInterface.statsdk.util.JsonUtil; -import com.tamic.statInterface.statsdk.util.StatLog; - -import java.net.URLEncoder; -import java.util.HashMap; -import java.util.Set; - -import cz.msebera.android.httpclient.Header; -import cz.msebera.android.httpclient.HeaderElement; -import cz.msebera.android.httpclient.HttpStatus; -import cz.msebera.android.httpclient.ParseException; - -/** - * Created by LIUYONGKUI726 on 2016-04-18. - */ -public class TcNetEngine { - - - private Context context; - - private TcHttpClient mHttpClient; - - private String mKey; - - /** 重试次数 */ - protected int mRetrytimes = NetConfig.RETRY_TIMES; - - public static final String TAG = "TamicStat::TaNetEngine"; - - /** 是否支持断点 */ - protected boolean mCanContinue; - - private String mHostUrl = NetConfig.ONLINE_URL; - - private PaJsonHttpResponseHandler mTaskHandler; - - private IUpLoadlistener mUpLoadlistener; - - private HashMap headers; - - private RequestParams requestParams; - - Header[] reqHeaders; - - Header header; - - public TcNetEngine(Context context, IUpLoadlistener upLoadlistener) { - - this(context, null, upLoadlistener); - - } - - public TcNetEngine(Context context, TcHttpClient httpClient, IUpLoadlistener upLoadlistener) { - this.context = context; - mHttpClient = httpClient; - mCanContinue = true; - mTaskHandler = new PaJsonHttpResponseHandler(true); - mUpLoadlistener = upLoadlistener; - init (); - - - } - - private void init() { - - if (StaticsConfig.DEBUG) { - mHostUrl = NetConfig.URL; - } - headers = new HashMap(); - requestParams = new RequestParams(); - } - - public TcHttpClient getHttpClient() { - return mHttpClient; - } - - public void setHttpClient(TcHttpClient mHttpClient) { - this.mHttpClient = mHttpClient; - } - - public String start(final String... strings) { - - - - String str = JsonUtil.toJSONString(TcHeadrHandle.getHeader(context)); - - StatLog.d(TAG, "head:" + str); - if (headers.size() >= 0) { - headers.clear(); - } - headers.put(NetConfig.HEADERS_KEY, URLEncoder.encode(str)); - //headers.put("Accept", "application/json"); - - requestParams.remove(NetConfig.PARAMS_KEY); - - requestParams.put(NetConfig.PARAMS_KEY, strings[0]); - - StatLog.d(TAG, "body:" + strings[0]); - - if (headers != null && headers.size() > 0) { - reqHeaders = new Header[headers.size()]; - Set keys = headers.keySet(); - int index = 0; - for (final String mykey : keys) { - header = new Header() { - @Override - public String getName() { - return mykey; - } - - @Override - public String getValue() { - return headers.get(mykey); - } - - @Override - public HeaderElement[] getElements() throws ParseException { - return new HeaderElement[0]; - } - }; - reqHeaders[index++] = header; - } - - } - - - TcHttpClient.post(context, mHostUrl, reqHeaders, requestParams, "application/json", mTaskHandler ); - return null; - } - - void cancel() { - - TcHttpClient.cancle(mKey, true); - } - - private class PaJsonHttpResponseHandler extends AsyncHttpResponseHandler { - - public PaJsonHttpResponseHandler() { - } - - public PaJsonHttpResponseHandler(Looper looper) { - super(looper); - } - - public PaJsonHttpResponseHandler(boolean usePoolThread) { - super(usePoolThread); - } - - @Override - public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) { - - if (mUpLoadlistener != null) { - mUpLoadlistener.onSucess(); - } - - for (Header tmp : headers) { - StatLog.d(TAG, tmp.getName() + ":" + tmp.getValue()); - } - - StatLog.d(TAG, "response code: " + statusCode); - if (statusCode == HttpStatus.SC_OK) { - StatLog.d(TAG, "onSuccess"); - mCanContinue = false; - } else if (statusCode == HttpStatus.SC_PARTIAL_CONTENT) { - mCanContinue = true; - } - } - - @Override - public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) { - if (mUpLoadlistener != null) { - mUpLoadlistener.onFailure(); - } - cancel(); - } - - } - -} diff --git a/StatInterface/src/main/java/com/tamic/statInterface/statsdk/core/TcObserverPresenter.java b/StatInterface/src/main/java/com/tamic/statInterface/statsdk/core/TcObserverPresenter.java deleted file mode 100644 index f3aa6fa..0000000 --- a/StatInterface/src/main/java/com/tamic/statInterface/statsdk/core/TcObserverPresenter.java +++ /dev/null @@ -1,398 +0,0 @@ -package com.tamic.statInterface.statsdk.core; - -import android.app.ActivityManager; -import android.content.Context; -import android.text.TextUtils; -import android.util.Log; - - -import com.tamic.statInterface.statsdk.constants.StaticsConfig; -import com.tamic.statInterface.statsdk.db.helper.DataConstruct; -import com.tamic.statInterface.statsdk.presenter.TcDeblockObserver; -import com.tamic.statInterface.statsdk.presenter.TcNetworkObserver; -import com.tamic.statInterface.statsdk.presenter.TcScreenObserver; -import com.tamic.statInterface.statsdk.util.StatLog; - -import java.util.List; - -/** - * ObserverPresenter - * Created by Tamic on 2016-04-14. - */ -public class TcObserverPresenter implements TcNetworkObserver.INetworkListener, TcScreenObserver.IScreenListener, - TcDeblockObserver.IKeyguardListener { - - /** NetworkObserver */ - private TcNetworkObserver mNetworkObserver; - /** ScreenObserver */ - private TcScreenObserver mScreenObserver; - /** DeblockObserver */ - private TcDeblockObserver mKeyguardObserver; - /** isForeground */ - private boolean isForeground; - /** isInit */ - private boolean isInit; - /** PackageName */ - private String mPackageName; - /** isTopTask */ - private boolean isTopTask; - /** isScreenOff */ - private boolean isScreenOff; - /** isScreenLocked */ - private boolean isScreenLocked; - /** APP_STATUS_FOREGROUND */ - public static final char APP_STATUS_FOREGROUND = '0'; - /** APP_STATUS_BACKGROUND */ - public static final char APP_STATUS_BACKGROUND = '1'; - /** TAG */ - private static final String LOG_TAG = "TamicStat::ObserverPresenter"; - - private ScheduleListener scheduleListener; - - - public TcObserverPresenter(ScheduleListener listener) { - scheduleListener = listener; - } - - public void init(Context context ) { - if (!isInit) { - mPackageName = context.getPackageName(); - isTopTask = true; - isScreenOff = false; - isScreenLocked = false; - isForeground = true; - registerObserver(context); - isInit = true; - } - } - - /** - * app is Foreground - * - * @return 如果在前台则返回true,否则返回false - */ - public boolean isForeground() { - return isForeground; - } - - /** - * getApp Status - * - * @return 前后为“0”,后台为“1” - */ - public char getAppStatus() { - if (isForeground) { - return APP_STATUS_FOREGROUND; - } else { - return APP_STATUS_BACKGROUND; - } - } - - - /** - * OnStart - * - * @param aContext - * Context - */ - public void onStart(Context aContext) { - if (!isTopTask) { - Log.d(LOG_TAG, "onStart,false-->onForegroundChanged"); - isTopTask = true; - onForegroundChanged(aContext, true); - } - } - - /** - * OnPause - * - * @param aContext - * Context - */ - public void onPause(Context aContext) { - Log.d(LOG_TAG, "onPause"); - if (isTopTask) { - ActivityManager.RunningTaskInfo taskInfo = getRunningTaskInfo(aContext); - if (taskInfo != null && taskInfo.topActivity != null) { - String packageName = taskInfo.topActivity.getPackageName(); - if (!TextUtils.isEmpty(packageName)) { - if (!packageName.equals(mPackageName)) { - isTopTask = false; - StatLog.d(LOG_TAG, "onPause --> onForegroundChanged(false)"); - onForegroundChanged(aContext, false); - } - } - } - } - } - - /** - * OnStop - * - * @param aContext - * Context - */ - public void onStop(Context aContext) { - StatLog.d(LOG_TAG, "onStop"); - if (isTopTask) { - ActivityManager.RunningTaskInfo taskInfo = getRunningTaskInfo(aContext); - if (taskInfo != null && taskInfo.topActivity != null) { - String packageName = taskInfo.topActivity.getPackageName(); - if (!TextUtils.isEmpty(packageName)) { - if (!packageName.equals(mPackageName)) { - isTopTask = false; - StatLog.d(LOG_TAG, "onStop --> onForegroundChanged(false)"); - onForegroundChanged(aContext, false); - } - } - } - } - } - - - /** - * registerObserver - * @param aContext - * Context - */ - private void registerObserver(Context aContext) { - - if (mScreenObserver == null) { - mScreenObserver = new TcScreenObserver(aContext, this); - } - mScreenObserver.start(); - - if (mNetworkObserver == null) { - mNetworkObserver = new TcNetworkObserver(aContext, this); - } - mNetworkObserver.start(); - - if (mKeyguardObserver == null) { - mKeyguardObserver = new TcDeblockObserver(aContext, this); - } - mKeyguardObserver.start(); - } - - /** - * unregisterObserver - */ - private void unregisterObserver() { - - if (mScreenObserver != null) { - mScreenObserver.stop(); - } - - if (mKeyguardObserver != null) { - mKeyguardObserver.stop(); - } - - if (mNetworkObserver != null) { - mNetworkObserver.stop(); - } - - } - - - /** - * Destroy - */ - public void destroy() { - unregisterObserver(); - mScreenObserver = null; - mKeyguardObserver = null; - mNetworkObserver = null; - //mDateObserver = null; - isInit = false; - } - - /** - * 获取正在运行的TaskInfo - * - * @param aContext - * Context - * @return RunningTaskInfo - */ - private ActivityManager.RunningTaskInfo getRunningTaskInfo(Context aContext) { - ActivityManager manager = (ActivityManager) aContext.getSystemService(Context.ACTIVITY_SERVICE); - List taskList = manager.getRunningTasks(1); - if (taskList == null || taskList.isEmpty()) { - return null; - } else { - return taskList.get(0); - } - } - - /** - * 判断当前是否锁屏 - * - * @param aContext - * Context - * @return true locked, false otherwise - */ - private boolean isScreenLocked(Context aContext) { - android.app.KeyguardManager km = (android.app.KeyguardManager) aContext - .getSystemService(Context.KEYGUARD_SERVICE); - return km.inKeyguardRestrictedInputMode(); - } - - - /** - * 前后台转换 - * - * @param aContext - * Context - * @param aIsForeground - * 如果在前台则为true,否则为false - */ - private synchronized void onForegroundChanged(Context aContext, boolean aIsForeground) { - // 更新前后台状态 - isForeground = aIsForeground; - //前后台变换时访问report - reportData(aContext); - //记录前后台切换 - if (aIsForeground) { - if (StaticsConfig.DEBUG) { - Log.d(LOG_TAG, "onForeground true"); - } - // app唤醒 - DataConstruct.storeAppAction("3"); - //切前台时开始计时 - scheduleStart(); - - } else { - //切后台 - if (StaticsConfig.DEBUG) { - Log.d(LOG_TAG, "onForeground false"); - } - //切后台时数据上传 - TcStatSdk.getInstance(aContext).send(); - // 切后台停止计时 - scheduleStop(); - - } - } - - private void reportData(Context context) { - - TcStatSdk.getInstance(context).send(); - } - - private void scheduleStart() { - if (scheduleListener != null) { - scheduleListener.onStart(); - } - - } - - private void scheduleStop() { - if (scheduleListener != null) { - scheduleListener.onStop(); - } - - } - - private void scheduleReStart() { - if (scheduleListener != null) { - scheduleListener.onReStart(); - } - - } - - @Override - public void onNetworkConnected(Context aContext) { - StatLog.d(LOG_TAG, "onNetworkConnected"); - // 同步网络信息 - TcHeadrHandle.getHeader(aContext).setNetworkinfo(TcHeadrHandle.getNetWorkInfo(aContext)); - if (isForeground) { - StatLog.d(LOG_TAG, "onNetworkConnected send data"); - reportData(aContext); - scheduleReStart(); - } else { - scheduleStop(); - } - - } - - @Override - public void onNetworkUnConnected(Context aContext) { - StatLog.d(LOG_TAG, "onNetworkUnConnected"); - scheduleStop(); - - } - - @Override - public void onScreenOn(Context aContext) { - - StatLog.d(LOG_TAG, "onScreenOn"); - //Toast.makeText(aContext, "屏幕亮起", Toast.LENGTH_SHORT).show(); - if (isTopTask) { - if (isScreenOff) { - isScreenOff = false; - - if (isScreenLocked(aContext)) { //如果锁屏,则不作处理 - isScreenLocked = true; - } else { - StatLog.d(LOG_TAG, "onScreenOn-->onForegroundChanged(true)"); - isScreenLocked = false; - onForegroundChanged(aContext, true); - } - } - } - - } - - @Override - public void onScreenOff(Context aContext) { - - //屏幕关闭时,如果还在前台,屏幕之前打开,则肯定切换至后台 - StatLog.d(LOG_TAG, "onScreenOff"); - if (isTopTask) { - if (!isScreenOff) { - isScreenOff = true; - if (!isScreenLocked) { - StatLog.d(LOG_TAG, "onScreenOff-->onForegroundChanged(false)"); - onForegroundChanged(aContext, false); - } - } - } - - } - - @Override - public void onKeyguardGone(Context aContext) { - StatLog.d(LOG_TAG, "onKeyGuardGone"); - if (isTopTask) { - StatLog.d(LOG_TAG, "onKeyGuardGone foreground"); - //如果在前台,屏幕锁屏,则屏幕已打开 - if (isScreenLocked) { - isScreenLocked = false; - onForegroundChanged(aContext, true); - } - } - } - - /** - * IKeyguardListener - */ - public interface ScheduleListener { - - - /** 开始 - * - */ - void onStart(); - - /** - * - */ - void onStop(); - - - /** - * 结束 - */ - void onReStart(); - } - - -} diff --git a/StatInterface/src/main/java/com/tamic/statInterface/statsdk/core/TcStatInterface.java b/StatInterface/src/main/java/com/tamic/statInterface/statsdk/core/TcStatInterface.java deleted file mode 100644 index 74c936e..0000000 --- a/StatInterface/src/main/java/com/tamic/statInterface/statsdk/core/TcStatInterface.java +++ /dev/null @@ -1,234 +0,0 @@ -package com.tamic.statInterface.statsdk.core; - -import android.content.Context; - -import com.tamic.statInterface.statsdk.constants.NetConfig; - - -/** - * StatInterface - * Created by tamic on 2016-04-06. - */ -public final class TcStatInterface { - - /**实时发送*/ - protected static final int UPLOAD_POLICY_REALTIME = 0; - /**只在wifi下*/ - protected static final int UPLOAD_POLICY_WIFI_ONLY = 2; - /**批量上报 达到一定次数*/ - protected static final int UPLOAD_POLICY_BATCH = 3; - /**时间间隔*/ - protected static final int UPLOAD_POLICY_INTERVAL = 4; - /**开发者debug模式 调用就可以发送*/ - protected static final int UPLOAD_POLICY_DEVELOPMENT = 5; - /**每次启动 发送上次产生的数据*/ - protected static final int UPLOAD_POLICY_WHILE_INITIALIZE = 6; - - /** - * 上报策略模式 - */ - public enum UploadPolicy { - /**实时发送*/ - UPLOAD_POLICY_REALTIME, - /**只在wifi下*/ - UPLOAD_POLICY_WIFI_ONLY, - /**批量上报 达到一定次数*/ - UPLOAD_POLICY_BATCH, - /**时间间隔*/ - UPLOAD_POLICY_INTERVA, - /**开发者debug模式 调用就可以发送*/ - UPLOAD_POLICY_DEVELOPMENT, - /**每次启动 发送上次产生的数据*/ - UPLOAD_POLICY_WHILE_INITIALIZE - } - - /**实时发送*/ - public static final int UPLOAD_INTERVAL_REALTIME = 0; - /**1分钟*/ - public static final int UPLOAD_TIME_ONE = 1; - /**5分钟*/ - public static final int UPLOAD_TIME_THREAD = 3; - /**10分钟*/ - public static final int UPLOAD_TIME_TEN = 10; - /**20分钟*/ - public static final int UPLOAD_TIME_TWENTY = 20; - /**30分钟发送*/ - public static final int UPLOAD_TIME_THIRTY = 30; - /** - * 上报策略 - */ - protected static UploadPolicy uploadPolicy; - - private static int intervalRealtime = UPLOAD_TIME_THREAD; - - private static Context context; - /** - * private constructor - */ - private TcStatInterface() { - - } - - /** - * initialize - * @param aContext - * @param appId - * @param channel - */ - public static void initialize(Context aContext, int appId, String channel, String fileName) { - - context = aContext; - - TcStatSdk.getInstance(aContext).init(appId, channel, fileName); - - } - - /** - * 设置策略模式 - * @param policy - * 策略模式(实时模式下间隔时间无效) - * 目前默认为UPLOAD_POLICY_INTERVA模式 - * @param time - * 时间间隔(1 5 10 20 30分钟) - */ - public static void setUploadPolicy(UploadPolicy policy, int time) { - - if (policy == null) { - uploadPolicy = UploadPolicy.UPLOAD_POLICY_INTERVA; - return; - } - - if (time > 0 || time <= 60) { - intervalRealtime = time; - } - uploadPolicy = policy; - - } - - /** - * getIntervalRealtime - * @return intervalRealtime - */ - public static int getIntervalRealtime() { - return intervalRealtime; - } - - public static void setIntervalRealtime(int intervalRealtime) { - TcStatInterface.intervalRealtime = intervalRealtime; - } - - /** setUrl - * @param url - */ - public static void setUrl(String url) { - NetConfig.ONLINE_URL = url; - } - - /** - * record Page Start - * */ - public static void recordPageStart(Context context) { - - TcStatSdk.getInstance(context).recordPageStart(context); - - } - /** - * record Page End - */ - public static void recordPageEnd() { - - TcStatSdk.getInstance(context).recordPageEnd(); - - } - - /** - * record App Start - */ - public static void recordAppStart() { - - TcStatSdk.getInstance(context).recordAppStart(); - - - } - - /** - * 关闭APP - */ - public static void recordAppEnd() { - - TcStatSdk.getInstance(context).recordAppEnd(); - - - TcStatSdk.getInstance(context).release(); - } - - /** - * 上报数据 - * 非Debug模式无法直接调用,请先设置为UPLOAD_POLICY_DEVELOPMENT - */ - protected static void report() { - - - TcStatSdk.getInstance(context).send(); - - } - - /** - * 上报数据 - * 非Debug模式无法直接调用,请先设置为UPLOAD_POLICY_DEVELOPMENT - */ - public static void reportData() { - - - if (uploadPolicy != UploadPolicy.UPLOAD_POLICY_DEVELOPMENT) { - - throw new RuntimeException("call reportData(), you must will UploadPolicy set : UPLOAD_POLICY_DEVELOPMENT!"); - } - - report(); - - } - - - /** - * 加入page参数 - * @param k 业务名字 - * @param v 对应值 - */ - public static void onPageParameter(String k,String v) { - - TcStatSdk.getInstance(context).setPageParameter(k, v); - - } - - /** - * 初始化Event - */ - public static void initEvent(String eventName) { - - TcStatSdk.getInstance(context).initEvent(eventName); - - } - - - /** - * 加入自定义envent - * @param k 业务名字 - * @param v 对应值 - */ - public static void onEventParameter(String k,String v) { - - TcStatSdk.getInstance(context).setEventParameter(k, v); - - } - - /** - * onEvent - */ - public static void onEvent(String eventName, String k,String v) { - initEvent(eventName); - onEventParameter(k, v); - - } - -} diff --git a/StatInterface/src/main/java/com/tamic/statInterface/statsdk/core/TcStatSdk.java b/StatInterface/src/main/java/com/tamic/statInterface/statsdk/core/TcStatSdk.java deleted file mode 100644 index eccb900..0000000 --- a/StatInterface/src/main/java/com/tamic/statInterface/statsdk/core/TcStatSdk.java +++ /dev/null @@ -1,126 +0,0 @@ -package com.tamic.statInterface.statsdk.core; - -import android.content.Context; - - -/** - * StatSdk - * Created by Tamic on 2016-04-05. - */ -public class TcStatSdk { - - /** context */ - private Context mContext; - /** Instance */ - private static TcStatSdk sInstance; - - private static final String TAG = "TcStaInterface::StatSdk"; - - private TcStaticsManager staticsManager; - - /** - * getInstance - * - * @param aContext - * context - * @return 返回 TcStaticsManager - */ - protected static synchronized TcStatSdk getInstance(Context aContext) { - if (sInstance == null) { - sInstance = new TcStatSdk(aContext, new TcStaticsManagerImpl(aContext)); - } - return sInstance; - } - - /** - * constructor - * - * @param aContext - * context - */ - private TcStatSdk(Context aContext, TcStaticsManager aStaticsManager) { - mContext = aContext; - staticsManager = aStaticsManager; - - } - - protected void init(int appId, String channel, String fileName) { - - staticsManager.onInit(appId, channel, fileName); - - } - - protected void send() { - - staticsManager.onSend(); - } - - protected void store() { - - staticsManager.onStore(); - - } - - protected void upLoad() { - - staticsManager.onSend(); - } - - /** - * release - */ - protected void release() { - - staticsManager.onRelease(); - - } - - protected void recordPageEnd() { - - staticsManager.onRrecordPageEnd(); - - } - - protected void recordAppStart() { - - staticsManager.onRecordAppStart(); - - } - - protected void recordAppEnd() { - - staticsManager.onRrecordAppEnd(); - - } - - protected void recordPageStart(Context context) { - - staticsManager.onRecordPageStart(context); - - } - - protected void setPageParameter(String k, String v) { - - staticsManager.onPageParameter(k, v); - - } - - protected void initEvent(String envntName) { - - staticsManager.onInitEvent(envntName); - - } - - protected void setEventParameter(String k, String v) { - - staticsManager.onEventParameter(k, v); - - } - - protected void initPage(String pageId, String referPageId) { - - staticsManager.onInitPage(pageId, referPageId); - - } - -} diff --git a/StatInterface/src/main/java/com/tamic/statInterface/statsdk/core/TcStatiPollMgr.java b/StatInterface/src/main/java/com/tamic/statInterface/statsdk/core/TcStatiPollMgr.java deleted file mode 100644 index 99d7096..0000000 --- a/StatInterface/src/main/java/com/tamic/statInterface/statsdk/core/TcStatiPollMgr.java +++ /dev/null @@ -1,121 +0,0 @@ - -package com.tamic.statInterface.statsdk.core; - -import android.os.Handler; -import android.os.Looper; -import android.os.Message; -import android.text.format.DateUtils; -import android.text.format.Time; - -import com.tamic.statInterface.statsdk.constants.StaticsConfig; - -/** - * - * StatiPollMgr - * Created by Tamic on 2016-04-19. - */ -public class TcStatiPollMgr { - - /** DEBUG mode */ - private static final boolean DEBUG = StaticsConfig.DEBUG; - /** Log TAG */ - private static final String LOG_TAG = TcStatiPollMgr.class.getSimpleName(); - /** MSG_TIMEOUT */ - private static final int MSG_TIMEOUT = 1; - private TcStaticsManagerImpl staticsManagerImpl; - /** 心跳周期 */ - private long mCardiacCycle; - /** DefaultCycle */ - private long mDefaultCycle; - - /** - * Constructor - */ - public TcStatiPollMgr(TcStaticsManagerImpl staticsManager) { - staticsManagerImpl = staticsManager; - } - - /** - * start - * - * @param aCardiacCycle - * 心跳周期 - */ - public void start(long aCardiacCycle) { - mDefaultCycle = aCardiacCycle; - mCardiacCycle = aCardiacCycle; - checkDateChanging(); - stop(); - loop(); - } - - /** - * stop - */ - public void stop() { - sPrivateHandler.get().removeMessages(MSG_TIMEOUT); - } - - /** - * loop - */ - private void loop() { - Message msg = sPrivateHandler.get().obtainMessage(MSG_TIMEOUT, this); - sPrivateHandler.get().sendMessageDelayed(msg, mCardiacCycle); - } - - /** - * onTimeOut msg - */ - public void onTimeOut() { - staticsManagerImpl.onScheduleTimeOut(); - } - - /** - * checkDateChanging - */ - private void checkDateChanging() { - Time time = new Time(); - time.setToNow(); - int hour = time.hour; //24小时制 - int minute = time.minute; - if (hour == 23) { //SUPPRESS CHECKSTYLE - int cycle = 61 - minute; // SUPPRESS CHECKSTYLE 12:01访问 - long timeSchedule = cycle * DateUtils.MINUTE_IN_MILLIS; - if (timeSchedule < mCardiacCycle) { - mCardiacCycle = timeSchedule; - } - } else { - if (mCardiacCycle != mDefaultCycle) { - mCardiacCycle = mDefaultCycle; - } - } - } - - /** - * Handler - */ - private static final ThreadLocal sPrivateHandler = new ThreadLocal() { - @Override - protected Handler initialValue() { - return new Handler(Looper.getMainLooper()) { - - @Override - public void handleMessage(Message msg) { - switch (msg.what) { - case MSG_TIMEOUT: - TcStatiPollMgr schedule = (TcStatiPollMgr) msg.obj; - if (schedule != null) { - schedule.onTimeOut(); - schedule.checkDateChanging(); - schedule.loop(); - } - break; - default: - break; - } - } - }; - } - }; -} diff --git a/StatInterface/src/main/java/com/tamic/statInterface/statsdk/core/TcStaticsManager.java b/StatInterface/src/main/java/com/tamic/statInterface/statsdk/core/TcStaticsManager.java deleted file mode 100644 index f042c33..0000000 --- a/StatInterface/src/main/java/com/tamic/statInterface/statsdk/core/TcStaticsManager.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.tamic.statInterface.statsdk.core; - -import android.content.Context; - -/** - * Created by Tamic on 2016-04-05. - * StaticsManager - */ -public interface TcStaticsManager { - - boolean onInit(int appId, String channel, String fileName); - - void onSend(); - - void onStore(); - - void onRelease(); - - void onRecordAppStart(); - - void onRrecordPageEnd(); - - void onRecordPageStart(Context context); - - void onRrecordAppEnd(); - - void onInitPage(String... strings); - - void onPageParameter(String... strings); - - void onInitEvent(String eventName); - - void onEventParameter(String... strings); - - -} diff --git a/StatInterface/src/main/java/com/tamic/statInterface/statsdk/core/TcStaticsManagerImpl.java b/StatInterface/src/main/java/com/tamic/statInterface/statsdk/core/TcStaticsManagerImpl.java deleted file mode 100644 index 090a950..0000000 --- a/StatInterface/src/main/java/com/tamic/statInterface/statsdk/core/TcStaticsManagerImpl.java +++ /dev/null @@ -1,315 +0,0 @@ -package com.tamic.statInterface.statsdk.core; - -import android.content.Context; -import android.text.TextUtils; - -import com.alibaba.fastjson.JSON; -import com.tamic.statInterface.statsdk.constants.StaticsConfig; -import com.tamic.statInterface.statsdk.db.helper.DataConstruct; -import com.tamic.statInterface.statsdk.db.helper.StaticsAgent; -import com.tamic.statInterface.statsdk.model.DataBlock; -import com.tamic.statInterface.statsdk.service.Platform; -import com.tamic.statInterface.statsdk.util.JsonUtil; -import com.tamic.statInterface.statsdk.util.NetworkUtil; -import com.tamic.statInterface.statsdk.util.StatLog; - -import java.io.InputStream; -import java.util.HashMap; - -import cz.msebera.android.httpclient.util.EncodingUtils; - -import static com.tamic.statInterface.statsdk.core.TcNetEngine.TAG; - - -/** - * StaticsManagerImpl core - * Created by LIUYONGKUI726 on 2016-03-24. - */ -public class TcStaticsManagerImpl implements TcStaticsManager, TcObserverPresenter.ScheduleListener { - /** context */ - private Context mContext; - /** sInstance */ - private static TcStaticsManager sInstance; - - private static TcObserverPresenter paObserverPresenter; - - private StaticsListener eventInterface; - - private TcStatiPollMgr statiPollMgr; - - HashMap pageIdMaps = new HashMap(); - /** Log TAG */ - private static final String LOG_TAG = TcStatiPollMgr.class.getSimpleName(); - - public TcStaticsManagerImpl(Context mContext) { - this.mContext = mContext; - } - - @Override - public boolean onInit(int appId, String channel, String fileName) { - - // init ObserverPresenter - paObserverPresenter = new TcObserverPresenter(this); - - // init StaticsAgent - StaticsAgent.init(mContext); - - // load pageIdMaps - pageIdMaps = getStatIdMaps(fileName); - - // init StatiPoll - statiPollMgr = new TcStatiPollMgr(this); - // init Header - return initHeader(appId, channel); - } - - @Override - public void onSend() { - // report data to server - Platform.get().execute(new Runnable() { - @Override - public void run() { - DataBlock dataBlock = StaticsAgent.getDataBlock(); - - if (dataBlock.getApp_action().isEmpty() && - dataBlock.getEvent().isEmpty() && - dataBlock.getPage().isEmpty()) { - return; - } - StatLog.d(TAG, "TcStatfacr >> report is Start"); - TcUpLoadManager.getInstance(mContext).report(JsonUtil.toJSONString(dataBlock)); - } - }); - - } - - @Override - public void onStore() { - DataConstruct.storeEvent(); - DataConstruct.storePage(); - } - - @Override - public void onRelease() { - if (paObserverPresenter != null) { - paObserverPresenter.destroy(); - } - - stopSchedule(); - - } - - @Override - public void onRecordAppStart() { - //send - onSend(); - // store appAction - DataConstruct.storeAppAction("1"); - } - - @Override - public void onRrecordPageEnd() { - DataConstruct.storeEvent(); - DataConstruct.storePage(); - if (paObserverPresenter != null) { - paObserverPresenter.onStop(mContext); - } - stopSchedule(); - } - - @Override - public void onRecordPageStart(Context context) { - - if (context == null) { - return; - } - - //开始计时 - startSchedule(); - - - String pageId = checkValidId(context.getClass().getSimpleName()); - if (pageId == null) { - pageId = context.getClass().getSimpleName(); - } - - // init page - onInitPage(pageId, null); - - if (paObserverPresenter != null) { - paObserverPresenter.init(mContext); - } - - if (paObserverPresenter != null) { - paObserverPresenter.onStart(mContext); - } - } - - - @Override - public void onRrecordAppEnd() { - - //recard APP exit - DataConstruct.storeAppAction("2"); - - onSend(); - - onRelease(); - } - - @Override - public void onInitPage(String... strings) { - - DataConstruct.initPage(mContext, eventInterface, strings[0], strings[1]); - - } - - @Override - public void onPageParameter(String... strings) { - - DataConstruct.initPageParameter(strings[0], strings[1]); - - } - - - @Override - public void onInitEvent(String eventName) { - - DataConstruct.initEvent(eventInterface, eventName); - } - - @Override - public void onEventParameter(String... strings) { - - DataConstruct.onEvent(strings[0], strings[1]); - - } - - /** - * init header - */ - private boolean initHeader(int appId, String channel) { - - - if (!TcHeadrHandle.isInit()) { - return TcHeadrHandle.initHeader(mContext, appId, channel); - } - - return false; - - } - - /** - * onScheduleTimeOut - */ - void onScheduleTimeOut() { - - StatLog.d(LOG_TAG, "onScheduleTimeOut is sendData"); - - onSend(); - } - - /** - * startSchedule - */ - public void startSchedule() { - // if debug time is 5 min - if (StaticsConfig.DEBUG && - TcStatInterface.uploadPolicy == TcStatInterface.UploadPolicy.UPLOAD_POLICY_DEVELOPMENT) { - statiPollMgr.start(5* 1000); - StatLog.d(LOG_TAG, "Schedule is start"); - } else { - if (NetworkUtil.isWifi(mContext)) { - statiPollMgr.start(TcStatInterface.getIntervalRealtime() * 60 *1000); - } else { - statiPollMgr.start(TcStatInterface.UPLOAD_TIME_THIRTY * 60 *1000); - } - - } - } - - /** checkValidId - * @param name activitiyname - * @return pageId - */ - private String checkValidId(String name) { - if (TextUtils.isEmpty(name)) { - return null; - } - if (name.length() <= 0) { - return null; - } - - return getPageId(name); - } - - - /** getPageId - * @param clazz - * @return - */ - private String getPageId(String clazz) { - if (mContext == null) { - return null; - } - return pageIdMaps.get(clazz); - } - - /** - * stop Schedule - */ - public void stopSchedule() { - - StatLog.d(LOG_TAG, "stopSchedule()"); - - statiPollMgr.stop(); - } - - @Override - public void onStart() { - StatLog.d(LOG_TAG, "startSchedule"); - - startSchedule(); - - } - - @Override - public void onStop() { - - stopSchedule(); - } - - @Override - public void onReStart() { - // stopSchedule - stopSchedule(); - // startSchedule - startSchedule(); - } - - - public HashMap getStatIdMaps(String jsonName) { - - - HashMap map = null; - if (getFromAsset(jsonName) != null) { - map = (HashMap) JSON.parseObject(getFromAsset("stat_id.json"), HashMap.class); - } - return map; - } - - public String getFromAsset(String fileName){ - String result=""; - try{ - InputStream in = mContext.getResources().getAssets().open(fileName); - int length = in.available(); - byte [] buffer = new byte[length]; - in.read(buffer); - result = EncodingUtils.getString(buffer, "UTF-8"); - } - catch(Exception e){ - e.printStackTrace(); - } - return result; - } -} diff --git a/StatInterface/src/main/java/com/tamic/statInterface/statsdk/core/TcUpLoadManager.java b/StatInterface/src/main/java/com/tamic/statInterface/statsdk/core/TcUpLoadManager.java deleted file mode 100644 index 5e7e1d3..0000000 --- a/StatInterface/src/main/java/com/tamic/statInterface/statsdk/core/TcUpLoadManager.java +++ /dev/null @@ -1,167 +0,0 @@ -package com.tamic.statInterface.statsdk.core; - -import android.content.Context; -import android.text.TextUtils; - - -import com.tamic.statInterface.statsdk.constants.NetConfig; -import com.tamic.statInterface.statsdk.db.helper.StaticsAgent; -import com.tamic.statInterface.statsdk.http.TcHttpClient; -import com.tamic.statInterface.statsdk.service.Platform; -import com.tamic.statInterface.statsdk.util.JsonUtil; -import com.tamic.statInterface.statsdk.util.NetworkUtil; -import com.tamic.statInterface.statsdk.util.StatLog; - -import java.util.concurrent.atomic.AtomicReference; - -/** - * Stat UpLoadManager - * Created by Tamic on 2016-03-24. - */ -public class TcUpLoadManager implements IUpLoadlistener { - - - /** - * context - */ - private Context mContext; - /** - * http client - */ - private TcHttpClient mHttpClient; - /** - * UpLoadManager - */ - private static TcUpLoadManager sInstance; - - private Boolean isRunning = false; - - private AtomicReference atomic; - - private TcNetEngine netEngine; - /** - * Log TAG - */ - private static final String TAG = TcNetEngine.class.getSimpleName(); - - /** - * getInstance - * - * @param aContext context - * @return UpLoadManager - */ - public static synchronized TcUpLoadManager getInstance(Context aContext) { - if (sInstance == null) { - sInstance = new TcUpLoadManager(aContext); - } - return sInstance; - } - - /** - * constructor - * - * @param aContext context - */ - private TcUpLoadManager(Context aContext) { - mContext = aContext; - init(); - } - - /** - * init - */ - private void init() { - mHttpClient = getHttpclient(); - atomic = new AtomicReference<>(); - netEngine = new TcNetEngine(mContext, this); - } - - - /** - * report - */ - public void report(String jsonString) { - - if (!NetworkUtil.isNetworkAvailable(mContext)) { - return; - } - - if (TextUtils.isEmpty(jsonString)) { - return; - } - //netEngine.setHttpClient(getHttpclient()); - atomic.set(netEngine); - atomic.getAndSet(netEngine).start(jsonString); - } - - /** - * cancle - */ - public void cancle() { - - if (atomic.get() != null) { - atomic.get().cancel(); - - } - - } - - - /** - * get http client - * - * @return http client - */ - public TcHttpClient getHttpclient() { - if (mHttpClient == null) { - // HttpClient - mHttpClient = new TcHttpClient(); - mHttpClient.setTimeOut(NetConfig.TIME_OUT); - } - return mHttpClient; - - } - - - @Override - public void onStart() { - - isRunning = true; - } - - @Override - public void onUpLoad() { - - isRunning = true; - } - - @Override - public void onSucess() { - - isRunning = false; - // delete data - StatLog.d(TAG, "DELETE :StaticsAgent.deleteTable()"); - // delete data - Platform.get().execute(new Runnable() { - @Override - public void run() { - StaticsAgent.deleteData(); - StatLog.d(TAG, "delete after :>>>>>>" + JsonUtil.toJSONString(StaticsAgent.getDataBlock())); - } - }); - - } - - @Override - public void onFailure() { - - isRunning = false; - - } - - @Override - public void onCancell() { - - isRunning = false; - } -} diff --git a/StatInterface/src/main/java/com/tamic/statInterface/statsdk/core/TcUploadCoreReceiver.java b/StatInterface/src/main/java/com/tamic/statInterface/statsdk/core/TcUploadCoreReceiver.java deleted file mode 100644 index 15c4bf0..0000000 --- a/StatInterface/src/main/java/com/tamic/statInterface/statsdk/core/TcUploadCoreReceiver.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.tamic.statInterface.statsdk.core; - -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.Intent; -import android.text.TextUtils; -import android.util.Log; -import android.widget.Toast; - -/** - * - * 轮询广播 - * Created by LIUYONGKUI726 on 2016-04-12. - */ -public class TcUploadCoreReceiver extends BroadcastReceiver { - - public static final String REPORT_ACTION = "action.com.pinganfang.base.send_report"; - - private static final String TAG = "TcUploadCoreReceiver"; - - @Override - public void onReceive(Context context, Intent intent) { - Log.d(TAG, "pollSever is started"); - - if (context == null || intent ==null ) { - return; - } - - if (TextUtils.equals(intent.getAction(), REPORT_ACTION)) { - - - Toast.makeText(context, "send statData", Toast.LENGTH_LONG).show(); - - //发送数据 -// TcStatSdk.getInstance(context).send(JsonUtil.toJSONString(StaticsAgent.getDataBlock())); - } - - - - } -} diff --git a/StatInterface/src/main/java/com/tamic/statInterface/statsdk/db/Customer.java b/StatInterface/src/main/java/com/tamic/statInterface/statsdk/db/Customer.java deleted file mode 100644 index f58019e..0000000 --- a/StatInterface/src/main/java/com/tamic/statInterface/statsdk/db/Customer.java +++ /dev/null @@ -1,88 +0,0 @@ -package com.tamic.statInterface.statsdk.db; - -import java.util.List; - -import de.greenrobot.dao.DaoException; - -// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. Enable "keep" sections if you want to edit. - -/** - * Entity mapped to table "CUSTOMER". - */ -public class Customer { - - private Long id; - /** Not-null value. */ - private String name; - - /** Used to resolve relations */ - private transient DaoSession daoSession; - - /** Used for active entity operations. */ - private transient CustomerDao myDao; - - public Customer() { - } - - public Customer(Long id) { - this.id = id; - } - - public Customer(Long id, String name) { - this.id = id; - this.name = name; - } - - /** called by internal mechanisms, do not call yourself. */ - public void __setDaoSession(DaoSession daoSession) { - this.daoSession = daoSession; - myDao = daoSession != null ? daoSession.getCustomerDao() : null; - } - - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - /** Not-null value. */ - public String getName() { - return name; - } - - /** Not-null value; ensure this value is available before it is saved to the database. */ - public void setName(String name) { - this.name = name; - } - - - - - - /** Convenient call for {@link AbstractDao#delete(Object)}. Entity must attached to an entity context. */ - public void delete() { - if (myDao == null) { - throw new DaoException("Entity is detached from DAO context"); - } - myDao.delete(this); - } - - /** Convenient call for {@link AbstractDao#update(Object)}. Entity must attached to an entity context. */ - public void update() { - if (myDao == null) { - throw new DaoException("Entity is detached from DAO context"); - } - myDao.update(this); - } - - /** Convenient call for {@link AbstractDao#refresh(Object)}. Entity must attached to an entity context. */ - public void refresh() { - if (myDao == null) { - throw new DaoException("Entity is detached from DAO context"); - } - myDao.refresh(this); - } - -} diff --git a/StatInterface/src/main/java/com/tamic/statInterface/statsdk/db/CustomerDao.java b/StatInterface/src/main/java/com/tamic/statInterface/statsdk/db/CustomerDao.java deleted file mode 100644 index 45c6d5b..0000000 --- a/StatInterface/src/main/java/com/tamic/statInterface/statsdk/db/CustomerDao.java +++ /dev/null @@ -1,119 +0,0 @@ -package com.tamic.statInterface.statsdk.db; - -import android.database.Cursor; -import android.database.sqlite.SQLiteDatabase; -import android.database.sqlite.SQLiteStatement; - -import de.greenrobot.dao.AbstractDao; -import de.greenrobot.dao.Property; -import de.greenrobot.dao.internal.DaoConfig; - -// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. - -/** - * DAO for table "CUSTOMER". -*/ -public class CustomerDao extends AbstractDao { - - public static final String TABLENAME = "CUSTOMER"; - - /** - * Properties of entity Customer.
- * Can be used for QueryBuilder and for referencing column names. - */ - public static class Properties { - public final static Property Id = new Property(0, Long.class, "id", true, "_id"); - public final static Property Name = new Property(1, String.class, "name", false, "NAME"); - }; - - private DaoSession daoSession; - - - public CustomerDao(DaoConfig config) { - super(config); - } - - public CustomerDao(DaoConfig config, DaoSession daoSession) { - super(config, daoSession); - this.daoSession = daoSession; - } - - /** Creates the underlying database table. */ - public static void createTable(SQLiteDatabase db, boolean ifNotExists) { - String constraint = ifNotExists? "IF NOT EXISTS ": ""; - db.execSQL("CREATE TABLE " + constraint + "\"CUSTOMER\" (" + // - "\"_id\" INTEGER PRIMARY KEY ," + // 0: id - "\"NAME\" TEXT NOT NULL );"); // 1: name - } - - /** Drops the underlying database table. */ - public static void dropTable(SQLiteDatabase db, boolean ifExists) { - String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"CUSTOMER\""; - db.execSQL(sql); - } - - /** @inheritdoc */ - @Override - protected void bindValues(SQLiteStatement stmt, Customer entity) { - stmt.clearBindings(); - - Long id = entity.getId(); - if (id != null) { - stmt.bindLong(1, id); - } - stmt.bindString(2, entity.getName()); - } - - @Override - protected void attachEntity(Customer entity) { - super.attachEntity(entity); - entity.__setDaoSession(daoSession); - } - - /** @inheritdoc */ - @Override - public Long readKey(Cursor cursor, int offset) { - return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0); - } - - /** @inheritdoc */ - @Override - public Customer readEntity(Cursor cursor, int offset) { - Customer entity = new Customer( // - cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id - cursor.getString(offset + 1) // name - ); - return entity; - } - - /** @inheritdoc */ - @Override - public void readEntity(Cursor cursor, Customer entity, int offset) { - entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); - entity.setName(cursor.getString(offset + 1)); - } - - /** @inheritdoc */ - @Override - protected Long updateKeyAfterInsert(Customer entity, long rowId) { - entity.setId(rowId); - return rowId; - } - - /** @inheritdoc */ - @Override - public Long getKey(Customer entity) { - if(entity != null) { - return entity.getId(); - } else { - return null; - } - } - - /** @inheritdoc */ - @Override - protected boolean isEntityUpdateable() { - return true; - } - -} diff --git a/StatInterface/src/main/java/com/tamic/statInterface/statsdk/db/DaoMaster.java b/StatInterface/src/main/java/com/tamic/statInterface/statsdk/db/DaoMaster.java deleted file mode 100644 index 87d76e8..0000000 --- a/StatInterface/src/main/java/com/tamic/statInterface/statsdk/db/DaoMaster.java +++ /dev/null @@ -1,73 +0,0 @@ -package com.tamic.statInterface.statsdk.db; - -import android.content.Context; -import android.database.sqlite.SQLiteDatabase; -import android.database.sqlite.SQLiteDatabase.CursorFactory; -import android.database.sqlite.SQLiteOpenHelper; -import android.util.Log; - -import de.greenrobot.dao.AbstractDaoMaster; -import de.greenrobot.dao.identityscope.IdentityScopeType; - -// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. - -/** - * Master of DAO (schema version 1000): knows all DAOs. -*/ -public class DaoMaster extends AbstractDaoMaster { - public static final int SCHEMA_VERSION = 1000; - - /** Creates underlying database table using DAOs. */ - public static void createAllTables(SQLiteDatabase db, boolean ifNotExists) { - TcNoteDao.createTable(db, ifNotExists); - CustomerDao.createTable(db, ifNotExists); - } - - /** Drops underlying database table using DAOs. */ - public static void dropAllTables(SQLiteDatabase db, boolean ifExists) { - TcNoteDao.dropTable(db, ifExists); - CustomerDao.dropTable(db, ifExists); - } - - public static abstract class OpenHelper extends SQLiteOpenHelper { - - public OpenHelper(Context context, String name, CursorFactory factory) { - super(context, name, factory, SCHEMA_VERSION); - } - - @Override - public void onCreate(SQLiteDatabase db) { - Log.i("greenDAO", "Creating tables for schema version " + SCHEMA_VERSION); - createAllTables(db, false); - } - } - - /** WARNING: Drops all table on Upgrade! Use only during development. */ - public static class DevOpenHelper extends OpenHelper { - public DevOpenHelper(Context context, String name, CursorFactory factory) { - super(context, name, factory); - } - - @Override - public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { - Log.i("greenDAO", "Upgrading schema from version " + oldVersion + " to " + newVersion + " by dropping all tables"); - dropAllTables(db, true); - onCreate(db); - } - } - - public DaoMaster(SQLiteDatabase db) { - super(db, SCHEMA_VERSION); - registerDaoClass(TcNoteDao.class); - registerDaoClass(CustomerDao.class); - } - - public DaoSession newSession() { - return new DaoSession(db, IdentityScopeType.Session, daoConfigMap); - } - - public DaoSession newSession(IdentityScopeType type) { - return new DaoSession(db, type, daoConfigMap); - } - -} diff --git a/StatInterface/src/main/java/com/tamic/statInterface/statsdk/db/DaoSession.java b/StatInterface/src/main/java/com/tamic/statInterface/statsdk/db/DaoSession.java deleted file mode 100644 index b236acf..0000000 --- a/StatInterface/src/main/java/com/tamic/statInterface/statsdk/db/DaoSession.java +++ /dev/null @@ -1,61 +0,0 @@ -package com.tamic.statInterface.statsdk .db; - -import android.database.sqlite.SQLiteDatabase; - -import java.util.Map; - -import de.greenrobot.dao.AbstractDao; -import de.greenrobot.dao.AbstractDaoSession; -import de.greenrobot.dao.identityscope.IdentityScopeType; -import de.greenrobot.dao.internal.DaoConfig; - -// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. - -/** - * {@inheritDoc} - * - * @see AbstractDaoSession - */ -public class DaoSession extends AbstractDaoSession { - - private final DaoConfig paNoteDaoConfig ; - private final DaoConfig customerDaoConfig; - - private final TcNoteDao paNoteDao ; - private final CustomerDao customerDao; - - - public DaoSession(SQLiteDatabase db, IdentityScopeType type, Map>, DaoConfig> - daoConfigMap) { - super(db); - paNoteDaoConfig = daoConfigMap.get(TcNoteDao.class).clone(); - paNoteDaoConfig.initIdentityScope(type); - - - customerDaoConfig = daoConfigMap.get(CustomerDao.class).clone(); - customerDaoConfig.initIdentityScope(type); - - - paNoteDao = new TcNoteDao(paNoteDaoConfig,this); - customerDao = new CustomerDao(customerDaoConfig, this); - - registerDao(TcNote.class,paNoteDao); - registerDao(Customer.class, customerDao); - } - - public void clear() { - paNoteDaoConfig.getIdentityScope().clear(); - customerDaoConfig.getIdentityScope().clear(); - } - - - - public TcNoteDao getPaNoteDao(){ - return paNoteDao ; - } - - public CustomerDao getCustomerDao() { - return customerDao; - } - -} diff --git a/StatInterface/src/main/java/com/tamic/statInterface/statsdk/db/TcNote.java b/StatInterface/src/main/java/com/tamic/statInterface/statsdk/db/TcNote.java deleted file mode 100644 index fdb4e3a..0000000 --- a/StatInterface/src/main/java/com/tamic/statInterface/statsdk/db/TcNote.java +++ /dev/null @@ -1,69 +0,0 @@ -package com.tamic.statInterface.statsdk.db; - -// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. Enable "keep" sections if you want to edit. -/** - * Entity mapped to table "Stact_NOTE". - */ -public class TcNote { - - private Long id; - /** Not-null value. */ - private String firstcloumn; - /** Not-null value. */ - private String secondcloumn; - /** Not-null value. */ - private String thirdcloumn; - - public TcNote() { - } - - public TcNote(Long id) { - this.id = id; - } - - public TcNote(Long id, String firstcloumn, String secondcloumn, String thirdcloumn) { - this.id = id; - this.firstcloumn = firstcloumn; - this.secondcloumn = secondcloumn; - this.thirdcloumn = thirdcloumn; - } - - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - /** Not-null value. */ - public String getFirstcloumn() { - return firstcloumn; - } - - /** Not-null value; ensure this value is available before it is saved to the database. */ - public void setFirstcloumn(String firstcloumn) { - this.firstcloumn = firstcloumn; - } - - /** Not-null value. */ - public String getSecondcloumn() { - return secondcloumn; - } - - /** Not-null value; ensure this value is available before it is saved to the database. */ - public void setSecondcloumn(String secondcloumn) { - this.secondcloumn = secondcloumn; - } - - /** Not-null value. */ - public String getThirdcloumn() { - return thirdcloumn; - } - - /** Not-null value; ensure this value is available before it is saved to the database. */ - public void setThirdcloumn(String thirdcloumn) { - this.thirdcloumn = thirdcloumn; - } - -} diff --git a/StatInterface/src/main/java/com/tamic/statInterface/statsdk/db/TcNoteDao.java b/StatInterface/src/main/java/com/tamic/statInterface/statsdk/db/TcNoteDao.java deleted file mode 100644 index 815b190..0000000 --- a/StatInterface/src/main/java/com/tamic/statInterface/statsdk/db/TcNoteDao.java +++ /dev/null @@ -1,122 +0,0 @@ -package com.tamic.statInterface.statsdk.db; - -import android.database.Cursor; -import android.database.sqlite.SQLiteDatabase; -import android.database.sqlite.SQLiteStatement; - -import com.tamic.statInterface.statsdk.constants.StaticsConfig; - -import de.greenrobot.dao.AbstractDao; -import de.greenrobot.dao.Property; -import de.greenrobot.dao.internal.DaoConfig; - -// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. - -/** - * DAO for table "PA_NOTE". -*/ -public class TcNoteDao extends AbstractDao { - - public static final String TABLENAME = StaticsConfig.SDK_TABLE_NAME; - - - /** - * Properties of entity TcNote.
- * Can be used for QueryBuilder and for referencing column names. - */ - public static class Properties { - public final static Property Id = new Property(0, Long.class, "id", true, "_id"); - public final static Property appActionInfo = new Property(1, String.class, StaticsConfig.APPACTION_INFO, false, "FIRSTCLOUMN"); - public final static Property pageInfo = new Property(2, String.class, StaticsConfig.PAGE_INFO, false, "SECONDCLOUMN"); - public final static Property enventInfo = new Property(3, String.class, StaticsConfig.ENVENT_INFO, false, "THIRDCLOUMN"); - } - - public TcNoteDao(DaoConfig config) { - super(config); - } - - public TcNoteDao(DaoConfig config, DaoSession daoSession) { - super(config, daoSession); - } - - /** Creates the underlying database table. */ - public static void createTable(SQLiteDatabase db, boolean ifNotExists) { - String constraint = ifNotExists? "IF NOT EXISTS ": ""; - db.execSQL("CREATE TABLE " + constraint + TABLENAME + "(" + // - "\"_id\" INTEGER PRIMARY KEY ," + // 0: id - "\"FIRSTCLOUMN\" TEXT NOT NULL ," + // 1: firstcloumn - "\"SECONDCLOUMN\" TEXT NOT NULL ," + // 2: secondcloumn - "\"THIRDCLOUMN\" TEXT NOT NULL );"); // 3: thirdcloumn - } - - /** Drops the underlying database table. */ - public static void dropTable(SQLiteDatabase db, boolean ifExists) { - String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + TABLENAME; - db.execSQL(sql); - } - - /** @inheritdoc */ - @Override - protected void bindValues(SQLiteStatement stmt, TcNote entity) { - stmt.clearBindings(); - - Long id = entity.getId(); - if (id != null) { - stmt.bindLong(1, id); - } - stmt.bindString(2, entity.getFirstcloumn()); - stmt.bindString(3, entity.getSecondcloumn()); - stmt.bindString(4, entity.getThirdcloumn()); - } - - /** @inheritdoc */ - @Override - public Long readKey(Cursor cursor, int offset) { - return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0); - } - - /** @inheritdoc */ - @Override - public TcNote readEntity(Cursor cursor, int offset) { - TcNote entity = new TcNote( // - cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id - cursor.getString(offset + 1), // firstcloumn - cursor.getString(offset + 2), // secondcloumn - cursor.getString(offset + 3) // thirdcloumn - ); - return entity; - } - - /** @inheritdoc */ - @Override - public void readEntity(Cursor cursor, TcNote entity, int offset) { - entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); - entity.setFirstcloumn(cursor.getString(offset + 1)); - entity.setSecondcloumn(cursor.getString(offset + 2)); - entity.setThirdcloumn(cursor.getString(offset + 3)); - } - - /** @inheritdoc */ - @Override - protected Long updateKeyAfterInsert(TcNote entity, long rowId) { - entity.setId(rowId); - return rowId; - } - - /** @inheritdoc */ - @Override - public Long getKey(TcNote entity) { - if(entity != null) { - return entity.getId(); - } else { - return null; - } - } - - /** @inheritdoc */ - @Override - protected boolean isEntityUpdateable() { - return true; - } - -} diff --git a/StatInterface/src/main/java/com/tamic/statInterface/statsdk/db/helper/DataConstruct.java b/StatInterface/src/main/java/com/tamic/statInterface/statsdk/db/helper/DataConstruct.java deleted file mode 100644 index 845bc8f..0000000 --- a/StatInterface/src/main/java/com/tamic/statInterface/statsdk/db/helper/DataConstruct.java +++ /dev/null @@ -1,159 +0,0 @@ -package com.tamic.statInterface.statsdk.db.helper; - -import android.app.Activity; -import android.content.Context; -import android.text.TextUtils; - -import com.tamic.statInterface.statsdk.core.StaticsListener; -import com.tamic.statInterface.statsdk.model.AppAction; -import com.tamic.statInterface.statsdk.model.Event; -import com.tamic.statInterface.statsdk.model.KeyValueBean; -import com.tamic.statInterface.statsdk.model.Page; -import com.tamic.statInterface.statsdk.sp.SharedPreferencesHelper; -import com.tamic.statInterface.statsdk.util.DateUtil; - -import java.util.ArrayList; - -/** - * DataConstruct - * Created by tamic on 2016-04-11. - */ -public class DataConstruct { - - private static Event event = null; - private static ArrayList parameter = new ArrayList<>() ; - - private static Page page = null ; - private static ArrayList pageParameter = new ArrayList<>() ; - - private static AppAction appAction = null ; - - private static StaticsListener staticsListener; - - private static String pageId; - - private static String referPageId; - - private static String REFERPAGE_ID = "referPage_Id"; - - private DataConstruct() { - } - - - - /** - * initEvent - * @param eventInterface - * @param event_name - */ - public static void initEvent(StaticsListener eventInterface, String event_name){ - event = new Event(); - event.setPage_id(pageId); - event.setReferer_page_id(referPageId); - event.setEvent_name(event_name); - event.setAction_time(DateUtil.getDateString(System.currentTimeMillis(), "yyyy-MM-dd HH:mm:ss")); - } - - /** - * onEvent - * @param businessName - * @param businessValue - */ - public static void onEvent(String businessName,String businessValue){ - parameter.add(new KeyValueBean(businessName, businessValue)); - if(event == null){ - throw new RuntimeException("you must call initEvent before onEvent!"); - } - event.setParameter(parameter); - } - - /** - * storeEvent - * Activity destory call - */ - public static void storeEvent(){ - if(event == null){ - return; - } - StaticsAgent.storeObject(event); - } - - - /** - * initPage - * @param eventInterface - */ - public static void initPage(Context context, StaticsListener eventInterface, String page_Id, String referPage_Id){ - staticsListener = eventInterface; - pageId = page_Id; - recardPageId(context, page_Id); - if (TextUtils.isEmpty(referPage_Id)){ - referPageId = getReferPageId(context); - } else { - referPageId = referPage_Id; - } - page = new Page(); - page.setPage_start_time(DateUtil.getDateString(System.currentTimeMillis(), "yyyy-MM-dd HH:mm:ss")); - page.setReferer_page_id(referPageId); - page.setPage_id(pageId); - } - - - public static void initPageParameter(String name,String value){ - pageParameter.add(new KeyValueBean(name, value)); - page.setParameter(pageParameter); - } - - - /** - * storePage - */ - public static void storePage(){ - if(page == null){ - throw new RuntimeException("you must init before storePage"); - } - page.setPage_end_time(DateUtil.getDateString(System.currentTimeMillis(), "yyyy-MM-dd HH:mm:ss")); - StaticsAgent.storeObject(page); - } - - - /** - * storeAppAction - * @param type 1 app打开 2app关闭 3唤醒 - */ - public static void storeAppAction(String type){ - appAction = new AppAction(); - appAction.setAction_time(DateUtil.getDateString(System.currentTimeMillis(), "yyyy-MM-dd HH:mm:ss")); - appAction.setApp_action_type(type); - StaticsAgent.storeObject(appAction); - } - - - /** - * deleteData - */ - public static void deleteData(){ - StaticsAgent.deleteData(); - } - - /** - * recardPageId - * @param context - * @param page_Id - */ - private static void recardPageId (Context context, String page_Id) { - SharedPreferencesHelper.getInstance(context).putString(REFERPAGE_ID, page_Id); - } - - /** - * get ReferPageId - * @param context - * @return - */ - private static String getReferPageId (Context context) { - return SharedPreferencesHelper.getInstance(context).getString(REFERPAGE_ID); - } - - - -} diff --git a/StatInterface/src/main/java/com/tamic/statInterface/statsdk/db/helper/NoteDaoHelper.java b/StatInterface/src/main/java/com/tamic/statInterface/statsdk/db/helper/NoteDaoHelper.java deleted file mode 100644 index 01d3f48..0000000 --- a/StatInterface/src/main/java/com/tamic/statInterface/statsdk/db/helper/NoteDaoHelper.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.tamic.statInterface.statsdk.db.helper; - -import android.content.Context; -import android.database.sqlite.SQLiteDatabase; - -import com.tamic.statInterface.statsdk.db.DaoMaster; -import com.tamic.statInterface.statsdk.db.DaoSession; -import com.tamic.statInterface.statsdk.db.TcNoteDao; - -/** - * Created by Tamic on 2016-03-16. - */ -public class NoteDaoHelper { - private SQLiteDatabase db; - private DaoMaster daoMaster; - private DaoSession daoSession; - private TcNoteDao paNoteDao ; - - public TcNoteDao getPaNoteDao(Context context){ - if(paNoteDao == null){ - paNoteDao = getDaoSession(context).getPaNoteDao(); - } - return paNoteDao ; - } - - - - - private DaoMaster getDaoMaster(Context context){ - if(daoMaster == null){ - DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(context, "tamic-db", null); - db = helper.getWritableDatabase(); - daoMaster = new DaoMaster(db); - } - return daoMaster ; - } - - private DaoSession getDaoSession(Context context){ - if(daoSession == null){ - daoSession = getDaoMaster(context).newSession(); - } - return daoSession ; - } - - - - -} diff --git a/StatInterface/src/main/java/com/tamic/statInterface/statsdk/db/helper/StaticsAgent.java b/StatInterface/src/main/java/com/tamic/statInterface/statsdk/db/helper/StaticsAgent.java deleted file mode 100644 index f199999..0000000 --- a/StatInterface/src/main/java/com/tamic/statInterface/statsdk/db/helper/StaticsAgent.java +++ /dev/null @@ -1,124 +0,0 @@ -package com.tamic.statInterface.statsdk.db.helper; - -import android.content.Context; -import android.text.TextUtils; - -import com.alibaba.fastjson.JSONObject; -import com.tamic.statInterface.statsdk.db.TcNote; -import com.tamic.statInterface.statsdk.db.TcNoteDao; -import com.tamic.statInterface.statsdk.model.AppAction; -import com.tamic.statInterface.statsdk.model.DataBlock; -import com.tamic.statInterface.statsdk.model.Event; -import com.tamic.statInterface.statsdk.model.Page; -import com.tamic.statInterface.statsdk.util.JsonUtil; - -import java.util.ArrayList; -import java.util.List; - -/** - * Created by Tamic on 2016-03-17. - */ -public class StaticsAgent { - private static NoteDaoHelper helper; - private static TcNoteDao noteDao; - private static TcNote note; - - /** - * @param context - */ - public static void init(Context context) { - helper = new NoteDaoHelper(); - noteDao = helper.getPaNoteDao(context); - } - - /** - * 存储appAction相关信息 - * - * @param appAction - */ - public static void storeAppAction(String appAction) { - if (TextUtils.isEmpty(appAction)) - throw new NullPointerException("appAction is null"); - storeData(appAction, "", ""); - } - - /** - * storePage - * - * @param pageString - */ - public static void storePage(String pageString) { - if (TextUtils.isEmpty(pageString)) - throw new NullPointerException("pageString is null"); - storeData("", pageString, ""); - } - - /** - * storeEvent - * - * @param eventString - */ - public static void storeEvent(String eventString) { - if (TextUtils.isEmpty(eventString)) - throw new NullPointerException("eventString is null"); - storeData("", "", eventString); - } - - public static DataBlock getDataBlock() { - DataBlock dataBlock = new DataBlock(); - List list = noteDao.loadAll(); - AppAction appAction = new AppAction(); - Page page = new Page(); - Event event = new Event(); - List actionList = new ArrayList(); - List pageList = new ArrayList(); - List eventList = new ArrayList(); - for (int i = 0; i < list.size(); i++) { - if (!TextUtils.isEmpty(list.get(i).getFirstcloumn())) { - appAction = JsonUtil.parseObject(list.get(i).getFirstcloumn(), AppAction.class); - actionList.add(appAction); - } - if (!TextUtils.isEmpty(list.get(i).getSecondcloumn())) { - page = JsonUtil.parseObject(list.get(i).getSecondcloumn(), Page.class); - pageList.add(page); - } - if (!TextUtils.isEmpty(list.get(i).getThirdcloumn())) { - event = JsonUtil.parseObject(list.get(i).getThirdcloumn(), Event.class); - eventList.add(event); - } - } - dataBlock.setApp_action(actionList); - dataBlock.setPage(pageList); - dataBlock.setEvent(eventList); - return dataBlock; - } - - - public static void storeData(String appActionInfo, String pageInfo, String eventInfo) { - note = new TcNote(null, appActionInfo, pageInfo, eventInfo); - if (null != helper) { - noteDao.insert(note); - } - } - - /** - * storeObject - * - * @param o - */ - public static void storeObject(Object o) { - if (o instanceof Event) { - storeEvent(JSONObject.toJSONString(o)); - } else if (o instanceof AppAction) { - storeAppAction(JSONObject.toJSONString(o)); - } else if (o instanceof Page) { - storePage(JSONObject.toJSONString(o)); - } - } - - public static void deleteData() { - noteDao.deleteAll(); - } - -} - diff --git a/StatInterface/src/main/java/com/tamic/statInterface/statsdk/http/TcHttpClient.java b/StatInterface/src/main/java/com/tamic/statInterface/statsdk/http/TcHttpClient.java deleted file mode 100644 index dacd28b..0000000 --- a/StatInterface/src/main/java/com/tamic/statInterface/statsdk/http/TcHttpClient.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.tamic.statInterface.statsdk.http; - -import android.content.Context; - -import com.loopj.android.http.*; - -import cz.msebera.android.httpclient.Header; - -/** - * Created by LIUYONGKUI726 on 2016-05-26. - */ -public class TcHttpClient { - - private static final String BASE_URL = ""; - - private static AsyncHttpClient client = new AsyncHttpClient(); - - public static void get(String url, RequestParams params, AsyncHttpResponseHandler responseHandler) { - client.get(getAbsoluteUrl(url), params, responseHandler); - } - - public static void post(String url, RequestParams params, AsyncHttpResponseHandler responseHandler) { - client.post(getAbsoluteUrl(url), params, responseHandler); - } - - private static String getAbsoluteUrl(String relativeUrl) { - return BASE_URL + relativeUrl; - } - - public static void get(Context context,String url, Header[] headers, RequestParams params, AsyncHttpResponseHandler responseHandler) { - client.get(context,getAbsoluteUrl(url),headers, params, responseHandler); - } - - public static void post(Context context,String url, Header[] headers, RequestParams params, String contentType, - AsyncHttpResponseHandler responseHandler) { - client.post(context, getAbsoluteUrl(url), headers, params, contentType, responseHandler); - } - - public static void cancle(String tag, boolean isRunning) { - client.cancelRequestsByTAG(tag, isRunning); - } - - public static void cancleAll(boolean isRunning) { - client.cancelAllRequests(isRunning); - } - - /**setTimeOut - * @param time 秒数 - */ - public static void setTimeOut(int time) { - client.setTimeout(time); - } -} diff --git a/StatInterface/src/main/java/com/tamic/statInterface/statsdk/model/AppAction.java b/StatInterface/src/main/java/com/tamic/statInterface/statsdk/model/AppAction.java deleted file mode 100644 index af3241a..0000000 --- a/StatInterface/src/main/java/com/tamic/statInterface/statsdk/model/AppAction.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.tamic.statInterface.statsdk.model; - -/** - - * Created by Tamic 2016-03-24. - */ -public class AppAction { - private String action_time ; - private String app_action_type ; - - public String getAction_time() { - return action_time; - } - - public void setAction_time(String action_time) { - this.action_time = action_time; - } - - public String getApp_action_type() { - return app_action_type; - } - - public void setApp_action_type(String app_action_type) { - this.app_action_type = app_action_type; - } -} diff --git a/StatInterface/src/main/java/com/tamic/statInterface/statsdk/model/AppActionList.java b/StatInterface/src/main/java/com/tamic/statInterface/statsdk/model/AppActionList.java deleted file mode 100644 index e1bc724..0000000 --- a/StatInterface/src/main/java/com/tamic/statInterface/statsdk/model/AppActionList.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.tamic.statInterface.statsdk.model; - -import java.util.List; - -/** - * AppAction - * Created by Tamic on 2016-03-24. - */ -public class AppActionList { - private List list ; - - public List getList() { - return list; - } - - public void setList(List list) { - this.list = list; - } -} diff --git a/StatInterface/src/main/java/com/tamic/statInterface/statsdk/model/DataBlock.java b/StatInterface/src/main/java/com/tamic/statInterface/statsdk/model/DataBlock.java deleted file mode 100644 index a0eca2e..0000000 --- a/StatInterface/src/main/java/com/tamic/statInterface/statsdk/model/DataBlock.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.tamic.statInterface.statsdk.model; - -import java.util.List; - -/** - * 上传数据对象bean - * Created by ZHANGLIANG098 on 2016-03-24. - */ -public class DataBlock { - private List app_action ; - private List page ; - private List event ; - - public List getApp_action() { - return app_action; - } - - public void setApp_action(List app_action) { - this.app_action = app_action; - } - - public List getPage() { - return page; - } - - public void setPage(List page) { - this.page = page; - } - - public List getEvent() { - return event; - } - - public void setEvent(List event) { - this.event = event; - } -} diff --git a/StatInterface/src/main/java/com/tamic/statInterface/statsdk/model/Event.java b/StatInterface/src/main/java/com/tamic/statInterface/statsdk/model/Event.java deleted file mode 100644 index 1f868ff..0000000 --- a/StatInterface/src/main/java/com/tamic/statInterface/statsdk/model/Event.java +++ /dev/null @@ -1,73 +0,0 @@ -package com.tamic.statInterface.statsdk.model; - -import java.util.List; - -/** - * 对应的event事件 - * Created by ZHANGLIANG098 on 2016-03-24. - */ -public class Event { - private String page_id ; - private String referer_page_id ; - private String uid ; - private String city_id ; - private String event_name ; - private String action_time ; - private List parameter ; - - public String getPage_id() { - return page_id; - } - - public void setPage_id(String page_id) { - this.page_id = page_id; - } - - public String getReferer_page_id() { - return referer_page_id; - } - - public void setReferer_page_id(String referer_page_id) { - this.referer_page_id = referer_page_id; - } - - public String getUid() { - return uid; - } - - public void setUid(String uid) { - this.uid = uid; - } - - public String getCity_id() { - return city_id; - } - - public void setCity_id(String city_id) { - this.city_id = city_id; - } - - public String getEvent_name() { - return event_name; - } - - public void setEvent_name(String event_name) { - this.event_name = event_name; - } - - public String getAction_time() { - return action_time; - } - - public void setAction_time(String action_time) { - this.action_time = action_time; - } - - public List getParameter() { - return parameter; - } - - public void setParameter(List parameter) { - this.parameter = parameter; - } -} diff --git a/StatInterface/src/main/java/com/tamic/statInterface/statsdk/model/EventList.java b/StatInterface/src/main/java/com/tamic/statInterface/statsdk/model/EventList.java deleted file mode 100644 index 8e8890a..0000000 --- a/StatInterface/src/main/java/com/tamic/statInterface/statsdk/model/EventList.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.tamic.statInterface.statsdk.model; - -import java.util.List; - -/** - * 对应的event事件集合 - * Created by ZHANGLIANG098 on 2016-03-24. - */ -public class EventList { - private List list ; - - public List getList() { - return list; - } - - public void setList(List list) { - this.list = list; - } -} diff --git a/StatInterface/src/main/java/com/tamic/statInterface/statsdk/model/KeyValueBean.java b/StatInterface/src/main/java/com/tamic/statInterface/statsdk/model/KeyValueBean.java deleted file mode 100644 index 49a8075..0000000 --- a/StatInterface/src/main/java/com/tamic/statInterface/statsdk/model/KeyValueBean.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.tamic.statInterface.statsdk.model; - -/** - *业务对应的key-value - * Created by ZHANGLIANG098 on 2016-03-24. - */ -public class KeyValueBean { - private String name; - private String value; - - public KeyValueBean(){} - - public KeyValueBean(String name,String value){ - this.name = name ; - this.value = value ; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getValue() { - return value; - } - - public void setValue(String value) { - this.value = value; - } - - @Override - public String toString() { - return "KeyValueBean{" + - "name='" + name + '\'' + - ", value='" + value + '\'' + - '}'; - } -} diff --git a/StatInterface/src/main/java/com/tamic/statInterface/statsdk/model/Page.java b/StatInterface/src/main/java/com/tamic/statInterface/statsdk/model/Page.java deleted file mode 100644 index b106d37..0000000 --- a/StatInterface/src/main/java/com/tamic/statInterface/statsdk/model/Page.java +++ /dev/null @@ -1,73 +0,0 @@ -package com.tamic.statInterface.statsdk.model; - -import java.util.List; - -/** - * Page - * Created by Tamic on 2016-03-24. - */ -public class Page { - private String page_id; - private String referer_page_id ; - private String page_start_time ; - private String page_end_time ; - private String city_id ; - private String uid ; - private List parameter ; - - public String getPage_id() { - return page_id; - } - - public void setPage_id(String page_id) { - this.page_id = page_id; - } - - public String getReferer_page_id() { - return referer_page_id; - } - - public void setReferer_page_id(String referer_page_id) { - this.referer_page_id = referer_page_id; - } - - public String getPage_start_time() { - return page_start_time; - } - - public void setPage_start_time(String page_start_time) { - this.page_start_time = page_start_time; - } - - public String getPage_end_time() { - return page_end_time; - } - - public void setPage_end_time(String page_end_time) { - this.page_end_time = page_end_time; - } - - public String getCity_id() { - return city_id; - } - - public void setCity_id(String city_id) { - this.city_id = city_id; - } - - public List getParameter() { - return parameter; - } - - public void setParameter(List parameter) { - this.parameter = parameter; - } - - public String getUid() { - return uid; - } - - public void setUid(String uid) { - this.uid = uid; - } -} diff --git a/StatInterface/src/main/java/com/tamic/statInterface/statsdk/model/PageList.java b/StatInterface/src/main/java/com/tamic/statInterface/statsdk/model/PageList.java deleted file mode 100644 index 722caf4..0000000 --- a/StatInterface/src/main/java/com/tamic/statInterface/statsdk/model/PageList.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.tamic.statInterface.statsdk.model; - -import java.util.List; - -/** - * 页面数据统计集合 - * Created by ZHANGLIANG098 on 2016-03-24. - */ -public class PageList { - private List list ; - - public List getList() { - return list; - } - - public void setList(List list) { - this.list = list; - } -} diff --git a/StatInterface/src/main/java/com/tamic/statInterface/statsdk/model/ParamterList.java b/StatInterface/src/main/java/com/tamic/statInterface/statsdk/model/ParamterList.java deleted file mode 100644 index 9b89b85..0000000 --- a/StatInterface/src/main/java/com/tamic/statInterface/statsdk/model/ParamterList.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.tamic.statInterface.statsdk.model; - -import java.util.List; - -/** - * 业务对应的key-value集合 - * Created by ZHANGLIANG098 on 2016-03-24. - */ -public class ParamterList { - private List list ; - - public List getList() { - return list; - } - - public void setList(List list) { - this.list = list; - } -} diff --git a/StatInterface/src/main/java/com/tamic/statInterface/statsdk/model/header/AppInfo.java b/StatInterface/src/main/java/com/tamic/statInterface/statsdk/model/header/AppInfo.java deleted file mode 100644 index 1a05635..0000000 --- a/StatInterface/src/main/java/com/tamic/statInterface/statsdk/model/header/AppInfo.java +++ /dev/null @@ -1,74 +0,0 @@ -package com.tamic.statInterface.statsdk.model.header; - -/** - * Created by Tamic on 2016-03-24. - * AppInfo - */ -public class AppInfo { - - /** - * App ID - */ - private String app_id; - - /** - * App版本 - */ - private String app_version; - - /** - * 统计sdk版本号 - */ - private int sdk_version_code; - - private String sdk_verson_name; - - /** - * app channel - */ - private String channel; - - public AppInfo() { - } - - public String getApp_id() { - return app_id; - } - - public void setApp_id(String app_id) { - this.app_id = app_id; - } - - public String getApp_version() { - return app_version; - } - - public void setApp_version(String app_version) { - this.app_version = app_version; - } - - public int getSdk_version() { - return sdk_version_code; - } - - public void setSdk_version(int sdk_version) { - this.sdk_version_code = sdk_version; - } - - public String getChannel() { - return channel; - } - - public void setChannel(String channel) { - this.channel = channel; - } - public String getSdk_verson_name() { - return sdk_verson_name; - } - - public void setSdk_verson_name(String sdk_verson_name) { - this.sdk_verson_name = sdk_verson_name; - } - - -} diff --git a/StatInterface/src/main/java/com/tamic/statInterface/statsdk/model/header/DeviceInfo.java b/StatInterface/src/main/java/com/tamic/statInterface/statsdk/model/header/DeviceInfo.java deleted file mode 100644 index 0f11bec..0000000 --- a/StatInterface/src/main/java/com/tamic/statInterface/statsdk/model/header/DeviceInfo.java +++ /dev/null @@ -1,127 +0,0 @@ -package com.tamic.statInterface.statsdk.model.header; - -/** - * Created by Tamic on 2016-03-24. - */ -public class DeviceInfo { - private String device_id; - private String idfa; - private String idfv; - private String openudid; - private String imei; - private String android_id; - private String mac; - private String locale; - private String os = "Android"; - private String os_version; - private String resolution; - private String density; - private String model; - - - public String getDevice_id() { - return device_id; - } - - public void setDevice_id(String device_id) { - this.device_id = device_id; - } - - public String getIdfv() { - return idfv; - } - - public void setIdfv(String idfv) { - this.idfv = idfv; - } - - public String getIdfa() { - return idfa; - } - - public void setIdfa(String idfa) { - this.idfa = idfa; - } - - public String getOpenudid() { - return openudid; - } - - public void setOpenudid(String openudid) { - this.openudid = openudid; - } - - public String getImei() { - return imei; - } - - public void setImei(String imei) { - this.imei = imei; - } - - public String getAndroid_id() { - return android_id; - } - - public void setAndroid_id(String android_id) { - this.android_id = android_id; - } - - public String getMac() { - return mac; - } - - public void setMac(String mac) { - this.mac = mac; - } - - public String getLocale() { - return locale; - } - - public void setLocale(String locale) { - this.locale = locale; - } - - public String getOs() { - return os; - } - - public void setOs(String os) { - this.os = os; - } - - public String getOs_version() { - return os_version; - } - - public void setOs_version(String os_version) { - this.os_version = os_version; - } - - public String getResolution() { - return resolution; - } - - public void setResolution(String resolution) { - this.resolution = resolution; - } - - public String getDensity() { - return density; - } - - public void setDensity(String density) { - this.density = density; - } - - public String getModel() { - return model; - } - - public void setModel(String model) { - this.model = model; - } - - -} diff --git a/StatInterface/src/main/java/com/tamic/statInterface/statsdk/model/header/HeaderInfo.java b/StatInterface/src/main/java/com/tamic/statInterface/statsdk/model/header/HeaderInfo.java deleted file mode 100644 index a36977e..0000000 --- a/StatInterface/src/main/java/com/tamic/statInterface/statsdk/model/header/HeaderInfo.java +++ /dev/null @@ -1,46 +0,0 @@ -package com.tamic.statInterface.statsdk.model.header; - -/** - * Created by Tamic on 2016-04-06. - */ -public class HeaderInfo { - - private AppInfo appinfo; - - private DeviceInfo deviceinfo; - - private NetworkInfo networkinfo; - - public HeaderInfo() { - } - - public HeaderInfo(AppInfo appinfo, DeviceInfo deviceinfo, NetworkInfo networkinfo) { - this.appinfo = appinfo; - this.deviceinfo = deviceinfo; - this.networkinfo = networkinfo; - } - - public AppInfo getAppinfo() { - return appinfo; - } - - public void setAppinfo(AppInfo appinfo) { - this.appinfo = appinfo; - } - - public DeviceInfo getDeviceinfo() { - return deviceinfo; - } - - public void setDeviceinfo(DeviceInfo deviceinfo) { - this.deviceinfo = deviceinfo; - } - - public NetworkInfo getNetworkinfo() { - return networkinfo; - } - - public void setNetworkinfo(NetworkInfo networkinfo) { - this.networkinfo = networkinfo; - } -} diff --git a/StatInterface/src/main/java/com/tamic/statInterface/statsdk/model/header/NetworkInfo.java b/StatInterface/src/main/java/com/tamic/statInterface/statsdk/model/header/NetworkInfo.java deleted file mode 100644 index d790961..0000000 --- a/StatInterface/src/main/java/com/tamic/statInterface/statsdk/model/header/NetworkInfo.java +++ /dev/null @@ -1,65 +0,0 @@ -package com.tamic.statInterface.statsdk.model.header; - -/** - * NetworkInfo - * Created by Tamic on 2016-03-24. - */ -public class NetworkInfo { - - //operator - private String carrier; - //is wifi - private Boolean wifi_ind; - //IP - private String ip_addr; - //latitude - private String latitude; - //longitude - private String longitude; - - - public NetworkInfo() { - } - - public String getCarrier() { - return carrier; - } - - public void setCarrier(String carrier) { - this.carrier = carrier; - } - - public String getLongitude() { - return longitude; - } - - public void setLongitude(String longitude) { - this.longitude = longitude; - } - - public String getIp_addr() { - return ip_addr; - } - - public void setIp_addr(String ip_addr) { - this.ip_addr = ip_addr; - } - - public Boolean getWifi_ind() { - return wifi_ind; - } - - public void setWifi_ind(Boolean wifi_ind) { - this.wifi_ind = wifi_ind; - } - - public String getLatitude() { - return latitude; - } - - public void setLatitude(String latitude) { - this.latitude = latitude; - } - - -} diff --git a/StatInterface/src/main/java/com/tamic/statInterface/statsdk/presenter/TcDeblockObserver.java b/StatInterface/src/main/java/com/tamic/statInterface/statsdk/presenter/TcDeblockObserver.java deleted file mode 100644 index 276a0cd..0000000 --- a/StatInterface/src/main/java/com/tamic/statInterface/statsdk/presenter/TcDeblockObserver.java +++ /dev/null @@ -1,109 +0,0 @@ - -package com.tamic.statInterface.statsdk.presenter; - -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.Intent; -import android.content.IntentFilter; - -import com.tamic.statInterface.statsdk.constants.StaticsConfig; -import com.tamic.statInterface.statsdk.core.TcIntentManager; -import com.tamic.statInterface.statsdk.util.StatLog; - -/** - * DeblockObserver - * Created by Tamic on 2016-04-15. - */ -public class TcDeblockObserver extends BroadcastReceiver { - - /** DEBUG mode */ - private static final boolean DEBUG = StaticsConfig.DEBUG; - /** StatLog TAG */ - private static final String StatLog_TAG = TcDeblockObserver.class.getSimpleName(); - /** Context */ - private Context mContext; - /** IKeyguardListener */ - private IKeyguardListener mListener; - - /** - * Constructor - * - * @param aContext - * Context - * @param aListener - * IScreenListener - */ - public TcDeblockObserver(Context aContext, IKeyguardListener aListener) { - mContext = aContext; - mListener = aListener; - } - - /** - * start Listener - */ - public void start() { - try { - IntentFilter filter = new IntentFilter(); - filter.addAction(Intent.ACTION_USER_PRESENT); - mContext.registerReceiver(this, filter); - - if (!isScreenLocked(mContext)) { - if (mListener != null) { - mListener.onKeyguardGone(mContext); - } - } - } catch (Exception e) { - if (DEBUG) { - StatLog.w(StatLog_TAG, "start Exception", e); - } - } - } - - /** - * stop Listener - */ - public void stop() { - try { - mContext.unregisterReceiver(this); - } catch (Exception e) { - if (DEBUG) { - StatLog.w(StatLog_TAG, "stop Exception", e); - } - } - } - - /** - * is Screen Locked - * - * @param aContext Context - * @return true if screen locked, false otherwise - */ - public boolean isScreenLocked(Context aContext) { - android.app.KeyguardManager km = (android.app.KeyguardManager) aContext - .getSystemService(Context.KEYGUARD_SERVICE); - return km.inKeyguardRestrictedInputMode(); - } - - @Override - public void onReceive(Context aContext, Intent aIntent) { - if (TcIntentManager.getInstance().isUserPresentIntent(aIntent)) { - if (mListener != null) { - mListener.onKeyguardGone(aContext); - } - } - } - - /** - * IKeyguardListener - */ - public interface IKeyguardListener { - - /** - * unlock - * - * @param aContext - * Context - */ - void onKeyguardGone(Context aContext); - } -} diff --git a/StatInterface/src/main/java/com/tamic/statInterface/statsdk/presenter/TcNetworkObserver.java b/StatInterface/src/main/java/com/tamic/statInterface/statsdk/presenter/TcNetworkObserver.java deleted file mode 100644 index f90e864..0000000 --- a/StatInterface/src/main/java/com/tamic/statInterface/statsdk/presenter/TcNetworkObserver.java +++ /dev/null @@ -1,143 +0,0 @@ - -package com.tamic.statInterface.statsdk.presenter; - -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.Intent; -import android.content.IntentFilter; -import android.net.ConnectivityManager; -import android.net.NetworkInfo; -import android.text.TextUtils; -import android.util.Log; - -import com.tamic.statInterface.statsdk.constants.StaticsConfig; - -/** - * NetworkObserver - * Created by Tamic. - */ -public class TcNetworkObserver extends BroadcastReceiver { - - /** Debug mode */ - private static final boolean DEBUG = StaticsConfig.DEBUG; - /** LOG Tag */ - private static final String LOG_TAG = TcNetworkObserver.class.getSimpleName(); - /** Context */ - private Context mContext; - /** NetworkListener */ - private INetworkListener mListener; - /** IsNetworkAvailable */ - private boolean mIsNetworkAvailable; - /** Is Registered */ - private boolean isRegistered; - - /** - * Constructor - * - * @param aContext - * Context - * @param aListener - * INetworkListener - */ - public TcNetworkObserver(Context aContext, INetworkListener aListener) { - mContext = aContext; - mListener = aListener; - mIsNetworkAvailable = false; - isRegistered = false; - } - - /** - * start, onResume call - */ - public void start() { - - if (isRegistered) { - - return; - } - try { - mContext.registerReceiver(this, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION)); - - isRegistered = true; - } catch (Exception e) { - isRegistered = false; - if (DEBUG) { - Log.e(LOG_TAG, "Start Exception", e); - } - } - } - - /** - * stop, onPause call - */ - public void stop() { - - if (!isRegistered) { - - return; - } - try { - mContext.unregisterReceiver(this); - isRegistered = false; - } catch (Exception e) { - if (DEBUG) { - Log.e(LOG_TAG, "Stop Exception", e); - } - isRegistered = true; - } - } - - /** - * Indicates whether network connectivity is possible. - * - * @param aContext - * Context - * - * @return true if the network is available, false otherwise - */ - public boolean isNetworkAvailable(Context aContext) { - ConnectivityManager cm = (ConnectivityManager) aContext - .getSystemService(Context.CONNECTIVITY_SERVICE); - NetworkInfo info = cm.getActiveNetworkInfo(); - return (info != null && info.isAvailable()); - } - - @Override - public void onReceive(Context aContext, Intent aIntent) { - - if (TextUtils.equals(aIntent.getAction(), ConnectivityManager.CONNECTIVITY_ACTION)) { - - boolean isAvailable = isNetworkAvailable(aContext); - if (isAvailable) { - if (!mIsNetworkAvailable && mListener != null) { - mListener.onNetworkConnected(aContext); - } - } else { - if (mListener != null) { - mListener.onNetworkUnConnected(aContext); - } - } - mIsNetworkAvailable = isAvailable; - - } - } - - /** - * INetworkListener - */ - public interface INetworkListener { - /** - * Connected( - * - * @param aContext - * Context - */ - void onNetworkConnected(Context aContext); - - - /** UnConnected - * @param aContext - */ - void onNetworkUnConnected(Context aContext); - } -} diff --git a/StatInterface/src/main/java/com/tamic/statInterface/statsdk/presenter/TcScreenObserver.java b/StatInterface/src/main/java/com/tamic/statInterface/statsdk/presenter/TcScreenObserver.java deleted file mode 100644 index 747ec0e..0000000 --- a/StatInterface/src/main/java/com/tamic/statInterface/statsdk/presenter/TcScreenObserver.java +++ /dev/null @@ -1,126 +0,0 @@ -/** - * Filename: TcScreenObserver.java - * Description: - * Copyright: Baidu MIC Copyright(c)2011 - * @author: CoCoMo - * @version: 1.0 - * Create at: 2013-1-6 下午1:55:30 - * - * Modification History: - * Date Author Version Description - * ------------------------------------------------------------------ - * 2013-1-6 CoCoMo 1.0 1.0 Version - */ -package com.tamic.statInterface.statsdk.presenter; - -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.Intent; -import android.content.IntentFilter; -import android.os.PowerManager; -import android.util.Log; - -import com.tamic.statInterface.statsdk.constants.StaticsConfig; -import com.tamic.statInterface.statsdk.core.TcIntentManager; - -/** - * ScreenObserver - * Created by Tamic. on 2016-04-15. - */ -public class TcScreenObserver extends BroadcastReceiver { - - /** DEBUG mode */ - private static final boolean DEBUG = StaticsConfig.DEBUG; - /** Log TAG */ - private static final String LOG_TAG = TcScreenObserver.class.getSimpleName(); - - /** Context */ - private Context mContext; - /** ScreenObserver */ - private IScreenListener mListener; - - /** - * Constructor - * - * @param aContext - * Context - * @param aListener - * IScreenListener - */ - public TcScreenObserver(Context aContext, IScreenListener aListener) { - mContext = aContext; - mListener = aListener; - } - - - public void start() { - try { - IntentFilter filter = new IntentFilter(); - filter.addAction(Intent.ACTION_SCREEN_ON); - filter.addAction(Intent.ACTION_SCREEN_OFF); - mContext.registerReceiver(this, filter); - - if (isScreenOn(mContext)) { - if (mListener != null) { - mListener.onScreenOn(mContext); - } - } else { - if (mListener != null) { - mListener.onScreenOff(mContext); - } - } - } catch (Exception e) { - if (DEBUG) { - Log.w(LOG_TAG, "start Exception", e); - } - } - } - - - public void stop() { - try { - mContext.unregisterReceiver(this); - } catch (Exception e) { - if (DEBUG) { - Log.w(LOG_TAG, "stop Exception", e); - } - } - } - - /** - * isScreenOn - * - * @param aContext - * Context - */ - public boolean isScreenOn(Context aContext) { - PowerManager pm = (PowerManager) aContext.getSystemService(Context.POWER_SERVICE); - return pm.isScreenOn(); - } - - @Override - public void onReceive(Context aContext, Intent aIntent) { - if (TcIntentManager.getInstance().isScreenOnIntent(aIntent)) { - if (mListener != null) { - mListener.onScreenOn(aContext); - } - } else if (TcIntentManager.getInstance().isScreenOffIntent(aIntent)) { - if (mListener != null) { - mListener.onScreenOff(aContext); - } - } - } - - /** - * IScreenListener - */ - public interface IScreenListener { - - - void onScreenOn(Context aContext); - - - void onScreenOff(Context aContext); - } - -} diff --git a/StatInterface/src/main/java/com/tamic/statInterface/statsdk/service/Platform.java b/StatInterface/src/main/java/com/tamic/statInterface/statsdk/service/Platform.java deleted file mode 100644 index c09acaa..0000000 --- a/StatInterface/src/main/java/com/tamic/statInterface/statsdk/service/Platform.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (C) 2013 Square, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.tamic.statInterface.statsdk.service; - -import android.os.Build; -import android.util.Log; - -import com.tamic.statInterface.statsdk.core.TcNetEngine; - -import java.util.concurrent.Executor; - -/** - * Created by Tamic on 2016-09-21. - * {@link # https://github.com/NeglectedByBoss} - */ -public class Platform { - private static final Platform PLATFORM = findPlatform(); - - public static Platform get() { - Log.v("TcStatInterfacePlatform", PLATFORM.getClass().toString()); - return PLATFORM; - } - - private static Platform findPlatform() { - try { - Class.forName("android.os.Build"); - if (Build.VERSION.SDK_INT != 0) { - return new Android(); - } - } catch (ClassNotFoundException ignored) { - } - return new Platform(); - } - - public Executor defaultCallbackExecutor() { - return new TcHandleThreadPool().getExecutor(); - } - - public Object execute(Runnable runnable) { - defaultCallbackExecutor().execute(runnable); - return null; - } - - static class Android extends Platform { - @Override - public Executor defaultCallbackExecutor() { - return new TcHandleThreadPool().getExecutor(); - } - - } - -} diff --git a/StatInterface/src/main/java/com/tamic/statInterface/statsdk/service/PriorityThreadFactory.java b/StatInterface/src/main/java/com/tamic/statInterface/statsdk/service/PriorityThreadFactory.java deleted file mode 100644 index fdfa843..0000000 --- a/StatInterface/src/main/java/com/tamic/statInterface/statsdk/service/PriorityThreadFactory.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.tamic.statInterface.statsdk.service; - -import android.os.Process; - -import java.util.concurrent.ThreadFactory; -import java.util.concurrent.atomic.AtomicInteger; - -/** - * Created by Tamic on 2016-09-20. - */ -public class PriorityThreadFactory implements ThreadFactory { - - private final String mName; - private final int mPriority; - private final AtomicInteger mNumber = new AtomicInteger(); - - public PriorityThreadFactory(String name, int priority) { - mName = name; - mPriority = priority; - } - @Override - public Thread newThread(Runnable r) { - return new Thread(r, mName +"-"+mNumber.getAndIncrement()){ - @Override - public void run() { - Process.setThreadPriority(mPriority); - super.run(); - } - }; - } -} diff --git a/StatInterface/src/main/java/com/tamic/statInterface/statsdk/service/TcHandleThreadPool.java b/StatInterface/src/main/java/com/tamic/statInterface/statsdk/service/TcHandleThreadPool.java deleted file mode 100644 index 96ec4ac..0000000 --- a/StatInterface/src/main/java/com/tamic/statInterface/statsdk/service/TcHandleThreadPool.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.tamic.statInterface.statsdk.service; - -import java.util.concurrent.BlockingQueue; -import java.util.concurrent.Executor; -import java.util.concurrent.LinkedBlockingDeque; -import java.util.concurrent.ThreadFactory; -import java.util.concurrent.ThreadPoolExecutor; -import java.util.concurrent.TimeUnit; - -/** - * Created by Tamic on 2016-09-22. - */ -public class TcHandleThreadPool { - - private final static int POOL_SIZE = 4; - private final static int MAX_POOL_SIZE = 6; - private final static int KEEP_ALIVE_TIME = 4; - private final Executor mExecutor; - private final static String THREAD_NAME ="paf-stat-thread-pool"; - public TcHandleThreadPool() { - - ThreadFactory factory = new PriorityThreadFactory(THREAD_NAME, android.os.Process.THREAD_PRIORITY_BACKGROUND); - BlockingQueue workQueue = new LinkedBlockingDeque(); - mExecutor = new ThreadPoolExecutor(POOL_SIZE, MAX_POOL_SIZE, KEEP_ALIVE_TIME, TimeUnit.SECONDS, workQueue, factory); - } - - public void execute(Runnable command){ - mExecutor.execute(command); - } - - public Executor getExecutor() { - return mExecutor; - } -} diff --git a/StatInterface/src/main/java/com/tamic/statInterface/statsdk/sp/SharedPreferencesHelper.java b/StatInterface/src/main/java/com/tamic/statInterface/statsdk/sp/SharedPreferencesHelper.java deleted file mode 100644 index 0ae0600..0000000 --- a/StatInterface/src/main/java/com/tamic/statInterface/statsdk/sp/SharedPreferencesHelper.java +++ /dev/null @@ -1,203 +0,0 @@ -package com.tamic.statInterface.statsdk.sp; - -import android.content.Context; -import android.content.SharedPreferences; - - -import com.tamic.statInterface.statsdk.util.JsonUtil; - -import org.json.JSONArray; -import org.json.JSONException; -import org.json.JSONObject; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; - -/** - * Created by Tamic on 2016-03-24. - */ -public class SharedPreferencesHelper { - private static SharedPreferencesHelper sInstance; - private static SharedPreferences sSettings; - - - public static synchronized SharedPreferencesHelper getInstance(Context outContext) { - if (sInstance == null) { - sInstance = new SharedPreferencesHelper(outContext); - } - return sInstance; - } - - private SharedPreferencesHelper(Context outContext) { - String OUT_APP_PACKAGENAME = outContext.getPackageName(); - sSettings = outContext.getSharedPreferences(OUT_APP_PACKAGENAME, 0); - } - - - public void putString(String key, String value) { - synchronized (sSettings) { - sSettings.edit().putString(key, value).commit(); - } - } - - - public String getString(String key) { - synchronized (sSettings) { - return sSettings.getString(key, ""); - } - } - - - public String getString(String key, String defValue) { - synchronized (sSettings) { - return sSettings.getString(key, defValue); - } - } - - public Double getDouble(String key) { - String retStr = getString(key, null); - Double ret = null; - try { - ret = Double.parseDouble(retStr); - } catch (Exception e) { - } - return ret; - } - - public void putBoolean(String key, boolean bool) { - synchronized (sSettings) { - sSettings.edit().putBoolean(key, bool).commit(); - } - } - - public void putInteger(String key, int integer) { - synchronized (sSettings) { - sSettings.edit().putInt(key, integer).commit(); - } - } - - public void putLong(String key, long lon) { - synchronized (sSettings) { - sSettings.edit().putLong(key, lon).commit(); - } - } - - public Boolean getBoolean(String key, boolean defValue) { - synchronized (sSettings) { - return sSettings.getBoolean(key, defValue); - } - - } - - public int getInteger(String key, int defValue) { - synchronized (sSettings) { - return sSettings.getInt(key, defValue); - } - } - - public long getLong(String key, long defValue) { - synchronized (sSettings) { - return sSettings.getLong(key, defValue); - } - } - - - public void putHashMap(String key, HashMap map) { - JSONObject ret = new JSONObject(map); - synchronized (sSettings) { - sSettings.edit().putString(key, ret.toString()).commit(); - } - } - - public HashMap getHashMap(String key) { - return getHashMapByKey(key); - } - - public HashMap getHashMapByKey(String key) { - HashMap ret = new HashMap(); - - String mapStr = getString(key, "{}"); - JSONObject mapJson = null; - try { - mapJson = new JSONObject(mapStr); - } catch (Exception e) { - return ret; - } - - if (mapJson != null) { - @SuppressWarnings("unchecked") - Iterator it = mapJson.keys(); - while (it.hasNext()) { - String theKey = it.next(); - String theValue = mapJson.optString(theKey); - ret.put(theKey, theValue); - } - } - - return ret; - } - - public void putArrayList(String key, ArrayList list) { - JSONArray ret = new JSONArray(list); - putString(key, ret.toString()); - } - - public ArrayList getArrayList(String key) { - ArrayList ret = new ArrayList(); - - String listStr = getString(key, "{}"); - JSONArray listJson = null; - try { - listJson = new JSONArray(listStr); - } catch (Exception e) { - return ret; - } - - if (listJson != null) { - for (int i = 0; i < listJson.length(); i++) { - String temp = listJson.optString(i); - ret.add(temp); - } - } - - return ret; - } - - - public void removeByKey(String key) { - synchronized (sSettings) { - sSettings.edit().remove(key).commit(); - } - } - - public void putJsonArray(String key, JSONArray value) { - putString(key, value.toString()); - } - - public JSONArray getJsonArray(String key) { - JSONArray ret = null; - String jsonArrayStr = getString(key); - try { - ret = new JSONArray(jsonArrayStr); - } catch (JSONException e) { - ret = null; - } - return ret; - } - - public void putObject(String key, Object obj) { - String toSave = JsonUtil.toJSONString(obj); - putString(key, toSave); - } - - public T getObject(String key, Class cla) { - String temp = getString(key); - - if (temp == null || temp.trim().length() == 0) { - return null; - } - - return JsonUtil.parseObject(temp, cla); - } -} diff --git a/StatInterface/src/main/java/com/tamic/statInterface/statsdk/util/DateUtil.java b/StatInterface/src/main/java/com/tamic/statInterface/statsdk/util/DateUtil.java deleted file mode 100644 index 27ab3e4..0000000 --- a/StatInterface/src/main/java/com/tamic/statInterface/statsdk/util/DateUtil.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.tamic.statInterface.statsdk.util; - -import java.text.SimpleDateFormat; -import java.util.Date; - -/** - * DateUtil - * - */ -public class DateUtil { - - /** - * - * @return currentTimeMillis - */ - public static long getCurrentTime(){ - long time = System.currentTimeMillis(); - return time ; - } - - /** - * getDate - * yyyy-MM-dd HH:mm:ss - * - * @param - * @param format - * 如yyyy-MM-dd HH:mm:ss - * @return - */ - public static String getDateString(long milliseconds, String format) { - SimpleDateFormat sdf = new SimpleDateFormat(format); - return sdf.format(new Date(milliseconds)); - } - -} diff --git a/StatInterface/src/main/java/com/tamic/statInterface/statsdk/util/DeviceUtil.java b/StatInterface/src/main/java/com/tamic/statInterface/statsdk/util/DeviceUtil.java deleted file mode 100644 index d7ceb21..0000000 --- a/StatInterface/src/main/java/com/tamic/statInterface/statsdk/util/DeviceUtil.java +++ /dev/null @@ -1,133 +0,0 @@ -package com.tamic.statInterface.statsdk.util; - -import android.app.Activity; -import android.content.Context; -import android.content.pm.PackageInfo; -import android.content.pm.PackageManager; -import android.net.wifi.WifiInfo; -import android.net.wifi.WifiManager; -import android.text.TextUtils; -import android.util.DisplayMetrics; -import android.view.WindowManager; - -import com.tamic.statInterface.statsdk.constants.StaticsConfig; - - -/** - * DeviceUtil - * Created by Tamic. - */ -public class DeviceUtil { - - - /** - * getAppVersionName - */ - public static String getAppVersionName(Context context) { - String versionName = ""; - try { - // Get the package info - PackageManager pm = context.getPackageManager(); - PackageInfo pi = pm.getPackageInfo(context.getPackageName(), 0); - versionName = pi.versionName; - if (TextUtils.isEmpty(versionName)) { - return ""; - } - } catch (Exception e) { - } - return versionName; - } - - /** - * getAppVersionCode - */ - public static int getAppVersionCode(Context context) { - int versionCode = 0; - try { - // Get the package info - PackageManager pm = context.getPackageManager(); - PackageInfo pi = pm.getPackageInfo(context.getPackageName(), 0); - versionCode = pi.versionCode; - } catch (Exception e) { - } - return versionCode; - } - - /** - * getSdkCode - */ - public static int getSdkCode() { - - return StaticsConfig.SDK_VERSION_CODE; - } - - /** - * getSdkName - */ - public static String getSdkName() { - - return StaticsConfig.SDK_VERSION_NAME; - } - - /** - *getMacAddress - * - * @param context - * @return MAC - */ - public static String getMacAddress(Context context) { - WifiManager wifi = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); - WifiInfo info = wifi.getConnectionInfo(); - return info != null ? info.getMacAddress() : ""; - } - - /** - * getScreenDisplay - * @param activity - * @return - */ - public static DisplayMetrics getScreenDisplay(Activity activity) - { - DisplayMetrics dm = new DisplayMetrics(); - activity.getWindowManager().getDefaultDisplay().getMetrics(dm); - return dm; - } - - /** - * getScreenWidth - * @param context - * @return - */ - public static int getScreenWidth(Context context) { - WindowManager wm = (WindowManager) context - .getSystemService(Context.WINDOW_SERVICE); - DisplayMetrics outMetrics = new DisplayMetrics(); - wm.getDefaultDisplay().getMetrics(outMetrics); - return outMetrics.widthPixels; - } - - /** - * getScreenHeight - * @param context - * @return - */ - public static int getScreenHeight(Context context) { - WindowManager wm = (WindowManager) context - .getSystemService(Context.WINDOW_SERVICE); - DisplayMetrics outMetrics = new DisplayMetrics(); - wm.getDefaultDisplay().getMetrics(outMetrics); - return outMetrics.heightPixels; - } - - /** - * etScreenDensity - * @param context - * @return - */ - public static float getScreenDensity(Context context) { - return context.getResources().getDisplayMetrics().density; - } - - - -} diff --git a/StatInterface/src/main/java/com/tamic/statInterface/statsdk/util/JsonUtil.java b/StatInterface/src/main/java/com/tamic/statInterface/statsdk/util/JsonUtil.java deleted file mode 100644 index 575e0f8..0000000 --- a/StatInterface/src/main/java/com/tamic/statInterface/statsdk/util/JsonUtil.java +++ /dev/null @@ -1,85 +0,0 @@ -package com.tamic.statInterface.statsdk.util; - -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.TypeReference; -import com.alibaba.fastjson.parser.Feature; - -import java.lang.reflect.Type; -import java.util.List; - -/** - * JsonUtil - * Created by Tamic - */ -public class JsonUtil { - - /**parseObject - * @param jsonStr - * @param entityClass - * @param - * @return - */ - public static T parseObject(String jsonStr, Class entityClass) { - T ret = null; - - try { - ret = JSON.parseObject(jsonStr, entityClass); - } catch (Exception e) { - e.printStackTrace(); - } - - return ret; - } - - public static T parseObject(String jsonStr, Type type) { - T obj = null; - try { - obj = JSON.parseObject(jsonStr, type, Feature.AutoCloseSource); - } catch (Exception e) { - e.printStackTrace(); - } - return obj; - } - - - public static T parseObject(String jsonStr, TypeReference tf) { - T obj = null; - try { - obj = JSON.parseObject(jsonStr, tf, Feature.AutoCloseSource); - } catch (Exception e) { - e.printStackTrace(); - } - return obj; - } - - /** - * parseList - * @param jsonStr - * @param entityClass - * @param - * @return - */ - public static List parseList(String jsonStr, Class entityClass) { - List ret = null; - - try { - ret = JSON.parseArray(jsonStr, entityClass); - } catch (Exception e) { - e.printStackTrace(); - } - - return ret; - } - - public static String toJSONString(Object obj) { - String ret = null; - - try { - ret = JSON.toJSONString(obj); - } catch (Exception e) { - e.printStackTrace(); - } - - return ret; - } -} diff --git a/StatInterface/src/main/java/com/tamic/statInterface/statsdk/util/NetworkUtil.java b/StatInterface/src/main/java/com/tamic/statInterface/statsdk/util/NetworkUtil.java deleted file mode 100644 index ba4d74f..0000000 --- a/StatInterface/src/main/java/com/tamic/statInterface/statsdk/util/NetworkUtil.java +++ /dev/null @@ -1,187 +0,0 @@ -package com.tamic.statInterface.statsdk.util; - -import android.content.Context; -import android.net.ConnectivityManager; -import android.net.NetworkInfo; -import android.telephony.TelephonyManager; - -import java.io.IOException; -import java.net.HttpURLConnection; -import java.net.InetAddress; -import java.net.NetworkInterface; -import java.net.SocketException; -import java.net.URL; -import java.util.Enumeration; - -/** - * NetworkUtil - */ -public class NetworkUtil { - - public static int NET_CNNT_BAIDU_OK = 1; - public static int NET_CNNT_BAIDU_TIMEOUT = 2; - public static int NET_NOT_PREPARE = 3; - public static int NET_ERROR = 4; - private static int TIMEOUT = 3000; - - - /** - * isNetworkAvailable - * - * @param context - * @return - */ - public static boolean isNetworkAvailable(Context context) { - ConnectivityManager manager = (ConnectivityManager) context.getApplicationContext().getSystemService( - Context.CONNECTIVITY_SERVICE); - if (null == manager) - return false; - NetworkInfo info = manager.getActiveNetworkInfo(); - if (null == info || !info.isAvailable()) - return false; - return true; - } - - /** - * getLocalIpAddress - * - * @return - */ - public static String getLocalIpAddress() { - String ret = ""; - try { - for (Enumeration en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) { - NetworkInterface intf = en.nextElement(); - for (Enumeration enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) { - InetAddress inetAddress = enumIpAddr.nextElement(); - if (!inetAddress.isLoopbackAddress()) { - ret = inetAddress.getHostAddress().toString(); - } - } - } - } catch (SocketException ex) { - ex.printStackTrace(); - } - return ret; - } - - /** - * getNetState - * - * @param context - * @return - */ - public static int getNetState(Context context) { - try { - ConnectivityManager connectivity = (ConnectivityManager) context - .getSystemService(Context.CONNECTIVITY_SERVICE); - if (connectivity != null) { - NetworkInfo networkinfo = connectivity.getActiveNetworkInfo(); - if (networkinfo != null) { - if (networkinfo.isAvailable() && networkinfo.isConnected()) { - if (!connectionNetwork()) - return NET_CNNT_BAIDU_TIMEOUT; - else - return NET_CNNT_BAIDU_OK; - } else { - return NET_NOT_PREPARE; - } - } - } - } catch (Exception e) { - e.printStackTrace(); - } - return NET_ERROR; - } - - /** - * connectionNetwork - * - * @return - */ - static private boolean connectionNetwork() { - boolean result = false; - HttpURLConnection httpUrl = null; - try { - httpUrl = (HttpURLConnection) new URL("http://www.baidu.com") - .openConnection(); - httpUrl.setConnectTimeout(TIMEOUT); - httpUrl.connect(); - result = true; - } catch (IOException e) { - } finally { - if (null != httpUrl) { - httpUrl.disconnect(); - } - httpUrl = null; - } - return result; - } - - /** - * net is3G - * - * @param context - * @return boolean - */ - public static boolean is3G(Context context) { - ConnectivityManager connectivityManager = (ConnectivityManager) context - .getSystemService(Context.CONNECTIVITY_SERVICE); - NetworkInfo activeNetInfo = connectivityManager.getActiveNetworkInfo(); - if (activeNetInfo != null - && activeNetInfo.getType() == ConnectivityManager.TYPE_MOBILE) { - return true; - } - return false; - } - - /** - * net is Wifi - * - * @param context - * @return boolean - */ - public static boolean isWifi(Context context) { - ConnectivityManager connectivityManager = (ConnectivityManager) context - .getSystemService(Context.CONNECTIVITY_SERVICE); - NetworkInfo activeNetInfo = connectivityManager.getActiveNetworkInfo(); - if (activeNetInfo != null - && activeNetInfo.getType() == ConnectivityManager.TYPE_WIFI) { - return true; - } - return false; - } - - /** - * Net is 2G - * - * @param context - * @return boolean - */ - public static boolean is2G(Context context) { - ConnectivityManager connectivityManager = (ConnectivityManager) context - .getSystemService(Context.CONNECTIVITY_SERVICE); - NetworkInfo activeNetInfo = connectivityManager.getActiveNetworkInfo(); - if (activeNetInfo != null - && (activeNetInfo.getSubtype() == TelephonyManager.NETWORK_TYPE_EDGE - || activeNetInfo.getSubtype() == TelephonyManager.NETWORK_TYPE_GPRS || activeNetInfo - .getSubtype() == TelephonyManager.NETWORK_TYPE_CDMA)) { - return true; - } - return false; - } - - /** - * is Wifi Enabled - */ - public static boolean isWifiEnabled(Context context) { - ConnectivityManager mgrConn = (ConnectivityManager) context - .getSystemService(Context.CONNECTIVITY_SERVICE); - TelephonyManager mgrTel = (TelephonyManager) context - .getSystemService(Context.TELEPHONY_SERVICE); - return ((mgrConn.getActiveNetworkInfo() != null && mgrConn - .getActiveNetworkInfo().getState() == NetworkInfo.State.CONNECTED) || mgrTel - .getNetworkType() == TelephonyManager.NETWORK_TYPE_UMTS); - } - -} diff --git a/StatInterface/src/main/java/com/tamic/statInterface/statsdk/util/PollUtil.java b/StatInterface/src/main/java/com/tamic/statInterface/statsdk/util/PollUtil.java deleted file mode 100644 index b13f5a7..0000000 --- a/StatInterface/src/main/java/com/tamic/statInterface/statsdk/util/PollUtil.java +++ /dev/null @@ -1,66 +0,0 @@ -package com.tamic.statInterface.statsdk.util; - -import android.app.AlarmManager; -import android.app.PendingIntent; -import android.content.Context; -import android.content.Intent; -import android.os.SystemClock; - -import com.tamic.statInterface.statsdk.core.TcUploadCoreReceiver; - - -/** - * PollUtil - * Created by Tamic. - */ -public class PollUtil { - - static TcUploadCoreReceiver receiver; - - - /**startPollingService - * @param context - * @param seconds - * @param cls - * @param action - */ - public static void startPollingService(Context context, int seconds, Class cls, String action) { - - - //获取AlarmManager系统服务 - AlarmManager manager = (AlarmManager) context - .getSystemService(Context.ALARM_SERVICE); - - //包装需要执行Service的Intent - Intent intent = new Intent(context, cls); - intent.setAction(action); - PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, - intent, PendingIntent.FLAG_UPDATE_CURRENT); - /* PendingIntent pendingIntent = PendingIntent.getService(context, 0, - intent, PendingIntent.FLAG_UPDATE_CURRENT);*/ - - long triggerAtTime = SystemClock.elapsedRealtime(); - - - manager.setRepeating(AlarmManager.ELAPSED_REALTIME, triggerAtTime, - seconds * 1000, pendingIntent); - } - - /** - * stopPollingService - * @param context - * @param cls - * @param action - */ - public static void stopPollingService(Context context, Class cls, String action) { - AlarmManager manager = (AlarmManager) context - .getSystemService(Context.ALARM_SERVICE); - Intent intent = new Intent(context, cls); - intent.setAction(action); - PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, - intent, PendingIntent.FLAG_UPDATE_CURRENT); - - manager.cancel(pendingIntent); - - } -} diff --git a/StatInterface/src/main/java/com/tamic/statInterface/statsdk/util/StatLog.java b/StatInterface/src/main/java/com/tamic/statInterface/statsdk/util/StatLog.java deleted file mode 100644 index 43020ac..0000000 --- a/StatInterface/src/main/java/com/tamic/statInterface/statsdk/util/StatLog.java +++ /dev/null @@ -1,417 +0,0 @@ - -package com.tamic.statInterface.statsdk.util; - -import android.os.Environment; -import android.util.Log; - - -import com.tamic.statInterface.statsdk.constants.StaticsConfig; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; - -/** - * LOG工具类 - */ -public final class StatLog { - /** 调试总开关 */ - private static boolean sDebug = StaticsConfig.DEBUG; - /** Log TAG */ - public static final String LOG_TAG = "StatLog"; - /** DEBUG调试开关 */ - public static final boolean DEBUG_DEBUG = true; - /** E RROR调试开关 */ - public static final boolean DEBUG_ERROR = true; - /** performance调试开关 */ - public static final boolean DEBUG_PERFORMENCE = true; - /** INFO调试开关 */ - public static final boolean DEBUG_INFO = true; - /** VERBOSE调试开关 */ - public static final boolean DEBUG_VERBOSE = true; - /** WARN调试开关 */ - public static final boolean DEBUG_WARN = true; - /** EXCEPTION调试开关 */ - public static final boolean DEBUG_EXCEPT = true; - /** 输出Stream **/ - private static FileOutputStream mOutfilestream; - /*** logcat stream */ - private static FileOutputStream mLogcaOutfilestream; - /** 保存log开关 */ - private static boolean mIsLogToFile = false; - /** folder name */ - private static String mFolderName = Environment.getExternalStorageDirectory() + File.separator + "TaStatSdk" - + File.separator + "StatLog" + File.separator + "log" + File.separator; - /** log file name */ - private static String mLogFileName = mFolderName + "TamicStatStat_log.txt"; - /** 当前log */ - private static String mLogFileNameLogcat = mFolderName + "TamicStat_lasttime_log.txt"; - - /** - * LogLevel - */ - private enum LogLevel { - /** DEBUG Level */ - DEBUG, - /** ERROR Level */ - ERROR, - /** INFO Level */ - INFO, - /** VERBOSE Level */ - VERBOSE, - /** WARN Level */ - WARN - } - - /** - * Constructor - */ - private StatLog() { - } - - /** - * 设置debug开关 - * - * @param aDebug - * true打开,false关闭 - */ - public static void setDebug(boolean aDebug) { - sDebug = aDebug; - } - - /** - * @return is BuildConfig.DEBUG - */ - public static boolean isDebug(){ - return sDebug; - } - - public static void d(String aTag, String aMessage) { - if (sDebug && DEBUG_DEBUG) { - doLog(LogLevel.DEBUG, aTag, aMessage, null); - } - } - - - public static void d(String aMessage) { - if (sDebug && DEBUG_DEBUG) { - doLog(LogLevel.DEBUG, LOG_TAG, aMessage, null); - } - } - - - - public static void d(String aMessage, Throwable aThrow) { - if (sDebug && DEBUG_DEBUG) { - doLog(LogLevel.DEBUG, LOG_TAG, aMessage, aThrow); - } - } - - - public static void d(String aTag, String aMessage, Throwable aThrow) { - if (sDebug && DEBUG_DEBUG) { - doLog(LogLevel.DEBUG, aTag, aMessage, aThrow); - } - } - - public static void p(String aMessage) { - if (sDebug && DEBUG_PERFORMENCE) { - doLog(LogLevel.DEBUG, LOG_TAG, aMessage, null); - } - } - - - public static void p(String aTag, String aMessage) { - if (sDebug && DEBUG_PERFORMENCE) { - doLog(LogLevel.DEBUG, aTag, aMessage, null); - } - } - - - public static void e(String aTag, String aMessage) { - if (DEBUG_ERROR) { - doLog(LogLevel.ERROR, aTag, aMessage, null); - } - } - - - public static void e(String aMessage) { - if (DEBUG_ERROR) { - doLog(LogLevel.ERROR, LOG_TAG, aMessage, null); - } - } - - - public static void e(String aMessage, Throwable aThrow) { - if (DEBUG_ERROR) { - doLog(LogLevel.ERROR, LOG_TAG, aMessage, aThrow); - } - } - - - @SuppressWarnings("unused") - public static void i(String aTag, String aMessage) { - if (sDebug && DEBUG_INFO) { - doLog(LogLevel.INFO, aTag, aMessage, null); - } - } - - - @SuppressWarnings("unused") - public static void i(String aMessage) { - if (sDebug && DEBUG_INFO) { - doLog(LogLevel.INFO, LOG_TAG, aMessage, null); - } - } - - - @SuppressWarnings("unused") - public static void i(String aMessage, Throwable aThrow) { - if (sDebug && DEBUG_INFO) { - doLog(LogLevel.INFO, LOG_TAG, aMessage, aThrow); - } - } - - - @SuppressWarnings("unused") - public static void v(String aTAG, String aMessage) { - if (sDebug && DEBUG_VERBOSE) { - doLog(LogLevel.VERBOSE, aTAG, aMessage, null); - } - } - - - @SuppressWarnings("unused") - public static void v(String aMessage) { - if (sDebug && DEBUG_VERBOSE) { - doLog(LogLevel.VERBOSE, LOG_TAG, aMessage, null); - } - } - - - @SuppressWarnings("unused") - public static void v(String aMessage, Throwable aThrow) { - if (sDebug && DEBUG_VERBOSE) { - doLog(LogLevel.VERBOSE, LOG_TAG, aMessage, aThrow); - } - } - - - public static void w(String aMessage) { - if (sDebug && DEBUG_WARN) { - doLog(LogLevel.WARN, LOG_TAG, aMessage, null); - } - } - - - public static void w(String aTag, String aMessage) { - if (sDebug && DEBUG_WARN) { - doLog(LogLevel.WARN, aTag, aMessage, null); - } - } - - - public static void w(String aTag, String aMessage, Throwable aThrow) { - if (sDebug && DEBUG_WARN) { - doLog(LogLevel.WARN, aTag, aMessage, aThrow); - } - } - - public static void w(String aMessage, Throwable aThrow) { - if (sDebug && DEBUG_WARN) { - doLog(LogLevel.WARN, LOG_TAG, aMessage, aThrow); - } - } - - public static void printStackTrace(Exception aException) { - if (sDebug && DEBUG_EXCEPT) { - aException.printStackTrace(); - } - } - - private static void doLog(LogLevel aLevel, String aTag, String aMessage, Throwable aThrow) { - - if (aMessage == null) { - aMessage = ""; - } - - switch (aLevel) { - case DEBUG: - if (aThrow == null) { - Log.d(aTag, aMessage); - } else { - Log.d(aTag, aMessage, aThrow); - } - break; - case ERROR: - if (aThrow == null) { - Log.e(aTag, aMessage); - } else { - Log.e(aTag, aMessage, aThrow); - } - break; - case INFO: - if (aThrow == null) { - Log.i(aTag, aMessage); - } else { - Log.i(aTag, aMessage, aThrow); - } - break; - case VERBOSE: - if (aThrow == null) { - Log.v(aTag, aMessage); - } else { - Log.v(aTag, aMessage, aThrow); - } - break; - case WARN: - if (aThrow == null) { - Log.w(aTag, aMessage); - } else { - Log.w(aTag, aMessage, aThrow); - } - break; - default: - break; - } - - if (mIsLogToFile) { - flushToFile(aTag, aMessage); - } - - } - - - public static void dumpLogcat() { - - BufferedReader localBufferedReader = null; - try { - - if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { - return; - } - - File folder = new File(mFolderName); - - if (!folder.exists()) { - folder.mkdirs(); - // myFile.createNewFile(); - } - - if (null == mLogcaOutfilestream) { - mLogcaOutfilestream = new FileOutputStream(mLogFileNameLogcat); - } - - Process localProcess = Runtime.getRuntime().exec("logcat -v time -d"); - InputStream localInputStream = localProcess.getInputStream(); - InputStreamReader localInputStreamReader = new InputStreamReader(localInputStream); - localBufferedReader = new BufferedReader(localInputStreamReader); - - for (String str1 = localBufferedReader.readLine(); str1 != null; str1 = localBufferedReader - .readLine()) { - mLogcaOutfilestream.write(str1.getBytes("UTF-8")); - mLogcaOutfilestream.write("\n".getBytes()); - - } - } catch (Exception e) { - e.printStackTrace(); - } finally { - try { - if (localBufferedReader != null) { - localBufferedReader.close(); - } - if (mLogcaOutfilestream != null) { - mLogcaOutfilestream.close(); - mLogcaOutfilestream = null; - } - } catch (IOException e) { - e.printStackTrace(); - } - } - - } - - - private static void flushToFile(String aTag, String aMessage) { - - if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { - return; - } - - try { - - File folder = new File(mFolderName); - - if (!folder.exists()) { - folder.mkdirs(); - // myFile.createNewFile(); - } - - if (null == mOutfilestream) { - mOutfilestream = new FileOutputStream(mLogFileName); - } - String output = aTag + " : " + aMessage; - mOutfilestream.write(output.getBytes("UTF-8")); - mOutfilestream.write("\n".getBytes()); - } catch (Exception e) { - e.printStackTrace(); - } - - } - - public static void setWriteToFile(boolean bWritetoFile) { - mIsLogToFile = bWritetoFile; - } - - - public static void logException(String aTag, Exception aException) { - try { - if (null == aException) { - return; - } - - if (sDebug) { - aException.printStackTrace(); - } - - StatLog.d(aTag, "========================= Exception Happened !!================================"); - - StatLog.d(aTag, aException.getMessage()); - StackTraceElement[] stack = aException.getStackTrace(); - // if (null == stack) { //FindBugs - // return; - // } - for (int i = 0; i < stack.length; i++) { - StatLog.d(aTag, stack[i].toString()); - - } - - StatLog.d(aTag, "========================= Exception Ended !!================================"); - - } catch (Exception ex) { - ex.printStackTrace(); - } - - } - - - public static void printInvokeTrace(String aTag) { - StackTraceElement[] stackTrace = (new Throwable()).getStackTrace(); - for (int i = 1; i < stackTrace.length; i++) { - StatLog.d(aTag + ": " + stackTrace[i].toString()); - } - } - - - public static void printInvokeTrace(String aTag, int aMax) { - StackTraceElement[] stackTrace = (new Throwable()).getStackTrace(); - int n = Math.min(aMax, stackTrace.length); - for (int i = 1; i < n; i++) { - StatLog.d(aTag + ": " + stackTrace[i].toString()); - } - } - -} diff --git a/StatInterface/src/main/res/values/strings.xml b/StatInterface/src/main/res/values/strings.xml deleted file mode 100644 index efe4a3a..0000000 --- a/StatInterface/src/main/res/values/strings.xml +++ /dev/null @@ -1,3 +0,0 @@ - - statLibrary - diff --git a/app/build.gradle b/app/build.gradle index a6a933d..613a549 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -19,8 +19,7 @@ release { } } - dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) - compile project(':StatInterface') + compile 'com.tamic:StatInterface:2.1' } diff --git a/app/src/main/java/com/tamic/statsdkdemo/MainActivity.java b/app/src/main/java/com/tamic/statsdkdemo/MainActivity.java index 36be676..6db90f4 100644 --- a/app/src/main/java/com/tamic/statsdkdemo/MainActivity.java +++ b/app/src/main/java/com/tamic/statsdkdemo/MainActivity.java @@ -6,6 +6,8 @@ import com.tamic.statInterface.statsdk.core.TcStatInterface; +import java.util.HashMap; + public class MainActivity extends BaseActivity { @@ -29,7 +31,11 @@ public void onClick(View v) { public void onClick(View v) { // test - TcStatInterface.onEventParameter("onclick", "open next"); + HashMap map = new HashMap(); + map.put("id1", "xxx"); + map.put("id2", "yyyy"); + + TcStatInterface.onEvent("open next", map); Intent intent = new Intent(MainActivity.this, SecondActivity.class); startActivity(intent); diff --git a/app/src/main/java/com/tamic/statsdkdemo/imp/StaticsImpl.java b/app/src/main/java/com/tamic/statsdkdemo/imp/StaticsImpl.java deleted file mode 100644 index 5ddf6a0..0000000 --- a/app/src/main/java/com/tamic/statsdkdemo/imp/StaticsImpl.java +++ /dev/null @@ -1,55 +0,0 @@ -package com.tamic.statsdkdemo.imp; - -import android.content.Context; - -import com.alibaba.fastjson.JSON; -import com.tamic.statInterface.statsdk.core.StaticsListener; - -import java.io.InputStream; -import java.util.HashMap; - -import cz.msebera.android.httpclient.util.EncodingUtils; - -/** - * Created by Tmaic on 2016-04-13. - */ -public class StaticsImpl implements StaticsListener { - - - - String json; - - private Context context; - - - public StaticsImpl(Context context) { - this.context = context; - } - - @Override - public HashMap getStatIdMaps() { - - - HashMap map = null; - if (getFromAsset("stat_id.json") != null) { - map = (HashMap) JSON.parseObject(getFromAsset("stat_id.json"), HashMap.class); - } - return map; - } - - public String getFromAsset(String fileName){ - String result=""; - try{ - InputStream in = context.getResources().getAssets().open(fileName); - int length = in.available(); - byte [] buffer = new byte[length]; - in.read(buffer); - result = EncodingUtils.getString(buffer, "UTF-8"); - } - catch(Exception e){ - e.printStackTrace(); - } - return result; - } - -} diff --git a/settings.gradle b/settings.gradle index a85f5f3..e7b4def 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1 +1 @@ -include ':app' ,':StatInterface' +include ':app'