1
0

2 Коммиты c4c0d59b32 ... e25edcc990

Автор SHA1 Сообщение Дата
  KngStr e25edcc990 add funtions of file size 3 лет назад
  KngStr b66400ce2f update unit header 3 лет назад
6 измененных файлов с 185 добавлено и 14 удалено
  1. 19 11
      Source/UMeng.pas
  2. 1 1
      Source/ksAndroid.Helpers.pas
  3. 9 1
      Source/ksBitmapHelper.pas
  4. 8 0
      Source/ksFmxUtils.pas
  5. 8 0
      Source/ksObjUtils.pas
  6. 140 1
      Source/ksString.pas

+ 19 - 11
Source/UMeng.pas

@@ -1,3 +1,11 @@
+{*******************************************************}
+{                                                       }
+{       Methods of UMeng                                }
+{                                                       }
+{       CopyRight (C) 2018-2020 KngStr                  }
+{                                                       }
+{*******************************************************}
+
 unit UMeng;
 
 //https://developer.umeng.com/docs/66632/detail/66889
@@ -49,8 +57,8 @@ uses
   FMX.Types;
 
 { TUMeng }
-
-class procedure TUMeng.Debug;
+
+class procedure TUMeng.Debug;
 {$IF DEFINED(ANDROID) && DEFINED(DEBUG)}
 var
   I: Integer;
@@ -85,7 +93,7 @@ begin
 {$ENDIF}
 end;
 
-class procedure TUMeng.onEvent(AID: string; ALabel: string = #0);
+class procedure TUMeng.onEvent(AID: string; ALabel: string = #0);
 begin
 {$IFDEF ANDROID}
   TJMobclickAgent.JavaClass.onEvent(
@@ -116,7 +124,7 @@ end;
 * 参数2:设备类型,UMConfigure.DEVICE_TYPE_PHONE为手机、UMConfigure.DEVICE_TYPE_BOX为盒子,默认为手机
 * 参数3:Push推送业务的secret
 *)
-class procedure TUMeng.Init(pushSecret: string; IsPhone: Boolean);
+class procedure TUMeng.Init(pushSecret: string; IsPhone: Boolean);
 begin
 {$IFDEF DEBUG}
   Debug;
@@ -136,7 +144,7 @@ begin
 {$ENDIF}
 end;
 
-(**
+(**
 * 初始化common库
 * 参数1:上下文,不能为空
 * 参数2:【友盟+】 AppKey
@@ -170,13 +178,13 @@ begin
 {$ENDIF}
 end;
 
-class procedure TUMeng.onEvent(AID: string;
+class procedure TUMeng.onEvent(AID: string;
   AProperties: TArray<TPair<string, string>>);
 begin
   onEventValue(AID, AProperties);
 end;
 
-class procedure TUMeng.onEventValue(AID: string;
+class procedure TUMeng.onEventValue(AID: string;
   AProperties: TArray<TPair<string, string>>; ADuration: Integer);
 {$IFDEF ANDROID}
 var
@@ -235,7 +243,7 @@ begin
   FLastViewName := ViewName;
 end;
 
-class procedure TUMeng.onPageEnd(ViewName: string);
+class procedure TUMeng.onPageEnd(ViewName: string);
 begin
 {$IFDEF DEBUG}
   Log.d('---onPageEnd:' + ViewName);
@@ -245,7 +253,7 @@ begin
 {$ENDIF}
 end;
 
-class procedure TUMeng.onPageStart(ViewName: string);
+class procedure TUMeng.onPageStart(ViewName: string);
 begin
 {$IFDEF DEBUG}
   Log.d('---onPageStart:' + ViewName);
@@ -255,7 +263,7 @@ begin
 {$ENDIF}
 end;
 
-class procedure TUMeng.onPause;
+class procedure TUMeng.onPause;
 begin
 {$IFDEF DEBUG}
   Log.d('---onPause');
@@ -271,7 +279,7 @@ begin
 {$ENDIF}
 end;
 
-class procedure TUMeng.onResume;
+class procedure TUMeng.onResume;
 begin
 {$IFDEF DEBUG}
   Log.d('---onResume');

+ 1 - 1
Source/ksAndroid.Helpers.pas

@@ -2,7 +2,7 @@
 {                                                       }
 {       Helpers for Android                             }
 {                                                       }
-{       Copyright (C) 2020 KngStr                       }
+{       CopyRight (C) 2018-2020 KngStr                  }
 {                                                       }
 {   Some Code from                                      }
 {     Kastri Free of DelphiWorlds                       }

+ 9 - 1
Source/ksBitmapHelper.pas

@@ -1,4 +1,12 @@
-unit ksBitmapHelper;
+{*******************************************************}
+{                                                       }
+{       Methods of Image                                }
+{                                                       }
+{       CopyRight (C) 2018-2020 KngStr                  }
+{                                                       }
+{*******************************************************}
+
+unit ksBitmapHelper;
 
 // 部分拷贝自 FlyUtils.TBitmapHelper
 

+ 8 - 0
Source/ksFmxUtils.pas

@@ -1,3 +1,11 @@
+{*******************************************************}
+{                                                       }
+{       Methods of FmxObject                            }
+{                                                       }
+{       CopyRight (C) 2018-2020 KngStr                  }
+{                                                       }
+{*******************************************************}
+
 unit ksFmxUtils;
 
 interface

+ 8 - 0
Source/ksObjUtils.pas

@@ -1,3 +1,11 @@
+{*******************************************************}
+{                                                       }
+{       Methods of Object                               }
+{                                                       }
+{       CopyRight (C) 2018-2020 KngStr                  }
+{                                                       }
+{*******************************************************}
+
 unit ksObjUtils;
 
 interface

+ 140 - 1
Source/ksString.pas

@@ -2,7 +2,11 @@
 {                                                       }
 {       Methods of Sting                                }
 {                                                       }
-{       版权所有 (C) 2020 KngStr                        }
+{       CopyRight (C) 2018-2020 KngStr                  }
+{                                                       }
+{   Some Code from                                      }
+{     QDAC of swish                                     }
+{   Thanks                                              }
 {                                                       }
 {*******************************************************}
 
@@ -37,6 +41,26 @@ function FormatSeconds(const AValue: Integer): string; overload;
 function FormatSeconds(const AValue: Double): string; overload;
 
 /// <summary>
+/// 格式化文件大小,拷贝自qdac,增加更多单位
+/// </summary>
+function FormatSize(ASize: Int64): string;
+
+/// <summary>
+/// 文件大小字符串转数字
+/// 1[b] "1 k[b]" " 1 m[b] " 1g[b] 1t[b]
+/// </summary>
+function SizeStrToInt(ASize: string; ADefault: Int64 = 0): Int64;
+
+/// <summary>
+/// 文件大小单位转数字
+/// </summary>
+function SizeUnitToInt(AUnit: string): Int64; overload;
+/// <summary>
+/// 文件大小单位转数字
+/// </summary>
+function SizeUnitToInt(AUnit: Char): Int64; overload;
+
+/// <summary>
 /// 是否中国手机号
 ///  13900000000
 ///  +8613900000000
@@ -134,6 +158,44 @@ begin
   FormatSeconds(Int64(AValue));
 end;
 
+function FormatSize(ASize: Int64): string;
+var
+  AIdx, R1, s1: Int64;
+  AIsNeg: Boolean;
+const
+  Units: array [0 .. 6] of string = ('EB', 'PB', 'TB', 'GB', 'MB', 'KB', 'B');
+begin
+  AIsNeg := (ASize < 0);
+  AIdx := 6;
+  R1 := 0;
+  if AIsNeg then
+    ASize := -ASize;
+  Result := '';
+  while (AIdx >= 0) do
+  begin
+    s1 := ASize mod 1024;
+    ASize := ASize shr 10;
+    if (ASize = 0) or (AIdx = 0) then
+    begin
+      R1 := R1 * 100 div 1024;
+      if R1 > 0 then
+      begin
+        if R1 >= 10 then
+          Result := IntToStr(s1) + '.' + IntToStr(R1) + Units[AIdx]
+        else
+          Result := IntToStr(s1) + '.' + '0' + IntToStr(R1) + Units[AIdx];
+      end
+      else
+        Result := IntToStr(s1) + Units[AIdx];
+      Break;
+    end;
+    R1 := s1;
+    Dec(AIdx);
+  end;
+  if AIsNeg then
+    Result := '-' + Result;
+end;
+
 function IsChineseMobileNumber(S: string; AOnlyNum: Boolean): boolean;
 var
   p: PChar;
@@ -170,4 +232,81 @@ begin
   Result := i = 11; //中国手机号 11位
 end;
 
+function SizeUnitToInt(AUnit: Char): Int64;
+const
+  Units: array [0 .. 6] of Char = ('b', 'k', 'm', 'g', 't', 'p', 'e');
+var
+  I: Integer;
+begin
+  Result := 1;
+
+  for I := Low(Units) to High(Units) do begin
+    if (I > 0) then
+      Result := Result * 1024;
+    if AUnit = Units[I] then
+      Exit;
+  end;
+
+  Result := 1;
+end;
+
+function SizeUnitToInt(AUnit: string): Int64;
+var
+  LSize: string;
+begin
+  Result := 1;
+
+  LSize := Trim(AUnit);
+  case Length(LSize) of
+    1,2: Result := SizeUnitToInt(LSize[Low(LSize)]);
+  end;
+end;
+
+function SizeStrToInt(ASize: string; ADefault: Int64): Int64;
+var
+  p: PChar;
+  c: Char;
+  s: string;
+begin
+  Result := ADefault;
+
+  if Length(ASize) = 0 then
+    Exit;
+
+  s := '';
+  c := #0;
+  p := PChar(ASize);
+  while p^ <> #0 do
+    case p^ of
+      'b', 'k', 'm', 'g', 't', 'p', 'e':
+        begin
+          if c <> #0 then
+            Exit;
+          c := p^;
+          Inc(p);
+          if p^ = 'b' then
+            Inc(p);
+        end;
+      '0' .. '9':
+        begin
+          if c <> #0 then
+            Exit;
+          s := s + p^;
+          Inc(p);
+        end;
+      ',':
+        begin
+          if c <> #0 then
+            Exit;
+          Inc(p);
+        end;
+      ' ':
+        Inc(p);
+    else
+      Exit;
+    end;
+
+  Result := StrToUInt64Def(s, Result) * SizeUnitToInt(c);
+end;
+
 end.