MainActivity.java 6.63 KB
package com.lotus.town.clean;

import android.app.Activity;
import android.app.ActivityManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.OvershootInterpolator;
import android.view.animation.ScaleAnimation;
import android.view.animation.TranslateAnimation;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.lotus.town.R;

import com.lotus.town.widget.RoundRelativeLayout;
import com.sdk.Sdk;
import com.ss.android.common.applog.TeaAgent;
import com.umeng.analytics.MobclickAgent;

import java.util.List;

public class MainActivity extends Activity implements View.OnClickListener {

    RelativeLayout mCleanPhone;
    RoundRelativeLayout mVirusCheck;
    RoundRelativeLayout mPhoneFast;
    TextView mMainWord;
    TextView mSubWord;
    TextView mRedDesc;
    ImageView mRedView;
    RelativeLayout mMoveId;
    LinearLayout mHomeStatusTitle;
    LinearLayout mSecondStatusTitle;

    public static boolean isOppo() {
        String manufacturer = Build.MANUFACTURER;
        if ("OPPO".equalsIgnoreCase(manufacturer)) {
            return true;
        }
        return false;
    }
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
//        if(isOppo()){
//            MonitorService.invokeMp3(this, true);
//        }
        initListener();
        setAnim2();
        setAnim3(mRedView);
        mRedDesc.setVisibility(View.GONE);
        mRedView.setVisibility(View.GONE);

//        new Handler().postDelayed(new Runnable() {
//            @Override
//            public void run() {
//                    IconUtils.checkIconStatus(MainActivity.this);
//            }
//        },2000);
//        LaunchIconUtil.getInstance().addGhostHomeShortcut(this, R.drawable.booster,"加速,",MainActivity.class);
    }

    private void setAnim3(View view){
        TranslateAnimation animation = new TranslateAnimation(0, 0, 0, -5);
        animation.setInterpolator(new OvershootInterpolator());
        animation.setDuration(1000);
        animation.setFillAfter(true);// True:图片停在动画结束位置
        animation.setDuration(1000);
        animation.setRepeatCount(Animation.INFINITE);
        animation.setRepeatMode(Animation.INFINITE);
        view.startAnimation(animation);
    }

    private void setAnim2() {
        AnimationSet as = new AnimationSet(true);
        //缩放动画,以中心从1.4倍放大到1.8倍
        ScaleAnimation scaleAnimation = new ScaleAnimation(1f, 1.3f, 1f, 1.3f,
                       ScaleAnimation.RELATIVE_TO_SELF, 0.5f,
                        ScaleAnimation.RELATIVE_TO_SELF, 0.5f);
        //渐变动画
        AlphaAnimation alphaAnimation = new AlphaAnimation(1f, 0f);
        scaleAnimation.setDuration(1200);
        scaleAnimation.setRepeatCount(Animation.INFINITE);
        alphaAnimation.setRepeatCount(Animation.INFINITE);
        as.setDuration(1200);
        as.addAnimation(scaleAnimation);
        as.addAnimation(alphaAnimation);
        mMoveId.startAnimation(as);
    }

    private void initView(){
        mCleanPhone = findViewById(R.id.clean_phone);
        mVirusCheck = findViewById(R.id.virus_check);
        mPhoneFast = findViewById(R.id.phone_faster);
//        mHomeStatusTitle = findViewById(R.id.home_status_title);
        mSecondStatusTitle = findViewById(R.id.second_status_title);

        mMainWord = findViewById(R.id.main_word);
        mSubWord = findViewById(R.id.sub_word);
        mMoveId = findViewById(R.id.move_id);
        mRedDesc = findViewById(R.id.red_desc);
        mRedView = findViewById(R.id.red_pack);
    }

    private void initListener(){
        mCleanPhone.setOnClickListener(this);
        mVirusCheck.setOnClickListener(this);
        mPhoneFast.setOnClickListener(this);
        mRedView.setOnClickListener(this);
    }

    @Override
    protected void onPause() {
        super.onPause();
        TeaAgent.onPause(this);
        MobclickAgent.onPause(this);
        Sdk.isInMain = false;
    }
    private long time;
    private Handler handler = new Handler(){
        @Override
        public void handleMessage(Message msg) {
            if(msg.what == 0){
                mRedDesc.setText(getTimeString(time)+"后可领取红包");
                time = time - 1000;
                handler.sendEmptyMessageDelayed(0,950);
            }
        }
    };

    private String getTimeString(long time){
        String result = "";
        if(time <=60000){
            result = time/1000 +"秒";
        } else if(time >60000 && time <60*60*1000){
            //70000        10000
            result = time/60/1000 +"分钟"+time%(60*1000)/(1000) +"秒";
        } else if(time >= 60*60*1000){

            //60 * 60 *1000  3600000
            result = time/(60*60*1000) +"小时"+time%(60*60*1000)/60/1000 +"分";
        }
        return result;
    }
    @Override
    protected void onResume() {
        super.onResume();
        TeaAgent.onResume(this);
        MobclickAgent.onResume(this);
    }

    public static boolean isApplicationBroughtToBackground(final Context context) {
        ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
        List<ActivityManager.RunningTaskInfo> tasks = am.getRunningTasks(1);
        if (!tasks.isEmpty()) {
            ComponentName topActivity = tasks.get(0).topActivity;
            if (!topActivity.getPackageName().equals(context.getPackageName())) {
                return true;
            }
        }
        return false;
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        Sdk.isInMain = false;

    }

    @Override
    public void onClick(View v) {
        gotoWorkPage(v.getId());
    }

    private void gotoWorkPage(int id){
        if(id == R.id.clean_phone){
            Intent i = new Intent();
            i.setClass(this,CleanActivity.class);
            this.startActivity(i);
        } else if(id == R.id.virus_check){
            Intent i = new Intent();
            i.setClass(this,VirusActivity.class);
            this.startActivity(i);
        } else if(id == R.id.phone_faster){
            Intent i = new Intent();
            i.setClass(this,BoosterActivity.class);
            this.startActivity(i);
        }
    }

}