//处理点击事件
mainPageAdapter.setOnItemClickListener(item -> {
//打开应用
-
});
looperPage.registerOnPageChangeCallback(onPageChangeCallback);
}
--- /dev/null
+package com.ic.launcher.loop.view;
+
+import android.content.Context;
+import android.util.AttributeSet;
+import android.view.View;
+import android.view.ViewGroup;
+
+import com.ic.iclooger.ICLogger;
+
+public class MarqueeView extends ViewGroup {
+
+ public MarqueeView(Context context) {
+ this(context, null);
+ }
+
+ public MarqueeView(Context context, AttributeSet attrs) {
+ this(context, attrs, 0);
+ }
+
+ public MarqueeView(Context context, AttributeSet attrs, int defStyleAttr) {
+ super(context, attrs, defStyleAttr);
+ }
+
+ public void setMargin(int margin) {
+ this.margin = margin;
+ }
+
+ static class Position {
+ public Position(int left, int top, int right, int bottom) {
+ this.left = left;
+ this.top = top;
+ this.right = right;
+ this.bottom = bottom;
+ }
+
+ public int left = 0;
+ public int top = 0;
+ public int right = 0;
+ public int bottom = 0;
+ }
+
+ private int margin = 0;
+
+ @Override
+ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
+ //测量孩子
+ int childCount = getChildCount();
+ int totalWidth = 0;
+ for (int i = 0; i < childCount; i++) {
+ View item = getChildAt(i);
+ if (item.getVisibility() == GONE) {
+ continue;
+ }
+ int widthSpec = MeasureSpec.makeMeasureSpec(MeasureSpec.getSize(widthMeasureSpec), MeasureSpec.AT_MOST);
+ item.measure(widthSpec, heightMeasureSpec);
+ //ICLogger.d("item.getMeasuredWidth() == > " + item.getMeasuredWidth());
+ //设置孩子的位置,从0开始
+ item.setTag(new Position(totalWidth, 0, totalWidth + item.getMeasuredWidth(), item.getMeasuredHeight()));
+ totalWidth += item.getMeasuredWidth() + margin * 2;
+ }
+ int parentWidth = MeasureSpec.makeMeasureSpec(totalWidth, MeasureSpec.EXACTLY);
+ setMeasuredDimension(parentWidth, heightMeasureSpec);
+ //测量完以后,判断宽度是否够用
+ int defaultWidth = MeasureSpec.getSize(widthMeasureSpec);
+ //如果不够用则滚动,如果够用则不滚动
+ ICLogger.d("default width == > " + totalWidth + " real width == > " + defaultWidth);
+ removeCallbacks(scrollTask);
+ if (totalWidth > defaultWidth) {
+ postDelayed(scrollTask, 1000);
+ }
+ }
+
+
+ //从这个地方开始摆放
+ private final int stepDx = 1;
+
+ private final Runnable scrollTask = new Runnable() {
+ @Override
+ public void run() {
+ updateLayout();
+ postDelayed(this, 100);
+ }
+ };
+
+
+ @Override
+ protected void onLayout(boolean changed, int l, int t, int r, int b) {
+ updateLayout();
+ }
+
+ private void updateLayout() {
+ //摆放孩子
+ int childCount = getChildCount();
+ //从0开始,
+ for (int i = 0; i < childCount; i++) {
+ View item = getChildAt(i);
+ if (item.getVisibility() == GONE) {
+ continue;
+ }
+ //拿到它的位置
+ Position position = (Position) item.getTag();
+ position.left -= stepDx;
+ position.right = position.left + item.getMeasuredWidth();
+ //检查位置是否超了
+ if (position.right <= 0) {
+ //归位到最后面去
+ position.right = getMeasuredWidth() - margin;
+ position.left = position.right - item.getMeasuredWidth();
+ }
+ item.setTag(position);
+ //布局
+ item.layout(position.left, position.top, position.right, position.bottom);
+ }
+ }
+}
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.FrameLayout;
+import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
public class StatusBarView extends FrameLayout {
private StatusBarPresenter statusBarPresenter;
+ private SignalView signalView;
+ private BatteryView batteryView;
+ private TextView batteryValueTv;
public StatusBarView(@NonNull Context context) {
this(context, null);
super(context, attrs, defStyleAttr);
//加载布局
LayoutInflater.from(context).inflate(R.layout.item_status_bar, this);
+ initView();
+ }
+
+ private void initView() {
+ signalView = findViewById(R.id.signal_view);
+ signalView.noNetwork();
+ batteryView = findViewById(R.id.right_battery_view);
+ batteryView.updateCurrentLev(30);
+ batteryValueTv = findViewById(R.id.battery_value);
+ batteryValueTv.setText(30 + "%");
+ MarqueeView marqueeView = findViewById(R.id.mar_queue_view);
}
public void initPresenter(LifecycleOwner lifecycleOwner) {
android:id="@+id/status_bar"
android:layout_width="match_parent"
android:layout_height="34dp"
- android:background="#00ffaa"
android:visibility="gone"
app:layout_constraintTop_toTopOf="parent" />
<com.ic.launcher.loop.view.SignalView
- android:layout_width="wrap_content"
android:id="@+id/signal_view"
+ android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent" />
+ <com.ic.launcher.loop.view.MarqueeView
+ android:id="@+id/mar_queue_view"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:layout_marginLeft="40dp"
+ android:layout_marginRight="90dp"
+ app:layout_constraintBottom_toBottomOf="parent">
+
+ <ImageView
+ android:id="@+id/top_icon_wifi"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:src="@mipmap/top_icon_wifi"
+ android:visibility="gone" />
+
+ <ImageView
+ android:id="@+id/top_icon_location"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:src="@mipmap/top_icon_location"
+ android:visibility="gone" />
+
+
+ <ImageView
+ android:id="@+id/top_icon_bt"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:src="@mipmap/top_icon_bt"
+ android:visibility="gone" />
+
+
+ <ImageView
+ android:id="@+id/top_icon_connected"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:src="@mipmap/top_icon_connected"
+ android:visibility="gone" />
+
+ <ImageView
+ android:id="@+id/top_warning_msg_un_read"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:src="@mipmap/top_icon_warning_msg_un_read"
+ android:visibility="gone" />
+ <ImageView
+ android:id="@+id/top_icon_alarm"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:src="@mipmap/top_alarm_open"
+ android:visibility="gone" />
+
+
+ <ImageView
+ android:id="@+id/top_icon_new_msg"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:src="@mipmap/top_icon_new_msg"
+ android:visibility="gone" />
+
+
+ <ImageView
+ android:id="@+id/top_icon_phone"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:src="@mipmap/top_icon_miss_phone"
+ android:visibility="gone" />
+
+ </com.ic.launcher.loop.view.MarqueeView>
<TextView
+ android:id="@+id/battery_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:text="12:12"
+ android:layout_marginRight="5dp"
+ android:text="100%"
android:textColor="@color/white"
- android:textSize="22sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
+ app:layout_constraintRight_toLeftOf="@id/right_battery_view"
+ app:layout_constraintTop_toTopOf="parent" />
+
+ <com.ic.launcher.loop.view.BatteryView
+ android:id="@+id/right_battery_view"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent" />