當前位置: 首頁>>代碼示例>>Java>>正文


Java ConditionVariable類代碼示例

本文整理匯總了Java中android.os.ConditionVariable的典型用法代碼示例。如果您正苦於以下問題:Java ConditionVariable類的具體用法?Java ConditionVariable怎麽用?Java ConditionVariable使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ConditionVariable類屬於android.os包,在下文中一共展示了ConditionVariable類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: AudioTrack

import android.os.ConditionVariable; //導入依賴的package包/類
/**
 * Creates an audio track using the specified audio capabilities and stream type.
 *
 * @param audioCapabilities The current audio playback capabilities.
 * @param streamType The type of audio stream for the underlying {@link android.media.AudioTrack}.
 */
public AudioTrack(AudioCapabilities audioCapabilities, int streamType) {
  this.audioCapabilities = audioCapabilities;
  this.streamType = streamType;
  releasingConditionVariable = new ConditionVariable(true);
  if (Util.SDK_INT >= 18) {
    try {
      getLatencyMethod =
          android.media.AudioTrack.class.getMethod("getLatency", (Class<?>[]) null);
    } catch (NoSuchMethodException e) {
      // There's no guarantee this method exists. Do nothing.
    }
  }
  if (Util.SDK_INT >= 23) {
    audioTrackUtil = new AudioTrackUtilV23();
  } else if (Util.SDK_INT >= 19) {
    audioTrackUtil = new AudioTrackUtilV19();
  } else {
    audioTrackUtil = new AudioTrackUtil();
  }
  playheadOffsets = new long[MAX_PLAYHEAD_OFFSET_COUNT];
  volume = 1.0f;
  startMediaTimeState = START_NOT_SET;
}
 
開發者ID:MLNO,項目名稱:airgram,代碼行數:30,代碼來源:AudioTrack.java

示例2: SimpleCache

import android.os.ConditionVariable; //導入依賴的package包/類
/**
 * Constructs the cache. The cache will delete any unrecognized files from the directory. Hence
 * the directory cannot be used to store other files.
 *
 * @param cacheDir A dedicated cache directory.
 */
public SimpleCache(File cacheDir, CacheEvictor evictor) {
  this.cacheDir = cacheDir;
  this.evictor = evictor;
  this.lockedSpans = new HashMap<>();
  this.cachedSpans = new HashMap<>();
  this.listeners = new HashMap<>();
  // Start cache initialization.
  final ConditionVariable conditionVariable = new ConditionVariable();
  new Thread("SimpleCache.initialize()") {
    @Override
    public void run() {
      synchronized (SimpleCache.this) {
        conditionVariable.open();
        initialize();
      }
    }
  }.start();
  conditionVariable.block();
}
 
開發者ID:MLNO,項目名稱:airgram,代碼行數:26,代碼來源:SimpleCache.java

示例3: testInitTwoEnginesSimultaneously

import android.os.ConditionVariable; //導入依賴的package包/類
@SmallTest
@Feature({"Cronet"})
public void testInitTwoEnginesSimultaneously() throws Exception {
    final CronetTestFramework testFramework = startCronetTestFrameworkAndSkipLibraryInit();

    // Threads will block on runBlocker to ensure simultaneous execution.
    ConditionVariable runBlocker = new ConditionVariable(false);
    RequestThread thread1 = new RequestThread(testFramework, mUrl, runBlocker);
    RequestThread thread2 = new RequestThread(testFramework, mUrl404, runBlocker);

    thread1.start();
    thread2.start();
    runBlocker.open();
    thread1.join();
    thread2.join();
    assertEquals(200, thread1.mCallback.mResponseInfo.getHttpStatusCode());
    assertEquals(404, thread2.mCallback.mResponseInfo.getHttpStatusCode());
}
 
開發者ID:lizhangqu,項目名稱:chromium-net-for-android,代碼行數:19,代碼來源:CronetUrlRequestContextTest.java

示例4: testInitTwoEnginesInSequence

import android.os.ConditionVariable; //導入依賴的package包/類
@SmallTest
@Feature({"Cronet"})
public void testInitTwoEnginesInSequence() throws Exception {
    final CronetTestFramework testFramework = startCronetTestFrameworkAndSkipLibraryInit();

    ConditionVariable runBlocker = new ConditionVariable(true);
    RequestThread thread1 = new RequestThread(testFramework, mUrl, runBlocker);
    RequestThread thread2 = new RequestThread(testFramework, mUrl404, runBlocker);

    thread1.start();
    thread1.join();
    thread2.start();
    thread2.join();
    assertEquals(200, thread1.mCallback.mResponseInfo.getHttpStatusCode());
    assertEquals(404, thread2.mCallback.mResponseInfo.getHttpStatusCode());
}
 
開發者ID:lizhangqu,項目名稱:chromium-net-for-android,代碼行數:17,代碼來源:CronetUrlRequestContextTest.java

示例5: testThreadedStartup

import android.os.ConditionVariable; //導入依賴的package包/類
@SmallTest
@Feature({"Cronet"})
public void testThreadedStartup() throws Exception {
    final ConditionVariable otherThreadDone = new ConditionVariable();
    final ConditionVariable uiThreadDone = new ConditionVariable();
    new Handler(Looper.getMainLooper()).post(new Runnable() {
        public void run() {
            final CronetEngine.Builder builder =
                    new CronetEngine.Builder(getContext()).setLibraryName("cronet_tests");
            new Thread() {
                public void run() {
                    CronetEngine cronetEngine = builder.build();
                    otherThreadDone.open();
                    cronetEngine.shutdown();
                }
            }.start();
            otherThreadDone.block();
            builder.build().shutdown();
            uiThreadDone.open();
        }
    });
    assertTrue(uiThreadDone.block(1000));
}
 
開發者ID:lizhangqu,項目名稱:chromium-net-for-android,代碼行數:24,代碼來源:CronetUrlRequestContextTest.java

示例6: SimpleCache

import android.os.ConditionVariable; //導入依賴的package包/類
/**
 * Constructs the cache. The cache will delete any unrecognized files from the directory. Hence
 * the directory cannot be used to store other files.
 *
 * @param cacheDir A dedicated cache directory.
 * @param evictor The evictor to be used.
 * @param secretKey If not null, cache keys will be stored encrypted on filesystem using AES/CBC.
 *     The key must be 16 bytes long.
 */
public SimpleCache(File cacheDir, CacheEvictor evictor, byte[] secretKey) {
  this.cacheDir = cacheDir;
  this.evictor = evictor;
  this.lockedSpans = new HashMap<>();
  this.index = new CachedContentIndex(cacheDir, secretKey);
  this.listeners = new HashMap<>();
  // Start cache initialization.
  final ConditionVariable conditionVariable = new ConditionVariable();
  new Thread("SimpleCache.initialize()") {
    @Override
    public void run() {
      synchronized (SimpleCache.this) {
        conditionVariable.open();
        try {
          initialize();
        } catch (CacheException e) {
          initializationException = e;
        }
        SimpleCache.this.evictor.onCacheInitialized();
      }
    }
  }.start();
  conditionVariable.block();
}
 
開發者ID:sanjaysingh1990,項目名稱:Exoplayer2Radio,代碼行數:34,代碼來源:SimpleCache.java

示例7: ChannelScanTask

import android.os.ConditionVariable; //導入依賴的package包/類
public ChannelScanTask(int channelMapId) {
    mActivity = getActivity();
    mChannelMapId = channelMapId;
    if (FAKE_MODE) {
        mScanTsStreamer = new FakeTsStreamer(this);
    } else {
        TunerHal hal = TunerHal.createInstance(mActivity.getApplicationContext());
        if (hal == null) {
            throw new RuntimeException("Failed to open a DVB device");
        }
        mScanTsStreamer = new TunerTsStreamer(hal, this);
    }
    mFileTsStreamer = SCAN_LOCAL_STREAMS ? new FileTsStreamer(this) : null;
    mConditionStopped = new ConditionVariable();
    mChannelDataManager.setChannelScanListener(this, new Handler());
}
 
開發者ID:trevd,項目名稱:android_packages_apps_tv,代碼行數:17,代碼來源:ScanFragment.java

示例8: writeSample

import android.os.ConditionVariable; //導入依賴的package包/類
@Override
public void writeSample(int index, SampleHolder sample,
        ConditionVariable conditionVariable) throws IOException {
    sample.data.position(0).limit(sample.size);
    SampleHolder sampleToQueue = mSamplePool.acquireSample(sample.size);
    sampleToQueue.size = sample.size;
    sampleToQueue.clearData();
    sampleToQueue.data.put(sample.data);
    sampleToQueue.timeUs = sample.timeUs;
    sampleToQueue.flags = sample.flags;

    synchronized (this) {
        if (mPlayingSampleQueues[index] != null) {
            mPlayingSampleQueues[index].queueSample(sampleToQueue);
        }
    }
}
 
開發者ID:trevd,項目名稱:android_packages_apps_tv,代碼行數:18,代碼來源:SimpleSampleBuffer.java

示例9: S3WholeBucketIterator

import android.os.ConditionVariable; //導入依賴的package包/類
/**
 * Constructs this iterator.
 * @param s3Client the S3 client.
 * @param bucketName the S3 bucket name.
 * @param s3ContentPrefix the portion of the s3 object prefix that should be omitted from the relative path
 *                        of the S3ContentSummary objects this iterator returns.
 * @param prefix the s3 object prefix; may be null.
 * @param delimiter the s3 object delimiter; may be null.
 * @param includeDirectories whether to include directories (common prefixes)
 * @param errorHandler an error handler.
 */
public S3WholeBucketIterator(final AmazonS3 s3Client, final String bucketName, final String s3ContentPrefix,
                             final String prefix, final String delimiter, final boolean includeDirectories,
                             final S3ListErrorHandler errorHandler) {
    this.s3Client = s3Client;
    this.bucketName = bucketName;
    this.errorHandler = errorHandler;
    this.s3ContentPrefix = s3ContentPrefix;
    this.prefix = prefix;
    this.delimiter = delimiter;
    this.includeDirectories = includeDirectories;
    summaries = new ConcurrentLinkedQueue<>();
    summaryCount = new AtomicInteger();
    summaryCount.set(0);
    waitingForObjects = new ConditionVariable();
    waitingForReader = new ConditionVariable(true);
    areListingObjects = true;

    // Start the background thread to begin listing objects.
    listingThread = new Thread(this);
    listingThread.start();
}
 
開發者ID:jtran064,項目名稱:PlatePicks-Android,代碼行數:33,代碼來源:S3WholeBucketIterator.java

示例10: AudioTrack

import android.os.ConditionVariable; //導入依賴的package包/類
public AudioTrack() {
  releasingConditionVariable = new ConditionVariable(true);
  if (Util.SDK_INT >= 18) {
    try {
      getLatencyMethod =
          android.media.AudioTrack.class.getMethod("getLatency", (Class<?>[]) null);
    } catch (NoSuchMethodException e) {
      // There's no guarantee this method exists. Do nothing.
    }
  }
  if (Util.SDK_INT >= 19) {
    audioTrackUtil = new AudioTrackUtilV19();
  } else {
    audioTrackUtil = new AudioTrackUtil();
  }
  playheadOffsets = new long[MAX_PLAYHEAD_OFFSET_COUNT];
  volume = 1.0f;
  startMediaTimeState = START_NOT_SET;
}
 
開發者ID:XueyanLiu,項目名稱:miku,代碼行數:20,代碼來源:AudioTrack.java

示例11: SimpleCache

import android.os.ConditionVariable; //導入依賴的package包/類
/**
 * Constructs the cache. The cache will delete any unrecognized files from the directory. Hence
 * the directory cannot be used to store other files.
 *
 * @param cacheDir A dedicated cache directory.
 */
public SimpleCache(File cacheDir, CacheEvictor evictor) {
  this.cacheDir = cacheDir;
  this.evictor = evictor;
  this.lockedSpans = new HashMap<>();
  this.cachedSpans = new HashMap<>();
  this.listeners = new HashMap<>();
  // Start cache initialization.
  final ConditionVariable conditionVariable = new ConditionVariable();
  new Thread() {
    @Override
    public void run() {
      synchronized (SimpleCache.this) {
        conditionVariable.open();
        initialize();
      }
    }
  }.start();
  conditionVariable.block();
}
 
開發者ID:XueyanLiu,項目名稱:miku,代碼行數:26,代碼來源:SimpleCache.java

示例12: execute

import android.os.ConditionVariable; //導入依賴的package包/類
@Override
public InitializeState execute() {
	DeviceLog.error("Unity Ads init: network error, waiting for connection events");

	_conditionVariable = new ConditionVariable();
	ConnectivityMonitor.addListener(this);

	if (_conditionVariable.block(10000L * 60L)) {
		ConnectivityMonitor.removeListener(this);
		return _erroredState;
	}
	else {
		ConnectivityMonitor.removeListener(this);
		return new InitializeStateError("network error", new Exception("No connected events within the timeout!"));
	}
}
 
開發者ID:Unity-Technologies,項目名稱:unity-ads-android,代碼行數:17,代碼來源:InitializeThread.java

示例13: testSetActivity

import android.os.ConditionVariable; //導入依賴的package包/類
@Test
public void testSetActivity () throws InterruptedException {
	final ConditionVariable cv = new ConditionVariable();

	Handler handler = new Handler(Looper.getMainLooper());
	handler.post(new Runnable() {
		@Override
		public void run() {
			MockActivity act = new MockActivity();
			ClientProperties.setActivity(act);
			cv.open();
		}
	});

	boolean success = cv.block(10000);
	assertTrue("ConditionVariable was not opened!", success);
	assertNotNull("Activity should not be null after setting it", ClientProperties.getActivity());
}
 
開發者ID:Unity-Technologies,項目名稱:unity-ads-android,代碼行數:19,代碼來源:ClientPropertiesTest.java

示例14: testSetConfiguration

import android.os.ConditionVariable; //導入依賴的package包/類
@Test
public void testSetConfiguration () throws Exception {
	WebViewApp.setCurrentApp(null);
	final ConditionVariable cv = new ConditionVariable();

	Handler handler = new Handler(Looper.getMainLooper());
	handler.post(new Runnable() {
		@Override
		public void run() {
			WebViewApp.setCurrentApp(new WebViewApp());
			WebViewApp.getCurrentApp().setWebView(new MockWebView(InstrumentationRegistry.getContext()));
			WebViewApp.getCurrentApp().setWebAppLoaded(true);
			WebViewApp.getCurrentApp().setWebAppInitialized(true);
			cv.open();
		}
	});

	boolean success = cv.block(10000);
	assertTrue("ConditionVariable was not opened successfully", success);

	final Configuration conf = new Configuration(TestUtilities.getTestServerAddress());
	WebViewApp.getCurrentApp().setConfiguration(conf);

	assertNotNull("Current WebApp configuration should not be null", WebViewApp.getCurrentApp().getConfiguration());
	assertEquals("Local configuration and current WebApp configuration should be the same object", conf, WebViewApp.getCurrentApp().getConfiguration());
}
 
開發者ID:Unity-Technologies,項目名稱:unity-ads-android,代碼行數:27,代碼來源:WebViewAppTest.java

示例15: testSetWebAppLoaded

import android.os.ConditionVariable; //導入依賴的package包/類
@Test
public void testSetWebAppLoaded () throws Exception {
	WebViewApp.setCurrentApp(null);
	final ConditionVariable cv = new ConditionVariable();

	Handler handler = new Handler(Looper.getMainLooper());
	handler.post(new Runnable() {
		@Override
		public void run() {
			WebViewApp.setCurrentApp(new WebViewApp());
			WebViewApp.getCurrentApp().setWebView(new MockWebView(InstrumentationRegistry.getContext()));
			WebViewApp.getCurrentApp().setWebAppInitialized(true);
			cv.open();
		}
	});

	boolean success = cv.block(10000);
	assertTrue("ConditionVariable was not opened successfully", success);
	assertFalse("WebApp should not be loaded. It was just created", WebViewApp.getCurrentApp().isWebAppLoaded());
	WebViewApp.getCurrentApp().setWebAppLoaded(true);
	assertTrue("WebApp should now be \"loaded\". We set the status to true", WebViewApp.getCurrentApp().isWebAppLoaded());
}
 
開發者ID:Unity-Technologies,項目名稱:unity-ads-android,代碼行數:23,代碼來源:WebViewAppTest.java


注:本文中的android.os.ConditionVariable類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。