Example usage for android.content.res AssetManager open

List of usage examples for android.content.res AssetManager open

Introduction

In this page you can find the example usage for android.content.res AssetManager open.

Prototype

public @NonNull InputStream open(@NonNull String fileName) throws IOException 

Source Link

Document

Open an asset using ACCESS_STREAMING mode.

Usage

From source file:com.ideateam.plugin.Version.java

private String getCurrentVersionWWW() {
    AssetManager am = activity.getAssets();
    InputStream reader = null;/*from   w  w  w.  j av  a  2s. co m*/
    String version = "";

    //Get version from APK's assets folder
    //zip with updates not founded 

    try {
        reader = am.open("www/index.html");
        BufferedReader r = new BufferedReader(new InputStreamReader(reader));

        String line;
        while ((line = r.readLine()) != null) {
            if (line.indexOf("src=\"app.js?") != -1) {
                int start = line.indexOf("?");
                int end = line.lastIndexOf("-");

                version = line.substring(start + 1, end);

                break;
            }
        }

    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } finally {
        if (reader != null) {
            try {
                reader.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }

    return version;
}

From source file:de.syss.MifareClassicTool.Activities.MainMenu.java

/**
 * Copy the standard key files ({@link Common#STD_KEYS} and
 * {@link Common#STD_KEYS_EXTENDED}) form assets to {@link Common#KEYS_DIR}.
 * Key files are simple text files. Any plain text editor will do the trick.
 * All key and dump data from this App is stored in
 * getExternalStoragePublicDirectory(Common.HOME_DIR) to remain
 * there after App uninstallation./*  w w  w . j  ava2s .  c o  m*/
 * @see Common#KEYS_DIR
 * @see Common#HOME_DIR
 * @see Common#copyFile(InputStream, OutputStream)
 */
private void copyStdKeysFilesIfNecessary() {
    File std = new File(Environment.getExternalStoragePublicDirectory(Common.HOME_DIR) + "/" + Common.KEYS_DIR,
            Common.STD_KEYS);
    File extended = new File(
            Environment.getExternalStoragePublicDirectory(Common.HOME_DIR) + "/" + Common.KEYS_DIR,
            Common.STD_KEYS_EXTENDED);
    AssetManager assetManager = getAssets();

    if (!std.exists()) {
        // Copy std.keys.
        try {
            InputStream in = assetManager.open(Common.KEYS_DIR + "/" + Common.STD_KEYS);
            OutputStream out = new FileOutputStream(std);
            Common.copyFile(in, out);
            in.close();
            out.flush();
            out.close();
        } catch (IOException e) {
            Log.e(LOG_TAG, "Error while copying 'std.keys' from assets " + "to external storage.");
        }
    }
    if (!extended.exists()) {
        // Copy extended-std.keys.
        try {
            InputStream in = assetManager.open(Common.KEYS_DIR + "/" + Common.STD_KEYS_EXTENDED);
            OutputStream out = new FileOutputStream(extended);
            Common.copyFile(in, out);
            in.close();
            out.flush();
            out.close();
        } catch (IOException e) {
            Log.e(LOG_TAG, "Error while copying 'extended-std.keys' " + "from assets to external storage.");
        }
    }
}

From source file:org.adblockplus.android.Preferences.java

/**
 * Copies file assets from installation package to filesystem.
 */// w  w  w  . j  a va  2s  .  com
private void copyAssets() {
    final AssetManager assetManager = getAssets();
    String[] files = null;
    try {
        files = assetManager.list("install");
    } catch (final IOException e) {
        Log.e(TAG, "Failed to get assets list", e);
    }
    for (int i = 0; i < files.length; i++) {
        try {
            Log.d(TAG, "Copy: install/" + files[i]);
            final InputStream in = assetManager.open("install/" + files[i]);
            final OutputStream out = openFileOutput(files[i], MODE_PRIVATE);
            final byte[] buffer = new byte[1024];
            int read;
            while ((read = in.read(buffer)) != -1) {
                out.write(buffer, 0, read);
            }
            in.close();
            out.flush();
            out.close();
        } catch (final Exception e) {
            Log.e(TAG, "Asset copy error", e);
        }
    }
}

From source file:net.zjy.zxcardumper.Activities.MainMenu.java

/**
 * Copy the standard key files ({@link Common#STD_KEYS} and
 * {@link Common#STD_KEYS_EXTENDED}) form assets to {@link Common#KEYS_DIR}.
 * Key files are simple text files. Any plain text editor will do the trick.
 * All key and dump data from this App is stored in
 * getExternalStoragePublicDirectory(Common.HOME_DIR) to remain
 * there after App uninstallation.//from  w  w w .  j a v  a2  s.  co m
 * @see Common#KEYS_DIR
 * @see Common#HOME_DIR
 * @see Common#copyFile(InputStream, OutputStream)
 */
private void copyStdKeysFilesIfNecessary() {
    File std = new File(Environment.getExternalStoragePublicDirectory(Common.HOME_DIR) + "/" + Common.KEYS_DIR,
            Common.STD_KEYS);
    /*File extended = new File(Environment.getExternalStoragePublicDirectory(
        Common.HOME_DIR) + "/" + Common.KEYS_DIR,
        Common.STD_KEYS_EXTENDED);*/
    AssetManager assetManager = getAssets();

    if (!std.exists()) {
        // Copy zx.keys.
        try {
            InputStream in = assetManager.open("key-files/zx.keys");
            OutputStream out = new FileOutputStream(std);
            Common.copyFile(in, out);
            in.close();
            out.flush();
            out.close();
        } catch (IOException e) {
            Log.e(LOG_TAG, "Error while copying 'zx.keys' from assets " + "to external storage.");
            e.printStackTrace();
        }
    }
    /*if (!extended.exists()) {
    // Copy extended-zx.keys.
    try {
        InputStream in = assetManager.open(
                Common.KEYS_DIR + "/" + Common.STD_KEYS_EXTENDED);
        OutputStream out = new FileOutputStream(extended);
        Common.copyFile(in, out);
        in.close();
        out.flush();
        out.close();
      } catch(IOException e) {
          Log.e(LOG_TAG, "Error while copying 'extended-zx.keys' "
                  + "from assets to external storage.");
      }
    }*/
}

From source file:com.appsimobile.appsii.timezonepicker.TimeZoneData.java

private HashSet<String> loadTzsInZoneTab(Context context) {
    HashSet<String> processedTimeZones = new HashSet<>();
    AssetManager am = context.getAssets();
    InputStream is = null;//from   ww w  .  ja v  a 2 s .  c o m

    /*
     * The 'backward' file contain mappings between new and old time zone
     * ids. We will explicitly ignore the old ones.
     */
    try {
        is = am.open("backward");
        BufferedReader reader = new BufferedReader(new InputStreamReader(is));
        String line;

        while ((line = reader.readLine()) != null) {
            // Skip comment lines
            if (!line.startsWith("#") && line.length() > 0) {
                // 0: "Link"
                // 1: New tz id
                // Last: Old tz id
                String[] fields = line.split("\t+");
                String newTzId = fields[1];
                String oldTzId = fields[fields.length - 1];

                final TimeZone tz = TimeZone.getTimeZone(newTzId);
                if (tz == null) {
                    Log.e(TAG, "Timezone not found: " + newTzId);
                    continue;
                }

                processedTimeZones.add(oldTzId);

                if (DEBUG) {
                    Log.e(TAG, "# Dropping identical time zone from backward: " + oldTzId);
                }

                // Remember the cooler/newer time zone id
                if (mDefaultTimeZoneId != null && mDefaultTimeZoneId.equals(oldTzId)) {
                    mAlternateDefaultTimeZoneId = newTzId;
                }
            }
        }
    } catch (IOException ex) {
        Log.e(TAG, "Failed to read 'backward' file.");
    } finally {
        try {
            if (is != null) {
                is.close();
            }
        } catch (IOException ignored) {
        }
    }

    /*
     * zone.tab contains a list of time zones and country code. They are
     * "sorted first by country, then an order within the country that (1)
     * makes some geographical sense, and (2) puts the most populous zones
     * first, where that does not contradict (1)."
     */
    try {
        String lang = Locale.getDefault().getLanguage();
        is = am.open("zone.tab");
        BufferedReader reader = new BufferedReader(new InputStreamReader(is));
        String line;
        while ((line = reader.readLine()) != null) {
            if (!line.startsWith("#")) { // Skip comment lines
                // 0: country code
                // 1: coordinates
                // 2: time zone id
                // 3: comments
                final String[] fields = line.split("\t");
                final String timeZoneId = fields[2];
                final String countryCode = fields[0];
                final TimeZone tz = TimeZone.getTimeZone(timeZoneId);
                if (tz == null) {
                    Log.e(TAG, "Timezone not found: " + timeZoneId);
                    continue;
                }

                /*
                 * Dropping non-GMT tzs without a country code. They are not
                 * really needed and they are dups but missing proper
                 * country codes. e.g. WET CET MST7MDT PST8PDT Asia/Khandyga
                 * Asia/Ust-Nera EST
                 */
                if (countryCode == null && !timeZoneId.startsWith("Etc/GMT")) {
                    processedTimeZones.add(timeZoneId);
                    continue;
                }

                // Remember the mapping between the country code and display
                // name
                String country = mCountryCodeToNameMap.get(countryCode);
                if (country == null) {
                    country = getCountryNames(lang, countryCode);
                    mCountryCodeToNameMap.put(countryCode, country);
                }

                // TODO Don't like this here but need to get the country of
                // the default tz.

                // Find the country of the default tz
                if (mDefaultTimeZoneId != null && mDefaultTimeZoneCountry == null
                        && timeZoneId.equals(mAlternateDefaultTimeZoneId)) {
                    mDefaultTimeZoneCountry = country;
                    TimeZone defaultTz = TimeZone.getTimeZone(mDefaultTimeZoneId);
                    if (defaultTz != null) {
                        mDefaultTimeZoneInfo = new TimeZoneInfo(defaultTz, country);

                        int tzToOverride = getIdenticalTimeZoneInTheCountry(mDefaultTimeZoneInfo);
                        if (tzToOverride == -1) {
                            if (DEBUG) {
                                Log.e(TAG, "Adding default time zone: " + mDefaultTimeZoneInfo.toString());
                            }
                            mTimeZones.add(mDefaultTimeZoneInfo);
                        } else {
                            mTimeZones.add(tzToOverride, mDefaultTimeZoneInfo);
                            if (DEBUG) {
                                TimeZoneInfo tzInfoToOverride = mTimeZones.get(tzToOverride);
                                String tzIdToOverride = tzInfoToOverride.mTzId;
                                Log.e(TAG, "Replaced by default tz: " + tzInfoToOverride.toString());
                                Log.e(TAG, "Adding default time zone: " + mDefaultTimeZoneInfo.toString());
                            }
                        }
                    }
                }

                // Add to the list of time zones if the time zone is unique
                // in the given country.
                TimeZoneInfo timeZoneInfo = new TimeZoneInfo(tz, country);
                int identicalTzIdx = getIdenticalTimeZoneInTheCountry(timeZoneInfo);
                if (identicalTzIdx == -1) {
                    if (DEBUG) {
                        Log.e(TAG, "# Adding time zone: " + timeZoneId + " ## " + tz.getDisplayName());
                    }
                    mTimeZones.add(timeZoneInfo);
                } else {
                    if (DEBUG) {
                        Log.e(TAG,
                                "# Dropping identical time zone: " + timeZoneId + " ## " + tz.getDisplayName());
                    }
                }
                processedTimeZones.add(timeZoneId);
            }
        }

    } catch (IOException ex) {
        Log.e(TAG, "Failed to read 'zone.tab'.");
    } finally {
        try {
            if (is != null) {
                is.close();
            }
        } catch (IOException ignored) {
        }
    }

    return processedTimeZones;
}

From source file:org.runnerup.view.MainLayout.java

void handleBundled(AssetManager mgr, String srcBase, String dstBase) {
    String list[] = null;//ww w.  j  a  v a2 s  .com

    try {
        list = mgr.list(srcBase);
    } catch (IOException e) {
        e.printStackTrace();
    }
    if (list != null) {
        for (String add : list) {
            boolean isFile = false;

            String src = srcBase + File.separator + add;
            String dst = dstBase + File.separator + add;
            try {
                InputStream is = mgr.open(src);
                is.close();
                isFile = true;
            } catch (Exception ex) {
                //Normal, src is directory for first call
            }

            Log.v(getClass().getName(), "Found: " + src + ", " + dst + ", isFile: " + isFile);

            if (!isFile) {
                //The request is hierarchical, source is still on a directory level
                File dstDir = new File(dstBase);
                dstDir.mkdir();
                if (!dstDir.isDirectory()) {
                    Log.w(getClass().getName(),
                            "Failed to copy " + src + " as \"" + dstBase + "\" is not a directory!");
                    continue;
                }
                handleBundled(mgr, src, dst);
            } else {
                //Source is a file, ready to copy
                File dstFile = new File(dst);
                if (dstFile.isDirectory() || dstFile.isFile()) {
                    Log.v(getClass().getName(), "Skip: " + dst + ", isDirectory(): " + dstFile.isDirectory()
                            + ", isFile(): " + dstFile.isFile());
                    continue;
                }

                //Only copy if the key do not exist already
                String key = "install_bundled_" + add;
                SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this);
                if (pref.contains(key)) {
                    Log.v(getClass().getName(), "Skip already existing pref: " + key);
                    continue;
                }

                pref.edit().putBoolean(key, true).commit();

                Log.v(getClass().getName(), "Copying: " + dst);
                InputStream input = null;
                try {
                    input = mgr.open(src);
                    FileUtil.copy(input, dst);
                    handleHooks(add);
                } catch (IOException e) {
                    e.printStackTrace();
                } finally {
                    FileUtil.close(input);
                }
            }
        }
    }
}

From source file:joshuamgoodwin.gmail.com.ohiolegalaidassistant.MainActivity.java

private void selectItem(String groupName, int groupPosition, int childPosition, String childName) {
    // update the main content by replacing fragments
    Fragment fragmentName = new Welcome();
    ActionMenuItemView search = (ActionMenuItemView) findViewById(R.id.action_search);
    //search.setVisibility(View.INVISIBLE);
    String tag = "WELCOME";
    Bundle bundle = new Bundle();
    boolean welcomeVisible = false;
    // Welcome welcome = (Welcome)getFragmentManager().findFragmentByTag("WELCOME");
    // if (welcome.isVisible()) welcomeVisible = true;
    if (groupName.equals("Calculators")) {
        if (childName.equals(getString(R.string.OWF_calculator))) {
            fragmentName = new OwfCalculator();
            tag = "OWF_CALCULATOR";
        } else if (childName.equals(getString(R.string.federal_poverty))) {
            fragmentName = new FplCalculatorController();
            tag = "FPL_CALCULATOR";
        } else if (childName.equals(getString(R.string.food_stamps))) {
            fragmentName = new FsCalculator();
            tag = "FS_CALCULATOR";
        } else if (childName.equals(getString(R.string.child_support))) {
            String url = "https://www.lawhelpinteractive.org/login_form?template_id=template.2014-06-05.4419790386&set_language=en";
            Intent i = new Intent(Intent.ACTION_VIEW);
            i.setData(Uri.parse(url));/*w w  w.j a v a 2 s .c o  m*/
            startActivity(i);
        } else if (childName.equals(getString(R.string.APR))) {
            fragmentName = new APRCalculator();
            tag = "APR";
        } else if (childName.equals(getString(R.string.ACACalculator))) {
            fragmentName = new ACACalculator();
            tag = "ACA";
        } else if (childName.equals("Garnishment")) {
            fragmentName = new GarnishmentCalculator();
            tag = "GARNISHMENT";
        } else {
            fragmentName = new Welcome();
        }
    } else if (groupName.equals("Court Dockets")) {
        tag = "WEBVIEW";
        if (childName.equals(getString(R.string.edit_courts))) {
            fragmentName = new ShowCourtsFragment();
        } else {
            CourtSitesDAO dao = new CourtSitesDAO(this);

            String address = dao.addressFromName(childName);
            bundle = new Bundle();
            bundle.putString("address", address);
            fragmentName = new WebViewFragment();
            fragmentName.setArguments(bundle);

        }
    } else if (groupName.equals("Rules")) {
        fragmentName = new RulesFragment();
        //search.setVisibility(View.VISIBLE);
        tag = "RULES";
        if (childName.equals("Federal Rules of Evidence")) {
            bundle.putString("ruleSet", "fre_by_rule");
        }
        if (childName.equals("Federal Rules of Civil Procedure")) {
            bundle.putString("ruleSet", "federal_rules_cp");
        }
        if (childName.equals("Ohio Rules of Civil Procedure")) {
            bundle.putString("ruleSet", "ohio_rules_cp");
        }
        if (childName.equals("Ohio Rules of Evidence")) {
            bundle.putString("ruleSet", "ohio_rules_evidence");
        }
        if (childName.equals("Ohio Rules of Juvenile Procedure")) {
            bundle.putString("ruleSet", "ohio_rules_juvenile");
        }
        if (childName.equals("Ohio Rules of Appellate Procedure")) {
            bundle.putString("ruleSet", "ohio_appellate_rules");
        }
        fragmentName.setArguments(bundle);
    } else if (groupName.equals("About")) {
        fragmentName = new AboutFragment();
        tag = "ABOUT";
    } else if (groupName.equals("License")) {
        fragmentName = new LicenseFragment();
        tag = "LICENSE";
    } else if (groupName.equals("Forms")) {
        if (childName.equals("Exemption List")) {
            CopyAssets("exemption.pdf");
        } else if (childName.equals("Standards Help Sheet")) {
            CopyAssets("standards_help_sheet.pdf");
        } else if (childName.equals("Edit/Add Forms")) {
            fragmentName = new ShowFormsFragment();
            tag = "ADD FORMS";
        } else {
            FormsDAO formsDao = new FormsDAO(this);
            String fileName = formsDao.addressFromName(childName);
            File file = new File(fileName);
            AssetManager am = getAssets();
            InputStream in = null;
            OutputStream out = null;
            try {
                in = am.open(fileName);
                out = openFileOutput(file.getName(), Context.MODE_WORLD_READABLE);
                copyFile(in, out);
                in.close();
                in = null;
                out.close();
                out = null;
            } catch (Exception e) {
                Log.e("tag", e.getMessage());
            }

            Intent intent = new Intent(Intent.ACTION_VIEW);
            String ext = formsDao.extensionFromName(childName);
            String type;
            if (ext.equals("doc") || ext.equals("docx")) {
                // Word document
                type = "application/msword";
            } else if (ext.equals("pdf")) {
                // PDF file
                type = "application/pdf";
            } else if (ext.equals("ppt") || ext.equals("pptx")) {
                // Powerpoint file
                type = "application/vnd.ms-powerpoint";
            } else if (ext.equals("xls") || ext.equals("xlsx")) {
                // Excel file
                type = "application/vnd.ms-excel";
            } else if (ext.equals("zip") || ext.equals("rar")) {
                // WAV audio file
                type = "application/x-wav";
            } else if (ext.equals("rtf")) {
                // RTF file
                type = "application/rtf";
            } else if (ext.equals("wav") || ext.equals("mp3")) {
                // WAV audio file
                type = "audio/x-wav";
            } else if (ext.equals("gif")) {
                // GIF file
                type = "image/gif";
            } else if (ext.equals("jpg") || ext.equals("jpeg") || ext.equals("png")) {
                // JPG file
                type = "image/jpeg";
            } else if (ext.equals("txt")) {
                // Text file
                type = "text/plain";
            } else if (ext.equals("3gp") || ext.equals("mpg") || ext.equals("mpeg") || ext.equals("mpe")
                    || ext.equals("mp4") || ext.equals("avi")) {
                // Video files
                type = "video/*";
            } else {
                //if you want you can also define the intent type for any other file

                //additionally use else clause below, to manage other unknown extensions
                //in this case, Android will show all applications installed on the device
                //so you can choose which application to use
                type = "*/*";
            }

            intent.setDataAndType(Uri.parse("file://" + fileName), type);
            startActivity(intent);
        }
    } else if (groupName.equals("Negotiations")) {
        if (childName.equals(getString(R.string.add_negotiations))) {
            fragmentName = new ShowNegotiationsFragment();
            tag = "Negotiations";
        }
    } else {
        fragmentName = new Welcome();
    }

    setFragment(fragmentName, tag);

    // update selected item and title, then close the drawer
    LinearLayout mDrawerContent = (LinearLayout) findViewById(R.id.left_drawer);
    mDrawerList.setItemChecked(childPosition, true);
    if (groupName.equals("About")) {
        setTitle("About");
    } else if (groupName.equals("License")) {
        setTitle("License");
    } else {
        setTitle(listDataChild.get(listDataHeader.get(groupPosition)).get(childPosition));
    }
    mDrawerLayout.closeDrawer(mDrawerContent);

}

From source file:com.orange.ocara.ui.activity.BaseActivity.java

/**
 * Show help item clicked.//from   ww w  .  j av  a  2s.  c  o m
 */

protected void showHelp(String pdfName) {
    AssetManager assetManager = getAssets();
    InputStream inputStream = null;
    OutputStream outputStream = null;
    String locale = Locale.getDefault().getLanguage();
    String folder;
    if (locale.equals("en")) {
        folder = "pdf/";
    } else {
        folder = "pdf-" + locale + "/";
    }
    Timber.v("locale " + locale + " folder " + folder);

    File file = new File(getFilesDir(), pdfName);

    try {
        inputStream = assetManager.open(folder + pdfName);

        viewFile(inputStream, outputStream, file, pdfName);
    } catch (Exception e) {
        Log.e("tag", e.getMessage());
        try {
            inputStream = assetManager.open("pdf/" + pdfName);
            viewFile(inputStream, outputStream, file, pdfName);

        } catch (Exception a) {
            Log.e("tag", a.getMessage());
        }

    }
}

From source file:org.catrobat.catroid.ui.MainMenuActivity.java

private void copyProgramZip() {
    AssetManager assetManager = getResources().getAssets();
    String[] files = null;/* w  ww  . jav  a  2  s  .co m*/
    try {
        files = assetManager.list("");
    } catch (IOException e) {
        Log.e("STANDALONE", "Failed to get asset file list.", e);
    }
    for (String filename : files) {
        if (filename.contains(ZIP_FILE_NAME)) {
            InputStream in;
            OutputStream out;
            try {
                in = assetManager.open(filename);
                File outFile = new File(Constants.DEFAULT_ROOT, filename);
                out = new FileOutputStream(outFile);
                copyFile(in, out);
                out.flush();
                out.close();
                in.close();
            } catch (IOException e) {
                Log.e("STANDALONE", "Failed to copy asset file: " + filename, e);
            }
        }
    }
}

From source file:com.ibuildapp.romanblack.MultiContactsPlugin.ContactDetailsActivity.java

@Override
public void create() {
    try {//w  w  w.j a va2  s .  c om
        setContentView(R.layout.grouped_contacts_details);

        Intent currentIntent = getIntent();
        Bundle store = currentIntent.getExtras();
        widget = (Widget) store.getSerializable("Widget");
        if (widget == null) {
            handler.sendEmptyMessageDelayed(INITIALIZATION_FAILED, 100);
            return;
        }

        person = (Person) store.getSerializable("person");
        if (person == null) {
            handler.sendEmptyMessageDelayed(INITIALIZATION_FAILED, 100);
            return;
        }
        setTopBarTitle(widget.getTitle());

        Boolean single = currentIntent.getBooleanExtra("single", true);

        setTopBarLeftButtonTextAndColor(
                single ? getResources().getString(R.string.common_home_upper)
                        : getResources().getString(R.string.common_back_upper),
                getResources().getColor(android.R.color.black), true, new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        finish();
                    }
                });
        setTopBarTitleColor(getResources().getColor(android.R.color.black));
        setTopBarBackgroundColor(Statics.color1);

        if ((Boolean.TRUE.equals(widget.getParameter(PARAM_SEND_MAIL)))
                || (Boolean.TRUE.equals(widget.getParameter(PARAM_SEND_SMS)))
                || (Boolean.TRUE.equals(widget.getParameter(PARAM_SEND_SMS)))) {

            ImageView shareButton = (ImageView) getLayoutInflater()
                    .inflate(R.layout.grouped_contacts_share_button, null);
            shareButton.setLayoutParams(
                    new LinearLayout.LayoutParams((int) (29 * getResources().getDisplayMetrics().density),
                            (int) (39 * getResources().getDisplayMetrics().density)));
            shareButton.setColorFilter(Color.BLACK);
            setTopBarRightButton(shareButton, getString(R.string.multicontacts_list_share),
                    new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            DialogSharing.Configuration.Builder sharingDialogBuilder = new DialogSharing.Configuration.Builder();

                            if (Boolean.TRUE.equals(widget.getParameter(PARAM_SEND_MAIL)))
                                sharingDialogBuilder
                                        .setEmailSharingClickListener(new DialogSharing.Item.OnClickListener() {
                                            @Override
                                            public void onClick() {
                                                String message = getContactInfo();
                                                Intent email = new Intent(Intent.ACTION_SEND);
                                                email.putExtra(Intent.EXTRA_TEXT, message);
                                                email.setType("message/rfc822");
                                                startActivity(Intent.createChooser(email,
                                                        getString(R.string.choose_email_client)));
                                            }
                                        });

                            if (Boolean.TRUE.equals(widget.getParameter(PARAM_SEND_SMS)))
                                sharingDialogBuilder
                                        .setSmsSharingClickListener(new DialogSharing.Item.OnClickListener() {
                                            @Override
                                            public void onClick() {
                                                String message = getContactInfo();

                                                try {
                                                    Utils.sendSms(ContactDetailsActivity.this, message);
                                                } catch (ActivityNotFoundException e) {
                                                    e.printStackTrace();
                                                }
                                            }
                                        });

                            if (Boolean.TRUE.equals(widget.getParameter(PARAM_ADD_CONTACT)))
                                sharingDialogBuilder.addCustomListener(R.string.multicontacts_add_to_phonebook,
                                        R.drawable.gc_add_to_contacts, true,
                                        new DialogSharing.Item.OnClickListener() {
                                            @Override
                                            public void onClick() {
                                                createNewContact(person.getName(), person.getPhone(),
                                                        person.getEmail());
                                            }
                                        });

                            showDialogSharing(sharingDialogBuilder.build());
                        }
                    });

        }

        boolean hasSchema = store.getBoolean("hasschema");
        cachePath = widget.getCachePath() + "/contacts-" + widget.getOrder();

        contacts = person.getContacts();

        if (widget.getTitle().length() > 0) {
            setTitle(widget.getTitle());
        }

        root = (LinearLayout) findViewById(R.id.grouped_contacts_details_root);

        if (hasSchema) {
            root.setBackgroundColor(Statics.color1);
        } else if (widget.isBackgroundURL()) {
            cacheBackgroundFile = cachePath + "/" + Utils.md5(widget.getBackgroundURL());
            File backgroundFile = new File(cacheBackgroundFile);
            if (backgroundFile.exists()) {
                root.setBackgroundDrawable(
                        new BitmapDrawable(BitmapFactory.decodeStream(new FileInputStream(backgroundFile))));
            } else {
                BackgroundDownloadTask dt = new BackgroundDownloadTask();
                dt.execute(widget.getBackgroundURL());
            }
        } else if (widget.isBackgroundInAssets()) {
            AssetManager am = this.getAssets();
            root.setBackgroundDrawable(new BitmapDrawable(am.open(widget.getBackgroundURL())));
        }

        if (contacts != null) {
            ImageView avatarImage = (ImageView) findViewById(R.id.grouped_contacts_details_avatar);

            avatarImage.setImageResource(R.drawable.gc_profile_avatar);
            if (person.hasAvatar() && NetworkUtils.isOnline(this)) {
                avatarImage.setVisibility(View.VISIBLE);
                Glide.with(this).load(person.getAvatarUrl()).placeholder(R.drawable.gc_profile_avatar)
                        .dontAnimate().into(avatarImage);
            } else {
                avatarImage.setVisibility(View.VISIBLE);
                avatarImage.setImageResource(R.drawable.gc_profile_avatar);
            }

            String name = "";
            neededContacts = new ArrayList<>();
            for (Contact con : contacts) {
                if ((con.getType() == 5) || (con.getDescription().length() == 0)) {
                } else {
                    if (con.getType() == 0) {
                        name = con.getDescription();
                    } else
                        neededContacts.add(con);
                }
            }

            if (neededContacts.isEmpty()) {
                handler.sendEmptyMessage(THERE_IS_NO_CONTACT_DATA);
                return;
            }

            headSeparator = findViewById(R.id.gc_head_separator);
            bottomSeparator = findViewById(R.id.gc_bottom_separator);
            imageBottom = findViewById(R.id.gc_image_bottom_layout);
            personName = (TextView) findViewById(R.id.gc_details_description);

            if ("".equals(name))
                personName.setVisibility(View.GONE);
            else {
                personName.setVisibility(View.VISIBLE);
                personName.setText(name);
                personName.setTextColor(Statics.color3);
            }
            if (Statics.isLight) {
                headSeparator.setBackgroundColor(Color.parseColor("#4d000000"));
                bottomSeparator.setBackgroundColor(Color.parseColor("#4d000000"));
            } else {
                headSeparator.setBackgroundColor(Color.parseColor("#4dFFFFFF"));
                bottomSeparator.setBackgroundColor(Color.parseColor("#4dFFFFFF"));
            }

            ViewUtils.setBackgroundLikeHeader(imageBottom, Statics.color1);

            ListView list = (ListView) findViewById(R.id.grouped_contacts_details_list_view);
            list.setDivider(null);

            ContactDetailsAdapter adapter = new ContactDetailsAdapter(ContactDetailsActivity.this,
                    R.layout.grouped_contacts_details_item, neededContacts, isChemeDark(Statics.color1));
            list.setAdapter(adapter);
            list.setOnItemClickListener(new OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> arg0, View view, int position, long id) {
                    listViewItemClick(position);
                }
            });
        }

        if (widget.hasParameter("add_contact")) {
            HashMap<String, String> hm = new HashMap<>();
            for (int i = 0; i < contacts.size(); i++) {
                switch (contacts.get(i).getType()) {
                case 0: {
                    hm.put("contactName", contacts.get(i).getDescription());
                }
                    break;
                case 1: {
                    hm.put("contactNumber", contacts.get(i).getDescription());
                }
                    break;
                case 2: {
                    hm.put("contactEmail", contacts.get(i).getDescription());
                }
                    break;
                case 3: {
                    hm.put("contactSite", contacts.get(i).getDescription());
                }
                    break;
                }
            }
            addNativeFeature(NATIVE_FEATURES.ADD_CONTACT, null, hm);
        }
        if (widget.hasParameter("send_sms")) {
            HashMap<String, String> hm = new HashMap<>();
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < contacts.size(); i++) {
                sb.append(contacts.get(i).getDescription());
                if (i < contacts.size() - 1) {
                    sb.append(", ");
                }
            }
            hm.put("text", sb.toString());
            addNativeFeature(NATIVE_FEATURES.SMS, null, hm);
        }
        if (widget.hasParameter("send_mail")) {
            HashMap<String, CharSequence> hm = new HashMap<>();
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < contacts.size(); i++) {
                switch (contacts.get(i).getType()) {
                case 0: {
                    sb.append("Name: ");
                }
                    break;
                case 1: {
                    sb.append("Phone: ");
                }
                    break;
                case 2: {
                    sb.append("Email: ");
                }
                    break;
                case 3: {
                    sb.append("Site: ");
                }
                    break;
                case 4: {
                    sb.append("Address: ");
                }
                    break;
                }
                sb.append(contacts.get(i).getDescription());
                sb.append("<br/>");
            }

            if (widget.isHaveAdvertisement()) {
                sb.append("<br>\n (sent from <a href=\"http://ibuildapp.com\">iBuildApp</a>)");
            }

            hm.put("text", sb.toString());
            hm.put("subject", "Contacts");
            addNativeFeature(NATIVE_FEATURES.EMAIL, null, hm);
        }

    } catch (Exception e) {
        Log.e(TAG, e.getMessage());
        e.printStackTrace();
    }
}