position
.
34 | */
35 | @Override
36 | public View onCreateFloatView(int position) {
37 | View v = mListView.getChildAt(position + mListView.getHeaderViewsCount()
38 | - mListView.getFirstVisiblePosition());
39 |
40 | if (v == null) {
41 | return null;
42 | }
43 |
44 | v.setPressed(false);
45 |
46 | v.setDrawingCacheEnabled(true);
47 | mFloatBitmap = Bitmap.createBitmap(v.getDrawingCache());
48 | v.setDrawingCacheEnabled(false);
49 |
50 | ImageView iv = new ImageView(mListView.getContext());
51 | iv.setBackgroundColor(mFloatBGColor);
52 | iv.setPadding(0, 0, 0, 0);
53 | iv.setImageBitmap(mFloatBitmap);
54 |
55 | return iv;
56 | }
57 |
58 | /**
59 | * Removes the Bitmap from the ImageView created in onCreateFloatView() and
60 | * tells the system to recycle it.
61 | */
62 | @Override
63 | public void onDestroyFloatView(View floatView) {
64 | ((ImageView)floatView).setImageDrawable(null);
65 |
66 | mFloatBitmap.recycle();
67 | mFloatBitmap = null;
68 | }
69 |
70 | /**
71 | * {@inheritDoc}
72 | */
73 | @Override
74 | public void onDragFloatView(View floatView, Point position, Point touch) {
75 | /* Nothing to do */
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/src/com/andrew/apollo/format/Capitalize.java:
--------------------------------------------------------------------------------
1 |
2 | package com.andrew.apollo.format;
3 |
4 | import android.text.TextUtils;
5 |
6 | public class Capitalize {
7 |
8 | /* This class is never initiated */
9 | public Capitalize() {
10 | }
11 |
12 | public static final String capitalize(String str) {
13 | return capitalize(str, null);
14 | }
15 |
16 | /**
17 | * Capitalizes the first character in a string
18 | *
19 | * @param str The string to capitalize
20 | * @param delimiters The delimiters
21 | * @return A captitalized string
22 | */
23 | public static final String capitalize(String str, char... delimiters) {
24 | final int delimLen = delimiters == null ? -1 : delimiters.length;
25 | if (TextUtils.isEmpty(str) || delimLen == 0) {
26 | return str;
27 | }
28 | final char[] buffer = str.toCharArray();
29 | boolean capitalizeNext = true;
30 | for (int i = 0; i < buffer.length; i++) {
31 | char ch = buffer[i];
32 | if (isDelimiter(ch, delimiters)) {
33 | capitalizeNext = true;
34 | } else if (capitalizeNext) {
35 | buffer[i] = Character.toTitleCase(ch);
36 | capitalizeNext = false;
37 | }
38 | }
39 | return new String(buffer);
40 | }
41 |
42 | /**
43 | * Is the character a delimiter.
44 | *
45 | * @param ch the character to check
46 | * @param delimiters the delimiters
47 | * @return true if it is a delimiter
48 | */
49 | private static final boolean isDelimiter(char ch, char[] delimiters) {
50 | if (delimiters == null) {
51 | return Character.isWhitespace(ch);
52 | }
53 | for (char delimiter : delimiters) {
54 | if (ch == delimiter) {
55 | return true;
56 | }
57 | }
58 | return false;
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/src/com/andrew/apollo/lastfm/ImageSize.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2012, the Last.fm Java Project and Committers All rights
3 | * reserved. Redistribution and use of this software in source and binary forms,
4 | * with or without modification, are permitted provided that the following
5 | * conditions are met: - Redistributions of source code must retain the above
6 | * copyright notice, this list of conditions and the following disclaimer. -
7 | * Redistributions in binary form must reproduce the above copyright notice,
8 | * this list of conditions and the following disclaimer in the documentation
9 | * and/or other materials provided with the distribution. THIS SOFTWARE IS
10 | * PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
11 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
12 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
13 | * EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
14 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
15 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
16 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
17 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
18 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
19 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
20 | */
21 |
22 | package com.andrew.apollo.lastfm;
23 |
24 | /**
25 | * @author Janni Kovacs
26 | */
27 | public enum ImageSize {
28 |
29 | SMALL, MEDIUM, LARGE, EXTRALARGE, MEGA, UNKNOWN
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/src/com/andrew/apollo/lastfm/ItemFactory.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2012, the Last.fm Java Project and Committers All rights
3 | * reserved. Redistribution and use of this software in source and binary forms,
4 | * with or without modification, are permitted provided that the following
5 | * conditions are met: - Redistributions of source code must retain the above
6 | * copyright notice, this list of conditions and the following disclaimer. -
7 | * Redistributions in binary form must reproduce the above copyright notice,
8 | * this list of conditions and the following disclaimer in the documentation
9 | * and/or other materials provided with the distribution. THIS SOFTWARE IS
10 | * PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
11 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
12 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
13 | * EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
14 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
15 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
16 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
17 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
18 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
19 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
20 | */
21 |
22 | package com.andrew.apollo.lastfm;
23 |
24 | /**
25 | * An ItemFactory
can be used to instantiate a value object - such
26 | * as Artist, Album, Track, Tag - from an XML element. Use the
27 | * {@link ItemFactoryBuilder} to obtain item factories for a specific type.
28 | *
29 | * @author Janni Kovacs
30 | * @see com.andrew.apollo.lastfm.api.ItemFactoryBuilder
31 | * @see ResponseBuilder
32 | */
33 | interface ItemFactoryT
, based on the passed
37 | * {@link DomElement}.
38 | *
39 | * @param element the XML element
40 | * @return a new object
41 | */
42 | public T createItemFromElement(DomElement element);
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/src/com/andrew/apollo/loaders/AsyncHandler.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2010 The Android Open Source Project Licensed under the Apache
3 | * License, Version 2.0 (the "License"); you may not use this file except in
4 | * compliance with the License. You may obtain a copy of the License at
5 | * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law
6 | * or agreed to in writing, software distributed under the License is
7 | * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
8 | * KIND, either express or implied. See the License for the specific language
9 | * governing permissions and limitations under the License.
10 | */
11 |
12 | package com.andrew.apollo.loaders;
13 |
14 | import android.os.Handler;
15 | import android.os.HandlerThread;
16 |
17 | /**
18 | * Helper class for managing the background thread used to perform io operations
19 | * and handle async broadcasts.
20 | */
21 | public final class AsyncHandler {
22 |
23 | private static final HandlerThread sHandlerThread = new HandlerThread("AsyncHandler");
24 |
25 | private static final Handler sHandler;
26 |
27 | static {
28 | sHandlerThread.start();
29 | sHandler = new Handler(sHandlerThread.getLooper());
30 | }
31 |
32 | /* This class is never initiated */
33 | private AsyncHandler() {
34 | }
35 |
36 | /**
37 | * @param r The {@link Runnable} to execute.
38 | */
39 | public static void post(final Runnable r) {
40 | sHandler.post(r);
41 | }
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/src/com/andrew/apollo/loaders/WrappedAsyncTaskLoader.java:
--------------------------------------------------------------------------------
1 |
2 | package com.andrew.apollo.loaders;
3 |
4 | import android.content.Context;
5 | import android.support.v4.content.AsyncTaskLoader;
6 |
7 | /**
8 | * Issue
9 | * 14944
10 | *
11 | * @author Alexander Blom
12 | */
13 | public abstract class WrappedAsyncTaskLoaderWrappedAsyncTaskLoader
19 | *
20 | * @param context The {@link Context} to use.
21 | */
22 | public WrappedAsyncTaskLoader(Context context) {
23 | super(context);
24 | }
25 |
26 | /**
27 | * {@inheritDoc}
28 | */
29 | @Override
30 | public void deliverResult(D data) {
31 | if (!isReset()) {
32 | this.mData = data;
33 | super.deliverResult(data);
34 | } else {
35 | // An asynchronous query came in while the loader is stopped
36 | }
37 | }
38 |
39 | /**
40 | * {@inheritDoc}
41 | */
42 | @Override
43 | protected void onStartLoading() {
44 | if (this.mData != null) {
45 | deliverResult(this.mData);
46 | } else if (takeContentChanged() || this.mData == null) {
47 | forceLoad();
48 | }
49 | }
50 |
51 | /**
52 | * {@inheritDoc}
53 | */
54 | @Override
55 | protected void onStopLoading() {
56 | // Attempt to cancel the current load task if possible
57 | cancelLoad();
58 | }
59 |
60 | /**
61 | * {@inheritDoc}
62 | */
63 | @Override
64 | protected void onReset() {
65 | super.onReset();
66 | // Ensure the loader is stopped
67 | onStopLoading();
68 | this.mData = null;
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/src/com/andrew/apollo/recycler/RecycleHolder.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012 Andrew Neal Licensed under the Apache License, Version 2.0
3 | * (the "License"); you may not use this file except in compliance with the
4 | * License. You may obtain a copy of the License at
5 | * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law
6 | * or agreed to in writing, software distributed under the License is
7 | * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
8 | * KIND, either express or implied. See the License for the specific language
9 | * governing permissions and limitations under the License.
10 | */
11 |
12 | package com.andrew.apollo.recycler;
13 |
14 | import android.view.View;
15 | import android.widget.AbsListView.RecyclerListener;
16 |
17 | import com.andrew.apollo.ui.MusicHolder;
18 |
19 | /**
20 | * A @ {@link RecyclerListener} for {@link MusicHolder}'s views.
21 | *
22 | * @author Andrew Neal (andrewdneal@gmail.com)
23 | */
24 | public class RecycleHolder implements RecyclerListener {
25 |
26 | /**
27 | * {@inheritDoc}
28 | */
29 | @Override
30 | public void onMovedToScrapHeap(final View view) {
31 | MusicHolder holder = (MusicHolder)view.getTag();
32 | if (holder == null) {
33 | holder = new MusicHolder(view);
34 | view.setTag(holder);
35 | }
36 |
37 | // Release mBackground's reference
38 | if (holder.mBackground.get() != null) {
39 | holder.mBackground.get().setImageDrawable(null);
40 | holder.mBackground.get().setImageBitmap(null);
41 | }
42 |
43 | // Release mImage's reference
44 | if (holder.mImage.get() != null) {
45 | holder.mImage.get().setImageDrawable(null);
46 | holder.mImage.get().setImageBitmap(null);
47 | }
48 |
49 | // Release mLineOne's reference
50 | if (holder.mLineOne.get() != null) {
51 | holder.mLineOne.get().setText(null);
52 | }
53 |
54 | // Release mLineTwo's reference
55 | if (holder.mLineTwo.get() != null) {
56 | holder.mLineTwo.get().setText(null);
57 | }
58 |
59 | // Release mLineThree's reference
60 | if (holder.mLineThree.get() != null) {
61 | holder.mLineThree.get().setText(null);
62 | }
63 | }
64 |
65 | }
66 |
--------------------------------------------------------------------------------
/src/com/andrew/apollo/ui/activities/HomeActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012 Andrew Neal Licensed under the Apache License, Version 2.0
3 | * (the "License"); you may not use this file except in compliance with the
4 | * License. You may obtain a copy of the License at
5 | * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law
6 | * or agreed to in writing, software distributed under the License is
7 | * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
8 | * KIND, either express or implied. See the License for the specific language
9 | * governing permissions and limitations under the License.
10 | */
11 |
12 | package com.andrew.apollo.ui.activities;
13 |
14 | import android.os.Bundle;
15 | import android.support.v4.app.Fragment;
16 | import android.support.v4.view.ViewPager;
17 |
18 | import com.andrew.apollo.R;
19 | import com.andrew.apollo.ui.fragments.phone.MusicBrowserPhoneFragment;
20 |
21 | /**
22 | * This class is used to display the {@link ViewPager} used to swipe between the
23 | * main {@link Fragment}s used to browse the user's music.
24 | *
25 | * @author Andrew Neal (andrewdneal@gmail.com)
26 | */
27 | public class HomeActivity extends BaseActivity {
28 |
29 | /**
30 | * {@inheritDoc}
31 | */
32 | @Override
33 | protected void onCreate(final Bundle savedInstanceState) {
34 | super.onCreate(savedInstanceState);
35 | // Load the music browser fragment
36 | if (savedInstanceState == null) {
37 | getSupportFragmentManager().beginTransaction()
38 | .replace(R.id.activity_base_content, new MusicBrowserPhoneFragment()).commit();
39 | }
40 | }
41 |
42 | /**
43 | * {@inheritDoc}
44 | */
45 | @Override
46 | public int setContentView() {
47 | return R.layout.activity_base;
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/src/com/andrew/apollo/utils/Lists.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012 Google Inc. Licensed under the Apache License, Version 2.0
3 | * (the "License"); you may not use this file except in compliance with the
4 | * License. You may obtain a copy of the License at
5 | * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law
6 | * or agreed to in writing, software distributed under the License is
7 | * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
8 | * KIND, either express or implied. See the License for the specific language
9 | * governing permissions and limitations under the License.
10 | */
11 |
12 | package com.andrew.apollo.utils;
13 |
14 | import java.util.ArrayList;
15 | import java.util.Collections;
16 | import java.util.LinkedList;
17 |
18 | /**
19 | * Provides static methods for creating {@code List} instances easily, and other
20 | * utility methods for working with lists.
21 | */
22 | public final class Lists {
23 |
24 | /** This class is never instantiated */
25 | public Lists() {
26 | }
27 |
28 | /**
29 | * Creates an empty {@code ArrayList} instance.
30 | *
31 | * Note: if you only need an immutable empty List, use
32 | * {@link Collections#emptyList} instead.
33 | *
34 | * @return a newly-created, initially-empty {@code ArrayList}
35 | */
36 | public static final
43 | * Note: if you only need an immutable empty List, use
44 | * {@link Collections#emptyList} instead.
45 | *
46 | * @return a newly-created, initially-empty {@code LinkedList}
47 | */
48 | public static final Set the current page of both the ViewPager and indicator. This must be used if you need to set the page before
46 | * the views are drawn on screen (e.g., default start page).