Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance ControlLayout Functionality #6459

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,26 @@ public class ControlLayout extends FrameLayout {
private ControlHandleView mHandleView;
private ControlButtonMenuListener mMenuListener;
public ActionRow mActionRow = null;
private HideLayoutsOnRecord hideLayoutsOnRecord;
public String mLayoutFileName;

/*
* added init(ctx); for hiding control layouts on recording or screenshot not for all devices!!
*/

public ControlLayout(Context ctx) {
super(ctx);
init(ctx);
}

public ControlLayout(Context ctx, AttributeSet attrs) {
super(ctx, attrs);
init(ctx);
}


/*
* added init(ctx); for hiding control layouts on recording or screenshot not for all devices!!
*/

public void loadLayout(String jsonPath) throws IOException, JsonSyntaxException {
CustomControls layout = LayoutConverter.loadAndConvertIfNecessary(jsonPath);
if(layout != null) {
Expand Down Expand Up @@ -213,7 +222,26 @@ private void addJoystickView(ControlJoystickData data){
addView(view);

}


/*
* hideonrecord
*/

private void init(Context ctx) {
hideLayoutsOnRecord = new HideLayoutsOnRecord(this);
}

@Override
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
if (hideLayoutsOnRecord != null) {
hideLayoutsOnRecord.unregisterReceiver(getContext());
}
}

/*
* hideonrecord
*/

private void removeAllButtons() {
for(ControlInterface button : getButtonChildren()){
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package net.kdt.pojavlaunch.customcontrols;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Build;
import android.view.View;

public class HideLayoutsOnRecord {

private ControlLayout controlLayout;

public HideLayoutsOnRecord(ControlLayout controlLayout) {
this.controlLayout = controlLayout;
registerReceiver(controlLayout.getContext());
}

private void registerReceiver(Context context) {
IntentFilter filter = new IntentFilter();
filter.addAction("android.media.RECORD_SOUND");
filter.addAction("android.media.SCREEN_RECORDING");
context.registerReceiver(recordingReceiver, filter);
}

private BroadcastReceiver recordingReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (action != null) {
switch (action) {
case "android.media.RECORD_SOUND":
case "android.media.SCREEN_RECORDING":
// Hide the ControlLayout
hideControlLayout();
break;
}
}
}
};

private void hideControlLayout() {
if (controlLayout.getVisibility() == View.VISIBLE) {
controlLayout.setVisibility(View.GONE);
}
}

public void unregisterReceiver(Context context) {
context.unregisterReceiver(recordingReceiver);
}
}