Skip to content

Commit

Permalink
Added: Music library stub for JSON-RPC
Browse files Browse the repository at this point in the history
Added: Gesture mode GFX

git-svn-id: http://android-xbmcremote.googlecode.com/svn/trunk/XBMC Remote@584 677bec2c-7919-11de-bdc7-1f637afd43b1
  • Loading branch information
freezy committed Apr 16, 2010
1 parent c1c30ee commit 63cf8a8
Show file tree
Hide file tree
Showing 38 changed files with 1,426 additions and 58 deletions.
2 changes: 1 addition & 1 deletion AndroidManifest.xml
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="org.xbmc.android.remote"
android:versionName="0.6.7+" android:versionCode="583">
android:versionName="0.6.7+" android:versionCode="584">
<application android:icon="@drawable/icon" android:label="@string/app_name" android:debuggable="false" >
<activity android:name=".presentation.activity.HomeActivity"
android:label="@string/app_name"
Expand Down
Binary file added res/drawable-hdpi-v4/remote_gest_cursor.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable-hdpi-v4/remote_xbox_gesturezone.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable-ldpi-v4/remote_gest_cursor.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable-ldpi-v4/remote_xbox_gesturezone.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable-ldpi-v4/remote_xbox_gesturezone_dim.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable/remote_gest_cursor.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable/remote_xbox_gesture_back_down.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable/remote_xbox_gesture_info_down.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable/remote_xbox_gesture_menu_down.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable/remote_xbox_gesture_title_down.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable/remote_xbox_gesturezone.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable/remote_xbox_gesturezone_dim.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 12 additions & 4 deletions src/org/xbmc/android/remote/business/Command.java
Expand Up @@ -16,14 +16,20 @@
public abstract class Command<T> implements Runnable {

public int mRetryCount = 0;
public long mStarted = 0;
public final INotifiableManager mManager;
public final DataResponse<T> response;
public final DataResponse<T> mResponse;

// TODO Disable this when not needed anymore
public final StackTraceElement mCaller;

public static final int MAX_RETRY = 5;

public Command(DataResponse<T> response, INotifiableManager manager) {
this.mManager = manager;
this.response = response;
mManager = manager;
mResponse = response;
mStarted = System.currentTimeMillis();
mCaller = new Throwable().fillInStackTrace().getStackTrace()[2];
}

public void run() {
Expand All @@ -32,7 +38,9 @@ public void run() {
Log.d("Command", "Running command counter: " + mRetryCount);
if(mRetryCount > MAX_RETRY) return;
doRun();
mManager.onFinish(response);
Log.i(mCaller.getClassName(), "*** " + mCaller.getMethodName() + ": " + (System.currentTimeMillis() - mStarted) + "ms");

mManager.onFinish(mResponse);
}catch (WifiStateException e) {
mManager.onWrongConnectionState(e.getState(), this);
}catch (Exception e) {
Expand Down
8 changes: 1 addition & 7 deletions src/org/xbmc/android/remote/business/MusicManager.java
Expand Up @@ -79,13 +79,7 @@ public void doRun() throws Exception {
* @param response Response object
*/
public void getAlbums(final DataResponse<ArrayList<Album>> response, final Context context) {
// mHandler.post(new Runnable() {
// public void run() {
// response.value = music(context).getAlbums(MusicManager.this, getSortBy(SortType.ALBUM), getSortOrder());
// onFinish(response);
// }
// });
mHandler.post(new Command<ArrayList<Album>>(response, this){
mHandler.post(new Command<ArrayList<Album>>(response, this) {
@Override
public void doRun() throws Exception {
response.value = music(context).getAlbums(MusicManager.this, getSortBy(SortType.ALBUM), getSortOrder());
Expand Down
10 changes: 5 additions & 5 deletions src/org/xbmc/android/remote/business/TvShowManager.java
Expand Up @@ -69,7 +69,7 @@ public void getTvShows(DataResponse<ArrayList<TvShow>> response, final Actor act
mHandler.post(new Command<ArrayList<TvShow>>(response, this) {
@Override
public void doRun() throws Exception {
response.value = shows(context).getTvShows(TvShowManager.this, actor);
mResponse.value = shows(context).getTvShows(TvShowManager.this, actor);
}
});
}
Expand All @@ -79,7 +79,7 @@ public void getEpisodes(DataResponse<ArrayList<Episode>> response,
mHandler.post(new Command<ArrayList<Episode>>(response, this) {
@Override
public void doRun() throws Exception {
response.value = shows(context).getEpisodes(TvShowManager.this, show);
mResponse.value = shows(context).getEpisodes(TvShowManager.this, show);
}
});
}
Expand All @@ -89,7 +89,7 @@ public void getSeasons(DataResponse<ArrayList<Season>> response,
mHandler.post(new Command<ArrayList<Season>>(response, this) {
@Override
public void doRun() throws Exception {
response.value = shows(context).getSeasons(TvShowManager.this, show);
mResponse.value = shows(context).getSeasons(TvShowManager.this, show);
}
});
}
Expand All @@ -99,7 +99,7 @@ public void getEpisodes(DataResponse<ArrayList<Episode>> response,
mHandler.post(new Command<ArrayList<Episode>>(response, this) {
@Override
public void doRun() throws Exception {
response.value = shows(context).getEpisodes(TvShowManager.this, show, season);
mResponse.value = shows(context).getEpisodes(TvShowManager.this, show, season);
}
});

Expand All @@ -110,7 +110,7 @@ public void getEpisodes(DataResponse<ArrayList<Episode>> response,
mHandler.post(new Command<ArrayList<Episode>>(response, this) {
@Override
public void doRun() throws Exception {
response.value = shows(context).getEpisodes(TvShowManager.this, season);
mResponse.value = shows(context).getEpisodes(TvShowManager.this, season);
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/org/xbmc/android/remote/business/VideoManager.java
Expand Up @@ -246,7 +246,7 @@ public void getTvShowGenres(DataResponse<ArrayList<Genre>> response,
mHandler.post(new Command<ArrayList<Genre>>(response, this) {
@Override
public void doRun() throws Exception {
response.value = video(context).getTvShowGenres(VideoManager.this);
mResponse.value = video(context).getTvShowGenres(VideoManager.this);
}
});
}
Expand Down
Expand Up @@ -26,7 +26,7 @@

import org.xbmc.android.remote.R;
import org.xbmc.android.remote.business.ManagerFactory;
import org.xbmc.android.remote.presentation.activity.AbsListActivity;
import org.xbmc.android.remote.presentation.activity.ListActivity;
import org.xbmc.android.remote.presentation.activity.NowPlayingActivity;
import org.xbmc.android.remote.presentation.widget.OneLabelItemView;
import org.xbmc.api.business.DataResponse;
Expand Down Expand Up @@ -100,7 +100,7 @@ public void onItemClick(AdapterView<?> parent, View view, int position, long id)

FileLocation item = mFileItems.get(((FileLocation)parent.getAdapter().getItem(position)).name);
if (item.isDirectory) {
Intent nextActivity = new Intent(mActivity, AbsListActivity.class);
Intent nextActivity = new Intent(mActivity, ListActivity.class);
nextActivity.putExtra(ListController.EXTRA_LIST_CONTROLLER, new FileListController());
nextActivity.putExtra(ListController.EXTRA_SHARE_TYPE, mMediaType);
nextActivity.putExtra(ListController.EXTRA_PATH, item.path);
Expand Down
13 changes: 11 additions & 2 deletions src/org/xbmc/android/util/ClientFactory.java
Expand Up @@ -85,7 +85,15 @@ public static IVideoClient getVideoClient(INotifiableManager manager, Context co

public static IMusicClient getMusicClient(INotifiableManager manager, Context context) throws WifiStateException {
assertWifiState(context);
return createHttpClient(manager).music;
probeQueryApiType(manager);
switch (sApiType) {
case API_TYPE_JSONRPC:
// return createJsonClient(manager).music;
case API_TYPE_UNSET:
case API_TYPE_HTTPIAPI:
default:
return createHttpClient(manager).music;
}
}

public static ITvShowClient getTvShowClient(INotifiableManager manager, Context context) throws WifiStateException {
Expand Down Expand Up @@ -204,7 +212,8 @@ private static void probeQueryApiType(final INotifiableManager manager) {
sApiType = API_TYPE_UNSET;
}
}



/**
* Returns an instance of the Event Server Client. Instantiation takes
* place only once, otherwise the first instance is returned.
Expand Down
12 changes: 12 additions & 0 deletions src/org/xbmc/api/data/IMusicClient.java
Expand Up @@ -39,6 +39,18 @@
* @author Team XBMC
*/
public interface IMusicClient extends IClient {

// those are the musicdb://n/ keys.
public static final int MUSICDB_GENRE = 1;
public static final int MUSICDB_ARTIST = 2;
public static final int MUSICDB_ALBUM = 3;
public static final int MUSICDB_SONG = 4;
public static final int MUSICDB_TOP100 = 5;
public static final int MUSICDB_RECENTLY_ADDED = 6;
public static final int MUSICDB_RECENTLY_PLAYED = 7;
public static final int MUSICDB_COMPILATION = 8;
public static final int MUSICDB_YEARS = 9;
public static final int MUSICDB_SINGLES = 10;

/**
* Adds an album to the current playlist.
Expand Down
21 changes: 21 additions & 0 deletions src/org/xbmc/httpapi/Connection.java
@@ -1,3 +1,24 @@
/*
* Copyright (C) 2005-2010 Team XBMC
* http://xbmc.org
*
* This Program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with XBMC Remote; see the file license. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
* http://www.gnu.org/copyleft/gpl.html
*
*/

package org.xbmc.httpapi;

import java.io.BufferedReader;
Expand Down
4 changes: 2 additions & 2 deletions src/org/xbmc/httpapi/client/Client.java
Expand Up @@ -45,9 +45,9 @@
*
* @author Team XBMC
*/
public abstract class Client {
abstract class Client {

public static final String TAG = "Client";
public static final String TAG = "Client-HTTPAPI";

protected final Connection mConnection;

Expand Down
12 changes: 0 additions & 12 deletions src/org/xbmc/httpapi/client/MusicClient.java
Expand Up @@ -50,18 +50,6 @@ public class MusicClient extends Client implements IMusicClient {

public static final String TAG = "MusicClient";

// those are the musicdb://n/ keys.
public static final int MUSICDB_GENRE = 1;
public static final int MUSICDB_ARTIST = 2;
public static final int MUSICDB_ALBUM = 3;
public static final int MUSICDB_SONG = 4;
public static final int MUSICDB_TOP100 = 5;
public static final int MUSICDB_RECENTLY_ADDED = 6;
public static final int MUSICDB_RECENTLY_PLAYED = 7;
public static final int MUSICDB_COMPILATION = 8;
public static final int MUSICDB_YEARS = 9;
public static final int MUSICDB_SINGLES = 10;

public static final int VIEW_ALBUMS = 1;
public static final int VIEW_SONGS = 2;

Expand Down
38 changes: 38 additions & 0 deletions src/org/xbmc/jsonrpc/Connection.java
@@ -1,7 +1,29 @@
/*
* Copyright (C) 2005-2010 Team XBMC
* http://xbmc.org
*
* This Program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with XBMC Remote; see the file license. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
* http://www.gnu.org/copyleft/gpl.html
*
*/

package org.xbmc.jsonrpc;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.Authenticator;
Expand Down Expand Up @@ -135,6 +157,20 @@ public void setTimeout(int timeout) {
}
}

public InputStream getInputStream(String url, INotifiableManager manager) {
try {
final URL u = new URL(url);
URLConnection uc;
uc = u.openConnection();
uc.setConnectTimeout(SOCKET_CONNECTION_TIMEOUT);
uc.setReadTimeout(mSocketReadTimeout);
return uc.getInputStream();
} catch (IOException e) {
manager.onError(e);
}
return null;
}

/**
* Executes a query.
* @param command Name of the command to execute
Expand Down Expand Up @@ -164,6 +200,8 @@ public JSONObject query(String command, JSONObject parameters, INotifiableManage
.put("id", "1");
if (parameters != null) {
data.put("params", parameters);
} else {
data.put("params", new JSONObject());
}

// POST data
Expand Down
54 changes: 54 additions & 0 deletions src/org/xbmc/jsonrpc/JSONHelper.java
@@ -0,0 +1,54 @@
/*
* Copyright (C) 2005-2010 Team XBMC
* http://xbmc.org
*
* This Program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with XBMC Remote; see the file license. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
* http://www.gnu.org/copyleft/gpl.html
*
*/

package org.xbmc.jsonrpc;

import org.json.JSONException;
import org.json.JSONObject;

/**
* Wraps some calls in order to avoid JSON exceptions
* @author Team XBMC
*/
public abstract class JSONHelper {

public final static String getString(JSONObject obj, String key) {
try {
return obj.getString(key);
} catch (JSONException e) {
return null;
}
}
public final static String getString(JSONObject obj, String key, String ifNullResult) {
try {
return obj.getString(key);
} catch (JSONException e) {
return ifNullResult;
}
}
public final static int getInt(JSONObject obj, String key) {
try {
return obj.getInt(key);
} catch (JSONException e) {
return -1;
}
}
}
12 changes: 7 additions & 5 deletions src/org/xbmc/jsonrpc/JsonRpc.java
Expand Up @@ -23,6 +23,7 @@

import org.xbmc.api.object.Host;
import org.xbmc.jsonrpc.client.InfoClient;
import org.xbmc.jsonrpc.client.MusicClient;

/**
* Wrapper class for JSON-RPC clients. The idea is to separate the loads of
Expand All @@ -33,14 +34,15 @@
*/
public class JsonRpc {


/**
* Use this client for anything system related
*/
public final InfoClient info;

/**
* Use this client for anything music related
*
*/
public final MusicClient music;

/**
Expand Down Expand Up @@ -73,8 +75,8 @@ public JsonRpc(Host host, int timeout) {
}
connection.setTimeout(timeout);
info = new InfoClient(connection);
/* music = new MusicClient(connection);
video = new VideoClient(connection);
music = new MusicClient(connection);
/* video = new VideoClient(connection);
control = new ControlClient(connection);
shows = new TvShowClient(connection);*/
}
Expand All @@ -85,8 +87,8 @@ public JsonRpc(Host host, int timeout) {
*/
public void setHost(Host host) {
info.setHost(host);
/* music.setHost(host);
video.setHost(host);
music.setHost(host);
/* video.setHost(host);
control.setHost(host);
shows.setHost(host);*/
}
Expand Down

0 comments on commit 63cf8a8

Please sign in to comment.