Add grid 3x3 and grid auto folder icon styles.

This commit is contained in:
Pierrot 2019-06-06 11:34:58 +02:00
parent 44e1e4948b
commit e55e4477c4
5 changed files with 132 additions and 41 deletions

View file

@ -2535,8 +2535,12 @@ public class CustomizeItemView extends MyViewPager implements LLPreferenceListVi
fcs.modifyFolderConfig().iconStyle = (FolderConfig.FolderIconStyle) enumValue;
if(object instanceof Folder) {
Folder folder = (Folder) object;
Page folder_page = folder.getOrLoadFolderPage();
ShortcutConfig.getIconBackFile(mPage.getIconDir(), folder.getId()).delete();
// when switching to a style with a dynamic background, force the recreation of
// the background with a default one, which will in turn trigger the recreation
// of a dynamic background
Utils.resetDynamicFolderBackground(ShortcutConfig.getIconBackFile(mPage.getIconDir(), folder.getId()), folder.getStdIconSize());
Utils.updateFolderIcon(folder);
} else {
Utils.updateFolderIconStyle((Page)object);

View file

@ -23,7 +23,9 @@ public class FolderConfig extends JsonLoader {
public enum FolderIconStyle {
NORMAL,
GRID_2_2,
STACK
STACK,
GRID_AUTO,
GRID_3_3
}
// public enum FolderBorderStyle {

View file

@ -1139,6 +1139,59 @@ public class Utils {
}
}
private static final float DYNAMIC_FOLDER_BG_MARGIN=0.03125f;
private static void buildDynamicFolderBackground(Canvas canvas, int icon_width, int icon_height) {
canvas.drawARGB(0, 0, 0, 0);
Paint bg_paint=new Paint(Paint.ANTI_ALIAS_FLAG);
bg_paint.setShader(new RadialGradient(icon_width/2, icon_height/2, (float) Math.sqrt(icon_width*icon_width+icon_height*icon_height), 0xff59514c, 0xff272424, TileMode.CLAMP));
canvas.drawRoundRect(new RectF(0, 0, icon_width, icon_height), DYNAMIC_FOLDER_BG_MARGIN*2*icon_width, DYNAMIC_FOLDER_BG_MARGIN*2*icon_height, bg_paint);
}
public static void resetDynamicFolderBackground(File image_file, int size) {
Bitmap icon = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
Canvas canvas=new Canvas(icon);
buildDynamicFolderBackground(canvas, size, size);
Utils.saveIconToFile(image_file, icon);
}
private static boolean hasDynamicFolderBackground(File image_file) {
// return true if the current folder background is a dynamic one (the one with a gray
// rounded rectangle, built with the function above)
// Historically there has been no metadata to distinguish between the dynamic folder bg and
// a manually chosen one. This function naively compares the current bitmap with a reference
// dynamically computed bitmap. This is kind of crappy but I can't see a better way to make
// it work with existing setups.
if(!image_file.exists()) {
return false;
}
// load the current bitmap (with a max size to limite computations to a reasonable amount)
Bitmap current = loadBitmap(image_file, 0, 32, 32);
// create a reference background with the same size
int w = current.getWidth();
int h = current.getHeight();
Bitmap reference = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
Canvas canvas=new Canvas(reference);
buildDynamicFolderBackground(canvas, w, h);
// now compare pixels (only the blue channel, this is probably enough)
int diff = 0; // enough for 2^15 pixels
for(int x=0; x<w; x++) {
for(int y=0; y<h; y++) {
int d = (current.getPixel(x, y)&0xff) - (reference.getPixel(x, y)&0xff);
diff += d*d;
}
}
int s = diff / (w*h);
return s < 4;
}
public static void updateFolderIcon(Folder folder) {
Page folder_page = folder.getOrLoadFolderPage();
FolderConfig fc = folder.getFolderConfig();
@ -1149,7 +1202,9 @@ public class Utils {
File icon_effect_background;
icon_effect_background = ShortcutConfig.getIconBackFile(folder_container_icon_dir, folder.mId);
boolean hasDynamicFolderBackground = hasDynamicFolderBackground(icon_effect_background);
Bitmap icon;
if(style==FolderIconStyle.NORMAL) {
icon=null; // do not update the icon, keep the current one
@ -1199,36 +1254,63 @@ public class Utils {
int icon_height=icon_width;
icon=Bitmap.createBitmap(icon_width, icon_height, Bitmap.Config.ARGB_8888);
Canvas canvas=new Canvas(icon);
final float margin=0.03125f;
canvas.drawARGB(0, 0, 0, 0);
Paint bg_paint=new Paint(Paint.ANTI_ALIAS_FLAG);
bg_paint.setShader(new RadialGradient(icon_width/2, icon_height/2, (float) Math.sqrt(icon_width*icon_width+icon_height*icon_height), 0xff59514c, 0xff272424, TileMode.CLAMP));
canvas.drawRoundRect(new RectF(0, 0, icon_width, icon_height), margin*2*icon_width, margin*2*icon_height, bg_paint);
if(hasDynamicFolderBackground) {
buildDynamicFolderBackground(canvas, icon_width, icon_height);
}
Paint bitmap_paint=new Paint(Paint.FILTER_BITMAP_FLAG|Paint.ANTI_ALIAS_FLAG);
if(style==FolderIconStyle.GRID_2_2) {
final int w=2;
final int h=2;
if(style==FolderIconStyle.GRID_2_2 || style==FolderIconStyle.GRID_3_3 || style==FolderIconStyle.GRID_AUTO) {
int l=folder_items.size();
final int w;
final int h;
switch(style) {
case GRID_2_2:
w = 2;
h = 2;
break;
case GRID_3_3:
w = 3;
h = 3;
break;
case GRID_AUTO:
default:
if(l <= 4) {
w = 2;
h = 2;
} else {
w = 3;
h = 3;
}
break;
}
final float bw=icon_width/(float)w;
final float bh=icon_height/(float)h;
final float mw=margin*icon_width;
final float mh=margin*icon_height;
final float mw=DYNAMIC_FOLDER_BG_MARGIN*icon_width;
final float mh=DYNAMIC_FOLDER_BG_MARGIN*icon_height;
final int max=w*h;
Paint line_paint=new Paint(Paint.ANTI_ALIAS_FLAG);
line_paint.setColor(0xff8C7F77);
canvas.drawLine(icon_width/2+0.5f, mh, icon_width/2+0.5f, icon_height-mh, line_paint);
canvas.drawLine(mw, icon_height/2+0.5f, icon_width-mh, icon_height/2+0.5f, line_paint);
storeFolderIconBackground(icon_effect_background, folder_container_icon_dir, folder, icon);
int l=folder_items.size();
if(hasDynamicFolderBackground) {
Paint line_paint = new Paint(Paint.ANTI_ALIAS_FLAG);
line_paint.setColor(0xff8C7F77);
for (int x = 1; x < w; x++) {
float p = x * icon_width / w + 0.5f;
canvas.drawLine(p, mh, p, icon_height - mh, line_paint);
}
for (int y = 1; y < h; y++) {
float p = y * icon_height / h + 0.5f;
canvas.drawLine(mw, p, icon_width - mh, p, line_paint);
}
storeFolderIconBackground(icon_effect_background, folder_container_icon_dir, folder, icon);
}
icon.eraseColor(0);
int x=0;
int y=0;
int n=0;
@ -1259,11 +1341,15 @@ public class Utils {
} else {
storeFolderIconBackground(icon_effect_background, folder_container_icon_dir, folder, icon);
if(hasDynamicFolderBackground) {
storeFolderIconBackground(icon_effect_background, folder_container_icon_dir, folder, icon);
}
icon.eraseColor(0);
final int max=4;
final float mw=margin*icon_width;
final float mh=margin*icon_height;
final float mw=DYNAMIC_FOLDER_BG_MARGIN*icon_width;
final float mh=DYNAMIC_FOLDER_BG_MARGIN*icon_height;
RectF dst=new RectF();
int n=folder_items.size();
@ -1307,12 +1393,9 @@ public class Utils {
}
private static void storeFolderIconBackground(File icon_effect_background, File folder_container_icon_dir, Folder folder, Bitmap icon) {
if(!icon_effect_background.exists()) {
Utils.saveIconToFile(icon_effect_background, icon);
ShortcutConfig new_sc = folder.modifyShortcutConfig();
new_sc.loadAssociatedIcons(folder_container_icon_dir, folder.mId);
}
icon.eraseColor(0);
Utils.saveIconToFile(icon_effect_background, icon);
ShortcutConfig new_sc = folder.modifyShortcutConfig();
new_sc.loadAssociatedIcons(folder_container_icon_dir, folder.mId);
}
public static void updateContainerIconIfNeeded(Page page) {

View file

@ -197,7 +197,7 @@ import java.lang.reflect.Field;
* <tr><td><a href="/help/app/topic.php?id=68">f.animationIn</a></td> <td>string</td> <td>Read/Write</td> <td>NONE|OPEN_CLOSE|SLIDE_FROM_LEFT|SLIDE_FROM_RIGHT|SLIDE_FROM_TOP|SLIDE_FROM_BOTTOM</td></tr>
* <tr><td><a href="/help/app/topic.php?id=69">f.animationOut</a></td> <td>string</td> <td>Read/Write</td> <td>NONE|OPEN_CLOSE|SLIDE_FROM_LEFT|SLIDE_FROM_RIGHT|SLIDE_FROM_TOP|SLIDE_FROM_BOTTOM</td></tr>
* <tr><td><a href="/help/app/topic.php?id=130">f.animFade</a></td> <td>boolean</td> <td>Read/Write</td> <td>true/false</td></tr>
* <tr><td><a href="/help/app/topic.php?id=17">f.iconStyle</a></td> <td>string</td> <td>Read/Write</td> <td>NORMAL|GRID_2_2|STACK</td></tr>
* <tr><td><a href="/help/app/topic.php?id=17">f.iconStyle</a></td> <td>string</td> <td>Read/Write</td> <td>NORMAL|GRID_2_2|STACK|GRID_AUTO|GRID_3_3</td></tr>
* <tr><td><a href="/help/app/topic.php?id=515">f.outsideTapClose</a></td> <td>boolean</td> <td>Read/Write</td> <td>true/false</td></tr>
* <tr><td><a href="/help/app/topic.php?id=93">f.autoClose</a></td> <td>boolean</td> <td>Read/Write</td> <td>true/false</td></tr>
* <tr><td><a href="/help/app/topic.php?id=136">f.closeOther</a></td> <td>boolean</td> <td>Read/Write</td> <td>true/false</td></tr>

View file

@ -356,8 +356,10 @@
<string-array name="i_folder_e">
<item>Icon</item>
<item>Grid</item>
<item>Grid 2x2</item>
<item>Stack</item>
<item>Grid auto</item>
<item>Grid 3x3</item>
</string-array>
<string name="i_effect">Layers</string>