Example usage for android.app Dialog Dialog

List of usage examples for android.app Dialog Dialog

Introduction

In this page you can find the example usage for android.app Dialog Dialog.

Prototype

public Dialog(@NonNull Context context) 

Source Link

Document

Creates a dialog window that uses the default dialog theme.

Usage

From source file:com.ijsbrandslob.appirater.Appirater.java

private Dialog buildRatingDialog() {
    final Dialog rateDialog = new Dialog(mContext);
    final Resources res = mContext.getResources();

    CharSequence appname = "unknown";
    try {//w w w . ja  v a2  s.  com
        appname = mContext.getPackageManager().getApplicationLabel(
                mContext.getPackageManager().getApplicationInfo(mContext.getPackageName(), 0));
    } catch (NameNotFoundException ex) { /* Do nothing */
    }

    rateDialog.setTitle(String.format(res.getString(R.string.APPIRATER_MESSAGE_TITLE), appname));
    rateDialog.setContentView(R.layout.appirater);

    TextView messageArea = (TextView) rateDialog.findViewById(R.id.appirater_message_area);
    messageArea.setText(String.format(res.getString(R.string.APPIRATER_MESSAGE), appname));

    Button rateButton = (Button) rateDialog.findViewById(R.id.appirater_rate_button);
    Button remindLaterButton = (Button) rateDialog.findViewById(R.id.appirater_rate_later_button);
    Button cancelButton = (Button) rateDialog.findViewById(R.id.appirater_cancel_button);

    rateButton.setText(String.format(res.getString(R.string.APPIRATER_RATE_BUTTON), appname));

    rateButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            rateDialog.dismiss();

            mRatedCurrentVersion = true;
            saveSettings();
            launchPlayStore();
        }
    });

    remindLaterButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            mReminderRequestDate = new Date();
            saveSettings();
            rateDialog.dismiss();
        }
    });

    cancelButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            mDeclinedToRate = true;
            saveSettings();
            rateDialog.dismiss();
        }
    });
    return rateDialog;
}

From source file:com.phonegap.plugins.slaveBrowser.SlaveBrowser.java

/**
 * Display a new browser with the specified URL.
 *
 * @param url       The url to load./*from  w ww . ja va2  s . c  om*/
 * @param jsonObject 
 */
public String showWebPage(final String url, JSONObject options, String myNewTitle) {
    // Determine if we should hide the location bar.
    if (options != null) {
        showLocationBar = options.optBoolean("showLocationBar", true);
    }
    zeTitle = myNewTitle;

    // Create dialog in new thread 
    Runnable runnable = new Runnable() {
        public void run() {
            dialog = new Dialog(ctx.getContext());
            dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
            dialog.setCancelable(true);
            dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
                public void onDismiss(DialogInterface dialog) {
                    try {
                        JSONObject obj = new JSONObject();
                        obj.put("type", CLOSE_EVENT);
                        sendUpdate(obj, false);
                    } catch (JSONException e) {
                        Log.d(LOG_TAG, "Should never happen");
                    }
                }
            });

            LinearLayout.LayoutParams backParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                    LayoutParams.WRAP_CONTENT);
            LinearLayout.LayoutParams forwardParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                    LayoutParams.WRAP_CONTENT);
            LinearLayout.LayoutParams editParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                    LayoutParams.WRAP_CONTENT, 1.0f);
            LinearLayout.LayoutParams closeParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                    LayoutParams.WRAP_CONTENT);
            LinearLayout.LayoutParams wvParams = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
                    LayoutParams.FILL_PARENT);
            LinearLayout main = new LinearLayout(ctx.getContext());
            main.setOrientation(LinearLayout.VERTICAL);

            LinearLayout toolbar = new LinearLayout(ctx.getContext());
            toolbar.setOrientation(LinearLayout.HORIZONTAL);

            edittext = new TextView(ctx.getContext());
            edittext.setId(3);
            edittext.setSingleLine(true);
            edittext.setText(zeTitle);
            edittext.setTextSize(TypedValue.COMPLEX_UNIT_PX, 24);
            edittext.setGravity(Gravity.CENTER);
            edittext.setTextColor(Color.DKGRAY);
            edittext.setTypeface(Typeface.DEFAULT_BOLD);
            edittext.setLayoutParams(editParams);

            webview = new WebView(ctx.getContext());
            webview.getSettings().setJavaScriptEnabled(true);
            webview.getSettings().setBuiltInZoomControls(true);

            // dda: intercept calls to console.log
            webview.setWebChromeClient(new WebChromeClient() {
                public boolean onConsoleMessage(ConsoleMessage cmsg) {
                    // check secret prefix
                    if (cmsg.message().startsWith("MAGICHTML")) {
                        String msg = cmsg.message().substring(9); // strip off prefix
                        /* process HTML */
                        try {
                            JSONObject obj = new JSONObject();
                            obj.put("type", PAGE_LOADED);
                            obj.put("html", msg);
                            sendUpdate(obj, true);
                        } catch (JSONException e) {
                            Log.d(LOG_TAG, "This should never happen");
                        }
                        return true;
                    }
                    return false;
                }
            });

            // dda: inject the JavaScript on page load
            webview.setWebViewClient(new SlaveBrowserClient(edittext) {
                public void onPageFinished(WebView view, String address) {
                    // have the page spill its guts, with a secret prefix
                    view.loadUrl(
                            "javascript:console.log('MAGICHTML'+document.getElementsByTagName('html')[0].innerHTML);");
                }
            });

            webview.loadUrl(url);
            webview.setId(5);
            webview.setInitialScale(0);
            webview.setLayoutParams(wvParams);
            webview.requestFocus();
            webview.requestFocusFromTouch();

            toolbar.addView(edittext);

            if (getShowLocationBar()) {
                main.addView(toolbar);
            }
            main.addView(webview);

            WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
            lp.copyFrom(dialog.getWindow().getAttributes());
            lp.width = WindowManager.LayoutParams.FILL_PARENT;
            lp.height = WindowManager.LayoutParams.FILL_PARENT;

            dialog.setContentView(main);
            dialog.show();
            dialog.getWindow().setAttributes(lp);
        }

        private Bitmap loadDrawable(String filename) throws java.io.IOException {
            InputStream input = ctx.getAssets().open(filename);
            return BitmapFactory.decodeStream(input);
        }
    };
    this.ctx.runOnUiThread(runnable);
    return "";
}

From source file:com.entertailion.android.launcher.Dialogs.java

/**
 * Display about dialog to user when invoked from menu option.
 * /*from   www  . ja va 2s. com*/
 * @param context
 */
public static void displayAbout(final Launcher context) {
    final Dialog dialog = new Dialog(context);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setContentView(R.layout.about);

    Typeface lightTypeface = ((LauncherApplication) context.getApplicationContext()).getLightTypeface(context);

    TextView aboutTextView = (TextView) dialog.findViewById(R.id.about_text1);
    aboutTextView.setTypeface(lightTypeface);
    aboutTextView.setText(context.getString(R.string.about_version_title, Utils.getVersion(context)));
    aboutTextView.setOnLongClickListener(new OnLongClickListener() {

        @Override
        public boolean onLongClick(View v) {
            context.showCover(false);
            dialog.dismiss();
            Intent intent = new Intent(context, EasterEggActivity.class);
            context.startActivity(intent);
            Analytics.logEvent(Analytics.EASTER_EGG);
            return true;
        }

    });
    TextView copyrightTextView = (TextView) dialog.findViewById(R.id.copyright_text);
    copyrightTextView.setTypeface(lightTypeface);
    TextView feedbackTextView = (TextView) dialog.findViewById(R.id.feedback_text);
    feedbackTextView.setTypeface(lightTypeface);

    ((Button) dialog.findViewById(R.id.button_web)).setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setData(Uri.parse(context.getString(R.string.about_button_web_url)));
            context.startActivity(intent);
            Analytics.logEvent(Analytics.ABOUT_WEB_SITE);
            context.showCover(false);
            dialog.dismiss();
        }

    });

    ((Button) dialog.findViewById(R.id.button_privacy_policy)).setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setData(Uri.parse(context.getString(R.string.about_button_privacy_policy_url)));
            context.startActivity(intent);
            Analytics.logEvent(Analytics.ABOUT_PRIVACY_POLICY);
            context.showCover(false);
            dialog.dismiss();
        }

    });
    ((Button) dialog.findViewById(R.id.button_more_apps)).setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setData(Uri.parse(context.getString(R.string.about_button_more_apps_url)));
            context.startActivity(intent);
            Analytics.logEvent(Analytics.ABOUT_MORE_APPS);
            context.showCover(false);
            dialog.dismiss();
        }

    });
    dialog.setOnDismissListener(new OnDismissListener() {

        @Override
        public void onDismiss(DialogInterface dialog) {
            context.showCover(false);
        }

    });
    context.showCover(true);
    dialog.show();
    Analytics.logEvent(Analytics.DIALOG_ABOUT);
}

From source file:com.sentaroh.android.Utilities.Dialog.MessageDialogFragment.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    if (DEBUG_ENABLE)
        Log.v(APPLICATION_TAG, "onCreateDialog terminateRequired=" + terminateRequired);
    mDialog = new Dialog(getActivity());//, MiscUtil.getAppTheme(getActivity()));
    mDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    mDialog.setCanceledOnTouchOutside(false);

    if (!terminateRequired) {
        mThemeColorList = ThemeUtil.getThemeColorList(getActivity());
        initViewWidget();/*w  w w.  jav  a2s .  com*/
    }

    return mDialog;
}

From source file:com.pericstudio.drawit.activities.DashboardMainActivity.java

/**
 * Sets up the toolbar and the FAB./*w  w  w  .ja va2s .co  m*/
 */
private void setUpToolbar() {
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar,
            R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.setDrawerListener(toggle);
    toggle.syncState();

    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);

    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {

        TextView tvName;
        TextView tvDes;

        @Override
        public void onClick(View view) {
            final Dialog testDialog = new Dialog(DashboardMainActivity.this);
            testDialog.setTitle("TEST TITLE!");
            testDialog.setContentView(R.layout.dialog_test);

            tvName = (TextView) testDialog.findViewById(R.id.et_dialog_name);
            tvDes = (TextView) testDialog.findViewById(R.id.et_dialog_desciption);

            Button button = (Button) testDialog.findViewById(R.id.dialog_button);
            button.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    final String tvNameContent = tvName.getText().toString().trim();
                    final String tvDesContent = tvDes.getText().toString().trim();

                    final Drawing drawing = new Drawing(tvNameContent, tvDesContent);

                    drawing.save(getApplicationContext(), new Response.Listener<ObjectModificationResponse>() {
                        @Override
                        public void onResponse(ObjectModificationResponse modificationResponse) {
                            //code
                            List<String> idList = modificationResponse.getCreatedObjectIds();
                            final String drawingID = idList.get(0);

                            LocallySavableCMObject.searchObjects(getApplicationContext(),
                                    SearchQuery.filter("ownerID").equal(MyApplication.userID).searchQuery(),
                                    new Response.Listener<CMObjectResponse>() {
                                        @Override
                                        public void onResponse(CMObjectResponse response) {
                                            List<CMObject> userObject = response.getObjects();
                                            UserObjectIDs ids = (UserObjectIDs) userObject.get(0);
                                            ids.addInProgress(drawingID);
                                            MyApplication.setUserDataObject(ids);

                                            ids.save();

                                            T.showShortDebug(getApplicationContext(), "Refresh for update");

                                            testDialog.dismiss();

                                        }
                                    });

                        }
                    }, new Response.ErrorListener() {
                        @Override
                        public void onErrorResponse(VolleyError volleyError) {
                            //code
                        }
                    });

                }
            });
            testDialog.show();
        }
    });
}

From source file:com.refujiate.ui.MainMapaActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    Intent i;/*from   w  w w .  j av  a  2  s. c o  m*/
    switch (item.getItemId()) {
    case R.id.MnuOpc1:
        final CharSequence[] items = { "1 Kilometro", "5 Kilometros", "10 Kilometros", "Todos" };
        AlertDialog.Builder alert = new AlertDialog.Builder(this);
        alert.setTitle("Busqueda por Distancia:");
        alert.setItems(items, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int item) {
                Mostrar(item);
            }
        });
        alert.show();

        return true;
    case R.id.MnuOpc2:
        i = new Intent(this, MainActivity.class);
        i.putExtra("idTipoHotel", "0");
        i.putExtra("idServicio", "0");
        i.putExtra("puntaje", "0");
        i.putExtra("estrellas", "0");
        startActivity(i);
        return true;
    case R.id.MnuOpc3:
        clsPersona objPersona = clsPersonalSQL.Buscar(this);
        if (objPersona == null) {
            final Dialog dialog = new Dialog(this);
            dialog.setContentView(R.layout.activity_inicio_sesion);
            dialog.setTitle("Login");
            final EditText txtUsuario = (EditText) dialog.findViewById(R.id.txtUsuario);
            final EditText txtClave = (EditText) dialog.findViewById(R.id.txtClave);

            Button btnAceptar = (Button) dialog.findViewById(R.id.btnAceptar);
            btnAceptar.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    dialog.dismiss();
                    Login(txtUsuario.getText().toString(), txtClave.getText().toString());
                }
            });
            Button btnRegistrar = (Button) dialog.findViewById(R.id.btnRegistrar);
            btnRegistrar.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    dialog.dismiss();
                    Registrar();
                }
            });
            dialog.show();
        } else {
            i = new Intent(this, MenuActivity.class);
            startActivity(i);
            Toast.makeText(this, objPersona.getStr_Apellido() + " ," + objPersona.getStr_Nombre(),
                    Toast.LENGTH_SHORT).show();
        }
        return true;

    case R.id.MnuOpc4:
        i = new Intent(this, ConfiguracionActivity.class);
        i.putExtra("Frame", "" + false);
        startActivity(i);
        return true;

    case R.id.MnuOpc5:
        AlertDialog.Builder alert1 = new AlertDialog.Builder(this);
        alert1.setTitle("Desea Cerrar Sesin?");
        alert1.setPositiveButton("Aceptar", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {
                clsPersonalSQL.Borrar(MainMapaActivity.this);
                clsDetalleReservaSQL.Borrar(MainMapaActivity.this);
                clsComentarioSQL.Borrar(MainMapaActivity.this);

            }
        });
        alert1.setNegativeButton("Cancelar", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {
            }
        });
        alert1.show();
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:com.zapto.park.ParkActivity.java

public boolean onOptionsItemSelected(MenuItem item) {
    Intent i = null;//w  w  w .  j a va 2s  .  c om
    switch (item.getItemId()) {
    // Add User
    case 1:
        Dialog d = new Dialog(cActivity);
        final Dialog dialog = d;
        d.setContentView(R.layout.dialog_add_employee);
        d.setTitle(R.string.create_user_title);

        final EditText first_name = (EditText) d.findViewById(R.id.employee_first);
        final EditText last_name = (EditText) d.findViewById(R.id.employee_last);
        Button button_getinfo = (Button) d.findViewById(R.id.button_getinfo);

        button_getinfo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                EmployeeDB edb = new EmployeeDB(context);

                String first = first_name.getText().toString();
                String last = last_name.getText().toString();

                ContentValues cv = new ContentValues();
                cv.put("totable_first", first);
                cv.put("totable_last", last);
                cv.put("totable_license", Globals.LICENSE_KEY);

                // Log request in database.
                ContentValues cv2 = new ContentValues();
                cv2.put("first", first);
                cv2.put("last", last);

                // Query database.
                edb.insertEmployee(cv2);

                // Close our database.
                edb.close();

                dialog.dismiss();
            }
        });

        d.show();

        break;
    // Settings
    case 2:
        Log.i(LOG_TAG, "Settings menu clicked.");
        i = new Intent(this, SettingsActivity.class);
        startActivity(i);
        break;
    case 3:
        Log.i(LOG_TAG, "View Log Loading.");
        i = new Intent(this, ListViewActivity.class);
        startActivity(i);
        break;
    case 4:
        doInit();
        Handler handler = new Handler();
        handler.post(new Runnable() {
            @Override
            public void run() {
                updateEmployees();
                doPendingRequests();
            }
        });
        break;
    case 5:
        Log.i(LOG_TAG, "SendEmailActivity Loading.");
        i = new Intent(this, SendEmailActivity.class);
        startActivity(i);
        break;
    case 6:
        Log.i(LOG_TAG, "View Log Loading.");
        i = new Intent(this, ListViewActivity.class);
        startActivity(i);
        break;
    }

    return true;
}

From source file:com.svpino.longhorn.activities.DashboardActivity.java

private void performSearch(String query) {
    this.stockListFragment.hideContextualActionBar();
    Cursor cursor = DataProvider.search(getApplicationContext(), query);

    if (this.searchDialog == null || !this.searchDialog.isShowing()) {
        this.searchDialog = new Dialog(this);
        this.searchDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        this.searchDialog.setContentView(R.layout.dialog);

        TextView messageTextView = (TextView) this.searchDialog.findViewById(R.id.messageTextView);
        TextView titleTextView = (TextView) this.searchDialog.findViewById(R.id.titleTextView);

        ListView listView = (ListView) this.searchDialog.findViewById(R.id.listView);

        if (cursor != null && cursor.getCount() > 0) {
            titleTextView.setText(String.format(getString(R.string.dialog_search_title), query));
            messageTextView.setVisibility(View.GONE);

            String[] from = new String[] { SearchManager.SUGGEST_COLUMN_TEXT_1,
                    SearchManager.SUGGEST_COLUMN_TEXT_2, LonghornDatabase.KEY_EXCHANGE_SYMBOL };
            int[] to = new int[] { R.id.nameTextView, R.id.descriptionTextView, R.id.additionalTextView };

            SimpleCursorAdapter adapter = new SimpleCursorAdapter(getApplicationContext(), R.layout.dialog_item,
                    cursor, from, to, 0);
            adapter.setViewBinder(new ViewBinder() {

                @Override/*from   w  ww. j ava2s.c  om*/
                public boolean setViewValue(View view, Cursor cursor, int columnIndex) {

                    if (columnIndex == 0) {
                        ((View) view.getParent()).setTag(cursor.getString(columnIndex));
                    }

                    return false;
                }
            });

            listView.setAdapter(adapter);

            listView.setOnItemClickListener(new OnItemClickListener() {

                @Override
                public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
                    Cursor cursor = (Cursor) adapterView.getItemAtPosition(position);
                    addStockToWatchList(cursor.getString(0));
                    DashboardActivity.this.searchDialog.dismiss();
                }
            });
        } else {
            titleTextView.setText(getString(R.string.dialog_search_empty_title));
            messageTextView.setText(String.format(getString(R.string.dialog_search_empty_message), query));
            messageTextView.setVisibility(View.VISIBLE);
            listView.setVisibility(View.GONE);
        }

        this.searchDialog.show();
    }
}

From source file:com.facebook.samples.sessionlogin.LoginUsingActivityActivity.java

public void showDialog() {
    final Dialog dialog = new Dialog(LoginUsingActivityActivity.this);
    dialog.setContentView(R.layout.list_view_contact);
    dialog.setTitle("Pic Number");
    ListView listView = (ListView) dialog.findViewById(R.id.lc_contacts);

    ArrayAdapter<String> adapter = new ArrayAdapter<String>(getApplicationContext(), R.layout.spinner_row_view,
            list);/*from   w  w  w.  j a  va2  s .  co  m*/
    listView.setAdapter(adapter);

    dialog.show();
    /*DisplayMetrics metrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(metrics);
            
    dialog.getWindow().setLayout(metrics.heightPixels, metrics.widthPixels);*/
}

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

@Override
public View getView(final int position, View convertView, ViewGroup parent) {
    View view = convertView;//w  w w. ja  v a  2 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;
}