Example usage for android.app Activity isFinishing

List of usage examples for android.app Activity isFinishing

Introduction

In this page you can find the example usage for android.app Activity isFinishing.

Prototype

public boolean isFinishing() 

Source Link

Document

Check to see whether this activity is in the process of finishing, either because you called #finish on it or someone else has requested that it finished.

Usage

From source file:com.hannesdorfmann.mosby3.FragmentMviDelegateImpl.java

private boolean retainPresenterInstance(boolean keepPresenterOnBackstack, Activity activity,
        Fragment fragment) {/*from   ww w .j  a v a  2  s  .c  om*/

    if (activity.isChangingConfigurations()) {
        if (keepPresenterDuringScreenOrientationChange) {
            return true;
        }
        return false;
    }

    if (activity.isFinishing()) {
        return false;
    }

    if (keepPresenterOnBackstack && BackstackAccessor.isFragmentOnBackStack(fragment)) {
        return true;
    }

    return !fragment.isRemoving();
}

From source file:com.arta.lib.widget.crouton.Manager.java

/**
 * Adds a {@link Crouton} to the {@link ViewParent} of it's {@link Activity}.
 *
 * @param crouton/*from w w w  . j a v a  2 s  .  co  m*/
 *     The {@link Crouton} that should be added.
 */
private void addCroutonToView(final Crouton crouton) {
    // don't add if it is already showing
    if (crouton.isShowing()) {
        return;
    }

    final View croutonView = crouton.getView();
    if (null == croutonView.getParent()) {
        ViewGroup.LayoutParams params = croutonView.getLayoutParams();
        if (null == params) {
            params = new ViewGroup.MarginLayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                    ViewGroup.LayoutParams.WRAP_CONTENT);
        }
        // display Crouton in ViewGroup is it has been supplied
        if (null != crouton.getViewGroup()) {
            // TODO implement add to last position feature (need to align with how this will be requested for activity)
            if (crouton.getViewGroup() instanceof FrameLayout) {
                crouton.getViewGroup().addView(croutonView, params);
            } else {
                crouton.getViewGroup().addView(croutonView, 0, params);
            }
        } else {
            Activity activity = crouton.getActivity();
            if (null == activity || activity.isFinishing()) {
                return;
            }
            handleTranslucentActionBar((ViewGroup.MarginLayoutParams) params, activity);

            activity.addContentView(croutonView, params);
        }
    }

    croutonView.requestLayout(); // This is needed so the animation can use the measured with/height
    ViewTreeObserver observer = croutonView.getViewTreeObserver();
    if (null != observer) {
        observer.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            @Override
            @TargetApi(16)
            public void onGlobalLayout() {
                if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
                    croutonView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
                } else {
                    croutonView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
                }

                croutonView.startAnimation(crouton.getInAnimation());
                announceForAccessibilityCompat(crouton.getActivity(), crouton.getText());
                if (Configuration.DURATION_INFINITE != crouton.getConfiguration().durationInMilliseconds) {
                    sendMessageDelayed(crouton, Messages.REMOVE_CROUTON,
                            crouton.getConfiguration().durationInMilliseconds
                                    + crouton.getInAnimation().getDuration());
                }
            }
        });
    }
}

From source file:cn.bingoogolapple.scaffolding.util.AppManager.java

/**
 * Activity/*from w  w w .j a  va 2  s . c o  m*/
 *
 * @param activity
 */
public void popOneActivity(Activity activity) {
    if (activity == null || mActivityStack.isEmpty()) {
        return;
    }
    if (!activity.isFinishing()) {
        activity.finish();
    }
    mActivityStack.remove(activity);
}

From source file:com.example.androidannotationtesttwo.widget.crouton.Manager.java

/**
 * Adds a {@link Crouton} to the {@link ViewParent} of it's {@link Activity}
 * .//from   www.  j av  a  2 s.c o m
 * 
 * @param crouton The {@link Crouton} that should be added.
 */
private void addCroutonToView(final Crouton crouton) {
    // don't add if it is already showing
    if (crouton.isShowing()) {
        return;
    }

    final View croutonView = crouton.getView();
    if (null == croutonView.getParent()) {
        ViewGroup.LayoutParams params = croutonView.getLayoutParams();
        if (null == params) {
            params = new ViewGroup.MarginLayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                    ViewGroup.LayoutParams.WRAP_CONTENT);
        }
        // display Crouton in ViewGroup is it has been supplied
        if (null != crouton.getViewGroup()) {
            // TODO implement add to last position feature (need to align
            // with how this will be requested for activity)
            if (crouton.getViewGroup() instanceof FrameLayout) {
                crouton.getViewGroup().addView(croutonView, params);
            } else {
                crouton.getViewGroup().addView(croutonView, 0, params);
            }
        } else {
            Activity activity = crouton.getActivity();
            if (null == activity || activity.isFinishing()) {
                return;
            }
            handleTranslucentActionBar((ViewGroup.MarginLayoutParams) params, activity);

            activity.addContentView(croutonView, params);
        }
    }

    croutonView.requestLayout(); // This is needed so the animation can use
                                 // the measured with/height
    ViewTreeObserver observer = croutonView.getViewTreeObserver();
    if (null != observer) {
        observer.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            @Override
            @TargetApi(16)
            public void onGlobalLayout() {
                if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
                    croutonView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
                } else {
                    croutonView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
                }

                croutonView.startAnimation(crouton.getInAnimation());
                announceForAccessibilityCompat(crouton.getActivity(), crouton.getText());
                if (Configuration.DURATION_INFINITE != crouton.getConfiguration().durationInMilliseconds) {
                    sendMessageDelayed(crouton, Messages.REMOVE_CROUTON,
                            crouton.getConfiguration().durationInMilliseconds
                                    + crouton.getInAnimation().getDuration());
                }
            }
        });
    }
}

From source file:de.manumaticx.crouton.Manager.java

/**
 * Adds a {@link Crouton} to the {@link ViewParent} of it's {@link Activity}.
 *
 * @param crouton// w w  w  .  j  av a 2 s .c om
 *     The {@link Crouton} that should be added.
 */
private void addCroutonToView(final Crouton crouton) {
    // don't add if it is already showing
    if (crouton.isShowing()) {
        return;
    }

    final View croutonView = crouton.getView();
    if (null == croutonView.getParent()) {
        ViewGroup.LayoutParams params = croutonView.getLayoutParams();
        if (null == params) {
            params = new ViewGroup.MarginLayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                    ViewGroup.LayoutParams.WRAP_CONTENT);
        }
        // display Crouton in ViewGroup is it has been supplied
        if (null != crouton.getViewGroup()) {
            // TODO implement add to last position feature (need to align with how this will be requested for activity)
            if (crouton.getViewGroup() instanceof FrameLayout) {
                crouton.getViewGroup().addView(croutonView, params);
            } else {
                crouton.getViewGroup().addView(croutonView, 0, params);
            }
        } else {
            Activity activity = crouton.getActivity();
            if (null == activity || activity.isFinishing()) {
                return;
            }
            handleTranslucentActionBar((ViewGroup.MarginLayoutParams) params, activity);

            if (Looper.myLooper() == Looper.getMainLooper()) {
                activity.addContentView(croutonView, params);
            } else {
                final Activity mActivity = activity;
                final ViewGroup.LayoutParams mParams = params;
                activity.runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        mActivity.addContentView(croutonView, mParams);
                    }
                });
            }
        }
    }

    croutonView.requestLayout(); // This is needed so the animation can use the measured with/height
    ViewTreeObserver observer = croutonView.getViewTreeObserver();
    if (null != observer) {
        observer.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            @Override
            @TargetApi(16)
            public void onGlobalLayout() {
                if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
                    croutonView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
                } else {
                    croutonView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
                }

                croutonView.startAnimation(crouton.getInAnimation());
                announceForAccessibilityCompat(crouton.getActivity(), crouton.getText());
                if (Configuration.DURATION_INFINITE != crouton.getConfiguration().durationInMilliseconds) {
                    sendMessageDelayed(crouton, Messages.REMOVE_CROUTON,
                            crouton.getConfiguration().durationInMilliseconds
                                    + crouton.getInAnimation().getDuration());
                }
            }
        });
    }
}

From source file:com.vuze.android.remote.AndroidUtils.java

public static void invalidateOptionsMenuHC(final Activity activity,
        final android.support.v7.view.ActionMode mActionMode) {
    if (activity == null) {
        return;//from w  ww  . ja v  a  2s .c om
    }
    activity.runOnUiThread(new Runnable() {
        @Override
        public void run() {
            if (activity.isFinishing()) {
                return;
            }
            if (mActionMode != null) {
                mActionMode.invalidate();
                return;
            }
            if (activity instanceof FragmentActivity) {
                FragmentActivity aba = (FragmentActivity) activity;
                aba.supportInvalidateOptionsMenu();
            } else {
                ActivityCompat.invalidateOptionsMenu(activity);
            }
        }
    });
}

From source file:dentex.youtube.downloader.utils.Utils.java

public static void notifyFfmpegNotInstalled(final Activity act) {
    Utils.logger("w", "FFmpeg not installed/enabled", DEBUG_TAG);
    BugSenseHandler.leaveBreadcrumb("notifyFfmpegNotInstalled");
    AlertDialog.Builder adb = new AlertDialog.Builder(act);
    adb.setTitle(act.getString(R.string.ffmpeg_not_enabled_title));
    adb.setMessage(act.getString(R.string.ffmpeg_not_enabled_msg));

    adb.setPositiveButton("OK", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            act.startActivity(new Intent(act, SettingsActivity.class));
        }//w w w.ja v  a 2s . co  m
    });

    adb.setNegativeButton(act.getString(R.string.dialogs_negative), new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            // cancel
        }
    });

    if (!act.isFinishing()) {
        adb.show();
    }
}

From source file:wisc.drivesense.vediorecorder.CameraFragment.java

/**
 * Tries to open a {@link CameraDevice}. The result is listened by `mStateCallback`.
 *///  w  w  w .  j  av a2 s . co m
private void openCamera(int width, int height) {

    final Activity activity = getActivity();
    if (null == activity || activity.isFinishing()) {
        return;
    }

    int permissionCheck = ContextCompat.checkSelfPermission(getActivity(), Manifest.permission.CAMERA);
    if (permissionCheck != PackageManager.PERMISSION_GRANTED) {
        return;
    }

    CameraManager manager = (CameraManager) activity.getSystemService(Context.CAMERA_SERVICE);
    try {
        Log.d(TAG, "tryAcquire");
        if (!mCameraOpenCloseLock.tryAcquire(2500, TimeUnit.MILLISECONDS)) {
            throw new RuntimeException("Time out waiting to lock camera opening.");
        }

        Log.d(TAG, "check how many cameras");
        for (int i = 0; i < manager.getCameraIdList().length; ++i) {
            Log.d(TAG, manager.getCameraIdList()[i]);
        }

        String cameraId = manager.getCameraIdList()[0];

        // Choose the sizes for camera preview and video recording
        CameraCharacteristics characteristics = manager.getCameraCharacteristics(cameraId);
        StreamConfigurationMap map = characteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
        mSensorOrientation = characteristics.get(CameraCharacteristics.SENSOR_ORIENTATION);
        mVideoSize = chooseVideoSize(map.getOutputSizes(MediaRecorder.class));
        mPreviewSize = chooseOptimalSize(map.getOutputSizes(SurfaceTexture.class), width, height, mVideoSize);

        int orientation = getResources().getConfiguration().orientation;
        if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
            mTextureView.setAspectRatio(mPreviewSize.getWidth(), mPreviewSize.getHeight());
        } else {
            mTextureView.setAspectRatio(mPreviewSize.getHeight(), mPreviewSize.getWidth());
        }
        configureTransform(width, height);
        mMediaRecorder = new MediaRecorder();

        manager.openCamera(cameraId, mStateCallback, null);
    } catch (CameraAccessException e) {
        Toast.makeText(activity, "Cannot access the camera.", Toast.LENGTH_SHORT).show();
        activity.finish();
    } catch (NullPointerException e) {
        // Currently an NPE is thrown when the Camera2API is used but not supported on the
        // device this code runs.
        //ErrorDialog.newInstance(getString(R.string.camera_error)).show(getChildFragmentManager(), FRAGMENT_DIALOG);
        Log.e(TAG, "This camera does not suppport Camera2API");
    } catch (InterruptedException e) {
        throw new RuntimeException("Interrupted while trying to lock camera opening.");
    }
}

From source file:com.docd.purefm.ui.dialogs.FilePropertiesDialog.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    final Activity activity = getActivity();
    if (activity == null || activity.isFinishing()) {
        return null;
    }/*from w ww. j a  va2 s .com*/
    final AlertDialog.Builder builder = new AlertDialog.Builder(activity);
    mAdapter = new PropertiesAdapter(activity, file);
    builder.setIcon(ThemeUtils.getDrawableNonNull(activity, R.attr.ic_menu_info));
    builder.setTitle(file.getName());
    builder.setNeutralButton(R.string.close, null);
    builder.setPositiveButton(R.string.apply, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            final FilePermissionsPagerItem fragment = (FilePermissionsPagerItem) mAdapter.getItem(1);
            fragment.applyPermissions(getActivity());
        }
    });

    //noinspection InflateParams
    final View content = activity.getLayoutInflater().inflate(R.layout.dialog_properties_container, null);
    if (content == null) {
        throw new RuntimeException("Inflated view is null");
    }
    this.initView(content);
    builder.setView(content);
    final AlertDialog dialog = builder.create();
    dialog.setOnShowListener(new DialogInterface.OnShowListener() {
        @Override
        public void onShow(final DialogInterface dialog) {
            final Button button = ((AlertDialog) dialog).getButton(DialogInterface.BUTTON_POSITIVE);
            if (button == null) {
                throw new RuntimeException("Can't get positive button");
            }
            button.setVisibility(View.GONE);
        }
    });
    return dialog;
}

From source file:com.github.ppamorim.dragger.DraggerView.java

private void finish() {
    Context context = getContext();
    if (context instanceof Activity) {
        Activity activity = (Activity) context;
        if (!activity.isFinishing()) {
            activity.overridePendingTransition(0, android.R.anim.fade_out);
            activity.finish();/*from w w  w .  j  ava2s. c  om*/
        }
    }
}