use of android.support.annotation.RequiresApi in project mapbox-plugins-android by mapbox.
the class OfflineDownloadService method setupNotificationChannel.
@RequiresApi(api = Build.VERSION_CODES.O)
private void setupNotificationChannel() {
NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
NotificationChannel channel = new NotificationChannel(OfflineConstants.NOTIFICATION_CHANNEL, "Offline", NotificationManager.IMPORTANCE_DEFAULT);
channel.setLightColor(Color.GREEN);
channel.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
manager.createNotificationChannel(channel);
}
use of android.support.annotation.RequiresApi in project MusicLake by caiyonglong.
the class PlayFragment method initViews.
@RequiresApi(api = Build.VERSION_CODES.M)
@Override
public void initViews() {
// 初始化控件
topContainer = rootView.findViewById(R.id.top_container);
mSlidingUpPaneLayout = (SlidingUpPanelLayout) rootView.getParent().getParent();
// 初始化viewpager
if (mViewPager != null) {
setupViewPager(mViewPager);
mViewPager.setPageTransformer(false, new DepthPageTransformer());
mViewPager.setOffscreenPageLimit(1);
mViewPager.setCurrentItem(0);
}
}
use of android.support.annotation.RequiresApi in project MusicLake by caiyonglong.
the class MusicPlayerService method onDestroy.
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR2)
@Override
public void onDestroy() {
super.onDestroy();
// Remove any sound effects
final Intent audioEffectsIntent = new Intent(AudioEffect.ACTION_CLOSE_AUDIO_EFFECT_CONTROL_SESSION);
audioEffectsIntent.putExtra(AudioEffect.EXTRA_AUDIO_SESSION, getAudioSessionId());
audioEffectsIntent.putExtra(AudioEffect.EXTRA_PACKAGE_NAME, getPackageName());
sendBroadcast(audioEffectsIntent);
savePlayQueue(true);
// 释放mPlayer
if (mPlayer != null) {
mPlayer.stop();
mPlayer.release();
mPlayer = null;
}
// 释放Handler资源
if (mHandler != null) {
mHandler.removeCallbacksAndMessages(null);
mHandler = null;
}
// 释放工作线程资源
if (mWorkThread != null && mWorkThread.isAlive()) {
mWorkThread.quitSafely();
mWorkThread.interrupt();
mWorkThread = null;
}
audioAndFocusManager.abandonAudioFocus();
cancelNotification();
// 注销广播
unregisterReceiver(mServiceReceiver);
unregisterReceiver(mHeadsetReceiver);
unregisterReceiver(mHeadsetPlugInReceiver);
if (mWakeLock.isHeld())
mWakeLock.release();
}
use of android.support.annotation.RequiresApi in project grafika by google.
the class ScreenRecordActivity method onCreate.
@TargetApi(Build.VERSION_CODES.M)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
new AlertDialog.Builder(this).setTitle("Error").setMessage("This activity only works on Marshmallow or later.").setNeutralButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
ScreenRecordActivity.this.finish();
}
}).show();
return;
}
Button toggleRecording = findViewById(R.id.screen_record_button);
toggleRecording.setOnClickListener(new View.OnClickListener() {
@RequiresApi(api = Build.VERSION_CODES.M)
@Override
public void onClick(View v) {
if (v.getId() == R.id.screen_record_button) {
if (muxerStarted) {
stopRecording();
((Button) findViewById(R.id.screen_record_button)).setText(R.string.toggleRecordingOn);
} else {
Intent permissionIntent = mediaProjectionManager.createScreenCaptureIntent();
startActivityForResult(permissionIntent, REQUEST_CODE_CAPTURE_PERM);
findViewById(R.id.screen_record_button).setEnabled(false);
}
}
}
});
mediaProjectionManager = (MediaProjectionManager) getSystemService(android.content.Context.MEDIA_PROJECTION_SERVICE);
encoderCallback = new MediaCodec.Callback() {
@Override
public void onInputBufferAvailable(@NonNull MediaCodec codec, int index) {
Log.d(TAG, "Input Buffer Avail");
}
@Override
public void onOutputBufferAvailable(@NonNull MediaCodec codec, int index, @NonNull MediaCodec.BufferInfo info) {
ByteBuffer encodedData = videoEncoder.getOutputBuffer(index);
if (encodedData == null) {
throw new RuntimeException("couldn't fetch buffer at index " + index);
}
if ((info.flags & MediaCodec.BUFFER_FLAG_CODEC_CONFIG) != 0) {
info.size = 0;
}
if (info.size != 0) {
if (muxerStarted) {
encodedData.position(info.offset);
encodedData.limit(info.offset + info.size);
muxer.writeSampleData(trackIndex, encodedData, info);
}
}
videoEncoder.releaseOutputBuffer(index, false);
}
@Override
public void onError(@NonNull MediaCodec codec, @NonNull MediaCodec.CodecException e) {
Log.e(TAG, "MediaCodec " + codec.getName() + " onError:", e);
}
@Override
public void onOutputFormatChanged(@NonNull MediaCodec codec, @NonNull MediaFormat format) {
Log.d(TAG, "Output Format changed");
if (trackIndex >= 0) {
throw new RuntimeException("format changed twice");
}
trackIndex = muxer.addTrack(videoEncoder.getOutputFormat());
if (!muxerStarted && trackIndex >= 0) {
muxer.start();
muxerStarted = true;
}
}
};
}
use of android.support.annotation.RequiresApi in project grafika by google.
the class ScreenRecordActivity method startRecording.
@RequiresApi(api = Build.VERSION_CODES.M)
private void startRecording() {
DisplayManager dm = (DisplayManager) getSystemService(Context.DISPLAY_SERVICE);
Display defaultDisplay;
if (dm != null) {
defaultDisplay = dm.getDisplay(Display.DEFAULT_DISPLAY);
} else {
throw new IllegalStateException("Cannot display manager?!?");
}
if (defaultDisplay == null) {
throw new RuntimeException("No display found.");
}
// Get the display size and density.
DisplayMetrics metrics = getResources().getDisplayMetrics();
int screenWidth = metrics.widthPixels;
int screenHeight = metrics.heightPixels;
int screenDensity = metrics.densityDpi;
prepareVideoEncoder(screenWidth, screenHeight);
try {
File outputFile = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES) + "/grafika", "Screen-record-" + Long.toHexString(System.currentTimeMillis()) + ".mp4");
if (!outputFile.getParentFile().exists()) {
outputFile.getParentFile().mkdirs();
}
muxer = new MediaMuxer(outputFile.getCanonicalPath(), MediaMuxer.OutputFormat.MUXER_OUTPUT_MPEG_4);
} catch (IOException ioe) {
throw new RuntimeException("MediaMuxer creation failed", ioe);
}
// Start the video input.
mediaProjection.createVirtualDisplay("Recording Display", screenWidth, screenHeight, screenDensity, DisplayManager.VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR, /* flags */
inputSurface, null, /* callback */
null);
}
Aggregations