當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。