@Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { super.onCreateView(inflater, container, savedInstanceState); View v = inflater.inflate(R.layout.layout_list, container, false); File f = new File("/sys/block/mmcblk0/queue/iosched"); String curSched = Helpers.getCurrentScheduler(); File[] files = f.listFiles(); if (files.length != 0) { MainActivity.menu.setEnabled(false); addPreferences(); mCategory.setTitle(curSched + " Tweakable values"); } else { Preference pref = new Preference(mContext); pref.setTitle("No tweakable values"); pref.setSummary(curSched + " Doesn\'t have tweakable values"); mCategory.addPreference(pref); } return v; }
@Override protected String doInBackground(String... params) { if (mCategory.getPreferenceCount() != 0) { mCategory.removeAll(); } File f = new File("/sys/block/mmcblk0/queue/iosched"); File[] files = f.listFiles(); for (File file : files) { String fileName = file.getName(); String filePath = file.getAbsolutePath(); final String fileContent = Helpers.getFileContent(file); CustomPreference pref = new CustomPreference(mContext, true, category); pref.setTitle(fileName); String color = "#ff0099cc"; if (MainActivity.mPrefs.getBoolean(SettingsFragment.KEY_ENABLE_GLOBAL, false)) { int col = MainActivity.mPrefs.getInt( SettingsFragment.KEY_GLOBAL_COLOR, Color.parseColor("#ff0099cc")); color = "#" + Integer.toHexString(col); pref.setTitleColor(color); } else { pref.setTitleColor(color); } pref.setSummary(fileContent); pref.setKey(filePath); mCategory.addPreference(pref); pref.setOnPreferenceClickListener( new OnPreferenceClickListener() { @Override public boolean onPreferenceClick(final Preference p) { // TODO Auto-generated method stub AlertDialog.Builder builder = new AlertDialog.Builder(mContext); LinearLayout ll = new LinearLayout(mContext); ll.setLayoutParams( new LinearLayout.LayoutParams( LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.MATCH_PARENT)); final EditText et = new EditText(mContext); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); params.setMargins(40, 40, 40, 40); params.gravity = Gravity.CENTER; String val = p.getSummary().toString(); et.setLayoutParams(params); et.setRawInputType(InputType.TYPE_CLASS_NUMBER); et.setGravity(Gravity.CENTER_HORIZONTAL); et.setText(val); ll.addView(et); builder.setView(ll); builder.setPositiveButton( "ok", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub String value = et.getText().toString(); p.setSummary(value); // Log.d("TEST", "echo "+value+" > "+ p.getKey()); CMDProcessor.runSuCommand("echo " + value + " > " + p.getKey()); updateListDb(p, value, ((CustomPreference) p).isBootChecked()); } }); AlertDialog dialog = builder.create(); dialog.show(); dialog.getWindow().getAttributes().windowAnimations = R.style.dialog_animation; Window window = dialog.getWindow(); window.setLayout(800, LayoutParams.WRAP_CONTENT); return true; } }); } return "Executed"; }