Search in sources :

Example 36 with UiThread

use of android.support.annotation.UiThread in project AndroidLife by CaMnter.

the class Utils method getFloat.

// Implicit synchronization for use of shared resource VALUE.
@UiThread
public static float getFloat(Context context, @DimenRes int id) {
    TypedValue value = VALUE;
    context.getResources().getValue(id, value, true);
    if (value.type == TypedValue.TYPE_FLOAT) {
        return value.getFloat();
    }
    throw new Resources.NotFoundException("Resource ID #0x" + Integer.toHexString(id) + " type #0x" + Integer.toHexString(value.type) + " is not valid");
}
Also used : TypedValue(android.util.TypedValue) UiThread(android.support.annotation.UiThread)

Example 37 with UiThread

use of android.support.annotation.UiThread in project AndroidChromium by JackyAndroid.

the class ChromeStrictMode method initializeStrictModeWatch.

/**
 * Replace Android OS's StrictMode.violationsBeingTimed with a custom ArrayList acting as an
 * observer into violation stack traces. Set up an idle handler so StrictMode violations that
 * occur on startup are not ignored.
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
@UiThread
private static void initializeStrictModeWatch() {
    try {
        Field violationsBeingTimedField = StrictMode.class.getDeclaredField("violationsBeingTimed");
        violationsBeingTimedField.setAccessible(true);
        ThreadLocal<ArrayList> violationsBeingTimed = (ThreadLocal<ArrayList>) violationsBeingTimedField.get(null);
        ArrayList replacementList = new SnoopingArrayList();
        violationsBeingTimed.set(replacementList);
    } catch (Exception e) {
        // Terminate watch if any exceptions are raised.
        Log.w(TAG, "Could not initialize StrictMode watch.", e);
        return;
    }
    sNumUploads.set(0);
    // Delay handling StrictMode violations during initialization until the main loop is idle.
    Looper.myQueue().addIdleHandler(new MessageQueue.IdleHandler() {

        @Override
        public boolean queueIdle() {
            // Will retry if the native library has not been initialized.
            if (!LibraryLoader.isInitialized())
                return true;
            // reached the max number of uploads for this session.
            if (sCachedStackTraces.isEmpty()) {
                // In case of races, continue checking an extra time (equal condition).
                return sNumUploads.get() <= MAX_UPLOADS_PER_SESSION;
            }
            // Since this is the only place we are removing elements, no need for additional
            // synchronization to ensure it is still non-empty.
            reportStrictModeViolation(sCachedStackTraces.remove(0));
            return true;
        }
    });
}
Also used : Field(java.lang.reflect.Field) MessageQueue(android.os.MessageQueue) ArrayList(java.util.ArrayList) UiThread(android.support.annotation.UiThread)

Example 38 with UiThread

use of android.support.annotation.UiThread in project AndroidChromium by JackyAndroid.

the class ChromeStrictMode method reportStrictModeViolation.

/**
 * Always process the violation on the UI thread. This ensures other crash reports are not
 * corrupted. Since each individual user has a very small chance of uploading each violation,
 * and we have a hard cap of 3 per session, this will not affect performance too much.
 *
 * @param violationInfo The violation info from the StrictMode violation in question.
 */
@UiThread
private static void reportStrictModeViolation(Object violationInfo) {
    try {
        Field crashInfoField = violationInfo.getClass().getField("crashInfo");
        ApplicationErrorReport.CrashInfo crashInfo = (ApplicationErrorReport.CrashInfo) crashInfoField.get(violationInfo);
        String stackTrace = crashInfo.stackTrace;
        if (stackTrace == null) {
            Log.d(TAG, "StrictMode violation stack trace was null.");
        } else {
            Log.d(TAG, "Upload stack trace: " + stackTrace);
            JavaExceptionReporter.reportStackTrace(stackTrace);
        }
    } catch (Exception e) {
        // Ignore all exceptions.
        Log.d(TAG, "Could not handle observed StrictMode violation.", e);
    }
}
Also used : Field(java.lang.reflect.Field) ApplicationErrorReport(android.app.ApplicationErrorReport) UiThread(android.support.annotation.UiThread)

Example 39 with UiThread

use of android.support.annotation.UiThread in project AndroidChromium by JackyAndroid.

the class ChromeStrictMode method configureStrictMode.

/**
 * Turn on StrictMode detection based on build and command-line switches.
 */
@UiThread
// FindBugs doesn't like conditionals with compile time results
@SuppressFBWarnings("UCF_USELESS_CONTROL_FLOW")
public static void configureStrictMode() {
    assert ThreadUtils.runningOnUiThread();
    if (sIsStrictModeAlreadyConfigured) {
        return;
    }
    sIsStrictModeAlreadyConfigured = true;
    StrictMode.ThreadPolicy.Builder threadPolicy = new StrictMode.ThreadPolicy.Builder(StrictMode.getThreadPolicy());
    StrictMode.VmPolicy.Builder vmPolicy = new StrictMode.VmPolicy.Builder(StrictMode.getVmPolicy());
    CommandLine commandLine = CommandLine.getInstance();
    if ("eng".equals(Build.TYPE) || BuildConfig.DCHECK_IS_ON || ChromeVersionInfo.isLocalBuild() || commandLine.hasSwitch(ChromeSwitches.STRICT_MODE)) {
        turnOnDetection(threadPolicy, vmPolicy);
        addDefaultPenalties(threadPolicy, vmPolicy);
        if ("death".equals(commandLine.getSwitchValue(ChromeSwitches.STRICT_MODE))) {
            addThreadDeathPenalty(threadPolicy);
            addVmDeathPenalty(vmPolicy);
        } else if ("testing".equals(commandLine.getSwitchValue(ChromeSwitches.STRICT_MODE))) {
            addThreadDeathPenalty(threadPolicy);
        // Currently VmDeathPolicy kills the process, and is not visible on bot test output.
        }
    }
    // Enroll 1% of dev sessions into StrictMode watch. This is done client-side rather than
    // through finch because this decision is as early as possible in the browser initialization
    // process. We need to detect early start-up StrictMode violations before loading native and
    // before warming the SharedPreferences (that is a violation in an of itself). We will
    // closely monitor this on dev channel.
    boolean enableStrictModeWatch = (ChromeVersionInfo.isDevBuild() && Math.random() < UPLOAD_PROBABILITY);
    if ((ChromeVersionInfo.isLocalBuild() && !BuildConfig.DCHECK_IS_ON) || enableStrictModeWatch) {
        turnOnDetection(threadPolicy, vmPolicy);
        initializeStrictModeWatch();
    }
    StrictMode.setThreadPolicy(threadPolicy.build());
    StrictMode.setVmPolicy(vmPolicy.build());
}
Also used : StrictMode(android.os.StrictMode) CommandLine(org.chromium.base.CommandLine) UiThread(android.support.annotation.UiThread) SuppressFBWarnings(org.chromium.base.annotations.SuppressFBWarnings)

Example 40 with UiThread

use of android.support.annotation.UiThread in project FastHub by k0shk0sh.

the class AnimHelper method revealDialog.

@UiThread
public static void revealDialog(@NonNull Dialog dialog, int animDuration) {
    if (dialog.getWindow() != null) {
        View view = dialog.getWindow().getDecorView();
        if (view != null) {
            view.post(() -> {
                if (ViewCompat.isAttachedToWindow(view)) {
                    int centerX = view.getWidth() / 2;
                    int centerY = view.getHeight() / 2;
                    Animator animator = ViewAnimationUtils.createCircularReveal(view, centerX, centerY, 20, view.getHeight());
                    animator.setDuration(animDuration);
                    animator.start();
                }
            });
        }
    }
}
Also used : ObjectAnimator(android.animation.ObjectAnimator) Animator(android.animation.Animator) ViewPropertyAnimator(android.view.ViewPropertyAnimator) View(android.view.View) UiThread(android.support.annotation.UiThread)

Aggregations

UiThread (android.support.annotation.UiThread)48 View (android.view.View)9 ObjectAnimator (android.animation.ObjectAnimator)6 Animator (android.animation.Animator)5 Drawable (android.graphics.drawable.Drawable)5 ImageView (android.widget.ImageView)5 TextView (android.widget.TextView)5 ArrayList (java.util.ArrayList)5 Intent (android.content.Intent)4 Fragment (android.support.v4.app.Fragment)4 MenuItem (android.view.MenuItem)4 ViewPropertyAnimator (android.view.ViewPropertyAnimator)4 Paint (android.graphics.Paint)3 Rect (android.graphics.Rect)3 DialogFragment (android.support.v4.app.DialogFragment)3 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)2 Location (android.location.Location)2 Bundle (android.os.Bundle)2 AlertDialog (android.support.v7.app.AlertDialog)2 RecyclerView (android.support.v7.widget.RecyclerView)2