Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7822997
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T08:05:44+00:00 2026-06-02T08:05:44+00:00

I’m currently trying to write an app for one special device running Android 2.3.4,

  • 0

I’m currently trying to write an app for one special device running Android 2.3.4, that places a system overlay on a precisely defined spot on the screen. This is why I am positioning the layer using absolute values.

I wrote an activity (including two buttons in the layout) that starts and stops a service displaying this overlay.

public class MyActivity extends Activity {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
}

public void showOverlay(View view) {
    Intent i = new Intent("myPackage.myService");
    startService(i);
}

public void hideOverlay(View view) {
    Intent i = new Intent("myPackage.myService");
    stopService(i);
}
}

And this is my service (which was also added to the manifest file).

public class MyService extends Service {    
ImageView iv;

@Override
    public IBinder onBind(Intent intent) {
    return null;
}

@Override
public void onCreate() {
    super.onCreate();

    int imageRes    =   0;

    final WindowManager.LayoutParams params = new WindowManager.LayoutParams(
            WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
            WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN,
            PixelFormat.TRANSLUCENT);

    params.gravity  =   Gravity.NO_GRAVITY;
    params.alpha    =   1; 

    switch (findRotation()) {
    case Surface.ROTATION_0:
        params.height = 12; params.width = 600; params.x = 0; params.y = 1012;
        imageRes = R.drawable.horizontal; 
        break;
    case Surface.ROTATION_180: 
        params.height = 12; params.width = 600; params.x = 0; params.y = 0;
        imageRes = R.drawable.horizontal; 
        break;
    case Surface.ROTATION_90: 
        params.height = 600; params.width = 12; params.x = 1012; params.y = 0;
        imageRes = R.drawable.vertical; 
        break;
    case Surface.ROTATION_270: 
        params.height = 600; params.width = 12; params.x = 0; params.y = 0;
        imageRes = R.drawable.vertical; 
        break;
    }

    final WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);        

    iv = new ImageView(getApplicationContext());
    iv.setClickable(false);
    iv.setImageResource(imageRes);
    iv.draw(new android.graphics.Canvas());
    wm.addView(iv, params);
}


private int findRotation() {
     Display display = ((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay();
     return display.getRotation();
}


@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
    onDestroy();    //I don't know how to to make the service reposition the layer, so I used this. Not nice but it works 
    onCreate();   
}


@Override
public void onDestroy() {
    super.onDestroy();
    if(iv != null) {
        ((WindowManager) getSystemService(WINDOW_SERVICE)).removeView(iv);
        iv = null;
    }
}
}

The image to display as overlay has the width (or heigth, I didn’t find a method to rotate drawabled at API level 10, so I used two images, one for horizontal display, one for vertical) of my device’s screen resolution in portrait mode (=600) and a heigth (or width) of 12 pixels. I want it to be positioned where the hardware buttons are, i.e. in portrait mode on the bottom, when turned 90° counter-clockwise on the right, when turned 180° on the top and so on.

This works well for a rotation of 0° and 90° (ccw), but for the other two orientations the image is displayed in the middle of the screen instead of at the top or on the left. What am I doing wrong?

EDIT 2012-04-19:
I have changed the value of params.y for ROTATION_180 to -1012, and this case works now. I don’t think this is expected behaviour, though. A similar change for ROTATION_270 did not work…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T08:05:45+00:00Added an answer on June 2, 2026 at 8:05 am

    OK, I’m sorry, I made a mistake when changing the parameters for ROTATION_270, when I wrote my edit.

    I got the code to do what I wanted, here’s what I did:

    I changed the y-param for 180° to -1012 and the x-param for 270° to -1012, too. Now, in all four orientations the image is displayed where the hardware buttons are.

    I write it down here just for the sake of completeness.

    (…)

    switch (findRotation()) {
        case Surface.ROTATION_0:
            params.height = 12; params.width = 600; params.x = 0; params.y = 1012;
            imageRes = R.drawable.horizontal; 
            break;
        case Surface.ROTATION_180: 
            params.height = 12; params.width = 600; params.x = 0; params.y = -1012;
            imageRes = R.drawable.horizontal; 
            break;
        case Surface.ROTATION_90: 
            params.height = 600; params.width = 12; params.x = 1012; params.y = 0;
            imageRes = R.drawable.vertical; 
            break;
        case Surface.ROTATION_270: 
            params.height = 600; params.width = 12; params.x = -1012; params.y = 0;
            imageRes = R.drawable.vertical; 
            break;
    }
    

    (…)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I am currently running into a problem where an element is coming back from
I need a function that will clean a strings' special characters. I do NOT
I'm trying to create an if statement in PHP that prevents a single post
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.