Skip to content

Commit

Permalink
Merge pull request #1 from hqwlkj/develop
Browse files Browse the repository at this point in the history
fix: add LoadingDialog
  • Loading branch information
hqwlkj authored Sep 22, 2021
2 parents 12c35e1 + 8a629e8 commit fcf5bfa
Show file tree
Hide file tree
Showing 21 changed files with 343 additions and 67 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 0.0.4

* fix: Flutter MethodChannel 原生通信导致的Reply already submitted问题
* 新增 Loading 方法 `showLoading`
* 关闭 Loading 方法 `hideLoading`

## 0.0.3

* 升级 FLutter 2.x
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class FlutterChsPlugin implements FlutterPlugin, MethodCallHandler, Activ
public void onAttachedToEngine(@NonNull FlutterPluginBinding flutterPluginBinding) {
channel = new MethodChannel(flutterPluginBinding.getBinaryMessenger(), "flutter_chs");
FlutterChsHandler.setContext(flutterPluginBinding.getApplicationContext());
FlutterChsHandler.initDialog(flutterPluginBinding.getApplicationContext());
FlutterChsHandler.setChannel(channel);
channel.setMethodCallHandler(this);
}
Expand Down Expand Up @@ -101,6 +102,14 @@ public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) {
case "closeDevice":
ChsService.closeDevice();
break;
case "showLoading":
String msg = call.argument("msg");
LoggerUtil.e("msg:" + msg);
FlutterChsHandler.showDialog(msg);
break;
case "hideLoading":
FlutterChsHandler.hideDialog();
break;
default:
result.notImplemented();
break;
Expand Down Expand Up @@ -128,7 +137,11 @@ public void callback(final Map<String, Object> params) {
uiThreadHandler.post(new Runnable() {
@Override
public void run() {
result.success(params);
try {
result.success(params);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
Expand Down Expand Up @@ -225,6 +238,7 @@ public void onReattachedToActivityForConfigChanges(ActivityPluginBinding binding
@Override
public void onAttachedToActivity(ActivityPluginBinding binding) {
FlutterChsHandler.setContext(binding.getActivity());
FlutterChsHandler.initDialog(binding.getActivity());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
package com.parsec.flutter_chs.handlers;

import android.content.Context;

import com.parsec.flutter_chs.loading.LoadingDialog;

import io.flutter.plugin.common.MethodChannel;

public class FlutterChsHandler {
private static Context context;
private static MethodChannel channel;

private static LoadingDialog loadingDialog;

public static void initDialog(Context _context){
loadingDialog = new LoadingDialog(_context);
}
public static void setContext(Context _context) {
context = _context;
}
Expand All @@ -22,4 +30,12 @@ public static void setChannel(MethodChannel _channel) {
public static MethodChannel getChannel() {
return channel;
}

public static void showDialog(String msg){
loadingDialog.show(msg);
}

public static void hideDialog(){
loadingDialog.hide();
}
}
18 changes: 18 additions & 0 deletions android/src/main/java/com/parsec/flutter_chs/loading/Loading.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.parsec.flutter_chs.loading;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.RelativeLayout;
import com.parsec.flutter_chs.R.layout;

public class Loading extends RelativeLayout {
public Loading(Context context) {
super(context);
}

public Loading(Context context, AttributeSet attrs) {
super(context, attrs);
LayoutInflater.from(context).inflate(layout.vs_main_loading, this);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package com.parsec.flutter_chs.loading;

import android.app.Dialog;
import android.content.Context;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;

import com.parsec.flutter_chs.R.id;
import com.parsec.flutter_chs.R.style;
import com.parsec.flutter_chs.R.layout;

public class LoadingDialog extends Dialog {
private static final int MSG_UPDATE_LOADING_DOT = 1;
private final ImageView mLoadingDot1;
private final ImageView mLoadingDot2;
private final ImageView mLoadingDot3;
private final TextView mLoadingBrand;
private final Handler mHandler;
private int mDotSeq;

public LoadingDialog(Context context){
super(context, style.Loading);
this.setContentView(layout.vs_main_loading);
Window window = this.getWindow();
WindowManager.LayoutParams params = window.getAttributes();
params.gravity = 17;
window.setAttributes(params);
this.mLoadingDot1 = this.findViewById(id.loading_dot1);
this.mLoadingDot2 = this.findViewById(id.loading_dot2);
this.mLoadingDot3 = this.findViewById(id.loading_dot3);
this.mLoadingBrand = this.findViewById(id.loading_brand);
this.mHandler = new Handler(Looper.myLooper()) {
public void handleMessage(Message msg) {
super.handleMessage(msg);
if (msg.what == 1) {
if (LoadingDialog.this.mDotSeq == 0) {
LoadingDialog.this.mLoadingDot1.setAlpha(0.6F);
LoadingDialog.this.mLoadingDot2.setAlpha(1.0F);
LoadingDialog.this.mLoadingDot3.setAlpha(0.6F);
LoadingDialog.this.mDotSeq++;
} else if (LoadingDialog.this.mDotSeq == 1) {
LoadingDialog.this.mLoadingDot1.setAlpha(0.3F);
LoadingDialog.this.mLoadingDot2.setAlpha(0.6F);
LoadingDialog.this.mLoadingDot3.setAlpha(1.0F);
LoadingDialog.this.mDotSeq++;
} else if (LoadingDialog.this.mDotSeq == 2) {
LoadingDialog.this.mLoadingDot1.setAlpha(1.0F);
LoadingDialog.this.mLoadingDot2.setAlpha(0.6F);
LoadingDialog.this.mLoadingDot3.setAlpha(0.3F);
LoadingDialog.this.mDotSeq = 0;
}
LoadingDialog.this.mHandler.sendEmptyMessageDelayed(1, 800L);
}
}
};
}


public void show(String msg) {
this.mHandler.sendEmptyMessageDelayed(1, 800L);
if(msg == null){
msg = "中国医疗保障";
}
mLoadingBrand.setText(msg);
this.mDotSeq = 0;
super.show();
}

public void hide() {
this.mHandler.removeMessages(1);
this.mDotSeq = 0;
this.mLoadingDot1.setAlpha(1.0F);
this.mLoadingDot2.setAlpha(0.6F);
this.mLoadingDot3.setAlpha(0.3F);
super.dismiss();
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions android/src/main/res/drawable/loading_bg.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>

<shape xmlns:android="http://schemas.android.com/apk/res/android">
<!-- 矩形的圆角弧度 -->
<corners android:radius="10dp"/>
<!-- 矩形的填充色 -->
<solid android:color="#b3000000" />


</shape>
12 changes: 12 additions & 0 deletions android/src/main/res/drawable/loading_round_dot.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval"
android:useLevel="true">

<size
android:width="80dp"
android:height="80dp" />

<solid android:color="#ffffff" />

</shape>
65 changes: 65 additions & 0 deletions android/src/main/res/layout/vs_main_loading.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/loading_wrap"
android:layout_width="150dp"
android:layout_height="150dp"
android:background="@drawable/loading_bg"
>

<ImageView
android:id="@+id/loading_icon"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_centerHorizontal="true"
android:layout_marginTop="12dp"
android:background="@drawable/loading_icon" />

<TextView
android:id="@+id/loading_brand"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="中国医疗保障"
android:textColor="#ffffff"
android:layout_below="@+id/loading_icon"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:textSize="14dp"/>

<ImageView
android:id="@+id/loading_dot2"
android:layout_width="10dp"
android:layout_height="10dp"
android:background="@drawable/loading_round_dot"
android:layout_centerHorizontal="true"
android:layout_below="@+id/loading_brand"
android:layout_marginTop="8dp"
android:alpha="0.6"
/>

<ImageView
android:id="@+id/loading_dot1"
android:layout_width="10dp"
android:layout_height="10dp"
android:background="@drawable/loading_round_dot"
android:layout_toLeftOf="@+id/loading_dot2"
android:layout_below="@+id/loading_brand"
android:layout_marginTop="8dp"
android:layout_marginRight="12dp"
/>

<ImageView
android:id="@+id/loading_dot3"
android:layout_width="10dp"
android:layout_height="10dp"
android:background="@drawable/loading_round_dot"
android:layout_toRightOf="@+id/loading_dot2"
android:layout_below="@+id/loading_brand"
android:layout_marginTop="8dp"
android:layout_marginLeft="12dp"
android:alpha="0.3"
/>


</RelativeLayout>
19 changes: 19 additions & 0 deletions android/src/main/res/values/values.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">flutter_chs</string>
<style name="Loading" parent="@android:style/Theme.Dialog">
<item name="android:windowFrame">@null</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowNoTitle">true</item>
<!-- 设置背景色 透明-->
<item name="android:background">@android:color/transparent</item>
<item name="android:windowBackground">@android:color/transparent</item>
<!-- 设置是否显示背景 -->
<item name="android:backgroundDimEnabled">true</item>
<!-- 设置背景透明度 -->
<item name="android:backgroundDimAmount">0</item>
<!-- 设置点击空白不消失 -->
<item name="android:windowCloseOnTouchOutside">false</item>
</style>
</resources>
10 changes: 6 additions & 4 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ import 'package:flutter_screenutil/flutter_screenutil.dart';
void main() {
LogUtil.init(tag: 'CHS_APP');
Request.init();
runApp(MyApp());
runApp(const MyApp());
}

class MyApp extends StatefulWidget {
const MyApp({Key key}) : super(key: key);

@override
_MyAppState createState() => _MyAppState();
}
Expand All @@ -19,14 +21,14 @@ class _MyAppState extends State<MyApp> {
@override
Widget build(BuildContext context) {
return ScreenUtilInit(
designSize: Size(750, 1334),
designSize: const Size(750, 1334),
builder: () => MaterialApp(
debugShowCheckedModeBanner: false,
title: 'CHS-FLUTTER-APP',
theme: ThemeData(
primarySwatch: Colors.blue,
buttonTheme: ButtonThemeData(shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(18.0),
side: BorderSide(color: Colors.red)),)
side: const BorderSide(color: Colors.red)),)
),
builder: (context, widget) {
return MediaQuery(
Expand All @@ -35,7 +37,7 @@ class _MyAppState extends State<MyApp> {
child: widget,
);
},
home: HomePage(),
home: const HomePage(),
));
}
}
Loading

0 comments on commit fcf5bfa

Please sign in to comment.