--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+ <component name="VcsDirectoryMappings">
+ <mapping directory="$PROJECT_DIR$" vcs="Git" />
+ </component>
+</project>
\ No newline at end of file
--- /dev/null
+package com.ic.launcher.loop;
+
+public class App {
+}
--- /dev/null
+package com.ic.launcher.view;
+
+import android.content.Context;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import android.graphics.Canvas;
+import android.graphics.Paint;
+import android.util.AttributeSet;
+import android.view.View;
+
+import androidx.annotation.Nullable;
+
+import com.ic.launcher.R;
+import com.ic.launcher.util.ICLogger;
+
+public class BatteryView extends View {
+
+ private int width;
+ private int height;
+ private int mCurrentLevel;
+ private Paint paint;
+ private int picWidth;
+ private int picHeight;
+ private BitmapFactory.Options options;
+ private Bitmap chargingPic;
+ private BatteryMode mCurrentMode = BatteryMode.NORMAL;
+
+ public BatteryView(Context context) {
+ this(context, null);
+ }
+
+ public BatteryView(Context context, @Nullable AttributeSet attrs) {
+ this(context, attrs, 0);
+ }
+
+ public BatteryView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
+ super(context, attrs, defStyleAttr);
+ paint = new Paint();
+ paint.setFlags(Paint.ANTI_ALIAS_FLAG);
+ options = new BitmapFactory.Options();
+ options.inScaled = false;
+ Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.battery_level_save_100, options);
+ picWidth = bitmap.getWidth();
+ picHeight = bitmap.getHeight();
+ //加载静态图片列表
+ initResource();
+ chargingPic = BitmapFactory.decodeResource(getResources(), R.mipmap.charge_state, options);
+ }
+
+ //充电状态图标变化
+ private final int[] chargeBatteryRes = new int[6];
+ //普通状态图标
+ private final int[] normalBatteryRes = new int[7];
+ //省电模式图标
+ private final int[] saveModeBatteryRes = new int[7];
+
+ @Override
+ protected void onSizeChanged(int w, int h, int oldw, int oldh) {
+ super.onSizeChanged(w, h, oldw, oldh);
+ width = w;
+ height = h;
+ }
+
+
+ private boolean isCharging = false;
+
+ public void charging(boolean isCharging) {
+ //充电状态,播放动画,显示充电图标
+ this.isCharging = isCharging;
+ //充电,并且不是100%的电量
+ if (isCharging && mCurrentLevel != 100) {
+ post(task);
+ } else {
+ //显示当前电量图标
+ showCurrentLev();
+ }
+ }
+
+ //更新当前电量图标
+ public void updateCurrentLev(int level) {
+ if (level > 100 || level < 0) {
+ throw new IllegalArgumentException("level range must in [0,100]");
+ }
+ this.mCurrentLevel = level;
+ showCurrentLev();
+ }
+
+ @Override
+ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
+ ICLogger.d("picWidth == > " + picWidth + " picHeight == > " + picHeight);
+ setMeasuredDimension(picWidth, picHeight);
+ }
+
+ private int currentDrawPic = -1;
+
+ public enum BatteryMode {
+ SAVE, NORMAL
+ }
+
+ public void updateMode(BatteryMode mode) {
+ this.mCurrentMode = mode;
+ }
+
+ private void showCurrentLev() {
+ loopIndex = 0;
+ //停掉所有的动画
+ removeCallbacks(task);
+ //对当前电量进行转换
+ int index;
+ if (mCurrentLevel < 5) {
+ index = 0;
+ } else if (mCurrentLevel < 20) {
+ index = 1;
+ } else if (mCurrentLevel < 40) {
+ index = 2;
+ } else if (mCurrentLevel < 60) {
+ index = 3;
+ } else if (mCurrentLevel < 80) {
+ index = 4;
+ } else if (mCurrentLevel < 99) {
+ index = 5;
+ } else {
+ index = 6;
+ }
+ ICLogger.d("current index == > " + index);
+ //判断是不是省电模式
+ if (mCurrentMode == BatteryMode.NORMAL) {
+ currentDrawPic = normalBatteryRes[index];
+ } else {
+ currentDrawPic = saveModeBatteryRes[index];
+ }
+ invalidate();
+ }
+
+ @Override
+ public void draw(Canvas canvas) {
+ super.draw(canvas);
+ if (currentDrawPic == -1) {
+ return;
+ }
+ //绘制内容
+ //电量图标
+ Bitmap bitmap = BitmapFactory.decodeResource(getResources(), currentDrawPic, options);
+ canvas.drawBitmap(bitmap, 0, 0, paint);
+ //是否要绘制充电中的图标
+ if (isCharging) {
+ int left = width / 2 - chargingPic.getWidth() / 2;
+ canvas.drawBitmap(chargingPic, left, 0, paint);
+ }
+ }
+
+ private int loopIndex = 0;
+
+ private final Runnable task = new Runnable() {
+ @Override
+ public void run() {
+ if (loopIndex >= chargeBatteryRes.length) {
+ loopIndex = 0;
+ }
+ //循环读取内容
+ currentDrawPic = chargeBatteryRes[loopIndex];
+ invalidate();
+ loopIndex++;
+ postDelayed(this, 1000);
+ }
+ };
+
+
+ private void initResource() {
+ //充电变化的图标
+ chargeBatteryRes[0] = R.mipmap.battery_chage_0;
+ chargeBatteryRes[1] = R.mipmap.battery_level_20;
+ chargeBatteryRes[2] = R.mipmap.battery_level_40;
+ chargeBatteryRes[3] = R.mipmap.battery_level_60;
+ chargeBatteryRes[4] = R.mipmap.battery_level_80;
+ chargeBatteryRes[5] = R.mipmap.battery_level_100;
+ //普通状态图标
+ normalBatteryRes[0] = R.mipmap.battery_level_0;
+ normalBatteryRes[1] = R.mipmap.battery_level_10;
+ normalBatteryRes[2] = R.mipmap.battery_level_save_20;
+ normalBatteryRes[3] = R.mipmap.battery_level_40;
+ normalBatteryRes[4] = R.mipmap.battery_level_60;
+ normalBatteryRes[5] = R.mipmap.battery_level_80;
+ normalBatteryRes[6] = R.mipmap.battery_level_100;
+ //省电模式状态图标
+ saveModeBatteryRes[0] = R.mipmap.battery_level_0;
+ saveModeBatteryRes[1] = R.mipmap.battery_level_10;
+ saveModeBatteryRes[2] = R.mipmap.battery_level_save_20;
+ saveModeBatteryRes[3] = R.mipmap.battery_level_save_40;
+ saveModeBatteryRes[4] = R.mipmap.battery_level_save_60;
+ saveModeBatteryRes[5] = R.mipmap.battery_level_save_80;
+ saveModeBatteryRes[6] = R.mipmap.battery_level_save_100;
+ }
+}
--- /dev/null
+package com.ic.launcher.view;
+
+import android.content.Context;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import android.graphics.Canvas;
+import android.graphics.Paint;
+import android.text.TextUtils;
+import android.util.AttributeSet;
+import android.view.View;
+
+import androidx.annotation.Nullable;
+
+import com.ic.launcher.R;
+import com.ic.launcher.util.ICLogger;
+
+public class SignalView extends View {
+
+ private Bitmap noSimCarPic;
+
+ public String showText = "";
+ private int totalWidth;
+ private int targetHeight;
+ private float textWidth;
+ private Paint textPaint;
+ private Paint picPaint;
+ private BitmapFactory.Options options;
+ private Bitmap bitmap;
+ private int width;
+
+ public SignalView(Context context) {
+ this(context, null);
+ }
+
+ public SignalView(Context context, @Nullable AttributeSet attrs) {
+ this(context, attrs, 0);
+ }
+
+ public SignalView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
+ super(context, attrs, defStyleAttr);
+ options = new BitmapFactory.Options();
+ options.inScaled = false;
+ //获取到图片的长宽
+ textPaint = new Paint();
+ textPaint.setFlags(Paint.ANTI_ALIAS_FLAG);
+ textPaint.setStyle(Paint.Style.STROKE);
+ textPaint.setColor(getResources().getColor(R.color.white));
+ textPaint.setTextSize(12.0f);
+ noSimCarPic = BitmapFactory.decodeResource(getResources(), R.mipmap.top_no_sim_card, options);
+ targetHeight = noSimCarPic.getHeight();
+ width = noSimCarPic.getWidth();
+ retestSize();
+ //绘制图片的画笔
+ picPaint = new Paint();
+ picPaint.setFlags(Paint.ANTI_ALIAS_FLAG);
+ initPicRes();
+ }
+
+ private void retestSize() {
+ textWidth = textPaint.measureText(showText);
+ totalWidth = (int) (textWidth + width);
+ ICLogger.d("textWidth == > " + textWidth + " totalWidth == > " + totalWidth);
+ }
+
+ private final int[] picsResArray = new int[5];
+
+ //初始化图片资源
+ private void initPicRes() {
+ picsResArray[0] = R.mipmap.top_signal_0;
+ picsResArray[1] = R.mipmap.top_signal_1;
+ picsResArray[2] = R.mipmap.top_signal_2;
+ picsResArray[3] = R.mipmap.top_signal_3;
+ picsResArray[4] = R.mipmap.top_signal_4;
+ }
+
+ private int currentPic = R.mipmap.top_no_sim_card;
+
+ private boolean isNoNetwork = false;
+
+ //没有网络
+ public void noNetwork() {
+ isNoNetwork = true;
+ //显示图片图标
+ this.currentPic = R.mipmap.top_no_sim_card;
+ //清空文字
+ this.showText = "";
+ retestSize();
+ updateBitMap();
+ invalidate();
+ }
+
+ private void updateBitMap() {
+ bitmap = BitmapFactory.decodeResource(getResources(), currentPic, options);
+ }
+
+ public void updateNetworkType(String text) {
+ this.isNoNetwork = false;
+ showText = text;
+ retestSize();
+ invalidate();
+ }
+
+ public void updateLev(int lev) {
+ ICLogger.d("update level..." + lev);
+ if (lev < 0 || lev > 5 || isNoNetwork) {
+ return;
+ }
+ //根据信号去显示对应的图标
+ //把lev转成Index
+ currentPic = picsResArray[lev - 1];
+ updateBitMap();
+ invalidate();
+ }
+
+ @Override
+ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
+ ICLogger.d("onMeasure...");
+ setMeasuredDimension(totalWidth, targetHeight);
+ }
+
+ @Override
+ protected void onDraw(Canvas canvas) {
+ if (!TextUtils.isEmpty(showText)) {
+ canvas.drawText(showText, totalWidth - textWidth,
+ targetHeight / 2, textPaint);
+ }
+ if (bitmap == null) {
+ return;
+ }
+ //判断状态
+ canvas.drawBitmap(bitmap, 0, 0, picPaint);
+ }
+}
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<androidx.constraintlayout.widget.ConstraintLayout
+ xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
+ android:layout_height="match_parent">
+
+</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
--- /dev/null
+<?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">
+
+
+ <com.ic.launcher.loop.view.SignalView
+ android:layout_width="wrap_content"
+ android:id="@+id/signal_view"
+ android:layout_height="wrap_content"
+ app:layout_constraintBottom_toBottomOf="parent"
+ app:layout_constraintLeft_toLeftOf="parent" />
+
+
+ <TextView
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="12:12"
+ android:textColor="@color/white"
+ android:textSize="22sp"
+ android:textStyle="bold"
+ app:layout_constraintBottom_toBottomOf="parent"
+ app:layout_constraintRight_toRightOf="parent" />
+
+
+</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file