From: Lennart Rosam Date: Sat, 14 Apr 2012 16:55:15 +0000 (+0200) Subject: More cleanup / refactoring: Name Fragments consistantly way X-Git-Tag: oc-android-1.4.3~446 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/a29469016eabccfd6e011659ccd426c2a0bc84c3 More cleanup / refactoring: Name Fragments consistantly way --- diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 493cbfe4..c278a8e1 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -114,7 +114,8 @@ - + + class="eu.alefzero.owncloud.ui.fragment.FileDetailFragment" /> \ No newline at end of file diff --git a/res/layout/file_details.xml b/res/layout/file_details.xml deleted file mode 100644 index e02ed7cd..00000000 --- a/res/layout/file_details.xml +++ /dev/null @@ -1,94 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/res/layout/file_details_fragment.xml b/res/layout/file_details_fragment.xml new file mode 100644 index 00000000..e02ed7cd --- /dev/null +++ b/res/layout/file_details_fragment.xml @@ -0,0 +1,94 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/res/layout/files.xml b/res/layout/files.xml index c64e3e85..9cbd3bb9 100644 --- a/res/layout/files.xml +++ b/res/layout/files.xml @@ -8,7 +8,7 @@ android:id="@+id/fileList" android:layout_width="fill_parent" android:layout_height="fill_parent" - class="eu.alefzero.owncloud.ui.fragment.FileList" > + class="eu.alefzero.owncloud.ui.fragment.FileListFragment" > \ No newline at end of file diff --git a/src/eu/alefzero/owncloud/ui/activity/FileDetailActivity.java b/src/eu/alefzero/owncloud/ui/activity/FileDetailActivity.java index 08710c51..f772e1db 100644 --- a/src/eu/alefzero/owncloud/ui/activity/FileDetailActivity.java +++ b/src/eu/alefzero/owncloud/ui/activity/FileDetailActivity.java @@ -25,7 +25,7 @@ import android.view.Window; import com.actionbarsherlock.app.SherlockFragmentActivity; import eu.alefzero.owncloud.R; -import eu.alefzero.owncloud.ui.fragment.FileDetail; +import eu.alefzero.owncloud.ui.fragment.FileDetailFragment; /** * This activity displays the details of a file like @@ -34,7 +34,7 @@ import eu.alefzero.owncloud.ui.fragment.FileDetail; * */ public class FileDetailActivity extends SherlockFragmentActivity { - private FileDetail mFileDetail; + private FileDetailFragment mFileDetail; @Override protected void onCreate(Bundle savedInstanceState) { @@ -43,7 +43,7 @@ protected void onCreate(Bundle savedInstanceState) { getWindow().requestFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.file_activity_details); - mFileDetail = new FileDetail(); + mFileDetail = new FileDetailFragment(); FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); ft.add(R.id.fileDetail, mFileDetail); ft.commit(); diff --git a/src/eu/alefzero/owncloud/ui/activity/FileDisplayActivity.java b/src/eu/alefzero/owncloud/ui/activity/FileDisplayActivity.java index 5656d3fc..0d042515 100644 --- a/src/eu/alefzero/owncloud/ui/activity/FileDisplayActivity.java +++ b/src/eu/alefzero/owncloud/ui/activity/FileDisplayActivity.java @@ -46,7 +46,7 @@ import eu.alefzero.owncloud.R; import eu.alefzero.owncloud.authenticator.AccountAuthenticator; import eu.alefzero.owncloud.authenticator.AuthUtils; import eu.alefzero.owncloud.datamodel.OCFile; -import eu.alefzero.owncloud.ui.fragment.FileList; +import eu.alefzero.owncloud.ui.fragment.FileListFragment; import eu.alefzero.webdav.WebdavClient; /** @@ -154,7 +154,7 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements startActivity(intent); return; } - ((FileList) getSupportFragmentManager().findFragmentById(R.id.fileList)) + ((FileListFragment) getSupportFragmentManager().findFragmentById(R.id.fileList)) .onNavigateUp(); } diff --git a/src/eu/alefzero/owncloud/ui/fragment/FileDetail.java b/src/eu/alefzero/owncloud/ui/fragment/FileDetail.java deleted file mode 100644 index 5e729ffb..00000000 --- a/src/eu/alefzero/owncloud/ui/fragment/FileDetail.java +++ /dev/null @@ -1,147 +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 . - * - */ -package eu.alefzero.owncloud.ui.fragment; - -import android.accounts.Account; -import android.content.Intent; -import android.database.Cursor; -import android.graphics.Bitmap; -import android.graphics.BitmapFactory; -import android.net.Uri; -import android.os.Bundle; -import android.view.LayoutInflater; -import android.view.View; -import android.view.View.OnClickListener; -import android.view.ViewGroup; -import android.widget.ImageView; -import android.widget.TextView; -import android.widget.Toast; -import android.widget.VideoView; - -import com.actionbarsherlock.app.SherlockFragment; - -import eu.alefzero.owncloud.DisplayUtils; -import eu.alefzero.owncloud.FileDownloader; -import eu.alefzero.owncloud.R; -import eu.alefzero.owncloud.db.ProviderMeta.ProviderTableMeta; - -/** - * This Fragment is used to display the details about a file. - * @author Bartek Przybylski - * - */ -public class FileDetail extends SherlockFragment implements OnClickListener { - - private Intent mIntent; - private View mView; - - public void setStuff(Intent intent) { - mIntent = intent; - setStuff(getView()); - } - - private void setStuff(View view) { - mView = view; - String id = mIntent.getStringExtra("FILE_ID"); - Account account = mIntent.getParcelableExtra("ACCOUNT"); - String account_name = account.name; - Cursor c = getActivity().managedQuery( - Uri.withAppendedPath(ProviderTableMeta.CONTENT_URI_FILE, id), - null, - ProviderTableMeta.FILE_ACCOUNT_OWNER+"=?", - new String[]{account_name}, - null); - c.moveToFirst(); - - // Retrieve details from DB - String filename = c.getString(c.getColumnIndex(ProviderTableMeta.FILE_NAME)); - String mimetype = c.getString(c.getColumnIndex(ProviderTableMeta.FILE_CONTENT_TYPE)); - String path = c.getString(c.getColumnIndex(ProviderTableMeta.FILE_STORAGE_PATH)); - long filesize = c.getLong(c.getColumnIndex(ProviderTableMeta.FILE_CONTENT_LENGTH)); - - // set file details - setFilename(filename); - setFiletype(DisplayUtils.convertMIMEtoPrettyPrint(mimetype)); - setFilesize(filesize); - - // set file preview if available and possible - View w = view.findViewById(R.id.videoView1); - w.setVisibility(View.INVISIBLE); - if (path == null) { - ImageView v = (ImageView) getView().findViewById(R.id.imageView2); - v.setImageResource(R.drawable.download); - v.setOnClickListener(this); - } else { - if (mimetype.startsWith("image/")) { - ImageView v = (ImageView) view.findViewById(R.id.imageView2); - Bitmap bmp = BitmapFactory.decodeFile(path); - v.setImageBitmap(bmp); - } else if (mimetype.startsWith("video/")) { - VideoView v = (VideoView) view.findViewById(R.id.videoView1); - v.setVisibility(View.VISIBLE); - v.setVideoPath(path); - v.start(); - } - } - } - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { - View v = null; - - if (getActivity().getIntent() != null && getActivity().getIntent().getStringExtra("FILE_ID") != null) { - v = inflater.inflate(R.layout.file_details, container, false); - mIntent = getActivity().getIntent(); - setStuff(v); - } else { - v = inflater.inflate(R.layout.file_details_empty, container, false); - } - return v; - } - - @Override - public View getView() { - return mView == null ? super.getView() : mView; - }; - - public void setFilename(String filename) { - TextView tv = (TextView) getView().findViewById(R.id.textView1); - if (tv != null) tv.setText(filename); - } - - public void setFiletype(String mimetype) { - TextView tv = (TextView) getView().findViewById(R.id.textView2); - if (tv != null) tv.setText(mimetype); - } - - public void setFilesize(long filesize) { - TextView tv = (TextView) getView().findViewById(R.id.textView3); - if (tv != null) tv.setText(DisplayUtils.bitsToHumanReadable(filesize)); - } - - @Override - public void onClick(View v) { - Toast.makeText(getActivity(), "Downloading", Toast.LENGTH_LONG).show(); - Intent i = new Intent(getActivity(), FileDownloader.class); - i.putExtra(FileDownloader.EXTRA_ACCOUNT, mIntent.getParcelableExtra("ACCOUNT")); - i.putExtra(FileDownloader.EXTRA_FILE_PATH, mIntent.getStringExtra("FULL_PATH")); - getActivity().startService(i); - } - -} diff --git a/src/eu/alefzero/owncloud/ui/fragment/FileDetailFragment.java b/src/eu/alefzero/owncloud/ui/fragment/FileDetailFragment.java new file mode 100644 index 00000000..fac9fa4a --- /dev/null +++ b/src/eu/alefzero/owncloud/ui/fragment/FileDetailFragment.java @@ -0,0 +1,147 @@ +/* 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 . + * + */ +package eu.alefzero.owncloud.ui.fragment; + +import android.accounts.Account; +import android.content.Intent; +import android.database.Cursor; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.net.Uri; +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.View.OnClickListener; +import android.view.ViewGroup; +import android.widget.ImageView; +import android.widget.TextView; +import android.widget.Toast; +import android.widget.VideoView; + +import com.actionbarsherlock.app.SherlockFragment; + +import eu.alefzero.owncloud.DisplayUtils; +import eu.alefzero.owncloud.FileDownloader; +import eu.alefzero.owncloud.R; +import eu.alefzero.owncloud.db.ProviderMeta.ProviderTableMeta; + +/** + * This Fragment is used to display the details about a file. + * @author Bartek Przybylski + * + */ +public class FileDetailFragment extends SherlockFragment implements OnClickListener { + + private Intent mIntent; + private View mView; + + public void setStuff(Intent intent) { + mIntent = intent; + setStuff(getView()); + } + + private void setStuff(View view) { + mView = view; + String id = mIntent.getStringExtra("FILE_ID"); + Account account = mIntent.getParcelableExtra("ACCOUNT"); + String account_name = account.name; + Cursor c = getActivity().managedQuery( + Uri.withAppendedPath(ProviderTableMeta.CONTENT_URI_FILE, id), + null, + ProviderTableMeta.FILE_ACCOUNT_OWNER+"=?", + new String[]{account_name}, + null); + c.moveToFirst(); + + // Retrieve details from DB + String filename = c.getString(c.getColumnIndex(ProviderTableMeta.FILE_NAME)); + String mimetype = c.getString(c.getColumnIndex(ProviderTableMeta.FILE_CONTENT_TYPE)); + String path = c.getString(c.getColumnIndex(ProviderTableMeta.FILE_STORAGE_PATH)); + long filesize = c.getLong(c.getColumnIndex(ProviderTableMeta.FILE_CONTENT_LENGTH)); + + // set file details + setFilename(filename); + setFiletype(DisplayUtils.convertMIMEtoPrettyPrint(mimetype)); + setFilesize(filesize); + + // set file preview if available and possible + View w = view.findViewById(R.id.videoView1); + w.setVisibility(View.INVISIBLE); + if (path == null) { + ImageView v = (ImageView) getView().findViewById(R.id.imageView2); + v.setImageResource(R.drawable.download); + v.setOnClickListener(this); + } else { + if (mimetype.startsWith("image/")) { + ImageView v = (ImageView) view.findViewById(R.id.imageView2); + Bitmap bmp = BitmapFactory.decodeFile(path); + v.setImageBitmap(bmp); + } else if (mimetype.startsWith("video/")) { + VideoView v = (VideoView) view.findViewById(R.id.videoView1); + v.setVisibility(View.VISIBLE); + v.setVideoPath(path); + v.start(); + } + } + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + View v = null; + + if (getActivity().getIntent() != null && getActivity().getIntent().getStringExtra("FILE_ID") != null) { + v = inflater.inflate(R.layout.file_details_fragment, container, false); + mIntent = getActivity().getIntent(); + setStuff(v); + } else { + v = inflater.inflate(R.layout.file_details_empty, container, false); + } + return v; + } + + @Override + public View getView() { + return mView == null ? super.getView() : mView; + }; + + public void setFilename(String filename) { + TextView tv = (TextView) getView().findViewById(R.id.textView1); + if (tv != null) tv.setText(filename); + } + + public void setFiletype(String mimetype) { + TextView tv = (TextView) getView().findViewById(R.id.textView2); + if (tv != null) tv.setText(mimetype); + } + + public void setFilesize(long filesize) { + TextView tv = (TextView) getView().findViewById(R.id.textView3); + if (tv != null) tv.setText(DisplayUtils.bitsToHumanReadable(filesize)); + } + + @Override + public void onClick(View v) { + Toast.makeText(getActivity(), "Downloading", Toast.LENGTH_LONG).show(); + Intent i = new Intent(getActivity(), FileDownloader.class); + i.putExtra(FileDownloader.EXTRA_ACCOUNT, mIntent.getParcelableExtra("ACCOUNT")); + i.putExtra(FileDownloader.EXTRA_FILE_PATH, mIntent.getStringExtra("FULL_PATH")); + getActivity().startService(i); + } + +} diff --git a/src/eu/alefzero/owncloud/ui/fragment/FileList.java b/src/eu/alefzero/owncloud/ui/fragment/FileList.java deleted file mode 100644 index 785b6baa..00000000 --- a/src/eu/alefzero/owncloud/ui/fragment/FileList.java +++ /dev/null @@ -1,146 +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 . - * - */ -package eu.alefzero.owncloud.ui.fragment; - -import java.util.Stack; -import java.util.Vector; - -import android.accounts.Account; -import android.content.Intent; -import android.os.Bundle; -import android.view.View; -import android.widget.AdapterView; -import eu.alefzero.owncloud.R; -import eu.alefzero.owncloud.authenticator.AuthUtils; -import eu.alefzero.owncloud.datamodel.OCFile; -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; - -/** - * A Fragment that lists all files and folders in a given path. - * @author Bartek Przybylski - * - */ -public class FileList extends FragmentListView { - private Account mAccount; - private Stack mDirNames; - private Vector mFiles; - - public FileList() { - mDirNames = new Stack(); - } - - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - mAccount = AuthUtils.getCurrentOwnCloudAccount(getActivity()); - populateFileList(); - // TODO: Remove this testing stuff - //addContact(mAccount, "Bartek Przybylski", "czlowiek"); - } - - @Override - public void onItemClick(AdapterView l, View v, int position, long id) { - if (mFiles.size() <= position) { - throw new IndexOutOfBoundsException("Incorrect item selected"); - } - OCFile file = mFiles.get(position); - String id_ = String.valueOf(file.getFileId()); - if (file.getMimetype().equals("DIR")) { - String dirname = file.getFileName(); - - mDirNames.push(dirname); - ((FileDisplayActivity)getActivity()).pushPath(dirname); - - populateFileList(); - return; - } - Intent i = new Intent(getActivity(), FileDetailActivity.class); - i.putExtra("FILE_NAME", file.getFileName()); - i.putExtra("FULL_PATH", file.getPath()); - i.putExtra("FILE_ID", id_); - i.putExtra("ACCOUNT", mAccount); - FileDetail fd = (FileDetail) getFragmentManager().findFragmentById(R.id.fileDetail); - if (fd != null) { - fd.setStuff(i); - } else { - startActivity(i); - } - } - - /** - * Call this, when the user presses the up button - */ - public void onNavigateUp() { - mDirNames.pop(); - populateFileList(); - } - - /** - * Lists the directory - */ - private void populateFileList() { - String s = "/"; - for (String a : mDirNames) - s+= a+"/"; - - OCFile file = new OCFile(getActivity().getContentResolver(), mAccount, s); - mFiles = file.getDirectoryContent(); - setListAdapter(new FileListListAdapter(file, getActivity())); - } - - //TODO: Delete this testing stuff. - /*private void addContact(Account account, String name, String username) { - Log.i("ASD", "Adding contact: " + name); - ArrayList operationList = new ArrayList(); - - //Create our RawContact - ContentProviderOperation.Builder builder = ContentProviderOperation.newInsert(RawContacts.CONTENT_URI); - builder.withValue(RawContacts.ACCOUNT_NAME, account.name); - builder.withValue(RawContacts.ACCOUNT_TYPE, account.type); - builder.withValue(RawContacts.SYNC1, username); - operationList.add(builder.build()); - - //Create a Data record of common type 'StructuredName' for our RawContact - builder = ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI); - builder.withValueBackReference(ContactsContract.CommonDataKinds.StructuredName.RAW_CONTACT_ID, 0); - builder.withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE); - builder.withValue(ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME, name); - operationList.add(builder.build()); - - //Create a Data record of custom type "vnd.android.cursor.item/vnd.fm.last.android.profile" to display a link to the Last.fm profile - builder = ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI); - builder.withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0); - builder.withValue(ContactsContract.Data.MIMETYPE, "vnd.android.cursor.item/vnd.owncloud.contact.profile"); - builder.withValue(ContactsContract.Data.DATA1, username); - builder.withValue(ContactsContract.Data.DATA2, "Last.fm Profile"); - builder.withValue(ContactsContract.Data.DATA3, "View profile"); - operationList.add(builder.build()); - - try { - getActivity().getContentResolver().applyBatch(ContactsContract.AUTHORITY, operationList); - } catch (Exception e) { - Log.e("ASD", "Something went wrong during creation! " + e); - e.printStackTrace(); - } - }*/ - -} diff --git a/src/eu/alefzero/owncloud/ui/fragment/FileListFragment.java b/src/eu/alefzero/owncloud/ui/fragment/FileListFragment.java new file mode 100644 index 00000000..a8bc9d39 --- /dev/null +++ b/src/eu/alefzero/owncloud/ui/fragment/FileListFragment.java @@ -0,0 +1,146 @@ +/* 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 . + * + */ +package eu.alefzero.owncloud.ui.fragment; + +import java.util.Stack; +import java.util.Vector; + +import android.accounts.Account; +import android.content.Intent; +import android.os.Bundle; +import android.view.View; +import android.widget.AdapterView; +import eu.alefzero.owncloud.R; +import eu.alefzero.owncloud.authenticator.AuthUtils; +import eu.alefzero.owncloud.datamodel.OCFile; +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; + +/** + * A Fragment that lists all files and folders in a given path. + * @author Bartek Przybylski + * + */ +public class FileListFragment extends FragmentListView { + private Account mAccount; + private Stack mDirNames; + private Vector mFiles; + + public FileListFragment() { + mDirNames = new Stack(); + } + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + mAccount = AuthUtils.getCurrentOwnCloudAccount(getActivity()); + populateFileList(); + // TODO: Remove this testing stuff + //addContact(mAccount, "Bartek Przybylski", "czlowiek"); + } + + @Override + public void onItemClick(AdapterView l, View v, int position, long id) { + if (mFiles.size() <= position) { + throw new IndexOutOfBoundsException("Incorrect item selected"); + } + OCFile file = mFiles.get(position); + String id_ = String.valueOf(file.getFileId()); + if (file.getMimetype().equals("DIR")) { + String dirname = file.getFileName(); + + mDirNames.push(dirname); + ((FileDisplayActivity)getActivity()).pushPath(dirname); + + populateFileList(); + return; + } + Intent i = new Intent(getActivity(), FileDetailActivity.class); + i.putExtra("FILE_NAME", file.getFileName()); + i.putExtra("FULL_PATH", file.getPath()); + i.putExtra("FILE_ID", id_); + i.putExtra("ACCOUNT", mAccount); + FileDetailFragment fd = (FileDetailFragment) getFragmentManager().findFragmentById(R.id.fileDetail); + if (fd != null) { + fd.setStuff(i); + } else { + startActivity(i); + } + } + + /** + * Call this, when the user presses the up button + */ + public void onNavigateUp() { + mDirNames.pop(); + populateFileList(); + } + + /** + * Lists the directory + */ + private void populateFileList() { + String s = "/"; + for (String a : mDirNames) + s+= a+"/"; + + OCFile file = new OCFile(getActivity().getContentResolver(), mAccount, s); + mFiles = file.getDirectoryContent(); + setListAdapter(new FileListListAdapter(file, getActivity())); + } + + //TODO: Delete this testing stuff. + /*private void addContact(Account account, String name, String username) { + Log.i("ASD", "Adding contact: " + name); + ArrayList operationList = new ArrayList(); + + //Create our RawContact + ContentProviderOperation.Builder builder = ContentProviderOperation.newInsert(RawContacts.CONTENT_URI); + builder.withValue(RawContacts.ACCOUNT_NAME, account.name); + builder.withValue(RawContacts.ACCOUNT_TYPE, account.type); + builder.withValue(RawContacts.SYNC1, username); + operationList.add(builder.build()); + + //Create a Data record of common type 'StructuredName' for our RawContact + builder = ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI); + builder.withValueBackReference(ContactsContract.CommonDataKinds.StructuredName.RAW_CONTACT_ID, 0); + builder.withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE); + builder.withValue(ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME, name); + operationList.add(builder.build()); + + //Create a Data record of custom type "vnd.android.cursor.item/vnd.fm.last.android.profile" to display a link to the Last.fm profile + builder = ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI); + builder.withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0); + builder.withValue(ContactsContract.Data.MIMETYPE, "vnd.android.cursor.item/vnd.owncloud.contact.profile"); + builder.withValue(ContactsContract.Data.DATA1, username); + builder.withValue(ContactsContract.Data.DATA2, "Last.fm Profile"); + builder.withValue(ContactsContract.Data.DATA3, "View profile"); + operationList.add(builder.build()); + + try { + getActivity().getContentResolver().applyBatch(ContactsContract.AUTHORITY, operationList); + } catch (Exception e) { + Log.e("ASD", "Something went wrong during creation! " + e); + e.printStackTrace(); + } + }*/ + +}