Skip to content

Instantly share code, notes, and snippets.

@beerbong
Last active August 29, 2015 13:56
Show Gist options
  • Save beerbong/9066787 to your computer and use it in GitHub Desktop.
Save beerbong/9066787 to your computer and use it in GitHub Desktop.
/*
* Copyright © 2014 Andre "ayysir" Saddler
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ayysir.paek.fragments;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CompoundButton;
import android.widget.Switch;
import com.ayysir.paek.R;
import com.ayysir.paek.interfaces.KernelInfo;
import com.ayysir.paek.tools.Constants;
import java.util.ArrayList;
import eu.chainfire.libsuperuser.Shell;
public class KernelSpecific extends Fragment
implements KernelInfo, CompoundButton.OnCheckedChangeListener {
ArrayList<Switch> buttons;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
SharedPreferences sharedPreferences = PreferenceManager
.getDefaultSharedPreferences(getActivity());
View v = inflater.inflate(R.layout.kernel_specifics, container, false);
buttons = new ArrayList<Switch>();
assert v != null;
boolean checked = sharedPreferences.getBoolean("FFC_Switch", false);
Switch ffc = (Switch) v.findViewById(R.id.ffc);
ffc.setChecked(checked);
buttons.add(ffc);
Switch ko = (Switch) v.findViewById(R.id.knockon);
checked = sharedPreferences.getBoolean("KO_Switch", false);
ko.setChecked(checked);
buttons.add(ko);
ffc.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
Shell.SU.run("chmod 755 /sys/kernel/fast_charge/force_fast_charge");
Shell.SU.run("echo 1 > /sys/kernel/fast_charge/force_fast_charge");
Log.d(Constants.LOG_TAG, "FFC ON");
} else {
Shell.SU.run("chmod 755 /sys/kernel/fast_charge/force_fast_charge");
Shell.SU.run("echo 0 > /sys/kernel/fast_charge/force_fast_charge");
Log.d(Constants.LOG_TAG, "FFC OFF");
}
SharedPreferences sharedPreferences = PreferenceManager
.getDefaultSharedPreferences(getActivity());
SharedPreferences.Editor ffc = sharedPreferences.edit();
ffc.putBoolean("FFC_Switch", isChecked);
ffc.commit();
}
});
ko.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
Shell.SU.run("chmod 755 /sys/devices/virtual/input/lge_touch/touch_gesture");
Shell.SU.run("echo 1 > /sys/devices/virtual/input/lge_touch/touch_gesture");
Log.d(Constants.LOG_TAG, "Knock ON");
} else {
Shell.SU.run("chmod 755 /sys/devices/virtual/input/lge_touch/touch_gesture");
Shell.SU.run("echo 0 > /sys/devices/virtual/input/lge_touch/touch_gesture");
Log.d(Constants.LOG_TAG, "Knock OFF");
}
SharedPreferences sharedPreferences = PreferenceManager
.getDefaultSharedPreferences(getActivity());
SharedPreferences.Editor ko = sharedPreferences.edit();
ko.putBoolean("KO_Switch", isChecked);
ko.commit();
}
});
return v;
}
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment