Java Code Examples for androidx.fragment.app.FragmentActivity#isDestroyed()

The following examples show how to use androidx.fragment.app.FragmentActivity#isDestroyed() . 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: MediaSetsDataSource.java    From YImagePicker with Apache License 2.0 5 votes vote down vote up
@Override
public void onLoadFinished(@NonNull Loader<Cursor> loader, Cursor cursor) {
    FragmentActivity context = mContext.get();
    if (context == null) {
        return;
    }
    ArrayList<ImageSet> imageSetList = new ArrayList<>();
    if (!context.isDestroyed() && cursor.moveToFirst() && !cursor.isClosed()) {
        do {
            ImageSet imageSet = new ImageSet();
            imageSet.id = getString(cursor, COLUMN_BUCKET_ID);
            imageSet.name = getString(cursor, COLUMN_BUCKET_DISPLAY_NAME);
            imageSet.coverPath = getString(cursor, COLUMN_URI);
            imageSet.count = getInt(cursor, COLUMN_COUNT);
            imageSetList.add(imageSet);
        } while (!context.isDestroyed() && cursor.moveToNext() && !cursor.isClosed());
    }

    if (mediaSetProvider != null) {
        mediaSetProvider.providerMediaSets(imageSetList);
    }

    if (mLoaderManager != null) {
        mLoaderManager.destroyLoader(LOADER_ID);
    }

}
 
Example 2
Source File: ConversationActivity.java    From Applozic-Android-SDK with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static void addFragment(FragmentActivity fragmentActivity, Fragment fragmentToAdd, String fragmentTag) {
    if (fragmentActivity.isFinishing() || (fragmentActivity instanceof ConversationActivity && ((ConversationActivity) fragmentActivity).isActivityDestroyed)) {
        return;
    }
    if (Utils.hasJellyBeanMR1()) {
        if (fragmentActivity.isDestroyed()) {
            return;
        }
    }
    FragmentManager supportFragmentManager = fragmentActivity.getSupportFragmentManager();

    // Fragment activeFragment = UIService.getActiveFragment(fragmentActivity);
    FragmentTransaction fragmentTransaction = supportFragmentManager
            .beginTransaction();
    fragmentTransaction.replace(R.id.layout_child_activity, fragmentToAdd,
            fragmentTag);

    if (supportFragmentManager.getBackStackEntryCount() > 1
            && !ConversationUIService.MESSGAE_INFO_FRAGMENT.equalsIgnoreCase(fragmentTag) && !ConversationUIService.USER_PROFILE_FRAMENT.equalsIgnoreCase(fragmentTag)) {
        supportFragmentManager.popBackStackImmediate();
    }

    fragmentTransaction.addToBackStack(fragmentTag);
    fragmentTransaction.commitAllowingStateLoss();
    supportFragmentManager.executePendingTransactions();
    //Log.i(TAG, "BackStackEntryCount: " + supportFragmentManager.getBackStackEntryCount());
}
 
Example 3
Source File: BaseFragment.java    From igniter with GNU General Public License v3.0 4 votes vote down vote up
protected void finishActivity() {
    FragmentActivity activity = getActivity();
    if (activity != null && !activity.isFinishing() && !activity.isDestroyed()) {
        activity.finish();
    }
}
 
Example 4
Source File: MediaItemsDataSource.java    From YImagePicker with Apache License 2.0 4 votes vote down vote up
@Override
public void run() {
    final FragmentActivity context = mContext.get();
    final ArrayList<ImageItem> imageItems = new ArrayList<>();
    ArrayList<ImageItem> allVideoItems = new ArrayList<>();
    if (!context.isDestroyed() && !cursor.isClosed() && cursor.moveToFirst()) {
        do {
            ImageItem item = new ImageItem();
            try {
                item.id = getLong(cursor, _ID);
                item.mimeType = getString(cursor, MIME_TYPE);
                item.displayName = getString(cursor, DISPLAY_NAME);
                //androidQ上废弃了DATA绝对路径,需要手动拼凑Uri,这里为了兼容大部分项目还没有适配androidQ的情况
                //默认path还是先取绝对路径,取不到或者异常才去取Uri路径
                /*if (MediaStoreConstants.isBeforeAndroidQ()) {
                    item.path = getConstants(cursor, MediaStore.Files.FileColumns.DATA);
                } else {
                    item.path = getUri(item.id, item.mimeType).toString();
                }*/
                try {
                    item.path = getString(cursor, DATA);
                } catch (Exception ignored) {

                }

                Uri urlPath = item.getUri();
                if (urlPath != null) {
                    item.setUriPath(urlPath.toString());
                }

                if (item.path == null || item.path.length() == 0) {
                    item.path = urlPath.toString();
                }

                item.width = getInt(cursor, WIDTH);
                item.height = getInt(cursor, HEIGHT);
                item.setVideo(MimeType.isVideo(item.mimeType));
                item.time = getLong(cursor, DATE_MODIFIED);
                item.timeFormat = PDateUtil.getStrTime(context, item.time);
            } catch (Exception e) {
                continue;
            }

            //没有查询到路径
            if (item.path == null || item.path.length() == 0) {
                continue;
            }

            //视频
            if (item.isVideo()) {
                item.duration = getLong(cursor, DURATION);
                if (item.duration == 0) {
                    continue;
                }
                item.durationFormat = PDateUtil.getVideoDuration(item.duration);

                //如果当前加载的是全部文件,需要拼凑一个全部视频的虚拟文件夹
                if (set.isAllMedia()) {
                    allVideoItems.add(item);
                }
            }
            //图片
            else {
                //如果媒体信息中不包含图片的宽高,则手动获取文件宽高
                if (item.width == 0 || item.height == 0) {
                    if (!item.isUriPath()) {
                        int[] size = PBitmapUtils.getImageWidthHeight(item.path);
                        item.width = size[0];
                        item.height = size[1];
                    }
                }
            }
            //添加到文件列表中
            imageItems.add(item);
            //回调预加载数据源
            if (preloadProvider != null && imageItems.size() == preloadSize) {
                notifyPreloadItem(context, imageItems);
            }
        } while (!context.isDestroyed() && !cursor.isClosed() && cursor.moveToNext());
    }
    //手动生成一个虚拟的全部视频文件夹
    ImageSet allVideoSet = null;
    if (allVideoItems.size() > 0) {
        allVideoSet = new ImageSet();
        allVideoSet.id = ImageSet.ID_ALL_VIDEO;
        allVideoSet.coverPath = allVideoItems.get(0).path;
        allVideoSet.cover = allVideoItems.get(0);
        allVideoSet.count = allVideoItems.size();
        allVideoSet.imageItems = allVideoItems;
        allVideoSet.name = context.getString(R.string.picker_str_folder_item_video);
    }
    //回调所有数据
    notifyMediaItem(context, imageItems, allVideoSet);
}