Java Code Examples for android.app.Activity#isFinishing()

The following examples show how to use android.app.Activity#isFinishing() . 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: ChatsFragment.java    From tindroid with Apache License 2.0 6 votes vote down vote up
@Override
public void toggleProgressIndicator(final boolean on) {
    Activity activity = getActivity();
    if (activity == null || activity.isFinishing() || activity.isDestroyed()) {
        return;
    }

    activity.runOnUiThread(new Runnable() {
        @Override
        public void run() {
            if (on) {
                mProgressView.show();
            } else {
                mProgressView.hide();
            }
        }
    });
}
 
Example 2
Source File: DialogUtil.java    From letv with Apache License 2.0 6 votes vote down vote up
public static void showDialog(Activity context, CharSequence title, CharSequence content, CharSequence leftText, CharSequence rightText, OnClickListener leftListener, OnClickListener rightListener) {
    if (mCommonDialog != null && mCommonDialog.isShowing()) {
        mCommonDialog.dismiss();
    }
    mCommonDialog = new LetvCommonDialog(context);
    mCommonDialog.setTitle(title);
    mCommonDialog.setContent(content.toString());
    mCommonDialog.setButtonText(leftText, rightText);
    if (leftListener != null) {
        mCommonDialog.setLeftOnClickListener(leftListener);
    }
    if (rightListener != null) {
        mCommonDialog.setRightOnClickListener(rightListener);
    }
    if (!context.isFinishing() && !context.isRestricted()) {
        try {
            mCommonDialog.show();
        } catch (Exception e) {
        }
    }
}
 
Example 3
Source File: DefaultChromeClient.java    From AgentWebX5 with Apache License 2.0 6 votes vote down vote up
private void createAndOpenCommonFileLoader(ValueCallback valueCallback) {
    Activity mActivity = this.mActivityWeakReference.get();
    if (mActivity == null||mActivity.isFinishing()){
        valueCallback.onReceiveValue(new Object());
        return;
    }
    this.mIFileUploadChooser = new FileUpLoadChooserImpl.Builder()
            .setWebView(this.mWebView)
            .setActivity(mActivity)
            .setUriValueCallback(valueCallback)
            .setFileUploadMsgConfig(mChromeClientMsgCfg.getFileUploadMsgConfig())
            .setPermissionInterceptor(this.mPermissionInterceptor)
            .build();
    this.mIFileUploadChooser.openFileChooser();

}
 
Example 4
Source File: DefaultChromeClient.java    From AgentWeb with Apache License 2.0 6 votes vote down vote up
private void createAndOpenCommonFileChooser(ValueCallback valueCallback, String mimeType) {
	Activity mActivity = this.mActivityWeakReference.get();
	if (mActivity == null || mActivity.isFinishing()) {
		valueCallback.onReceiveValue(new Object());
		return;
	}
	AgentWebUtils.showFileChooserCompat(mActivity,
			mWebView,
			null,
			null,
			this.mPermissionInterceptor,
			valueCallback,
			mimeType,
			null
	);
}
 
Example 5
Source File: ActivityHolder.java    From PermissionAgent with Apache License 2.0 6 votes vote down vote up
public Activity getCurrentActivity() {
    if (mActivityList.isEmpty()) {
        throw new IllegalStateException("请在Application的onCreate中初始化");
    }
    AgentLog.d(TAG, "current activity stack " + mActivityList);
    int size = mActivityList.size();
    Activity activity;
    do {
        activity = mActivityList.get(--size);
        if (!activity.isFinishing()) {
            return activity;
        }
    } while (size > 0);

    return mActivityList.get(0);
}
 
Example 6
Source File: DialogUtil.java    From letv with Apache License 2.0 6 votes vote down vote up
public static void showDialog(Activity context, CharSequence title, CharSequence content, CharSequence leftText, CharSequence rightText, OnClickListener leftListener, OnClickListener rightListener, int layoutId) {
    if (mCommonDialog != null && mCommonDialog.isShowing()) {
        mCommonDialog.dismiss();
    }
    mCommonDialog = new CommonDialog(context, layoutId);
    mCommonDialog.setTitle(title);
    mCommonDialog.setContent(content.toString());
    mCommonDialog.setButtonText(leftText, rightText);
    if (leftListener != null) {
        mCommonDialog.setLeftOnClickListener(leftListener);
    }
    if (rightListener != null) {
        mCommonDialog.setRightOnClickListener(rightListener);
    }
    if (!context.isFinishing() && !context.isRestricted()) {
        mCommonDialog.show();
    }
}
 
Example 7
Source File: SwipeBackListenerActivityAdapter.java    From SwipeBackLayout with Apache License 2.0 5 votes vote down vote up
@Override
public void onContentViewSwipedBack() {
    Activity activity = mActivity.get();
    if (null != activity && !activity.isFinishing()) {
        activity.finish();
        activity.overridePendingTransition(0, 0);
    }
}
 
Example 8
Source File: ShareUtil.java    From ShareSDK with MIT License 5 votes vote down vote up
/**
 * 调起ShareDialogActivity
 * @param activity Activity
 * @param data {@link ShareEntity}
 * @param channel {@link ShareConstant#SHARE_CHANNEL_ALL}
 * @param requestCode requestCode
 */
public static void showShareDialog(Activity activity, int channel, ShareEntity data, int requestCode) {
    if (null == activity || activity.isFinishing()) {
        return;
    }
    Intent intent = new Intent(activity, ShareDialogActivity.class);
    intent.putExtra(ShareConstant.EXTRA_SHARE_DATA, data);
    intent.putExtra(ShareConstant.EXTRA_SHARE_CHANNEL, channel);
    activity.startActivityForResult(intent, requestCode);
}
 
Example 9
Source File: CocoTask.java    From COCOQuery with Apache License 2.0 5 votes vote down vote up
void async(final Activity act) {
    this.act = new WeakReference<Activity>(act);
    if (act.isFinishing()) {
        return;
    }

    runtask(act);
}
 
Example 10
Source File: DialogUtil.java    From letv with Apache License 2.0 5 votes vote down vote up
public static void call(Activity activity, int messageId, int yes, int no, OnClickListener yesListener, OnClickListener noListener, View view) {
    if (activity != null) {
        Dialog dialog = new Builder(activity).setTitle(R.string.dialog_default_title).setIcon(R.drawable.dialog_icon).setMessage(messageId).setView(view).setPositiveButton(yes, yesListener).setNegativeButton(no, noListener).create();
        if (!activity.isFinishing() && !activity.isRestricted()) {
            dialog.show();
        }
    }
}
 
Example 11
Source File: Keyboards.java    From yandex-money-sdk-android with MIT License 5 votes vote down vote up
/**
 * Shows soft keyboards for a view.
 *
 * @param activity activity
 * @param view view
 */
public static void showKeyboard(@Nullable Activity activity, @NonNull View view) {
    if (activity == null || activity.isFinishing()) {
        return;
    }
    InputMethodManager manager = getInputMethodManager(activity);
    if (manager != null) {
        manager.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT);
    }
}
 
Example 12
Source File: ActivityTestRule.java    From android-test with Apache License 2.0 5 votes vote down vote up
@Override
public void onActivityLifecycleChanged(Activity activity, Stage stage) {
  if (activityClass.isInstance(activity)) {
    if (Stage.RESUMED == stage) {
      ActivityTestRule.this.activity = makeWeakReference(activityClass.cast(activity));
    } else if (Stage.PAUSED == stage) {
      // If there is an activity result we save it
      if (activity.isFinishing() && activityResult != null) {
        setActivityResultForActivity(activityClass.cast(activity));
      }
    }
  }
}
 
Example 13
Source File: BaoKanApp.java    From BaoKanAndroid with MIT License 5 votes vote down vote up
/**
 * 销毁所有的Activity
 */
public void removeAllActivity() {
    for (Activity activity : mActivityList) {
        if (!activity.isFinishing()) {
            activity.finish();
        }
    }
}
 
Example 14
Source File: CheckVersionHelper.java    From FastLib with Apache License 2.0 5 votes vote down vote up
private void checkVersion(UpdateEntity entity) {
    if (entity == null) {
        if (mIsLoading) {
            ToastUtil.show("版本信息有误");
        }
        return;
    }
    LoggerManager.i("check_saturation:"+entity.saturation+";sp:"+AppData.getSaturation());
    if (entity.saturation != AppData.getSaturation()) {
        AppData.setSaturation(entity.saturation);
        Stack<Activity> activities = FastStackUtil.getInstance().getStack();
        for (Activity activity : activities) {
            if (activity != null && !activity.isFinishing()) {
                App.setSaturation(activity);
            }
        }
    }
    if (!entity.isSuccess()) {
        if (mIsLoading) {
            ToastUtil.show(entity.getMessage());
        }
        return;
    }
    if (TextUtils.isEmpty(entity.url)) {
        if (mIsLoading) {
            ToastUtil.show("不是有效的下载链接:" + entity.url);
        }
        LoggerManager.e("检测新版本:不是有效的apk下载链接");
        return;
    }
    showAlert(entity);
}
 
Example 15
Source File: ContextKit.java    From RichText with MIT License 5 votes vote down vote up
/**
 * 判断Activity是否已经结束
 *
 * @param context context
 * @return true:已结束
 */
public static boolean activityIsAlive(Context context) {
    Activity activity = getActivity(context);
    if (activity == null) {
        return false;
    }
    if (activity.isFinishing()) {
        return false;
    } else {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 && activity.isDestroyed()) {
            return false;
        }
    }
    return true;
}
 
Example 16
Source File: Keyboards.java    From yandex-money-sdk-android with MIT License 5 votes vote down vote up
/**
 * Hides soft keyboard.
 *
 * @param activity activity
 */
public static void hideKeyboard(@Nullable Activity activity) {
    if (activity == null || activity.isFinishing()) {
        return;
    }
    View view = activity.getWindow().getCurrentFocus();
    if (view != null) {
        InputMethodManager manager = getInputMethodManager(activity);
        if (manager != null) {
            manager.hideSoftInputFromWindow(view.getWindowToken(), 0);
        }
    }
}
 
Example 17
Source File: BasicManagedProfileFragment.java    From enterprise-samples with Apache License 2.0 5 votes vote down vote up
/**
 * Wipes out all the data related to this managed profile.
 */
private void removeProfile() {
    Activity activity = getActivity();
    if (null == activity || activity.isFinishing()) {
        return;
    }
    DevicePolicyManager manager =
            (DevicePolicyManager) activity.getSystemService(Context.DEVICE_POLICY_SERVICE);
    manager.wipeData(0);
    // The screen turns off here
}
 
Example 18
Source File: AndroidLifecycleUtils.java    From PhotoPicker with Apache License 2.0 5 votes vote down vote up
public static boolean canLoadImage(Activity activity) {
    if (activity == null) {
        return true;
    }

    boolean destroyed = Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 &&
            activity.isDestroyed();

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

    return true;
}
 
Example 19
Source File: DialogHelpPopupWindowX.java    From PhoneProfilesPlus with Apache License 2.0 4 votes vote down vote up
static void showPopup(ImageView helpIcon, int titleStringId, Activity activity, final Dialog dialog, String helpString) {
    if (!activity.isFinishing()) {
        DialogHelpPopupWindowX popup = new DialogHelpPopupWindowX(titleStringId, activity, dialog, helpString);

        View contentView = popup.getContentView();
        contentView.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
        int popupWidth = contentView.getMeasuredWidth();
        int popupHeight = contentView.getMeasuredHeight();
        /*if (PPApplication.logEnabled()) {
            PPApplication.logE("DialogHelpPopupWindowX.showPopup", "popupWidth=" + popupWidth);
            PPApplication.logE("DialogHelpPopupWindowX.showPopup", "popupHeight=" + popupHeight);
        }*/

        ViewGroup activityView = activity.findViewById(android.R.id.content);
        int activityHeight = activityView.getHeight();
        //int activityWidth = activityView.getWidth();
        //PPApplication.logE("DialogHelpPopupWindowX.showPopup","activityHeight="+activityHeight);

        //int[] activityLocation = new int[2];
        //_eventStatusView.getLocationOnScreen(location);
        //activityView.getLocationInWindow(activityLocation);

        int[] locationHelpIcon = new int[2];
        helpIcon.getLocationOnScreen(locationHelpIcon); // must be used this in dialogs.
        //helpIcon.getLocationInWindow(locationHelpIcon);
        /*if (PPApplication.logEnabled()) {
            PPApplication.logE("DialogHelpPopupWindowX.showPopup", "locationHelpIcon[0]=" + locationHelpIcon[0]);
            PPApplication.logE("DialogHelpPopupWindowX.showPopup", "locationHelpIcon[1]=" + locationHelpIcon[1]);
        }*/

        int x = 0;
        int y = 0;

        if (locationHelpIcon[0] + helpIcon.getWidth() - popupWidth < 0)
            x = -(locationHelpIcon[0] + helpIcon.getWidth() - popupWidth);

        if ((locationHelpIcon[1] + popupHeight) > activityHeight)
            y = -(locationHelpIcon[1] - (activityHeight - popupHeight));

        /*if (PPApplication.logEnabled()) {
            PPApplication.logE("DialogHelpPopupWindowX.showPopup", "x=" + x);
            PPApplication.logE("DialogHelpPopupWindowX.showPopup", "y=" + y);
        }*/

        popup.setClippingEnabled(false); // disabled for draw outside activity
        popup.showOnAnchor(helpIcon, VerticalPosition.ALIGN_TOP,
                HorizontalPosition.ALIGN_RIGHT, x, y, false);
    }
}
 
Example 20
Source File: OkUtils.java    From BlueBoard with Apache License 2.0 4 votes vote down vote up
/**
 * 检查activity是否还存在
 */
public static boolean isActivityLive(Activity activity) {
    return activity != null && !activity.isDestroyed() && !activity.isFinishing();
}