Search in sources :

Example 6 with UrlImageViewCallback

use of com.koushikdutta.urlimageviewhelper.UrlImageViewCallback in project iNaturalistAndroid by inaturalist.

the class ProjectNewsAdapter method getView.

public View getView(int position, View convertView, ViewGroup parent) {
    LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View view = inflater.inflate(R.layout.project_news_item, parent, false);
    JSONObject item = mResultList.get(position);
    try {
        ImageView projectPic = (ImageView) view.findViewById(R.id.project_pic);
        ImageView postPic = (ImageView) view.findViewById(R.id.post_pic);
        TextView projectTitle = (TextView) view.findViewById(R.id.project_title);
        TextView newsDate = (TextView) view.findViewById(R.id.news_date);
        TextView newsTitle = (TextView) view.findViewById(R.id.news_title);
        TextView newsContent = (TextView) view.findViewById(R.id.news_content);
        JSONObject project = mProject != null ? mProject : item.getJSONObject("parent");
        if (project.has("icon_url") && !project.isNull("icon_url")) {
            UrlImageViewHelper.setUrlDrawable(projectPic, project.getString("icon_url"));
        }
        projectTitle.setText(project.optString("title", project.optString("name")));
        newsTitle.setText(item.getString("title"));
        String html = item.getString("body");
        String firstPhotoUrl = findFirstPhotoUrl(html);
        // Image tags do not get removed cleanly by toString
        html = html.replaceAll("<img .+?>", "");
        String noHTML = Html.fromHtml(html).toString().trim();
        newsContent.setText(noHTML);
        BetterJSONObject newsItem = new BetterJSONObject(item);
        newsDate.setText(CommentsIdsAdapter.formatIdDate(mContext, newsItem.getTimestamp("updated_at")));
        if (firstPhotoUrl != null) {
            // Set the article photo
            postPic.setVisibility(View.VISIBLE);
            UrlImageViewHelper.setUrlDrawable(postPic, firstPhotoUrl, new UrlImageViewCallback() {

                @Override
                public void onLoaded(ImageView imageView, Bitmap loadedBitmap, String url, boolean loadedFromCache) {
                }

                @Override
                public Bitmap onPreSetBitmap(ImageView imageView, Bitmap loadedBitmap, String url, boolean loadedFromCache) {
                    Bitmap centerCrop = ImageUtils.centerCropBitmap(loadedBitmap);
                    return centerCrop;
                }
            });
        } else {
            // No article photo
            postPic.setVisibility(View.GONE);
        }
        view.setTag(item);
    } catch (JSONException e) {
        e.printStackTrace();
    }
    return view;
}
Also used : Bitmap(android.graphics.Bitmap) JSONObject(org.json.JSONObject) LayoutInflater(android.view.LayoutInflater) UrlImageViewCallback(com.koushikdutta.urlimageviewhelper.UrlImageViewCallback) JSONException(org.json.JSONException) TextView(android.widget.TextView) ImageView(android.widget.ImageView) ImageView(android.widget.ImageView) TextView(android.widget.TextView) View(android.view.View)

Example 7 with UrlImageViewCallback

use of com.koushikdutta.urlimageviewhelper.UrlImageViewCallback in project iNaturalistAndroid by inaturalist.

the class NewsArticle method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mHelper = new ActivityHelper(this);
    final Intent intent = getIntent();
    setContentView(R.layout.article);
    ActionBar actionBar = getSupportActionBar();
    actionBar.setHomeButtonEnabled(true);
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setLogo(R.drawable.ic_arrow_back);
    actionBar.setTitle(R.string.article);
    mArticleTitle = (TextView) findViewById(R.id.article_title);
    mArticleContentWeb = (WebView) findViewById(R.id.article_content_web);
    mArticleContent = (TextView) findViewById(R.id.article_content);
    mUsername = (TextView) findViewById(R.id.username);
    mUserPic = (ImageView) findViewById(R.id.user_pic);
    if (mApp == null) {
        mApp = (INaturalistApp) getApplicationContext();
    }
    if (savedInstanceState == null) {
        mArticle = (BetterJSONObject) intent.getSerializableExtra(KEY_ARTICLE);
        mIsUserFeed = intent.getBooleanExtra(KEY_IS_USER_FEED, false);
    } else {
        mArticle = (BetterJSONObject) savedInstanceState.getSerializable(KEY_ARTICLE);
        mIsUserFeed = savedInstanceState.getBoolean(KEY_IS_USER_FEED);
    }
    if (mArticle == null) {
        finish();
        return;
    }
    mArticleTitle.setText(mArticle.getString("title"));
    if (mIsUserFeed) {
        mArticleContent.setVisibility(View.GONE);
        mArticleContentWeb.setVisibility(View.VISIBLE);
        mArticleContentWeb.setBackgroundColor(Color.TRANSPARENT);
        mArticleContentWeb.getSettings().setJavaScriptEnabled(true);
        mArticleContentWeb.setVerticalScrollBarEnabled(false);
        String html = "" + "<html>" + "<head>" + "<style type=\"text/css\"> " + "body {" + "line-height: 22pt;" + "margin: 0;" + "padding: 0;" + "font-family: \"HelveticaNeue-UltraLight\", \"Segoe UI\", \"Roboto Light\", sans-serif;" + "font-size: medium;" + "} " + "div {max-width: 100%;} " + "figure { padding: 0; margin: 0; } " + "img { padding-top: 4; padding-bottom: 4; max-width: 100%; } " + "</style>" + "<meta name=\"viewport\" content=\"user-scalable=no, initial-scale=1.0, maximum-scale=1.0, width=device-width\" >" + "</head>" + "<body>";
        mArticleContentWeb.loadDataWithBaseURL("", html + mArticle.getString("body") + "</body></html>", "text/html", "UTF-8", "");
    } else {
        mArticleContentWeb.setVisibility(View.GONE);
        mArticleContent.setVisibility(View.VISIBLE);
        mArticleContent.setText(Html.fromHtml(mArticle.getString("body")));
        Linkify.addLinks(mArticleContent, Linkify.ALL);
    }
    final JSONObject user = mArticle.getJSONObject("user");
    mUsername.setText(user.optString("login"));
    // Intercept link clicks (for analytics events)
    WebViewClient webClient = new WebViewClient() {

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            try {
                JSONObject eventParams = new JSONObject();
                JSONObject item = mArticle.getJSONObject();
                eventParams.put(AnalyticsClient.EVENT_PARAM_LINK, url);
                eventParams.put(AnalyticsClient.EVENT_PARAM_ARTICLE_TITLE, item.optString("title", ""));
                eventParams.put(AnalyticsClient.EVENT_PARAM_PARENT_TYPE, item.optString("parent_type", ""));
                JSONObject parent = item.optJSONObject("parent");
                if (parent == null)
                    parent = new JSONObject();
                eventParams.put(AnalyticsClient.EVENT_PARAM_PARENT_NAME, parent.optString("title", parent.optString("name", "")));
                AnalyticsClient.getInstance().logEvent(AnalyticsClient.EVENT_NAME_NEWS_TAP_LINK, eventParams);
            } catch (JSONException e) {
                e.printStackTrace();
            }
            Uri uri = Uri.parse(url);
            Intent intent = new Intent(Intent.ACTION_VIEW, uri);
            NewsArticle.this.startActivity(intent);
            return true;
        }
    };
    mArticleContentWeb.setWebViewClient(webClient);
    View.OnClickListener showUser = new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            Intent intent = new Intent(NewsArticle.this, UserProfile.class);
            intent.putExtra("user", new BetterJSONObject(user));
            startActivity(intent);
        }
    };
    if (user.has("user_icon_url") && !user.isNull("user_icon_url")) {
        UrlImageViewHelper.setUrlDrawable(mUserPic, user.optString("user_icon_url"), R.drawable.ic_account_circle_black_24dp, new UrlImageViewCallback() {

            @Override
            public void onLoaded(ImageView imageView, Bitmap loadedBitmap, String url, boolean loadedFromCache) {
            // Nothing to do here
            }

            @Override
            public Bitmap onPreSetBitmap(ImageView imageView, Bitmap loadedBitmap, String url, boolean loadedFromCache) {
                // Return a circular version of the profile picture
                return ImageUtils.getCircleBitmap(loadedBitmap);
            }
        });
    }
    mUserPic.setOnClickListener(showUser);
    mUsername.setOnClickListener(showUser);
}
Also used : UrlImageViewCallback(com.koushikdutta.urlimageviewhelper.UrlImageViewCallback) JSONException(org.json.JSONException) Intent(android.content.Intent) Uri(android.net.Uri) ImageView(android.widget.ImageView) View(android.view.View) WebView(android.webkit.WebView) TextView(android.widget.TextView) ListView(android.widget.ListView) Bitmap(android.graphics.Bitmap) JSONObject(org.json.JSONObject) ImageView(android.widget.ImageView) WebView(android.webkit.WebView) ActionBar(android.support.v7.app.ActionBar) WebViewClient(android.webkit.WebViewClient)

Example 8 with UrlImageViewCallback

use of com.koushikdutta.urlimageviewhelper.UrlImageViewCallback in project iNaturalistAndroid by inaturalist.

the class FavoritesAdapter method getView.

@Override
public View getView(final int position, View convertView, ViewGroup parent) {
    Resources res = mContext.getResources();
    LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    final View view = inflater.inflate(R.layout.favorite_item, parent, false);
    final BetterJSONObject item = mItems.get(position);
    try {
        TextView favDate = (TextView) view.findViewById(R.id.faved_on);
        TextView userNameText = (TextView) view.findViewById(R.id.user_name);
        final String username = item.getJSONObject("user").getString("login");
        userNameText.setText(username);
        Timestamp postDate = item.getTimestamp("created_at");
        favDate.setText(CommentsIdsAdapter.formatIdDate(mContext, postDate));
        final ImageView userPic = (ImageView) view.findViewById(R.id.user_pic);
        boolean hasUserIcon = item.getJSONObject("user").getString("user_icon_url") != null;
        if (hasUserIcon) {
            UrlImageViewHelper.setUrlDrawable(userPic, item.getJSONObject("user").getString("user_icon_url"), R.drawable.ic_account_circle_black_24dp, new UrlImageViewCallback() {

                @Override
                public void onLoaded(ImageView imageView, Bitmap loadedBitmap, String url, boolean loadedFromCache) {
                // Nothing to do here
                }

                @Override
                public Bitmap onPreSetBitmap(ImageView imageView, Bitmap loadedBitmap, String url, boolean loadedFromCache) {
                    // Return a circular version of the profile picture
                    return ImageUtils.getCircleBitmap(loadedBitmap);
                }
            });
        } else {
            userPic.setAlpha(100);
        }
    } catch (JSONException e) {
        e.printStackTrace();
    }
    view.setTag(item);
    return view;
}
Also used : UrlImageViewCallback(com.koushikdutta.urlimageviewhelper.UrlImageViewCallback) JSONException(org.json.JSONException) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) Timestamp(java.sql.Timestamp) Bitmap(android.graphics.Bitmap) LayoutInflater(android.view.LayoutInflater) TextView(android.widget.TextView) Resources(android.content.res.Resources) ImageView(android.widget.ImageView)

Example 9 with UrlImageViewCallback

use of com.koushikdutta.urlimageviewhelper.UrlImageViewCallback in project iNaturalistAndroid by inaturalist.

the class GuideTaxonActivity method loadTaxon.

private void loadTaxon() {
    if (mTaxon == null) {
        finish();
        return;
    }
    findViewById(R.id.loading_image).setVisibility(View.VISIBLE);
    TextView displayNameText = (TextView) findViewById(R.id.displayName);
    TextView name = (TextView) findViewById(R.id.name);
    String displayName = null;
    // Get the taxon display name according to configuration of the current iNat network
    if (displayName == null) {
        // Couldn't extract the display name from the taxon names list - use the default one
        try {
            displayName = mTaxon.getJSONObject().getString("unique_name");
        } catch (JSONException e2) {
        }
        try {
            JSONObject defaultName = mTaxon.getJSONObject().getJSONObject("default_name");
            displayName = defaultName.getString("name");
        } catch (JSONException e1) {
        // alas
        }
        if (displayName == null) {
            displayName = mTaxon.getJSONObject().optString("preferred_common_name");
        }
        if ((displayName == null) || (displayName.length() == 0)) {
            displayName = mTaxon.getJSONObject().optString("english_common_name");
        }
    }
    if ((displayName == null) || (displayName.length() == 0)) {
        displayNameText.setText(mTaxon.getJSONObject().optString("name"));
        name.setVisibility(View.GONE);
    } else {
        displayNameText.setText(displayName);
        name.setText(TaxonUtils.getTaxonScientificName(mTaxon.getJSONObject()));
    }
    JSONObject itemJson = mTaxon.getJSONObject();
    ImageView taxonImage = (ImageView) findViewById(R.id.taxon_image);
    String photoUrl = null;
    JSONObject defaultPhoto = itemJson.isNull("default_photo") ? null : itemJson.optJSONObject("default_photo");
    TextView photosAttr = (TextView) findViewById(R.id.attributions_photos);
    if (defaultPhoto != null) {
        photoUrl = defaultPhoto.optString("medium_url");
        photosAttr.setText(Html.fromHtml(String.format(getString(R.string.photo), photoUrl, defaultPhoto.optString("attribution"))));
        photosAttr.setMovementMethod(LinkMovementMethod.getInstance());
        stripUnderlines(photosAttr);
    } else {
        photosAttr.setVisibility(View.GONE);
    }
    if ((photoUrl == null) || (photoUrl.length() == 0)) {
        photoUrl = itemJson.isNull("photo_url") ? null : itemJson.optString("photo_url");
    }
    if (photoUrl != null) {
        findViewById(R.id.loading_image).setVisibility(View.VISIBLE);
        UrlImageViewHelper.setUrlDrawable(taxonImage, photoUrl, new UrlImageViewCallback() {

            @Override
            public void onLoaded(ImageView imageView, Bitmap loadedBitmap, String url, boolean loadedFromCache) {
                findViewById(R.id.loading_image).setVisibility(View.GONE);
            }

            @Override
            public Bitmap onPreSetBitmap(ImageView imageView, Bitmap loadedBitmap, String url, boolean loadedFromCache) {
                return loadedBitmap;
            }
        });
    } else {
        findViewById(R.id.loading_image).setVisibility(View.GONE);
        taxonImage.setScaleType(ImageView.ScaleType.FIT_CENTER);
        taxonImage.setImageResource(TaxonUtils.observationIcon(itemJson));
    }
    TextView description = (TextView) findViewById(R.id.description);
    String descriptionText = itemJson.isNull("wikipedia_summary") ? "" : itemJson.optString("wikipedia_summary", "");
    description.setText(Html.fromHtml(descriptionText));
    ViewGroup viewOnWiki = (ViewGroup) findViewById(R.id.view_on_wikipedia);
    viewOnWiki.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            JSONObject taxonObj = mTaxon.getJSONObject();
            String obsUrl = null;
            try {
                String wikiTitle;
                if ((taxonObj.has("wikipedia_title")) && (!taxonObj.isNull("wikipedia_title")) && (taxonObj.optString("wikipedia_title").length() > 0)) {
                    wikiTitle = taxonObj.optString("wikipedia_title");
                } else {
                    wikiTitle = taxonObj.optString("name");
                }
                wikiTitle = wikiTitle.replace(" ", "_");
                Locale deviceLocale = getResources().getConfiguration().locale;
                String deviceLanguage = deviceLocale.getLanguage();
                obsUrl = "https://" + deviceLanguage + ".wikipedia.org/wiki/" + URLEncoder.encode(wikiTitle, "utf-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
            Intent i = new Intent(Intent.ACTION_VIEW);
            i.setData(Uri.parse(obsUrl));
            startActivity(i);
        }
    });
}
Also used : Locale(java.util.Locale) ViewGroup(android.view.ViewGroup) UrlImageViewCallback(com.koushikdutta.urlimageviewhelper.UrlImageViewCallback) JSONException(org.json.JSONException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Intent(android.content.Intent) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) Bitmap(android.graphics.Bitmap) JSONObject(org.json.JSONObject) TextView(android.widget.TextView) ImageView(android.widget.ImageView)

Example 10 with UrlImageViewCallback

use of com.koushikdutta.urlimageviewhelper.UrlImageViewCallback in project iNaturalistAndroid by inaturalist.

the class ObservationViewerActivity method loadObservationIntoUI.

private void loadObservationIntoUI() {
    String userIconUrl = null;
    if (mReadOnly) {
        if (mObsJson == null) {
            finish();
            return;
        }
        BetterJSONObject obs = new BetterJSONObject(mObsJson);
        JSONObject userObj = obs.getJSONObject("user");
        if (userObj != null) {
            userIconUrl = userObj.has("user_icon_url") && !userObj.isNull("user_icon_url") ? userObj.optString("user_icon_url", null) : null;
            if (userIconUrl == null) {
                userIconUrl = userObj.has("icon_url") && !userObj.isNull("icon_url") ? userObj.optString("icon_url", null) : null;
            }
            mUserName.setText(userObj.optString("login"));
            mUserPic.setVisibility(View.VISIBLE);
            mUserName.setVisibility(View.VISIBLE);
        }
    } else {
        SharedPreferences pref = getSharedPreferences("iNaturalistPreferences", MODE_PRIVATE);
        String username = pref.getString("username", null);
        userIconUrl = pref.getString("user_icon_url", null);
        mUserName.setText(username);
        // Display the errors for the observation, if any
        TextView errorsDescription = (TextView) findViewById(R.id.errors);
        if (mObservation.id != null) {
            JSONArray errors = mApp.getErrorsForObservation(mObservation.id);
            if (errors.length() == 0) {
                errorsDescription.setVisibility(View.GONE);
            } else {
                errorsDescription.setVisibility(View.VISIBLE);
                StringBuilder errorsHtml = new StringBuilder();
                try {
                    for (int i = 0; i < errors.length(); i++) {
                        errorsHtml.append("&#8226; ");
                        errorsHtml.append(errors.getString(i));
                        if (i < errors.length() - 1)
                            errorsHtml.append("<br/>");
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                errorsDescription.setText(Html.fromHtml(errorsHtml.toString()));
            }
        } else {
            errorsDescription.setVisibility(View.GONE);
        }
    }
    if ((userIconUrl != null) && (userIconUrl.length() > 0)) {
        String extension = userIconUrl.substring(userIconUrl.lastIndexOf(".") + 1);
        userIconUrl = userIconUrl.substring(0, userIconUrl.lastIndexOf('/') + 1) + "medium." + extension;
    }
    if ((userIconUrl != null) && (userIconUrl.length() > 0)) {
        UrlImageViewHelper.setUrlDrawable(mUserPic, userIconUrl, R.drawable.ic_account_circle_black_24dp, new UrlImageViewCallback() {

            @Override
            public void onLoaded(ImageView imageView, Bitmap loadedBitmap, String url, boolean loadedFromCache) {
            }

            @Override
            public Bitmap onPreSetBitmap(ImageView imageView, Bitmap loadedBitmap, String url, boolean loadedFromCache) {
                // Return a circular version of the profile picture
                Bitmap centerCrop = ImageUtils.centerCropBitmap(loadedBitmap);
                return ImageUtils.getCircleBitmap(centerCrop);
            }
        });
    } else {
        mUserPic.setImageResource(R.drawable.ic_account_circle_black_24dp);
    }
    if (mReadOnly) {
        if (mObsJson == null)
            return;
        BetterJSONObject obs = new BetterJSONObject(mObsJson);
        final JSONObject userObj = obs.getJSONObject("user");
        OnClickListener showUser = new OnClickListener() {

            @Override
            public void onClick(View view) {
                Intent intent = new Intent(ObservationViewerActivity.this, UserProfile.class);
                intent.putExtra("user", new BetterJSONObject(userObj));
                startActivity(intent);
            }
        };
        mUserName.setOnClickListener(showUser);
        mUserPic.setOnClickListener(showUser);
    }
    mObservedOn.setText(formatObservedOn(mObservation.observed_on, mObservation.time_observed_at));
    if (mPhotosAdapter.getCount() <= 1) {
        mIndicator.setVisibility(View.GONE);
        mNoPhotosContainer.setVisibility(View.GONE);
        if (mPhotosAdapter.getCount() == 0) {
            // No photos at all
            mNoPhotosContainer.setVisibility(View.VISIBLE);
            mIdPicBig.setImageResource(TaxonUtils.observationIcon(mObservation.toJSONObject()));
        }
    } else {
        mIndicator.setVisibility(View.VISIBLE);
        mNoPhotosContainer.setVisibility(View.GONE);
    }
    mSharePhoto.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View view) {
            final DialogInterface.OnClickListener onClick = new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    String inatNetwork = mApp.getInaturalistNetworkMember();
                    String inatHost = mApp.getStringResourceByName("inat_host_" + inatNetwork);
                    String obsUrl = inatHost + "/observations/" + mObservation.id;
                    switch(which) {
                        case R.id.share:
                            Intent shareIntent = new Intent();
                            shareIntent.setAction(Intent.ACTION_SEND);
                            shareIntent.setType("text/plain");
                            shareIntent.putExtra(Intent.EXTRA_TEXT, obsUrl);
                            startActivityForResult(shareIntent, SHARE_REQUEST_CODE);
                            AnalyticsClient.getInstance().logEvent(AnalyticsClient.EVENT_NAME_OBS_SHARE_STARTED);
                            break;
                        case R.id.view_on_inat:
                            Intent i = new Intent(Intent.ACTION_VIEW);
                            i.setData(Uri.parse(obsUrl));
                            startActivity(i);
                            break;
                    }
                }
            };
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
                PopupMenu popup = new PopupMenu(ObservationViewerActivity.this, mSharePhoto);
                popup.getMenuInflater().inflate(R.menu.share_photo_menu, popup.getMenu());
                popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {

                    @Override
                    public boolean onMenuItemClick(android.view.MenuItem menuItem) {
                        onClick.onClick(null, menuItem.getItemId());
                        return true;
                    }
                });
                popup.show();
            } else {
                new BottomSheet.Builder(ObservationViewerActivity.this).sheet(R.menu.share_photo_menu).listener(onClick).show();
            }
        }
    });
    OnClickListener listener = new OnClickListener() {

        @Override
        public void onClick(View view) {
            if (mTaxon == null) {
                // No taxon - don't show the taxon details page
                return;
            }
            Intent intent = new Intent(ObservationViewerActivity.this, TaxonActivity.class);
            intent.putExtra(TaxonActivity.TAXON, new BetterJSONObject(mTaxon));
            intent.putExtra(TaxonActivity.OBSERVATION, mObsJson != null ? new BetterJSONObject(mObsJson) : new BetterJSONObject(mObservation.toJSONObject()));
            startActivity(intent);
        }
    };
    mIdRow.setOnClickListener(listener);
    mIdName.setOnClickListener(listener);
    mTaxonicName.setOnClickListener(listener);
    mIdPic.setImageResource(TaxonUtils.observationIcon(mObservation.toJSONObject()));
    if (mObservation.preferred_common_name != null && mObservation.preferred_common_name.length() > 0) {
        mIdName.setText(mObservation.preferred_common_name);
        mTaxonicName.setText(mObservation.preferred_common_name);
    } else {
        mIdName.setText(mObservation.species_guess);
        mTaxonicName.setText(mObservation.species_guess);
    }
    if (mObservation.id == null) {
        mSharePhoto.setVisibility(View.GONE);
    }
    if ((mObservation.taxon_id == null) && (mObservation.species_guess == null)) {
        mIdName.setText(R.string.unknown_species);
        mIdArrow.setVisibility(View.GONE);
    } else if (mObservation.taxon_id != null) {
        mIdArrow.setVisibility(View.VISIBLE);
        if ((mTaxonName == null) || (mTaxonIdName == null) || (mTaxonImage == null)) {
            downloadObsTaxonAndUpdate();
        } else {
            UrlImageViewHelper.setUrlDrawable(mIdPic, mTaxonImage);
            if ((mTaxonIdName == null) || (mTaxonIdName.length() == 0)) {
                mIdName.setText(mTaxonName);
                mTaxonicName.setText(mTaxonName);
            } else {
                mIdName.setText(mTaxonIdName);
                mTaxonicName.setText(mTaxonName);
                mTaxonicName.setVisibility(View.VISIBLE);
                if (mTaxonRankLevel <= 20) {
                    mTaxonicName.setTypeface(null, Typeface.ITALIC);
                } else {
                    mTaxonicName.setTypeface(null, Typeface.NORMAL);
                }
            }
        }
    }
    mTaxonInactive.setVisibility(mTaxon == null || mTaxon.optBoolean("is_active", true) ? View.GONE : View.VISIBLE);
    mTaxonInactive.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            String inatNetwork = mApp.getInaturalistNetworkMember();
            String inatHost = mApp.getStringResourceByName("inat_host_" + inatNetwork);
            Locale deviceLocale = getResources().getConfiguration().locale;
            String deviceLanguage = deviceLocale.getLanguage();
            String taxonUrl = String.format("%s/taxon_changes?taxon_id=%d&locale=%s", inatHost, mTaxon.optInt("id"), deviceLanguage);
            Intent i = new Intent(Intent.ACTION_VIEW);
            i.setData(Uri.parse(taxonUrl));
            startActivity(i);
        }
    });
    if (!mReadOnly) {
        // Get IDs of project-observations
        int obsId = (mObservation.id == null ? mObservation._id : mObservation.id);
        Cursor c = getContentResolver().query(ProjectObservation.CONTENT_URI, ProjectObservation.PROJECTION, "(observation_id = " + obsId + ") AND ((is_deleted = 0) OR (is_deleted is NULL))", null, ProjectObservation.DEFAULT_SORT_ORDER);
        mProjectIds = new ArrayList<Integer>();
        while (c.isAfterLast() == false) {
            ProjectObservation projectObservation = new ProjectObservation(c);
            mProjectIds.add(projectObservation.project_id);
            c.moveToNext();
        }
        c.close();
        mProjects = new ArrayList<BetterJSONObject>();
        for (int projectId : mProjectIds) {
            c = getContentResolver().query(Project.CONTENT_URI, Project.PROJECTION, "(id = " + projectId + ")", null, Project.DEFAULT_SORT_ORDER);
            if (c.getCount() > 0) {
                Project project = new Project(c);
                BetterJSONObject projectJson = new BetterJSONObject();
                projectJson.put("project", project.toJSONObject());
                mProjects.add(projectJson);
            }
            c.close();
        }
    }
    refreshProjectList();
    mIncludedInProjectsContainer.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View view) {
            Intent intent = new Intent(ObservationViewerActivity.this, ObservationProjectsViewer.class);
            intent.putExtra(ObservationProjectsViewer.PROJECTS, mProjects);
            startActivity(intent);
        }
    });
    if ((mObservation.description != null) && (mObservation.description.trim().length() > 0)) {
        mNotesContainer.setVisibility(View.VISIBLE);
        mNotes.setText(mObservation.description);
    } else {
        mNotesContainer.setVisibility(View.GONE);
    }
}
Also used : Locale(java.util.Locale) DialogInterface(android.content.DialogInterface) Cursor(android.database.Cursor) Bitmap(android.graphics.Bitmap) TextView(android.widget.TextView) ImageView(android.widget.ImageView) SharedPreferences(android.content.SharedPreferences) JSONArray(org.json.JSONArray) UrlImageViewCallback(com.koushikdutta.urlimageviewhelper.UrlImageViewCallback) JSONException(org.json.JSONException) Intent(android.content.Intent) MenuItem(android.view.MenuItem) OnClickListener(android.view.View.OnClickListener) TwoWayView(org.lucasr.twowayview.TwoWayView) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) ListView(android.widget.ListView) AbsListView(android.widget.AbsListView) ScrollView(android.widget.ScrollView) JSONObject(org.json.JSONObject) OnClickListener(android.view.View.OnClickListener) PopupMenu(android.widget.PopupMenu)

Aggregations

Bitmap (android.graphics.Bitmap)13 ImageView (android.widget.ImageView)13 UrlImageViewCallback (com.koushikdutta.urlimageviewhelper.UrlImageViewCallback)13 TextView (android.widget.TextView)10 View (android.view.View)9 Intent (android.content.Intent)8 JSONException (org.json.JSONException)7 JSONObject (org.json.JSONObject)6 ListView (android.widget.ListView)5 AdapterView (android.widget.AdapterView)4 DialogInterface (android.content.DialogInterface)3 SharedPreferences (android.content.SharedPreferences)3 Cursor (android.database.Cursor)3 LayoutInflater (android.view.LayoutInflater)3 OnClickListener (android.view.View.OnClickListener)3 Uri (android.net.Uri)2 CollapsingToolbarLayout (android.support.design.widget.CollapsingToolbarLayout)2 DecimalFormat (java.text.DecimalFormat)2 SuppressLint (android.annotation.SuppressLint)1 AlertDialog (android.app.AlertDialog)1