Search in sources :

Example 1 with WeiboException

use of org.qii.weiciyuan.support.error.WeiboException in project weiciyuan by qii.

the class LocationInfoDao method getInfo.

public String getInfo() {
    Map<String, String> map = new HashMap<String, String>();
    map.put("language", "zh-CN");
    map.put("sensor", "false");
    map.put("latlng", getLatlng());
    String url = URLHelper.GOOGLELOCATION;
    String jsonData = null;
    try {
        jsonData = HttpUtility.getInstance().executeNormalTask(HttpMethod.Get, url, map);
    } catch (WeiboException e) {
        AppLogger.e(e.getMessage());
    }
    try {
        JSONObject jsonObject = new JSONObject(jsonData);
        JSONArray results = jsonObject.optJSONArray("results");
        JSONObject jsonObject1 = results.getJSONObject(0);
        String formatAddress = jsonObject1.optString("formatted_address");
        int index = formatAddress.indexOf(" ");
        if (index > 0) {
            String location = formatAddress.substring(0, index);
            return location;
        } else {
            return formatAddress;
        }
    } catch (JSONException e) {
        AppLogger.e(e.getMessage());
    }
    return "";
}
Also used : WeiboException(org.qii.weiciyuan.support.error.WeiboException) JSONObject(org.json.JSONObject) HashMap(java.util.HashMap) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException)

Example 2 with WeiboException

use of org.qii.weiciyuan.support.error.WeiboException in project weiciyuan by qii.

the class MainFriendsTimeLineDao method getMsgListJson.

private String getMsgListJson() throws WeiboException {
    String url = getUrl();
    Map<String, String> map = new HashMap<String, String>();
    map.put("access_token", access_token);
    map.put("since_id", since_id);
    map.put("max_id", max_id);
    map.put("count", count);
    map.put("page", page);
    map.put("base_app", base_app);
    map.put("feature", feature);
    map.put("trim_user", trim_user);
    String jsonData = HttpUtility.getInstance().executeNormalTask(HttpMethod.Get, url, map);
    try {
        new ClearUnreadDao(access_token, ClearUnreadDao.STATUS).clearUnread();
    } catch (WeiboException ignored) {
    }
    return jsonData;
}
Also used : ClearUnreadDao(org.qii.weiciyuan.dao.unread.ClearUnreadDao) WeiboException(org.qii.weiciyuan.support.error.WeiboException) HashMap(java.util.HashMap)

Example 3 with WeiboException

use of org.qii.weiciyuan.support.error.WeiboException in project weiciyuan by qii.

the class JBInboxNotification 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));
    if (NotificationUtility.getCount(unreadBean) > 1) {
        builder.setNumber(NotificationUtility.getCount(unreadBean));
    }
    if (clearNotificationEventReceiver != null) {
        GlobalContext.getInstance().unregisterReceiver(clearNotificationEventReceiver);
        JBInboxNotification.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);
                        JBInboxNotification.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.InboxStyle inboxStyle = new Notification.InboxStyle(builder);
    inboxStyle.setBigContentTitle(NotificationUtility.getTicker(unreadBean, null, null, null));
    if (comment != null) {
        for (CommentBean c : comment.getItemList()) {
            inboxStyle.addLine(c.getUser().getScreen_name() + ":" + c.getText());
        }
    }
    if (repost != null) {
        for (MessageBean m : repost.getItemList()) {
            inboxStyle.addLine(m.getUser().getScreen_name() + ":" + m.getText());
        }
    }
    if (mentionCommentsResult != null) {
        for (CommentBean m : mentionCommentsResult.getItemList()) {
            inboxStyle.addLine(m.getUser().getScreen_name() + ":" + m.getText());
        }
    }
    inboxStyle.setSummaryText(accountBean.getUsernick());
    builder.setStyle(inboxStyle);
    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 4 with WeiboException

use of org.qii.weiciyuan.support.error.WeiboException in project weiciyuan by qii.

the class SimpleTextNotificationService method buildNotification.

private void buildNotification(String uid) {
    ValueWrapper valueWrapper = valueBagHashMap.get(uid);
    if (valueWrapper == null) {
        return;
    }
    final AccountBean accountBean = valueWrapper.accountBean;
    final UnreadBean unreadBean = valueWrapper.unreadBean;
    Intent clickToOpenAppPendingIntentInner = valueWrapper.clickToOpenAppPendingIntentInner;
    String ticker = valueWrapper.ticker;
    final RecordOperationAppBroadcastReceiver clearNotificationEventReceiver = valueWrapper.clearNotificationEventReceiver;
    Notification.Builder builder = new Notification.Builder(getBaseContext()).setTicker(ticker).setContentText(accountBean.getUsernick()).setSmallIcon(R.drawable.ic_notification).setAutoCancel(true).setContentIntent(getPendingIntent(clickToOpenAppPendingIntentInner)).setOnlyAlertOnce(true);
    builder.setContentTitle(ticker);
    Utility.unregisterReceiverIgnoredReceiverNotRegisteredException(GlobalContext.getInstance(), clearNotificationEventReceiver);
    valueWrapper.clearNotificationEventReceiver = new RecordOperationAppBroadcastReceiver() {

        @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 {
                        Utility.unregisterReceiverIgnoredReceiverNotRegisteredException(GlobalContext.getInstance(), clearNotificationEventReceiver);
                        if (Utility.isDebugMode()) {
                            new Handler(Looper.getMainLooper()).post(new Runnable() {

                                @Override
                                public void run() {
                                    Toast.makeText(getApplicationContext(), "weiciyuan:remove notification items", Toast.LENGTH_SHORT).show();
                                }
                            });
                        }
                    }
                }
            }).start();
        }
    };
    IntentFilter intentFilter = new IntentFilter(RESET_UNREAD_MENTIONS_WEIBO_ACTION);
    GlobalContext.getInstance().registerReceiver(valueWrapper.clearNotificationEventReceiver, intentFilter);
    Intent broadcastIntent = new Intent(RESET_UNREAD_MENTIONS_WEIBO_ACTION);
    PendingIntent deletedPendingIntent = PendingIntent.getBroadcast(GlobalContext.getInstance(), accountBean.getUid().hashCode(), broadcastIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    builder.setDeleteIntent(deletedPendingIntent);
    Utility.configVibrateLedRingTone(builder);
    NotificationManager notificationManager = (NotificationManager) getApplicationContext().getSystemService(NOTIFICATION_SERVICE);
    notificationManager.notify(getMentionsWeiboNotificationId(accountBean), builder.build());
}
Also used : Context(android.content.Context) GlobalContext(org.qii.weiciyuan.support.utils.GlobalContext) IntentFilter(android.content.IntentFilter) NotificationManager(android.app.NotificationManager) Handler(android.os.Handler) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) RecordOperationAppBroadcastReceiver(org.qii.weiciyuan.support.lib.RecordOperationAppBroadcastReceiver) Notification(android.app.Notification) ClearUnreadDao(org.qii.weiciyuan.dao.unread.ClearUnreadDao) UnreadBean(org.qii.weiciyuan.bean.UnreadBean) WeiboException(org.qii.weiciyuan.support.error.WeiboException) PendingIntent(android.app.PendingIntent) AccountBean(org.qii.weiciyuan.bean.AccountBean)

Example 5 with WeiboException

use of org.qii.weiciyuan.support.error.WeiboException in project weiciyuan by qii.

the class JavaHttpUtility method handleResponse.

private String handleResponse(HttpURLConnection httpURLConnection) throws WeiboException {
    GlobalContext globalContext = GlobalContext.getInstance();
    String errorStr = globalContext.getString(R.string.timeout);
    globalContext = null;
    int status = 0;
    try {
        status = httpURLConnection.getResponseCode();
    } catch (IOException e) {
        e.printStackTrace();
        httpURLConnection.disconnect();
        throw new WeiboException(errorStr, e);
    }
    if (status != HttpURLConnection.HTTP_OK) {
        return handleError(httpURLConnection);
    }
    return readResult(httpURLConnection);
}
Also used : GlobalContext(org.qii.weiciyuan.support.utils.GlobalContext) WeiboException(org.qii.weiciyuan.support.error.WeiboException) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException)

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