Yo John,

I've made a blog post for you entitled:   Android Custom Transparent
Dialog Alarm Style @ http://www.ryangmattison.com/

It is clearly formatted there, I'll also include it below:

Running out of topics to blog about, so I'm going to randomly select
questions off the Android Developer boards.   There was a UI question
today:



Hello,

I would like to know whether it is somehow possible
to create a popup window which does not take up the
whole display area. I am asking because I need to display
a message when an alarm expires but do not want to resort
to notifications because they seem to be squished in the top
right corner of the phone and I think would make it hard to turn
an alarm off it it were a notification. On the other hand bringing
up an entire window could obfuscate other applications. I guess
there is nothing like HP/Palm webOS's notification mechanism
on android (there you can pop up a window and the users can
still keep on interacting with whatever app they were using or
close the popup window)jQuery152008387357299216092_1317069193779?

Regards,

John Goche

http://groups.google.com/group/android-developers/msg/debed653b314232f



I assume he means something like this,





To implement something like this, first you'll need to create some
themes - these are to be saved in styles.xml:



<?xml version="1.0" encoding="utf-8"?>
<resources>

    <drawable name="transparent_background">#00FFFFFF</drawable>
    <drawable name="translucent_background">#aa000000</drawable>

    <style parent="android:Theme"
        name="Theme.CompletelyTransparentWindow">
        <item name="android:windowIsTranslucent">true</item>
        <item name="android:windowAnimationStyle">@null</item>
        <item name="android:windowBackground">@drawable/
transparent_background</item>
        <item name="android:windowNoTitle">true</item>
        <item name="android:backgroundDimAmount">0.0</item>
    </style>

        <style name="Theme.ProgressDialog"
        parent="android:style/Theme.Translucent.NoTitleBar">
        <item name="android:windowNoTitle">true</item>
        <item name="android:windowIsTranslucent">true</item>
        <item name="android:windowAnimationStyle">@null</item>
        <item name="android:windowBackground">
            @drawable/translucent_background
        </item>
        <item name="android:backgroundDimAmount">0.0</item>
    </style>


    <style name="Theme.CustomDialog"
        parent="android:style/Theme.Dialog">
        <item name="android:windowNoTitle">true</item>
        <item name="android:windowIsTranslucent">true</item>
        <item name="android:windowAnimationStyle">@null</item>
        <item name="android:backgroundDimAmount">0.3</item>
        <item name="android:textAppearanceLarge">
            @style/TextAppearance
        </item>
        <item name="android:textAppearanceMedium">
            @style/TextAppearance
        </item>
        <item name="android:textAppearanceSmall">
            @style/TextAppearance
        </item>
    </style>


        <style name="TextAppearance">
        <item name="android:textColor">#FFFFFFFF</item>
        <item name="android:textColorHighlight">#FF1B82EB</item>
        <item name="android:textColorHint">#5C5CFF</item>
        <item name="android:textColorLink">#5C5CFF</item>
        <item name="android:textSize">13sp</item>
        <item name="android:textStyle">normal</item>
    </style>

</resources>
You'll want to edit the manifest, so the Alarm popup activity themes
to not have a background - notice the Theme.CustomDialog




<activity android:name=".TransparentDialogActivity"
android:theme="@style/Theme.CustomDialog"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category
android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
Next, you'll want to create a custom control that makes custom popups
really easy to work with, first the XML for a two button popup.  I
have this title twobuttonpopupdialog.xml


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/
android"
    android:layout_width="match_parent"
android:layout_height="wrap_content"
    android:orientation="vertical">

    <TextView android:id="@+id/twobuttondialog_title"
        android:typeface="sans" android:gravity="center_horizontal|
top"
        android:paddingTop="10dip" android:paddingLeft="10dip"
        android:paddingRight="10dip" android:paddingBottom="10dip"
        android:layout_width="wrap_content"
android:layout_height="wrap_content" />
    <LinearLayout android:layout_width="match_parent"
        android:minWidth="260dip" android:layout_height="match_parent"
        android:gravity="center_horizontal|bottom"
android:orientation="horizontal"
        android:paddingTop="16dip" android:paddingBottom="8dip">

        <LinearLayout android:layout_width="match_parent"
            android:layout_weight=".5"
android:layout_height="wrap_content">

            <Button android:id="@+id/twobuttondialog_button_one"
style="?android:attr/buttonStyleSmall"

                android:layout_width="match_parent"
android:layout_height="match_parent" />

        </LinearLayout>

        <LinearLayout android:layout_width="match_parent"
            android:layout_weight=".5"
android:layout_height="wrap_content">

            <Button android:id="@+id/twobuttondialog_button_two"
style="?android:attr/buttonStyleSmall"
                android:layout_width="match_parent"
android:layout_height="match_parent" />

        </LinearLayout>

    </LinearLayout>
</LinearLayout>
To simplify coding in the future and keep everything consistent, it is
nice to follow the Android developers code style and create a class to
work with this. I titled this, TwoButtonDialog.java



import android.app.Dialog;
import android.content.Context;
import android.text.util.Linkify;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;


public class TwoButtonDialog
{

    private Dialog twoButtonDialog;
    private Button buttonOne;
    private Button buttonTwo;
    private TextView message;

    public TwoButtonDialog(Context mCtx)
    {
         twoButtonDialog = new Dialog(mCtx,
R.style.Theme_CustomDialog);
 
twoButtonDialog.setContentView(R.layout.twobuttonpopupdialog);

         buttonOne =
(Button)twoButtonDialog.findViewById(R.id.twobuttondialog_button_one);
         buttonTwo =
(Button)twoButtonDialog.findViewById(R.id.twobuttondialog_button_two);
         message =
(TextView)twoButtonDialog.findViewById(R.id.twobuttondialog_title);
    }

    public void showTwoButtonDialog(String buttonOneMessage, String
buttonTwoMessage, String Message, boolean linkify,
            final onTwoButtonDialogShow commands)
    {
        buttonOne.setText(buttonOneMessage);
        buttonTwo.setText(buttonTwoMessage);
        message.setText(Message);
        twoButtonDialog.show();


        buttonOne.setOnClickListener(new OnClickListener()
        {
            public void onClick(View arg0)
            {
                if (commands != null) commands.onButtonOneClicked();
                twoButtonDialog.dismiss();
            }
        });

        buttonTwo.setOnClickListener(new OnClickListener()
        {
            public void onClick(View arg0)
            {
                if (commands != null) commands.onButtonTwoClicked();
                twoButtonDialog.dismiss();
            }
        });

        if(linkify)
        {
            Linkify.addLinks(message, Linkify.WEB_URLS);
        }
    }

    public interface onTwoButtonDialogShow
    {
        void onButtonOneClicked();
        void onButtonTwoClicked();
    }


}
Now, to tie it all together whenever you want to use the popup you can
call the show snippet in the following snippet. This activity
TransparentDialogActivity was also setup to be transparent in the
Android Manifest, so it'll appear see through as the alarm activity
does.


public class TransparentDialogActivity extends Activity {
    /** Called when the activity is first created. */

    Context _context;

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

        _context = this;


        TwoButtonDialog tbd = new TwoButtonDialog(this);

        tbd.showTwoButtonDialog("Off", "Snooze", "Take Alarm Action",
false, new onTwoButtonDialogShow(){

            @Override
            public void onButtonOneClicked() {
                Toast.makeText(_context, "Off Button Pressed",
Toast.LENGTH_LONG).show();
                finish();
            }

            @Override
            public void onButtonTwoClicked() {
                Toast.makeText(_context, "Snooze Button Pressed",
Toast.LENGTH_LONG).show();
                finish();
            }});


    }
Thanks for reading, if you found this helpful - please follow one of
the social networks above for future original tutorials.

To those that have been stealing my tutorials & open source and
posting it as their own, please don't follow!


Be the first to rate this post
12345
Tags: Alarm Dialog, Transparent Popup, Custom Dialog, Android, Ryan
Mattison, UX, User Interface, Learning Android, Android Tutorials

Thanks,

Ryan Mattison

On Sep 26, 1:37 pm, John Goche <johngoch...@googlemail.com> wrote:
> Hello,
>
> I would like to know whether it is somehow possible
> to create a popup window which does not take up the
> whole display area. I am asking because I need to display
> a message when an alarm expires but do not want to resort
> to notifications because they seem to be squished in the top
> right corner of the phone and I think would make it hard to turn
> an alarm off it it were a notification. On the other hand bringing
> up an entire window could obfuscate other applications. I guess
> there is nothing like HP/Palm webOS's notification mechanism
> on android (there you can pop up a window and the users can
> still keep on interacting with whatever app they were using or
> close the popup window)???
>
> Regards,
>
> John Goche

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to