添加BaseOchFragment
This commit is contained in:
87
OCH/mogo-och/src/main/java/com/mogo/och/BaseOchFragment.java
Normal file
87
OCH/mogo-och/src/main/java/com/mogo/och/BaseOchFragment.java
Normal 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();
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user