添加BaseOchFragment

This commit is contained in:
tongchenfei
2021-01-21 15:45:34 +08:00
parent a46aaa1110
commit 5e1961eb33
14 changed files with 314 additions and 87 deletions

1
.idea/gradle.xml generated
View File

@@ -89,6 +89,7 @@
</set>
</option>
<option name="resolveModulePerSourceSet" value="false" />
<option name="useQualifiedModuleNames" value="true" />
</GradleProjectSettings>
</option>
</component>

View File

@@ -1,5 +1,6 @@
package com.mogo.och.bus.fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
@@ -10,9 +11,11 @@ import androidx.constraintlayout.widget.Group;
import com.mogo.commons.mvp.MvpFragment;
import com.mogo.module.common.MogoApisHandler;
import com.mogo.module.common.view.OnPreventFastClickListener;
import com.mogo.och.BaseOchFragment;
import com.mogo.och.bus.R;
import com.mogo.och.bus.bean.OchBusStation;
import com.mogo.och.bus.presenter.OchBusPresenter;
import com.mogo.och.view.SlidePanelView;
import com.mogo.service.adas.entity.AdasOCHData;
import com.mogo.utils.logger.Logger;
@@ -25,36 +28,36 @@ import java.util.List;
*
* @author tongchenfei
*/
public class OchBusFragment extends MvpFragment<OchBusFragment, OchBusPresenter> {
public class OchBusFragment extends BaseOchFragment<OchBusFragment, OchBusPresenter> implements SlidePanelView.OnSlidePanelMoveToEndListener {
private static final String TAG = "OchBusFragment";
private final List<OchBusStation> stationList = new ArrayList<>();
private Button btnExecute;
private TextView tvNotice;
@Override
protected int getLayoutId() {
return R.layout.fragment_och_bus;
}
@Override
protected void initViews() {
findViewById(R.id.btnEnterOchBus).setOnClickListener(new OnPreventFastClickListener() {
@Override
public void onClickImpl(View v) {
showOchBus();
}
super.initViews();
// findViewById(R.id.btnEnterOchBus).setOnClickListener(new OnPreventFastClickListener() {
// @Override
// public void onClickImpl(View v) {
// showOchBus();
// }
// });
// findViewById(R.id.btnArrive).setOnClickListener(view->{
// mPresenter.onArriveAt(new AdasOCHData(10, nextStation.getLon(), nextStation.getLat()));
// });
// btnExecute = findViewById(R.id.btnExecute);
// btnExecute.setOnClickListener(new OnPreventFastClickListener() {
// @Override
// public void onClickImpl(View v) {
// mPresenter.autoDriveToNextStation();
// }
// });
tvNotice = findViewById(R.id.module_mogo_och_bus_station_notice);
tvNotice.setOnClickListener(view->{
showSlidePanle("到达站点,乘客以下车");
});
findViewById(R.id.btnArrive).setOnClickListener(view->{
mPresenter.onArriveAt(new AdasOCHData(10, nextStation.getLon(), nextStation.getLat()));
});
btnExecute = findViewById(R.id.btnExecute);
btnExecute.setOnClickListener(new OnPreventFastClickListener() {
@Override
public void onClickImpl(View v) {
mPresenter.autoDriveToNextStation();
}
});
tvNotice = findViewById(R.id.vBusRoute);
}
@NonNull
@@ -66,7 +69,7 @@ public class OchBusFragment extends MvpFragment<OchBusFragment, OchBusPresenter>
public void showOchBus() {
MogoApisHandler.getInstance().getApis().getTopViewManager().removeAllViewInVrMode();
tvNotice.setVisibility(View.VISIBLE);
// tvNotice.setVisibility(View.VISIBLE);
}
@Override
@@ -98,32 +101,32 @@ public class OchBusFragment extends MvpFragment<OchBusFragment, OchBusPresenter>
// todo 渲染小巴路线数据
stationList.clear();
stationList.addAll(busStationList);
for (int i = 0; i < stationList.size(); i++) {
OchBusStation station = stationList.get(i);
if (station.getIsCurrentSite() == OchBusPresenter.STATION_STATUS_LEAVING) {
tvNotice.setText("正在从 " + i + "站驶向" + (i + 1) + "");
nextStation = stationList.get(i + 1);
btnExecute.setVisibility(View.GONE);
break;
} else if (station.getIsCurrentSite() == OchBusPresenter.STATION_STATUS_STOPED) {
tvNotice.setText("车辆正停在" + i + "");
btnExecute.setVisibility(View.VISIBLE);
if (i == stationList.size() - 1) {
btnExecute.setText("单程结束");
}else if(i == 0){
btnExecute.setText("准备出发");
}else{
btnExecute.setText("乘客已上车,准备出发");
}
break;
}
}
// for (int i = 0; i < stationList.size(); i++) {
// OchBusStation station = stationList.get(i);
// if (station.getIsCurrentSite() == OchBusPresenter.STATION_STATUS_LEAVING) {
// tvNotice.setText("正在从 " + i + "站驶向" + (i + 1) + "站");
// nextStation = stationList.get(i + 1);
// btnExecute.setVisibility(View.GONE);
// break;
// } else if (station.getIsCurrentSite() == OchBusPresenter.STATION_STATUS_STOPED) {
// tvNotice.setText("车辆正停在" + i + "站");
// btnExecute.setVisibility(View.VISIBLE);
// if (i == stationList.size() - 1) {
// btnExecute.setText("单程结束");
// }else if(i == 0){
// btnExecute.setText("准备出发");
// }else{
// btnExecute.setText("乘客已上车,准备出发");
// }
// break;
// }
// }
}
});
}
public void hideOchBus() {
tvNotice.setVisibility(View.GONE);
// tvNotice.setVisibility(View.GONE);
}
private void queryStationListIfNecessary() {
@@ -131,4 +134,22 @@ public class OchBusFragment extends MvpFragment<OchBusFragment, OchBusPresenter>
mPresenter.queryBusRoutes();
}
}
@Override
public int getStationPanelViewId() {
return R.layout.fragment_och_bus;
}
@Override
public SlidePanelView.OnSlidePanelMoveToEndListener getSlidePanelOnEndListener() {
return this;
}
private boolean isInAutopilot;
@Override
public void moveToEnd() {
onAutopilotStatusChanged(isInAutopilot);
isInAutopilot = !isInAutopilot;
}
}

View File

@@ -1,45 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
<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">
<Button
android:id="@+id/btnEnterOchBus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="进入网约车小巴"
android:textSize="40sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent" />
<Button
android:id="@+id/btnExecute"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="准备出发"
android:textSize="30sp"
app:layout_constraintRight_toRightOf="@id/vBusRoute"
app:layout_constraintTop_toBottomOf="@id/vBusRoute" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/btnArrive"
android:text="到达"
android:textSize="30sp"
app:layout_constraintRight_toLeftOf="@id/vBusRoute"
app:layout_constraintTop_toTopOf="@id/vBusRoute" />
android:layout_width="@dimen/module_mogo_och_bus_station_panel_width"
android:layout_height="@dimen/module_mogo_och_bus_station_panel_height">
<TextView
android:id="@+id/vBusRoute"
android:layout_width="600px"
android:layout_height="300px"
android:background="#0f0"
android:gravity="center"
android:text="notice"
android:textSize="30sp"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/module_mogo_och_bus_station_notice"
android:text="站点信息"
android:textSize="@dimen/module_mogo_och_bus_station_notice_text_size"
android:textColor="#fff"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- 本套资源适配分体机xhdpi -->
<dimen name="module_mogo_och_bus_station_notice_text_size">24px</dimen>
<dimen name="module_mogo_och_bus_station_panel_width">464px</dimen>
<dimen name="module_mogo_och_bus_station_panel_height">310px</dimen>
</resources>

View File

@@ -39,6 +39,18 @@ dependencies {
implementation rootProject.ext.dependencies.androidxappcompat
implementation rootProject.ext.dependencies.arouter
annotationProcessor rootProject.ext.dependencies.aroutercompiler
implementation rootProject.ext.dependencies.androidxconstraintlayout
if (Boolean.valueOf(RELEASE)) {
implementation rootProject.ext.dependencies.mogoutils
implementation rootProject.ext.dependencies.mogocommons
implementation rootProject.ext.dependencies.modulecommon
} else {
implementation project(":foudations:mogo-utils")
implementation project(":foudations:mogo-commons")
implementation project(":modules:mogo-module-common")
}
}
apply from: new File(rootProject.rootDir, "gradle/upload.gradle").toString()

View File

@@ -0,0 +1,87 @@
package com.mogo.och;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.CheckedTextView;
import android.widget.FrameLayout;
import android.widget.TextView;
import androidx.fragment.app.Fragment;
import com.mogo.commons.mvp.IView;
import com.mogo.commons.mvp.MvpFragment;
import com.mogo.commons.mvp.Presenter;
import com.mogo.och.view.SlidePanelView;
/**
* 网约车基础Fragment主要负责布局通用界面处理站点面板和通话面板互斥情况
*
* @author tongchenfei
*/
public abstract class BaseOchFragment<V extends IView, P extends Presenter<V>> extends MvpFragment<V, P> {
private SlidePanelView slidePanelView;
private TextView tvNotice;
private CheckedTextView ctvAutopilotStatus;
private FrameLayout flStationPanelContainer;
private final SlidePanelView.OnSlidePanelMoveToEndListener onSlideToEndListener = () -> {
// 此处做一个代理,处理一下共有情况
hideSlidePanel();
hideNotice();
if (getSlidePanelOnEndListener() != null) {
getSlidePanelOnEndListener().moveToEnd();
}
};
@Override
protected int getLayoutId() {
return R.layout.module_mogo_och_base_fragment;
}
@Override
protected void initViews() {
slidePanelView = findViewById(R.id.module_mogo_och_slide_panel);
tvNotice = findViewById(R.id.module_mogo_och_notice);
ctvAutopilotStatus = findViewById(R.id.module_mogo_och_autopilot_status);
flStationPanelContainer = findViewById(R.id.module_mogo_och_station_panel_container);
LayoutInflater.from(getContext()).inflate(getStationPanelViewId(), flStationPanelContainer);
slidePanelView.setOnSlidePanelMoveToEndListener(onSlideToEndListener);
}
public void showSlidePanle(String text) {
slidePanelView.setText(text);
slidePanelView.setVisibility(View.VISIBLE);
}
public void hideSlidePanel(){
slidePanelView.setVisibility(View.GONE);
}
public void showNotice(String notice) {
tvNotice.setText(notice);
tvNotice.setVisibility(View.VISIBLE);
}
public void hideNotice(){
tvNotice.setVisibility(View.GONE);
}
/**
* 改变自动驾驶状态
* @param isInAutopilot true - 在自动驾驶中 false - 不在自动驾驶中
*/
public void onAutopilotStatusChanged(boolean isInAutopilot) {
ctvAutopilotStatus.setChecked(isInAutopilot);
}
public SlidePanelView.OnSlidePanelMoveToEndListener getSlidePanelOnEndListener(){
return null;
}
/**
* 获取站点面板view在{@link #initViews()}时候添加到container中
* @return 站点面板view
*/
public abstract int getStationPanelViewId();
}

View File

@@ -76,6 +76,8 @@ public class SlidePanelView extends View {
private String blockText = STRING_SLIDE_TO_RIGHT;
private Paint.FontMetrics blockTextMetrics = new Paint.FontMetrics();
private static final int GRADIENT_OFFSET = 200;
public void setOnSlidePanelMoveToEndListener(OnSlidePanelMoveToEndListener moveToEndListener) {
this.moveToEndListener = moveToEndListener;
}
@@ -97,13 +99,13 @@ public class SlidePanelView extends View {
}
private void init() {
bgPaint.setColor(Color.RED);
bgPaint.setColor(Color.parseColor("#CC0F1325"));
bgPaint.setStyle(Paint.Style.FILL);
textPaint.setStyle(Paint.Style.FILL);
textPaint.setTextSize(40);
textPaint.setTextAlign(Paint.Align.LEFT);
textGradient = new LinearGradient(-80, 0, 0, 0, new int[]{0xffffffff, 0xff000000, 0xffffffff}, new float[]{0, 0.5f, 1f}, Shader.TileMode.CLAMP);
textGradient = new LinearGradient(-GRADIENT_OFFSET, 0, 0, 0, new int[]{0x33ffffff, 0xffffffff, 0x29ffffff}, new float[]{0, 0.5f, 1f}, Shader.TileMode.CLAMP);
textGradient.setLocalMatrix(gradientMatrix);
textPaint.setShader(textGradient);
textPaint.getFontMetrics(blockTextMetrics);
@@ -146,7 +148,7 @@ public class SlidePanelView extends View {
matrixAnim.cancel();
}
textOffset = (getHeight() - blockTextMetrics.ascent - blockTextMetrics.descent) / 2;
matrixAnim = ObjectAnimator.ofFloat(this, "matrixTranslate", 0, w + 80).setDuration(1000);
matrixAnim = ObjectAnimator.ofFloat(this, "matrixTranslate", 0, w + GRADIENT_OFFSET).setDuration(1000);
matrixAnim.setRepeatCount(ValueAnimator.INFINITE);
matrixAnim.start();
}

View File

@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/module_mogo_och_autopilot_text_color_checked" android:state_checked="true" />
<item android:color="@color/module_mogo_och_autopilot_text_color_normal"/>
</selector>

View File

Before

Width:  |  Height:  |  Size: 7.3 KiB

After

Width:  |  Height:  |  Size: 7.3 KiB

View File

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="@dimen/module_mogo_och_autopilot_status_bg_corner" />
<gradient
android:startColor="#FF405591"
android:endColor="#FF28376B"
android:angle="315"/>
</shape>

View File

@@ -0,0 +1,69 @@
<?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:paddingStart="@dimen/module_mogo_och_margin_left"
android:paddingTop="@dimen/module_mogo_och_margin_top"
android:paddingEnd="@dimen/module_mogo_och_margin_right"
android:paddingBottom="@dimen/module_mogo_och_margin_bottom">
<FrameLayout
android:id="@+id/module_mogo_och_station_panel_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/module_mogo_och_station_panel_container_margin_top_no_call"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<!-- <View-->
<!-- android:layout_width="@dimen/module_mogo_och_autopilot_status_bg_width"-->
<!-- android:layout_height="@dimen/module_mogo_och_autopilot_status_bg_height"-->
<!-- android:id="@+id/module_mogo_och_autopilot_status_bg"-->
<!-- android:background="@drawable/module_mogo_och_autopilot_status_bg"-->
<!-- app:layout_constraintLeft_toLeftOf="parent"-->
<!-- app:layout_constraintBottom_toBottomOf="parent"/>-->
<!-- <TextView-->
<!-- android:layout_width="wrap_content"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:id="@+id/module_mogo_och_"-->
<CheckedTextView
android:id="@+id/module_mogo_och_autopilot_status"
android:layout_width="@dimen/module_mogo_och_autopilot_status_bg_width"
android:layout_height="@dimen/module_mogo_och_autopilot_status_bg_height"
android:background="@drawable/module_mogo_och_autopilot_status_bg"
android:drawableTop="@drawable/icon_heart_choose"
android:drawablePadding="@dimen/module_mogo_och_autopilot_status_text_drawable_padding"
android:gravity="center"
android:paddingTop="@dimen/module_mogo_och_autopilot_status_text_padding_top"
android:text="自动驾驶"
android:textColor="@color/module_mogo_och_autopilot_text_color_selector"
android:textSize="@dimen/module_mogo_och_autopilot_status_text_size"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent" />
<com.mogo.och.view.SlidePanelView
android:id="@+id/module_mogo_och_slide_panel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" />
<TextView
android:id="@+id/module_mogo_och_notice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#FF2254B1"
android:maxWidth="@dimen/module_mogo_och_notice_text_max_width"
android:text="请携带好随身物品,注意侧后方来车,感谢体验蘑菇智行自动驾驶车!"
android:textColor="#fff"
android:textSize="@dimen/module_mogo_och_notice_text_size"
android:visibility="gone"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="module_mogo_och_autopilot_text_color_normal">#B2FFFFFF</color>
<color name="module_mogo_och_autopilot_text_color_checked">#FF52BBFF</color>
</resources>

View File

@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- 此资源适配分体机 xhdpi -->
<dimen name="module_mogo_och_margin_left">37px</dimen>
<dimen name="module_mogo_och_margin_right">40px</dimen>
<dimen name="module_mogo_och_margin_bottom">40px</dimen>
<dimen name="module_mogo_och_margin_top">24px</dimen>
<dimen name="module_mogo_och_station_panel_container_margin_top_no_call">362px</dimen>
<dimen name="module_mogo_och_station_panel_container_margin_top_with_call">492px</dimen>
<dimen name="module_mogo_och_autopilot_status_bg_corner">24px</dimen>
<dimen name="module_mogo_och_autopilot_status_bg_width">120px</dimen>
<dimen name="module_mogo_och_autopilot_status_bg_height">120px</dimen>
<dimen name="module_mogo_och_autopilot_status_text_size">20px</dimen>
<dimen name="module_mogo_och_autopilot_status_text_padding_top">25px</dimen>
<dimen name="module_mogo_och_autopilot_status_text_drawable_padding">12px</dimen>
<dimen name="module_mogo_och_notice_text_max_width">460px</dimen>
<dimen name="module_mogo_och_notice_text_size">30px</dimen>
</resources>

View File

@@ -9,6 +9,7 @@ import com.alibaba.android.arouter.facade.annotation.Route;
import com.mogo.commons.debug.DebugConfig;
import com.mogo.httpdns.HttpDnsConst;
import com.mogo.httpdns.IHttpDnsCallback;
import com.mogo.httpdns.IHttpDnsLocationChanged;
import com.mogo.httpdns.IHttpDnsTtlCallback;
import com.mogo.httpdns.IMogoHttpDns;
import com.mogo.utils.logger.Logger;
@@ -97,6 +98,11 @@ class TencentHttpDns implements IMogoHttpDns, HttpDns {
}
}
@Override
public String syncGetHttpDns(String host, int type, boolean useCache) {
return null;
}
@Override
public void addHttpDnsTtlCallback( String host,int type, IHttpDnsTtlCallback callback ) {
HttpDnsIpsCache.addHttpDnsTtlCallback( host, callback );
@@ -107,6 +113,11 @@ class TencentHttpDns implements IMogoHttpDns, HttpDns {
HttpDnsIpsCache.removeHttpDnsTtlCallback( host );
}
@Override
public void init(Context context, IHttpDnsLocationChanged locationChanged) {
}
@Keep
@Override
public void init( Context context ) {