Search in sources :

Example 16 with RequiresApi

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);
}
Also used : NotificationChannel(android.app.NotificationChannel) NotificationManager(android.app.NotificationManager) RequiresApi(android.support.annotation.RequiresApi)

Example 17 with RequiresApi

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);
    }
}
Also used : DepthPageTransformer(com.cyl.musiclake.view.DepthPageTransformer) RequiresApi(android.support.annotation.RequiresApi)

Example 18 with RequiresApi

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();
}
Also used : PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) RequiresApi(android.support.annotation.RequiresApi)

Example 19 with RequiresApi

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;
            }
        }
    };
}
Also used : MediaFormat(android.media.MediaFormat) DialogInterface(android.content.DialogInterface) Intent(android.content.Intent) View(android.view.View) ByteBuffer(java.nio.ByteBuffer) Button(android.widget.Button) MediaCodec(android.media.MediaCodec) RequiresApi(android.support.annotation.RequiresApi) TargetApi(android.annotation.TargetApi)

Example 20 with RequiresApi

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);
}
Also used : DisplayManager(android.hardware.display.DisplayManager) IOException(java.io.IOException) DisplayMetrics(android.util.DisplayMetrics) File(java.io.File) MediaMuxer(android.media.MediaMuxer) Display(android.view.Display) RequiresApi(android.support.annotation.RequiresApi)

Aggregations

RequiresApi (android.support.annotation.RequiresApi)217 Intent (android.content.Intent)30 Allocation (android.renderscript.Allocation)30 NotificationChannel (android.app.NotificationChannel)27 View (android.view.View)26 Bitmap (android.graphics.Bitmap)24 Paint (android.graphics.Paint)20 Point (android.graphics.Point)20 NotificationManager (android.app.NotificationManager)17 ViewGroup (android.view.ViewGroup)15 RecyclerView (android.support.v7.widget.RecyclerView)13 Uri (android.net.Uri)12 ViewTreeObserver (android.view.ViewTreeObserver)12 WindowInsets (android.view.WindowInsets)12 SuppressLint (android.annotation.SuppressLint)11 ActionBar (android.support.v7.app.ActionBar)11 Toolbar (android.support.v7.widget.Toolbar)11 TextView (android.widget.TextView)11 IOException (java.io.IOException)10 StatFs (android.os.StatFs)9