some file list handling, action bar added

This commit is contained in:
Bartek Przybylski 2012-02-11 23:11:57 +01:00
parent 7d93f30346
commit 6deca0f9b1
7 changed files with 136 additions and 41 deletions

View file

@ -25,7 +25,7 @@
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".ui.activity.FileDisplayActivity"></activity>
<activity android:name=".ui.activity.FileDisplayActivity" android:theme="@style/Theme.ownCloud" android:label="@string/app_name"></activity>
<activity android:name=".Uploader">
<intent-filter>
<action android:name="android.intent.action.SEND"></action>

View file

@ -5,14 +5,6 @@
android:background="#F7F7F7"
android:orientation="vertical" >
<fragment
android:id="@+id/actionBar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
class="eu.alefzero.owncloud.ui.fragment.ActionBar">
<!-- Preview: layout=@layout/action_bar -->
</fragment>
<fragment
android:id="@+id/fileList"
android:layout_width="fill_parent"

View file

@ -11,14 +11,6 @@
android:layout_height="fill_parent"
android:orientation="vertical" >
<fragment
android:id="@+id/actionBar"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
class="eu.alefzero.owncloud.ui.fragment.ActionBar">
<!-- Preview: layout=@layout/action_bar -->
</fragment>
<LinearLayout
android:id="@+id/linearLayout2"
android:layout_width="fill_parent"

View file

@ -13,7 +13,6 @@
</style>
<!-- PopDownMenu -->
<style name="Animations.PopDownMenu" />

View file

@ -0,0 +1,38 @@
package eu.alefzero.owncloud.ui;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;
public class FragmentListView extends Fragment implements OnItemClickListener {
ListView mList;
@Override
public void onCreate(Bundle savedInstanceState) {
mList = new ListView(getActivity());
mList.setOnItemClickListener(this);
super.onCreate(savedInstanceState);
}
public void setListAdapter(ListAdapter listAdapter) {
mList.setAdapter(listAdapter);
mList.invalidate();
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return mList;
//return super.onCreateView(inflater, container, savedInstanceState);
}
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {}
}

View file

@ -30,14 +30,17 @@ import android.accounts.AccountManager;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.ListActivity;
import android.app.ActionBar.OnNavigationListener;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.DialogInterface.OnCancelListener;
import android.content.res.Configuration;
import android.database.Cursor;
import android.database.DataSetObserver;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
@ -49,9 +52,13 @@ import android.text.TextUtils;
import android.util.Log;
import android.view.MenuInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.Spinner;
import android.widget.SpinnerAdapter;
import android.widget.TextView;
import eu.alefzero.owncloud.R;
import eu.alefzero.owncloud.R.id;
@ -70,25 +77,42 @@ import eu.alefzero.owncloud.ui.fragment.ActionBar;
* @author Bartek Przybylski
*
*/
public class FileDisplayActivity extends FragmentActivity {
public class FileDisplayActivity extends android.support.v4.app.FragmentActivity implements OnNavigationListener {
private DbHandler mDBHandler;
private Stack<String> mParents;
private LinkedList<String> mPath;
private Account mAccount;
private Cursor mCursor;
private boolean mIsDisplayingFile;
private ArrayAdapter<String> mDirectories;
private FileList mFileList;
private static final int DIALOG_CHOOSE_ACCOUNT = 0;
public void pushPath(String path) {
mDirectories.insert(path, 0);
}
public boolean popPath() {
mDirectories.remove(mDirectories.getItem(0));
Log.d("TAG", ""+getActionBar().getCustomView());
return !mDirectories.isEmpty();
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().requestFeature(Window.FEATURE_NO_TITLE);
mDirectories = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item);
mDirectories.add("/");
mFileList = new FileList();
setContentView(R.layout.files);
getActionBar().setNavigationMode(android.support.v4.app.ActionBar.NAVIGATION_MODE_LIST);
getActionBar().setDisplayShowTitleEnabled(false);
getActionBar().setListNavigationCallbacks(mDirectories, this);
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
//ft.add(R.id.actionBar, new ActionBar());
ft.add(R.id.fileList, new FileList());
ft.add(R.id.fileList, mFileList);
if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
ft.add(R.id.fileDetail, new FileDetail());
}
@ -345,6 +369,25 @@ public class FileDisplayActivity extends FragmentActivity {
// getListView().invalidate();
}
@Override
public boolean onNavigationItemSelected(int itemPosition, long itemId) {
int i = itemPosition;
while (i-- != 0) {
popPath();
mFileList.onBackPressed();
}
return true;
}
@Override
public void onBackPressed() {
popPath();
if (mDirectories.isEmpty()) {
super.onBackPressed();
}
mFileList.onBackPressed();
}
//@Override
/*protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);

View file

@ -17,11 +17,17 @@
*/
package eu.alefzero.owncloud.ui.fragment;
import java.util.ListIterator;
import java.util.Stack;
import eu.alefzero.owncloud.DisplayUtils;
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.FragmentListView;
import eu.alefzero.owncloud.ui.activity.FileDetailActivity;
import eu.alefzero.owncloud.ui.activity.FileDisplayActivity;
import eu.alefzero.owncloud.ui.adapter.FileListListAdapter;
import eu.alefzero.owncloud.ui.fragment.ActionBar;
import android.accounts.Account;
@ -33,32 +39,39 @@ import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.app.Fragment;
import android.support.v4.app.ListFragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;
/**
* A Fragment that lists all files and folders in a given path.
* @author Bartek Przybylski
*
*/
public class FileList extends ListFragment {
public class FileList extends FragmentListView {
private Cursor mCursor;
private Account mAccount;
private AccountManager mAccountManager;
private View mheaderView;
private Stack<String> mParentsIds;
private Stack<String> mDirNames;
@Override
public void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
mParentsIds = new Stack<String>();
mDirNames = new Stack<String>();
mAccountManager = (AccountManager)getActivity().getSystemService(Service.ACCOUNT_SERVICE);
mAccount = mAccountManager.getAccountsByType(AccountAuthenticator.ACCOUNT_TYPE)[0];
populateFileList();
@ -71,41 +84,39 @@ public class FileList extends ListFragment {
}
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
public void onItemClick(AdapterView<?> l, View v, int position, long id) {
FileDetail fd = (FileDetail) getFragmentManager().findFragmentById(R.id.fileDetail);
ActionBar ab = (ActionBar) getFragmentManager().findFragmentById(R.id.actionBar);
if (!mCursor.moveToPosition(position)) {
throw new IndexOutOfBoundsException("Incorrect item selected");
}
if (mCursor.getString(mCursor.getColumnIndex(ProviderTableMeta.FILE_CONTENT_TYPE)).equals("DIR")) {
String id_ = mCursor.getString(mCursor.getColumnIndex(ProviderTableMeta._ID));
mParentsIds.push(id_);
String dirname = mCursor.getString(mCursor.getColumnIndex(ProviderTableMeta.FILE_NAME));
//ab..push(DisplayUtils.HtmlDecode(dirname));
//mPath.addLast(DisplayUtils.HtmlDecode(dirname));
//mParents.push(id_);
mDirNames.push(dirname);
((FileDisplayActivity)getActivity()).pushPath(DisplayUtils.HtmlDecode(dirname));
mCursor = getActivity().managedQuery(Uri.withAppendedPath(ProviderTableMeta.CONTENT_URI_DIR, id_),
null,
ProviderTableMeta.FILE_ACCOUNT_OWNER + "=?",
new String[]{mAccount.name}, null);
setListAdapter(new FileListListAdapter(mCursor, getActivity()));
setListShown(false);
setListShown(true);
super.onListItemClick(l, v, position, id);
//super.onListItemClick(l, v, position, id);
return;
}
Intent i = new Intent(getActivity(), FileDetailActivity.class);
i.putExtra("FILE_PATH", ab.getCurrentPath());
i.putExtra("FILE_NAME", ((TextView)v.findViewById(R.id.Filename)).getText());
if (fd != null) {
fd.setStuff(i);
//fd.use(((TextView)v.findViewById(R.id.Filename)).getText());
} else {
i.putExtra("FILE_PATH", ab.getCurrentPath());
i.putExtra("FILE_NAME", ((TextView)v.findViewById(R.id.Filename)).getText());
startActivity(i);
}
super.onListItemClick(l, v, position, id);
FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.replace(R.id.fileList, this);
ft.commitAllowingStateLoss();
//super.onListItemClick(l, v, position, id);
}
@ -124,4 +135,24 @@ public class FileList extends ListFragment {
setListAdapter(new FileListListAdapter(mCursor, getActivity()));
}
public void onBackPressed() {
if (!mParentsIds.empty()) {
mParentsIds.pop();
mDirNames.pop();
}
if (!mParentsIds.empty()) {
String id_ = mParentsIds.peek();
String dirname = mDirNames.peek();
mCursor = getActivity().managedQuery(Uri.withAppendedPath(ProviderTableMeta.CONTENT_URI_DIR, id_),
null,
ProviderTableMeta.FILE_ACCOUNT_OWNER + "=?",
new String[]{mAccount.name}, null);
setListAdapter(new FileListListAdapter(mCursor, getActivity()));
} else {
populateFileList();
}
}
}