Guest User

Untitled

a guest
Jan 22nd, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. package com.android.systemui.statusbar.preferences;
  2.  
  3. import android.content.*;
  4. import android.view.*;
  5. import android.widget.*;
  6. import android.provider.*;
  7. import java.util.List;
  8. import java.util.ArrayList;
  9. import android.net.Uri;
  10. import java.io.*;
  11. import com.android.systemui.statusbar.preferences.*;
  12.  
  13. public class TorchController extends SettingsController {
  14.  
  15. private ContentResolver mContentResolver;
  16.  
  17. public TorchController (Context context, View button) {
  18. super (context, button);
  19.  
  20. mContentResolver = context.getContentResolver();
  21. }
  22.  
  23. protected int getPreferenceStatus () {
  24. try {
  25. BufferedReader reader = new BufferedReader(new FileReader("/sys/class/leds/torch/brightness"));
  26. int currentValue = Integer.parseInt(reader.readLine());
  27. reader.close();
  28. if (currentValue == 0)
  29. return 0;
  30. return 1;
  31. }catch (IOException e){
  32. return 0;
  33. }
  34. }
  35.  
  36. protected void setPreferenceStatus(int status) {
  37. try {
  38. BufferedWriter writer = new BufferedWriter(new FileWriter("/sys/class/leds/torch/brightness"));
  39. String output = "" + (status * 48);
  40. writer.write(output.toCharArray(), 0, output.toCharArray().length);
  41. writer.close();
  42. }catch (IOException e){
  43.  
  44. }
  45. }
  46.  
  47. protected String getSettingsIntent() {
  48. return null;
  49. }
  50.  
  51. protected int getDrawableIcon() {
  52. int status = getPreferenceStatus();
  53.  
  54. switch (status) {
  55. case 0: return 0x7f0200f6;
  56. case 1: return 0x7f0200f5;
  57. }
  58.  
  59. return 0x0;
  60. }
  61.  
  62. }
Add Comment
Please, Sign In to add comment