From 13fac9267b11f08e32fb82d18f98d5e4f27075dc Mon Sep 17 00:00:00 2001 From: sunilpaulmathew Date: Sun, 6 Mar 2022 23:31:34 +0100 Subject: [PATCH] Screen: Added Mediatek display color control (MTK GAMMA) (LiveDisplay) (KCAL analogue) closes #124 Signed-off-by: sunilpaulmathew --- .../fragments/kernel/ScreenFragment.java | 65 +++++++++++++++ .../utils/kernel/screen/RGB.java | 80 +++++++++++++++++++ .../utils/kernel/screen/Screen.java | 2 +- 3 files changed, 146 insertions(+), 1 deletion(-) create mode 100644 app/src/main/java/com/smartpack/kernelmanager/utils/kernel/screen/RGB.java diff --git a/app/src/main/java/com/smartpack/kernelmanager/fragments/kernel/ScreenFragment.java b/app/src/main/java/com/smartpack/kernelmanager/fragments/kernel/ScreenFragment.java index 652a14c45..81199d0e2 100644 --- a/app/src/main/java/com/smartpack/kernelmanager/fragments/kernel/ScreenFragment.java +++ b/app/src/main/java/com/smartpack/kernelmanager/fragments/kernel/ScreenFragment.java @@ -38,6 +38,7 @@ import com.smartpack.kernelmanager.utils.kernel.screen.Gamma; import com.smartpack.kernelmanager.utils.kernel.screen.GammaProfiles; import com.smartpack.kernelmanager.utils.kernel.screen.Misc; +import com.smartpack.kernelmanager.utils.kernel.screen.RGB; import com.smartpack.kernelmanager.views.ColorTable; import com.smartpack.kernelmanager.views.recyclerview.CardView; import com.smartpack.kernelmanager.views.recyclerview.DropDownView; @@ -103,6 +104,8 @@ protected void init() { protected void addItems(List items) { if (Misc.haskcalRed() || Misc.haskcalGreen() || Misc.haskcalBlue()) { kcalColorInit(items); + } else if (RGB.supported()) { + rgbColorInit(items); } else if (mCalibration.hasColors()) { screenColorInit(items); } @@ -206,6 +209,68 @@ public void onMove(SeekBarView seekBarView, int position, String value) { } } + private void rgbColorInit(List items) { + if (RGB.hasMTKRGBControl()) { + CardView kcalCard = new CardView(getActivity()); + kcalCard.setTitle(getString(R.string.screen_color)); + + SeekBarView red = new SeekBarView(); + red.setTitle(getString(R.string.red)); + red.setMax(2000); + red.setProgress(RGB.getMTKRed()); + red.setOnSeekBarListener(new SeekBarView.OnSeekBarListener() { + @Override + public void onStop(SeekBarView seekBarView, int position, String value) { + RGB.setMTKRed((position), getActivity()); + } + + @Override + public void onMove(SeekBarView seekBarView, int position, String value) { + } + }); + + kcalCard.addItem(red); + + SeekBarView green = new SeekBarView(); + green.setTitle(getString(R.string.green)); + green.setMax(2000); + green.setProgress(RGB.getMTKGreen()); + green.setOnSeekBarListener(new SeekBarView.OnSeekBarListener() { + @Override + public void onStop(SeekBarView seekBarView, int position, String value) { + RGB.setMTKGreen((position), getActivity()); + } + + @Override + public void onMove(SeekBarView seekBarView, int position, String value) { + } + }); + + kcalCard.addItem(green); + + SeekBarView blue = new SeekBarView(); + blue.setTitle(getString(R.string.blue)); + blue.setMax(2000); + blue.setProgress(RGB.getMTKBlue()); + blue.setOnSeekBarListener(new SeekBarView.OnSeekBarListener() { + @Override + public void onStop(SeekBarView seekBarView, int position, String value) { + RGB.setMTKBlue((position), getActivity()); + } + + @Override + public void onMove(SeekBarView seekBarView, int position, String value) { + } + }); + + kcalCard.addItem(blue); + + if (kcalCard.size() > 0) { + items.add(kcalCard); + } + } + } + private void screenColorInit(List items) { if (mCalibration.hasColors()) { CardView screenColor = new CardView(getActivity()); diff --git a/app/src/main/java/com/smartpack/kernelmanager/utils/kernel/screen/RGB.java b/app/src/main/java/com/smartpack/kernelmanager/utils/kernel/screen/RGB.java new file mode 100644 index 000000000..486b7ed5e --- /dev/null +++ b/app/src/main/java/com/smartpack/kernelmanager/utils/kernel/screen/RGB.java @@ -0,0 +1,80 @@ +/* + * Copyright (C) 2022-2023 sunilpaulmathew + * + * This file is part of SmartPack Kernel Manager, which is a heavily modified version of Kernel Adiutor, + * originally developed by Willi Ye + * + * Both SmartPack Kernel Manager & Kernel Adiutor are free softwares: you can redistribute it + * and/or modify it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * SmartPack Kernel Manager is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with SmartPack Kernel Manager. If not, see . + * + */ + +package com.smartpack.kernelmanager.utils.kernel.screen; + +import android.content.Context; + +import com.smartpack.kernelmanager.fragments.ApplyOnBootFragment; +import com.smartpack.kernelmanager.utils.Utils; +import com.smartpack.kernelmanager.utils.root.Control; + +/** + * Created by sunilpaulmathew on March 06, 2022 + */ +public class RGB { + + private static final String MTK_RGB = "/sys/devices/platform/mtk_disp_mgr.0/rgb"; + + public static boolean hasMTKRGBControl() { + return Utils.existFile(MTK_RGB); + } + + public static int getMTKRed() { + return Utils.strToInt(getMTKRGB().split(" ")[0]); + } + + public static int getMTKGreen() { + return Utils.strToInt(getMTKRGB().split(" ")[1]); + } + + public static int getMTKBlue() { + return Utils.strToInt(getMTKRGB().split(" ")[2]); + } + + public static String getMTKRGB() { + return Utils.readFile(MTK_RGB); + } + + public static void setMTKRed(int red, Context context) { + String value = red + " " + getMTKGreen() + " " + getMTKBlue(); + run(Control.write(value, MTK_RGB), MTK_RGB, context); + } + + public static void setMTKGreen(int green, Context context) { + String value = getMTKRed() + " " + green + " " + getMTKBlue(); + run(Control.write(value, MTK_RGB), MTK_RGB, context); + } + + public static void setMTKBlue(int blue, Context context) { + String value = getMTKRed() + " " + getMTKGreen() + " " + blue; + run(Control.write(value, MTK_RGB), MTK_RGB, context); + } + + public static boolean supported() { + return hasMTKRGBControl(); + } + + private static void run(String command, String id, Context context) { + Control.runSetting(command, ApplyOnBootFragment.SCREEN, id, context); + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/smartpack/kernelmanager/utils/kernel/screen/Screen.java b/app/src/main/java/com/smartpack/kernelmanager/utils/kernel/screen/Screen.java index 8672cd576..46ee5b993 100644 --- a/app/src/main/java/com/smartpack/kernelmanager/utils/kernel/screen/Screen.java +++ b/app/src/main/java/com/smartpack/kernelmanager/utils/kernel/screen/Screen.java @@ -26,7 +26,7 @@ public class Screen { public static boolean supported() { return Calibration.getInstance().supported() || Gamma.supported() - || Misc.getInstance().supported(); + || Misc.getInstance().supported() || RGB.supported(); } }