diff --git a/.gitignore b/.gitignore
index bcf9aec..51df8ea 100644
--- a/.gitignore
+++ b/.gitignore
@@ -31,3 +31,4 @@ build
*.ipr
*~
*.swp
+.DS_Store
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..78a0eaa
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,15 @@
+language: android
+android:
+ components:
+ # Uncomment the lines below if you want to
+ # use the latest revision of Android SDK Tools
+ # - platform-tools
+ # - tools
+
+ # The BuildTools version used by your project
+ - tools
+ - build-tools-23.0.2
+
+ # The SDK version used to compile your project
+ - android-23
+ - extra-android-m2repository
diff --git a/README-cn.md b/README-cn.md
new file mode 100644
index 0000000..2b151f5
--- /dev/null
+++ b/README-cn.md
@@ -0,0 +1,123 @@
+# LessCode [](https://bintray.com/openproject/maven/lesscode) [](https://travis-ci.org/openproject/LessCode)
+
+打造精简、高效的最好Android工具库!
+
+## Overview
+
+> * 大量比原生更便捷的方法
+> * 高性能
+> * 易于集成
+> * 小体积 (60k+,开启混淆后更小)
+> * 开源
+
+## Gradle
+
+```groovy
+implementation 'com.jayfeng:lesscode-core:2.4.2'
+```
+
+## Features
+|源码|备注|
+|-------|-------|
+|ActivityLess|Activity相关辅助类:去标题,全屏,两次退出提示,优化Overdraw背景等|
+|AdapterLess|打造通用的BaseAdapter,PagerAdapter,RecyclerView.Adapter等|
+|AlarmLess|定时器相关|
+|AppLess|获取应用版本,名称,签名,清理缓存等|
+|BitmapLess|Bitmap处理相关|
+|CacheLess|缓存网络请求返回的json|
+|DeviceLess|获取设备信息,比如mac|
+|DisplayLess|屏幕相关,比如dp和px的转换,状态栏或者标题栏的高度,dpi判断|
+|DrawableLess|通用的着色方案|
+|EncodeLess|md5加密|
+|FileLess|文件处理相关|
+|HttpLess|简单的Http工具类,如果是专业用途还是用其他更强大的第三方库吧|
+|ImageLess|图片相关|
+|KeyBoardLess|输入法的弹出或隐藏|
+|LogLess|强大的Log库|
+|NetworkLess|网络判断|
+|ResourceLess|根据资源名获取ID|
+|SerializeLess|序列化和反序列化|
+|SharedPreferenceLess|简化和增强SharedPreference的操作|
+|StorageLess|手机存储相关,包括:手机内存,内置存储卡(Sdcard),外置存储卡(ExtSdcard)|
+|ToastLess|简化Toast的使用|
+|UpdateLess/UpdateService|简单但完整的自动更新实现,无缝对接(已分离到LessCode-Update项目)|
+|ViewLess|简化繁琐的findViewById和强制转换|
+
+## Usage
+
+####Config
+* Required
+```java
+$.getInstance()
+ .context(getApplicationContext())
+ .build();
+```
+
+* Optional
+```java
+$.getInstance()
+ .context(getApplicationContext())
+ .log(BuildConfig.DEBUG, "LESSCODE") // LogLess - debug, tag
+ .update(null, 5) // UpdateLess - null means the default value, 5 is the notification frequent, default is 5
+ .http(5000, 5000) // HttpLess - default connect and read timeout
+ .build();
+```
+
+####Android VS LessCode
+
+* ViewLess
+```java
+// 强制转化View类型
+// Before
+ListView listView = (ListView) findViewById(R.id.list);
+// After
+ListView listView = ViewLess.$(this, R.id.list);
+```
+
+* ActivityLess
+```java
+// 无标题全屏
+// Before
+requestWindowFeature(Window.FEATURE_NO_TITLE);
+getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
+ activity.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
+ WindowManager.LayoutParams.FLAG_FULLSCREEN);
+// After
+ActivityLess.$noTitle(this);
+ActivityLess.$fullScreen(this);
+```
+
+## Proguard
+```
+-dontwarn com.jayfeng.lesscode.**
+```
+
+See more details on the [Wiki](https://github.com/openproject/LessCode/wiki)
+
+## Alternative libraries
+* [xUtils3](https://github.com/wyouflf/xUtils3)
+* [LiteCommon](https://github.com/litesuits/android-common)
+* [TrineaAndroidCommon](https://github.com/Trinea/android-common)
+* [AndroidUtils](https://github.com/jingle1267/android-utils)
+
+## Author
+
+> Author weibo:冯建V mail:673592063@qq.com QQ:673592063
+
+## License
+
+```
+Copyright (C) LessCode Open Source Project
+
+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.
+```
diff --git a/README.md b/README.md
index de36b9c..c5f87c8 100644
--- a/README.md
+++ b/README.md
@@ -1,29 +1,55 @@
-LessCode - Less Code For Android
-================================
-Less code, more efficient for android
+#### [中文版文档](https://github.com/openproject/LessCode/blob/master/README-cn.md)
-> Author weibo:冯建V mail:673592063@qq.com QQ:673592063
+[](https://bintray.com/openproject/maven/lesscode)
+[](https://travis-ci.org/openproject/LessCode)
+[![MethodCount][methodcount-svg]][methodcount-link]
+
+# LessCode
+less code, more efficient for android, for the best android tools library!
+
+## Overview
+
+> * support more effective methods than android
+> * high performence
+> * easy integration
+> * small size (only 45k~ by proguard)
+> * open source
+
+## Gradle
-Main freatures
-------
-* support many more simpler method than android
-* high performence
-* easy integrate
-* very small (less than 100k, only 60k+ now)
-* open source
-
-Gradle
-------
-core version:
```groovy
-compile('com.jayfeng:lesscode-core:0.4.2') {
- // exclusion for update the android support jar (for example, you can use the appcompat-v7 in your project)
- exclude group: 'com.android.support', module: 'support-v4'
-}
+implementation 'com.jayfeng:lesscode-core:2.4.2'
```
-Usage
--------
+## Features
+|源码|备注|
+|-------|-------|
+|ActivityLess|Activity相关辅助类:去标题,全屏,两次退出提示,优化Overdraw背景等|
+|AdapterLess|打造通用的BaseAdapter,PagerAdapter,RecyclerView.Adapter等|
+|AlarmLess|定时器相关|
+|AppLess|获取应用版本,名称,签名,清理缓存等|
+|BitmapLess|Bitmap处理相关|
+|CacheLess|缓存网络请求返回的json|
+|DeviceLess|获取设备信息,比如mac|
+|DisplayLess|屏幕相关,比如dp和px的转换,状态栏或者标题栏的高度,dpi判断|
+|DrawableLess|通用的着色方案|
+|EncodeLess|md5加密|
+|FileLess|文件处理相关|
+|HttpLess|简单的Http工具类,如果是专业用途还是用其他更强大的第三方库吧|
+|ImageLess|图片相关|
+|KeyBoardLess|输入法的弹出或隐藏|
+|LogLess|强大的Log库|
+|NetworkLess|网络判断|
+|ResourceLess|根据资源名获取ID|
+|SerializeLess|序列化和反序列化|
+|SharedPreferenceLess|简化和增强SharedPreference的操作|
+|StorageLess|手机存储相关,包括:手机内存,内置存储卡(Sdcard),外置存储卡(ExtSdcard)|
+|ToastLess|简化Toast的使用|
+|UpdateLess/UpdateService|简单但完整的自动更新实现,无缝对接(已分离到LessCode-Update项目)|
+|ViewLess|简化繁琐的findViewById和强制转换|
+
+## Usage
+
####Config
* Required
```java
@@ -66,4 +92,39 @@ ActivityLess.$noTitle(this);
ActivityLess.$fullScreen(this);
```
-See more details on the [WIKI](https://github.com/openproject/LessCode/wiki)
+## Proguard
+```
+-dontwarn com.jayfeng.lesscode.**
+```
+
+See more details on the [Wiki](https://github.com/openproject/LessCode/wiki)
+
+## Alternative libraries
+* [xUtils3](https://github.com/wyouflf/xUtils3)
+* [LiteCommon](https://github.com/litesuits/android-common)
+* [TrineaAndroidCommon](https://github.com/Trinea/android-common)
+* [AndroidUtils](https://github.com/jingle1267/android-utils)
+
+## Author
+
+> Author weibo:冯建V mail:673592063@qq.com QQ:673592063
+
+## License
+
+```
+Copyright (C) LessCode Open Source Project
+
+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.
+```
+[methodcount-svg]: https://img.shields.io/badge/Methodscount-717-e91e63.svg
+[methodcount-link]: http://www.methodscount.com/?lib=com.jayfeng%3Alesscode-core%3A0.9.6.1
diff --git a/app-ref-lesscode-core/.gitignore b/app-ref-lesscode-core/.gitignore
deleted file mode 100644
index 796b96d..0000000
--- a/app-ref-lesscode-core/.gitignore
+++ /dev/null
@@ -1 +0,0 @@
-/build
diff --git a/app-ref-lesscode-core/build.gradle b/app-ref-lesscode-core/build.gradle
deleted file mode 100644
index 232cf73..0000000
--- a/app-ref-lesscode-core/build.gradle
+++ /dev/null
@@ -1,28 +0,0 @@
-apply plugin: 'com.android.application'
-
-android {
- compileSdkVersion 21
- buildToolsVersion "21.1.2"
-
- defaultConfig {
- applicationId "com.jayfeng.lesscode.app.ref.lesscodecore"
- minSdkVersion 9
- targetSdkVersion 21
- 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 'com.android.support:appcompat-v7:22.1.1'
- compile('com.jayfeng:lesscode-core:0.6') {
- exclude group: 'com.android.support', module: 'support-v4'
- }
-}
diff --git a/app-ref-lesscode-core/proguard-rules.pro b/app-ref-lesscode-core/proguard-rules.pro
deleted file mode 100644
index 3ffecd2..0000000
--- a/app-ref-lesscode-core/proguard-rules.pro
+++ /dev/null
@@ -1,17 +0,0 @@
-# Add project specific ProGuard rules here.
-# By default, the flags in this file are appended to flags specified
-# in /home/jay/tools/android-sdk/tools/proguard/proguard-android.txt
-# You can edit the include path and order by changing the proguardFiles
-# directive in build.gradle.
-#
-# For more details, see
-# http://developer.android.com/guide/developing/tools/proguard.html
-
-# Add any project specific keep options here:
-
-# If your project uses WebView with JS, uncomment the following
-# and specify the fully qualified class name to the JavaScript interface
-# class:
-#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
-# public *;
-#}
diff --git a/app-ref-lesscode-core/src/androidTest/java/com/jayfeng/lesscode/app/ref/lesscodecore/ApplicationTest.java b/app-ref-lesscode-core/src/androidTest/java/com/jayfeng/lesscode/app/ref/lesscodecore/ApplicationTest.java
deleted file mode 100644
index 2a9b149..0000000
--- a/app-ref-lesscode-core/src/androidTest/java/com/jayfeng/lesscode/app/ref/lesscodecore/ApplicationTest.java
+++ /dev/null
@@ -1,13 +0,0 @@
-package com.jayfeng.lesscode.app.ref.lesscodecore;
-
-import android.app.Application;
-import android.test.ApplicationTestCase;
-
-/**
- * Testing Fundamentals
- */
-public class ApplicationTest extends ApplicationTestCase {
- public ApplicationTest() {
- super(Application.class);
- }
-}
\ No newline at end of file
diff --git a/app-ref-lesscode-core/src/main/AndroidManifest.xml b/app-ref-lesscode-core/src/main/AndroidManifest.xml
deleted file mode 100644
index b52f528..0000000
--- a/app-ref-lesscode-core/src/main/AndroidManifest.xml
+++ /dev/null
@@ -1,21 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/app-ref-lesscode-core/src/main/java/com/jayfeng/lesscode/app/ref/lesscodecore/MainActivity.java b/app-ref-lesscode-core/src/main/java/com/jayfeng/lesscode/app/ref/lesscodecore/MainActivity.java
deleted file mode 100644
index 6fcff14..0000000
--- a/app-ref-lesscode-core/src/main/java/com/jayfeng/lesscode/app/ref/lesscodecore/MainActivity.java
+++ /dev/null
@@ -1,66 +0,0 @@
-package com.jayfeng.lesscode.app.ref.lesscodecore;
-
-import android.app.Activity;
-import android.os.Bundle;
-import android.view.Menu;
-import android.view.MenuItem;
-import android.view.View;
-import android.widget.TextView;
-
-import com.jayfeng.lesscode.core.AdapterLess;
-import com.jayfeng.lesscode.core.ToastLess;
-import com.jayfeng.lesscode.core.ViewLess;
-
-import java.util.ArrayList;
-import java.util.List;
-
-
-public class MainActivity extends Activity {
-
- private TextView textView;
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
-
- textView = ViewLess.$(this, R.id.text);
-
- ToastLess.$(this, textView.getText().toString());
-
- List list = new ArrayList<>();
- list.add("A");
- list.add("B");
-
-
- AdapterLess.$pager(this, list, R.layout.activity_main, new AdapterLess.PageCallBack() {
- @Override
- public void instantiateItem(int i, View view, Object o) {
-
- }
- });
- }
-
-
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- // Inflate the menu; this adds items to the action bar if it is present.
- getMenuInflater().inflate(R.menu.menu_main, menu);
- return true;
- }
-
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- // Handle action bar item clicks here. The action bar will
- // automatically handle clicks on the Home/Up button, so long
- // as you specify a parent activity in AndroidManifest.xml.
- int id = item.getItemId();
-
- //noinspection SimplifiableIfStatement
- if (id == R.id.action_settings) {
- return true;
- }
-
- return super.onOptionsItemSelected(item);
- }
-}
diff --git a/app-ref-lesscode-core/src/main/res/layout/activity_main.xml b/app-ref-lesscode-core/src/main/res/layout/activity_main.xml
deleted file mode 100644
index cb4b9cb..0000000
--- a/app-ref-lesscode-core/src/main/res/layout/activity_main.xml
+++ /dev/null
@@ -1,17 +0,0 @@
-
-
-
-
-
diff --git a/app-ref-lesscode-core/src/main/res/menu/menu_main.xml b/app-ref-lesscode-core/src/main/res/menu/menu_main.xml
deleted file mode 100644
index c24a41e..0000000
--- a/app-ref-lesscode-core/src/main/res/menu/menu_main.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-
diff --git a/app-ref-lesscode-core/src/main/res/mipmap-hdpi/ic_launcher.png b/app-ref-lesscode-core/src/main/res/mipmap-hdpi/ic_launcher.png
deleted file mode 100644
index cde69bc..0000000
Binary files a/app-ref-lesscode-core/src/main/res/mipmap-hdpi/ic_launcher.png and /dev/null differ
diff --git a/app-ref-lesscode-core/src/main/res/mipmap-mdpi/ic_launcher.png b/app-ref-lesscode-core/src/main/res/mipmap-mdpi/ic_launcher.png
deleted file mode 100644
index c133a0c..0000000
Binary files a/app-ref-lesscode-core/src/main/res/mipmap-mdpi/ic_launcher.png and /dev/null differ
diff --git a/app-ref-lesscode-core/src/main/res/mipmap-xhdpi/ic_launcher.png b/app-ref-lesscode-core/src/main/res/mipmap-xhdpi/ic_launcher.png
deleted file mode 100644
index bfa42f0..0000000
Binary files a/app-ref-lesscode-core/src/main/res/mipmap-xhdpi/ic_launcher.png and /dev/null differ
diff --git a/app-ref-lesscode-core/src/main/res/mipmap-xxhdpi/ic_launcher.png b/app-ref-lesscode-core/src/main/res/mipmap-xxhdpi/ic_launcher.png
deleted file mode 100644
index 324e72c..0000000
Binary files a/app-ref-lesscode-core/src/main/res/mipmap-xxhdpi/ic_launcher.png and /dev/null differ
diff --git a/app-ref-lesscode-core/src/main/res/values-w820dp/dimens.xml b/app-ref-lesscode-core/src/main/res/values-w820dp/dimens.xml
deleted file mode 100644
index 63fc816..0000000
--- a/app-ref-lesscode-core/src/main/res/values-w820dp/dimens.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
- 64dp
-
diff --git a/app-ref-lesscode-core/src/main/res/values/dimens.xml b/app-ref-lesscode-core/src/main/res/values/dimens.xml
deleted file mode 100644
index 47c8224..0000000
--- a/app-ref-lesscode-core/src/main/res/values/dimens.xml
+++ /dev/null
@@ -1,5 +0,0 @@
-
-
- 16dp
- 16dp
-
diff --git a/app-ref-lesscode-core/src/main/res/values/strings.xml b/app-ref-lesscode-core/src/main/res/values/strings.xml
deleted file mode 100644
index 8878ed6..0000000
--- a/app-ref-lesscode-core/src/main/res/values/strings.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-
- AppRef-LesscodeCore
-
- Hello world!
- Settings
-
diff --git a/app-ref-lesscode-core/src/main/res/values/styles.xml b/app-ref-lesscode-core/src/main/res/values/styles.xml
deleted file mode 100644
index 9812b28..0000000
--- a/app-ref-lesscode-core/src/main/res/values/styles.xml
+++ /dev/null
@@ -1,8 +0,0 @@
-
-
-
-
-
-
diff --git a/app/build.gradle b/app/build.gradle
index 513751e..3384bef 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -1,13 +1,13 @@
apply plugin: 'com.android.application'
android {
- compileSdkVersion 21
- buildToolsVersion "21.1.2"
+ compileSdkVersion 27
+ buildToolsVersion '27.0.3'
defaultConfig {
applicationId "com.jayfeng.lesscode.app"
- minSdkVersion 9
- targetSdkVersion 21
+ minSdkVersion 14
+ targetSdkVersion 27
versionCode 1
versionName "1.0"
}
@@ -17,9 +17,13 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
+
+ lintOptions {
+ abortOnError false
+ }
}
dependencies {
- compile fileTree(dir: 'libs', include: ['*.jar'])
+ compile fileTree(include: ['*.jar'], dir: 'libs')
compile project(':lesscode-core')
}
diff --git a/app/src/androidTest/java/com/jayfeng/lesscode/app/ApplicationTest.java b/app/src/androidTest/java/com/jayfeng/lesscode/app/ApplicationTest.java
deleted file mode 100644
index c8260ef..0000000
--- a/app/src/androidTest/java/com/jayfeng/lesscode/app/ApplicationTest.java
+++ /dev/null
@@ -1,13 +0,0 @@
-package com.jayfeng.lesscode.app;
-
-import android.app.Application;
-import android.test.ApplicationTestCase;
-
-/**
- * Testing Fundamentals
- */
-public class ApplicationTest extends ApplicationTestCase {
- public ApplicationTest() {
- super(Application.class);
- }
-}
\ No newline at end of file
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 48e0791..dfbd8b5 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -6,7 +6,6 @@
@@ -25,9 +24,6 @@
-
@@ -35,8 +31,8 @@
android:name=".activity.adapterless.PagerAdapterActivity"
android:label="@string/title_activity_adapter_pager" />
+ android:name=".activity.adapterless.RecyclerAdapterActivity"
+ android:label="@string/title_activity_adapter_recycler" />
@@ -79,6 +75,12 @@
+
+
diff --git a/app/src/main/java/com/jayfeng/lesscode/app/activity/ActivityActivity.java b/app/src/main/java/com/jayfeng/lesscode/app/activity/ActivityActivity.java
index 17ea843..589a58a 100644
--- a/app/src/main/java/com/jayfeng/lesscode/app/activity/ActivityActivity.java
+++ b/app/src/main/java/com/jayfeng/lesscode/app/activity/ActivityActivity.java
@@ -4,11 +4,14 @@
import android.os.Bundle;
import com.jayfeng.lesscode.app.R;
+import com.jayfeng.lesscode.core.ActivityLess;
public class ActivityActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
+ ActivityLess.$noTitle(this);
+ ActivityLess.$fullScreen(this);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_activity);
}
diff --git a/app/src/main/java/com/jayfeng/lesscode/app/activity/AdapterActivity.java b/app/src/main/java/com/jayfeng/lesscode/app/activity/AdapterActivity.java
deleted file mode 100644
index ce32e3c..0000000
--- a/app/src/main/java/com/jayfeng/lesscode/app/activity/AdapterActivity.java
+++ /dev/null
@@ -1,69 +0,0 @@
-package com.jayfeng.lesscode.app.activity;
-
-import android.app.Activity;
-import android.content.Intent;
-import android.os.Bundle;
-import android.view.View;
-import android.widget.AdapterView;
-import android.widget.BaseAdapter;
-import android.widget.ListView;
-import android.widget.TextView;
-
-import com.jayfeng.lesscode.app.R;
-import com.jayfeng.lesscode.app.model.LessItem;
-import com.jayfeng.lesscode.core.AdapterLess;
-import com.jayfeng.lesscode.core.ViewLess;
-
-import java.util.ArrayList;
-import java.util.List;
-
-public class AdapterActivity extends Activity {
-
- List list;
- ListView listView;
- BaseAdapter adapter;
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_adapter);
-
- listView = ViewLess.$(this, R.id.listview);
-
- initData();
-
- adapter = AdapterLess.$base(this, list, R.layout.activity_main_list_item,
- new AdapterLess.CallBack() {
- @Override
- public View getView(int position, View convertView, AdapterLess.ViewHolder holder, LessItem lessItem) {
- TextView nameView = holder.$view(convertView, R.id.name);
- nameView.setText(lessItem.getName());
- return convertView;
- }
- });
- listView.setAdapter(adapter);
- listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
- @Override
- public void onItemClick(AdapterView> parent, View view, int position, long id) {
- Intent intent = new Intent();
- intent.setClassName(AdapterActivity.this, "com.jayfeng.lesscode.app.activity.adapterless." + list.get(position).getClassName());
- startActivity(intent);
- }
- });
- }
-
- private void initData() {
- list = new ArrayList<>();
-
- LessItem lessItem = new LessItem();
- lessItem.setName("AdapterLess.$base的使用");
- lessItem.setClassName("BaseAdapterActivity");
- list.add(lessItem);
-
- lessItem = new LessItem();
- lessItem.setName("AdapterLess.$pager的使用");
- lessItem.setClassName("PagerAdapterActivity");
- list.add(lessItem);
- }
-
-}
diff --git a/app/src/main/java/com/jayfeng/lesscode/app/activity/AppActivity.java b/app/src/main/java/com/jayfeng/lesscode/app/activity/AppActivity.java
index bbda738..ad58b2f 100644
--- a/app/src/main/java/com/jayfeng/lesscode/app/activity/AppActivity.java
+++ b/app/src/main/java/com/jayfeng/lesscode/app/activity/AppActivity.java
@@ -2,19 +2,44 @@
import android.app.Activity;
import android.os.Bundle;
+import android.view.View;
+import android.widget.Button;
+import android.widget.EditText;
import com.jayfeng.lesscode.app.R;
import com.jayfeng.lesscode.core.AppLess;
+import com.jayfeng.lesscode.core.FileLess;
+import com.jayfeng.lesscode.core.StorageLess;
import com.jayfeng.lesscode.core.ToastLess;
+import com.jayfeng.lesscode.core.ViewLess;
+
+import java.io.File;
public class AppActivity extends Activity {
+ private EditText deleteDirPathView;
+ private Button deleteButton;
+
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_app);
- ToastLess.$(this, "current package:" + AppLess.$running(this, null)
- + ", else package:" + AppLess.$running(this, "com.marriage"));
+ ToastLess.$(this, "current package:" + AppLess.$running(getPackageName())
+ + ", else package:" + AppLess.$running("com.marriage"));
+
+ deleteDirPathView = ViewLess.$(this, R.id.del_dir_path);
+ deleteButton = ViewLess.$(this, R.id.del_dir_btn);
+
+ deleteDirPathView.setText(StorageLess.Sdcard.$path().getPath() + "/test");
+
+ deleteButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ String path = deleteDirPathView.getText().toString();
+ File dir = new File(path);
+ FileLess.$del(dir, true);
+ }
+ });
}
}
diff --git a/app/src/main/java/com/jayfeng/lesscode/app/activity/BitmapActivity.java b/app/src/main/java/com/jayfeng/lesscode/app/activity/BitmapActivity.java
new file mode 100644
index 0000000..704d696
--- /dev/null
+++ b/app/src/main/java/com/jayfeng/lesscode/app/activity/BitmapActivity.java
@@ -0,0 +1,31 @@
+package com.jayfeng.lesscode.app.activity;
+
+import android.app.Activity;
+import android.graphics.Bitmap;
+import android.graphics.drawable.BitmapDrawable;
+import android.os.Bundle;
+import android.widget.ImageView;
+import android.widget.TextView;
+
+import com.jayfeng.lesscode.app.R;
+import com.jayfeng.lesscode.core.BitmapLess;
+import com.jayfeng.lesscode.core.DeviceLess;
+import com.jayfeng.lesscode.core.DisplayLess;
+import com.jayfeng.lesscode.core.ViewLess;
+
+public class BitmapActivity extends Activity {
+
+ private ImageView roundImageView;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_bitmap);
+
+ roundImageView = ViewLess.$(this, R.id.image_round);
+
+ Bitmap bitmap = ((BitmapDrawable) getResources().getDrawable(R.drawable.girl2)).getBitmap();
+ bitmap = BitmapLess.$gray(bitmap, true);
+ roundImageView.setImageBitmap(bitmap);
+ }
+}
diff --git a/app/src/main/java/com/jayfeng/lesscode/app/activity/CacheActivity.java b/app/src/main/java/com/jayfeng/lesscode/app/activity/CacheActivity.java
index ecdf664..669693d 100644
--- a/app/src/main/java/com/jayfeng/lesscode/app/activity/CacheActivity.java
+++ b/app/src/main/java/com/jayfeng/lesscode/app/activity/CacheActivity.java
@@ -1,7 +1,12 @@
package com.jayfeng.lesscode.app.activity;
import android.app.Activity;
+import android.graphics.Bitmap;
+import android.graphics.BitmapRegionDecoder;
+import android.graphics.Matrix;
+import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
+import android.support.v4.util.LruCache;
import com.jayfeng.lesscode.app.R;
diff --git a/app/src/main/java/com/jayfeng/lesscode/app/activity/DeviceActivity.java b/app/src/main/java/com/jayfeng/lesscode/app/activity/DeviceActivity.java
index 3b71ead..d3c5894 100644
--- a/app/src/main/java/com/jayfeng/lesscode/app/activity/DeviceActivity.java
+++ b/app/src/main/java/com/jayfeng/lesscode/app/activity/DeviceActivity.java
@@ -2,10 +2,13 @@
import android.app.Activity;
import android.os.Bundle;
+import android.os.Handler;
import android.widget.TextView;
import com.jayfeng.lesscode.app.R;
import com.jayfeng.lesscode.core.DeviceLess;
+import com.jayfeng.lesscode.core.DisplayLess;
+import com.jayfeng.lesscode.core.ToastLess;
import com.jayfeng.lesscode.core.ViewLess;
public class DeviceActivity extends Activity {
diff --git a/app/src/main/java/com/jayfeng/lesscode/app/activity/DisplayActivity.java b/app/src/main/java/com/jayfeng/lesscode/app/activity/DisplayActivity.java
index 11b0261..6470ea4 100644
--- a/app/src/main/java/com/jayfeng/lesscode/app/activity/DisplayActivity.java
+++ b/app/src/main/java/com/jayfeng/lesscode/app/activity/DisplayActivity.java
@@ -2,8 +2,11 @@
import android.app.Activity;
import android.os.Bundle;
+import android.os.Handler;
import com.jayfeng.lesscode.app.R;
+import com.jayfeng.lesscode.core.DisplayLess;
+import com.jayfeng.lesscode.core.ToastLess;
public class DisplayActivity extends Activity {
@@ -11,5 +14,16 @@ public class DisplayActivity extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_display);
+
+ ToastLess.$(this, DisplayLess.$width(this) + "x" + DisplayLess.$height(this));
+
+ new Handler().postDelayed(new Runnable() {
+ @Override
+ public void run() {
+ ToastLess.$(DisplayActivity.this, "status bar height:" + DisplayLess.$statusBarHeight(DisplayActivity.this)
+ + ", title bar height:" + DisplayLess.$titleBarHeight(DisplayActivity.this));
+ }
+ }, 2000);
+ ToastLess.$(this, "status bar height with reflect:" + DisplayLess.$statusBarHeight(getResources()));
}
}
diff --git a/app/src/main/java/com/jayfeng/lesscode/app/activity/DrawableActivity.java b/app/src/main/java/com/jayfeng/lesscode/app/activity/DrawableActivity.java
new file mode 100644
index 0000000..b04f197
--- /dev/null
+++ b/app/src/main/java/com/jayfeng/lesscode/app/activity/DrawableActivity.java
@@ -0,0 +1,81 @@
+package com.jayfeng.lesscode.app.activity;
+
+import android.app.Activity;
+import android.content.res.ColorStateList;
+import android.graphics.Color;
+import android.graphics.PorterDuff;
+import android.graphics.drawable.Drawable;
+import android.os.Bundle;
+import android.view.View;
+import android.widget.AdapterView;
+import android.widget.ArrayAdapter;
+import android.widget.ImageView;
+import android.widget.Spinner;
+
+import com.jayfeng.lesscode.app.R;
+import com.jayfeng.lesscode.core.DrawableLess;
+import com.jayfeng.lesscode.core.ToastLess;
+import com.jayfeng.lesscode.core.ViewLess;
+
+public class DrawableActivity extends Activity {
+
+ private static final PorterDuff.Mode[] tintModeArray = {
+// PorterDuff.Mode.ADD,
+ PorterDuff.Mode.CLEAR,
+ PorterDuff.Mode.DARKEN,
+ PorterDuff.Mode.DST,
+ PorterDuff.Mode.DST_ATOP,
+ PorterDuff.Mode.DST_IN,
+ PorterDuff.Mode.DST_OUT,
+ PorterDuff.Mode.DST_OVER,
+ PorterDuff.Mode.LIGHTEN,
+ PorterDuff.Mode.MULTIPLY,
+// PorterDuff.Mode.OVERLAY,
+ PorterDuff.Mode.SCREEN,
+ PorterDuff.Mode.SRC,
+ PorterDuff.Mode.SRC_ATOP,
+ PorterDuff.Mode.SRC_IN,
+ PorterDuff.Mode.SRC_OUT,
+ PorterDuff.Mode.SRC_OVER,
+ PorterDuff.Mode.XOR
+ };
+
+ private ImageView imageView;
+ private Spinner tintModeView;
+
+ private ArrayAdapter tintModeAdapter;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_drawable);
+
+ imageView = ViewLess.$(this, R.id.image);
+ tintModeView = ViewLess.$(this, R.id.tintMode);
+
+ tintModeAdapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, tintModeArray);
+ tintModeAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
+ tintModeView.setAdapter(tintModeAdapter);
+
+ tintModeView.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
+ @Override
+ public void onItemSelected(AdapterView> parent, View view, int position, long id) {
+ Drawable tintDrawable = DrawableLess.$tint(
+ getResources().getDrawable(R.drawable.ic_launcher),
+ ColorStateList.valueOf(Color.RED),
+ tintModeArray[position]
+ );
+
+ ToastLess.$(DrawableActivity.this, tintModeArray[position].name());
+
+ imageView.setImageDrawable(tintDrawable);
+ }
+
+ @Override
+ public void onNothingSelected(AdapterView> parent) {
+
+ }
+ });
+
+ }
+}
diff --git a/app/src/main/java/com/jayfeng/lesscode/app/activity/KeyboradActivity.java b/app/src/main/java/com/jayfeng/lesscode/app/activity/KeyboradActivity.java
index a1612bd..e9dd8d7 100644
--- a/app/src/main/java/com/jayfeng/lesscode/app/activity/KeyboradActivity.java
+++ b/app/src/main/java/com/jayfeng/lesscode/app/activity/KeyboradActivity.java
@@ -2,14 +2,42 @@
import android.app.Activity;
import android.os.Bundle;
+import android.view.View;
+import android.widget.Button;
+import android.widget.EditText;
import com.jayfeng.lesscode.app.R;
+import com.jayfeng.lesscode.core.KeyBoardLess;
+import com.jayfeng.lesscode.core.ViewLess;
public class KeyboradActivity extends Activity {
+ private EditText editText;
+ private Button showKeyboradButton;
+ private Button hideKeyboradButton;
+
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_keyborad);
+
+ editText = ViewLess.$(this, R.id.edit);
+ showKeyboradButton = ViewLess.$(this, R.id.show);
+ hideKeyboradButton = ViewLess.$(this, R.id.hide);
+
+ showKeyboradButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ KeyBoardLess.$show(KeyboradActivity.this, editText);
+ }
+ });
+
+ hideKeyboradButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ KeyBoardLess.$hide(KeyboradActivity.this, editText);
+ }
+ });
+
}
}
diff --git a/app/src/main/java/com/jayfeng/lesscode/app/activity/LogActivity.java b/app/src/main/java/com/jayfeng/lesscode/app/activity/LogActivity.java
index d21d7d7..40649b6 100644
--- a/app/src/main/java/com/jayfeng/lesscode/app/activity/LogActivity.java
+++ b/app/src/main/java/com/jayfeng/lesscode/app/activity/LogActivity.java
@@ -15,6 +15,6 @@ protected void onCreate(Bundle savedInstanceState) {
LogLess.$d("xxxxxxx");
LogLess.$e("yyyyy");
- LogLess.$e("zzzzzzzzzz");
+ LogLess.$json("{\"a\":\"aValue\"}", "test");
}
}
diff --git a/app/src/main/java/com/jayfeng/lesscode/app/activity/MainActivity.java b/app/src/main/java/com/jayfeng/lesscode/app/activity/MainActivity.java
index 3eb4691..8e12900 100644
--- a/app/src/main/java/com/jayfeng/lesscode/app/activity/MainActivity.java
+++ b/app/src/main/java/com/jayfeng/lesscode/app/activity/MainActivity.java
@@ -1,27 +1,21 @@
package com.jayfeng.lesscode.app.activity;
import android.app.Activity;
-import android.content.Intent;
import android.os.Bundle;
-import android.view.View;
-import android.widget.AdapterView;
+import android.os.Environment;
import android.widget.BaseAdapter;
import android.widget.ListView;
-import android.widget.TextView;
import com.jayfeng.lesscode.app.R;
import com.jayfeng.lesscode.app.model.LessItem;
-import com.jayfeng.lesscode.app.model.Person;
import com.jayfeng.lesscode.core.ActivityLess;
-import com.jayfeng.lesscode.core.AdapterLess;
+import com.jayfeng.lesscode.core.HttpLess;
import com.jayfeng.lesscode.core.LogLess;
-import com.jayfeng.lesscode.core.NetworkLess;
-import com.jayfeng.lesscode.core.SerializeLess;
-import com.jayfeng.lesscode.core.SharedPreferenceLess;
import com.jayfeng.lesscode.core.ToastLess;
import com.jayfeng.lesscode.core.ViewLess;
import java.io.File;
+import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;
@@ -36,8 +30,6 @@ public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
- ActivityLess.$noTitle(this);
- ActivityLess.$fullScreen(this);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
@@ -45,41 +37,63 @@ protected void onCreate(Bundle savedInstanceState) {
initData();
- adapter = AdapterLess.$base(this, list, R.layout.activity_main_list_item,
- new AdapterLess.CallBack() {
- @Override
- public View getView(int position, View convertView, AdapterLess.ViewHolder holder, LessItem lessItem) {
- TextView nameView = holder.$view(convertView, R.id.name);
- nameView.setText(lessItem.getName());
- return convertView;
- }
- });
- listView.setAdapter(adapter);
- listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
+ final File mDestDir = new File(Environment.getExternalStorageDirectory().getPath() + "/lesscode-download");
+ if (mDestDir.exists() && !mDestDir.isDirectory()) {
+ mDestDir.delete();
+ }
+ if (mDestDir.exists() || mDestDir.mkdirs()) {
+
+ }
+ final File mDestFile = new File(mDestDir.getPath() + "/" + URLEncoder.encode("http://www.vpngo.com/download/vpngo-release-v1.3.1-46.apk"));
+ new Thread() {
@Override
- public void onItemClick(AdapterView> parent, View view, int position, long id) {
- Intent intent = new Intent();
- intent.setClassName(MainActivity.this, "com.jayfeng.lesscode.app.activity." + list.get(position).getClassName());
- startActivity(intent);
+ public void run() {
+ try {
+ HttpLess.$download("http://www.vpngo.com/download/vpngo-release-v1.3.1-46.apk", mDestFile, false, new HttpLess.DownloadCallBack() {
+ @Override
+ public void onDownloading(int progress) {
+
+ }
+
+ @Override
+ public void onDownloaded() {
+ LogLess.$d("下载完成");
+ }
+ });
+ } catch (Exception e) {
+ e.printStackTrace();
+ LogLess.$d(e.getMessage());
+ }
}
- });
-
- LogLess.$d("network:" + NetworkLess.$online() + ", type:" + NetworkLess.$type());
-
- SharedPreferenceLess.$put(this, "key1", "value");
- SharedPreferenceLess.$put(this, "key2", "100000022");
- ToastLess.$(MainActivity.this,
- "key1:" + SharedPreferenceLess.$get(MainActivity.this, "key1", "") +
- ", " +
- "key2:" + SharedPreferenceLess.$get(MainActivity.this, "key2", ""));
-
-// LogLess.$e("hello id:" + R.id.hello + "/" + ResourceLess.$id(this, "hello", ResourceLess.TYPE.ID));
-
- Person person = new Person("fengj");
- SerializeLess.$se(new File(getCacheDir(), "person").getAbsolutePath(), person);
-
- Person person1 = SerializeLess.$de(new File(getCacheDir(), "person").getAbsolutePath());
- ToastLess.$(this, person1.getName());
+ }.start();
+
+
+// adapter = AdapterLess.$base(this, list, R.layout.activity_main_list_item,
+// new AdapterLess.CallBack() {
+// @Override
+// public View getView(int position, View convertView, AdapterLess.ViewHolder holder, LessItem lessItem) {
+// TextView nameView = holder.$view(convertView, R.id.name);
+// nameView.setText(lessItem.getName());
+// return convertView;
+// }
+// });
+// listView.setAdapter(adapter);
+// listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
+// @Override
+// public void onItemClick(AdapterView> parent, View view, int position, long id) {
+// Intent intent = new Intent();
+// intent.setClassName(MainActivity.this, "com.jayfeng.lesscode.app.activity." + list.get(position).getClassName());
+// startActivity(intent);
+// }
+// });
+//
+// LogLess.$d("network: %s, type: %s", NetworkLess.$online(), NetworkLess.$type());
+//
+// Person person = new Person("fengj");
+// SerializeLess.$se(new File(getCacheDir(), "person").getAbsolutePath(), person);
+//
+// Person person1 = SerializeLess.$de(new File(getCacheDir(), "person").getAbsolutePath());
+// ToastLess.$(this, person1.getName());
}
@@ -92,13 +106,13 @@ private void initData() {
list.add(lessItem);
lessItem = new LessItem();
- lessItem.setName("AdapterLess的使用");
- lessItem.setClassName("AdapterActivity");
+ lessItem.setName("AppLess的使用");
+ lessItem.setClassName("AppActivity");
list.add(lessItem);
lessItem = new LessItem();
- lessItem.setName("AppLess的使用");
- lessItem.setClassName("AppActivity");
+ lessItem.setName("BitmapLess的使用");
+ lessItem.setClassName("BitmapActivity");
list.add(lessItem);
lessItem = new LessItem();
@@ -116,6 +130,11 @@ private void initData() {
lessItem.setClassName("DisplayActivity");
list.add(lessItem);
+ lessItem = new LessItem();
+ lessItem.setName("DrawableLess的使用");
+ lessItem.setClassName("DrawableActivity");
+ list.add(lessItem);
+
lessItem = new LessItem();
lessItem.setName("EncodeLess的使用");
lessItem.setClassName("EncodeActivity");
@@ -136,6 +155,11 @@ private void initData() {
lessItem.setClassName("KeyboradActivity");
list.add(lessItem);
+ lessItem = new LessItem();
+ lessItem.setName("LogLess的使用");
+ lessItem.setClassName("LogActivity");
+ list.add(lessItem);
+
lessItem = new LessItem();
lessItem.setName("NetworkLess的使用");
lessItem.setClassName("NetworkActivity");
@@ -161,11 +185,6 @@ private void initData() {
lessItem.setClassName("ToastActivity");
list.add(lessItem);
- lessItem = new LessItem();
- lessItem.setName("UpdateLess的使用");
- lessItem.setClassName("UpdateActivity");
- list.add(lessItem);
-
lessItem = new LessItem();
lessItem.setName("ViewLess的使用");
lessItem.setClassName("ViewActivity");
diff --git a/app/src/main/java/com/jayfeng/lesscode/app/activity/SharedPreferenceActivity.java b/app/src/main/java/com/jayfeng/lesscode/app/activity/SharedPreferenceActivity.java
index 266167d..7156472 100644
--- a/app/src/main/java/com/jayfeng/lesscode/app/activity/SharedPreferenceActivity.java
+++ b/app/src/main/java/com/jayfeng/lesscode/app/activity/SharedPreferenceActivity.java
@@ -4,6 +4,8 @@
import android.os.Bundle;
import com.jayfeng.lesscode.app.R;
+import com.jayfeng.lesscode.core.LogLess;
+import com.jayfeng.lesscode.core.SharedPreferenceLess;
public class SharedPreferenceActivity extends Activity {
@@ -11,5 +13,19 @@ public class SharedPreferenceActivity extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_shared_preference);
+
+
+ SharedPreferenceLess.$put("key1", 333);
+ SharedPreferenceLess.$put("key2", 0.5f);
+ SharedPreferenceLess.$put("key3", true);
+ SharedPreferenceLess.$put("key4", 100000L);
+ SharedPreferenceLess.$put("key5", "i am a string");
+ SharedPreferenceLess.$put("key5", null);
+
+ LogLess.$d(SharedPreferenceLess.$get("key1", 0) + "");
+ LogLess.$d(SharedPreferenceLess.$get("key2", 0f) + "");
+ LogLess.$d(SharedPreferenceLess.$get("key3", false) + "");
+ LogLess.$d(SharedPreferenceLess.$get("key4", 0L) + "");
+ LogLess.$d(SharedPreferenceLess.$get("key5", ""));
}
}
diff --git a/app/src/main/java/com/jayfeng/lesscode/app/activity/ToastActivity.java b/app/src/main/java/com/jayfeng/lesscode/app/activity/ToastActivity.java
index e830192..71721b8 100644
--- a/app/src/main/java/com/jayfeng/lesscode/app/activity/ToastActivity.java
+++ b/app/src/main/java/com/jayfeng/lesscode/app/activity/ToastActivity.java
@@ -4,6 +4,7 @@
import android.os.Bundle;
import com.jayfeng.lesscode.app.R;
+import com.jayfeng.lesscode.core.ToastLess;
public class ToastActivity extends Activity {
@@ -11,5 +12,8 @@ public class ToastActivity extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_toast);
+
+
+ ToastLess.$("xxxxx");
}
}
diff --git a/app/src/main/java/com/jayfeng/lesscode/app/activity/UpdateActivity.java b/app/src/main/java/com/jayfeng/lesscode/app/activity/UpdateActivity.java
deleted file mode 100644
index 3dbb731..0000000
--- a/app/src/main/java/com/jayfeng/lesscode/app/activity/UpdateActivity.java
+++ /dev/null
@@ -1,24 +0,0 @@
-package com.jayfeng.lesscode.app.activity;
-
-import android.app.Activity;
-import android.os.Bundle;
-
-import com.jayfeng.lesscode.app.R;
-import com.jayfeng.lesscode.core.UpdateLess;
-
-public class UpdateActivity extends Activity {
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_update);
-
- String updateJson = "{\n" +
- " \"vercode\":112,\n" +
- " \"vername\":\"V1.1\",\n" +
- " \"download\":\"http://www.apk.anzhi.com/data3/apk/201506/09/3a978f27369b4a8bf6de1270da9871ec_86281300.apk\",\n" +
- " \"log\":\"upgrade content\"\n" +
- " }";
- UpdateLess.$check(this, updateJson);
- }
-}
diff --git a/app/src/main/java/com/jayfeng/lesscode/app/activity/ViewActivity.java b/app/src/main/java/com/jayfeng/lesscode/app/activity/ViewActivity.java
index e16cc61..c3dd291 100644
--- a/app/src/main/java/com/jayfeng/lesscode/app/activity/ViewActivity.java
+++ b/app/src/main/java/com/jayfeng/lesscode/app/activity/ViewActivity.java
@@ -2,14 +2,51 @@
import android.app.Activity;
import android.os.Bundle;
+import android.view.View;
+import android.widget.Button;
import com.jayfeng.lesscode.app.R;
+import com.jayfeng.lesscode.core.LogLess;
+import com.jayfeng.lesscode.core.ViewLess;
+import com.jayfeng.lesscode.core.other.ViewThrottleClickListener;
public class ViewActivity extends Activity {
+ private Button normalButton;
+ private Button throttleButton;
+ private Button throttleLongButton;
+
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_view);
+
+ normalButton = ViewLess.$(this, R.id.button_normal);
+ throttleButton = ViewLess.$(this, R.id.button_throttle);
+ throttleLongButton = ViewLess.$(this, R.id.button_throttle_long);
+
+ normalButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ LogLess.$d("normal button click");
+ }
+ });
+ throttleButton.setOnClickListener(new ViewThrottleClickListener() {
+ @Override
+ public void throttleClick(View view) {
+ LogLess.$d("throttle click");
+ }
+ });
+ throttleLongButton.setOnClickListener(new ViewThrottleClickListener() {
+ @Override
+ public void throttleClick(View view) {
+ LogLess.$d("throttle click 3s");
+ }
+
+ @Override
+ public long getThrottleTime() {
+ return 3000;
+ }
+ });
}
}
diff --git a/app/src/main/java/com/jayfeng/lesscode/app/activity/adapterless/BaseAdapterActivity.java b/app/src/main/java/com/jayfeng/lesscode/app/activity/adapterless/BaseAdapterActivity.java
deleted file mode 100644
index d4deedd..0000000
--- a/app/src/main/java/com/jayfeng/lesscode/app/activity/adapterless/BaseAdapterActivity.java
+++ /dev/null
@@ -1,87 +0,0 @@
-package com.jayfeng.lesscode.app.activity.adapterless;
-
-import android.app.Activity;
-import android.os.Bundle;
-import android.view.View;
-import android.widget.BaseAdapter;
-import android.widget.ListView;
-import android.widget.TextView;
-
-import com.jayfeng.lesscode.app.R;
-import com.jayfeng.lesscode.app.model.Person;
-import com.jayfeng.lesscode.core.AdapterLess;
-import com.jayfeng.lesscode.core.ViewLess;
-
-import java.util.ArrayList;
-import java.util.List;
-
-public class BaseAdapterActivity extends Activity {
-
- List list;
- ListView listView;
- BaseAdapter adapter;
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_adapter_base);
- listView = ViewLess.$(this, R.id.listview);
- initData();
-
- // simple callback
- /*
- adapter = AdapterLess.$base(this, list, R.layout.activity_main_list_item,
- new AdapterLess.CallBack() {
- @Override
- public View getView(int position, View convertView, AdapterLess.ViewHolder holder, Person person) {
- TextView nameView = holder.$view(convertView, R.id.name);
- nameView.setText(person.getName());
- return convertView;
- }
- });
- */
- adapter = AdapterLess.$base(this, list,
- new int[] { R.layout.activity_main_list_item, R.layout.adapter_list_item_header},
- new AdapterLess.FullCallBack() {
- @Override
- public View getView(int position, View convertView, AdapterLess.ViewHolder holder, Person person) {
- TextView nameView = holder.$view(convertView, R.id.name);
- nameView.setText(person.getName());
- return convertView;
- }
-
- @Override
- public int getItemViewType(int position) {
- Person person = list.get(position);
- if ("header".equals(person.getName())) {
- return 1;
- } else {
- return 0;
- }
- }
-
- @Override
- public boolean isEnabled(int position) {
- Person person = list.get(position);
- if ("header".equals(person.getName())) {
- return false;
- }
- return true;
- }
- });
- // full callback
-
- listView.setAdapter(adapter);
- }
-
- private void initData() {
- list = new ArrayList<>();
- list.add(new Person("header"));
- list.add(new Person("jay"));
- list.add(new Person("bee"));
- list.add(new Person("header"));
- list.add(new Person("chras"));
- list.add(new Person("nichid"));
- }
-
-}
diff --git a/app/src/main/java/com/jayfeng/lesscode/app/activity/adapterless/PagerAdapterActivity.java b/app/src/main/java/com/jayfeng/lesscode/app/activity/adapterless/PagerAdapterActivity.java
deleted file mode 100644
index ea3ca7a..0000000
--- a/app/src/main/java/com/jayfeng/lesscode/app/activity/adapterless/PagerAdapterActivity.java
+++ /dev/null
@@ -1,56 +0,0 @@
-package com.jayfeng.lesscode.app.activity.adapterless;
-
-import android.app.Activity;
-import android.os.Bundle;
-import android.support.v4.view.PagerAdapter;
-import android.support.v4.view.ViewPager;
-import android.view.View;
-import android.widget.BaseAdapter;
-import android.widget.ListView;
-import android.widget.TextView;
-
-import com.jayfeng.lesscode.app.R;
-import com.jayfeng.lesscode.app.model.Person;
-import com.jayfeng.lesscode.core.AdapterLess;
-import com.jayfeng.lesscode.core.ViewLess;
-
-import java.util.ArrayList;
-import java.util.List;
-
-public class PagerAdapterActivity extends Activity {
-
- List list;
- ViewPager viewPager;
- PagerAdapter adapter;
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_adapter_pager);
- viewPager = ViewLess.$(this, R.id.viewpager);
- initData();
-
- adapter = AdapterLess.$pager(this, list,
- R.layout.activity_main_list_item,
- new AdapterLess.PageCallBack() {
- @Override
- public void instantiateItem(int position, View view, Person person) {
- TextView nameView = ViewLess.$(view, R.id.name);
- nameView.setText("page " + position + ":" + person.getName());
- }
- });
-
- viewPager.setAdapter(adapter);
- }
-
- private void initData() {
- list = new ArrayList<>();
- list.add(new Person("header"));
- list.add(new Person("jay"));
- list.add(new Person("bee"));
- list.add(new Person("header"));
- list.add(new Person("chras"));
- list.add(new Person("nichid"));
- }
-
-}
diff --git a/app/src/main/res/drawable-xhdpi/girl.jpg b/app/src/main/res/drawable-xhdpi/girl.jpg
new file mode 100644
index 0000000..d63d2c8
Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/girl.jpg differ
diff --git a/app/src/main/res/drawable-xhdpi/girl2.jpg b/app/src/main/res/drawable-xhdpi/girl2.jpg
new file mode 100644
index 0000000..568bb02
Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/girl2.jpg differ
diff --git a/app/src/main/res/drawable-xhdpi/xinru.jpg b/app/src/main/res/drawable-xhdpi/xinru.jpg
new file mode 100644
index 0000000..7f199cd
Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/xinru.jpg differ
diff --git a/app/src/main/res/drawable/list_divider.xml b/app/src/main/res/drawable/list_divider.xml
new file mode 100644
index 0000000..383a429
--- /dev/null
+++ b/app/src/main/res/drawable/list_divider.xml
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/drawable/list_divider_p.xml b/app/src/main/res/drawable/list_divider_p.xml
new file mode 100644
index 0000000..dc9ea11
--- /dev/null
+++ b/app/src/main/res/drawable/list_divider_p.xml
@@ -0,0 +1,8 @@
+
+
+ -
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/drawable/list_item_bg.xml b/app/src/main/res/drawable/list_item_bg.xml
new file mode 100644
index 0000000..a9c68a1
--- /dev/null
+++ b/app/src/main/res/drawable/list_item_bg.xml
@@ -0,0 +1,22 @@
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/activity_adapter.xml b/app/src/main/res/layout/activity_adapter.xml
index aef4c57..0216d88 100644
--- a/app/src/main/res/layout/activity_adapter.xml
+++ b/app/src/main/res/layout/activity_adapter.xml
@@ -6,6 +6,9 @@
+ android:layout_height="match_parent"
+ android:footerDividersEnabled="false"
+ android:divider="@drawable/list_divider"
+ android:dividerHeight="1dp">
diff --git a/app/src/main/res/layout/activity_adapter_recycler.xml b/app/src/main/res/layout/activity_adapter_recycler.xml
new file mode 100644
index 0000000..5014665
--- /dev/null
+++ b/app/src/main/res/layout/activity_adapter_recycler.xml
@@ -0,0 +1,12 @@
+
+
+
+
+
diff --git a/app/src/main/res/layout/activity_app.xml b/app/src/main/res/layout/activity_app.xml
index c83387a..0bfb101 100644
--- a/app/src/main/res/layout/activity_app.xml
+++ b/app/src/main/res/layout/activity_app.xml
@@ -1,12 +1,25 @@
-
-
+
-
+
+
+
+
diff --git a/app/src/main/res/layout/activity_bitmap.xml b/app/src/main/res/layout/activity_bitmap.xml
new file mode 100644
index 0000000..0030c92
--- /dev/null
+++ b/app/src/main/res/layout/activity_bitmap.xml
@@ -0,0 +1,17 @@
+
+
+
+
+
+
+
diff --git a/app/src/main/res/layout/activity_display.xml b/app/src/main/res/layout/activity_display.xml
index 3b312fb..6f02e8c 100644
--- a/app/src/main/res/layout/activity_display.xml
+++ b/app/src/main/res/layout/activity_display.xml
@@ -1,12 +1,25 @@
-
+
+
+
diff --git a/app/src/main/res/layout/activity_drawable.xml b/app/src/main/res/layout/activity_drawable.xml
new file mode 100644
index 0000000..632aa14
--- /dev/null
+++ b/app/src/main/res/layout/activity_drawable.xml
@@ -0,0 +1,21 @@
+
+
+
+
+
+
+
diff --git a/app/src/main/res/layout/activity_keyborad.xml b/app/src/main/res/layout/activity_keyborad.xml
index 4f669c7..ba68b90 100644
--- a/app/src/main/res/layout/activity_keyborad.xml
+++ b/app/src/main/res/layout/activity_keyborad.xml
@@ -1,12 +1,29 @@
-
-
+
-
+
+
+
+
+
diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml
index 385c3ac..8fd5755 100644
--- a/app/src/main/res/layout/activity_main.xml
+++ b/app/src/main/res/layout/activity_main.xml
@@ -6,6 +6,8 @@
+ android:layout_height="wrap_content"
+ android:divider="@drawable/list_divider_p"
+ android:dividerHeight="1dp">
diff --git a/app/src/main/res/layout/activity_main_list_item.xml b/app/src/main/res/layout/activity_main_list_item.xml
index c4a29e1..847d0ee 100644
--- a/app/src/main/res/layout/activity_main_list_item.xml
+++ b/app/src/main/res/layout/activity_main_list_item.xml
@@ -1,6 +1,6 @@
+ android:layout_height="wrap_content">
-
-
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ xmlns:app="http://schemas.android.com/apk/res-auto">
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/app/src/main/res/layout/activity_view.xml b/app/src/main/res/layout/activity_view.xml
index 0ee1cb1..837d7c4 100644
--- a/app/src/main/res/layout/activity_view.xml
+++ b/app/src/main/res/layout/activity_view.xml
@@ -1,12 +1,29 @@
-
-
+
-
+
+
+
+
+
+
+
+
diff --git a/app/src/main/res/layout/adapter_list_item_header.xml b/app/src/main/res/layout/adapter_list_item_header.xml
index 33c19af..0b70684 100644
--- a/app/src/main/res/layout/adapter_list_item_header.xml
+++ b/app/src/main/res/layout/adapter_list_item_header.xml
@@ -1,6 +1,6 @@
+
+ #fff
+ #eee
+
\ No newline at end of file
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index c3c6f07..c97142c 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -10,6 +10,7 @@
AdapterActivity
BaseAdapterActivity
PagerAdapterActivity
+ RecyclerAdapterActivity
UpdateActivity
ActivityActivity
CacheActivity
@@ -25,5 +26,7 @@
ToastActivity
ViewActivity
AppActivity
+ DrawableActivity
+ BitmapActivity
diff --git a/build.gradle b/build.gradle
index cc7daad..9987d03 100644
--- a/build.gradle
+++ b/build.gradle
@@ -3,11 +3,12 @@
buildscript {
repositories {
jcenter()
+ google()
}
dependencies {
- classpath 'com.android.tools.build:gradle:1.0.0'
- classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.0'
- classpath 'com.github.dcendents:android-maven-plugin:1.2'
+ classpath 'com.android.tools.build:gradle:3.0.1'
+ classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.1'
+ classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
@@ -16,5 +17,6 @@ buildscript {
allprojects {
repositories {
jcenter()
+ google()
}
}
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index 0c71e76..cb24766 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -1,6 +1,6 @@
-#Wed Apr 10 15:27:10 PDT 2013
+#Wed Mar 28 16:07:08 CST 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
diff --git a/lesscode-core/build.gradle b/lesscode-core/build.gradle
index ccd6484..55d9bb4 100644
--- a/lesscode-core/build.gradle
+++ b/lesscode-core/build.gradle
@@ -2,15 +2,15 @@ apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'
apply plugin: 'com.jfrog.bintray'
-version = "0.6.4" // #CONFIG# // project version
+version = "2.4.2" // #CONFIG# // project version
android {
- compileSdkVersion 21
- buildToolsVersion "21.1.2"
- resourcePrefix "less_" // #CONFIG# // please remove this if you don't known it
+ compileSdkVersion 27
+ buildToolsVersion "27.0.2"
+ // resourcePrefix "less_" // #CONFIG# // please remove this if you don't known it
defaultConfig {
- minSdkVersion 8
- targetSdkVersion 21
+ minSdkVersion 14
+ targetSdkVersion 27
versionCode 1
versionName "1.0"
}
@@ -20,12 +20,16 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
+
+ lintOptions {
+ abortOnError false
+ }
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
- compile 'com.android.support:support-v4:22.2.1'
- compile 'com.android.support:recyclerview-v7:22.2.1'
+ compile 'com.android.support:support-v4:27.0.2'
+ compile 'com.android.support:recyclerview-v7:27.0.2'
}
def siteUrl = 'https://github.com/openproject/LessCode' // #CONFIG# // project homepage
@@ -80,15 +84,19 @@ task javadocJar(type: Jar, dependsOn: javadoc) {
}
artifacts {
- archives javadocJar
+ // archives javadocJar
archives sourcesJar
}
Properties properties = new Properties()
-properties.load(project.rootProject.file('local.properties').newDataInputStream())
+boolean isHasFile = false
+if (project.rootProject.file('local.properties') != null){
+ isHasFile = true
+ properties.load(project.rootProject.file('local.properties').newDataInputStream())
+}
bintray {
- user = properties.getProperty("bintray.user")
- key = properties.getProperty("bintray.apikey")
+ user = isHasFile ? properties.getProperty("bintray.user") : System.getenv("bintray.user")
+ key = isHasFile ? properties.getProperty("bintray.apikey") : System.getenv("bintray.apikey")
configurations = ['archives']
pkg {
repo = "maven"
diff --git a/lesscode-core/proguard-rules.pro b/lesscode-core/proguard-rules.pro
index 3ffecd2..4ee7340 100644
--- a/lesscode-core/proguard-rules.pro
+++ b/lesscode-core/proguard-rules.pro
@@ -12,6 +12,17 @@
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
-#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
+#-keepattributes Exceptions,InnerClasses
+# keep public class
+#-dontwarn com.jayfeng.lesscode.core.*
+#-keep public class com.jayfeng.lesscode.core.*
+#-keep public class *$*
+# keep public member
+#-keepclassmembers class com.jayfeng.lesscode.core.* {
+# public *;
+}
+#-keepclassmembers class com.jayfeng.lesscode.core.*$* {
# public *;
#}
+# keep and reflect
+#-keepattributes Signature
diff --git a/lesscode-core/src/androidTest/java/com/jayfeng/lesscode/core/ApplicationTest.java b/lesscode-core/src/androidTest/java/com/jayfeng/lesscode/core/ApplicationTest.java
deleted file mode 100644
index 896d6d6..0000000
--- a/lesscode-core/src/androidTest/java/com/jayfeng/lesscode/core/ApplicationTest.java
+++ /dev/null
@@ -1,13 +0,0 @@
-package com.jayfeng.lesscode.core;
-
-import android.app.Application;
-import android.test.ApplicationTestCase;
-
-/**
- * Testing Fundamentals
- */
-public class ApplicationTest extends ApplicationTestCase {
- public ApplicationTest() {
- super(Application.class);
- }
-}
\ No newline at end of file
diff --git a/lesscode-core/src/main/AndroidManifest.xml b/lesscode-core/src/main/AndroidManifest.xml
index a015d3a..25dc021 100644
--- a/lesscode-core/src/main/AndroidManifest.xml
+++ b/lesscode-core/src/main/AndroidManifest.xml
@@ -8,9 +8,6 @@
-
-
-
-
+
diff --git a/lesscode-core/src/main/java/com/jayfeng/lesscode/core/$.java b/lesscode-core/src/main/java/com/jayfeng/lesscode/core/$.java
index 5807d51..0caf8e9 100644
--- a/lesscode-core/src/main/java/com/jayfeng/lesscode/core/$.java
+++ b/lesscode-core/src/main/java/com/jayfeng/lesscode/core/$.java
@@ -2,10 +2,11 @@
import android.content.Context;
-public class $ {
-
- private static $ instance;
-
+public final class $ {
+ /**
+ * 单例
+ */
+ private volatile static $ instance;
public static $ getInstance() {
if (instance == null) {
synchronized ($.class) {
@@ -17,6 +18,9 @@ public class $ {
return instance;
}
+ /**
+ * 名义上为build,实则是检查一些必须配置的变量
+ */
public void build(){
if (sAppContext == null) {
throw new RuntimeException("please config the lesscode application context");
diff --git a/lesscode-core/src/main/java/com/jayfeng/lesscode/core/ActivityLess.java b/lesscode-core/src/main/java/com/jayfeng/lesscode/core/ActivityLess.java
index 9e8afce..17ac313 100644
--- a/lesscode-core/src/main/java/com/jayfeng/lesscode/core/ActivityLess.java
+++ b/lesscode-core/src/main/java/com/jayfeng/lesscode/core/ActivityLess.java
@@ -4,20 +4,36 @@
import android.view.Window;
import android.view.WindowManager;
-public class ActivityLess {
+public final class ActivityLess {
+ /**
+ * 第一次和第二次的退出间隔时间基准
+ */
private static final long EXIT_TWICE_INTERVAL = 2000;
private static long mExitTime = 0;
+ /**
+ * 设置Activity无标题
+ * @param activity
+ */
public static void $noTitle(Activity activity) {
activity.requestWindowFeature(Window.FEATURE_NO_TITLE);
}
+ /**
+ * 设置Activity全屏
+ * @param activity
+ */
public static void $fullScreen(Activity activity) {
$fullScreen(activity, true);
}
+ /**
+ * 根据参数设置Activity是否全屏
+ * @param activity
+ * @param fullScreen
+ */
public static void $fullScreen(Activity activity, boolean fullScreen) {
if (fullScreen) {
activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
@@ -31,6 +47,10 @@ public class ActivityLess {
}
+ /**
+ * 第二次按退出则返回true,否则返回false
+ * @return
+ */
public static boolean $exitTwice() {
long newExitTime = System.currentTimeMillis();
if (newExitTime - mExitTime > EXIT_TWICE_INTERVAL) {
@@ -40,4 +60,13 @@ public class ActivityLess {
return true;
}
}
+
+ /**
+ * 优化activity的背景过度绘制
+ * 在合适的时候调用,建议放在super.onCreate(saveInstanceState)代码下面一行
+ * @param activity
+ */
+ public static void $optimizeBackgroundOverdraw(Activity activity) {
+ activity.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
+ }
}
diff --git a/lesscode-core/src/main/java/com/jayfeng/lesscode/core/AdapterLess.java b/lesscode-core/src/main/java/com/jayfeng/lesscode/core/AdapterLess.java
deleted file mode 100644
index bb9a09e..0000000
--- a/lesscode-core/src/main/java/com/jayfeng/lesscode/core/AdapterLess.java
+++ /dev/null
@@ -1,276 +0,0 @@
-package com.jayfeng.lesscode.core;
-
-import android.content.Context;
-import android.support.v4.app.Fragment;
-import android.support.v4.app.FragmentManager;
-import android.support.v4.app.FragmentPagerAdapter;
-import android.support.v4.view.PagerAdapter;
-import android.support.v7.widget.RecyclerView;
-import android.util.SparseArray;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.ViewGroup;
-import android.widget.BaseAdapter;
-
-import java.util.List;
-
-public class AdapterLess {
-
- public static RecyclerView.Adapter $recycle(final Context context,
- final List list,
- final int layoutId,
- final RecycleCallBack recycleCallBack) {
- RecyclerView.Adapter result = new RecyclerView.Adapter() {
- @Override
- public RecycleViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
- View view = LayoutInflater.from(context)
- .inflate(layoutId, viewGroup, false);
- RecycleViewHolder recycleViewHolder = new RecycleViewHolder(view);
- return recycleViewHolder;
- }
-
- @Override
- public void onBindViewHolder(RecycleViewHolder viewHolder, int position) {
- T t = list.get(position);
- recycleCallBack.onBindViewHolder(position, viewHolder, t);
- }
-
- @Override
- public int getItemCount() {
- if (list != null) {
- return list.size();
- }
- return 0;
- }
- };
- return result;
- }
-
- public static BaseAdapter $base(final Context context,
- final List list,
- final int layoutId,
- final CallBack callBack) {
-
- BaseAdapter result = new BaseAdapter() {
-
- @Override
- public int getCount() {
- if (list != null) {
- return list.size();
- }
- return 0;
- }
-
- @Override
- public T getItem(int position) {
- return list.get(position);
- }
-
- @Override
- public long getItemId(int position) {
- return 0;
- }
-
- @Override
- public View getView(int position, View convertView, ViewGroup parent) {
- ViewHolder holder;
- if (null == convertView) {
- holder = new ViewHolder();
- convertView = LayoutInflater.from(context).inflate(layoutId, null);
- ;
- convertView.setTag(holder);
- } else {
- holder = (ViewHolder) convertView.getTag();
- }
- T t = getItem(position);
- return callBack.getView(position, convertView, holder, t);
- }
-
- };
- return result;
- }
-
-
- public static BaseAdapter $base(final Context context,
- final List list,
- final int[] layoutIds,
- final FullCallBack fullCallBack) {
-
- BaseAdapter result = new BaseAdapter() {
-
- @Override
- public int getCount() {
- if (list != null) {
- return list.size();
- }
- return 0;
- }
-
- @Override
- public T getItem(int position) {
- return list.get(position);
- }
-
- @Override
- public long getItemId(int position) {
- return 0;
- }
-
- @Override
- public int getItemViewType(int position) {
- return fullCallBack.getItemViewType(position);
- }
-
- @Override
- public int getViewTypeCount() {
- return layoutIds.length;
- }
-
- @Override
- public boolean isEnabled(int position) {
- return fullCallBack.isEnabled(position);
- }
-
- @Override
- public View getView(int position, View convertView, ViewGroup parent) {
- ViewHolder[] holders = new ViewHolder[layoutIds.length];
- int i = getItemViewType(position);
- if (null == convertView) {
- holders[i] = new ViewHolder();
- convertView = LayoutInflater.from(context).inflate(layoutIds[i], null);
- convertView.setTag(holders[i]);
- } else {
- holders[i] = (ViewHolder) convertView.getTag();
- }
- T t = getItem(position);
- return fullCallBack.getView(position, convertView, holders[i], t);
- }
-
- };
- return result;
- }
-
- public static PagerAdapter $pager(final Context context,
- final List list,
- final int layoutId,
- final PageCallBack pageCallBack) {
- PagerAdapter result = new PagerAdapter() {
-
- @Override
- public int getCount() {
- return list.size();
- }
-
- @Override
- public boolean isViewFromObject(View view, Object object) {
- return view == object;
- }
-
- @Override
- public Object instantiateItem(ViewGroup container, int position) {
- View view = LayoutInflater.from(context).inflate(layoutId, null);
- container.addView(view);
- pageCallBack.instantiateItem(position, view, list.get(position));
- return view;
- }
-
- @Override
- public void destroyItem(ViewGroup container, int position, Object object) {
- container.removeView((View) object);
- }
- };
- return result;
- }
-
- public static FragmentPagerAdapter $pager(FragmentManager fragmentManager,
- final int count,
- final FragmentPagerCallBack fragmentPagerCallBack) {
- FragmentPagerAdapter result = new FragmentPagerAdapter(fragmentManager) {
- @Override
- public Fragment getItem(int position) {
- return fragmentPagerCallBack.getItem(position);
- }
-
- @Override
- public int getCount() {
- return count;
- }
- };
- return result;
- }
-
- public static FragmentPagerAdapter $pager(final FragmentManager fragmentManager,
- final int count,
- final FullFragmentPagerCallBack fullFragmentPagerCallBack) {
- FragmentPagerAdapter result = new FragmentPagerAdapter(fragmentManager) {
- @Override
- public Fragment getItem(int position) {
- return fullFragmentPagerCallBack.getItem(position);
- }
-
- @Override
- public int getCount() {
- return count;
- }
-
- @Override
- public String getPageTitle(int position) {
- return fullFragmentPagerCallBack.getPageTitle(position);
- }
- };
- return result;
- }
-
- public interface RecycleCallBack {
- void onBindViewHolder(int position, RecycleViewHolder recycleViewHolder, T t);
- }
-
- public interface CallBack {
- View getView(int position, View convertView, ViewHolder holder, T t);
- }
-
- public interface FullCallBack {
- View getView(int position, View convertView, ViewHolder holder, T t);
-
- int getItemViewType(int position);
-
- boolean isEnabled(int position);
- }
-
- public interface PageCallBack {
- void instantiateItem(int position, View view, T t);
- }
-
- public interface FragmentPagerCallBack {
- Fragment getItem(int position);
- }
-
- public interface FullFragmentPagerCallBack {
- Fragment getItem(int position);
- String getPageTitle(int position);
- }
-
-
- public static class ViewHolder {
- public SparseArray views = new SparseArray();
-
- public T $view(View convertView, int viewId) {
- View v = views.get(viewId);
- if (null == v) {
- v = ViewLess.$(convertView, viewId);
- views.put(viewId, v);
- }
- return (T) v;
- }
- }
-
- public static class RecycleViewHolder extends RecyclerView.ViewHolder {
- public RecycleViewHolder(View itemView) {
- super(itemView);
- }
-
- public T $view(int viewId) {
- return ViewLess.$(itemView, viewId);
- }
- }
-}
diff --git a/lesscode-core/src/main/java/com/jayfeng/lesscode/core/AlarmLess.java b/lesscode-core/src/main/java/com/jayfeng/lesscode/core/AlarmLess.java
new file mode 100644
index 0000000..a9fc351
--- /dev/null
+++ b/lesscode-core/src/main/java/com/jayfeng/lesscode/core/AlarmLess.java
@@ -0,0 +1,57 @@
+package com.jayfeng.lesscode.core;
+
+import android.app.AlarmManager;
+import android.app.PendingIntent;
+import android.content.Context;
+import android.content.Intent;
+
+public final class AlarmLess {
+
+ /**
+ * 开启定时器
+ * @param context
+ * @param triggerAtMillis
+ * @param pendingIntent
+ */
+ public static void $startIntent(Context context, int triggerAtMillis, PendingIntent pendingIntent) {
+ AlarmManager manager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
+ manager.set(AlarmManager.RTC_WAKEUP, triggerAtMillis, pendingIntent);
+ }
+
+ /**
+ * 停止定时器
+ * @param context
+ * @param pendingIntent
+ */
+ public static void $stop(Context context, PendingIntent pendingIntent) {
+ AlarmManager manager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
+ manager.cancel(pendingIntent);
+ }
+
+ /**
+ * 开启轮询闹钟
+ * @param context
+ * @param triggerAtMillis
+ * @param cls
+ * @param action
+ */
+ public static void $startAction(Context context, int triggerAtMillis, Class> cls, String action) {
+ Intent intent = new Intent(context, cls);
+ intent.setAction(action);
+ PendingIntent pendingIntent = PendingIntent.getService(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
+ $startIntent(context, triggerAtMillis, pendingIntent);
+ }
+
+ /**
+ * 停止轮询闹钟
+ * @param context
+ * @param cls
+ * @param action
+ */
+ public static void $stop(Context context, Class> cls, String action) {
+ Intent intent = new Intent(context, cls);
+ intent.setAction(action);
+ PendingIntent pendingIntent = PendingIntent.getService(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
+ $stop(context, pendingIntent);
+ }
+}
diff --git a/lesscode-core/src/main/java/com/jayfeng/lesscode/core/AppLess.java b/lesscode-core/src/main/java/com/jayfeng/lesscode/core/AppLess.java
index c13fafe..e9f2a61 100644
--- a/lesscode-core/src/main/java/com/jayfeng/lesscode/core/AppLess.java
+++ b/lesscode-core/src/main/java/com/jayfeng/lesscode/core/AppLess.java
@@ -5,17 +5,23 @@
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
+import android.content.pm.Signature;
+import java.io.File;
import java.util.List;
-public class AppLess {
+public final class AppLess {
- public static int $vercode(Context context) {
+ /**
+ * 获取app的版本数versionCode,比如38
+ * @return
+ */
+ public static int $vercode() {
int result = 0;
- String packageName = context.getPackageName();
+ String packageName = $.sAppContext.getPackageName();
PackageInfo packageInfo;
try {
- packageInfo = context.getPackageManager().getPackageInfo(packageName, 0);
+ packageInfo = $.sAppContext.getPackageManager().getPackageInfo(packageName, 0);
result = packageInfo.versionCode;
} catch (PackageManager.NameNotFoundException e) {
throw new AssertionError(e);
@@ -23,12 +29,16 @@ public class AppLess {
return result;
}
- public static String $vername(Context context) {
+ /**
+ * 获取app的版本名versionName,比如0.6.9
+ * @return
+ */
+ public static String $vername() {
String result = null;
- String packageName = context.getPackageName();
+ String packageName = $.sAppContext.getPackageName();
PackageInfo packageInfo;
try {
- packageInfo = context.getPackageManager().getPackageInfo(packageName, 0);
+ packageInfo = $.sAppContext.getPackageManager().getPackageInfo(packageName, 0);
result = packageInfo.versionName;
} catch (PackageManager.NameNotFoundException e) {
throw new AssertionError(e);
@@ -36,12 +46,16 @@ public class AppLess {
return result;
}
- public static String $appname(Context context) {
+ /**
+ * 获取app的名称
+ * @return
+ */
+ public static String $appname() {
String result = null;
- String packageName = context.getPackageName();
+ String packageName = $.sAppContext.getPackageName();
ApplicationInfo applicationInfo;
try {
- PackageManager packageManager = context.getPackageManager();
+ PackageManager packageManager = $.sAppContext.getPackageManager();
applicationInfo = packageManager.getApplicationInfo(packageName, 0);
result = packageManager.getApplicationLabel(applicationInfo).toString();
} catch (PackageManager.NameNotFoundException e) {
@@ -52,11 +66,16 @@ public class AppLess {
return result;
}
- public static boolean $running(Context context, String packageName) {
+ /**
+ * 判断一个app是否在运行
+ * @param packageName app的包名
+ * @return 在运行则返回true,否则false
+ */
+ public static boolean $running(String packageName) {
if (packageName == null) {
- packageName = context.getPackageName();
+ packageName = $.sAppContext.getPackageName();
}
- ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
+ ActivityManager am = (ActivityManager) $.sAppContext.getSystemService(Context.ACTIVITY_SERVICE);
List infos = am.getRunningAppProcesses();
for(ActivityManager.RunningAppProcessInfo rapi : infos){
if(rapi.processName.equals(packageName))
@@ -65,8 +84,13 @@ public class AppLess {
return false;
}
- public static boolean isTopActivy(Context context, String activityName) {
- ActivityManager manager = (ActivityManager) context.getSystemService(context.ACTIVITY_SERVICE);
+ /**
+ * 判断一个activity是否在前台运行
+ * @param activityName activity的全路径名称
+ * @return 在前台则返回true,否则返回false
+ */
+ public static boolean isTopActivy(String activityName) {
+ ActivityManager manager = (ActivityManager) $.sAppContext.getSystemService(Context.ACTIVITY_SERVICE);
List runningTaskInfos = manager.getRunningTasks(1);
String cmpNameTemp = null;
@@ -80,4 +104,76 @@ public static boolean isTopActivy(Context context, String activityName) {
return cmpNameTemp.endsWith(activityName);
}
+ /**
+ * 获取应用公钥签名
+ * @param context
+ * @return
+ */
+ public static Signature $sign(Context context) {
+ PackageInfo pi;
+ Signature sign = null;
+ try {
+ pi = context.getPackageManager().getPackageInfo(
+ context.getPackageName(), PackageManager.GET_SIGNATURES);
+ sign = pi.signatures[0];
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return sign;
+ }
+
+ /**
+ * 比较当前签名HashCode和预设的HashCode
+ * @param context
+ * @param presetHashCode
+ * @return
+ */
+ public static boolean $signCheckWithHashCode(Context context, int presetHashCode) {
+ Signature signature = $sign(context);
+ return signature.hashCode() == presetHashCode;
+ }
+
+ /**
+ * 删除应用数据: cache, file, share prefs, databases
+ * @param context
+ */
+ public static void $clear(Context context) {
+ $clearCache(context);
+ $clearFiles(context);
+ $clearSharedPreference(context);
+ $clearDatabase(context);
+ }
+
+ /**
+ * 删除应用缓存目录
+ * @param context
+ */
+ public static void $clearCache(Context context) {
+ FileLess.$del(context.getCacheDir(), true);
+ FileLess.$del(context.getExternalCacheDir(), true);
+ }
+
+ /**
+ * 删除应用文件目录
+ * @param context
+ */
+ public static void $clearFiles(Context context) {
+ FileLess.$del(context.getFilesDir(), true);
+ }
+
+ /**
+ * 删除应用Shared Prefrence目录
+ * @param context
+ */
+ public static void $clearSharedPreference(Context context) {
+ FileLess.$del(new File("/data/data/" + context.getPackageName() + "/shared_prefs"), true);
+ }
+
+ /**
+ * 删除应用数据库目录
+ * @param context
+ */
+ public static void $clearDatabase(Context context) {
+ FileLess.$del(new File("/data/data/" + context.getPackageName() + "/databases"), true);
+ }
}
diff --git a/lesscode-core/src/main/java/com/jayfeng/lesscode/core/ApplicationLess.java b/lesscode-core/src/main/java/com/jayfeng/lesscode/core/ApplicationLess.java
new file mode 100644
index 0000000..4a521bb
--- /dev/null
+++ b/lesscode-core/src/main/java/com/jayfeng/lesscode/core/ApplicationLess.java
@@ -0,0 +1,29 @@
+package com.jayfeng.lesscode.core;
+
+import android.app.ActivityManager;
+import android.content.Context;
+import android.os.Process;
+
+import java.util.List;
+
+public final class ApplicationLess {
+
+ /**
+ * 根据进程名称判断第一次真正的初始化
+ *
+ * @param context
+ * @return
+ */
+ public static boolean $init(Context context) {
+ ActivityManager am = ((ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE));
+ List processInfos = am.getRunningAppProcesses();
+ String mainProcessName = context.getPackageName();
+ int myPid = Process.myPid();
+ for (ActivityManager.RunningAppProcessInfo info : processInfos) {
+ if (info.pid == myPid && mainProcessName.equals(info.processName)) {
+ return true;
+ }
+ }
+ return false;
+ }
+}
diff --git a/lesscode-core/src/main/java/com/jayfeng/lesscode/core/BitmapLess.java b/lesscode-core/src/main/java/com/jayfeng/lesscode/core/BitmapLess.java
new file mode 100644
index 0000000..b59bd16
--- /dev/null
+++ b/lesscode-core/src/main/java/com/jayfeng/lesscode/core/BitmapLess.java
@@ -0,0 +1,339 @@
+package com.jayfeng.lesscode.core;
+
+import android.content.Context;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import android.graphics.Canvas;
+import android.graphics.Color;
+import android.graphics.ColorMatrix;
+import android.graphics.ColorMatrixColorFilter;
+import android.graphics.Matrix;
+import android.graphics.Paint;
+import android.graphics.PorterDuff;
+import android.graphics.PorterDuffXfermode;
+import android.graphics.Rect;
+import android.graphics.RectF;
+import android.os.Environment;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.UUID;
+
+public final class BitmapLess {
+
+ /**
+ * 根据reqWidth, reqHeight计算最合适的inSampleSize
+ *
+ * @param options
+ * @param maxWidth
+ * @param maxHeight
+ * @return
+ */
+ public static int $sampleSize(BitmapFactory.Options options, int maxWidth, int maxHeight) {
+ // raw height and width of image
+ int rawWidth = options.outWidth;
+ int rawHeight = options.outHeight;
+
+ // calculate best sample size
+ int inSampleSize = 0;
+ if (rawHeight > maxHeight || rawWidth > maxWidth) {
+ float ratioWidth = (float) rawWidth / maxWidth;
+ float ratioHeight = (float) rawHeight / maxHeight;
+ inSampleSize = (int) Math.min(ratioHeight, ratioWidth);
+ }
+ inSampleSize = Math.max(1, inSampleSize);
+
+ return inSampleSize;
+ }
+
+ /**
+ * 更节省内存的读取raw资源成Bitmap
+ *
+ * @param context
+ * @param rawId
+ * @return
+ */
+ public static Bitmap $raw(Context context, int rawId) {
+ BitmapFactory.Options opt = new BitmapFactory.Options();
+ opt.inPreferredConfig = Bitmap.Config.RGB_565;
+ opt.inPurgeable = true;
+ opt.inInputShareable = true;
+ InputStream is = context.getResources().openRawResource(rawId);
+ return BitmapFactory.decodeStream(is, null, opt);
+ }
+
+ /**
+ * 旋转Bitmap(默认回收传进来的原始Bitmap)
+ *
+ * @param originBitmap
+ * @param angle
+ * @return
+ */
+ public static Bitmap $rotate(Bitmap originBitmap, int angle) {
+ return $rotate(originBitmap, angle, true);
+ }
+
+ /**
+ * 旋转Bitmap
+ *
+ * @param angle
+ * @param originBitmap
+ * @param recycle 是否回收传进来的原始Bitmap
+ * @return
+ */
+ public static Bitmap $rotate(Bitmap originBitmap, int angle, boolean recycle) {
+ Matrix matrix = new Matrix();
+ matrix.postRotate(angle);
+ Bitmap rotatedBitmap = Bitmap.createBitmap(originBitmap,
+ 0, 0, originBitmap.getWidth(), originBitmap.getHeight(), matrix, true);
+ if (recycle && originBitmap != null && !originBitmap.isRecycled()) {
+ originBitmap.recycle();
+ }
+ return rotatedBitmap;
+ }
+
+ /**
+ * 缩放Bitmap(默认回收传进来的原始Bitmap)
+ *
+ * @param originBitmap
+ * @param scaleX
+ * @param scaleY
+ * @return
+ */
+ public static Bitmap $scale(Bitmap originBitmap, float scaleX, float scaleY) {
+ return $scale(originBitmap, scaleX, scaleY, true);
+ }
+
+ /**
+ * 缩放Bitmap - 按缩放倍数
+ *
+ * @param originBitmap
+ * @param scaleX
+ * @param scaleY
+ * @param recycle 是否回收传进来的原始Bitmap
+ * @return
+ */
+ public static Bitmap $scale(Bitmap originBitmap, float scaleX, float scaleY, boolean recycle) {
+ Matrix matrix = new Matrix();
+ matrix.postScale(scaleX, scaleY);
+ Bitmap scaledBitmap = Bitmap.createBitmap(originBitmap,
+ 0, 0, originBitmap.getWidth(), originBitmap.getHeight(), matrix, true);
+ if (recycle && originBitmap != null && !originBitmap.isRecycled()) {
+ originBitmap.recycle();
+ }
+ return scaledBitmap;
+ }
+
+ /**
+ * 缩放Bitmap - 缩放到目标大小
+ *
+ * @param originBitmap
+ * @param dstWidth
+ * @param dstHeight
+ * @param recycle 是否回收传进来的原始Bitmap
+ * @return
+ */
+ public static Bitmap $scale(Bitmap originBitmap, int dstWidth, int dstHeight, boolean recycle) {
+ Bitmap scaledBitmap = Bitmap.createScaledBitmap(originBitmap, dstWidth, dstHeight, true);
+ if (recycle && originBitmap != null && !originBitmap.isRecycled()) {
+ originBitmap.recycle();
+ }
+ return scaledBitmap;
+ }
+
+ /**
+ * 获取缩略图(默认关闭自动旋转)
+ *
+ * @param path
+ * @param maxWidth
+ * @param maxHeight
+ * @return
+ */
+ public static Bitmap $thumbnail(String path, int maxWidth, int maxHeight) {
+ return $thumbnail(path, maxWidth, maxHeight, false);
+ }
+
+ /**
+ * 获取缩略图
+ * 1. 支持自动旋转
+ *
+ * @param path
+ * @param maxWidth
+ * @param maxHeight
+ * @param autoRotate
+ * @return
+ */
+ public static Bitmap $thumbnail(String path, int maxWidth, int maxHeight, boolean autoRotate) {
+
+ int angle = 0;
+ if (autoRotate) {
+ angle = ImageLess.$exifRotateAngle(path);
+ }
+
+ BitmapFactory.Options options = new BitmapFactory.Options();
+ options.inJustDecodeBounds = true;
+ // 获取这个图片的宽和高, 此时返回bm为空
+ Bitmap bitmap = BitmapFactory.decodeFile(path, options);
+ options.inJustDecodeBounds = false;
+ // 计算缩放比
+ int sampleSize = $sampleSize(options, maxWidth, maxHeight);
+ options.inSampleSize = sampleSize;
+ options.inPreferredConfig = Bitmap.Config.RGB_565;
+ options.inPurgeable = true;
+ options.inInputShareable = true;
+
+ if (bitmap != null && !bitmap.isRecycled()) {
+ bitmap.recycle();
+ }
+ bitmap = BitmapFactory.decodeFile(path, options);
+
+ if (autoRotate && angle != 0) {
+ bitmap = $rotate(bitmap, angle);
+ }
+
+ return bitmap;
+ }
+
+ /**
+ * 保存到本地,默认路径/mnt/sdcard/[package]/save/
+ *
+ * @param bitmap
+ * @param format
+ * @param quality
+ * @param context
+ * @return
+ */
+ public static String $save(Bitmap bitmap, Bitmap.CompressFormat format, int quality, Context context) {
+ if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
+ return null;
+ }
+
+ File dir = new File(Environment.getExternalStorageDirectory() + "/" + context.getPackageName() + "/save/");
+ if (!dir.exists()) {
+ dir.mkdirs();
+ }
+ File destFile = new File(dir, UUID.randomUUID().toString());
+ return $save(bitmap, format, quality, destFile);
+ }
+
+ /**
+ * 保存到本地destFile
+ *
+ * @param bitmap
+ * @param format
+ * @param quality
+ * @param destFile
+ * @return
+ */
+ public static String $save(Bitmap bitmap, Bitmap.CompressFormat format, int quality, File destFile) {
+ try {
+ FileOutputStream out = new FileOutputStream(destFile);
+ if (bitmap.compress(format, quality, out)) {
+ out.flush();
+ out.close();
+ }
+
+ if (bitmap != null && !bitmap.isRecycled()) {
+ bitmap.recycle();
+ }
+
+ return destFile.getAbsolutePath();
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ /**
+ * 圆角Bitmap
+ *
+ * @param originBitmap
+ * @param radius
+ * @param recycle
+ * @return
+ */
+ public static Bitmap $round(Bitmap originBitmap, int radius, boolean recycle) {
+ // 准备画笔
+ Paint paint = new Paint();
+ paint.setAntiAlias(true);
+
+ // 准备裁剪的矩阵
+ Rect rect = new Rect(0, 0, originBitmap.getWidth(), originBitmap.getHeight());
+ RectF rectF = new RectF(new Rect(0, 0, originBitmap.getWidth(), originBitmap.getHeight()));
+
+ Bitmap roundBitmap = Bitmap.createBitmap(originBitmap.getWidth(), originBitmap.getHeight(), Bitmap.Config.ARGB_8888);
+ Canvas canvas = new Canvas(roundBitmap);
+ canvas.drawRoundRect(rectF, radius, radius, paint);
+
+ // 这一句是核心,关于Xfermode和SRC_IN请自行查阅
+ paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
+ canvas.drawBitmap(originBitmap, rect, rect, paint);
+
+ // 是否回收原始Bitmap
+ if (recycle && originBitmap != null && !originBitmap.isRecycled()) {
+ originBitmap.recycle();
+ }
+
+ return roundBitmap;
+ }
+
+ /**
+ * 圆形Bitmap:居中裁剪
+ *
+ * @param originBitmap
+ * @param recycle
+ * @return
+ */
+ public static Bitmap $circle(Bitmap originBitmap, boolean recycle) {
+ int min = originBitmap.getWidth() > originBitmap.getHeight() ? originBitmap.getHeight() : originBitmap.getWidth();
+ Paint paint = new Paint();
+ paint.setAntiAlias(true);
+ Bitmap circleBitmap = Bitmap.createBitmap(min, min, Bitmap.Config.ARGB_8888);
+ Canvas canvas = new Canvas(circleBitmap);
+ canvas.drawCircle(min / 2, min / 2, min / 2, paint);
+ paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
+
+ // 居中显示
+ int left = - (originBitmap.getWidth() - min) / 2;
+ int top = - (originBitmap.getHeight() - min) / 2;
+ canvas.drawBitmap(originBitmap, left, top, paint);
+
+ // 是否回收原始Bitmap
+ if (recycle && originBitmap != null && !originBitmap.isRecycled()) {
+ originBitmap.recycle();
+ }
+
+ return circleBitmap;
+ }
+
+ /**
+ * 灰阶效果
+ * @param originBitmap
+ * @param recycle
+ * @return
+ */
+ public static Bitmap $gray(Bitmap originBitmap, boolean recycle) {
+ Bitmap grayBitmap = Bitmap.createBitmap(originBitmap.getWidth(),
+ originBitmap.getHeight(), Bitmap.Config.RGB_565);
+ Canvas canvas = new Canvas(grayBitmap);
+ Paint paint = new Paint();
+ ColorMatrix colorMatrix = new ColorMatrix();
+ colorMatrix.setSaturation(0);
+ ColorMatrixColorFilter colorMatrixColorFilter =
+ new ColorMatrixColorFilter(colorMatrix);
+ paint.setColorFilter(colorMatrixColorFilter);
+ canvas.drawBitmap(originBitmap, 0, 0, paint);
+
+ // 是否回收原始Bitmap
+ if (recycle && originBitmap != null && !originBitmap.isRecycled()) {
+ originBitmap.recycle();
+ }
+
+ return grayBitmap;
+ }
+}
diff --git a/lesscode-core/src/main/java/com/jayfeng/lesscode/core/CacheLess.java b/lesscode-core/src/main/java/com/jayfeng/lesscode/core/CacheLess.java
index 93d2a80..5a6384c 100644
--- a/lesscode-core/src/main/java/com/jayfeng/lesscode/core/CacheLess.java
+++ b/lesscode-core/src/main/java/com/jayfeng/lesscode/core/CacheLess.java
@@ -3,8 +3,18 @@
import java.io.File;
import java.io.IOException;
-public class CacheLess {
+/**
+ * 缓存相关的工具类
+ * 常用于缓存网络请求返回的json保存到本地的缓存策略
+ */
+public final class CacheLess {
+ /**
+ * 根据key查找缓存的内容
+ * @param key
+ * @param expireTime
+ * @return
+ */
public static String $get(String key, long expireTime) {
String result = null;
@@ -17,19 +27,16 @@ public class CacheLess {
if (file.exists() && file.isFile()) {
long storageTime = System.currentTimeMillis() - file.lastModified();
- NetworkLess.NetworkType networkType = NetworkLess.$type();
+ boolean online = NetworkLess.$online();
- //1. in case the system time is incorrect (the time is turn back long ago)
- //2. when the network is invalid, you can only read the cache
- if (networkType != NetworkLess.NetworkType.NONE && storageTime < 0) {
+ // 如果系统时间不对(被调回很久之前),storageTime和expireTime的比较就没有意义了
+ // 在这种情况下,如果有网就请求新内容,否则才考虑缓存
+ if (online && storageTime < 0) {
return null;
}
- if(networkType == NetworkLess.NetworkType.WIFI_FAST && storageTime > expireTime) {
- return null;
- } else if ((networkType == NetworkLess.NetworkType.MOBILE_FAST
- || networkType == NetworkLess.NetworkType.MOBILE_MIDDLE
- || networkType == NetworkLess.NetworkType.MOBILE_SLOW)
- && storageTime > expireTime) {
+ // 如果有网的情况下,且缓存已经过期,则返回null
+ // 在无网的情况下, 即使过期也返回缓存
+ if (online && storageTime > expireTime) {
return null;
}
try {
@@ -41,6 +48,11 @@ public class CacheLess {
return result;
}
+ /**
+ * 设置字符串为特定key的缓存,保存到本地
+ * @param key
+ * @param data
+ */
public static void $set(String key, String data) {
File cacheDir = $.sAppContext.getCacheDir();
if (StorageLess.Sdcard.$ready()) {
diff --git a/lesscode-core/src/main/java/com/jayfeng/lesscode/core/DeviceLess.java b/lesscode-core/src/main/java/com/jayfeng/lesscode/core/DeviceLess.java
index f94d9a4..c226f7e 100644
--- a/lesscode-core/src/main/java/com/jayfeng/lesscode/core/DeviceLess.java
+++ b/lesscode-core/src/main/java/com/jayfeng/lesscode/core/DeviceLess.java
@@ -7,30 +7,59 @@
import java.io.File;
import java.io.FileInputStream;
+import java.io.IOException;
-public class DeviceLess {
+/**
+ * 设备相关的工具类
+ */
+public final class DeviceLess {
+ /**
+ * 获取设备的mac地址
+ * 这里要特别说明一下,mac地址不是一定能获取的到的,你可能要更优先使用设备ID
+ * @return mac地址
+ */
public static String $mac() {
String result = null;
try {
String path = "sys/class/net/wlan0/address";
if ((new File(path)).exists()) {
- FileInputStream fis = new FileInputStream(path);
- byte[] buffer = new byte[8192];
- int byteCount = fis.read(buffer);
- if (byteCount > 0) {
- result = new String(buffer, 0, byteCount, "utf-8");
+ FileInputStream fis = null;
+ try {
+ fis = new FileInputStream(path);
+ byte[] buffer = new byte[8192];
+ int byteCount = fis.read(buffer);
+ if (byteCount > 0) {
+ result = new String(buffer, 0, byteCount, "utf-8");
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ } finally {
+ if (fis != null) {
+ fis.close();
+ }
}
+
}
if (TextUtils.isEmpty(result)) {
path = "sys/class/net/eth0/address";
- FileInputStream fis_name = new FileInputStream(path);
- byte[] buffer_name = new byte[8192];
- int byteCount_name = fis_name.read(buffer_name);
- if (byteCount_name > 0) {
- result = new String(buffer_name, 0, byteCount_name, "utf-8");
+ FileInputStream fis_name = null;
+ try {
+ fis_name = new FileInputStream(path);
+ byte[] buffer_name = new byte[8192];
+ int byteCount_name = fis_name.read(buffer_name);
+ if (byteCount_name > 0) {
+ result = new String(buffer_name, 0, byteCount_name, "utf-8");
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ } finally {
+ if (fis_name != null) {
+ fis_name.close();
+ }
}
+
}
if (TextUtils.isEmpty(result)) {
diff --git a/lesscode-core/src/main/java/com/jayfeng/lesscode/core/DisplayLess.java b/lesscode-core/src/main/java/com/jayfeng/lesscode/core/DisplayLess.java
index 062e00a..561a340 100644
--- a/lesscode-core/src/main/java/com/jayfeng/lesscode/core/DisplayLess.java
+++ b/lesscode-core/src/main/java/com/jayfeng/lesscode/core/DisplayLess.java
@@ -5,27 +5,121 @@
import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.Bitmap;
+import android.graphics.Rect;
import android.util.DisplayMetrics;
+import android.view.Window;
+import android.view.WindowManager;
-public class DisplayLess {
+import java.lang.reflect.Field;
- public static int $width(Activity activity) {
+/**
+ * 屏幕显示相关的工具类
+ */
+public final class DisplayLess {
+
+ /**
+ * 屏幕宽度
+ *
+ * @param context
+ * @return
+ */
+ public static int $width(Context context) {
DisplayMetrics displayMetrics = new DisplayMetrics();
- activity.getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
+ WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
+ windowManager.getDefaultDisplay().getMetrics(displayMetrics);
return displayMetrics.widthPixels;
}
-
- public static int $height(Activity activity) {
+ /**
+ * 屏幕高度
+ *
+ * @param context
+ * @return
+ */
+ public static int $height(Context context) {
DisplayMetrics displayMetrics = new DisplayMetrics();
- activity.getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
+ WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
+ windowManager.getDefaultDisplay().getMetrics(displayMetrics);
return displayMetrics.heightPixels;
}
+ /**
+ * dp转px
+ *
+ * @param dp
+ * @return
+ */
public static int $dp2px(float dp) {
return (int) (dp * Resources.getSystem().getDisplayMetrics().density);
}
+ /**
+ * sp转px
+ *
+ * @param sp
+ * @return
+ */
+ public static int $sp2px(float sp) {
+ float scale = Resources.getSystem().getDisplayMetrics().scaledDensity;
+ return (int) (sp * scale + 0.5f);
+ }
+
+ /**
+ * 获取状态栏高度
+ * 注: 该方法在onCreate中获取值为0
+ *
+ * @param activity
+ * @return
+ */
+ public static int $statusBarHeight(Activity activity) {
+ Rect frame = new Rect();
+ activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);
+ return frame.top;
+ }
+
+ /**
+ * 获取状态栏高度
+ * 注: 该方法在onCreate中获取值为0
+ *
+ * @param resources
+ * @return
+ */
+ public static int $statusBarHeight(Resources resources) {
+ Class> c = null;
+ Object obj = null;
+ Field field = null;
+ int x = 0;
+ int statusBarHeight = 0;
+ try {
+ c = Class.forName("com.android.internal.R$dimen");
+ obj = c.newInstance();
+ field = c.getField("status_bar_height");
+ x = Integer.parseInt(field.get(obj).toString());
+ statusBarHeight = resources.getDimensionPixelSize(x);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return statusBarHeight;
+ }
+
+ /**
+ * 获取标题栏高度
+ *
+ * @param activity
+ * @return
+ */
+ public static int $titleBarHeight(Activity activity) {
+ int contentTop = activity.getWindow().findViewById(Window.ID_ANDROID_CONTENT).getTop();
+ int titleBarHeight = contentTop - $statusBarHeight(activity);
+ return titleBarHeight;
+ }
+
+ /**
+ * 是否为平板
+ *
+ * @param context
+ * @return
+ */
public static boolean $tablet(Context context) {
return (context.getResources().getConfiguration().screenLayout
& Configuration.SCREENLAYOUT_SIZE_MASK)
@@ -33,27 +127,36 @@ public class DisplayLess {
Configuration.SCREENLAYOUT_SIZE_LARGE;
}
- public static boolean isLdpi() {
+ /**
+ * ****************************
+ * 各大设备密度判断
+ * ****************************
+ */
+ public static boolean $ldpi() {
return $.sAppContext.getResources().getBoolean(R.bool.less_ldpi);
}
- public static boolean isMdpi() {
+ public static boolean $mdpi() {
return $.sAppContext.getResources().getBoolean(R.bool.less_mdpi);
}
- public static boolean isTVdpi() {
+ public static boolean $tvdpi() {
return $.sAppContext.getResources().getBoolean(R.bool.less_tvdpi);
}
- public static boolean isHdpi() {
+ public static boolean $hdpi() {
return $.sAppContext.getResources().getBoolean(R.bool.less_hdpi);
}
- public static boolean isXHdpi() {
+ public static boolean $xhdpi() {
return $.sAppContext.getResources().getBoolean(R.bool.less_xhdpi);
}
- public static boolean isXXHdpi() {
+ public static boolean $xxhdpi() {
return $.sAppContext.getResources().getBoolean(R.bool.less_xxhdpi);
}
+
+ public static boolean $xxxhdpi() {
+ return $.sAppContext.getResources().getBoolean(R.bool.less_xxxhdpi);
+ }
}
diff --git a/lesscode-core/src/main/java/com/jayfeng/lesscode/core/DrawableLess.java b/lesscode-core/src/main/java/com/jayfeng/lesscode/core/DrawableLess.java
new file mode 100644
index 0000000..9e1b02b
--- /dev/null
+++ b/lesscode-core/src/main/java/com/jayfeng/lesscode/core/DrawableLess.java
@@ -0,0 +1,39 @@
+package com.jayfeng.lesscode.core;
+
+import android.content.res.ColorStateList;
+import android.graphics.PorterDuff;
+import android.graphics.drawable.Drawable;
+import android.support.v4.graphics.drawable.DrawableCompat;
+
+public final class DrawableLess {
+
+
+ /**
+ * ========================================================
+ * tint drawable with Color or ColorStateList
+ * using the DrawableCompat in support v4 library
+ * ========================================================
+ */
+ public static Drawable $tint(Drawable originDrawable, int color) {
+ return $tint(originDrawable, ColorStateList.valueOf(color));
+ }
+
+ public static Drawable $tint(Drawable originDrawable, int color, PorterDuff.Mode tintMode) {
+ return $tint(originDrawable, ColorStateList.valueOf(color), tintMode);
+ }
+
+ public static Drawable $tint(Drawable originDrawable, ColorStateList colorStateList) {
+ return $tint(originDrawable, colorStateList, null);
+ }
+
+ public static Drawable $tint(Drawable originDrawable, ColorStateList colorStateList, PorterDuff.Mode tintMode) {
+ Drawable tintDrawable = DrawableCompat.wrap(originDrawable);
+ if (tintMode != null) {
+ DrawableCompat.setTintMode(tintDrawable, tintMode);
+ }
+ DrawableCompat.setTintList(tintDrawable, colorStateList);
+ return tintDrawable;
+ }
+
+
+}
diff --git a/lesscode-core/src/main/java/com/jayfeng/lesscode/core/EncodeLess.java b/lesscode-core/src/main/java/com/jayfeng/lesscode/core/EncodeLess.java
index e51033b..d5ed104 100644
--- a/lesscode-core/src/main/java/com/jayfeng/lesscode/core/EncodeLess.java
+++ b/lesscode-core/src/main/java/com/jayfeng/lesscode/core/EncodeLess.java
@@ -4,8 +4,16 @@
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
-public class EncodeLess {
+/**
+ * 加解密相关的工具类
+ */
+public final class EncodeLess {
+ /**
+ * 通用MD5加密
+ * @param string
+ * @return
+ */
public static String $md5(String string) {
byte[] hash;
diff --git a/lesscode-core/src/main/java/com/jayfeng/lesscode/core/FileLess.java b/lesscode-core/src/main/java/com/jayfeng/lesscode/core/FileLess.java
index 4b4f203..bd0d21c 100644
--- a/lesscode-core/src/main/java/com/jayfeng/lesscode/core/FileLess.java
+++ b/lesscode-core/src/main/java/com/jayfeng/lesscode/core/FileLess.java
@@ -8,11 +8,19 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipInputStream;
-public class FileLess {
+/**
+ * 文件操作相关的工具类
+ */
+public final class FileLess {
/**
- * read content from file
+ * 读取文件为字符串
+ * @param file 文件
+ * @return 文件内容字符串
+ * @throws IOException
*/
public static String $read(File file) throws IOException {
String text = null;
@@ -29,7 +37,10 @@ public class FileLess {
}
/**
- * read content from inputstream
+ * 读取输入流为字符串,最常见的是网络请求
+ * @param is 输入流
+ * @return 输入流内容字符串
+ * @throws IOException
*/
public static String $read(InputStream is) throws IOException {
StringBuffer strbuffer = new StringBuffer();
@@ -48,6 +59,12 @@ public class FileLess {
return strbuffer.toString();
}
+ /**
+ * 把字符串写入到文件中
+ * @param file 被写入的目标文件
+ * @param str 要写入的字符串内容
+ * @throws IOException
+ */
public static void $write(File file, String str) throws IOException {
DataOutputStream out = null;
try {
@@ -59,4 +76,70 @@ public class FileLess {
}
}
}
+
+ /**
+ * unzip zip file to dest folder
+ * @param zipFilePath
+ * @param destPath
+ */
+ public static void $unzip(String zipFilePath, String destPath) throws IOException {
+ // check or create dest folder
+ File destFile = new File(destPath);
+ if (!destFile.exists()) {
+ destFile.mkdirs();
+ }
+
+ // start unzip
+ ZipInputStream zipInputStream = new ZipInputStream(new FileInputStream(zipFilePath));
+ ZipEntry zipEntry;
+ String zipEntryName;
+ while ((zipEntry = zipInputStream.getNextEntry()) != null) {
+ zipEntryName = zipEntry.getName();
+ if (zipEntry.isDirectory()) {
+ File folder = new File(destPath + File.separator + zipEntryName);
+ folder.mkdirs();
+ } else {
+ File file = new File(destPath + File.separator + zipEntryName);
+ if (file != null && !file.getParentFile().exists()) {
+ file.getParentFile().mkdirs();
+ }
+ file.createNewFile();
+ FileOutputStream out = new FileOutputStream(file);
+ int len;
+ byte[] buffer = new byte[1024];
+ while ((len = zipInputStream.read(buffer)) > 0) {
+ out.write(buffer, 0, len);
+ out.flush();
+ }
+ out.close();
+ }
+ }
+ zipInputStream.close();
+ }
+
+ /**
+ * 删除文件或者文件夹,默认保留根目录
+ * @param directory
+ */
+ public static void $del(File directory) {
+ $del(directory, false);
+ }
+
+ /**
+ * 删除文件或者文件夹
+ * @param directory
+ */
+ public static void $del(File directory, boolean keepRoot) {
+ if (directory != null && directory.exists()) {
+ if (directory.isDirectory()) {
+ for (File subDirectory : directory.listFiles()) {
+ $del(subDirectory, false);
+ }
+ }
+
+ if (!keepRoot) {
+ directory.delete();
+ }
+ }
+ }
}
diff --git a/lesscode-core/src/main/java/com/jayfeng/lesscode/core/HttpLess.java b/lesscode-core/src/main/java/com/jayfeng/lesscode/core/HttpLess.java
index e4e4892..d0936f3 100644
--- a/lesscode-core/src/main/java/com/jayfeng/lesscode/core/HttpLess.java
+++ b/lesscode-core/src/main/java/com/jayfeng/lesscode/core/HttpLess.java
@@ -1,14 +1,6 @@
package com.jayfeng.lesscode.core;
-import org.apache.http.Header;
-import org.apache.http.HttpResponse;
-import org.apache.http.HttpStatus;
-import org.apache.http.client.HttpClient;
-import org.apache.http.client.methods.HttpGet;
-import org.apache.http.impl.client.DefaultHttpClient;
-import org.apache.http.params.BasicHttpParams;
-import org.apache.http.params.HttpConnectionParams;
-import org.apache.http.params.HttpParams;
+import android.content.ContentValues;
import java.io.DataOutputStream;
import java.io.File;
@@ -19,19 +11,32 @@
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
-import java.util.Iterator;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.zip.GZIPInputStream;
-public class HttpLess {
+public final class HttpLess {
- private final static String QUERY_ENCODING = "UTF-8";
private static ExecutorService mExecutorService = Executors.newFixedThreadPool(4);
+ /**
+ * 同步get方式获取url内容
+ * @param url
+ * @return
+ */
public static String $get(String url) {
+ return $get(url, new ContentValues());
+ }
+
+ /**
+ * 同步get方式获取url内容,支持自定义Header
+ * @param url
+ * @param header
+ * @return
+ */
+ public static String $get(String url, ContentValues header) {
InputStream is = null;
try {
URL u = new URL(url);
@@ -40,7 +45,19 @@ public class HttpLess {
conn.setConnectTimeout($.sConnectTimeOut);
conn.setReadTimeout($.sReadTimeout);
conn.setRequestMethod("GET");
- if (conn.getResponseCode() == HttpStatus.SC_OK) {
+
+ // 自定义header
+ for (Map.Entry entry : header.valueSet()) {
+ String key = entry.getKey();
+ String value = entry.getValue().toString();
+ conn.setRequestProperty(key, value);
+ }
+ if (conn.getResponseCode() == HttpURLConnection.HTTP_MOVED_PERM
+ || conn.getResponseCode()== HttpURLConnection.HTTP_MOVED_TEMP) {
+ // 重定向地址下载
+ String redirectDownloadUrl = conn.getHeaderField("location");
+ return $get(redirectDownloadUrl, header);
+ } else if (conn.getResponseCode() == HttpURLConnection.HTTP_OK) {
is = conn.getInputStream();
return FileLess.$read(is);
}
@@ -60,23 +77,61 @@ public class HttpLess {
return null;
}
+ /**
+ * 异步get方式获取url内容
+ * @param url
+ * @param callBack 包含一个onFinish方法的回调,并带上结果result参数
+ */
public static void $get(final String url, final CallBack callBack) {
+ $get(url, new ContentValues(), callBack);
+ }
+
+ public static void $get(final String url, final ContentValues header, final CallBack callBack) {
mExecutorService.submit(new Runnable() {
@Override
public void run() {
- String result = $get(url);
+ String result = $get(url, header);
callBack.onFinish(result);
}
});
}
- public static String $post(String url, Map params) {
+ /**
+ * 同步post方式获取url内容
+ * @param url
+ * @param params
+ * @return
+ */
+ public static String $post(String url, ContentValues params) {
+ return $post(url, params, new ContentValues());
+ }
+
+ /**
+ * 同步post方式获取url内容,支持自定义Header
+ * @param url
+ * @param params
+ * @return
+ */
+ public static String $post(String url, ContentValues params, ContentValues header) {
if (params == null || params.size() == 0) {
return $get(url);
}
OutputStream os = null;
InputStream is = null;
- StringBuffer body = joinParam(params);
+ StringBuffer body = new StringBuffer();
+
+ // 拼接参数
+ for (Map.Entry entry : params.valueSet()) {
+ String key = entry.getKey();
+ String value = entry.getValue().toString();
+ body.append(key).append('=').append(value);
+ body.append('&');
+ }
+ // 去掉最尾部多余的&符号
+ if (body.length() > 0) {
+ body = body.deleteCharAt(body.length() - 1);
+ }
+
byte[] data = body.toString().getBytes();
try {
URL u = new URL(url);
@@ -86,10 +141,17 @@ public void run() {
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
conn.setRequestProperty("Content-Length", String.valueOf(data.length));
+
+ // 自定义header
+ for (Map.Entry entry : header.valueSet()) {
+ String key = entry.getKey();
+ String value = entry.getValue().toString();
+ conn.setRequestProperty(key, value);
+ }
conn.setDoOutput(true);
os = conn.getOutputStream();
os.write(data);
- if (conn.getResponseCode() == HttpStatus.SC_OK) {
+ if (conn.getResponseCode() == HttpURLConnection.HTTP_OK) {
is = conn.getInputStream();
return FileLess.$read(is);
}
@@ -114,17 +176,57 @@ public void run() {
return null;
}
- public static void $post(final String url, final Map params, final CallBack callBack) {
+ /**
+ * 异步post方式获取url内容
+ * @param url
+ * @param params
+ * @param callBack 包含一个onFinish方法的回调,并带上结果result参数
+ */
+ public static void $post(final String url, final ContentValues params, final CallBack callBack) {
+ $post(url, params, new ContentValues(), callBack);
+ }
+
+ /**
+ * 异步post方式获取url内容,支持自定义Header
+ * @param url
+ * @param params
+ * @param header
+ * @param callBack 包含一个onFinish方法的回调,并带上结果result参数
+ */
+ public static void $post(final String url, final ContentValues params, final ContentValues header, final CallBack callBack) {
mExecutorService.submit(new Runnable() {
@Override
public void run() {
- String result = $post(url, params);
+ String result = $post(url, params, header);
callBack.onFinish(result);
}
});
}
+ /**
+ * 异步下载文件
+ * @param downloadUrl
+ * @param dest
+ * @param append
+ * @param callBack
+ * @return
+ * @throws Exception
+ */
public static long $download(String downloadUrl, File dest, boolean append, DownloadCallBack callBack) throws Exception {
+ return $download(downloadUrl, dest, append, new ContentValues(), callBack);
+ }
+
+ /**
+ * 异步下载文件,支持自定义Header
+ * @param downloadUrl
+ * @param dest
+ * @param append
+ * @param header
+ * @param callBack
+ * @return
+ * @throws Exception
+ */
+ public static long $download(String downloadUrl, File dest, boolean append, ContentValues header, DownloadCallBack callBack) throws Exception {
int progress = 0;
long remoteSize = 0;
int currentSize = 0;
@@ -148,26 +250,35 @@ public void run() {
}
}
- HttpGet request = new HttpGet(downloadUrl);
-
- if (currentSize > 0) {
- request.addHeader("RANGE", "bytes=" + currentSize + "-");
- }
-
- HttpParams params = new BasicHttpParams();
- HttpConnectionParams.setConnectionTimeout(params, $.sConnectTimeOut);
- HttpConnectionParams.setSoTimeout(params, 40000);
- HttpClient httpClient = new DefaultHttpClient(params);
-
InputStream is = null;
FileOutputStream os = null;
try {
- HttpResponse response = httpClient.execute(request);
- if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
- is = response.getEntity().getContent();
- remoteSize = response.getEntity().getContentLength();
- Header contentEncoding = response.getFirstHeader("Content-Encoding");
- if (contentEncoding != null && contentEncoding.getValue().equalsIgnoreCase("gzip")) {
+ URL u = new URL(downloadUrl);
+ HttpURLConnection conn = (HttpURLConnection) u.openConnection();
+ conn.setUseCaches(false);
+ conn.setConnectTimeout($.sConnectTimeOut);
+ conn.setReadTimeout($.sReadTimeout);
+ conn.setRequestMethod("GET");
+ // 设置断点续传的起始位置
+ if (currentSize > 0) {
+ conn.setRequestProperty("RANGE", "bytes=" + currentSize + "-");
+ }
+ // 自定义header
+ for (Map.Entry entry : header.valueSet()) {
+ String key = entry.getKey();
+ String value = entry.getValue().toString();
+ conn.setRequestProperty(key, value);
+ }
+ if (conn.getResponseCode() == HttpURLConnection.HTTP_MOVED_PERM
+ || conn.getResponseCode()== HttpURLConnection.HTTP_MOVED_TEMP) {
+ // 重定向地址下载
+ String redirectDownloadUrl = conn.getHeaderField("location");
+ return $download(redirectDownloadUrl, dest, append, header, callBack);
+ } else if (conn.getResponseCode() == HttpURLConnection.HTTP_OK) {
+ is = conn.getInputStream();
+ remoteSize = conn.getContentLength();
+ String contentEndcoding = conn.getHeaderField("Content-Encoding");
+ if (contentEndcoding != null && contentEndcoding.equalsIgnoreCase("gzip")) {
is = new GZIPInputStream(is);
}
os = new FileOutputStream(dest, append);
@@ -177,6 +288,7 @@ public void run() {
os.write(buffer, 0, readSize);
os.flush();
totalSize += readSize;
+ // 通知回调下载进度
if (callBack != null) {
progress = (int) (totalSize * 100 / remoteSize);
callBack.onDownloading(progress);
@@ -191,6 +303,8 @@ public void run() {
totalSize = 0;
}
}
+ } catch (Exception e) {
+ throw e;
} finally {
if (os != null) {
os.close();
@@ -204,14 +318,21 @@ public void run() {
throw new Exception("Download file fail: " + downloadUrl);
}
+ // 下载完成并通知回调
if (callBack != null) {
callBack.onDownloaded();
}
return totalSize;
-
}
+ /**
+ * 同步上传文件
+ * @param url
+ * @param params
+ * @param files
+ * @return
+ */
public static String $upload(String url, Map params, Map files) {
String BOUNDARY = UUID.randomUUID().toString();
String PREFIX = "--", LINEND = "\r\n";
@@ -275,8 +396,7 @@ public void run() {
byte[] end_data = (PREFIX + BOUNDARY + PREFIX + LINEND).getBytes();
os.write(end_data);
os.flush();
- StringBuilder sb2 = new StringBuilder();
- if (conn.getResponseCode() == HttpStatus.SC_OK) {
+ if (conn.getResponseCode() == HttpURLConnection.HTTP_OK) {
InputStream in = conn.getInputStream();
return FileLess.$read(in);
}
@@ -306,6 +426,13 @@ public void run() {
return null;
}
+ /**
+ * 异步上传文件
+ * @param url
+ * @param params
+ * @param files
+ * @param callBack
+ */
public static void $upload(final String url, final Map params, final Map files, final CallBack callBack) {
mExecutorService.submit(new Runnable() {
@Override
@@ -316,28 +443,21 @@ public void run() {
});
}
- private static StringBuffer joinParam(Map params) {
- StringBuffer result = new StringBuffer();
- Iterator> iterator = params.entrySet().iterator();
- while (iterator.hasNext()) {
- Map.Entry param = iterator.next();
- String key = param.getKey();
- String value = param.getValue();
- result.append(key).append('=').append(value);
- if (iterator.hasNext()) {
- result.append('&');
- }
- }
- return result;
- }
-
+ /**
+ * Http请求回调
+ * onFinish,带结果字符串
+ */
public interface CallBack {
- public void onFinish(String result);
+ void onFinish(String result);
}
+ /**
+ * 下载回调:下载进度和下载完成
+ * onDownloading,带一个进度值:0~100
+ * onDownloaded
+ */
public interface DownloadCallBack {
- public void onDownloading(int progress);
-
- public void onDownloaded();
+ void onDownloading(int progress);
+ void onDownloaded();
}
}
diff --git a/lesscode-core/src/main/java/com/jayfeng/lesscode/core/ImageLess.java b/lesscode-core/src/main/java/com/jayfeng/lesscode/core/ImageLess.java
new file mode 100644
index 0000000..b4b5162
--- /dev/null
+++ b/lesscode-core/src/main/java/com/jayfeng/lesscode/core/ImageLess.java
@@ -0,0 +1,35 @@
+package com.jayfeng.lesscode.core;
+
+import android.media.ExifInterface;
+
+import java.io.IOException;
+
+public final class ImageLess {
+
+ /**
+ * 获取图片的exif的旋转角度
+ * @param path
+ * @return
+ */
+ public static int $exifRotateAngle(String path) {
+ int angle = 0;
+ try {
+ ExifInterface exifInterface = new ExifInterface(path);
+ int orientation = exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
+ switch (orientation) {
+ case ExifInterface.ORIENTATION_ROTATE_90:
+ angle = 90;
+ break;
+ case ExifInterface.ORIENTATION_ROTATE_180:
+ angle = 180;
+ break;
+ case ExifInterface.ORIENTATION_ROTATE_270:
+ angle = 270;
+ break;
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ return angle;
+ }
+}
diff --git a/lesscode-core/src/main/java/com/jayfeng/lesscode/core/KeyBoardLess.java b/lesscode-core/src/main/java/com/jayfeng/lesscode/core/KeyBoardLess.java
index 43ae197..dbf98fd 100644
--- a/lesscode-core/src/main/java/com/jayfeng/lesscode/core/KeyBoardLess.java
+++ b/lesscode-core/src/main/java/com/jayfeng/lesscode/core/KeyBoardLess.java
@@ -4,15 +4,28 @@
import android.view.View;
import android.view.inputmethod.InputMethodManager;
-public class KeyBoardLess {
+/**
+ * 输入法相关的工具类
+ */
+public final class KeyBoardLess {
+ /**
+ * 显示输入法
+ * @param context
+ * @param view
+ */
public static void $show(Context context, View view) {
InputMethodManager imm =
(InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
- imm.showSoftInput(view, InputMethodManager.RESULT_SHOWN);
+ imm.showSoftInput(view, InputMethodManager.SHOW_FORCED);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
}
+ /**
+ * 隐藏输入法
+ * @param context
+ * @param view
+ */
public static void $hide(Context context, View view) {
InputMethodManager imm =
(InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
diff --git a/lesscode-core/src/main/java/com/jayfeng/lesscode/core/LogLess.java b/lesscode-core/src/main/java/com/jayfeng/lesscode/core/LogLess.java
index 87e55f4..c6c3905 100644
--- a/lesscode-core/src/main/java/com/jayfeng/lesscode/core/LogLess.java
+++ b/lesscode-core/src/main/java/com/jayfeng/lesscode/core/LogLess.java
@@ -3,6 +3,10 @@
import android.text.TextUtils;
import android.util.Log;
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
+
/**
* support for custom log printing out in case
* adb shell setprop log.tag.YOUR_LOG_TAG LEVEL
@@ -11,49 +15,141 @@
* Example (from system):
* adb shell setprop log.tag.SQLiteLog V
*/
-public class LogLess {
+public final class LogLess {
public static final boolean DEBUG_TAG_LOG = Log.isLoggable($.sTAG, Log.VERBOSE);
- public static void v(String str) {
+ private static final int JSON_INDENT = 4;
+
+ /**
+ * verbose
+ *
+ * @param str
+ */
+ public static void v(String str, Object... args) {
if ($.sDebug || DEBUG_TAG_LOG) {
- Log.v(getTag(), buildLogString(str));
+ Log.v(getTag(), buildLogString(str, args));
}
}
- public static void $d(String str) {
+ /**
+ * debug
+ *
+ * @param str
+ */
+ public static void $d(String str, Object... args) {
if ($.sDebug || DEBUG_TAG_LOG) {
- Log.d(getTag(), buildLogString(str));
+ Log.d(getTag(), buildLogString(str, args));
}
}
- public static void $i(String str) {
+ /**
+ * info
+ *
+ * @param str
+ */
+ public static void $i(String str, Object... args) {
if ($.sDebug || DEBUG_TAG_LOG) {
- Log.i(getTag(), buildLogString(str));
+ Log.i(getTag(), buildLogString(str, args));
}
}
- public static void $w(String str) {
+ /**
+ * warning
+ *
+ * @param str
+ */
+ public static void $w(String str, Object... args) {
if ($.sDebug || DEBUG_TAG_LOG) {
- Log.w(getTag(), buildLogString(str));
+ Log.w(getTag(), buildLogString(str, args));
}
}
- public static void $e(String str) {
+ /**
+ * error
+ *
+ * @param str
+ */
+ public static void $e(String str, Object... args) {
if ($.sDebug || DEBUG_TAG_LOG) {
- Log.e(getTag(), buildLogString(str));
+ Log.e(getTag(), buildLogString(str, args));
}
}
+ /**
+ * json with a title
+ *
+ * @param str
+ * @param title
+ */
+ public static void $json(String str, String title) {
+ if ($.sDebug || DEBUG_TAG_LOG) {
+ Log.d(getTag(), "|===================================================================");
+
+ if (!TextUtils.isEmpty(title)) {
+ Log.d(getTag(), "| " + title);
+ Log.d(getTag(), "|-------------------------------------------------------------------");
+ }
+
+ String message;
+ try {
+ if (str.startsWith("{")) {
+ JSONObject jsonObject = new JSONObject(str);
+ message = jsonObject.toString(JSON_INDENT);
+ } else if (str.startsWith("[")) {
+ JSONArray jsonArray = new JSONArray(str);
+ message = jsonArray.toString(JSON_INDENT);
+ } else {
+ message = str;
+ }
+ } catch (JSONException e) {
+ message = str;
+ }
+
+ String[] lines = message.split("\n");
+ for (String line : lines) {
+ Log.d(getTag(), line);
+ }
+ Log.d(getTag(), "===================================================================|");
+ }
+ }
+
+ /**
+ * json
+ *
+ * @param str
+ */
+ public static void $json(String str) {
+ $json(str, null);
+ }
+
+ /**
+ * 如果$.sTAG是空则自动从StackTrace中取TAG
+ *
+ * @return
+ */
private static String getTag() {
- StackTraceElement caller = new Throwable().fillInStackTrace().getStackTrace()[2];
- if (TextUtils.isEmpty($.sTAG)) {
- return caller.getFileName();
+ if (!TextUtils.isEmpty($.sTAG)) {
+ return $.sTAG;
}
- return $.sTAG;
+ StackTraceElement caller = new Throwable().fillInStackTrace().getStackTrace()[2];
+ return caller.getFileName();
}
- private static String buildLogString(String str) {
+ /**
+ * 根据StackTrace生成带更多信息的log
+ * 文件名,方法名,行数
+ *
+ * @param str
+ * @return
+ */
+ private static String buildLogString(String str, Object... args) {
+
+ // format string with args
+ if (args.length > 0) {
+ str = String.format(str, args);
+ }
+
StackTraceElement caller = new Throwable().fillInStackTrace().getStackTrace()[2];
StringBuilder stringBuilder = new StringBuilder();
if (TextUtils.isEmpty($.sTAG)) {
@@ -64,12 +160,13 @@ private static String buildLogString(String str) {
.append(str);
} else {
stringBuilder
+ .append("(")
.append(caller.getFileName())
- .append(".")
+ .append(":")
+ .append(caller.getLineNumber())
+ .append(").")
.append(caller.getMethodName())
.append("():")
- .append(caller.getLineNumber())
- .append(":")
.append(str);
}
return stringBuilder.toString();
diff --git a/lesscode-core/src/main/java/com/jayfeng/lesscode/core/NetworkLess.java b/lesscode-core/src/main/java/com/jayfeng/lesscode/core/NetworkLess.java
index 3e98b21..c532f5a 100644
--- a/lesscode-core/src/main/java/com/jayfeng/lesscode/core/NetworkLess.java
+++ b/lesscode-core/src/main/java/com/jayfeng/lesscode/core/NetworkLess.java
@@ -5,17 +5,37 @@
import android.net.NetworkInfo;
import android.telephony.TelephonyManager;
-public class NetworkLess {
+/**
+ * 手机网络相关的工具类
+ */
+public final class NetworkLess {
+ /**
+ * 定义网络类型的枚举分类
+ * 这里把一些一些2G,2.5G,2.7G等等按照快慢又做了一个分类,仅供参考
+ */
public static enum NetworkType {
WIRED_FAST, WIFI_FAST, MOBILE_FAST, MOBILE_MIDDLE, MOBILE_SLOW, NONE,
}
+ /**
+ * 是否网络在线
+ * @return
+ */
public static boolean $online() {
- NetworkType networkType = $type();
- return networkType != NetworkType.NONE;
+ ConnectivityManager manager = (ConnectivityManager) $.sAppContext
+ .getSystemService(Context.CONNECTIVITY_SERVICE);
+ NetworkInfo networkInfo = manager.getActiveNetworkInfo();
+ if (networkInfo != null) {
+ return networkInfo.isAvailable();
+ }
+ return false;
}
+ /**
+ * 当期的网络类型
+ * @return
+ */
public static NetworkType $type() {
ConnectivityManager manager = (ConnectivityManager) $.sAppContext
.getSystemService(Context.CONNECTIVITY_SERVICE);
@@ -40,6 +60,7 @@ public static enum NetworkType {
if (type == ConnectivityManager.TYPE_MOBILE) {
switch (subType) {
case TelephonyManager.NETWORK_TYPE_GPRS:
+ case TelephonyManager.NETWORK_TYPE_GSM:
case TelephonyManager.NETWORK_TYPE_EDGE:
case TelephonyManager.NETWORK_TYPE_CDMA:
case TelephonyManager.NETWORK_TYPE_1xRTT:
@@ -55,10 +76,15 @@ public static enum NetworkType {
case TelephonyManager.NETWORK_TYPE_EVDO_B:
case TelephonyManager.NETWORK_TYPE_EHRPD:
case TelephonyManager.NETWORK_TYPE_HSPAP:
+ case TelephonyManager.NETWORK_TYPE_TD_SCDMA:
return NetworkType.MOBILE_MIDDLE;// 3G
case TelephonyManager.NETWORK_TYPE_LTE:
+ case TelephonyManager.NETWORK_TYPE_IWLAN:
+ case 19: // TelephonyManager.NETWORK_TYPE_LTE_CA
return NetworkType.MOBILE_FAST; // 4G
+ default: // we think the network will be more and more better
+ return NetworkType.MOBILE_FAST;
}
}
diff --git a/lesscode-core/src/main/java/com/jayfeng/lesscode/core/PackageLess.java b/lesscode-core/src/main/java/com/jayfeng/lesscode/core/PackageLess.java
deleted file mode 100644
index 3b3e710..0000000
--- a/lesscode-core/src/main/java/com/jayfeng/lesscode/core/PackageLess.java
+++ /dev/null
@@ -1,394 +0,0 @@
-package com.jayfeng.lesscode.core;
-
-import android.content.Context;
-import android.content.Intent;
-import android.content.pm.ApplicationInfo;
-import android.content.pm.PackageInfo;
-import android.content.pm.PackageManager;
-import android.net.Uri;
-import android.util.Log;
-
-import java.io.File;
-
-public class PackageLess {
-
- public static final String TAG = "PackageLess";
-
- public static final int APP_INSTALL_AUTO = 0;
- public static final int APP_INSTALL_INTERNAL = 1;
- public static final int APP_INSTALL_EXTERNAL = 2;
-
- public static final int INSTALL_SUCCEEDED = 1;
-
- public static final int INSTALL_FAILED_ALREADY_EXISTS = -1;
-
- public static final int INSTALL_FAILED_INVALID_APK = -2;
-
- public static final int INSTALL_FAILED_INVALID_URI = -3;
-
- public static final int INSTALL_FAILED_INSUFFICIENT_STORAGE = -4;
-
- public static final int INSTALL_FAILED_DUPLICATE_PACKAGE = -5;
-
- public static final int INSTALL_FAILED_NO_SHARED_USER = -6;
-
- public static final int INSTALL_FAILED_UPDATE_INCOMPATIBLE = -7;
-
- public static final int INSTALL_FAILED_SHARED_USER_INCOMPATIBLE = -8;
-
- public static final int INSTALL_FAILED_MISSING_SHARED_LIBRARY = -9;
-
- public static final int INSTALL_FAILED_REPLACE_COULDNT_DELETE = -10;
-
- public static final int INSTALL_FAILED_DEXOPT = -11;
-
- public static final int INSTALL_FAILED_OLDER_SDK = -12;
-
- public static final int INSTALL_FAILED_CONFLICTING_PROVIDER = -13;
-
- public static final int INSTALL_FAILED_NEWER_SDK = -14;
-
- public static final int INSTALL_FAILED_TEST_ONLY = -15;
-
- public static final int INSTALL_FAILED_CPU_ABI_INCOMPATIBLE = -16;
-
- public static final int INSTALL_FAILED_MISSING_FEATURE = -17;
-
- public static final int INSTALL_FAILED_CONTAINER_ERROR = -18;
-
- public static final int INSTALL_FAILED_INVALID_INSTALL_LOCATION = -19;
-
- public static final int INSTALL_FAILED_MEDIA_UNAVAILABLE = -20;
-
- public static final int INSTALL_FAILED_VERIFICATION_TIMEOUT = -21;
-
- public static final int INSTALL_FAILED_VERIFICATION_FAILURE = -22;
-
- public static final int INSTALL_FAILED_PACKAGE_CHANGED = -23;
-
- public static final int INSTALL_FAILED_UID_CHANGED = -24;
-
- public static final int INSTALL_PARSE_FAILED_NOT_APK = -100;
-
- public static final int INSTALL_PARSE_FAILED_BAD_MANIFEST = -101;
-
- public static final int INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION = -102;
-
- public static final int INSTALL_PARSE_FAILED_NO_CERTIFICATES = -103;
-
- public static final int INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES = -104;
-
- public static final int INSTALL_PARSE_FAILED_CERTIFICATE_ENCODING = -105;
-
- public static final int INSTALL_PARSE_FAILED_BAD_PACKAGE_NAME = -106;
-
- public static final int INSTALL_PARSE_FAILED_BAD_SHARED_USER_ID = -107;
-
- public static final int INSTALL_PARSE_FAILED_MANIFEST_MALFORMED = -108;
-
- public static final int INSTALL_PARSE_FAILED_MANIFEST_EMPTY = -109;
-
- public static final int INSTALL_FAILED_INTERNAL_ERROR = -110;
-
- public static final int INSTALL_FAILED_OTHER = -1000000;
-
- public static final int DELETE_SUCCEEDED = 1;
-
- public static final int DELETE_FAILED_INTERNAL_ERROR = -1;
-
- public static final int DELETE_FAILED_DEVICE_POLICY_MANAGER = -2;
-
- public static final int DELETE_FAILED_INVALID_PACKAGE = -3;
-
- public static final int DELETE_FAILED_PERMISSION_DENIED = -4;
-
- public static final int install(Context context, String filePath) {
- if (PackageLess.isSystemApplication(context) || ShellLess.checkRootPermission()) {
- return installSilent(context, filePath);
- }
- return installNormal(context, filePath) ? INSTALL_SUCCEEDED : INSTALL_FAILED_INVALID_URI;
- }
-
- public static boolean installNormal(Context context, String filePath) {
- Intent i = new Intent(Intent.ACTION_VIEW);
- File file = new File(filePath);
- if (file == null || !file.exists() || !file.isFile() || file.length() <= 0) {
- return false;
- }
-
- i.setDataAndType(Uri.parse("file://" + filePath), "application/vnd.android.package-archive");
- i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- context.startActivity(i);
- return true;
- }
-
- public static int installSilent(Context context, String filePath) {
- return installSilent(context, filePath, " -r " + getInstallLocationParams());
- }
-
- public static int installSilent(Context context, String filePath, String pmParams) {
- if (filePath == null || filePath.length() == 0) {
- return INSTALL_FAILED_INVALID_URI;
- }
-
- File file = new File(filePath);
- if (file == null || file.length() <= 0 || !file.exists() || !file.isFile()) {
- return INSTALL_FAILED_INVALID_URI;
- }
-
- /**
- * if context is system app, don't need root permission, but should add in mainfest
- **/
- StringBuilder command = new StringBuilder().append("LD_LIBRARY_PATH=/vendor/lib:/system/lib pm install ")
- .append(pmParams == null ? "" : pmParams).append(" ").append(filePath.replace(" ", "\\ "));
- ShellLess.CommandResult commandResult = ShellLess.execCommand(command.toString(), !isSystemApplication(context), true);
- if (commandResult.successMsg != null
- && (commandResult.successMsg.contains("Success") || commandResult.successMsg.contains("success"))) {
- return INSTALL_SUCCEEDED;
- }
-
- Log.e(TAG,
- new StringBuilder().append("installSilent successMsg:").append(commandResult.successMsg)
- .append(", ErrorMsg:").append(commandResult.errorMsg).toString());
- if (commandResult.errorMsg == null) {
- return INSTALL_FAILED_OTHER;
- }
- if (commandResult.errorMsg.contains("INSTALL_FAILED_ALREADY_EXISTS")) {
- return INSTALL_FAILED_ALREADY_EXISTS;
- }
- if (commandResult.errorMsg.contains("INSTALL_FAILED_INVALID_APK")) {
- return INSTALL_FAILED_INVALID_APK;
- }
- if (commandResult.errorMsg.contains("INSTALL_FAILED_INVALID_URI")) {
- return INSTALL_FAILED_INVALID_URI;
- }
- if (commandResult.errorMsg.contains("INSTALL_FAILED_INSUFFICIENT_STORAGE")) {
- return INSTALL_FAILED_INSUFFICIENT_STORAGE;
- }
- if (commandResult.errorMsg.contains("INSTALL_FAILED_DUPLICATE_PACKAGE")) {
- return INSTALL_FAILED_DUPLICATE_PACKAGE;
- }
- if (commandResult.errorMsg.contains("INSTALL_FAILED_NO_SHARED_USER")) {
- return INSTALL_FAILED_NO_SHARED_USER;
- }
- if (commandResult.errorMsg.contains("INSTALL_FAILED_UPDATE_INCOMPATIBLE")) {
- return INSTALL_FAILED_UPDATE_INCOMPATIBLE;
- }
- if (commandResult.errorMsg.contains("INSTALL_FAILED_SHARED_USER_INCOMPATIBLE")) {
- return INSTALL_FAILED_SHARED_USER_INCOMPATIBLE;
- }
- if (commandResult.errorMsg.contains("INSTALL_FAILED_MISSING_SHARED_LIBRARY")) {
- return INSTALL_FAILED_MISSING_SHARED_LIBRARY;
- }
- if (commandResult.errorMsg.contains("INSTALL_FAILED_REPLACE_COULDNT_DELETE")) {
- return INSTALL_FAILED_REPLACE_COULDNT_DELETE;
- }
- if (commandResult.errorMsg.contains("INSTALL_FAILED_DEXOPT")) {
- return INSTALL_FAILED_DEXOPT;
- }
- if (commandResult.errorMsg.contains("INSTALL_FAILED_OLDER_SDK")) {
- return INSTALL_FAILED_OLDER_SDK;
- }
- if (commandResult.errorMsg.contains("INSTALL_FAILED_CONFLICTING_PROVIDER")) {
- return INSTALL_FAILED_CONFLICTING_PROVIDER;
- }
- if (commandResult.errorMsg.contains("INSTALL_FAILED_NEWER_SDK")) {
- return INSTALL_FAILED_NEWER_SDK;
- }
- if (commandResult.errorMsg.contains("INSTALL_FAILED_TEST_ONLY")) {
- return INSTALL_FAILED_TEST_ONLY;
- }
- if (commandResult.errorMsg.contains("INSTALL_FAILED_CPU_ABI_INCOMPATIBLE")) {
- return INSTALL_FAILED_CPU_ABI_INCOMPATIBLE;
- }
- if (commandResult.errorMsg.contains("INSTALL_FAILED_MISSING_FEATURE")) {
- return INSTALL_FAILED_MISSING_FEATURE;
- }
- if (commandResult.errorMsg.contains("INSTALL_FAILED_CONTAINER_ERROR")) {
- return INSTALL_FAILED_CONTAINER_ERROR;
- }
- if (commandResult.errorMsg.contains("INSTALL_FAILED_INVALID_INSTALL_LOCATION")) {
- return INSTALL_FAILED_INVALID_INSTALL_LOCATION;
- }
- if (commandResult.errorMsg.contains("INSTALL_FAILED_MEDIA_UNAVAILABLE")) {
- return INSTALL_FAILED_MEDIA_UNAVAILABLE;
- }
- if (commandResult.errorMsg.contains("INSTALL_FAILED_VERIFICATION_TIMEOUT")) {
- return INSTALL_FAILED_VERIFICATION_TIMEOUT;
- }
- if (commandResult.errorMsg.contains("INSTALL_FAILED_VERIFICATION_FAILURE")) {
- return INSTALL_FAILED_VERIFICATION_FAILURE;
- }
- if (commandResult.errorMsg.contains("INSTALL_FAILED_PACKAGE_CHANGED")) {
- return INSTALL_FAILED_PACKAGE_CHANGED;
- }
- if (commandResult.errorMsg.contains("INSTALL_FAILED_UID_CHANGED")) {
- return INSTALL_FAILED_UID_CHANGED;
- }
- if (commandResult.errorMsg.contains("INSTALL_PARSE_FAILED_NOT_APK")) {
- return INSTALL_PARSE_FAILED_NOT_APK;
- }
- if (commandResult.errorMsg.contains("INSTALL_PARSE_FAILED_BAD_MANIFEST")) {
- return INSTALL_PARSE_FAILED_BAD_MANIFEST;
- }
- if (commandResult.errorMsg.contains("INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION")) {
- return INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION;
- }
- if (commandResult.errorMsg.contains("INSTALL_PARSE_FAILED_NO_CERTIFICATES")) {
- return INSTALL_PARSE_FAILED_NO_CERTIFICATES;
- }
- if (commandResult.errorMsg.contains("INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES")) {
- return INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES;
- }
- if (commandResult.errorMsg.contains("INSTALL_PARSE_FAILED_CERTIFICATE_ENCODING")) {
- return INSTALL_PARSE_FAILED_CERTIFICATE_ENCODING;
- }
- if (commandResult.errorMsg.contains("INSTALL_PARSE_FAILED_BAD_PACKAGE_NAME")) {
- return INSTALL_PARSE_FAILED_BAD_PACKAGE_NAME;
- }
- if (commandResult.errorMsg.contains("INSTALL_PARSE_FAILED_BAD_SHARED_USER_ID")) {
- return INSTALL_PARSE_FAILED_BAD_SHARED_USER_ID;
- }
- if (commandResult.errorMsg.contains("INSTALL_PARSE_FAILED_MANIFEST_MALFORMED")) {
- return INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
- }
- if (commandResult.errorMsg.contains("INSTALL_PARSE_FAILED_MANIFEST_EMPTY")) {
- return INSTALL_PARSE_FAILED_MANIFEST_EMPTY;
- }
- if (commandResult.errorMsg.contains("INSTALL_FAILED_INTERNAL_ERROR")) {
- return INSTALL_FAILED_INTERNAL_ERROR;
- }
- return INSTALL_FAILED_OTHER;
- }
-
- public static final int uninstall(Context context, String packageName) {
- if (isSystemApplication(context)) {
- return uninstallSilent(context, packageName);
- }
- return uninstallNormal(context, packageName) ? DELETE_SUCCEEDED : DELETE_FAILED_INVALID_PACKAGE;
- }
-
- public static boolean uninstallNormal(Context context, String packageName) {
- if (packageName == null || packageName.length() == 0) {
- return false;
- }
-
- Intent i = new Intent(Intent.ACTION_DELETE, Uri.parse(new StringBuilder(32).append("package:")
- .append(packageName).toString()));
- i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- context.startActivity(i);
- return true;
- }
-
- public static int uninstallSilent(Context context, String packageName) {
- return uninstallSilent(context, packageName, true);
- }
-
- public static int uninstallSilent(Context context, String packageName, boolean isKeepData) {
- if (packageName == null || packageName.length() == 0) {
- return DELETE_FAILED_INVALID_PACKAGE;
- }
-
- /**
- * if context is system app, don't need root permission, but should add in mainfest
- **/
- StringBuilder command = new StringBuilder().append("LD_LIBRARY_PATH=/vendor/lib:/system/lib pm uninstall")
- .append(isKeepData ? " -k " : " ").append(packageName.replace(" ", "\\ "));
- ShellLess.CommandResult commandResult = ShellLess.execCommand(command.toString(), !isSystemApplication(context), true);
- if (commandResult.successMsg != null
- && (commandResult.successMsg.contains("Success") || commandResult.successMsg.contains("success"))) {
- return DELETE_SUCCEEDED;
- }
- Log.e(TAG,
- new StringBuilder().append("uninstallSilent successMsg:").append(commandResult.successMsg)
- .append(", ErrorMsg:").append(commandResult.errorMsg).toString());
- if (commandResult.errorMsg == null) {
- return DELETE_FAILED_INTERNAL_ERROR;
- }
- if (commandResult.errorMsg.contains("Permission denied")) {
- return DELETE_FAILED_PERMISSION_DENIED;
- }
- return DELETE_FAILED_INTERNAL_ERROR;
- }
-
- public static boolean isSystemApplication(Context context) {
- if (context == null) {
- return false;
- }
-
- return isSystemApplication(context, context.getPackageName());
- }
-
- public static boolean isSystemApplication(Context context, String packageName) {
- if (context == null) {
- return false;
- }
-
- return isSystemApplication(context.getPackageManager(), packageName);
- }
-
- public static boolean isSystemApplication(PackageManager packageManager, String packageName) {
- if (packageManager == null || packageName == null || packageName.length() == 0) {
- return false;
- }
-
- try {
- ApplicationInfo app = packageManager.getApplicationInfo(packageName, 0);
- return (app != null && (app.flags & ApplicationInfo.FLAG_SYSTEM) > 0);
- } catch (PackageManager.NameNotFoundException e) {
- e.printStackTrace();
- }
- return false;
- }
-
- public static int getAppVersionCode(Context context) {
- if (context != null) {
- PackageManager pm = context.getPackageManager();
- if (pm != null) {
- PackageInfo pi;
- try {
- pi = pm.getPackageInfo(context.getPackageName(), 0);
- if (pi != null) {
- return pi.versionCode;
- }
- } catch (PackageManager.NameNotFoundException e) {
- e.printStackTrace();
- }
- }
- }
- return -1;
- }
-
- public static int getInstallLocation() {
- ShellLess.CommandResult commandResult = ShellLess.execCommand(
- "LD_LIBRARY_PATH=/vendor/lib:/system/lib pm get-install-location", false, true);
- if (commandResult.result == 0 && commandResult.successMsg != null && commandResult.successMsg.length() > 0) {
- try {
- int location = Integer.parseInt(commandResult.successMsg.substring(0, 1));
- switch (location) {
- case APP_INSTALL_INTERNAL:
- return APP_INSTALL_INTERNAL;
- case APP_INSTALL_EXTERNAL:
- return APP_INSTALL_EXTERNAL;
- }
- } catch (NumberFormatException e) {
- e.printStackTrace();
- Log.e(TAG, "pm get-install-location error");
- }
- }
- return APP_INSTALL_AUTO;
- }
-
- private static String getInstallLocationParams() {
- int location = getInstallLocation();
- switch (location) {
- case APP_INSTALL_INTERNAL:
- return "-f";
- case APP_INSTALL_EXTERNAL:
- return "-s";
- }
- return "";
- }
-}
diff --git a/lesscode-core/src/main/java/com/jayfeng/lesscode/core/ResourceLess.java b/lesscode-core/src/main/java/com/jayfeng/lesscode/core/ResourceLess.java
index 458d7f1..4af5b54 100644
--- a/lesscode-core/src/main/java/com/jayfeng/lesscode/core/ResourceLess.java
+++ b/lesscode-core/src/main/java/com/jayfeng/lesscode/core/ResourceLess.java
@@ -3,13 +3,23 @@
import android.content.Context;
import android.content.res.Resources;
-public class ResourceLess {
+public final class ResourceLess {
+ /**
+ * 根据资源名称和类型,得到资源ID
+ * @param context
+ * @param resourceName
+ * @param type
+ * @return
+ */
public static int $id(Context context, String resourceName, TYPE type) {
Resources resources = context.getResources();
return resources.getIdentifier(resourceName, type.getString(), context.getPackageName());
}
+ /**
+ * 定义资源枚举类型
+ */
public enum TYPE {
ATTR("attr"),
ARRAY("array"),
@@ -23,6 +33,7 @@ public enum TYPE {
LAYOUT("layout"),
MENU("menu"),
MIPMAP("mipmap"),
+ RAW("raw"),
STRING("string"),
STYLE("style"),
STYLEABLE("styleable");
diff --git a/lesscode-core/src/main/java/com/jayfeng/lesscode/core/SerializeLess.java b/lesscode-core/src/main/java/com/jayfeng/lesscode/core/SerializeLess.java
index fbf4ff2..fe15acd 100644
--- a/lesscode-core/src/main/java/com/jayfeng/lesscode/core/SerializeLess.java
+++ b/lesscode-core/src/main/java/com/jayfeng/lesscode/core/SerializeLess.java
@@ -6,8 +6,17 @@
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
-public class SerializeLess {
+/**
+ * 序列化相关的工具类
+ */
+public final class SerializeLess {
+ /**
+ * 序列化对象到本地文件
+ * @param path
+ * @param object
+ * @param
+ */
public static void $se(String path, T object) {
ObjectOutputStream out = null;
try {
@@ -27,6 +36,12 @@ public class SerializeLess {
}
}
+ /**
+ * 从本地文件中解析出序列化对象
+ * @param path
+ * @param
+ * @return
+ */
public static T $de(String path) {
ObjectInputStream in = null;
try {
diff --git a/lesscode-core/src/main/java/com/jayfeng/lesscode/core/SharedPreferenceLess.java b/lesscode-core/src/main/java/com/jayfeng/lesscode/core/SharedPreferenceLess.java
index 0d23499..88f75b1 100644
--- a/lesscode-core/src/main/java/com/jayfeng/lesscode/core/SharedPreferenceLess.java
+++ b/lesscode-core/src/main/java/com/jayfeng/lesscode/core/SharedPreferenceLess.java
@@ -6,34 +6,77 @@
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
-public class SharedPreferenceLess {
+public final class SharedPreferenceLess {
public static final String SHARED_NAME = "shared_name";
- public static void $put(Context context, String key, String value) {
- SharedPreferences sp = context.getSharedPreferences(SHARED_NAME,
+ public static void $put(String key, T value) {
+ SharedPreferences sp = $.sAppContext.getSharedPreferences(SHARED_NAME,
Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sp.edit();
- editor.putString(key, value);
+
+ if (value == null) {
+ // if value is null, just handler it as a String
+ editor.putString(key, null);
+ } else {
+ if (value.getClass() == Boolean.class) {
+ editor.putBoolean(key, (Boolean) value);
+ } else if (value.getClass() == Float.class) {
+ editor.putFloat(key, (Float) value);
+ } else if (value.getClass() == Integer.class) {
+ editor.putInt(key, (Integer) value);
+ } else if (value.getClass() == Long.class) {
+ editor.putLong(key, (Long) value);
+ } else if (value.getClass() == String.class) {
+ editor.putString(key, (String) value);
+ } else {
+ throw new RuntimeException("the put value type can't support.");
+ }
+ }
+
SharedPreferencesCompat.apply(editor);
}
- public static Object $get(Context context, String key, String defaultValue) {
- SharedPreferences sp = context.getSharedPreferences(SHARED_NAME,
+ public static String $get(String key, String defaultValue) {
+ SharedPreferences sp = $.sAppContext.getSharedPreferences(SHARED_NAME,
Context.MODE_PRIVATE);
return sp.getString(key, defaultValue);
}
- public static void $remove(Context context, String key) {
- SharedPreferences sp = context.getSharedPreferences(SHARED_NAME,
+ public static boolean $get(String key, boolean defaultValue) {
+ SharedPreferences sp = $.sAppContext.getSharedPreferences(SHARED_NAME,
+ Context.MODE_PRIVATE);
+ return sp.getBoolean(key, defaultValue);
+ }
+
+ public static float $get(String key, float defaultValue) {
+ SharedPreferences sp = $.sAppContext.getSharedPreferences(SHARED_NAME,
+ Context.MODE_PRIVATE);
+ return sp.getFloat(key, defaultValue);
+ }
+
+ public static int $get(String key, int defaultValue) {
+ SharedPreferences sp = $.sAppContext.getSharedPreferences(SHARED_NAME,
+ Context.MODE_PRIVATE);
+ return sp.getInt(key, defaultValue);
+ }
+
+ public static long $get(String key, long defaultValue) {
+ SharedPreferences sp = $.sAppContext.getSharedPreferences(SHARED_NAME,
+ Context.MODE_PRIVATE);
+ return sp.getLong(key, defaultValue);
+ }
+
+ public static void $remove(String key) {
+ SharedPreferences sp = $.sAppContext.getSharedPreferences(SHARED_NAME,
Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sp.edit();
editor.remove(key);
SharedPreferencesCompat.apply(editor);
}
- public static void $clear(Context context) {
- SharedPreferences sp = context.getSharedPreferences(SHARED_NAME,
+ public static void $clear() {
+ SharedPreferences sp = $.sAppContext.getSharedPreferences(SHARED_NAME,
Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sp.edit();
editor.clear();
diff --git a/lesscode-core/src/main/java/com/jayfeng/lesscode/core/ShellLess.java b/lesscode-core/src/main/java/com/jayfeng/lesscode/core/ShellLess.java
deleted file mode 100644
index 42d215d..0000000
--- a/lesscode-core/src/main/java/com/jayfeng/lesscode/core/ShellLess.java
+++ /dev/null
@@ -1,130 +0,0 @@
-package com.jayfeng.lesscode.core;
-
-import java.io.BufferedReader;
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.util.List;
-
-public class ShellLess {
-
- public static final String COMMAND_SU = "su";
- public static final String COMMAND_SH = "sh";
- public static final String COMMAND_EXIT = "exit\n";
- public static final String COMMAND_LINE_END = "\n";
-
- public static boolean checkRootPermission() {
- return execCommand("echo root", true, false).result == 0;
- }
-
- public static CommandResult execCommand(String command, boolean isRoot) {
- return execCommand(new String[] {command}, isRoot, true);
- }
-
- public static CommandResult execCommand(List commands, boolean isRoot) {
- return execCommand(commands == null ? null : commands.toArray(new String[] {}), isRoot, true);
- }
-
- public static CommandResult execCommand(String[] commands, boolean isRoot) {
- return execCommand(commands, isRoot, true);
- }
-
- public static CommandResult execCommand(String command, boolean isRoot, boolean isNeedResultMsg) {
- return execCommand(new String[] {command}, isRoot, isNeedResultMsg);
- }
-
- public static CommandResult execCommand(List commands, boolean isRoot, boolean isNeedResultMsg) {
- return execCommand(commands == null ? null : commands.toArray(new String[] {}), isRoot, isNeedResultMsg);
- }
-
- public static CommandResult execCommand(String[] commands, boolean isRoot, boolean isNeedResultMsg) {
- int result = -1;
- if (commands == null || commands.length == 0) {
- return new CommandResult(result, null, null);
- }
-
- Process process = null;
- BufferedReader successResult = null;
- BufferedReader errorResult = null;
- StringBuilder successMsg = null;
- StringBuilder errorMsg = null;
-
- DataOutputStream os = null;
- try {
- process = Runtime.getRuntime().exec(isRoot ? COMMAND_SU : COMMAND_SH);
- os = new DataOutputStream(process.getOutputStream());
- for (String command : commands) {
- if (command == null) {
- continue;
- }
-
- // donnot use os.writeBytes(commmand), avoid chinese charset error
- os.write(command.getBytes());
- os.writeBytes(COMMAND_LINE_END);
- os.flush();
- }
- os.writeBytes(COMMAND_EXIT);
- os.flush();
-
- result = process.waitFor();
- // get command result
- if (isNeedResultMsg) {
- successMsg = new StringBuilder();
- errorMsg = new StringBuilder();
- successResult = new BufferedReader(new InputStreamReader(process.getInputStream()));
- errorResult = new BufferedReader(new InputStreamReader(process.getErrorStream()));
- String s;
- while ((s = successResult.readLine()) != null) {
- successMsg.append(s);
- }
- while ((s = errorResult.readLine()) != null) {
- errorMsg.append(s);
- }
- }
- } catch (IOException e) {
- e.printStackTrace();
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- try {
- if (os != null) {
- os.close();
- }
- if (successResult != null) {
- successResult.close();
- }
- if (errorResult != null) {
- errorResult.close();
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
-
- if (process != null) {
- process.destroy();
- }
- }
- return new CommandResult(result, successMsg == null ? null : successMsg.toString(), errorMsg == null ? null
- : errorMsg.toString());
- }
-
- public static class CommandResult {
-
- /** result of command **/
- public int result;
- /** success message of command result **/
- public String successMsg;
- /** error message of command result **/
- public String errorMsg;
-
- public CommandResult(int result) {
- this.result = result;
- }
-
- public CommandResult(int result, String successMsg, String errorMsg) {
- this.result = result;
- this.successMsg = successMsg;
- this.errorMsg = errorMsg;
- }
- }
-}
diff --git a/lesscode-core/src/main/java/com/jayfeng/lesscode/core/StorageLess.java b/lesscode-core/src/main/java/com/jayfeng/lesscode/core/StorageLess.java
index b0207e3..d881dc2 100644
--- a/lesscode-core/src/main/java/com/jayfeng/lesscode/core/StorageLess.java
+++ b/lesscode-core/src/main/java/com/jayfeng/lesscode/core/StorageLess.java
@@ -13,8 +13,15 @@
import java.util.ArrayList;
import java.util.List;
-public class StorageLess {
-
+/**
+ * 手机存储相关的工具类
+ * 包括:手机内存,内置存储卡(Sdcard),外置存储卡(ExtSdcard)
+ */
+public final class StorageLess {
+
+ /**
+ * 手机内存
+ */
public static class Phone {
public static long $total() {
File path = Environment.getDataDirectory();
@@ -43,6 +50,11 @@ public static class Phone {
}
+ /**
+ * 内部存储
+ * 1. 如果没有内部存储,则为外部存储
+ * 2. 一般默认说的sdcard就是指这一层
+ */
public static class Sdcard {
public static boolean $ready() {
@@ -80,6 +92,9 @@ public static class Sdcard {
}
}
+ /**
+ * 外部存储
+ */
public static class ExtSdcard {
public static File $path() {
@@ -171,17 +186,29 @@ public static class ExtSdcard {
}
private static long total(File path) {
- StatFs stat = new StatFs(path.getPath());
- long blockSize = stat.getBlockSize();
- long totalBlocks = stat.getBlockCount();
- return blockSize * totalBlocks;
+ try {
+ StatFs stat = new StatFs(path.getPath());
+ long blockSize = stat.getBlockSize();
+ long totalBlocks = stat.getBlockCount();
+ return blockSize * totalBlocks;
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ return 0;
}
private static long free(File path) {
- StatFs stat = new StatFs(path.getPath());
- long blockSize = stat.getBlockSize();
- long freeBlocks = stat.getAvailableBlocks();
- return blockSize * freeBlocks;
+ try {
+ StatFs stat = new StatFs(path.getPath());
+ long blockSize = stat.getBlockSize();
+ long freeBlocks = stat.getAvailableBlocks();
+ return blockSize * freeBlocks;
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ return 0;
}
private static long used(File path) {
diff --git a/lesscode-core/src/main/java/com/jayfeng/lesscode/core/ToastLess.java b/lesscode-core/src/main/java/com/jayfeng/lesscode/core/ToastLess.java
index f8867e3..c28d5b9 100644
--- a/lesscode-core/src/main/java/com/jayfeng/lesscode/core/ToastLess.java
+++ b/lesscode-core/src/main/java/com/jayfeng/lesscode/core/ToastLess.java
@@ -3,14 +3,26 @@
import android.content.Context;
import android.widget.Toast;
-public class ToastLess {
+/**
+ * 简化Toast的工具类
+ */
+public final class ToastLess {
+ @Deprecated
public static void $(Context context, String message) {
- Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
- };
+ Toast.makeText(context.getApplicationContext(), message, Toast.LENGTH_SHORT).show();
+ }
+ @Deprecated
public static void $(Context context, int stringId) {
- Toast.makeText(context, stringId, Toast.LENGTH_SHORT).show();
- };
+ Toast.makeText(context.getApplicationContext(), stringId, Toast.LENGTH_SHORT).show();
+ }
+ public static void $(String message) {
+ Toast.makeText($.sAppContext, message, Toast.LENGTH_SHORT).show();
+ }
+
+ public static void $(int stringId) {
+ Toast.makeText($.sAppContext, stringId, Toast.LENGTH_SHORT).show();
+ }
}
diff --git a/lesscode-core/src/main/java/com/jayfeng/lesscode/core/UpdateLess.java b/lesscode-core/src/main/java/com/jayfeng/lesscode/core/UpdateLess.java
deleted file mode 100644
index 4788716..0000000
--- a/lesscode-core/src/main/java/com/jayfeng/lesscode/core/UpdateLess.java
+++ /dev/null
@@ -1,83 +0,0 @@
-package com.jayfeng.lesscode.core;
-
-import android.app.AlertDialog;
-import android.app.Dialog;
-import android.content.Context;
-import android.content.DialogInterface;
-import android.content.Intent;
-
-import org.json.JSONException;
-import org.json.JSONObject;
-
-public class UpdateLess {
-
- /**
- * {
- * "vercode":1,
- * "vername":"v1.1",
- * "download":"http://www.jayfeng.com/lesscode-app.apk",
- * "log":"upgrade content"
- * }
- *
- * @return whether has a update version
- */
- public static boolean $check(final Context context, String updateJson) {
- int vercode = 0;
- String vername = "";
- String log = "";
- String download;
-
- JSONObject jsonObject;
- try {
- jsonObject = new JSONObject(updateJson);
- vercode = jsonObject.optInt("vercode");
- vername = jsonObject.optString("vername");
- download = jsonObject.optString("download");
- log = jsonObject.optString("log");
- } catch (JSONException e) {
- e.printStackTrace();
- return false;
- }
-
- return $check(context, vercode, vername, download, log);
- }
-
- public static boolean $check(final Context context,
- int vercode,
- String vername,
- final String download,
- String log) {
-
- if (vercode <= AppLess.$vercode(context)) {
- return false;
- }
-
- new AlertDialog.Builder(context)
- .setTitle(context.getString(R.string.less_app_download_dialog_title) + vername)
- .setMessage(log)
- .setNegativeButton(android.R.string.cancel, null)
- .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- Intent intent = new Intent(context, UpdateService.class);
- intent.putExtra($.KEY_DOWNLOAD_URL, download);
- context.startService(intent);
- }
- }).show();
-
- return true;
- }
-
- public static boolean $hasUpdate(Context context, int vercode) {
- if (vercode <= AppLess.$vercode(context)) {
- return false;
- }
- return true;
- }
-
- public static void $download(Context context, String download) {
- Intent intent = new Intent(context, UpdateService.class);
- intent.putExtra($.KEY_DOWNLOAD_URL, download);
- context.startService(intent);
- }
-}
diff --git a/lesscode-core/src/main/java/com/jayfeng/lesscode/core/UpdateService.java b/lesscode-core/src/main/java/com/jayfeng/lesscode/core/UpdateService.java
deleted file mode 100644
index 6ff3885..0000000
--- a/lesscode-core/src/main/java/com/jayfeng/lesscode/core/UpdateService.java
+++ /dev/null
@@ -1,230 +0,0 @@
-package com.jayfeng.lesscode.core;
-
-import android.app.Notification;
-import android.app.NotificationManager;
-import android.app.PendingIntent;
-import android.app.Service;
-import android.content.Intent;
-import android.content.pm.PackageInfo;
-import android.content.pm.PackageManager;
-import android.net.Uri;
-import android.os.Environment;
-import android.os.Handler;
-import android.os.IBinder;
-import android.os.Message;
-import android.text.TextUtils;
-import android.view.View;
-import android.widget.RemoteViews;
-import android.widget.Toast;
-
-import java.io.File;
-import java.net.URLEncoder;
-
-public class UpdateService extends Service {
-
- private static final int DOWNLOAD_STATE_FAILURE = -1;
- private static final int DOWNLOAD_STATE_SUCCESS = 0;
- private static final int DOWNLOAD_STATE_START = 1;
- private static final int DOWNLOAD_STATE_INSTALL = 2;
- private static final int DOWNLOAD_STATE_ERROR_SDCARD = 3;
-
- private static final int NOTIFICATION_ID = 3956;
- private NotificationManager mNotificationManager = null;
- private Notification mNotification = null;
- private PendingIntent mPendingIntent = null;
-
- private String mDownloadSDPath;
- private String mDownloadUrl;
- private File mDestDir;
- private File mDestFile;
-
- private Handler.Callback mHandlerCallBack = new Handler.Callback() {
- @Override
- public boolean handleMessage(Message msg) {
- switch (msg.what) {
- case DOWNLOAD_STATE_SUCCESS:
- Toast.makeText(getApplicationContext(), R.string.less_app_download_success, Toast.LENGTH_LONG).show();
- install(mDestFile);
- break;
- case DOWNLOAD_STATE_FAILURE:
- Toast.makeText(getApplicationContext(), R.string.less_app_download_failure, Toast.LENGTH_LONG).show();
- mNotificationManager.cancel(NOTIFICATION_ID);
- break;
- case DOWNLOAD_STATE_START:
- Toast.makeText(getApplicationContext(), R.string.less_app_download_start, Toast.LENGTH_LONG).show();
- break;
- case DOWNLOAD_STATE_INSTALL:
- Toast.makeText(getApplicationContext(), R.string.less_app_download_install, Toast.LENGTH_LONG).show();
- break;
- case DOWNLOAD_STATE_ERROR_SDCARD:
- Toast.makeText(getApplicationContext(), R.string.less_app_download_error_sdcard, Toast.LENGTH_LONG).show();
- break;
- default:
- break;
- }
- return true;
- }
- };
- private Handler mHandler = new Handler(mHandlerCallBack);
-
- private HttpLess.DownloadCallBack mDownloadCallBack = new HttpLess.DownloadCallBack() {
-
- @Override
- public void onDownloading(int progress) {
- if (progress % $.sNotificationFrequent == 0 || progress == 1 || progress == 100) {
- mNotification.contentView.setProgressBar(R.id.less_app_update_progressbar, 100, progress, false);
- mNotification.contentView.setTextViewText(R.id.less_app_update_progress_text, progress + "%");
- mNotificationManager.notify(NOTIFICATION_ID, mNotification);
- }
- }
-
- @Override
- public void onDownloaded() {
- mNotification.contentView.setViewVisibility(R.id.less_app_update_progress_block, View.GONE);
- mNotification.defaults = Notification.DEFAULT_SOUND;
- mNotification.contentIntent = mPendingIntent;
- mNotification.contentView.setTextViewText(R.id.less_app_update_progress_text, getText(R.string.less_app_download_notification_success));
- mNotificationManager.notify(NOTIFICATION_ID, mNotification);
- if (mDestFile.exists() && mDestFile.isFile() && checkApkFile(mDestFile.getPath())) {
- Message msg = mHandler.obtainMessage();
- msg.what = DOWNLOAD_STATE_SUCCESS;
- mHandler.sendMessage(msg);
- }
- mNotificationManager.cancel(NOTIFICATION_ID);
- }
- };
-
- @Override
- public int onStartCommand(Intent intent, int flags, int startId) {
- mDownloadUrl = intent.getStringExtra($.KEY_DOWNLOAD_URL);
- if (TextUtils.isEmpty($.sDownloadSDPath)) {
- mDownloadSDPath = getPackageName() + "/download";
- } else {
- mDownloadSDPath = $.sDownloadSDPath;
- }
-
- if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
- mDestDir = new File(Environment.getExternalStorageDirectory().getPath()
- + "/" + mDownloadSDPath);
- if (mDestDir.exists()) {
- File destFile = new File(mDestDir.getPath() + "/" + URLEncoder.encode(mDownloadUrl));
- if (destFile.exists() && destFile.isFile() && checkApkFile(destFile.getPath())) {
-
- sendMessage(DOWNLOAD_STATE_INSTALL);
- install(destFile);
- stopSelf();
- return super.onStartCommand(intent, flags, startId);
- }
- }
- } else {
- sendMessage(DOWNLOAD_STATE_ERROR_SDCARD);
- return super.onStartCommand(intent, flags, startId);
- }
-
- mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
- mNotification = new Notification();
-
- mNotification.contentView = new RemoteViews(getApplication().getPackageName(), R.layout.less_app_update_notification);
-
- Intent completingIntent = new Intent();
- completingIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
- completingIntent.setClass(getApplicationContext(), UpdateService.class);
-
- mPendingIntent = PendingIntent.getActivity(UpdateService.this, R.string.less_app_name, completingIntent, PendingIntent.FLAG_UPDATE_CURRENT);
-
- mNotification.icon = $.sUpdateIcon != 0 ? $.sUpdateIcon : R.drawable.less_app_update_icon;
- mNotification.tickerText = getText(R.string.less_app_download_notification_start);
- mNotification.contentIntent = mPendingIntent;
- mNotification.contentView.setProgressBar(R.id.less_app_update_progressbar, 100, 0, false);
- mNotification.contentView.setTextViewText(R.id.less_app_update_progress_text, "0%");
- if ($.sUpdateIcon != 0) {
- mNotification.contentView.setImageViewResource(R.id.less_app_update_progress_icon, $.sUpdateIcon);
- }
- mNotificationManager.cancel(NOTIFICATION_ID);
- mNotificationManager.notify(NOTIFICATION_ID, mNotification);
- new UpdateThread().start();
-
- return super.onStartCommand(intent, flags, startId);
- }
-
- public boolean checkApkFile(String apkFilePath) {
- boolean result;
- try {
- PackageManager pManager = getPackageManager();
- PackageInfo pInfo = pManager.getPackageArchiveInfo(apkFilePath, PackageManager.GET_ACTIVITIES);
- if (pInfo == null) {
- result = false;
- } else {
- result = true;
- }
- } catch (Exception e) {
- result = false;
- e.printStackTrace();
- }
- return result;
- }
-
- private void install(File apkFile) {
- Uri uri = Uri.fromFile(apkFile);
- Intent intent = new Intent(Intent.ACTION_VIEW);
- intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- intent.setDataAndType(uri, "application/vnd.android.package-archive");
- startActivity(intent);
- }
-
- private void sendMessage(int what) {
- Message msg = mHandler.obtainMessage();
- msg.what = what;
- mHandler.sendMessage(msg);
- }
-
- @Override
- public IBinder onBind(Intent intent) {
- return null;
- }
-
- @Override
- public void onDestroy() {
- super.onDestroy();
- mHandler.removeCallbacksAndMessages(null);
- }
-
- class UpdateThread extends Thread {
-
- @Override
- public void run() {
- if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
- if (mDestDir == null) {
- mDestDir = new File(Environment.getExternalStorageDirectory().getPath()
- + "/" + mDownloadSDPath);
- }
-
- if (mDestDir.exists() && !mDestDir.isDirectory()) {
- mDestDir.delete();
- }
-
- if (mDestDir.exists() || mDestDir.mkdirs()) {
- mDestFile = new File(mDestDir.getPath()
- + "/" + URLEncoder.encode(mDownloadUrl));
- if (mDestFile.exists()
- && mDestFile.isFile()
- && checkApkFile(mDestFile.getPath())) {
- sendMessage(DOWNLOAD_STATE_INSTALL);
- install(mDestFile);
- } else {
- try {
- sendMessage(DOWNLOAD_STATE_START);
- HttpLess.$download(mDownloadUrl, mDestFile, false, mDownloadCallBack);
- } catch (Exception e) {
- sendMessage(DOWNLOAD_STATE_FAILURE);
- e.printStackTrace();
- }
- }
- }
- } else {
- sendMessage(DOWNLOAD_STATE_ERROR_SDCARD);
- }
- stopSelf();
- }
- }
-}
diff --git a/lesscode-core/src/main/java/com/jayfeng/lesscode/core/ViewLess.java b/lesscode-core/src/main/java/com/jayfeng/lesscode/core/ViewLess.java
index d8ec878..d68ac73 100644
--- a/lesscode-core/src/main/java/com/jayfeng/lesscode/core/ViewLess.java
+++ b/lesscode-core/src/main/java/com/jayfeng/lesscode/core/ViewLess.java
@@ -4,8 +4,19 @@
import android.app.Dialog;
import android.view.View;
-public class ViewLess {
+import java.util.Calendar;
+/**
+ * View相关工具类
+ */
+public final class ViewLess {
+
+ /**
+ * ***********************************************************
+ * findViewById的一种更优雅的写法
+ * 原理:泛型的类型推断
+ * ***********************************************************
+ */
public static T $(Activity activity, int viewId) {
return (T) activity.findViewById(viewId);
}
diff --git a/lesscode-core/src/main/java/com/jayfeng/lesscode/core/other/DividerItemDecoration.java b/lesscode-core/src/main/java/com/jayfeng/lesscode/core/other/DividerItemDecoration.java
new file mode 100644
index 0000000..dd6ff88
--- /dev/null
+++ b/lesscode-core/src/main/java/com/jayfeng/lesscode/core/other/DividerItemDecoration.java
@@ -0,0 +1,150 @@
+package com.jayfeng.lesscode.core.other;
+
+import android.content.Context;
+import android.content.res.TypedArray;
+import android.graphics.Canvas;
+import android.graphics.Rect;
+import android.graphics.drawable.Drawable;
+import android.support.v4.view.ViewCompat;
+import android.support.v7.widget.GridLayoutManager;
+import android.support.v7.widget.LinearLayoutManager;
+import android.support.v7.widget.RecyclerView;
+import android.view.View;
+
+/**
+ * RecyclerView的ItemDecoration的默认实现
+ * 1. 默认使用系统的分割线
+ * 2. 支持自定义Drawable类型
+ * 3. 支持水平和垂直方向
+ * 4. 修复了官方垂直Divider显示的bug
+ * 5. 增加支持GRID_LIST的分割线, 但仅支持空视图分割(如果嫌弃左右上下多余的padding, 可以在RecyclerView中设置padding为负值解决)
+ * 扩展自官方android sdk下的Support7Demos下的DividerItemDecoration
+ */
+public class DividerItemDecoration extends RecyclerView.ItemDecoration {
+
+ private static final int[] ATTRS = new int[]{
+ android.R.attr.listDivider
+ };
+
+ public static final int HORIZONTAL_LIST = LinearLayoutManager.HORIZONTAL;
+ public static final int VERTICAL_LIST = LinearLayoutManager.VERTICAL;
+ public static final int GRID_LIST = LinearLayoutManager.VERTICAL + 1;
+
+ private Drawable mDivider;
+ private int mWidth;
+ private int mHeight;
+
+ private int mOrientation;
+
+ public DividerItemDecoration(Context context, int orientation) {
+ final TypedArray a = context.obtainStyledAttributes(ATTRS);
+ mDivider = a.getDrawable(0);
+ a.recycle();
+ setOrientation(orientation);
+ }
+
+ /**
+ * 新增:支持自定义dividerDrawable
+ *
+ * @param context
+ * @param orientation
+ * @param dividerDrawable
+ */
+ public DividerItemDecoration(Context context, int orientation, Drawable dividerDrawable) {
+ mDivider = dividerDrawable;
+ setOrientation(orientation);
+ }
+
+ public void setOrientation(int orientation) {
+ if (orientation != HORIZONTAL_LIST
+ && orientation != VERTICAL_LIST
+ && orientation != GRID_LIST) {
+ throw new IllegalArgumentException("invalid orientation");
+ }
+ mOrientation = orientation;
+ }
+
+ /**
+ * 新增:支持手动为无高宽的drawable制定宽度
+ *
+ * @param width
+ */
+ public void setWidth(int width) {
+ this.mWidth = width;
+ }
+
+ /**
+ * 新增:支持手动为无高宽的drawable制定高度
+ *
+ * @param height
+ */
+ public void setHeight(int height) {
+ this.mHeight = height;
+ }
+
+ @Override
+ public void onDraw(Canvas c, RecyclerView parent) {
+ if (mOrientation == VERTICAL_LIST) {
+ drawVertical(c, parent);
+ } else if (mOrientation == HORIZONTAL_LIST) {
+ drawHorizontal(c, parent);
+ }
+ }
+
+ public void drawVertical(Canvas c, RecyclerView parent) {
+ int left = parent.getPaddingLeft();
+ int right = parent.getWidth() - parent.getPaddingRight();
+
+ final int childCount = parent.getChildCount();
+ for (int i = 0; i < childCount; i++) {
+ final View child = parent.getChildAt(i);
+ final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child
+ .getLayoutParams();
+ int top = child.getBottom() + params.bottomMargin +
+ Math.round(ViewCompat.getTranslationY(child));
+ int bottom = top + getDividerHeight();
+
+
+ mDivider.setBounds(left, top, right, bottom);
+ mDivider.draw(c);
+ }
+ }
+
+ public void drawHorizontal(Canvas c, RecyclerView parent) {
+ int top = parent.getPaddingTop();
+ int bottom = parent.getHeight() - parent.getPaddingBottom();
+
+ final int childCount = parent.getChildCount();
+ for (int i = 0; i < childCount; i++) {
+ final View child = parent.getChildAt(i);
+ final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child
+ .getLayoutParams();
+ int left = child.getRight() + params.rightMargin +
+ Math.round(ViewCompat.getTranslationX(child));
+ int right = left + getDividerWidth();
+
+ mDivider.setBounds(left, top, right, bottom);
+ mDivider.draw(c);
+ }
+ }
+
+ @Override
+ public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
+ if (mOrientation == VERTICAL_LIST) {
+ outRect.set(0, 0, 0, getDividerHeight());
+ } else if (mOrientation == HORIZONTAL_LIST) {
+ outRect.set(0, 0, getDividerWidth(), 0);
+ } else if (mOrientation == GRID_LIST) {
+ outRect.set(getDividerWidth(), getDividerHeight(), getDividerWidth(), getDividerHeight());
+ }
+ }
+
+ private int getDividerWidth() {
+ return mWidth > 0 ? mWidth : mDivider.getIntrinsicWidth();
+ }
+
+ private int getDividerHeight() {
+ return mHeight > 0 ? mHeight : mDivider.getIntrinsicHeight();
+ }
+
+}
diff --git a/lesscode-core/src/main/java/com/jayfeng/lesscode/core/other/SpaceDividerView.java b/lesscode-core/src/main/java/com/jayfeng/lesscode/core/other/SpaceDividerView.java
new file mode 100644
index 0000000..6a3492c
--- /dev/null
+++ b/lesscode-core/src/main/java/com/jayfeng/lesscode/core/other/SpaceDividerView.java
@@ -0,0 +1,91 @@
+package com.jayfeng.lesscode.core.other;
+
+import android.content.Context;
+import android.content.res.TypedArray;
+import android.graphics.Canvas;
+import android.graphics.Color;
+import android.graphics.Paint;
+import android.util.AttributeSet;
+import android.util.TypedValue;
+import android.view.View;
+
+import com.jayfeng.lesscode.core.R;
+
+public class SpaceDividerView extends View {
+
+ private int mSpaceLeft = 0;
+ private int mSpaceTop = 0;
+ private int mSpaceRight = 0;
+ private int mSpaceBottom = 0;
+ private int mSpaceColor = Color.TRANSPARENT;
+
+ private Paint mPaint = new Paint();
+
+ public SpaceDividerView(Context context) {
+ this(context, null);
+ }
+
+ public SpaceDividerView(Context context, AttributeSet attrs) {
+ this(context, attrs, 0);
+ }
+
+ public SpaceDividerView(Context context, AttributeSet attrs, int defStyleAttr) {
+ super(context, attrs, defStyleAttr);
+
+ TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SpaceDividerView, defStyleAttr, 0);
+ mSpaceLeft = a.getDimensionPixelSize(R.styleable.SpaceDividerView_spaceLeft,
+ (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 0, getResources().getDisplayMetrics()));
+ mSpaceTop = a.getDimensionPixelSize(R.styleable.SpaceDividerView_spaceTop,
+ (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 0, getResources().getDisplayMetrics()));
+ mSpaceRight = a.getDimensionPixelSize(R.styleable.SpaceDividerView_spaceRight,
+ (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 0, getResources().getDisplayMetrics()));
+ mSpaceBottom = a.getDimensionPixelSize(R.styleable.SpaceDividerView_spaceBottom,
+ (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 0, getResources().getDisplayMetrics()));
+ mSpaceColor = a.getColor(R.styleable.SpaceDividerView_spaceColor, Color.TRANSPARENT);
+ a.recycle();
+
+ mPaint.setColor(mSpaceColor);
+ }
+
+ @Override
+ protected void onDraw(Canvas canvas) {
+ super.onDraw(canvas);
+ if (mSpaceLeft > 0) {
+ canvas.drawRect(0, 0, mSpaceLeft, getMeasuredHeight(), mPaint);
+ }
+ if (mSpaceTop > 0) {
+ canvas.drawRect(0, 0, getMeasuredWidth(), mSpaceTop, mPaint);
+ }
+ if (mSpaceRight > 0) {
+ canvas.drawRect(getMeasuredWidth() - mSpaceRight, 0, getMeasuredWidth(), getMeasuredHeight(), mPaint);
+ }
+ if (mSpaceBottom > 0) {
+ canvas.drawRect(0, getMeasuredHeight() - mSpaceBottom, getMeasuredWidth(), getMeasuredHeight(), mPaint);
+ }
+ }
+
+ public void setSpaceLeft(int spaceLeft) {
+ this.mSpaceLeft = spaceLeft;
+ invalidate();
+ }
+
+ public void setSpaceTop(int spaceTop) {
+ this.mSpaceTop = spaceTop;
+ invalidate();
+ }
+
+ public void setSpaceRight(int spaceRight) {
+ this.mSpaceRight = spaceRight;
+ invalidate();
+ }
+
+ public void setSpaceBottom(int spaceBottom) {
+ this.mSpaceBottom = spaceBottom;
+ invalidate();
+ }
+
+ public void setSpaceColor(int spaceColor) {
+ this.mSpaceColor = spaceColor;
+ invalidate();
+ }
+}
diff --git a/lesscode-core/src/main/java/com/jayfeng/lesscode/core/other/ViewThrottleClickListener.java b/lesscode-core/src/main/java/com/jayfeng/lesscode/core/other/ViewThrottleClickListener.java
new file mode 100644
index 0000000..98a1cb9
--- /dev/null
+++ b/lesscode-core/src/main/java/com/jayfeng/lesscode/core/other/ViewThrottleClickListener.java
@@ -0,0 +1,31 @@
+package com.jayfeng.lesscode.core.other;
+
+import android.view.View;
+
+import java.util.Calendar;
+
+/**
+ * 防止快速点击的ClickListener
+ */
+public abstract class ViewThrottleClickListener implements View.OnClickListener {
+ private static final int THROTTLE_TIME_DEFAULT = 1000; // 1s
+ private long mLastClickTime = 0;
+
+ public long getThrottleTime() {
+ return THROTTLE_TIME_DEFAULT;
+ }
+ public void discardClick() {}
+
+ public abstract void throttleClick(View view);
+
+ @Override
+ public void onClick(View v) {
+ long currentTime = Calendar.getInstance().getTimeInMillis();
+ if (currentTime - mLastClickTime > getThrottleTime()) {
+ mLastClickTime = currentTime;
+ throttleClick(v);
+ } else {
+ discardClick();
+ }
+ }
+}
diff --git a/lesscode-core/src/main/java/com/jayfeng/lesscode/core/other/WeakHandler.java b/lesscode-core/src/main/java/com/jayfeng/lesscode/core/other/WeakHandler.java
new file mode 100644
index 0000000..8256131
--- /dev/null
+++ b/lesscode-core/src/main/java/com/jayfeng/lesscode/core/other/WeakHandler.java
@@ -0,0 +1,17 @@
+package com.jayfeng.lesscode.core.other;
+
+import android.os.Handler;
+
+import java.lang.ref.WeakReference;
+
+public abstract class WeakHandler extends Handler {
+ private WeakReference mOwner;
+
+ public WeakHandler(T owner) {
+ mOwner = new WeakReference<>(owner);
+ }
+
+ public T getOwner() {
+ return mOwner.get();
+ }
+}
diff --git a/lesscode-core/src/main/res/drawable-xhdpi/less_app_update_icon.png b/lesscode-core/src/main/res/drawable-xhdpi/less_app_update_icon.png
deleted file mode 100644
index 71c6d76..0000000
Binary files a/lesscode-core/src/main/res/drawable-xhdpi/less_app_update_icon.png and /dev/null differ
diff --git a/lesscode-core/src/main/res/layout/less_app_update_notification.xml b/lesscode-core/src/main/res/layout/less_app_update_notification.xml
deleted file mode 100755
index a0abbd7..0000000
--- a/lesscode-core/src/main/res/layout/less_app_update_notification.xml
+++ /dev/null
@@ -1,59 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/lesscode-core/src/main/res/values-hdpi/bools.xml b/lesscode-core/src/main/res/values-hdpi/bools.xml
index 9ee1bad..15e7bf1 100644
--- a/lesscode-core/src/main/res/values-hdpi/bools.xml
+++ b/lesscode-core/src/main/res/values-hdpi/bools.xml
@@ -6,4 +6,5 @@
true
false
false
+ false
\ No newline at end of file
diff --git a/lesscode-core/src/main/res/values-ldpi/bools.xml b/lesscode-core/src/main/res/values-ldpi/bools.xml
index 9d45f0e..af66e2a 100644
--- a/lesscode-core/src/main/res/values-ldpi/bools.xml
+++ b/lesscode-core/src/main/res/values-ldpi/bools.xml
@@ -6,4 +6,5 @@
false
false
false
+ false
\ No newline at end of file
diff --git a/lesscode-core/src/main/res/values-mdpi/bools.xml b/lesscode-core/src/main/res/values-mdpi/bools.xml
index e5d0e67..b6e468c 100644
--- a/lesscode-core/src/main/res/values-mdpi/bools.xml
+++ b/lesscode-core/src/main/res/values-mdpi/bools.xml
@@ -6,4 +6,5 @@
false
false
false
+ false
\ No newline at end of file
diff --git a/lesscode-core/src/main/res/values-tvdpi/bools.xml b/lesscode-core/src/main/res/values-tvdpi/bools.xml
index 9214cf2..8bb3bf4 100644
--- a/lesscode-core/src/main/res/values-tvdpi/bools.xml
+++ b/lesscode-core/src/main/res/values-tvdpi/bools.xml
@@ -6,4 +6,5 @@
false
false
false
+ false
\ No newline at end of file
diff --git a/lesscode-core/src/main/res/values-xhdpi/bools.xml b/lesscode-core/src/main/res/values-xhdpi/bools.xml
index f74fff0..2071961 100644
--- a/lesscode-core/src/main/res/values-xhdpi/bools.xml
+++ b/lesscode-core/src/main/res/values-xhdpi/bools.xml
@@ -6,4 +6,5 @@
false
true
false
+ false
\ No newline at end of file
diff --git a/lesscode-core/src/main/res/values-xxhdpi/bools.xml b/lesscode-core/src/main/res/values-xxhdpi/bools.xml
index 1eb0eb7..7696bba 100644
--- a/lesscode-core/src/main/res/values-xxhdpi/bools.xml
+++ b/lesscode-core/src/main/res/values-xxhdpi/bools.xml
@@ -6,4 +6,5 @@
false
false
true
+ false
\ No newline at end of file
diff --git a/lesscode-core/src/main/res/values-xxxhdpi/bools.xml b/lesscode-core/src/main/res/values-xxxhdpi/bools.xml
new file mode 100644
index 0000000..c6c675c
--- /dev/null
+++ b/lesscode-core/src/main/res/values-xxxhdpi/bools.xml
@@ -0,0 +1,10 @@
+
+
+ false
+ false
+ false
+ false
+ false
+ false
+ true
+
\ No newline at end of file
diff --git a/lesscode-core/src/main/res/values/attrs_space_divider_view.xml b/lesscode-core/src/main/res/values/attrs_space_divider_view.xml
new file mode 100644
index 0000000..d6316d9
--- /dev/null
+++ b/lesscode-core/src/main/res/values/attrs_space_divider_view.xml
@@ -0,0 +1,10 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/lesscode-core/src/main/res/values/strings.xml b/lesscode-core/src/main/res/values/strings.xml
index a4d2128..26de80e 100644
--- a/lesscode-core/src/main/res/values/strings.xml
+++ b/lesscode-core/src/main/res/values/strings.xml
@@ -1,12 +1,3 @@
LessCode Core
-
- 发现新版本:
- 开始下载
- 下载完成。
- 新版本下载成功,开始安装。
- 新版本下载失败,请稍后再试。
- 开始下载
- 准备安装
- 未找到SD卡,无法下载。
\ No newline at end of file
diff --git a/settings.gradle b/settings.gradle
index 174e218..e414997 100644
--- a/settings.gradle
+++ b/settings.gradle
@@ -1 +1 @@
-include ':app', ':lesscode-core', ':app-ref-lesscode-core'
+include ':app', ':lesscode-core'