Skip to content

Commit

Permalink
Implemented mouse control
Browse files Browse the repository at this point in the history
  • Loading branch information
hwnl committed Aug 15, 2024
1 parent a626a5d commit 2cfc0c6
Show file tree
Hide file tree
Showing 9 changed files with 166 additions and 17 deletions.
3 changes: 2 additions & 1 deletion app/src/main/assets/litepal.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
For example:
<version value="1" />
-->
<version value="18" />
<version value="19" />

<!--
Define your models in the list with mapping tag, LitePal will
Expand All @@ -37,6 +37,7 @@
<mapping class="com.fde.keyassist.entity.Plan"/>
<mapping class="com.fde.keyassist.entity.DoubleClickMappingEntity"/>
<mapping class="com.fde.keyassist.entity.ScaleMappingEntity"/>
<mapping class="com.fde.keyassist.entity.CursorEntity"/>
</list>

<!--
Expand Down
46 changes: 36 additions & 10 deletions app/src/main/java/com/fde/keyassist/FloatingService.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,14 @@ public class FloatingService extends Service implements View.OnClickListener,Ada

private ImageView key_mapping_open_cursor;

private Boolean cursorMake = false;
private Boolean cursorMake = true;

private ImageView dropdown_menu_import;





@Nullable
@Override
public IBinder onBind(Intent intent) {
Expand Down Expand Up @@ -270,6 +273,7 @@ public void showKeyMapping(){
isMainWindow = true;



if(isApply){
key_mapping_apply.setText("取消");
}
Expand Down Expand Up @@ -468,16 +472,22 @@ public void onClick(View view) {
switch (view.getId()){

case R.id.key_mapping_open_cursor:
if(cursorMake){
openCursor();
cursorMake = !cursorMake;
}else{
closeCursor();
cursorMake = !cursorMake;
// openCursor();
if(!editAndCancal){
if(cursorMake){
modifyDialog.setCursorSwitch(true);
cursorMake = !cursorMake;
setCursorBack(true);
}else{
modifyDialog.setCursorSwitch(false);
cursorMake = !cursorMake;
setCursorBack(false);
}
}

break;



case R.id.key_mapping_plan_linear:
View dropdownView = LayoutInflater.from(this).inflate(R.layout.dropdown_menu, null);
dropdown_menu_add = dropdownView.findViewById(R.id.dropdown_menu_add);
Expand Down Expand Up @@ -576,6 +586,12 @@ public void onClick(View view) {
directMappingEntities = applyDialog.applyDirect();
doubleClickMappingEntities = applyDialog.applyDoubleClick();
scaleMappingEntities = applyDialog.applyScaleClick();
Boolean b = applyDialog.applyCursor();
if(b){
openCursor();
}else{
closeCursor();
}
isApply = true;
isMainWindow = false;
key_mapping_apply.setText("取消");
Expand All @@ -586,11 +602,13 @@ public void onClick(View view) {
applyDialog.cancal();
isApply = false;
key_mapping_apply.setText("应用");
closeCursor();
}
}
break;
case R.id.key_mapping_save:
setButtonBack(null);
setCursorBack(false);
if(!editAndCancal) {
modifyDialog.save();
key_mapping_cancel.setText("编辑");
Expand All @@ -608,6 +626,7 @@ public void onClick(View view) {
break;
case R.id.key_mapping_cancel:
setButtonBack(null);
setCursorBack(false);
// 编辑
if(editAndCancal){
key_mapping_save.setText("保存");
Expand All @@ -619,6 +638,7 @@ public void onClick(View view) {
key_mapping_cancel.setText("取消");
startModify(Constant.planName);
modifyDialog.showView(); //单击事件
setCursorBack(modifyDialog.getCursorSwitch());
}else{
key_mapping_save.setText("退出");
editAndCancal = true;
Expand Down Expand Up @@ -657,7 +677,13 @@ public void setButtonBack(ImageView imageView){




public void setCursorBack(Boolean b){
if(b){
key_mapping_open_cursor.setBackgroundResource(R.drawable.key_mapping_key_background_click);
}else{
key_mapping_open_cursor.setBackgroundResource(R.drawable.key_mapping_key_background);
}
}



Expand Down Expand Up @@ -694,7 +720,7 @@ public void closeCursor(){
try {
Process process = Runtime.getRuntime().exec("/system/bin/sh");
DataOutputStream os = new DataOutputStream(process.getOutputStream());
os.writeBytes("setprop fde.show_wayland_cursor false\n");
os.writeBytes("setprop fde.show_wayland_cursor true\n");
os.writeBytes("setprop fde.click_as_touch false\n");
os.writeBytes("setprop fde.inject_as_touch false\n");
os.writeBytes("exit\n");
Expand Down
14 changes: 14 additions & 0 deletions app/src/main/java/com/fde/keyassist/dialog/ApplyDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import android.widget.TextView;

import com.fde.keyassist.R;
import com.fde.keyassist.entity.CursorEntity;
import com.fde.keyassist.entity.DirectMappingEntity;
import com.fde.keyassist.entity.DoubleClickMappingEntity;
import com.fde.keyassist.entity.KeyMappingEntity;
Expand Down Expand Up @@ -212,6 +213,19 @@ public List<DoubleClickMappingEntity> applyDoubleClick(){
return curKeyMappingEntity;
}

public Boolean applyCursor(){
List<CursorEntity> cursorEntities = new ArrayList<>();
List<Plan> plans = LitePal.where("planName = ?",planName).find(Plan.class);
if(plans != null && plans.size() >=1){
Plan plan = plans.get(0);
cursorEntities = LitePal.where("planId = ?", plan.getId().toString()).find(CursorEntity.class);
}
if(cursorEntities != null && !cursorEntities.isEmpty()){
return cursorEntities.get(0).getCursorSwitch();
}
return false;
}


public void cancal(){
if(windowManager!=null && allView!=null && !allView.isEmpty()){
Expand Down
44 changes: 44 additions & 0 deletions app/src/main/java/com/fde/keyassist/dialog/ModifyDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@

import androidx.annotation.NonNull;

import com.fde.keyassist.FloatingService;
import com.fde.keyassist.R;
import com.fde.keyassist.entity.CursorEntity;
import com.fde.keyassist.entity.DirectMappingEntity;
import com.fde.keyassist.entity.DoubleClickMappingEntity;
import com.fde.keyassist.entity.KeyMappingEntity;
Expand All @@ -49,6 +51,8 @@ public class ModifyDialog extends BaseServiceDialog implements View.OnClickListe

private Integer eventType = Constant.TAP_CLICK_EVENT;

private Boolean cursorSwitch = false;

private TextView curText;
private TextView lastText;
// private TextView curHintText;
Expand Down Expand Up @@ -76,6 +80,13 @@ public class ModifyDialog extends BaseServiceDialog implements View.OnClickListe

private TextView curCount;

public Boolean getCursorSwitch() {
return cursorSwitch;
}

public void setCursorSwitch(Boolean cursorSwitch) {
this.cursorSwitch = cursorSwitch;
}

public void setEventType(Integer eventType) {
this.eventType = eventType;
Expand Down Expand Up @@ -361,6 +372,7 @@ public void save(){
LitePal.deleteAll(DirectMappingEntity.class, "planId = ?" , plans.get(0).getId().toString());
LitePal.deleteAll(DoubleClickMappingEntity.class, "planId = ?" , plans.get(0).getId().toString());
LitePal.deleteAll(ScaleMappingEntity.class, "planId = ?" , plans.get(0).getId().toString());
LitePal.deleteAll(CursorEntity.class, "planId = ?" , plans.get(0).getId().toString());
}
// 保存单个按键
saveTapEvent();
Expand All @@ -370,6 +382,8 @@ public void save(){
saveDoubleClickEvent();
// 保存缩放键
saveScaleEvent();
// 保存鼠标状态
saveCursor();

if(allView != null && !allView.isEmpty()){
for (View view : allView){
Expand All @@ -385,6 +399,21 @@ public void save(){
dismiss();
}

public void saveCursor(){
CursorEntity cursorEntity = new CursorEntity();
cursorEntity.setCursorSwitch(cursorSwitch);
List<Plan> plans = LitePal.where("planName = ?",planName).find(Plan.class);
if(plans != null && plans.size() >=1){
cursorEntity.setPlanId(plans.get(0).getId());
}else{
Plan plan = new Plan();
plan.setPlanName(planName);
plan.save();
cursorEntity.setPlanId(plan.getId());
}
cursorEntity.save();
}

public void saveTapEvent(){
// 单机事件view
for (View view : tapView){
Expand Down Expand Up @@ -674,12 +703,27 @@ public void showDoubleClickEvent(){
}
}

public void showCursor(){
// 取出planId
List<Plan> plans = LitePal.where("planName = ?",planName).find(Plan.class);
List<CursorEntity> cursorEntity = new ArrayList<>();
if(plans != null && plans.size() >=1){
Plan plan = plans.get(0);
cursorEntity = LitePal.where("planId = ?", plan.getId().toString()).find(CursorEntity.class);
}
if(cursorEntity!= null && !cursorEntity.isEmpty()){
CursorEntity cursor = cursorEntity.get(0);
cursorSwitch = cursor.getCursorSwitch();
}
}

// 从数据库取出所有事件
public void showView(){
showTapEvent();
showDirectEvent();
showDoubleClickEvent();
showScaleEvent();
showCursor();
}


Expand Down
33 changes: 33 additions & 0 deletions app/src/main/java/com/fde/keyassist/entity/CursorEntity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.fde.keyassist.entity;

import org.litepal.crud.LitePalSupport;

public class CursorEntity extends LitePalSupport {
private Integer id;
private Boolean cursorSwitch; // 鼠标开关
private Integer planId;

public Integer getPlanId() {
return planId;
}

public void setPlanId(Integer planId) {
this.planId = planId;
}

public Integer getId() {
return id;
}

public void setId(Integer id) {
this.id = id;
}

public Boolean getCursorSwitch() {
return cursorSwitch;
}

public void setCursorSwitch(Boolean cursorSwitch) {
this.cursorSwitch = cursorSwitch;
}
}
17 changes: 16 additions & 1 deletion app/src/main/java/com/fde/keyassist/util/FileUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.content.Context;
import android.os.Environment;

import com.fde.keyassist.entity.CursorEntity;
import com.fde.keyassist.entity.DirectMappingEntity;
import com.fde.keyassist.entity.DoubleClickMappingEntity;
import com.fde.keyassist.entity.KeyMappingEntity;
Expand Down Expand Up @@ -66,6 +67,9 @@ public static void exportData(List<String> planNames, Context context){
List<ScaleMappingEntity> curScaleMappingEntity = new ArrayList<>();
curScaleMappingEntity = LitePal.where("planId = ?", plan.getId().toString()).find(ScaleMappingEntity.class);

// 获得鼠标事件
List<CursorEntity> cursorEntities = new ArrayList<>();
cursorEntities = LitePal.where("planId = ?", plan.getId().toString()).find(CursorEntity.class);


// 定义保存 JSON 文件的文件夹
Expand All @@ -87,7 +91,7 @@ public static void exportData(List<String> planNames, Context context){

exportListToJson(curScaleMappingEntity, new File(outputDir, plan.getPlanName()+"_scaleClick.json"));


exportListToJson(cursorEntities, new File(outputDir, plan.getPlanName()+"_cursorClick.json"));
}


Expand Down Expand Up @@ -156,6 +160,17 @@ public static void readJsonFilesFromFolder(File folder) {
}
}
}
if(keyName.getName().contains("cursorClick")){
List<CursorEntity> cursorEntities = readJsonFile(keyName, new TypeToken<ArrayList<CursorEntity>>(){}.getType());
if(cursorEntities != null && !cursorEntities.isEmpty()){
for(CursorEntity cursor : cursorEntities){
cursor.assignBaseObjId(0);
cursor.setId(null);
cursor.setPlanId(plan.getId());
cursor.save();
}
}
}
}
}
}
Expand Down
Binary file added app/src/main/res/drawable/key_mapping_cursor.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions app/src/main/res/layout/dropdown_menu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
android:layout_marginBottom="5dp"
android:layout_marginTop="10dp"
android:id="@+id/dropdown_menu_import"
android:src="@drawable/dropdown_menu_import"
android:src="@drawable/dropdown_menu_export"
android:layout_width="20dp"
android:layout_height="20dp"/>

Expand All @@ -39,7 +39,7 @@
android:layout_marginBottom="5dp"
android:layout_marginTop="10dp"
android:id="@+id/dropdown_menu_export"
android:src="@drawable/dropdown_menu_export"
android:src="@drawable/dropdown_menu_import"
android:layout_width="20dp"
android:layout_height="20dp"/>
</LinearLayout>
Expand Down
Loading

0 comments on commit 2cfc0c6

Please sign in to comment.