Skip to content

Commit

Permalink
Screen: Added Mediatek display color control
Browse files Browse the repository at this point in the history
(MTK GAMMA) (LiveDisplay) (KCAL analogue)
closes #124

Signed-off-by: sunilpaulmathew <sunil.kde@gmail.com>
  • Loading branch information
sunilpaulmathew committed Mar 6, 2022
1 parent 31591a8 commit 13fac92
Show file tree
Hide file tree
Showing 3 changed files with 146 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -103,6 +104,8 @@ protected void init() {
protected void addItems(List<RecyclerViewItem> items) {
if (Misc.haskcalRed() || Misc.haskcalGreen() || Misc.haskcalBlue()) {
kcalColorInit(items);
} else if (RGB.supported()) {
rgbColorInit(items);
} else if (mCalibration.hasColors()) {
screenColorInit(items);
}
Expand Down Expand Up @@ -206,6 +209,68 @@ public void onMove(SeekBarView seekBarView, int position, String value) {
}
}

private void rgbColorInit(List<RecyclerViewItem> 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<RecyclerViewItem> items) {
if (mCalibration.hasColors()) {
CardView screenColor = new CardView(getActivity());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* Copyright (C) 2022-2023 sunilpaulmathew <sunil.kde@gmail.com>
*
* This file is part of SmartPack Kernel Manager, which is a heavily modified version of Kernel Adiutor,
* originally developed by Willi Ye <williye97@gmail.com>
*
* 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 <http://www.gnu.org/licenses/>.
*
*/

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 <sunil.kde@gmail.com> 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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

}

0 comments on commit 13fac92

Please sign in to comment.