use of org.qii.weiciyuan.support.error.WeiboException in project weiciyuan by qii.
the class ICSNotification method get.
public Notification get() {
Notification.Builder builder = new Notification.Builder(context).setTicker(getTicker()).setContentTitle(getTicker()).setContentText(accountBean.getUsernick()).setSmallIcon(R.drawable.ic_notification).setAutoCancel(true).setContentIntent(getPendingIntent()).setOnlyAlertOnce(true);
if (getCount() > 1) {
builder.setNumber(getCount());
}
Utility.configVibrateLedRingTone(builder);
if (clearNotificationEventReceiver != null) {
GlobalContext.getInstance().unregisterReceiver(clearNotificationEventReceiver);
ICSNotification.clearNotificationEventReceiver = null;
}
clearNotificationEventReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
new Thread(new Runnable() {
@Override
public void run() {
try {
new ClearUnreadDao(accountBean.getAccess_token()).clearMentionStatusUnread(unreadBean, accountBean.getUid());
new ClearUnreadDao(accountBean.getAccess_token()).clearMentionCommentUnread(unreadBean, accountBean.getUid());
new ClearUnreadDao(accountBean.getAccess_token()).clearCommentUnread(unreadBean, accountBean.getUid());
} catch (WeiboException ignored) {
} finally {
GlobalContext.getInstance().unregisterReceiver(clearNotificationEventReceiver);
ICSNotification.clearNotificationEventReceiver = null;
}
}
}).start();
}
};
IntentFilter intentFilter = new IntentFilter("org.qii.weiciyuan.Notification.unread");
GlobalContext.getInstance().registerReceiver(clearNotificationEventReceiver, intentFilter);
Intent broadcastIntent = new Intent("org.qii.weiciyuan.Notification.unread");
PendingIntent deletedPendingIntent = PendingIntent.getBroadcast(GlobalContext.getInstance(), 0, broadcastIntent, PendingIntent.FLAG_UPDATE_CURRENT);
builder.setDeleteIntent(deletedPendingIntent);
return builder.getNotification();
}
use of org.qii.weiciyuan.support.error.WeiboException in project weiciyuan by qii.
the class JBBigTextNotification method get.
public Notification get() {
Notification.Builder builder = new Notification.Builder(context).setTicker(NotificationUtility.getTicker(unreadBean, null, null, null)).setContentText(accountBean.getUsernick()).setSmallIcon(R.drawable.ic_notification).setAutoCancel(true).setContentIntent(getPendingIntent()).setOnlyAlertOnce(true);
builder.setContentTitle(NotificationUtility.getTicker(unreadBean, null, null, null));
builder.setNumber(1);
if (clearNotificationEventReceiver != null) {
GlobalContext.getInstance().unregisterReceiver(clearNotificationEventReceiver);
JBBigTextNotification.clearNotificationEventReceiver = null;
}
clearNotificationEventReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
new Thread(new Runnable() {
@Override
public void run() {
try {
new ClearUnreadDao(accountBean.getAccess_token()).clearMentionStatusUnread(unreadBean, accountBean.getUid());
new ClearUnreadDao(accountBean.getAccess_token()).clearMentionCommentUnread(unreadBean, accountBean.getUid());
new ClearUnreadDao(accountBean.getAccess_token()).clearCommentUnread(unreadBean, accountBean.getUid());
} catch (WeiboException ignored) {
} finally {
GlobalContext.getInstance().unregisterReceiver(clearNotificationEventReceiver);
JBBigTextNotification.clearNotificationEventReceiver = null;
}
}
}).start();
}
};
IntentFilter intentFilter = new IntentFilter("org.qii.weiciyuan.Notification.unread");
GlobalContext.getInstance().registerReceiver(clearNotificationEventReceiver, intentFilter);
Intent broadcastIntent = new Intent("org.qii.weiciyuan.Notification.unread");
PendingIntent deletedPendingIntent = PendingIntent.getBroadcast(GlobalContext.getInstance(), 0, broadcastIntent, PendingIntent.FLAG_UPDATE_CURRENT);
builder.setDeleteIntent(deletedPendingIntent);
Notification.BigTextStyle bigTextStyle = new Notification.BigTextStyle(builder);
if (unreadBean.getMention_status() == 1) {
bigTextStyle.setBigContentTitle(repost.getItem(0).getUser().getScreen_name() + ":");
bigTextStyle.bigText(repost.getItem(0).getText());
Intent intent = new Intent(context, WriteCommentActivity.class);
intent.putExtra("token", accountBean.getAccess_token());
intent.putExtra("msg", repost.getItem(0));
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
builder.addAction(R.drawable.comment_light, context.getString(R.string.comments), pendingIntent);
}
if (unreadBean.getCmt() == 1) {
bigTextStyle.setBigContentTitle(comment.getItem(0).getUser().getScreen_name() + ":");
bigTextStyle.bigText(comment.getItem(0).getText());
Intent intent = new Intent(context, WriteReplyToCommentActivity.class);
intent.putExtra("token", accountBean.getAccess_token());
intent.putExtra("msg", comment.getItem(0));
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
builder.addAction(R.drawable.reply_to_comment_light, context.getString(R.string.reply_to_comment), pendingIntent);
}
if (unreadBean.getMention_cmt() == 1) {
bigTextStyle.setBigContentTitle(mentionCommentsResult.getItem(0).getUser().getScreen_name() + ":");
bigTextStyle.bigText(mentionCommentsResult.getItem(0).getText());
Intent intent = new Intent(context, WriteReplyToCommentActivity.class);
intent.putExtra("token", accountBean.getAccess_token());
intent.putExtra("msg", mentionCommentsResult.getItem(0));
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
builder.addAction(R.drawable.reply_to_comment_light, context.getString(R.string.reply_to_comment), pendingIntent);
}
bigTextStyle.setSummaryText(accountBean.getUsernick());
builder.setStyle(bigTextStyle);
Utility.configVibrateLedRingTone(builder);
return builder.build();
}
use of org.qii.weiciyuan.support.error.WeiboException in project weiciyuan by qii.
the class JavaHttpUtility method readError.
private String readError(HttpURLConnection urlConnection) throws WeiboException {
InputStream is = null;
BufferedReader buffer = null;
GlobalContext globalContext = GlobalContext.getInstance();
String errorStr = globalContext.getString(R.string.timeout);
try {
is = urlConnection.getErrorStream();
if (is == null) {
errorStr = globalContext.getString(R.string.unknown_sina_network_error);
throw new WeiboException(errorStr);
}
String content_encode = urlConnection.getContentEncoding();
if (!TextUtils.isEmpty(content_encode) && content_encode.equals("gzip")) {
is = new GZIPInputStream(is);
}
buffer = new BufferedReader(new InputStreamReader(is));
StringBuilder strBuilder = new StringBuilder();
String line;
while ((line = buffer.readLine()) != null) {
strBuilder.append(line);
}
AppLogger.d("error result=" + strBuilder.toString());
return strBuilder.toString();
} catch (IOException e) {
e.printStackTrace();
throw new WeiboException(errorStr, e);
} finally {
Utility.closeSilently(is);
Utility.closeSilently(buffer);
urlConnection.disconnect();
globalContext = null;
}
}
use of org.qii.weiciyuan.support.error.WeiboException in project weiciyuan by qii.
the class JavaHttpUtility method doPost.
public String doPost(String urlAddress, Map<String, String> param) throws WeiboException {
GlobalContext globalContext = GlobalContext.getInstance();
String errorStr = globalContext.getString(R.string.timeout);
globalContext = null;
try {
URL url = new URL(urlAddress);
Proxy proxy = getProxy();
HttpsURLConnection uRLConnection;
if (proxy != null) {
uRLConnection = (HttpsURLConnection) url.openConnection(proxy);
} else {
uRLConnection = (HttpsURLConnection) url.openConnection();
}
uRLConnection.setDoInput(true);
uRLConnection.setDoOutput(true);
uRLConnection.setRequestMethod("POST");
uRLConnection.setUseCaches(false);
uRLConnection.setConnectTimeout(CONNECT_TIMEOUT);
uRLConnection.setReadTimeout(READ_TIMEOUT);
uRLConnection.setInstanceFollowRedirects(false);
uRLConnection.setRequestProperty("Connection", "Keep-Alive");
uRLConnection.setRequestProperty("Charset", "UTF-8");
uRLConnection.setRequestProperty("Accept-Encoding", "gzip, deflate");
uRLConnection.connect();
DataOutputStream out = new DataOutputStream(uRLConnection.getOutputStream());
out.write(Utility.encodeUrl(param).getBytes());
out.flush();
out.close();
return handleResponse(uRLConnection);
} catch (IOException e) {
e.printStackTrace();
throw new WeiboException(errorStr, e);
}
}
use of org.qii.weiciyuan.support.error.WeiboException in project weiciyuan by qii.
the class AbstractAsyncNetRequestTaskLoader method loadInBackground.
@Override
public AsyncTaskLoaderResult<T> loadInBackground() {
T data = null;
WeiboException exception = null;
try {
data = loadData();
} catch (WeiboException e) {
exception = e;
}
result = new AsyncTaskLoaderResult<T>();
result.data = data;
result.exception = exception;
result.args = this.args;
return result;
}
Aggregations