Skip to content

Commit 9a6ae29

Browse files
committed
Initial commit
0 parents  commit 9a6ae29

File tree

84 files changed

+5965
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+5965
-0
lines changed

.gitignore

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
*.iml
2+
.gradle
3+
.idea
4+
/local.properties
5+
.DS_Store
6+
/build
7+
/captures
8+
.externalNativeBuild

app/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

app/build.gradle

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
apply plugin: 'com.android.application'
2+
3+
android {
4+
compileSdkVersion 25
5+
buildToolsVersion "25.0.0"
6+
defaultConfig {
7+
applicationId "org.yh.yhframe"
8+
minSdkVersion 19
9+
targetSdkVersion 25
10+
versionCode 1
11+
versionName "1.0"
12+
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
13+
}
14+
buildTypes {
15+
release {
16+
minifyEnabled false
17+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18+
}
19+
}
20+
}
21+
22+
dependencies {
23+
compile fileTree(include: ['*.jar'], dir: 'libs')
24+
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
25+
exclude group: 'com.android.support', module: 'support-annotations'
26+
})
27+
compile 'com.android.support:appcompat-v7:25.3.1'
28+
compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha7'
29+
testCompile 'junit:junit:4.12'
30+
compile project(':yhlibrary')
31+
}

app/proguard-rules.pro

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Add project specific ProGuard rules here.
2+
# By default, the flags in this file are appended to flags specified
3+
# in /Users/yhlyl/java/android-sdk-macosx/tools/proguard/proguard-android.txt
4+
# You can edit the include path and order by changing the proguardFiles
5+
# directive in build.gradle.
6+
#
7+
# For more details, see
8+
# http://developer.android.com/guide/developing/tools/proguard.html
9+
10+
# Add any project specific keep options here:
11+
12+
# If your project uses WebView with JS, uncomment the following
13+
# and specify the fully qualified class name to the JavaScript interface
14+
# class:
15+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16+
# public *;
17+
#}
18+
19+
# Uncomment this to preserve the line number information for
20+
# debugging stack traces.
21+
#-keepattributes SourceFile,LineNumberTable
22+
23+
# If you keep the line number information, uncomment this to
24+
# hide the original source file name.
25+
#-renamesourcefileattribute SourceFile
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package org.yh.yhframe;
2+
3+
import android.content.Context;
4+
import android.support.test.InstrumentationRegistry;
5+
import android.support.test.runner.AndroidJUnit4;
6+
7+
import org.junit.Test;
8+
import org.junit.runner.RunWith;
9+
10+
import static org.junit.Assert.*;
11+
12+
/**
13+
* Instrumentation test, which will execute on an Android device.
14+
*
15+
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
16+
*/
17+
@RunWith(AndroidJUnit4.class)
18+
public class ExampleInstrumentedTest
19+
{
20+
@Test
21+
public void useAppContext() throws Exception
22+
{
23+
// Context of the app under test.
24+
Context appContext = InstrumentationRegistry.getTargetContext();
25+
26+
assertEquals("org.yh.yhframe", appContext.getPackageName());
27+
}
28+
}

app/src/main/AndroidManifest.xml

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="org.yh.yhframe">
4+
5+
<application
6+
android:name=".MyApplication"
7+
android:allowBackup="true"
8+
android:icon="@mipmap/ic_launcher"
9+
android:label="@string/app_name"
10+
android:roundIcon="@mipmap/ic_launcher_round"
11+
android:supportsRtl="true"
12+
android:theme="@style/AppTheme">
13+
<activity android:name=".MainActivity">
14+
<intent-filter>
15+
<action android:name="android.intent.action.MAIN"/>
16+
17+
<category android:name="android.intent.category.LAUNCHER"/>
18+
</intent-filter>
19+
</activity>
20+
</application>
21+
22+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package org.yh.yhframe;
2+
3+
import android.support.v7.app.AppCompatActivity;
4+
import android.os.Bundle;
5+
6+
public class MainActivity extends AppCompatActivity
7+
{
8+
9+
@Override
10+
protected void onCreate(Bundle savedInstanceState)
11+
{
12+
super.onCreate(savedInstanceState);
13+
setContentView(R.layout.activity_main);
14+
}
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,219 @@
1+
package org.yh.yhframe;
2+
3+
import android.app.Application;
4+
import android.content.Context;
5+
import android.graphics.Bitmap;
6+
import android.os.Build;
7+
import android.os.Handler;
8+
9+
import com.nostra13.universalimageloader.cache.disc.naming.HashCodeFileNameGenerator;
10+
import com.nostra13.universalimageloader.cache.memory.impl.LruMemoryCache;
11+
import com.nostra13.universalimageloader.core.DisplayImageOptions;
12+
import com.nostra13.universalimageloader.core.ImageLoader;
13+
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
14+
import com.nostra13.universalimageloader.core.assist.ImageScaleType;
15+
import com.nostra13.universalimageloader.core.assist.QueueProcessingType;
16+
import com.nostra13.universalimageloader.core.decode.BaseImageDecoder;
17+
import com.nostra13.universalimageloader.core.download.BaseImageDownloader;
18+
19+
import org.yh.library.db.YhDBManager;
20+
import org.yh.library.okhttp.OkHttpUtils;
21+
import org.yh.library.okhttp.https.HttpsUtils;
22+
import org.yh.library.okhttp.utils.LoggerInterceptor;
23+
import org.yh.library.utils.Constants;
24+
import org.yh.library.utils.CrashHandler;
25+
import org.yh.library.utils.LogUtils;
26+
import org.yh.library.utils.YHUtils;
27+
28+
import java.util.concurrent.TimeUnit;
29+
30+
import javax.net.ssl.HostnameVerifier;
31+
import javax.net.ssl.SSLSession;
32+
33+
import okhttp3.OkHttpClient;
34+
35+
/**
36+
* @author hao
37+
* @version 1.0
38+
* @ClassName: MyApplication<br/>
39+
* @Description: MyApplication<br/>
40+
* @date: 2015-6-17 下午5:00:20 <br/>
41+
* @since JDK 1.7
42+
*/
43+
public class MyApplication extends Application
44+
{
45+
private static final String TAG = "MyApplication";
46+
private static MyApplication mInstance = null;
47+
SendEmailThread sendEmail;
48+
public static int width = 1080;
49+
public static int height = 960;
50+
private Handler mHandler = new Handler();
51+
@Override
52+
public void onCreate()
53+
{
54+
super.onCreate();
55+
mInstance = this;
56+
width = YHUtils.getScreenWidth(MyApplication.getInstance()
57+
.getApplicationContext());
58+
height = YHUtils.getScreenHeight(MyApplication.getInstance()
59+
.getApplicationContext());
60+
if (width == 0)
61+
{
62+
width = 1080;
63+
}
64+
65+
if (height == 0)
66+
{
67+
height = 960;
68+
}
69+
70+
LogUtils.e(TAG, "onCreate() height:" + height + " width:" + width );
71+
mHandler.postDelayed(new Runnable()
72+
{
73+
74+
@Override
75+
public void run()
76+
{
77+
initSystem();
78+
}
79+
}, 500);
80+
LogUtils.e("MyApplication:", "onCreate()" + Build.CPU_ABI + " " + Build.CPU_ABI2);
81+
}
82+
83+
public synchronized static MyApplication getInstance()
84+
{
85+
return mInstance;
86+
}
87+
88+
/**
89+
* 初始化系统信息
90+
*/
91+
public void initSystem()
92+
{
93+
94+
if (!YHUtils.isEmpty(mInstance))
95+
{
96+
97+
98+
// 图片缓存框架初始化
99+
initImageLoader(mInstance);
100+
// 网络框架初始化
101+
initHttp();
102+
//根据不同的用户生成不同的数据库
103+
Constants.Config.yhDBManager = YhDBManager.getInstance(mInstance,"yh.db",true);
104+
}
105+
// 发布BUG用邮件形式发送
106+
CrashHandler.create(getApplicationContext());
107+
sendEmail = new SendEmailThread();
108+
sendEmail.start();
109+
110+
}
111+
112+
// 初始化OKHTTP
113+
public static void initHttp()
114+
{
115+
HttpsUtils.SSLParams sslParams = HttpsUtils.getSslSocketFactory(null,
116+
null, null);
117+
OkHttpClient okHttpClient = new OkHttpClient.Builder()
118+
.connectTimeout(60000L, TimeUnit.MILLISECONDS)
119+
.readTimeout(60000L, TimeUnit.MILLISECONDS)
120+
.addInterceptor(new LoggerInterceptor(""))
121+
.hostnameVerifier(new HostnameVerifier()
122+
{
123+
@Override
124+
public boolean verify(String hostname, SSLSession session)
125+
{
126+
return true;
127+
}
128+
})
129+
.sslSocketFactory(sslParams.sSLSocketFactory,
130+
sslParams.trustManager).build();
131+
OkHttpUtils.initClient(okHttpClient);
132+
}
133+
134+
// 初始化缓存框架
135+
public static void initImageLoader(Context context)
136+
{
137+
138+
DisplayImageOptions imageOptions = new DisplayImageOptions.Builder()
139+
.showImageOnLoading(R.mipmap.ic_launcher)//加载中图片
140+
.showImageForEmptyUri(R.mipmap.ic_launcher)//加载空URL图片
141+
.showImageOnFail(R.mipmap.ic_launcher)//加载错误图片
142+
.cacheInMemory(false).cacheOnDisk(false)
143+
.imageScaleType(ImageScaleType.EXACTLY)
144+
.resetViewBeforeLoading(true).considerExifParams(false)
145+
.bitmapConfig(Bitmap.Config.RGB_565).build();
146+
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context)
147+
.memoryCacheExtraOptions(width, height)
148+
// default = device screen dimensions
149+
.diskCacheExtraOptions(width, height, null)
150+
.threadPoolSize(5)
151+
// default Thread.NORM_PRIORITY - 1
152+
.threadPriority(Thread.NORM_PRIORITY)
153+
// default FIFO
154+
.tasksProcessingOrder(QueueProcessingType.LIFO)
155+
// default
156+
.denyCacheImageMultipleSizesInMemory()
157+
.memoryCache(new LruMemoryCache(2 * 1024 * 1024))
158+
.memoryCacheSize(2 * 1024 * 1024)
159+
.memoryCacheSizePercentage(13)
160+
// default// 文件路径
161+
// .diskCache(
162+
// new UnlimitedDiskCache(StorageUtils
163+
// .getOwnCacheDirectory(context,
164+
// AppConfig.imgCachePath)))
165+
.diskCacheFileNameGenerator(new HashCodeFileNameGenerator())
166+
// default// connectTimeout (20 s), readTimeout (60 s)超时时间
167+
.imageDownloader(new BaseImageDownloader(context, 20 * 1000, 60 * 1000))
168+
// default
169+
.imageDecoder(new BaseImageDecoder(false))
170+
// default
171+
.defaultDisplayImageOptions(DisplayImageOptions.createSimple())
172+
// default
173+
.defaultDisplayImageOptions(imageOptions) // Log日志
174+
.build();
175+
ImageLoader.getInstance().init(config);
176+
}
177+
178+
/**
179+
* 发送邮件线程
180+
*
181+
* @author youhao
182+
*/
183+
private class SendEmailThread extends Thread
184+
{
185+
@Override
186+
public void run()
187+
{
188+
super.run();
189+
190+
//SystemUtils.sendLogEmail();
191+
}
192+
}
193+
194+
// 杀进程
195+
@Override
196+
public void onLowMemory()
197+
{
198+
super.onLowMemory();
199+
LogUtils.e(TAG, "onLowMemory()");
200+
}
201+
202+
@Override
203+
public void onTerminate()
204+
{
205+
// 程序终止的时候执行
206+
super.onTerminate();
207+
System.exit(1);
208+
LogUtils.e(TAG, "onTerminate()");
209+
}
210+
211+
@Override
212+
public void onTrimMemory(int level)
213+
{
214+
// 程序在内存清理的时候执行
215+
super.onTrimMemory(level);
216+
LogUtils.e(TAG, "内存清理():" + level + "");
217+
}
218+
219+
}
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<android.support.constraint.ConstraintLayout
3+
xmlns:android="http://schemas.android.com/apk/res/android"
4+
xmlns:app="http://schemas.android.com/apk/res-auto"
5+
xmlns:tools="http://schemas.android.com/tools"
6+
android:layout_width="match_parent"
7+
android:layout_height="match_parent"
8+
tools:context="org.yh.yhframe.MainActivity">
9+
10+
<TextView
11+
android:layout_width="wrap_content"
12+
android:layout_height="wrap_content"
13+
android:text="Hello World!"
14+
app:layout_constraintBottom_toBottomOf="parent"
15+
app:layout_constraintLeft_toLeftOf="parent"
16+
app:layout_constraintRight_toRightOf="parent"
17+
app:layout_constraintTop_toTopOf="parent"/>
18+
19+
</android.support.constraint.ConstraintLayout>
3.34 KB
Loading
Loading
2.15 KB
Loading
Loading
4.73 KB
Loading
Loading
7.54 KB
Loading
Loading
10.2 KB
Loading
Loading

app/src/main/res/values/colors.xml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
<color name="colorPrimary">#3F51B5</color>
4+
<color name="colorPrimaryDark">#303F9F</color>
5+
<color name="colorAccent">#FF4081</color>
6+
</resources>

app/src/main/res/values/strings.xml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<resources>
2+
<string name="app_name">YhLibraryForAndroid</string>
3+
</resources>

0 commit comments

Comments
 (0)