Heavy refactoring: Moved UI things to UI packages
authorLennart Rosam <lennart@familie-rosam.de>
Sun, 22 Jan 2012 18:05:47 +0000 (19:05 +0100)
committerLennart Rosam <lennart@familie-rosam.de>
Sun, 22 Jan 2012 18:05:47 +0000 (19:05 +0100)
24 files changed:
AndroidManifest.xml
res/layout/main.xml
res/values/strings.xml
src/eu/alefzero/owncloud/FileDetailActivity.java [deleted file]
src/eu/alefzero/owncloud/FileDownloader.java
src/eu/alefzero/owncloud/FileList.java [deleted file]
src/eu/alefzero/owncloud/FileListActionListAdapter.java [deleted file]
src/eu/alefzero/owncloud/FileListListAdapter.java [deleted file]
src/eu/alefzero/owncloud/MainScreen.java [deleted file]
src/eu/alefzero/owncloud/Preferences.java [deleted file]
src/eu/alefzero/owncloud/PreferencesNewSession.java [deleted file]
src/eu/alefzero/owncloud/authenticator/AccountAuthenticator.java
src/eu/alefzero/owncloud/authenticator/AuthUtils.java
src/eu/alefzero/owncloud/authenticator/AuthenticatorActivity.java [deleted file]
src/eu/alefzero/owncloud/ui/ActionBar.java [deleted file]
src/eu/alefzero/owncloud/ui/AuthenticatorActivity.java [new file with mode: 0644]
src/eu/alefzero/owncloud/ui/FileDetailActivity.java [new file with mode: 0644]
src/eu/alefzero/owncloud/ui/FileDisplayActivity.java [new file with mode: 0644]
src/eu/alefzero/owncloud/ui/Preferences.java [new file with mode: 0644]
src/eu/alefzero/owncloud/ui/PreferencesNewSession.java [new file with mode: 0644]
src/eu/alefzero/owncloud/ui/adapter/FileListActionListAdapter.java [new file with mode: 0644]
src/eu/alefzero/owncloud/ui/adapter/FileListListAdapter.java [new file with mode: 0644]
src/eu/alefzero/owncloud/ui/fragment/ActionBar.java [new file with mode: 0644]
src/eu/alefzero/owncloud/ui/fragment/FileList.java [new file with mode: 0644]

index 1d6c69c..8dd03ad 100644 (file)
@@ -25,9 +25,9 @@
     <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
 
     <application android:icon="@drawable/icon" android:label="@string/app_name">
-        <activity android:name=".MainScreen"
+        <activity android:name=".ui.FileDisplayActivity"
                   android:label="@string/app_name">
-            <intent-filter>
+                  <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
                 <category android:name="android.intent.category.LAUNCHER" />
             </intent-filter>
@@ -44,8 +44,8 @@
                 <data android:mimeType="*/*"></data>
             </intent-filter>
         </activity>
-        <activity android:name="Preferences"></activity>
-        <activity android:name="PreferencesNewSession">
+        <activity android:name=".ui.Preferences"></activity>
+        <activity android:name=".ui.PreferencesNewSession">
         </activity>
                 <service
             android:exported="true" android:name=".authenticator.AccountAuthenticatorService">
                 android:name="android.content.SyncAdapter"
                 android:resource="@xml/syncadapter_files"/>
         </service>
-         <provider android:name="cp" android:enabled="true" android:syncable="true" android:exported="false" android:authorities="org.owncloud" android:label="@string/sync_string_files"></provider>
-         <activity android:name=".authenticator.AuthenticatorActivity"></activity>
-         <service android:name="FileDownloader">
+         <provider android:name=".cp" android:enabled="true" android:syncable="true" android:exported="false" android:authorities="org.owncloud" android:label="@string/sync_string_files"></provider>
+         <activity android:name=".ui.AuthenticatorActivity"></activity>
+         <service android:name=".FileDownloader">
          </service>
-         <activity android:name="FileDetailActivity"></activity>
+         <activity android:name=".ui.FileDetailActivity"></activity>
     </application>
 </manifest>
\ No newline at end of file
index 378b777..cddcacb 100644 (file)
@@ -15,7 +15,7 @@
             android:id="@+id/actionBar"
             android:layout_height="wrap_content"
             android:layout_width="fill_parent"
-            class="eu.alefzero.owncloud.ui.ActionBar">
+            class="eu.alefzero.owncloud.ui.fragment.ActionBar">
             <!-- Preview: layout=@layout/action_bar -->
         </fragment>
 
@@ -29,7 +29,7 @@
                 android:layout_width="0dp"
                 android:layout_height="fill_parent"
                 android:layout_weight="1"
-                class="eu.alefzero.owncloud.FileList" >
+                class="eu.alefzero.owncloud.ui.fragment.FileList" >
 
                 <!-- Preview: layout=@layout/list_layout -->
             </fragment>
index 57c58a8..fb2bae7 100644 (file)
@@ -5,6 +5,13 @@
     <string name="main_password">Password:</string>
     <string name="main_login">Username:</string>
     <string name="main_button_login">Login</string>
+    <string name="main_welcome">Welcome to your ownCloud</string>
+    <string name="main_files">Files</string>
+    <string name="main_music">Music</string>
+    <string name="main_contacts">Contacts</string>
+    <string name="main_calendar">Calendar</string>
+    <string name="main_bookmarks">Bookmarks</string>
+    <string name="main_settings">Settings</string>
     <string name="prefs_general">General</string>
     <string name="prefs_sessions">Stored sessions</string>
     <string name="prefs_add_session">Add new session</string>
diff --git a/src/eu/alefzero/owncloud/FileDetailActivity.java b/src/eu/alefzero/owncloud/FileDetailActivity.java
deleted file mode 100644 (file)
index c0e0147..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-package eu.alefzero.owncloud;
-
-import android.app.Activity;
-import android.content.res.Configuration;
-import android.os.Bundle;
-import android.support.v4.app.FragmentActivity;
-import android.support.v4.app.FragmentTransaction;
-import android.view.Window;
-
-public class FileDetailActivity extends FragmentActivity {
-@Override
-protected void onCreate(Bundle savedInstanceState) {
-  // TODO Auto-generated method stub
-  super.onCreate(savedInstanceState);
-  getWindow().requestFeature(Window.FEATURE_NO_TITLE);
-  setContentView(R.layout.file_activity_details);
-  
-  FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
-  ft.add(R.id.fileDetail, new FileDetail());
-  ft.commit();
-  
-}
-}
index 9e4ab76..7d3605e 100644 (file)
@@ -14,6 +14,7 @@ import android.os.Environment;
 import android.os.IBinder;
 import android.util.Log;
 import eu.alefzero.owncloud.authenticator.AccountAuthenticator;
+import eu.alefzero.owncloud.ui.FileDisplayActivity;
 
 public class FileDownloader extends Service {
   static final String EXTRA_ACCOUNT = "ACCOUNT";
@@ -57,7 +58,7 @@ public class FileDownloader extends Service {
     wdc.allowUnsignedCertificates();
 
     Notification n = new Notification(R.drawable.icon, "Downloading file", System.currentTimeMillis());
-    PendingIntent pi = PendingIntent.getActivity(this, 1, new Intent(this, MainScreen.class), 0);
+    PendingIntent pi = PendingIntent.getActivity(this, 1, new Intent(this, FileDisplayActivity.class), 0);
     n.setLatestEventInfo(this, "A", "B", pi);
     nm.notify(1, n);
 
diff --git a/src/eu/alefzero/owncloud/FileList.java b/src/eu/alefzero/owncloud/FileList.java
deleted file mode 100644 (file)
index 1f62b85..0000000
+++ /dev/null
@@ -1,65 +0,0 @@
-package eu.alefzero.owncloud;
-
-import eu.alefzero.owncloud.authenticator.AccountAuthenticator;
-import eu.alefzero.owncloud.db.ProviderMeta.ProviderTableMeta;
-import android.accounts.Account;
-import android.accounts.AccountManager;
-import android.app.Activity;
-import android.app.Service;
-import android.content.Intent;
-import android.database.Cursor;
-import android.os.Bundle;
-import android.support.v4.app.FragmentTransaction;
-import android.support.v4.app.ListFragment;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.ViewGroup;
-import android.widget.ArrayAdapter;
-import android.widget.ListView;
-import android.widget.TextView;
-import android.widget.Toast;
-
-public class FileList extends ListFragment {
-  private Cursor mCursor;
-  private Account mAccount;
-  private AccountManager mAccountManager;
-  
-  @Override
-  public void onCreate(Bundle savedInstanceState) {
-    // TODO Auto-generated method stub
-    super.onCreate(savedInstanceState);
-    
-    mAccountManager = (AccountManager)getActivity().getSystemService(Service.ACCOUNT_SERVICE);
-    mAccount = mAccountManager.getAccountsByType(AccountAuthenticator.ACCOUNT_TYPE)[0];
-    populateFileList();
-  }
-  
-  @Override
-  public void onActivityCreated(Bundle savedInstanceState) {
-    // TODO Auto-generated method stub
-    super.onActivityCreated(savedInstanceState);
-  }
-  @Override
-  public void onListItemClick(ListView l, View v, int position, long id) {
-    // TODO Auto-generated method stub
-    FileDetail fd = (FileDetail) getFragmentManager().findFragmentById(R.id.fileDetail);
-    if (fd != null) {
-      fd.use(((TextView)v.findViewById(R.id.Filename)).getText());
-    } else {
-      Intent i = new Intent(getActivity(), FileDetailActivity.class);
-      startActivity(i);
-    }
-    super.onListItemClick(l, v, position, id);
-  }
-  
-  private void populateFileList() {
-    mCursor = getActivity().getContentResolver().query(ProviderTableMeta.CONTENT_URI,
-        null,
-        ProviderTableMeta.FILE_ACCOUNT_OWNER+"=?",
-        new String[]{mAccount.name},
-        null);
-    
-    setListAdapter(new FileListListAdapter(mCursor, getActivity()));
-  }
-}
diff --git a/src/eu/alefzero/owncloud/FileListActionListAdapter.java b/src/eu/alefzero/owncloud/FileListActionListAdapter.java
deleted file mode 100644 (file)
index 212a6f2..0000000
+++ /dev/null
@@ -1,162 +0,0 @@
-/* ownCloud Android client application
- *   Copyright (C) 2011  Bartek Przybylski
- *
- *   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 3 of the License, 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 this program.  If not, see <http://www.gnu.org/licenses/>.
- *
- */
-
-package eu.alefzero.owncloud;
-
-import java.io.File;
-
-import eu.alefzero.owncloud.authenticator.AccountAuthenticator;
-import eu.alefzero.owncloud.db.ProviderMeta.ProviderTableMeta;
-import android.accounts.Account;
-import android.accounts.AccountManager;
-import android.content.Context;
-import android.content.Intent;
-import android.database.Cursor;
-import android.database.DataSetObserver;
-import android.net.Uri;
-import android.text.TextUtils;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.ViewGroup;
-import android.widget.ImageView;
-import android.widget.ListAdapter;
-import android.widget.TextView;
-
-public class FileListActionListAdapter implements ListAdapter {
-
-  private Context mContext;
-  private Account mAccount;
-  private String mFilename, mFileType, mFilePath, mFileStoragePath, mItemId;
-  
-  private final int ITEM_DOWNLOAD = 0;
-  private final int ITEM_SHARE = 1;
-  
-  public FileListActionListAdapter(Cursor c, Context co, Account account) {
-    mContext = co;
-    mFilename = c.getString(c.getColumnIndex(ProviderTableMeta.FILE_NAME));
-    mFileType = c.getString(c.getColumnIndex(ProviderTableMeta.FILE_CONTENT_TYPE));
-    mFilePath = c.getString(c.getColumnIndex(ProviderTableMeta.FILE_PATH));
-    mFileStoragePath = c.getString(c.getColumnIndex(ProviderTableMeta.FILE_STORAGE_PATH));
-    mItemId = c.getString(c.getColumnIndex(ProviderTableMeta._ID));
-    mAccount = account;
-  }
-  
-  public boolean areAllItemsEnabled() {
-    // TODO Auto-generated method stub
-    return true;
-  }
-
-  public boolean isEnabled(int position) {
-    // TODO Auto-generated method stub
-    return true;
-  }
-
-  public int getCount() {
-    // TODO Auto-generated method stub
-    return 1;
-  }
-
-  public Object getItem(int position) {
-    if (position == 0) {
-      Intent intent = new Intent(Intent.ACTION_VIEW);
-      if (TextUtils.isEmpty(mFileStoragePath)) {
-        intent.putExtra("toDownload", true);
-        AccountManager accm = (AccountManager) mContext.getSystemService(Context.ACCOUNT_SERVICE);
-        String ocurl = accm.getUserData(mAccount, AccountAuthenticator.KEY_OC_URL);
-        ocurl += mFilePath + mFilename;
-        intent.setData(Uri.parse(ocurl));
-      } else {
-        intent.putExtra("toDownload", false);
-        intent.setDataAndType(Uri.fromFile(new File(mFileStoragePath)), mFileType);
-      }
-      return intent;
-    }
-    return null;
-  }
-
-  public long getItemId(int position) {
-    // TODO Auto-generated method stub
-    return 0;
-  }
-
-  public int getItemViewType(int position) {
-    // TODO Auto-generated method stub
-    return 0;
-  }
-
-  public View getView(int position, View convertView, ViewGroup parent) {
-    View v = convertView;
-    if (v == null) {
-      LayoutInflater vi = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
-      v = vi.inflate(R.layout.file_display_action_list_element, null);
-    }
-
-    TextView tv;
-    ImageView iv;
-    switch (position) {
-      case ITEM_DOWNLOAD :
-        tv = (TextView) v.findViewById(R.id.textView1);
-        if (mFileStoragePath == null) {
-          tv.setText("Download");
-        } else {
-          setActionName(tv);
-        }
-        iv = (ImageView) v.findViewById(R.id.imageView1);
-        iv.setImageResource(R.drawable.download);
-        break;
-    }
-    
-    return v;
-  }
-
-  public int getViewTypeCount() {
-    // TODO Auto-generated method stub
-    return 2;
-  }
-
-  public boolean hasStableIds() {
-    // TODO Auto-generated method stub
-    return false;
-  }
-
-  public boolean isEmpty() {
-    // TODO Auto-generated method stub
-    return false;
-  }
-
-  public void registerDataSetObserver(DataSetObserver observer) {
-    // TODO Auto-generated method stub
-    
-  }
-
-  public void unregisterDataSetObserver(DataSetObserver observer) {
-    // TODO Auto-generated method stub
-    
-  }
-
-  private void setActionName(TextView tv) {
-    if (mFileType.matches("image/.*")) {
-      tv.setText("View");
-    } else if (mFileType.matches("audio/.*") || mFileType.matches("video/.*")) {
-      tv.setText("Play");
-    } else {
-      tv.setText("Open");
-    }
-  }
-  
-}
diff --git a/src/eu/alefzero/owncloud/FileListListAdapter.java b/src/eu/alefzero/owncloud/FileListListAdapter.java
deleted file mode 100644 (file)
index 3b432fc..0000000
+++ /dev/null
@@ -1,103 +0,0 @@
-package eu.alefzero.owncloud;
-
-import java.security.Provider;
-
-import eu.alefzero.owncloud.db.ProviderMeta;
-import eu.alefzero.owncloud.db.ProviderMeta.ProviderTableMeta;
-
-import android.content.Context;
-import android.database.Cursor;
-import android.database.DataSetObserver;
-import android.util.Log;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.ViewGroup;
-import android.view.View.OnLongClickListener;
-import android.widget.AdapterView;
-import android.widget.ImageView;
-import android.widget.ListAdapter;
-import android.widget.TextView;
-import android.widget.AdapterView.OnItemClickListener;
-
-public class FileListListAdapter implements ListAdapter {
-
-  private Cursor mCursor;
-  private Context mContext;
-  
-  public FileListListAdapter(Cursor c, Context context) {
-    mCursor = c;
-    mContext = context;
-  }
-  
-  public boolean areAllItemsEnabled() {
-    return true;
-  }
-
-  public boolean isEnabled(int position) {
-    // TODO Auto-generated method stub
-    return true;
-  }
-
-  public int getCount() {
-    // TODO Auto-generated method stub
-    return mCursor.getCount();
-  }
-
-  public Object getItem(int position) {
-    // TODO Auto-generated method stub
-    return null;
-  }
-
-  public long getItemId(int position) {
-    // TODO Auto-generated method stub
-    return 0;
-  }
-
-  public int getItemViewType(int position) {
-    // TODO Auto-generated method stub
-    return 0;
-  }
-
-  public View getView(int position, View convertView, ViewGroup parent) {
-    View v = convertView;
-    if (v == null) {
-      LayoutInflater vi = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
-      v = vi.inflate(R.layout.list_layout, null);
-    }
-    if (mCursor.moveToPosition(position)) {
-      TextView tv = (TextView) v.findViewById(R.id.Filename);
-      tv.setText(DisplayUtils.HtmlDecode(mCursor.getString(mCursor.getColumnIndex(ProviderMeta.ProviderTableMeta.FILE_NAME))));
-      if (!mCursor.getString(mCursor.getColumnIndex(ProviderTableMeta.FILE_CONTENT_TYPE)).equals("DIR")) {
-        ImageView iv = (ImageView) v.findViewById(R.id.imageView1);
-        iv.setImageResource(R.drawable.file);
-      }
-    }
-    
-    return v;
-  }
-
-  public int getViewTypeCount() {
-    // TODO Auto-generated method stub
-    return 4;
-  }
-
-  public boolean hasStableIds() {
-    // TODO Auto-generated method stub
-    return true;
-  }
-
-  public boolean isEmpty() {
-    // TODO Auto-generated method stub
-    return false;
-  }
-
-  public void registerDataSetObserver(DataSetObserver observer) {
-    // TODO Auto-generated method stub
-    
-  }
-
-  public void unregisterDataSetObserver(DataSetObserver observer) {
-    // TODO Auto-generated method stub
-    
-  }
-}
diff --git a/src/eu/alefzero/owncloud/MainScreen.java b/src/eu/alefzero/owncloud/MainScreen.java
deleted file mode 100644 (file)
index 4ec6adc..0000000
+++ /dev/null
@@ -1,346 +0,0 @@
-/* ownCloud Android client application
- *   Copyright (C) 2011  Bartek Przybylski
- *
- *   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 3 of the License, 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 this program.  If not, see <http://www.gnu.org/licenses/>.
- *
- */
-
-package eu.alefzero.owncloud;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.util.LinkedList;
-import java.util.Stack;
-
-import android.accounts.Account;
-import android.accounts.AccountManager;
-import android.app.AlertDialog;
-import android.app.Dialog;
-import android.app.ListActivity;
-import android.content.DialogInterface;
-import android.content.Intent;
-import android.content.DialogInterface.OnCancelListener;
-import android.content.res.Configuration;
-import android.database.Cursor;
-import android.graphics.Bitmap;
-import android.graphics.BitmapFactory;
-import android.graphics.Matrix;
-import android.net.Uri;
-import android.os.Bundle;
-import android.os.Environment;
-import android.support.v4.app.FragmentActivity;
-import android.support.v4.app.FragmentTransaction;
-import android.text.TextUtils;
-import android.util.Log;
-import android.view.Menu;
-import android.view.MenuInflater;
-import android.view.MenuItem;
-import android.view.View;
-import android.view.Window;
-import android.widget.ImageView;
-import android.widget.ListView;
-import android.widget.TextView;
-import eu.alefzero.owncloud.authenticator.AccountAuthenticator;
-import eu.alefzero.owncloud.db.ProviderMeta.ProviderTableMeta;
-
-public class MainScreen extends FragmentActivity {
-  private DbHandler mDBHandler;
-  private Stack<String> mParents;
-  private LinkedList<String> mPath;
-  private Account mAccount;
-  private Cursor mCursor;
-  private boolean mIsDisplayingFile;
-
-  private static final int DIALOG_CHOOSE_ACCOUNT = 0;
-
-  @Override
-  public void onCreate(Bundle savedInstanceState) {
-    super.onCreate(savedInstanceState);
-    getWindow().requestFeature(Window.FEATURE_NO_TITLE);
-    setContentView(R.layout.main);
-    
-    FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
-    ft.add(R.id.fileList, new FileList());
-    if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
-      ft.add(R.id.fileDetail, new FileDetail());
-    }
-    ft.commit();
-
-    /*getSupportFragmentManager().beginTransaction().add(arg0, arg1);
-    FileList fl = new FileList();
-    ft.add(R.id.fileList, fl);
-    ft.commit();
-    /*
-
-    
-    if (savedInstanceState != null) {
-      mParents = (Stack<String>)savedInstanceState.getSerializable("parentsStack");
-      mIsDisplayingFile = savedInstanceState.getBoolean("isDisplayingFile");
-      mPath = (LinkedList<String>)savedInstanceState.getSerializable("path");
-    } else {
-      mParents = new Stack<String>();
-      mPath = new LinkedList<String>();
-      mIsDisplayingFile = false;
-    }
-
-    mDBHandler = new DbHandler(getBaseContext());
-    requestWindowFeature(Window.FEATURE_NO_TITLE);
-    setContentView(R.layout.main);
-
-    AccountManager accMan = AccountManager.get(this);
-    Account[] accounts = accMan.getAccountsByType(AccountAuthenticator.ACCOUNT_TYPE);
-
-    if (accounts.length == 0) {
-      // using string value since in API7 this constatn is not defined
-      // in API7 < this constatant is defined in Settings.ADD_ACCOUNT_SETTINGS
-      // and Settings.EXTRA_AUTHORITIES
-      Intent intent = new Intent("android.settings.ADD_ACCOUNT_SETTINGS");
-      intent.putExtra("authorities", new String[] {AccountAuthenticator.AUTH_TOKEN_TYPE});
-      startActivity(intent);
-    } else if (accounts.length > 1) {
-      showDialog(DIALOG_CHOOSE_ACCOUNT);
-    } else {
-      mAccount = accounts[0];
-      populateFileList();
-    }*/
-  }
-
-  @Override
-  public boolean onOptionsItemSelected(MenuItem item) {
-    switch (item.getItemId()) {
-      case R.id.settingsItem :
-        Intent i = new Intent(this, Preferences.class);
-        startActivity(i);
-        break;
-    }
-    return true;
-  }
-
-  @Override
-  protected Dialog onCreateDialog(int id) {
-    switch (id) {
-      case DIALOG_CHOOSE_ACCOUNT:
-        return createChooseAccountDialog();
-      default:
-        throw new IllegalArgumentException("Unknown dialog id: " + id);
-    }
-  }
-  
-  @Override
-  public boolean onCreateOptionsMenu(Menu menu) {
-    MenuInflater inflater = getMenuInflater();
-    inflater.inflate(R.menu.menu, menu);
-    return true;
-  }
-    
-  private Dialog createChooseAccountDialog() {
-    final AccountManager accMan = AccountManager.get(this);
-    CharSequence[] items = new CharSequence[accMan.getAccountsByType(AccountAuthenticator.ACCOUNT_TYPE).length];
-    int i = 0;
-    for (Account a : accMan.getAccountsByType(AccountAuthenticator.ACCOUNT_TYPE)) {
-      items[i++] = a.name;
-    }
-    
-    AlertDialog.Builder builder = new AlertDialog.Builder(this);
-    builder.setTitle(R.string.common_choose_account);
-    builder.setCancelable(true);
-    builder.setItems(items, new DialogInterface.OnClickListener() {
-        public void onClick(DialogInterface dialog, int item) {
-            mAccount = accMan.getAccountsByType(AccountAuthenticator.ACCOUNT_TYPE)[item];
-            dialog.dismiss();
-            populateFileList();
-        }
-    });
-    builder.setOnCancelListener(new OnCancelListener() {
-      public void onCancel(DialogInterface dialog) {
-        MainScreen.this.finish();
-      }
-    });
-    AlertDialog alert = builder.create();
-    return alert;
-  }
-
-  //@Override
-  //public void onBackPressed() {
-    /*PathLayout pl = (PathLayout) findViewById(R.id.pathLayout1);
-    if (mIsDisplayingFile) {
-      mIsDisplayingFile = false;
-      setContentView(R.layout.main);
-      pl = (PathLayout) findViewById(R.id.pathLayout1);
-      Uri uri;
-      if (mParents.empty()) {
-        uri = ProviderTableMeta.CONTENT_URI;
-      } else {
-        uri = Uri.withAppendedPath(ProviderTableMeta.CONTENT_URI_DIR, mParents.peek());
-      }
-      mCursor = managedQuery(uri,
-                             null,
-                             ProviderTableMeta.FILE_ACCOUNT_OWNER+"=?",
-                             new String[]{mAccount.name}, null);
-  
-      if (mCursor.moveToFirst()) {
-        String s = mCursor.getString(mCursor.getColumnIndex(ProviderTableMeta.FILE_PATH));
-        for (String str : s.split("/")) {
-          if (!TextUtils.isEmpty(str))
-            pl.push(DisplayUtils.HtmlDecode(str));
-        }
-      }
-      getListView().setAdapter(new FileListListAdapter(mCursor, this));      
-      getListView().invalidate();
-      return;
-    }
-    if (mParents.size()==0) {
-      super.onBackPressed();
-      return;
-    } else if (mParents.size() == 1) {
-      mParents.pop();
-      mPath.removeLast();
-      pl.pop();
-      mCursor = managedQuery(ProviderTableMeta.CONTENT_URI,
-          null,
-          ProviderTableMeta.FILE_ACCOUNT_OWNER+"=?",
-          new String[]{mAccount.name},
-          null);
-    } else {
-      mParents.pop();
-      mPath.removeLast();
-      pl.pop();
-      mCursor = managedQuery(Uri.withAppendedPath(ProviderTableMeta.CONTENT_URI_DIR, mParents.peek()),
-          null,
-          ProviderTableMeta.FILE_ACCOUNT_OWNER+"=?",
-          new String[]{mAccount.name},
-          null);
-    }
-    
-    setListAdapter(new FileListListAdapter(mCursor, this));
-    getListView().invalidate();*/
-  //}
-
-  //@Override
-/*  protected void onListItemClick(ListView l, View v, int position, long id) {
-    super.onListItemClick(l, v, position, id);
-    /*PathLayout pl = (PathLayout) findViewById(R.id.pathLayout1);
-    if (!mCursor.moveToPosition(position)) {
-      throw new IndexOutOfBoundsException("Incorrect item selected");
-    }
-    if (!mIsDisplayingFile) {
-      if (mCursor.getString(mCursor.getColumnIndex(ProviderTableMeta.FILE_CONTENT_TYPE)).equals("DIR")) {
-        String id_ = mCursor.getString(mCursor.getColumnIndex(ProviderTableMeta._ID));
-        String dirname = mCursor.getString(mCursor.getColumnIndex(ProviderTableMeta.FILE_NAME));
-        pl.push(DisplayUtils.HtmlDecode(dirname));
-        mPath.addLast(DisplayUtils.HtmlDecode(dirname));
-        mParents.push(id_);
-        mCursor = managedQuery(Uri.withAppendedPath(ProviderTableMeta.CONTENT_URI_DIR, id_),
-                               null,
-                               ProviderTableMeta.FILE_ACCOUNT_OWNER + "=?",
-                               new String[]{mAccount.name}, null);
-        setListAdapter(new FileListListAdapter(mCursor, this));
-      } else {
-        mIsDisplayingFile = true;
-        setContentView(R.layout.file_display);
-        String id_ = mCursor.getString(mCursor.getColumnIndex(ProviderTableMeta._ID));
-        mCursor = managedQuery(Uri.withAppendedPath(ProviderTableMeta.CONTENT_URI_FILE, id_),
-                               null,
-                               null,
-                               null,
-                               null);
-        mCursor.moveToFirst();
-        // filename
-        TextView tv = (TextView) findViewById(R.id.textView1);
-        tv.setText(mCursor.getString(mCursor.getColumnIndex(ProviderTableMeta.FILE_NAME)));
-        // filetype
-        tv = (TextView) findViewById(R.id.textView2);
-        tv.setText(DisplayUtils.convertMIMEtoPrettyPrint(mCursor.getString(mCursor.getColumnIndex(ProviderTableMeta.FILE_CONTENT_TYPE))));
-        // size
-        tv = (TextView) findViewById(R.id.textView3);
-        tv.setText(DisplayUtils.bitsToHumanReadable(mCursor.getLong(mCursor.getColumnIndex(ProviderTableMeta.FILE_CONTENT_LENGTH))));
-        // modified
-        tv = (TextView) findViewById(R.id.textView4);
-        tv.setText(mCursor.getString(mCursor.getColumnIndex(ProviderTableMeta.FILE_MODIFIED)));
-        if (!TextUtils.isEmpty(mCursor.getString(mCursor.getColumnIndex(ProviderTableMeta.FILE_STORAGE_PATH))) &&
-            mCursor.getString(mCursor.getColumnIndex(ProviderTableMeta.FILE_CONTENT_TYPE)).matches("image/*")) {
-          ImageView iv = (ImageView) findViewById(R.id.imageView1);
-          Bitmap bmp = BitmapFactory.decodeFile(mCursor.getString(mCursor.getColumnIndex(ProviderTableMeta.FILE_STORAGE_PATH)));
-          Matrix m = new Matrix();
-          float scale;
-          if (bmp.getWidth() > bmp.getHeight()) {
-            scale = (float) (200./bmp.getWidth());
-          } else {
-            scale = (float) (200./bmp.getHeight());
-          }
-          m.postScale(scale, scale);
-          Bitmap newBmp = Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(), bmp.getHeight(), m, true);
-          iv.setImageBitmap(newBmp);
-        }
-        setListAdapter(new FileListActionListAdapter(mCursor, this, mAccount));
-      }    
-      getListView().invalidate();
-    } else {
-        Intent i = (Intent) getListAdapter().getItem(position);
-        if (i.hasExtra("toDownload")) {
-          
-          Intent intent = new Intent(this, FileDownloader.class);
-          intent.putExtra(FileDownloader.EXTRA_FILE_PATH, "/"+((TextView)findViewById(R.id.textView1)).getText().toString());
-          intent.putExtra(FileDownloader.EXTRA_ACCOUNT, mAccount);
-          startService(intent);
-          /*
-          if (i.getBooleanExtra("toDownload", false)) {
-            startActivityForResult(i, 200);
-          } else {
-            startActivity(i);            
-          }*/
-       // }
-
-    //}
-//  }
-  
-  private void populateFileList() {
-    if (mParents.empty()) {
-      mCursor = getContentResolver().query(ProviderTableMeta.CONTENT_URI,
-                                           null,
-                                           ProviderTableMeta.FILE_ACCOUNT_OWNER+"=?",
-                                           new String[]{mAccount.name},
-                                           null);
-    } else {
-      mCursor = getContentResolver().query(Uri.withAppendedPath(ProviderTableMeta.CONTENT_URI_DIR, mParents.peek()),
-                                           null,
-                                           ProviderTableMeta.FILE_ACCOUNT_OWNER + "=?",
-                                           new String[]{mAccount.name}, null);
-      if (!mIsDisplayingFile) {
-        //PathLayout pl = (PathLayout) findViewById(R.id.pathLayout1);
-        //for (String s : mPath) {
-        //  pl.push(s);
-       // }
-      }
-    }
-//    setListAdapter(new FileListListAdapter(mCursor, this));
-//    getListView().invalidate();
-  }
-  
-  //@Override
-  /*protected void onActivityResult(int requestCode, int resultCode, Intent data) {
-    super.onActivityResult(requestCode, resultCode, data);
-  }
-  
-  @Override
-  protected void onSaveInstanceState(Bundle outState) {
-    super.onSaveInstanceState(outState);
-    outState.putSerializable("parentsStack", mParents);
-    outState.putSerializable("path", mPath);
-    outState.putBoolean("isDisplayingFile", mIsDisplayingFile);
-  }*/
-
-}
\ No newline at end of file
diff --git a/src/eu/alefzero/owncloud/Preferences.java b/src/eu/alefzero/owncloud/Preferences.java
deleted file mode 100644 (file)
index 9ca0e25..0000000
+++ /dev/null
@@ -1,139 +0,0 @@
-package eu.alefzero.owncloud;
-
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.util.Vector;
-
-import android.app.Activity;
-import android.content.Intent;
-import android.os.Bundle;
-import android.preference.Preference;
-import android.preference.PreferenceActivity;
-import android.preference.PreferenceScreen;
-import android.util.Log;
-import android.view.ContextMenu;
-import android.view.Menu;
-import android.view.MenuInflater;
-import android.view.MenuItem;
-import android.view.View;
-import android.view.ContextMenu.ContextMenuInfo;
-import android.widget.AdapterView.AdapterContextMenuInfo;
-
-public class Preferences extends PreferenceActivity {
-  private String TAG = "OwnCloudPreferences";
-  private final int mNewSession = 47;
-  private final int mEditSession = 48;
-  private DbHandler mDbHandler;
-  private Vector<OwnCloudSession> mSessions;
-  private int mSelectedMenuItem;
-  
-  @Override
-  public void onCreate(Bundle savedInstanceState){
-    super.onCreate(savedInstanceState);
-    mDbHandler = new DbHandler(getBaseContext());
-    mSessions = new Vector<OwnCloudSession>();
-    addPreferencesFromResource(R.xml.preferences);
-    registerForContextMenu(getListView());
-    //populateSessionList();
-  }
-  
-  private void populateSessionList() {
-    mSessions.clear();
-    mSessions = mDbHandler.getSessionList();
-    PreferenceScreen ps = getPreferenceScreen();
-    ps.removeAll();
-    addPreferencesFromResource(R.xml.preferences);
-    for (int i = 0; i < mSessions.size(); i++) {
-      Preference preference = new Preference(getBaseContext());
-      preference.setTitle(mSessions.get(i).getName());
-      URI uri;
-      try {
-        uri = new URI(mSessions.get(i).getUrl());
-      } catch (URISyntaxException e) {
-        e.printStackTrace(); // should never happend
-        continue;
-      }
-      preference.setSummary(uri.getScheme() + "://" + uri.getHost()+uri.getPath());
-      ps.addPreference(preference);
-    }
-  }
-
-  @Override
-  public boolean onCreateOptionsMenu(Menu menu) {
-    super.onCreateOptionsMenu(menu);
-    MenuInflater inflater = getMenuInflater();
-    inflater.inflate(R.menu.prefs_menu, menu);
-    return true;
-  }
-  
-  @Override
-  public boolean onMenuItemSelected(int featureId, MenuItem item) {
-    super.onMenuItemSelected(featureId, item);
-    Intent intent;
-    
-    switch (item.getItemId()) {
-      case R.id.addSessionItem:
-        intent = new Intent(this, PreferencesNewSession.class);
-        startActivityForResult(intent, mNewSession);
-        break;
-      case R.id.SessionContextEdit:
-        intent = new Intent(this, PreferencesNewSession.class);
-        intent.putExtra("sessionId", mSessions.get(mSelectedMenuItem).getEntryId());
-        intent.putExtra("sessionName", mSessions.get(mSelectedMenuItem).getName());
-        intent.putExtra("sessionURL", mSessions.get(mSelectedMenuItem).getUrl());
-        startActivityForResult(intent, mEditSession);
-        break;
-      case R.id.SessionContextRemove:
-        OwnCloudSession ocs = mSessions.get(mSelectedMenuItem);
-        mDbHandler.removeSessionWithId(ocs.getEntryId());
-        mSessions.remove(ocs);
-        getPreferenceScreen().removePreference(getPreferenceScreen().getPreference(mSelectedMenuItem+1));
-        break;
-      default:
-        Log.w(TAG, "Unknown menu item triggered");
-        return false;
-    }
-    return true;
-  }
-
-  @Override
-  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
-    super.onActivityResult(requestCode, resultCode, data);
-    if (resultCode == Activity.RESULT_OK) {
-      switch (requestCode) {
-        case mNewSession:
-          mDbHandler.addSession(data.getStringExtra("sessionName"), 
-                                data.getStringExtra("sessionURL"));
-          getPreferenceScreen().removeAll();
-          addPreferencesFromResource(R.xml.preferences);
-          populateSessionList();
-          break;
-        case mEditSession:
-          mDbHandler.changeSessionFields(data.getIntExtra("sessionId", -1),
-                                         data.getStringExtra("sessionName"),
-                                         data.getStringExtra("sessionURL"));
-          populateSessionList();
-          break;
-      }
-    }
-  }
-
-  @Override
-  public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
-    super.onCreateContextMenu(menu, v, menuInfo);
-    AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
-    mSelectedMenuItem = info.position-1;
-    menu.setHeaderTitle(mSessions.get(mSelectedMenuItem).getName());
-    
-    MenuInflater inflater = getMenuInflater();
-    inflater.inflate(R.menu.session_context_menu, menu);
-    
-  }
-  
-  @Override
-  protected void onDestroy() {
-    mDbHandler.close();
-    super.onDestroy();
-  }
-  
-}
diff --git a/src/eu/alefzero/owncloud/PreferencesNewSession.java b/src/eu/alefzero/owncloud/PreferencesNewSession.java
deleted file mode 100644 (file)
index bb4a9c0..0000000
+++ /dev/null
@@ -1,143 +0,0 @@
-package eu.alefzero.owncloud;
-
-import java.net.URI;
-import java.net.URISyntaxException;
-
-import eu.alefzero.owncloud.authenticator.AccountAuthenticatorService;
-
-import android.accounts.Account;
-import android.accounts.AccountAuthenticatorActivity;
-import android.accounts.AccountManager;
-import android.app.Activity;
-import android.content.Intent;
-import android.os.Bundle;
-import android.util.Log;
-import android.view.View;
-import android.view.View.OnClickListener;
-import android.widget.Button;
-import android.widget.EditText;
-import android.widget.Toast;
-
-public class PreferencesNewSession extends AccountAuthenticatorActivity implements OnClickListener {
-  private Intent mReturnData;
-  private final String TAG = "OwnCloudPreferencesNewSession";
-  @Override
-  public void onCreate(Bundle savedInstanceState){
-    super.onCreate(savedInstanceState);
-    //setContentView(R.layout.add_new_session);
-    /*
-    EditText et;// = (EditText) findViewById(R.id.newSession_sessionName);
-    
-    et = (EditText) findViewById(R.id.newSession_URL);
-    if (getIntent().hasExtra("sessionURL")) {
-      try {
-        URI uri = new URI(getIntent().getStringExtra("sessionURL"));
-        String url = uri.getHost();
-        if (uri.getPort() != -1) {
-          url += ":" + String.valueOf(uri.getPort());
-        }
-        if (uri.getPath() != null) {
-          url += uri.getPath();
-        } else {
-          url += "/";
-        }
-        et.setText(url);
-        et = (EditText) findViewById(R.id.newSession_username);
-        if (uri.getAuthority() != null) {
-          if (uri.getUserInfo().indexOf(':') != -1) {
-            et.setText(uri.getUserInfo().substring(0, uri.getUserInfo().indexOf(':')));
-            et = (EditText) findViewById(R.id.newSession_password);
-            et.setText(uri.getUserInfo().substring(uri.getUserInfo().indexOf(':')+1));
-          } else {
-            et.setText(uri.getUserInfo());
-          }
-        }
-        
-      } catch (URISyntaxException e) {
-        Log.e(TAG, "Incorrect URI syntax " + e.getLocalizedMessage());
-      }
-    }
-    
-    mReturnData = new Intent();
-    setResult(Activity.RESULT_OK, mReturnData);
-    ((Button) findViewById(R.id.button1)).setOnClickListener(this);
-    ((Button) findViewById(R.id.button2)).setOnClickListener(this);*/
-  }
-  
-  @Override
-  protected void onResume() {
-    super.onResume();
-  }
-
-  public void onClick(View v) {
-   /* switch (v.getId()) {
-      case R.id.button1:
-        Intent intent = new Intent();
-        if (getIntent().hasExtra("sessionId")) {
-          intent.putExtra("sessionId", getIntent().getIntExtra("sessionId", -1));
-        }
-        //String sessionName = ((EditText) findViewById(R.id.newSession_sessionName)).getText().toString();
-      //  if (sessionName.trim().equals("") || !isNameValid(sessionName)) {
-     //    Toast.makeText(this, R.string.new_session_session_name_error, Toast.LENGTH_LONG).show();
-     //     break;
-       // }
-        URI uri = prepareURI();
-        if (uri != null) {
-          //intent.putExtra("sessionName", sessionName);
-          intent.putExtra("sessionURL", uri.toString());
-          setResult(Activity.RESULT_OK, intent);
-          AccountManager accMgr = AccountManager.get(this);
-          Account a = new Account("OwnCloud", AccountAuthenticatorService.ACCOUNT_TYPE);
-          accMgr.addAccountExplicitly(a, "asd", null);
-          finish();
-        }
-        break;
-      case R.id.button2:
-        setResult(Activity.RESULT_CANCELED);
-        finish();
-        break;
-    }*/
-  }
-  
-  private URI prepareURI() {
-    URI uri = null;
-   /* String url = "";
-    try {
-      String username = ((EditText) findViewById(R.id.newSession_username)).getText().toString().trim();
-      String password = ((EditText) findViewById(R.id.newSession_password)).getText().toString().trim();
-      String hostname = ((EditText) findViewById(R.id.newSession_URL)).getText().toString().trim();
-      String scheme;
-      if (hostname.matches("[A-Za-z]://")) {
-        scheme = hostname.substring(0, hostname.indexOf("://")+3);
-        hostname = hostname.substring(hostname.indexOf("://")+3);
-      } else {
-        scheme = "http://";
-      }
-      if (!username.equals("")) {
-        if (!password.equals("")) {
-          username += ":" + password + "@";
-        } else {
-          username += "@";
-        }
-      }
-      url = scheme + username + hostname;
-      Log.i(TAG, url);
-      uri = new URI(url);
-    } catch (URISyntaxException e) {
-      Log.e(TAG, "Incorrect URI syntax " + e.getLocalizedMessage());
-      Toast.makeText(this, R.string.new_session_uri_error, Toast.LENGTH_LONG).show();
-    }
-    */return uri;
-  }
-  
-  private boolean isNameValid(String string) {
-    return string.matches("[A-Za-z0-9 _-]*");
-  }
-  
-  @Override
-  public void onBackPressed() {
-    setResult(Activity.RESULT_CANCELED);
-    super.onBackPressed();
-  }
-  
-}
index 59ea5fe..e4b118c 100644 (file)
@@ -1,5 +1,6 @@
 package eu.alefzero.owncloud.authenticator;
 
+import eu.alefzero.owncloud.ui.AuthenticatorActivity;
 import android.accounts.*;
 import android.content.Context;
 import android.content.Intent;
index c506886..e444824 100644 (file)
@@ -66,6 +66,8 @@ import org.apache.http.params.HttpParams;
 import org.apache.http.params.HttpProtocolParams;
 import org.apache.http.protocol.BasicHttpContext;
 
+import eu.alefzero.owncloud.ui.AuthenticatorActivity;
+
 
 import android.content.Context;
 import android.os.Handler;
diff --git a/src/eu/alefzero/owncloud/authenticator/AuthenticatorActivity.java b/src/eu/alefzero/owncloud/authenticator/AuthenticatorActivity.java
deleted file mode 100644 (file)
index f292b2c..0000000
+++ /dev/null
@@ -1,184 +0,0 @@
-/* ownCloud Android client application
- *   Copyright (C) 2011  Bartek Przybylski
- *
- *   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 3 of the License, 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 this program.  If not, see <http://www.gnu.org/licenses/>.
- *
- */
-
-package eu.alefzero.owncloud.authenticator;
-
-import java.net.MalformedURLException;
-import java.net.URL;
-
-import android.accounts.Account;
-import android.accounts.AccountAuthenticatorActivity;
-import android.accounts.AccountManager;
-import android.app.Dialog;
-import android.app.ProgressDialog;
-import android.content.ContentResolver;
-import android.content.DialogInterface;
-import android.content.Intent;
-import android.graphics.Color;
-import android.os.Bundle;
-import android.os.Handler;
-import android.util.Log;
-import android.view.View;
-import android.view.Window;
-import android.widget.TextView;
-import android.widget.Toast;
-import eu.alefzero.owncloud.R;
-import eu.alefzero.owncloud.db.ProviderMeta.ProviderTableMeta;
-
-public class AuthenticatorActivity extends AccountAuthenticatorActivity {
-    private Thread mAuthThread;
-    private final Handler mHandler = new Handler();
-
-    public static final String PARAM_USERNAME = "param_Username";
-    public static final String PARAM_HOSTNAME = "param_Hostname";
-
-    @Override
-    protected void onCreate(Bundle savedInstanceState) {
-        super.onCreate(savedInstanceState);
-        getWindow().requestFeature(Window.FEATURE_NO_TITLE);
-        setContentView(R.layout.account_setup);
-        if (getIntent().hasExtra(PARAM_USERNAME)) {
-            String username = getIntent().getStringExtra(PARAM_HOSTNAME);
-            TextView host_text, user_text;
-            host_text = (TextView) findViewById(R.id.host_URL);
-            user_text = (TextView) findViewById(R.id.account_username);
-            host_text.setText(host_text.getText() + username.substring(username.lastIndexOf('@')));
-            user_text.setText(user_text.getText() + username.substring(0, username.lastIndexOf('@') - 1));
-        }
-    }
-
-    @Override
-    protected Dialog onCreateDialog(int id) {
-        final ProgressDialog dialog = new ProgressDialog(this);
-        dialog.setMessage("Trying to login");
-        dialog.setIndeterminate(true);
-        dialog.setCancelable(true);
-        dialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
-            public void onCancel(DialogInterface dialog) {
-                Log.i(getClass().getName(), "Login canceled");
-                if (mAuthThread != null) {
-                    mAuthThread.interrupt();
-                    finish();
-                }
-            }
-        });
-        return dialog;
-    }
-
-    public void onAuthenticationResult(boolean result, String message) {
-        if (result) {
-            TextView username_text = (TextView) findViewById(R.id.account_username),
-                    password_text = (TextView) findViewById(R.id.account_password);
-
-            URL url;
-            try {
-                url = new URL(message);
-            } catch (MalformedURLException e) {
-                // should never happend
-                Log.e(getClass().getName(), "Malformed URL: " + message);
-                return;
-            }
-
-            String username = username_text.getText().toString().trim();
-            Account account = new Account(username + "@" + url.getHost(), AccountAuthenticator.ACCOUNT_TYPE);
-            AccountManager accManager = AccountManager.get(this);
-            accManager.addAccountExplicitly(account, password_text.getText().toString(), null);
-
-            final Intent intent = new Intent();
-            intent.putExtra(AccountManager.KEY_ACCOUNT_TYPE, AccountAuthenticator.ACCOUNT_TYPE);
-            intent.putExtra(AccountManager.KEY_ACCOUNT_NAME, account.name);
-            intent.putExtra(AccountManager.KEY_AUTHTOKEN, AccountAuthenticator.ACCOUNT_TYPE);
-            accManager.setUserData(account, AccountAuthenticator.KEY_OC_URL, url.toString());
-
-            // TODO prepare this URL during a central service
-            intent.putExtra(AccountManager.KEY_USERDATA, username);
-            accManager.setUserData(account, AccountAuthenticator.KEY_CONTACT_URL,
-                    url.toString().replace(AuthUtils.WEBDAV_PATH_2_0, AuthUtils.CARDDAV_PATH_2_0)
-            );
-
-            setAccountAuthenticatorResult(intent.getExtras());
-            setResult(RESULT_OK, intent);
-            Bundle bundle = new Bundle();
-            bundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);
-            getContentResolver().startSync(ProviderTableMeta.CONTENT_URI, bundle);
-
-            dismissDialog(0);
-            finish();
-        } else {
-            Toast.makeText(this, message, Toast.LENGTH_LONG).show();
-            dismissDialog(0);
-        }
-    }
-
-    public void onCancelClick(View view) {
-        Log.i(getClass().getName(), "Account creating canceled");
-        this.finish();
-    }
-
-    public void onOkClick(View view) {
-        TextView url_text = (TextView) findViewById(R.id.host_URL);
-        TextView username_text = (TextView) findViewById(R.id.account_username);
-        TextView password_text = (TextView) findViewById(R.id.account_password);
-        Log.i(getClass().getName(), "OK clicked");
-        boolean hasErrors = false;
-
-        URL uri = null;
-        if (url_text.getText().toString().trim().length() == 0) {
-            url_text.setTextColor(Color.RED);
-            hasErrors = true;
-        } else {
-            url_text.setTextColor(Color.BLACK);
-        }
-        try {
-            String url_str = url_text.getText().toString();
-            if (!url_str.startsWith("http://") &&
-                    !url_str.startsWith("https://")) {
-                url_str = "http://" + url_str;
-            }
-            uri = new URL(url_str);
-        } catch (MalformedURLException e) {
-            url_text.setTextColor(Color.RED);
-            e.printStackTrace();
-            hasErrors = true;
-        }
-
-        if (username_text.getText().toString().contains(" ") ||
-                username_text.getText().toString().trim().length() == 0) {
-            username_text.setTextColor(Color.RED);
-            hasErrors = true;
-        } else {
-            username_text.setTextColor(Color.BLACK);
-        }
-
-        if (password_text.getText().toString().trim().length() == 0) {
-            password_text.setTextColor(Color.RED);
-            hasErrors = true;
-        } else {
-            password_text.setTextColor(Color.BLACK);
-        }
-        if (hasErrors) {
-            return;
-        }
-        showDialog(0);
-        mAuthThread = AuthUtils.attemptAuth(uri,
-                username_text.getText().toString(),
-                password_text.getText().toString(),
-                mHandler,
-                AuthenticatorActivity.this);
-    }
-}
diff --git a/src/eu/alefzero/owncloud/ui/ActionBar.java b/src/eu/alefzero/owncloud/ui/ActionBar.java
deleted file mode 100644 (file)
index c3b13bc..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-package eu.alefzero.owncloud.ui;
-
-import eu.alefzero.owncloud.R;
-import android.app.Activity;
-import android.os.Bundle;
-import android.support.v4.app.Fragment;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.ViewGroup;
-
-public class ActionBar extends Fragment {
-
-  @Override
-  public void onCreate(Bundle savedInstanceState) {
-    super.onCreate(savedInstanceState);
-    
-  }
-  @Override
-  public View onCreateView(LayoutInflater inflater, ViewGroup container,
-      Bundle savedInstanceState) {
-    View v = inflater.inflate(R.layout.action_bar, container, false);
-    return v;
-  }
-  
-  @Override
-  public void onAttach(Activity activity) {
-    super.onAttach(activity);
-  }
-}
diff --git a/src/eu/alefzero/owncloud/ui/AuthenticatorActivity.java b/src/eu/alefzero/owncloud/ui/AuthenticatorActivity.java
new file mode 100644 (file)
index 0000000..a912160
--- /dev/null
@@ -0,0 +1,186 @@
+/* ownCloud Android client application
+ *   Copyright (C) 2011  Bartek Przybylski
+ *
+ *   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 3 of the License, 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 this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+package eu.alefzero.owncloud.ui;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import android.accounts.Account;
+import android.accounts.AccountAuthenticatorActivity;
+import android.accounts.AccountManager;
+import android.app.Dialog;
+import android.app.ProgressDialog;
+import android.content.ContentResolver;
+import android.content.DialogInterface;
+import android.content.Intent;
+import android.graphics.Color;
+import android.os.Bundle;
+import android.os.Handler;
+import android.util.Log;
+import android.view.View;
+import android.view.Window;
+import android.widget.TextView;
+import android.widget.Toast;
+import eu.alefzero.owncloud.R;
+import eu.alefzero.owncloud.authenticator.AccountAuthenticator;
+import eu.alefzero.owncloud.authenticator.AuthUtils;
+import eu.alefzero.owncloud.db.ProviderMeta.ProviderTableMeta;
+
+public class AuthenticatorActivity extends AccountAuthenticatorActivity {
+    private Thread mAuthThread;
+    private final Handler mHandler = new Handler();
+
+    public static final String PARAM_USERNAME = "param_Username";
+    public static final String PARAM_HOSTNAME = "param_Hostname";
+
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        getWindow().requestFeature(Window.FEATURE_NO_TITLE);
+        setContentView(R.layout.account_setup);
+        if (getIntent().hasExtra(PARAM_USERNAME)) {
+            String username = getIntent().getStringExtra(PARAM_HOSTNAME);
+            TextView host_text, user_text;
+            host_text = (TextView) findViewById(R.id.host_URL);
+            user_text = (TextView) findViewById(R.id.account_username);
+            host_text.setText(host_text.getText() + username.substring(username.lastIndexOf('@')));
+            user_text.setText(user_text.getText() + username.substring(0, username.lastIndexOf('@') - 1));
+        }
+    }
+
+    @Override
+    protected Dialog onCreateDialog(int id) {
+        final ProgressDialog dialog = new ProgressDialog(this);
+        dialog.setMessage("Trying to login");
+        dialog.setIndeterminate(true);
+        dialog.setCancelable(true);
+        dialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
+            public void onCancel(DialogInterface dialog) {
+                Log.i(getClass().getName(), "Login canceled");
+                if (mAuthThread != null) {
+                    mAuthThread.interrupt();
+                    finish();
+                }
+            }
+        });
+        return dialog;
+    }
+
+    public void onAuthenticationResult(boolean result, String message) {
+        if (result) {
+            TextView username_text = (TextView) findViewById(R.id.account_username),
+                    password_text = (TextView) findViewById(R.id.account_password);
+
+            URL url;
+            try {
+                url = new URL(message);
+            } catch (MalformedURLException e) {
+                // should never happend
+                Log.e(getClass().getName(), "Malformed URL: " + message);
+                return;
+            }
+
+            String username = username_text.getText().toString().trim();
+            Account account = new Account(username + "@" + url.getHost(), AccountAuthenticator.ACCOUNT_TYPE);
+            AccountManager accManager = AccountManager.get(this);
+            accManager.addAccountExplicitly(account, password_text.getText().toString(), null);
+
+            final Intent intent = new Intent();
+            intent.putExtra(AccountManager.KEY_ACCOUNT_TYPE, AccountAuthenticator.ACCOUNT_TYPE);
+            intent.putExtra(AccountManager.KEY_ACCOUNT_NAME, account.name);
+            intent.putExtra(AccountManager.KEY_AUTHTOKEN, AccountAuthenticator.ACCOUNT_TYPE);
+            accManager.setUserData(account, AccountAuthenticator.KEY_OC_URL, url.toString());
+
+            // TODO prepare this URL during a central service
+            intent.putExtra(AccountManager.KEY_USERDATA, username);
+            accManager.setUserData(account, AccountAuthenticator.KEY_CONTACT_URL,
+                    url.toString().replace(AuthUtils.WEBDAV_PATH_2_0, AuthUtils.CARDDAV_PATH_2_0)
+            );
+
+            setAccountAuthenticatorResult(intent.getExtras());
+            setResult(RESULT_OK, intent);
+            Bundle bundle = new Bundle();
+            bundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);
+            getContentResolver().startSync(ProviderTableMeta.CONTENT_URI, bundle);
+
+            dismissDialog(0);
+            finish();
+        } else {
+            Toast.makeText(this, message, Toast.LENGTH_LONG).show();
+            dismissDialog(0);
+        }
+    }
+
+    public void onCancelClick(View view) {
+        Log.i(getClass().getName(), "Account creating canceled");
+        this.finish();
+    }
+
+    public void onOkClick(View view) {
+        TextView url_text = (TextView) findViewById(R.id.host_URL);
+        TextView username_text = (TextView) findViewById(R.id.account_username);
+        TextView password_text = (TextView) findViewById(R.id.account_password);
+        Log.i(getClass().getName(), "OK clicked");
+        boolean hasErrors = false;
+
+        URL uri = null;
+        if (url_text.getText().toString().trim().length() == 0) {
+            url_text.setTextColor(Color.RED);
+            hasErrors = true;
+        } else {
+            url_text.setTextColor(Color.BLACK);
+        }
+        try {
+            String url_str = url_text.getText().toString();
+            if (!url_str.startsWith("http://") &&
+                    !url_str.startsWith("https://")) {
+                url_str = "http://" + url_str;
+            }
+            uri = new URL(url_str);
+        } catch (MalformedURLException e) {
+            url_text.setTextColor(Color.RED);
+            e.printStackTrace();
+            hasErrors = true;
+        }
+
+        if (username_text.getText().toString().contains(" ") ||
+                username_text.getText().toString().trim().length() == 0) {
+            username_text.setTextColor(Color.RED);
+            hasErrors = true;
+        } else {
+            username_text.setTextColor(Color.BLACK);
+        }
+
+        if (password_text.getText().toString().trim().length() == 0) {
+            password_text.setTextColor(Color.RED);
+            hasErrors = true;
+        } else {
+            password_text.setTextColor(Color.BLACK);
+        }
+        if (hasErrors) {
+            return;
+        }
+        showDialog(0);
+        mAuthThread = AuthUtils.attemptAuth(uri,
+                username_text.getText().toString(),
+                password_text.getText().toString(),
+                mHandler,
+                AuthenticatorActivity.this);
+    }
+}
diff --git a/src/eu/alefzero/owncloud/ui/FileDetailActivity.java b/src/eu/alefzero/owncloud/ui/FileDetailActivity.java
new file mode 100644 (file)
index 0000000..45026fa
--- /dev/null
@@ -0,0 +1,27 @@
+package eu.alefzero.owncloud.ui;
+
+import eu.alefzero.owncloud.FileDetail;
+import eu.alefzero.owncloud.R;
+import eu.alefzero.owncloud.R.id;
+import eu.alefzero.owncloud.R.layout;
+import android.app.Activity;
+import android.content.res.Configuration;
+import android.os.Bundle;
+import android.support.v4.app.FragmentActivity;
+import android.support.v4.app.FragmentTransaction;
+import android.view.Window;
+
+public class FileDetailActivity extends FragmentActivity {
+@Override
+protected void onCreate(Bundle savedInstanceState) {
+  // TODO Auto-generated method stub
+  super.onCreate(savedInstanceState);
+  getWindow().requestFeature(Window.FEATURE_NO_TITLE);
+  setContentView(R.layout.file_activity_details);
+  
+  FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
+  ft.add(R.id.fileDetail, new FileDetail());
+  ft.commit();
+  
+}
+}
diff --git a/src/eu/alefzero/owncloud/ui/FileDisplayActivity.java b/src/eu/alefzero/owncloud/ui/FileDisplayActivity.java
new file mode 100644 (file)
index 0000000..dd92393
--- /dev/null
@@ -0,0 +1,354 @@
+/* ownCloud Android client application
+ *   Copyright (C) 2011  Bartek Przybylski
+ *
+ *   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 3 of the License, 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 this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+package eu.alefzero.owncloud.ui;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.util.LinkedList;
+import java.util.Stack;
+
+import android.accounts.Account;
+import android.accounts.AccountManager;
+import android.app.AlertDialog;
+import android.app.Dialog;
+import android.app.ListActivity;
+import android.content.DialogInterface;
+import android.content.Intent;
+import android.content.DialogInterface.OnCancelListener;
+import android.content.res.Configuration;
+import android.database.Cursor;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import android.graphics.Matrix;
+import android.net.Uri;
+import android.os.Bundle;
+import android.os.Environment;
+import android.support.v4.app.FragmentActivity;
+import android.support.v4.app.FragmentTransaction;
+import android.text.TextUtils;
+import android.util.Log;
+import android.view.Menu;
+import android.view.MenuInflater;
+import android.view.MenuItem;
+import android.view.View;
+import android.view.Window;
+import android.widget.ImageView;
+import android.widget.ListView;
+import android.widget.TextView;
+import eu.alefzero.owncloud.DbHandler;
+import eu.alefzero.owncloud.FileDetail;
+import eu.alefzero.owncloud.R;
+import eu.alefzero.owncloud.R.id;
+import eu.alefzero.owncloud.R.layout;
+import eu.alefzero.owncloud.R.menu;
+import eu.alefzero.owncloud.R.string;
+import eu.alefzero.owncloud.authenticator.AccountAuthenticator;
+import eu.alefzero.owncloud.db.ProviderMeta.ProviderTableMeta;
+import eu.alefzero.owncloud.ui.fragment.FileList;
+
+public class FileDisplayActivity extends FragmentActivity {
+  private DbHandler mDBHandler;
+  private Stack<String> mParents;
+  private LinkedList<String> mPath;
+  private Account mAccount;
+  private Cursor mCursor;
+  private boolean mIsDisplayingFile;
+
+  private static final int DIALOG_CHOOSE_ACCOUNT = 0;
+
+  @Override
+  public void onCreate(Bundle savedInstanceState) {
+    super.onCreate(savedInstanceState);
+    getWindow().requestFeature(Window.FEATURE_NO_TITLE);
+    setContentView(R.layout.main);
+    
+    FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
+    ft.add(R.id.fileList, new FileList());
+    if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
+      ft.add(R.id.fileDetail, new FileDetail());
+    }
+    ft.commit();
+
+    /*getSupportFragmentManager().beginTransaction().add(arg0, arg1);
+    FileList fl = new FileList();
+    ft.add(R.id.fileList, fl);
+    ft.commit();
+    /*
+
+    
+    if (savedInstanceState != null) {
+      mParents = (Stack<String>)savedInstanceState.getSerializable("parentsStack");
+      mIsDisplayingFile = savedInstanceState.getBoolean("isDisplayingFile");
+      mPath = (LinkedList<String>)savedInstanceState.getSerializable("path");
+    } else {
+      mParents = new Stack<String>();
+      mPath = new LinkedList<String>();
+      mIsDisplayingFile = false;
+    }
+
+    mDBHandler = new DbHandler(getBaseContext());
+    requestWindowFeature(Window.FEATURE_NO_TITLE);
+    setContentView(R.layout.main);
+
+    AccountManager accMan = AccountManager.get(this);
+    Account[] accounts = accMan.getAccountsByType(AccountAuthenticator.ACCOUNT_TYPE);
+
+    if (accounts.length == 0) {
+      // using string value since in API7 this constatn is not defined
+      // in API7 < this constatant is defined in Settings.ADD_ACCOUNT_SETTINGS
+      // and Settings.EXTRA_AUTHORITIES
+      Intent intent = new Intent("android.settings.ADD_ACCOUNT_SETTINGS");
+      intent.putExtra("authorities", new String[] {AccountAuthenticator.AUTH_TOKEN_TYPE});
+      startActivity(intent);
+    } else if (accounts.length > 1) {
+      showDialog(DIALOG_CHOOSE_ACCOUNT);
+    } else {
+      mAccount = accounts[0];
+      populateFileList();
+    }*/
+  }
+
+  @Override
+  public boolean onOptionsItemSelected(MenuItem item) {
+    switch (item.getItemId()) {
+      case R.id.settingsItem :
+        Intent i = new Intent(this, Preferences.class);
+        startActivity(i);
+        break;
+    }
+    return true;
+  }
+
+  @Override
+  protected Dialog onCreateDialog(int id) {
+    switch (id) {
+      case DIALOG_CHOOSE_ACCOUNT:
+        return createChooseAccountDialog();
+      default:
+        throw new IllegalArgumentException("Unknown dialog id: " + id);
+    }
+  }
+  
+  @Override
+  public boolean onCreateOptionsMenu(Menu menu) {
+    MenuInflater inflater = getMenuInflater();
+    inflater.inflate(R.menu.menu, menu);
+    return true;
+  }
+    
+  private Dialog createChooseAccountDialog() {
+    final AccountManager accMan = AccountManager.get(this);
+    CharSequence[] items = new CharSequence[accMan.getAccountsByType(AccountAuthenticator.ACCOUNT_TYPE).length];
+    int i = 0;
+    for (Account a : accMan.getAccountsByType(AccountAuthenticator.ACCOUNT_TYPE)) {
+      items[i++] = a.name;
+    }
+    
+    AlertDialog.Builder builder = new AlertDialog.Builder(this);
+    builder.setTitle(R.string.common_choose_account);
+    builder.setCancelable(true);
+    builder.setItems(items, new DialogInterface.OnClickListener() {
+        public void onClick(DialogInterface dialog, int item) {
+            mAccount = accMan.getAccountsByType(AccountAuthenticator.ACCOUNT_TYPE)[item];
+            dialog.dismiss();
+            populateFileList();
+        }
+    });
+    builder.setOnCancelListener(new OnCancelListener() {
+      public void onCancel(DialogInterface dialog) {
+        FileDisplayActivity.this.finish();
+      }
+    });
+    AlertDialog alert = builder.create();
+    return alert;
+  }
+
+  //@Override
+  //public void onBackPressed() {
+    /*PathLayout pl = (PathLayout) findViewById(R.id.pathLayout1);
+    if (mIsDisplayingFile) {
+      mIsDisplayingFile = false;
+      setContentView(R.layout.main);
+      pl = (PathLayout) findViewById(R.id.pathLayout1);
+      Uri uri;
+      if (mParents.empty()) {
+        uri = ProviderTableMeta.CONTENT_URI;
+      } else {
+        uri = Uri.withAppendedPath(ProviderTableMeta.CONTENT_URI_DIR, mParents.peek());
+      }
+      mCursor = managedQuery(uri,
+                             null,
+                             ProviderTableMeta.FILE_ACCOUNT_OWNER+"=?",
+                             new String[]{mAccount.name}, null);
+  
+      if (mCursor.moveToFirst()) {
+        String s = mCursor.getString(mCursor.getColumnIndex(ProviderTableMeta.FILE_PATH));
+        for (String str : s.split("/")) {
+          if (!TextUtils.isEmpty(str))
+            pl.push(DisplayUtils.HtmlDecode(str));
+        }
+      }
+      getListView().setAdapter(new FileListListAdapter(mCursor, this));      
+      getListView().invalidate();
+      return;
+    }
+    if (mParents.size()==0) {
+      super.onBackPressed();
+      return;
+    } else if (mParents.size() == 1) {
+      mParents.pop();
+      mPath.removeLast();
+      pl.pop();
+      mCursor = managedQuery(ProviderTableMeta.CONTENT_URI,
+          null,
+          ProviderTableMeta.FILE_ACCOUNT_OWNER+"=?",
+          new String[]{mAccount.name},
+          null);
+    } else {
+      mParents.pop();
+      mPath.removeLast();
+      pl.pop();
+      mCursor = managedQuery(Uri.withAppendedPath(ProviderTableMeta.CONTENT_URI_DIR, mParents.peek()),
+          null,
+          ProviderTableMeta.FILE_ACCOUNT_OWNER+"=?",
+          new String[]{mAccount.name},
+          null);
+    }
+    
+    setListAdapter(new FileListListAdapter(mCursor, this));
+    getListView().invalidate();*/
+  //}
+
+  //@Override
+/*  protected void onListItemClick(ListView l, View v, int position, long id) {
+    super.onListItemClick(l, v, position, id);
+    /*PathLayout pl = (PathLayout) findViewById(R.id.pathLayout1);
+    if (!mCursor.moveToPosition(position)) {
+      throw new IndexOutOfBoundsException("Incorrect item selected");
+    }
+    if (!mIsDisplayingFile) {
+      if (mCursor.getString(mCursor.getColumnIndex(ProviderTableMeta.FILE_CONTENT_TYPE)).equals("DIR")) {
+        String id_ = mCursor.getString(mCursor.getColumnIndex(ProviderTableMeta._ID));
+        String dirname = mCursor.getString(mCursor.getColumnIndex(ProviderTableMeta.FILE_NAME));
+        pl.push(DisplayUtils.HtmlDecode(dirname));
+        mPath.addLast(DisplayUtils.HtmlDecode(dirname));
+        mParents.push(id_);
+        mCursor = managedQuery(Uri.withAppendedPath(ProviderTableMeta.CONTENT_URI_DIR, id_),
+                               null,
+                               ProviderTableMeta.FILE_ACCOUNT_OWNER + "=?",
+                               new String[]{mAccount.name}, null);
+        setListAdapter(new FileListListAdapter(mCursor, this));
+      } else {
+        mIsDisplayingFile = true;
+        setContentView(R.layout.file_display);
+        String id_ = mCursor.getString(mCursor.getColumnIndex(ProviderTableMeta._ID));
+        mCursor = managedQuery(Uri.withAppendedPath(ProviderTableMeta.CONTENT_URI_FILE, id_),
+                               null,
+                               null,
+                               null,
+                               null);
+        mCursor.moveToFirst();
+        // filename
+        TextView tv = (TextView) findViewById(R.id.textView1);
+        tv.setText(mCursor.getString(mCursor.getColumnIndex(ProviderTableMeta.FILE_NAME)));
+        // filetype
+        tv = (TextView) findViewById(R.id.textView2);
+        tv.setText(DisplayUtils.convertMIMEtoPrettyPrint(mCursor.getString(mCursor.getColumnIndex(ProviderTableMeta.FILE_CONTENT_TYPE))));
+        // size
+        tv = (TextView) findViewById(R.id.textView3);
+        tv.setText(DisplayUtils.bitsToHumanReadable(mCursor.getLong(mCursor.getColumnIndex(ProviderTableMeta.FILE_CONTENT_LENGTH))));
+        // modified
+        tv = (TextView) findViewById(R.id.textView4);
+        tv.setText(mCursor.getString(mCursor.getColumnIndex(ProviderTableMeta.FILE_MODIFIED)));
+        if (!TextUtils.isEmpty(mCursor.getString(mCursor.getColumnIndex(ProviderTableMeta.FILE_STORAGE_PATH))) &&
+            mCursor.getString(mCursor.getColumnIndex(ProviderTableMeta.FILE_CONTENT_TYPE)).matches("image/*")) {
+          ImageView iv = (ImageView) findViewById(R.id.imageView1);
+          Bitmap bmp = BitmapFactory.decodeFile(mCursor.getString(mCursor.getColumnIndex(ProviderTableMeta.FILE_STORAGE_PATH)));
+          Matrix m = new Matrix();
+          float scale;
+          if (bmp.getWidth() > bmp.getHeight()) {
+            scale = (float) (200./bmp.getWidth());
+          } else {
+            scale = (float) (200./bmp.getHeight());
+          }
+          m.postScale(scale, scale);
+          Bitmap newBmp = Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(), bmp.getHeight(), m, true);
+          iv.setImageBitmap(newBmp);
+        }
+        setListAdapter(new FileListActionListAdapter(mCursor, this, mAccount));
+      }    
+      getListView().invalidate();
+    } else {
+        Intent i = (Intent) getListAdapter().getItem(position);
+        if (i.hasExtra("toDownload")) {
+          
+          Intent intent = new Intent(this, FileDownloader.class);
+          intent.putExtra(FileDownloader.EXTRA_FILE_PATH, "/"+((TextView)findViewById(R.id.textView1)).getText().toString());
+          intent.putExtra(FileDownloader.EXTRA_ACCOUNT, mAccount);
+          startService(intent);
+          /*
+          if (i.getBooleanExtra("toDownload", false)) {
+            startActivityForResult(i, 200);
+          } else {
+            startActivity(i);            
+          }*/
+       // }
+
+    //}
+//  }
+  
+  private void populateFileList() {
+    if (mParents.empty()) {
+      mCursor = getContentResolver().query(ProviderTableMeta.CONTENT_URI,
+                                           null,
+                                           ProviderTableMeta.FILE_ACCOUNT_OWNER+"=?",
+                                           new String[]{mAccount.name},
+                                           null);
+    } else {
+      mCursor = getContentResolver().query(Uri.withAppendedPath(ProviderTableMeta.CONTENT_URI_DIR, mParents.peek()),
+                                           null,
+                                           ProviderTableMeta.FILE_ACCOUNT_OWNER + "=?",
+                                           new String[]{mAccount.name}, null);
+      if (!mIsDisplayingFile) {
+        //PathLayout pl = (PathLayout) findViewById(R.id.pathLayout1);
+        //for (String s : mPath) {
+        //  pl.push(s);
+       // }
+      }
+    }
+//    setListAdapter(new FileListListAdapter(mCursor, this));
+//    getListView().invalidate();
+  }
+  
+  //@Override
+  /*protected void onActivityResult(int requestCode, int resultCode, Intent data) {
+    super.onActivityResult(requestCode, resultCode, data);
+  }
+  
+  @Override
+  protected void onSaveInstanceState(Bundle outState) {
+    super.onSaveInstanceState(outState);
+    outState.putSerializable("parentsStack", mParents);
+    outState.putSerializable("path", mPath);
+    outState.putBoolean("isDisplayingFile", mIsDisplayingFile);
+  }*/
+
+}
\ No newline at end of file
diff --git a/src/eu/alefzero/owncloud/ui/Preferences.java b/src/eu/alefzero/owncloud/ui/Preferences.java
new file mode 100644 (file)
index 0000000..5dc260d
--- /dev/null
@@ -0,0 +1,146 @@
+package eu.alefzero.owncloud.ui;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.Vector;
+
+import eu.alefzero.owncloud.DbHandler;
+import eu.alefzero.owncloud.OwnCloudSession;
+import eu.alefzero.owncloud.R;
+import eu.alefzero.owncloud.R.id;
+import eu.alefzero.owncloud.R.menu;
+import eu.alefzero.owncloud.R.xml;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.os.Bundle;
+import android.preference.Preference;
+import android.preference.PreferenceActivity;
+import android.preference.PreferenceScreen;
+import android.util.Log;
+import android.view.ContextMenu;
+import android.view.Menu;
+import android.view.MenuInflater;
+import android.view.MenuItem;
+import android.view.View;
+import android.view.ContextMenu.ContextMenuInfo;
+import android.widget.AdapterView.AdapterContextMenuInfo;
+
+public class Preferences extends PreferenceActivity {
+  private String TAG = "OwnCloudPreferences";
+  private final int mNewSession = 47;
+  private final int mEditSession = 48;
+  private DbHandler mDbHandler;
+  private Vector<OwnCloudSession> mSessions;
+  private int mSelectedMenuItem;
+  
+  @Override
+  public void onCreate(Bundle savedInstanceState){
+    super.onCreate(savedInstanceState);
+    mDbHandler = new DbHandler(getBaseContext());
+    mSessions = new Vector<OwnCloudSession>();
+    addPreferencesFromResource(R.xml.preferences);
+    registerForContextMenu(getListView());
+    //populateSessionList();
+  }
+  
+  private void populateSessionList() {
+    mSessions.clear();
+    mSessions = mDbHandler.getSessionList();
+    PreferenceScreen ps = getPreferenceScreen();
+    ps.removeAll();
+    addPreferencesFromResource(R.xml.preferences);
+    for (int i = 0; i < mSessions.size(); i++) {
+      Preference preference = new Preference(getBaseContext());
+      preference.setTitle(mSessions.get(i).getName());
+      URI uri;
+      try {
+        uri = new URI(mSessions.get(i).getUrl());
+      } catch (URISyntaxException e) {
+        e.printStackTrace(); // should never happend
+        continue;
+      }
+      preference.setSummary(uri.getScheme() + "://" + uri.getHost()+uri.getPath());
+      ps.addPreference(preference);
+    }
+  }
+
+  @Override
+  public boolean onCreateOptionsMenu(Menu menu) {
+    super.onCreateOptionsMenu(menu);
+    MenuInflater inflater = getMenuInflater();
+    inflater.inflate(R.menu.prefs_menu, menu);
+    return true;
+  }
+  
+  @Override
+  public boolean onMenuItemSelected(int featureId, MenuItem item) {
+    super.onMenuItemSelected(featureId, item);
+    Intent intent;
+    
+    switch (item.getItemId()) {
+      case R.id.addSessionItem:
+        intent = new Intent(this, PreferencesNewSession.class);
+        startActivityForResult(intent, mNewSession);
+        break;
+      case R.id.SessionContextEdit:
+        intent = new Intent(this, PreferencesNewSession.class);
+        intent.putExtra("sessionId", mSessions.get(mSelectedMenuItem).getEntryId());
+        intent.putExtra("sessionName", mSessions.get(mSelectedMenuItem).getName());
+        intent.putExtra("sessionURL", mSessions.get(mSelectedMenuItem).getUrl());
+        startActivityForResult(intent, mEditSession);
+        break;
+      case R.id.SessionContextRemove:
+        OwnCloudSession ocs = mSessions.get(mSelectedMenuItem);
+        mDbHandler.removeSessionWithId(ocs.getEntryId());
+        mSessions.remove(ocs);
+        getPreferenceScreen().removePreference(getPreferenceScreen().getPreference(mSelectedMenuItem+1));
+        break;
+      default:
+        Log.w(TAG, "Unknown menu item triggered");
+        return false;
+    }
+    return true;
+  }
+
+  @Override
+  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
+    super.onActivityResult(requestCode, resultCode, data);
+    if (resultCode == Activity.RESULT_OK) {
+      switch (requestCode) {
+        case mNewSession:
+          mDbHandler.addSession(data.getStringExtra("sessionName"), 
+                                data.getStringExtra("sessionURL"));
+          getPreferenceScreen().removeAll();
+          addPreferencesFromResource(R.xml.preferences);
+          populateSessionList();
+          break;
+        case mEditSession:
+          mDbHandler.changeSessionFields(data.getIntExtra("sessionId", -1),
+                                         data.getStringExtra("sessionName"),
+                                         data.getStringExtra("sessionURL"));
+          populateSessionList();
+          break;
+      }
+    }
+  }
+
+  @Override
+  public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
+    super.onCreateContextMenu(menu, v, menuInfo);
+    AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
+    mSelectedMenuItem = info.position-1;
+    menu.setHeaderTitle(mSessions.get(mSelectedMenuItem).getName());
+    
+    MenuInflater inflater = getMenuInflater();
+    inflater.inflate(R.menu.session_context_menu, menu);
+    
+  }
+  
+  @Override
+  protected void onDestroy() {
+    mDbHandler.close();
+    super.onDestroy();
+  }
+  
+}
diff --git a/src/eu/alefzero/owncloud/ui/PreferencesNewSession.java b/src/eu/alefzero/owncloud/ui/PreferencesNewSession.java
new file mode 100644 (file)
index 0000000..9900abf
--- /dev/null
@@ -0,0 +1,143 @@
+package eu.alefzero.owncloud.ui;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import eu.alefzero.owncloud.authenticator.AccountAuthenticatorService;
+
+import android.accounts.Account;
+import android.accounts.AccountAuthenticatorActivity;
+import android.accounts.AccountManager;
+import android.app.Activity;
+import android.content.Intent;
+import android.os.Bundle;
+import android.util.Log;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.widget.Button;
+import android.widget.EditText;
+import android.widget.Toast;
+
+public class PreferencesNewSession extends AccountAuthenticatorActivity implements OnClickListener {
+  private Intent mReturnData;
+  private final String TAG = "OwnCloudPreferencesNewSession";
+  @Override
+  public void onCreate(Bundle savedInstanceState){
+    super.onCreate(savedInstanceState);
+    //setContentView(R.layout.add_new_session);
+    /*
+    EditText et;// = (EditText) findViewById(R.id.newSession_sessionName);
+    
+    et = (EditText) findViewById(R.id.newSession_URL);
+    if (getIntent().hasExtra("sessionURL")) {
+      try {
+        URI uri = new URI(getIntent().getStringExtra("sessionURL"));
+        String url = uri.getHost();
+        if (uri.getPort() != -1) {
+          url += ":" + String.valueOf(uri.getPort());
+        }
+        if (uri.getPath() != null) {
+          url += uri.getPath();
+        } else {
+          url += "/";
+        }
+        et.setText(url);
+        et = (EditText) findViewById(R.id.newSession_username);
+        if (uri.getAuthority() != null) {
+          if (uri.getUserInfo().indexOf(':') != -1) {
+            et.setText(uri.getUserInfo().substring(0, uri.getUserInfo().indexOf(':')));
+            et = (EditText) findViewById(R.id.newSession_password);
+            et.setText(uri.getUserInfo().substring(uri.getUserInfo().indexOf(':')+1));
+          } else {
+            et.setText(uri.getUserInfo());
+          }
+        }
+        
+      } catch (URISyntaxException e) {
+        Log.e(TAG, "Incorrect URI syntax " + e.getLocalizedMessage());
+      }
+    }
+    
+    mReturnData = new Intent();
+    setResult(Activity.RESULT_OK, mReturnData);
+    ((Button) findViewById(R.id.button1)).setOnClickListener(this);
+    ((Button) findViewById(R.id.button2)).setOnClickListener(this);*/
+  }
+  
+  @Override
+  protected void onResume() {
+    super.onResume();
+  }
+
+  public void onClick(View v) {
+   /* switch (v.getId()) {
+      case R.id.button1:
+        Intent intent = new Intent();
+        if (getIntent().hasExtra("sessionId")) {
+          intent.putExtra("sessionId", getIntent().getIntExtra("sessionId", -1));
+        }
+        //String sessionName = ((EditText) findViewById(R.id.newSession_sessionName)).getText().toString();
+      //  if (sessionName.trim().equals("") || !isNameValid(sessionName)) {
+     //    Toast.makeText(this, R.string.new_session_session_name_error, Toast.LENGTH_LONG).show();
+     //     break;
+       // }
+        URI uri = prepareURI();
+        if (uri != null) {
+          //intent.putExtra("sessionName", sessionName);
+          intent.putExtra("sessionURL", uri.toString());
+          setResult(Activity.RESULT_OK, intent);
+          AccountManager accMgr = AccountManager.get(this);
+          Account a = new Account("OwnCloud", AccountAuthenticatorService.ACCOUNT_TYPE);
+          accMgr.addAccountExplicitly(a, "asd", null);
+          finish();
+        }
+        break;
+      case R.id.button2:
+        setResult(Activity.RESULT_CANCELED);
+        finish();
+        break;
+    }*/
+  }
+  
+  private URI prepareURI() {
+    URI uri = null;
+   /* String url = "";
+    try {
+      String username = ((EditText) findViewById(R.id.newSession_username)).getText().toString().trim();
+      String password = ((EditText) findViewById(R.id.newSession_password)).getText().toString().trim();
+      String hostname = ((EditText) findViewById(R.id.newSession_URL)).getText().toString().trim();
+      String scheme;
+      if (hostname.matches("[A-Za-z]://")) {
+        scheme = hostname.substring(0, hostname.indexOf("://")+3);
+        hostname = hostname.substring(hostname.indexOf("://")+3);
+      } else {
+        scheme = "http://";
+      }
+      if (!username.equals("")) {
+        if (!password.equals("")) {
+          username += ":" + password + "@";
+        } else {
+          username += "@";
+        }
+      }
+      url = scheme + username + hostname;
+      Log.i(TAG, url);
+      uri = new URI(url);
+    } catch (URISyntaxException e) {
+      Log.e(TAG, "Incorrect URI syntax " + e.getLocalizedMessage());
+      Toast.makeText(this, R.string.new_session_uri_error, Toast.LENGTH_LONG).show();
+    }
+    */return uri;
+  }
+  
+  private boolean isNameValid(String string) {
+    return string.matches("[A-Za-z0-9 _-]*");
+  }
+  
+  @Override
+  public void onBackPressed() {
+    setResult(Activity.RESULT_CANCELED);
+    super.onBackPressed();
+  }
+  
+}
diff --git a/src/eu/alefzero/owncloud/ui/adapter/FileListActionListAdapter.java b/src/eu/alefzero/owncloud/ui/adapter/FileListActionListAdapter.java
new file mode 100644 (file)
index 0000000..5747a7b
--- /dev/null
@@ -0,0 +1,166 @@
+/* ownCloud Android client application
+ *   Copyright (C) 2011  Bartek Przybylski
+ *
+ *   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 3 of the License, 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 this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+package eu.alefzero.owncloud.ui.adapter;
+
+import java.io.File;
+
+import eu.alefzero.owncloud.R;
+import eu.alefzero.owncloud.R.drawable;
+import eu.alefzero.owncloud.R.id;
+import eu.alefzero.owncloud.R.layout;
+import eu.alefzero.owncloud.authenticator.AccountAuthenticator;
+import eu.alefzero.owncloud.db.ProviderMeta.ProviderTableMeta;
+import android.accounts.Account;
+import android.accounts.AccountManager;
+import android.content.Context;
+import android.content.Intent;
+import android.database.Cursor;
+import android.database.DataSetObserver;
+import android.net.Uri;
+import android.text.TextUtils;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ImageView;
+import android.widget.ListAdapter;
+import android.widget.TextView;
+
+public class FileListActionListAdapter implements ListAdapter {
+
+  private Context mContext;
+  private Account mAccount;
+  private String mFilename, mFileType, mFilePath, mFileStoragePath, mItemId;
+  
+  private final int ITEM_DOWNLOAD = 0;
+  private final int ITEM_SHARE = 1;
+  
+  public FileListActionListAdapter(Cursor c, Context co, Account account) {
+    mContext = co;
+    mFilename = c.getString(c.getColumnIndex(ProviderTableMeta.FILE_NAME));
+    mFileType = c.getString(c.getColumnIndex(ProviderTableMeta.FILE_CONTENT_TYPE));
+    mFilePath = c.getString(c.getColumnIndex(ProviderTableMeta.FILE_PATH));
+    mFileStoragePath = c.getString(c.getColumnIndex(ProviderTableMeta.FILE_STORAGE_PATH));
+    mItemId = c.getString(c.getColumnIndex(ProviderTableMeta._ID));
+    mAccount = account;
+  }
+  
+  public boolean areAllItemsEnabled() {
+    // TODO Auto-generated method stub
+    return true;
+  }
+
+  public boolean isEnabled(int position) {
+    // TODO Auto-generated method stub
+    return true;
+  }
+
+  public int getCount() {
+    // TODO Auto-generated method stub
+    return 1;
+  }
+
+  public Object getItem(int position) {
+    if (position == 0) {
+      Intent intent = new Intent(Intent.ACTION_VIEW);
+      if (TextUtils.isEmpty(mFileStoragePath)) {
+        intent.putExtra("toDownload", true);
+        AccountManager accm = (AccountManager) mContext.getSystemService(Context.ACCOUNT_SERVICE);
+        String ocurl = accm.getUserData(mAccount, AccountAuthenticator.KEY_OC_URL);
+        ocurl += mFilePath + mFilename;
+        intent.setData(Uri.parse(ocurl));
+      } else {
+        intent.putExtra("toDownload", false);
+        intent.setDataAndType(Uri.fromFile(new File(mFileStoragePath)), mFileType);
+      }
+      return intent;
+    }
+    return null;
+  }
+
+  public long getItemId(int position) {
+    // TODO Auto-generated method stub
+    return 0;
+  }
+
+  public int getItemViewType(int position) {
+    // TODO Auto-generated method stub
+    return 0;
+  }
+
+  public View getView(int position, View convertView, ViewGroup parent) {
+    View v = convertView;
+    if (v == null) {
+      LayoutInflater vi = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+      v = vi.inflate(R.layout.file_display_action_list_element, null);
+    }
+
+    TextView tv;
+    ImageView iv;
+    switch (position) {
+      case ITEM_DOWNLOAD :
+        tv = (TextView) v.findViewById(R.id.textView1);
+        if (mFileStoragePath == null) {
+          tv.setText("Download");
+        } else {
+          setActionName(tv);
+        }
+        iv = (ImageView) v.findViewById(R.id.imageView1);
+        iv.setImageResource(R.drawable.download);
+        break;
+    }
+    
+    return v;
+  }
+
+  public int getViewTypeCount() {
+    // TODO Auto-generated method stub
+    return 2;
+  }
+
+  public boolean hasStableIds() {
+    // TODO Auto-generated method stub
+    return false;
+  }
+
+  public boolean isEmpty() {
+    // TODO Auto-generated method stub
+    return false;
+  }
+
+  public void registerDataSetObserver(DataSetObserver observer) {
+    // TODO Auto-generated method stub
+    
+  }
+
+  public void unregisterDataSetObserver(DataSetObserver observer) {
+    // TODO Auto-generated method stub
+    
+  }
+
+  private void setActionName(TextView tv) {
+    if (mFileType.matches("image/.*")) {
+      tv.setText("View");
+    } else if (mFileType.matches("audio/.*") || mFileType.matches("video/.*")) {
+      tv.setText("Play");
+    } else {
+      tv.setText("Open");
+    }
+  }
+  
+}
diff --git a/src/eu/alefzero/owncloud/ui/adapter/FileListListAdapter.java b/src/eu/alefzero/owncloud/ui/adapter/FileListListAdapter.java
new file mode 100644 (file)
index 0000000..02f1db2
--- /dev/null
@@ -0,0 +1,108 @@
+package eu.alefzero.owncloud.ui.adapter;
+
+import java.security.Provider;
+
+import eu.alefzero.owncloud.DisplayUtils;
+import eu.alefzero.owncloud.R;
+import eu.alefzero.owncloud.R.drawable;
+import eu.alefzero.owncloud.R.id;
+import eu.alefzero.owncloud.R.layout;
+import eu.alefzero.owncloud.db.ProviderMeta;
+import eu.alefzero.owncloud.db.ProviderMeta.ProviderTableMeta;
+
+import android.content.Context;
+import android.database.Cursor;
+import android.database.DataSetObserver;
+import android.util.Log;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.view.View.OnLongClickListener;
+import android.widget.AdapterView;
+import android.widget.ImageView;
+import android.widget.ListAdapter;
+import android.widget.TextView;
+import android.widget.AdapterView.OnItemClickListener;
+
+public class FileListListAdapter implements ListAdapter {
+
+  private Cursor mCursor;
+  private Context mContext;
+  
+  public FileListListAdapter(Cursor c, Context context) {
+    mCursor = c;
+    mContext = context;
+  }
+  
+  public boolean areAllItemsEnabled() {
+    return true;
+  }
+
+  public boolean isEnabled(int position) {
+    // TODO Auto-generated method stub
+    return true;
+  }
+
+  public int getCount() {
+    // TODO Auto-generated method stub
+    return mCursor.getCount();
+  }
+
+  public Object getItem(int position) {
+    // TODO Auto-generated method stub
+    return null;
+  }
+
+  public long getItemId(int position) {
+    // TODO Auto-generated method stub
+    return 0;
+  }
+
+  public int getItemViewType(int position) {
+    // TODO Auto-generated method stub
+    return 0;
+  }
+
+  public View getView(int position, View convertView, ViewGroup parent) {
+    View v = convertView;
+    if (v == null) {
+      LayoutInflater vi = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+      v = vi.inflate(R.layout.list_layout, null);
+    }
+    if (mCursor.moveToPosition(position)) {
+      TextView tv = (TextView) v.findViewById(R.id.Filename);
+      tv.setText(DisplayUtils.HtmlDecode(mCursor.getString(mCursor.getColumnIndex(ProviderMeta.ProviderTableMeta.FILE_NAME))));
+      if (!mCursor.getString(mCursor.getColumnIndex(ProviderTableMeta.FILE_CONTENT_TYPE)).equals("DIR")) {
+        ImageView iv = (ImageView) v.findViewById(R.id.imageView1);
+        iv.setImageResource(R.drawable.file);
+      }
+    }
+    
+    return v;
+  }
+
+  public int getViewTypeCount() {
+    // TODO Auto-generated method stub
+    return 4;
+  }
+
+  public boolean hasStableIds() {
+    // TODO Auto-generated method stub
+    return true;
+  }
+
+  public boolean isEmpty() {
+    // TODO Auto-generated method stub
+    return false;
+  }
+
+  public void registerDataSetObserver(DataSetObserver observer) {
+    // TODO Auto-generated method stub
+    
+  }
+
+  public void unregisterDataSetObserver(DataSetObserver observer) {
+    // TODO Auto-generated method stub
+    
+  }
+}
diff --git a/src/eu/alefzero/owncloud/ui/fragment/ActionBar.java b/src/eu/alefzero/owncloud/ui/fragment/ActionBar.java
new file mode 100644 (file)
index 0000000..95ddef8
--- /dev/null
@@ -0,0 +1,29 @@
+package eu.alefzero.owncloud.ui.fragment;
+
+import eu.alefzero.owncloud.R;
+import android.app.Activity;
+import android.os.Bundle;
+import android.support.v4.app.Fragment;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+
+public class ActionBar extends Fragment {
+
+  @Override
+  public void onCreate(Bundle savedInstanceState) {
+    super.onCreate(savedInstanceState);
+    
+  }
+  @Override
+  public View onCreateView(LayoutInflater inflater, ViewGroup container,
+      Bundle savedInstanceState) {
+    View v = inflater.inflate(R.layout.action_bar, container, false);
+    return v;
+  }
+  
+  @Override
+  public void onAttach(Activity activity) {
+    super.onAttach(activity);
+  }
+}
diff --git a/src/eu/alefzero/owncloud/ui/fragment/FileList.java b/src/eu/alefzero/owncloud/ui/fragment/FileList.java
new file mode 100644 (file)
index 0000000..a3e3a99
--- /dev/null
@@ -0,0 +1,70 @@
+package eu.alefzero.owncloud.ui.fragment;
+
+import eu.alefzero.owncloud.FileDetail;
+import eu.alefzero.owncloud.R;
+import eu.alefzero.owncloud.R.id;
+import eu.alefzero.owncloud.authenticator.AccountAuthenticator;
+import eu.alefzero.owncloud.db.ProviderMeta.ProviderTableMeta;
+import eu.alefzero.owncloud.ui.FileDetailActivity;
+import eu.alefzero.owncloud.ui.adapter.FileListListAdapter;
+import android.accounts.Account;
+import android.accounts.AccountManager;
+import android.app.Activity;
+import android.app.Service;
+import android.content.Intent;
+import android.database.Cursor;
+import android.os.Bundle;
+import android.support.v4.app.FragmentTransaction;
+import android.support.v4.app.ListFragment;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ArrayAdapter;
+import android.widget.ListView;
+import android.widget.TextView;
+import android.widget.Toast;
+
+public class FileList extends ListFragment {
+  private Cursor mCursor;
+  private Account mAccount;
+  private AccountManager mAccountManager;
+  
+  @Override
+  public void onCreate(Bundle savedInstanceState) {
+    // TODO Auto-generated method stub
+    super.onCreate(savedInstanceState);
+    
+    mAccountManager = (AccountManager)getActivity().getSystemService(Service.ACCOUNT_SERVICE);
+    mAccount = mAccountManager.getAccountsByType(AccountAuthenticator.ACCOUNT_TYPE)[0];
+    populateFileList();
+  }
+  
+  @Override
+  public void onActivityCreated(Bundle savedInstanceState) {
+    // TODO Auto-generated method stub
+    super.onActivityCreated(savedInstanceState);
+  }
+  @Override
+  public void onListItemClick(ListView l, View v, int position, long id) {
+    // TODO Auto-generated method stub
+    FileDetail fd = (FileDetail) getFragmentManager().findFragmentById(R.id.fileDetail);
+    if (fd != null) {
+      fd.use(((TextView)v.findViewById(R.id.Filename)).getText());
+    } else {
+      Intent i = new Intent(getActivity(), FileDetailActivity.class);
+      startActivity(i);
+    }
+    super.onListItemClick(l, v, position, id);
+  }
+  
+  private void populateFileList() {
+    mCursor = getActivity().getContentResolver().query(ProviderTableMeta.CONTENT_URI,
+        null,
+        ProviderTableMeta.FILE_ACCOUNT_OWNER+"=?",
+        new String[]{mAccount.name},
+        null);
+    
+    setListAdapter(new FileListListAdapter(mCursor, getActivity()));
+  }
+}