Friday 26 February 2016


Custom Alerts

package com.sollet.buzz.main;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.Typeface;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.text.method.ScrollingMovementMethod;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.sollet.buzz.common.Common;
import com.sollet.buzz.dto.MyApplication;
import com.sollet.buzz.utils.UiUtility;

import java.util.Enumeration;
import java.util.Vector;

public class MyAlertDialog extends Activity {
UiUtility uiUtility= new UiUtility();
MyApplication myapp;
Button closeButton;
Button readButton;
TextView sender;
TextView message;
Intent myIntent;
Vector pendingVector = new Vector();
Button attachButton = null;
OnClickListener attachmentOnClickListener=null;
String linkString ;

protected void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);

setContentView(R.layout.mydialog);
myapp = (MyApplication)getApplication();
getWindow().getAttributes().windowAnimations = R.style.Alertstyle;

Window window = this.getWindow();
WindowManager.LayoutParams wlp = window.getAttributes();
window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
window.setAttributes(wlp);
String headerfontPath = "fonts/titlefont.ttf";

// Loading Font Face
Typeface headerTF = Typeface.createFromAsset(getAssets(), headerfontPath);

myIntent = getIntent();
sender=(TextView) findViewById(R.id.from);
sender.setTypeface(headerTF);

message=(TextView) findViewById(R.id.message);
message.setMovementMethod(new ScrollingMovementMethod());
sender.setText(myIntent.getExtras().getString("from"));

String message_=myIntent.getExtras().getString("messgaebody");
int msgIndex = message_.indexOf("|||F");

if (msgIndex != -1) {

message_ = message_.substring(0, msgIndex);
}
message.setText(message_);

try{
if(!Common.isAscii(myIntent.getExtras().getString("messgaebody").substring(0, 1))){
message.setTextSize(20);
message.setMaxLines(9);
}
}catch (Exception e) {

}


// if(!uiUtility.isAscii(myIntent.getExtras().getString("messgaebody"))){
// message.setTextSize(20);
// message.setMaxLines(9);
// }

attachButton = (Button) findViewById(R.id.attachment);
linkString = myIntent.getExtras().getString("link");
if(linkString.trim().length() > 0) {
attachmentOnClickListener = new OnClickListener() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub

uiUtility.showProgressBar(MyAlertDialog.this, "Downloading Wait...");
Thread t = new Thread() {

public void run() {
uiUtility.saveAndOpenFile(MyAlertDialog.this, linkString);
}
};

t.start();


}
};
attachButton.setOnClickListener(attachmentOnClickListener);
}

if(linkString.trim().length()>0){
attachButton.setVisibility(View.VISIBLE);

String fileName = uiUtility.getFileNameFromURL(linkString);
String fileExtenString= uiUtility.getFileExtensionFromFile(fileName);
if(fileExtenString.equalsIgnoreCase("image/*")){
uiUtility.setDrawableToButton(this, attachButton, "LEFT", R.drawable.ic_image_attach);
attachButton.setText(" (Click here to view attachment)");
}else if(fileExtenString.equalsIgnoreCase("video/*")){
uiUtility.setDrawableToButton(this, attachButton, "LEFT", R.drawable.ic_video_attach);
attachButton.setText(" (Click here to play video)");
}else if(fileExtenString.equalsIgnoreCase("audio/*")){
uiUtility.setDrawableToButton(this, attachButton, "LEFT", R.drawable.ic_audio_attach);
attachButton.setText(" (Click here to play audio)");
}else if(fileExtenString.equalsIgnoreCase("application/*")){
uiUtility.setDrawableToButton(this, attachButton, "LEFT", R.drawable.ic_docfiles);
attachButton.setText(" (Click here to Open doc)");
}else{
uiUtility.setDrawableToButton(this, attachButton, "LEFT", R.drawable.ic_attachment);
attachButton.setText(" (Click here for attachment)");
}

}else{
attachButton.setVisibility(View.GONE);
}





closeButton=(Button) findViewById(R.id.ok);
closeButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (!pendingVector.isEmpty()) {

String messageContent = pendingVector.firstElement().toString();
int index = messageContent.indexOf("|||");
int linkindex = messageContent.indexOf("$|$");
String pendingfrom = messageContent.substring(0, index);
String pendingmessage = messageContent.substring(index + 3,linkindex);
linkString = messageContent.substring(linkindex+3);
UiUtility.printMe("title===" + pendingfrom + "body===" + pendingmessage);

sender.setText(pendingfrom);


String message_ = pendingmessage;
int msgIndex = message_.indexOf("|||F");

if (msgIndex != -1) {

message_ = message_.substring(0, msgIndex);
}


message.setText(message_);
if(!Common.isAscii(pendingmessage)){
message.setTextSize(20);
message.setMaxLines(9);
}else{
message.setTextSize(15);
message.setMaxLines(15);
}

if( linkString.trim().length() > 0){
attachButton.setVisibility(View.VISIBLE);
String fileName = uiUtility.getFileNameFromURL(linkString);
String fileExtenString= uiUtility.getFileExtensionFromFile(fileName);
if(fileExtenString.equalsIgnoreCase("image/*")){
uiUtility.setDrawableToButton(MyAlertDialog.this, attachButton, "LEFT", R.drawable.ic_image_attach);
attachButton.setText(" (Click here to view attachment)");
}else if(fileExtenString.equalsIgnoreCase("video/*")){
uiUtility.setDrawableToButton(MyAlertDialog.this, attachButton, "LEFT", R.drawable.ic_video_attach);
attachButton.setText(" (Click here to play video)");
}else if(fileExtenString.equalsIgnoreCase("audio/*")){
uiUtility.setDrawableToButton(MyAlertDialog.this, attachButton, "LEFT", R.drawable.ic_audio_attach);
attachButton.setText(" (Click here to play audio)");
}else if(fileExtenString.equalsIgnoreCase("application/*")){
uiUtility.setDrawableToButton(MyAlertDialog.this, attachButton, "LEFT", R.drawable.ic_docfiles);
attachButton.setText(" (Click here to Open doc)");
}else{
uiUtility.setDrawableToButton(MyAlertDialog.this, attachButton, "LEFT", R.drawable.ic_attachment);
attachButton.setText(" (Click here for attachment)");
}

}else{
attachButton.setVisibility(View.GONE);
}

pendingVector.removeElement(pendingVector.firstElement());
} else {
finish();
}
}
});

readButton=(Button) findViewById(R.id.read);
readButton.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
boolean isDataRemoved = pendingVector.removeAll(pendingVector);

Intent intent =new Intent(MyAlertDialog.this, ACTMainScreen.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
finish();
}
});

final LinearLayout adLinLay = (LinearLayout) findViewById(R.id.slider);
myapp.loadAd(adLinLay);

}

@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
setIntent(intent);
myIntent = getIntent();
UiUtility.printMe("----------------" + myIntent.getExtras().getString("messgaebody"));
pendingVector.addElement(myIntent.getExtras().getString("from") + "|||" + myIntent.getExtras().getString("messgaebody")+"$|$"+myIntent.getExtras().getString("link"));

Enumeration vEnum = pendingVector.elements();
while (vEnum.hasMoreElements()) {
UiUtility.printMe(vEnum.nextElement());
}
}


@Override
public void onBackPressed() {
// TODO Auto-generated method stub

}


}



layout




No comments:

Post a Comment