Commit 53a78807 authored by Joey's avatar Joey

Recorder: update deprecated methods to new ones

Change-Id: I06dc78f4c7b682a4a63cdde81bcda83d49d65840
Signed-off-by: default avatarJoey <joey@lineageos.org>
parent b768a6a7
......@@ -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);
......
......@@ -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() {
......
......@@ -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,
......
......@@ -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();
}
}
......@@ -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) {
......
......@@ -38,10 +38,9 @@ public class OverlayLayer extends View {
public OverlayLayer(Context context) {
super(context);
LayoutInflater inflater = (LayoutInflater)
context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
LayoutInflater inflater = context.getSystemService(LayoutInflater.class);
mLayout = new FrameLayout(context);
mManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
mManager = context.getSystemService(WindowManager.class);
mParams = new WindowManager.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT,
......@@ -50,11 +49,15 @@ public class OverlayLayer extends View {
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,
PixelFormat.TRANSLUCENT);
mParams.gravity = Gravity.START;
mManager.addView(mLayout, mParams);
inflater.inflate(R.layout.window_screen_recorder_overlay, mLayout);
if (mManager != null) {
mManager.addView(mLayout, mParams);
}
if (inflater != null) {
inflater.inflate(R.layout.window_screen_recorder_overlay, mLayout);
}
mButton = (ImageButton) mLayout.findViewById(R.id.overlay_button);
DragView drag = (DragView) mLayout.findViewById(R.id.overlay_drag);
mButton = mLayout.findViewById(R.id.overlay_button);
DragView drag = mLayout.findViewById(R.id.overlay_drag);
drag.setOnTouchListener(new OnTouchListener() {
private int origX;
private int origY;
......@@ -76,7 +79,9 @@ public class OverlayLayer extends View {
case MotionEvent.ACTION_MOVE:
mParams.x = origX + x - touchX;
mParams.y = origY + y - touchY;
mManager.updateViewLayout(mLayout, mParams);
if (mManager != null) {
mManager.updateViewLayout(mLayout, mParams);
}
break;
case MotionEvent.ACTION_UP:
v.performClick();
......
......@@ -51,8 +51,11 @@ public class LastRecordHelper {
//noinspection ResultOfMethodCallIgnored
record.delete();
}
NotificationManager nm = (NotificationManager)
context.getSystemService(Context.NOTIFICATION_SERVICE);
NotificationManager nm = context.getSystemService(NotificationManager.class);
if (nm == null) {
return;
}
if (isSound) {
nm.cancel(SoundRecorderService.NOTIFICATION_ID);
} else {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment