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:ti.modules.titanium.ui.widget.TiUIDialog.java

public void show(KrollDict options) {
    AlertDialog dialog = dialogWrapper.getDialog();
    if (dialog == null) {
        processProperties(proxy.getProperties());
        getBuilder().setOnCancelListener(new OnCancelListener() {
            @Override// w  ww.  j av a2  s  . com
            public void onCancel(DialogInterface dlg) {
                int cancelIndex = (proxy.hasProperty(TiC.PROPERTY_CANCEL))
                        ? TiConvert.toInt(proxy.getProperty(TiC.PROPERTY_CANCEL))
                        : -1;
                Log.d(TAG, "onCancelListener called. Sending index: " + cancelIndex, Log.DEBUG_MODE);
                handleEvent(cancelIndex);
                hide(null);
            }
        });
        dialog = getBuilder().create();

        // Initially apply accessibility properties here, the first time
        // the dialog actually becomes available. After this, propertyChanged
        // can also be used.
        ListView listView = dialog.getListView();
        if (listView != null) {
            listView.setContentDescription(composeContentDescription());
            int importance = ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_AUTO;
            if (proxy != null) {
                Object propertyValue = proxy.getProperty(TiC.PROPERTY_ACCESSIBILITY_HIDDEN);
                if (propertyValue != null && TiConvert.toBoolean(propertyValue)) {
                    importance = ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_NO;
                }
            }
            ViewCompat.setImportantForAccessibility(listView, importance);
        }

        dialogWrapper.setDialog(dialog);
        builder = null;
    }

    try {
        Activity dialogActivity = dialogWrapper.getActivity();
        if (dialogActivity != null && !dialogActivity.isFinishing()) {
            if (dialogActivity instanceof TiBaseActivity) {
                //add dialog to its activity so we can clean it up later to prevent memory leak.
                ((TiBaseActivity) dialogActivity).addDialog(dialogWrapper);
                dialog.show();
            }
        } else {
            dialog = null;
            Log.w(TAG, "Dialog activity is destroyed, unable to show dialog with message: "
                    + TiConvert.toString(proxy.getProperty(TiC.PROPERTY_MESSAGE)));
        }
    } catch (Throwable t) {
        Log.w(TAG, "Context must have gone away: " + t.getMessage(), t);
    }
}

From source file:com.fatelon.partyphotobooth.setup.fragments.ShareServicesSetupFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    final Context appContext = getActivity().getApplicationContext();

    /*/*  w w w  .  j a  v a  2 s.c  o m*/
     * Configure views with saved preferences and functionalize.
     */
    mFacebook.setOnClickListener(new MyLinkOnClickListener(FacebookEndpoint.class));
    mDropbox.setOnClickListener(new MyLinkOnClickListener(DropboxEndpoint.class));
    mGcp.setOnClickListener(new MyLinkOnClickListener(GoogleCloudPrintEndpoint.class));
    mMail.setOnClickListener(new MyMailOnClickListener());

    final PreferencesHelper preferencesHelper = new PreferencesHelper();
    boolean isChecked = preferencesHelper.getNoticeEnabled(appContext);
    mNoticeEnabled.setChecked(isChecked);
    mNoticeEnabled.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            Activity activity = getActivity();
            if (activity != null && !activity.isFinishing()) {
                preferencesHelper.storeNoticeEnabled(appContext, isChecked);
            }
        }
    });

    mNext.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            // Call to client.
            ICallbacks callbacks = getCallbacks();
            if (callbacks != null) {
                callbacks.onShareServicesSetupCompleted();
            }
        }
    });
}

From source file:com.yixia.zi.widget.crouton.Manager.java

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

    View croutonView = crouton.getView();
    if (null == croutonView.getParent()) {
        ViewGroup.LayoutParams params = croutonView.getLayoutParams();
        if (null == params) {
            params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
                    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;
            }
            activity.addContentView(croutonView, params);
        }
    }
    croutonView.startAnimation(crouton.getInAnimation());
    announceForAccessibilityCompat(crouton.getActivity(), crouton.getText());
    if (Style.DURATION_INFINITE != crouton.getStyle().durationInMilliseconds) {
        sendMessageDelayed(crouton, Messages.REMOVE_CROUTON,
                crouton.getStyle().durationInMilliseconds + crouton.getInAnimation().getDuration());
    }
}

From source file:it.scoppelletti.mobilepower.app.data.DatabaseConnectionManager.java

/**
 * Gestisce l’interruzione dell’aggiornamento del database. 
 *///from ww  w. j  a va  2s.c  om
public void onCancel(DialogInterface dialog) {
    Activity activity;

    if (myUpgradeTask != null) {
        myUpgradeTask.cancel(true);
        myUpgradeTask = null;
    }

    if (myDb != null) {
        myDb.close();
        myDb = null;
    }

    activity = myActivity.asActivity();
    if (!activity.isFinishing()) {
        activity.finish();
    }
}

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

public static void showFeatureRequiresVuze(final Activity activity, final String feature) {
    activity.runOnUiThread(new Runnable() {
        public void run() {
            if (activity.isFinishing()) {
                if (DEBUG) {
                    System.out.println("can't display -- finishing");
                }//from  www.j a va  2  s . com
                return;
            }
            String msg = activity.getResources().getString(R.string.vuze_required, feature);
            Builder builder = new AlertDialog.Builder(activity).setMessage(msg).setCancelable(true)
                    .setPositiveButton(android.R.string.ok, new OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {
                        }
                    });
            builder.show();
        }
    });

}

From source file:com.prashant.custom.widget.crouton.Manager.java

/**
 * Adds a {@link Crouton} to the {@link ViewParent} of it's {@link Activity}.
 *
 * @param crouton/*from ww w  .  j  a va2  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.LayoutParams(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;
            }
            activity.addContentView(croutonView, params);
        }
    }

    croutonView.requestLayout(); // This is needed so the animation can use the measured with/height
    croutonView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
        @SuppressWarnings("deprecation")
        @Override
        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.machine.custom.view.crouton.Manager.java

/**
 * Adds a {@link Crouton} to the {@link ViewParent} of it's {@link Activity}.
 *
 * @param crouton/*from   w ww  . j a va2 s . c  o 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.LayoutParams(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;
            }
            activity.addContentView(croutonView, params);
        }
    }

    croutonView.requestLayout(); // This is needed so the animation can use the measured with/height
    croutonView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @SuppressWarnings("deprecation")
        @Override
        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 showDialog(final Activity activity, final CharSequence title, final CharSequence msg) {
    activity.runOnUiThread(new Runnable() {
        public void run() {
            if (activity.isFinishing()) {
                if (DEBUG) {
                    System.out.println("can't display -- finishing");
                }/*  w  w w  .j  a v  a2  s  .co  m*/
                return;
            }
            Builder builder = new AlertDialog.Builder(activity).setMessage(msg).setCancelable(true)
                    .setNegativeButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {
                        }
                    });
            if (title != null) {
                builder.setTitle(title);
            }
            builder.show();
        }
    });

}

From source file:com.elephant.widget.crouton.Manager.java

/**
 * Adds a {@link Crouton} to the {@link ViewParent} of it's {@link Activity}
 * .//from   w  ww.ja  va2 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.LayoutParams(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;
            }
            activity.addContentView(croutonView, params);
        }
    }

    croutonView.requestLayout(); // This is needed so the animation can use
    // the measured with/height
    croutonView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @SuppressLint("NewApi")
        @Override
        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.partynetwork.iparty.app.widget.crouton.Manager.java

/**
 * Adds a {@link Crouton} to the {@link ViewParent} of it's {@link Activity}
 * .//from www  .j a  v  a  2 s.  com
 * 
 * @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;
            }

            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() {

                croutonView.getViewTreeObserver().removeGlobalOnLayoutListener(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());
                }
            }
        });
    }
}