Skip to content

Commit

Permalink
feat: Support text in CustomViewBlock on Android (#14)
Browse files Browse the repository at this point in the history
Co-authored-by: Ji Fang <[email protected]>
  • Loading branch information
jifang and Ji Fang authored May 12, 2023
1 parent 1a03348 commit 7cc1538
Showing 1 changed file with 17 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.Surface;
import android.view.View;
import android.widget.ImageView;
Expand Down Expand Up @@ -43,7 +44,7 @@ public abstract class BaseUIConfig {
public PhoneNumberAuthHelper mAuthHelper;
public int mScreenWidthDp;
public int mScreenHeightDp;
// public EventChannel.EventSink mEventSink;
// public EventChannel.EventSink mEventSink;
public MethodChannel mChannel;
public FlutterPlugin.FlutterAssets mFlutterAssets;

Expand Down Expand Up @@ -128,9 +129,9 @@ public void onResume() {

public void buildCustomView( @NonNull List<CustomViewBlock> customViewConfigList) {
for (CustomViewBlock customViewBlock : customViewConfigList) {
ImageView imageView = null;
View view = null;
if (customViewBlock.image != null){
imageView = new ImageView(mContext);
ImageView imageView = new ImageView(mContext);
String flutterAssetFilePath = mFlutterAssets.getAssetFilePathByName(customViewBlock.image);
AssetManager assets = mContext.getAssets();
try {
Expand All @@ -141,6 +142,15 @@ public void buildCustomView( @NonNull List<CustomViewBlock> customViewConfigList
e.printStackTrace();
}
imageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
view = imageView;
}
else if (customViewBlock.text != null){
TextView textView = new TextView(mContext);
textView.setText(customViewBlock.text);
textView.setTextColor(Color.parseColor(customViewBlock.textColor));
textView.setTextSize(customViewBlock.textSize.floatValue());
textView.setGravity(Gravity.CENTER);
view = textView;
}

int width = dp2px(mContext, customViewBlock.width == null ? 30 : customViewBlock.width.floatValue());
Expand All @@ -149,8 +159,8 @@ public void buildCustomView( @NonNull List<CustomViewBlock> customViewConfigList
int offsetX = dp2px(mContext, customViewBlock.offsetX == null ? 0 : customViewBlock.offsetX.floatValue());
int offsetY = dp2px(mContext, customViewBlock.offsetY == null ? 0 : customViewBlock.offsetY.floatValue());
layoutParams.setMargins(offsetX, offsetY, 0, 0);
if(imageView != null){
imageView.setLayoutParams(layoutParams);
if(view != null){
view.setLayoutParams(layoutParams);
}
CustomInterface customInterface = null;
if (customViewBlock.enableTap != null && customViewBlock.enableTap){
Expand All @@ -163,12 +173,12 @@ public void buildCustomView( @NonNull List<CustomViewBlock> customViewConfigList
};
}
mAuthHelper.addAuthRegistViewConfig(customViewBlock.viewId.toString(), new AuthRegisterViewConfig.Builder()
.setView(imageView)
.setView(view)
.setRootViewId(AuthRegisterViewConfig.RootViewId.ROOT_VIEW_ID_BODY)
.setCustomInterface(customInterface).build()
);
}
}


}
}

0 comments on commit 7cc1538

Please sign in to comment.