本文整理匯總了Java中android.util.Pair.create方法的典型用法代碼示例。如果您正苦於以下問題:Java Pair.create方法的具體用法?Java Pair.create怎麽用?Java Pair.create使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.util.Pair
的用法示例。
在下文中一共展示了Pair.create方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: findSystemApk
import android.util.Pair; //導入方法依賴的package包/類
static Pair<String, Resources> findSystemApk(String action, PackageManager pm) {
final Intent intent = new Intent(action);
for (ResolveInfo info : pm.queryBroadcastReceivers(intent, 0)) {
if (info.activityInfo != null &&
(info.activityInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
final String packageName = info.activityInfo.packageName;
try {
final Resources res = pm.getResourcesForApplication(packageName);
return Pair.create(packageName, res);
} catch (NameNotFoundException e) {
e.printStackTrace();
}
}
}
return null;
}
示例2: parseEdts
import android.util.Pair; //導入方法依賴的package包/類
/**
* Parses the edts atom (defined in 14496-12 subsection 8.6.5).
*
* @param edtsAtom edts (edit box) atom to decode.
* @return Pair of edit list durations and edit list media times, or a pair of nulls if they are
* not present.
*/
private static Pair<long[], long[]> parseEdts(Atom.ContainerAtom edtsAtom) {
Atom.LeafAtom elst;
if (edtsAtom == null || (elst = edtsAtom.getLeafAtomOfType(Atom.TYPE_elst)) == null) {
return Pair.create(null, null);
}
ParsableByteArray elstData = elst.data;
elstData.setPosition(Atom.HEADER_SIZE);
int fullAtom = elstData.readInt();
int version = Atom.parseFullAtomVersion(fullAtom);
int entryCount = elstData.readUnsignedIntToInt();
long[] editListDurations = new long[entryCount];
long[] editListMediaTimes = new long[entryCount];
for (int i = 0; i < entryCount; i++) {
editListDurations[i] =
version == 1 ? elstData.readUnsignedLongToLong() : elstData.readUnsignedInt();
editListMediaTimes[i] = version == 1 ? elstData.readLong() : elstData.readInt();
int mediaRateInteger = elstData.readShort();
if (mediaRateInteger != 1) {
// The extractor does not handle dwell edits (mediaRateInteger == 0).
throw new IllegalArgumentException("Unsupported media rate.");
}
elstData.skipBytes(2);
}
return Pair.create(editListDurations, editListMediaTimes);
}
示例3: start
import android.util.Pair; //導入方法依賴的package包/類
public static void start(final GarlandViewMainActivity activity,
final String name, final String address, final String url,
final View card, final View avatar) {
Intent starter = new Intent(activity, GarlandViewDetailsActivity.class);
starter.putExtra(BUNDLE_NAME, name);
starter.putExtra(BUNDLE_INFO, address);
starter.putExtra(BUNDLE_AVATAR_URL, url);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
final Pair<View, String> p1 = Pair.create(card, activity.getString(R.string.gv_transition_card));
final Pair<View, String> p2 = Pair.create(avatar, activity.getString(R.string.gv_transition_avatar_border));
final ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(activity, p1, p2);
activity.startActivity(starter, options.toBundle());
} else {
activity.startActivity(starter);
}
}
示例4: getLicenseDurationRemainingSec
import android.util.Pair; //導入方法依賴的package包/類
/**
* Returns the remaining license and playback durations in seconds, for an offline license.
*
* @param offlineLicenseKeySetId The key set id of the license.
* @return The remaining license and playback durations, in seconds.
* @throws DrmSessionException Thrown when a DRM session error occurs.
*/
public synchronized Pair<Long, Long> getLicenseDurationRemainingSec(byte[] offlineLicenseKeySetId)
throws DrmSessionException {
Assertions.checkNotNull(offlineLicenseKeySetId);
DrmSession<T> drmSession = openBlockingKeyRequest(DefaultDrmSessionManager.MODE_QUERY,
offlineLicenseKeySetId, null);
DrmSessionException error = drmSession.getError();
Pair<Long, Long> licenseDurationRemainingSec =
WidevineUtil.getLicenseDurationRemainingSec(drmSession);
drmSessionManager.releaseSession(drmSession);
if (error != null) {
if (error.getCause() instanceof KeysExpiredException) {
return Pair.create(0L, 0L);
}
throw error;
}
return licenseDurationRemainingSec;
}
示例5: onProducerEvent
import android.util.Pair; //導入方法依賴的package包/類
@Override
public synchronized void onProducerEvent(
String requestId, String producerName, String producerEventName) {
if (FLog.isLoggable(FLog.VERBOSE)) {
Pair<String, String> mapKey = Pair.create(requestId, producerName);
Long startTime = mProducerStartTimeMap.get(mapKey);
long currentTime = getTime();
FLog.v(
TAG,
"time %d: onProducerEvent: {requestId: %s, stage: %s, eventName: %s; elapsedTime: %d ms}",
getTime(),
requestId,
producerName,
producerEventName,
getElapsedTime(startTime, currentTime));
}
}
示例6: start
import android.util.Pair; //導入方法依賴的package包/類
public static void start(Activity activity,
String url, String name, String info, String status,
View avatar, View card, View image, View list,
ArrayList<DetailsData> listData) {
Intent starter = new Intent(activity, ProfileActivity.class);
starter.putExtra(BUNDLE_NAME, name);
starter.putExtra(BUNDLE_INFO, info);
starter.putExtra(BUNDLE_STATUS, status);
starter.putExtra(BUNDLE_AVATAR_URL, url);
starter.putParcelableArrayListExtra(BUNDLE_LIST_DATA, listData);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
final Pair<View, String> p1 = Pair.create(avatar, activity.getString(R.string.transition_avatar_border));
final Pair<View, String> p2 = Pair.create(card, activity.getString(R.string.transition_card));
final Pair<View, String> p3 = Pair.create(image, activity.getString(R.string.transition_background));
final Pair<View, String> p4 = Pair.create(list, activity.getString(R.string.transition_list));
final ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(activity, p1, p2, p3, p4);
activity.startActivity(starter, options.toBundle());
} else {
activity.startActivity(starter);
}
}
示例7: onRequestStart
import android.util.Pair; //導入方法依賴的package包/類
@Override
public void onRequestStart(
ImageRequest request,
Object callerContext,
String requestId,
boolean isPrefetch) {
if (!Systrace.isTracing(Systrace.TRACE_TAG_REACT_FRESCO)) {
return;
}
StringBuilder entryName = new StringBuilder();
entryName.append("FRESCO_REQUEST_");
entryName.append(request.getSourceUri().toString().replace(':', '_'));
Pair<Integer,String> requestPair = Pair.create(mCurrentID, entryName.toString());
Systrace.beginAsyncSection(
Systrace.TRACE_TAG_REACT_FRESCO,
requestPair.second,
mCurrentID);
mRequestsID.put(requestId, requestPair);
mCurrentID++;
}
示例8: buildExecutionTimesFromXml
import android.util.Pair; //導入方法依賴的package包/類
/**
* Convenience function to read out and convert deadline and delay from xml into elapsed real
* time.
*
* @return A {@link android.util.Pair}, where the first value is the earliest elapsed runtime
* and the second is the latest elapsed runtime.
*/
private Pair<Long, Long> buildExecutionTimesFromXml(XmlPullParser parser) throws NumberFormatException {
// Pull out execution time data.
final long nowWallclock = System.currentTimeMillis();
final long nowElapsed = SystemClock.elapsedRealtime();
long earliestRunTimeElapsed = JobStatus.NO_EARLIEST_RUNTIME;
long latestRunTimeElapsed = JobStatus.NO_LATEST_RUNTIME;
String val = parser.getAttributeValue(null, "deadline");
if (val != null) {
long latestRuntimeWallclock = Long.parseLong(val);
long maxDelayElapsed = Math.max(latestRuntimeWallclock - nowWallclock, 0);
latestRunTimeElapsed = nowElapsed + maxDelayElapsed;
}
val = parser.getAttributeValue(null, "delay");
if (val != null) {
long earliestRuntimeWallclock = Long.parseLong(val);
long minDelayElapsed = Math.max(earliestRuntimeWallclock - nowWallclock, 0);
earliestRunTimeElapsed = nowElapsed + minDelayElapsed;
}
return Pair.create(earliestRunTimeElapsed, latestRunTimeElapsed);
}
示例9: parseAvcCodecPrivate
import android.util.Pair; //導入方法依賴的package包/類
/**
* Builds initialization data for a {@link MediaFormat} from H.264 (AVC) codec private data.
*
* @return The initialization data for the {@link MediaFormat}.
* @throws ParserException If the initialization data could not be built.
*/
private static Pair<List<byte[]>, Integer> parseAvcCodecPrivate(ParsableByteArray buffer)
throws ParserException {
try {
// TODO: Deduplicate with AtomParsers.parseAvcCFromParent.
buffer.setPosition(4);
int nalUnitLengthFieldLength = (buffer.readUnsignedByte() & 0x03) + 1;
if (nalUnitLengthFieldLength == 3) {
throw new ParserException();
}
List<byte[]> initializationData = new ArrayList<>();
int numSequenceParameterSets = buffer.readUnsignedByte() & 0x1F;
for (int i = 0; i < numSequenceParameterSets; i++) {
initializationData.add(NalUnitUtil.parseChildNalUnit(buffer));
}
int numPictureParameterSets = buffer.readUnsignedByte();
for (int j = 0; j < numPictureParameterSets; j++) {
initializationData.add(NalUnitUtil.parseChildNalUnit(buffer));
}
return Pair.create(initializationData, nalUnitLengthFieldLength);
} catch (ArrayIndexOutOfBoundsException e) {
throw new ParserException("Error parsing AVC codec private");
}
}
示例10: parseCipherText
import android.util.Pair; //導入方法依賴的package包/類
public static Pair<EncryptionType, String> parseCipherText(String cipherText) {
if (cipherText == null || cipherText.isEmpty()) {
return null;
}
if (cipherText.startsWith("[")) {
return Pair.create(LEGACY_TOKEN, cipherText);
}
if (cipherText.startsWith(APP_ID_KEY.prefixWithBracket)) {
return Pair.create(
APP_ID_KEY, cipherText.substring(APP_ID_KEY.prefixWithBracket.length() - 1));
}
return null;
}
示例11: parseTrex
import android.util.Pair; //導入方法依賴的package包/類
/**
* Parses a trex atom (defined in 14496-12).
*/
private static Pair<Integer, DefaultSampleValues> parseTrex(ParsableByteArray trex) {
trex.setPosition(Atom.FULL_HEADER_SIZE);
int trackId = trex.readInt();
int defaultSampleDescriptionIndex = trex.readUnsignedIntToInt() - 1;
int defaultSampleDuration = trex.readUnsignedIntToInt();
int defaultSampleSize = trex.readUnsignedIntToInt();
int defaultSampleFlags = trex.readInt();
return Pair.create(trackId, new DefaultSampleValues(defaultSampleDescriptionIndex,
defaultSampleDuration, defaultSampleSize, defaultSampleFlags));
}
示例12: getKey
import android.util.Pair; //導入方法依賴的package包/類
protected Pair<CacheKey, ImageRequest.RequestLevel> getKey(
ProducerContext producerContext) {
return Pair.create(
mCacheKeyFactory.getBitmapCacheKey(
producerContext.getImageRequest(),
producerContext.getCallerContext()),
producerContext.getLowestPermittedRequestLevel());
}
示例13: parseMdhd
import android.util.Pair; //導入方法依賴的package包/類
/**
* Parses an mdhd atom (defined in 14496-12).
*
* @param mdhd The mdhd atom to parse.
* @return A pair consisting of the media timescale defined as the number of time units that pass
* in one second, and the language code.
*/
private static Pair<Long, String> parseMdhd(ParsableByteArray mdhd) {
mdhd.setPosition(Atom.HEADER_SIZE);
int fullAtom = mdhd.readInt();
int version = Atom.parseFullAtomVersion(fullAtom);
mdhd.skipBytes(version == 0 ? 8 : 16);
long timescale = mdhd.readUnsignedInt();
mdhd.skipBytes(version == 0 ? 4 : 8);
int languageCode = mdhd.readUnsignedShort();
String language = "" + (char) (((languageCode >> 10) & 0x1F) + 0x60)
+ (char) (((languageCode >> 5) & 0x1F) + 0x60)
+ (char) (((languageCode) & 0x1F) + 0x60);
return Pair.create(timescale, language);
}
示例14: doInBackground
import android.util.Pair; //導入方法依賴的package包/類
@Override
public Pair<Integer, Boolean> doInBackground(Void...voids) {
DownloadManager manager =
(DownloadManager) mContext.getSystemService(Context.DOWNLOAD_SERVICE);
Cursor c = manager.query(new DownloadManager.Query().setFilterById(
mDownloadItem.getSystemDownloadId()));
int statusIndex = c.getColumnIndex(DownloadManager.COLUMN_STATUS);
int reasonIndex = c.getColumnIndex(DownloadManager.COLUMN_REASON);
int titleIndex = c.getColumnIndex(DownloadManager.COLUMN_TITLE);
int status = DownloadManager.STATUS_FAILED;
Boolean canResolve = false;
if (c.moveToNext()) {
status = c.getInt(statusIndex);
String title = c.getString(titleIndex);
if (mDownloadInfo == null) {
// Chrome has been killed, reconstruct a DownloadInfo.
mDownloadInfo = new DownloadInfo.Builder()
.setFileName(title)
.setDescription(c.getString(
c.getColumnIndex(DownloadManager.COLUMN_DESCRIPTION)))
.setMimeType(c.getString(
c.getColumnIndex(DownloadManager.COLUMN_MEDIA_TYPE)))
.setContentLength(Long.parseLong(c.getString(
c.getColumnIndex(DownloadManager.COLUMN_TOTAL_SIZE_BYTES))))
.build();
}
if (status == DownloadManager.STATUS_SUCCESSFUL) {
mDownloadInfo = DownloadInfo.Builder.fromDownloadInfo(mDownloadInfo)
.setFileName(title)
.build();
mDownloadItem.setDownloadInfo(mDownloadInfo);
canResolve = canResolveDownloadItem(mContext, mDownloadItem, false);
} else if (status == DownloadManager.STATUS_FAILED) {
mFailureReason = c.getInt(reasonIndex);
manager.remove(mDownloadItem.getSystemDownloadId());
}
}
c.close();
return Pair.create(status, canResolve);
}
示例15: parseCsdBuffer
import android.util.Pair; //導入方法依賴的package包/類
/**
* Parses the {@link MediaFormat} and frame duration from a csd buffer.
*
* @param csdBuffer The csd buffer.
* @return A pair consisting of the {@link MediaFormat} and the frame duration in microseconds, or
* 0 if the duration could not be determined.
*/
private static Pair<MediaFormat, Long> parseCsdBuffer(CsdBuffer csdBuffer) {
byte[] csdData = Arrays.copyOf(csdBuffer.data, csdBuffer.length);
int firstByte = csdData[4] & 0xFF;
int secondByte = csdData[5] & 0xFF;
int thirdByte = csdData[6] & 0xFF;
int width = (firstByte << 4) | (secondByte >> 4);
int height = (secondByte & 0x0F) << 8 | thirdByte;
float pixelWidthHeightRatio = 1f;
int aspectRatioCode = (csdData[7] & 0xF0) >> 4;
switch(aspectRatioCode) {
case 2:
pixelWidthHeightRatio = (4 * height) / (float) (3 * width);
break;
case 3:
pixelWidthHeightRatio = (16 * height) / (float) (9 * width);
break;
case 4:
pixelWidthHeightRatio = (121 * height) / (float) (100 * width);
break;
default:
// Do nothing.
break;
}
MediaFormat format = MediaFormat.createVideoFormat(null, MimeTypes.VIDEO_MPEG2,
MediaFormat.NO_VALUE, MediaFormat.NO_VALUE, C.UNKNOWN_TIME_US, width, height,
Collections.singletonList(csdData), MediaFormat.NO_VALUE, pixelWidthHeightRatio);
long frameDurationUs = 0;
int frameRateCodeMinusOne = (csdData[7] & 0x0F) - 1;
if (0 <= frameRateCodeMinusOne && frameRateCodeMinusOne < FRAME_RATE_VALUES.length) {
double frameRate = FRAME_RATE_VALUES[frameRateCodeMinusOne];
int sequenceExtensionPosition = csdBuffer.sequenceExtensionPosition;
int frameRateExtensionN = (csdData[sequenceExtensionPosition + 9] & 0x60) >> 5;
int frameRateExtensionD = (csdData[sequenceExtensionPosition + 9] & 0x1F);
if (frameRateExtensionN != frameRateExtensionD) {
frameRate *= (frameRateExtensionN + 1d) / (frameRateExtensionD + 1);
}
frameDurationUs = (long) (C.MICROS_PER_SECOND / frameRate);
}
return Pair.create(format, frameDurationUs);
}