diff --git a/.idea/deploymentTargetDropDown.xml b/.idea/deploymentTargetDropDown.xml new file mode 100644 index 0000000..4ab7d56 --- /dev/null +++ b/.idea/deploymentTargetDropDown.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 703e5d4..9b76bd8 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -5,7 +5,16 @@ - + + + + diff --git a/app/build.gradle b/app/build.gradle index f607e15..35ad913 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,4 +1,7 @@ apply plugin: 'com.android.application' +apply plugin: 'kotlin-android' +apply plugin: 'kotlin-android-extensions' +apply plugin: 'kotlin-kapt' android { compileSdkVersion 29 @@ -17,7 +20,7 @@ android { // App Secret buildConfigField "String", "APP_SECRET", "\"bdfd76cae24d4313\"" // API服务地址 - buildConfigField "String", "API_URL", "\"https://mp.finogeeks.com\"" + buildConfigField "String", "API_URL", "\"https://api.finclip.com\"" // API服务前缀 buildConfigField "String", "API_PREFIX", "\"/api/v1/mop/\"" @@ -69,5 +72,7 @@ dependencies { testImplementation 'junit:junit:4.12' androidTestImplementation 'androidx.test:runner:1.2.0' androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' - implementation 'com.finogeeks.lib:finapplet:2.35.7' + implementation 'com.finogeeks.lib:finapplet:2.38.3' + implementation 'cn.bingoogolapple:bga-qrcode-zbar:1.3.7' + } \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index f4c83b3..0f56c3e 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -2,6 +2,7 @@ + + + + \ No newline at end of file diff --git a/app/src/main/java/com/finogeeks/mop/demo/AppletHandler.java b/app/src/main/java/com/finogeeks/mop/demo/AppletHandler.java index ed4392a..d6361c8 100644 --- a/app/src/main/java/com/finogeeks/mop/demo/AppletHandler.java +++ b/app/src/main/java/com/finogeeks/mop/demo/AppletHandler.java @@ -2,6 +2,7 @@ package com.finogeeks.mop.demo; import android.content.Context; import android.graphics.Bitmap; +import android.os.Bundle; import android.widget.Toast; import androidx.annotation.NonNull; @@ -13,6 +14,7 @@ import com.finogeeks.lib.applet.sdk.api.IAppletHandler; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.json.JSONObject; import java.util.ArrayList; import java.util.List; @@ -170,4 +172,40 @@ public class AppletHandler implements IAppletHandler { public void shareAppMessage(@NotNull String appInfo, @Nullable Bitmap bitmap, @NotNull IAppletCallback callback) { Toast.makeText(mContext, "点击了转发按钮,去实现您的转发/分享逻辑吧", Toast.LENGTH_SHORT).show(); } + + @Override + public void chooseAvatar(@NonNull IAppletCallback iAppletCallback) { + + } + + @Override + public boolean contact(@NonNull JSONObject jsonObject) { + return false; + } + + @Override + public boolean feedback(@NonNull Bundle bundle) { + return false; + } + + @Override + public void getJSSDKConfig(@NonNull JSONObject jsonObject, @NonNull IAppletCallback iAppletCallback) { + + } + + @Override + public void getPhoneNumber(@NonNull IAppletCallback iAppletCallback) { + + } + + @androidx.annotation.Nullable + @Override + public Map getWebViewCookie(@NonNull String s) { + return null; + } + + @Override + public boolean launchApp(@androidx.annotation.Nullable String s) { + return false; + } } \ No newline at end of file diff --git a/app/src/main/java/com/finogeeks/mop/demo/MainActivity.java b/app/src/main/java/com/finogeeks/mop/demo/MainActivity.java index cc0c645..f7c91fc 100644 --- a/app/src/main/java/com/finogeeks/mop/demo/MainActivity.java +++ b/app/src/main/java/com/finogeeks/mop/demo/MainActivity.java @@ -1,5 +1,6 @@ package com.finogeeks.mop.demo; +import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.Button; @@ -8,6 +9,7 @@ import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.widget.Toolbar; import com.finogeeks.lib.applet.client.FinAppClient; +import com.finogeeks.lib.applet.sdk.api.request.IFinAppletRequest; import java.util.HashMap; import java.util.Map; @@ -21,11 +23,20 @@ public class MainActivity extends AppCompatActivity { Toolbar toolbar = findViewById(R.id.toolbar); setSupportActionBar(toolbar); + Button btnScan = findViewById(R.id.btn_scan); + btnScan.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + startActivity(new Intent(MainActivity.this, ScanStartAppletActivity.class)); + } + }); + + Button btnCharts = findViewById(R.id.btn_charts); btnCharts.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - FinAppClient.INSTANCE.getAppletApiManager().startApplet(MainActivity.this, "5facb3a52dcbff00017469bd"); + FinAppClient.INSTANCE.getAppletApiManager().startApplet(MainActivity.this, IFinAppletRequest.Companion.fromAppId("5facb3a52dcbff00017469bd"),null); } }); @@ -33,7 +44,7 @@ public class MainActivity extends AppCompatActivity { btnDemo.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - FinAppClient.INSTANCE.getAppletApiManager().startApplet(MainActivity.this, "5fa214a29a6a7900019b5cc1"); + FinAppClient.INSTANCE.getAppletApiManager().startApplet(MainActivity.this,IFinAppletRequest.Companion.fromAppId( "5fa214a29a6a7900019b5cc1"),null); } }); @@ -41,7 +52,7 @@ public class MainActivity extends AppCompatActivity { btnProfile.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - FinAppClient.INSTANCE.getAppletApiManager().startApplet(MainActivity.this, "5fa215459a6a7900019b5cc3"); + FinAppClient.INSTANCE.getAppletApiManager().startApplet(MainActivity.this, IFinAppletRequest.Companion.fromAppId("5fa215459a6a7900019b5cc3"),null); } }); @@ -51,7 +62,7 @@ public class MainActivity extends AppCompatActivity { public void onClick(View v) { Map params = new HashMap<>(); params.put("path", "pages/index/index"); - FinAppClient.INSTANCE.getAppletApiManager().startApplet(MainActivity.this, "5fc8934aefb8c600019e9747", params); + FinAppClient.INSTANCE.getAppletApiManager().startApplet(MainActivity.this, IFinAppletRequest.Companion.fromAppId("5fc8934aefb8c600019e9747").setStartParams(params),null); } }); @@ -61,7 +72,7 @@ public class MainActivity extends AppCompatActivity { public void onClick(View v) { Map params = new HashMap<>(); params.put("path", "pages/webview/webview"); - FinAppClient.INSTANCE.getAppletApiManager().startApplet(MainActivity.this, "5fc8934aefb8c600019e9747", params); + FinAppClient.INSTANCE.getAppletApiManager().startApplet(MainActivity.this, "5fc8934aefb8c600019e9747", params,null); } }); @@ -69,7 +80,7 @@ public class MainActivity extends AppCompatActivity { btnAppletLogin.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - FinAppClient.INSTANCE.getAppletApiManager().startApplet(MainActivity.this, "60f051ea525ea10001c0bd22"); + FinAppClient.INSTANCE.getAppletApiManager().startApplet(MainActivity.this, "60f051ea525ea10001c0bd22",null); } }); } diff --git a/app/src/main/java/com/finogeeks/mop/demo/ScanQRCodeActivity.kt b/app/src/main/java/com/finogeeks/mop/demo/ScanQRCodeActivity.kt new file mode 100644 index 0000000..f3209ae --- /dev/null +++ b/app/src/main/java/com/finogeeks/mop/demo/ScanQRCodeActivity.kt @@ -0,0 +1,114 @@ +package com.finogeeks.mop.demo + +import android.Manifest +import android.app.Activity +import android.content.Intent +import android.os.Build +import android.os.Bundle +import android.os.VibrationEffect +import android.os.Vibrator +import android.util.Log +import android.view.MenuItem +import android.view.View +import android.widget.Toast +import androidx.appcompat.app.AppCompatActivity +import cn.bingoogolapple.qrcode.core.QRCodeView +import com.finogeeks.lib.applet.modules.permission.checkPermissions +import kotlinx.android.synthetic.main.activity_scan_qr_code.* + +/** + * 扫描二维码页面 + */ +class ScanQRCodeActivity : AppCompatActivity(), QRCodeView.Delegate { + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_scan_qr_code) + setSupportActionBar(toolbar) + supportActionBar?.setDisplayHomeAsUpEnabled(true) + } + + override fun onStart() { + super.onStart() + checkPermissions(Manifest.permission.CAMERA, granted = { + zBarView.visibility = View.VISIBLE + zBarView.setDelegate(this) + zBarView.startCamera() + zBarView.startSpotAndShowRect() + }) + } + + override fun onStop() { + zBarView.stopCamera() + super.onStop() + } + + override fun onDestroy() { + zBarView.onDestroy() + super.onDestroy() + } + + override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { + super.onActivityResult(requestCode, resultCode, data) + zBarView.showScanRect() + } + + override fun onScanQRCodeSuccess(result: String?) { + vibrate() + zBarView.startSpot() + setResult(Activity.RESULT_OK, Intent().putExtra(EXTRA_RESULT, result)) + finish() + } + + override fun onCameraAmbientBrightnessChanged(isDark: Boolean) { + var tipText: String = zBarView.scanBoxView.tipText + val ambientBrightnessTip = "\n环境过暗,请打开闪光灯" + if (isDark) { + if (!tipText.contains(ambientBrightnessTip)) { + zBarView.scanBoxView.tipText = tipText + ambientBrightnessTip + } + } else { + if (tipText.contains(ambientBrightnessTip)) { + tipText = tipText.substring(0, tipText.indexOf(ambientBrightnessTip)) + zBarView.scanBoxView.tipText = tipText + } + } + } + + override fun onScanQRCodeOpenCameraError() { + Toast.makeText(this, "打开相机出错", Toast.LENGTH_SHORT).show() + } + + private fun vibrate() { + val vibrator = getSystemService(VIBRATOR_SERVICE) as Vibrator + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) { + @Suppress("DEPRECATION") + vibrator.vibrate(200) + } else { + try { + val effect = VibrationEffect.createOneShot( + 200, + VibrationEffect.DEFAULT_AMPLITUDE + ) + vibrator.vibrate(effect, null) + } catch (iae: IllegalArgumentException) { + Log.e(TAG, "Failed to create VibrationEffect", iae) + } + } + } + + override fun onOptionsItemSelected(item: MenuItem): Boolean { + if (item.itemId == android.R.id.home) { + onBackPressed() + return true + } + return super.onOptionsItemSelected(item) + } + + companion object { + + private const val TAG = "ScanQRCodeActivity" + + const val EXTRA_RESULT = "result" + } +} \ No newline at end of file diff --git a/app/src/main/java/com/finogeeks/mop/demo/ScanStartAppletActivity.kt b/app/src/main/java/com/finogeeks/mop/demo/ScanStartAppletActivity.kt new file mode 100644 index 0000000..130e21c --- /dev/null +++ b/app/src/main/java/com/finogeeks/mop/demo/ScanStartAppletActivity.kt @@ -0,0 +1,97 @@ +package com.finogeeks.mop.demo + +import android.annotation.SuppressLint +import android.app.Activity +import android.content.Intent +import android.os.Bundle +import android.view.MenuItem +import android.widget.Toast +import androidx.appcompat.app.AppCompatActivity +import com.finogeeks.lib.applet.client.FinAppClient +import com.finogeeks.lib.applet.interfaces.FinCallback +import com.finogeeks.lib.applet.sdk.api.request.IFinAppletRequest +import kotlinx.android.synthetic.main.activity_scan_start_applet.* + +/** + * 扫码启动小程序的页面 + */ +@SuppressLint("Registered") +open class ScanStartAppletActivity : AppCompatActivity() { + + private var isStartingApplet = false + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_scan_start_applet) + setSupportActionBar(toolbar) + supportActionBar?.setDisplayHomeAsUpEnabled(true) + + btnScan.setOnClickListener { scanQRCode() } + } + + private fun scanQRCode() { + startActivityForResult(Intent(this, ScanQRCodeActivity::class.java), REQ_CODE_SCAN_QR_CODE) + } + + override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { + super.onActivityResult(requestCode, resultCode, data) + if (requestCode == REQ_CODE_SCAN_QR_CODE) { + if (resultCode == Activity.RESULT_OK && data != null) { + if (!isStartingApplet) + FinAppClient.appletApiManager.startApplet(this, IFinAppletRequest.fromQrCode(data.getStringExtra(ScanQRCodeActivity.EXTRA_RESULT)), + object : FinCallback { + override fun onSuccess(result: String?) { + isStartingApplet = false + runOnUiThread { + Toast.makeText(this@ScanStartAppletActivity, "扫码成功", Toast.LENGTH_SHORT).show() + } + } + + override fun onError(code: Int, error: String?) { + isStartingApplet = false + runOnUiThread { + Toast.makeText(this@ScanStartAppletActivity, error, Toast.LENGTH_SHORT).show() + } + } + + override fun onProgress(status: Int, info: String?) { + } + }) + /*FinAppClient.appletApiManager.startAppletByQrcode(this, data.getStringExtra(ScanQRCodeActivity.EXTRA_RESULT), + object : FinCallback { + override fun onSuccess(result: String?) { + isStartingApplet = false + runOnUiThread { + Toast.makeText(this@ScanStartAppletActivity, "扫码成功", Toast.LENGTH_SHORT).show() + } + } + + override fun onError(code: Int, error: String?) { + isStartingApplet = false + runOnUiThread { + Toast.makeText(this@ScanStartAppletActivity, error, Toast.LENGTH_SHORT).show() + } + } + + override fun onProgress(status: Int, info: String?) { + } + })*/ + } + } + } + + override fun onOptionsItemSelected(item: MenuItem): Boolean { + if (item.itemId == android.R.id.home) { + onBackPressed() + return true + } + return super.onOptionsItemSelected(item) + } + + companion object { + + private const val TAG = "StartAppletActivity" + + private const val REQ_CODE_SCAN_QR_CODE = 0x01 + } +} \ No newline at end of file diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index e49549d..dcce262 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -17,6 +17,17 @@ app:layout_constraintTop_toTopOf="parent" app:titleTextColor="@android:color/white" /> +