Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.mycompany.application;
- import android.app.Activity;
- import android.content.Context;
- import android.graphics.PixelFormat;
- import android.graphics.Point;
- import android.os.Build;
- import android.os.Bundle;
- import android.os.Handler;
- import android.view.Gravity;
- import android.view.MotionEvent;
- import android.view.View;
- import android.view.ViewTreeObserver;
- import android.view.Window;
- import android.widget.LinearLayout;
- import android.view.WindowManager;
- import com.mycompany.application.GLES3JNIView;
- import java.io.InputStream;
- import android.view.WindowManager.LayoutParams;
- import android.view.Display;
- import android.provider.Settings;
- import android.widget.Toast;
- import android.content.Intent;
- import android.Manifest;
- import android.net.Uri;
- import java.io.IOException;
- import java.io.File;
- import android.util.Log;
- import java.io.InputStream;
- import java.io.IOException;
- import java.io.FileOutputStream;
- import java.io.DataOutputStream;
- import android.content.pm.PackageManager;
- import android.widget.FrameLayout;
- import android.annotation.SuppressLint;
- //import android.app.*;
- import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
- import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
- import static android.view.WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
- import static android.widget.RelativeLayout.ALIGN_PARENT_LEFT;
- import static android.widget.RelativeLayout.ALIGN_PARENT_RIGHT;
- import android.widget.ImageView;
- import android.graphics.drawable.Drawable;
- import android.widget.RelativeLayout;
- import android.util.TypedValue;
- import android.view.ViewGroup;
- import android.view.View.OnClickListener;
- import android.content.res.AssetManager;
- import android.widget.TextView;
- import android.graphics.Color;
- import android.widget.ScrollView;
- import android.graphics.Typeface;
- import android.widget.SeekBar;
- import android.content.SharedPreferences;
- import android.app.Service;
- import android.widget.Spinner;
- import android.widget.Switch;
- import android.widget.CompoundButton;
- import android.content.res.Configuration;
- public class MainActivity extends Activity {
- static{
- System.loadLibrary("IMGUI");
- }
- public static native void Resolution(float px, float py);
- public static native void Close();
- public static native void getReady();
- WindowManager mWindowManager;
- FrameLayout vTouch;
- // ประกาศเมธอด native ที่จะเรียกจาก JNI
- public static native boolean getFixTouchScreen();
- // คุณสามารถใช้เมธอดนี้เพื่อรับค่า boolean จากฝั่ง C++
- public void checkFixTouchScreen(GLES3JNIView display) {
- boolean isFixTouchEnabled = getFixTouchScreen();
- if (isFixTouchEnabled) {
- // ทำสิ่งที่ต้องการเมื่อ FixTouchScreen เป็น true
- //System.out.println("FixTouchScreen is enabled.");
- display.setVisibility(View.INVISIBLE);
- } else {
- // ทำสิ่งที่ต้องการเมื่อ FixTouchScreen เป็น false
- //System.out.println("FixTouchScreen is disabled.");
- //display.setVisibility(View.VISIBLE);
- }
- }
- private RelativeLayout ICON_IMG;
- private Point point;
- private static MainActivity Instance;
- private WindowManager manager;
- private WindowManager.LayoutParams vParams;
- //private View vTouch;
- public WindowManager windowManager,xfqManager;
- private WindowManager 绘制窗口;
- public static int 真实宽;//ความละเอียด x
- public static int 真实高;//ความละเอียด y
- private LinearLayout Start_btn;
- public int POS_X = 0;
- public int POS_Y = 100;
- // WindowManager.LayoutParams vmParams;
- public static boolean 写出assets资源文件(Context context, String outPath, String fileName) {
- File file = new File(outPath);
- if (!file.exists()) {
- if (!file.mkdirs()) {
- Log.e("--Method--", "copyAssetsSingleFile: cannot create directory.");
- return false;
- }
- }
- try {
- InputStream inputStream = context.getAssets().open(fileName);
- File outFile = new File(file, fileName);
- FileOutputStream fileOutputStream = new FileOutputStream(outFile);
- // ถ่ายโอนไบต์จาก inputStream ไปยัง fileOutputStream
- byte[] buffer = new byte[1024];
- int byteRead;
- while (-1 != (byteRead = inputStream.read(buffer))) {
- fileOutputStream.write(buffer, 0, byteRead);
- }
- inputStream.close();
- fileOutputStream.flush();
- fileOutputStream.close();
- return true;
- } catch (IOException e) {
- e.printStackTrace();
- return false;
- }
- }
- //ตรวจจับรูท
- /*สมัครสิทธิ์รูทและกำหนดสิทธิ์รูท*/
- public static synchronized boolean 申请ROOT() {
- Process process = null;
- DataOutputStream os = null;
- try {
- process = Runtime.getRuntime().exec("su");
- os = new DataOutputStream(process.getOutputStream());
- os.writeBytes("exit\n");
- os.flush();
- int exitValue = process.waitFor();
- if (exitValue == 0) {
- return true;
- } else {
- return false;
- }
- } catch (Exception e) {
- return false;
- } finally {
- try {
- if (os != null) {
- os.close();
- }
- process.destroy();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
- public static void RunShell(String shell) {
- String s = shell;
- try {
- Runtime.getRuntime().exec(s, null, null);//ดำเนินการ
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- public void 执行二进制(String 路径) {
- if (申请ROOT() == false) {
- RunShell("chmod 777 " + getFilesDir() + 路径);
- RunShell(" " + getFilesDir() + 路径);
- } else {
- RunShell("su -c chmod 777 " + getFilesDir() + 路径);
- RunShell("su -c " + getFilesDir() + 路径);
- }
- }
- public void 储存权限(){
- boolean isGranted = true;
- if (android.os.Build.VERSION.SDK_INT >= 23) {
- if (this.checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
- isGranted = false;
- }
- if (this.checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
- isGranted = false;
- }
- if (!isGranted) {
- this.requestPermissions(
- new String[]{Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission
- .ACCESS_FINE_LOCATION,
- Manifest.permission.READ_EXTERNAL_STORAGE,
- Manifest.permission.WRITE_EXTERNAL_STORAGE},
- 102);
- }
- }
- }
- private static final int CODE_DRAW_OVER_OTHER_APP_PERMISSION = 2002;
- public void StartFloating() {
- // System.loadLibrary("KittyMemory");
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !Settings.canDrawOverlays(this)) {
- Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + getPackageName()));
- startActivityForResult(intent, CODE_DRAW_OVER_OTHER_APP_PERMISSION);
- } else {
- startService(new Intent(MainActivity.this, FloatingModMenuService.class));
- }
- }
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- /*super.onSaveInstanceState(savedInstanceState);
- savedInstanceState.putInt("postX",0);*/
- if (!Settings.canDrawOverlays(this)) {
- Toast.makeText(this, "โปรดอนุญาตให้ใช้หน้าต่างลอย", Toast.LENGTH_LONG).show();
- startActivityForResult(new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + getPackageName())), 0);
- } /*else {
- createFloatingIcon(); // สร้าง Floating Icon
- }*/
- 储存权限();
- try {//สมัครเพื่อรับสิทธิ์รูท
- Runtime.getRuntime().exec("su", null, null);
- } catch (IOException e) {}
- this.requestWindowFeature(Window.FEATURE_NO_TITLE);
- windowManager = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
- WindowManager 窗口=(WindowManager)getSystemService(Context.WINDOW_SERVICE);
- assert 窗口 != null;
- Display 分辨率=窗口.getDefaultDisplay();
- Point 输出分辨=new Point();
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
- 分辨率.getRealSize(输出分辨);
- }
- 真实宽 = 输出分辨.x;
- 真实高 = 输出分辨.y;
- if (真实宽 > 真实高) {
- 真实宽 = 输出分辨.y;
- 真实高 = 输出分辨.x;
- }
- Resolution(真实高, 真实宽);
- setContentView(R.layout.activity_main);
- // Start();
- //แถบสถานะโปร่งใสและแถบนำทาง
- if (Build.VERSION.SDK_INT >= 19) {
- //แถบสถานะโปร่งใส
- this.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
- this.getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
- this.getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
- //แถบนำทางแบบโปร่งใส
- //this.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
- }
- if (Build.VERSION.SDK_INT >= 19) {
- this.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
- }
- try {
- InputStream in =getAssets().open("JSKarabow.otf");
- GLES3JNIView.fontData = new byte[in.available()];
- in.read(GLES3JNIView.fontData);
- } catch (Exception e) {
- System.err.println(e.getMessage());
- }
- //写出assets资源文件(this, getFilesDir() + "/assets", "1");
- //执行二进制("/assets/1");
- ICON_IMG = new RelativeLayout(this);
- Start_btn = findViewById(R.id.btnStartTG);
- Start_btn.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- String url = "https://t.me/Anil_Xd";
- Intent i = new Intent(Intent.ACTION_VIEW);
- i.setData(Uri.parse(url));
- startActivity(i);
- }
- });
- // FloatingModMenuService floatingModMenuService = new FloatingModMenuService();
- //floatingModMenuService.initFloating(MainActivity.this);
- }
- /*
- @Override
- protected void onSaveInstanceState(Bundle outState) {
- super.onSaveInstanceState(outState);
- outState.putInt("vTouchVisibility", vTouch.getVisibility());
- outState.putInt("displayVisibility", display.getVisibility());
- }
- @Override
- protected void onRestoreInstanceState(Bundle savedInstanceState) {
- super.onRestoreInstanceState(savedInstanceState);
- vTouch.setVisibility(savedInstanceState.getInt("vTouchVisibility", View.VISIBLE));
- display.setVisibility(savedInstanceState.getInt("displayVisibility", View.VISIBLE));
- }
- */
- @Override
- public void onConfigurationChanged(Configuration newConfig) {
- super.onConfigurationChanged(newConfig);
- if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE ||
- newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
- updateFloatingWindow();
- }
- }
- private void updateFloatingWindow() {
- if (vTouch == null || manager == null) {
- return; // ออกหาก View หรือ Manager ยังไม่มีค่า
- }
- try {
- Point newSize = new Point();
- windowManager.getDefaultDisplay().getRealSize(newSize);
- vParams.width = newSize.x;
- vParams.height = newSize.y;
- if (vTouch.getParent() != null) {
- manager.updateViewLayout(vTouch, vParams);
- }
- } catch (IllegalArgumentException e) {
- e.printStackTrace();
- }
- }
- public void StartMenu(View v){
- // createFloatingIcon();
- //StartFloating();
- loadPrefs();
- initFloating();
- final Handler handler = new Handler();
- handler.post(new Runnable() {
- public void run() {
- MainActivity.this.Thread();
- handler.postDelayed(this, 1000);
- }
- });
- //startService(new Intent(MainActivity.this, FloatingModMenuService.class));
- Toast.makeText(getApplicationContext(), "Test Hello", Toast.LENGTH_LONG).show();
- }
- public void StartMenuIMGUI(View v){
- loadPrefs();
- initFloating();
- final Handler handler = new Handler();
- handler.post(new Runnable() {
- public void run() {
- MainActivity.this.Thread();
- handler.postDelayed(this, 1000);
- }
- });
- StartIMGUI();
- }
- @SuppressLint("WrongConstant")
- public void SetWindowManagerWindowService(WindowManager.LayoutParams vmParams) {
- //Variable to check later if the phone supports Draw over other apps permission
- int iparams = Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O ? 2038 : 2002;
- vmParams = new WindowManager.LayoutParams(
- WRAP_CONTENT,
- WRAP_CONTENT,
- iparams,
- 8 | FLAG_TRANSLUCENT_STATUS,
- -3);
- //params = new WindowManager.LayoutParams(WindowManager.LayoutParams.LAST_APPLICATION_WINDOW, 8, -3);
- vmParams.gravity = 51;
- vmParams.x = POS_X;
- vmParams.y = POS_Y;
- //mWindowManager = (WindowManager) getContext.getSystemService(getContext.WINDOW_SERVICE);
- //mWindowManager.addView(rootFrame, vmParams);
- //overlayRequired = true;
- }
- //private FrameLayout _vTouch;
- // private GLES3JNIView _display;
- public static GLES3JNIView display;
- public void StartIMGUI() {
- manager = (WindowManager) getApplicationContext().getSystemService(Context.WINDOW_SERVICE);
- vParams = getAttributes(false);
- final WindowManager.LayoutParams wParams = getAttributes(true);
- display = new GLES3JNIView(this);
- vTouch = new FrameLayout(getApplicationContext());
- try {
- manager.addView(vTouch, vParams);
- manager.addView(display, wParams);
- } catch (Exception e) {
- e.printStackTrace();
- }
- vTouch.setOnTouchListener(new View.OnTouchListener() {
- @Override
- public boolean onTouch(View v, MotionEvent event) {
- int action = event.getAction();
- if (action == MotionEvent.ACTION_DOWN || action == MotionEvent.ACTION_MOVE || action == MotionEvent.ACTION_UP) {
- GLES3JNIView.MotionEventClick(action != MotionEvent.ACTION_UP, event.getRawX(), event.getRawY());
- }
- return true;
- }
- });
- final Handler handler = new Handler();
- handler.postDelayed(new Runnable() {
- @Override
- public void run() {
- try {
- if (vTouch.getParent() != null) {
- String[] rect = GLES3JNIView.getWindowRect().split("\\|");
- if (rect.length == 4) {
- vParams.x = Integer.parseInt(rect[0]);
- vParams.y = Integer.parseInt(rect[1]);
- vParams.width = Integer.parseInt(rect[2]);
- vParams.height = Integer.parseInt(rect[3]);
- manager.updateViewLayout(vTouch, vParams);
- boolean isFixTouchEnabled = getFixTouchScreen();
- if (isFixTouchEnabled) {
- mWindowManager_.addView(mFloatingView, params);
- } else {
- mWindowManager_.removeView(mFloatingView);
- }
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- handler.postDelayed(this, 20);
- }
- }
- }, 20);
- point = new Point();
- vTouch.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
- @Override
- public void onGlobalLayout() {
- manager.getDefaultDisplay().getRealSize(point);
- GLES3JNIView.real(point.x, point.y);
- }
- });
- }
- @Override
- protected void onPause() {
- super.onPause();
- if (vTouch != null && vTouch.getParent() != null) {
- //manager.removeView(vTouch);
- }
- }
- public void StartIMGUI_สำรอง(){
- 绘制窗口 = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
- //manager = (WindowManager) getApplicationContext().getSystemService(Context.WINDOW_SERVICE);
- manager = (WindowManager) getApplicationContext().getSystemService(Context.WINDOW_SERVICE);
- // กำหนด vParams และ wParams ให้มีค่าตรงกัน และตั้งค่า FLAG_NOT_TOUCH_MODAL
- vParams = getAttributes(false);
- //vParams.flags = WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
- final WindowManager.LayoutParams wParams = getAttributes(true);
- // final GLES3JNIView
- display = new GLES3JNIView(this);
- //vTouch = new View(this);
- //mWindowManager = ((Activity)getApplicationContext()).getWindowManager();
- vTouch = new FrameLayout(getApplicationContext());
- // เพิ่ม vTouch และ display ลงใน WindowManager
- manager.addView(vTouch, vParams);
- manager.addView(display, wParams);
- //display.setVisibility(View.INVISIBLE);
- // รับสัมผัสใน vTouch
- vTouch.setOnTouchListener(new View.OnTouchListener() {
- @Override
- public boolean onTouch(View v, MotionEvent event) {
- int action = event.getAction();
- switch (action) {
- case MotionEvent.ACTION_MOVE:
- case MotionEvent.ACTION_DOWN:
- case MotionEvent.ACTION_UP:
- GLES3JNIView.MotionEventClick(action != MotionEvent.ACTION_UP, event.getRawX(), event.getRawY());
- break;
- default:
- break;
- }
- return true;
- }
- });
- //_display = display;
- ///_vTouch = vTouch;
- // อัปเดตขนาดและตำแหน่งของ vTouch
- final Handler handler = new Handler();
- handler.postDelayed(new Runnable() {
- @Override
- public void run() {
- try {
- String rect[] = GLES3JNIView.getWindowRect().split("\\|");
- vParams.x = Integer.parseInt(rect[0]);
- vParams.y = Integer.parseInt(rect[1]);
- vParams.width = Integer.parseInt(rect[2]);
- vParams.height = Integer.parseInt(rect[3]);
- manager.updateViewLayout(vTouch, vParams);
- //display.setVisibility(View.VISIBLE);
- //checkFixTouchScreen(display);
- boolean isFixTouchEnabled = getFixTouchScreen();
- if (isFixTouchEnabled) {
- // System.out.println("FixTouchScreen is enabled.");
- //display.setVisibility(View.INVISIBLE);
- //vTouch.setVisibility(View.GONE);
- // ICON_IMG.setVisibility(View.VISIBLE);
- // Toast.makeText(getApplication(), "เปิด", Toast.LENGTH_LONG).show();
- //window_Manager.addView(startimage, layoutParams);
- mWindowManager_.addView(mFloatingView, params);
- } else {
- //System.out.println("FixTouchScreen is disabled.");
- //display.setVisibility(View.VISIBLE);
- //vTouch.setVisibility(View.VISIBLE);
- // ICON_IMG.setVisibility(View.GONE);
- // Toast.makeText(getApplication(), "ปิด", Toast.LENGTH_LONG).show();
- //window_Manager.removeView(startimage);
- mWindowManager_.removeView(mFloatingView);
- }
- } catch (Exception e) {
- System.err.println(e.getMessage());
- }
- handler.postDelayed(this, 20);
- }
- }, 20);
- point = new Point();
- // ได้ขนาดหน้าจอจริง
- vTouch.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
- @Override
- public void onGlobalLayout() {
- 绘制窗口.getDefaultDisplay().getRealSize(point);
- GLES3JNIView.real(point.x, point.y);
- }
- });
- /*startimage.setOnClickListener(new ImageView.OnClickListener() {
- boolean hide_imgui = false;
- @Override
- public void onClick(View view) {
- //collapsedView.setVisibility(View.GONE);
- //expandedView.setVisibility(View.VISIBLE);
- //mainActivity.StartIMGUI();
- // hide_imgui = (hide_imgui == false);
- Toast.makeText(getApplicationContext(), "AAAAAA", Toast.LENGTH_LONG).show();
- }
- });*/
- }
- ///####END StartMenuFix ######
- public void onClick1(View v) {
- Start();
- }
- public void Start() {
- if (Instance == null) {
- Thread t1 = new Thread(new Runnable() {
- @Override
- public void run() {
- getReady();
- }
- });
- t1.start();
- Thread t2 = new Thread(new Runnable() {
- @Override
- public void run() {
- try {
- Thread.sleep(200);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- // Tool.runExecutable(FloatingModMenuService.this, "/assets/Son_non_fish", 1);
- }
- });
- t2.start();
- }
- }
- public WindowManager window_Manager;
- private ImageView startimage2;
- private WindowManager.LayoutParams layoutParams;
- private float initialTouchX, initialTouchY;
- private int initialX, initialY;
- int ICON_SIZE = 0;
- // ตัวแปรเพื่อติดตามการเคลื่อนไหว
- private boolean isMoved = false;
- private WindowManager.LayoutParams getAttributes(boolean isWindow) {
- WindowManager.LayoutParams params = new WindowManager.LayoutParams();
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
- params.type = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
- } else {
- params.type = WindowManager.LayoutParams.TYPE_PHONE;
- }
- params.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN
- | WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
- | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION
- | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
- if (isWindow) {
- params.flags |= WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
- }
- params.format = PixelFormat.RGBA_8888;
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
- params.layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
- }
- params.gravity = Gravity.START | Gravity.TOP;
- params.x = 0;
- params.y = 0;
- params.width = WindowManager.LayoutParams.MATCH_PARENT; // ใช้ MATCH_PARENT
- params.height = WindowManager.LayoutParams.MATCH_PARENT; // ใช้ MATCH_PARENT
- return params;
- }
- @Override
- protected void onActivityResult(int requestCode, int resultCode, Intent data) {
- super.onActivityResult(requestCode, resultCode, data);
- if (requestCode == 1234) {
- if (Settings.canDrawOverlays(this)) {
- //createFloatingIcon(); // สร้าง Floating Icon
- startService(new Intent(MainActivity.this, FloatingModMenuService.class));
- }
- }
- }
- private int convertDipToPixels(int i) {
- return (int) ((((float) i) * getApplicationContext().getResources().getDisplayMetrics().density) + 0.5f);
- }
- //#######################################################//#######################################################
- //#######################################################//#######################################################
- Drawable icon;
- private WindowManager mWindowManager_;
- private View mFloatingView;
- private RelativeLayout mCollapsed;
- private LinearLayout patches, mExpandet, settings, mButtonPanel, mTitlle, settingsTitle;
- private ImageView startimage, closeimage, closeimage_title, closeimage_settings, mSettinsMenu, openSite;
- private SeekBar seek_icon, seek_alpha, seek_red, seek_green, seek_blue;
- private WindowManager.LayoutParams params;
- private float curent_icon;
- private SharedPreferences.Editor editor;
- private int mProgress_icon, background_color, alpha, red, green, blue;
- private TextView alpha_text, red_text, green_text, blue_text, current_opacity_icon;
- private Spinner spinner;
- private int dp2px(int dp){
- final float scale = getResources().getDisplayMetrics().density;
- return (int) (dp * scale + 0.5f);
- }
- /* access modifiers changed from: private */
- public void Thread() {
- if (this.mFloatingView == null) {
- return;
- }
- if (Util.isAppBackground()) {
- //this.mFloatingView.setVisibility(View.INVISIBLE);
- } else {
- this.mFloatingView.setVisibility(View.VISIBLE);
- }
- }
- public void initFloating() {
- //MainActivity mainActivity = new MainActivity();
- //mainActivity.StartIMGUI();
- //MainActivity.StartIMGUI();
- AssetManager assetManager = getAssets();
- //инициализируем элементы
- FrameLayout rootFrame = new FrameLayout(getBaseContext()); //глобальная разметка
- RelativeLayout mRootContainer = new RelativeLayout(getBaseContext());//разметка на которую будут помещены две разметки иконки и самого меню
- mCollapsed = new RelativeLayout(getBaseContext());//разметка иконки(когда меню свернуто)
- mExpandet = new LinearLayout(getBaseContext());//разметка меню(когда меню развернуто)
- patches = new LinearLayout(getBaseContext());//разметка самих опций(когда меню развернуто)
- mButtonPanel = new LinearLayout(getBaseContext());//разметка кнопок опций(когда меню развернуто)
- mTitlle = new LinearLayout(getBaseContext());//разметка заголовка меню(когда меню развернуто)
- settingsTitle = new LinearLayout(getBaseContext());//разметка заголовка настроек(когда меню развернуто)
- //mCloseMenu = new Button(getBaseContext());//кнопка закрыть меню(когда меню развернуто)
- mSettinsMenu = new ImageView(getBaseContext());//кнопка настроить меню(когда меню развернуто)
- //прописываем разметку
- FrameLayout.LayoutParams flayoutParams = new FrameLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT);
- rootFrame.setLayoutParams(flayoutParams);
- mRootContainer.setLayoutParams(new FrameLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT));
- //корневая разметка плавающей иконки
- mCollapsed.setLayoutParams(new RelativeLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT));
- mCollapsed.setVisibility(View.VISIBLE);//mExpandet видимый
- try {
- startimage = new ImageView(getBaseContext());
- startimage.setLayoutParams(new RelativeLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT));
- //задаём размер иконки
- int dimension = 60;//60dp
- int dimensionInDp = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dimension, getResources().getDisplayMetrics());
- startimage.getLayoutParams().height = dimensionInDp;
- startimage.getLayoutParams().width = dimensionInDp;
- startimage.requestLayout();
- startimage.setScaleType(ImageView.ScaleType.FIT_XY);
- InputStream inputStream_hack = assetManager.open("v1on.png"); //ic_hack_floating
- icon = Drawable.createFromStream(inputStream_hack, null);
- startimage.setImageDrawable(icon);
- startimage.setAlpha(curent_icon);
- //
- closeimage = new ImageView(getBaseContext());
- closeimage.setLayoutParams(new RelativeLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT));
- ((ViewGroup.MarginLayoutParams) startimage.getLayoutParams()).topMargin = dp2px(10);
- //задаём размер иконки закрыть
- int dimensionClose = 20;//20dp
- int dimensionInDpClose = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dimensionClose, getResources().getDisplayMetrics());
- closeimage.getLayoutParams().height = dimensionInDpClose;
- closeimage.getLayoutParams().width = dimensionInDpClose;
- closeimage.requestLayout();
- InputStream inputStream_close = assetManager.open("ic_close.png");
- Drawable ic_close = Drawable.createFromStream(inputStream_close, null);
- closeimage.setImageDrawable(ic_close);
- closeimage.setAlpha(curent_icon);
- ((ViewGroup.MarginLayoutParams) closeimage.getLayoutParams()).leftMargin = dp2px(35);
- //
- //иконка закрыть для развернутого меню
- closeimage_title = new ImageView(getBaseContext());
- LinearLayout.LayoutParams pp1 = new LinearLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT);
- pp1.gravity = Gravity.LEFT;
- pp1.height = dimensionInDpClose;
- pp1.width = dimensionInDpClose;
- closeimage_title.setLayoutParams(pp1);
- closeimage_title.requestLayout();
- closeimage_title.setImageDrawable(ic_close);
- //
- closeimage_settings = new ImageView(getBaseContext());
- LinearLayout.LayoutParams pp = new LinearLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT);
- pp.gravity = Gravity.LEFT;
- pp.height = dimensionInDpClose;
- pp.width = dimensionInDpClose;
- closeimage_settings.setLayoutParams(pp);
- closeimage_settings.requestLayout();
- closeimage_settings.setImageDrawable(ic_close);
- ((ViewGroup.MarginLayoutParams) closeimage_settings.getLayoutParams()).leftMargin = dp2px(95);
- //
- LinearLayout.LayoutParams set = new LinearLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT);
- set.gravity = Gravity.RIGHT;
- set.height = dimensionInDpClose;
- set.width = dimensionInDpClose;
- mSettinsMenu.setLayoutParams(set);
- mSettinsMenu.requestLayout();
- InputStream inputStream_settings = assetManager.open("ic_settings.png");
- Drawable ic_settings = Drawable.createFromStream(inputStream_settings, null);
- mSettinsMenu.setImageDrawable(ic_settings);
- //
- LinearLayout.LayoutParams pp3 = new LinearLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT);
- openSite = new ImageView(getBaseContext());
- pp3.gravity = Gravity.LEFT;
- pp3.height = dimensionInDpClose;
- pp3.width = dimensionInDpClose;
- openSite.setLayoutParams(pp3);
- openSite.requestLayout();
- InputStream inputStream_openSite = assetManager.open("ic_open.png");
- Drawable ic_openSite = Drawable.createFromStream(inputStream_openSite, null);
- openSite.setImageDrawable(ic_openSite);
- ((ViewGroup.MarginLayoutParams) openSite.getLayoutParams()).leftMargin = dp2px(95);
- } catch (IOException ex) {
- Toast.makeText(getBaseContext(), ex.toString(), Toast.LENGTH_LONG).show();
- }
- //прописываем разметку когда меню развернуто
- mExpandet.setVisibility(View.GONE);//mExpandet скрытый
- mExpandet.setBackgroundColor(background_color);
- //mExpandet.setOrientation(LinearLayout.VERTICAL);
- LinearLayout.LayoutParams params_mExpandet = new LinearLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT);
- mExpandet.setLayoutParams(params_mExpandet);
- ScrollView scrollView = new ScrollView(getBaseContext());
- scrollView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT));
- patches.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, WRAP_CONTENT));
- patches.setOrientation(LinearLayout.VERTICAL);
- mButtonPanel.setLayoutParams(new LinearLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT));
- mTitlle.setLayoutParams(new LinearLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT));
- TextView title_text = new TextView(getBaseContext());
- title_text.setText("Mod Menu v1.0.1");
- title_text.setTextColor(Color.RED);
- title_text.setTypeface(Typeface.DEFAULT_BOLD);
- title_text.setTextSize(16);
- title_text.setPadding(10, 10, 10, 10);
- LinearLayout.LayoutParams title_Layout = new LinearLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT);
- title_Layout.gravity = Gravity.CENTER;
- title_text.setLayoutParams(title_Layout);
- mTitlle.addView(title_text);
- mTitlle.addView(closeimage_title);
- settings = new LinearLayout(getBaseContext());
- settings.setVisibility(View.GONE);//mExpandet скрытый
- settings.setBackgroundColor(background_color);
- settings.setOrientation(LinearLayout.VERTICAL);
- settings.setLayoutParams(new LinearLayout.LayoutParams(dp2px(175), WRAP_CONTENT));
- TextView settings_title_text = new TextView(getBaseContext());
- settings_title_text.setText("Settings");
- settings_title_text.setTextColor(Color.RED);
- settings_title_text.setTypeface(Typeface.DEFAULT_BOLD);
- settings_title_text.setTextSize(16);
- //settings_title_text.setPadding(10, 10, 10, 10);
- settingsTitle.setLayoutParams(new LinearLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT));
- LinearLayout.LayoutParams settingstitle_Layout = new LinearLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT);
- settingstitle_Layout.gravity = Gravity.CENTER;
- settings_title_text.setLayoutParams(settingstitle_Layout);
- ScrollView settings_scroll = new ScrollView(getBaseContext());
- settings_scroll.setLayoutParams(new LinearLayout.LayoutParams(WRAP_CONTENT, dp2px(160)));
- LinearLayout settings_scroll_linear = new LinearLayout(getBaseContext());
- settings_scroll_linear.setLayoutParams(new LinearLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT));
- settings_scroll_linear.setOrientation(LinearLayout.VERTICAL);
- TextView opacity_icon = new TextView(getBaseContext());
- opacity_icon.setText("Change opacity icon");
- opacity_icon.setTypeface(Typeface.DEFAULT_BOLD);
- opacity_icon.setTextColor(Color.WHITE);
- opacity_icon.setPadding(10, 10, 10, 10);
- current_opacity_icon = new TextView(getBaseContext());
- current_opacity_icon.setText("Opacity:" + curent_icon);
- current_opacity_icon.setTextColor(Color.WHITE);
- current_opacity_icon.setPadding(10, 10, 10, 10);
- TextView background_menu = new TextView(getBaseContext());
- background_menu.setText("Change color background");
- background_menu.setTypeface(Typeface.DEFAULT_BOLD);
- background_menu.setTextColor(Color.WHITE);
- background_menu.setPadding(10, 10, 10, 10);
- alpha_text = new TextView(getBaseContext());
- alpha_text.setText("Alpha:" + alpha);
- alpha_text.setTextColor(Color.WHITE);
- alpha_text.setPadding(10, 10, 10, 10);
- red_text = new TextView(getBaseContext());
- red_text.setText("Red:" + red);
- red_text.setTextColor(Color.WHITE);
- red_text.setPadding(10, 10, 10, 10);
- green_text = new TextView(getBaseContext());
- green_text.setText("Green:" + green);
- green_text.setTextColor(Color.WHITE);
- green_text.setPadding(10, 10, 10, 10);
- blue_text = new TextView(getBaseContext());
- blue_text.setText("Blue:" + blue);
- blue_text.setTextColor(Color.WHITE);
- blue_text.setPadding(10, 10, 10, 10);
- seek_icon = new SeekBar(getBaseContext());
- seek_icon.setMax(10);
- seek_icon.setProgress(mProgress_icon);
- seek_alpha = new SeekBar(getBaseContext());
- seek_alpha.setMax(255);
- seek_alpha.setProgress(alpha);
- seek_red = new SeekBar(getBaseContext());
- seek_red.setProgress(red);
- seek_red.setMax(255);
- seek_green = new SeekBar(getBaseContext());
- seek_green.setMax(255);
- seek_green.setProgress(green);
- seek_blue = new SeekBar(getBaseContext());
- seek_blue.setProgress(blue);
- seek_blue.setMax(255);
- /*Спиннер на всякий случай*/
- /* String[] items = {"Item 1", "Item 2", "Item 3"};
- spinner = new Spinner(getBaseContext());
- ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item, items);
- spinner.setAdapter(arrayAdapter);
- spinner.setBackgroundColor(background_color);*/
- settingsTitle.addView(settings_title_text);
- settingsTitle.addView(closeimage_settings);
- settings.addView(settingsTitle);
- settings.addView(settings_scroll);
- settings_scroll.addView(settings_scroll_linear);
- settings_scroll_linear.addView(opacity_icon);
- settings_scroll_linear.addView(current_opacity_icon);
- settings_scroll_linear.addView(seek_icon);
- settings_scroll_linear.addView(background_menu);
- settings_scroll_linear.addView(alpha_text);
- settings_scroll_linear.addView(seek_alpha);
- settings_scroll_linear.addView(red_text);
- settings_scroll_linear.addView(seek_red);
- settings_scroll_linear.addView(green_text);
- settings_scroll_linear.addView(seek_green);
- settings_scroll_linear.addView(blue_text);
- settings_scroll_linear.addView(seek_blue);
- //settings_scroll_linear.addView(spinner);
- //добавляем элементы в корневую разметку
- rootFrame.addView(mRootContainer);
- //добавляем элементы в mRootContainer
- mRootContainer.addView(mCollapsed);//меню закрыто
- mRootContainer.addView(mExpandet);//меню открыто
- mRootContainer.addView(settings);
- //добавляем элементы в mCollapsed
- mCollapsed.addView(startimage);
- mCollapsed.addView(closeimage);
- //добавляем элементы в mExpandet
- //mExpandet.addView(scrollView);
- //scrollView.addView(patches);
- mExpandet.addView(patches);
- patches.addView(mTitlle);
- //добавляем элементы в mButtonPanel
- mButtonPanel.addView(mSettinsMenu);
- mButtonPanel.addView(openSite);
- mFloatingView = rootFrame;//rootFrame(mFloatingView) корневая разметка всего окна
- //Add the view to the window.
- if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
- params = new WindowManager.LayoutParams(
- WRAP_CONTENT,
- WRAP_CONTENT,
- WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY,
- WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
- PixelFormat.TRANSLUCENT);
- } else {
- params = new WindowManager.LayoutParams(
- WRAP_CONTENT,
- WRAP_CONTENT,
- WindowManager.LayoutParams.TYPE_PHONE,
- WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
- PixelFormat.TRANSLUCENT);
- }
- //Specify the view position
- params.gravity = Gravity.TOP | Gravity.START; //Initially view will be added to top-left corner
- params.x = 0;
- params.y = 100;
- //Add the view to the window
- mWindowManager_ = (WindowManager) getSystemService(WINDOW_SERVICE);
- //mWindowManager_.addView(mFloatingView, params);
- //The root element of the collapsed view layout
- final View collapsedView = mCollapsed;
- //The root element of the expanded view layout
- final View expandedView = mExpandet;
- mFloatingView.setOnTouchListener(onTouchListener());
- startimage.setOnTouchListener(onTouchListener());
- initMenuButton(collapsedView, expandedView, vTouch, display);
- //modMenu();
- }
- //обработчик события, когда перетаскивают объект касанием
- private View.OnTouchListener onTouchListener() {
- return new View.OnTouchListener() {
- final View collapsedView = mCollapsed;
- //The root element of the expanded view layout
- final View expandedView = mExpandet;
- private int initialX;
- private int initialY;
- private float initialTouchX;
- private float initialTouchY;
- @Override
- public boolean onTouch(View v, MotionEvent event) {
- switch (event.getAction()) {
- case MotionEvent.ACTION_DOWN:
- //remember the initial position.
- initialX = params.x;
- initialY = params.y;
- //get the touch location
- initialTouchX = event.getRawX();
- initialTouchY = event.getRawY();
- return true;
- case MotionEvent.ACTION_UP:
- int Xdiff = (int) (event.getRawX() - initialTouchX);
- int Ydiff = (int) (event.getRawY() - initialTouchY);
- //The check for Xdiff <10 && YDiff< 10 because sometime elements moves a little while clicking.
- //So that is click event.
- if (Xdiff < 10 && Ydiff < 10) {
- if (isViewCollapsed()) {
- //When user clicks on the image view of the collapsed layout,
- //visibility of the collapsed layout will be changed to "View.GONE"
- //and expanded view will become visible.
- //collapsedView.setVisibility(View.GONE);
- //expandedView.setVisibility(View.VISIBLE);
- เปลี่ยนสลับไอค่อน();
- }
- }
- return true;
- case MotionEvent.ACTION_MOVE:
- //Calculate the X and Y coordinates of the view.
- params.x = initialX + (int) (event.getRawX() - initialTouchX);
- params.y = initialY + (int) (event.getRawY() - initialTouchY);
- //Update the layout with new X & Y coordinate
- mWindowManager_.updateViewLayout(mFloatingView, params);
- return true;
- }
- return false;
- }
- };
- }
- private boolean hide_imgui = false;
- public void เปลี่ยนสลับไอค่อน(){
- //collapsedView.setVisibility(View.GONE);
- //expandedView.setVisibility(View.VISIBLE);
- hide_imgui = (hide_imgui == false);
- if (hide_imgui){
- vTouch.setVisibility(View.GONE);
- display.setVisibility(View.INVISIBLE);
- } else {
- vTouch.setVisibility(View.VISIBLE);
- display.setVisibility(View.VISIBLE);
- }
- Util.Tost("Hello,999",MainActivity.this);
- }
- //private FrameLayout _vTouch;
- //private GLES3JNIView _display;
- //иницализируем обработчики событий для кнопок итд..
- public void initMenuButton(final View collapsedView, final View expandedView, final FrameLayout vTouch, final GLES3JNIView display) {
- }
- //загрузка и установка настроек по-умолчанию
- private void loadPrefs() {
- SharedPreferences preferences = getApplicationContext().getSharedPreferences("mod_menu", 0);
- editor = preferences.edit();
- background_color = preferences.getInt("background_color", -14606047);
- curent_icon = preferences.getFloat("current_background", 1);
- alpha = preferences.getInt("current_progress_alpha", 255);
- red = preferences.getInt("current_progress_red", 33);
- green = preferences.getInt("current_progress_green", 33);
- blue = preferences.getInt("current_progress_blue", 33);
- mProgress_icon = preferences.getInt("current_progress_icon", 10);
- }
- private boolean isViewCollapsed() {
- return mFloatingView == null || mCollapsed.getVisibility() == View.VISIBLE;
- }
- @Override
- public void onDestroy() {
- super.onDestroy();
- if (mFloatingView != null){
- //mWindowManager_.removeView(mFloatingView);
- Toast.makeText(getBaseContext(), "Mod Menu Service is stopped", Toast.LENGTH_SHORT).show();
- }
- if (manager != null){
- //manager.updateViewLayout(vTouch, params);
- }
- }
- private interface SW {
- void OnWrite(boolean z);
- }
- @Override
- public void onResume() {
- super.onResume();
- // updateFloatingWindow(); // เรียกฟังก์ชันที่อัปเดตขนาดและตำแหน่ง
- }
- //#######################################################//#######################################################
- //#######################################################//#######################################################
- }
Advertisement
Add Comment
Please, Sign In to add comment