Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 53a78807 authored by Joey's avatar Joey
Browse files

Recorder: update deprecated methods to new ones



Change-Id: I06dc78f4c7b682a4a63cdde81bcda83d49d65840
Signed-off-by: default avatarJoey <joey@lineageos.org>
parent b768a6a7
Loading
Loading
Loading
Loading
+8 −8
Original line number Diff line number Diff line
@@ -60,9 +60,9 @@ public class DialogActivity extends AppCompatActivity implements
        setContentView(R.layout.dialog_base);
        setFinishOnTouchOutside(true);

        mRootView = (LinearLayout) findViewById(R.id.dialog_root);
        TextView title = (TextView) findViewById(R.id.dialog_title);
        mContent = (FrameLayout) findViewById(R.id.dialog_content);
        mRootView = findViewById(R.id.dialog_root);
        TextView title = findViewById(R.id.dialog_title);
        mContent = findViewById(R.id.dialog_content);

        mPrefs = getSharedPreferences(Utils.PREFS, 0);
        mPrefs.registerOnSharedPreferenceChangeListener(this);
@@ -136,10 +136,10 @@ public class DialogActivity extends AppCompatActivity implements

    private void setupAsLastItem(boolean isSound) {
        View view = createContentView(R.layout.dialog_content_last_item);
        TextView description = (TextView) view.findViewById(R.id.dialog_content_last_description);
        ImageView play = (ImageView) view.findViewById(R.id.dialog_content_last_play);
        ImageView delete = (ImageView) view.findViewById(R.id.dialog_content_last_delete);
        ImageView share = (ImageView) view.findViewById(R.id.dialog_content_last_share);
        TextView description = view.findViewById(R.id.dialog_content_last_description);
        ImageView play = view.findViewById(R.id.dialog_content_last_play);
        ImageView delete = view.findViewById(R.id.dialog_content_last_delete);
        ImageView share = view.findViewById(R.id.dialog_content_last_share);

        description.setText(LastRecordHelper.getLastItemDescription(this, isSound));

@@ -169,7 +169,7 @@ public class DialogActivity extends AppCompatActivity implements

    private void setupAsSettingsScreen() {
        View view = createContentView(R.layout.dialog_content_screen_settings);
        mAudioSwitch = (Switch) view.findViewById(R.id.dialog_content_screen_settings_switch);
        mAudioSwitch = view.findViewById(R.id.dialog_content_screen_settings_switch);
        mAudioSwitch.setOnCheckedChangeListener((button, isChecked) -> {
            if (hasAudioPermission()) {
                setScreenWithAudio(isChecked);
+12 −18
Original line number Diff line number Diff line
@@ -16,7 +16,6 @@
package org.lineageos.recorder;

import android.Manifest;
import android.app.ActivityManager;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
@@ -56,7 +55,6 @@ import org.lineageos.recorder.utils.OnBoardingHelper;
import org.lineageos.recorder.utils.Utils;

import java.util.ArrayList;
import java.util.List;

public class RecorderActivity extends AppCompatActivity implements
        SharedPreferences.OnSharedPreferenceChangeListener {
@@ -110,18 +108,18 @@ public class RecorderActivity extends AppCompatActivity implements
        super.onCreate(savedInstance);
        setContentView(R.layout.activty_constraint);

        mConstraintRoot = (ConstraintLayout) findViewById(R.id.main_root);
        mConstraintRoot = findViewById(R.id.main_root);

        mScreenFab = (FloatingActionButton) findViewById(R.id.screen_fab);
        mScreenSettings = (ImageView) findViewById(R.id.screen_settings_icon);
        mScreenLast = (ImageView) findViewById(R.id.screen_last_icon);
        mScreenFab = findViewById(R.id.screen_fab);
        mScreenSettings = findViewById(R.id.screen_settings_icon);
        mScreenLast = findViewById(R.id.screen_last_icon);

        mSoundFab = (FloatingActionButton) findViewById(R.id.sound_fab);
        mSoundLast = (ImageView) findViewById(R.id.sound_last_icon);
        mSoundFab = findViewById(R.id.sound_fab);
        mSoundLast = findViewById(R.id.sound_last_icon);

        mRecordingLayout = (RelativeLayout) findViewById(R.id.main_recording);
        mRecordingText = (TextView) findViewById(R.id.main_recording_text);
        mRecordingVisualizer = (SoundVisualizer) findViewById(R.id.main_recording_visualizer);
        mRecordingLayout = findViewById(R.id.main_recording);
        mRecordingText = findViewById(R.id.main_recording_text);
        mRecordingVisualizer = findViewById(R.id.main_recording_visualizer);

        mScreenFab.setOnClickListener(v -> toggleScreenRecorder());
        mSoundFab.setOnClickListener(v -> toggleSoundRecorder());
@@ -433,14 +431,10 @@ public class RecorderActivity extends AppCompatActivity implements
    }

    private void stopOverlayService() {
        ActivityManager manager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
        List<ActivityManager.RunningServiceInfo> services =
                manager.getRunningServices(Integer.MAX_VALUE);

        // Stop overlay service if running
        services.stream().filter(info -> getPackageName().equals(info.service.getPackageName()) &&
                OverlayService.class.getName().equals(info.service.getClassName()))
                .forEach(info -> stopService(new Intent(this, OverlayService.class)));
        if (OverlayService.isRunning) {
            stopService(new Intent(this, OverlayService.class));
        }
    }

    private void updateLastItemStatus() {
+2 −2
Original line number Diff line number Diff line
@@ -90,9 +90,9 @@ abstract class EncoderDevice {

    VirtualDisplay registerVirtualDisplay(Context context) {
        assert virtualDisplay == null;
        DisplayManager dm = (DisplayManager) context.getSystemService(Context.DISPLAY_SERVICE);
        DisplayManager dm = context.getSystemService(DisplayManager.class);
        Surface surface = createDisplaySurface();
        if (surface == null)
        if (surface == null || dm == null)
            return null;
        return virtualDisplay = dm.createVirtualDisplay(ScreencastService.SCREENCASTER_NAME,
                width, height, 1,
+8 −0
Original line number Diff line number Diff line
@@ -37,6 +37,12 @@ public class OverlayService extends Service {
    public static final String EXTRA_HAS_AUDIO = "extra_audio";
    private final static int FG_ID = 123;

    /* Horrible hack to determine whether the service is running:
     * the ActivityManager.getRunningServices() method has been nuked on api 26+
     * so we're unable to properly determine if this service is currently running
     */
    public static boolean isRunning = false;

    private OverlayLayer mLayer;

    @Override
@@ -62,6 +68,7 @@ public class OverlayService extends Service {
                .build();

        startForeground(FG_ID, notification);
        isRunning = true;
        return START_NOT_STICKY;
    }

@@ -92,6 +99,7 @@ public class OverlayService extends Service {
        }

        stopForeground(true);
        isRunning = false;
        super.onDestroy();
    }
}
+11 −1
Original line number Diff line number Diff line
@@ -180,14 +180,20 @@ public class ScreencastService extends Service {
    }

    private Point getNativeResolution() {
        DisplayManager dm = (DisplayManager) getSystemService(DISPLAY_SERVICE);
        DisplayManager dm = getSystemService(DisplayManager.class);
        if (dm == null) {
            return null;
        }

        Display display = dm.getDisplay(Display.DEFAULT_DISPLAY);
        Point ret = new Point();
        try {
            display.getRealSize(ret);
        } catch (Exception e) {
            try {
                //noinspection JavaReflectionMemberAccess
                Method mGetRawH = Display.class.getMethod("getRawHeight");
                //noinspection JavaReflectionMemberAccess
                Method mGetRawW = Display.class.getMethod("getRawWidth");
                ret.x = (Integer) mGetRawW.invoke(display);
                ret.y = (Integer) mGetRawH.invoke(display);
@@ -219,6 +225,10 @@ public class ScreencastService extends Service {
    private void registerScreencaster(boolean withAudio) {
        assert mRecorder == null;
        Point size = getNativeResolution();
        if (size == null) {
            return;
        }

        mRecorder = new RecordingDevice(this, size.x, size.y, withAudio);
        VirtualDisplay vd = mRecorder.registerVirtualDisplay(this);
        if (vd == null) {
Loading