Skip to content

Commit 0906dba

Browse files
committed
Added demangler and float menu
1 parent b2700bd commit 0906dba

23 files changed

+402
-201
lines changed

app/src/main/AndroidManifest.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
xmlns:tools="http://schemas.android.com/tools"
55
package="com.mcal.disassembler">
66

7-
<!--uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
8-
<uses-permission android:name="android.permission.READ_PHONE_STATE" /-->
7+
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
8+
<uses-permission android:name="android.permission.INTERNAL_SYSTEM_WINDOW "/>
99
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
1010
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
1111
<uses-permission android:name="com.android.vending.BILLING" />

app/src/main/java/com/mcal/disassembler/activities/MainActivity.java

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
import android.Manifest;
44
import android.animation.LayoutTransition;
55
import android.annotation.SuppressLint;
6+
import android.annotation.TargetApi;
67
import android.app.ProgressDialog;
78
import android.content.Intent;
89
import android.content.pm.PackageManager;
910
import android.database.Cursor;
11+
import android.net.Uri;
1012
import android.os.Build;
1113
import android.os.Bundle;
1214
import android.provider.Settings;
@@ -47,6 +49,7 @@ public class MainActivity extends AppCompatActivity implements MainView {
4749
System.loadLibrary("disassembler");
4850
}
4951

52+
public static int ACTION_MANAGE_OVERLAY_PERMISSION_REQUEST_CODE = 5469;
5053
ProgressDialog dialog;
5154
private RecyclerView recentOpened;
5255
private final ArrayList<String> paths = new ArrayList<>();
@@ -58,11 +61,12 @@ public void onCreate(Bundle savedInstanceState) {
5861
super.onCreate(savedInstanceState);
5962
setContentView(R.layout.main_activity);
6063
setupToolbar(getString(R.string.app_name));
61-
if (Build.VERSION.SDK_INT >= 23) {
64+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
6265
if (checkSelfPermission(android.Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED && checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED && checkSelfPermission(Settings.ACTION_MANAGE_OVERLAY_PERMISSION) != PackageManager.PERMISSION_GRANTED) {
6366
requestPermissions(new String[]{Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE, Settings.ACTION_MANAGE_OVERLAY_PERMISSION}, 1);
6467
}
6568
}
69+
checkPermission();
6670
new Database(this);
6771
welcomeLayout = findViewById(R.id.welcome_layout);
6872
recentOpened = findViewById(R.id.items);
@@ -204,6 +208,27 @@ public void toClassesActivity() {
204208
dismissProgressDialog();
205209
}
206210

211+
@TargetApi(Build.VERSION_CODES.M)
212+
@Override
213+
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
214+
super.onActivityResult(requestCode, resultCode, data);
215+
if (requestCode == ACTION_MANAGE_OVERLAY_PERMISSION_REQUEST_CODE) {
216+
if (!Settings.canDrawOverlays(this)) {
217+
checkPermission();
218+
}
219+
}
220+
}
221+
222+
public void checkPermission() {
223+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
224+
if (!Settings.canDrawOverlays(this)) {
225+
Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
226+
Uri.parse("package:" + getPackageName()));
227+
startActivityForResult(intent, ACTION_MANAGE_OVERLAY_PERMISSION_REQUEST_CODE);
228+
}
229+
}
230+
}
231+
207232
@Override
208233
public void onResume() {
209234
super.onResume();

app/src/main/java/com/mcal/disassembler/activities/MenuActivity.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import com.mcal.disassembler.util.FileSaver;
2626
import com.mcal.disassembler.view.CenteredToolBar;
2727
import com.mcal.disassembler.view.FloatingButton;
28+
import com.mcal.disassembler.view.FloatingMenu;
2829
import com.mcal.disassembler.widgets.SnackBar;
2930

3031
import org.jetbrains.annotations.NotNull;

app/src/main/java/com/mcal/disassembler/activities/NameDemanglerActivity.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,6 @@ public void onCreate(Bundle savedInstanceState) {
2020
super.onCreate(savedInstanceState);
2121
setContentView(R.layout.name_demangler_activity);
2222
setupToolbar(getString(R.string.app_symbols));
23-
int width = getWindowManager().getDefaultDisplay().getWidth();
24-
25-
AppCompatEditText editText1 = findViewById(R.id.namedemangleractivityEditText1);
26-
AppCompatEditText editText2 = findViewById(R.id.namedemangleractivityEditText2);
27-
28-
ViewGroup.LayoutParams params1 = editText1.getLayoutParams();
29-
params1.width = width / 2 - 1;
30-
editText1.setLayoutParams(params1);
31-
32-
ViewGroup.LayoutParams params2 = editText2.getLayoutParams();
33-
params2.width = width / 2 - 1;
34-
editText2.setLayoutParams(params2);
3523
}
3624

3725
@SuppressWarnings("ConstantConditions")

app/src/main/java/com/mcal/disassembler/util/Utils.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
package com.mcal.disassembler.util;
22

3+
import android.content.Context;
34
import android.content.res.Resources;
45
import android.util.TypedValue;
56
import android.view.View;
67

78
import org.jetbrains.annotations.NotNull;
89

910
public class Utils {
11+
public static int dp(Context context, int i) {
12+
return (int) TypedValue.applyDimension(1, (float) i, context.getResources().getDisplayMetrics());
13+
}
14+
1015
public static int dpToPx(float dp, @NotNull Resources resources) {
1116
float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, resources.getDisplayMetrics());
1217
return (int) px;

app/src/main/java/com/mcal/disassembler/view/Button.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
import android.graphics.drawable.LayerDrawable;
1212
import android.util.AttributeSet;
1313
import android.view.MotionEvent;
14-
15-
import androidx.appcompat.widget.AppCompatTextView;
14+
import android.widget.TextView;
1615

1716
import com.mcal.disassembler.R;
1817
import com.mcal.disassembler.util.Utils;
@@ -29,7 +28,7 @@ public abstract class Button extends CustomView {
2928
OnClickListener onClickListener;
3029
boolean clickAfterRipple = true;
3130
int backgroundColor = Color.parseColor("#1E88E5");
32-
AppCompatTextView textButton;
31+
TextView textButton;
3332
float x = -1, y = -1;
3433
float radius = -1;
3534

@@ -168,7 +167,6 @@ public void setBackgroundColor(int color) {
168167
rippleColor = makePressColor();
169168
} catch (Exception ex) {
170169
// Without bacground
171-
ex.printStackTrace();
172170
}
173171
}
174172

@@ -184,7 +182,7 @@ public void setTextColor(int color) {
184182
textButton.setTextColor(color);
185183
}
186184

187-
public AppCompatTextView getTextView() {
185+
public TextView getTextView() {
188186
return textButton;
189187
}
190188

@@ -195,4 +193,4 @@ public String getText() {
195193
public void setText(String text) {
196194
textButton.setText(text);
197195
}
198-
}
196+
}

app/src/main/java/com/mcal/disassembler/view/ButtonFlat.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77
import android.graphics.Typeface;
88
import android.util.AttributeSet;
99
import android.widget.RelativeLayout;
10-
11-
import androidx.appcompat.widget.AppCompatTextView;
10+
import android.widget.TextView;
1211

1312
import com.mcal.disassembler.R;
1413
import com.mcal.disassembler.util.Utils;
1514

1615
public class ButtonFlat extends Button {
17-
AppCompatTextView textButton;
16+
17+
TextView textButton;
1818

1919
public ButtonFlat(Context context, AttributeSet attrs) {
2020
super(context, attrs);
@@ -43,7 +43,7 @@ protected void setAttributes(AttributeSet attrs) {
4343
}
4444
if (text == null)
4545
text = "";
46-
textButton = new AppCompatTextView(getContext());
46+
textButton = new TextView(getContext());
4747
textButton.setText(text.toUpperCase());
4848
textButton.setTextColor(backgroundColor);
4949
textButton.setTypeface(null, Typeface.BOLD);
@@ -84,6 +84,7 @@ protected void onDraw(Canvas canvas) {
8484
}
8585
invalidate();
8686
}
87+
8788
}
8889

8990
/**
@@ -105,7 +106,7 @@ public void setBackgroundColor(int color) {
105106
}
106107

107108
@Override
108-
public AppCompatTextView getTextView() {
109+
public TextView getTextView() {
109110
return textButton;
110111
}
111112

@@ -116,4 +117,5 @@ public String getText() {
116117
public void setText(String text) {
117118
textButton.setText(text.toUpperCase());
118119
}
119-
}
120+
121+
}

app/src/main/java/com/mcal/disassembler/view/FloatingButton.java

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,42 @@
33
import android.annotation.SuppressLint;
44
import android.content.Context;
55
import android.graphics.PixelFormat;
6+
import android.os.Build;
67
import android.view.MotionEvent;
78
import android.view.View;
89
import android.view.View.OnTouchListener;
910
import android.view.WindowManager;
1011

1112
import com.mcal.disassembler.R;
13+
import com.mcal.disassembler.util.Utils;
1214

1315
public class FloatingButton {
14-
private static int xPos = 0;
15-
private static int yPos = 0;
16+
public static int xPos = 0;
17+
public static int yPos = 0;
18+
private final Context context;
19+
private final String path;
20+
public boolean isAdded = false;
21+
public WindowManager wm;
1622
public WindowManager.LayoutParams params;
17-
private WindowManager wm;
18-
private View floatView;
19-
20-
private Context context;
21-
private String path;
23+
public View floatView;
2224

2325
public FloatingButton(Context c, String p) {
2426
context = c;
2527
path = p;
2628
}
2729

2830
public void show() {
31+
int LAYOUT_FLAG;
32+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
33+
LAYOUT_FLAG = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
34+
} else {
35+
LAYOUT_FLAG = WindowManager.LayoutParams.TYPE_PHONE;
36+
}
37+
2938
floatView = new View(context);
3039
floatView.setClickable(true);
3140

32-
floatView.setBackgroundResource(R.drawable.ic_box_green);
41+
floatView.setBackgroundResource(R.mipmap.ic_launcher_round);
3342
floatView.setOnClickListener(p1 -> {
3443
FloatingMenu menu = new FloatingMenu(context, path);
3544
menu.show();
@@ -38,14 +47,14 @@ public void show() {
3847
wm = (WindowManager) context.getApplicationContext().getSystemService(Context.WINDOW_SERVICE);
3948
params = new WindowManager.LayoutParams();
4049

41-
params.type = WindowManager.LayoutParams.TYPE_SYSTEM_ALERT;
50+
params.type = LAYOUT_FLAG; // WindowManager.LayoutParams.TYPE_SYSTEM_ALERT;
4251

4352
params.format = PixelFormat.TRANSPARENT;
4453

4554
params.flags = WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
4655
| WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
47-
params.width = 50;
48-
params.height = 50;
56+
params.width = Utils.dp(context, 64);;
57+
params.height = Utils.dp(context, 64);;
4958
params.x = xPos;
5059
params.y = yPos;
5160

@@ -70,13 +79,14 @@ public boolean onTouch(View v, MotionEvent event) {
7079
wm.updateViewLayout(floatView, params);
7180
break;
7281
}
73-
xPos = params.x;
74-
yPos = params.y;
82+
FloatingButton.xPos = params.x;
83+
FloatingButton.yPos = params.y;
7584
return false;
7685
}
7786
});
7887

7988
wm.addView(floatView, params);
89+
isAdded = true;
8090
}
8191

8292
public void dismiss() {

app/src/main/java/com/mcal/disassembler/view/FloatingMenu.java

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,44 +3,55 @@
33
import android.annotation.SuppressLint;
44
import android.content.Context;
55
import android.graphics.PixelFormat;
6+
import android.os.Build;
7+
import android.util.TypedValue;
68
import android.view.MotionEvent;
79
import android.view.View;
810
import android.view.View.OnTouchListener;
911
import android.view.WindowManager;
12+
import android.widget.LinearLayout;
13+
14+
import com.mcal.disassembler.util.Utils;
1015

1116
public class FloatingMenu {
12-
private static int xPos = 0;
13-
private static int yPos = 0;
17+
public static int xPos = 0;
18+
public static int yPos = 0;
19+
private final Context context;
20+
private final String path;
21+
public boolean isAdded = false;
22+
public WindowManager wm;
1423
public WindowManager.LayoutParams params;
15-
private WindowManager wm;
16-
private FloatingMenuView floatView;
17-
18-
private Context context;
19-
private String path;
24+
public FloatingMenuView floatView;
2025

21-
FloatingMenu(Context c, String filePath) {
26+
public FloatingMenu(Context c, String filePath) {
2227
context = c;
2328
path = filePath;
2429
}
2530

2631
@SuppressLint("ClickableViewAccessibility")
2732
public void show() {
33+
int LAYOUT_FLAG;
34+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
35+
LAYOUT_FLAG = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
36+
} else {
37+
LAYOUT_FLAG = WindowManager.LayoutParams.TYPE_PHONE;
38+
}
39+
2840
wm = (WindowManager) context.getApplicationContext().getSystemService(Context.WINDOW_SERVICE);
2941
params = new WindowManager.LayoutParams();
3042

31-
32-
params.type = WindowManager.LayoutParams.TYPE_SYSTEM_ALERT;
43+
params.type = LAYOUT_FLAG; // WindowManager.LayoutParams.TYPE_SYSTEM_ALERT;
3344

3445
params.format = PixelFormat.RGBA_8888;
3546

36-
3747
params.flags = WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
38-
params.width = wm.getDefaultDisplay().getWidth() / 2;
3948
params.height = wm.getDefaultDisplay().getHeight() / 2;
49+
params.width = Utils.dp(context, 250);
50+
4051
params.x = xPos;
4152
params.y = yPos;
4253

43-
floatView = new FloatingMenuView(context, this, path, params.width);
54+
floatView = new FloatingMenuView(context, this, path, params.width, params.height);
4455
floatView.setClickable(true);
4556

4657
floatView.setOnTouchListener(new OnTouchListener() {
@@ -63,16 +74,17 @@ public boolean onTouch(View v, MotionEvent event) {
6374
wm.updateViewLayout(floatView, params);
6475
break;
6576
}
66-
xPos = params.x;
67-
yPos = params.y;
77+
FloatingMenu.xPos = params.x;
78+
FloatingMenu.yPos = params.y;
6879
return false;
6980
}
7081
});
7182

7283
wm.addView(floatView, params);
84+
isAdded = true;
7385
}
7486

7587
public void dismiss() {
7688
wm.removeView(floatView);
7789
}
78-
}
90+
}

0 commit comments

Comments
 (0)