Back to project page pequeno-android-spotify.
The source code is released under:
Apache License
If you think the Android project pequeno-android-spotify listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
/** * Copyright 2015 ze-pequeno/* www . j a v a 2 s. com*/ * * 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.pequeno.android.spotify.app.roboguice.ui; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.Button; import android.widget.Toast; import com.google.inject.Inject; import com.pequeno.android.spotify.api.business.enums.SearchType; import com.pequeno.android.spotify.api.http.SearchService; import com.pequeno.android.spotify.api.http.params.SearchParameters; import com.pequeno.android.spotify.api.http.responses.SearchResponse; import com.pequeno.android.spotify.app.roboguice.R; import retrofit.Callback; import retrofit.RetrofitError; import retrofit.client.Response; import roboguice.activity.RoboActionBarActivity; import roboguice.inject.InjectView; public class HomeActivity extends RoboActionBarActivity implements View.OnClickListener, Callback<SearchResponse> { @InjectView(R.id.search_button) private Button searchButton; @Inject private SearchService searchService; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.home_activity); searchButton.setOnClickListener(this); } @Override public void onClick(View v) { SearchType[] types = new SearchType[] { SearchType.Album, SearchType.Artist, SearchType.Playlist, SearchType.Track }; SearchParameters parameters = new SearchParameters("Hocus Pocus", types); searchService.search(parameters.toMap(), this); } @Override public void success(SearchResponse search, Response response) { Integer artists = 0, albums = 0, playlist = 0, tracks = 0; if (search.hasArtists()) { artists = search.getArtists().getTotal(); } if (search.hasAlbums()) { albums = search.getAlbums().getTotal(); } if (search.hasPlayists()) { playlist = search.getPlaylists().getTotal(); } if (search.hasTracks()) { tracks = search.getTracks().getTotal(); } this.showToast(String.format("%d albums, %d artists, %d playlists, %d tracks", albums, artists, playlist, tracks)); } @Override public void failure(RetrofitError error) { this.showToast(error.getMessage()); } private void showToast(String message) { Log.d(this.getClass().getCanonicalName(), message); Toast.makeText(this, message, Toast.LENGTH_SHORT).show(); } }