Search in sources :

Example 11 with WeiboException

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();
}
Also used : Context(android.content.Context) GlobalContext(org.qii.weiciyuan.support.utils.GlobalContext) IntentFilter(android.content.IntentFilter) ClearUnreadDao(org.qii.weiciyuan.dao.unread.ClearUnreadDao) WeiboException(org.qii.weiciyuan.support.error.WeiboException) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent) BroadcastReceiver(android.content.BroadcastReceiver) Notification(android.app.Notification)

Example 12 with WeiboException

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();
}
Also used : Context(android.content.Context) GlobalContext(org.qii.weiciyuan.support.utils.GlobalContext) IntentFilter(android.content.IntentFilter) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) BroadcastReceiver(android.content.BroadcastReceiver) Notification(android.app.Notification) ClearUnreadDao(org.qii.weiciyuan.dao.unread.ClearUnreadDao) WeiboException(org.qii.weiciyuan.support.error.WeiboException) PendingIntent(android.app.PendingIntent)

Example 13 with WeiboException

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;
    }
}
Also used : GlobalContext(org.qii.weiciyuan.support.utils.GlobalContext) GZIPInputStream(java.util.zip.GZIPInputStream) WeiboException(org.qii.weiciyuan.support.error.WeiboException) InputStreamReader(java.io.InputStreamReader) GZIPInputStream(java.util.zip.GZIPInputStream) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) BufferedReader(java.io.BufferedReader) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException)

Example 14 with WeiboException

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);
    }
}
Also used : GlobalContext(org.qii.weiciyuan.support.utils.GlobalContext) Proxy(java.net.Proxy) WeiboException(org.qii.weiciyuan.support.error.WeiboException) DataOutputStream(java.io.DataOutputStream) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) URL(java.net.URL) HttpsURLConnection(javax.net.ssl.HttpsURLConnection)

Example 15 with WeiboException

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;
}
Also used : WeiboException(org.qii.weiciyuan.support.error.WeiboException)

Aggregations

WeiboException (org.qii.weiciyuan.support.error.WeiboException)16 GlobalContext (org.qii.weiciyuan.support.utils.GlobalContext)10 IOException (java.io.IOException)6 InterruptedIOException (java.io.InterruptedIOException)6 ClearUnreadDao (org.qii.weiciyuan.dao.unread.ClearUnreadDao)5 Notification (android.app.Notification)4 PendingIntent (android.app.PendingIntent)4 Context (android.content.Context)4 Intent (android.content.Intent)4 IntentFilter (android.content.IntentFilter)4 FileInputStream (java.io.FileInputStream)4 BroadcastReceiver (android.content.BroadcastReceiver)3 BufferedInputStream (java.io.BufferedInputStream)3 InputStream (java.io.InputStream)3 Proxy (java.net.Proxy)3 URL (java.net.URL)3 GZIPInputStream (java.util.zip.GZIPInputStream)3 BufferedReader (java.io.BufferedReader)2 InputStreamReader (java.io.InputStreamReader)2 HttpURLConnection (java.net.HttpURLConnection)2