1 /* ownCloud Android client application
2 * Copyright (C) 2011 Bartek Przybylski
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 package eu
.alefzero
.owncloud
.ui
.activity
;
21 import android
.accounts
.Account
;
22 import android
.accounts
.AccountManager
;
23 import android
.app
.AlertDialog
;
24 import android
.app
.Dialog
;
25 import android
.content
.DialogInterface
;
26 import android
.content
.Intent
;
27 import android
.content
.DialogInterface
.OnCancelListener
;
28 import android
.content
.res
.Configuration
;
29 import android
.os
.Bundle
;
30 import android
.support
.v4
.app
.ActionBar
;
31 import android
.support
.v4
.app
.FragmentTransaction
;
32 import android
.support
.v4
.app
.ActionBar
.OnNavigationListener
;
33 import android
.support
.v4
.view
.Menu
;
34 import android
.support
.v4
.view
.MenuItem
;
35 import android
.view
.MenuInflater
;
36 import android
.widget
.ArrayAdapter
;
37 import eu
.alefzero
.owncloud
.R
;
38 import eu
.alefzero
.owncloud
.R
.id
;
39 import eu
.alefzero
.owncloud
.authenticator
.AccountAuthenticator
;
40 import eu
.alefzero
.owncloud
.ui
.fragment
.FileDetail
;
41 import eu
.alefzero
.owncloud
.ui
.fragment
.FileList
;
44 * Displays, what files the user has available in his ownCloud.
45 * @author Bartek Przybylski
49 public class FileDisplayActivity
extends android
.support
.v4
.app
.FragmentActivity
implements OnNavigationListener
{
50 private ArrayAdapter
<String
> mDirectories
;
52 private static final int DIALOG_CHOOSE_ACCOUNT
= 0;
54 public void pushPath(String path
) {
55 mDirectories
.insert(path
, 0);
58 public boolean popPath() {
59 mDirectories
.remove(mDirectories
.getItem(0));
60 return !mDirectories
.isEmpty();
64 public void onCreate(Bundle savedInstanceState
) {
65 super.onCreate(savedInstanceState
);
66 mDirectories
= new ArrayAdapter
<String
>(this, android
.R
.layout
.simple_spinner_dropdown_item
);
67 mDirectories
.add("/");
68 setContentView(R
.layout
.files
);
69 ActionBar action_bar
= getSupportActionBar();
70 action_bar
.setNavigationMode(android
.support
.v4
.app
.ActionBar
.NAVIGATION_MODE_LIST
);
71 action_bar
.setDisplayShowTitleEnabled(false
);
72 action_bar
.setListNavigationCallbacks(mDirectories
, this);
74 FragmentTransaction ft
= getSupportFragmentManager().beginTransaction();
75 ft
.add(R
.id
.file_list_container
, new FileList());
76 if (getResources().getConfiguration().orientation
== Configuration
.ORIENTATION_LANDSCAPE
) {
77 ft
.add(R
.id
.fileDetail
, new FileDetail());
83 public boolean onOptionsItemSelected(MenuItem item
) {
84 switch (item
.getItemId()) {
85 case R
.id
.settingsItem
:
86 Intent i
= new Intent(this, Preferences
.class);
94 protected Dialog
onCreateDialog(int id
) {
96 case DIALOG_CHOOSE_ACCOUNT
:
97 return createChooseAccountDialog();
99 throw new IllegalArgumentException("Unknown dialog id: " + id
);
104 public boolean onCreateOptionsMenu(Menu menu
) {
105 MenuInflater inflater
= getMenuInflater();
106 inflater
.inflate(R
.menu
.menu
, menu
);
110 private Dialog
createChooseAccountDialog() {
111 final AccountManager accMan
= AccountManager
.get(this);
112 CharSequence
[] items
= new CharSequence
[accMan
.getAccountsByType(AccountAuthenticator
.ACCOUNT_TYPE
).length
];
114 for (Account a
: accMan
.getAccountsByType(AccountAuthenticator
.ACCOUNT_TYPE
)) {
118 AlertDialog
.Builder builder
= new AlertDialog
.Builder(this);
119 builder
.setTitle(R
.string
.common_choose_account
);
120 builder
.setCancelable(true
);
121 builder
.setItems(items
, new DialogInterface
.OnClickListener() {
122 public void onClick(DialogInterface dialog
, int item
) {
123 //mAccount = accMan.getAccountsByType(AccountAuthenticator.ACCOUNT_TYPE)[item];
127 builder
.setOnCancelListener(new OnCancelListener() {
128 public void onCancel(DialogInterface dialog
) {
129 FileDisplayActivity
.this.finish();
132 AlertDialog alert
= builder
.create();
137 public boolean onNavigationItemSelected(int itemPosition
, long itemId
) {
138 int i
= itemPosition
;
146 public void onBackPressed() {
148 if (mDirectories
.getCount() == 0)
150 super.onBackPressed();
153 ((FileList
)getSupportFragmentManager().findFragmentById(id
.file_list_container
)).onBackPressed();