Issue
I am working on adding halo into cyanogenmod 11. And for that I am using a method which gets the state of halo being active or not, and then assigns image to it accordingly.
First, here's my code from latest try (I have made multiple attempts to do this task)->
protected void updateHalo() {
//mHaloActive is a boolean. mHaloButton is an ImageView
mHaloActive = Settings.System.getInt(mContext.getContentResolver(),
Settings.System.HALO_ACTIVE, 0) == 1;
int resID;
String mDrawableName;
if (mHaloActive) {
mDrawableName = "ic_notify_halo_pressed";
resID = getResources().getIdentifier(mDrawableName, "drawable", getPackageName());
mHaloButton.setImageResource(resID);
} else {
mDrawableName = "ic_notify_halo_normal";
resID = getResources().getIdentifier(mDrawableName, "drawable", getPackageName());
mHaloButton.setImageResource(resID);
}
if (mHaloActive) {
if (mHalo == null) {
LayoutInflater inflater = (LayoutInflater) mContext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
mHalo = (Halo) inflater.inflate(R.layout.halo_trigger, null);
mHalo.setLayerType(View.LAYER_TYPE_HARDWARE, null);
WindowManager.LayoutParams params = mHalo.getWMParams();
mWindowManager.addView(mHalo, params);
mHalo.setStatusBar(this);
}
} else {
if (mHalo != null) {
mHalo.cleanUp();
mWindowManager.removeView(mHalo);
mHalo = null;
}
}
}
Now here, it says cannot find symbol: method getPackageName()
Earlier I had made multiple attempts too like using setImageResource(R.drawable.ic_notify_halo_pressed);
But that was giving me NPE.
Then I also tried using:
Resources resources = getResources(); mHaloButton.setImageDrawable(resources.getDrawable(R.drawable.ic_notify_halo_pressed));
But this gave error cannot find symbol: method getResources()
And I also tried mHaloButton.setImageDrawable(R.drawable.ic_notify_halo_pressed);
but it gives error: setImageDrawable(android.graphics.drawable.Drawable) in android.widget.ImageView cannot be applied to (int)
So I know it needs resource ID, but how do I get that?
Please note: I am not building an application, and this is not a android studio project. I am trying to port halo to cyanogenmod 11.
Solution
Replace Resources resources = getResources();
with Resources resources = mContext.getResources();
since you have already a reference to Context.
Same for getPackageName()
. Replace it with mContext.getPackageName()
.
Answered By - Karim
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.