Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,22 @@
android:max="255"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>


<CheckBox
android:layout_below="@+id/blueControl"
android:id="@+id/bblOff"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:text="Turn off button backlight"/>


<LinearLayout
android:id="@+id/buttons"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/blueControl"
android:layout_below="@+id/bblOff"
android:orientation="horizontal"
android:layout_marginTop="10dp"
>
Expand Down
15 changes: 15 additions & 0 deletions src/com/hathy/shade/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
import android.support.v4.app.TaskStackBuilder;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.SeekBar;
import android.widget.CheckBox;
import android.widget.SeekBar.OnSeekBarChangeListener;

/**
Expand All @@ -26,8 +28,10 @@ public class MainActivity extends Activity implements OnSeekBarChangeListener {
SeekBar redSeek;
SeekBar greenSeek;
SeekBar blueSeek;
CheckBox bblOffCheckBox;

int alpha,red,green,blue;
boolean bblOff;

@Override
public void onCreate(Bundle savedInstanceState) {
Expand All @@ -46,21 +50,30 @@ private void initialize(){
redSeek=(SeekBar)findViewById(R.id.redControl);
greenSeek=(SeekBar)findViewById(R.id.greenControl);
blueSeek=(SeekBar)findViewById(R.id.blueControl);
bblOffCheckBox = (CheckBox) findViewById(R.id.bblOff);

alphaSeek.setOnSeekBarChangeListener(this);
redSeek.setOnSeekBarChangeListener(this);
greenSeek.setOnSeekBarChangeListener(this);
blueSeek.setOnSeekBarChangeListener(this);
bblOffCheckBox.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
bblOff = ((CheckBox) v).isChecked();
}
});

alpha=shared.getAlpha();
red=shared.getRed();
green=shared.getGreen();
blue=shared.getBlue();
bblOff=shared.getBblOff();

alphaSeek.setProgress(alpha);
redSeek.setProgress(red);
greenSeek.setProgress(green);
blueSeek.setProgress(blue);
bblOffCheckBox.setChecked(bblOff);

updateColor();
}
Expand Down Expand Up @@ -111,6 +124,7 @@ public void applyClick(View v){
shared.setRed(red);
shared.setGreen(green);
shared.setBlue(blue);
shared.setBblOff(bblOff);

Intent i=new Intent(MainActivity.this, MainService.class);
startService(i);
Expand Down Expand Up @@ -140,3 +154,4 @@ private void makeNotification(){
mNotificationManager.notify(0x355, nb.build());
}
}

19 changes: 17 additions & 2 deletions src/com/hathy/shade/MainService.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
import android.graphics.PixelFormat;
import android.os.IBinder;
import android.view.Gravity;
import android.view.Window;
import android.view.WindowManager;
import android.view.WindowManager.LayoutParams;
import android.widget.LinearLayout;
import android.widget.Toast;
import android.util.Log;

/**
* This is the class that is responsible for adding the filter on the
Expand All @@ -17,7 +20,7 @@
* @author Hathibelagal
*/
public class MainService extends Service {

public final static String TAG = "shade.MainService";
LinearLayout mView;
SharedMemory shared;

Expand Down Expand Up @@ -45,8 +48,20 @@ public void onCreate() {
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
0 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
| WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
| WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN, /* dim statusbar, too */
PixelFormat.TRANSLUCENT);
if(shared.getBblOff()) {
/* from https://github.com/TomTasche/ScreenFilter.git */
try {
WindowManager.LayoutParams.class.getField("buttonBrightness").set(params, Integer.valueOf(0));
}
catch (Exception ex) {
Log.w(TAG, "Cannot set button brightness");
ex.printStackTrace();
}
}
WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);
wm.addView(mView, params);
}
Expand Down
8 changes: 8 additions & 0 deletions src/com/hathy/shade/SharedMemory.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ void setBlue(int value){
prefs.edit().putInt("blue", value).commit();
}

void setBblOff(boolean value){
prefs.edit().putBoolean("bblOff", value).commit();
}

int getBlue(){
return prefs.getInt("blue", 0x00);
}
Expand All @@ -47,6 +51,10 @@ int getAlpha(){
return prefs.getInt("alpha", 0x33);
}

boolean getBblOff(){
return prefs.getBoolean("bblOff", true);
}

public static int getColor(int alpha, int red, int green, int blue){
String hex = String.format("%02x%02x%02x%02x", alpha, red, green, blue);
int color=(int)Long.parseLong(hex,16);
Expand Down