Search This Blog

Wednesday, 14 March 2012

Chapter 13:Popup- AnimatePopup Example Program


Popup
AnimatePopup
-----
package com.popup.design;

import com.popup.design.layers.TransparentPanel;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.TextView;

/**
*
* @author http://www.android-codes-examples.blogspot.com/
*
*/
public class AnimatePopup extends Activity {
private Animation animShow, animHide;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);

setContentView(R.layout.popup);
initPopup();
}
private void initPopup() {
final TransparentPanel popup = (TransparentPanel) findViewById(R.id.popup_window);

// Start out with the popup initially hidden.
popup.setVisibility(View.GONE);
animShow = AnimationUtils.loadAnimation( this, R.anim.popup_show);
animHide = AnimationUtils.loadAnimation( this, R.anim.popup_hide);
final Button showButton = (Button) findViewById(R.id.show_popup_button);
// final Button hideButton = (Button) findViewById(R.id.hide_popup_button);
showButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
popup.setVisibility(View.VISIBLE);
popup.startAnimation( animShow );
showButton.setEnabled(false);
// hideButton.setEnabled(true);
}});
/* hideButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
popup.startAnimation( animHide );
showButton.setEnabled(true);
hideButton.setEnabled(false);
popup.setVisibility(View.GONE);
}});
*/

final TextView locationName = (TextView) findViewById(R.id.location_name);
final TextView locationDescription = (TextView) findViewById(R.id.location_description);
locationName.setText("Animated Popup");
locationDescription.setText("Animated popup is created by http://www.android-codes-examples.blogspot.com/"
+ " Transparent layout is used on this example, and animation xml is also used"
+ " on this example. Have a Good day guys.");
}
}

TransparentPanel
----------------

package com.popup.design.layers;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.RectF;
import android.graphics.Paint.Style;
import android.util.AttributeSet;
import android.widget.LinearLayout;

public class TransparentPanel extends LinearLayout
{
private Paint innerPaint, borderPaint ;
public TransparentPanel(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}

public TransparentPanel(Context context) {
super(context);
init();
}

private void init() {
innerPaint = new Paint();
innerPaint.setARGB(128, 255, 255, 255);
innerPaint.setAntiAlias(true);

borderPaint = new Paint();
borderPaint.setARGB(255, 0, 0, 0);
borderPaint.setAntiAlias(true);
borderPaint.setStyle(Style.STROKE);
borderPaint.setStrokeWidth(2);
}
public void setInnerPaint(Paint innerPaint) {
this.innerPaint = innerPaint;
}

public void setBorderPaint(Paint borderPaint) {
this.borderPaint = borderPaint;
}

@Override
protected void dispatchDraw(Canvas canvas) {
RectF drawRect = new RectF();
drawRect.set(0,0, getMeasuredWidth(), getMeasuredHeight());
canvas.drawRoundRect(drawRect, 5, 5, innerPaint);
canvas.drawRoundRect(drawRect, 5, 5, borderPaint);
super.dispatchDraw(canvas);
}
}

res->layout->popup.xml

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:background="@drawable/white"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<ScrollView
android:id="@+id/scrollvancy"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView android:id="@+id/locion_name" android:text="sdfgskdf"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:textStyle="bold" android:textSize="16px" android:textColor="#ffffff"
android:layout_marginTop="5px" android:layout_marginLeft="5px" />

<TextView android:id="@+id/lation_description" android:text="sdfgskdf"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:textColor="#ffffff" android:layout_margin="5px" />
</LinearLayout>
</ScrollView>



<Button android:id="@+id/show_popup_button" android:layout_gravity="bottom"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_marginBottom="25px" android:text="Show Popup" />

<com.popup.design.layers.TransparentPanel
android:id="@+id/popup_window" android:layout_width="fill_parent"
android:orientation="vertical"
android:layout_gravity="bottom" android:gravity="left" android:padding="1px"
android:background="@drawable/white" android:layout_height="wrap_content">

<TextView android:id="@+id/location_name"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:textStyle="bold" android:textSize="16px" android:textColor="@drawable/white"
android:layout_marginTop="5px" android:layout_marginLeft="5px" />

<TextView android:id="@+id/location_description"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:textColor="@drawable/white" android:layout_margin="5px" />

</com.popup.design.layers.TransparentPanel>

</FrameLayout>



http://developer.android.com/guide/topics/ui/menus.html#options-menu

No comments:

Post a Comment