当前位置: 首页>>代码示例>>Java>>正文


Java TargetApi类代码示例

本文整理汇总了Java中android.annotation.TargetApi的典型用法代码示例。如果您正苦于以下问题:Java TargetApi类的具体用法?Java TargetApi怎么用?Java TargetApi使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


TargetApi类属于android.annotation包,在下文中一共展示了TargetApi类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getBitmapSize

import android.annotation.TargetApi; //导入依赖的package包/类
/**
 * Get the size in bytes of a bitmap in a BitmapDrawable. Note that from Android 4.4 (KitKat)
 * onward this returns the allocated memory size of the bitmap which can be larger than the
 * actual bitmap data byte count (in the case it was re-used).
 *
 * @param value
 * @return size in bytes
 */
@TargetApi(VERSION_CODES.KITKAT)
public static int getBitmapSize(BitmapDrawable value) {
    Bitmap bitmap = value.getBitmap();

    // From KitKat onward use getAllocationByteCount() as allocated bytes can potentially be
    // larger than bitmap byte count.
    if (Utils.hasKitKat()) {
        return bitmap.getAllocationByteCount();
    }

    if (Utils.hasHoneycombMR1()) {
        return bitmap.getByteCount();
    }

    // Pre HC-MR1
    return bitmap.getRowBytes() * bitmap.getHeight();
}
 
开发者ID:gavinking,项目名称:DisplayingBitmaps,代码行数:26,代码来源:ImageCache.java

示例2:

import android.annotation.TargetApi; //导入依赖的package包/类
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public static <A, B, C> void executeTask(AsyncTask<A, B, C> task, A... params ) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, params);
    }
    else {
        task.execute(params);
    }
}
 
开发者ID:ceji-longquan,项目名称:ceji_android,代码行数:10,代码来源:PlatformUtil.java

示例3: checkOp

import android.annotation.TargetApi; //导入依赖的package包/类
@TargetApi(19)
private static boolean checkOp(Context context, int op) {
    final int version = Build.VERSION.SDK_INT;
    if (version >= Build.VERSION_CODES.KITKAT) {
        AppOpsManager manager = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
        try {
            Method method = manager.getClass().getDeclaredMethod("checkOp", int.class, int.class, String.class);
            int property = (Integer) method.invoke(manager, op,
                    Binder.getCallingUid(), context.getPackageName());
            return AppOpsManager.MODE_ALLOWED == property;
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return false;
}
 
开发者ID:QMUI,项目名称:QMUI_Android,代码行数:17,代码来源:QMUIDeviceHelper.java

示例4: getEngineDefaultSaiyVoice

import android.annotation.TargetApi; //导入依赖的package包/类
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private SaiyVoice getEngineDefaultSaiyVoice() {

    final Voice voice = getDefaultVoice();

    if (voice != null) {
        final SaiyVoice saiyVoice = new SaiyVoice(voice);
        saiyVoice.setEngine(getInitialisedEngine());
        saiyVoice.setGender(saiyVoice.getName());

        if (DEBUG) {
            MyLog.i(CLS_NAME, "getEngineDefaultSaiyVoice: setting Gender: " + saiyVoice.getGender().name());
        }

        return saiyVoice;
    } else {
        if (DEBUG) {
            MyLog.i(CLS_NAME, "getEngineDefaultSaiyVoice: voice null");
        }
        return null;
    }
}
 
开发者ID:brandall76,项目名称:Saiy-PS,代码行数:23,代码来源:SaiyTextToSpeech.java

示例5: onItemClick

import android.annotation.TargetApi; //导入依赖的package包/类
@TargetApi(VERSION_CODES.JELLY_BEAN)
@Override
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
    final Intent i = new Intent(getActivity(), ImageDetailActivity.class);
    i.putExtra(ImageDetailActivity.EXTRA_IMAGE, (int) id);
    if (Utils.hasJellyBean()) {
        // makeThumbnailScaleUpAnimation() looks kind of ugly here as the loading spinner may
        // show plus the thumbnail image in GridView is cropped. so using
        // makeScaleUpAnimation() instead.
        ActivityOptions options =
                ActivityOptions.makeScaleUpAnimation(v, 0, 0, v.getWidth(), v.getHeight());
        getActivity().startActivity(i, options.toBundle());
    } else {
        startActivity(i);
    }
}
 
开发者ID:jjuiddong,项目名称:Android-Practice,代码行数:17,代码来源:ImageGridFragment.java

示例6: onClick

import android.annotation.TargetApi; //导入依赖的package包/类
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Override
public void onClick(View view) {
    switch (view.getId()) {
        case R.id.tv_setting:
            Intent intent = new Intent(this, SettingActivity.class);
            startActivityForResult(intent, SETTING_REQUEST_CODE);
            tv_setting.setVisibility(View.GONE);
            break;
        case R.id.rel_main:
            localWakeLock.isHeld();
            switchMode(MODE_SETTING_OTHER);
            break;
        case R.id.tv_time:
            switchMode(MODE_SETTING_OTHER);
            break;
    }
}
 
开发者ID:socoolby,项目名称:CoolClock,代码行数:19,代码来源:MainActivity.java

示例7: openNotify

import android.annotation.TargetApi; //导入依赖的package包/类
/** 打开通知栏消息 */
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
private void openNotify(AccessibilityEvent event)
{
	if (event.getParcelableData() == null || !(event.getParcelableData() instanceof Notification))
	{
		return;
	}
	// 将微信的通知栏消息打开
	Notification notification = (Notification) event.getParcelableData();
	PendingIntent pendingIntent = notification.contentIntent;
	try
	{
		pendingIntent.send();
	} catch (PendingIntent.CanceledException e)
	{
		e.printStackTrace();
	}
}
 
开发者ID:stytooldex,项目名称:stynico,代码行数:20,代码来源:MD5_jni.java

示例8: getSDCardInfo

import android.annotation.TargetApi; //导入依赖的package包/类
/**
 * 获取SD卡信息
 *
 * @return SDCardInfo
 */
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
public static String getSDCardInfo() {
    if (!isSDCardEnable()) return null;
    SDCardInfo sd = new SDCardInfo();
    sd.isExist = true;
    StatFs sf = new StatFs(Environment.getExternalStorageDirectory().getPath());
    sd.totalBlocks = sf.getBlockCountLong();
    sd.blockByteSize = sf.getBlockSizeLong();
    sd.availableBlocks = sf.getAvailableBlocksLong();
    sd.availableBytes = sf.getAvailableBytes();
    sd.freeBlocks = sf.getFreeBlocksLong();
    sd.freeBytes = sf.getFreeBytes();
    sd.totalBytes = sf.getTotalBytes();
    return sd.toString();
}
 
开发者ID:Wilshion,项目名称:HeadlineNews,代码行数:21,代码来源:SDCardUtils.java

示例9: manageLayer

import android.annotation.TargetApi; //导入依赖的package包/类
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private void manageLayer(View v, boolean enableHardware) {
	if (!API_11) return;
	int layerType = enableHardware ? View.LAYER_TYPE_HARDWARE : View.LAYER_TYPE_NONE;
	if (layerType != v.getLayerType())
		v.setLayerType(layerType, null);
}
 
开发者ID:SimonCherryGZ,项目名称:JewelryUI,代码行数:8,代码来源:JazzyViewPager.java

示例10: checkSinglePermission

import android.annotation.TargetApi; //导入依赖的package包/类
/**
 * 检查单个权限是否被允许,(当应用第一次安装的时候,不会有rational的值,此时返回均是denied)
 *
 * @param permission The name of the permission being checked.
 * @return PermissionUtil.PERMISSION_GRANTED / PERMISSION_DENIED / PERMISSION_RATIONAL or {@code null}
 *         if context is not instanceof Activity.
 */
@TargetApi(Build.VERSION_CODES.M)
public int checkSinglePermission(String permission) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
        return PERMISSION_GRANTED;
    }

    if (mActivity == null) {
        mActivity = getTopActivity();
    }

    if (mActivity != null) {
        if (mActivity.checkSelfPermission(permission) == PackageManager.PERMISSION_GRANTED) {
            return PERMISSION_GRANTED;
        } else {
            if (mActivity.shouldShowRequestPermissionRationale(permission)) {
                return PERMISSION_RATIONAL;
            } else {
                return PERMISSION_DENIED;
            }
        }
    } else {
        Log.e(TAG, "TopActivity not find");
        return -1;
    }
}
 
开发者ID:nanyuweiyi,项目名称:permissionUtil,代码行数:33,代码来源:PermissionUtil.java

示例11: hasNavBar

import android.annotation.TargetApi; //导入依赖的package包/类
@TargetApi(14)
private boolean hasNavBar(Context context) {
    Resources res = context.getResources();
    int resourceId = res.getIdentifier(SHOW_NAV_BAR_RES_NAME, "bool", "android");
    if (resourceId != 0) {
        boolean hasNav = res.getBoolean(resourceId);
        // check override flag (see static block)
        if ("1".equals(sNavBarOverride)) {
            hasNav = false;
        } else if ("0".equals(sNavBarOverride)) {
            hasNav = true;
        }
        return hasNav;
    } else { // fallback
        return !ViewConfiguration.get(context).hasPermanentMenuKey();
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:18,代码来源:SystemBarTintManager.java

示例12: getDisplayDimens

import android.annotation.TargetApi; //导入依赖的package包/类
@SuppressLint("ObsoleteSdkInt")
@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2)
@SuppressWarnings("deprecation")
private synchronized Point getDisplayDimens() {
    if (mDisplayDimens != null) {
        return mDisplayDimens;
    }
    Point displayDimens;
    WindowManager windowManager = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
    assert windowManager != null;
    Display display = windowManager.getDefaultDisplay();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
        displayDimens = new Point();
        display.getSize(displayDimens);
    } else {
        displayDimens = new Point(display.getWidth(), display.getHeight());
    }

    // In this we can only get 85% width and 60% height
    //displayDimens.y = (int) (displayDimens.y * 0.60f);
    //displayDimens.x = (int) (displayDimens.x * 0.85f);

    mDisplayDimens = displayDimens;
    return mDisplayDimens;
}
 
开发者ID:hsj-xiaokang,项目名称:OSchina_resources_android,代码行数:26,代码来源:ImageGalleryActivity.java

示例13: shouldOverrideUrlLoading

import android.annotation.TargetApi; //导入依赖的package包/类
@TargetApi(24)
@Override
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
	Log.d(TAG, "shouldOverrideUrlLoading() called with: request = [" + request.getUrl() + "]");
	if (pager.webviewClient != null) {
		if (pager.webviewClient.shouldOverrideUrlLoading(view, request)) {
			return true;
		}
	}

	if (handleUrlLoading(view, request.getUrl().toString())) {
		return true;
	}

	return super.shouldOverrideUrlLoading(view, request);
}
 
开发者ID:fengshihao,项目名称:WebPager,代码行数:17,代码来源:PagerWebViewClient.java

示例14: sendNotification

import android.annotation.TargetApi; //导入依赖的package包/类
/**
 *
 * @param context
 * @param title
 * @param message
 * @param isCritical
 */
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
public static void sendNotification(Context context, String title, String message, boolean isCritical) {
    Intent broadCastIntent = new Intent(context, DashboardActivity.class);
    PendingIntent pIntent = PendingIntent.getActivity(context, (int) System.currentTimeMillis(), broadCastIntent, 0);
    NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
            .setSmallIcon(R.drawable.app_icon)
            .setContentIntent(pIntent)
            .setAutoCancel(true).setContentTitle("" + title);
    if (!TextUtils.isEmpty(message)) {
        mBuilder.setContentText(message);
    }
    if (isCritical) {
        mBuilder.setVibrate(new long[]{100, 250}).setDefaults(Notification.DEFAULT_SOUND);
        mBuilder.setColor(Color.RED);
    } else {
        mBuilder.setColor(Color.GREEN);
    }
    mBuilder.setContentIntent(pIntent);
    mNotificationManager.notify(0, mBuilder.build());
}
 
开发者ID:Welloculus,项目名称:MobileAppForPatient,代码行数:29,代码来源:AppUtility.java

示例15: onInitializeAccessibilityNodeInfo

import android.annotation.TargetApi; //导入依赖的package包/类
@TargetApi(21)
@Override
public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
    super.onInitializeAccessibilityNodeInfo(info);
    info.setClassName(com.google.android.exoplayer2.ui.DefaultTimeBar.class.getCanonicalName());
    info.setContentDescription(getProgressText());
    if (duration <= 0) {
        return;
    }
    if (Util.SDK_INT >= 21) {
        info.addAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_SCROLL_FORWARD);
        info.addAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_SCROLL_BACKWARD);
    } else if (Util.SDK_INT >= 16) {
        info.addAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD);
        info.addAction(AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD);
    }
}
 
开发者ID:rubensousa,项目名称:PreviewSeekBar,代码行数:18,代码来源:CustomTimeBar.java


注:本文中的android.annotation.TargetApi类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。