更改扫描APP时会闪一下之前的代码

//

//  DiskManageViewController.m

//  DiskMaster

//

//  Created by chenyongyong on 14-7-1.

//  Copyright (c) 2014 chenyongyong. All rights reserved.

//


#import "DiskManageViewController.h"

#include <sys/mount.h>

#import "ZZGetApplicationList.h"

#import "AppInformationCell.h"

#import "AppDelegate.h"

#import "GNSettingViewController.h"

#import "UMSocial.h"

#import "GNNotification.h"

#import <MediaPlayer/MediaPlayer.h>

#import <AVFoundation/AVFoundation.h>

#import "ZZGetApplicationList.h"

#include<AssetsLibrary/AssetsLibrary.h>

#import "ALAssetsLibrary+EEEConcurrency.h"

#import "ZZMBProgressHUD.h"

#import "GADBannerView.h"


#define  MyBallBj_Top_Height       (GNDEVICE_IS_IPHONE5?30:10)     //圆形总背景距离状态栏高度

#define  CleanButton_Top_Height    (GNDEVICE_IS_IPHONE5?264:225)   //垃圾清理按钮距离状态栏高度

#define  SysInfBjView_Top_Height   (GNDEVICE_IS_IPHONE5?330:290)   //系统占用信息距离状态栏高度

#define  Scaning_Top_Height        (GNDEVICE_IS_IPHONE5?250:210)   //正在扫描中距离状态栏高度

#define  FinishedBj_Top_Height     (GNDEVICE_IS_IPHONE5?250:210)   //清理完成总背景距离状态栏高度


#define  MyFreeSizeDecToZeroTime             6                      //获取释放空间大小后减小到 0 所需时间(单位为 S )

#define  KeyToday    @"keytoday"  //今天KEY

#define  RealFreeDiskSpaceError   (200*1024*1024//200MB(因为发现康总的方法与系统实际的总是差200M左右,为了真实起见,康总方法减去200MB)


#define  GNNotiGetAppFinished @"GNNotiGetAppFinished" //获取APP列表完成通知


extern BOOL isCreatingFile;

static int linshiInt;


@interface DiskManageViewController ()

{

    BOOL                isOpen;                 //审核状态(AppDelegate里的isOpen对应) YES-放开 NO-正在审核

    UIView              *_myBallBjView;         //因为需要翻转动画,此处为圆形背景总的背景图

    

    UIImageView         *_ballImageView;        //上方圆形背景图片

    UIImageView         *_ballOverImageView;    //圆形背景图片背面

    UIImageView         *_rotateImageView;      //高亮旋转图片

    UIView              *_cleanTipBjView;       //清理空间及可用空间提示

    UILabel             *_cleanTipSizeLabel;    //清理大小

    UILabel             *_cleanTipGBLabel;      //清理单位 GB.MB.KB

    UILabel             *_cleanTipText;         //清理文字 可用.垃圾

    UILabel             *_cleanTipTextNoFree;   //"手机中没有垃圾文件"

    NSString            *_cleanUnit;            //清理单位 _cleanTipGBLabel text GB.MB.KB

    UIButton            *_cleanButton;          //开始清理按钮

    

    UIView              *_systemInformationBjView;//系统信息背景(应用--照片--音乐--视频)

    NSString            *applicationSize;        //应用占用大小

    NSString            *photoSize;              //照片占用大小

    NSString            *musicSize;              //音乐占用大小

    NSString            *videoSize;              //视频占用大小

    NSTimer             *mytimer;                //定时器

    NSInteger           percentNumber;           //百分比

    long long           BeforFreeSize;          //清理之前本机剩余空间大小

    long long           AfterFreeSize;          //清理之后本机剩余空间大小

    long long           freeSize;               //释放空间

    

    UILabel             *_cleanTotalSizeLabel;   //累计清理了"0 MB"

    UILabel             *_cleanTotalDaysLabel;   //累计清理天数"12 "

    

    UILabel             *_cleaningOrScaningLabel;//界面中间显示的"正在清理中..."或者"正在扫描中..."

    

    UIImageView         *_cleanFinishedBjView;  //清理完成总的背景图(包括"完成" "分享" "累计清理了" "累计清理天数")

    UIImageView         *_appListBjView;        //APP列表背景图

    UIScrollView        *_myscrollView;         //横向滚动app视图

    UIImageView         *_scanLineImageView;    //加在APP列表上的高亮扫描线

    

    BOOL                myscrollviewStopFlag; //扫描APP动画结束标志 YES-应停止扫描动画

    BOOL                myscrollviewPauseFlag; //myscrollview暂停动画(因为涉及到倒转) YES-暂停状态 NO-已完成

    BOOL                myGetAppInfoFinishedFlag; //获取APP列表信息完成标志  YES-已完成 NO-还在读取

    BOOL                touchedFlag;        //防止重复点击

    

    UIAlertView *alertGetting;

}


@property (nonatomic, strong) NSMutableArray     *applistArray;      //应用列表

@property (nonatomic, assign) unsigned long long freeSpaceSize;      //可用空间


@property (nonatomic,strong) GADBannerView *bannerView;

@end


@implementation DiskManageViewController


- (void)dealloc

{

    [GNNotification notificatonRemove:self name:UIApplicationWillEnterForegroundNotification object:nil];

}

- (void)viewDidLoad

{

    [super viewDidLoad];

    // Do any additional setup after loading the view.

    

    isOpen = GNAppDelegate.isOpen;

    freeSize = 0;

    myscrollviewStopFlag = NO;

    myscrollviewPauseFlag = NO;

    myGetAppInfoFinishedFlag = NO;

    touchedFlag = NO;

    linshiInt = 0;

    if (GNDEVICE_IS_IOS7) {

        self.edgesForExtendedLayout = UIRectEdgeNone;

    }

    self.freeSpaceSize = [self freeDiskSpace];

    percentNumber = 0;

    [self initTitleView];

    AppDelegate *delegate = (AppDelegate *)MY_APPDELEGATE;

    if (delegate.isOpen) {

        [self initNavigationBar];

    }

    

    [GNNotification notificatonRemove:self name:UIApplicationWillEnterForegroundNotification object:nil];

    [GNNotification notificatonAdd:self selector:@selector(handleWillEnterforeground:) name:UIApplicationWillEnterForegroundNotification object:nil];

    

    [self initBackgroundView];

    [self initBallImageView];

    [self initDescribeView];

    [self initCleanButton];

    [self initCleaningOrScaningLabel];

    [self initSystemInformationBjView];

    [self initCleanFinishedBjView];

    [self getApplicationList];

//    [self initAppListBjView];

    

    [self addGoogleAD];

}


- (void)didReceiveMemoryWarning

{

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}


- (void)addGoogleAD

{

    if (!isOpen)

    {

        int i=405;

        if (MY_SCREEN_HEIGHT<=480)

        {

            i=320;

        }

        self.bannerView = [[[GADBannerView alloc] initWithAdSize:kGADAdSizeBanner origin:CGPointMake(0, i)] autorelease];

        self.bannerView.adUnitID = @"a152faebdabb4ef";

        self.bannerView.rootViewController = self;

        [self.view addSubview:self.bannerView];

        [self.bannerView loadRequest:[GADRequest request]];

    }

}


#pragma mark --

#pragma mark init

/**

 *  初始化TitleView

 */

- (void)initTitleView

{

    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 180, 40)];

    titleLabel.backgroundColor = [UIColor clearColor];

    titleLabel.textColor = [UIColor whiteColor];

    titleLabel.text = MyNavigationTitle;

    titleLabel.font = [UIFont boldSystemFontOfSize:22];

    titleLabel.textAlignment = NSTextAlignmentCenter;

    self.navigationItem.titleView = titleLabel;

}


/**

 *  初始化NavigationBar

 */

- (void)initNavigationBar

{

    UIButton *settingButton = [UIButton buttonWithType:UIButtonTypeCustom];

    settingButton.frame = CGRectMake(0, 0, 25, 25);

    settingButton.exclusiveTouch = YES;

    [settingButton setBackgroundImage:[UIImage imageNamed:@"szan.png"] forState:UIControlStateNormal];

    [settingButton addTarget:self action:@selector(getSeting) forControlEvents:UIControlEventTouchUpInside];

    UIBarButtonItem *barBtn = [[UIBarButtonItem alloc] initWithCustomView:settingButton];

    self.navigationItem.rightBarButtonItem = barBtn;

}


/**

 *  初始化整个页面背景图片

 */

- (void)initBackgroundView

{

    UIImageView *bjImageView = [[UIImageView alloc] init];

    bjImageView.image = [UIImage imageNamed:@"bg.png"];

    bjImageView.frame = CGRectMake(0, 0, self.view.frame.size.width, GNDEVICE_SCREEN_HEIGHT-64);

    [self.view addSubview:bjImageView];

}


- (void)initBallImageView

{

    if (!_myBallBjView) {

        _myBallBjView = [[UIView alloc] init];

    }

    

    _myBallBjView.frame = CGRectMake((GNDEVICE_SCREEN_WIDTH-201)/2.0, MyBallBj_Top_Height, 201, 201);

    _myBallBjView.backgroundColor = [UIColor clearColor];

    [self.view addSubview:_myBallBjView];

    

    //圆背景图

    if (!_ballImageView) {

        _ballImageView = [[UIImageView alloc] init];

    }

    //    _ballImageView.frame = CGRectMake((GNDEVICE_SCREEN_WIDTH-201)/2.0, 30, 201, 201);

    _ballImageView.frame = CGRectMake(0, 0, 201, 201);

    _ballImageView.image = [UIImage imageNamed:@"ball_bg.png"];

    _ballImageView.userInteractionEnabled = YES;

    [_myBallBjView addSubview:_ballImageView];

    

    //上方圆形背景上加的用来响应的UIButton,相当于点击了"垃圾清理"按钮

    UIButton *ballImageViewButton = [UIButton buttonWithType:UIButtonTypeCustom];

    ballImageViewButton.backgroundColor = [UIColor clearColor];

    ballImageViewButton.frame = CGRectMake(0, 0, _ballImageView.frame.size.width, _ballImageView.frame.size.height);

    [ballImageViewButton addTarget:self action:@selector(cleanButtonClicked:) forControlEvents:UIControlEventTouchUpInside];

    [_ballImageView addSubview:ballImageViewButton];

    

    //高亮旋转动画图片

    if (!_rotateImageView) {

        _rotateImageView = [[UIImageView alloc] init];

    }

    _rotateImageView.frame = CGRectMake(0, 0, _ballImageView.frame.size.width, _ballImageView.frame.size.height);

    _rotateImageView.image = [UIImage imageNamed:@"ball_zhuan.png"];

    _rotateImageView.alpha = 0.0;

    [_ballImageView addSubview:_rotateImageView];

    

    if (!_ballOverImageView) {

        _ballOverImageView = [[UIImageView alloc] init];

    }

    //    _ballOverImageView.frame = CGRectMake((GNDEVICE_SCREEN_WIDTH-201)/2.0, 30, 201, 201);

    _ballOverImageView.frame = CGRectMake(0, 0, 201, 201);

    _ballOverImageView.image = [UIImage imageNamed:@"ball_over.png"];

    _ballOverImageView.alpha = 0.0;

    _ballOverImageView.userInteractionEnabled = YES;

    [_myBallBjView addSubview:_ballOverImageView];

    [_myBallBjView sendSubviewToBack:_ballOverImageView];

    

    //上方圆形背景图背面上加的用来响应UIButton,相当于点击了"完成"按钮

    UIButton *ballOverImageViewButton = [UIButton buttonWithType:UIButtonTypeCustom];

    ballOverImageViewButton.backgroundColor = [UIColor clearColor];

    ballOverImageViewButton.frame = CGRectMake(0, 0, _ballOverImageView.frame.size.width, _ballOverImageView.frame.size.height);

    [ballOverImageViewButton addTarget:self action:@selector(finishedButtonClicked:) forControlEvents:UIControlEventTouchUpInside];

    [_ballOverImageView addSubview:ballOverImageViewButton];

    

    //文字信息 "手机中没有垃圾文件"

    if (!_cleanTipTextNoFree) {

        _cleanTipTextNoFree = [[UILabel alloc] init];

    }

    _cleanTipTextNoFree.frame = CGRectMake(25, 120, 150, 13);

    _cleanTipTextNoFree.textColor = [UIColor whiteColor];

    _cleanTipTextNoFree.text = @"手机中没有垃圾文件";

    _cleanTipTextNoFree.font = [UIFont fontWithName:@"Eurostile" size:12.0];

    _cleanTipTextNoFree.textAlignment = GNTextAlignmentCenter;

    _cleanTipTextNoFree.alpha = 0.0;

    _cleanTipTextNoFree.backgroundColor = [UIColor clearColor];

    [_ballOverImageView addSubview:_cleanTipTextNoFree];

}


/**

 *  初始化描述信息

 */

- (void)initDescribeView

{

    if (!_cleanTipBjView) {

        _cleanTipBjView = [[UIView alloc] init];

    }

    

    //背景

    _cleanTipBjView.frame = CGRectMake(75, 120, 150, 80);

    _cleanTipBjView.backgroundColor = [UIColor clearColor];

    _cleanTipBjView.alpha = 1.0;

    _cleanTipBjView.userInteractionEnabled = NO;

    [self.view addSubview:_cleanTipBjView];

    

    //空间大小及清理掉的大小

    if (!_cleanTipSizeLabel) {

        _cleanTipSizeLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];

    }

    NSString *sizeFree = [self formattedFileSize:self.freeSpaceSize];

    UIFont *font = [UIFont fontWithName:@"Eurostile" size:36.0];;

    CGSize size = CGSizeMake(320,2000);

    CGSize labelsize = [sizeFree sizeWithFont:font constrainedToSize:size lineBreakMode:GNLineBreakModeWordWrap];

    _cleanTipSizeLabel.frame = CGRectMake(0, 0, labelsize.width, 80);

    _cleanTipSizeLabel.textAlignment = GNTextAlignmentLeft;

    _cleanTipSizeLabel.font = [UIFont fontWithName:@"Eurostile" size:36.0];

    _cleanTipSizeLabel.textColor = [UIColor whiteColor];

    _cleanTipSizeLabel.text = sizeFree;

    _cleanTipSizeLabel.numberOfLines = 0;

    _cleanTipSizeLabel.backgroundColor = [UIColor clearColor]; //奇怪了 IOS6的系统上必须加上这句话才行,不然显示的是空白,在IOS7不加也正常

    [_cleanTipBjView addSubview:_cleanTipSizeLabel];

    

    //单位 GB.MB.KB.B

    if (!_cleanTipGBLabel) {

        _cleanTipGBLabel = [[UILabel alloc] init];

    }

    _cleanTipGBLabel.frame = CGRectMake(_cleanTipSizeLabel.frame.size.width+3,_cleanTipSizeLabel.frame.size.height/2.0-14 , 30, 13);

    _cleanTipGBLabel.textColor = [UIColor whiteColor];

    _cleanTipGBLabel.text = _cleanUnit;

    _cleanTipGBLabel.font = [UIFont fontWithName:@"Eurostile" size:13.0];

    _cleanTipGBLabel.textAlignment = GNTextAlignmentLeft;

    _cleanTipGBLabel.hidden = NO;

    _cleanTipGBLabel.backgroundColor = [UIColor clearColor];

    [_cleanTipBjView addSubview:_cleanTipGBLabel];

    

    //文字信息可用” “垃圾

    if (!_cleanTipText) {

        _cleanTipText = [[UILabel alloc] init];

    }

    _cleanTipText.frame = CGRectMake(_cleanTipSizeLabel.frame.size.width+3,_cleanTipSizeLabel.frame.size.height/2.0 , 30, 13);

    _cleanTipText.textColor = [UIColor whiteColor];

    _cleanTipText.text = @"可用";

    _cleanTipText.font = [UIFont fontWithName:@"Eurostile" size:11.0];

    _cleanTipText.textAlignment = GNTextAlignmentLeft;

    _cleanTipText.alpha = 1.0;

    _cleanTipText.backgroundColor = [UIColor clearColor];

    [_cleanTipBjView addSubview:_cleanTipText];

    

    CGRect rect = _cleanTipBjView.frame;

    rect.size.width = _cleanTipSizeLabel.frame.size.width + 25;

    _cleanTipBjView.frame = rect;

    _cleanTipBjView.center = _myBallBjView.center;

}


//刷新旋转图像中间显示label

- (void)refrushCleanTipBjViewFrame

{

    CGSize size = CGSizeMake(320,2000);

    CGSize labelsize = [_cleanTipSizeLabel.text sizeWithFont:_cleanTipSizeLabel.font constrainedToSize:size lineBreakMode:GNLineBreakModeWordWrap];

    _cleanTipSizeLabel.frame = CGRectMake(0, 0, labelsize.width, 80);

    

    //去判断是 "%" 还是单位"GB-MB-KB"来相应调整高度

    if ([_cleanTipGBLabel.text isEqualToString:@"%"]) {

        _cleanTipGBLabel.font = [UIFont fontWithName:@"Eurostile" size:17.0];

        _cleanTipGBLabel.frame = CGRectMake(_cleanTipSizeLabel.frame.size.width+3,_cleanTipSizeLabel.frame.size.height/2.0-16 , 30, 15);

    } else {

        _cleanTipGBLabel.font = [UIFont fontWithName:@"Eurostile" size:13.0];

        _cleanTipGBLabel.frame = CGRectMake(_cleanTipSizeLabel.frame.size.width+3,_cleanTipSizeLabel.frame.size.height/2.0-14 , 30, 13);

    }

    

    //这个不需要调整

    _cleanTipText.frame = CGRectMake(_cleanTipSizeLabel.frame.size.width+3,_cleanTipSizeLabel.frame.size.height/2.0 , 40, 13);

    

    CGRect rect = _cleanTipBjView.frame;

    rect.size.width = _cleanTipSizeLabel.frame.size.width + 25;

    _cleanTipBjView.frame = rect;

    _cleanTipBjView.center = _myBallBjView.center;

}


/**

 *  初始化开始清理按钮

 */

- (void)initCleanButton

{

    if (!_cleanButton) {

        _cleanButton = [UIButton buttonWithType:UIButtonTypeCustom];

    }

    _cleanButton.frame = CGRectMake((GNDEVICE_SCREEN_WIDTH-282)/2.0, CleanButton_Top_Height, 282, 50);

    [_cleanButton setBackgroundImage:[UIImage imageNamed:@"btn_ksql.png"] forState:UIControlStateNormal];

    [_cleanButton setBackgroundImage:[UIImage imageNamed:@"btn_ksql_1.png"] forState:UIControlStateHighlighted];

    [_cleanButton addTarget:self action:@selector(cleanButtonClicked:) forControlEvents:UIControlEventTouchUpInside];

    _cleanButton.alpha = 1.0;

    if (!isOpen) _cleanButton.alpha = 0.0;

    [self.view addSubview:_cleanButton];

}


/**

 *  初始化界面中间显示的"正在清理中..."或者"正在扫描中..."

 */

- (void)initCleaningOrScaningLabel

{

    if (!_cleaningOrScaningLabel) {

        _cleaningOrScaningLabel = [[UILabel alloc] init];

    }

    _cleaningOrScaningLabel.frame = CGRectMake(0, Scaning_Top_Height, GNDEVICE_SCREEN_WIDTH, 60);

    _cleaningOrScaningLabel.text = @"正在扫描中...";

    _cleaningOrScaningLabel.alpha = 0.0;

    _cleaningOrScaningLabel.textColor = [UIColor whiteColor];

    _cleaningOrScaningLabel.backgroundColor = [UIColor clearColor];

    _cleaningOrScaningLabel.font = [UIFont boldSystemFontOfSize:13.0f];

    _cleaningOrScaningLabel.textAlignment = GNTextAlignmentCenter;

    [self.view addSubview:_cleaningOrScaningLabel];

}


/**

 *  初始化系统占用信息背景

 */

- (void)initSystemInformationBjView

{

    if (!_systemInformationBjView) {

        _systemInformationBjView = [[UIView alloc] init];

    }

    if (isOpen) {

        _systemInformationBjView.frame = CGRectMake(0, SysInfBjView_Top_Height, self.view.frame.size.width, 55.0);

    } else {

        _systemInformationBjView.frame = CGRectMake(0, SysInfBjView_Top_Height-50, self.view.frame.size.width, 55.0);

    }

    

    _systemInformationBjView.backgroundColor = [UIColor clearColor];

    [self.view addSubview:_systemInformationBjView];

    

    //中间横线

    UIImageView *lineImageView = [[UIImageView alloc] init];

    lineImageView.frame = CGRectMake(20, _systemInformationBjView.frame.size.height/2.0 + 2, 276, 1);

    lineImageView.image = [UIImage imageNamed:@"information_line.png"];

    [_systemInformationBjView addSubview:lineImageView];

    

    //应用图标 --------------------------

    UIImageView *appIcon = [[UIImageView alloc] init];

    appIcon.frame = CGRectMake(20, 0, 22, 22);

    appIcon.image = [UIImage imageNamed:@"icon_1.png"];

    [_systemInformationBjView addSubview:appIcon];

    

    //文字"应用"

    UILabel *appNameLabel = [[UILabel alloc] init];

    appNameLabel.frame = CGRectMake(appIcon.frame.origin.x+30, 0, 30, 22);

    appNameLabel.text = @"应用";

    appNameLabel.textColor = MY_RGBCOLOR(255, 255, 255);

    appNameLabel.font = [UIFont systemFontOfSize:14.0f];

    appNameLabel.backgroundColor = [UIColor clearColor];

    [_systemInformationBjView addSubview:appNameLabel];

    

    //"应用"大小

    UILabel *appSizeLabel = [[UILabel alloc] init];

    appSizeLabel.frame = CGRectMake(appNameLabel.frame.origin.x + appNameLabel.frame.size.width , 1.0, 30+25, 22);

    [self getSystemApplicationSize];

//    if ([NSUserDefaults standardUserDefaults] objectForKey:SavedApplicationSize) {

//        appSizeLabel.text =

//    }

    if ([[NSUserDefaults standardUserDefaults] objectForKey:SavedApplicationSize]) {

        appSizeLabel.text = [[NSUserDefaults standardUserDefaults] objectForKey:SavedApplicationSize];

    } else {

        appSizeLabel.text = @"读取中...";

    }

    

    appSizeLabel.textColor = MY_RGBCOLOR(255, 255, 255);

    appSizeLabel.font = [UIFont systemFontOfSize:13.0f];

    appSizeLabel.backgroundColor = [UIColor clearColor];

    appSizeLabel.textAlignment = GNTextAlignmentRight;

    appSizeLabel.tag = 111;

    [_systemInformationBjView addSubview:appSizeLabel];

    

    //"应用"单位 "KB-MB-GB"

    //    UILabel *appUnitLabel = [[UILabel alloc] init];

    //    appUnitLabel.frame = CGRectMake(appSizeLabel.frame.origin.x + appSizeLabel.frame.size.width +3, 1.0, 30, 22);

    //    appUnitLabel.text = @"MB";

    //    appUnitLabel.textColor = MY_RGBCOLOR(255, 255, 255);

    //    appUnitLabel.font = [UIFont systemFontOfSize:13.0f];

    //    appUnitLabel.backgroundColor = [UIColor clearColor];

    //    appUnitLabel.textAlignment = GNTextAlignmentLeft;

    //    [_systemInformationBjView addSubview:appUnitLabel];

    

    //照片图标 --------------------------

    UIImageView *photoIcon = [[UIImageView alloc] init];

    photoIcon.frame = CGRectMake(183, 0, 22, 22);

    photoIcon.image = [UIImage imageNamed:@"icon_3.png"];

    [_systemInformationBjView addSubview:photoIcon];

    

    //文字"照片"

    UILabel *photoNameLabel = [[UILabel alloc] init];

    photoNameLabel.frame = CGRectMake(photoIcon.frame.origin.x+30, 0, 30, 22);

    photoNameLabel.text = @"照片";

    photoNameLabel.textColor = MY_RGBCOLOR(255, 255, 255);

    photoNameLabel.font = [UIFont systemFontOfSize:14.0f];

    photoNameLabel.backgroundColor = [UIColor clearColor];

    [_systemInformationBjView addSubview:photoNameLabel];

    

    //"照片"大小

    UILabel *photoSizeLabel = [[UILabel alloc] init];

    photoSizeLabel.frame = CGRectMake(photoNameLabel.frame.origin.x + photoNameLabel.frame.size.width, 1.0, 30+25, 22);

    [self getSystemPhotosSize];

    if ([[NSUserDefaults standardUserDefaults] objectForKey:SavedPhotosSize]) {

        photoSizeLabel.text = [[NSUserDefaults standardUserDefaults] objectForKey:SavedPhotosSize];

    } else {

        photoSizeLabel.text = @"读取中...";

    }

    photoSizeLabel.textColor = MY_RGBCOLOR(255, 255, 255);

    photoSizeLabel.font = [UIFont systemFontOfSize:13.0f];

    photoSizeLabel.backgroundColor = [UIColor clearColor];

    photoSizeLabel.textAlignment = GNTextAlignmentRight;

    photoSizeLabel.tag = 222;

    [_systemInformationBjView addSubview:photoSizeLabel];

    

    //"照片"单位 "KB-MB-GB"

    //    UILabel *photoUnitLabel = [[UILabel alloc] init];

    //    photoUnitLabel.frame = CGRectMake(photoSizeLabel.frame.origin.x + photoSizeLabel.frame.size.width +3, 1.0, 30, 22);

    //    photoUnitLabel.text = @"MB";

    //    photoUnitLabel.textColor = MY_RGBCOLOR(255, 255, 255);

    //    photoUnitLabel.font = [UIFont systemFontOfSize:13.0f];

    //    photoUnitLabel.backgroundColor = [UIColor clearColor];

    //    [_systemInformationBjView addSubview:photoUnitLabel];

    

    //音乐图标 --------------------------

    UIImageView *musicIcon = [[UIImageView alloc] init];

    musicIcon.frame = CGRectMake(20, 38, 22, 22);

    musicIcon.image = [UIImage imageNamed:@"icon_5.png"];

    [_systemInformationBjView addSubview:musicIcon];

    

    //文字"音乐"

    UILabel *musicNameLabel = [[UILabel alloc] init];

    musicNameLabel.frame = CGRectMake(musicIcon.frame.origin.x+30, musicIcon.frame.origin.y, 30, 22);

    musicNameLabel.text = @"音乐";

    musicNameLabel.textColor = MY_RGBCOLOR(255, 255, 255);

    musicNameLabel.font = [UIFont systemFontOfSize:14.0f];

    musicNameLabel.backgroundColor = [UIColor clearColor];

    [_systemInformationBjView addSubview:musicNameLabel];

    

    //"音乐"大小

    UILabel *musicSizeLabel = [[UILabel alloc] init];

    musicSizeLabel.frame = CGRectMake(musicNameLabel.frame.origin.x + musicNameLabel.frame.size.width, musicIcon.frame.origin.y+1.0, 30+25, 22);

//    musicSizeLabel.text = [self getSystemMusicSize]; //cyy 这个方法也是反应慢的原因之一 还有一个原因:获取APP安装列表信息getApplicationList

    [self getSystemMusicSize];

    if ([[NSUserDefaults standardUserDefaults] objectForKey:SavedMusicSize]) {

        musicSizeLabel.text = [[NSUserDefaults standardUserDefaults] objectForKey:SavedMusicSize];

    } else {

        musicSizeLabel.text = @"读取中...";

    }

    musicSizeLabel.textColor = MY_RGBCOLOR(255, 255, 255);

    musicSizeLabel.font = [UIFont systemFontOfSize:13.0f];

    musicSizeLabel.backgroundColor = [UIColor clearColor];

    musicSizeLabel.textAlignment = GNTextAlignmentRight;

    musicSizeLabel.tag = 333;

    [_systemInformationBjView addSubview:musicSizeLabel];

    

    //"音乐"单位 "KB-MB-GB"

    //    UILabel *musicUnitLabel = [[UILabel alloc] init];

    //    musicUnitLabel.frame = CGRectMake(musicSizeLabel.frame.origin.x + musicSizeLabel.frame.size.width +3, musicIcon.frame.origin.y+1.0, 30, 22);

    //    musicUnitLabel.text = @"MB";

    //    musicUnitLabel.textColor = MY_RGBCOLOR(255, 255, 255);

    //    musicUnitLabel.font = [UIFont systemFontOfSize:13.0f];

    //    musicUnitLabel.backgroundColor = [UIColor clearColor];

    //    [_systemInformationBjView addSubview:musicUnitLabel];

    

    //视频图标 --------------------------

    UIImageView *videoIcon = [[UIImageView alloc] init];

    videoIcon.frame = CGRectMake(183, 38, 22, 22);

    videoIcon.image = [UIImage imageNamed:@"icon_2.png"];

    [_systemInformationBjView addSubview:videoIcon];

    

    //文字"视频"

    UILabel *videoNameLabel = [[UILabel alloc] init];

    videoNameLabel.frame = CGRectMake(videoIcon.frame.origin.x+30, videoIcon.frame.origin.y, 30, 22);

    videoNameLabel.text = @"视频";

    videoNameLabel.textColor = MY_RGBCOLOR(255, 255, 255);

    videoNameLabel.font = [UIFont systemFontOfSize:14.0f];

    videoNameLabel.backgroundColor = [UIColor clearColor];

    [_systemInformationBjView addSubview:videoNameLabel];

    

    //"视频"大小

    UILabel *videoSizeLabel = [[UILabel alloc] init];

    videoSizeLabel.frame = CGRectMake(videoNameLabel.frame.origin.x + videoNameLabel.frame.size.width, videoIcon.frame.origin.y+1.0, 30+25, 22);

    [self getSystemVideoSize];

    if ([[NSUserDefaults standardUserDefaults] objectForKey:SavedVideoSize]) {

        videoSizeLabel.text = [[NSUserDefaults standardUserDefaults] objectForKey:SavedVideoSize];

    } else {

        videoSizeLabel.text = @"读取中...";

    }

    videoSizeLabel.textColor = MY_RGBCOLOR(255, 255, 255);

    videoSizeLabel.font = [UIFont systemFontOfSize:13.0f];

    videoSizeLabel.backgroundColor = [UIColor clearColor];

    videoSizeLabel.textAlignment = GNTextAlignmentRight;

    videoSizeLabel.tag = 444;

    [_systemInformationBjView addSubview:videoSizeLabel];

    

    //"视频"单位 "KB-MB-GB"

    //    UILabel *videoUnitLabel = [[UILabel alloc] init];

    //    videoUnitLabel.frame = CGRectMake(videoSizeLabel.frame.origin.x + videoSizeLabel.frame.size.width +3, videoIcon.frame.origin.y+1.0, 30, 22);

    //    videoUnitLabel.text = @"MB";

    //    videoUnitLabel.textColor = MY_RGBCOLOR(255, 255, 255);

    //    videoUnitLabel.font = [UIFont systemFontOfSize:13.0f];

    //    videoUnitLabel.backgroundColor = [UIColor clearColor];

    //    [_systemInformationBjView addSubview:videoUnitLabel];

}


/**

 *  保存到 NSUserDefaults

 */

- (void)savedToUserDefStr:(NSString *)obj forKey:(NSString *)key

{

    if (!obj || !key) return;

    

    [[NSUserDefaults standardUserDefaults] setObject:obj forKey:key];

    [[NSUserDefaults standardUserDefaults] synchronize];

}


/**

 *  获取系统应用所占空间大小

 */

- (void)getSystemApplicationSize

{

    __block long long systemApplicationSize = 0;

    dispatch_async(dispatch_get_global_queue(0, 0), ^{

        

        NSDictionary *dic = [ZZGetApplicationList getApplicationDiskUsageList];

        [dic enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {

            if (![key hasPrefix:@"com.apple"]) {

                systemApplicationSize += [[obj objectForKey:@"Dynamic"]longLongValue];

                systemApplicationSize += [[obj objectForKey:@"Static"]longLongValue];

            }

        }];

        dispatch_async(dispatch_get_main_queue(), ^{

            

            UILabel *applicationSizeTemp = (UILabel *)[_systemInformationBjView viewWithTag:111];

            applicationSizeTemp.text = [self formattedSystemInfo:systemApplicationSize];

            

            [self savedToUserDefStr:[self formattedSystemInfo:systemApplicationSize] forKey:SavedApplicationSize];

        });

    });

    

}


/**

 *  获取系统音乐所占空间大小

 */

- (void)getSystemMusicSize

{

    dispatch_async(dispatch_get_global_queue(0, 0), ^{

    

            int musicUsage = [MPMediaQuery songsQuery].items.count * 4;

        

        dispatch_async(dispatch_get_main_queue(), ^{

            UILabel *musicSizeLabel = (UILabel *)[_systemInformationBjView viewWithTag:333];

            musicSizeLabel.text = [self formattedSystemInfo:musicUsage*1024*1024];

            

            [self savedToUserDefStr:[self formattedSystemInfo:musicUsage*1024*1024] forKey:SavedMusicSize];

        });

    });

}




/**

 *  获取系统照片所占空间大小

 */

- (void)getSystemPhotosSize

{

    __block unsigned long long photosSize = 0;

    __block BOOL photoFlag = NO;

    

    dispatch_async(dispatch_get_global_queue(0, 0), ^{

        

        ALAssetsLibrary *library=[[ALAssetsLibrary alloc]init];

        void (^assetEnumerator)( ALAsset *, NSUInteger, BOOL *) = ^(ALAsset *result, NSUInteger index, BOOL *stop) {

            if(result != nil) {

                if([[result valueForProperty:ALAssetPropertyType] isEqualToString:ALAssetTypePhoto]) {

                    photosSize += [[result defaultRepresentation]size];

                }

            }

        };

        void (^ assetGroupEnumerator)( ALAssetsGroup *, BOOL *)= ^(ALAssetsGroup *group, BOOL *stop) {

            if(group != nil) {

                [group enumerateAssetsUsingBlock:assetEnumerator];

            }

        };

        

        //                [library enumerateGroupsWithTypes:ALAssetsGroupAll

        //                                       usingBlock:assetGroupEnumerator

        //                                     failureBlock:^(NSError *error) {

        //                                         photoFlag = YES;

        //                                     }];

        

        [library eee_enumerateGroupsLockedWithTypes:ALAssetsGroupAll

                                         usingBlock:assetGroupEnumerator

                                       failureBlock:^(NSError *error) {

                                           photoFlag = YES;

                                       }];

        

        dispatch_async(dispatch_get_main_queue(), ^{

            UILabel *photosSizeLabel = (UILabel *)[_systemInformationBjView viewWithTag:222];

            if (photoFlag) {

                photosSizeLabel.text = @"禁止获取";

            } else {

                photosSizeLabel.text = [self formattedSystemInfo:photosSize];

                

                [self savedToUserDefStr:[self formattedSystemInfo:photosSize] forKey:SavedPhotosSize];

            }

        });

    });

}


/**

 *  获取系统视频所占空间大小

 */

- (void)getSystemVideoSize

{

    __block unsigned long long videoSizeTemp = 0;

    __block BOOL videoFlag = NO;

    dispatch_async(dispatch_get_global_queue(0, 0), ^{

        

        ALAssetsLibrary *library=[[ALAssetsLibrary alloc]init];

        void (^assetEnumerator)( ALAsset *, NSUInteger, BOOL *) = ^(ALAsset *result, NSUInteger index, BOOL *stop) {

            if(result != nil) {

                if([[result valueForProperty:ALAssetPropertyType] isEqualToString:ALAssetTypeVideo]) {

                    videoSizeTemp += [[result defaultRepresentation]size];

                }

            }

        };

        void (^ assetGroupEnumerator)( ALAssetsGroup *, BOOL *)= ^(ALAssetsGroup *group, BOOL *stop) {

            if(group != nil) {

                [group enumerateAssetsUsingBlock:assetEnumerator];

            }

        };

        

        //        [library enumerateGroupsWithTypes:ALAssetsGroupAll

        //                               usingBlock:assetGroupEnumerator

        //                             failureBlock:^(NSError *error) {

        //                                 videoFlag = YES;

        //                             }];

        

        [library eee_enumerateGroupsLockedWithTypes:ALAssetsGroupAll usingBlock:assetGroupEnumerator failureBlock:^(NSError *error) {

            videoFlag = YES;

        }];

        

        dispatch_async(dispatch_get_main_queue(), ^{

            UILabel *videoSizeLabel = (UILabel *)[_systemInformationBjView viewWithTag:444];

            if (videoFlag) {

                videoSizeLabel.text = @"禁止获取";

            } else {

                videoSizeLabel.text = [self formattedSystemInfo:videoSizeTemp];

                [self savedToUserDefStr:[self formattedSystemInfo:videoSizeTemp] forKey:SavedVideoSize];

            }

            

        });

    });

}




//- (void)getSystemVideoSize

//{

//    __block unsigned long long videoSizeTemp = 0;

//    ALAssetsLibrary *library=[[ALAssetsLibrary alloc]init];

//

//    void (^assetEnumerator)( ALAsset *, NSUInteger, BOOL *) = ^(ALAsset *result, NSUInteger index, BOOL *stop) {

//        if(result != nil) {

//            if([[result valueForProperty:ALAssetPropertyType] isEqualToString:ALAssetTypeVideo]) {

//                videoSizeTemp += [[result defaultRepresentation] size];

//            }

//        } else {

//            UILabel *videoSizeLabel = (UILabel *)[_systemInformationBjView viewWithTag:444];

//            videoSizeLabel.text = [self formattedSystemInfo:videoSizeTemp];

//        }

//    };

//

//    void (^ assetGroupEnumerator)( ALAssetsGroup *, BOOL *)= ^(ALAssetsGroup *group, BOOL *stop) {

//        if(group != nil) {

//            [group enumerateAssetsUsingBlock:assetEnumerator];

//        }

//    };

//

//    [library enumerateGroupsWithTypes:ALAssetsGroupAll

//                           usingBlock:assetGroupEnumerator

//                         failureBlock:^(NSError *error) {

//                             UILabel *videoSizeLabel = (UILabel *)[_systemInformationBjView viewWithTag:444];

//                             videoSizeLabel.text = @"禁止获取";

//                         }];

//}







//---------------------------------------------- end


///**

// *  获取系统照片所占空间大小

// */

//- (void)getSystemPhotosSize

//{

//    __block unsigned long long photosSize = 0;

//    ALAssetsLibrary *library=[[ALAssetsLibrary alloc]init];

//

//    void (^assetEnumerator)( ALAsset *, NSUInteger, BOOL *) = ^(ALAsset *result, NSUInteger index, BOOL *stop) {

//        if(result != nil) {

//            if([[result valueForProperty:ALAssetPropertyType] isEqualToString:ALAssetTypePhoto]) {

//                photosSize += [[result defaultRepresentation]size];

//            }

//        } else {

//            UILabel *photosSizeLabel = (UILabel *)[_systemInformationBjView viewWithTag:222];

//            photosSizeLabel.text = [self formattedSystemInfo:photosSize];

//        }

//    };

//

//    void (^ assetGroupEnumerator)( ALAssetsGroup *, BOOL *)= ^(ALAssetsGroup *group, BOOL *stop) {

//        if(group != nil) {

//            [group enumerateAssetsUsingBlock:assetEnumerator];

//        }

//    };

//

//    [library enumerateGroupsWithTypes:ALAssetsGroupAll

//

//                           usingBlock:assetGroupEnumerator

//

//                         failureBlock:^(NSError *error) {

//                             UILabel *photosSizeLabel = (UILabel *)[_systemInformationBjView viewWithTag:222];

//                             photosSizeLabel.text = @"禁止获取";

//                         }];

//}

//

///**

// *  获取系统视频所占空间大小

// */

//- (void)getSystemVideoSize

//{

//    __block unsigned long long videoSizeTemp = 0;

//    ALAssetsLibrary *library=[[ALAssetsLibrary alloc]init];

//

//    void (^assetEnumerator)( ALAsset *, NSUInteger, BOOL *) = ^(ALAsset *result, NSUInteger index, BOOL *stop) {

//        if(result != nil) {

//            if([[result valueForProperty:ALAssetPropertyType] isEqualToString:ALAssetTypeVideo]) {

//                videoSizeTemp += [[result defaultRepresentation] size];

//            }

//        } else {

//            UILabel *videoSizeLabel = (UILabel *)[_systemInformationBjView viewWithTag:444];

//            videoSizeLabel.text = [self formattedSystemInfo:videoSizeTemp];

//        }

//    };

//

//    void (^ assetGroupEnumerator)( ALAssetsGroup *, BOOL *)= ^(ALAssetsGroup *group, BOOL *stop) {

//        if(group != nil) {

//            [group enumerateAssetsUsingBlock:assetEnumerator];

//        }

//    };

//

//    [library enumerateGroupsWithTypes:ALAssetsGroupAll

//                           usingBlock:assetGroupEnumerator

//                         failureBlock:^(NSError *error) {

//                             UILabel *videoSizeLabel = (UILabel *)[_systemInformationBjView viewWithTag:444];

//                             videoSizeLabel.text = @"禁止获取";

//                         }];

//}



/**

 *  格式化系统所占空间大小(应用、照片、音乐、视频)

 */

- (NSString *)formattedSystemInfo:(unsigned long long)size

{

    NSString *formattedStr = nil;

    if (size == 0) {

        formattedStr = @"0 MB";

    } else if (size > 0 && size < 1024) {

        formattedStr = [NSString stringWithFormat:@"%qu B", size];

    } else if (size >= 1024 && size < pow(1024, 2)){

        formattedStr = [NSString stringWithFormat:@"%.0f KB", (size / 1024.)];

    } else if (size >= pow(1024, 2) && size < pow(1024, 3)) {

        formattedStr = [NSString stringWithFormat:@"%.0f MB", (size / pow(1024, 2))];

    } else if (size >= pow(1024, 3)) {

        formattedStr = [NSString stringWithFormat:@"%.1f GB", (size / pow(1024, 3))];

    }

    

    return formattedStr;

}


/**

 *  初始化APP列表背景

 */

- (void)initAppListBjView

{

    if (!_appListBjView) {

        _appListBjView = [[UIImageView alloc] init];

    }

    _appListBjView.frame = CGRectMake(0, GNDEVICE_SCREEN_HEIGHT-64-92-50, GNDEVICE_SCREEN_WIDTH, 92);

    _appListBjView.image = [UIImage imageNamed:@"daomiao_bg.png"];

    _appListBjView.backgroundColor = [UIColor clearColor];

    _appListBjView.alpha = 0.0;

    _appListBjView.userInteractionEnabled = NO;

    [self.view addSubview:_appListBjView];

    

    if (!_myscrollView) {

        _myscrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 10, _appListBjView.frame.size.width, _appListBjView.frame.size.height)];

    }

    _myscrollView.backgroundColor = [UIColor clearColor];

    _myscrollView.showsHorizontalScrollIndicator = NO;

    _myscrollView.showsVerticalScrollIndicator = NO;

    _myscrollView.contentSize = CGSizeMake(self.applistArray.count * 80, 80);

    [_appListBjView addSubview:_myscrollView];

    

    //高亮扫描线

    if (!_scanLineImageView) {

        _scanLineImageView = [[UIImageView alloc] init];

    }

    _scanLineImageView.frame = CGRectMake(60, 2, 94, 93); //原来为70

    _scanLineImageView.image = [UIImage imageNamed:@"saomiao_light.png"];

    _scanLineImageView.backgroundColor = [UIColor clearColor];

    [_appListBjView addSubview:_scanLineImageView];

    

    for (int i = 0; i < self.applistArray.count; i++) {

        AppInformationCell *appInformationCell = [[AppInformationCell alloc] init];

        appInformationCell.frame = CGRectMake(i * 80, 0, 80, 80);

        [appInformationCell refreshWithData:[self.applistArray objectAtIndex:i]];

        

        appInformationCell.tag = i+1;

        

        [_myscrollView addSubview:appInformationCell];

    }

}


/**

 *  清理完成总的背景图(包括"完成" "分享" "累计清理了" "累计清理天数")

 */

- (void)initCleanFinishedBjView

{

    //总背景

    if (!_cleanFinishedBjView) {

        _cleanFinishedBjView = [[UIImageView alloc] init];

    }

    _cleanFinishedBjView.frame = CGRectMake(0, FinishedBj_Top_Height, GNDEVICE_SCREEN_WIDTH, 150);

    //    _cleanFinishedBjView.image = [UIImage imageNamed:@"daomiao_bg.png"];

    _cleanFinishedBjView.backgroundColor = [UIColor clearColor];

    _cleanFinishedBjView.alpha = 0.0;

    _cleanFinishedBjView.userInteractionEnabled = YES;

    [self.view addSubview:_cleanFinishedBjView];

    

    //"完成" UIButton

    UIButton *finishedButton = [UIButton buttonWithType:UIButtonTypeCustom];

    //    finishedButton.frame = CGRectMake(20, 15, 150, 51);

    finishedButton.frame = CGRectMake(18-5+2.5, 15, 137, 54);

    [finishedButton setBackgroundImage:[UIImage imageNamed:@"btn_over.png"] forState:UIControlStateNormal];

    [finishedButton setBackgroundImage:[UIImage imageNamed:@"btn_over_1.png"] forState:UIControlStateHighlighted];

    //    [finishedButton setTitle:@"完成" forState:UIControlStateNormal]; //cyy

    [finishedButton addTarget:self action:@selector(finishedButtonClicked:) forControlEvents:UIControlEventTouchUpInside];

    [_cleanFinishedBjView addSubview:finishedButton];

    

    //"分享" UIButton

    UIButton *sharedButton = [UIButton buttonWithType:UIButtonTypeCustom];

    //    sharedButton.frame = CGRectMake(180, 15, 122, 51);

    sharedButton.frame = CGRectMake(172-5+2.5, 15, 137, 54);

    [sharedButton setBackgroundImage:[UIImage imageNamed:@"btn_share.png"] forState:UIControlStateNormal];

    [sharedButton setBackgroundImage:[UIImage imageNamed:@"btn_share_1.png"] forState:UIControlStateHighlighted];

    //    [sharedButton setTitle:@"分享" forState:UIControlStateNormal]; //cyy

    

    [sharedButton setTitleEdgeInsets:UIEdgeInsetsMake(0, 15, 0, 0)];

    [sharedButton addTarget:self action:@selector(sharedButtonClicked:) forControlEvents:UIControlEventTouchUpInside];

    [_cleanFinishedBjView addSubview:sharedButton];

    

    //累计清理大小 Icon

    UIImageView *cleanTotalSizeImageView = [[UIImageView alloc] init];

    cleanTotalSizeImageView.frame = CGRectMake(20, 80, 22, 22);

    cleanTotalSizeImageView.image = [UIImage imageNamed:@"icon_4.png"];

    [_cleanFinishedBjView addSubview:cleanTotalSizeImageView];

    

    //"累计清理了" UILabel

    UILabel *cleanTotalTextLabel = [[UILabel alloc] init];

    cleanTotalTextLabel.frame = CGRectMake(45, 80, 90, 22);

    cleanTotalTextLabel.text = @"累计清理了";

    cleanTotalTextLabel.textColor = [UIColor whiteColor];

    cleanTotalTextLabel.textAlignment = GNTextAlignmentLeft;

    cleanTotalTextLabel.font = [UIFont systemFontOfSize:13.0f];

    cleanTotalTextLabel.backgroundColor = [UIColor clearColor];

    [_cleanFinishedBjView addSubview:cleanTotalTextLabel];

    

    //"累计清理了"

    _cleanTotalSizeLabel = [[UILabel alloc] init];

    _cleanTotalSizeLabel.frame = CGRectMake(200, 80, 100, 22);

    //    _cleanTotalSizeLabel.text = @"912 MB";

    _cleanTotalSizeLabel.text = [self getTotalCleanSize];

    _cleanTotalSizeLabel.textColor = [UIColor whiteColor];

    _cleanTotalSizeLabel.textAlignment = GNTextAlignmentRight;

    _cleanTotalSizeLabel.font = [UIFont systemFontOfSize:13.0f];

    _cleanTotalSizeLabel.backgroundColor = [UIColor clearColor];

    [_cleanFinishedBjView addSubview:_cleanTotalSizeLabel];

    

    //中间的分割线

    UIImageView *middleLineImageView = [[UIImageView alloc] init];

    middleLineImageView.frame = CGRectMake(20, 108, 280, 1);

    middleLineImageView.image = [UIImage imageNamed:@"information_line.png"];

    middleLineImageView.backgroundColor = [UIColor clearColor];

    [_cleanFinishedBjView addSubview:middleLineImageView];

    

    //累计清理天数 Icon

    UIImageView *cleanTotalDaysImageView = [[UIImageView alloc] init];

    cleanTotalDaysImageView.frame = CGRectMake(20, 115, 22, 22);

    cleanTotalDaysImageView.image = [UIImage imageNamed:@"icon_6.png"];

    [_cleanFinishedBjView addSubview:cleanTotalDaysImageView];

    

    //"累计清理天数" UILabel

    UILabel *cleanTotalTextDaysLabel = [[UILabel alloc] init];

    cleanTotalTextDaysLabel.frame = CGRectMake(45, 115, 90, 22);

    cleanTotalTextDaysLabel.text = @"累计清理天数";

    cleanTotalTextDaysLabel.textColor = [UIColor whiteColor];

    cleanTotalTextDaysLabel.textAlignment = GNTextAlignmentLeft;

    cleanTotalTextDaysLabel.font = [UIFont systemFontOfSize:13.0f];

    cleanTotalTextDaysLabel.backgroundColor = [UIColor clearColor];

    [_cleanFinishedBjView addSubview:cleanTotalTextDaysLabel];

    

    //"累计清理天数"

    _cleanTotalDaysLabel = [[UILabel alloc] init];

    _cleanTotalDaysLabel.frame = CGRectMake(200, 115, 100, 22);

    //    _cleanTotalDaysLabel.text = @"12 ";

    _cleanTotalDaysLabel.text = [self getTotalCleanDays];

    _cleanTotalDaysLabel.textColor = [UIColor whiteColor];

    _cleanTotalDaysLabel.textAlignment = GNTextAlignmentRight;

    _cleanTotalDaysLabel.font = [UIFont systemFontOfSize:13.0f];

    _cleanTotalDaysLabel.backgroundColor = [UIColor clearColor];

    [_cleanFinishedBjView addSubview:_cleanTotalDaysLabel];

}


/**

 *  获取累计清理大小(带单位"MB""GB")

 */

- (NSString *)getTotalCleanSize

{

    NSString *cleanSizeStr;

    NSInteger cleanSize = [[NSUserDefaults standardUserDefaults] integerForKey:KeyTotalCleanSize];

    if (cleanSize < 0) cleanSize = 0;

    if (cleanSize <= 1024) {

        cleanSizeStr = [NSString stringWithFormat:@"%d MB",cleanSize];

    } else {

        cleanSizeStr = [NSString stringWithFormat:@"%.1f GB",cleanSize/1024.0];

    }

    

    return cleanSizeStr;

}


/**

 *  保存累计清理大小

 */

- (void)setTotalCleanSize:(long long)size

{

    NSInteger cleanSize = [[NSUserDefaults standardUserDefaults] integerForKey:KeyTotalCleanSize];

    if (cleanSize < 0) cleanSize = 0;

    if (size < 0) size = 0;

    [[NSUserDefaults standardUserDefaults] setInteger:(cleanSize+(int)size) forKey:KeyTotalCleanSize];

    [[NSUserDefaults standardUserDefaults] synchronize];

}


/**

 *  获取累计清理天数("")

 */

- (NSString *)getTotalCleanDays

{

    NSString *cleanDaysStr;

    NSInteger cleanDays = [[NSUserDefaults standardUserDefaults] integerForKey:KeyTotalCleanDays];

    if (cleanDays < 0) cleanDays = 0;

    cleanDaysStr = [NSString stringWithFormat:@"%d ",cleanDays];

    

    return cleanDaysStr;

}


/**

 *  保存累计清理天数(和空间管理SDK不同,这个地方若隔天不清理不需要置0)

 */

- (void)setTotalCleanDays

{

    //上次清理时间

    NSString *lastDate = [[NSUserDefaults standardUserDefaults] objectForKey:KeyToday];

    

    NSDate *today = [NSDate date];

    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];

    [dateFormatter setDateFormat:@"yyyy-MM-dd"];

    NSString *todayDateStr = [dateFormatter stringFromDate:today];

    

    NSInteger cleanDays = [[NSUserDefaults standardUserDefaults] integerForKey:KeyTotalCleanDays];

    if (cleanDays < 0) cleanDays = 0;

    if ([lastDate isEqualToString:todayDateStr]) {

        

    } else {

        cleanDays += 1;

    }

    [[NSUserDefaults standardUserDefaults] setInteger:cleanDays forKey:KeyTotalCleanDays];

    [[NSUserDefaults standardUserDefaults] setObject:todayDateStr forKey:KeyToday];

    [[NSUserDefaults standardUserDefaults] synchronize];

}


#pragma mark --

#pragma mark Methods

/**

 *  右上角设置按钮

 */

- (void)getSeting

{

    if (self.isScanning) {

        [GNAppDelegate tipCleaning];

        return;

    }

    GNSettingViewController *settingViewController = [[GNSettingViewController alloc] init];

    settingViewController.hidesBottomBarWhenPushed = YES;

    settingViewController.fromBottom = YES;

    [self.navigationController pushViewController:settingViewController animated:YES];

}


/**

 *  缩放动画效果

 */

- (void)zoomAnimation

{

    if (myscrollviewStopFlag) return;

    

    _appListBjView.alpha = 1.0;

    for (AppInformationCell *cellView in _myscrollView.subviews) {

        if (cellView.tag == 1) {

            cellView.transform=CGAffineTransformMakeScale(0.7f, 0.7f);

        } else if (cellView.tag == 2) {

            cellView.transform=CGAffineTransformMakeScale(0.8f, 0.8f);

        } else if (cellView.tag == 3) {

            cellView.transform=CGAffineTransformMakeScale(1.0f, 1.0f);

        } else if (cellView.tag == 4) {

            cellView.transform=CGAffineTransformMakeScale(0.8f, 0.8f);

        } else if (cellView.tag == 5) {

            cellView.transform=CGAffineTransformMakeScale(0.7f, 0.7f);

        } else {

            cellView.transform=CGAffineTransformMakeScale(0.67f, 0.67f);

        }

        

        CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];

        // 动画选项设定

        animation.duration = 0.5; // 动画持续时间

        animation.repeatCount = 1; // 重复次数

        animation.autoreverses = NO; // 动画结束时执行逆动画

        animation.removedOnCompletion = NO//下边这两行一定要注意加上

        animation.fillMode = kCAFillModeForwards;

        animation.timingFunction = [CAMediaTimingFunction functionWithName: kCAMediaTimingFunctionEaseInEaseOut];

        // 缩放倍数

        

        if (cellView.tag == 1) {

            animation.fromValue = [NSNumber numberWithFloat:0.7]; // 开始时的倍率

            animation.toValue = [NSNumber numberWithFloat:0.67]; // 结束时的倍率

        } else if (cellView.tag == 2) {

            animation.fromValue = [NSNumber numberWithFloat:0.8]; // 开始时的倍率

            animation.toValue = [NSNumber numberWithFloat:0.7]; // 结束时的倍率

        } else if (cellView.tag == 3) {

            animation.fromValue = [NSNumber numberWithFloat:1.0]; // 开始时的倍率

            animation.toValue = [NSNumber numberWithFloat:0.8]; // 结束时的倍率

        } else if (cellView.tag == 4) {

            animation.fromValue = [NSNumber numberWithFloat:0.8]; // 开始时的倍率

            animation.toValue = [NSNumber numberWithFloat:1.0]; // 结束时的倍率

        } else if (cellView.tag == 5) {

            animation.fromValue = [NSNumber numberWithFloat:0.7]; // 开始时的倍率

            animation.toValue = [NSNumber numberWithFloat:0.8]; // 结束时的倍率

        } else {

            animation.fromValue = [NSNumber numberWithFloat:0.67]; // 开始时的倍率

            animation.toValue = [NSNumber numberWithFloat:0.7]; // 结束时的倍率

        }

        

        // 添加动画

        [cellView.layer addAnimation:animation forKey:@"scale-layer"];

        cellView.tag -=  1;

        

        //扫描线动画效果

        _scanLineImageView.alpha = 1.0;

        CABasicAnimation *animation2 = [CABasicAnimation animationWithKeyPath:@"position"];

        animation2.fromValue = [NSValue valueWithCGRect:CGRectMake(60+44, 2+44, 94, 93)];

        animation2.toValue = [NSValue valueWithCGRect:CGRectMake(60+80+44+5, 2+44, 94, 93)];

        animation2.duration = 0.40;

        animation2.repeatCount = MAXFLOAT;

        animation2.autoreverses = YES;

        animation2.timingFunction = [CAMediaTimingFunction functionWithName: kCAMediaTimingFunctionEaseInEaseOut];

        [_scanLineImageView.layer addAnimation:animation2 forKey:@"scanLineAnimationID"];

    }

    

    linshiInt++;

    [UIView animateWithDuration:0.5 animations:^{

        _myscrollView.contentOffset = CGPointMake(80*linshiInt+40, 0);

    } completion:^(BOOL finished) {

        

        if (linshiInt == self.applistArray.count-5) {

            for (AppInformationCell *cellView in _myscrollView.subviews) {

                cellView.tag += (self.applistArray.count-5);

            }

            _myscrollView.contentOffset = CGPointMake(40, 0);

            linshiInt = 0;

            

            [self performSelector:@selector(zoomAnimation) withObject:nil afterDelay:0.0];

            return ;

        }

        

        [self performSelector:@selector(zoomAnimation) withObject:nil afterDelay:0.28];

    }];

}


/**

 *  点击"开始清理" 不立即显示百分比  这样效果好点(和猎豹一样)

 */

- (void)gradualAnimationTipBjView

{

    if (!mytimer) {

        mytimer = [NSTimer scheduledTimerWithTimeInterval:0.20 target:self selector:@selector(addPercent) userInfo:nil repeats:YES];

    }

    

    percentNumber = 0;

    _cleanTipSizeLabel.text = @"0";

    _cleanTipGBLabel.text = @"%";

    //    _cleanTipText.hidden = YES;

    _cleanTipText.alpha = 0.0;

    [self refrushCleanTipBjViewFrame];

}


/**

 *  正在获取APP列表信息Alert

 */

- (void)alertGettingAppInfo

{

    [GNNotification notificatonRemove:self name:GNNotiGetAppFinished object:nil];

    [GNNotification notificatonAdd:self selector:@selector(autoDismissAlert) name:GNNotiGetAppFinished object:nil];

    

    alertGetting = [[UIAlertView alloc] initWithTitle:nil message:@"正在分析您的设备,请稍候..." delegate:nil cancelButtonTitle:nil otherButtonTitles: nil,nil];

    [alertGetting show];

}


- (void)autoDismissAlert

{

    [alertGetting dismissWithClickedButtonIndex:0 animated:NO];

    [self cleanButtonClicked:nil];

}


/**

 *  "开始清理" 按钮点击

 */

- (void)cleanButtonClicked:(UIButton *)sender

{

    if (!isOpen) return; //审核时不可点(因为圆形图片点击时也会调用到这个方法)

    

    if (touchedFlag) {

        return;

    }

    touchedFlag = YES;

    

    if (!myGetAppInfoFinishedFlag) {

        touchedFlag = NO;

        [self alertGettingAppInfo];

        return;

    }

    

    if ([self firstLaunch]) {

        touchedFlag = NO;

        [self AddGuidePicture];

        return;

    }


//    [GNAppDelegate disableTabbarTouch];

    self.isScanning = YES;

    _cleaningOrScaningLabel.text = @"正在扫描中...";

    myscrollviewStopFlag = NO;

    for (AppInformationCell *cellView in _myscrollView.subviews){

        cellView.transform=CGAffineTransformMakeScale(1.0f, 1.0f);

    }

    

    //_appListBjView 向上浮动出来的动画效果

    _appListBjView.frame = CGRectMake(0, GNDEVICE_SCREEN_HEIGHT-64-50, GNDEVICE_SCREEN_WIDTH, 0);

    _appListBjView.alpha = 1.0;

    [UIView animateWithDuration:0.8 animations:^{

        _appListBjView.alpha = 1.0;

        _appListBjView.frame = CGRectMake(0, GNDEVICE_SCREEN_HEIGHT-64-92-50, GNDEVICE_SCREEN_WIDTH, 92);

    }completion:^(BOOL finished){

        //创建大件

        [self createFile];  //放到这个地方 点击后不至于立即弹出空间不足提醒

    }];

    

    [self zoomAnimation];

    

    _systemInformationBjView.alpha = 0.0;

    

    [UIView animateWithDuration:0.3 animations:^{

        _cleanButton.alpha = 0.0;

        _cleaningOrScaningLabel.alpha = 1.0;

    }completion:nil];

    

    

    //这个地方做下延时  为了过度美观

    [self performSelector:@selector(gradualAnimationTipBjView) withObject:nil afterDelay:0.8];

    

    //高亮圆圈旋转动画效果

    [self rotateAnimation:YES];

    [UIView animateWithDuration:1.0 animations:^{

        _rotateImageView.alpha = 1.0;

    }completion:nil];

}


/**

 *  "完成" 按钮点击

 */

- (void)finishedButtonClicked:(UIButton *)sender

{

    if (touchedFlag) {

        return;

    }

    touchedFlag = YES;

    

    _cleanTipBjView.alpha = 0.0;

    

    [UIView animateWithDuration:1.0 animations:^{

        _cleanFinishedBjView.alpha = 0.0;

    }completion:^(BOOL finished){

        

    }];

    

    [UIView transitionFromView:_ballOverImageView

                        toView:_ballImageView

                      duration: 1.0

                       options: UIViewAnimationOptionTransitionFlipFromLeft+UIViewAnimationOptionCurveEaseInOut

                    completion:^(BOOL finished) {

                        touchedFlag = NO;

                        

                        CGRect rect = _cleanTipBjView.frame;

                        rect.origin.y -= 36;

                        _cleanTipBjView.frame = rect;

                        self.freeSpaceSize = [self freeDiskSpace]; //记得刷新数据

                        _cleanTipSizeLabel.text = [self formattedFileSize:self.freeSpaceSize];

                        _cleanTipText.alpha = 1.0;

                        _cleanTipText.text = @"可用";

                        _cleanTipGBLabel.text = _cleanUnit;

                        [self refrushCleanTipBjViewFrame];

                        

                        [UIView animateWithDuration:0.5 animations:^{

                            _cleanTipBjView.alpha = 1.0;

                        }completion:^(BOOL finished){

                            

                            

                        }];

                        

                        

                        //纯属为了使动画过渡好看、自然

                        [UIView animateWithDuration:0.85 animations:^{

                            _systemInformationBjView.alpha = 1.0;

                            _cleanButton.alpha = 1.0;

                        }completion:^(BOOL finished){

                            

                        }];

                        

                    }

     ];

}


/**

 *  "分享" 按钮点击

 */

- (void)sharedButtonClicked:(UIButton *)sender

{

    WXWebpageObject *wxObj = [WXWebpageObject object];

    wxObj.webpageUrl=[NSString stringWithFormat:@"https://itunes.apple.com/cn/app/id%@?mt=8",APPID];

    [UMSocialData defaultData].extConfig.wxMessageType = UMSocialWXMessageTypeOther;

    [UMSocialData defaultData].extConfig.wxMediaObject = wxObj;

    NSString *str=[NSString stringWithFormat:@"我的设备清理出了%lld %@的垃圾文件!你也来试试吧~ https://itunes.apple.com/cn/app/id%@?mt=8",freeSize,_cleanUnit,APPID];

    [UMSocialSnsService presentSnsIconSheetView:self

                                         appKey:MY_UMENG_KEY

                                      shareText:str

                                     shareImage:[UIImage imageNamed:@"AppIcon57x57"]

                                shareToSnsNames:@[UMShareToWechatSession,UMShareToWechatTimeline, UMShareToSina, UMShareToDouban]

                                       delegate:nil];

    

}


/**

 *  综合旋转动画(把渐变效果加上)

 */

- (void)rotateAnimationTotal:(BOOL)clockwise

{

    [self rotateAnimation:clockwise];

    [UIView animateWithDuration:1.0 animations:^{

        _rotateImageView.alpha = 1.0;

    }completion:nil];

}


/**

 *  清理过程中高亮圆圈旋转动画 clockwise  YES:顺时针旋转 NO:逆时针旋转

 */

- (void)rotateAnimation:(BOOL)clockwise

{

    CGFloat duringTime;

    NSNumber *myNumber ;

    if (clockwise) {

        duringTime = 1.5;

        myNumber = [NSNumber numberWithFloat: (M_PI * 2)];

        _rotateImageView.image = [UIImage imageNamed:@"ball_zhuan.png"];

    } else {

        duringTime = 0.5;

        myNumber = [NSNumber numberWithFloat: (-M_PI * 2)];

        _rotateImageView.image = [UIImage imageNamed:@"ball_zhuan_2.png"];

    }

    CABasicAnimation *rotationAnimation;

    rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];

    rotationAnimation.toValue = myNumber;

    [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];

    rotationAnimation.duration = duringTime;

    rotationAnimation.RepeatCount = MAXFLOAT;//你可以设置到最大的整数值

    rotationAnimation.cumulative = NO;

    rotationAnimation.removedOnCompletion = NO;

    rotationAnimation.fillMode = kCAFillModeForwards;

    rotationAnimation.delegate = self;

    [_rotateImageView.layer addAnimation:rotationAnimation forKey:@"Rotation"];

}


- (void)addPercent

{

    percentNumber++;

    _cleanTipSizeLabel.text = [NSString stringWithFormat:@"%d",percentNumber];

    [self refrushCleanTipBjViewFrame];

    

    if (percentNumber == 100) {

        [self stopMyTimer];

        [self getCleanSize];

        [self setTotalCleanDays]; //不管是否释放了空间,这个时间都要加上

        

        if (freeSize == 0) {

//            [GNAppDelegate enableTabbarTouch];

            self.isScanning = NO;

            [self rotateImageViewDisappearAnimation];

            [self appListGlideAnimation];

            [self cleaningOrScaningAnimation:YES];

            [self performSelector:@selector(flipAnimationNoFree) withObject:nil afterDelay:1.0];

        } else {

            //            [self appListGlideAnimation];

            [self rotateImageViewDisappearAnimation];

            [self setTotalCleanSize:freeSize];

            [self cleanTipBjViewDownAnimation];

        }

    }

}


/**

 *  高亮图片消失动画

 */

- (void)rotateImageViewDisappearAnimation

{

    _rotateImageView.alpha = 1.0;

    [UIView animateWithDuration:0.8 animations:^{

        _rotateImageView.alpha = 0.0;

    }completion:^(BOOL finished){

        [_rotateImageView.layer removeAllAnimations];

    }];

}


/**

 *  停止定时器

 */

- (void)stopMyTimer

{

    if (mytimer) {

        [mytimer invalidate];

        mytimer = nil;

    }

}


/**

 *  百分比从0%100%后此视图下滑动画

 */

- (void)cleanTipBjViewDownAnimation

{

    myscrollviewPauseFlag = YES;

    [self appListGlideAnimation];

    

    [UIView animateWithDuration:1.5 animations:^{

        CGRect rect = _cleanTipBjView.frame;

        rect.origin.y += 40;

        _cleanTipBjView.frame = rect;

        

        _cleanTipBjView.alpha = 0.0;

    }completion:^(BOOL finished){

        

        _cleanTipBjView.alpha = 0.5;

        [UIView animateWithDuration:0.4 animations:^{

            _cleanTipBjView.alpha = 1.0;

        }completion:nil];

        

        _cleanTipSizeLabel.text = [NSString stringWithFormat:@"%lld",freeSize];

        _cleanTipGBLabel.text = _cleanUnit;

        _cleanTipText.text = @"垃圾";

        _cleanTipText.alpha = 1.0;

        [self refrushCleanTipBjViewFrame];

        

        [self addAnimation:_cleanTipBjView.layer atKeyName:nil];

        for (AppInformationCell *cellView in _myscrollView.subviews){

            cellView.transform=CGAffineTransformMakeScale(1.0f, 1.0f);

        }

        [self performSelector:@selector(appListRiseAnimation) withObject:nil afterDelay:0.5];

        

        [self performSelector:@selector(rotateAnimationTotal:) withObject:NO afterDelay:1.0];

        

        [UIView animateWithDuration:1.5 animations:^{

            _cleanTipBjView.alpha = 1.0;

        }completion:^(BOOL finished){

            [self performSelector:@selector(delayOneSecond) withObject:nil afterDelay:1.2];

            [self performSelector:@selector(rotateAnimationDisappear) withObject:nil afterDelay:(MyFreeSizeDecToZeroTime+0.3)];

            

            //            myscrollviewStopFlag = YES;

            //            for (AppInformationCell *cellView in _myscrollView.subviews){

            //                cellView.transform=CGAffineTransformMakeScale(1.0f, 1.0f);

            //            }

            //            [self myScrollViewOffsetAnimation];

        }];

        

    }];

}


#pragma mark --

#pragma mark Animation

/**

 *  获取释放空间大小后的动画效果

 */

-(void)addAnimation:(CALayer *)layer atKeyName:(NSString *)key

{

    CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"transform.scale"];

    animation.values = @[@(0.01), @(1.5), @(0.7), @(1.2), @(1)];

    animation.keyTimes = @[@(0), @(0.3), @(0.6), @(0.8), @(1)];

    animation.timingFunctions = @[[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear], [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear], [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]];

    animation.duration = 0.5;

    animation.delegate = self;

    [layer addAnimation:animation forKey:key];

}


/**

 *  延迟1S再去执行 效果好看点感觉

 */

- (void)delayOneSecond

{

    percentNumber = (int)freeSize;

    if (!mytimer) {

        mytimer = [NSTimer scheduledTimerWithTimeInterval:(MyFreeSizeDecToZeroTime/(float)freeSize) target:self selector:@selector(decrementCleanSize) userInfo:nil repeats:YES];

    }

}


/**

 *  PUSH出来没有垃圾文件提示

 */

- (void)pushNoRubbishFileTip

{

    [self decrementCleanSize];

}


/**

 *  高亮旋转图片消失动画

 */

- (void)rotateAnimationDisappear

{

    [UIView animateWithDuration:1.0 animations:^{

        _rotateImageView.alpha = 0.0;

    }completion:^(BOOL finished){

        [_rotateImageView.layer removeAllAnimations];

    }];

}


/**

 *  清理出来的垃圾文件大小减少到0

 */

- (void)decrementCleanSize

{

    _cleaningOrScaningLabel.text = @"正在清理中...";

    percentNumber--;

    

    _cleanTipSizeLabel.text = [NSString stringWithFormat:@"%d",percentNumber];

    [self refrushCleanTipBjViewFrame];

    if (percentNumber == 0) {

//        [GNAppDelegate enableTabbarTouch];

        self.isScanning = NO;

        [[NSRunLoop mainRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.5]]; //一定要加上这句话 不然界面上显示不到 0

        sleep(0.9);

        [UIView animateWithDuration:1.0 animations:^{

            //            _rotateImageView.alpha = 0.0;

            

            _cleaningOrScaningLabel.alpha = 0.0;

            _systemInformationBjView.alpha = 0.0;

        }completion:^(BOOL finished){

            //            [_rotateImageView.layer removeAllAnimations];

        }];

        

        _cleanTipText.text = @"已清理";

        CGRect rect = _cleanTipText.frame;

        rect.size.width += 10;

        _cleanTipText.frame = rect;

        _cleanTipBjView.alpha = 0.0;

        _ballOverImageView.alpha = 1.0;

        

        

        [self flipAnimation];

        //        [self appListGlideAnimation];//css

        

        

        if (mytimer) {

            [mytimer invalidate];

            mytimer = nil;

        }

    }

}


/**

 *  "正在扫描中..."隐藏或显示动画效果

 */

- (void)cleaningOrScaningAnimation:(BOOL)hidden

{

    if (hidden) {

        _cleaningOrScaningLabel.alpha = 1.0;

        [UIView animateWithDuration:0.8 animations:^{

            _cleaningOrScaningLabel.alpha = 0.0;

        }completion:nil];

    } else {

        _cleaningOrScaningLabel.alpha = 0.0;

        [UIView animateWithDuration:0.8 animations:^{

            _cleaningOrScaningLabel.alpha = 1.0;

        }completion:nil];

    }

}


/**

 *  清理完成后 有释放 圆形背景反转动画

 */

- (void)flipAnimation

{

    _cleanTipTextNoFree.alpha = 0.0;

    [UIView transitionFromView:_ballImageView

                        toView:_ballOverImageView

                      duration: 1.0

                       options: UIViewAnimationOptionTransitionFlipFromLeft+UIViewAnimationOptionCurveEaseInOut

                    completion:^(BOOL finished) {

                        

                        _cleanTipSizeLabel.text = [NSString stringWithFormat:@"%lld",freeSize];

                        [self refrushCleanTipBjViewFrame];

                        

                        _cleanTotalSizeLabel.text = [self getTotalCleanSize];

                        _cleanTotalDaysLabel.text = [self getTotalCleanDays];

                        

                        CGRect rect = _cleanTipBjView.frame;

                        rect.origin.y += 36;

                        _cleanTipBjView.frame = rect;

                        

                        [UIView animateWithDuration:0.5 animations:^{

                            _cleanTipBjView.alpha = 1.0;

                        }completion:nil];

                        

                        [UIView animateWithDuration:0.8 animations:^{

                            _cleanFinishedBjView.alpha = 1.0;

                        }completion:nil];

                        

                    }

     ];

}


/**

 *  清理完成后 无释放 圆形背景反转动画

 */

- (void)flipAnimationNoFree

{

    _ballOverImageView.alpha = 1.0;

    _cleanTipBjView.alpha = 0.0;

    [UIView transitionFromView:_ballImageView

                        toView:_ballOverImageView

                      duration: 1.0

                       options: UIViewAnimationOptionTransitionFlipFromLeft+UIViewAnimationOptionCurveEaseInOut

                    completion:^(BOOL finished) {

                        

                        //                        [self judgePopGiveRateAlert]; //这个好评不要了

                        _cleanTotalSizeLabel.text = [self getTotalCleanSize];

                        _cleanTotalDaysLabel.text = [self getTotalCleanDays];

                        

                        _cleanTipTextNoFree.alpha = 1.0;

                        

                        touchedFlag = NO;

                        [UIView animateWithDuration:0.8 animations:^{

                            _cleanFinishedBjView.alpha = 1.0;

                        }completion:^(BOOL finished){

                            

                        }];

                    }

     ];

}


/**

 *  判断是否弹出给好评提示

 */

- (void)judgePopGiveRateAlert

{

    NSString *key = [NSString stringWithFormat:@"%@-%@",@"FirstRemind",[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"]];

    if (![[NSUserDefaults standardUserDefaults] boolForKey:key]) {

        [[NSUserDefaults standardUserDefaults] setBool:YES forKey:key];

        [[NSUserDefaults standardUserDefaults] synchronize];

        [self remindGiveRate];

    } else {

        

    }

}


/**

 *  提醒用户给好评

 */

- (void)remindGiveRate

{

    UIAlertView *remindGiveRateAlertView = [[UIAlertView alloc] initWithTitle:@"哇塞" message:@"手机中已无垃圾文件,请给我们一个好评,鼓励一下我们!" delegate:self cancelButtonTitle:@"不了" otherButtonTitles:@"没问题", nil];

    [remindGiveRateAlertView show];

}


- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex

{

    if (buttonIndex == 1) {

        if (SYSTEMVERSION>=7.0)

        {

            NSString *str=[NSString stringWithFormat:@"https://itunes.apple.com/cn/app/id%@?mt=8",APPID];

            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];

        }

        else

        {

            NSString *urlString = [NSString stringWithFormat:@"itms-apps://ax.itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?type=Purple+Software&id=%@",APPID];

            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];

        }

    }

}


/**

 *  myScrollView反向滑动动画

 */

- (void)myScrollViewOffsetAnimation

{

    _myscrollView.contentOffset = CGPointMake(80*self.applistArray.count-320-40, 0);

    [UIView animateWithDuration:MyFreeSizeDecToZeroTime animations:^{

        _myscrollView.contentOffset = CGPointMake(40, 0);

    }completion:^(BOOL finished){

        myscrollviewPauseFlag = NO;

        [self appListGlideAnimation];

    }];

}


/**

 *  appListBjView 背景上升动画

 */

- (void)appListRiseAnimation

{

    for (AppInformationCell *cellView in _myscrollView.subviews){

        [cellView.layer removeAllAnimations];

    }

    _scanLineImageView.alpha = 0.0;

    _appListBjView.alpha = 0.0;

    _appListBjView.frame = CGRectMake(0, GNDEVICE_SCREEN_HEIGHT-64-50, GNDEVICE_SCREEN_WIDTH, 92);

    [UIView animateWithDuration:0.8 animations:^{

        _appListBjView.alpha = 1.0;

        _appListBjView.frame = CGRectMake(0, GNDEVICE_SCREEN_HEIGHT-64-92-50, GNDEVICE_SCREEN_WIDTH, 92);

    }completion:^(BOOL finished){

        [self myScrollViewOffsetAnimation];

    }];

}


/**

 *  appListBjView 背景下滑动画

 */

- (void)appListGlideAnimation

{

    _appListBjView.frame = CGRectMake(0, GNDEVICE_SCREEN_HEIGHT-64-92-50, GNDEVICE_SCREEN_WIDTH, 92);

    [UIView animateWithDuration:0.7 animations:^{

        _appListBjView.alpha = 0.0;

        _appListBjView.frame = CGRectMake(0, GNDEVICE_SCREEN_HEIGHT-64-50, GNDEVICE_SCREEN_WIDTH, 92);

    }completion:^(BOOL finished){

        myscrollviewStopFlag = YES;

        [_scanLineImageView.layer removeAllAnimations];

        [_myscrollView.layer removeAllAnimations];

        if (myscrollviewPauseFlag) {

            _myscrollView.contentOffset = CGPointMake(80*self.applistArray.count-320-40, 0);

        } else {

            touchedFlag = NO;

            _myscrollView.contentOffset = CGPointMake(80*linshiInt+40, 0);

        }

    }];

}


/**

 *  可用磁盘空间

 */

- (long long)freeDiskSpace

{

    struct statfs buf;

    long long freespace = -1;

    if(statfs("/var", &buf) >= 0){

        freespace = (long long)(buf.f_bsize * buf.f_bfree);

    }

    return (freespace-RealFreeDiskSpaceError)>0?(freespace-RealFreeDiskSpaceError):0;

    //    return freespace;

}


- (NSString*)formattedFileSize:(unsigned long long)size

{

    NSString *formattedStr = nil;

    if (size == 0) {

        _cleanUnit = @"MB";

        formattedStr = @"0.0";

    } else if (size > 0 && size < 1024) {

        _cleanUnit = @"B";

        formattedStr = [NSString stringWithFormat:@"%qu", size];

    } else if (size >= 1024 && size < pow(1024, 2)){

        _cleanUnit = @"KB";

        formattedStr = [NSString stringWithFormat:@"%.0f", (size / 1024.)];

    } else if (size >= pow(1024, 2) && size < pow(1024, 3)) {

        _cleanUnit = @"MB";

        formattedStr = [NSString stringWithFormat:@"%.0f", (size / pow(1024, 2))];

    } else if (size >= pow(1024, 3)) {

        _cleanUnit = @"GB";

        formattedStr = [NSString stringWithFormat:@"%.1f", (size / pow(1024, 3))];

    }

    

    return formattedStr;

}


/**

 *  获取App列表信息

 */

//- (void)getApplicationList

//{

//    NSMutableArray *array = [NSMutableArray arrayWithCapacity:20];

//    

//    NSDictionary *dic = [ZZGetApplicationList getApplicationInfoList];

//    [dic enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {

//        //发现有的应用貌似获取不到 Dynamic Static 但感觉还是不屏蔽的好

//        if (![key hasPrefix:@"com.apple"] && [obj objectForKey:@"CFBundleDisplayName"]) {

//            NSMutableDictionary *applicationDic = [[NSMutableDictionary alloc] init];

//            [applicationDic setObject:[obj objectForKey:@"CFBundleDisplayName"] forKey:KeyApplicationName];

//            [applicationDic setObject:[ZZGetApplicationList getApplicationIcon:key] forKey:KeyApplicationImage];

//            [array addObject:applicationDic];

//        }

//    }];

//    

//    NSDictionary *dicSystem = [ZZGetApplicationList getSystemApplicationInfoList];

//    [dicSystem enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {

//        if ([ZZGetApplicationList getApplicationIcon:key] && [obj objectForKey:@"CFBundleDisplayName"]) {

//            NSMutableDictionary *applicationDic = [[NSMutableDictionary alloc] init];

//            [applicationDic setObject:[obj objectForKey:@"CFBundleDisplayName"] forKey:KeyApplicationName];

//            [applicationDic setObject:[ZZGetApplicationList getApplicationIcon:key] forKey:KeyApplicationImage];

//            [array addObject:applicationDic];

//        }

//    }];

//    

//    self.applistArray = array;

//}



- (void)getApplicationList

{

    dispatch_async(dispatch_get_global_queue(0, 0), ^{

        

        if (self.applistArray && (self.applistArray.count > 0)) [self.applistArray removeAllObjects];

        

        NSMutableArray *array = [NSMutableArray arrayWithCapacity:20];

        NSDictionary *dic = [ZZGetApplicationList getApplicationInfoList];

        [dic enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {

            //发现有的应用貌似获取不到 Dynamic Static 但感觉还是不屏蔽的好

            if (![key hasPrefix:@"com.apple"] && [obj objectForKey:@"CFBundleDisplayName"]) {

                NSMutableDictionary *applicationDic = [[NSMutableDictionary alloc] init];

                [applicationDic setObject:[obj objectForKey:@"CFBundleDisplayName"] forKey:KeyApplicationName];

                [applicationDic setObject:[ZZGetApplicationList getApplicationIcon:key] forKey:KeyApplicationImage];

                [array addObject:applicationDic];

            }

        }];

        

        NSDictionary *dicSystem = [ZZGetApplicationList getSystemApplicationInfoList];

        [dicSystem enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {

            if ([ZZGetApplicationList getApplicationIcon:key] && [obj objectForKey:@"CFBundleDisplayName"]) {

                NSMutableDictionary *applicationDic = [[NSMutableDictionary alloc] init];

                [applicationDic setObject:[obj objectForKey:@"CFBundleDisplayName"] forKey:KeyApplicationName];

                [applicationDic setObject:[ZZGetApplicationList getApplicationIcon:key] forKey:KeyApplicationImage];

                [array addObject:applicationDic];

            }

        }];

        

        dispatch_async(dispatch_get_main_queue(), ^{

            myGetAppInfoFinishedFlag = YES;

            self.applistArray = array;

            [self initAppListBjView];

            [GNNotification notificatonPost:GNNotiGetAppFinished object:nil userInfo:nil];

        });

    });

}


#pragma mark --

#pragma makr FileManage

/**

 *  创建大文件

 */

//-(void)createFile

//{

//    isCreatingFile = YES;

//    BeforFreeSize = [self freeDiskSpace];

//    NSLog(@"清理之前本机剩余空间:  %lld",BeforFreeSize);

//    long long freeSizeCreate=BeforFreeSize*1.5;  //cyy这个地方本来是 1.1 但这样的话如果要获取的是真实剩余空间在扫描完成后点完成反转过来会显示 0.0

//    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

//        

//        NSString *path =[NSString stringWithFormat:@"%@/Documents/000.txt",NSHomeDirectory()];

//        FILE* file = fopen([path UTF8String], "w+");

//        fsetpos(file, &freeSizeCreate);

//        fwrite("", 1, 1, file);

//        fclose(file);

//        

//        NSString *path1 =[NSString stringWithFormat:@"%@/Documents/001.txt",NSHomeDirectory()];

//        FILE* file1 = fopen([path1 UTF8String], "w+");

//        fsetpos(file1, &freeSizeCreate);

//        fwrite("", 1, 1, file1);

//        fclose(file1);

//        

//        dispatch_async(dispatch_get_main_queue(), ^{

//            

//            NSFileManager *fileManager = [NSFileManager defaultManager];

//            if([fileManager fileExistsAtPath:path])

//            {

//                [fileManager removeItemAtPath:path error:nil];

//            }

//            if([fileManager fileExistsAtPath:path1])

//            {

//                [fileManager removeItemAtPath:path1 error:nil];

//            }

//            

//            isCreatingFile = NO;

//        });

//    });

//}




-(void)createFile

{

    isCreatingFile = YES;

    BeforFreeSize = [self freeDiskSpace];

    NSLog(@"清理之前本机剩余空间:  %lld",BeforFreeSize);

    long long freeSizeCreate=BeforFreeSize*1.6//cyy这个地方本来是 1.1 但这样的话如果要获取的是真实剩余空间在扫描完成后点完成反转过来会显示 0.0

    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

    

        NSLog(@"begin begin begin ...");

        NSString *path =[NSString stringWithFormat:@"%@/Documents/000.txt",NSHomeDirectory()];

        FILE* file = fopen([path UTF8String], "w+");

        fsetpos(file, &freeSizeCreate);

        fwrite("", 1, 1, file);

        fclose(file);

        

//        NSString *path1 =[NSString stringWithFormat:@"%@/Documents/001.txt",NSHomeDirectory()];

//        FILE* file1 = fopen([path1 UTF8String], "w+");

//        fsetpos(file1, &freeSizeCreate);

//        fwrite("", 1, 1, file1);

//        fclose(file1);

        

        dispatch_async(dispatch_get_main_queue(), ^{

    

            

            NSFileManager *fileManager = [NSFileManager defaultManager];

            if([fileManager fileExistsAtPath:path])

            {

                [fileManager removeItemAtPath:path error:nil];

            }

            NSLog(@"end end end .........");

//            if([fileManager fileExistsAtPath:path1])

//            {

//                [fileManager removeItemAtPath:path1 error:nil];

//            }

            

            isCreatingFile = NO;

        });

    });

}


/**

 *  获取完成清理后释放空间大小

 */

- (void)getCleanSize

{

    AfterFreeSize =[self freeDiskSpace];

    long long size =AfterFreeSize - BeforFreeSize;

    

    if (size <= 0) {

        size = 0;

    }

    [self formattedFileSize:size];

    

    if (size < 5*1024*1024) {

        freeSize = 0;

    } else {

        freeSize = (size / pow(1024, 2));

    }

}


#pragma mark --

#pragma mark  UIApplicationWillEnterForegroundNotification

- (void)handleWillEnterforeground:(NSNotification*)notification

{

    [self getSystemApplicationSize];

    [self getSystemPhotosSize];

    [self getSystemMusicSize];

    [self getSystemVideoSize];

}


#pragma mark --

#pragma mark FirstLaunch And GuidePicture

/**

 *  判断首次启动

 */

- (BOOL)firstLaunch

{

    NSString *everLaunch = [NSString stringWithFormat:@"DiskMaster-%@-%@",@"everLaunched",[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"]];

    NSString *firstLaunch = [NSString stringWithFormat:@"DiskMaster-%@-%@",@"firstLaunch",[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"]];

    if (![[NSUserDefaults standardUserDefaults] boolForKey:everLaunch]) {

        [[NSUserDefaults standardUserDefaults] setBool:YES forKey:everLaunch];

        [[NSUserDefaults standardUserDefaults] setBool:YES forKey:firstLaunch];

        [[NSUserDefaults standardUserDefaults] synchronize];

    } else {

        [[NSUserDefaults standardUserDefaults] setBool:NO forKey:firstLaunch];

        [[NSUserDefaults standardUserDefaults] synchronize];

    }

    

    return [[NSUserDefaults standardUserDefaults] boolForKey:firstLaunch];

}


/**

 *  首次点击清理增加引导图

 */

- (void)AddGuidePicture

{

    UIView *guidePicView = [[UIView alloc] init];

    guidePicView.frame = CGRectMake(0, 0, GNDEVICE_SCREEN_WIDTH, GNDEVICE_SCREEN_HEIGHT);

    guidePicView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.98f];

    guidePicView.tag = 100010;

    guidePicView.alpha = 1.0;

    [self.tabBarController.view addSubview:guidePicView];

    

    CGFloat OffYImageView = GNDEVICE_IS_IPHONE5?200:150;

    UIImageView *imgView = [[UIImageView alloc] init];

    imgView.frame = CGRectMake((GNDEVICE_SCREEN_WIDTH-270)/2.0, OffYImageView, 270, 168);

    imgView.image = [UIImage imageNamed:@"qlqsts.png"];

    [guidePicView addSubview:imgView];

    

    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];

    button.frame = CGRectMake((GNDEVICE_SCREEN_WIDTH-78)/2.0, imgView.frame.origin.y+imgView.frame.size.height+40, 78, 28);

    button.frame = CGRectMake((GNDEVICE_SCREEN_WIDTH-224)/2.0, imgView.frame.origin.y+imgView.frame.size.height+40, 224, 45);

    [button setBackgroundImage:[UIImage imageNamed:@"zdl.png"] forState:UIControlStateNormal];

    [button addTarget:self action:@selector(guideButtonClicked:) forControlEvents:UIControlEventTouchUpInside];

    button.tag = 100020;

//    [button.layer setMasksToBounds:YES];

//    [button.layer setCornerRadius:3.0];

    [self.tabBarController.view addSubview:button];

}


/**

 *  "知道了"点击事件

 */

- (void)guideButtonClicked:(UIButton *)sender

{

    UIView *guidePicView = [self.tabBarController.view viewWithTag:100010];

    if (guidePicView) {

        [guidePicView removeFromSuperview];

        guidePicView = nil;

    }

    UIButton *button = (UIButton *)[self.tabBarController.view viewWithTag:100020];

    if (button) {

        [button removeFromSuperview];

        button = nil;

    }

    [self cleanButtonClicked:nil];

}


@end


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值