Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

show pop up like gmail in android [closed]

I want to show an alert in my android just like gmail notification in desktop

enter image description here

how should I approach.

Solution made it showing like this

enter image description here

like image 868
Anirban Avatar asked Jun 04 '13 05:06

Anirban


1 Answers

Dialogs cannot be triggered without an activity..

So ,you can create an activity with dialog theme.

    <activity android:theme="@android:style/Theme.Dialog" />

Now from your service ..just call this activity when your notification arrives... And it will pop up like a dialog...

Edit:

While calling your activity:

   startActivity(intent);
   overridePendingTransition(R.anim.enter_anim, R.anim.right_exit_anim);

Now create the two anim files in a seperate folder called anim in the resource dir.

enter_anim:

   <?xml version="1.0" encoding="utf-8"?>
   <set xmlns:android="http://schemas.android.com/apk/res/android"    
        android:interpolator="@android:anim/accelerate_decelerate_interpolator">
   <translate
    android:fromYDelta="20%p" //this takes val from 0(screenbottom) to 100(screentop).
    android:toYDelta="0%p"  //this takes val from 0(screenbottom) to 100(screentop).
    android:duration="700"   //transition timing
    />
   </set>

exit_anim:

   <?xml version="1.0" encoding="utf-8"?>
   <set xmlns:android="http://schemas.android.com/apk/res/android"    
        android:interpolator="@android:anim/accelerate_decelerate_interpolator">
   <translate
    android:fromYDelta="0%p" //this takes val from 0(screenbottom) to 100(screentop).
    android:toYDelta="20%p"  //this takes val from 0(screenbottom) to 100(screentop).
    android:duration="700"   //transition timing
    />
   </set>

EDIT 2:

Create an activity.. design it..then go to your manifest file.. And under your activity tag.. add:

    <activity android:theme="@android:style/Theme.Dialog" />

Now your activity will look like a dialog...

EDIT 3:

Now add the following function in your activity(dialog) after onCreate():

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

    View view = getWindow().getDecorView();
    WindowManager.LayoutParams lp = (WindowManager.LayoutParams) view.getLayoutParams();
    lp.gravity = Gravity.RIGHT | Gravity.BOTTOM;//setting the gravity just like any view
    lp.x = 10;
    lp.y = 10;
    lp.width = 200;
    lp.height = 100;
    getWindowManager().updateViewLayout(view, lp);
}

We are overriding the attach window to specify the activity location on the screen.

Now your activity will be placed in the right side bottom of the screen.

EDIT 4:

Now to give your specified co ordinate points for the dialog, use the lp.x and lp.y...

like image 133
amalBit Avatar answered Sep 23 '22 12:09

amalBit