Search in sources :

Example 26 with TargetApi

use of android.annotation.TargetApi in project tinker by Tencent.

the class TinkerDexLoader method loadTinkerJars.

/**
     * Load tinker JARs and add them to
     * the Application ClassLoader.
     *
     * @param application The application.
     */
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
public static boolean loadTinkerJars(Application application, boolean tinkerLoadVerifyFlag, String directory, Intent intentResult, boolean isSystemOTA) {
    if (dexList.isEmpty()) {
        Log.w(TAG, "there is no dex to load");
        return true;
    }
    PathClassLoader classLoader = (PathClassLoader) TinkerDexLoader.class.getClassLoader();
    if (classLoader != null) {
        Log.i(TAG, "classloader: " + classLoader.toString());
    } else {
        Log.e(TAG, "classloader is null");
        ShareIntentUtil.setIntentReturnCode(intentResult, ShareConstants.ERROR_LOAD_PATCH_VERSION_DEX_CLASSLOADER_NULL);
        return false;
    }
    String dexPath = directory + "/" + DEX_PATH + "/";
    File optimizeDir = new File(directory + "/" + DEX_OPTIMIZE_PATH);
    //        Log.i(TAG, "loadTinkerJars: dex path: " + dexPath);
    //        Log.i(TAG, "loadTinkerJars: opt path: " + optimizeDir.getAbsolutePath());
    ArrayList<File> legalFiles = new ArrayList<>();
    final boolean isArtPlatForm = ShareTinkerInternals.isVmArt();
    for (ShareDexDiffPatchInfo info : dexList) {
        //for dalvik, ignore art support dex
        if (isJustArtSupportDex(info)) {
            continue;
        }
        String path = dexPath + info.realName;
        File file = new File(path);
        if (tinkerLoadVerifyFlag) {
            long start = System.currentTimeMillis();
            String checkMd5 = isArtPlatForm ? info.destMd5InArt : info.destMd5InDvm;
            if (!SharePatchFileUtil.verifyDexFileMd5(file, checkMd5)) {
                //it is good to delete the mismatch file
                ShareIntentUtil.setIntentReturnCode(intentResult, ShareConstants.ERROR_LOAD_PATCH_VERSION_DEX_MD5_MISMATCH);
                intentResult.putExtra(ShareIntentUtil.INTENT_PATCH_MISMATCH_DEX_PATH, file.getAbsolutePath());
                return false;
            }
            Log.i(TAG, "verify dex file:" + file.getPath() + " md5, use time: " + (System.currentTimeMillis() - start));
        }
        legalFiles.add(file);
    }
    if (isSystemOTA) {
        parallelOTAResult = true;
        parallelOTAThrowable = null;
        Log.w(TAG, "systemOTA, try parallel oat dexes!!!!!");
        TinkerParallelDexOptimizer.optimizeAll(legalFiles, optimizeDir, new TinkerParallelDexOptimizer.ResultCallback() {

            long start;

            @Override
            public void onStart(File dexFile, File optimizedDir) {
                start = System.currentTimeMillis();
                Log.i(TAG, "start to optimize dex:" + dexFile.getPath());
            }

            @Override
            public void onSuccess(File dexFile, File optimizedDir, File optimizedFile) {
                // Do nothing.
                Log.i(TAG, "success to optimize dex " + dexFile.getPath() + "use time " + (System.currentTimeMillis() - start));
            }

            @Override
            public void onFailed(File dexFile, File optimizedDir, Throwable thr) {
                parallelOTAResult = false;
                parallelOTAThrowable = thr;
                Log.i(TAG, "fail to optimize dex " + dexFile.getPath() + "use time " + (System.currentTimeMillis() - start));
            }
        });
        if (!parallelOTAResult) {
            Log.e(TAG, "parallel oat dexes failed");
            intentResult.putExtra(ShareIntentUtil.INTENT_PATCH_EXCEPTION, parallelOTAThrowable);
            ShareIntentUtil.setIntentReturnCode(intentResult, ShareConstants.ERROR_LOAD_PATCH_VERSION_PARALLEL_DEX_OPT_EXCEPTION);
            return false;
        }
    }
    try {
        SystemClassLoaderAdder.installDexes(application, classLoader, optimizeDir, legalFiles);
    } catch (Throwable e) {
        Log.e(TAG, "install dexes failed");
        //            e.printStackTrace();
        intentResult.putExtra(ShareIntentUtil.INTENT_PATCH_EXCEPTION, e);
        ShareIntentUtil.setIntentReturnCode(intentResult, ShareConstants.ERROR_LOAD_PATCH_VERSION_DEX_LOAD_EXCEPTION);
        return false;
    }
    return true;
}
Also used : ArrayList(java.util.ArrayList) PathClassLoader(dalvik.system.PathClassLoader) File(java.io.File) ShareDexDiffPatchInfo(com.tencent.tinker.loader.shareutil.ShareDexDiffPatchInfo) TargetApi(android.annotation.TargetApi)

Example 27 with TargetApi

use of android.annotation.TargetApi in project ExpandTextView by mugku.

the class ExpandableTextView method applyAlphaAnimation.

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private static void applyAlphaAnimation(View view, float alpha) {
    if (isPostHoneycomb()) {
        view.setAlpha(alpha);
    } else {
        AlphaAnimation alphaAnimation = new AlphaAnimation(alpha, alpha);
        // make it instant
        alphaAnimation.setDuration(0);
        alphaAnimation.setFillAfter(true);
        view.startAnimation(alphaAnimation);
    }
}
Also used : AlphaAnimation(android.view.animation.AlphaAnimation) TargetApi(android.annotation.TargetApi)

Example 28 with TargetApi

use of android.annotation.TargetApi in project cw-omnibus by commonsguy.

the class ConsumerFragment method open.

@TargetApi(Build.VERSION_CODES.KITKAT)
private void open() {
    Intent i = new Intent().setType("*/*").setAction(Intent.ACTION_OPEN_DOCUMENT).addCategory(Intent.CATEGORY_OPENABLE);
    startActivityForResult(i, REQUEST_OPEN);
}
Also used : Intent(android.content.Intent) TargetApi(android.annotation.TargetApi)

Example 29 with TargetApi

use of android.annotation.TargetApi in project UltimateAndroid by cymcsg.

the class DynamicGridModification method animateBounds.

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private void animateBounds(final View mobileView) {
    TypeEvaluator<Rect> sBoundEvaluator = new TypeEvaluator<Rect>() {

        public Rect evaluate(float fraction, Rect startValue, Rect endValue) {
            return new Rect(interpolate(startValue.left, endValue.left, fraction), interpolate(startValue.top, endValue.top, fraction), interpolate(startValue.right, endValue.right, fraction), interpolate(startValue.bottom, endValue.bottom, fraction));
        }

        public int interpolate(int start, int end, float fraction) {
            return (int) (start + fraction * (end - start));
        }
    };
    ObjectAnimator hoverViewAnimator = ObjectAnimator.ofObject(mHoverCell, "bounds", sBoundEvaluator, mHoverCellCurrentBounds);
    hoverViewAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            invalidate();
        }
    });
    hoverViewAnimator.addListener(new AnimatorListenerAdapter() {

        @Override
        public void onAnimationStart(Animator animation) {
            mHoverAnimation = true;
            updateEnableState();
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            mHoverAnimation = false;
            updateEnableState();
            reset(mobileView);
        }
    });
    hoverViewAnimator.start();
}
Also used : Rect(android.graphics.Rect) Animator(android.animation.Animator) ObjectAnimator(android.animation.ObjectAnimator) ValueAnimator(android.animation.ValueAnimator) TypeEvaluator(android.animation.TypeEvaluator) ObjectAnimator(android.animation.ObjectAnimator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) ValueAnimator(android.animation.ValueAnimator) TargetApi(android.annotation.TargetApi)

Example 30 with TargetApi

use of android.annotation.TargetApi in project plaid by nickbutcher.

the class ShortcutHelper method reportPostUsed.

@TargetApi(Build.VERSION_CODES.N_MR1)
public static void reportPostUsed(@NonNull Context context) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N_MR1)
        return;
    ShortcutManager shortcutManager = context.getSystemService(ShortcutManager.class);
    shortcutManager.reportShortcutUsed(POST_SHORTCUT_ID);
}
Also used : ShortcutManager(android.content.pm.ShortcutManager) TargetApi(android.annotation.TargetApi)

Aggregations

TargetApi (android.annotation.TargetApi)1367 Intent (android.content.Intent)153 View (android.view.View)148 Test (org.junit.Test)119 SuppressLint (android.annotation.SuppressLint)115 Uri (android.net.Uri)70 ArrayList (java.util.ArrayList)68 Animator (android.animation.Animator)67 Point (android.graphics.Point)64 Window (android.view.Window)56 TextView (android.widget.TextView)56 IOException (java.io.IOException)56 ViewGroup (android.view.ViewGroup)54 Matchers.anyString (org.mockito.Matchers.anyString)53 SharedPreferences (android.content.SharedPreferences)44 File (java.io.File)44 Field (java.lang.reflect.Field)44 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)43 Bitmap (android.graphics.Bitmap)43 ImageView (android.widget.ImageView)40