添加EntranceFragment底层view增加方法

This commit is contained in:
tongchenfei
2020-08-11 19:05:50 +08:00
parent cdb48ea0d8
commit a11f74e334
6 changed files with 222 additions and 22 deletions

View File

@@ -0,0 +1,46 @@
package com.mogo.module.extensions.bean;
import android.view.View;
/**
* 底层view封装
*
* @author tongchenfei
*/
public class BottomLayerViewWrapper {
private View view;
private int x;
private int y;
public BottomLayerViewWrapper(){}
public BottomLayerViewWrapper(View view, int x, int y) {
this.view = view;
this.x = x;
this.y = y;
}
public View getView() {
return view;
}
public void setView(View view) {
this.view = view;
}
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}
}

View File

@@ -1,5 +1,6 @@
package com.mogo.module.extensions.entrance;
import android.content.Context;
import android.content.Intent;
import android.graphics.Rect;
import android.os.Bundle;
@@ -8,6 +9,7 @@ import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;
@@ -38,6 +40,7 @@ import com.mogo.module.extensions.ExtensionsModuleConst;
import com.mogo.module.extensions.R;
import com.mogo.module.extensions.navi.NaviInfoView;
import com.mogo.module.extensions.userinfo.UserInfo;
import com.mogo.module.extensions.utils.EntranceViewHolder;
import com.mogo.module.extensions.utils.TopViewAnimHelper;
import com.mogo.module.share.manager.ServiceApisManager;
import com.mogo.service.IMogoServiceApis;
@@ -153,6 +156,7 @@ public class EntranceFragment extends MvpFragment<EntranceView, EntrancePresente
mEntrancePresenter = new EntrancePresenter(getContext(), this);
mMogoFragmentManager = mApis.getFragmentManagerApi();
EntranceViewHolder.getInstance().initRootViewGroup(mRootView);
mStatusManager = mApis.getStatusManagerApi();
@@ -581,6 +585,12 @@ public class EntranceFragment extends MvpFragment<EntranceView, EntrancePresente
}
});
});
findViewById(R.id.btnDebugAddBottomLayerView).setOnClickListener(v->{
TextView tv = new TextView(getContext());
tv.setText("entrance add");
mApis.getEntranceButtonController().addBottomLayerView(tv, 50, 50);
});
}
@Override

View File

@@ -1,9 +1,11 @@
package com.mogo.module.extensions.entrance;
import android.content.Context;
import android.view.View;
import android.widget.TextView;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.mogo.module.extensions.utils.EntranceViewHolder;
import com.mogo.service.MogoServicePaths;
import com.mogo.service.entrance.ButtonIndex;
import com.mogo.service.entrance.IMogoEntranceButtonController;
@@ -22,6 +24,21 @@ public class MogoEntranceButtonControllerImpl implements IMogoEntranceButtonCont
return MogoEntranceButtons.getButton( index );
}
@Override
public void addBottomLayerView(View view) {
EntranceViewHolder.getInstance().addBottomLayerView(view);
}
@Override
public void addBottomLayerView(View view, int x, int y) {
EntranceViewHolder.getInstance().addBottomLayerView(view, x, y);
}
@Override
public void removeBottomLayerView(View view) {
EntranceViewHolder.getInstance().removeBottomLayerView(view);
}
@Override
public void init( Context context ) {

View File

@@ -0,0 +1,94 @@
package com.mogo.module.extensions.utils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import com.mogo.module.extensions.bean.BottomLayerViewWrapper;
import com.mogo.utils.logger.Logger;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
/**
* 入口页view管理
* @author tongchenfei
*/
public class EntranceViewHolder {
private static final String TAG = "EntranceViewHolder";
private List<BottomLayerViewWrapper> preAddView = new ArrayList<>();
private EntranceViewHolder(){}
private volatile static EntranceViewHolder instance = null;
public static EntranceViewHolder getInstance(){
if (instance == null) {
synchronized (EntranceViewHolder.class) {
if (instance == null) {
instance = new EntranceViewHolder();
}
}
}
return instance;
}
private ViewGroup rootViewGroup = null;
public void initRootViewGroup(View rootView) {
Logger.i(TAG, "initRootViewGroup==");
if(rootView instanceof ViewGroup) {
Logger.d(TAG, "initRootViewGroup 赋值");
rootViewGroup = (ViewGroup) rootView.getParent();
if (!preAddView.isEmpty()) {
Logger.d(TAG, "initRootViewGroup 增加底层view: " + preAddView.size());
Iterator<BottomLayerViewWrapper> iterator = preAddView.iterator();
while (iterator.hasNext()) {
BottomLayerViewWrapper wrapper = iterator.next();
realAddView(wrapper);
iterator.remove();
}
}
}
}
public void addBottomLayerView(View view) {
Logger.d(TAG, "addBottomLayerView, rootViewGroup is null: " + (rootViewGroup == null));
addBottomLayerView(view, 0, 0);
}
public void addBottomLayerView(View view, int x, int y) {
Logger.d(TAG, "addBottomLayerView, rootViewGroup is null: " + (rootViewGroup == null) +
"\n x: " + x + ", y: " + y);
BottomLayerViewWrapper wrapper = new BottomLayerViewWrapper(view, x, y);
if(rootViewGroup == null) {
preAddView.add(wrapper);
}else{
realAddView(wrapper);
}
}
/**
* 使用的时候需要预先判断rootViewGroup是否为空本方法默认rootViewGroup不为空
*/
private void realAddView(BottomLayerViewWrapper wrapper){
FrameLayout.LayoutParams params =
new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT,
FrameLayout.LayoutParams.WRAP_CONTENT);
params.topMargin = wrapper.getY();
params.leftMargin = wrapper.getX();
View v = wrapper.getView();
v.setLayoutParams(params);
rootViewGroup.addView(v, 0);
}
public void removeBottomLayerView(View view) {
if (rootViewGroup != null) {
rootViewGroup.removeView(view);
}
Iterator<BottomLayerViewWrapper> iterator = preAddView.iterator();
while (iterator.hasNext()) {
BottomLayerViewWrapper wrapper = iterator.next();
if (wrapper.getView().equals(view)) {
iterator.remove();
}
}
}
}

View File

@@ -14,7 +14,7 @@
<include
layout="@layout/include_navi_info_panle"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
android:layout_height="wrap_content" />
<TextView
android:id="@+id/module_ext_id_north"
@@ -30,17 +30,17 @@
android:textSize="@dimen/module_ext_north_textSize"
android:textStyle="bold"
android:visibility="gone"
tools:visibility="visible"
app:layout_constraintRight_toRightOf="@+id/module_entrance_id_upload_road_condition"
app:layout_constraintTop_toBottomOf="@+id/module_map_id_navi_bg"
app:layout_goneMarginTop="@dimen/module_ext_north_goneMarginTop" />
app:layout_goneMarginTop="@dimen/module_ext_north_goneMarginTop"
tools:visibility="visible" />
<com.mogo.module.extensions.navi.TopView
android:id="@+id/module_entrance_id_top_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="true"
android:clickable="true"
android:focusable="true"
app:layout_constraintBottom_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" />
@@ -51,12 +51,12 @@
android:layout_height="@dimen/module_ext_button_height"
android:layout_marginTop="@dimen/module_ext_camera_button_marginTop"
android:background="@drawable/module_ext_dw_common_corner_bkg"
android:orientation="vertical"
android:gravity="center_horizontal"
android:orientation="vertical"
android:visibility="gone"
tools:visibility="gone"
app:layout_constraintLeft_toLeftOf="@+id/module_map_id_navi_bg"
app:layout_constraintTop_toBottomOf="@+id/module_map_id_navi_bg">
app:layout_constraintTop_toBottomOf="@+id/module_map_id_navi_bg"
tools:visibility="gone">
<ImageView
android:id="@+id/module_ext_id_display_overview_icon"
@@ -175,35 +175,46 @@
</LinearLayout>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/btnDebugCtrlTopView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="显示隐藏TopView"
app:layout_constraintLeft_toLeftOf="parent"
android:textSize="20sp"
app:layout_constraintBottom_toBottomOf="parent"
android:textSize="20sp" />
app:layout_constraintLeft_toLeftOf="parent" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/btnDebugCtrlSubView"
android:text="显示隐藏SubView"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintBottom_toTopOf="@id/btnDebugCtrlTopView"
android:textSize="20sp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="显示隐藏SubView"
android:textSize="20sp"
app:layout_constraintBottom_toTopOf="@id/btnDebugCtrlTopView"
app:layout_constraintLeft_toLeftOf="parent" />
<Button
android:id="@+id/btnDebugCtrlNaviView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="显示隐藏导航view"
app:layout_constraintLeft_toLeftOf="parent"
android:textSize="20sp"
app:layout_constraintBottom_toTopOf="@id/btnDebugCtrlSubView"
android:textSize="20sp" />
app:layout_constraintLeft_toLeftOf="parent" />
<Button
android:id="@+id/btnDebugAddBottomLayerView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="增加底层view"
android:textSize="20sp"
app:layout_constraintBottom_toTopOf="@id/btnDebugCtrlNaviView"
app:layout_constraintLeft_toLeftOf="parent" />
<androidx.constraintlayout.widget.Group
android:id="@+id/groupTopViewDebug"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
app:constraint_referenced_ids="btnDebugCtrlNaviView,btnDebugCtrlSubView,btnDebugCtrlTopView"
android:id="@+id/groupTopViewDebug" />
app:constraint_referenced_ids="btnDebugCtrlNaviView,btnDebugCtrlSubView,btnDebugCtrlTopView,btnDebugAddBottomLayerView" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@@ -1,5 +1,6 @@
package com.mogo.service.entrance;
import android.view.View;
import android.widget.TextView;
import com.alibaba.android.arouter.facade.template.IProvider;
@@ -19,4 +20,25 @@ public interface IMogoEntranceButtonController extends IProvider {
* @return
*/
TextView getButton( ButtonIndex index );
/**
* 添加低层级view使用ViewGroup.addView(v,0)实现
* @param view 将要添加的view
*/
void addBottomLayerView(View view);
/**
* 添加低层级view使用ViewGroup.addView(v,0)实现
* 可指定x,y位置
* @param view 将要添加的view
* @param x leftMargin
* @param y topMargin
*/
void addBottomLayerView(View view, int x, int y);
/**
* 移除对应的底层view
* @param view 待移除view
*/
void removeBottomLayerView(View view);
}