commit 5d3c349889763c233fd24cc6ae7e98adb7578f9a Author: 雷云 Date: Wed Jul 15 17:38:05 2020 +0800 first commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..603b140 --- /dev/null +++ b/.gitignore @@ -0,0 +1,14 @@ +*.iml +.gradle +/local.properties +/.idea/caches +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +/.idea/navEditor.xml +/.idea/assetWizardSettings.xml +.DS_Store +/build +/captures +.externalNativeBuild +.cxx diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml new file mode 100644 index 0000000..88ea3aa --- /dev/null +++ b/.idea/codeStyles/Project.xml @@ -0,0 +1,122 @@ + + + + + + + + + +
+ + + + xmlns:android + + ^$ + + + +
+
+ + + + xmlns:.* + + ^$ + + + BY_NAME + +
+
+ + + + .*:id + + http://schemas.android.com/apk/res/android + + + +
+
+ + + + .*:name + + http://schemas.android.com/apk/res/android + + + +
+
+ + + + name + + ^$ + + + +
+
+ + + + style + + ^$ + + + +
+
+ + + + .* + + ^$ + + + BY_NAME + +
+
+ + + + .* + + http://schemas.android.com/apk/res/android + + + ANDROID_ATTRIBUTE_ORDER + +
+
+ + + + .* + + .* + + + BY_NAME + +
+
+
+
+ + +
+
\ No newline at end of file diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml new file mode 100644 index 0000000..79ee123 --- /dev/null +++ b/.idea/codeStyles/codeStyleConfig.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 0000000..e04498a --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,21 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..2c5b9b7 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,7 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..37a7509 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,9 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/render.experimental.xml b/.idea/render.experimental.xml new file mode 100644 index 0000000..8ec256a --- /dev/null +++ b/.idea/render.experimental.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml new file mode 100644 index 0000000..7f68460 --- /dev/null +++ b/.idea/runConfigurations.xml @@ -0,0 +1,12 @@ + + + + + + \ No newline at end of file diff --git a/README.MD b/README.MD new file mode 100644 index 0000000..5fe60c7 --- /dev/null +++ b/README.MD @@ -0,0 +1,3 @@ +### 电子书项目 + +#### 开发工具 AndroidStudio \ No newline at end of file diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/app/.gitignore @@ -0,0 +1 @@ +/build diff --git a/app/build.gradle b/app/build.gradle new file mode 100644 index 0000000..3691e08 --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,80 @@ +apply plugin: 'com.android.application' + +apply plugin: 'kotlin-android' + +apply plugin: 'kotlin-android-extensions' + +android { + compileSdkVersion 29 + buildToolsVersion "29.0.3" + defaultConfig { + applicationId "com.yzx.webebook" + minSdkVersion 26 + targetSdkVersion 29 + versionCode 1 + versionName "1.0" + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + } + signingConfigs { + yzx { + keyAlias ALIAS_NAME + keyPassword ALIAS_PWD + storeFile file(KEY_PATH) + storePassword KEY_PWD + v2SigningEnabled false + } + } + buildTypes { + release { + minifyEnabled true + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + zipAlignEnabled true + debuggable false + signingConfig signingConfigs.yzx + // 移除无用的resource文件 + shrinkResources true + } + + debug { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + debuggable true + signingConfig signingConfigs.yzx + // 移除无用的resource文件 + shrinkResources false + } + + applicationVariants.all { variant -> + variant.outputs.all { output -> + def fileName + fileName = "Yzx_${variant.versionName}.apk" + output.outputFileName = fileName + } + } + } +} + +dependencies { + implementation fileTree(dir: 'libs', include: ['*.jar']) + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" + implementation "org.jetbrains.anko:anko:$anko_version" + // 基础依赖包,必须要依赖 + implementation 'com.gyf.immersionbar:immersionbar:3.0.0' + // fragment快速实现(可选) + implementation 'com.gyf.immersionbar:immersionbar-components:3.0.0' + // kotlin扩展(可选) + implementation 'com.gyf.immersionbar:immersionbar-ktx:3.0.0' + implementation 'androidx.appcompat:appcompat:1.1.0' + implementation 'com.google.android.material:material:1.1.0' + implementation 'androidx.core:core-ktx:1.2.0' + implementation 'androidx.constraintlayout:constraintlayout:1.1.3' + testImplementation 'junit:junit:4.12' + androidTestImplementation 'androidx.test.ext:junit:1.1.0' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1' + implementation files('libs/wenote.jar') + implementation 'com.github.bumptech.glide:glide:4.11.0' + implementation 'com.lzy.net:okgo:3.0.4' + annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0' + + +} diff --git a/app/libs/wenote.jar b/app/libs/wenote.jar new file mode 100644 index 0000000..527a621 Binary files /dev/null and b/app/libs/wenote.jar differ diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 0000000..f1b4245 --- /dev/null +++ b/app/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# 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 *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile diff --git a/app/src/androidTest/java/com/yzx/webebook/ExampleInstrumentedTest.kt b/app/src/androidTest/java/com/yzx/webebook/ExampleInstrumentedTest.kt new file mode 100644 index 0000000..b594d48 --- /dev/null +++ b/app/src/androidTest/java/com/yzx/webebook/ExampleInstrumentedTest.kt @@ -0,0 +1,24 @@ +package com.yzx.webebook + +import androidx.test.platform.app.InstrumentationRegistry +import androidx.test.ext.junit.runners.AndroidJUnit4 + +import org.junit.Test +import org.junit.runner.RunWith + +import org.junit.Assert.* + +/** + * Instrumented test, which will execute on an Android device. + * + * See [testing documentation](http://d.android.com/tools/testing). + */ +@RunWith(AndroidJUnit4::class) +class ExampleInstrumentedTest { + @Test + fun useAppContext() { + // Context of the app under test. + val appContext = InstrumentationRegistry.getInstrumentation().targetContext + assertEquals("com.yzx.webebook", appContext.packageName) + } +} diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..956f110 --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/yzx/webebook/App.kt b/app/src/main/java/com/yzx/webebook/App.kt new file mode 100644 index 0000000..f6a8e2a --- /dev/null +++ b/app/src/main/java/com/yzx/webebook/App.kt @@ -0,0 +1,12 @@ +package com.yzx.webebook + +import android.app.Application +import com.lzy.okgo.OkGo + +class App: Application() { + + override fun onCreate() { + super.onCreate() + OkGo.getInstance().init(this) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/yzx/webebook/MainActivity.kt b/app/src/main/java/com/yzx/webebook/MainActivity.kt new file mode 100644 index 0000000..db09631 --- /dev/null +++ b/app/src/main/java/com/yzx/webebook/MainActivity.kt @@ -0,0 +1,90 @@ +package com.yzx.webebook + +import android.annotation.SuppressLint +import android.app.Activity +import android.content.Intent +import com.bumptech.glide.Glide +import com.yzx.webebook.activity.BookActivity +import com.yzx.webebook.activity.WebActivity +import com.yzx.webebook.activity.base.BaseActivity +import com.yzx.webebook.presenter.base.BasePresenter +import kotlinx.android.synthetic.main.activity_main.* +import java.io.File + +/** + * Yun.Lei + * 2020年5月6日14:49:10 + */ +class MainActivity : BaseActivity>() { + + + override val inflateId: Int + get() = R.layout.activity_main + + + override fun initView() { + btn1.setOnClickListener { + WebActivity.active(this, "https://m.qbjjyyun.net/") + } + btn2.setOnClickListener { + WebActivity.active(this, "https://m.live.educlouddata.com/") + } + btn6.setOnClickListener { + WebActivity.active(this, "http://192.168.69.200:8098/") + } + btn3.setOnClickListener { + WebActivity.active(this, editText.text.toString()) + } + btn4.setOnClickListener { + BookActivity.active(this,"教育云空间","f04be754f6cb3f6168f582403a514c39","filec","",1,1) + } + btn5.setOnClickListener { + BookActivity.active(this,"教育云空间(无图)","","","",2,2) + } + + /*OkGo.post("https://fileupload.oa.qbjjyyun.net/edufile/fileUpload") + .tag(this) + .params("token","0fc58a8df03c46d3f85b1047c4693cf6") + .params("user","97244") + .params("file",file) + .execute(object : StringCallback(){ + override fun onError(response: Response?) { + super.onError(response) + Log.d("onError",response?.body()) + } + + override fun onSuccess(response: Response?) { + val json = response?.body() + Log.d("onSuccess",response?.body()) + val jsonObject = JSONObject(json) + val content = jsonObject.optString("content") + Log.d("onSuccess,content",content) + val contentObject = JSONObject(content) + val key = contentObject.optString("key") + val identity = contentObject.optString("identity") + Log.d("onSuccess,identity",identity) + Log.d("onSuccess,key",key) + } + })*/ + + } + + override fun initData() { + } + + override fun initPresenter(): BasePresenter<*>? = null + + @SuppressLint("SetTextI18n") + override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { + super.onActivityResult(requestCode, resultCode, data) + if(requestCode==BookActivity.REQ_CODE&&resultCode== Activity.RESULT_OK){ + val mKey = data?.getStringExtra("key") + val mIdentity = data?.getStringExtra("identity") + + val url = "https://$mIdentity.oa.qbjjyyun.net/edufile/imageView?uniqueKey=$mKey" + Glide.with(this) + .load(url) + .into(testImageView) + } + } +} diff --git a/app/src/main/java/com/yzx/webebook/activity/BookActivity.java b/app/src/main/java/com/yzx/webebook/activity/BookActivity.java new file mode 100644 index 0000000..b9ae595 --- /dev/null +++ b/app/src/main/java/com/yzx/webebook/activity/BookActivity.java @@ -0,0 +1,1060 @@ +package com.yzx.webebook.activity; + +import android.Manifest; +import android.app.Activity; +import android.app.AlertDialog; +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.DialogInterface; +import android.content.Intent; +import android.content.IntentFilter; +import android.content.pm.ActivityInfo; +import android.content.pm.PackageManager; +import android.graphics.Bitmap; +import android.graphics.Canvas; +import android.graphics.PixelFormat; +import android.graphics.Rect; +import android.graphics.drawable.Drawable; +import android.os.Bundle; +import android.os.Handler; +import android.os.Message; +import android.text.TextUtils; +import android.util.DisplayMetrics; +import android.util.Log; +import android.view.KeyEvent; +import android.view.View; +import android.view.Window; +import android.widget.Button; +import android.widget.CheckBox; +import android.widget.TextView; +import android.widget.Toast; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + +import com.bumptech.glide.Glide; +import com.bumptech.glide.load.engine.DiskCacheStrategy; +import com.bumptech.glide.request.target.CustomTarget; +import com.bumptech.glide.request.target.Target; +import com.bumptech.glide.request.transition.Transition; +import com.lzy.okgo.OkGo; +import com.lzy.okgo.callback.StringCallback; +import com.lzy.okgo.model.Response; +import com.wetao.note.NotePageInfo; +import com.wetao.note.WeNoteView; +import com.wetao.note.WePoint; +import com.yzx.webebook.R; + +import org.json.JSONObject; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Date; + + +public class BookActivity extends Activity { + private static final String TAG = "BookActivity"; + public static final int REQ_CODE = 0x99; + + private static final String BACKGROUND1_PATH = "/mnt/sdcard/test.png"; + private static final String BACKGROUND2_PATH = "/mnt/sdcard/net.png"; + private static final String SAVE_PIC_PATH = "/mnt/sdcard/Note01.png"; + + private static final String NOTE_FOLDER_DIR = "/mnt/sdcard/ebook/"; + private static final String NOTE_FILE_NAME = "note.png"; + private static final String DRAWABLE_FILE_NAME = ".drawable.txt"; + + static final int[] mBGDrawableList = {R.drawable.background0, R.drawable.background1, R.drawable.background2, + R.drawable.background3, R.drawable.background4, R.drawable.background5, R.drawable.background6, + R.drawable.background7, R.drawable.background8, R.drawable.background9, R.drawable.background10}; + + String SCREEN_ON = "android.intent.action.SCREEN_ON"; + String SCREEN_OFF = "android.intent.action.SCREEN_OFF"; + + private static final int MSG_SAVE_END = 2001; + private int imageIndex = 0; + + private static Context mContext; + private static Handler mHandler; + + private WeNoteView mView; + + + private TextView mLeftView; + private TextView mRightView; + private TextView btnSave; + private TextView mTotalTv; + private TextView mIndexTv; + private Button mDeleteBtn; + private Button mPicBtn; + private Button mClearBtn; + private Button mUndoBtn; + private Button mRedoBtn; + private Button mPenWidthBtn; + private Button mPenWidthSubBtn; + private Button mEraserWidthBtn; + private Button mCancelBtn; + private CheckBox mCBEraser; + private CheckBox mCBStrokes; + + private static int mScreenH; + private static int mScreenW; + + //private boolean mPage = false; + private static int mBGId = 0; + private Drawable mBGDrawable = null; + + private boolean mReDrawEnable = false; + + private static ArrayList mWePointList = null; + + private static NotePageInfo mNotePageInfo = null; + + private Runnable mRunnable = new Runnable() { + public void run() { + int count = 0; + while (mView.getHeight() <= 0) { + try { + Thread.sleep(50); + } catch (InterruptedException e) { + e.printStackTrace(); + } + if (count++ > 40) { + Log.d(TAG, "Flash test : ++++++++ removeCallbacks"); + mHandler.removeCallbacks(mRunnable); + System.exit(0); + } + + } + Log.d(TAG, "Flash test : ++++++++ mView.getHeight() = " + mView.getHeight() + ", count = " + count); + //mView.initNative(new Rect(mScreenW, mScreenH - mView.getHeight(), 0, mScreenH), SAVE_PIC_PATH); + mView.initNative(new Rect(mScreenW, mScreenH - mView.getHeight(), 0, mScreenH)); + mView.setTouchEventHander(mPointHandler); + + Log.d(TAG, "Flash test : ++++++ mRunnable() start loader notepageinfo"); + if (mNotePageInfo == null) { + mNotePageInfo = getNotePageInfo(NOTE_FOLDER_DIR); + } + if (mNotePageInfo == null) { + Log.d(TAG, "Flash test : +++++ no note, so init a page"); + initPage(); + } + initNoteView(); + if (!TextUtils.isEmpty(mKey) && !TextUtils.isEmpty(mIdentity)) { //没有传递突变则加载空页面 + loadImage(); + } else { + loadOldPage(); + } + } + }; + + private static String[] imgList = new String[]{}; + + public static void active(Activity activity, String title, String key, String identity, String name, int index, int type) { + Intent intent = new Intent(activity, BookActivity.class); + intent.putExtra("title", title); + intent.putExtra("key", key); + intent.putExtra("identity", identity); + intent.putExtra("name", name); + intent.putExtra("index", index); + intent.putExtra("type", type); + activity.startActivityForResult(intent, REQ_CODE); + } + + private String mTitle; + private String mKey; + private String mIdentity; + private String mName; + private int mIndex; + private int mType; + + private AlertDialog loadingDialog; + + private void getIntentInfo() { + Intent intent = getIntent(); + mTitle = intent.getStringExtra("title"); + mKey = intent.getStringExtra("key"); + mIdentity = intent.getStringExtra("identity"); + mName = intent.getStringExtra("name"); + mIndex = intent.getIntExtra("index", 0); + mType = intent.getIntExtra("type", 1); + if (!TextUtils.isEmpty(mKey) && !TextUtils.isEmpty(mIdentity)) { + imgList = new String[]{"https://" + mIdentity + ".oa.qbjjyyun.net/edufile/imageView?uniqueKey=" + mKey}; + } else { + + } + } + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + requestWindowFeature(Window.FEATURE_NO_TITLE); + setContentView(R.layout.activity_book); + checkPermission(); + Log.d(TAG, "Flash test : +++++++ onCreate()"); + mContext = BookActivity.this; + + setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); + getIntentInfo(); + mView = (WeNoteView) findViewById(R.id.note_view); + // mView.setBackground(Drawable.createFromPath(BACKGROUND1_PATH)); + mView.setBackground(null); + mBGId = 0; + + mDeleteBtn = (Button) findViewById(R.id.delete); + mDeleteBtn.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + if (deleteNote()) { + cancel(false); + BookActivity.this.finish(); + } + } + }); + + mPicBtn = (Button) findViewById(R.id.init); + mPicBtn.setText("背景" + mBGId); + mPicBtn.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + //mView.clear(); + mView.setEnable(false); + mBGId++; + if (mBGId >= mBGDrawableList.length) mBGId = 0; + mView.updateBackground(mBGDrawableList[mBGId]); + mPicBtn.setText("背景" + mBGId); + saveBGId(); + } + }); + + mClearBtn = (Button) findViewById(R.id.clear); + mClearBtn.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + mView.clear(); + } + }); + + mPenWidthBtn = (Button) findViewById(R.id.pen_width); + mPenWidthBtn.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + int width = mView.getPenWidth(); + if (width == 10) { + width = 1; + } else { + width++; + } + + if (width > 0 && width <= 10) { + mView.setPenWidth(width); + mPenWidthBtn.setText("+宽度" + width); + mPenWidthSubBtn.setText("-宽度" + width); + } + } + }); + mPenWidthSubBtn = (Button) findViewById(R.id.pen_width_sub); + mPenWidthSubBtn.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + int width = mView.getPenWidth(); + if (width == 1) { + width = 10; + } else { + width--; + } + + if (width > 0 && width <= 10) { + mView.setPenWidth(width); + mPenWidthBtn.setText("+宽度" + width); + mPenWidthSubBtn.setText("-宽度" + width); + } + } + }); + + mUndoBtn = (Button) findViewById(R.id.undo); + mUndoBtn.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + mView.unDo(); + } + }); + + mRedoBtn = (Button) findViewById(R.id.redo); + mRedoBtn.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + mView.reDo(); + } + }); + + mEraserWidthBtn = (Button) findViewById(R.id.eraser_width); + mEraserWidthBtn.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + int width = mView.getEraserWidth(); + if (width == 20) { + width = 1; + } else { + width++; + } + + if (width > 0 && width <= 20) { + mView.setEraserWidth(width); + mEraserWidthBtn.setText("橡皮宽" + width); + } + } + }); + + mCancelBtn = (Button) findViewById(R.id.cancel); + mCancelBtn.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + cancel(true); + BookActivity.this.finish(); + } + }); + + mCBEraser = (CheckBox) findViewById(R.id.eraser); + mCBEraser.setSelected(false); + mCBEraser.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + if (mView.isEraserEnable()) { + mCBEraser.setSelected(false); + mView.setEraserEnable(false); + } else { + mCBEraser.setSelected(true); + mView.setEraserEnable(true); + } + } + }); + //mCBEraser.setVisibility(View.GONE); + + mCBStrokes = (CheckBox) findViewById(R.id.strokes); + mCBStrokes.setSelected(false); + mCBStrokes.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + if (mView.isStrokesEnable()) { + mCBStrokes.setSelected(false); + mView.setStrokesEnable(false); + } else { + mCBStrokes.setSelected(true); + mView.setStrokesEnable(true); + } + } + }); + + mWePointList = new ArrayList(); + mWePointList.clear(); + + DisplayMetrics metrics = new DisplayMetrics(); + metrics = getApplicationContext().getResources().getDisplayMetrics(); + mScreenW = metrics.widthPixels; + mScreenH = metrics.heightPixels; + + mHandler = new Handler(); +// mHandler.postDelayed(mRunnable, 1000); + + + mView.post(new Runnable() { + @Override + public void run() { + mHandler.post(mRunnable); + } + }); + + IntentFilter filter = new IntentFilter(); + filter.addAction(SCREEN_ON); + filter.addAction(SCREEN_OFF); + mContext.registerReceiver(mReceiver, filter); + + initTabBar(); + } + + private void initNoteView() { + //宽度 + mView.setPenWidth(5); + mPenWidthBtn.setText("+宽度5"); + mPenWidthSubBtn.setText("-宽度5"); + //橡皮擦 + mCBEraser.setSelected(false); + mView.setEraserEnable(false); + //笔锋 + mCBStrokes.setSelected(false); + mView.setStrokesEnable(false); + //橡皮擦 + mView.setEraserWidth(20); + mEraserWidthBtn.setText("橡皮宽20"); + } + + private void initTabBar() { + findViewById(R.id.btnBack).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + onBackPressed(); + } + }); + TextView titleTv = findViewById(R.id.titleTv); + titleTv.setText(mTitle); + mLeftView = findViewById(R.id.btnPre); + mRightView = findViewById(R.id.btnNext); + mIndexTv = findViewById(R.id.tvIndex); + mTotalTv = findViewById(R.id.tvTotal); + btnSave = findViewById(R.id.save); + mLeftView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (imageIndex == 0) { + return; + } + pre(); + } + }); + mRightView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (imageIndex == imgList.length - 1) { + return; + } + next(); + } + }); + btnSave.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (mView.isHandwritingExist()) { + save(); + } else { + toast("暂无可保存的内容!"); + } + } + }); + + if (mType == 2) { + mPicBtn.setVisibility(View.VISIBLE); + } else { + mPicBtn.setVisibility(View.GONE); + } + + } + + private void showDialog(String msg) { + AlertDialog.Builder builder = new AlertDialog.Builder(this); + builder.setMessage(msg); + builder.setCancelable(false); + loadingDialog = builder.create(); + if (loadingDialog != null) { + loadingDialog.setCanceledOnTouchOutside(false); + loadingDialog.show(); + } + } + + private void dismissDialog() { + if (loadingDialog != null) { + loadingDialog.dismiss(); + } + } + + private void save() { + mView.post(new Runnable() { + @Override + public void run() { + showDialog("保存中..."); + } + }); + + String noteName = mKey + ".png"; + if (mKey.length() == 0) { + noteName = "note.png"; + mBGDrawable = getDrawable(mBGDrawableList[mBGId]); + } + String path = NOTE_FOLDER_DIR + "/" + noteName; + boolean success = saveAll(path, mView.getCurrentNoteBitmap(), mBGDrawable); + if (success) { + OkGo.post("https://fileupload.oa.qbjjyyun.net/edufile/fileUpload") + .tag(this) + .params("token", "0fc58a8df03c46d3f85b1047c4693cf6") + .params("user", new Date().getTime()) + .params("file", new File(path)) + .execute(new StringCallback() { + @Override + public void onSuccess(Response response) { + try { + String json = response.body(); + Log.d("onSuccess", response.body()); + JSONObject jsonObject = new JSONObject(json); + String content = jsonObject.optString("content"); + Log.d("onSuccess,content", content); + JSONObject contentObject = new JSONObject(content); + String key = contentObject.optString("key"); + String identity = contentObject.optString("identity"); + Log.d("onSuccess,identity", identity); + Log.d("onSuccess,key", key); + + toast("保存成功!"); + Intent intent = new Intent(); + intent.putExtra("key", key); + intent.putExtra("identity", identity); + intent.putExtra("name", mName); + intent.putExtra("index", mIndex); + intent.putExtra("type", mType); + setResult(Activity.RESULT_OK, intent); + finish(); + } catch (Exception e) { + + } + } + + @Override + public void onError(Response response) { + super.onError(response); + toast("保存失败!"); + } + + @Override + public void onFinish() { + super.onFinish(); + dismissDialog(); + } + }); + } else { + toast("保存失败!"); + } + } + + private void pre() { + AlertDialog.Builder builder = new AlertDialog.Builder(this); + builder.setMessage("是否保存当前页面内容?"); + builder.setPositiveButton("保存", new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { +// boolean success = mView.savePicture(NOTE_FOLDER_DIR+"/"+imgList[imageIndex]+".png",true); + String noteName = "note2.png"; + String path = NOTE_FOLDER_DIR + "/" + noteName; + boolean success = saveAll(path, mView.getCurrentNoteBitmap(), mBGDrawable); + if (success) { + toast("保存成功!"); + } else { + toast("保存失败!"); + } + imageIndex--; + loadImage(); + mIndexTv.setText(String.valueOf(imageIndex + 1)); + } + }); + builder.setNegativeButton("不保存", new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + imageIndex--; + loadImage(); + mIndexTv.setText(String.valueOf(imageIndex + 1)); + } + }); + builder.show(); + } + + private void next() { + AlertDialog.Builder builder = new AlertDialog.Builder(this); + builder.setMessage("是否保存当前页面内容?"); + builder.setPositiveButton("保存", new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { +// boolean success = mView.savePicture(NOTE_FOLDER_DIR+"/"+imgList[imageIndex]+".png",true); + String noteName = "note1.png"; + String path = NOTE_FOLDER_DIR + "/" + noteName; + boolean success = saveAll(path, mView.getCurrentNoteBitmap(), mBGDrawable); + if (success) { + toast("保存成功!"); + } else { + toast("保存失败!"); + } + imageIndex++; + loadImage(); + mIndexTv.setText(String.valueOf(imageIndex + 1)); + } + }); + builder.setNegativeButton("不保存", new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + imageIndex++; + loadImage(); + mIndexTv.setText(String.valueOf(imageIndex + 1)); + } + }); + builder.show(); + } + + private void loadImage() { + showDialog("加载中..."); + CustomTarget customTarget = new CustomTarget() { + @Override + public void onResourceReady(@NonNull Drawable resource, @Nullable Transition transition) { + loadOldPage(); + mView.setBackground(resource); + mBGDrawable = resource; + dismissDialog(); + } + + @Override + public void onLoadCleared(@Nullable Drawable placeholder) { + + } + + @Override + public void onLoadFailed(@Nullable Drawable errorDrawable) { + super.onLoadFailed(errorDrawable); + dismissDialog(); + toast(mTitle + "加载失败!"); + } + }; + Glide.with(this) + .load(imgList[imageIndex]) + .diskCacheStrategy(DiskCacheStrategy.ALL) + .override(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL) + .into(customTarget); + } + + private void toast(String msg) { + Toast.makeText(this, msg, Toast.LENGTH_LONG).show(); + } + + private void loadOldPage() { + if (mNotePageInfo == null) { + return; + } + Log.d(TAG, "Flash test : +++++ loadOldPage() mNotePageInfo = " + mNotePageInfo); + mBGId = mNotePageInfo.drwId; + mView.showExistPage(mNotePageInfo.notePath, mBGDrawableList[mBGId]); + mPicBtn.setText("背景" + mBGId); + } + + public void onResume() { + Log.d(TAG, "Flash test : +++++++ onResume()"); + mView.setEnable(true); + mView.setSleepMode(true); + mReDrawEnable = true; + super.onResume(); + } + + public void onPause() { + Log.d(TAG, "Flash test : +++++++ onPause()"); + mView.setEnable(false); + mReDrawEnable = false; + super.onPause(); + } + + public void onDestroy() { + Log.d(TAG, "Flash test : +++++++ onDestroy()"); + //mView.exitView(); + mHandler.removeCallbacks(mRunnable); + mView.exitNative(); + if (mReceiver != null) { + mContext.unregisterReceiver(mReceiver); + mReceiver = null; + } + super.onDestroy(); + } + + private static Handler mPointHandler = new Handler() { + @Override + public void handleMessage(Message msg) { + int what = msg.what; + //同步获取的笔记点坐标信息msg + if (what == WeNoteView.TOUCH_EVENT) { + WePoint point = (WePoint) msg.obj; + Log.d(TAG, "Flash test : ++++++++ mPointHandler WePoint = " + point); + mWePointList.add(point); + } + + //保存笔记结束msg + if (what == MSG_SAVE_END) { + int status = msg.arg1; + if (status > 0) { //保存成功 + Log.d(TAG, "Flash test : ++++++++ mPointHandler page save ok"); + //Toast.makeText(mContext, "Note saved OK", Toast.LENGTH_SHORT).show(); + } else { //保存失败 + Log.d(TAG, "Flash test : ++++++++ mPointHandler page save failed"); + //Toast.makeText(mContext, "Note saved Fail", Toast.LENGTH_SHORT).show(); + } + } + } + }; + + private void cancel(boolean save) { + mView.exitNativeOnly(); + if (save && mView.isHandwritingExist()) { + saveNote(); + } + mView.exit(); + BookActivity.this.finish(); + } + + private static boolean initPage() { + Log.d(TAG, "Flash test : +++++++++ intPage()"); + File file = new File(NOTE_FOLDER_DIR); + if (!file.exists()) { + Log.e(TAG, "Flash test : +++++++++ addPageFolder() no folder path = " + NOTE_FOLDER_DIR); + if (!makeDir(file)) { + return false; + } + } + + String notePath = null; + file = new File(NOTE_FOLDER_DIR + "/note.png"); + if (file.exists()) { + notePath = NOTE_FOLDER_DIR + "/note.png"; + } + file = new File(NOTE_FOLDER_DIR + "/.drawable.txt"); + if (!file.exists()) { + try { + file.createNewFile(); + } catch (IOException e) { + e.printStackTrace(); + return false; + } + } + saveBGId(); + mNotePageInfo = new NotePageInfo(notePath, mBGId); + return true; + } + + private boolean deleteNote() { + Log.d(TAG, "Flash test : +++++++++ deletdNote()"); + File file = new File(NOTE_FOLDER_DIR); + if (!file.exists()) { + Log.e(TAG, "Flash test : +++++++++ deletdPageFolder() no folder path = " + NOTE_FOLDER_DIR); + return true; + } + deleteDirWithFile(file); + return true; + } + + @Override + protected void onStart() { + File f = new File(NOTE_FOLDER_DIR + "/" + "note.png"); + if (f.exists()) { + f.delete(); + } + super.onStart(); + } + + private boolean saveNote() { + Log.d(TAG, "Flash test : ++++++++ saveNote()"); + File f = new File(NOTE_FOLDER_DIR); + if (!f.exists()) { + Log.d(TAG, "Flash test : +++++++ saveNote() create folder " + NOTE_FOLDER_DIR); + if (!makeDir(f)) { + return false; + } + } + + String noteName = "note.png"; + final Bitmap bmp = Bitmap.createBitmap(mView.getCurrentNoteBitmap()); + if (bmp == null) { + Log.e(TAG, "Flash test : ++++ saveNote() getCurrentNoteBitmap is null"); + return false; + } + + String path = NOTE_FOLDER_DIR + "/" + noteName; + if (!saveNoteWithoutBG(path, bmp)) { + Log.e(TAG, "Flash test : ++++ saveNote() saveNoteWithoutBG fail"); + freeBitmap(bmp); + return false; + } + + saveBGId(); + freeBitmap(bmp); + Log.e(TAG, "Flash test : ++++ saveNote() OK !!!!!"); + return true; + } + + private static boolean saveBGId() { + Log.d(TAG, "Flash test : ++++++++ saveBGId drwId = " + mBGId); + File f = new File(NOTE_FOLDER_DIR); + if (!f.exists()) { + Log.d(TAG, "Flash test : +++++++ saveAllNote() create folder " + NOTE_FOLDER_DIR); + if (!makeDir(f)) { + return false; + } + } + + String path = NOTE_FOLDER_DIR + "/.drawable.txt"; + writeFileData(path, String.valueOf(mBGId)); + return true; + } + + private static void freeBitmap(Bitmap bit) { + if (bit != null && !bit.isRecycled()) { + bit.recycle(); + } + } + + //保存不带背景的笔记为png + private boolean saveNoteWithoutBG(String picPath, Bitmap bmp) { + Log.d(TAG, "Flash test : +++++++ saveNoteWithoutBG() picPath = " + picPath); + File f = new File(picPath); + if (f.exists()) { + f.delete(); + } + FileOutputStream fos = null; + try { + fos = new FileOutputStream(f); + bmp.compress(Bitmap.CompressFormat.PNG, 90, fos); + try { + fos.flush(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + try { + fos.close(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } catch (FileNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return true; + } + + //保存带背景的笔记为png + private boolean saveAll(String picPath, Bitmap bmp, Drawable drw) { + Log.d(TAG, "Flash test : ++++ saveAll() picPath = " + picPath); + int width = bmp.getWidth(); + int height = bmp.getHeight(); + + Bitmap bitmap = Bitmap.createBitmap(width, height, + drw.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565); + Canvas canvas = new Canvas(bitmap); + drw.setBounds(0, 0, width, height); + drw.draw(canvas); + + canvas.drawBitmap(bmp, new Rect(0, 0, width, height), + new Rect(0, 0, width, height), null); + canvas.save();//Canvas.ALL_SAVE_FLAG); + canvas.restore(); + + boolean result = saveNoteWithoutBG(picPath, bitmap); + if (bitmap != null && !bitmap.isRecycled()) { + bitmap.recycle(); + bitmap = null; + } + System.gc(); + return result; + } + + //保存笔记背景为png + private boolean saveNoteBG(String picPath, Drawable drw, int width, int height) { + Log.d(TAG, "Flash test : ++++ saveNoteBG() picPath = " + picPath); + Bitmap bitmap = Bitmap.createBitmap(width, height, + drw.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565); + Canvas canvas = new Canvas(bitmap); + drw.setBounds(0, 0, width, height); + drw.draw(canvas); + + boolean result = saveNoteWithoutBG(picPath, bitmap); + if (bitmap != null && !bitmap.isRecycled()) { + bitmap.recycle(); + bitmap = null; + } + System.gc(); + return result; + } + + //重绘之前绘制的画笔 + private void drawWePointList() { + if (mView.isReDrawDoing()) { + Log.i(TAG, "Flash test : +++++ drawWePointList() return because isReDrawDoing is true"); + return; + } + if (mWePointList != null && !mWePointList.isEmpty()) { + new Thread(new Runnable() { + @Override + public void run() { + mView.setReDrawEnable(true); + mReDrawEnable = true; + int size = mWePointList.size(); + int i = 0; + while (i < size) { + while (!mReDrawEnable) { + try { + Thread.sleep(100); + } catch (InterruptedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + WePoint wp = mWePointList.get(i); + mView.drawPoint(wp); + try { + if (i + 1 < size) + Thread.sleep(mWePointList.get(i + 1).eventTime - wp.eventTime); + } catch (InterruptedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + i++; + } + mView.setReDrawEnable(false); + } + }).start(); + } + } + + @Override + public boolean onKeyDown(int keyCode, KeyEvent event) { + if (keyCode == KeyEvent.KEYCODE_BACK) { + //to-do + mView.exitNative(); + if (mReceiver != null) { + mContext.unregisterReceiver(mReceiver); + mReceiver = null; + } + BookActivity.this.finish(); + return true; + } + return super.onKeyDown(keyCode, event); + } + + //从笔记文件夹中读取当前笔记的页面信息 + private static NotePageInfo getNotePageInfo(String path) { + Log.d(TAG, "Flash test : +++++++++ getNotePageInfo() path = " + path); + File file = new File(path); + if (!file.exists()) { + Log.e(TAG, "Flash test : +++++++++ getNotePageInfo() no folder path = " + path); + return null; + } + File[] files = file.listFiles(); + if (files == null) { + Log.e(TAG, "Flash test : +++++++++ getNotePageInfo() no files in this Note folder = " + path); + return null; + } + NotePageInfo info = new NotePageInfo(null, 0); + String notePath = path + "/note.png"; + file = new File(notePath); + if (file.exists()) { + info.notePath = notePath; + } + //String drwId = readFileData(path + "/.drawable.txt"); + info.drwId = 0; //Integer.parseInt(drwId); + return info; + } + + private void checkPermission() { + boolean isGranted = true; + if (android.os.Build.VERSION.SDK_INT >= 23) { + if (this.checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { + //如果没有写sd卡权限 + isGranted = false; + } + if (this.checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { + isGranted = false; + } + Log.i("cbs", "isGranted == " + isGranted); + if (!isGranted) { + this.requestPermissions( + new String[]{Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission + .ACCESS_FINE_LOCATION, + Manifest.permission.READ_EXTERNAL_STORAGE, + Manifest.permission.WRITE_EXTERNAL_STORAGE}, + 102); + } + } + } + + private BroadcastReceiver mReceiver = new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + // 屏幕唤醒 + if (SCREEN_ON.equals(intent.getAction())) { + Log.e(TAG, "Flash test : ++++++ " + SCREEN_ON); + /*if (mDialog != null && mDialog.isShowing()) { + mView.setEnable(false); + }*/ + mView.setSleepMode(true); + } + // 屏幕休眠 + else if (SCREEN_OFF.equals(intent.getAction())) { + Log.e(TAG, "Flash test : ++++++ " + SCREEN_OFF); + mView.setSleepMode(true); + } + } + }; + + private static boolean makeDir(File folder) { + try { + //按照指定的路径创建文件夹 + folder.mkdirs(); + } catch (Exception e) { + // TODO: handle exception + Log.e(TAG, "Flash test : +++++ makeDir() create dir " + folder.getPath() + " error = " + e); + return false; + } + Log.d(TAG, "Flash test : +++++ makeDir() create dir " + folder.getPath()); + return true; + } + + private void deleteDirWithFile(File dir) { + if (dir == null || !dir.exists() || !dir.isDirectory()) + return; + for (File file : dir.listFiles()) { + if (file.isFile()) + file.delete(); // 删除所有文件 + else if (file.isDirectory()) + deleteDirWithFile(file); // 递规的方式删除文件夹 + } + dir.delete();// 删除目录本身 + } + + public static void writeFileData(String fileName, String content) { + File file = new File(fileName); + if (!file.exists()) { + try { + file.createNewFile(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + try { + BufferedWriter bw = new BufferedWriter(new FileWriter(file)); + bw.write(content); + bw.close(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + //打开指定文件,读取其数据,返回字符串对象 + public static String readFileData(String fileName) { + File file = new File(fileName); + if (!file.exists()) { + return "1"; + } + BufferedReader br; + try { + br = new BufferedReader(new FileReader(file)); + //System.out.println("br.readLine=" + br.readLine()); + return br.readLine(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return "1"; + } + +} + diff --git a/app/src/main/java/com/yzx/webebook/activity/WebActivity.kt b/app/src/main/java/com/yzx/webebook/activity/WebActivity.kt new file mode 100644 index 0000000..6594128 --- /dev/null +++ b/app/src/main/java/com/yzx/webebook/activity/WebActivity.kt @@ -0,0 +1,273 @@ +package com.yzx.webebook.activity + +import android.annotation.SuppressLint +import android.app.Activity +import android.app.AlertDialog +import android.content.Intent +import android.net.http.SslError +import android.os.Build +import android.text.TextUtils +import android.util.Log +import android.view.View +import android.view.ViewGroup +import android.webkit.* +import android.widget.LinearLayout +import androidx.annotation.RequiresApi +import com.yzx.webebook.R +import com.yzx.webebook.activity.base.BaseActivity +import com.yzx.webebook.presenter.base.BasePresenter +import kotlinx.android.synthetic.main.activity_web.* +import org.jetbrains.anko.ctx +import org.jetbrains.anko.startActivity +import org.jetbrains.anko.toast +import org.json.JSONObject + +/** + * 类名:WebActivity + * 作者:Yun.Lei + * 功能: + * 创建日期:2020年5月6日14:42:16 + * 修改人: + * 修改时间: + * 修改备注: + */ +class WebActivity : BaseActivity>() { + + + companion object { + fun active(act: Activity, link: String) { + act.startActivity("link" to link) + } + } + + private val webView: WebView by lazy { WebView(this) } + private var url: String = "" + override val inflateId: Int + get() = R.layout.activity_web + + @SuppressLint("SetJavaScriptEnabled") + override fun initView() { + url = intent?.getStringExtra("link") ?: "https://m.ykj.qbjjyyun.net/" + + btnBack.setOnClickListener { onBackPressed() } + btnClose.setOnClickListener { + finish() + } + btnRefresh.setOnClickListener { + webView.reload() + } + webView.layoutParams = LinearLayout.LayoutParams( + ViewGroup.LayoutParams.MATCH_PARENT, + ViewGroup.LayoutParams.MATCH_PARENT + ) + webLayout.addView(webView) + webView.addJavascriptInterface(YzxJavascriptInterface(this), "YZX") + val userAgent = webView.settings.userAgentString + webView.settings.apply { + allowFileAccess = true + javaScriptEnabled = true + loadWithOverviewMode = true + useWideViewPort = true + defaultTextEncodingName = "gb2312" + setAppCacheEnabled(true) + mediaPlaybackRequiresUserGesture = false + javaScriptCanOpenWindowsAutomatically = true + cacheMode = WebSettings.LOAD_DEFAULT + databaseEnabled = true + setRenderPriority(WebSettings.RenderPriority.HIGH) + blockNetworkImage = false + domStorageEnabled = true + setAppCacheMaxSize(1024 * 1024 * 8) + setAppCachePath(ctx.cacheDir.absolutePath) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + mixedContentMode = WebSettings.MIXED_CONTENT_ALWAYS_ALLOW + } + userAgentString = "$userAgent app/ebook" + } + webView.webViewClient = object : WebViewClient() { + @RequiresApi(Build.VERSION_CODES.LOLLIPOP) + override fun shouldOverrideUrlLoading( + view: WebView?, + request: WebResourceRequest? + ): Boolean { + view?.loadUrl(request?.url.toString()) + return super.shouldOverrideUrlLoading(view, request) + } + + // 即使加载失败后,webview执行完onReceivedError()方法也会执行这个方法 + override fun onPageFinished(view: WebView, url: String) { + super.onPageFinished(view, url) + webView.settings.blockNetworkImage = false + if (!TextUtils.isEmpty(view.title)) { + titleTv.text = view.title//webView获取到网页title + } + } + + override fun onReceivedSslError( + view: WebView, + handler: SslErrorHandler, + error: SslError + ) { + handler.proceed() + } + } + webView.webChromeClient = object : WebChromeClient() { + override fun onProgressChanged(view: WebView?, newProgress: Int) { + super.onProgressChanged(view, newProgress) + progressbar.progress = newProgress + if (newProgress >= 100) { + view?.post { + progressbar.visibility = View.GONE + if (view.canGoBack()) { + btnClose.visibility = View.VISIBLE + //btnBack.visibility = View.VISIBLE + } else { + btnClose.visibility = View.GONE + //btnBack.visibility = View.GONE + } + } + } else { + if (progressbar.visibility == View.GONE) { + view?.post { progressbar.visibility = View.VISIBLE } + } + } + } + + override fun onJsAlert( + view: WebView?, + url: String?, + message: String?, + result: JsResult? + ): Boolean { + val b = AlertDialog.Builder(this@WebActivity) + b.setTitle(message) + b.setPositiveButton("确定") { _, _ -> + result?.confirm() + } + return true + } + } + WebView.setWebContentsDebuggingEnabled(true) //将 WebViews 配置为可调试状态 + webView.setLayerType(View.LAYER_TYPE_HARDWARE, null) + } + + override fun initData() { + webView.loadUrl(url) + } + + override fun initPresenter(): BasePresenter<*>? { + return null + } + + override fun onResume() { + super.onResume() + webView.onResume() + } + + override fun onPause() { + super.onPause() + webView.onPause() + } + + override fun onBackPressed() { + if (webView.canGoBack()) { + webView.goBack() + } else { + super.onBackPressed() + } + } + + override fun onDestroy() { + super.onDestroy() + webView.apply { + webViewClient = null + webChromeClient = null + (parent as ViewGroup).removeView(webView) + removeAllViews() + destroy() + } + } + + /** + * 调用js方法 + */ + private fun evaluateJavascript(funName: String, data: String) { + webView.post { + webView.evaluateJavascript("javascript:$funName('$data')") { + Log.d("javascriptCallBack:", it) + //toast(it) + } + } + } + + @SuppressLint("SetTextI18n") + override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { + super.onActivityResult(requestCode, resultCode, data) + if (requestCode == BookActivity.REQ_CODE && resultCode == Activity.RESULT_OK) { + val mKey = data?.getStringExtra("key") ?: "" + val mIdentity = data?.getStringExtra("identity") ?: "" + val obj = JSONObject() + obj.put("key", mKey) + obj.put("identity", mIdentity) + obj.put("name", data?.getStringExtra("name") ?: "") + obj.put("index", data?.getIntExtra("index",0)) + obj.put("type", data?.getIntExtra("type",1)) + evaluateJavascript("onImageUploadSuccess", obj.toString()) + } + } + +} + + +class YzxJavascriptInterface(var ctx: Activity) { + + /** + * 获取电子书的clientId + */ + @JavascriptInterface + fun getClientId(): Int = 601 + + /** + * 跳转到电子书页面 + */ + @JavascriptInterface + fun bookPage( + title: String, + identity: String, + key: String, + name: String, + index: Int, + type: Int + ) { + BookActivity.active(ctx, title, key, identity,name,index,type) + } + + /** + * 提示 + */ + @JavascriptInterface + fun toast(msg: String) { + ctx.toast("android:$msg") + } + +} + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/java/com/yzx/webebook/activity/base/BaseActivity.kt b/app/src/main/java/com/yzx/webebook/activity/base/BaseActivity.kt new file mode 100644 index 0000000..7387c26 --- /dev/null +++ b/app/src/main/java/com/yzx/webebook/activity/base/BaseActivity.kt @@ -0,0 +1,73 @@ +package com.yzx.webebook.activity.base + +import android.os.Bundle +import androidx.appcompat.app.AppCompatActivity +import com.gyf.immersionbar.ktx.immersionBar +import com.yzx.webebook.R +import com.yzx.webebook.presenter.base.BasePresenter + +/** + * 类名:BaseActivity + * 作者:Yun.Lei + * 功能: + * 创建日期:2020年5月6日14:27:04 + * 修改人: + * 修改时间: + * 修改备注: + */ +abstract class BaseActivity> : AppCompatActivity() { + + /** + * 当前页面需要加载的layoutId,等价setContentView + */ + abstract val inflateId: Int + + /** + * 初始化视图操作在这里执行,执行时机为onCreate之后 + */ + abstract fun initView(): Unit + + /** + * 数据初始化在这里执行,执行时机为initView之后 + */ + abstract fun initData(): Unit + + //kotlin 懒加载,在第一次使用Presenter时初始化,这种设计是针对一个View只针对一个Presenter。 + //多个Presenter的情况此处不应该使用泛型 + protected val mPresenter: P? by lazy { initPresenter() } + + abstract fun initPresenter(): P? + + + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(inflateId) + initView() + initData() + setStatusBar() + } + + open fun setStatusBar() { + immersionBar { + statusBarColor(R.color.white) + fitsSystemWindows(true) + statusBarDarkFont(true, 0.2f) + keyboardEnable(true) + init() + } + } + + + + + + override fun onBackPressed() { + super.onBackPressed() + } + + override fun onDestroy() { + super.onDestroy() + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/yzx/webebook/model/UploadBean.kt b/app/src/main/java/com/yzx/webebook/model/UploadBean.kt new file mode 100644 index 0000000..d3ab83e --- /dev/null +++ b/app/src/main/java/com/yzx/webebook/model/UploadBean.kt @@ -0,0 +1,13 @@ +package com.yzx.webebook.model + +class UploadBean { + var code:Int = 0 + var msg:String = "" + var content:UploadContent = UploadContent() +} + +class UploadContent{ + var identity:String = "" + var key:String = "" + var file_size:String = "" +} \ No newline at end of file diff --git a/app/src/main/java/com/yzx/webebook/presenter/base/BasePresenter.kt b/app/src/main/java/com/yzx/webebook/presenter/base/BasePresenter.kt new file mode 100644 index 0000000..46903c7 --- /dev/null +++ b/app/src/main/java/com/yzx/webebook/presenter/base/BasePresenter.kt @@ -0,0 +1,19 @@ +package com.yzx.webebook.presenter.base + +/** + * 类名:BasePresenter + * 作者:Yun.Lei + * 功能: + * 创建日期:2018-07-13 10:40 + * 修改人: + * 修改时间: + * 修改备注: + */ +abstract class BasePresenter(view: T) { + protected var mView: T? = view + + fun onDestroy() { + mView = null + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/yzx/webebook/presenter/base/IView.kt b/app/src/main/java/com/yzx/webebook/presenter/base/IView.kt new file mode 100644 index 0000000..4330164 --- /dev/null +++ b/app/src/main/java/com/yzx/webebook/presenter/base/IView.kt @@ -0,0 +1,12 @@ +package com.yzx.webebook.presenter.base + +/** + * 类名:IView + * 作者:Yun.Lei + * 功能: + * 创建日期:2018-07-13 10:39 + * 修改人: + * 修改时间: + * 修改备注: + */ +interface IView \ No newline at end of file diff --git a/app/src/main/java/com/yzx/webebook/utils/KotlinX.kt b/app/src/main/java/com/yzx/webebook/utils/KotlinX.kt new file mode 100644 index 0000000..606d4d6 --- /dev/null +++ b/app/src/main/java/com/yzx/webebook/utils/KotlinX.kt @@ -0,0 +1,2 @@ +package com.yzx.webebook.utils + diff --git a/app/src/main/java/com/yzx/webebook/utils/YzxFileProvider.kt b/app/src/main/java/com/yzx/webebook/utils/YzxFileProvider.kt new file mode 100644 index 0000000..a861c7e --- /dev/null +++ b/app/src/main/java/com/yzx/webebook/utils/YzxFileProvider.kt @@ -0,0 +1,15 @@ +package com.yzx.webebook.utils + +import androidx.core.content.FileProvider + + +/** + * 类名:YzxFileProvider + * 作者:Yun.Lei + * 功能: + * 创建日期:2020年5月6日14:09:27 + * 修改人: + * 修改时间: + * 修改备注: + */ +class YzxFileProvider: FileProvider() \ No newline at end of file diff --git a/app/src/main/java/com/yzx/webebook/widget/EBookView.java b/app/src/main/java/com/yzx/webebook/widget/EBookView.java new file mode 100644 index 0000000..2359dfe --- /dev/null +++ b/app/src/main/java/com/yzx/webebook/widget/EBookView.java @@ -0,0 +1,22 @@ +package com.yzx.webebook.widget; + +import android.content.Context; +import android.graphics.drawable.Drawable; +import android.util.AttributeSet; + +import com.wetao.note.WeNoteView; + +public class EBookView extends WeNoteView { + + public EBookView(Context context) { + super(context); + } + + public EBookView(Context context, AttributeSet attributeSet) { + super(context, attributeSet); + } + + public void updateBackground(Drawable drawable){ + + } +} diff --git a/app/src/main/java/com/yzx/webebook/widget/ScrollTextView.kt b/app/src/main/java/com/yzx/webebook/widget/ScrollTextView.kt new file mode 100644 index 0000000..33eda6e --- /dev/null +++ b/app/src/main/java/com/yzx/webebook/widget/ScrollTextView.kt @@ -0,0 +1,32 @@ +package com.yzx.webebook.widget + +import android.content.Context +import android.text.TextUtils +import android.util.AttributeSet +import androidx.appcompat.widget.AppCompatTextView + +/** + * 类名:ScrollTextView + * 作者:Yun.Lei + * 功能: + * 创建日期:2020年5月6日14:29:39 + * 修改人: + * 修改时间: + * 修改备注: + */ +class ScrollTextView : AppCompatTextView { + + constructor(context: Context?) : super(context) + constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs) + constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr) + + init { + ellipsize = TextUtils.TruncateAt.MARQUEE + marqueeRepeatLimit = -1 + isSingleLine = true + } + + override fun isFocused(): Boolean { + return true + } +} diff --git a/app/src/main/jniLibs/armeabi/libpaintworker.so b/app/src/main/jniLibs/armeabi/libpaintworker.so new file mode 100644 index 0000000..466849e --- /dev/null +++ b/app/src/main/jniLibs/armeabi/libpaintworker.so @@ -0,0 +1 @@ +/system/lib/libpaintworker.so \ No newline at end of file diff --git a/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml new file mode 100644 index 0000000..c7bd21d --- /dev/null +++ b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + diff --git a/app/src/main/res/drawable-v24/progress_horizontal.xml b/app/src/main/res/drawable-v24/progress_horizontal.xml new file mode 100644 index 0000000..d489a6d --- /dev/null +++ b/app/src/main/res/drawable-v24/progress_horizontal.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/Thumbs.db b/app/src/main/res/drawable/Thumbs.db new file mode 100644 index 0000000..4d6ca08 Binary files /dev/null and b/app/src/main/res/drawable/Thumbs.db differ diff --git a/app/src/main/res/drawable/background0.png b/app/src/main/res/drawable/background0.png new file mode 100644 index 0000000..08bf0dd Binary files /dev/null and b/app/src/main/res/drawable/background0.png differ diff --git a/app/src/main/res/drawable/background1.png b/app/src/main/res/drawable/background1.png new file mode 100644 index 0000000..c98524f Binary files /dev/null and b/app/src/main/res/drawable/background1.png differ diff --git a/app/src/main/res/drawable/background10.png b/app/src/main/res/drawable/background10.png new file mode 100644 index 0000000..ddc0c74 Binary files /dev/null and b/app/src/main/res/drawable/background10.png differ diff --git a/app/src/main/res/drawable/background11.jpg b/app/src/main/res/drawable/background11.jpg new file mode 100644 index 0000000..3bf240d Binary files /dev/null and b/app/src/main/res/drawable/background11.jpg differ diff --git a/app/src/main/res/drawable/background2.png b/app/src/main/res/drawable/background2.png new file mode 100644 index 0000000..764b1b7 Binary files /dev/null and b/app/src/main/res/drawable/background2.png differ diff --git a/app/src/main/res/drawable/background3.png b/app/src/main/res/drawable/background3.png new file mode 100644 index 0000000..ce8f367 Binary files /dev/null and b/app/src/main/res/drawable/background3.png differ diff --git a/app/src/main/res/drawable/background4.png b/app/src/main/res/drawable/background4.png new file mode 100644 index 0000000..960c26a Binary files /dev/null and b/app/src/main/res/drawable/background4.png differ diff --git a/app/src/main/res/drawable/background5.png b/app/src/main/res/drawable/background5.png new file mode 100644 index 0000000..af2f576 Binary files /dev/null and b/app/src/main/res/drawable/background5.png differ diff --git a/app/src/main/res/drawable/background6.png b/app/src/main/res/drawable/background6.png new file mode 100644 index 0000000..189c2d3 Binary files /dev/null and b/app/src/main/res/drawable/background6.png differ diff --git a/app/src/main/res/drawable/background7.png b/app/src/main/res/drawable/background7.png new file mode 100644 index 0000000..aa9bb7e Binary files /dev/null and b/app/src/main/res/drawable/background7.png differ diff --git a/app/src/main/res/drawable/background8.png b/app/src/main/res/drawable/background8.png new file mode 100644 index 0000000..d6831ec Binary files /dev/null and b/app/src/main/res/drawable/background8.png differ diff --git a/app/src/main/res/drawable/background9.png b/app/src/main/res/drawable/background9.png new file mode 100644 index 0000000..d21c0b6 Binary files /dev/null and b/app/src/main/res/drawable/background9.png differ diff --git a/app/src/main/res/drawable/btn_select.xml b/app/src/main/res/drawable/btn_select.xml new file mode 100644 index 0000000..69870e7 --- /dev/null +++ b/app/src/main/res/drawable/btn_select.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/app/src/main/res/drawable/ic_launcher_background.xml b/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..2408e30 --- /dev/null +++ b/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/drawable/ic_note_page_left_normal.png b/app/src/main/res/drawable/ic_note_page_left_normal.png new file mode 100644 index 0000000..a967b0a Binary files /dev/null and b/app/src/main/res/drawable/ic_note_page_left_normal.png differ diff --git a/app/src/main/res/drawable/ic_note_page_right_normal.png b/app/src/main/res/drawable/ic_note_page_right_normal.png new file mode 100644 index 0000000..24125ae Binary files /dev/null and b/app/src/main/res/drawable/ic_note_page_right_normal.png differ diff --git a/app/src/main/res/drawable/progress_horizontal.xml b/app/src/main/res/drawable/progress_horizontal.xml new file mode 100644 index 0000000..d489a6d --- /dev/null +++ b/app/src/main/res/drawable/progress_horizontal.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_book.xml b/app/src/main/res/layout/activity_book.xml new file mode 100644 index 0000000..199a797 --- /dev/null +++ b/app/src/main/res/layout/activity_book.xml @@ -0,0 +1,235 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +