android-openrat

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit 439f240b4820ba55f3d86bff62959aca2412f7e7
parent fb46d0a62f950dbaff780f5c86d719e7c16e32f0
Author: dankert <devnull@localhost>
Date:   Fri, 30 Sep 2011 00:58:45 +0200

Erweiterung um weitere Activitys, Laden der Projektliste, Laden von Ordner-Inhalten.

Diffstat:
AndroidManifest.xml | 37++++++++++++++++++++++---------------
res/layout/listing.xml | 10++++++++++
res/layout/listing_entry.xml | 13+++++++++++++
res/layout/main.xml | 27++++++++++++++++-----------
res/layout/properties.xml | 6++++++
res/values/strings.xml | 24+++++++++++++++++++++---
res/xml/preferences.xml | 27+++++++++++++++++++++++----
src/de/openrat/android/blog/EditorActivity.java | 6++++++
src/de/openrat/android/blog/FolderActivity.java | 122+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
src/de/openrat/android/blog/NewActivity.java | 6++++++
src/de/openrat/android/blog/OpenRatBlog.java | 54+++++++++++++++++++++++++++++++++---------------------
src/de/openrat/android/blog/PageElementsActivity.java | 16++++++++++++++++
src/de/openrat/android/blog/ProjectActivity.java | 135+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
src/de/openrat/android/blog/PropertiesActivity.java | 8++++++++
src/de/openrat/android/blog/adapter/FSimpleAdapter.java | 27+++++++++++++++++++++++++++
src/de/openrat/android/blog/client/CMSRequest.java | 3++-
16 files changed, 466 insertions(+), 55 deletions(-)

diff --git a/AndroidManifest.xml b/AndroidManifest.xml @@ -1,21 +1,28 @@ <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" - package="de.openrat.android.blog" - android:versionCode="1" - android:versionName="1.0"> - <uses-permission android:name="android.permission.INTERNET" /> - - <application android:icon="@drawable/icon" android:label="@string/app_name"> - <activity android:name=".OpenRatBlog" - android:label="@string/app_name"> - <intent-filter> - <action android:name="android.intent.action.MAIN" /> - <category android:name="android.intent.category.LAUNCHER" /> - </intent-filter> - </activity> + package="de.openrat.android.blog" android:versionCode="1" + android:versionName="1.0"> - <activity android:name="Configuration"></activity> -</application> + <application android:icon="@drawable/icon" android:label="@string/app_name"> + <activity android:name=".OpenRatBlog" android:label="@string/app_name"> + <intent-filter> + <action android:name="android.intent.action.MAIN" /> + <category android:name="android.intent.category.LAUNCHER" /> + </intent-filter> + </activity> + <activity android:name="Configuration"></activity> + + <activity android:name="ProjectActivity"></activity> + <activity android:name="FolderActivity"></activity> + <activity android:name="PageElementsActivity"></activity> + <activity android:name="PropertiesActivity"></activity> + + </application> + + <uses-permission android:name="android.permission.INTERNET" /> + + <!-- Android 1.6 --> + <uses-sdk android:minSdkVersion="4"></uses-sdk> </manifest> \ No newline at end of file diff --git a/res/layout/listing.xml b/res/layout/listing.xml @@ -0,0 +1,10 @@ +<?xml version="1.0" encoding="utf-8"?> +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="wrap_content" android:layout_height="wrap_content"> + + <ListView android:id="@id/android:list" android:textSize="25sp" + android:layout_width="wrap_content" android:layout_height="wrap_content"> + </ListView> + + +</LinearLayout> diff --git a/res/layout/listing_entry.xml b/res/layout/listing_entry.xml @@ -0,0 +1,13 @@ +<?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" android:padding="10sp"> + + <TextView android:text="@+id/TextView03" android:layout_width="wrap_content" + android:layout_height="wrap_content" android:id="@+id/listentry_name" + android:textSize="16sp"></TextView> + <TextView android:text="@+id/TextView01" android:layout_width="wrap_content" + android:layout_height="wrap_content" android:id="@+id/listentry_description" + android:textSize="14sp"></TextView> + +</LinearLayout> diff --git a/res/layout/main.xml b/res/layout/main.xml @@ -1,12 +1,16 @@ <?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" - > -<TextView - android:layout_width="fill_parent" - android:layout_height="wrap_content" - android:text="@string/hello" - /> -</LinearLayout> +<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="fill_parent" android:layout_height="wrap_content"> + + <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:orientation="vertical" android:layout_width="fill_parent" + android:layout_height="fill_parent"> + + <TextView android:layout_width="fill_parent" android:id="@+id/hello" + android:layout_height="wrap_content" /> + + <Button android:id="@+id/connect" android:text="@string/connect" + android:layout_width="fill_parent" android:layout_height="wrap_content"></Button> + </LinearLayout> + +</ScrollView>+ \ No newline at end of file diff --git a/res/layout/properties.xml b/res/layout/properties.xml @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="utf-8"?> +<LinearLayout + xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="wrap_content" + android:layout_height="wrap_content"> +</LinearLayout> diff --git a/res/values/strings.xml b/res/values/strings.xml @@ -1,6 +1,24 @@ <?xml version="1.0" encoding="utf-8"?> <resources> - <string name="hello">Hello World, OpenRatBlog!</string> - <string name="app_name"></string> -<string name="preferences">Einstellungen</string> + <string name="hello">Hallo</string> + <string name="app_name">OpenRat</string> + <string name="preferences">Einstellungen</string> + <string name="username">Benutzername</string> + + <string name="hostname">Hostname</string> + <string name="password">Kennwort</string> + <string name="port">Port</string> + <string name="version">Version</string> + <string name="connect">Mit Server verbinden</string> + <string-array name="api_list"> + <item>1</item> + <item>2</item> + + </string-array> + <string-array name="version_list"> + <item>1.0</item> + <item>1.1</item> + </string-array> + <string name="writable">Schreibzugriff</string> + <string name="version_summary">Server-Version</string> </resources> diff --git a/res/xml/preferences.xml b/res/xml/preferences.xml @@ -1,6 +1,25 @@ <?xml version="1.0" encoding="utf-8"?> -<PreferenceScreen - xmlns:android="http://schemas.android.com/apk/res/android"> -<PreferenceCategory><EditTextPreference android:key="server" android:title="Server"></EditTextPreference> -</PreferenceCategory> +<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" android:title="@string/preferences"> + <PreferenceScreen android:title="Server"> + + <PreferenceCategory android:title="@string/preferences"> + <EditTextPreference android:key="name" + android:title="Name"></EditTextPreference> + <EditTextPreference android:key="hostname" + android:title="@string/hostname"></EditTextPreference> + <EditTextPreference android:key="port" + android:defaultValue="80" android:title="@string/port"></EditTextPreference> + <EditTextPreference android:key="username" + android:title="@string/username"></EditTextPreference> + <EditTextPreference android:key="password" + android:title="@string/password"></EditTextPreference> + + + </PreferenceCategory> + + </PreferenceScreen> + + <ListPreference android:key="version" android:title="@string/version" android:entries="@array/version_list" android:entryValues="@array/api_list" android:summary="@string/version"></ListPreference> + +<CheckBoxPreference android:key="writable" android:title="@string/writable"></CheckBoxPreference> </PreferenceScreen> diff --git a/src/de/openrat/android/blog/EditorActivity.java b/src/de/openrat/android/blog/EditorActivity.java @@ -0,0 +1,6 @@ +package de.openrat.android.blog; + +public class EditorActivity +{ + +} diff --git a/src/de/openrat/android/blog/FolderActivity.java b/src/de/openrat/android/blog/FolderActivity.java @@ -0,0 +1,122 @@ +/** + * + */ +package de.openrat.android.blog; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.json.JSONArray; +import org.json.JSONObject; + +import android.app.ListActivity; +import android.content.Intent; +import android.os.Bundle; +import android.view.View; +import android.widget.AdapterView; +import android.widget.ListAdapter; +import android.widget.ListView; +import android.widget.SimpleAdapter; +import android.widget.AdapterView.OnItemClickListener; +import de.openrat.android.blog.client.CMSRequest; + +/** + * @author dankert + * + */ +public class FolderActivity extends ListActivity +{ + + private static final String ID2 = "id"; + public static final String CLIENT = "client"; + private static final String NAME = "name"; + private static final String DESCRIPTION = "description"; + private CMSRequest request; + private List<Map<String, String>> data; + + @Override + protected void onCreate(Bundle savedInstanceState) + { + setContentView(R.layout.listing); + setTitle(R.string.connect); + + super.onCreate(savedInstanceState); + + int[] to = new int[] { R.id.listentry_name, R.id.listentry_description }; + ; + String[] from = new String[] { NAME, DESCRIPTION }; + ; + data = new ArrayList<Map<String, String>>(); + + request = (CMSRequest) getIntent().getSerializableExtra(CLIENT); + + // + request.clearParameters(); + request.setParameter("action", "folder"); + request.setParameter("subaction", "show"); + String folderid = getIntent().getStringExtra("folderid"); + request.setParameter("id", folderid != null ? folderid : "1"); + + String response = null; + try + { + response = request.performRequest(); + System.out.println("Ordnerinhalt: " + response); + + } catch (IOException e) + { + System.err.println("Fuck Folder"); + System.err.println(response); + System.err.println(e.getMessage()); + } + + try + { + System.out.println(response); + JSONObject json = new JSONObject(response); + JSONObject inhalte = json.getJSONObject("object"); + JSONArray names = inhalte.names(); + for (int i = 0; i < names.length(); i++) + { + JSONObject obj = inhalte.getJSONObject(names.getString(i)); + + final Map<String, String> values = new HashMap<String, String>(); + values.put(NAME, "[" + obj.getString("type") + "] " + + obj.getString("name")); + values.put(DESCRIPTION, obj.getString("desc")); + values.put(ID2, names.getString(i)); + data.add(values); + + } + + } catch (Exception e) + { + e.printStackTrace(); + } + + final ListAdapter adapter = new SimpleAdapter(this, data, + R.layout.listing_entry, from, to); + setListAdapter(adapter); + + ListView list = getListView(); + + list.setOnItemClickListener(new OnItemClickListener() + { + + @Override + public void onItemClick(AdapterView<?> parent, View view, + int position, long id) + { + final Intent i = new Intent(FolderActivity.this, + FolderActivity.class); + i.putExtra(CLIENT, request); + i.putExtra("folderid", data.get(position).get(ID2)); + startActivity(i); + } + }); + } + +} diff --git a/src/de/openrat/android/blog/NewActivity.java b/src/de/openrat/android/blog/NewActivity.java @@ -0,0 +1,6 @@ +package de.openrat.android.blog; + +public class NewActivity +{ + +} diff --git a/src/de/openrat/android/blog/OpenRatBlog.java b/src/de/openrat/android/blog/OpenRatBlog.java @@ -8,16 +8,19 @@ import android.app.Activity; import android.content.Intent; import android.content.SharedPreferences; import android.os.Bundle; +import android.preference.PreferenceManager; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; -import android.widget.ScrollView; +import android.view.View; +import android.view.View.OnClickListener; import android.widget.TextView; import de.openrat.android.blog.client.CMSRequest; public class OpenRatBlog extends Activity { private static final String PREFS_NAME = "OR_BLOG_PREFS"; + private CMSRequest request; /** Called when the activity is first created. */ @Override @@ -25,14 +28,21 @@ public class OpenRatBlog extends Activity { super.onCreate(savedInstanceState); setContentView(R.layout.main); + setTitle(R.string.app_name); - CMSRequest request = new CMSRequest("demo.openrat.de"); + SharedPreferences prefs = PreferenceManager + .getDefaultSharedPreferences(this); + + int port = Integer.parseInt(prefs.getString("port", "80")); + String path = prefs.getString("path", "/"); + String host = prefs.getString("hostname", ""); + request = new CMSRequest(host, path, port); request.setParameter("action", "index"); request.setParameter("subaction", "login"); request.setParameter("dbid", "db1"); - request.setParameter("login_name", "admin"); - request.setParameter("login_password", "admin"); + request.setParameter("login_name", prefs.getString("username","")); + request.setParameter("login_password", prefs.getString("password","")); String response = null; try { @@ -52,34 +62,37 @@ public class OpenRatBlog extends Activity final String msgText = json.getJSONArray("notices") .getJSONObject(0).getString("text"); -// final String msgText2 = json.getJSONArray("notics") -// .getJSONObject(0).getString("text"); + // final String msgText2 = json.getJSONArray("notics") + // .getJSONObject(0).getString("text"); // TextView text = new TextView(this); // text.setText("Sitzung '" + sessionId + "': " + sessionId); request.setCookie(sessionName, sessionId); - TextView tv = new TextView(this); - tv.setVerticalScrollBarEnabled(true); - tv.setHorizontalScrollBarEnabled(true); - tv.setScrollBarStyle(TextView.SCROLLBARS_INSIDE_INSET); + TextView tv = (TextView) findViewById(R.id.hello); tv.setText(msgText + "\nSitzung '" + sessionName + "': " + sessionId + "\nAusgabe: " + response); - - ScrollView scrollView =new ScrollView(this); - scrollView.setScrollContainer(true); - scrollView.setFocusable(true); - scrollView.addView(tv); - setContentView(scrollView); + + View connect = findViewById(R.id.connect); + connect.setOnClickListener( new OnClickListener() + { + + @Override + public void onClick(View v) + { + Intent intent = new Intent(v.getContext(),ProjectActivity.class); + intent.putExtra(ProjectActivity.CLIENT, request); + startActivity(intent); + } + }); } catch (Exception e) { response = e.getMessage(); - TextView tv = new TextView(this); + TextView tv = (TextView) findViewById(R.id.hello); tv.setText("Fehler: " + response); - setContentView(tv); } @@ -95,17 +108,16 @@ public class OpenRatBlog extends Activity super.onCreateOptionsMenu(menu); MenuInflater mi = new MenuInflater(getApplication()); mi.inflate(R.menu.main, menu); - + return true; } - public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.menu_preferences: - startActivity( new Intent(this,Configuration.class)); + startActivity(new Intent(this, Configuration.class)); } return false; } diff --git a/src/de/openrat/android/blog/PageElementsActivity.java b/src/de/openrat/android/blog/PageElementsActivity.java @@ -0,0 +1,16 @@ +/** + * + */ +package de.openrat.android.blog; + +import android.app.Activity; + +/** + * @author dankert + * + */ +public class PageElementsActivity extends Activity +{ + + +} diff --git a/src/de/openrat/android/blog/ProjectActivity.java b/src/de/openrat/android/blog/ProjectActivity.java @@ -0,0 +1,135 @@ +/** + * + */ +package de.openrat.android.blog; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.json.JSONArray; +import org.json.JSONObject; + +import android.app.ListActivity; +import android.content.Intent; +import android.os.Bundle; +import android.view.View; +import android.widget.AdapterView; +import android.widget.ListAdapter; +import android.widget.ListView; +import android.widget.SimpleAdapter; +import android.widget.Toast; +import android.widget.AdapterView.OnItemClickListener; +import de.openrat.android.blog.client.CMSRequest; + +/** + * @author dankert + * + */ +public class ProjectActivity extends ListActivity +{ + private static final String ID2 = "id"; + public static final String CLIENT = "client"; + private static final String NAME = "name"; + private static final String DESCRIPTION = "description"; + private CMSRequest request; + private List<Map<String, String>> data; + + @Override + protected void onCreate(Bundle savedInstanceState) + { + setContentView(R.layout.listing); + setTitle(R.string.connect); + + super.onCreate(savedInstanceState); + + int[] to = new int[] { R.id.listentry_name, R.id.listentry_description }; + ; + String[] from = new String[] { NAME, DESCRIPTION }; + ; + data = new ArrayList<Map<String, String>>(); + + request = (CMSRequest) getIntent().getSerializableExtra(CLIENT); + + request.clearParameters(); + request.setParameter("action", "index"); + request.setParameter("subaction", "projectmenu"); + String response = null; + try + { + response = request.performRequest(); + + } catch (IOException e) + { + response = e.getMessage(); + } + + try + { + System.out.println(response); + JSONObject json = new JSONObject(response); + JSONArray projects = json.getJSONArray("projects"); + for (int i = 0; i < projects.length(); i++) + { + final Map<String, String> values = new HashMap<String, String>(); + JSONObject project = projects.getJSONObject(i); + values.put(NAME, project.getString("name")); + values.put(DESCRIPTION, ""); + values.put(ID2, project.getString("id")); + data.add(values); + + } + + } catch (Exception e) + { + e.printStackTrace(); + } + + ListView list = getListView(); + + list.setOnItemClickListener(new OnItemClickListener() + { + + @Override + public void onItemClick(AdapterView<?> parent, View view, + int position, long id) + { + Toast.makeText(ProjectActivity.this, "Click on " + position, + Toast.LENGTH_SHORT).show(); + + final Intent i = new Intent(ProjectActivity.this, + FolderActivity.class); + i.putExtra(CLIENT, request); + + // Projekt auswählen + String projectid = data.get(position).get(ID2); + + request = (CMSRequest) getIntent().getSerializableExtra(CLIENT); + + request.clearParameters(); + request.setParameter("action", "index"); + request.setParameter("subaction", "project"); + request.setParameter("id", projectid); + String response = null; + try + { + response = request.performRequest(); + System.out.println("Projekt ausgewählt: " + response); + + } catch (IOException e) + { + System.err.println("Fehler bei Projektauswahl: "+response); + System.err.println(e.getMessage()); + } + + startActivity(i); + } + }); + + final ListAdapter adapter = new SimpleAdapter(this, data, + R.layout.listing_entry, from, to); + setListAdapter(adapter); + } +} diff --git a/src/de/openrat/android/blog/PropertiesActivity.java b/src/de/openrat/android/blog/PropertiesActivity.java @@ -0,0 +1,8 @@ +package de.openrat.android.blog; + +import android.app.Activity; + +public class PropertiesActivity extends Activity +{ + +} diff --git a/src/de/openrat/android/blog/adapter/FSimpleAdapter.java b/src/de/openrat/android/blog/adapter/FSimpleAdapter.java @@ -0,0 +1,27 @@ +/** + * + */ +package de.openrat.android.blog.adapter; + +import java.util.List; +import java.util.Map; + +import android.content.Context; +import android.widget.SimpleAdapter; + +/** + * @author dankert + * + */ +public class FSimpleAdapter extends SimpleAdapter +{ + + public FSimpleAdapter(Context context, List<? extends Map<String, ?>> data, + int resource, String[] from, int[] to) + { + super(context, data, resource, from, to); + } + + + +} diff --git a/src/de/openrat/android/blog/client/CMSRequest.java b/src/de/openrat/android/blog/client/CMSRequest.java @@ -25,6 +25,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; +import java.io.Serializable; import java.io.StringReader; import java.io.UnsupportedEncodingException; import java.net.InetSocketAddress; @@ -71,7 +72,7 @@ import org.xml.sax.SAXException; * * @author Jan Dankert */ -public class CMSRequest { +public class CMSRequest implements Serializable { // some constants... private static final String CHARSET_UTF8 = "UTF-8";