Skip to content

Commit

Permalink
Add front light controlling function for JDRead1
Browse files Browse the repository at this point in the history
  • Loading branch information
rs-sr committed Feb 6, 2021
1 parent 9920383 commit 723cafd
Show file tree
Hide file tree
Showing 6 changed files with 406 additions and 10 deletions.
14 changes: 8 additions & 6 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
//noinspection GradleDynamicVersion
apply plugin: 'com.android.application'
//apply plugin: 'com.jakewharton.hugo'
apply from: '../config.gradle'

Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())

android {
signingConfigs {
config {
keyAlias release.keyAlias
keyPassword release.keyPassword
storeFile release.storeFile
storePassword release.storePassword
storeFile file(properties.getProperty("keystore_storeFile"))
storePassword properties.getProperty("keystore_storePassword")
keyAlias properties.getProperty("keystore_keyAlias")
keyPassword properties.getProperty("keystore_keyPassword")
}
}
compileSdkVersion 29
buildToolsVersion '29.0.2'
defaultConfig {
applicationId "cn.modificator.launcher"
applicationId "com.onyx.launcher"
minSdkVersion 14
targetSdkVersion 29
versionCode 25
Expand Down
68 changes: 64 additions & 4 deletions app/src/main/java/cn/modificator/launcher/SettingFramgent.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
import android.net.NetworkInfo;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
Expand All @@ -20,13 +20,21 @@
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import java.lang.reflect.Method;

import java.util.Observable;
import androidx.annotation.NonNull;

import cn.modificator.launcher.ftpservice.FTPService;
import cn.modificator.launcher.jdreadutil.DeviceControl;
import cn.modificator.launcher.jdreadutil.ReflectUtil;
import cn.modificator.launcher.model.WifiControl;







/**
* Created by mod on 16-5-3.
*/
Expand All @@ -35,9 +43,11 @@ public class SettingFramgent extends Fragment implements View.OnClickListener {
Spinner row_num_spinner;
Spinner appNameLinesSpinner;
SeekBar font_control;
SeekBar light_control;
View rootView;
TextView hideDivider, ftpAddr, ftpStatus,showStatusBar,showCustomIcon;

DeviceControl device_control;
int LightValue;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand All @@ -62,6 +72,7 @@ public void onActivityCreated(Bundle savedInstanceState) {
ftpAddr = rootView.findViewById(R.id.ftp_addr);
hideDivider = rootView.findViewById(R.id.hideDivider);
font_control = rootView.findViewById(R.id.font_control);
light_control = rootView.findViewById(R.id.light_control);
col_num_spinner = rootView.findViewById(R.id.col_num_spinner);
row_num_spinner = rootView.findViewById(R.id.row_num_spinner);
appNameLinesSpinner = rootView.findViewById(R.id.appNameLine);
Expand All @@ -73,6 +84,11 @@ public void onActivityCreated(Bundle savedInstanceState) {
hideDivider.getPaint().setStrikeThruText(Config.hideDivider);
row_num_spinner.setSelection(Config.rowNum - 2, false);
font_control.setProgress((int) ((Config.fontSize - 10) * 10));

device_control = new DeviceControl();
LightValue = device_control.getFrontLightValue(getActivity());

light_control.setProgress(LightValue/2*5);
showCustomIcon.getPaint().setStrikeThruText(Config.showCustomIcon);

row_num_spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
Expand Down Expand Up @@ -120,7 +136,9 @@ public void onNothingSelected(AdapterView<?> parent) {
}
});
rootView.findViewById(R.id.btnHideFontControl).setOnClickListener(this);
rootView.findViewById(R.id.btnHideLightControl).setOnClickListener(this);
rootView.findViewById(R.id.changeFontSize).setOnClickListener(this);
rootView.findViewById(R.id.change_light).setOnClickListener(this);
rootView.findViewById(R.id.helpAbout).setOnClickListener(this);
rootView.findViewById(R.id.menu_ftp).setOnClickListener(this);

Expand All @@ -136,6 +154,37 @@ public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
}
}



@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}

@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});

light_control.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
if (fromUser) {
Log.e("P", String.valueOf(LightValue));

int light_value = 0;
if(progress/5.0 - progress/5 >= 0.5){
light_value = progress/5+1;
}
else{
light_value = progress/5;
}
seekBar.setProgress(light_value*5);
device_control.setFrontLightValue(getActivity(),Integer.valueOf(light_value*2));
device_control.setFrontLightConfigValue(getActivity(),Integer.valueOf(light_value*2));
Log.e("L", String.valueOf(light_value));
}
}

@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
Expand All @@ -148,6 +197,9 @@ public void onStopTrackingTouch(SeekBar seekBar) {
updateStatus();
}




private int getAppLineSpinnerSelectPosition(){
if (Config.appNameLines<3)return Config.appNameLines;
return 3;
Expand Down Expand Up @@ -182,10 +234,18 @@ public void onClick(View v) {
rootView.findViewById(R.id.menuList).setVisibility(View.VISIBLE);
rootView.findViewById(R.id.font_control_p).setVisibility(View.GONE);
break;
case R.id.btnHideLightControl:
rootView.findViewById(R.id.menuList).setVisibility(View.VISIBLE);
rootView.findViewById(R.id.light_control_p).setVisibility(View.GONE);
break;
case R.id.changeFontSize:
rootView.findViewById(R.id.menuList).setVisibility(View.GONE);
rootView.findViewById(R.id.font_control_p).setVisibility(View.VISIBLE);
break;
case R.id.change_light:
rootView.findViewById(R.id.menuList).setVisibility(View.GONE);
rootView.findViewById(R.id.light_control_p).setVisibility(View.VISIBLE);
break;
case R.id.hideDivider:
Config.hideDivider = !Config.hideDivider;
hideDivider.setText(Config.hideDivider ? "显示分隔线" : "隐藏分隔线");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package cn.modificator.launcher.jdreadutil;

import android.content.Context;

import java.lang.reflect.Method;

public class DeviceControl {

private Class<?> classForName;
private Method getFrontLightValueMethod;
private Method setFrontLightValueMethod;
private Method getFrontLightConfigValueMethod;
private Method setFrontLightConfigValueMethod;

public DeviceControl(){
classForName = ReflectUtil.classForName("android.onyx.hardware.DeviceController");
getFrontLightValueMethod = ReflectUtil.getMethodSafely(classForName, "getFrontLightValue", Context.class);
getFrontLightConfigValueMethod = ReflectUtil.getMethodSafely(classForName, "getFrontLightConfigValue", Context.class);
setFrontLightValueMethod = ReflectUtil.getMethodSafely(classForName, "setFrontLightValue", Context.class, Integer.TYPE);
setFrontLightConfigValueMethod = ReflectUtil.getMethodSafely(classForName, "setFrontLightConfigValue", Context.class, Integer.TYPE);;
}


public int getFrontLightValue(Context context)
{
return (Integer) invokeMethod(context,getFrontLightValueMethod, context);
}
public void setFrontLightValue(Context context,int v)
{
invokeMethod(context, setFrontLightValueMethod, new Object[]{context, v});
}
public int getFrontLightConfigValue(Context context)
{
return (Integer) invokeMethod(context,getFrontLightValueMethod, context);
}
public void setFrontLightConfigValue(Context context,int v)
{
invokeMethod(context, setFrontLightConfigValueMethod, new Object[]{context, v});
}


private Object invokeMethod(Context context, Method method, Object... objArr) {
if (method == null) {
return null;
}
return ReflectUtil.invokeMethodSafely(method, null, objArr);
}


}
20 changes: 20 additions & 0 deletions app/src/main/java/cn/modificator/launcher/jdreadutil/RefValue.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package cn.modificator.launcher.jdreadutil;

public class RefValue<T> {
private T a = null;

public RefValue() {
}

public RefValue(T t) {
this.a = t;
}

public T getValue() {
return this.a;
}

public void setValue(T t) {
this.a = t;
}
}
Loading

0 comments on commit 723cafd

Please sign in to comment.