version:2.6
fix: update:修改主页图标,布局
This commit is contained in:
@@ -104,10 +104,10 @@ public class MainActivity extends BaseActivity implements MainContact.MainView {
|
||||
|
||||
is_twoscreen = Settings.Global.getInt(getContentResolver(), "is_twoscreen", 1) == 1;
|
||||
if (is_twoscreen) {
|
||||
appListIndex = 2;
|
||||
defaultCurrent = 1;
|
||||
mSecondFragment = new SecondFragment();
|
||||
mFragments.add(mSecondFragment);
|
||||
// appListIndex = 2;
|
||||
// defaultCurrent = 1;
|
||||
// mSecondFragment = new SecondFragment();
|
||||
// mFragments.add(mSecondFragment);
|
||||
}
|
||||
mCustomFragment = new CustomFragment();
|
||||
mFragments.add(mCustomFragment);
|
||||
|
||||
@@ -9,6 +9,8 @@ import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkCapabilities;
|
||||
import android.net.NetworkInfo;
|
||||
@@ -72,6 +74,7 @@ import com.uiuios.aios.network.URLAddress;
|
||||
import com.uiuios.aios.tpush.MessageReceiver;
|
||||
import com.uiuios.aios.utils.ApkUtils;
|
||||
import com.uiuios.aios.utils.AppUtil;
|
||||
import com.uiuios.aios.utils.BitmapUtils;
|
||||
import com.uiuios.aios.utils.NetStateUtils;
|
||||
import com.uiuios.aios.utils.SchemeUtils;
|
||||
import com.uiuios.aios.utils.ToastUtil;
|
||||
@@ -153,18 +156,19 @@ public class CustomFragment extends BaseFragment implements CustomContact.Custom
|
||||
@BindView(R.id.rv_sos)
|
||||
RecyclerView rv_sos;
|
||||
@BindView(R.id.iv_note_nodata)
|
||||
TextView iv_note_nodata;
|
||||
ImageView iv_note_nodata;
|
||||
// @BindView(R.id.iv_head)
|
||||
// ImageView iv_head;
|
||||
@BindView(R.id.tv_name)
|
||||
TextView tv_name;
|
||||
@BindView(R.id.iv_app)
|
||||
ImageView iv_app;
|
||||
|
||||
@BindView(R.id.iv_battery)
|
||||
ImageView iv_battery;
|
||||
|
||||
private static final String TAG = CustomFragment.class.getSimpleName();
|
||||
// private int[] mShaderColors = new int[]{0xFFfa3db5, 0xFFF8867E, 0xFFF79F6B, 0xFFF79F6B, 0xFFF79F6B, 0xFFF8867E, 0xFFfa3db5};
|
||||
private int[] mShaderColors = new int[]{0xFFff9300, 0xFFff9300, 0xFFff9300, 0xFFff9300, 0xFFff9300, 0xFFff9300, 0xFFff9300};
|
||||
private int[] mShaderColors = new int[]{0xFF05d192, 0xFF05d192, 0xFF05d192, 0xFF05d192, 0xFF05d192, 0xFF05d192, 0xFF05d192};
|
||||
private int[] mShaderColorsRed = new int[]{0xFFFF0000, 0xFFFF0000, 0xFFFF0000, 0xFFFF0000, 0xFFFF0000, 0xFFFF0000, 0xFFFF0000};
|
||||
private View rootView;
|
||||
private List<AlarmItem> alarmItemList;
|
||||
@@ -351,6 +355,10 @@ public class CustomFragment extends BaseFragment implements CustomContact.Custom
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
String action = intent.getAction();
|
||||
if (Intent.ACTION_BATTERY_CHANGED.equals(action)) {
|
||||
//你可以读到充电状态,如果在充电,可以读到是usb还是交流电
|
||||
int status = intent.getIntExtra(BatteryManager.EXTRA_STATUS, -1);
|
||||
boolean isCharging = status == BatteryManager.BATTERY_STATUS_CHARGING ||
|
||||
status == BatteryManager.BATTERY_STATUS_FULL;
|
||||
// 当前电量
|
||||
int level = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, 0);
|
||||
// 最大电量
|
||||
@@ -358,6 +366,7 @@ public class CustomFragment extends BaseFragment implements CustomContact.Custom
|
||||
int elec = (level * 100) / scale;
|
||||
Log.i(TAG, "electricity:=" + elec + "%");
|
||||
tv_battery.setText(elec + "%");
|
||||
notifyBattery(level, scale, status, isCharging);
|
||||
} else if (Intent.ACTION_POWER_CONNECTED.equals(action)
|
||||
|| Intent.ACTION_POWER_DISCONNECTED.equals(action)
|
||||
|| Intent.ACTION_BATTERY_LOW.equals(action)
|
||||
@@ -368,6 +377,11 @@ public class CustomFragment extends BaseFragment implements CustomContact.Custom
|
||||
}
|
||||
}
|
||||
|
||||
public void notifyBattery(int level, int scale, int status, boolean isCharging) {
|
||||
Bitmap bitmap = BitmapUtils.getbatteryIcon(mContext, BitmapFactory.decodeResource(getResources(), R.drawable.battery_icon), level, isCharging);
|
||||
iv_battery.setImageBitmap(bitmap);
|
||||
}
|
||||
|
||||
private BroadcastReceiver mbatteryReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
@@ -828,19 +842,19 @@ public class CustomFragment extends BaseFragment implements CustomContact.Custom
|
||||
});
|
||||
}
|
||||
|
||||
private void getAlarmCache(){
|
||||
private void getAlarmCache() {
|
||||
String jsonString = mCacheHelper.getAsString(URLAddress.GET_ALARM_CLOCK);
|
||||
Gson gson = new Gson();
|
||||
Type type = new TypeToken<List<AlarmClockData>>() {
|
||||
}.getType();
|
||||
List<AlarmClockData> list = gson.fromJson(jsonString, type);
|
||||
if (list == null || list.size() == 0) {
|
||||
rv_noti.setVisibility(View.GONE);
|
||||
iv_note_nodata.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
notificationAdapter.setDataList(list);
|
||||
rv_noti.setVisibility(View.VISIBLE);
|
||||
iv_note_nodata.setVisibility(View.GONE);
|
||||
} else {
|
||||
rv_noti.setVisibility(View.GONE);
|
||||
iv_note_nodata.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -77,9 +77,9 @@ public class ApkUtils {
|
||||
this.add("com.uiui.city");
|
||||
this.add("com.uiui.health");
|
||||
// this.add("com.alldocube.store");
|
||||
this.add("com.android.fmradio");
|
||||
this.add("com.android.documentsui");
|
||||
this.add("com.android.calculator2");
|
||||
// this.add("com.android.fmradio");
|
||||
// this.add("com.android.documentsui");
|
||||
// this.add("com.android.calculator2");
|
||||
}};
|
||||
private static HashSet<String> allHintPackage = new HashSet<String>() {{
|
||||
this.add("com.android.uiuios");
|
||||
|
||||
@@ -4,12 +4,19 @@ import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.PixelFormat;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.RectF;
|
||||
import android.graphics.Typeface;
|
||||
import android.graphics.drawable.AdaptiveIconDrawable;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Build;
|
||||
|
||||
import com.uiuios.aios.R;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
|
||||
public class BitmapUtils {
|
||||
@@ -69,4 +76,54 @@ public class BitmapUtils {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static Bitmap getbatteryIcon(Context context, Bitmap bitmap, int level, boolean charging) {
|
||||
String st_level = String.valueOf(level);
|
||||
int paddingLeft = 6;
|
||||
int paddingRight = 8;
|
||||
int paddingTop = 6;
|
||||
int paddingBottom = 6;
|
||||
int width = bitmap.getWidth();
|
||||
int height = bitmap.getHeight();
|
||||
Bitmap background = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
|
||||
Bitmap bitmapScale = Bitmap.createScaledBitmap(bitmap, width, height, true);
|
||||
Canvas canvas = new Canvas();
|
||||
canvas.setBitmap(background);
|
||||
Paint paint = new Paint();
|
||||
if (charging) {
|
||||
paint.setColor(context.getColor(R.color.charging_color));
|
||||
} else {
|
||||
if (level <= 20) {
|
||||
paint.setColor(Color.RED);
|
||||
} else {
|
||||
paint.setColor(context.getColor(R.color.no_charging_color));
|
||||
}
|
||||
}
|
||||
//设置画笔类型
|
||||
paint.setStyle(Paint.Style.FILL);
|
||||
//使用画笔在画布上画矩形
|
||||
paint.setAntiAlias(true);
|
||||
Rect mSrcRect = new Rect(0, 0, width, height);
|
||||
canvas.drawBitmap(bitmapScale, mSrcRect, mSrcRect, null);
|
||||
RectF rectF = new RectF(paddingLeft, paddingTop, (bitmap.getWidth() - paddingRight) * level / 100, bitmap.getHeight() - paddingBottom);// 设置个新的长方形
|
||||
canvas.drawRoundRect(rectF, 3, 3, paint);
|
||||
|
||||
final float mDensity = context.getResources().getDisplayMetrics().density;
|
||||
Rect rect = new Rect();
|
||||
Paint mDatePaint = new Paint();
|
||||
mDatePaint.setTypeface(Typeface.SANS_SERIF);
|
||||
mDatePaint.setTextSize((int) 9F * mDensity);//文字大小
|
||||
mDatePaint.setColor(Color.BLACK);
|
||||
mDatePaint.setAntiAlias(true);
|
||||
|
||||
mDatePaint.getTextBounds(st_level, 0, st_level.length(), rect);
|
||||
//通过文字获取矩形的面积
|
||||
int width1 = rect.right - rect.left;
|
||||
int height1 = rect.bottom - rect.top;
|
||||
int width2 = background.getWidth();
|
||||
int height2 = background.getHeight();
|
||||
canvas.drawText(st_level, (width2 - width1) / 2 - rect.left, (height2 - height1) / 2 - rect.top, mDatePaint);
|
||||
return background;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user