當前位置: 首頁>>代碼示例>>Java>>正文


Java AndroidJsonFactory類代碼示例

本文整理匯總了Java中com.google.api.client.extensions.android.json.AndroidJsonFactory的典型用法代碼示例。如果您正苦於以下問題:Java AndroidJsonFactory類的具體用法?Java AndroidJsonFactory怎麽用?Java AndroidJsonFactory使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


AndroidJsonFactory類屬於com.google.api.client.extensions.android.json包,在下文中一共展示了AndroidJsonFactory類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: search

import com.google.api.client.extensions.android.json.AndroidJsonFactory; //導入依賴的package包/類
/**
 * Main search method, runs outside UI thread.
 */
private Book search(Book query) {
  Books books = new Books.Builder(AndroidHttp.newCompatibleTransport(), AndroidJsonFactory.getDefaultInstance(), null)
     .setApplicationName(BuildConfig.APPLICATION_ID)
     .build();

  try {
    // Executes the query
    Log.d(TAG, "Fetching details for "+query.getId());
    Books.Volumes.Get get = books.volumes().get(query.getId());
    final Volume execute = get.execute();
    BookDetails details = new BookDetails(execute);
    query.setDetails(details);
    Log.d(TAG, "Details loaded " + details.getSubtitle());
    return query;
  } catch (IOException e) {
    Log.e(TAG, "IO ex", e);
    return query;
  }
}
 
開發者ID:andviane,項目名稱:google-books-android-viewer,代碼行數:23,代碼來源:DetailsLoader.java

示例2: fetch

import com.google.api.client.extensions.android.json.AndroidJsonFactory; //導入依賴的package包/類
/**
 * Main search method, runs outside UI thread.
 */
@Override
public PrimaryResponse fetch(PrimaryRequest request) {
  Books books = new Books.Builder(AndroidHttp.newCompatibleTransport(), AndroidJsonFactory.getDefaultInstance(), null)
     .setApplicationName(BuildConfig.APPLICATION_ID)
     .setGoogleClientRequestInitializer(new BooksRequestInitializer(API_KEY))
     .build();

  try {
    // Executes the query
    Books.Volumes.List list = books.volumes().list(request.getQuery().getQueryString());
    list.setMaxResults(Long.valueOf(request.getTo() - request.getFrom()));
    list.setStartIndex(Long.valueOf(request.getFrom()));
    list.setFields("totalItems,items(volumeInfo(title,authors,pageCount,imageLinks/smallThumbnail),id)");

    Volumes execution = list.execute();
    ArrayList<Book> bookList = convert(execution);
    return new PrimaryResponse<>(bookList, execution.getTotalItems());
  } catch (IOException e) {
    Log.e(TAG, "IO ex", e);
    return null;
  }
}
 
開發者ID:andviane,項目名稱:google-books-android-viewer,代碼行數:26,代碼來源:BookDataProvider.java

示例3: initGAEService

import com.google.api.client.extensions.android.json.AndroidJsonFactory; //導入依賴的package包/類
private void initGAEService() {
    if (service != null) {
        return;
    }
    if (mGoogleSignInAccount == null) {
        return;
    }
    GoogleAccountCredential credential = GoogleAccountCredential.usingAudience(mContext,
            "server:client_id:" + Constants.SERVER_CLIENT_ID);
    credential.setSelectedAccountName(mGoogleSignInAccount.getEmail());
    Log.d(TAG, "credential account name" + credential.getSelectedAccountName());
    U2fRequestHandler.Builder builder = new U2fRequestHandler.Builder(
            AndroidHttp.newCompatibleTransport(),
            new AndroidJsonFactory(), credential)
            .setGoogleClientRequestInitializer(new GoogleClientRequestInitializer() {
                @Override
                public void initialize(
                        AbstractGoogleClientRequest<?> abstractGoogleClientRequest)
                        throws IOException {
                    abstractGoogleClientRequest.setDisableGZipContent(true);
                }
            });
    service = builder.build();
}
 
開發者ID:googlesamples,項目名稱:android-fido,代碼行數:25,代碼來源:GAEService.java

示例4: doInBackground

import com.google.api.client.extensions.android.json.AndroidJsonFactory; //導入依賴的package包/類
@Override
protected String doInBackground(String... params) {
    if (myApiService == null) {  // Only do this once
        MyApi.Builder builder = new MyApi.Builder(AndroidHttp.newCompatibleTransport(),
                new AndroidJsonFactory(), null)
                .setRootUrl("https://YOUR-PROJECT-ID.appspot.com/_ah/api/")
                .setGoogleClientRequestInitializer(new GoogleClientRequestInitializer() {
                    @Override
                    public void initialize(AbstractGoogleClientRequest<?> abstractGoogleClientRequest) throws IOException {
                        abstractGoogleClientRequest.setDisableGZipContent(true);
                    }
                });
        // end options for devappserver
        myApiService = builder.build();
    }

    try {
        return myApiService.sayHi(params[0]).execute().getData();
    } catch (IOException e) {
        return e.getMessage();
    }
}
 
開發者ID:GoogleCloudPlatform,項目名稱:android-docs-samples,代碼行數:23,代碼來源:MainActivity.java

示例5: doInBackground

import com.google.api.client.extensions.android.json.AndroidJsonFactory; //導入依賴的package包/類
@Override
protected String doInBackground(String... params) {
    if (myApiService == null) {  // Only do this once
        MyApi.Builder builder = new MyApi.Builder(AndroidHttp.newCompatibleTransport(),
                new AndroidJsonFactory(), null)
                .setRootUrl("http://YOUR-PROJECT-ID.appspot.com/_ah/api/")
                .setGoogleClientRequestInitializer(new GoogleClientRequestInitializer() {
                    @Override
                    public void initialize(AbstractGoogleClientRequest<?> abstractGoogleClientRequest) throws IOException {
                        abstractGoogleClientRequest.setDisableGZipContent(true);
                    }
                });
        // end options for devappserver
        myApiService = builder.build();
    }

    try {
        return myApiService.sayHi(params[0]).execute().getData();
    } catch (IOException e) {
        return e.getMessage();
    }
}
 
開發者ID:GoogleCloudPlatform,項目名稱:android-docs-samples,代碼行數:23,代碼來源:MainActivity.java

示例6: doInBackground

import com.google.api.client.extensions.android.json.AndroidJsonFactory; //導入依賴的package包/類
@Override
protected String doInBackground(Context... params) {
    if (jokeApiService == null) {
        final JokeApi.Builder builder = new JokeApi.Builder(AndroidHttp.newCompatibleTransport(),
                new AndroidJsonFactory(), null)
                .setRootUrl("http://10.0.2.2:8080/_ah/api/")
                .setGoogleClientRequestInitializer(new GoogleClientRequestInitializer() {
                    @Override
                    public void initialize(AbstractGoogleClientRequest<?> abstractGoogleClientRequest) throws IOException {
                        abstractGoogleClientRequest.setDisableGZipContent(true);
                    }
                });
        jokeApiService = builder.build();
    }

    context = params[0];

    try {
        return jokeApiService.tellAJoke().execute().getData();
    } catch (IOException e) {
        return e.getMessage();
    }
}
 
開發者ID:scarrupt,項目名稱:Build-It-Bigger,代碼行數:24,代碼來源:GetJokeAsyncTask.java

示例7: getEndpoints

import com.google.api.client.extensions.android.json.AndroidJsonFactory; //導入依賴的package包/類
/**
 * *
 *
 * @return ShoppingAssistant endpoints to the GAE backend.
 */
static ShoppingAssistant getEndpoints() {

    // Create API handler
    ShoppingAssistant.Builder builder = new ShoppingAssistant.Builder(
            AndroidHttp.newCompatibleTransport(),
            new AndroidJsonFactory(), getRequestInitializer())
            .setRootUrl(Constants.ROOT_URL)
            .setGoogleClientRequestInitializer(
                    new GoogleClientRequestInitializer() {
                        @Override
                        public void initialize(
                                final AbstractGoogleClientRequest<?>
                                        abstractGoogleClientRequest)
                                throws IOException {
                            abstractGoogleClientRequest
                                    .setDisableGZipContent(true);
                        }
                    }
            );

    return builder.build();
}
 
開發者ID:googlearchive,項目名稱:MobileShoppingAssistant-sample,代碼行數:28,代碼來源:CloudEndpointBuilderHelper.java

示例8: setupRegistration

import com.google.api.client.extensions.android.json.AndroidJsonFactory; //導入依賴的package包/類
/**
 * Setting up the registration object for communicating with the backend server
 */
private void setupRegistration() {
    if (mRegService == null) {
        Registration.Builder builder = new Registration.Builder(AndroidHttp.newCompatibleTransport(),
                new AndroidJsonFactory(), null);

        //Run in the emulator, connect to local server
        if (Utils.runningOnEmulator()) {
            // Need setRootUrl and setGoogleClientRequestInitializer only for local testing,
            // otherwise they can be skipped
            builder
                    .setRootUrl("http://10.0.2.2:8080/_ah/api/")
                    .setGoogleClientRequestInitializer(new GoogleClientRequestInitializer() {
                        @Override
                        public void initialize(AbstractGoogleClientRequest<?> abstractGoogleClientRequest)
                                throws IOException {
                            abstractGoogleClientRequest.setDisableGZipContent(true);
                        }
                    });
        // Run on device, connect on real server
        } else {
            builder.setRootUrl("https://play-together-2015.appspot.com/_ah/api/");
        }
        mRegService = builder.build();
    }
}
 
開發者ID:rainbowbreeze,項目名稱:playtogether,代碼行數:29,代碼來源:BackendHelper.java

示例9: setupGame

import com.google.api.client.extensions.android.json.AndroidJsonFactory; //導入依賴的package包/類
/**
 * Setting up the registration object for communicating with the backend server
 */
private void setupGame() {
    if (mGameService == null) {
        Game.Builder builder = new Game.Builder(AndroidHttp.newCompatibleTransport(),
                new AndroidJsonFactory(), null);

        //Run in the emulator, connect to local server
        if (Utils.runningOnEmulator()) {
            // Need setRootUrl and setGoogleClientRequestInitializer only for local testing,
            // otherwise they can be skipped
            builder
                    .setRootUrl("http://10.0.2.2:8080/_ah/api/")
                    .setGoogleClientRequestInitializer(new GoogleClientRequestInitializer() {
                        @Override
                        public void initialize(AbstractGoogleClientRequest<?> abstractGoogleClientRequest)
                                throws IOException {
                            abstractGoogleClientRequest.setDisableGZipContent(true);
                        }
                    });
            // Run on device, connect on real server
        } else {
            builder.setRootUrl("https://play-together-2015.appspot.com/_ah/api/");
        }
        mGameService = builder.build();
    }
}
 
開發者ID:rainbowbreeze,項目名稱:playtogether,代碼行數:29,代碼來源:BackendHelper.java

示例10: setUpEndpoint

import com.google.api.client.extensions.android.json.AndroidJsonFactory; //導入依賴的package包/類
/**
 * Instantiates {@link FunnyApi} object
 */
private void setUpEndpoint() {
    if(funnyEndpoint == null) {  // Only do this once
        FunnyApi.Builder builder = new FunnyApi.Builder(AndroidHttp.newCompatibleTransport(),
                new AndroidJsonFactory(), null)
                .setApplicationName(getResources().getString(R.string.app_name))
                        // options for running against local devappserver
                        // - 10.0.2.2 is localhost's IP address in Android emulator
                        // - turn off compression when running against local devappserver
                .setRootUrl("https://nanodegree-funny-endpoint-1024.appspot.com/_ah/api/")
                .setGoogleClientRequestInitializer(new GoogleClientRequestInitializer() {
                    @Override
                    public void initialize(AbstractGoogleClientRequest<?> abstractGoogleClientRequest) throws IOException {
                        abstractGoogleClientRequest.setDisableGZipContent(true);
                    }
                });
        // end options for devappserver

        funnyEndpoint = builder.build();
    }
}
 
開發者ID:josemontiel,項目名稱:FunnyDroids,代碼行數:24,代碼來源:MainActivity.java

示例11: EndpointsTaskBagImpl

import com.google.api.client.extensions.android.json.AndroidJsonFactory; //導入依賴的package包/類
public EndpointsTaskBagImpl(TodoPreferences preferences,
                            LocalTaskRepository localRepository) {
    super(preferences, localRepository, null);

    // Production testing
    //TaskApi.Builder builder = new TaskApi.Builder(AndroidHttp.newCompatibleTransport(), new AndroidJsonFactory(), null);

    // Local testing
    TaskApi.Builder builder = new TaskApi.Builder(AndroidHttp.newCompatibleTransport(), new AndroidJsonFactory(), null)
            .setRootUrl("http://10.0.2.2:8080/_ah/api/")
            .setGoogleClientRequestInitializer(new GoogleClientRequestInitializer() {
                @Override
                public void initialize(AbstractGoogleClientRequest<?> abstractGoogleClientRequest) throws IOException {
                    abstractGoogleClientRequest.setDisableGZipContent(true);
                }
            });

    taskApiService = builder.build();

}
 
開發者ID:GoogleCloudPlatform,項目名稱:endpoints-codelab-android,代碼行數:21,代碼來源:EndpointsTaskBagImpl.java

示例12: doInBackground

import com.google.api.client.extensions.android.json.AndroidJsonFactory; //導入依賴的package包/類
/**
 * The main method that creates an API call to our endpoint
 * @param params
 * @return
 */
@Override
protected DealBean doInBackground(Void... params) {
    DealBean dealBean = new DealBean();

    try {
        MyApi api = new MyApi.Builder(AndroidHttp.newCompatibleTransport(), new AndroidJsonFactory(), null).setRootUrl("https://skilled-outlook-686.appspot.com/_ah/api")
                .setGoogleClientRequestInitializer(new GoogleClientRequestInitializer() {
                    @Override
                    public void initialize(AbstractGoogleClientRequest<?> request) throws IOException {
                        request.setDisableGZipContent(true);
                    }
                }).build();
        dealBean = api.getDeals().execute();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return dealBean;
}
 
開發者ID:triveous,項目名稱:GSASummit2014,代碼行數:24,代碼來源:MyActivity.java

示例13: youTube

import com.google.api.client.extensions.android.json.AndroidJsonFactory; //導入依賴的package包/類
public YouTube youTube() {
  if (youTube == null) {
    try {
      HttpRequestInitializer credentials;

      if (mUseAuthCredentials)
        credentials = Auth.getCredentials(mContext, mUseDefaultAccount);
      else
        credentials = Auth.nullCredentials(mContext);

      youTube = new YouTube.Builder(new NetHttpTransport(), new AndroidJsonFactory(), credentials).setApplicationName("YouTubeAPI")
          .build();
    } catch (Exception e) {
      e.printStackTrace();
    } catch (Throwable t) {
      t.printStackTrace();
    }
  }

  return youTube;
}
 
開發者ID:sgehrman,項目名稱:UTubeTV,代碼行數:22,代碼來源:YouTubeAPI.java

示例14: doInBackground

import com.google.api.client.extensions.android.json.AndroidJsonFactory; //導入依賴的package包/類
@Override
protected String doInBackground(Pair<Context, String>... params) {
    if(myApiService == null) {  // Only do this once
        UserApi.Builder builder = new UserApi.Builder(AndroidHttp.newCompatibleTransport(),
                new AndroidJsonFactory(), null)
                // options for running against local devappserver
                // - 10.0.2.2 is localhost's IP address in Android emulator
                // - turn off compression when running against local devappserver
                .setRootUrl("https://infra-vertex-182716.appspot.com/_ah/api/")
                .setGoogleClientRequestInitializer(new GoogleClientRequestInitializer() {
                    @Override
                    public void initialize(AbstractGoogleClientRequest<?> abstractGoogleClientRequest) throws IOException {
                        abstractGoogleClientRequest.setDisableGZipContent(true);
                    }
                });
        // end options for devappserver

        myApiService = builder.build();
    }

    context = params[0].first;

    try {
        List<User> users = myApiService.list().execute().getItems();
        if (users == null || users.isEmpty()){
            return NO_DATA;
        }

        return users.get(users.size() - 1).getName();
    } catch (IOException e) {
        return e.getMessage();
    }
}
 
開發者ID:IstiN,項目名稱:android-training-2017,代碼行數:34,代碼來源:EndpointsAsyncTask.java

示例15: getLastStatusRequest

import com.google.api.client.extensions.android.json.AndroidJsonFactory; //導入依賴的package包/類
private ApiMedicion getLastStatusRequest(boolean isFromBackgound) {
    ApiMedicion result = null;
    try {
        if (myApiService == null) {  // Only do this once
            PureMadridApi.Builder builder = new PureMadridApi.Builder(AndroidHttp.newCompatibleTransport(),
                    new AndroidJsonFactory(), null)
                    // options for running against local devappserver
                    // - 10.0.2.2 is localhost's IP address in Android emulator
                    // - turn off compression date running against local devappserver
                    // .setRootUrl("http://10.0.2.2:8080/_ah/api/")
                    .setRootUrl(mContext.getString(R.string.your_api_url))
                    .setGoogleClientRequestInitializer(new GoogleClientRequestInitializer() {
                        @Override
                        public void initialize(AbstractGoogleClientRequest<?> abstractGoogleClientRequest) throws IOException {
                            abstractGoogleClientRequest.setDisableGZipContent(true);
                        }
                    });

            myApiService = builder.build();
        }

        if (date == null) {
            result = myApiService.getLastStatus().execute();
        } else {
            result = myApiService.getStatusAt(new DateTime(date)).execute();
        }
    } catch (IOException e) {
        return null;
    }
    return result;
}
 
開發者ID:medialab-prado,項目名稱:puremadrid,代碼行數:32,代碼來源:GetLastStatusAsync.java


注:本文中的com.google.api.client.extensions.android.json.AndroidJsonFactory類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。