Android UI框架
Activity、Fragment封装,支持状态栏修改、快速设置标题栏、设置空视图、
内含轮播、刷新、加载、侧滑删除、ShapeButton、日期选择器、滚轮选择器、权限工具、分享数据、
流式布局列表、桌面圆点、字体大小设置、语言设置、短信发送倒计时、消息提示、数据库、
常用正则、网页加载器、数字处理、价格处理
名字 | 资源 |
---|---|
AAR | uicore.aar |
GitHub | UICore |
Gitee | UICore |
1.build.grade
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
2./app/build.grade
dependencies {
implementation 'com.github.RelinRan:UICore:2022.7.25.1'
}
@Override
public int getContentViewLayoutResId() {
return R.layout.xxx;
}
详细使用请查阅AppActionBar
AppActionBar actionBar = getAppActionBar();
返回点击
@Override
public void onBackClick(View v) {
finish();
}
标题点击
@Override
public void onTitleClick(View v) {
}
菜单点击
@Override
public void onMenuClick(View v) {
}
@Override
public int getContainerViewResId() {
//fragment_container为Activity内容布局中的View
//通常为FrameLayout,id=fragment_container
return R.id.fragment_container;
}
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//方式一
MainFragment fragment = new MainFragment();
Bundle bundle = new Bundle();
bundle.putString("key","value");
fragment.setArguments(bundle);
addFragment(fragment);
//方式二
Bundle options = new Bundle();
options.putString("key","value");
addFragment(MainFragment.class,options);
}
权限对象
AppPermission permission = getAppPermission();
权限请求
getPermission().requestPermissions(AppPermission.GROUP_CAMERA,AppPermission.REQUEST_CODE)
权限回调
@Override
public void onRequestPermissionsGranted(String[] permissions) {
super.onRequestPermissionsGranted(permissions);
//已同意
}
@Override
public void onRequestPermissionsDenied(String[] permissions) {
super.onRequestPermissionsDenied(permissions);
//已取消
}
@Override
public void onRequestPermissionRationale(String[] permissions) {
super.onRequestPermissionRationale(permissions);
//不再提示
}
网络加载
showLoading("登陆中...");
隐藏加载
dismissLoading();
显示提示
showToast(String msg);
设置登录
setLogin(boolean login);
是否登录
boolean isLogin()
设置token
setToken(String token);
获取token
String getToken();
设置用户信息JSON
setUserInfo(String json);
获取用户信息JSON
String getUserInfo();
设置占位图
setPlaceholder(AppPlaceholder.PLACEHOLDER_EMPTY,R.mipmap.xxx);;
显示占位图
showPlaceholder(AppPlaceholder.PLACEHOLDER_EMPTY);
隐藏占位图
hidePlaceholder();
@Override
public int getContentViewLayoutResId() {
return R.layout.xxx;
}
@Override
public int getContainerViewResId() {
//fragment_container为Activity内容布局中的View
//通常为FrameLayout,id=fragment_container
return R.id.fragment_container;
}
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//方式一
MainFragment fragment = new MainFragment();
Bundle bundle = new Bundle();
bundle.putString("key","value");
fragment.setArguments(bundle);
addFragment(fragment);
//方式二
Bundle options = new Bundle();
options.putString("key","value");
addFragment(MainFragment.class,options);
}
权限对象
AppPermission permission = getAppPermission();
权限请求
getPermission().requestPermissions(AppPermission.GROUP_CAMERA,AppPermission.REQUEST_CODE)
权限回调
@Override
public void onRequestPermissionsGranted(String[] permissions) {
super.onRequestPermissionsGranted(permissions);
//已同意
}
@Override
public void onRequestPermissionsDenied(String[] permissions) {
super.onRequestPermissionsDenied(permissions);
//已取消
}
@Override
public void onRequestPermissionRationale(String[] permissions) {
super.onRequestPermissionRationale(permissions);
//不再提示
}
网络加载
showLoading("登陆中...");
隐藏加载
dismissLoading();
显示提示
showToast(String msg);
设置登录
setLogin(boolean login);
是否登录
boolean isLogin()
设置token
setToken(String token);
获取token
String getToken();
设置用户信息JSON
setUserInfo(String json);
获取用户信息JSON
String getUserInfo();
设置占位图
setPlaceholder(AppPlaceholder.PLACEHOLDER_EMPTY,R.mipmap.xxx);;
显示占位图
showPlaceholder(AppPlaceholder.PLACEHOLDER_EMPTY);
隐藏占位图
hidePlaceholder();
setTitle("xxx");
setImmersed(boolean statusBarTextDark);
状态栏同时修改
setBackgroundColor(@ColorInt int color);
setBackIconResource(@DrawableRes int resId);
### setBackText(String text);
setBackTextSize(int size);
setBackTextColor(@ColorInt int color);
setBackTextPadding(int position, int padding);
setStatusBarColor(int color);
setStatusBarTextColor(boolean dark);
状态栏
AppStatusBar.setColor(this, Color.parseColor("#3C3F41"));
AppStatusBar.setTextColor(this,false);
int height = AppStatusBar.height(this);
AppStatusBar.show(this);
AppStatusBar.hide(this);
支持圆角背景的Layout
<androidx.ui.core.widget.ShapeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:solidColor="#BC68E0"
app:radius="5dp"/>
</androidx.ui.core.widget.ShapeLayout>
支持圆角背景的TextView
<androidx.ui.core.widget.ShapeText
android:layout_width="match_parent"
android:layout_height="45dp"
app:solidColor="#BC68E0"
app:radius="5dp"
android:text="item"
android:textSize="14sp"/>
支持圆角背景的按钮
<androidx.ui.core.widget.ShapeButton
android:layout_width="match_parent"
android:layout_height="45dp"
app:solidColor="#BC68E0"
app:radius="5dp"
android:text="item"
android:textSize="14sp"/>
轮播图
<androidx.ui.core.carousel.CarouselPager
android:id="@+id/carousel"
android:layout_width="match_parent"
android:layout_height="180dp"
app:duration="3000"
app:autoPlay="true"
app:itemCount="1" />
预定义Layout
public class ImageAdapter extends CarouselAdapter<Integer> {
public ImageAdapter(Context context) {
super(context);
}
@Override
public void onItemBindViewHolder(ViewHolder holder, int position) {
ImageView target = holder.find(CarouselPager.RES_IMAGE);
target.setImageResource(getItem(position));
holder.addItemClick(target);
}
}
自定义Layout
@Override
public int getItemLayoutResId() {
return R.layout.xxx;
}
CarouselPager carousel = findViewById(R.id.carousel);
ImageAdapter adapter = new ImageAdapter(context);
carousel.setAdapter(imageAdapter);
adapter.setOnItemClickListener((adapter, view, position) -> {
});
List<Integer> list = new ArrayList<>();
list.add(R.mipmap.ic_img_0);
list.add(R.mipmap.ic_img_1);
list.add(R.mipmap.ic_img_2);
adapter.setItems(list);
下拉刷新
<androidx.ui.core.refrsh.SwipeRefreshLayout
android:id="@+id/swipe_refresh"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white">
<androidx.ui.core.recycler.SwipeRecyclerView
android:id="@+id/rv_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:itemCount="5"
tools:listitem="@layout/ui_core_item"/>
</androidx.ui.core.refrsh.SwipeRefreshLayout>
setColorSchemeColors(Color.parseColor("#26C9B7"));
swipe_refresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
}
});
setRefreshing(false);
setRefreshing(true);
消息确认
MessageDialog messageDialog = new MessageDialog(getContext());
messageDialog.setTitle("提示");
messageDialog.setTitleVisibility(View.VISIBLE);
messageDialog.setContent("是否确认删除此项?");
messageDialog.setCancel("取消");
messageDialog.setConfirm("确认");
messageDialog.setOnMessageDialogListener(new MessageDialogCallback() {
@Override
public void onMessageDialogConfirm(MessageDialog dialog) {
super.onMessageDialogConfirm(dialog);
dialog.dismiss();
}
});
messageDialog.show();
滚轮选择器
List<String> list = new ArrayList<>();
for (int i = 0; i < 10; i++) {
list.add(i+"");
}
WheelPicker picker = new WheelPicker(getContext(),1);
picker.setTitle("请选择");
picker.setOnWheelPickerConfirmListener(picker1 -> {
String value = picker1.getSelected(true);
});
picker.setWheelsDataSource(0,list);
picker.show();
日期选择器
DatePicker picker = new DatePicker(getContext());
//选择范围
picker.setBoundary("2022-2-20","2050-2-20","yyyy-MM-dd");
picker.setOnDatePickerConfirmListener((picker1, date) -> {
});
//选中
picker.setSelected("2022-02-20", "yyyy-MM-dd");
picker.show();
时段选择器
PeriodPicker picker = new PeriodPicker(getContext());
//选择范围
picker.setBoundary("2022-2-20","2050-2-20","yyyy-MM-dd");
picker.setOnPeriodPickerConfirmListener((picker12, start, end) -> {
});
//选中
picker.setSelected("2022-02-20", "yyyy-MM-dd");
picker.show();
日期切换选择器(选择年、月、日)
DateSwitchPicker datePicker = new DateSwitchPicker(this);
datePicker.setOnDatePickerConfirmListener((picker, date) -> {
showToast(date);
});
datePicker.setSelected("2022-02-20", "yyyy-MM-dd");
datePicker.show();
快速清除内容的EditTextView
<androidx.ui.core.widget.ClearEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableRight="@drawable/android_ic_clear_text">
</androidx.ui.core.widget.ClearEditText>
清除图标
android:drawableRight="@drawable/android_ic_clear_text"
普通RecyclerView Adapter封装类
public class ItemAdapter extends RecyclerAdapter<String> {
public ItemAdapter(Context context) {
super(context);
}
@Override
protected int getItemLayoutResId(int viewType) {
return R.layout.xxx;
}
@Override
protected void onItemBindViewHolder(ViewHolder holder, int position) {
holder.find(TextView.class,R.id.tv_name).setText("xxx");
holder.addItemClick(R.id.tv_name);
}
}
侧滑删除,上拉加载更多,使用请查阅SwipeRecyclerView; 注意:UICore内含SwipeRecyclerView,只是包名和SwipeRecyclerView单独依赖不一致。不要使用错误。
<androidx.ui.core.recycler.SwipeRecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
SwipeRecyclerView侧滑删除,上拉加载更多RecyclerView Adapter封装类; 详细使用请查阅SwipeRecyclerAdapter; 注意:UICore内含SwipeRecyclerAdapter,只是包名和SwipeRecyclerAdapter单独依赖不一致。不要使用错误。
public class ItemAdapter extends SwipeRecyclerAdapter<String> {
public ItemAdapter(Context context) {
super(context);
}
@Override
protected int getItemSwipeMenuLayoutResId() {
//菜单布局
return R.layout.xxx;
}
@Override
protected int getItemLayoutResId(int viewType) {
//普通item布局
return R.layout.xxx;
}
@Override
protected void onSwipeBindViewHolder(ViewHolder holder, int position) {
super.onSwipeBindViewHolder(holder, position);
//侧滑绑定数据
}
@Override
protected void onItemBindViewHolder(ViewHolder holder, int position) {
}
}
时间工具类
String now = Time.now(Time.DATE_FORMAT_YYYY_MM_DD);
String time = Time.parseFromTimestamp(timestamp);
String time = Time.parseFromTimestamp(timestamp,Time.DATE_FORMAT_YYYY_MM_DD);
Date date = Time.parse("2019-09-10 09:00:10");
Date date = Time.parse("2019-09-10 09:00:10",Time.DATE_FORMAT_YYYY_MM_DD_BLANK_24H_MM_SS);
long diff = Time.diff("2022-2-10","2022-2-20","yyyy-MM-dd");
小数位数处理,通常用于价格保留2位小数;四舍五入功能使用.
String value = Decimal.format(2.351F,2);
String value = Decimal.format("2.351",2,Decimal.ROUND_HALF_UP);
String value = Decimal.format("2.351",2,Decimal.ROUND_HALF_DOWN);
限制输入2位数,最大输入10位
EditText etPrice = findViewById(R.id.et_price);
Decimal.format(etPrice,2,10);
文本处理
boolean isEmpty = Text.isEmpty("xxx");
boolean isAssign = Text.isAssign("xxx");
String value = from(TextView textView);
兼容性数字转换
//为空自动转为0
int intValue = Numeric.parseInt("null");
//Float自动加".00"
float floatValue = Numeric.parseFloat("2");
//Double自动加".00"
double doubleValue = Numeric.parseDouble("34");
//为空自动转为0
String intValue = Numeric.toInt("null");
//Float自动加".00"
String floatValue = Numeric.toFloat("2");
//Double自动加".00"
String doubleValue = Numeric.toDouble("34");
语言工具
Locale systemLanguage = Language.getSystem();
Locale applicationLanguage = Language.getApplication(context);
Language.update(context,Locale.US);
boolean isSame = Language.compare(source,target);
Locale locale = Language.getSystem();
boolean isChinese = Language.isChinese(locale);
网页加载器
WebLoader.Builder builder = new WebLoader.Builder(webView);
builder.url("https://xxxxxxx");
builder.build();
WebLoader.Builder builder = new WebLoader.Builder(webView);
builder.data("Html data");
builder.build();
WebLoader.Builder builder = new WebLoader.Builder(webView);
builder.data("Html data");
builder.imageClickListener(new WebLoader.OnWebImageClickListener() {
@Override
public void onWebImageClick(String url) {
}
});
builder.build();
WebLoader.Builder builder = new WebLoader.Builder(webView);
builder.data("Html data");
builder.imageFit(true);
builder.build();
Activity管理器
AppActivityManager.getInstance().add(MainActivity.class);
AppActivityManager.getInstance().clear();
AppActivityManager.getInstance().remove(MainActivity.class);
AppActivityManager.getInstance().exit(context);
APP桌面角标-红色圆点,主要是显示红色圆点,但是不支持所有手机类型,目前支持小米、华为、三星、索尼。 Badge已经做了缓存处理,同时去区别了多个项目在一个手机的缓存区别。
Badge.add(cntext);
Badge.reset(context);
Badge.setNumber(context,number);
int number = Badge.number(context);
数据库操作
SQLite.initialize(getApplicationContext());
//方式1
SQLite.administrator().create("table_name",new String[]{"column_name_a","column_name_b"});
//方式2
User user = new User();
SQLite.administrator().create(user);
//方式1
User user = new User();
SQLite.administrator().insert(user);
//方式2
SQLite.administrator().insert("sql");
//方式3
ContentValues values = new ContentValues();
values.put("user_id","1");
values.put("user_name","name");
SQLite.administrator().insert("table_name",values);
//方式1
SQLite.administrator().delete("sql");
//方式2
SQLite.administrator().delete(User.class,"user_id=?",new String[]{"1"});
//方式3
SQLite.administrator().delete("table_name","user_id=?",new String[]{"1"});
//方式1
SQLite.administrator().update("sql");
//方式2
User user = new User();
user.setUserName("Name");
ContentValues values = new ContentValues();
values.put("user_id","1");
values.put("user_name","name");
SQLite.administrator().update(user,values,"user_id=?",new String[]{"1"});
//方式1
List<Map<String, String>> list = SQLite.administrator().query("sql");
//方式2
List<User> list = SQLite.administrator().query(User.class,"sql");
//方式1
SQLite.administrator().deleteTable("table_name");
//方式2
SQLite.administrator().deleteTable(User.class);
//方式3
SQLite.administrator().dropTable("table_name");//删除表
正则验证
Validator.REGEX_PHONE = "xxx";
Validator.isPhone(String number);
粗略的校验
Validator.isIdCard(String number);
Validator.isWeChat(String number);
默认正则,密码长度为8到20位,必须包含字母和数字,字母区分大小写
Validator.isPassword(String password);
Validator.isNumeric(String number);
Validator.isEmail(String mail);
Validator.isQQ(String number);