com.blankj.utilcode.util.ActivityUtils Java Examples

The following examples show how to use com.blankj.utilcode.util.ActivityUtils. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DeviceInfoItem.java    From AndroidUtilCode with Apache License 2.0 6 votes vote down vote up
public static List<DeviceInfoItem> getAppInfoItems() {
    List<DeviceInfoItem> appInfoItems = new ArrayList<>();
    appInfoItems.add(new DeviceInfoItem(R.string.du_device_info_name, Build.MANUFACTURER + " " + Build.MODEL));
    appInfoItems.add(new DeviceInfoItem(R.string.du_device_info_android_version, DeviceUtils.getSDKVersionName() + " (" + DeviceUtils.getSDKVersionCode() + ")"));
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        appInfoItems.add(new DeviceInfoItem(R.string.du_device_info_adb_enabled, String.valueOf(DeviceUtils.isAdbEnabled())));
    }
    appInfoItems.add(new DeviceInfoItem(R.string.du_device_info_support_abis, ArrayUtils.toString(DeviceUtils.getABIs())));
    appInfoItems.add(new DeviceInfoItem(R.string.du_device_info_screen_info, getScreenInfo()));
    appInfoItems.add(new DeviceInfoItem(R.string.du_device_info_open_development_settings_page, "", new OnClickListener() {
        @Override
        public void onClick(View v) {
            ActivityUtils.startActivity(new Intent(Settings.ACTION_APPLICATION_DEVELOPMENT_SETTINGS));
        }
    }));
    return appInfoItems;
}
 
Example #2
Source File: BaseDialogFragment.java    From AndroidUtilCode with Apache License 2.0 6 votes vote down vote up
public void show(final String tag) {
    ThreadUtils.runOnUiThread(new Runnable() {
        @SuppressLint("CommitTransaction")
        @Override
        public void run() {
            if (ActivityUtils.isActivityAlive(mActivity)) {
                FragmentManager fm = mActivity.getSupportFragmentManager();
                Fragment prev = fm.findFragmentByTag(tag);
                if (prev != null) {
                    fm.beginTransaction().remove(prev);
                }
                BaseDialogFragment.super.show(fm, tag);
            }
        }
    });
}
 
Example #3
Source File: ColorPickerInfoDokitView.java    From DoraemonKit with Apache License 2.0 6 votes vote down vote up
private void initView() {
    mColor = findViewById(R.id.color);
    mColorHex = findViewById(R.id.color_hex);
    mClose = findViewById(R.id.close);
    mClose.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            ColorPickManager.getInstance().setColorPickerDokitView(null);
            ColorPickConfig.setColorPickOpen(false);
            DokitViewManager.getInstance().detach(ColorPickerDokitView.class.getSimpleName());
            DokitViewManager.getInstance().detach(ColorPickerInfoDokitView.class.getSimpleName());
            //取色器kit是依赖在当前透明的Activity上的 所以关闭控件时需要finish
            if (ActivityUtils.getTopActivity() != null && ActivityUtils.getTopActivity() instanceof TranslucentActivity) {
                ActivityUtils.getTopActivity().finish();
            }

        }
    });
}
 
Example #4
Source File: LeakCanaryManager.java    From DoraemonKit with Apache License 2.0 6 votes vote down vote up
/**
 * 初始化跨进程框架
 * 接受leakcanary 进程泄漏传递过来的数据
 */
public static void initAidlBridge(Application application) {
    if (!DokitConstant.APP_HEALTH_RUNNING) {
        return;
    }
    IBridge.init(application, application.getPackageName(), IBridge.AbridgeType.AIDL);
    IBridge.registerAIDLCallBack(new AbridgeCallBack() {
        @Override
        public void receiveMessage(String message) {
            try {
                Log.i(TAG, "====aidl=====>" + message);
                if (DokitConstant.APP_HEALTH_RUNNING) {
                    AppHealthInfo.DataBean.LeakBean leakBean = new AppHealthInfo.DataBean.LeakBean();
                    leakBean.setPage(ActivityUtils.getTopActivity().getClass().getCanonicalName());
                    leakBean.setDetail(message);
                    AppHealthInfoUtil.getInstance().addLeakInfo(leakBean);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }

        }
    });

}
 
Example #5
Source File: LargePictureManager.java    From DoraemonKit with Apache License 2.0 6 votes vote down vote up
/**
 * 保存在内部里的图片信息
 *
 * @param url
 * @param memorySize
 * @param width
 * @param height
 */
public void saveImageInfo(String url, double memorySize, int width, int height, String framework) {
    if (ActivityUtils.getTopActivity() instanceof UniversalActivity) {
        return;
    }
    LargeImageInfo largeImageInfo;
    if (LARGE_IMAGE_INFO_MAP.containsKey(url)) {
        largeImageInfo = LARGE_IMAGE_INFO_MAP.get(url);
    } else {
        largeImageInfo = new LargeImageInfo();
        LARGE_IMAGE_INFO_MAP.put(url, largeImageInfo);
        largeImageInfo.setUrl(url);
    }
    largeImageInfo.setMemorySize(memorySize);
    largeImageInfo.setWidth(width);
    largeImageInfo.setHeight(height);
    largeImageInfo.setFramework(framework);
}
 
Example #6
Source File: ActivityCounter.java    From DoraemonKit with Apache License 2.0 6 votes vote down vote up
public void render() {
    mRenderStartTime = System.currentTimeMillis();
    final Activity activity = ActivityUtils.getTopActivity();
    if (activity != null && activity.getWindow() != null) {
        mCurrentActivity = activity.getClass().getSimpleName();
        activity.getWindow().getDecorView().post(new Runnable() {
            @Override
            public void run() {
                activity.getWindow().getDecorView().post(new Runnable() {
                    @Override
                    public void run() {
                        renderEnd();
                    }
                });
            }
        });
    } else {
        renderEnd();
    }
}
 
Example #7
Source File: ChangePasswordActivity.java    From DanDanPlayForAndroid with MIT License 6 votes vote down vote up
@Override
public void changeSuccess() {
    ToLoginDialog dialog = new ToLoginDialog(this, R.style.Dialog, 2, () -> {
        AppConfig.getInstance().setLogin(false);
        AppConfig.getInstance().saveUserName("");
        AppConfig.getInstance().saveUserScreenName("");
        AppConfig.getInstance().saveUserImage("");
        AppConfig.getInstance().saveToken("");
        EventBus.getDefault().post(UpdateFragmentEvent.updatePersonal());
        if (ActivityUtils.isActivityExistsInStack(PersonalInfoActivity.class))
            ActivityUtils.finishActivity(PersonalInfoActivity.class);
        launchActivity(LoginActivity.class);
        ChangePasswordActivity.this.finish();
    });
    dialog.show();
}
 
Example #8
Source File: AlignRulerInfoDokitView.java    From DoraemonKit with Apache License 2.0 5 votes vote down vote up
@Override
public void onViewCreated(FrameLayout view) {
    postDelayed(new Runnable() {
        @Override
        public void run() {
            mMarker = (AlignRulerMarkerDokitView) DokitViewManager.getInstance().getDokitView(ActivityUtils.getTopActivity(), AlignRulerMarkerDokitView.class.getSimpleName());
            if (mMarker != null) {
                mMarker.addPositionChangeListener(AlignRulerInfoDokitView.this);
            }
        }
    }, 100);
    initView();
}
 
Example #9
Source File: SplashPagerActivity.java    From YCAudioPlayer with Apache License 2.0 5 votes vote down vote up
@Override
public void initListener() {
    btnGo.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            ActivityUtils.startActivity(GuideActivity.class);
            finish();
            SPUtils.getInstance(Constant.SP_NAME).put(Constant.KEY_FIRST_SPLASH,false);
        }
    });
}
 
Example #10
Source File: AlignRulerLineDokitView.java    From DoraemonKit with Apache License 2.0 5 votes vote down vote up
@Override
public void onViewCreated(FrameLayout view) {
    postDelayed(new Runnable() {
        @Override
        public void run() {
            mMarker = (AlignRulerMarkerDokitView) DokitViewManager.getInstance().getDokitView(ActivityUtils.getTopActivity(), AlignRulerMarkerDokitView.class.getSimpleName());
            if (mMarker != null) {
                mMarker.addPositionChangeListener(AlignRulerLineDokitView.this);
            }
        }
    }, 100);
    setDokitViewNotResponseTouchEvent(getRootView());
    mAlignInfoView = findViewById(R.id.info_view);
}
 
Example #11
Source File: BlockMonitorManager.java    From DoraemonKit with Apache License 2.0 5 votes vote down vote up
/**
 * 动态添加卡顿信息到appHealth
 *
 * @param blockInfo
 */
private void addBlockInfoInAppHealth(@NonNull BlockInfo blockInfo) {
    try {
        String activityName = ActivityUtils.getTopActivity().getClass().getCanonicalName();
        AppHealthInfo.DataBean.BlockBean blockBean = new AppHealthInfo.DataBean.BlockBean();
        blockBean.setPage(activityName);
        blockBean.setBlockTime(blockInfo.timeCost);
        blockBean.setDetail(blockInfo.toString());
        AppHealthInfoUtil.getInstance().addBlockInfo(blockBean);
    } catch (Exception e) {
        e.printStackTrace();
    }

}
 
Example #12
Source File: ColorPickerDokitView.java    From DoraemonKit with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate(Context context) {
    ColorPickManager.getInstance().setColorPickerDokitView(this);
    mInfoDokitView = (ColorPickerInfoDokitView) DokitViewManager.getInstance().getDokitView(ActivityUtils.getTopActivity(), ColorPickerInfoDokitView.class.getSimpleName());
    mImageCapture = new ImageCapture();
    try {
        mImageCapture.init(context, getBundle(), this);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example #13
Source File: QPMGetActivityStackExecutor.java    From QPM with Apache License 2.0 5 votes vote down vote up
private List<String> getRunningActivityNames() {
    List<Activity> activityList = ActivityUtils.getActivityList();
    List<String> activitiNames = new ArrayList<>();
    for (Activity activity : activityList) {
        activitiNames.add(activity.getLocalClassName());
    }
    return activitiNames;
}
 
Example #14
Source File: QPMGetTopActivityExecutor.java    From QPM with Apache License 2.0 5 votes vote down vote up
@Override
public void exec() throws QPMException {
    Activity topActivity = ActivityUtils.getTopActivity();
    if (topActivity != null) {
        analysys.onCollectTopActivityInfo(topActivity.getLocalClassName());
    }
}
 
Example #15
Source File: ActivityActivity.java    From Android-UtilCode with Apache License 2.0 5 votes vote down vote up
@Override
public void initView(Bundle savedInstanceState, View view) {
    findViewById(R.id.btn_launch_image_activity).setOnClickListener(this);
    TextView tvAboutActivity = (TextView) findViewById(R.id.tv_about_activity);
    tvAboutActivity.setText("Is ImageActivity Exists: " + ActivityUtils.isActivityExists(Config.PKG, imageActivityClassName)
            + "\ngetLauncherActivity: " + ActivityUtils.getLauncherActivity(Config.PKG)
            + "\ngetTopActivity: " + ActivityUtils.getTopActivity()
    );
}
 
Example #16
Source File: ActivityActivity.java    From Android-UtilCode with Apache License 2.0 5 votes vote down vote up
@Override
public void onWidgetClick(View view) {
    switch (view.getId()) {
        case R.id.btn_launch_image_activity:
            ActivityUtils.startActivity(Config.PKG, imageActivityClassName);
            break;
        default:
            break;
    }
}
 
Example #17
Source File: BaseDialog.java    From AndroidUtilCode with Apache License 2.0 5 votes vote down vote up
public BaseDialog(@NonNull Context context, int themeResId) {
    super(context, themeResId);
    Activity activity = ActivityUtils.getActivityByContext(context);
    if (activity == null) {
        throw new IllegalArgumentException("context is not instance of Activity.");
    }
    mActivity = activity;
}
 
Example #18
Source File: BaseDialog.java    From AndroidUtilCode with Apache License 2.0 5 votes vote down vote up
@Override
public void show() {
    ThreadUtils.runOnUiThread(new Runnable() {
        @Override
        public void run() {
            if (ActivityUtils.isActivityAlive(getContext())) {
                BaseDialog.super.show();
            }
        }
    });
}
 
Example #19
Source File: BaseDialog.java    From AndroidUtilCode with Apache License 2.0 5 votes vote down vote up
@Override
public void dismiss() {
    ThreadUtils.runOnUiThread(new Runnable() {
        @Override
        public void run() {
            if (ActivityUtils.isActivityAlive(getContext())) {
                BaseDialog.super.dismiss();
            }
        }
    });
}
 
Example #20
Source File: BaseDialogFragment.java    From AndroidUtilCode with Apache License 2.0 5 votes vote down vote up
private FragmentActivity getFragmentActivity(Context context) {
    Activity activity = ActivityUtils.getActivityByContext(context);
    if (activity == null) return null;
    if (activity instanceof FragmentActivity) {
        return (FragmentActivity) activity;
    }
    LogUtils.w(context + "not instanceof FragmentActivity");
    return null;
}
 
Example #21
Source File: BaseDialogFragment.java    From AndroidUtilCode with Apache License 2.0 5 votes vote down vote up
@Override
public void dismiss() {
    ThreadUtils.runOnUiThread(new Runnable() {
        @Override
        public void run() {
            if (ActivityUtils.isActivityAlive(mActivity)) {
                BaseDialogFragment.super.dismissAllowingStateLoss();
            }
        }
    });
}
 
Example #22
Source File: BaseFloatView.java    From AndroidUtilCode with Apache License 2.0 5 votes vote down vote up
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    Activity topActivity = ActivityUtils.getTopActivity();
    if (topActivity != null) {
        if (topActivity.getWindow().getDecorView().dispatchKeyEvent(event)) {
            return true;
        }
    }
    return super.dispatchKeyEvent(event);
}
 
Example #23
Source File: PerformanceDokitViewManager.java    From DoraemonKit with Apache License 2.0 5 votes vote down vote up
/**
 * 性能检测设置页面关闭时调用
 *
 * @param listener
 */
public static void onPerformanceSettingFragmentDestroy(PerformanceFragmentCloseListener listener) {
    PerformanceDokitView performanceDokitView = (PerformanceDokitView) DokitViewManager.getInstance().getDokitView(ActivityUtils.getTopActivity(), PerformanceDokitView.class.getSimpleName());
    if (performanceDokitView != null) {
        performanceDokitView.removePerformanceFragmentCloseListener(listener);
    }
}
 
Example #24
Source File: SplashPagerActivity.java    From YCAudioPlayer with Apache License 2.0 5 votes vote down vote up
@Override
public void initView() {
    if(SPUtils.getInstance(Constant.SP_NAME).getBoolean(Constant.KEY_FIRST_SPLASH,true)){
        initGetImage();
        initBanner();
    } else {
        ActivityUtils.startActivity(GuideActivity.class);
        finish();
    }
}
 
Example #25
Source File: MainActivity.java    From YCAudioPlayer with Apache License 2.0 5 votes vote down vote up
@Override
public void onClick(View v) {
    switch (v.getId()) {
        case R.id.fl_search:
            ActivityUtils.startActivity(SearchMusicActivity.class);
            break;
        case R.id.fl_play_bar:
            showPlayingFragment();
            break;
        case R.id.iv_play_bar_list:
            showListDialog();
            break;
        case R.id.iv_play_bar_play:
            if(getPlayService().isDefault()){
                if(BaseAppHelper.get().getMusicList().size()>0){
                    int mPlayPosition;
                    if (getPlayService().getPlayingMusic() != null &&
                            getPlayService().getPlayingMusic().getType() == AudioBean.Type.LOCAL) {
                        mPlayPosition = getPlayService().getPlayingPosition();
                    } else {
                        mPlayPosition = 0;
                    }
                    getPlayService().play(BaseAppHelper.get().getMusicList().get(mPlayPosition));
                }else {
                    ToastUtils.showToast("请检查是否有音乐");
                }
            }else {
                getPlayService().playPause();
            }
            break;
        case R.id.iv_play_bar_next:
            getPlayService().next();
            break;
        default:
            break;
    }
}
 
Example #26
Source File: MeFragment.java    From YCAudioPlayer with Apache License 2.0 5 votes vote down vote up
@Override
public void onClick(View v) {
    switch (v.getId()) {
        case R.id.rl_me_collect:
            ShareDetailBean shareDetailBean = new ShareDetailBean();
            shareDetailBean.setShareType(ShareComment.ShareType.SHARE_GOODS);
            shareDetailBean.setContent("商品详情页分享");
            shareDetailBean.setTitle("分享");
            shareDetailBean.setImage("https://upload-images.jianshu.io/upload_images/4432347-fb25131b5629346a.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240");
            ShareDialog shareDialog = new ShareDialog(activity,shareDetailBean);
            shareDialog.show(getChildFragmentManager());
            break;
        case R.id.rl_me_question:

            break;
        case R.id.rl_me_setting:
            ActivityUtils.startActivity(MeSettingActivity.class);
            break;
        case R.id.ll_timer:
            timerDialog(activity);
            break;
        case R.id.rl_me_feed_back:

            break;
        case R.id.rl_me_phone:

            break;
        case R.id.btn_exit:
            exit();
            break;
        default:
            break;
    }
}
 
Example #27
Source File: ButtonViewHolder.java    From YCAudioPlayer with Apache License 2.0 5 votes vote down vote up
public void bindData(List<String> mButtonList, Context mContext) {
    if(mButtonList!=null && mButtonList.size()>0){
        tv_home_first.setText(mButtonList.get(0));
        tv_home_second.setText(mButtonList.get(1));
        tv_home_third.setText(mButtonList.get(2));
        tv_home_four.setText(mButtonList.get(3));
        tv_home_five.setText(mButtonList.get(4));


        View.OnClickListener listener = new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                switch (v.getId()){
                    case R.id.tv_home_first:
                        ActivityUtils.startActivity(AndroidActivity.class);
                        break;
                }
            }
        };

        tv_home_first.setOnClickListener(listener);
        tv_home_first.setOnClickListener(listener);
        tv_home_first.setOnClickListener(listener);
        tv_home_first.setOnClickListener(listener);
        tv_home_first.setOnClickListener(listener);
    }
}
 
Example #28
Source File: LargePictureManager.java    From DoraemonKit with Apache License 2.0 5 votes vote down vote up
/**
 * @param url
 * @param size
 */
public void process(String url, int size) {
    if (ActivityUtils.getTopActivity() instanceof UniversalActivity) {
        return;
    }
    if (PerformanceSpInfoConfig.isLargeImgOpen()) {
        //转化成kb
        double fileSize = (double) (size / 1024.0);
        saveImageInfo(url, fileSize);
    }

}
 
Example #29
Source File: LargePictureManager.java    From DoraemonKit with Apache License 2.0 5 votes vote down vote up
/**
 * 保存网络图片信息
 *
 * @param url
 * @param fileSize
 */
private void saveImageInfo(String url, double fileSize) {
    if (ActivityUtils.getTopActivity() instanceof UniversalActivity) {
        return;
    }
    LargeImageInfo largeImageInfo;
    if (LARGE_IMAGE_INFO_MAP.containsKey(url)) {
        largeImageInfo = LARGE_IMAGE_INFO_MAP.get(url);
    } else {
        largeImageInfo = new LargeImageInfo();
        LARGE_IMAGE_INFO_MAP.put(url, largeImageInfo);
        largeImageInfo.setUrl(url);
    }
    largeImageInfo.setFileSize(fileSize);
}
 
Example #30
Source File: ActivityCounter.java    From DoraemonKit with Apache License 2.0 5 votes vote down vote up
public void pause() {
    mStartTime = System.currentTimeMillis();
    mPauseCostTime = 0;
    mRenderCostTime = 0;
    mOtherCostTime = 0;
    mLaunchCostTime = 0;
    mLaunchStartTime = 0;
    mTotalCostTime = 0;
    mPreviousActivity = null;
    Activity activity = ActivityUtils.getTopActivity();
    if (activity != null) {
        mPreviousActivity = activity.getClass().getSimpleName();
    }
}