提交保证28可以编译通过并且运行,还存在部分未适配

This commit is contained in:
zengfantian 2020-02-03 18:11:15 +08:00
parent c47112a01e
commit 95f5bdb930
9 changed files with 493 additions and 102 deletions

View File

@ -173,6 +173,7 @@ dependencies {
// -()
compile project(':modules:bm_dynamic-page')
compile("com.squareup.okhttp3:okhttp:3.12.1")
// // ()
// compile 'com.zftlive.android.library:common-resource:1.0.0'

View File

@ -18,6 +18,10 @@
package com.zftlive.android;
import android.app.Activity;
import android.content.pm.ActivityInfo;
import android.content.res.TypedArray;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
@ -29,6 +33,9 @@ import com.zftlive.android.library.Logger;
import com.zftlive.android.library.base.ui.CommonActivity;
import com.zftlive.android.sample.MainActivity;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
/**
* 程序启动界面
* @author 曾繁添,曾宪明
@ -37,6 +44,15 @@ import com.zftlive.android.sample.MainActivity;
*/
public class Launcher extends CommonActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.O && isTranslucentOrFloating()) {
boolean result = fixOrientation();
// XLog.i(XLog.BASE, "onCreate fixOrientation when Oreo, result = " + result);
}
super.onCreate(savedInstanceState);
}
@Override
public int bindLayout() {
return R.layout.activity_launcher;
@ -94,4 +110,43 @@ public class Launcher extends CommonActivity {
});
view.setAnimation(animation);
}
@Override
public void setRequestedOrientation(int requestedOrientation) {
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.O && isTranslucentOrFloating()) {
// XLog.i(XLog.BASE, "avoid calling setRequestedOrientation when Oreo.");
return;
}
super.setRequestedOrientation(requestedOrientation);
}
private boolean isTranslucentOrFloating() {
boolean isTranslucentOrFloating = false;
try {
int[] styleableRes =
(int[]) Class.forName("com.android.internal.R$styleable").getField("Window").get(null);
final TypedArray ta = obtainStyledAttributes(styleableRes);
Method m = ActivityInfo.class.getMethod("isTranslucentOrFloating", TypedArray.class);
m.setAccessible(true);
isTranslucentOrFloating = (boolean) m.invoke(null, ta);
m.setAccessible(false);
} catch (Exception e) {
e.printStackTrace();
}
return isTranslucentOrFloating;
}
private boolean fixOrientation() {
try {
Field field = Activity.class.getDeclaredField("mActivityInfo");
field.setAccessible(true);
ActivityInfo o = (ActivityInfo) field.get(this);
o.screenOrientation = -1;
field.setAccessible(false);
return true;
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
}

View File

@ -22,7 +22,10 @@ import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.ResolveInfo;
import android.content.res.TypedArray;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.view.Gravity;
@ -45,6 +48,8 @@ import com.zftlive.android.library.base.bean.AdapterModelBean;
import com.zftlive.android.library.base.ui.CommonActivity;
import com.zftlive.android.library.tools.ToolPhone;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
@ -66,6 +71,16 @@ public class MainActivity extends CommonActivity {
private ListView mListView;
public final static String SAMPLE_CODE = "com.zftlive.android.SAMPLE_CODE";
@Override
protected void onCreate(Bundle savedInstanceState) {
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.O && isTranslucentOrFloating()) {
boolean result = fixOrientation();
// XLog.i(XLog.BASE, "onCreate fixOrientation when Oreo, result = " + result);
}
super.onCreate(savedInstanceState);
}
@Override
public void config(Bundle savedInstanceState) {
super.config(savedInstanceState);
@ -256,4 +271,43 @@ public class MainActivity extends CommonActivity {
}
}
@Override
public void setRequestedOrientation(int requestedOrientation) {
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.O && isTranslucentOrFloating()) {
// XLog.i(XLog.BASE, "avoid calling setRequestedOrientation when Oreo.");
return;
}
super.setRequestedOrientation(requestedOrientation);
}
private boolean isTranslucentOrFloating() {
boolean isTranslucentOrFloating = false;
try {
int[] styleableRes =
(int[]) Class.forName("com.android.internal.R$styleable").getField("Window").get(null);
final TypedArray ta = obtainStyledAttributes(styleableRes);
Method m = ActivityInfo.class.getMethod("isTranslucentOrFloating", TypedArray.class);
m.setAccessible(true);
isTranslucentOrFloating = (boolean) m.invoke(null, ta);
m.setAccessible(false);
} catch (Exception e) {
e.printStackTrace();
}
return isTranslucentOrFloating;
}
private boolean fixOrientation() {
try {
Field field = Activity.class.getDeclaredField("mActivityInfo");
field.setAccessible(true);
ActivityInfo o = (ActivityInfo) field.get(this);
o.screenOrientation = -1;
field.setAccessible(false);
return true;
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
}

View File

@ -0,0 +1,128 @@
package com.zftlive.android.sample.http;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
/**
* Created by wanglingsheng on 2018/5/29.
* 文件下载工具类单例模式
*/
public class DownloadUtil {
private static DownloadUtil downloadUtil;
private final OkHttpClient okHttpClient;
public static DownloadUtil get() {
if (downloadUtil == null) {
downloadUtil = new DownloadUtil();
}
return downloadUtil;
}
public DownloadUtil() {
okHttpClient = new OkHttpClient();
}
/**
* @param url 下载连接
* @param destFileDir 下载的文件储存目录
* @param destFileName 下载文件名称
* @param listener 下载监听
*/
public void download(final String url, final String destFileDir, final String destFileName, final OnDownloadListener listener) {
Request request = new Request.Builder()
.url(url)
.build();
//异步请求
okHttpClient.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
// 下载失败监听回调
listener.onDownloadFailed(e);
}
@Override
public void onResponse(Call call, Response response) throws IOException {
InputStream is = null;
byte[] buf = new byte[2048];
int len = 0;
FileOutputStream fos = null;
//储存下载文件的目录
File dir = new File(destFileDir);
if (!dir.exists()) {
dir.mkdirs();
}
File file = new File(dir, destFileName);
try {
is = response.body().byteStream();
long total = response.body().contentLength();
fos = new FileOutputStream(file);
long sum = 0;
while ((len = is.read(buf)) != -1) {
fos.write(buf, 0, len);
sum += len;
int progress = (int) (sum * 1.0f / total * 100);
//下载中更新进度条
listener.onDownloading(progress);
}
fos.flush();
//下载完成
listener.onDownloadSuccess(file);
} catch (Exception e) {
listener.onDownloadFailed(e);
}finally {
try {
if (is != null) {
is.close();
}
if (fos != null) {
fos.close();
}
} catch (IOException e) {
}
}
}
});
}
public interface OnDownloadListener{
/**
* 下载成功之后的文件
*/
void onDownloadSuccess(File file);
/**
* 下载进度
*/
void onDownloading(int progress);
/**
* 下载异常信息
*/
void onDownloadFailed(Exception e);
}
}

View File

@ -20,17 +20,19 @@ package com.zftlive.android.sample.http;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import com.loopj.android.http.BinaryHttpResponseHandler;
import com.loopj.android.http.JsonHttpResponseHandler;
import com.loopj.android.http.RequestParams;
import com.loopj.android.http.ResponseHandlerInterface;
import com.zftlive.android.R;
import com.zftlive.android.library.Alert;
import com.zftlive.android.library.Logger;
import com.zftlive.android.library.base.ui.CommonActivity;
import com.zftlive.android.library.network.ToolHTTP;
import com.zftlive.android.library.tools.ToolDateTime;
@ -63,7 +65,11 @@ public class FileDownloadUploadActivity extends CommonActivity implements OnClic
public final static String DOWNLOAD_FILE_PATH = "http://zftlive-images.qiniudn.com/avatar.png";
public final static String UPLOAD_FILE = "http://10.45.255.90:8080/AjavaWeb/cn/com/ajava/servlet/ServletUploadFile";
private final static String apk = "https://125.39.12.5/downapp/JDJR-release-20191203T1741.apk";
private Handler mHandler;
@Override
public int bindLayout() {
return R.layout.activity_file_upload_download;
@ -71,7 +77,18 @@ public class FileDownloadUploadActivity extends CommonActivity implements OnClic
@Override
public void initParams(Bundle parms) {
mHandler = new Handler(){
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
if(msg.what == 11){
Alert.updateProgressText(String.valueOf(msg.obj));
}else{
Alert.closeLoading();
}
}
};
}
@Override
@ -84,6 +101,7 @@ public class FileDownloadUploadActivity extends CommonActivity implements OnClic
et_downfile_path = (EditText) findViewById(R.id.et_downfile_path);
et_downfile_path.setText(DOWNLOAD_FILE_PATH);
et_downfile_path.setText(apk);
et_upload_file_path = (EditText) findViewById(R.id.et_upload_file_path);
}
@ -101,6 +119,10 @@ public class FileDownloadUploadActivity extends CommonActivity implements OnClic
case R.id.btn_download:
Alert.loading(getContext(), "准备下载");
downFile(et_downfile_path.getText().toString().trim());
/**
String[] allowType = {".*"};
ToolHTTP.get(DOWNLOAD_FILE_PATH, new BinaryHttpResponseHandler(allowType) {
@ -136,6 +158,7 @@ public class FileDownloadUploadActivity extends CommonActivity implements OnClic
Alert.closeLoading();
}
});
**/
break;
case R.id.btn_upload:
@ -205,4 +228,41 @@ public class FileDownloadUploadActivity extends CommonActivity implements OnClic
}
};
}
/**
* 文件下载
*/
private void downFile(String url) {
DownloadUtil.get().download(url, ToolFile.gainSDCardPath()+"/ajava_download/", ToolDateTime.gainCurrentDate("yyyyMMddHHmmss")+".apk",
new DownloadUtil.OnDownloadListener() {
@Override
public void onDownloadSuccess(File file) {
//下载完成进行相关逻辑操作
Message msg = mHandler.obtainMessage();
msg.what = 0;
mHandler.sendMessage(msg);
}
@Override
public void onDownloading(int progress) {
Message msg = mHandler.obtainMessage();
msg.what = 11;
msg.obj = progress;
mHandler.sendMessage(msg);
Logger.d(TAG,"当前下载进度:"+progress);
}
@Override
public void onDownloadFailed(Exception e) {
//下载异常进行相关提示操作
Message msg = mHandler.obtainMessage();
msg.what = 1;
msg.obj = e;
mHandler.sendMessage(msg);
}
});
}
}

View File

@ -1,93 +1,93 @@
/*
* Android基础开发个人积累沉淀封装整理共通
* Copyright (c) 2016. 曾繁添 <zftlive@163.com>
* Githubhttps://github.com/zengfantian || http://git.oschina.net/zftlive
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.zftlive.android.tests;
import java.io.UnsupportedEncodingException;
import android.test.AndroidTestCase;
import android.util.Log;
import com.zftlive.android.library.tools.security.Base64;
import com.zftlive.android.library.tools.security.DES;
import com.zftlive.android.library.tools.security.MD5;
/**
* 安全加密测试用例
* @author 曾繁添
* @version 1.0
*
*/
public class TestSecurity extends AndroidTestCase {
/**
* 加密Key可以用官方的签名指纹作为加密key只要官方签名文件不泄露加密则是安全的
*/
String key = "ajavagongchengshi";
/**
* 加密明文
*/
String encrypt = "Ajava工程师";
String TAG = "Test";
public void testBase64EnDecrypt(){
try {
String encodeResult = Base64.encode(encrypt.getBytes());
Log.e(TAG, "testBase64EnDecrypt.encodeResult-->"+encodeResult);
String decodeResult = new String(Base64.decode(encodeResult),"UTF-8");
Log.e(TAG, "testDESEnDecrypt.decodeResult-->"+decodeResult);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
/**
* 测试DES加密/解密
*/
public void testDESEnDecrypt(){
try {
String encodeResult = DES.encrypt(key, encrypt);
Log.e(TAG, "testDESEnDecrypt.encodeResult-->"+encodeResult);
String decodeResult = DES.decrypt(key, encodeResult);
Log.e(TAG, "testDESEnDecrypt.decodeResult-->"+decodeResult);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* MD5加密
*/
public void testMD5EnDecrypt(){
try {
String encodeResult1 = MD5.encrypt16byte(encrypt);
Log.e(TAG, "testMD5EnDecrypt.encrypt16byte-->"+encodeResult1);
String encodeResult2 = MD5.encrypt32byte(encrypt);
Log.e(TAG, "testMD5EnDecrypt.encrypt32byte-->"+encodeResult2);
} catch (Exception e) {
e.printStackTrace();
}
}
}
///*
// * Android基础开发个人积累沉淀封装整理共通
// * Copyright (c) 2016. 曾繁添 <zftlive@163.com>
// * Githubhttps://github.com/zengfantian || http://git.oschina.net/zftlive
// *
// * Licensed under the Apache License, Version 2.0 (the "License");
// * you may not use this file except in compliance with the License.
// * You may obtain a copy of the License at
// *
// * http://www.apache.org/licenses/LICENSE-2.0
// *
// * Unless required by applicable law or agreed to in writing, software
// * distributed under the License is distributed on an "AS IS" BASIS,
// * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// * See the License for the specific language governing permissions and
// * limitations under the License.
// */
//
//package com.zftlive.android.tests;
//
//import android.test.AndroidTestCase;
//import android.util.Log;
//
//import com.zftlive.android.library.tools.security.Base64;
//import com.zftlive.android.library.tools.security.DES;
//import com.zftlive.android.library.tools.security.MD5;
//
//import java.io.UnsupportedEncodingException;
//
///**
// * 安全加密测试用例
// * @author 曾繁添
// * @version 1.0
// *
// */
//public class TestSecurity extends AndroidTestCase {
//
// /**
// * 加密Key可以用官方的签名指纹作为加密key只要官方签名文件不泄露加密则是安全的
// */
// String key = "ajavagongchengshi";
//
// /**
// * 加密明文
// */
// String encrypt = "Ajava工程师";
//
// String TAG = "Test";
//
// public void testBase64EnDecrypt(){
// try {
// String encodeResult = Base64.encode(encrypt.getBytes());
// Log.e(TAG, "testBase64EnDecrypt.encodeResult-->"+encodeResult);
//
// String decodeResult = new String(Base64.decode(encodeResult),"UTF-8");
// Log.e(TAG, "testDESEnDecrypt.decodeResult-->"+decodeResult);
//
// } catch (UnsupportedEncodingException e) {
// e.printStackTrace();
// }
// }
//
// /**
// * 测试DES加密/解密
// */
// public void testDESEnDecrypt(){
// try {
// String encodeResult = DES.encrypt(key, encrypt);
// Log.e(TAG, "testDESEnDecrypt.encodeResult-->"+encodeResult);
//
// String decodeResult = DES.decrypt(key, encodeResult);
// Log.e(TAG, "testDESEnDecrypt.decodeResult-->"+decodeResult);
// } catch (Exception e) {
// e.printStackTrace();
// }
// }
//
// /**
// * MD5加密
// */
// public void testMD5EnDecrypt(){
// try {
// String encodeResult1 = MD5.encrypt16byte(encrypt);
// Log.e(TAG, "testMD5EnDecrypt.encrypt16byte-->"+encodeResult1);
//
// String encodeResult2 = MD5.encrypt32byte(encrypt);
// Log.e(TAG, "testMD5EnDecrypt.encrypt32byte-->"+encodeResult2);
// } catch (Exception e) {
// e.printStackTrace();
// }
// }
//
//}

View File

@ -21,10 +21,16 @@ buildscript {
//
//minSdkVersion <= targetSdkVersion <= compileSdkVersion
ext {
compileSdkVersion = 23 //SDK版本
buildToolsVersion = "25.0.3"//SDK工具版本
minSdkVersion = 9 //
targetSdkVersion = 22 //23
// compileSdkVersion = 23 //SDK版本
// buildToolsVersion = "25.0.3"//SDK工具版本
// minSdkVersion = 9 //
// targetSdkVersion = 22 //23
compileSdkVersion = 28
//24+[too many classes in main-dex-list, main dex capacity exceeded] v4.2.0 20170704
buildToolsVersion = "28.0.3"
minSdkVersion = 16
//23
targetSdkVersion = 28
}
allprojects {

85
config.gradle Normal file
View File

@ -0,0 +1,85 @@
/**
* ext自定义[App全局环境变量配置]
*
* @author
* @version 1.0
*
*/
def jdjr_repo_snapshots = '';
def jdjr_repo_release = '';
ext {
//app配置
app = [
applicationId : "com.zftlive.android",
versionCode : 3,
versionName : "1.2",
releaseVersion: "0"
]
//
android = [
compileSdkVersion: 28,
buildToolsVersion: "28.0.3",
minSdkVersion : 16,
targetSdkVersion : 28
]
//maven发布相关配置
maven = [
repo_snapshots : jdjr_repo_snapshots,
repo_release : jdjr_repo_release,
bintrayRepo : 'android',
publishedGroupIdForBm : "com.zftlive.android.bm",
publishedGroupIdForBmc: "com.zftlive.android.bm.common",
publishedGroupIdForLib: "com.zftlive.android.library",
publishedGroupIdForSDK: "com.zftlive.android.sdk",
developerId : 'zengfantian',
developerName : '曾繁添',
developerEmail : 'zftlive@163.com',
allLicenses : '["Apache-2.0"]',
licenseName : 'The Apache Software License, Version 2.0',
licenseUrl : 'http://www.apache.com/'
]
//
basicDependencies = [
support_v4 : 'com.android.support:support-v4:28.0.0',
support_v7 : 'com.android.support:appcompat-v7:28.0.0',
support_annotations : 'com.android.support:support-annotations:28.0.0',
support_exif : 'com.android.support:exifinterface:28.0.0',
recyclerview : 'com.android.support:recyclerview-v7:28.0.0',
cardview_v7 : 'com.android.support:cardview-v7:28.0.0',
spring_animation : 'com.android.support:support-dynamic-animation:28.0.0',
constraint : 'com.android.support.constraint:constraint-layout:1.1.0',
percent : 'com.android.support:percent:28.0.0',
design : 'com.android.support:design:28.0.0',
multidex : 'com.android.support:multidex:1.0.3',
multidex_instrumentation: 'com.android.support:multidex-instrumentation:1.0.3',
junit : 'junit:junit:4.12',
gson : 'com.google.code.gson:gson:2.8.5',
fastjson : 'com.alibaba:fastjson:1.2.7',
nineoldandroids : 'com.nineoldandroids:library:2.4.0',
wheelpicker : 'cn.aigestudio.wheelpicker:WheelPicker:1.1.2',
greendao : 'org.greenrobot:greendao:3.2.2',
flexbox : 'com.google.android:flexbox:1.0.0',
countdownview : 'com.github.iwgang:countdownview:2.1.6',
eventbus : 'org.greenrobot:eventbus:3.0.0',
okhttp3 : 'com.squareup.okhttp3:okhttp:3.6.0',
lifecycle_runtime : 'android.arch.lifecycle:runtime:1.0.3',
wechatopen : 'com.tencent.mm.opensdk:wechat-sdk-android-without-mta:5.1.4',
flexbox : 'com.google.android:flexbox:1.0.0',
countdownview : 'com.github.iwgang:countdownview:2.1.6',
okio : 'com.squareup.okio:okio:1.13.0',
retrofit : 'com.squareup.retrofit2:retrofit:2.2.0',
eventbus : 'org.greenrobot:eventbus:3.0.0',
lottie : 'com.airbnb.android:lottie:2.3.1',
walle : 'com.meituan.android.walle:library:1.1.6'
]
}

View File

@ -961,7 +961,8 @@ public class ToolPicture extends ToolBase {
cv.drawBitmap(markBMP, srcBMP.getWidth() - markBMP.getWidth() + 5,
srcBMP.getHeight() - markBMP.getHeight() + 5, null);
// 保存
cv.save(Canvas.ALL_SAVE_FLAG);
// cv.save(Canvas.ALL_SAVE_FLAG);
cv.save();
// 存储
cv.restore();
@ -1129,7 +1130,8 @@ public class ToolPicture extends ToolBase {
drawLine(c, paint);
}
// 保存
c.save(Canvas.ALL_SAVE_FLAG);
// c.save(Canvas.ALL_SAVE_FLAG);
c.save();
c.restore();
return bp;