Android screen "watermarked" - android

How could be done such thing, like "watermark" on top of any other Activities on Android?
In detail: I need to show some message on top of everything what is running on my device. No matter if this is game, movie, app.
Is possible to achive something on Android? My phone is rooted.
Is possible to use some OpenGL features?

Use this code.
At first, I am using here FrameLayout, that is transparent and you can see "watermarked" text on image.
At second, I am using android:background="#99 000000" on my button and you also can see it on the image. First 2 digits, as i know, named alpha channel and you can set them from 0 to ff; 0 is fully transparent, and ff is non-transparent, as usual.
I think you get the idea or may be you can draw your custom image on canvas, put on your framelayout and set 50% trasparent-background. And you have to do this 50% transparent layers onto all your layouts and so, all activities will have watermark.
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/frameLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<FrameLayout
android:id="#+id/frameLayout2"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:src="#drawable/ic_launcher" />
</FrameLayout>
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
android:background="#99000000" />
</LinearLayout>
</FrameLayout>

Use a master activity which have layout according to you. And then use this master activity in other activity by extending to child activity.
Its simple.

Yes, it is possible to run a base activity and over that some intended activity to perform the action you want.
Now, you can use the concept of sub-activities and activities in android to ensure this type of result.

Related

Is it okay to use the same layout for two different activities?

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="92dp"
android:text="Start Download" />
</LinearLayout>
Both activities have to perform the same things.The only difference is the type of data they handles.
Just for curiosity I am asking this question.
Yes, there's no problem with that technically. Just remember that if you change anything for one activity it will change for both, so its best suited for very simple layouts. But frequently I'll use the same placeholder for 4 or 5 activities that aren't written yet, or I'll use the same layout for placeholder listview elements.

How to handle multitouch events in Android with multiple nested layouts?

I am designing an Android application and I would like to find a way to handle multitouch between multiple nested views.
My layout is as following:
Relative layout
|
|---Linear layout
| \---Linear layout
| \--Button A
|
|---Linear layout
\---Button B
The two buttons take approximately 50% of the screen size. I would like to be able to press the two buttons at the same time one after the other. I can press button B and then A but when I press A, I'm not able to press B.
It seems that it's a normal behaviour if we consider the way that Android handles event. I googled my problem and I only found complex solutions that involve rewriting a custom view and the "DispatchTouchEvent" method.
Do you know if there's a easy way to avoid that behaviour (being able to press A then B and B and then A)?
I wrote a minimal example: run an activity with the following layout
<?xml version="1.0" encoding="utf-8"?>
<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:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:splitMotionEvents="true"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="epl.groupe16.testbutton.MainActivity">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:text="New Button"
android:id="#+id/button" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:weightSum="2">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="New Button"
android:id="#+id/button21"
/>
</LinearLayout>
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="New Button"
android:id="#+id/button20"
android:layout_weight="1"
android:visibility="invisible" />
</LinearLayout>
I can press the lowest button, hold my touch and then click on the upper button but if I try the highest first, the lowest isn't clickable.
Thank you in advance
Finally we found that there's no easy solution for this.
But there was some workarounds that I would like to share if somebody had the same problem.
First, there's a manual way to do that: reconding a proper way to propagate event by creating custom views and overwriting the method "DispatchTouchEvent". It's quite long but it can solve the problem.
Also, Google added a PercentRelativeLayout in API 23, so you can place all of your components in a single view. But, we were targetting API 19 and Android Marshmallow doesn't represent a huge percentage of the current devices.
Finally, we decided to code our custom SurfaceView and touchEvent listener. We drawed our components in a SurfaceView and handled clics manually.
I hope it will help you :)

Android screen rendered really wrong

I'm using a GLSurfaceView to render a live wallpaper behind my apps interface which consists of android UI elements.
In the beginning of my app I ask the user if they would like to see this wallpaper or not.
ONLY if the user accepts the GLSurfaceView is inflated in the existing xml as a first element so it will stay behind.
My problem is exactly the opposite of what i would think it would.
When the wallpaper is ACTIVATED the screen renders properly, like so:
When I don't use the wallpaper it's rendered like a, partially burned graphic card:
As you see from the xml structure, my GLSurfaceView is not even injected in the problematic case.
Something weird is that when it's injected the DDMS Monitor displays it as just
If the opposite was the case it would be clear that the problem is caused by the GLSurfaceView. But now it seems as if the lack of it causes this problem.
Any ideas on what could be the problem?
I'm using Nexus 4 to test and it seems that it could be related based on DanJAB
XML layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
style="?metaButtonBarButtonStyle"
android:id="#+id/home_history"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="#+id/button_calibrator"
android:text="#string/history"/>
<View
android:id="#+id/button_calibrator"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/home_history"
android:layout_alignBottom="#+id/home_history"
android:layout_centerHorizontal="true"/>
<Button
style="?metaButtonBarButtonStyle"
android:id="#+id/home_help"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_toRightOf="#+id/button_calibrator"
android:text="#string/help"/>
<View
android:id="#+id/screen_menu_seperator"
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_below="#+id/home_history"
android:background="#color/holo_blue"/>
<ListView
android:id="#+id/homescreen_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/screen_menu_seperator"
android:background="#android:color/transparent"
android:cacheColorHint="#android:color/transparent"/>
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_alignParentBottom="true"
android:background="#color/holo_blue"/>
</RelativeLayout>
GLSurfaceView XML:
<?xml version="1.0" encoding="utf-8"?>
<android.opengl.GLSurfaceView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/background"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:visibility="gone"/>
and in java:
getLayoutInflater().inflate(R.layout.background, contents);
GLSurfaceView background = (GLSurfaceView) contents.findViewById(R.id.background);
This is a phone bug. Nexus 4 causes this issue with certain theme configurations.

Android Button Layout - Not Displaying Correctly

I am trying to get three images to display on the "welcome screen" of my Android app. Only one of the images is being displayed, and I cant figure out why... any Help?
XML File:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:background="#drawable/main_bg"
>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:paddingTop="30dip"
android:layout_height="wrap_content"
android:gravity="center"
>
<ImageButton
android:id="#+id/mnwvbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="15dip"
android:background="#drawable/mnwvicon" />
<ImageButton
android:id="#+id/reportsbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/reportsicon" />
</LinearLayout>
<ImageButton
android:id="#+id/mnwvshowbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/showicon"
android:paddingTop="30dip" />
</LinearLayout>
I have the exact same set up in another app, so I dont know why it isnt working here??
I think its because the last image is outside the inner linearlayout so put it inside the inner linearlayout and you should be able to see all three images in a row.
Try scaling the images using the attribute android:ScaleType="centre" inside the ImageButton
or try a different layout like Tablayout for arranging the images in rows and columns with proper spacing.
Sorry guys. I didnt have the app support the different screen sizes. I am not sure why this mattered, but once I added support, then it worked perfectly!. Thanks for your input though! Anyone know why this mattered though?? I dont know why supporting screen sizes matters?

Angry birds like Floating menu on Android

Does anyone know how to make a floating menu like the ones in Angry Birds home screen?
Here is a picture showing the menu buttons in collapsed mode (gear, up buttons). On tapping these buttons, the actual menu would expand, showing two or more round buttons.
Any links, clues is much appreciated.
I might be wrong but I think that the entire thing is done in OpenGL.
I guess it's an image with a transparent background and you calculate its position based on time....
Although you could achieve it with standard widgets, maybe it would be a better idea to create a custom view and implement onDraw()
This is done within the XML of your 'game screen.' Assuming you've done a tutorial on OpenGL-ES, you should have an xml file that holds your custom GLSurfaceView. To add overlay items like buttons and, well.. anything, just add them to this xml file. Here's an example of a game I'm working on:
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
//This is your GLSurfaceView which will fill the whole screen
<android.opengl.GLSurfaceView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/GLSurface" />
//This layout will overlay the game
<LinearLayout
android:gravity="center"
android:weightSum="100"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:layout_weight="10"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Sel"
/>
<SeekBar
android:paddingLeft="30px"
android:paddingRight="30px"
android:layout_weight="80"
android:gravity="center"
android:id="#+id/RotateBar"
android:layout_width="180px"
android:layout_height="wrap_content"
android:max="180"
/>
<Button
android:layout_weight="10"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Act"
/>
</LinearLayout>
Obviously this is modified (I don't have buttons floating in the center of the screen :P ) but you get the idea. Here's a link to good OpenGL-ES tutorial: link

Categories

Resources