优化基础布局

This commit is contained in:
tongchenfei
2021-01-22 09:58:22 +08:00
parent 5e1961eb33
commit 6952cfac94
9 changed files with 106 additions and 57 deletions

View File

@@ -11,7 +11,10 @@ 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.module.common.MogoApisHandler;
import com.mogo.och.view.SlidePanelView;
import com.mogo.service.statusmanager.IMogoStatusChangedListener;
import com.mogo.service.statusmanager.StatusDescriptor;
/**
* 网约车基础Fragment主要负责布局通用界面处理站点面板和通话面板互斥情况
@@ -47,6 +50,20 @@ public abstract class BaseOchFragment<V extends IView, P extends Presenter<V>> e
LayoutInflater.from(getContext()).inflate(getStationPanelViewId(), flStationPanelContainer);
slidePanelView.setOnSlidePanelMoveToEndListener(onSlideToEndListener);
checkCallView(MogoApisHandler.getInstance().getApis().getStatusManagerApi().isCallViewShow());
MogoApisHandler.getInstance().getApis().getStatusManagerApi().registerStatusChangedListener("Och", StatusDescriptor.CALL_VIEW, callViewListener);
}
private void checkCallView(boolean isShown){
if (flStationPanelContainer == null) {
return;
}
if (isShown) {
flStationPanelContainer.setTranslationY(131f);
}else{
flStationPanelContainer.setTranslationY(0f);
}
}
public void showSlidePanle(String text) {
@@ -79,6 +96,18 @@ public abstract class BaseOchFragment<V extends IView, P extends Presenter<V>> e
return null;
}
private final IMogoStatusChangedListener callViewListener = (descriptor, isTrue) -> {
if (descriptor == StatusDescriptor.CALL_VIEW) {
checkCallView(isTrue);
}
};
@Override
public void onDestroyView() {
super.onDestroyView();
MogoApisHandler.getInstance().getApis().getStatusManagerApi().unregisterStatusChangedListener("Och", StatusDescriptor.CALL_VIEW, callViewListener);
}
/**
* 获取站点面板view在{@link #initViews()}时候添加到container中
* @return 站点面板view

View File

@@ -14,7 +14,6 @@ import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.Shader;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.animation.DecelerateInterpolator;
@@ -49,10 +48,15 @@ public class SlidePanelView extends View {
private final Paint blockPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
private final Paint textPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
private static final int BLOCK_START_X = 10;
private static final int BLOCK_START_Y = 10;
private static final int TEXT_MARGIN_LEFT = 20;
private static final int TEXT_MARGIN_RIGHT = 30;
private static final int BLOCK_START_X = 15;
private static final int BLOCK_START_Y = 15;
private static final int NORMAL_TEXT_MARGIN_LEFT = 40;
private static final int NORMAL_TEXT_MARGIN_RIGHT = 50;
private static final int SHORT_TEXT_MARGIN_LEFT = 60;
private static final int SHORT_TEXT_MARGIN_RIGHT = 70;
private int textMarginLeft = NORMAL_TEXT_MARGIN_LEFT;
private int textMarginRight = NORMAL_TEXT_MARGIN_RIGHT;
private OnSlidePanelMoveToEndListener moveToEndListener;
@@ -105,7 +109,7 @@ public class SlidePanelView extends View {
textPaint.setStyle(Paint.Style.FILL);
textPaint.setTextSize(40);
textPaint.setTextAlign(Paint.Align.LEFT);
textGradient = new LinearGradient(-GRADIENT_OFFSET, 0, 0, 0, new int[]{0x33ffffff, 0xffffffff, 0x29ffffff}, new float[]{0, 0.5f, 1f}, Shader.TileMode.CLAMP);
textGradient = new LinearGradient(-GRADIENT_OFFSET, 0, 0, 0, new int[]{0x33ffffff, 0xffffffff, 0x33ffffff}, null, Shader.TileMode.CLAMP);
textGradient.setLocalMatrix(gradientMatrix);
textPaint.setShader(textGradient);
textPaint.getFontMetrics(blockTextMetrics);
@@ -118,17 +122,22 @@ public class SlidePanelView extends View {
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int widthMode = MeasureSpec.getMode(widthMeasureSpec);
int heightMode = MeasureSpec.getMode(heightMeasureSpec);
int widthSize = MeasureSpec.getSize(widthMeasureSpec);
int heightSize = MeasureSpec.getSize(heightMeasureSpec);
int widthSize;
int heightSize;
Log.d(TAG, "onMeasure:\r\n widthMode: " + widthMode + " widthSize: " + widthSize + " \r\n heightMode: " + heightMode + " heightSize: " + heightSize);
if (blockText.length() < 5) {
textMarginLeft = SHORT_TEXT_MARGIN_LEFT;
textMarginRight = SHORT_TEXT_MARGIN_RIGHT;
} else {
textMarginLeft = NORMAL_TEXT_MARGIN_LEFT;
textMarginRight = NORMAL_TEXT_MARGIN_RIGHT;
}
Log.d(TAG, "textMetrics: ascent: " + blockTextMetrics.ascent + " descent: " + blockTextMetrics.descent + " top: " + blockTextMetrics.top + " bottom: " + blockTextMetrics.bottom);
if (widthMode == MeasureSpec.AT_MOST) {
// 宽度根据图片大小,字符串长度,各种间隔确定
// 高度根据图片大小和上下间隔确定
textPaint.getTextBounds(blockText, 0, blockText.length(), textRect);
widthSize = BLOCK_START_X * 2 + bmBlock.getWidth() + TEXT_MARGIN_LEFT + TEXT_MARGIN_RIGHT + textRect.width();
widthSize = BLOCK_START_X * 2 + bmBlock.getWidth() + textMarginLeft + textMarginRight + textRect.width();
heightSize = BLOCK_START_Y * 2 + bmBlock.getHeight();
widthMeasureSpec = MeasureSpec.makeMeasureSpec(widthSize, widthMode);
heightMeasureSpec = MeasureSpec.makeMeasureSpec(heightSize, heightMode);
@@ -148,7 +157,7 @@ public class SlidePanelView extends View {
matrixAnim.cancel();
}
textOffset = (getHeight() - blockTextMetrics.ascent - blockTextMetrics.descent) / 2;
matrixAnim = ObjectAnimator.ofFloat(this, "matrixTranslate", 0, w + GRADIENT_OFFSET).setDuration(1000);
matrixAnim = ObjectAnimator.ofFloat(this, "matrixTranslate", 0, w + GRADIENT_OFFSET).setDuration(2000);
matrixAnim.setRepeatCount(ValueAnimator.INFINITE);
matrixAnim.start();
}
@@ -231,7 +240,7 @@ public class SlidePanelView extends View {
gradientMatrix.setTranslate(matrixTranslate, 0);
textGradient.setLocalMatrix(gradientMatrix);
canvas.save();
canvas.drawText(blockText, blockWidth + BLOCK_START_X + TEXT_MARGIN_LEFT, textOffset, textPaint);
canvas.drawText(blockText, blockWidth + BLOCK_START_X + textMarginLeft, textOffset, textPaint);
canvas.restore();
// 画滑块
canvas.drawBitmap(bmBlock, BLOCK_START_X + blockOffset, BLOCK_START_Y, blockPaint);