Android Open Source - dropbox-android-sync-sdk-mirror Folder Adapter






From Project

Back to project page dropbox-android-sync-sdk-mirror.

License

The source code is released under:

Apache License

If you think the Android project dropbox-android-sync-sdk-mirror listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.dropbox.examples.notes;
/*from   w ww. j a  v a2s  .  c  om*/
import java.util.List;

import android.annotation.SuppressLint;
import android.content.Context;
import android.os.Build;
import android.text.format.DateFormat;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.dropbox.sync.android.DbxFileInfo;

/**
 * Adapts a {@code List<DbxFileInfo>} to be displayed in a listview.
 * Displays folders as disabled.
 */
class FolderAdapter extends BaseAdapter {

    private final List<DbxFileInfo> mEntries;
    private final LayoutInflater mInflater;
    private final Context mContext;

    public FolderAdapter(Context context, List<DbxFileInfo> entries) {
        mEntries = entries;
        mContext = context;
        mInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    @Override
    public int getCount() {
        return mEntries.size();
    }

    @Override
    public Object getItem(int position) {
        return mEntries.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    @SuppressLint("InlinedApi")
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            int list_item_resid = (Build.VERSION.SDK_INT >= 11)
                    ? android.R.layout.simple_list_item_activated_2
                    : android.R.layout.simple_list_item_2;
            convertView = mInflater.inflate(list_item_resid, parent, false);
        }
        DbxFileInfo info = mEntries.get(position);
        TextView text = (TextView)convertView.findViewById(android.R.id.text1);
        text.setText(getName(info));

        TextView text2 = (TextView)convertView.findViewById(android.R.id.text2);

        if (info.isFolder) {
            text2.setText(R.string.status_folder);

            text.setEnabled(false);
            text2.setEnabled(false);
        } else {
            String modDate = DateFormat.getMediumDateFormat(mContext).format(info.modifiedTime) + " " + DateFormat.getTimeFormat(mContext).format(info.modifiedTime);
            text2.setText(modDate);

            text.setEnabled(true);
            text2.setEnabled(true);
        }
        return convertView;
    }

    @Override
    public boolean isEnabled(int position) {
        DbxFileInfo info = mEntries.get(position);
        return !info.isFolder;
    }

    private String getName(DbxFileInfo info) {
        return Util.stripExtension("txt", info.path.getName());
    }

}




Java Source Code List

com.dropbox.examples.notes.FolderAdapter.java
com.dropbox.examples.notes.NoteDetailActivity.java
com.dropbox.examples.notes.NoteDetailFragment.java
com.dropbox.examples.notes.NoteListActivity.java
com.dropbox.examples.notes.NoteListFragment.java
com.dropbox.examples.notes.NotesAppConfig.java
com.dropbox.examples.notes.Util.java
com.dropbox.sample.hellodropbox.HelloDropboxActivity.java
com.dropbox.sync.android.util.FolderListComparator.java
com.dropbox.sync.android.util.FolderListComparator.java
com.dropbox.sync.android.util.FolderLoader.java
com.dropbox.sync.android.util.FolderLoader.java