1
0
Fork 0

增加扫码打开小程序功能

master
kangxuyao 2022-10-24 17:48:50 +08:00
parent 4a19e07f10
commit 11b50d19d7
12 changed files with 403 additions and 9 deletions

View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="deploymentTargetDropDown">
<runningDeviceTargetSelectedWithDropDown>
<Target>
<type value="RUNNING_DEVICE_TARGET" />
<deviceKey>
<Key>
<type value="SERIAL_NUMBER" />
<value value="FA7AZ1A07148" />
</Key>
</deviceKey>
</Target>
</runningDeviceTargetSelectedWithDropDown>
<timeTargetWasSelectedWithDropDown value="2022-10-24T09:17:42.427931Z" />
</component>
</project>

View File

@ -5,7 +5,16 @@
<configuration PROFILE_NAME="Debug" CONFIG_NAME="Debug" /> <configuration PROFILE_NAME="Debug" CONFIG_NAME="Debug" />
</configurations> </configurations>
</component> </component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK"> <component name="DesignSurface">
<option name="filePathToZoomLevelMap">
<map>
<entry key="app/src/main/res/layout/activity_main.xml" value="0.34427083333333336" />
<entry key="app/src/main/res/layout/activity_scan_qr_code.xml" value="0.12135416666666667" />
<entry key="app/src/main/res/layout/activity_scan_start_applet.xml" value="0.20244565217391305" />
</map>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" /> <output url="file://$PROJECT_DIR$/build/classes" />
</component> </component>
<component name="ProjectType"> <component name="ProjectType">

View File

@ -1,4 +1,7 @@
apply plugin: 'com.android.application' apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
android { android {
compileSdkVersion 29 compileSdkVersion 29
@ -17,7 +20,7 @@ android {
// App Secret // App Secret
buildConfigField "String", "APP_SECRET", "\"bdfd76cae24d4313\"" buildConfigField "String", "APP_SECRET", "\"bdfd76cae24d4313\""
// API // API
buildConfigField "String", "API_URL", "\"https://mp.finogeeks.com\"" buildConfigField "String", "API_URL", "\"https://api.finclip.com\""
// API // API
buildConfigField "String", "API_PREFIX", "\"/api/v1/mop/\"" buildConfigField "String", "API_PREFIX", "\"/api/v1/mop/\""
@ -69,5 +72,7 @@ dependencies {
testImplementation 'junit:junit:4.12' testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0' androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.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'
} }

View File

@ -2,6 +2,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.finogeeks.mop.demo"> package="com.finogeeks.mop.demo">
<uses-permission android:name="android.permission.VIBRATE" />
<application <application
android:name=".MopApplication" android:name=".MopApplication"
android:allowBackup="false" android:allowBackup="false"
@ -25,5 +26,16 @@
android:name=".InputContentActivity" android:name=".InputContentActivity"
android:label="@string/app_name" android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar" /> android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".ScanStartAppletActivity"
android:theme="@style/Theme.AppCompat.Light.NoActionBar"
android:label="@string/scan_start_applet" />
<activity
android:name=".ScanQRCodeActivity"
android:theme="@style/Theme.AppCompat.Light.NoActionBar"
android:configChanges="keyboardHidden|orientation|screenSize"
android:label="@string/scan_start_applet"
android:screenOrientation="portrait" />
</application> </application>
</manifest> </manifest>

View File

@ -2,6 +2,7 @@ package com.finogeeks.mop.demo;
import android.content.Context; import android.content.Context;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.os.Bundle;
import android.widget.Toast; import android.widget.Toast;
import androidx.annotation.NonNull; 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.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.json.JSONObject;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; 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) { public void shareAppMessage(@NotNull String appInfo, @Nullable Bitmap bitmap, @NotNull IAppletCallback callback) {
Toast.makeText(mContext, "点击了转发按钮,去实现您的转发/分享逻辑吧", Toast.LENGTH_SHORT).show(); 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<String, String> getWebViewCookie(@NonNull String s) {
return null;
}
@Override
public boolean launchApp(@androidx.annotation.Nullable String s) {
return false;
}
} }

View File

@ -1,5 +1,6 @@
package com.finogeeks.mop.demo; package com.finogeeks.mop.demo;
import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.view.View; import android.view.View;
import android.widget.Button; import android.widget.Button;
@ -8,6 +9,7 @@ import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar; import androidx.appcompat.widget.Toolbar;
import com.finogeeks.lib.applet.client.FinAppClient; import com.finogeeks.lib.applet.client.FinAppClient;
import com.finogeeks.lib.applet.sdk.api.request.IFinAppletRequest;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -21,11 +23,20 @@ public class MainActivity extends AppCompatActivity {
Toolbar toolbar = findViewById(R.id.toolbar); Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(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); Button btnCharts = findViewById(R.id.btn_charts);
btnCharts.setOnClickListener(new View.OnClickListener() { btnCharts.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { 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() { btnDemo.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { 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() { btnProfile.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { 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) { public void onClick(View v) {
Map<String, String> params = new HashMap<>(); Map<String, String> params = new HashMap<>();
params.put("path", "pages/index/index"); 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) { public void onClick(View v) {
Map<String, String> params = new HashMap<>(); Map<String, String> params = new HashMap<>();
params.put("path", "pages/webview/webview"); 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() { btnAppletLogin.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
FinAppClient.INSTANCE.getAppletApiManager().startApplet(MainActivity.this, "60f051ea525ea10001c0bd22"); FinAppClient.INSTANCE.getAppletApiManager().startApplet(MainActivity.this, "60f051ea525ea10001c0bd22",null);
} }
}); });
} }

View File

@ -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"
}
}

View File

@ -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<String> {
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<String> {
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
}
}

View File

@ -17,6 +17,17 @@
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent"
app:titleTextColor="@android:color/white" /> app:titleTextColor="@android:color/white" />
<Button
android:id="@+id/btn_scan"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/scan_start_applet"
app:layout_constraintBottom_toTopOf="@+id/btn_demo"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_chainStyle="packed" />
<Button <Button
android:id="@+id/btn_charts" android:id="@+id/btn_charts"
android:layout_width="wrap_content" android:layout_width="wrap_content"

View File

@ -0,0 +1,50 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
style="@style/Widget.AppCompat.Toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<cn.bingoogolapple.qrcode.zbar.ZBarView
android:id="@+id/zBarView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:visibility="gone"
app:layout_constraintTop_toBottomOf="@id/toolbar"
app:qrcv_animTime="1000"
app:qrcv_barCodeTipText="将条码放入框内,即可自动扫描"
app:qrcv_barcodeRectHeight="120dp"
app:qrcv_borderColor="@android:color/white"
app:qrcv_borderSize="1px"
app:qrcv_cornerColor="@color/colorPrimaryDark"
app:qrcv_cornerLength="20dp"
app:qrcv_cornerSize="3dp"
app:qrcv_isAutoZoom="true"
app:qrcv_isBarcode="false"
app:qrcv_isOnlyDecodeScanBoxArea="true"
app:qrcv_isShowDefaultGridScanLineDrawable="false"
app:qrcv_isShowDefaultScanLineDrawable="true"
app:qrcv_isShowLocationPoint="true"
app:qrcv_isShowTipBackground="false"
app:qrcv_isShowTipTextAsSingleLine="false"
app:qrcv_isTipTextBelowRect="true"
app:qrcv_maskColor="#4D000000"
app:qrcv_qrCodeTipText="将二维码放入框内,即可自动扫描"
app:qrcv_rectWidth="260dp"
app:qrcv_scanLineColor="@color/colorPrimaryDark"
app:qrcv_tipTextMargin="20dp"
app:qrcv_tipTextSize="12sp"
app:qrcv_toolbarHeight="@dimen/fin_applet_navbar_height"
app:qrcv_topOffset="80dp"
app:qrcv_verticalBias="-1"
tools:visibility="visible" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#f5f5f6">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
style="@style/Widget.AppCompat.Toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/btnScan"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginTop="40dp"
android:layout_marginEnd="10dp"
android:text="扫码打开小程序"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -9,4 +9,5 @@
<string name="fin_clip_input_content_hint">请输入内容</string> <string name="fin_clip_input_content_hint">请输入内容</string>
<string name="fin_clip_confirm">确定</string> <string name="fin_clip_confirm">确定</string>
<string name="fin_clip_get_input_content_failed">获取输入内容失败</string> <string name="fin_clip_get_input_content_failed">获取输入内容失败</string>
<string name="scan_start_applet">扫码打开小程序</string>
</resources> </resources>