\r
package eu.alefzero.owncloud.ui.activity;\r
\r
+import java.io.BufferedReader;\r
import java.io.File;\r
+import java.io.InputStreamReader;\r
+import java.lang.Thread.UncaughtExceptionHandler;\r
import java.net.URLEncoder;\r
import java.util.ArrayList;\r
\r
import android.net.Uri;\r
import android.os.Bundle;\r
import android.provider.MediaStore;\r
+import android.telephony.TelephonyManager;\r
import android.util.Log;\r
import android.view.View;\r
import android.view.ViewGroup;\r
import com.actionbarsherlock.view.Window;\r
\r
import eu.alefzero.owncloud.AccountUtils;\r
+import eu.alefzero.owncloud.CrashHandler;\r
import eu.alefzero.owncloud.R;\r
import eu.alefzero.owncloud.authenticator.AccountAuthenticator;\r
import eu.alefzero.owncloud.datamodel.DataStorageManager;\r
private String[] mDirs = null;\r
\r
private SyncBroadcastReceiver syncBroadcastRevceiver;\r
-\r
+ \r
+ private View mLayoutView = null;\r
+ \r
private static final String KEY_DIR_ARRAY = "DIR_ARRAY";\r
private static final String KEY_CURRENT_DIR = "DIR";\r
\r
\r
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);\r
setProgressBarIndeterminateVisibility(false);\r
- \r
+\r
+ Thread.setDefaultUncaughtExceptionHandler(new CrashHandler(getApplicationContext()));\r
+\r
if(savedInstanceState != null){\r
mCurrentDir = (OCFile) savedInstanceState.getParcelable(KEY_CURRENT_DIR);\r
}\r
+ \r
+ if (findViewById(R.id.file_list_view) == null) \r
+ mLayoutView = getLayoutInflater().inflate(R.layout.files, null); // always inflate this at onCreate() ; just once!\r
+ \r
+ //TODO: Dialog useless -> get rid of this\r
+ if (!accountsAreSetup()) {\r
+ setContentView(R.layout.no_account_available);\r
+ setProgressBarIndeterminateVisibility(false);\r
+ getSupportActionBar().setNavigationMode(ActionBar.DISPLAY_SHOW_TITLE);\r
+ findViewById(R.id.setup_account).setOnClickListener(this);\r
+ \r
+ } else if (findViewById(R.id.file_list_view) == null) {\r
+ setContentView(mLayoutView);\r
+ }\r
+ \r
}\r
\r
@Override\r
if (!remotepath.endsWith("/"))\r
remotepath += "/";\r
remotepath += URLEncoder.encode(new File(filepath).getName());\r
- Log.e("ASD", remotepath + "");\r
\r
i.putExtra(FileUploader.KEY_LOCAL_FILE, filepath);\r
i.putExtra(FileUploader.KEY_REMOTE_FILE, remotepath);\r
if (mDirs != null)\r
for (String s : mDirs)\r
mDirectories.insert(s, 0);\r
+ mCurrentDir = savedInstanceState.getParcelable(KEY_CURRENT_DIR);\r
}\r
\r
@Override\r
protected void onResume() {\r
super.onResume();\r
\r
- //TODO: Dialog useless -> get rid of this\r
- if (!accountsAreSetup()) {\r
- setContentView(R.layout.no_account_available);\r
- setProgressBarIndeterminateVisibility(false);\r
- getSupportActionBar().setNavigationMode(ActionBar.DISPLAY_SHOW_TITLE);\r
- findViewById(R.id.setup_account).setOnClickListener(this);\r
- return;\r
- } else if (findViewById(R.id.file_list_view) == null) {\r
- setContentView(R.layout.files);\r
- }\r
+ if (accountsAreSetup()) {\r
+\r
+ setContentView(mLayoutView); // this should solve the crash by repeated inflating in big screens (DROIDCLOUD-27)\r
\r
- // Listen for sync messages\r
- IntentFilter syncIntentFilter = new IntentFilter(FileSyncService.SYNC_MESSAGE);\r
- syncBroadcastRevceiver = new SyncBroadcastReceiver();\r
- registerReceiver(syncBroadcastRevceiver, syncIntentFilter);\r
+ // Listen for sync messages\r
+ IntentFilter syncIntentFilter = new IntentFilter(FileSyncService.SYNC_MESSAGE);\r
+ syncBroadcastRevceiver = new SyncBroadcastReceiver();\r
+ registerReceiver(syncBroadcastRevceiver, syncIntentFilter);\r
\r
- // Storage manager initialization\r
- mStorageManager = new FileDataStorageManager(\r
- AccountUtils.getCurrentOwnCloudAccount(this),\r
- getContentResolver());\r
+ // Storage manager initialization\r
+ mStorageManager = new FileDataStorageManager(\r
+ AccountUtils.getCurrentOwnCloudAccount(this),\r
+ getContentResolver());\r
\r
- // File list\r
- mFileList = (FileListFragment) getSupportFragmentManager().findFragmentById(R.id.fileList);\r
+ // File list\r
+ mFileList = (FileListFragment) getSupportFragmentManager().findFragmentById(R.id.fileList);\r
\r
- // Figure out what directory to list. \r
- // Priority: Intent (here), savedInstanceState (onCreate), root dir (dir is null)\r
- if(getIntent().hasExtra(FileDetailFragment.EXTRA_FILE)){\r
- mCurrentDir = (OCFile) getIntent().getParcelableExtra(FileDetailFragment.EXTRA_FILE);\r
- if(!mCurrentDir.isDirectory()){\r
- mCurrentDir = mStorageManager.getFileById(mCurrentDir.getParentId());\r
- }\r
+ // Figure out what directory to list. \r
+ // Priority: Intent (here), savedInstanceState (onCreate), root dir (dir is null)\r
+ if(getIntent().hasExtra(FileDetailFragment.EXTRA_FILE)){\r
+ mCurrentDir = (OCFile) getIntent().getParcelableExtra(FileDetailFragment.EXTRA_FILE);\r
+ if(!mCurrentDir.isDirectory()){\r
+ mCurrentDir = mStorageManager.getFileById(mCurrentDir.getParentId());\r
+ }\r
\r
- // Clear intent extra, so rotating the screen will not return us to this directory\r
- getIntent().removeExtra(FileDetailFragment.EXTRA_FILE);\r
- } \r
+ // Clear intent extra, so rotating the screen will not return us to this directory\r
+ getIntent().removeExtra(FileDetailFragment.EXTRA_FILE);\r
+ } else {\r
+ mCurrentDir = mStorageManager.getFileByPath("/");\r
+ }\r
\r
- // Drop-Down navigation and file list restore\r
- mDirectories = new CustomArrayAdapter<String>(this, R.layout.sherlock_spinner_dropdown_item);\r
+ // Drop-Down navigation and file list restore\r
+ mDirectories = new CustomArrayAdapter<String>(this, R.layout.sherlock_spinner_dropdown_item);\r
\r
\r
- // Given the case we have a file to display:\r
- if(mCurrentDir != null){\r
- ArrayList<OCFile> files = new ArrayList<OCFile>();\r
- OCFile currFile = mCurrentDir;\r
- while(currFile != null){\r
- files.add(currFile);\r
- currFile = mStorageManager.getFileById(currFile.getParentId());\r
- }\r
+ // Given the case we have a file to display:\r
+ if(mCurrentDir != null){\r
+ ArrayList<OCFile> files = new ArrayList<OCFile>();\r
+ OCFile currFile = mCurrentDir;\r
+ while(currFile != null){\r
+ files.add(currFile);\r
+ currFile = mStorageManager.getFileById(currFile.getParentId());\r
+ }\r
\r
- // Insert in mDirs\r
- mDirs = new String[files.size()];\r
- for(int i = files.size() - 1; i >= 0; i--){\r
- mDirs[i] = files.get(i).getFileName();\r
+ // Insert in mDirs\r
+ mDirs = new String[files.size()];\r
+ for(int i = files.size() - 1; i >= 0; i--){\r
+ mDirs[i] = files.get(i).getFileName();\r
+ }\r
}\r
- }\r
\r
- if (mDirs != null) {\r
- for (String s : mDirs)\r
- mDirectories.add(s);\r
- } else {\r
- mDirectories.add("/");\r
- }\r
+ if (mDirs != null) {\r
+ for (String s : mDirs)\r
+ mDirectories.add(s);\r
+ } else {\r
+ mDirectories.add("/");\r
+ }\r
\r
- // Actionbar setup\r
- ActionBar action_bar = getSupportActionBar();\r
- action_bar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);\r
- action_bar.setDisplayShowTitleEnabled(false);\r
- action_bar.setListNavigationCallbacks(mDirectories, this);\r
- if(mCurrentDir != null && mCurrentDir.getParentId() != 0){\r
- action_bar.setDisplayHomeAsUpEnabled(true);\r
- } else {\r
- action_bar.setDisplayHomeAsUpEnabled(false);\r
- }\r
+ // Actionbar setup\r
+ ActionBar action_bar = getSupportActionBar();\r
+ action_bar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);\r
+ action_bar.setDisplayShowTitleEnabled(false);\r
+ action_bar.setListNavigationCallbacks(mDirectories, this);\r
+ if(mCurrentDir != null && mCurrentDir.getParentId() != 0){\r
+ action_bar.setDisplayHomeAsUpEnabled(true);\r
+ } else {\r
+ action_bar.setDisplayHomeAsUpEnabled(false);\r
+ }\r
\r
- // List dir here\r
- mFileList.listDirectory(mCurrentDir);\r
+ // List dir here\r
+ mFileList.listDirectory(mCurrentDir);\r
+ }\r
}\r
\r
@Override\r
unregisterReceiver(syncBroadcastRevceiver);\r
syncBroadcastRevceiver = null;\r
}\r
- \r
}\r
\r
@Override\r
builder.setTitle(R.string.uploader_info_dirname);\r
int typed_color = getResources().getColor(R.color.setup_text_typed);\r
dirNameInput.setTextColor(typed_color);\r
- \r
builder.setPositiveButton(android.R.string.ok,\r
new OnClickListener() {\r
public void onClick(DialogInterface dialog, int which) {\r
}\r
\r
// Figure out the path where the dir needs to be created\r
- String path = mCurrentDir.getRemotePath();\r
+ String path = FileDisplayActivity.this.mCurrentDir.getRemotePath();\r
\r
// Create directory\r
path += directoryName + "/";\r
- Thread thread = new Thread(new DirectoryCreator(\r
- path, a));\r
+ Thread thread = new Thread(new DirectoryCreator(path, a));\r
thread.start();\r
\r
// Save new directory in local database\r
}\r
}\r
\r
+ public DataStorageManager getStorageManager() {\r
+ return mStorageManager;\r
+ } \r
}\r