示例#1
0
  @Override
  public void onResume() {
    super.onResume();
    Log.d(LOG_TAG, "onResume()");

    for (int i = 0; i <= mList.getChildCount(); i++) {
      mAdapter.updatePlusOne(mList.getChildAt(i));
    }
  }
示例#2
0
 @Override
 public void onStart() {
   super.onStart();
   Log.d(LOG_TAG, "onStart()");
 }
示例#3
0
 @Override
 public void onSaveInstanceState(Bundle outState) {
   Log.d(LOG_TAG, "onSaveInstanceState()");
   super.onSaveInstanceState(outState);
 }
示例#4
0
 @Override
 public void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
 }
示例#5
0
 @Override
 public void onDestroy() {
   super.onDestroy();
   Log.d(LOG_TAG, "onDestroy()");
 }
示例#6
0
 @Override
 public void onViewCreated(View view, Bundle savedInstanceState) {
   super.onViewCreated(view, savedInstanceState);
 }
示例#7
0
 @Override
 public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
   super.onCreateContextMenu(menu, v, menuInfo);
   AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
   getActivity().getMenuInflater().inflate(R.menu.news_context, menu);
 }
示例#8
0
  @Override
  public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    Log.d(LOG_TAG, "onActivityCreated()");

    mClient =
        new Plus.Builder(mTransport, mJsonFactory, null)
            .setGoogleClientRequestInitializer(
                new CommonGoogleJsonClientRequestInitializer(
                    getString(R.string.ip_simple_api_access_key)))
            .build();

    PlusClient plusClient = null;
    if (((GdgActivity) getActivity()).getPlayServicesHelper() != null) {
      plusClient = ((GdgActivity) getActivity()).getPlayServicesHelper().getPlusClient();
    }
    mAdapter = new NewsAdapter(getActivity(), plusClient);
    setListAdapter(mAdapter);

    registerForContextMenu(getListView());

    ((GdgActivity) getActivity())
        .getPullToRefreshHelper()
        .addRefreshableView(
            getListView(),
            new PullToRefreshAttacher.ViewDelegate() {
              @Override
              public boolean isScrolledToTop(View view) {
                AbsListView absListView = (AbsListView) view;
                if (absListView.getCount() == 0) {
                  return true;
                } else if (absListView.getFirstVisiblePosition() == 0) {
                  final View firstVisibleChild = absListView.getChildAt(0);
                  return firstVisibleChild != null && firstVisibleChild.getTop() >= 0;
                }
                return false;
              }
            },
            this);

    if (getListView() instanceof ListView) {
      ListView listView = (ListView) getListView();
      listView.setDivider(null);
      listView.setDividerHeight(0);
    }

    if (Utils.isOnline(getActivity())) {
      new Builder<String, ActivityFeed>(String.class, ActivityFeed.class)
          .addParameter(getArguments().getString("plus_id"))
          .setOnPreExecuteListener(
              new CommonAsyncTask.OnPreExecuteListener() {
                @Override
                public void onPreExecute() {
                  setIsLoading(true);
                }
              })
          .setOnBackgroundExecuteListener(
              new CommonAsyncTask.OnBackgroundExecuteListener<String, ActivityFeed>() {
                @Override
                public ActivityFeed doInBackground(String... params) {
                  try {

                    ActivityFeed feed =
                        (ActivityFeed) App.getInstance().getModelCache().get("news_" + params[0]);

                    if (feed == null) {
                      Plus.Activities.List request = mClient.activities().list(params[0], "public");
                      request.setMaxResults(10L);
                      request.setFields(
                          "nextPageToken,items(id,published,url,object/content,verb,object/attachments,object/actor,annotation,object(plusoners,replies,resharers))");
                      feed = request.execute();

                      App.getInstance()
                          .getModelCache()
                          .put("news_" + params[0], feed, DateTime.now().plusHours(1));
                    }

                    return feed;
                  } catch (IOException e) {
                    e.printStackTrace();
                  }
                  return null;
                }
              })
          .setOnPostExecuteListener(
              new CommonAsyncTask.OnPostExecuteListener<ActivityFeed>() {
                @Override
                public void onPostExecute(ActivityFeed activityFeed) {
                  if (activityFeed != null) {
                    mAdapter.addAll(activityFeed.getItems());
                    setIsLoading(false);
                  }
                }
              })
          .buildAndExecute();
    } else {
      App.getInstance()
          .getModelCache()
          .getAsync(
              "news_" + getArguments().getString("plus_id"),
              false,
              new ModelCache.CacheListener() {
                @Override
                public void onGet(Object item) {
                  ActivityFeed feed = (ActivityFeed) item;

                  if (isAdded())
                    Crouton.makeText(getActivity(), getString(R.string.cached_content), Style.INFO)
                        .show();

                  mAdapter.addAll(feed.getItems());
                  setIsLoading(false);
                }

                @Override
                public void onNotFound(String key) {
                  if (isAdded())
                    Crouton.makeText(getActivity(), getString(R.string.offline_alert), Style.ALERT)
                        .show();
                }
              });
    }
  }
示例#9
0
 @Override
 public void onPause() {
   super.onPause();
   Log.d(LOG_TAG, "onPause()");
 }