private void handleIntent(Intent intent) {
    // Special processing of the incoming intent only occurs if the action specified
    // by the intent is ACTION_SEARCH.
    if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
      String query = intent.getStringExtra(SearchManager.QUERY);

      SearchRecentSuggestions suggestions =
          new SearchRecentSuggestions(
              this,
              SearchRecentSuggestionsProviderImpl.AUTHORITY,
              SearchRecentSuggestionsProviderImpl.MODE);
      suggestions.saveRecentQuery(query, null);

      if (mTwoPane) {
        TopTracksActivityFragment fragment = new TopTracksActivityFragment();
        mUserLeaveHintCallback = fragment;
        getSupportFragmentManager()
            .beginTransaction()
            .replace(R.id.activity_fragment_top_tracks, fragment, TOPTRACKS_FRAGMENT_TAG)
            .commit();
      }

      // do the actual search on the fragment
      MainActivityFragment mainActivityFragment =
          (MainActivityFragment)
              getSupportFragmentManager().findFragmentById(R.id.activity_fragment_main);

      mainActivityFragment.searchArtists(query);
    }
  }
  private void doSearch(String query) {

    SearchRecentSuggestions suggestions =
        new SearchRecentSuggestions(
            this, RoomFinderSuggestionProvider.AUTHORITY, RoomFinderSuggestionProvider.MODE);
    suggestions.saveRecentQuery(query, null);

    roomFinderRequest.fetchSearchInteractive(this, this, query);
  }
  @Override
  public boolean performSearchAlgorithm() {
    EditText searchString = (EditText) this.findViewById(R.id.search_field);

    SearchRecentSuggestions suggestions =
        new SearchRecentSuggestions(
            this, RoomFinderSuggestionProvider.AUTHORITY, RoomFinderSuggestionProvider.MODE);
    suggestions.saveRecentQuery(searchString.getText().toString(), null);

    roomFinderRequest.fetchSearchInteractive(this, this, searchString.getText().toString());
    return true;
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Get the intent, verify the action and get the query
    Intent intent = getIntent();
    if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
      String query = intent.getStringExtra(SearchManager.QUERY);
      SearchRecentSuggestions suggestions =
          new SearchRecentSuggestions(
              this, RecentSuggestionsProvider.AUTHORITY, RecentSuggestionsProvider.MODE);
      suggestions.saveRecentQuery(query, null);
      finish();
    }
  }
  private void handleIntent(final Intent intent) {
    if (ACTION_SEARCH.equals(intent.getAction())) {

      final String query = intent.getStringExtra(SearchManager.QUERY);

      Log.d(TAG, Utils.buildStr("Searching for food [", query, "]"));

      SearchRecentSuggestions suggestions =
          new SearchRecentSuggestions(
              this, RecentSearchesProvider.AUTHORITY, RecentSearchesProvider.MODE);
      suggestions.saveRecentQuery(query, null);

      new SearchProgressTask(this, PROGRESS_DIALOG).execute(query);
    }
  }
 @Override
 public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
   final String key = preference.getKey();
   if (KEY_CLEAR_SEARCH_HISTORY.equals(key)) {
     SearchRecentSuggestions suggestions =
         new SearchRecentSuggestions(
             getActivity(),
             Utils.getSearchAuthority(getActivity()),
             CalendarRecentSuggestionsProvider.MODE);
     suggestions.clearHistory();
     Toast.makeText(getActivity(), R.string.search_history_cleared, Toast.LENGTH_SHORT).show();
     return true;
   } else {
     return super.onPreferenceTreeClick(preferenceScreen, preference);
   }
 }
Beispiel #7
0
  @Override
  protected void onNewIntent(Intent intent) {

    super.onNewIntent(intent);

    if (intent.getAction() == "android.intent.action.SEARCH") {

      showSearch(false); // Suchfeld schliessen

      // Suchbegriff speichern in der Vorschlagsliste
      Bundle extras = intent.getExtras();
      String userQuery = String.valueOf(extras.get(SearchManager.USER_QUERY));
      String query = String.valueOf(extras.get(SearchManager.QUERY));
      suggestions.saveRecentQuery(query, "in Kontakten");

      // Toast.makeText(this, "query: " + query + " user_query: " + userQuery,
      // Toast.LENGTH_SHORT).show(); // TEST Meldung

      Bundle args = new Bundle(); // Uebergabe-Parameter für Fragment erstellen
      args.putString("search", query);
      getSupportActionBar().setSubtitle("Suche  '" + query + "'");

      showFragment("list", args); // Fragment OrdersList anzeigen
    }
  }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    String query = getIntent().getStringExtra(SearchManager.QUERY);

    if (query != null) {
      SearchRecentSuggestions suggestions =
          new SearchRecentSuggestions(
              this, SearchSuggestionProvider.AUTHORITY, SearchSuggestionProvider.MODE);
      suggestions.saveRecentQuery(query, null);

      Intent intent = new Intent(VoiceQueryReceiverActivity.this, SearchActivity.class);
      intent.putExtra(Constants.INTENT_EXTRA_NAME_QUERY, query);
      intent.putExtra(Constants.INTENT_EXTRA_NAME_AUTOPLAY, true);
      Util.startActivityWithoutTransition(VoiceQueryReceiverActivity.this, intent);
    }
    finish();
    Util.disablePendingTransition(this);
  }
  private void checkSearch(Intent intent) {
    if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
      String query = intent.getStringExtra(SearchManager.QUERY);
      Log.d("basti", "Search String: " + query);

      SearchRecentSuggestions suggestions =
          new SearchRecentSuggestions(
              this, SelectScreenSavedSearches.AUTHORITY, SelectScreenSavedSearches.MODE);
      suggestions.saveRecentQuery(query, null);

      if (searchForSearchResults(classSpinner, query)) return;
      if (searchForSearchResults(teacherSpinner, query)) return;
      if (searchForSearchResults(roomSpinner, query)) return;
      if (searchForSearchResults(subjectSpinner, query)) return;

      Toast.makeText(
              this, getResources().getString(R.string.selectscreen_search_fail), Toast.LENGTH_SHORT)
          .show();
    }
  }
  @Override
  public void onNewIntent(Intent intent) {
    if (DEBUG) Log.d(TAG, "New Intent: " + intent);
    String action = intent.getAction();
    String query = intent.getStringExtra(SearchManager.QUERY);

    if (intent == null) {
      if (DEBUG) Log.d(TAG, "No intent to search, querying default.");
      executeSearchTask(query);

    } else if (Intent.ACTION_SEARCH.equals(action) && query != null) {
      if (DEBUG) Log.d(TAG, "onNewIntent received search intent and saving.");
      SearchRecentSuggestions suggestions =
          new SearchRecentSuggestions(
              this, VenueQuerySuggestionsProvider.AUTHORITY, VenueQuerySuggestionsProvider.MODE);
      suggestions.saveRecentQuery(query, null);
      executeSearchTask(query);
    } else {
      onSearchRequested();
    }
  }
Beispiel #11
0
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {

    int id = item.getItemId();

    switch (id) {
      case R.id.action_settings: // TODO
        return true;

      case R.id.itm_action_search: // TODO
        showSearch(true);
        return true;

      case R.id.action_clear_history: // ok
        suggestions.clearHistory();
        return true;
    }
    return super.onOptionsItemSelected(item);
  }
Beispiel #12
0
  private void handleIntent(Intent intent) {

    // Extract string from intent
    String query = intent.getStringExtra(SearchManager.QUERY);

    if (query == null || query.length() <= 0 || !Intent.ACTION_SEARCH.equals(intent.getAction())) {
      // No (valid) query provided
      empty.setText(R.string.search_no_query);
      // Provide search input
      onSearchRequested();
      return;
    }

    // Remember this search query to later show as a suggestion
    suggestions.saveRecentQuery(query, null);

    // Start search task
    new SearchTask(Search.this).execute(query, getUserId());
  }
  /**
   * Method that do the search.
   *
   * @param voiceQuery Indicates if the query is from voice recognition
   * @param query The terms of the search
   * @param searchDirectory The directory of the search
   * @hide
   */
  void doSearch(final boolean voiceQuery, final Query query, final String searchDirectory) {

    // Recovers the user preferences about save suggestions
    boolean saveSuggestions =
        Preferences.getSharedPreferences()
            .getBoolean(
                FileManagerSettings.SETTINGS_SAVE_SEARCH_TERMS.getId(),
                ((Boolean) FileManagerSettings.SETTINGS_SAVE_SEARCH_TERMS.getDefaultValue())
                    .booleanValue());
    if (saveSuggestions) {
      // Save every query for use as recent suggestions
      SearchRecentSuggestions suggestions =
          new SearchRecentSuggestions(
              this, RecentSearchesContentProvider.AUTHORITY, RecentSearchesContentProvider.MODE);
      if (!voiceQuery) {
        List<String> queries = query.getQueries();
        int cc = queries.size();
        for (int i = 0; i < cc; i++) {
          suggestions.saveRecentQuery(queries.get(i), null);
        }
      }
    }

    // Set the listview
    this.mResultList = new ArrayList<FileSystemObject>();
    SearchResultAdapter adapter =
        new SearchResultAdapter(
            this, new ArrayList<SearchResult>(), R.layout.search_item, this.mQuery);
    this.mSearchListView.setAdapter(adapter);

    // Set terms
    this.mSearchTerms.setText(Html.fromHtml(getString(R.string.search_terms, query.getTerms())));

    // Now, do the search in background
    this.mSearchListView.post(
        new Runnable() {
          @Override
          public void run() {
            try {
              // Retrieve the terms of the search
              String label = getString(R.string.searching_action_label);

              // Show a dialog for the progress
              SearchActivity.this.mDialog =
                  new MessageProgressDialog(
                      SearchActivity.this, 0, R.string.searching, label, true);
              // Initialize the
              setProgressMsg(0);

              // Set the cancel listener
              SearchActivity.this.mDialog.setOnCancelListener(
                  new MessageProgressDialog.OnCancelListener() {
                    @Override
                    public boolean onCancel() {
                      // User has requested the cancellation of the search
                      // Broadcast the cancellation
                      if (!SearchActivity.this.mExecutable.isCancelled()) {
                        if (SearchActivity.this.mExecutable.cancel()) {
                          ListAdapter listAdapter =
                              SearchActivity.this.mSearchListView.getAdapter();
                          if (listAdapter != null) {
                            SearchActivity.this.toggleResults(listAdapter.getCount() > 0, true);
                          }
                          return true;
                        }
                        return false;
                      }
                      return true;
                    }
                  });
              SearchActivity.this.mDialog.show();

              // Execute the query (search are process in background)
              SearchActivity.this.mExecutable =
                  CommandHelper.findFiles(
                      SearchActivity.this,
                      searchDirectory,
                      SearchActivity.this.mQuery,
                      SearchActivity.this,
                      null);

            } catch (Throwable ex) {
              // Remove all elements
              try {
                SearchActivity.this.removeAll();
              } catch (Throwable ex2) {
                /** NON BLOCK* */
              }
              try {
                if (SearchActivity.this.mDialog != null) {
                  SearchActivity.this.mDialog.dismiss();
                }
              } catch (Throwable ex2) {
                /** NON BLOCK* */
              }

              // Capture the exception
              Log.e(TAG, "Search failed", ex); // $NON-NLS-1$
              DialogHelper.showToast(
                  SearchActivity.this, R.string.search_error_msg, Toast.LENGTH_SHORT);
              SearchActivity.this.mSearchListView.setVisibility(View.GONE);
            }
          }
        });
  }
Beispiel #14
0
  /** Called when the activity is created. */
  @SuppressLint("NewApi")
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Preferences.init(this, CLEAR_PREFERENCES);
    context = this;
    SyncManager.setActivity(this);
    SyncManager.setHandler(this.syncMessageHandler);

    main = View.inflate(this, R.layout.main, null);

    setContentView(main);

    // get the Path to the notes-folder from Preferences
    if (Preferences.getString(Preferences.Key.SD_LOCATION).startsWith("/")) {
      NOTES_PATH = Preferences.getString(Preferences.Key.SD_LOCATION);
    } else {
      NOTES_PATH =
          Environment.getExternalStorageDirectory()
              + "/"
              + Preferences.getString(Preferences.Key.SD_LOCATION)
              + "/";
    }

    // generate the http header we want to send on syncing
    getPackageManager();
    try {
      PackageInfo pi =
          getPackageManager().getPackageInfo(getPackageName(), PackageManager.GET_META_DATA);
      HTTP_HEADER =
          String.format(
              "%1$s v%2$s, build %3$s, Android v%4$s, %5$s/%6$s",
              pi.packageName,
              pi.versionName,
              pi.versionCode,
              Build.VERSION.RELEASE,
              Build.MANUFACTURER,
              Build.MODEL);
    } catch (NameNotFoundException e) {
      e.printStackTrace();
      HTTP_HEADER = "Tomdroid vunknown, build unknown, Android unknown, unknown/unknown";
    }
    TLog.v(TAG, "Generated http-header: {0}: {1}", "X-Tomboy-Client", Tomdroid.HTTP_HEADER);

    // did we already show the warning and got destroyed by android's activity killer?
    if (Preferences.getBoolean(Preferences.Key.FIRST_RUN)) {
      TLog.i(TAG, "Tomdroid is first run.");

      // add a first explanatory note
      NoteManager.putNote(this, FirstNote.createFirstNote(this));

      // Warn that this is a "will eat your babies" release
      showDialog(DIALOG_FIRST_RUN);
    }

    this.intent = getIntent();

    if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
      this.setTitle(getString(R.string.app_name) + " - " + getString(R.string.SearchResultTitle));
      query = intent.getStringExtra(SearchManager.QUERY);

      // adds query to search history suggestions
      SearchRecentSuggestions suggestions =
          new SearchRecentSuggestions(
              this, SearchSuggestionProvider.AUTHORITY, SearchSuggestionProvider.MODE);
      suggestions.saveRecentQuery(query, null);
    } else {
      // if main view -> disable the tomdroid icon home button
      setHomeButtonEnabled(false);
    }

    String defaultSortOrder = Preferences.getString(Preferences.Key.SORT_ORDER);
    NoteManager.setSortOrder(defaultSortOrder);

    // set list adapter
    updateNotesList(query, -1);

    // add note to pane for tablet
    rightPane = (LinearLayout) findViewById(R.id.right_pane);
    registerForContextMenu(findViewById(android.R.id.list));

    // check if receiving note
    if (getIntent().hasExtra("view_note")) {
      uri = getIntent().getData();
      getIntent().setData(null);
      Intent i = new Intent(Intent.ACTION_VIEW, uri, this, ViewNote.class);
      startActivity(i);
    }

    if (rightPane != null) {
      content = (TextView) findViewById(R.id.content);
      title = (TextView) findViewById(R.id.title);

      // this we will call on resume as well.
      updateTextAttributes();
      showNoteInPane(0);
    }

    // set the view shown when the list is empty
    updateEmptyList(query);

    // Syncing if SyncOnStart (pref) set AND onCreate_SyncOnStart set false for syncing only on
    // startup
    if (Preferences.getBoolean(Preferences.Key.SYNC_ON_START) && first_onCreate_run) {
      startSyncing(true);
      TLog.i(TAG, "SyncOnStart activated");
    }

    // we already run onCreate now!
    first_onCreate_run = false;
  }
Beispiel #15
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_show_stock);

    // Controls configuration.
    final View controlsView = findViewById(R.id.fullscreen_content_controls);
    final View contentView = findViewById(R.id.fullscreen_content);

    // Get information according to start type.
    Intent intent = getIntent();
    if (Intent.ACTION_SEARCH.equals(intent.getAction())) { // It's started by search.
      String query = intent.getStringExtra(SearchManager.QUERY);

      // Add to search suggestion.
      SearchRecentSuggestions suggestions =
          new SearchRecentSuggestions(
              this, SearchSuggestionProvider.AUTHORITY, SearchSuggestionProvider.MODE);
      suggestions.saveRecentQuery(query, null);

      // Get extra data.
      Bundle appData = intent.getBundleExtra(SearchManager.APP_DATA);
      if (appData != null) {
        appData.getString("ddd");
      }

      // Search to get stock.
      mStockId = StockSearcher.searchWithDesc(query);
      if (mStockId == null) {
        Toast.makeText(
                getApplicationContext(),
                getString(R.string.error_can_not_find_stock) + query,
                Toast.LENGTH_LONG)
            .show();
      }
    } else { // Normally start.
      mStockId = intent.getStringExtra(INTENT_KEY_STOCK_ID);
    }

    // Not valid stock id.
    mStock = DataWrapper.getStock(mStockId);
    if (mStock == null) {
      Toast.makeText(
              getApplicationContext(), "It\'s a invalid stock id: " + mStockId, Toast.LENGTH_LONG)
          .show();
      onDestroy();
    }

    // Configure favorite toggle button.
    mBtnFavoriateToggle = (Button) findViewById(R.id.btn_favorite_toggle);
    mBtnFavoriateToggle.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View view) {
            if (mBtnFavoriateToggle.getText()
                == getApplicationContext().getString(R.string.add_to_favorite)) {
              FavoriteContent.addItem(mStockId);
              mBtnFavoriateToggle.setText(
                  getApplicationContext().getString(R.string.remove_from_favorite));
            } else {
              FavoriteContent.deleteItem(mStockId);
              mBtnFavoriateToggle.setText(
                  getApplicationContext().getString(R.string.add_to_favorite));
            }
            Intent intentAction = new Intent();
            intentAction.setAction(FavoriteListFragment.ACTION_FAVORITE_CHANGE);
            sendBroadcast(intentAction);
          }
        });
    if (FavoriteContent.findItem(mStockId) != null) {
      mBtnFavoriateToggle.setText(getApplicationContext().getString(R.string.remove_from_favorite));
    } else {
      mBtnFavoriateToggle.setText(getApplicationContext().getString(R.string.add_to_favorite));
    }
    mBtnFavoriateToggle.setOnTouchListener(mDelayHideTouchListener);

    // Set up an instance of SystemUiHider to control the system UI for
    // this activity.
    mSystemUiHider = SystemUiHider.getInstance(this, contentView, HIDER_FLAGS);
    mSystemUiHider.setup();
    mSystemUiHider.setOnVisibilityChangeListener(
        new SystemUiHider.OnVisibilityChangeListener() {
          // Cached values.
          int mControlsHeight;
          int mShortAnimTime;

          @Override
          @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2)
          public void onVisibilityChange(boolean visible) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
              // If the ViewPropertyAnimator API is available
              // (Honeycomb MR2 and later), use it to animate the
              // in-layout UI controls at the bottom of the
              // screen.
              if (mControlsHeight == 0) {
                mControlsHeight = controlsView.getHeight();
              }
              if (mShortAnimTime == 0) {
                mShortAnimTime = getResources().getInteger(android.R.integer.config_shortAnimTime);
              }
              controlsView
                  .animate()
                  .translationY(visible ? 0 : mControlsHeight)
                  .setDuration(mShortAnimTime);
            } else {
              // If the ViewPropertyAnimator APIs aren't
              // available, simply show or hide the in-layout UI
              // controls.
              controlsView.setVisibility(visible ? View.VISIBLE : View.GONE);
            }

            if (visible && AUTO_HIDE) {
              // Schedule a hide().
              delayedHide(AUTO_HIDE_DELAY_MILLIS);
            }
          }
        });

    // Set up the user interaction to manually show or hide the system UI.
    contentView.setOnClickListener(
        new View.OnClickListener() {
          long mLastClick = 0;

          @Override
          public void onClick(View view) {
            //                long lTime = System.currentTimeMillis();
            //                if(lTime-mLastClick < 1000) { // Double click.
            //                    Log.d("show", "double click");
            //                    if (TOGGLE_ON_CLICK) {
            //                        //mSystemUiHider.toggle();
            //                    } else {
            //                        //mSystemUiHider.show();
            //                    }
            //                    return;
            //                }
            //
            //                mLastClick = lTime;
          }
        });

    // Upon interacting with UI controls, delay any scheduled hide()
    // operations to prevent the jarring behavior of controls going away
    // while interacting with the UI.
    //        findViewById(R.id.dummy_button).setOnTouchListener(mDelayHideTouchListener);

    // mWebView = (WebView) findViewById(R.id.fullscreen_content);
    // mWebView.loadUrl("http://www.baidu.com/");
    // mWebView.loadUrl("http://finance.sina.com.cn/flash/cn.swf?symbol=sh000001");
    /*mWebView.loadData("<html>\n" +
    "<body>\n" +
    "\n" +
    "<div>\n" +
    "<embed src=\"http://finance.sina.com.cn/flash/cn.swf?symbol=sh000001\" quality=\"high\" type=\"application/x-shockwave-flash\" allowscriptaccess=\"always\" allowfullscreen=\"true\" wmode=\"opaque\" height=\"490\" width=\"560\"></embed>\n" +
    "</div>" +
    "</body></html>");*/
    //        try {
    //            mWebView.getSettings().setJavaScriptEnabled(true);
    //            mWebView.loadData(URLEncoder.encode("<html>\n" +
    //                            "<body>" +
    //                            "<div>abcd" +
    //                            "<embed
    // src=\"http://finance.sina.com.cn/flash/cn.swf?symbol=sh000001\" quality=\"high\"
    // type=\"application/x-shockwave-flash\" allowscriptaccess=\"always\" allowfullscreen=\"true\"
    // wmode=\"opaque\" height=\"490\" width=\"560\"></embed>" +
    //                            "</div>" +
    //                            "</body></html>", "utf-8"),
    //                    "text/html", "utf-8");
    //            mWebView.loadUrl("http://image.sinajs.cn/newchart/min/n/sh000001.gif");
    //        } catch(Exception e) {}

    ImageView iv = (ImageView) findViewById(R.id.fullscreen_content);
    iv.setImageBitmap(this.generatePriceImage(mStockId));
  }
    protected String doInBackground(Void... args) {

      try {
        settings = new AppSettings(context);

        twitter = Utils.getTwitter(context, settings);

        User user = twitter.verifyCredentials();
        if (sharedPrefs.getInt("current_account", 1) == 1) {
          sharedPrefs.edit().putString("twitter_users_name_1", user.getName()).commit();
          sharedPrefs.edit().putString("twitter_screen_name_1", user.getScreenName()).commit();
          sharedPrefs
              .edit()
              .putString("translate_url", Utils.getTranslateURL(user.getLang()))
              .commit();
          sharedPrefs
              .edit()
              .putString("twitter_background_url_1", user.getProfileBannerURL())
              .commit();
          sharedPrefs
              .edit()
              .putString("profile_pic_url_1", user.getBiggerProfileImageURL())
              .commit();
          sharedPrefs.edit().putLong("twitter_id_1", user.getId()).commit();
        } else {
          sharedPrefs.edit().putString("twitter_users_name_2", user.getName()).commit();
          sharedPrefs.edit().putString("twitter_screen_name_2", user.getScreenName()).commit();
          sharedPrefs
              .edit()
              .putString("twitter_background_url_2", user.getProfileBannerURL())
              .commit();
          sharedPrefs
              .edit()
              .putString("profile_pic_url_2", user.getBiggerProfileImageURL())
              .commit();
          sharedPrefs.edit().putLong("twitter_id_2", user.getId()).commit();
        }

        // syncs 200 timeline tweets with 2 pages
        Paging paging;
        paging = new Paging(2, 100);
        List<twitter4j.Status> statuses = twitter.getHomeTimeline(paging);

        HomeDataSource dataSource = HomeDataSource.getInstance(context);

        for (twitter4j.Status status : statuses) {
          try {
            dataSource.createTweet(status, sharedPrefs.getInt("current_account", 1), true);
          } catch (Exception e) {
            dataSource = HomeDataSource.getInstance(context);
            dataSource.createTweet(status, sharedPrefs.getInt("current_account", 1), true);
          }
        }
        paging = new Paging(1, 100);
        statuses = twitter.getHomeTimeline(paging);

        if (statuses.size() > 0) {
          sharedPrefs
              .edit()
              .putLong(
                  "last_tweet_id_" + sharedPrefs.getInt("current_account", 1),
                  statuses.get(0).getId())
              .commit();
        }

        for (twitter4j.Status status : statuses) {
          try {
            dataSource.createTweet(status, sharedPrefs.getInt("current_account", 1), true);
          } catch (Exception e) {
            dataSource = HomeDataSource.getInstance(context);
            dataSource.createTweet(status, sharedPrefs.getInt("current_account", 1), true);
          }
        }

        runOnUiThread(
            new Runnable() {
              @Override
              public void run() {
                progDescription.setText(getResources().getString(R.string.syncing_mentions));
              }
            });

        MentionsDataSource mentionsSource = MentionsDataSource.getInstance(context);

        // syncs 100 mentions
        paging = new Paging(1, 100);
        statuses = twitter.getMentionsTimeline(paging);

        for (twitter4j.Status status : statuses) {
          try {
            mentionsSource.createTweet(status, sharedPrefs.getInt("current_account", 1), false);
          } catch (Exception e) {
            mentionsSource = MentionsDataSource.getInstance(context);
            mentionsSource.createTweet(status, sharedPrefs.getInt("current_account", 1), false);
          }
        }

        runOnUiThread(
            new Runnable() {
              @Override
              public void run() {
                progDescription.setText(getResources().getString(R.string.syncing_direct_messages));
              }
            });

        // syncs 100 Direct Messages
        DMDataSource dmSource = DMDataSource.getInstance(context);

        try {
          paging = new Paging(1, 100);

          List<DirectMessage> dm = twitter.getDirectMessages(paging);

          sharedPrefs
              .edit()
              .putLong(
                  "last_direct_message_id_" + sharedPrefs.getInt("current_account", 1),
                  dm.get(0).getId())
              .commit();

          for (DirectMessage directMessage : dm) {
            try {
              dmSource.createDirectMessage(directMessage, sharedPrefs.getInt("current_account", 1));
            } catch (Exception e) {
              dmSource = DMDataSource.getInstance(context);
              dmSource.createDirectMessage(directMessage, sharedPrefs.getInt("current_account", 1));
            }
          }

          List<DirectMessage> sent = twitter.getSentDirectMessages();

          for (DirectMessage directMessage : sent) {
            try {
              dmSource.createDirectMessage(directMessage, sharedPrefs.getInt("current_account", 1));
            } catch (Exception e) {
              dmSource = DMDataSource.getInstance(context);
              dmSource.createDirectMessage(directMessage, sharedPrefs.getInt("current_account", 1));
            }
          }

        } catch (Exception e) {
          // they have no direct messages
          e.printStackTrace();
        }

        runOnUiThread(
            new Runnable() {
              @Override
              public void run() {
                progDescription.setText(getResources().getString(R.string.syncing_user));
              }
            });

        FollowersDataSource followers = FollowersDataSource.getInstance(context);

        try {
          int currentAccount = sharedPrefs.getInt("current_account", 1);
          PagableResponseList<User> friendsPaging = twitter.getFriendsList(user.getId(), -1, 200);

          for (User friend : friendsPaging) {
            followers.createUser(friend, currentAccount);
          }

          long nextCursor = friendsPaging.getNextCursor();

          final SearchRecentSuggestions suggestions =
              new SearchRecentSuggestions(
                  context, MySuggestionsProvider.AUTHORITY, MySuggestionsProvider.MODE);

          while (nextCursor != -1) {
            friendsPaging = twitter.getFriendsList(user.getId(), nextCursor, 200);

            for (User friend : friendsPaging) {
              followers.createUser(friend, currentAccount);

              // insert them into the suggestion search provider
              suggestions.saveRecentQuery("@" + friend.getScreenName(), null);
            }

            nextCursor = friendsPaging.getNextCursor();
          }

        } catch (Exception e) {
          e.printStackTrace();
        }

      } catch (TwitterException e) {
        // Error in updating status
        Log.d("Twitter Update Error", e.getMessage());
        e.printStackTrace();
      }
      return null;
    }
  private void handleIntent(Intent intent) {
    if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
      searchQuery = intent.getStringExtra(SearchManager.QUERY);

      SearchRecentSuggestions suggestions =
          new SearchRecentSuggestions(
              this, MySuggestionsProvider.AUTHORITY, MySuggestionsProvider.MODE);

      if (searchQuery.contains("#")) {
        suggestions.saveRecentQuery(searchQuery.replaceAll("\"", ""), null);
      } else {
        suggestions.saveRecentQuery(searchQuery, null);
      }

      searchQuery += " -RT";
    } else if (Intent.ACTION_VIEW.equals(intent.getAction())) {
      Uri uri = intent.getData();
      String uriString = uri.toString();
      if (uriString.contains("status/")) {
        long id;
        String replace =
            uriString
                .substring(uriString.indexOf("status"))
                .replace("status/", "")
                .replaceAll("photo/*", "");
        if (replace.contains("/")) {
          replace = replace.substring(0, replace.indexOf("/"));
        } else if (replace.contains("?")) {
          replace = replace.substring(0, replace.indexOf("?"));
        }
        try {
          id = Long.parseLong(replace);
        } catch (Exception e) {
          id = 0l;
        }
        searchQuery = id + "";
        onlyStatus = true;
      } else if (!uriString.contains("q=") && !uriString.contains("screen_name%3D")) {
        // going to try searching for users i guess
        String name = uriString.substring(uriString.indexOf(".com/"));
        name = name.replaceAll("/", "").replaceAll(".com", "");
        searchQuery = name;
        onlyProfile = true;
      } else if (uriString.contains("q=")) {
        try {
          String search = uri.getQueryParameter("q");

          if (search != null) {
            searchQuery = search;
            SearchRecentSuggestions suggestions =
                new SearchRecentSuggestions(
                    this, MySuggestionsProvider.AUTHORITY, MySuggestionsProvider.MODE);

            if (searchQuery.contains("#")) {
              suggestions.saveRecentQuery(searchQuery.replaceAll("\"", ""), null);
            } else {
              suggestions.saveRecentQuery(searchQuery, null);
            }

            searchQuery += " -RT";
          } else {
            searchQuery = "";
          }

        } catch (Exception e) {

        }
      } else {
        try {
          String search = uriString;

          search = search.substring(search.indexOf("screen_name%3D") + 14);
          search = search.substring(0, search.indexOf("%"));

          if (search != null) {
            searchQuery = search;

            SearchRecentSuggestions suggestions =
                new SearchRecentSuggestions(
                    this, MySuggestionsProvider.AUTHORITY, MySuggestionsProvider.MODE);

            if (searchQuery.contains("#")) {
              suggestions.saveRecentQuery(searchQuery.replaceAll("\"", ""), null);
            } else {
              suggestions.saveRecentQuery(searchQuery, null);
            }

            searchQuery += " -RT";
          } else {
            searchQuery = "";
          }

          onlyProfile = true;
        } catch (Exception e) {

        }
      }
    }
  }