diff --git a/app/build.gradle b/app/build.gradle index dba4ead..f590f66 100755 --- a/app/build.gradle +++ b/app/build.gradle @@ -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 diff --git a/app/src/main/java/cn/modificator/launcher/SettingFramgent.java b/app/src/main/java/cn/modificator/launcher/SettingFramgent.java index b20b7b6..857699b 100755 --- a/app/src/main/java/cn/modificator/launcher/SettingFramgent.java +++ b/app/src/main/java/cn/modificator/launcher/SettingFramgent.java @@ -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; @@ -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. */ @@ -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); @@ -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); @@ -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() { @@ -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); @@ -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) { } @@ -148,6 +197,9 @@ public void onStopTrackingTouch(SeekBar seekBar) { updateStatus(); } + + + private int getAppLineSpinnerSelectPosition(){ if (Config.appNameLines<3)return Config.appNameLines; return 3; @@ -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 ? "显示分隔线" : "隐藏分隔线"); diff --git a/app/src/main/java/cn/modificator/launcher/jdreadutil/DeviceControl.java b/app/src/main/java/cn/modificator/launcher/jdreadutil/DeviceControl.java new file mode 100644 index 0000000..f0fb29c --- /dev/null +++ b/app/src/main/java/cn/modificator/launcher/jdreadutil/DeviceControl.java @@ -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); + } + + +} diff --git a/app/src/main/java/cn/modificator/launcher/jdreadutil/RefValue.java b/app/src/main/java/cn/modificator/launcher/jdreadutil/RefValue.java new file mode 100644 index 0000000..de8a788 --- /dev/null +++ b/app/src/main/java/cn/modificator/launcher/jdreadutil/RefValue.java @@ -0,0 +1,20 @@ +package cn.modificator.launcher.jdreadutil; + +public class RefValue { + 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; + } +} \ No newline at end of file diff --git a/app/src/main/java/cn/modificator/launcher/jdreadutil/ReflectUtil.java b/app/src/main/java/cn/modificator/launcher/jdreadutil/ReflectUtil.java new file mode 100644 index 0000000..a078ac1 --- /dev/null +++ b/app/src/main/java/cn/modificator/launcher/jdreadutil/ReflectUtil.java @@ -0,0 +1,190 @@ +package cn.modificator.launcher.jdreadutil; + +import android.util.Log; +import java.lang.reflect.Constructor; +import java.lang.reflect.Method; + +public class ReflectUtil { + private static final String a = "ReflectUtil"; + private static Object b = new Object(); + + public static boolean getConstructorSafely(RefValue> refValue, Class cls, Class... clsArr) { + if (cls == null) { + return false; + } + try { + refValue.setValue(cls.getConstructor(clsArr)); + return true; + } catch (SecurityException e) { + Log.w(a, e); + return false; + } catch (NoSuchMethodException e2) { + Log.w(a, e2); + return false; + } + } + + public static Constructor getConstructorSafely(Class cls, Class... clsArr) { + RefValue refValue = new RefValue(); + if (getConstructorSafely(refValue, cls, clsArr)) { + return (Constructor) refValue.getValue(); + } + return null; + } + + public static Class classForName(String str) { + try { + return Class.forName(str); + } catch (Exception e) { + Log.e(a, "", e); + return null; + } + } + + public static boolean getMethodSafely(RefValue refValue, Class cls, String str, Class... clsArr) { + if (cls == null) { + return false; + } + try { + refValue.setValue(cls.getMethod(str, clsArr)); + return true; + } catch (NoSuchMethodException | SecurityException unused) { + return false; + } + } + + public static Method getMethodSafely(Class cls, String str, Class... clsArr) { + RefValue refValue = new RefValue(); + if (getMethodSafely(refValue, cls, str, clsArr)) { + return (Method) refValue.getValue(); + } + return null; + } + + public static boolean getStaticIntFieldSafely(RefValue refValue, Class cls, String str) { + if (cls == null) { + return false; + } + try { + refValue.setValue(Integer.valueOf(cls.getField(str).getInt(null))); + return true; + } catch (IllegalArgumentException e) { + Log.w(a, e); + return false; + } catch (SecurityException e2) { + Log.w(a, e2); + return false; + } catch (IllegalAccessException e3) { + Log.w(a, e3); + return false; + } catch (NoSuchFieldException e4) { + Log.w(a, e4); + return false; + } + } + + public static int getStaticIntFieldSafely(Class cls, String str) { + RefValue refValue = new RefValue(); + if (getStaticIntFieldSafely(refValue, cls, str)) { + return ((Integer) refValue.getValue()).intValue(); + } + return 0; + } + + public static boolean getStaticFieldSafely(RefValue refValue, Class cls, String str) { + if (cls == null) { + return false; + } + try { + refValue.setValue(cls.getField(str).get(null)); + return true; + } catch (IllegalArgumentException e) { + Log.w(a, e); + return false; + } catch (SecurityException e2) { + Log.w(a, e2); + return false; + } catch (IllegalAccessException e3) { + Log.w(a, e3); + return false; + } catch (NoSuchFieldException e4) { + Log.w(a, e4); + return false; + } + } + + public static Object getStaticFieldSafely(Class cls, String str) { + RefValue refValue = new RefValue(); + if (getStaticFieldSafely(refValue, cls, str)) { + return refValue.getValue(); + } + return null; + } + + public static boolean constructObjectSafely(RefValue refValue, Constructor constructor, Object... objArr) { + if (constructor == null) { + return false; + } + try { + refValue.setValue(constructor.newInstance(objArr)); + return true; + } catch (Throwable th) { + Log.w(a, "", th); + return false; + } + } + + public static Object newInstance(Constructor constructor, Object... objArr) { + RefValue refValue = new RefValue(); + if (constructObjectSafely(refValue, constructor, objArr)) { + return refValue.getValue(); + } + return null; + } + + public static boolean invokeMethodSafely(RefValue refValue, Method method, Object obj, Object... objArr) { + if (method == null) { + return false; + } + try { + refValue.setValue(method.invoke(obj, objArr)); + return true; + } catch (Throwable th) { + Log.w(a, th); + return false; + } + } + + public static Object invokeMethodSafely(Method method, Object obj, Object... objArr) { + RefValue refValue = new RefValue(); + if (!invokeMethodSafely(refValue, method, obj, objArr)) { + return null; + } + if (refValue.getValue() != null) { + return refValue.getValue(); + } + return b; + } + + public static Method getDeclaredMethodSafely(Class cls, String str, Class... clsArr) { + RefValue refValue = new RefValue(); + if (getDeclaredMethod(refValue, cls, str, clsArr)) { + return (Method) refValue.getValue(); + } + return null; + } + + public static boolean getDeclaredMethod(RefValue refValue, Class cls, String str, Class... clsArr) { + if (cls == null) { + return false; + } + try { + Method declaredMethod = cls.getDeclaredMethod(str, clsArr); + declaredMethod.setAccessible(true); + refValue.setValue(declaredMethod); + return true; + } catch (NoSuchMethodException | SecurityException unused) { + return false; + } + } +} diff --git a/app/src/main/res/layout/activity_setting.xml b/app/src/main/res/layout/activity_setting.xml index 1453027..2226867 100755 --- a/app/src/main/res/layout/activity_setting.xml +++ b/app/src/main/res/layout/activity_setting.xml @@ -260,6 +260,8 @@ android:progress="40" android:progressDrawable="@drawable/progress_style" android:thumb="@drawable/progress_thumb_drawable" /> + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file