Here is my first tutorial post here. I Hope u all will like this tiny tutorial.This is a small demo of how to use pop ups in android.
Question What is this
Difficulty: 2 of 5
i have attached the whole source code.please find the attachment and let me know whether It is helpful or not
Please also notify me , if u hv any query. and also guide me if i m wrong anywhere.
Using java Syntax Highlighting
- package com.shishir.popup;
- 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;
- import com.shishir.view.TransparentPanel;
- public class Popup extends Activity {
- private Animation animShow, animHide;
- 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("Android");
- locationDescription
- .setText("The second Android Developer Challenge has begun! In this contest, real-world users will help review and score applications"
- + "and the overall winner will take away $250,000. The deadline for submitting an application to the contest is August 31, 2009.");
- }
- }
Parsed in 0.038 seconds, using GeSHi 1.0.8.4
Using java Syntax Highlighting
- package com.shishir.view;
- 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.RelativeLayout;
- public class TransparentRelativePanel extends RelativeLayout {
- private Paint innerPaint, borderPaint;
- public TransparentRelativePanel(Context context, AttributeSet attrs) {
- super(context, attrs);
- init();
- }
- public TransparentRelativePanel(Context context) {
- super(context);
- init();
- }
- private void init() {
- innerPaint = new Paint();
- innerPaint.setARGB(225, 75, 75, 75); //gray
- innerPaint.setAntiAlias(true);
- borderPaint = new Paint();
- borderPaint.setARGB(255, 255, 255, 255);
- 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);
- }
- }
Parsed in 0.036 seconds, using GeSHi 1.0.8.4
Using java Syntax Highlighting
- package com.shishir.view;
- 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(225, 75, 75, 75); //gray
- innerPaint.setAntiAlias(true);
- borderPaint = new Paint();
- borderPaint.setARGB(255, 255, 255, 255);
- 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);
- }
- }
Parsed in 0.038 seconds, using GeSHi 1.0.8.4
Thanks And Regards
shishir Mishra



