Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-10066] Android: Allow for transparent activities

GitHub Issuen/a
TypeNew Feature
PriorityHigh
StatusClosed
ResolutionHold
Resolution Date2012-12-11T18:40:41.000+0000
Affected Version/sRelease 2.1.0
Fix Version/s2012 Sprint 25, 2012 Sprint 25 API
ComponentsAndroid
Labelsapi
ReporterRick Blalock
AssigneeKarl Rowley
Created2012-07-20T15:55:40.000+0000
Updated2013-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

FileDateSize
Archive.zip2012-07-23T16:58:01.000+0000750636
IMG_3009.MOV2012-07-23T15:38:13.000+00001814938

Comments

  1. Vishal Duggal 2012-08-06

    Moving to sprint 17. Trading for some 2.1.2 requests
  2. Neeraj Gupta 2012-08-09

    De-prioritizing this feature based on the discussion with services team.
  3. Karl Rowley 2012-11-01

    Here's an example of a transparent activity.
       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
       	
       }
        
       }
       
    layout/main.xml:
       <?xml version="1.0" encoding="utf-8"?>
       <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
           android:id="@+id/FrameLayout1"
           android:layout_width="100dp"
           android:layout_height="100dp" >
       
           <Button
               android:id="@+id/button1"
               android:layout_width="match_parent"
               android:layout_height="match_parent"
               android:layout_gravity="top"
               android:text="Button" />
       
       </FrameLayout>
       
    values/styles.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>
       
    AndroidManifest.xml:
       <manifest xmlns:android="http://schemas.android.com/apk/res/android"
           package="com.alert"
           android:versionCode="1"
           android:versionName="1.0" >
       
           <uses-sdk
               android:minSdkVersion="8"
               android:targetSdkVersion="15" />
           
           <application
               android:icon="@drawable/ic_launcher"
               android:label="@string/app_name"
               android:theme="@style/Theme.Transparent" >
               <activity
                   android:name=".ServicesDemo"
                   android:label="@string/title_activity_main" >
                   <intent-filter>
                       <action android:name="android.intent.action.MAIN" />
       
                       <category android:name="android.intent.category.LAUNCHER" />
                   </intent-filter>
               </activity>
              
           </application>
           
        
       
       </manifest>
       
  4. Karl Rowley 2012-11-02

    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());
                   }
       
           }
       
       
       }
       
       <?xml version="1.0" encoding="utf-8"?>
       <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
           android:id="@+id/FrameLayout1"
           android:layout_width="100dp"
           android:layout_height="100dp" >
       
           <Button
               android:id="@+id/button1"
               android:layout_width="match_parent"
               android:layout_height="match_parent"
               android:layout_gravity="top"
               android:text="Button" />
       
       </FrameLayout>
       
       <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>
       
    AndroidManifest.xml
       <?xml version="1.0" encoding="utf-8"?>
       <manifest xmlns:android="http://schemas.android.com/apk/res/android"
             package="com.phone"
             android:versionCode="1"
             android:versionName="1.0">
           <application  android:label="@string/app_name"
               android:theme="@style/Theme.Transparent">
       
       		<receiver android:name=".IncomingReceiver" android:enabled="true">
       		    <intent-filter>
       				<action android:name="android.intent.action.PHONE_STATE"></action>
       			</intent-filter>
       		</receiver>
       		
       		<activity
                   android:name=".ButtonActivity"
                   android:launchMode="singleTask" 
                   android:label="@string/title_activity_main" >
       		                    <intent-filter>
                           <action android:name="android.intent.action.MAIN"/>
                       </intent-filter>
               </activity>
       
           </application>
           <uses-sdk android:minSdkVersion="3" />
       
       <uses-permission android:name="android.permission.READ_PHONE_STATE"></uses-permission>
       </manifest>
       
       
  5. Karl Rowley 2012-11-05

    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();
       
       
  6. Ingo Muschenetz 2012-11-06

    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.
  7. Ingo Muschenetz 2012-11-19

    Should we resolve this ticket as "on hold" until the module is done?
  8. Martin Guillon 2013-03-30

    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

JSON Source