首页>代码>Android商业项目多功能媒体完整版APP源代码>/telecapoland-jamendo-android-6cd07fb/src/com/teleca/jamendo/activity/ArtistActivity.java
/* * Copyright (C) 2009 Teleca Poland Sp. z o.o. <android@teleca.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.teleca.jamendo.activity; import java.util.ArrayList; import org.json.JSONException; import com.teleca.jamendo.adapter.AlbumGridAdapter; import com.teleca.jamendo.api.Album; import com.teleca.jamendo.api.Artist; import com.teleca.jamendo.api.JamendoGet2Api; import com.teleca.jamendo.api.Track; import com.teleca.jamendo.api.WSError; import com.teleca.jamendo.api.impl.JamendoGet2ApiImpl; import com.teleca.jamendo.dialog.AddToPlaylistDialog; import com.teleca.jamendo.dialog.ArtistLoadingDialog; import com.teleca.jamendo.dialog.LoadingDialog; import com.teleca.jamendo.widget.ArtistBar; import com.teleca.jamendo.JamendoApplication; import com.teleca.jamendo.R; import android.app.Activity; import android.content.Intent; import android.net.Uri; import android.os.Bundle; import android.view.View; import android.view.Window; import android.view.View.OnClickListener; import android.widget.AdapterView; import android.widget.Button; import android.widget.GridView; import android.widget.Toast; import android.widget.AdapterView.OnItemClickListener; import android.widget.AdapterView.OnItemLongClickListener; /** * Artist View - discography, webpage & donate buttons * * @author Lukasz Wisniewski */ public class ArtistActivity extends Activity { private ArtistBar mArtistBar; private AlbumGridAdapter mAlbumGridAdapter; private GridView mAlbumGridView; private Button mDonateButton; private Button mWebpageButton; private Artist mArtist; /** * Launch this Activity from the outside * * @param c context from which Activity should be started * @param artistName Artist to be presented */ public static void launch(Activity c, String artistName){ new ArtistLoadingDialog(c,R.string.artist_loading, R.string.artist_fail).execute(artistName); } /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.artist); mArtistBar = (ArtistBar)findViewById(R.id.ArtistBar); mAlbumGridView = (GridView)findViewById(R.id.AlbumGridView); mArtistBar.setDescription(R.string.discography); mArtist = (Artist) getIntent().getSerializableExtra("artist"); mAlbumGridAdapter = new AlbumGridAdapter(this); mArtistBar.setArtist(mArtist); loadAlbums(); mAlbumGridView.setOnItemClickListener(mOnItemClickListener); mAlbumGridView.setOnItemLongClickListener(mOnItemLongClickListener); mDonateButton = (Button)findViewById(R.id.DonateButton); mDonateButton.setOnClickListener(mDonateClick); mWebpageButton = (Button)findViewById(R.id.WebpageButton); mWebpageButton.setOnClickListener(mWebpageClick); Toast.makeText(ArtistActivity.this, R.string.long_press_playlist, Toast.LENGTH_SHORT).show(); } @SuppressWarnings("unchecked") private void loadAlbums() { // JamendoGet2Api server = new JamendoGet2ApiImpl(); // Album[] albums = server.searchForAlbumsByArtist(artistName); ArrayList<Album> albums = (ArrayList<Album>)getIntent().getSerializableExtra("albums"); mAlbumGridAdapter.setList(albums); mAlbumGridView.setAdapter(mAlbumGridAdapter); } /** * Album grid OnItemClickListener, launches Album Activity */ private OnItemClickListener mOnItemClickListener = new OnItemClickListener(){ @Override public void onItemClick(AdapterView<?> adapter, View view, int position, long time) { Album album = (Album)mAlbumGridAdapter.getItem(position); AlbumActivity.launch(ArtistActivity.this, album); } }; /** * Long press adds album to the current playlist */ private OnItemLongClickListener mOnItemLongClickListener = new OnItemLongClickListener(){ @Override public boolean onItemLongClick(AdapterView<?> adapterView, View view, int position, long time) { Album album = (Album)mAlbumGridView.getAdapter().getItem(position); new AddToPlaylistLoadingDialog( ArtistActivity.this, R.string.adding_to_playlist, R.string.adding_to_playlist_fail ).execute(album); return true; } }; /** * Donation link */ private OnClickListener mDonateClick = new OnClickListener(){ @Override public void onClick(View v) { Intent myIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(mArtist.getUrl()+"/donate")); startActivity(myIntent); } }; /** * Artist's webpage */ private OnClickListener mWebpageClick = new OnClickListener(){ @Override public void onClick(View v) { Intent myIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(mArtist.getUrl())); startActivity(myIntent); } }; /** * Loading progress dialog adding asynchronously * tracks from album to playlist * * @author Lukasz Wisniewski */ private class AddToPlaylistLoadingDialog extends LoadingDialog<Album, Track[] >{ private Album mAlbum; public AddToPlaylistLoadingDialog(Activity activity, int loadingMsg, int failMsg) { super(activity, loadingMsg, failMsg); } @Override public Track[] doInBackground(Album... params) { mAlbum = params[0]; JamendoGet2Api service = new JamendoGet2ApiImpl(); Track[] tracks = null; try { tracks = service.getAlbumTracks(mAlbum, JamendoApplication.getInstance().getStreamEncoding()); } catch (JSONException e) { e.printStackTrace(); } catch (WSError e){ publishProgress(e); } return tracks; } @Override public void doStuffWithResult(Track[] tracks) { AddToPlaylistDialog dialog = new AddToPlaylistDialog(ArtistActivity.this); dialog.setPlaylistAlbum(tracks, mAlbum); dialog.show(); } } }
最近下载更多
haozhilang LV9
2023年11月2日
wzm123530 LV4
2023年5月30日
moomin709 LV24
2022年2月28日
木木不爱安妮酱 LV10
2022年1月7日
oopocia LV4
2021年5月26日
香菜 LV1
2021年5月11日
LogCat LV1
2021年3月26日
wcyzm999 LV4
2021年1月13日
123211234567 LV1
2021年1月8日
18781170695 LV6
2020年12月30日
最近浏览更多
微信网友_7041036943331328 LV3
10月8日
2636804923 LV6
6月20日
咩咩咩咩咩 LV2
6月17日
AIWU1234 LV2
6月9日
求学的熊猫 LV11
6月3日
lilitu LV6
5月30日
happySuperman LV2
5月29日
13543528515 LV8
5月21日
阿九11111 LV4
5月21日
MrDuan LV2
5月14日