Android Open Source - Test-SimpleTwitterClient Searchable Activity






From Project

Back to project page Test-SimpleTwitterClient.

License

The source code is released under:

This is free and unencumbered software released into the public domain. Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a co...

If you think the Android project Test-SimpleTwitterClient listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.example.Twitter_Android.AppActivity;
/*from   w w  w . java 2s  .  c  om*/
import android.app.ListActivity;
import android.app.LoaderManager;
import android.app.SearchManager;
import android.content.Intent;
import android.content.Loader;
import android.net.Uri;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import com.example.Twitter_Android.Logic.Constants;
import com.example.Twitter_Android.Fragments.Adapters.FollowingsListAdapter;
import com.example.Twitter_Android.Fragments.Adapters.TweetAdapter;
import com.example.Twitter_Android.Loaders.Task_LoadSearchedTweets;
import com.example.Twitter_Android.Loaders.Task_LoadSearchedUsers;
import com.example.Twitter_Android.Logic.Person;
import com.example.Twitter_Android.Logic.Tweet;
import com.example.Twitter_Android.R;

import java.util.List;

public class SearchableActivity extends ListActivity implements LoaderManager.LoaderCallbacks {
  private static final String ADAPTER_TAG = "SEARCH_ACTIVITY";
  private static final int TWEETS_LOADER = Constants.SEARCH_RESULT_LOADER;
  private static final int USERS_LOADER = Constants.SEARCH_USERS_LOADER;
  private static final String QUERY = "QUERY";


  private TweetAdapter tweetAdapter;
  private FollowingsListAdapter followingsAdapter;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Intent intent = getIntent();
    String intentAction = intent.getAction();
    if ((intentAction != null) && (intentAction.equals(Intent.ACTION_SEARCH))) {
      String query = intent.getStringExtra(SearchManager.QUERY);
      doSearch(query);
    }
  }

  @Override
  protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);
    String action = intent.getAction();
    if ((action != null) && (action.equals(Intent.ACTION_SEARCH))) {
      String query = intent.getStringExtra(SearchManager.QUERY);
      doSearch(query);
    }
  }

  private void doSearch(String query) {
    Bundle args = new Bundle();
    args.putString(QUERY, query);
    if (query.trim().startsWith("@")) {
      getLoaderManager().restartLoader(USERS_LOADER, args, this);
    } else {
      getLoaderManager().restartLoader(TWEETS_LOADER, args, this);
    }
  }

  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.menu_home_timeline, menu);

    return true;
  }

  @Override
  public Loader onCreateLoader(int id, Bundle args) {
    String query = args.getString(QUERY, "Need_question");
    String qq = Uri.encode(query);
    Loader loader;
    switch (id) {
      case TWEETS_LOADER:
        loader = new Task_LoadSearchedTweets(this, qq);
        return loader;
      case USERS_LOADER:
        loader = new Task_LoadSearchedUsers(this, qq);
        return loader;
    }
    return null;
  }


  @Override
  public void onLoadFinished(Loader loader, Object data) {
    if (loader.getId() == TWEETS_LOADER) {
      if (tweetAdapter == null) {
        tweetAdapter = new TweetAdapter(this, (List<Tweet>) data, ADAPTER_TAG);
        setListAdapter(tweetAdapter);
      } else {
        tweetAdapter.addItemsInstead((List<Tweet>) data);
      }
      followingsAdapter = null;
    } else if (loader.getId() == USERS_LOADER) {
      if (followingsAdapter == null) {
        followingsAdapter = new FollowingsListAdapter(this, (List<Person>) data, ADAPTER_TAG);
        setListAdapter(followingsAdapter);
      } else {
        followingsAdapter.addItemsInstead((List<Person>) data);
      }
      tweetAdapter = null;
    }
  }

  @Override
  public void onLoaderReset(Loader loader) {

  }

}




Java Source Code List

com.example.Twitter_Android.AppActivity.ConcreteUserTimelineActivity.java
com.example.Twitter_Android.AppActivity.MainActivity.java
com.example.Twitter_Android.AppActivity.MessagesActivity.java
com.example.Twitter_Android.AppActivity.SearchableActivity.java
com.example.Twitter_Android.AppActivity.SettingsActivity.java
com.example.Twitter_Android.AsynkTasks.ImageDownloader.java
com.example.Twitter_Android.AsynkTasks.TaskDeleteTweet.java
com.example.Twitter_Android.AsynkTasks.TaskFollow.java
com.example.Twitter_Android.AsynkTasks.TaskPostTweet.java
com.example.Twitter_Android.AsynkTasks.TaskReply.java
com.example.Twitter_Android.AsynkTasks.TaskRetweet.java
com.example.Twitter_Android.AsynkTasks.TaskSendMessage.java
com.example.Twitter_Android.AsynkTasks.TaskUnfollow.java
com.example.Twitter_Android.Fragments.ConcreteUserTimelineFragment.java
com.example.Twitter_Android.Fragments.ConnectedUserTimelineFragment.java
com.example.Twitter_Android.Fragments.FollowersFragment.java
com.example.Twitter_Android.Fragments.FollowingsFragment.java
com.example.Twitter_Android.Fragments.HomeTimelineFragment.java
com.example.Twitter_Android.Fragments.TimelineFragment.java
com.example.Twitter_Android.Fragments.UserInfoFragment.java
com.example.Twitter_Android.Fragments.Adapters.ConcreteUserTimelineAdapter.java
com.example.Twitter_Android.Fragments.Adapters.FollowingsListAdapter.java
com.example.Twitter_Android.Fragments.Adapters.MessagesAdapter.java
com.example.Twitter_Android.Fragments.Adapters.TimelineAdapter.java
com.example.Twitter_Android.Fragments.Adapters.TweetAdapter.java
com.example.Twitter_Android.Fragments.Dialogs.DeleteTweetDialog.java
com.example.Twitter_Android.Fragments.Dialogs.DirectMessageDialog.java
com.example.Twitter_Android.Fragments.Dialogs.ErrorDialog.java
com.example.Twitter_Android.Fragments.Dialogs.PostTweetDialog.java
com.example.Twitter_Android.Fragments.Dialogs.ReplyDialog.java
com.example.Twitter_Android.Fragments.Dialogs.RetweetDialog.java
com.example.Twitter_Android.Fragments.Dialogs.ShowImageDialog.java
com.example.Twitter_Android.Fragments.Dialogs.UserInfoDialog.java
com.example.Twitter_Android.Fragments.Preferences.SettingsFragment.java
com.example.Twitter_Android.Loaders.AsyncUserInfoLoader.java
com.example.Twitter_Android.Loaders.FollowersLoader.java
com.example.Twitter_Android.Loaders.FollowingsLoader.java
com.example.Twitter_Android.Loaders.HomeTimelineLoader.java
com.example.Twitter_Android.Loaders.MessageLoader.java
com.example.Twitter_Android.Loaders.Task_LoadSearchedTweets.java
com.example.Twitter_Android.Loaders.Task_LoadSearchedUsers.java
com.example.Twitter_Android.Loaders.TweetLoader.java
com.example.Twitter_Android.Loaders.UserTimelineLoader.java
com.example.Twitter_Android.Logic.AppDatabase.java
com.example.Twitter_Android.Logic.Constants.java
com.example.Twitter_Android.Logic.DataCache.java
com.example.Twitter_Android.Logic.FileWorker.java
com.example.Twitter_Android.Logic.Person.java
com.example.Twitter_Android.Logic.Tweet.java
com.example.Twitter_Android.Net.Connector.java
com.example.Twitter_Android.Net.Parser.java
com.mass.cmassive.CMassive.java