QGDialog dialog = new QGDialog.Builder(context).setMessage(
msg).create();
dialog.show(time);
public class QGDialog {
private QGDialog.Builder mBuilder;
private boolean isShow;
private OnDismissListener internalDismissListener;
private static final String TAG = "PateoDialog";
private QGDialog(QGDialog.Builder mBuilder) {
this.mBuilder = null;
this.isShow = false;
this.internalDismissListener = new OnDismissListener() {
public void onDismiss(DialogInterface dialog) {
QGDialog.this.isShow = false;
if(QGDialog.this.mBuilder.dismissListener != null) {
QGDialog.this.mBuilder.dismissListener.onDismiss(dialog);
}
}
};
this.mBuilder = mBuilder;
}
public void show() {
if(!this.isShow) {
this.isShow = true;
Message msg = QGDialogConnection.mMyHandler.obtainMessage();
msg.obj = this.getConnection();
msg.what = 0;
msg.sendToTarget();
} else {
Log.e("PateoDialog", "You have use show() before! if you want show again, you can use update(RemoteViews view)");
}
}
public void show(Long milliseconds) {
if(milliseconds.longValue() <= 0L) {
this.show();
} else if(this.isShow) {
Log.e("PateoDialog", "You have use show(), and not dissmis()");
} else {
this.isShow = true;
Message msg = QGDialogConnection.mMyHandler.obtainMessage();
msg.obj = this.getConnection();
Bundle data = new Bundle();
msg.setData(data);
msg.what = 0;
msg.sendToTarget();
this.dismiss(milliseconds.longValue());
}
}
private void dismiss(long timeout) {
if(this.isShow) {
Message msg = QGDialogConnection.mMyHandler.obtainMessage();
msg.obj = this.getConnection();
msg.what = 1;
QGDialogConnection.mMyHandler.sendMessageDelayed(msg, timeout);
QGDialogConnection.mMyHandler.postDelayed(new Runnable() {
public void run() {
QGDialog.this.isShow = false;
QGDialog.this.mBuilder.connection = null;
}
}, timeout);
}
}
public void dismiss() {
if(this.isShow) {
this.isShow = false;
}
Message msg = QGDialogConnection.mMyHandler.obtainMessage();
msg.obj = this.getConnection();
msg.what = 1;
msg.sendToTarget();
this.mBuilder.connection = null;
}
public void update(RemoteViews view) {
Log.i("feifei", "update RemoteViews!!!");
if(!this.isShow) {
Log.i("feifei", "Please use show() first!");
} else {
this.mBuilder.mContentView = view;
this.isShow = false;
this.show();
}
}
public void update(QGRemoteViews view) {
Log.i("feifei", "update RemoteViews!!!");
if(!this.isShow) {
Log.i("feifei", "Please use show() first!");
} else {
this.mBuilder.mPateoContentView = view;
this.isShow = false;
this.show();
}
}
public void update(String message) {
if(this.mBuilder.mContentView != null) {
Log.i("feifei", "Please use \'update(RemoteViews view)\' for customer view!");
} else {
this.mBuilder.mMessage = message;
this.isShow = false;
this.show();
}
}
public void update(String message, long timeout) {
if(this.mBuilder.mContentView != null) {
Log.i("feifei", "Please use \'update(RemoteViews view)\' for customer view!");
} else {
this.mBuilder.mMessage = message;
this.isShow = false;
this.show(Long.valueOf(timeout));
}
}
public void setLayoutParamsType(int LayoutParamsType) {
this.mBuilder.mLayoutParamsType = LayoutParamsType;
}
public void setToTopLayer() {
this.mBuilder.mLayoutParamsType = 2010;
}
private QGDialogConnection getConnection() {
if(this.mBuilder.connection == null) {
ClientProxy client = new ClientProxy(this.mBuilder.mCallback);
QGDialogConnection connection = new QGDialogConnection(this.mBuilder, client);
connection.dismissListener = this.internalDismissListener;
client.mConnection = connection;
this.mBuilder.connection = connection;
connection.connect();
}
return this.mBuilder.connection;
}
public int getId() {
return this.mBuilder.id;
}
public boolean isShowing() {
return this.isShow;
}
public static class Builder {
int id = -1;
int type = 0;
int mLayoutParamsType = 2002;
QGDialogConnection connection = null;
Context mContext = null;
CharSequence mMessage;
CharSequence mLeftButtonTxt;
CharSequence mRightButtonTxt;
int mLevel = -1;
CallBack mCallback;
RemoteViews mContentView = null;
QGRemoteViews mPateoContentView = null;
RemoteViews mOnClickContentView = null;
OnDismissListener dismissListener = null;
public Builder(Context context) {
this.mContext = context;
}
public Context getContext() {
return this.mContext;
}
public QGDialog.Builder setTitle(int titleId) {
return this;
}
public QGDialog.Builder setMessage(CharSequence message) {
this.mMessage = message;
return this;
}
public QGDialog.Builder setLeftButtonText(int resId) {
this.mLeftButtonTxt = this.mContext.getText(resId);
return this;
}
public QGDialog.Builder setLeftButtonText(String msg) {
this.mLeftButtonTxt = msg;
return this;
}
public QGDialog.Builder setRightButtonText(int resId) {
this.mRightButtonTxt = this.mContext.getText(resId);
return this;
}
public QGDialog.Builder setRightButtonText(String msg) {
this.mRightButtonTxt = msg;
return this;
}
public QGDialog.Builder setMessageText(int resId) {
this.mMessage = this.mContext.getText(resId);
return this;
}
public QGDialog.Builder setMessageText(String msg) {
this.mMessage = msg;
return this;
}
public QGDialog.Builder setLevel(NotificationLevel messageLevel) {
if(messageLevel == null) {
return this;
} else {
this.mLevel = messageLevel.ordinal();
return this;
}
}
public QGDialog.Builder setCallBack(CallBack callback) {
this.mCallback = callback;
return this;
}
public QGDialog.Builder setOnDismissListener(OnDismissListener listener) {
if(this.dismissListener != null) {
throw new IllegalStateException("OnDismissListener is already exsit");
} else {
if(listener != null) {
this.dismissListener = listener;
} else {
this.dismissListener = null;
}
return this;
}
}
public QGDialog create() {
if(this.mContentView == null && this.mPateoContentView == null) {
this.type = DialogConstants.defaultLayout;
} else {
this.type = DialogConstants.customLayout;
}
this.id = QGDialogConnection.getUniqueId();
if(this.mLevel > -1) {
this.mLayoutParamsType = 2010;
}
return new QGDialog(this, null);
}
public QGDialog.Builder setCustomerView(RemoteViews rv) {
this.mContentView = rv;
return this;
}
public QGDialog.Builder setCustomerView(QGRemoteViews prv) {
this.mPateoContentView = prv;
return this;
}
}
}