Skip to content

Commit

Permalink
style modified
Browse files Browse the repository at this point in the history
  • Loading branch information
zjkuki committed Oct 13, 2019
1 parent e15984a commit 9ae2b21
Showing 44 changed files with 339 additions and 47 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
@@ -59,7 +59,7 @@ android {
// javaMaxHeapSize "4g"
// }
configurations.all {
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
resolutionStrategy.eachDependency { details ->
def requested = details.requested
if (requested.group == 'com.android.support') {
if (!requested.name.startsWith("multidex")) {
3 changes: 1 addition & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -32,7 +32,6 @@
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.WRITE_SETTINGS"
tools:ignore="ProtectedPermissions" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"
@@ -46,7 +45,7 @@
<application
android:name="com.example.funsdkdemo.MyApplication"
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:icon="@drawable/logo"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
Binary file added app/src/main/ic_launcher-web.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 14 additions & 7 deletions app/src/main/java/com/TestFragment.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Rect;
import android.media.Image;
import android.support.annotation.NonNull;
@@ -18,6 +19,7 @@

import com.example.funsdkdemo.MyApplication;
import com.example.funsdkdemo.R;
import com.janady.RoundRect;
import com.janady.adapter.FunDeviceAdapter;
import com.janady.base.BaseRecyclerAdapter;
import com.janady.base.GridDividerItemDecoration;
@@ -88,7 +90,7 @@ public void run() {
return rootView;
}
private void initTopBar() {
mTopBar.setTitle("我的摄像机");
mTopBar.setTitle("我的所有设备");
mTopBar.addRightImageButton(R.drawable.ic_topbar_add, R.id.topbar_add_button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
@@ -113,15 +115,17 @@ public List<MainItemDescription> createData() {
MainItemDescription items = new MainItemDescription(CameraListFragment.class, "camera-"+i, R.drawable.ic_camera, MainItemDescription.DeviceType.CAM);
res.add(items);
}
MainItemDescription bleDescription = new MainItemDescription(BluetoothListFragment.class, "蓝牙门禁", R.drawable.ic_bluetooth, MainItemDescription.DeviceType.BLE);
ArrayList<Bluetooth> blists = MyApplication.liteOrm.query(Bluetooth.class);
List<Object> items = new ArrayList<>();
for (int i =0; i< 5; i++) {
ItemDescription itemDescription = new ItemDescription(BluetoothEditFragment.class, "ble-"+i, R.drawable.ic_bluetooth);
items.add(itemDescription);
if(blists.size()>0) {
MainItemDescription bleDescription = new MainItemDescription(BluetoothListFragment.class, "蓝牙设备", R.drawable.ic_bluetooth_black_24dp, MainItemDescription.DeviceType.BLE);
for (int i = 0; i < 5; i++) {
ItemDescription itemDescription = new ItemDescription(BluetoothEditFragment.class, "ble-" + i, R.drawable.ic_bluetooth_black_24dp);
items.add(itemDescription);
}
bleDescription.setList(items);
res.add(bleDescription);
}
bleDescription.setList(items);
res.add(bleDescription);
for (int i = 0; i < 2; i++) {
MainItemDescription remoteDescription = new MainItemDescription(BluetoothListFragment.class, "remote-"+i, R.drawable.ic_remote, MainItemDescription.DeviceType.REMOTE);
List<Object> remote_items = new ArrayList<>();
@@ -210,6 +214,9 @@ public void onClick(View v) {
Toast.makeText(context, item.name, Toast.LENGTH_LONG);
}
});
RoundRect roundRect = new RoundRect(500,500,100);
Bitmap photo = roundRect.toRoundRect(context,R.mipmap.ic_launcher);
itemViewHolder.imageView.setImageBitmap(photo);
}

@Override
114 changes: 114 additions & 0 deletions app/src/main/java/com/janady/RoundRect.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
package com.janady;

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.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.graphics.RectF;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;


public class RoundRect {

private int width;
private int height;
private float cornerRadius;

/**
* 用于初始化圆角矩形基本参数
*
* @param width 图片宽度
* @param height 图片高度
* @param cornerRadius 圆角半径
*/
public RoundRect(int width, int height, float cornerRadius) {
this.width = width;
this.height = height;
this.cornerRadius = cornerRadius;
}

/**
* 用于把普通图片转换为圆角矩形图像
*
* @param path 图片路径
* @return output 转换后的圆角矩形图像
*/
Bitmap toRoundRect(String path) {
//创建位图对象
Bitmap photo = lessenUriImage(path);
return Transformation(photo);
}

/**
* 用于把普通图片转换为圆角矩形图像
*
* @param imageID 图片资源ID
* @param context 上下文对象
* @return output 转换后的圆角矩形图像
*/
public Bitmap toRoundRect(Context context, int imageID) {
//创建位图对象
Bitmap photo = BitmapFactory.decodeResource(context.getResources(), imageID);
return Transformation(photo);
}

/**
* 用于把Uri图片转换为Bitmap对象
*
* @param path 图片URI地址
* @return 生成的Bitmap对象
*/
public final static Bitmap lessenUriImage(String path) {
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
Bitmap bitmap = BitmapFactory.decodeFile(path, options); //此时返回 bm 为空
options.inJustDecodeBounds = false; //缩放比。由于是固定比例缩放,只用高或者宽其中一个数据进行计算即可
int be = (int) (options.outHeight / (float) 320);
if (be <= 0) be = 1;
options.inSampleSize = be; //重新读入图片,注意此时已经把 options.inJustDecodeBounds 设回 false 了
bitmap = BitmapFactory.decodeFile(path, options);
int w = bitmap.getWidth();
int h = bitmap.getHeight();
System.out.println(w + " " + h); //after zoom
return bitmap;
}

/**
* 用于把Bitmap图像转换为圆角图像
*
* @param photo 需要转换的Bitmap对象
* @return 转换成圆角的Bitmap对象
*/
private Bitmap Transformation(Bitmap photo) {

//根据源文件新建一个darwable对象
Drawable imageDrawable = new BitmapDrawable(photo);

// 新建一个新的输出图片
Bitmap output = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(output);

// 新建一个矩形
RectF outerRect = new RectF(0, 0, width, height);

// 产生一个红色的圆角矩形
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setColor(Color.RED);
canvas.drawRoundRect(outerRect, cornerRadius, cornerRadius, paint);

// 将源图片绘制到这个圆角矩形上
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
imageDrawable.setBounds(0, 0, width, height);
canvas.saveLayer(outerRect, paint, Canvas.ALL_SAVE_FLAG);
imageDrawable.draw(canvas);
canvas.restore();

return output;
}

}
13 changes: 13 additions & 0 deletions app/src/main/java/com/janady/base/BaseRecyclerAdapter.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
package com.janady.base;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.PaintDrawable;
import android.support.annotation.DrawableRes;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.funsdkdemo.R;
import com.janady.RoundRect;
import com.janady.model.ItemDescription;

import java.util.ArrayList;
@@ -38,6 +47,10 @@ public void setData(List<T> list) {
public RecyclerViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
final RecyclerViewHolder holder = new RecyclerViewHolder(mContext,
mInflater.inflate(getItemLayoutId(viewType), parent, false));
RoundRect roundRect = new RoundRect(50,50,100);
Bitmap photo = roundRect.toRoundRect(mContext, R.drawable.ic_locker);


if (mClickListener != null) {
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
7 changes: 7 additions & 0 deletions app/src/main/java/com/janady/database/model/Bluetooth.java
Original file line number Diff line number Diff line change
@@ -15,6 +15,13 @@ public class Bluetooth {
@Column("_id") // 指定列名
private int id;

private String mac;
private String uuid;
private String serviceUuid;
private String writeUuid;
private String notifyUuid;
private String password;
private boolean isFirst = true;
public String name;
@Mapping(Relation.OneToOne)
public Door door;
20 changes: 13 additions & 7 deletions app/src/main/java/com/janady/manager/DataManager.java
Original file line number Diff line number Diff line change
@@ -45,9 +45,11 @@ public List<CategoryItemDescription> getCategoryDesciptions() {
ArrayList<Remote> rlists = MyApplication.liteOrm.query(Remote.class);
ArrayList<Door> dlists = MyApplication.liteOrm.query(Door.class);
CategoryItemDescription camera = new CategoryItemDescription(CameraListFragment.class, "摄像机", R.drawable.ic_camera, funDevices.size());
CategoryItemDescription bluetooth = new CategoryItemDescription(BluetoothListFragment.class, "蓝牙门禁", R.drawable.ic_bluetooth, blists.size());
CategoryItemDescription remote = new CategoryItemDescription(RemoteListFragment.class, "远程控制", R.drawable.ic_remote, rlists.size());
CategoryItemDescription room = new CategoryItemDescription(DoorListFragment.class, "房间", R.drawable.ic_room, dlists.size());
//CategoryItemDescription bluetooth = new CategoryItemDescription(BluetoothListFragment.class, "蓝牙门禁", R.drawable.ic_bluetooth, blists.size());
//CategoryItemDescription remote = new CategoryItemDescription(RemoteListFragment.class, "远程控制", R.drawable.ic_remote, rlists.size());
CategoryItemDescription bluetooth = new CategoryItemDescription(BluetoothListFragment.class, "蓝牙门禁", R.drawable.ic_bluetooth_black_24dp, blists.size());
CategoryItemDescription remote = new CategoryItemDescription(RemoteListFragment.class, "远程控制", R.drawable.ic_remote_3, rlists.size());
CategoryItemDescription room = new CategoryItemDescription(DoorListFragment.class, "场景", R.drawable.ic_room2, dlists.size());
list.add(camera);
list.add(bluetooth);
list.add(remote);
@@ -58,9 +60,12 @@ public List<CategoryItemDescription> showCategoryDesciptions() {
List<CategoryItemDescription> list = new ArrayList<>();

CategoryItemDescription camera = new CategoryItemDescription(AddDeviceFragment.class, "摄像机", R.drawable.ic_camera, 0);
CategoryItemDescription bluetooth = new CategoryItemDescription(BluetoothEditFragment.class, "蓝牙门禁", R.drawable.ic_bluetooth, 0);
/*CategoryItemDescription bluetooth = new CategoryItemDescription(BluetoothEditFragment.class, "蓝牙门禁", R.drawable.ic_bluetooth, 0);
CategoryItemDescription remote = new CategoryItemDescription(RemoteEditFragment.class, "远程控制", R.drawable.ic_remote, 0);
CategoryItemDescription room = new CategoryItemDescription(DoorEditFragment.class, "房间", R.drawable.ic_room, 0);
CategoryItemDescription room = new CategoryItemDescription(DoorEditFragment.class, "房间", R.drawable.ic_room, 0);*/
CategoryItemDescription bluetooth = new CategoryItemDescription(BluetoothEditFragment.class, "蓝牙门禁", R.drawable.ic_bluetooth_black_24dp, 0);
CategoryItemDescription remote = new CategoryItemDescription(RemoteEditFragment.class, "远程控制", R.drawable.ic_remote_3, 0);
CategoryItemDescription room = new CategoryItemDescription(DoorEditFragment.class, "场景", R.drawable.ic_room2, 0);
list.add(camera);
list.add(bluetooth);
list.add(remote);
@@ -76,7 +81,8 @@ public List<MainItemDescription> getDescriptions() {
list.add(mainDescription);
}

MainItemDescription bleDescription = new MainItemDescription(BluetoothLockFragment.class, "蓝牙门禁", R.drawable.ic_bluetooth, MainItemDescription.DeviceType.BLE);
//MainItemDescription bleDescription = new MainItemDescription(BluetoothLockFragment.class, "蓝牙门禁", R.drawable.ic_bluetooth, MainItemDescription.DeviceType.BLE);
MainItemDescription bleDescription = new MainItemDescription(BluetoothLockFragment.class, "蓝牙门禁", R.drawable.ic_bluetooth_black_24dp, MainItemDescription.DeviceType.BLE);
ArrayList<Bluetooth> blists = MyApplication.liteOrm.query(Bluetooth.class);
List<Object> bitems = new ArrayList<>();
for (Bluetooth bluetooth : blists) {
@@ -89,7 +95,7 @@ public List<MainItemDescription> getDescriptions() {

ArrayList<Remote> rlists = MyApplication.liteOrm.query(Remote.class);
for (Remote remote : rlists) {
MainItemDescription remoteDescription = new MainItemDescription(BluetoothListFragment.class, remote.name, R.drawable.ic_remote, MainItemDescription.DeviceType.REMOTE);
MainItemDescription remoteDescription = new MainItemDescription(BluetoothListFragment.class, remote.name, R.drawable.ic_remote_3, MainItemDescription.DeviceType.REMOTE);
remoteDescription.setDevice(remote);
List<Object> ritems = new ArrayList<>();
for (Bluetooth bluetooth : blists) {
6 changes: 6 additions & 0 deletions app/src/main/java/com/janady/model/BaseItemAdapter.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.janady.model;

import android.content.Context;
import android.graphics.Bitmap;
import android.view.View;
import android.widget.Toast;

import com.example.funsdkdemo.R;
import com.janady.RoundRect;
import com.janady.base.BaseRecyclerAdapter;
import com.janady.base.RecyclerViewHolder;

@@ -26,5 +28,9 @@ public int getItemLayoutId(int viewType) {
public void bindData(RecyclerViewHolder holder, int position, final ItemDescription item) {
if (item.getIconRes() != 0) holder.getImageView(R.id.img).setImageResource(item.getIconRes());
holder.getTextView(R.id.name).setText(item.getName());

RoundRect roundRect = new RoundRect(100,100,10);
Bitmap photo = roundRect.toRoundRect(context,R.drawable.btlocker2);
holder.getImageView(R.id.img).setImageBitmap(photo);
}
}
Loading

0 comments on commit 9ae2b21

Please sign in to comment.