@Override
  public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {

    if (key.equals(SettingActivity.ENABLE_FETCH_MSG)) {
      boolean value = sharedPreferences.getBoolean(key, false);
      if (value) {
        AppNewMsgAlarm.startAlarm(getActivity(), false);
      } else {
        AppNewMsgAlarm.stopAlarm(getActivity(), true);
      }
    }

    if (key.equals(SettingActivity.FREQUENCY)) {

      AppNewMsgAlarm.startAlarm(getActivity(), false);
      buildSummary();
    }

    if (key.equals(SettingActivity.FONT_SIZE)) {
      String value = sharedPreferences.getString(key, "15");
      GlobalContext.getInstance().setFontSize(Integer.valueOf(value));
    }

    if (key.equals(SettingActivity.SOUND)) {
      boolean value = sharedPreferences.getBoolean(key, true);
      GlobalContext.getInstance().setEnableSound(value);
    }

    if (key.equals(SettingActivity.AUTO_REFRESH)) {
      boolean value = sharedPreferences.getBoolean(key, false);
      GlobalContext.getInstance().setEnableAutoRefresh(value);
    }
  }
  @Override
  public boolean onActionItemClicked(ActionMode mode, MenuItem item) {

    switch (item.getItemId()) {
      case R.id.menu_at:
        Intent intent = new Intent(getActivity(), WriteWeiboActivity.class);
        intent.putExtra("token", GlobalContext.getInstance().getSpecialToken());
        intent.putExtra("content", "@" + bean.getScreen_name());
        intent.putExtra("account", GlobalContext.getInstance().getAccountBean());
        getActivity().startActivity(intent);
        listView.clearChoices();
        mode.finish();
        break;
      case R.id.menu_follow:
        if (followOrUnfollowTask == null
            || followOrUnfollowTask.getStatus() == MyAsyncTask.Status.FINISHED) {
          followOrUnfollowTask = new FollowTask();
          followOrUnfollowTask.executeOnExecutor(MyAsyncTask.THREAD_POOL_EXECUTOR);
        }
        listView.clearChoices();
        mode.finish();
        break;
      case R.id.menu_unfollow:
        if (followOrUnfollowTask == null
            || followOrUnfollowTask.getStatus() == MyAsyncTask.Status.FINISHED) {
          followOrUnfollowTask = new UnFollowTask();
          followOrUnfollowTask.executeOnExecutor(MyAsyncTask.THREAD_POOL_EXECUTOR);
        }
        listView.clearChoices();
        mode.finish();
        break;
    }

    return true;
  }
    @Override
    protected void onPostExecute(GroupListBean groupListBean) {
      GroupDBManager.getInstance()
          .updateGroupInfo(groupListBean, GlobalContext.getInstance().getCurrentAccountId());
      GlobalContext.getInstance().setGroup(groupListBean);

      super.onPostExecute(groupListBean);
    }
 private int getRecentNavIndex() {
   List<GroupBean> list = new ArrayList<GroupBean>();
   if (GlobalContext.getInstance().getGroup() != null) {
     list = GlobalContext.getInstance().getGroup().getLists();
   } else {
     list = new ArrayList<GroupBean>();
   }
   return getIndexFromGroupId(currentGroupId, list);
 }
  public void buildActionBarNav() {
    if ((((MainTimeLineActivity) getActivity()).getMenuFragment()).getCurrentIndex()
        != LeftMenuFragment.HOME_INDEX) {
      return;
    }
    ((MainTimeLineActivity) getActivity()).setCurrentFragment(this);

    getActivity().getActionBar().setDisplayShowTitleEnabled(false);
    getActivity().getActionBar().setDisplayHomeAsUpEnabled(Utility.isDevicePort());
    getActivity().getActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
    List<GroupBean> list = new ArrayList<GroupBean>();
    if (GlobalContext.getInstance().getGroup() != null) {
      list = GlobalContext.getInstance().getGroup().getLists();
    } else {
      list = new ArrayList<GroupBean>();
    }

    navAdapter = new FriendsTimeLineListNavAdapter(getActivity(), buildListNavData(list));
    final List<GroupBean> finalList = list;
    getActivity()
        .getActionBar()
        .setListNavigationCallbacks(
            navAdapter,
            new ActionBar.OnNavigationListener() {
              @Override
              public boolean onNavigationItemSelected(int which, long itemId) {

                if (!Utility.isTaskStopped(dbTask)) {
                  return true;
                }

                String groupId = getGroupIdFromIndex(which, finalList);

                if (!groupId.equals(currentGroupId)) {

                  switchFriendsGroup(groupId);
                }
                return true;
              }
            });
    currentGroupId =
        FriendsTimeLineDBTask.getRecentGroupId(GlobalContext.getInstance().getCurrentAccountId());

    if (Utility.isDevicePort()) {
      ((MainTimeLineActivity) getActivity()).setTitle("");
      getActivity().getActionBar().setIcon(R.drawable.ic_menu_home);
    } else {
      ((MainTimeLineActivity) getActivity()).setTitle("");
      getActivity().getActionBar().setIcon(R.drawable.ic_launcher);
    }

    if (getActivity().getActionBar().getNavigationMode() == ActionBar.NAVIGATION_MODE_LIST
        && isVisible()) {
      getActivity().getActionBar().setSelectedNavigationItem(getRecentNavIndex());
    }
  }
 public void saveNavigationPositionToDB() {
   int navPosition = getMenuFragment().getCurrentIndex() * 10;
   ActionBar actionBar = getActionBar();
   int second = 0;
   if (actionBar.getNavigationMode() != ActionBar.NAVIGATION_MODE_STANDARD) {
     second = actionBar.getSelectedNavigationIndex();
   }
   int result = navPosition + second;
   GlobalContext.getInstance().getAccountBean().setNavigationPosition(result);
   AccountDBTask.updateNavigationPosition(GlobalContext.getInstance().getAccountBean(), result);
 }
 public UserInfoFragment getMyProfileFragment() {
   UserInfoFragment fragment =
       ((UserInfoFragment)
           getSupportFragmentManager().findFragmentByTag(UserInfoFragment.class.getName()));
   if (fragment == null) {
     fragment =
         UserInfoFragment.newInstance(
             GlobalContext.getInstance().getAccountBean().getInfo(),
             GlobalContext.getInstance().getSpecialToken());
   }
   return fragment;
 }
 @Override
 protected void listViewItemClick(AdapterView parent, View view, int position, long id) {
   startActivityForResult(
       BrowserWeiboMsgActivity.newIntent(
           getList().getItem(position), GlobalContext.getInstance().getSpecialToken()),
       MainTimeLineActivity.REQUEST_CODE_UPDATE_FRIENDS_TIMELINE_COMMENT_REPOST_COUNT);
 }
Beispiel #9
0
  public static Bitmap getMiddlePictureInBrowserMSGActivity(
      String url, FileDownloaderHttpHelper.DownloadListener downloadListener) {

    try {

      String filePath = FileManager.getFilePathFromUrl(url, FileLocationMethod.picture_bmiddle);

      File file = new File(filePath);

      if (!file.exists() && !SettingUtility.isEnablePic()) {
        return null;
      }

      if (!file.exists()) {
        getBitmapFromNetWork(url, filePath, downloadListener);
      }
      file = new File(filePath);
      if (file.exists()) {
        DisplayMetrics displayMetrics = GlobalContext.getInstance().getDisplayMetrics();
        return decodeBitmapFromSDCard(filePath, displayMetrics.widthPixels, 900);
      }
      return null;
    } catch (OutOfMemoryError ignored) {
      return null;
    }
  }
Beispiel #10
0
  public static Bitmap getMiddlePictureInBrowserMSGActivity(
      String url, FileDownloaderHttpHelper.DownloadListener downloadListener) {

    String absoluteFilePath =
        FileManager.getFilePathFromUrl(url, FileLocationMethod.picture_bmiddle);

    File file = new File(absoluteFilePath);

    if (!file.exists() && !SettingUtility.isEnablePic()) {
      return null;
    }

    if (!file.exists()) {
      getBitmapFromNetWork(url, absoluteFilePath, downloadListener);
    }
    file = new File(absoluteFilePath);
    if (file.exists()) {
      DisplayMetrics displayMetrics = GlobalContext.getInstance().getDisplayMetrics();

      Bitmap bitmap =
          decodeBitmapFromSDCard(
              absoluteFilePath, displayMetrics.widthPixels, displayMetrics.heightPixels);
      return bitmap;
    }
    return null;
  }
  private String readResult(HttpURLConnection urlConnection) throws WeiboException {
    InputStream is = null;
    BufferedReader buffer = null;
    GlobalContext globalContext = GlobalContext.getInstance();
    String errorStr = globalContext.getString(R.string.timeout);
    globalContext = null;
    try {
      is = urlConnection.getInputStream();

      String content_encode = urlConnection.getContentEncoding();

      if (null != content_encode && !"".equals(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("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();
    }
  }
  public String doGet(String urlStr, Map<String, String> param) throws WeiboException {
    GlobalContext globalContext = GlobalContext.getInstance();
    String errorStr = globalContext.getString(R.string.timeout);
    globalContext = null;
    InputStream is = null;
    try {

      StringBuilder urlBuilder = new StringBuilder(urlStr);
      urlBuilder.append("?").append(Utility.encodeUrl(param));
      URL url = new URL(urlBuilder.toString());
      AppLogger.d("get request" + url);
      Proxy proxy = getProxy();
      HttpURLConnection urlConnection;
      if (proxy != null) urlConnection = (HttpURLConnection) url.openConnection(proxy);
      else urlConnection = (HttpURLConnection) url.openConnection();

      urlConnection.setRequestMethod("GET");
      urlConnection.setDoOutput(false);
      urlConnection.setConnectTimeout(CONNECT_TIMEOUT);
      urlConnection.setReadTimeout(READ_TIMEOUT);
      urlConnection.setRequestProperty("Connection", "Keep-Alive");
      urlConnection.setRequestProperty("Charset", "UTF-8");
      urlConnection.setRequestProperty("Accept-Encoding", "gzip, deflate");

      urlConnection.connect();

      return handleResponse(urlConnection);
    } catch (IOException e) {
      e.printStackTrace();
      throw new WeiboException(errorStr, e);
    }
  }
  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();
      HttpURLConnection uRLConnection;
      if (proxy != null) uRLConnection = (HttpURLConnection) url.openConnection(proxy);
      else uRLConnection = (HttpURLConnection) 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);
    }
  }
 @Override
 protected DMListBean getDoInBackgroundNewData() throws WeiboException {
   page = 1;
   return new DMConversationDao(GlobalContext.getInstance().getSpecialToken())
       .setUid(userBean.getId())
       .setPage(page)
       .getConversationList();
 }
 @Override
 protected DMListBean getDoInBackgroundOldData() throws WeiboException {
   DMConversationDao dao =
       new DMConversationDao(GlobalContext.getInstance().getSpecialToken())
           .setUid(userBean.getId())
           .setPage(page + 1);
   DMListBean result = dao.getConversationList();
   return result;
 }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    getActionBar().setTitle(R.string.comments);
    getActionBar().setSubtitle(GlobalContext.getInstance().getCurrentAccountName());

    token = getIntent().getStringExtra("token");
    if (TextUtils.isEmpty(token)) token = GlobalContext.getInstance().getSpecialToken();

    msg = (MessageBean) getIntent().getSerializableExtra("msg");
    if (msg == null) {
      commentDraftBean = (CommentDraftBean) getIntent().getSerializableExtra("draft");
      msg = commentDraftBean.getMessageBean();
      getEditTextView().setText(commentDraftBean.getContent());
    }

    getEditTextView().setHint("@" + msg.getUser().getScreen_name() + ":" + msg.getText());
  }
 @Override
 protected List<MessageReCmtCountBean> doInBackground(Void... params) {
   try {
     return new TimeLineReCmtCountDao(GlobalContext.getInstance().getSpecialToken(), msgIds)
         .get();
   } catch (WeiboException e) {
     cancel(true);
   }
   return null;
 }
 @Override
 public void saveToDraft() {
   if (!TextUtils.isEmpty(getEditTextView().getText().toString())) {
     DraftDBManager.getInstance()
         .insertComment(
             getEditTextView().getText().toString(),
             msg,
             GlobalContext.getInstance().getCurrentAccountId());
   }
   finish();
 }
 private void savePositionToDB() {
   TimeLinePosition position = positionCache.get(currentGroupId);
   if (position == null) {
     savePositionToPositionsCache();
     position = positionCache.get(currentGroupId);
   }
   position.newMsgIds = newMsgTipBar.getValues();
   final String groupId = currentGroupId;
   FriendsTimeLineDBTask.asyncUpdatePosition(
       position, GlobalContext.getInstance().getCurrentAccountId(), groupId);
 }
 @Override
 public void onResume() {
   super.onResume();
   addRefresh();
   GlobalContext.getInstance().registerForAccountChangeListener(this);
   if (SettingUtility.getEnableAutoRefresh()) {
     this.newMsgTipBar.setType(TopTipBar.Type.ALWAYS);
   } else {
     this.newMsgTipBar.setType(TopTipBar.Type.AUTO);
   }
 }
 @Override
 public boolean onOptionsItemSelected(MenuItem item) {
   Intent intent;
   switch (item.getItemId()) {
     case R.id.name:
       intent = new Intent(getActivity(), MyInfoActivity.class);
       intent.putExtra("token", token);
       intent.putExtra("user", userBean);
       intent.putExtra("account", GlobalContext.getInstance().getAccountBean());
       startActivity(intent);
       break;
     case R.id.write_weibo:
       intent = new Intent(getActivity(), WriteWeiboActivity.class);
       intent.putExtra("token", token);
       intent.putExtra("account", GlobalContext.getInstance().getAccountBean());
       startActivity(intent);
       break;
   }
   return true;
 }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (savedInstanceState != null) {
      accountBean = savedInstanceState.getParcelable("account");
    } else {
      Intent intent = getIntent();
      accountBean = intent.getParcelableExtra(BundleArgsConstants.ACCOUNT_EXTRA);
    }

    if (accountBean == null) {
      accountBean = GlobalContext.getInstance().getAccountBean();
    }

    GlobalContext.getInstance().setGroup(null);
    GlobalContext.getInstance().setAccountBean(accountBean);
    SettingUtility.setDefaultAccountId(accountBean.getUid());

    buildInterface(savedInstanceState);
  }
  private void initFragments() {
    Fragment friend = getFriendsTimeLineFragment();
    Fragment mentions = getMentionsTimeLineFragment();
    Fragment comments = getCommentsTimeLineFragment();

    Fragment fav = getFavFragment();
    Fragment myself = getMyProfileFragment();

    FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
    if (!friend.isAdded()) {
      fragmentTransaction.add(R.id.menu_right_fl, friend, FriendsTimeLineFragment.class.getName());
      fragmentTransaction.hide(friend);
    }
    if (!mentions.isAdded()) {
      fragmentTransaction.add(R.id.menu_right_fl, mentions, MentionsTimeLine.class.getName());
      fragmentTransaction.hide(mentions);
    }
    if (!comments.isAdded()) {
      fragmentTransaction.add(R.id.menu_right_fl, comments, CommentsTimeLine.class.getName());
      fragmentTransaction.hide(comments);
    }

    if (!fav.isAdded()) {
      fragmentTransaction.add(R.id.menu_right_fl, fav, MyFavListFragment.class.getName());
      fragmentTransaction.hide(fav);
    }

    if (!myself.isAdded()) {
      fragmentTransaction.add(R.id.menu_right_fl, myself, UserInfoFragment.class.getName());
      fragmentTransaction.hide(myself);
    }

    if (GlobalContext.getInstance().getAccountBean().isBlack_magic()) {
      Fragment search = getSearchFragment();
      Fragment dm = getDMFragment();

      if (!search.isAdded()) {
        fragmentTransaction.add(
            R.id.menu_right_fl, search, SearchMainParentFragment.class.getName());
        fragmentTransaction.hide(search);
      }

      if (!dm.isAdded()) {
        fragmentTransaction.add(R.id.menu_right_fl, dm, DMUserListFragment.class.getName());
        fragmentTransaction.hide(dm);
      }
    }

    if (!fragmentTransaction.isEmpty()) {
      fragmentTransaction.commit();
      getSupportFragmentManager().executePendingTransactions();
    }
  }
    @Override
    protected Void doInBackground(Void... params) {
      Map<String, String> emotions = GlobalContext.getInstance().getEmotions();
      List<String> index = new ArrayList<String>();
      index.addAll(emotions.keySet());
      for (String str : index) {
        if (!isCancelled()) {
          String url = emotions.get(str);
          String path = FileManager.getFileAbsolutePathFromUrl(url, FileLocationMethod.emotion);
          String name = new File(path).getName();
          AssetManager assetManager = GlobalContext.getInstance().getAssets();
          InputStream inputStream;
          try {
            inputStream = assetManager.open(name);
            Bitmap bitmap = BitmapFactory.decodeStream(inputStream);
            emotionsPic.put(str, bitmap);
          } catch (IOException ignored) {

          }
        }
      }
      return null;
    }
Beispiel #25
0
  private HttpResponse getHttpResponse(HttpRequestBase httpRequest, HttpContext localContext)
      throws WeiboException {
    HttpResponse response = null;
    try {
      if (localContext != null) {
        response = httpClient.execute(httpRequest, localContext);
      } else {
        response = httpClient.execute(httpRequest);
      }
    } catch (ConnectTimeoutException e) {

      AppLogger.e(e.getMessage());
      throw new WeiboException(GlobalContext.getInstance().getString(R.string.timeout), e);

    } catch (ClientProtocolException e) {
      AppLogger.e(e.getMessage());
      throw new WeiboException(GlobalContext.getInstance().getString(R.string.timeout), e);

    } catch (IOException e) {
      AppLogger.e(e.getMessage());
      throw new WeiboException(GlobalContext.getInstance().getString(R.string.timeout), e);
    }
    return response;
  }
    @Override
    protected UserBean doInBackground(Void... params) {

      FriendshipsDao dao = new FriendshipsDao(GlobalContext.getInstance().getSpecialToken());
      if (!TextUtils.isEmpty(bean.getId())) {
        dao.setUid(bean.getId());
      } else {
        dao.setScreen_name(bean.getScreen_name());
      }
      try {
        return dao.followIt();
      } catch (WeiboException e) {
        AppLogger.e(e.getError());
        this.e = e;
        cancel(true);
        return null;
      }
    }
 @Override
 public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
   super.onCreateOptionsMenu(menu, inflater);
   inflater.inflate(R.menu.actionbar_menu_friendstimelinefragment, menu);
   name = menu.findItem(R.id.group_name);
   if (selectedId.equals("0")) {
     name.setTitle(userBean.getScreen_name());
   }
   if (selectedId.equals("1")) {
     name.setTitle(getString(R.string.bilateral));
   } else {
     for (GroupBean b : GlobalContext.getInstance().getGroup().getLists()) {
       if (b.getIdstr().equals(selectedId)) {
         name.setTitle(b.getName());
         return;
       }
     }
   }
 }
  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);
  }
  @Override
  protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);
    AccountBean intentAccountBean = intent.getParcelableExtra(BundleArgsConstants.ACCOUNT_EXTRA);
    if (intentAccountBean == null) {
      return;
    }

    if (accountBean.equals(intentAccountBean)) {
      accountBean = intentAccountBean;
      GlobalContext.getInstance().setAccountBean(accountBean);
      setIntent(intent);
    } else {
      finish();
      overridePendingTransition(0, 0);
      startActivity(intent);
      overridePendingTransition(0, 0);
    }
  }
Beispiel #30
0
  @Override
  public void run() {

    Thread.currentThread().setPriority(Thread.MIN_PRIORITY);

    AppLogger.d("clear cache task start");

    if (Utility.isWifi(GlobalContext.getInstance())) {

      List<String> pathList = FileManager.getCachePath();

      for (String path : pathList) {
        if (!TextUtils.isEmpty(path)) handleDir(new File(path));
      }

      AppLogger.d("clear cache task stop");
    } else {
      AppLogger.d("this device dont have wifi network, clear cache task stop");
    }
  }