Android Open Source - longhorn Search Content Provider






From Project

Back to project page longhorn.

License

The source code is released under:

Apache License

If you think the Android project longhorn 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

/*
 * Copyright (C) 2012 Santiago Valdarrama
 * //  w w  w  .ja v  a2s .co m
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at 
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 */
package com.svpino.longhorn.providers;

import android.app.SearchManager;
import android.content.ContentProvider;
import android.content.ContentValues;
import android.content.UriMatcher;
import android.database.Cursor;
import android.net.Uri;

import com.svpino.longhorn.data.DataProvider;

public class SearchContentProvider extends ContentProvider {

  public static String AUTHORITY = "com.svpino.longhorn.providers.SearchContentProvider";
  public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/stocks");

  private static final int SEARCH_STOCKS = 0;
  private static final int GET_STOCK = 1;
  private static final int SEARCH_SUGGEST = 2;
  private static final int REFRESH_SHORTCUT = 3;

  private static final UriMatcher uriMatcher = buildUriMatcher();

  @Override
  public boolean onCreate() {
    return true;
  }

  private static UriMatcher buildUriMatcher() {
    UriMatcher matcher = new UriMatcher(UriMatcher.NO_MATCH);

    matcher.addURI(AUTHORITY, "stocks", SEARCH_STOCKS);
    matcher.addURI(AUTHORITY, "stocks/#", GET_STOCK);

    matcher.addURI(AUTHORITY, SearchManager.SUGGEST_URI_PATH_QUERY, SEARCH_SUGGEST);
    matcher.addURI(AUTHORITY, SearchManager.SUGGEST_URI_PATH_QUERY + "/*", SEARCH_SUGGEST);

    matcher.addURI(AUTHORITY, SearchManager.SUGGEST_URI_PATH_SHORTCUT, REFRESH_SHORTCUT);
    matcher.addURI(AUTHORITY, SearchManager.SUGGEST_URI_PATH_SHORTCUT + "/*", REFRESH_SHORTCUT);
    return matcher;
  }

  @Override
  public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
    switch (SearchContentProvider.uriMatcher.match(uri)) {
      case SEARCH_SUGGEST:
        return retrieveStockSuggestions(selectionArgs[0]);
      case SEARCH_STOCKS:
        return null;
      case GET_STOCK:
        return null;
      case REFRESH_SHORTCUT:
        return null;
      default:
        throw new IllegalArgumentException("Unknown Uri: " + uri);
    }
  }

  private Cursor retrieveStockSuggestions(String query) {
    return DataProvider.search(getContext(), query);
  }

  @Override
  public int delete(Uri uri, String selection, String[] selectionArgs) {
    return 0;
  }

  @Override
  public String getType(Uri uri) {
    return null;
  }

  @Override
  public Uri insert(Uri uri, ContentValues values) {
    return null;
  }

  @Override
  public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
    return 0;
  }

}




Java Source Code List

com.svpino.longhorn.MarketCollectorService.java
com.svpino.longhorn.activities.DashboardActivity.java
com.svpino.longhorn.artifacts.Constants.java
com.svpino.longhorn.artifacts.Extensions.java
com.svpino.longhorn.artifacts.StockOverviewManager.java
com.svpino.longhorn.artifacts.StockTileProcessor.java
com.svpino.longhorn.artifacts.StockTileViewHolder.java
com.svpino.longhorn.artifacts.TabFragment.java
com.svpino.longhorn.artifacts.back.BackStack.java
com.svpino.longhorn.artifacts.back.StockOverviewBackStackItem.java
com.svpino.longhorn.data.DataProvider.java
com.svpino.longhorn.data.LonghornDatabase.java
com.svpino.longhorn.data.LonghornOpenHelper.java
com.svpino.longhorn.fragments.StockListFragment.java
com.svpino.longhorn.layouts.BorderRelativeLayout.java
com.svpino.longhorn.layouts.StockOverviewLayout.java
com.svpino.longhorn.model.Stock.java
com.svpino.longhorn.providers.SearchContentProvider.java
com.svpino.longhorn.receivers.BatteryBroadcastReceiver.java
com.svpino.longhorn.receivers.ConnectivityBroadcastReceiver.java
com.svpino.longhorn.receivers.MarketCollectionReceiver.java