mirror of
https://github.com/clangen/musikcube.git
synced 2025-02-06 12:39:54 +00:00
Started playing around with some android client development.
This commit is contained in:
parent
ef68e9f271
commit
8d42ed35df
7
src/android/.classpath
Normal file
7
src/android/.classpath
Normal file
@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="src" path="gen"/>
|
||||
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
33
src/android/.project
Normal file
33
src/android/.project
Normal file
@ -0,0 +1,33 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>musikCube</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>com.android.ide.eclipse.adt.ApkBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
5
src/android/.settings/org.eclipse.jdt.core.prefs
Normal file
5
src/android/.settings/org.eclipse.jdt.core.prefs
Normal file
@ -0,0 +1,5 @@
|
||||
#Thu Jun 11 22:13:22 CEST 2009
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
|
||||
org.eclipse.jdt.core.compiler.compliance=1.5
|
||||
org.eclipse.jdt.core.compiler.source=1.5
|
19
src/android/AndroidManifest.xml
Normal file
19
src/android/AndroidManifest.xml
Normal file
@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="org.musikcube"
|
||||
android:versionCode="1"
|
||||
android:versionName="1.0">
|
||||
<application android:icon="@drawable/icon" android:label="@string/app_name">
|
||||
<activity android:name=".main"
|
||||
android:label="@string/app_name">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
</application>
|
||||
<uses-sdk android:minSdkVersion="3" />
|
||||
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
|
||||
</manifest>
|
11
src/android/default.properties
Normal file
11
src/android/default.properties
Normal file
@ -0,0 +1,11 @@
|
||||
# This file is automatically generated by Android Tools.
|
||||
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
|
||||
#
|
||||
# This file must be checked in Version Control Systems.
|
||||
#
|
||||
# To customize properties used by the Ant build system use,
|
||||
# "build.properties", and override values to adapt the script to your
|
||||
# project structure.
|
||||
|
||||
# Project target.
|
||||
target=android-3
|
BIN
src/android/res/drawable/icon.png
Normal file
BIN
src/android/res/drawable/icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.1 KiB |
21
src/android/res/layout/main.xml
Normal file
21
src/android/res/layout/main.xml
Normal file
@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<LinearLayout android:id="@+id/LinearLayout01" android:orientation="horizontal" android:layout_height="fill_parent" android:layout_width="fill_parent" android:layout_weight="0.5"><ImageButton android:id="@+id/ImageButton01" android:layout_height="fill_parent" android:layout_width="fill_parent" android:layout_weight="0.5" android:layout_margin="5px"></ImageButton><ImageButton android:id="@+id/ImageButton01" android:layout_height="fill_parent" android:layout_width="fill_parent" android:layout_weight="0.5" android:layout_margin="5px"></ImageButton></LinearLayout>
|
||||
|
||||
|
||||
<LinearLayout android:id="@+id/LinearLayout02" android:layout_height="fill_parent" android:layout_width="fill_parent" android:layout_weight="0.5"><ImageButton android:id="@+id/ImageButton01" android:layout_height="fill_parent" android:layout_width="fill_parent" android:layout_weight="0.5" android:layout_margin="5px"></ImageButton><ImageButton android:id="@+id/ImageButton01" android:layout_height="fill_parent" android:layout_width="fill_parent" android:layout_weight="0.5" android:layout_margin="5px"></ImageButton></LinearLayout>
|
||||
|
||||
|
||||
</LinearLayout>
|
5
src/android/res/values/strings.xml
Normal file
5
src/android/res/values/strings.xml
Normal file
@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string name="hello">Hello World, main!</string>
|
||||
<string name="app_name">musikCube</string>
|
||||
</resources>
|
101
src/android/src/doep/xml/Reader.java
Normal file
101
src/android/src/doep/xml/Reader.java
Normal file
@ -0,0 +1,101 @@
|
||||
package doep.xml;
|
||||
import org.xmlpull.v1.*;
|
||||
|
||||
import android.util.Log;
|
||||
import doep.xml.ReaderNode;
|
||||
import java.io.InputStream;
|
||||
import java.util.LinkedList;
|
||||
import java.lang.Exception;
|
||||
|
||||
|
||||
public class Reader extends ReaderNode {
|
||||
private InputStream stream;
|
||||
private org.xmlpull.v1.XmlPullParser parser;
|
||||
private java.util.LinkedList<ReaderNode> nodeLevels = new java.util.LinkedList<ReaderNode>();
|
||||
public ReaderNode currentNode;
|
||||
private boolean firstParse = true;
|
||||
|
||||
|
||||
public Reader(InputStream stream)
|
||||
throws Exception
|
||||
{
|
||||
super("",null);
|
||||
this.stream = stream;
|
||||
this.reader = this;
|
||||
|
||||
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
|
||||
factory.setNamespaceAware(false);
|
||||
this.parser = factory.newPullParser();
|
||||
this.parser.setInput(this.stream, null);
|
||||
|
||||
// Add the Reader to the nodeLevels itself
|
||||
this.nodeLevels.addLast(this);
|
||||
this.currentNode = this;
|
||||
}
|
||||
|
||||
|
||||
public void Parse()
|
||||
throws Exception
|
||||
{
|
||||
int eventType = 0;
|
||||
if(this.firstParse){
|
||||
this.firstParse = false;
|
||||
eventType = this.parser.getEventType();
|
||||
}else{
|
||||
eventType = this.parser.next();
|
||||
}
|
||||
|
||||
// while (eventType != XmlPullParser.END_DOCUMENT) {
|
||||
if(eventType == XmlPullParser.START_DOCUMENT) {
|
||||
//Log.v("doep::Reader::Parse","Start document");
|
||||
// Start document
|
||||
} else if(eventType == XmlPullParser.END_DOCUMENT) {
|
||||
// End document
|
||||
//Log.v("doep::Reader::Parse","End document");
|
||||
|
||||
java.util.ListIterator<ReaderNode> it=this.nodeLevels.listIterator();
|
||||
while(it.hasNext()){
|
||||
it.next().ended = true;
|
||||
}
|
||||
|
||||
} else if(eventType == XmlPullParser.START_TAG) {
|
||||
//Log.v("doep::Reader::Parse","Start tag "+this.parser.getName());
|
||||
//System.out.println("Start tag "+xpp.getName());
|
||||
// Start a new node
|
||||
ReaderNode node = new ReaderNode(this.parser.getName(),this.nodeLevels.getLast());
|
||||
|
||||
// Get the attributes
|
||||
int attributes = this.parser.getAttributeCount();
|
||||
for(int i=0;i<attributes;i++){
|
||||
node.attributes.put(this.parser.getAttributeName(i),this.parser.getAttributeValue(i));
|
||||
}
|
||||
|
||||
// Add to the end of the levels
|
||||
this.nodeLevels.addLast(node);
|
||||
node.level = this.nodeLevels.size();
|
||||
// Set to current node for futher processing
|
||||
this.currentNode = node;
|
||||
|
||||
} else if(eventType == XmlPullParser.END_TAG) {
|
||||
//Log.v("doep::Reader::Parse","End tag "+this.parser.getName());
|
||||
//System.out.println("End tag "+xpp.getName());
|
||||
if(this.parser.getName().equals(this.currentNode.name)){
|
||||
// End the node, and remove from levels
|
||||
this.currentNode.ended = true;
|
||||
this.nodeLevels.removeLast();
|
||||
this.currentNode = this.nodeLevels.getLast();
|
||||
}else{
|
||||
// Something is wrong.. wrong end tag
|
||||
throw new Exception("Wrong end tag.. expecting "+this.currentNode.name);
|
||||
}
|
||||
} else if(eventType == XmlPullParser.TEXT) {
|
||||
//Log.v("doep::Reader::Parse","Text "+this.parser.getText());
|
||||
//System.out.println("Text "+xpp.getText());
|
||||
this.currentNode.content += this.parser.getText();
|
||||
}
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
92
src/android/src/doep/xml/ReaderNode.java
Normal file
92
src/android/src/doep/xml/ReaderNode.java
Normal file
@ -0,0 +1,92 @@
|
||||
package doep.xml;
|
||||
import android.util.Log;
|
||||
import doep.xml.Reader;
|
||||
|
||||
public class ReaderNode {
|
||||
|
||||
public String name = "";
|
||||
public boolean ended = false;
|
||||
public String content = "";
|
||||
public ReaderNode parent;
|
||||
public Reader reader;
|
||||
public int level = 1;
|
||||
|
||||
public java.util.SortedMap<String,String> attributes = new java.util.TreeMap<String,String>();
|
||||
|
||||
public ReaderNode(String name,ReaderNode parent){
|
||||
this.name = name;
|
||||
this.parent = parent;
|
||||
if(parent!=null){
|
||||
this.reader = parent.reader;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get attribute from node
|
||||
* @param attribute
|
||||
* @return String or null
|
||||
*/
|
||||
public String Attribute(String attribute){
|
||||
return this.attributes.get(attribute);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wait for a childnode with the specific name
|
||||
* @param name Name of node to be found
|
||||
* @return ReaderNode if found, or null if this goes out of scope
|
||||
*/
|
||||
public ReaderNode ChildNode(String name)
|
||||
throws Exception
|
||||
{
|
||||
Log.v("doep::ReaderNode::ChildNode","Node: "+name);
|
||||
// Check if this is the current node, if not - lets wait for it to bee
|
||||
while(!this.ended){
|
||||
this.reader.Parse();
|
||||
//Log.v("doep::ReaderNode::ChildNode1","Node: "+this.reader.currentNode.level+" "+this.level);
|
||||
if(this.reader.currentNode.level==this.level+1){
|
||||
// We have a childnode
|
||||
//Log.v("doep::ReaderNode::ChildNode2",""+this.reader.currentNode.name+"=="+name);
|
||||
if(this.reader.currentNode.name.equals(name)){
|
||||
//Log.v("doep::ReaderNode::ChildNode3","FOUND "+this.reader.currentNode.name);
|
||||
return this.reader.currentNode;
|
||||
}else{
|
||||
this.reader.currentNode.End();
|
||||
}
|
||||
}else if( this.reader.currentNode.level>this.level+1){
|
||||
this.reader.currentNode.End();
|
||||
}
|
||||
}
|
||||
//Log.v("doep::ReaderNode::ChildNode4","NOT FOUND "+name);
|
||||
return null;
|
||||
}
|
||||
|
||||
public void End()
|
||||
throws Exception
|
||||
{
|
||||
while(!this.ended){
|
||||
//Log.v("doep::ReaderNode::End","Node: "+this.name+" "+this.level);
|
||||
this.reader.Parse();
|
||||
}
|
||||
//Log.v("doep::ReaderNode::End","Ended");
|
||||
}
|
||||
|
||||
/**
|
||||
* Wait for a childnode
|
||||
* @return ReaderNode if found, or null if this goes out of scope
|
||||
*/
|
||||
public ReaderNode ChildNode()
|
||||
throws Exception
|
||||
{
|
||||
while(!this.ended){
|
||||
this.reader.Parse();
|
||||
if(this.reader.currentNode.level==this.level+1){
|
||||
// We have a childnode
|
||||
return this.reader.currentNode;
|
||||
}else if( this.reader.currentNode.level>this.level+1){
|
||||
this.reader.currentNode.End();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
104
src/android/src/org/musikcube/core/Library.java
Normal file
104
src/android/src/org/musikcube/core/Library.java
Normal file
@ -0,0 +1,104 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package org.musikcube.core;
|
||||
|
||||
import java.net.*;
|
||||
import java.io.*;
|
||||
import android.util.*;
|
||||
import doep.xml.*;
|
||||
|
||||
/**
|
||||
* @author doy
|
||||
*
|
||||
*/
|
||||
public class Library implements Runnable{
|
||||
|
||||
private String username;
|
||||
private String password;
|
||||
private String authorization;
|
||||
private String host;
|
||||
private int queryPort;
|
||||
private int httpPort;
|
||||
|
||||
private Thread thread;
|
||||
private boolean running;
|
||||
private Socket socket;
|
||||
|
||||
private class WriterThreadHelper implements Runnable{
|
||||
private Thread thread;
|
||||
private Library library;
|
||||
public WriterThreadHelper(Library library){
|
||||
this.library = library;
|
||||
this.thread = new Thread(this);
|
||||
this.thread.start();
|
||||
}
|
||||
|
||||
public void run(){
|
||||
this.library.WriteThread();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private WriterThreadHelper writerThreadHelper;
|
||||
|
||||
public Library(){
|
||||
this.running = false;
|
||||
}
|
||||
|
||||
public boolean Connect(String host,String username,String password,int queryPort,int httpPort){
|
||||
Log.i("Library","starting "+host+":"+queryPort);
|
||||
if(!running){
|
||||
this.host = host;
|
||||
this.username = username;
|
||||
this.password = password;
|
||||
this.queryPort = queryPort;
|
||||
this.httpPort = httpPort;
|
||||
|
||||
// Startup thread
|
||||
this.thread = new Thread(this);
|
||||
// this.thread.setDaemon(true);
|
||||
this.running = true;
|
||||
this.thread.start();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void run(){
|
||||
// First try to connect
|
||||
try{
|
||||
this.socket = new java.net.Socket(this.host,this.queryPort);
|
||||
//Log.v("Library::socket","Successfully connected to "+this.host+":"+this.queryPort);
|
||||
|
||||
doep.xml.Reader reader = new doep.xml.Reader(this.socket.getInputStream());
|
||||
//Log.v("Library::run","Reader started");
|
||||
// Wait for a "authentication" tag
|
||||
doep.xml.ReaderNode authNode=null;
|
||||
if( (authNode=reader.ChildNode("authentication")) != null ){
|
||||
//Log.v("Library::run","Authtag found");
|
||||
// Wait for authorization tag to end
|
||||
authNode.End();
|
||||
//Log.v("Library::run","Authtag end");
|
||||
this.authorization = authNode.content;
|
||||
//Log.v("Library::run","Authorization="+this.authorization);
|
||||
}
|
||||
|
||||
// Start write thread
|
||||
this.writerThreadHelper = new WriterThreadHelper(this);
|
||||
|
||||
}
|
||||
catch(IOException x){
|
||||
Log.e("Library::socket","Unable to connect to "+this.host+":"+this.queryPort);
|
||||
}
|
||||
catch(Exception x){
|
||||
Log.e("Library::socket","E "+this.host+":"+this.queryPort);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void WriteThread(){
|
||||
|
||||
}
|
||||
|
||||
}
|
22
src/android/src/org/musikcube/main.java
Normal file
22
src/android/src/org/musikcube/main.java
Normal file
@ -0,0 +1,22 @@
|
||||
package org.musikcube;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import org.musikcube.core.Library;
|
||||
|
||||
public class main extends Activity {
|
||||
|
||||
private org.musikcube.core.Library library;
|
||||
|
||||
/** Called when the activity is first created. */
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.main);
|
||||
|
||||
this.library = new org.musikcube.core.Library();
|
||||
this.library.Connect("192.168.99.100", "doep", "doep", 10543, 10544);
|
||||
|
||||
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user