android.util.AndroidRuntimeException Java Examples

The following examples show how to use android.util.AndroidRuntimeException. 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: AnimatorSet.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * <p>Note that canceling a <code>AnimatorSet</code> also cancels all of the animations that it
 * is responsible for.</p>
 */
@SuppressWarnings("unchecked")
@Override
public void cancel() {
    if (Looper.myLooper() == null) {
        throw new AndroidRuntimeException("Animators may only be run on Looper threads");
    }
    if (isStarted()) {
        ArrayList<AnimatorListener> tmpListeners = null;
        if (mListeners != null) {
            tmpListeners = (ArrayList<AnimatorListener>) mListeners.clone();
            int size = tmpListeners.size();
            for (int i = 0; i < size; i++) {
                tmpListeners.get(i).onAnimationCancel(this);
            }
        }
        ArrayList<Node> playingSet = new ArrayList<>(mPlayingSet);
        int setSize = playingSet.size();
        for (int i = 0; i < setSize; i++) {
            playingSet.get(i).mAnimation.cancel();
        }
        mPlayingSet.clear();
        endAnimation();
    }
}
 
Example #2
Source File: ContextImpl.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
@Override
public void startActivity(Intent intent, Bundle options) {
    warnIfCallingFromSystemProcess();

    // Calling start activity from outside an activity without FLAG_ACTIVITY_NEW_TASK is
    // generally not allowed, except if the caller specifies the task id the activity should
    // be launched in. A bug was existed between N and O-MR1 which allowed this to work. We
    // maintain this for backwards compatibility.
    final int targetSdkVersion = getApplicationInfo().targetSdkVersion;

    if ((intent.getFlags() & Intent.FLAG_ACTIVITY_NEW_TASK) == 0
            && (targetSdkVersion < Build.VERSION_CODES.N
                    || targetSdkVersion >= Build.VERSION_CODES.P)
            && (options == null
                    || ActivityOptions.fromBundle(options).getLaunchTaskId() == -1)) {
        throw new AndroidRuntimeException(
                "Calling startActivity() from outside of an Activity "
                        + " context requires the FLAG_ACTIVITY_NEW_TASK flag."
                        + " Is this really what you want?");
    }
    mMainThread.getInstrumentation().execStartActivity(
            getOuterContext(), mMainThread.getApplicationThread(), null,
            (Activity) null, intent, -1, options);
}
 
Example #3
Source File: ActionBarSherlockCompat.java    From zhangshangwuda with Apache License 2.0 6 votes vote down vote up
@Override
public boolean requestFeature(int featureId) {
    if (ActionBarSherlock.DEBUG) Log.d(TAG, "[requestFeature] featureId: " + featureId);

    if (mContentParent != null) {
        throw new AndroidRuntimeException("requestFeature() must be called before adding content");
    }

    switch (featureId) {
        case Window.FEATURE_ACTION_BAR:
        case Window.FEATURE_ACTION_BAR_OVERLAY:
        case Window.FEATURE_ACTION_MODE_OVERLAY:
        case Window.FEATURE_INDETERMINATE_PROGRESS:
        case Window.FEATURE_NO_TITLE:
        case Window.FEATURE_PROGRESS:
            mFeatures |= (1 << featureId);
            return true;

        default:
            return false;
    }
}
 
Example #4
Source File: ActionBarSherlockCompat.java    From Libraries-for-Android-Developers with MIT License 6 votes vote down vote up
@Override
public boolean requestFeature(int featureId) {
    if (ActionBarSherlock.DEBUG) Log.d(TAG, "[requestFeature] featureId: " + featureId);

    if (mContentParent != null) {
        throw new AndroidRuntimeException("requestFeature() must be called before adding content");
    }

    switch (featureId) {
        case Window.FEATURE_ACTION_BAR:
        case Window.FEATURE_ACTION_BAR_OVERLAY:
        case Window.FEATURE_ACTION_MODE_OVERLAY:
        case Window.FEATURE_INDETERMINATE_PROGRESS:
        case Window.FEATURE_NO_TITLE:
        case Window.FEATURE_PROGRESS:
            mFeatures |= (1 << featureId);
            return true;

        default:
            return false;
    }
}
 
Example #5
Source File: ActionBarSherlockCompat.java    From CSipSimple with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean requestFeature(int featureId) {
    if (ActionBarSherlock.DEBUG) Log.d(TAG, "[requestFeature] featureId: " + featureId);

    if (mContentParent != null) {
        throw new AndroidRuntimeException("requestFeature() must be called before adding content");
    }

    switch (featureId) {
        case Window.FEATURE_ACTION_BAR:
        case Window.FEATURE_ACTION_BAR_OVERLAY:
        case Window.FEATURE_ACTION_MODE_OVERLAY:
        case Window.FEATURE_INDETERMINATE_PROGRESS:
        case Window.FEATURE_NO_TITLE:
        case Window.FEATURE_PROGRESS:
            mFeatures |= (1 << featureId);
            return true;

        default:
            return false;
    }
}
 
Example #6
Source File: AboutFragment.java    From android-wallet-app with GNU General Public License v3.0 6 votes vote down vote up
@OnClick(R.id.about_licenses)
public void onAboutLicensesClick() {
    try {
        new LicensesDialog.Builder(getActivity())
                .setNotices(R.raw.licenses)
                .setTitle(R.string.about_licenses)
                .setIncludeOwnLicense(true)
                .setCloseText(R.string.buttons_ok)
                .build()
                .showAppCompat();
    } catch (AndroidRuntimeException e) {
        View contentView = getActivity().getWindow().getDecorView();
        Snackbar snackbar = Snackbar.make(contentView,
                R.string.message_open_licenses_error, Snackbar.LENGTH_LONG);
        snackbar.setAction(R.string.message_install_web_view, v -> openPlayStore());
        snackbar.show();
    }
}
 
Example #7
Source File: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 6 votes vote down vote up
@Override
public void startActivity(Intent intent, Bundle options) {
    warnIfCallingFromSystemProcess();

    // Calling start activity from outside an activity without FLAG_ACTIVITY_NEW_TASK is
    // generally not allowed, except if the caller specifies the task id the activity should
    // be launched in.
    if ((intent.getFlags()&Intent.FLAG_ACTIVITY_NEW_TASK) == 0
            && options != null && ActivityOptions.fromBundle(options).getLaunchTaskId() == -1) {
        throw new AndroidRuntimeException(
                "Calling startActivity() from outside of an Activity "
                + " context requires the FLAG_ACTIVITY_NEW_TASK flag."
                + " Is this really what you want?");
    }
    mMainThread.getInstrumentation().execStartActivity(
            getOuterContext(), mMainThread.getApplicationThread(), null,
            (Activity) null, intent, -1, options);
}
 
Example #8
Source File: SpringAnimation.java    From CircularReveal with MIT License 6 votes vote down vote up
/**
 * Skips to the end of the animation. If the spring is undamped, an
 * {@link IllegalStateException} will be thrown, as the animation would never reach to an end.
 * It is recommended to check {@link #canSkipToEnd()} before calling this method. This method
 * should only be called on main thread. If animation is not running, no-op.
 *
 * @throws IllegalStateException if the spring is undamped (i.e. damping ratio = 0)
 * @throws AndroidRuntimeException if this method is not called on the main thread
 */
public void skipToEnd() {
  if (!canSkipToEnd()) {
    throw new UnsupportedOperationException("Spring animations can only come to an end"
        + " when there is damping");
  }
  if (Looper.myLooper() != Looper.getMainLooper()) {
    throw new AndroidRuntimeException("Animations may only be started on the main thread");
  }
  if (mRunning) {
    if (mPendingPosition != UNSET) {
      mSpring.setFinalPosition(mPendingPosition);
      mPendingPosition = UNSET;
    }
    mValue = mSpring.getFinalPosition();
    mVelocity = 0;
    cancel();
  }
}
 
Example #9
Source File: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 6 votes vote down vote up
@Override
public void startActivity(Intent intent, Bundle options) {
    warnIfCallingFromSystemProcess();

    // Calling start activity from outside an activity without FLAG_ACTIVITY_NEW_TASK is
    // generally not allowed, except if the caller specifies the task id the activity should
    // be launched in.
    if ((intent.getFlags()&Intent.FLAG_ACTIVITY_NEW_TASK) == 0
            && options != null && ActivityOptions.fromBundle(options).getLaunchTaskId() == -1) {
        throw new AndroidRuntimeException(
                "Calling startActivity() from outside of an Activity "
                + " context requires the FLAG_ACTIVITY_NEW_TASK flag."
                + " Is this really what you want?");
    }
    mMainThread.getInstrumentation().execStartActivity(
            getOuterContext(), mMainThread.getApplicationThread(), null,
            (Activity) null, intent, -1, options);
}
 
Example #10
Source File: TransitionSet.java    From Transitions-Everywhere with Apache License 2.0 6 votes vote down vote up
/**
 * Sets the play order of this set's child transitions.
 *
 * @param ordering {@link #ORDERING_TOGETHER} to play this set's child
 *                 transitions together, {@link #ORDERING_SEQUENTIAL} to play the child
 *                 transitions in sequence.
 * @return This transitionSet object.
 */
@NonNull
public TransitionSet setOrdering(int ordering) {
    switch (ordering) {
        case ORDERING_SEQUENTIAL:
            mPlayTogether = false;
            break;
        case ORDERING_TOGETHER:
            mPlayTogether = true;
            break;
        default:
            throw new AndroidRuntimeException("Invalid parameter for TransitionSet " +
                    "ordering: " + ordering);
    }
    return this;
}
 
Example #11
Source File: ActionBarSherlockCompat.java    From zen4android with MIT License 6 votes vote down vote up
@Override
public boolean requestFeature(int featureId) {
    if (ActionBarSherlock.DEBUG) Log.d(TAG, "[requestFeature] featureId: " + featureId);

    if (mContentParent != null) {
        throw new AndroidRuntimeException("requestFeature() must be called before adding content");
    }

    switch (featureId) {
        case Window.FEATURE_ACTION_BAR:
        case Window.FEATURE_ACTION_BAR_OVERLAY:
        case Window.FEATURE_ACTION_MODE_OVERLAY:
        case Window.FEATURE_INDETERMINATE_PROGRESS:
        case Window.FEATURE_NO_TITLE:
        case Window.FEATURE_PROGRESS:
            mFeatures |= (1 << featureId);
            return true;

        default:
            return false;
    }
}
 
Example #12
Source File: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 6 votes vote down vote up
@Override
public void startActivity(Intent intent, Bundle options) {
    warnIfCallingFromSystemProcess();

    // Calling start activity from outside an activity without FLAG_ACTIVITY_NEW_TASK is
    // generally not allowed, except if the caller specifies the task id the activity should
    // be launched in. A bug was existed between N and O-MR1 which allowed this to work. We
    // maintain this for backwards compatibility.
    final int targetSdkVersion = getApplicationInfo().targetSdkVersion;

    if ((intent.getFlags() & Intent.FLAG_ACTIVITY_NEW_TASK) == 0
            && (targetSdkVersion < Build.VERSION_CODES.N
                    || targetSdkVersion >= Build.VERSION_CODES.P)
            && (options == null
                    || ActivityOptions.fromBundle(options).getLaunchTaskId() == -1)) {
        throw new AndroidRuntimeException(
                "Calling startActivity() from outside of an Activity "
                        + " context requires the FLAG_ACTIVITY_NEW_TASK flag."
                        + " Is this really what you want?");
    }
    mMainThread.getInstrumentation().execStartActivity(
            getOuterContext(), mMainThread.getApplicationThread(), null,
            (Activity) null, intent, -1, options);
}
 
Example #13
Source File: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 6 votes vote down vote up
@Override
public void startActivity(Intent intent, Bundle options) {
    warnIfCallingFromSystemProcess();

    // Calling start activity from outside an activity without FLAG_ACTIVITY_NEW_TASK is
    // generally not allowed, except if the caller specifies the task id the activity should
    // be launched in. A bug was existed between N and O-MR1 which allowed this to work. We
    // maintain this for backwards compatibility.
    final int targetSdkVersion = getApplicationInfo().targetSdkVersion;

    if ((intent.getFlags() & Intent.FLAG_ACTIVITY_NEW_TASK) == 0
            && (targetSdkVersion < Build.VERSION_CODES.N
                    || targetSdkVersion >= Build.VERSION_CODES.P)
            && (options == null
                    || ActivityOptions.fromBundle(options).getLaunchTaskId() == -1)) {
        throw new AndroidRuntimeException(
                "Calling startActivity() from outside of an Activity "
                        + " context requires the FLAG_ACTIVITY_NEW_TASK flag."
                        + " Is this really what you want?");
    }
    mMainThread.getInstrumentation().execStartActivity(
            getOuterContext(), mMainThread.getApplicationThread(), null,
            (Activity) null, intent, -1, options);
}
 
Example #14
Source File: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 6 votes vote down vote up
@Override
public void startActivity(Intent intent, Bundle options) {
    warnIfCallingFromSystemProcess();

    // Calling start activity from outside an activity without FLAG_ACTIVITY_NEW_TASK is
    // generally not allowed, except if the caller specifies the task id the activity should
    // be launched in.
    if ((intent.getFlags()&Intent.FLAG_ACTIVITY_NEW_TASK) == 0
            && options != null && ActivityOptions.fromBundle(options).getLaunchTaskId() == -1) {
        throw new AndroidRuntimeException(
                "Calling startActivity() from outside of an Activity "
                + " context requires the FLAG_ACTIVITY_NEW_TASK flag."
                + " Is this really what you want?");
    }
    mMainThread.getInstrumentation().execStartActivity(
            getOuterContext(), mMainThread.getApplicationThread(), null,
            (Activity) null, intent, -1, options);
}
 
Example #15
Source File: SdlBroadcastReceiver.java    From sdl_java_suite with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * This method will set a new UncaughtExceptionHandler for the current thread. The only
 * purpose of the custom UncaughtExceptionHandler is to catch the rare occurrence that the
 * SdlRouterService can't be started fast enough by the system after calling
 * startForegroundService so the onCreate method doesn't get called before the foreground promise
 * timer expires. The new UncaughtExceptionHandler will catch that specific exception and tell the
 * main looper to continue forward. This still leaves the SdlRouterService killed, but prevents
 * an ANR to the app that makes the startForegroundService call.
 */
static protected void setForegroundExceptionHandler() {
	final Thread.UncaughtExceptionHandler defaultUncaughtExceptionHandler = Thread.getDefaultUncaughtExceptionHandler();
	if(defaultUncaughtExceptionHandler != foregroundExceptionHandler){
		foregroundExceptionHandler = new Thread.UncaughtExceptionHandler() {
			@Override
			public void uncaughtException(Thread t, Throwable e) {
				if (e != null
						&& e instanceof AndroidRuntimeException
						&& "android.app.RemoteServiceException".equals(e.getClass().getName())  //android.app.RemoteServiceException is a private class
						&& e.getMessage().contains("SdlRouterService")) {

					Log.i(TAG, "Handling failed startForegroundService call");
					Looper.loop();
				} else if (defaultUncaughtExceptionHandler != null) { //No other exception should be handled
					defaultUncaughtExceptionHandler.uncaughtException(t, e);
				}
			}
		};
		Thread.setDefaultUncaughtExceptionHandler(foregroundExceptionHandler);
	}
}
 
Example #16
Source File: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 6 votes vote down vote up
@Override
public void startActivity(Intent intent, Bundle options) {
    warnIfCallingFromSystemProcess();

    // Calling start activity from outside an activity without FLAG_ACTIVITY_NEW_TASK is
    // generally not allowed, except if the caller specifies the task id the activity should
    // be launched in.
    if ((intent.getFlags()&Intent.FLAG_ACTIVITY_NEW_TASK) == 0
            && options != null && ActivityOptions.fromBundle(options).getLaunchTaskId() == -1) {
        throw new AndroidRuntimeException(
                "Calling startActivity() from outside of an Activity "
                + " context requires the FLAG_ACTIVITY_NEW_TASK flag."
                + " Is this really what you want?");
    }
    mMainThread.getInstrumentation().execStartActivity(
            getOuterContext(), mMainThread.getApplicationThread(), null,
            (Activity) null, intent, -1, options);
}
 
Example #17
Source File: ActionBarSherlockCompat.java    From android-apps with MIT License 6 votes vote down vote up
@Override
public boolean requestFeature(int featureId) {
    if (DEBUG) Log.d(TAG, "[requestFeature] featureId: " + featureId);

    if (mContentParent != null) {
        throw new AndroidRuntimeException("requestFeature() must be called before adding content");
    }

    switch (featureId) {
        case Window.FEATURE_ACTION_BAR:
        case Window.FEATURE_ACTION_BAR_OVERLAY:
        case Window.FEATURE_ACTION_MODE_OVERLAY:
        case Window.FEATURE_INDETERMINATE_PROGRESS:
        case Window.FEATURE_NO_TITLE:
        case Window.FEATURE_PROGRESS:
            mFeatures |= (1 << featureId);
            return true;

        default:
            return false;
    }
}
 
Example #18
Source File: ValueAnimator.java    From Libraries-for-Android-Developers with MIT License 5 votes vote down vote up
/**
 * Start the animation playing. This version of start() takes a boolean flag that indicates
 * whether the animation should play in reverse. The flag is usually false, but may be set
 * to true if called from the reverse() method.
 *
 * <p>The animation started by calling this method will be run on the thread that called
 * this method. This thread should have a Looper on it (a runtime exception will be thrown if
 * this is not the case). Also, if the animation will animate
 * properties of objects in the view hierarchy, then the calling thread should be the UI
 * thread for that view hierarchy.</p>
 *
 * @param playBackwards Whether the ValueAnimator should start playing in reverse.
 */
private void start(boolean playBackwards) {
    if (Looper.myLooper() == null) {
        throw new AndroidRuntimeException("Animators may only be run on Looper threads");
    }
    mPlayingBackwards = playBackwards;
    mCurrentIteration = 0;
    mPlayingState = STOPPED;
    mStarted = true;
    mStartedDelay = false;
    sPendingAnimations.get().add(this);
    if (mStartDelay == 0) {
        // This sets the initial value of the animation, prior to actually starting it running
        setCurrentPlayTime(getCurrentPlayTime());
        mPlayingState = STOPPED;
        mRunning = true;

        if (mListeners != null) {
            ArrayList<AnimatorListener> tmpListeners =
                    (ArrayList<AnimatorListener>) mListeners.clone();
            int numListeners = tmpListeners.size();
            for (int i = 0; i < numListeners; ++i) {
                tmpListeners.get(i).onAnimationStart(this);
            }
        }
    }
    AnimationHandler animationHandler = sAnimationHandler.get();
    if (animationHandler == null) {
        animationHandler = new AnimationHandler();
        sAnimationHandler.set(animationHandler);
    }
    animationHandler.sendEmptyMessage(ANIMATION_START);
}
 
Example #19
Source File: Utility.java    From iBeebo with GNU General Public License v3.0 5 votes vote down vote up
public static void registerReceiverIgnoredReceiverHasRegisteredHereException(Context context,
                                                                             RecordOperationAppBroadcastReceiver broadcastReceiver,
                                                                             IntentFilter intentFilter) {
    if (broadcastReceiver == null || broadcastReceiver.hasRegistered() || intentFilter == null) {
        return;
    }
    try {
        context.getApplicationContext().registerReceiver(broadcastReceiver, intentFilter);
        broadcastReceiver.setHasRegistered(true);
    } catch (AndroidRuntimeException receiverHasRegisteredException) {
        receiverHasRegisteredException.printStackTrace();
    }
}
 
Example #20
Source File: ValueAnimator.java    From Mover with Apache License 2.0 5 votes vote down vote up
/**
 * Start the animation playing. This version of start() takes a boolean flag that indicates
 * whether the animation should play in reverse. The flag is usually false, but may be set
 * to true if called from the reverse() method.
 *
 * <p>The animation started by calling this method will be run on the thread that called
 * this method. This thread should have a Looper on it (a runtime exception will be thrown if
 * this is not the case). Also, if the animation will animate
 * properties of objects in the view hierarchy, then the calling thread should be the UI
 * thread for that view hierarchy.</p>
 *
 * @param playBackwards Whether the ValueAnimator should start playing in reverse.
 */
private void start(boolean playBackwards) {
    if (Looper.myLooper() == null) {
        throw new AndroidRuntimeException("Animators may only be run on Looper threads");
    }
    mPlayingBackwards = playBackwards;
    mCurrentIteration = 0;
    mPlayingState = STOPPED;
    mStarted = true;
    mStartedDelay = false;
    sPendingAnimations.get().add(this);
    if (mStartDelay == 0) {
        // This sets the initial value of the animation, prior to actually starting it running
        setCurrentPlayTime(getCurrentPlayTime());
        mPlayingState = STOPPED;
        mRunning = true;

        if (mListeners != null) {
            ArrayList<AnimatorListener> tmpListeners =
                    (ArrayList<AnimatorListener>) mListeners.clone();
            int numListeners = tmpListeners.size();
            for (int i = 0; i < numListeners; ++i) {
                tmpListeners.get(i).onAnimationStart(this);
            }
        }
    }
    AnimationHandler animationHandler = sAnimationHandler.get();
    if (animationHandler == null) {
        animationHandler = new AnimationHandler();
        sAnimationHandler.set(animationHandler);
    }
    animationHandler.sendEmptyMessage(ANIMATION_START);
}
 
Example #21
Source File: Utility.java    From iBeebo with GNU General Public License v3.0 5 votes vote down vote up
public static void registerReceiverIgnoredReceiverHasRegisteredHereException(Context context,
                                                                             RecordOperationAppBroadcastReceiver broadcastReceiver,
                                                                             IntentFilter intentFilter) {
    if (broadcastReceiver == null || broadcastReceiver.hasRegistered() || intentFilter == null) {
        return;
    }
    try {
        context.getApplicationContext().registerReceiver(broadcastReceiver, intentFilter);
        broadcastReceiver.setHasRegistered(true);
    } catch (AndroidRuntimeException receiverHasRegisteredException) {
        receiverHasRegisteredException.printStackTrace();
    }
}
 
Example #22
Source File: TransitionSet.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the play order of this set's child transitions.
 *
 * @param ordering {@link #ORDERING_TOGETHER} to play this set's child
 * transitions together, {@link #ORDERING_SEQUENTIAL} to play the child
 * transitions in sequence.
 * @return This transitionSet object.
 */
public TransitionSet setOrdering(int ordering) {
    switch (ordering) {
        case ORDERING_SEQUENTIAL:
            mPlayTogether = false;
            break;
        case ORDERING_TOGETHER:
            mPlayTogether = true;
            break;
        default:
            throw new AndroidRuntimeException("Invalid parameter for TransitionSet " +
                    "ordering: " + ordering);
    }
    return this;
}
 
Example #23
Source File: ValueAnimator.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public void resume() {
    if (Looper.myLooper() == null) {
        throw new AndroidRuntimeException("Animators may only be resumed from the same " +
                "thread that the animator was started on");
    }
    if (mPaused && !mResumed) {
        mResumed = true;
        if (mPauseTime > 0) {
            addAnimationCallback(0);
        }
    }
    super.resume();
}
 
Example #24
Source File: ValueAnimator.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public void end() {
    if (Looper.myLooper() == null) {
        throw new AndroidRuntimeException("Animators may only be run on Looper threads");
    }
    if (!mRunning) {
        // Special case if the animation has not yet started; get it ready for ending
        startAnimation();
        mStarted = true;
    } else if (!mInitialized) {
        initAnimation();
    }
    animateValue(shouldPlayBackward(mRepeatCount, mReversing) ? 0f : 1f);
    endAnimation();
}
 
Example #25
Source File: FabSpeedDial.java    From FireFiles with Apache License 2.0 5 votes vote down vote up
private void resolveCompulsoryAttributes(TypedArray typedArray) {
    if (typedArray.hasValue(R.styleable.FabSpeedDial_fabMenu)) {
        menuId = typedArray.getResourceId(R.styleable.FabSpeedDial_fabMenu, 0);
    } else {
        throw new AndroidRuntimeException("You must provide the id of the menu resource.");
    }

    if (typedArray.hasValue(R.styleable.FabSpeedDial_fabGravity)) {
        fabGravity = typedArray.getInt(R.styleable.FabSpeedDial_fabGravity, DEFAULT_MENU_POSITION);
    } else {
        throw new AndroidRuntimeException("You must specify the gravity of the Fab.");
    }
}
 
Example #26
Source File: AnimatorSet.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public void pause() {
    if (Looper.myLooper() == null) {
        throw new AndroidRuntimeException("Animators may only be run on Looper threads");
    }
    boolean previouslyPaused = mPaused;
    super.pause();
    if (!previouslyPaused && mPaused) {
        mPauseTime = -1;
    }
}
 
Example #27
Source File: AnimatorSet.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public void onAnimationEnd(Animator animation) {
    if (mNodeMap.get(animation) == null) {
        throw new AndroidRuntimeException("Error: animation ended is not in the node map");
    }
    mNodeMap.get(animation).mEnded = true;

}
 
Example #28
Source File: SdlRouterService.java    From sdl_java_suite with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * This method will set a new UncaughtExceptionHandler for the current thread. The only
 * purpose of the custom UncaughtExceptionHandler is to catch the rare occurrence that the
 * a specific mobile device/OS can't properly handle the deletion and creation of the foreground
 * notification channel that is necessary for foreground services after Android Oreo.
 * The new UncaughtExceptionHandler will catch that specific exception and tell the
 * main looper to continue forward. This still leaves the SdlRouterService killed, but prevents
 * an ANR to the app that makes the startForegroundService call. It will set a flag that will
 * prevent the channel from being deleted in the future and therefore avoiding this exception.
 */
protected void setRouterServiceExceptionHandler() {
	final Thread.UncaughtExceptionHandler defaultUncaughtExceptionHandler = Thread.getDefaultUncaughtExceptionHandler();
	if (defaultUncaughtExceptionHandler != routerServiceExceptionHandler) {
		routerServiceExceptionHandler = new Thread.UncaughtExceptionHandler() {
			@Override
			public void uncaughtException(Thread t, Throwable e) {
				if (e != null
						&& e instanceof AndroidRuntimeException
						&& "android.app.RemoteServiceException".equals(e.getClass().getName())  //android.app.RemoteServiceException is a private class
						&& e.getMessage().contains("invalid channel for service notification")) { //This is the message received in the exception for notification channel issues

					// Set the flag to not delete the notification channel to avoid this exception in the future
					try{
					    SdlRouterService.this.setSdlRouterServicePrefs(KEY_AVOID_NOTIFICATION_CHANNEL_DELETE, true);
					}catch (Exception exception){
					    //Unable to save flag for KEY_AVOID_NOTIFICATION_CHANNEL_DELETE
					}
					Looper.loop();
				} else if (defaultUncaughtExceptionHandler != null) { //No other exception should be handled
					defaultUncaughtExceptionHandler.uncaughtException(t, e);
				}
			}
		};
		Thread.setDefaultUncaughtExceptionHandler(routerServiceExceptionHandler);
	}
}
 
Example #29
Source File: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 5 votes vote down vote up
/** @hide */
@Override
public void startActivitiesAsUser(Intent[] intents, Bundle options, UserHandle userHandle) {
    if ((intents[0].getFlags()&Intent.FLAG_ACTIVITY_NEW_TASK) == 0) {
        throw new AndroidRuntimeException(
                "Calling startActivities() from outside of an Activity "
                + " context requires the FLAG_ACTIVITY_NEW_TASK flag on first Intent."
                + " Is this really what you want?");
    }
    mMainThread.getInstrumentation().execStartActivitiesAsUser(
            getOuterContext(), mMainThread.getApplicationThread(), null,
            (Activity) null, intents, options, userHandle.getIdentifier());
}
 
Example #30
Source File: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 5 votes vote down vote up
@Override
public void startActivities(Intent[] intents, Bundle options) {
    warnIfCallingFromSystemProcess();
    if ((intents[0].getFlags()&Intent.FLAG_ACTIVITY_NEW_TASK) == 0) {
        throw new AndroidRuntimeException(
                "Calling startActivities() from outside of an Activity "
                + " context requires the FLAG_ACTIVITY_NEW_TASK flag on first Intent."
                + " Is this really what you want?");
    }
    mMainThread.getInstrumentation().execStartActivities(
        getOuterContext(), mMainThread.getApplicationThread(), null,
        (Activity)null, intents, options);
}