ステータスバーにもフィルターをかけたい
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="add Filter"
android:id="@+id/ButtonAddFilter"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Remove Filter"
android:id="@+id/ButtonRemoveFilter"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
</RelativeLayout>
MainActivity.java
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button buttonAddFilter = (Button) findViewById(R.id.ButtonAddFilter);
buttonAddFilter.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, FilterService.class);
startService(intent);
}
});
Button buttonRemoveFilter = (Button) findViewById(R.id.ButtonRemoveFilter);
buttonRemoveFilter.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, FilterService.class);
stopService(intent);
}
});
}
}
filter.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
FilterService.java
public class FilterService extends Service {
private View mView;
private WindowManager mWindowManager;
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
LayoutInflater layoutInflater = LayoutInflater.from(this);
WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams(
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH,
PixelFormat.TRANSLUCENT
);
mWindowManager = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
mView = layoutInflater.inflate(R.layout.filter, null);
mView.setBackgroundColor(Color.argb(80, 0, 0, 0));
mWindowManager.addView(mView, layoutParams);
return START_NOT_STICKY;
}
@Override
public void onDestroy() {
super.onDestroy();
mWindowManager.removeView(mView);
}
@Nullable
@Override
public IBinder onBind(Intent intent) {
return null;
}
}
これは画面にフィルターをかける処理です。この場合、ステータスバーが暗くなりません。
ステータスバーの場所までmWindowManagerを反映させる、またはステータスバーを違和感が無いように暗くする処理はあるのでしょうか。