allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
dependencies {
implementation 'com.github.Ahackerl.fishModel:fishaq:1.7'
implementation 'com.github.Ahackerl.fishModel:permission:1.7'
}
- 无标题栏
public class MainActivity extends FishBaseActivity {
@ViewInject(R.id.test)
TextView test;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
test.setText("test");
}
@Override
public int initLayoutId() {
return R.layout.activity_main;
}
}
- 有标题栏
public class MainActivity extends FishBaseAppCompatActivity {
@ViewInject(R.id.test)
TextView test;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//注入id示例
test.setText("test");
}
@Override
public int initLayoutId() {
return R.layout.activity_main;
}
}
//首次需要创建表 暂不支持数据库更新
List<String> tableList=new ArrayList<>();
tableList.add("create table bill (id integer primary key autoincrement,"+ //id主键
"sum varchar(255)," +
"type varchar(255))");
FishDbTools fishDbTools=new FishDbTools(this,"test",tableList);
fishDbTools.update("insert into bill (sum,type) values (?,?)",new Object[]{"test1","test2"});
Cursor cursor=fishDbTools.search("select * from bill",null);
fishDbTools.close();
//非首次直接用数据库名访问
FishDbTools dbTools=new FishDbTools(this,"test");
Cursor cursor2=dbTools.search("select * from bill",null);
cursor2.moveToNext();
String sum=cursor2.getString(1);
dbTools.close();
- 添加gradle依赖okhttp:implementation 'com.squareup.okhttp3:okhttp:3.3.1'
- 添加gradle依赖androidx:implementation 'androidx.appcompat:appcompat:1.1.0'
new FishHttp() {//get
@Override
public void OnCallBack(String result) {
//Get the result here.Has returned to the ui main thread.
//在这里处理结果,已经回到ui主线程
}
}.okGet("http://www.baidu.com");
Bundle bundle=new Bundle();
bundle.putString("test","test");
//Currently the post bundle only supports strings.(目前post bundle仅支持字符串)
new FishHttp() {//post
@Override
public void OnCallBack(String result) {
//Get the result here.Has returned to the ui main thread.
//在这里处理结果,已经回到ui主线程
}
}.okPost("http://www.baidu.com",bundle);
JSONObject jsonObject=new JSONObject();
jsonObject.putString("test","test");
new FishHttp() {//post
@Override
public void OnCallBack(String result) {
//Get the result here.Has returned to the ui main thread.
//在这里处理结果,已经回到ui主线程
}
}.okPostBody("http://www.baidu.com",jsonObject);
new FishHttp() {//upload file
@Override
public void OnCallBack(String result) {
//Get the result here.Has returned to the ui main thread.
//在这里处理结果,已经回到ui主线程
}
}.uploadFile("http://path","/sdcard/file","test");
- 可以通过访问父类成员重新设置头像,设置按钮,编辑框和复选框
- 可以通过重写方法initLayoutId()来更换布局
- 账户account的id为account
- 密码password的id为password
- 头像head的id为head
- 记住密码checkbox的id为remember
public class MainActivity extends FishLoginActivity {
@Override
protected void loginToDo(String account, String password) {
//在这里实现登录
}
@Override
protected void registerToDo() {
//在这里实现注册跳转
}
@Override
protected void retrieveToDo() {
//在这里实现找回跳转
}
@Override
protected int setIcon() {
//在这里设置icon 这里1.4版本之前为资源文件中获取 目前修改为代码中设置图片
return R.drawable.ic_launcher_background;
}
}
- 可以通过调用方法将实体类转为HashMap
- 生成map的key为实体类中属性的名称 通过get方法获取
- 必须生成get方法
public class TestEntity {
int id;
String test;
public TestEntity(int id, String test) {
this.id = id;
this.test = test;
}
public int getId() {
return id;
}
public String getTest() {
return test;
}
}
TestEntity testEntity=new TestEntity(1,"123");
Map map=EntityUtils.convert2Map(testEntity);
- 可以通过调用方法将实体类转为JSONObject
public class TestEntity {
int id;
String test;
public TestEntity(int id, String test) {
this.id = id;
this.test = test;
}
public int getId() {
return id;
}
public String getTest() {
return test;
}
}
TestEntity testEntity=new TestEntity(1,"123");
JSONObject jsonObject = EntityUtils.convert2JsonObject(testEntity);
- 可以通过调用方法将JSONObject转为实体类
- 实体类必须生成无参构造方法
- 添加gradle依赖 implementation('com.fasterxml.jackson.core:jackson-core:2.11.1')
- 添加gradle依赖 implementation('com.fasterxml.jackson.core:jackson-annotations:2.11.1')
- 添加gradle依赖 implementation('com.fasterxml.jackson.core:jackson-databind:2.11.1')
public class TestEntity {
int id;
String test;
public TestEntity() {
}
public TestEntity(int id, String test) {
this.id = id;
this.test = test;
}
public int getId() {
return id;
}
public String getTest() {
return test;
}
}
JSONObject jsonObject=new JSONObject();
jsonObject.put("id",2);
jsonObject.put("test","qwe");
TestEntity testEntity = (TestEntity) EntityUtils.jsonObject2Obj(jsonObject, TestEntity.class);
- 郭霖博主第一行代码最后动态权限申请的封装
- 添加java方式
//java方式
new PermissonXOnJava() {
@Override
public void callBack(boolean allGranted, List<String> deniedList) {
}
}.request(this,Manifest.permission.CALL_PHONE);
//kotlin方式
PermissionX.request(this, Manifest.permission.CALL_PHONE) { allGranted, deniedList ->
if (allGranted) {
call()
} else {
Toast.makeText(this, "You denied $deniedList", Toast.LENGTH_SHORT).show()
}
}
//其中request为变长参数,可传入多个权限。
String filePath = Uri2PathUtil.getRealPathFromUri(MainActivity.this, originalUri);