Example usage for android.content Context LAYOUT_INFLATER_SERVICE

List of usage examples for android.content Context LAYOUT_INFLATER_SERVICE

Introduction

In this page you can find the example usage for android.content Context LAYOUT_INFLATER_SERVICE.

Prototype

String LAYOUT_INFLATER_SERVICE

To view the source code for android.content Context LAYOUT_INFLATER_SERVICE.

Click Source Link

Document

Use with #getSystemService(String) to retrieve a android.view.LayoutInflater for inflating layout resources in this context.

Usage

From source file:org.mifos.androidclient.util.listadapters.SimpleExpandableListAdapter.java

@Override
public View getChildView(int groupPos, int childPos, boolean isLastChild, View convertView, ViewGroup parent) {
    View row;/*  w ww  . j ava  2  s.c o  m*/
    if (convertView == null) {
        LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        row = inflater.inflate(R.layout.simple_list_child, parent, false);
    } else {
        row = convertView;
    }
    SimpleListItem item = (SimpleListItem) getChild(groupPos, childPos);
    if (item != null) {
        TextView label = (TextView) row.findViewById(R.id.simple_list_item_label);
        label.setText(item.getListLabel());
    }
    return row;
}

From source file:com.binoy.vibhinna.VibhinnaFragment.java

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);
    AdapterView.AdapterContextMenuInfo info;
    PropManager propmanager = new PropManager(getActivity().getApplicationContext());
    try {//w w w  .jav a2  s . com
        // Casts the incoming data object into the type for AdapterView
        // objects.
        info = (AdapterView.AdapterContextMenuInfo) menuInfo;
    } catch (ClassCastException e) {
        // If the menu object can't be cast, logs an error.
        Log.w("Exception", "exception in getting menuinfo");
        return;
    }
    Cursor cursor = (Cursor) getListAdapter().getItem(info.position);
    String s1 = Constants.SD_PATH + propmanager.mbActivePath();
    String s2 = cursor.getString(7);
    if (cursor.equals(null) || s1.equals(s2))
        return;
    if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB) {
        LayoutInflater headerInflater = (LayoutInflater) getSherlockActivity()
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        ViewGroup header = (ViewGroup) headerInflater.inflate(R.layout.context_menu_header, null);
        TextView title = (TextView) header.findViewById(R.id.context_menu_title);
        title.setText(cursor.getString(1));
        menu.setHeaderView(header);
    } else
        menu.setHeaderTitle(cursor.getString(1));
    android.view.MenuInflater inflater = getActivity().getMenuInflater();
    inflater.inflate(R.menu.context_menu, menu);
}

From source file:com.android.calendar.event.EventLocationAdapter.java

/**
 * Constructor.//from   ww  w. j  a  v  a 2  s  .c o m
 */
public EventLocationAdapter(Context context) {
    super(context, R.layout.location_dropdown_item, EMPTY_LIST);

    mContext = context;
    mResolver = context.getContentResolver();
    mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}

From source file:com.moki.touch.fragments.views.WebContent.java

@Override
public View getView() {
    View emptyView = super.getView();
    if (emptyView != null) {
        return emptyView;
    }/*from   www .  j  a  v  a2s. c o  m*/
    LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    rootView = (LinearLayout) inflater.inflate(R.layout.webcontentlayout, null);
    webView = (WebView) rootView.findViewById(R.id.webcontentview);
    configureWebView(context);
    browserBar = (RelativeLayout) rootView.findViewById(R.id.barlayout);
    // this is added so no swipe actions are detected on the browser bar
    browserBar.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            return true;
        }
    });
    progressBar = (ProgressBar) rootView.findViewById(R.id.web_progress_bar);
    progressBar.setVisibility(View.GONE);
    rootView.findViewById(R.id.barlayout).setBackgroundColor(Color.parseColor(styleColor));
    configureNavigationBar();

    if (!isHomeMode) {
        // this listener is being added to ensure that touch events bubble up to the correct receivers.
        disableWebView();
    }

    if (!showBrowserBar) {
        browserBar.setVisibility(View.GONE);
    }

    boolean listenForLogo = setLogo();
    if (listenForLogo) {
        registerForLogoDownload();
    }

    return rootView;
}

From source file:com.df.app.carsWaiting.CarsWaitingListActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_cars_waiting);

    swipeListView = (SwipeListView) findViewById(R.id.carsWaitingList);

    data = new ArrayList<CarsWaitingItem>();

    adapter = new CarsWaitingListAdapter(this, data, new CarsWaitingListAdapter.OnAction() {
        @Override/*from w  ww.  java2s  .  co m*/
        public void onEditPressed(int position) {
            swipeListView.openAnimate(position);
        }

        @Override
        public void onModifyProcedure(int positon) {
            CarsWaitingItem item = data.get(positon);
            Intent intent = new Intent(CarsWaitingListActivity.this, InputProceduresActivity.class);
            intent.putExtra("carId", item.getCarId());
            startActivity(intent);
        }

        @Override
        public void onDeleteCar(final int position) {
            View view1 = getLayoutInflater().inflate(R.layout.popup_layout, null);
            TableLayout contentArea = (TableLayout) view1.findViewById(R.id.contentArea);
            TextView content = new TextView(view1.getContext());
            content.setText(R.string.confirmDeleteCar);
            content.setTextSize(20f);
            contentArea.addView(content);

            setTextView(view1, R.id.title, getResources().getString(R.string.alert));

            AlertDialog dialog = new AlertDialog.Builder(CarsWaitingListActivity.this).setView(view1)
                    .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialogInterface, int i) {
                            CarsWaitingItem item = data.get(position);
                            deleteCar(item.getCarId());
                        }
                    }).setNegativeButton(R.string.cancel, null).create();

            dialog.show();
        }
    });

    swipeListView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
    swipeListView.setSwipeListViewListener(new BaseSwipeListViewListener() {
        @Override
        public void onClickFrontView(int position) {
            getCarDetail(data.get(position).getCarId(), CarCheckActivity.class);
        }

        @Override
        public void onDismiss(int[] reverseSortedPositions) {
            for (int position : reverseSortedPositions) {
                data.remove(position);
            }
            adapter.notifyDataSetChanged();
        }

        @Override
        public void onStartOpen(int position, int action, boolean right) {
            swipeListView.closeOpenedItems();
        }
    });

    swipeListView.setSwipeMode(SwipeListView.SWIPE_MODE_LEFT);
    swipeListView.setSwipeActionLeft(SwipeListView.SWIPE_ACTION_REVEAL);
    swipeListView.setLongClickable(false);
    swipeListView.setSwipeOpenOnLongPress(false);
    swipeListView.setOffsetLeft(620);
    swipeListView.setAnimationTime(300);
    swipeListView.setAdapter(adapter);

    footerView = ((LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE))
            .inflate(R.layout.footer, null, false);

    swipeListView.addFooterView(footerView);

    Button homeButton = (Button) findViewById(R.id.buttonHome);
    homeButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            finish();
        }
    });

    Button loadMoreButton = (Button) findViewById(R.id.loadMore);
    loadMoreButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            refresh(false);
        }
    });

    Button refreshButton = (Button) findViewById(R.id.buttonRefresh);
    refreshButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            refresh(true);
        }
    });

    refresh(true);
}

From source file:com.df.kia.carsWaiting.CarsWaitingListActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_cars_waiting);

    swipeListView = (SwipeListView) findViewById(R.id.carsWaitingList);

    data = new ArrayList<CarsWaitingItem>();

    adapter = new CarsWaitingListAdapter(this, data, new CarsWaitingListAdapter.OnAction() {
        @Override/*ww  w  .j a  va 2  s. c  o m*/
        public void onEditPressed(int position) {
            swipeListView.openAnimate(position);
        }

        @Override
        public void onModifyProcedure(int positon) {
            CarsWaitingItem item = data.get(positon);
            Intent intent = new Intent(CarsWaitingListActivity.this, InputProceduresActivity.class);
            intent.putExtra("carId", item.getCarId());
            startActivity(intent);
        }

        @Override
        public void onDeleteCar(final int position) {
            View view1 = getLayoutInflater().inflate(R.layout.popup_layout, null);
            TableLayout contentArea = (TableLayout) view1.findViewById(R.id.contentArea);
            TextView content = new TextView(view1.getContext());
            content.setText(R.string.confirmDeleteCar);
            content.setTextSize(20f);
            contentArea.addView(content);

            setTextView(view1, R.id.title, getResources().getString(R.string.alert));

            AlertDialog dialog = new AlertDialog.Builder(CarsWaitingListActivity.this).setView(view1)
                    .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialogInterface, int i) {
                            CarsWaitingItem item = data.get(position);
                            deleteCar(item.getCarId());
                        }
                    }).setNegativeButton(R.string.cancel, null).create();

            dialog.show();
        }
    });

    swipeListView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
    swipeListView.setSwipeListViewListener(new BaseSwipeListViewListener() {
        @Override
        public void onClickFrontView(int position) {
            getCarDetail(data.get(position).getCarId(), CarCheckActivity.class);
        }

        @Override
        public void onDismiss(int[] reverseSortedPositions) {
            for (int position : reverseSortedPositions) {
                data.remove(position);
            }
            adapter.notifyDataSetChanged();
        }

        @Override
        public void onStartOpen(int position, int action, boolean right) {
            swipeListView.closeOpenedItems();
            lastPos = position;
        }
    });

    swipeListView.setSwipeMode(SwipeListView.SWIPE_MODE_LEFT);
    swipeListView.setSwipeActionLeft(SwipeListView.SWIPE_ACTION_REVEAL);
    swipeListView.setLongClickable(false);
    swipeListView.setSwipeOpenOnLongPress(false);
    swipeListView.setOffsetLeft(620);
    swipeListView.setAnimationTime(300);
    swipeListView.setAdapter(adapter);

    footerView = ((LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE))
            .inflate(R.layout.footer, null, false);

    swipeListView.addFooterView(footerView);

    Button homeButton = (Button) findViewById(R.id.buttonHome);
    homeButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            finish();
        }
    });

    Button loadMoreButton = (Button) findViewById(R.id.loadMore);
    loadMoreButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            refresh();
        }
    });

    Button refreshButton = (Button) findViewById(R.id.buttonRefresh);
    refreshButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            startNumber = 1;
            data.clear();
            adapter.notifyDataSetChanged();

            swipeListView.closeOpenedItems();

            refresh();
        }
    });

    refresh();
}

From source file:br.liveo.adapter.NavigationLiveoAdapter.java

@SuppressLint("ViewHolder")
public View getView(int position, View convertView, ViewGroup parent) {

    ViewHolder holder;/*  w ww  .j a  v  a2  s.  c  o m*/
    holder = new ViewHolder();

    LayoutInflater inflater = (LayoutInflater) mcontext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    convertView = inflater.inflate(R.layout.navigation_list_item, parent, false);

    holder.title = (TextView) convertView.findViewById(R.id.title);
    holder.counter = (TextView) convertView.findViewById(R.id.counter);
    holder.icon = (ImageView) convertView.findViewById(R.id.icon);

    holder.separator = convertView.findViewById(R.id.separator);

    holder.layoutDados = (RelativeLayout) convertView.findViewById(R.id.layoutDados);
    holder.layoutSeparator = (LinearLayout) convertView.findViewById(R.id.layoutSeparator);

    convertView.setTag(holder);

    NavigationLiveoItemAdapter item = mList.get(position);

    if (holder.title != null) {
        holder.title.setText(item.title);

        if (!item.isHeader) {
            holder.layoutSeparator.setVisibility(View.GONE);

            int type = getItemViewType(position);
            holder.layoutDados.setVisibility(type == 0 ? View.VISIBLE : View.GONE);

            setAlpha(holder.title, (item.checked ? 1f : 0.87f));
        } else {
            holder.layoutSeparator.setVisibility(View.VISIBLE);

            if (mColorSeparator > 0) {
                holder.separator.setBackgroundResource(mColorSeparator);
            }

            if (item.title.equals("")) {
                holder.title.setVisibility(View.GONE);
                holder.layoutDados.setVisibility(View.GONE);
            } else {
                holder.layoutDados.setVisibility(View.VISIBLE);
            }
        }

        holder.title.setTextColor((!item.isHeader && item.checked && item.colorSelected > 0
                ? ContextCompat.getColor(mcontext, item.colorSelected)
                : mColorDefault != 0 ? ContextCompat.getColor(mcontext, mColorDefault)
                        : mColorName > 0 ? ContextCompat.getColor(mcontext, mColorName)
                                : (item.isHeader && mColorSubHeader > 0)
                                        ? ContextCompat.getColor(mcontext, mColorSubHeader)
                                        : ContextCompat.getColor(mcontext, R.color.nliveo_black)));
    }

    if (holder.counter != null) {
        if (item.counter >= 1) {
            setAlpha(holder.counter, (item.checked ? 1f : 0.87f));
            holder.counter.setVisibility(View.VISIBLE);
            holder.counter.setText((item.counter > 99) ? "99+" : item.counter + "");

            holder.counter.setTextColor((!item.isHeader && item.checked && item.colorSelected > 0
                    ? ContextCompat.getColor(mcontext, item.colorSelected)
                    : mColorDefault != 0 ? ContextCompat.getColor(mcontext, mColorDefault)
                            : mColorCounter > 0 ? ContextCompat.getColor(mcontext, mColorCounter)
                                    : ContextCompat.getColor(mcontext, R.color.nliveo_black)));

        } else {
            holder.counter.setVisibility(View.GONE);

            if (item.counter < 0) {
                setNewCounterValue(position, 0);
            }
        }
    }

    if (holder.icon != null) {
        if (item.icon != 0) {
            holder.icon.setVisibility(View.VISIBLE);
            holder.icon.setImageResource(item.icon);
            setAlpha(holder.icon, (!item.isHeader && item.checked ? 1f : 0.54f));

            if (!this.mRemoveColorFilter) {
                holder.icon.setColorFilter((!item.isHeader && item.checked && item.colorSelected > 0
                        ? ContextCompat.getColor(mcontext, item.colorSelected)
                        : (mColorDefault != 0 ? ContextCompat.getColor(mcontext, mColorDefault)
                                : mColorIcon > 0 ? ContextCompat.getColor(mcontext, mColorIcon)
                                        : ContextCompat.getColor(mcontext, R.color.nliveo_black))));
            }
        } else {
            holder.icon.setVisibility(View.GONE);
        }
    }

    if (!item.isHeader) {
        if (item.checked) {
            convertView.setBackgroundResource((!item.removeSelector
                    ? (mNewSelector == 0 ? R.drawable.selector_check_item_navigation : mNewSelector)
                    : R.drawable.selector_no_item_navigation));
        } else {
            convertView
                    .setBackgroundResource(mSelectorDefault == 0 ? R.drawable.selector_no_check_item_navigation
                            : R.drawable.selector_no_item_navigation);
        }
    } else {
        convertView.setBackgroundResource(
                mSelectorDefault == 0 ? R.drawable.selector_no_check_item_navigation : mSelectorDefault);
    }

    return convertView;
}

From source file:com.nickandjerry.dynamiclayoutinflator.DynamicLayoutInflator.java

public static View inflateName(Context context, String name, ViewGroup parent) {
    if (name.startsWith("<")) {
        // Assume it's XML
        return DynamicLayoutInflator.inflate(context, name, parent);
    } else {//from w ww . j  a  v  a  2s.  c  o  m
        File savedFile = context.getFileStreamPath(name + ".xml");
        try {
            InputStream fileStream = new FileInputStream(savedFile);
            return DynamicLayoutInflator.inflate(context, fileStream, parent);
        } catch (FileNotFoundException e) {
        }
        try {
            InputStream assetStream = context.getAssets().open(name + ".xml");
            return DynamicLayoutInflator.inflate(context, assetStream, parent);
        } catch (IOException e) {
        }
        int id = context.getResources().getIdentifier(name, "layout", context.getPackageName());
        if (id > 0) {
            LayoutInflater inflater = (LayoutInflater) context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            return inflater.inflate(id, parent, false);
        }
    }
    return null;
}

From source file:de.geeksfactory.opacclient.frontend.ResultsAdapter.java

@Override
public View getView(int position, View contentView, ViewGroup viewGroup) {
    View view;//from w w w .  ja va2 s.c  o  m

    // position always 0-7
    if (objects.get(position) == null) {
        LayoutInflater layoutInflater = (LayoutInflater) getContext()
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        view = layoutInflater.inflate(R.layout.listitem_searchresult, viewGroup, false);
        return view;
    }

    SearchResult item = objects.get(position);

    if (contentView == null) {
        LayoutInflater layoutInflater = (LayoutInflater) getContext()
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        view = layoutInflater.inflate(R.layout.listitem_searchresult, viewGroup, false);
    } else {
        view = contentView;
    }

    TextView tv = (TextView) view.findViewById(R.id.tvResult);
    tv.setText(Html.fromHtml(item.getInnerhtml()));

    ImageView ivType = (ImageView) view.findViewById(R.id.ivType);

    PreferenceDataSource pds = new PreferenceDataSource(getContext());
    ConnectivityManager connMgr = (ConnectivityManager) getContext()
            .getSystemService(Context.CONNECTIVITY_SERVICE);

    if (item.getCoverBitmap() != null) {
        ivType.setImageBitmap(BitmapUtils.bitmapFromBytes(item.getCoverBitmap()));
        ivType.setVisibility(View.VISIBLE);
        ivType.setPadding(0, 0, 0, 0);
    } else if ((pds.isLoadCoversOnDataPreferenceSet()
            || !ConnectivityManagerCompat.isActiveNetworkMetered(connMgr)) && item.getCover() != null) {
        LoadCoverTask lct = new LoadCoverTask(ivType, item);
        lct.execute();
        ivType.setImageResource(R.drawable.ic_loading);
        ivType.setVisibility(View.VISIBLE);
        ivType.setPadding(0, 0, 0, 0);
    } else if (item.getType() != null && item.getType() != MediaType.NONE) {
        ivType.setImageResource(getResourceByMediaType(item.getType()));
        ivType.setVisibility(View.VISIBLE);
        ivType.setPadding(padding8dp, padding8dp, padding8dp, padding8dp);
    } else {
        ivType.setVisibility(View.INVISIBLE);
    }
    ImageView ivStatus = (ImageView) view.findViewById(R.id.ivStatus);

    if (item.getStatus() != null) {
        ivStatus.setVisibility(View.VISIBLE);
        switch (item.getStatus()) {
        case GREEN:
            ivStatus.setImageResource(R.drawable.status_light_green_check);
            break;
        case RED:
            ivStatus.setImageResource(R.drawable.status_light_red_cross);
            break;
        case YELLOW:
            ivStatus.setImageResource(R.drawable.status_light_yellow_alert);
            break;
        case UNKNOWN:
            ivStatus.setVisibility(View.INVISIBLE);
            break;
        }
    } else {
        ivStatus.setVisibility(View.GONE);
    }

    return view;
}

From source file:com.owncloud.android.ui.adapter.FileListListAdapter.java

@Override
public View getView(final int position, View convertView, ViewGroup parent) {
    View view = convertView;/*ww w.jav  a2  s  . c  om*/
    if (view == null) {
        LayoutInflater inflator = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        view = inflator.inflate(R.layout.list_item, null);
    }

    if (mFiles != null && mFiles.size() > position) {
        OCFile file = mFiles.get(position);
        TextView fileName = (TextView) view.findViewById(R.id.Filename);
        String name = file.getFileName();
        if (dataSourceShareFile == null)
            dataSourceShareFile = new DbShareFile(mContext);

        Account account = AccountUtils.getCurrentOwnCloudAccount(mContext);
        String[] accountNames = account.name.split("@");

        if (accountNames.length > 2) {
            accountName = accountNames[0] + "@" + accountNames[1];
            url = accountNames[2];
        }
        Map<String, String> fileSharers = dataSourceShareFile.getUsersWhoSharedFilesWithMe(accountName);
        TextView sharer = (TextView) view.findViewById(R.id.sharer);
        ImageView shareButton = (ImageView) view.findViewById(R.id.shareItem);
        fileName.setText(name);
        ImageView fileIcon = (ImageView) view.findViewById(R.id.imageView1);
        fileIcon.setImageResource(DisplayUtils.getResourceId(file.getMimetype()));
        ImageView localStateView = (ImageView) view.findViewById(R.id.imageView2);
        FileDownloaderBinder downloaderBinder = mTransferServiceGetter.getFileDownloaderBinder();
        FileUploaderBinder uploaderBinder = mTransferServiceGetter.getFileUploaderBinder();
        if (fileSharers.size() != 0 && (!file.equals("Shared") && file.getRemotePath().contains("Shared"))) {
            if (fileSharers.containsKey(name)) {
                sharer.setText(fileSharers.get(name));
                fileSharers.remove(name);
            } else {
                sharer.setText(" ");
            }
        } else {
            sharer.setText(" ");
        }

        if (downloaderBinder != null && downloaderBinder.isDownloading(mAccount, file)) {
            localStateView.setImageResource(R.drawable.downloading_file_indicator);
            localStateView.setVisibility(View.VISIBLE);
        } else if (uploaderBinder != null && uploaderBinder.isUploading(mAccount, file)) {
            localStateView.setImageResource(R.drawable.uploading_file_indicator);
            localStateView.setVisibility(View.VISIBLE);
        } else if (file.isDown()) {
            localStateView.setImageResource(R.drawable.local_file_indicator);
            localStateView.setVisibility(View.VISIBLE);
        } else {
            localStateView.setVisibility(View.INVISIBLE);
        }

        TextView fileSizeV = (TextView) view.findViewById(R.id.file_size);
        TextView lastModV = (TextView) view.findViewById(R.id.last_mod);
        ImageView checkBoxV = (ImageView) view.findViewById(R.id.custom_checkbox);
        shareButton.setOnClickListener(new OnClickListener() {
            String shareStatusDisplay;
            int flagShare = 0;

            @Override
            public void onClick(View v) {
                final Dialog dialog = new Dialog(mContext);
                final OCFile fileToBeShared = (OCFile) getItem(position);
                final ArrayAdapter<String> shareWithFriends;
                final ArrayAdapter<String> shareAdapter;
                final String filePath;
                sharedWith = new ArrayList<String>();
                dataSource = new DbFriends(mContext);
                dataSourceShareFile = new DbShareFile(mContext);
                dialog.setContentView(R.layout.share_file_with);
                dialog.setTitle("Share");
                Account account = AccountUtils.getCurrentOwnCloudAccount(mContext);
                String[] accountNames = account.name.split("@");

                if (accountNames.length > 2) {
                    accountName = accountNames[0] + "@" + accountNames[1];
                    url = accountNames[2];
                }

                final AutoCompleteTextView textView = (AutoCompleteTextView) dialog
                        .findViewById(R.id.autocompleteshare);
                Button shareBtn = (Button) dialog.findViewById(R.id.ShareBtn);
                Button doneBtn = (Button) dialog.findViewById(R.id.ShareDoneBtn);
                final ListView listview = (ListView) dialog.findViewById(R.id.alreadySharedWithList);

                textView.setThreshold(2);
                final String itemType;

                filePath = "files" + String.valueOf(fileToBeShared.getRemotePath());
                final String fileName = fileToBeShared.getFileName();
                final String fileRemotePath = fileToBeShared.getRemotePath();
                if (dataSourceShareFile == null)
                    dataSourceShareFile = new DbShareFile(mContext);
                sharedWith = dataSourceShareFile.getUsersWithWhomIhaveSharedFile(fileName, fileRemotePath,
                        accountName, String.valueOf(1));
                shareAdapter = new ArrayAdapter<String>(mContext, android.R.layout.simple_list_item_1,
                        sharedWith);
                listview.setAdapter(shareAdapter);
                final String itemSource;
                if (fileToBeShared.isDirectory()) {
                    itemType = "folder";
                    int lastSlashInFolderPath = filePath.lastIndexOf('/');
                    itemSource = filePath.substring(0, lastSlashInFolderPath);
                } else {
                    itemType = "file";
                    itemSource = filePath;
                }

                //Permissions disabled with friends app
                ArrayList<String> friendList = dataSource.getFriendList(accountName);
                dataSource.close();
                shareWithFriends = new ArrayAdapter<String>(mContext, android.R.layout.simple_list_item_1,
                        friendList);
                textView.setAdapter(shareWithFriends);
                textView.setFocusableInTouchMode(true);
                dialog.show();
                textView.setOnItemClickListener(new OnItemClickListener() {

                    @Override
                    public void onItemClick(AdapterView<?> parent, View v, int position, long id) {

                    }
                });
                final Handler finishedHandler = new Handler() {
                    @Override
                    public void handleMessage(Message msg) {
                        shareAdapter.notifyDataSetChanged();
                        Toast.makeText(mContext, shareStatusDisplay, Toast.LENGTH_SHORT).show();

                    }
                };
                shareBtn.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        final String shareWith = textView.getText().toString();

                        if (shareWith.equals("")) {
                            textView.setHint("Share With");
                            Toast.makeText(mContext,
                                    "Please enter the friends name with whom you want to share",
                                    Toast.LENGTH_SHORT).show();
                        } else if (sharedWith.contains(shareWith)) {
                            textView.setHint("Share With");
                            Toast.makeText(mContext, "You have shared the file with that person",
                                    Toast.LENGTH_SHORT).show();
                        } else {

                            textView.setText("");
                            Runnable runnable = new Runnable() {
                                @Override
                                public void run() {
                                    HttpPost post = new HttpPost(
                                            "http://" + url + "/owncloud/androidshare.php");
                                    final ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();

                                    params.add(new BasicNameValuePair("itemType", itemType));
                                    params.add(new BasicNameValuePair("itemSource", itemSource));
                                    params.add(new BasicNameValuePair("shareType", shareType));
                                    params.add(new BasicNameValuePair("shareWith", shareWith));
                                    params.add(new BasicNameValuePair("permission", permissions));
                                    params.add(new BasicNameValuePair("uidOwner", accountName));
                                    HttpEntity entity;
                                    String shareSuccess = "false";
                                    try {
                                        entity = new UrlEncodedFormEntity(params, "utf-8");
                                        HttpClient client = new DefaultHttpClient();
                                        post.setEntity(entity);
                                        HttpResponse response = client.execute(post);

                                        if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
                                            HttpEntity entityresponse = response.getEntity();
                                            String jsonentity = EntityUtils.toString(entityresponse);
                                            JSONObject obj = new JSONObject(jsonentity);
                                            shareSuccess = obj.getString("SHARE_STATUS");
                                            flagShare = 1;
                                            if (shareSuccess.equals("true")) {
                                                dataSourceShareFile.putNewShares(fileName, fileRemotePath,
                                                        accountName, shareWith);
                                                sharedWith.add(shareWith);
                                                shareStatusDisplay = "File share succeeded";
                                            } else if (shareSuccess.equals("INVALID_FILE")) {
                                                shareStatusDisplay = "File you are trying to share does not exist";
                                            } else if (shareSuccess.equals("INVALID_SHARETYPE")) {
                                                shareStatusDisplay = "File Share type is invalid";
                                            } else {
                                                shareStatusDisplay = "Share did not succeed. Please check your internet connection";
                                            }

                                            finishedHandler.sendEmptyMessage(flagShare);

                                        }
                                    } catch (Exception e) {
                                        e.printStackTrace();
                                    }

                                }
                            };
                            new Thread(runnable).start();

                        }

                        if (flagShare == 1) {
                        }

                    }

                });
                doneBtn.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        dialog.dismiss();
                        //dataSourceShareFile.close();
                    }
                });
            }

        });
        //dataSourceShareFile.close();
        if (!file.isDirectory()) {
            fileSizeV.setVisibility(View.VISIBLE);
            fileSizeV.setText(DisplayUtils.bytesToHumanReadable(file.getFileLength()));
            lastModV.setVisibility(View.VISIBLE);
            lastModV.setText(DisplayUtils.unixTimeToHumanReadable(file.getModificationTimestamp()));
            // this if-else is needed even thoe fav icon is visible by default
            // because android reuses views in listview
            if (!file.keepInSync()) {
                view.findViewById(R.id.imageView3).setVisibility(View.GONE);
            } else {
                view.findViewById(R.id.imageView3).setVisibility(View.VISIBLE);
            }

            ListView parentList = (ListView) parent;
            if (parentList.getChoiceMode() == ListView.CHOICE_MODE_NONE) {
                checkBoxV.setVisibility(View.GONE);
            } else {
                if (parentList.isItemChecked(position)) {
                    checkBoxV.setImageResource(android.R.drawable.checkbox_on_background);
                } else {
                    checkBoxV.setImageResource(android.R.drawable.checkbox_off_background);
                }
                checkBoxV.setVisibility(View.VISIBLE);
            }

        } else {

            fileSizeV.setVisibility(View.VISIBLE);
            fileSizeV.setText(DisplayUtils.bytesToHumanReadable(file.getFileLength()));
            lastModV.setVisibility(View.VISIBLE);
            lastModV.setText(DisplayUtils.unixTimeToHumanReadable(file.getModificationTimestamp()));
            checkBoxV.setVisibility(View.GONE);
            view.findViewById(R.id.imageView3).setVisibility(View.GONE);
        }
    }

    return view;
}