[TIMOB-10066] Android: Allow for transparent activities
| GitHub Issue | n/a |
|---|---|
| Type | New Feature |
| Priority | High |
| Status | Closed |
| Resolution | Hold |
| Resolution Date | 2012-12-11T18:40:41.000+0000 |
| Affected Version/s | Release 2.1.0 |
| Fix Version/s | 2012 Sprint 25, 2012 Sprint 25 API |
| Components | Android |
| Labels | api |
| Reporter | Rick Blalock |
| Assignee | Karl Rowley |
| Created | 2012-07-20T15:55:40.000+0000 |
| Updated | 2013-03-30T16:47:44.000+0000 |
Description
We need a way to have a transparent activity on top of another app. Here is some information:
http://abtandroid.blogspot.com/2011/08/small-tutorial-on-creating-transparent.html
http://www.coderzheaven.com/2011/07/20/how-to-create-a-transparent-activity-in-android/
An app that does something similar to what the customer wants to do: https://play.google.com/store/apps/details?id=at.neiti.scribblesmart
Here is the source: https://github.com/mneubrand/scribble-smart
This possibly is a module request or is even possible just with the theme manifests. If so I'll need some guidance on the best way to tackle this.
Attachments
| File | Date | Size |
|---|---|---|
| Archive.zip | 2012-07-23T16:58:01.000+0000 | 750636 |
| IMG_3009.MOV | 2012-07-23T15:38:13.000+0000 | 1814938 |
Moving to sprint 17. Trading for some 2.1.2 requests
De-prioritizing this feature based on the discussion with services team.
Here's an example of a transparent activity.
layout/main.xml:package com.alert; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.util.Log; import android.view.Gravity; import android.view.View; import android.view.View.OnClickListener; import android.view.Window; import android.view.WindowManager; import android.widget.Button; public class ServicesDemo extends Activity implements OnClickListener { private static final String TAG = "ServicesDemo"; Button buttonStart, buttonStop; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Window window = getWindow(); window.setLayout(100, 100); window.setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL, WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL); window.setGravity(Gravity.LEFT); window.setContentView(R.layout.main) } @Override public void onClick(View v) { // TODO Auto-generated method stub } }values/styles.xml:AndroidManifest.xml:<resources> <style name="AppTheme" parent="android:Theme.Light" /> <style name="Theme.Transparent" parent="android:Theme"> <item name="android:windowIsTranslucent">true</item> <item name="android:windowBackground">@android:color/transparent</item> <item name="android:windowContentOverlay">@null</item> <item name="android:windowNoTitle">true</item> <item name="android:windowIsFloating">true</item> <item name="android:backgroundDimEnabled">false</item> </style> </resources>Here's a transparent activity that's started from a broadcast receiver (listening for changes to phone state):
package com.phone; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.util.Log; import android.view.Gravity; import android.view.View; import android.view.View.OnClickListener; import android.view.Window; import android.view.WindowManager; import android.widget.Button; public class ButtonActivity extends Activity implements OnClickListener { private static final String TAG = "ServicesDemo"; Button buttonStart, buttonStop; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Window window = getWindow(); window.setLayout(100, 100); window.setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL, WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL); window.setGravity(Gravity.LEFT); window.setContentView(R.layout.main); } @Override public void onClick(View v) { // TODO Auto-generated method stub } }package com.phone; import android.app.Activity; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.util.Log; public class IncomingReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { Log.i("com.phone", "onReceive"); try { Intent activityIntent = new Intent(context, ButtonActivity.class); activityIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(activityIntent); Log.i("com.phone", "Started activity"); } catch (Exception exp) { Log.i("com.phone", "Caught exception trying to start activity " + exp.toString()); } } }AndroidManifest.xml<resources> <style name="AppTheme" parent="android:Theme.Light" /> <style name="Theme.Transparent" parent="android:Theme"> <item name="android:windowIsTranslucent">true</item> <item name="android:windowBackground">@android:color/transparent</item> <item name="android:windowContentOverlay">@null</item> <item name="android:windowNoTitle">true</item> <item name="android:windowIsFloating">true</item> <item name="android:backgroundDimEnabled">false</item> </style> </resources>A Javascript version of the transparent activity would look something like the following. A problem here is that the activity in the background does not show through -- I am not sure how to bypass the splash screen here so that the existing activity shows.
var win = Titanium.UI.createWindow({ id: "propertyWindow", title: "My New Window", modal: true, width:100, height: 100, top: 100, left: 0, full: false, opacity: 0.5, topMost: true, visible: true, transparentBackground: true, transparency: true }); var button = Titanium.UI.createButton({title: "Button"}); button.height=100; button.width=100; button.left=0; button.top=100; win.add(button); win.width=100; win.height=100; win.left=0; win.top=100; win.open();Module needs to be be 2.1.X compatible (and should also work on 3.0.0). Once we've figured out for sure this is a module item, be can move the ticket and remove the merge tags.
Should we resolve this ticket as "on hold" until the module is done?
That's actually already possible. I already do it. You only need to use android theming system. Use a style like this And it will give you a transparent window