2012-11-15 7 views
6

Androidの性質上、これは可能ではないと思われますが、すべてのアプリケーションの上に表示されるソート(おそらくCanvasオブジェクトを使用していますか?)のビューを作成する方法はありますか?すべてのアプリケーションの上にAndroidキャンバスを描画しますか?

このプロジェクトの目的は悪意のあるわけではありません。私はいくつかのWindows用simple Color Filter softwareを作成しました。これは、すべてのウィンドウの上にウィンドウを追加するだけで、ユーザーが選択した色で塗りつぶされ、不透明度が低くなりました。これにより、画面に明るい色合いが加わり、痙攣感覚症候群のユーザーがコンピュータを長期間使用するのに役立ちます。私はこのソフトウェアのAndroid版を作りたいと思います。たとえば、次のように

Color Filter for Android Example

左の画像がオリジナルで、右のは、私が達成しようとしているものです。

Androidでこれを行う方法はありますか?私はアプリケーションが予期せず停止されないようにシステムサービスとして実行する必要があることを理解していますが、私の知る限り、一般的に他のアプリケーションの上に画面を描画する方法はありません。可能であれば、調べるAPIを提案できますか?ここで

答えて

11

は私が働くかもしれないと思うものです:

次の値が必要になります。

赤、緑、青、アルファとコントラスト(R、G、B、C)

をスライダーを使用した後に優先して

ストアそれら:

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(); 
    } 

はレイヤーCLASの定義ビューを拡張し、適用された値をキャンバスに描画するために使用されます。

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(); 
    } 
} 

これらの値の変更を処理し、それらをウィンドウに適用するサービスを作成します。

public class ScreenAdjustService extends Service 
{ 
    //Handle everything here 
} 

//環境設定 プライベート静的レイヤビューに格納された値を適用するためのビューを宣言します。 ... パブリックstatic int r; パブリックstatic int b; public static int g; パブリックstatic int a; public static int c; onCreateメソッドで

以前の好みに格納された値、取得した値を設定するための

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); 

セットビュー、

view = new Layer(this); 
redView = new Layer(this); 
... 

が窓

にこれらのビューを追加取得
//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); 
私は

ScreenAdjustService.setRGB(MyActivity.this.r, MyActivity.this.g, MyActivity.this.b); 
ScreenAdjustService.setAlpha(MyActivity.this.a); 
ScreenAdjustService.setContrast(MyActivity.this.c); 

マニフェストXMLファイルにあなたのサービスを宣言することを忘れないでください

<service android:name=".ScreenAdjustService " /> 

サービスクラスをかもしれません使用してどこに必要な

は、再利用可能な方法

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); 
} 

コールこれらのメソッドを書きます私はこれを飛行機でやったのと同じことを2回も逃してしまったのですが、これがそうするべきだと私は考えています。

+0

また、ビューに常にフラグを追加する必要があります。 – tomwesolowski

+0

だから、このアプローチでは、このオーバーレイされたアクティビティは、オーバーラップしたアクティビティにタッチイベントをどのように渡しますか? – Paras

関連する問題