Dưới đây là những gì tôi nghĩ có thể làm việc:
Bạn sẽ cần các giá trị sau:
Red, Green, Blue, Alpha và Contrast (r, g, b, a, c)
lưu trữ chúng trong một sở thích sau khi sử dụng thanh trượt:
private SharedPreferences pref;
//In onCreate..
this.pref = getSharedPreferences("pref", 0);
//Method to save the values in Preferences
private void save()
{
SharedPreferences.Editor localEditor = this.pref.edit();
localEditor.putInt("a", this.a);
localEditor.putInt("r", this.r);
localEditor.putInt("g", this.g);
localEditor.putInt("b", this.b);
localEditor.putInt("c", this.c);
localEditor.commit();
}
Định nghĩa một lớp Clas s mở rộng chế độ xem và được sử dụng để vẽ các giá trị được áp dụng trên canvas.
import android.view.View;
import android.graphics.Canvas;
import android.content.Context;
public class Layer extends View
{
private int a;
private int b;
private int g;
private int r;
public Layer(Context context){
super(context)
}
protected void onDraw(Canvas canvas){
super.onDraw(canvas);
canvas.drawARGB(this.a, this.r, this.g, this.b);
}
public void setColor(int a, int r, int g, int b){
this.a = a;
this.r = r;
this.g = g;
this.b = b;
invalidate();
}
}
Tiếp theo viết một dịch vụ mà là vụ phải xử lý những thay đổi trong các giá trị và áp dụng chúng vào các cửa sổ.
public class ScreenAdjustService extends Service
{
//Handle everything here
}
// Khai báo điểm để áp dụng các giá trị được lưu trữ trong Prefs private static lớp xem; ... public static int r; static static int b; static tĩnh int g; tĩnh công cộng int a; static tĩnh int c;
Trong phương thức onCreate,
giá trị Nhận được lưu trước đó trong tùy chọn,
SharedPreferences localSharedPreferences = getSharedPreferences("pref", 0);
a = localSharedPreferences.getInt("a", 0);
r = localSharedPreferences.getInt("r", 0);
g = localSharedPreferences.getInt("g", 0);
b = localSharedPreferences.getInt("b", 0);
c = localSharedPreferences.getInt("c", 0);
bộ quan điểm để thiết lập các giá trị lấy ra,
view = new Layer(this);
redView = new Layer(this);
...
Thêm những quan điểm sang cửa sổ
//Pass the necessary values for localLayoutParams
WindowManager.LayoutParams localLayoutParams = new WindowManager.LayoutParams(...);
WindowManager localWindowManager = (WindowManager)getSystemService("window");
localWindowManager.addView(view, localLayoutParams);
localWindowManager.addView(redView, localLayoutParams);
localWindowManager.addView(greenView, localLayoutParams);
Viết phương pháp tái sử dụng
public static void setAlpha(int alpha){
//Handle all conditions
view.setColor(alpha, 0, 0, 0);
}
public static void setContrast(int contrast){
//Handle all conditions
view.setColor(c, 100, 100, 100);
}
public static void setRGB(int r, int g, int b){
//Handle all conditions
redView.setColor(r, 255, 0, 0);
greenView.setColor(g, 0, 255, 0);
blueView.setColor(b, 0, 0, 255);
}
Gọi các phương pháp này bất cứ nơi nào cần thiết sử dụng các lớp dịch vụ
ScreenAdjustService.setRGB(MyActivity.this.r, MyActivity.this.g, MyActivity.this.b);
ScreenAdjustService.setAlpha(MyActivity.this.a);
ScreenAdjustService.setContrast(MyActivity.this.c);
Đừng quên khai báo dịch vụ của bạn trong file xml Manifest
<service android:name=".ScreenAdjustService " />
tôi có thể đã bỏ lỡ một hoặc hai điều như tôi đã làm điều này trên bay, nhưng tôi nghĩ rằng điều này nên làm điều đó.
cũng vậy, bạn cần thêm cờ để chế độ xem luôn ở trên cùng. – tomwesolowski
Vì vậy, trong phương pháp này hoạt động phủ sóng này sẽ chuyển các sự kiện chạm đến hoạt động chồng chéo như thế nào? – Paras