• 08-02-2019, 11:43:20
    #1
    Herkese merhaba, android studio ile yemek tarifleri uygulaması yazıyorum bitti sayılır çok az bir işlemi kaldı fakat takıldığım bir yer oldu aşağıdaki kodda yer alan news_desc = (WebView) findViewById(R.id.desc); kısmı çalışmıyor tarif içeriğine girince resim ve pişirme süresi geliyor fakat tarif detayları kısmı gelmiyor log ekranında çıkan tek uyarı mesajı
    Note: Some input files use or override a deprecated API.
    Note: Recompile with -Xlint:deprecation for details.
    bu sorunu nasıl çözebilirim. Teşekkürler


    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:ads="http://schemas.android.com/apk/res-auto"
        xmlns:card_view="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
    
        <android.support.design.widget.CoordinatorLayout
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/main_content"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#e7e7e7"
            android:visibility="gone"
            android:layout_above="@+id/relativeLayout">
    
            <android.support.design.widget.AppBarLayout
                android:id="@+id/appbar"
                android:layout_width="match_parent"
                android:layout_height="256dp"
                android:fitsSystemWindows="true"
                android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" >
    
                <android.support.design.widget.CollapsingToolbarLayout
                    android:id="@+id/collapsing_toolbar"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    app:layout_scrollFlags="scroll|exitUntilCollapsed"
                    android:fitsSystemWindows="true"
                    app:contentScrim="?attr/colorPrimary"
                    app:expandedTitleMarginEnd="64dp"
                    app:expandedTitleMarginStart="48dp" >
    
                    <ImageView
                        android:id="@+id/image"
                        app:layout_collapseMode="parallax"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:scaleType="centerCrop"/>
    
                    <RelativeLayout
                        android:layout_width="match_parent"
                        android:layout_height="match_parent">
    
                        <LinearLayout
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_alignParentBottom="true"
                            android:background="@drawable/drawer_top_gradient"
                            android:orientation="vertical" >
    
                            <TextView
                                android:id="@+id/title"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:layout_above="@+id/date"
                                android:layout_marginLeft="18dp"
                                android:layout_marginRight="10dp"
                                android:layout_marginTop="10dp"
                                android:text=""
                                android:textStyle="bold"
                                android:textColor="@color/white"
                                android:textSize="24sp" />
    
                            <TextView
                                android:id="@+id/date"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:text=""
                                android:layout_marginLeft="18dp"
                                android:layout_marginRight="10dp"
                                android:layout_marginTop="5dp"
                                android:layout_marginBottom="12dp"
                                android:layout_alignParentBottom="true"
                                android:textColor="@color/white" />
                        </LinearLayout>
                    </RelativeLayout>
    
                    <android.support.v7.widget.Toolbar
                        android:id="@+id/toolbar"
                        android:layout_width="match_parent"
                        android:layout_height="?attr/actionBarSize"
                        app:layout_collapseMode="pin"
                        app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
                </android.support.design.widget.CollapsingToolbarLayout>
            </android.support.design.widget.AppBarLayout>
    
            <android.support.v4.widget.NestedScrollView
                android:id="@+id/sclDetail"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="10dp"
                app:layout_behavior="@string/appbar_scrolling_view_behavior"
                android:fillViewport="true" >
    
                <android.support.v7.widget.CardView
                    android:id="@+id/cv"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    card_view:cardBackgroundColor="@android:color/white"
                    card_view:cardElevation="8sp"
                    card_view:cardUseCompatPadding="true">
    
                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:orientation="vertical"
                        android:background="@color/white">
    
                        <WebView
                            android:id="@+id/desc"
                            android:layout_margin="10dp"
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:scrollbars="none"/>
                    </LinearLayout>
                </android.support.v7.widget.CardView>
            </android.support.v4.widget.NestedScrollView>
    
            <android.support.design.widget.FloatingActionButton
                android:id="@+id/img_fav"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_margin="16dp"
                app:layout_anchor="@id/appbar"
                app:layout_anchorGravity="bottom|right|end"
                android:clickable="true"
                android:src="@drawable/ic_favorite_outline_white"
                app:borderWidth="0dp"
                app:fabSize="normal" />
        </android.support.design.widget.CoordinatorLayout>
    
        <RelativeLayout
            android:id="@+id/relativeLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true">
    
            <com.google.android.gms.ads.AdView
                android:id="@+id/adView"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:visibility="gone"
                ads:adSize="SMART_BANNER"
                ads:adUnitId="@string/admob_banner_id" />
    
        </RelativeLayout>
    
        <ProgressBar
            android:id="@+id/progressBar"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true" />
    
    </RelativeLayout>
    package com.app.yourrecipesapp.activities;
    
    import android.content.Context;
    import android.content.Intent;
    import android.content.res.Resources;
    import android.graphics.Color;
    import android.os.AsyncTask;
    import android.os.Build;
    import android.os.Bundle;
    import android.support.design.widget.AppBarLayout;
    import android.support.design.widget.CollapsingToolbarLayout;
    import android.support.design.widget.CoordinatorLayout;
    import android.support.design.widget.FloatingActionButton;
    import android.support.v7.app.AppCompatActivity;
    import android.support.v7.widget.Toolbar;
    import android.util.Log;
    import android.view.Menu;
    import android.view.MenuItem;
    import android.view.View;
    import android.webkit.WebSettings;
    import android.webkit.WebView;
    import android.widget.ImageView;
    import android.widget.ProgressBar;
    import android.widget.TextView;
    import android.widget.Toast;
    
    import com.app.yourrecipesapp.Config;
    import com.app.yourrecipesapp.R;
    import com.app.yourrecipesapp.json.JsonConfig;
    import com.app.yourrecipesapp.json.JsonUtils;
    import com.app.yourrecipesapp.models.ItemFavorite;
    import com.app.yourrecipesapp.models.ItemRecipesList;
    import com.app.yourrecipesapp.utilities.DatabaseHandler;
    import com.app.yourrecipesapp.utilities.GDPR;
    import com.google.ads.mediation.admob.AdMobAdapter;
    import com.google.android.gms.ads.AdListener;
    import com.google.android.gms.ads.AdRequest;
    import com.google.android.gms.ads.AdView;
    import com.squareup.picasso.Picasso;
    
    import org.json.JSONArray;
    import org.json.JSONException;
    import org.json.JSONObject;
    
    import java.util.ArrayList;
    import java.util.List;
    
    public class ActivityRecipesDetail extends AppCompatActivity {
    
        String str_cid, str_cat_id, str_cat_image, str_cat_name, str_title, str_image, str_desc, str_date;
        TextView news_title, news_date;
        WebView news_desc;
        ImageView img_news, img_fav;
        DatabaseHandler db;
        List<ItemRecipesList> arrayItemRecipesList;
        ItemRecipesList itemRecipesList;
        final Context context = this;
        CollapsingToolbarLayout collapsingToolbarLayout;
        private AppBarLayout appBarLayout;
        ProgressBar progressBar;
        static final String TAG = "RecipesDetail";
        CoordinatorLayout coordinatorLayout;
        private AdView adView;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
    
            setContentView(R.layout.activity_recipes_detail);
    
            if (Config.ENABLE_RTL_MODE) {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
                    getWindow().getDecorView().setLayoutDirection(View.LAYOUT_DIRECTION_RTL);
                }
            } else {
                Log.d("RTL Mode", "Working in Normal Mode, RTL Mode is Disabled");
            }
    
            loadAdMobBannerAd();
    
            final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
            setSupportActionBar(toolbar);
            final android.support.v7.app.ActionBar actionBar = getSupportActionBar();
            if (actionBar != null) {
                getSupportActionBar().setDisplayHomeAsUpEnabled(true);
                getSupportActionBar().setDisplayHomeAsUpEnabled(true);
                getSupportActionBar().setTitle("");
            }
    
            appBarLayout = (AppBarLayout) findViewById(R.id.appbar);
            appBarLayout.setExpanded(true);
            collapsingToolbarLayout = (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar);
            collapsingToolbarLayout.setTitle("");
    
            appBarLayout.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {
                boolean isShow = false;
                int scrollRange = -1;
    
                @Override
                public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
                    if (scrollRange == -1) {
                        scrollRange = appBarLayout.getTotalScrollRange();
                    }
                    if (scrollRange + verticalOffset == 0) {
                        collapsingToolbarLayout.setTitle(itemRecipesList.getCategoryName());
                        isShow = true;
                    } else if (isShow) {
                        collapsingToolbarLayout.setTitle("");
                        isShow = false;
                    }
                }
            });
    
            coordinatorLayout = (CoordinatorLayout) findViewById(R.id.main_content);
            progressBar = (ProgressBar) findViewById(R.id.progressBar);
    
            img_news = (ImageView) findViewById(R.id.image);
            img_fav = (FloatingActionButton) findViewById(R.id.img_fav);
    
            news_title = (TextView) findViewById(R.id.title);
            news_date = (TextView) findViewById(R.id.date);
            news_desc = (WebView) findViewById(R.id.desc);
    
            db = new DatabaseHandler(ActivityRecipesDetail.this);
    
            arrayItemRecipesList = new ArrayList<ItemRecipesList>();
    
            if (JsonUtils.isNetworkAvailable(ActivityRecipesDetail.this)) {
                new MyTask().execute(Config.SERVER_URL + "/api.php?nid=" + JsonConfig.NEWS_ITEMID);
            } else {
                Toast.makeText(getApplicationContext(), getResources().getString(R.string.failed_connect_network), Toast.LENGTH_SHORT).show();
            }
    
        }
    
        private class MyTask extends AsyncTask<String, Void, String> {
    
            @Override
            protected void onPreExecute() {
                super.onPreExecute();
    
                progressBar.setVisibility(View.VISIBLE);
            }
    
            @Override
            protected String doInBackground(String... params) {
                return JsonUtils.getJSONString(params[0]);
            }
    
            @Override
            protected void onPostExecute(String result) {
                super.onPostExecute(result);
    
                progressBar.setVisibility(View.GONE);
                coordinatorLayout.setVisibility(View.VISIBLE);
    
                if (null == result || result.length() == 0) {
                    Toast.makeText(getApplicationContext(), getResources().getString(R.string.failed_connect_network), Toast.LENGTH_SHORT).show();
                    coordinatorLayout.setVisibility(View.GONE);
                } else {
    
                    try {
                        JSONObject mainJson = new JSONObject(result);
                        JSONArray jsonArray = mainJson.getJSONArray(JsonConfig.CATEGORY_ARRAY_NAME);
                        JSONObject objJson = null;
                        for (int i = 0; i < jsonArray.length(); i++) {
                            objJson = jsonArray.getJSONObject(i);
    
                            ItemRecipesList objItem = new ItemRecipesList();
    
                            objItem.setCId(objJson.getString(JsonConfig.CATEGORY_ITEM_CID));
                            objItem.setCategoryName(objJson.getString(JsonConfig.CATEGORY_ITEM_NAME));
                            objItem.setCategoryImage(objJson.getString(JsonConfig.CATEGORY_ITEM_IMAGE));
                            objItem.setCatId(objJson.getString(JsonConfig.CATEGORY_ITEM_CAT_ID));
                            objItem.setNewsImage(objJson.getString(JsonConfig.CATEGORY_ITEM_NEWSIMAGE));
                            objItem.setNewsHeading(objJson.getString(JsonConfig.CATEGORY_ITEM_NEWSHEADING));
                            objItem.setNewsDescription(objJson.getString(JsonConfig.CATEGORY_ITEM_NEWSDESCRI));
                            objItem.setNewsDate(objJson.getString(JsonConfig.CATEGORY_ITEM_NEWSDATE));
    
                            arrayItemRecipesList.add(objItem);
    
                        }
    
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
    
                    setAdapterToRecyclerView();
                }
    
            }
        }
    
        public void setAdapterToRecyclerView() {
    
            if (Config.ENABLE_RTL_MODE) {
    
                itemRecipesList = arrayItemRecipesList.get(0);
                str_cid = itemRecipesList.getCId();
                str_cat_name = itemRecipesList.getCategoryName();
                str_cat_image = itemRecipesList.getCategoryImage();
                str_cat_id = itemRecipesList.getCatId();
                str_title = itemRecipesList.getNewsHeading();
                str_desc = itemRecipesList.getNewsDescription();
                str_image = itemRecipesList.getNewsImage();
                str_date = itemRecipesList.getNewsDate();
    
                news_title.setText(str_title);
                news_date.setText(str_date);
    
                news_desc.setBackgroundColor(Color.parseColor("#ffffff"));
                news_desc.setFocusableInTouchMode(false);
                news_desc.setFocusable(false);
                news_desc.getSettings().setDefaultTextEncodingName("UTF-8");
    
                WebSettings webSettings = news_desc.getSettings();
                Resources res = getResources();
                int fontSize = res.getInteger(R.integer.font_size);
                webSettings.setDefaultFontSize(fontSize);
    
                String mimeType = "text/html; charset=UTF-8";
                String encoding = "utf-8";
                String htmlText = str_desc;
    
                String text = "<html dir='rtl'><head>"
                        + "<style type=\"text/css\">body{color: #525252;}"
                        + "</style></head>"
                        + "<body>"
                        + htmlText
                        + "</body></html>";
    
                news_desc.loadData(text, mimeType, encoding);
    
                Picasso
                        .with(context)
                        .load(Config.SERVER_URL + "/upload/" + itemRecipesList.getNewsImage())
                        .placeholder(R.drawable.ic_thumbnail)
                        .into(img_news);
    
                List<ItemFavorite> itemFavorites = db.getFavRow(str_cat_id);
                if (itemFavorites.size() == 0) {
                    img_fav.setImageResource(R.drawable.ic_favorite_outline_white);
                } else {
                    if (itemFavorites.get(0).getCatId().equals(str_cat_id)) {
                        img_fav.setImageResource(R.drawable.ic_favorite_white);
                    }
                }
    
                img_fav.setOnClickListener(new View.OnClickListener() {
    
                    @Override
                    public void onClick(View v) {
    
                        List<ItemFavorite> itemFavorites = db.getFavRow(str_cat_id);
                        if (itemFavorites.size() == 0) {
    
                            db.AddtoFavorite(new ItemFavorite(str_cat_id, str_cid, str_cat_name, str_title, str_image, str_desc, str_date));
                            Toast.makeText(getApplicationContext(), getResources().getString(R.string.favorite_added), Toast.LENGTH_SHORT).show();
                            img_fav.setImageResource(R.drawable.ic_favorite_white);
    
                        } else {
                            if (itemFavorites.get(0).getCatId().equals(str_cat_id)) {
    
                                db.RemoveFav(new ItemFavorite(str_cat_id));
                                Toast.makeText(getApplicationContext(), getResources().getString(R.string.favorite_removed), Toast.LENGTH_SHORT).show();
                                img_fav.setImageResource(R.drawable.ic_favorite_outline_white);
                            }
                        }
                    }
                });
    
            } else {
    
                itemRecipesList = arrayItemRecipesList.get(0);
                str_cid = itemRecipesList.getCId();
                str_cat_name = itemRecipesList.getCategoryName();
                str_cat_image = itemRecipesList.getCategoryImage();
                str_cat_id = itemRecipesList.getCatId();
                str_title = itemRecipesList.getNewsHeading();
                str_desc = itemRecipesList.getNewsDescription();
                str_image = itemRecipesList.getNewsImage();
                str_date = itemRecipesList.getNewsDate();
    
                news_title.setText(str_title);
                news_date.setText(str_date);
    
                news_desc.setBackgroundColor(Color.parseColor("#ffffff"));
                news_desc.setFocusableInTouchMode(false);
                news_desc.setFocusable(false);
                news_desc.getSettings().setDefaultTextEncodingName("UTF-8");
    
                WebSettings webSettings = news_desc.getSettings();
                Resources res = getResources();
                int fontSize = res.getInteger(R.integer.font_size);
                webSettings.setDefaultFontSize(fontSize);
    
                String mimeType = "text/html; charset=UTF-8";
                String encoding = "utf-8";
                String htmlText = str_desc;
    
                String text = "<html><head>"
                        + "<style type=\"text/css\">body{color: #525252;}"
                        + "</style></head>"
                        + "<body>"
                        + htmlText
                        + "</body></html>";
    
                news_desc.loadData(text, mimeType, encoding);
    
                Picasso
                        .with(context)
                        .load(Config.SERVER_URL + "/upload/" + itemRecipesList.getNewsImage())
                        .placeholder(R.drawable.ic_thumbnail)
                        .into(img_news);
    
                List<ItemFavorite> itemFavorites = db.getFavRow(str_cat_id);
                if (itemFavorites.size() == 0) {
                    img_fav.setImageResource(R.drawable.ic_favorite_outline_white);
                } else {
                    if (itemFavorites.get(0).getCatId().equals(str_cat_id)) {
                        img_fav.setImageResource(R.drawable.ic_favorite_white);
                    }
                }
    
                img_fav.setOnClickListener(new View.OnClickListener() {
    
                    @Override
                    public void onClick(View v) {
    
                        List<ItemFavorite> itemFavorites = db.getFavRow(str_cat_id);
                        if (itemFavorites.size() == 0) {
    
                            db.AddtoFavorite(new ItemFavorite(str_cat_id, str_cid, str_cat_name, str_title, str_image, str_desc, str_date));
                            Toast.makeText(getApplicationContext(), getResources().getString(R.string.favorite_added), Toast.LENGTH_SHORT).show();
                            img_fav.setImageResource(R.drawable.ic_favorite_white);
    
                        } else {
                            if (itemFavorites.get(0).getCatId().equals(str_cat_id)) {
    
                                db.RemoveFav(new ItemFavorite(str_cat_id));
                                Toast.makeText(getApplicationContext(), getResources().getString(R.string.favorite_removed), Toast.LENGTH_SHORT).show();
                                img_fav.setImageResource(R.drawable.ic_favorite_outline_white);
                            }
                        }
                    }
                });
    
            }
    
        }
    
        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            getMenuInflater().inflate(R.menu.menu_share, menu);
            return super.onCreateOptionsMenu(menu);
        }
    
        @Override
        public boolean onOptionsItemSelected(MenuItem menuItem) {
            switch (menuItem.getItemId()) {
                case android.R.id.home:
                    onBackPressed();
                    break;
    
                case R.id.menu_share:
    
                    String formattedString = android.text.Html.fromHtml(str_desc).toString();
                    Intent sendIntent = new Intent();
                    sendIntent.setAction(Intent.ACTION_SEND);
                    sendIntent.putExtra(Intent.EXTRA_TEXT, str_title + "\n" + formattedString + "\n" + getResources().getString(R.string.share_text) + "https://play.google.com/store/apps/details?id=" + getPackageName());
                    sendIntent.setType("text/plain");
                    startActivity(sendIntent);
    
                    break;
    
                default:
                    return super.onOptionsItemSelected(menuItem);
            }
            return true;
        }
    
        @Override
        public void onStart() {
            super.onStart();
        }
    
        @Override
        public void onStop() {
            super.onStop();
        }
    
        private void loadAdMobBannerAd() {
            if (Config.ENABLE_ADMOB_BANNER_ADS) {
                adView = (AdView) findViewById(R.id.adView);
                AdRequest adRequest = new AdRequest.Builder().addNetworkExtrasBundle(AdMobAdapter.class, GDPR.getBundleAd(ActivityRecipesDetail.this)).build();
                adView.loadAd(adRequest);
                adView.setAdListener(new AdListener() {
    
                    @Override
                    public void onAdClosed() {
                    }
    
                    @Override
                    public void onAdFailedToLoad(int error) {
                        adView.setVisibility(View.GONE);
                    }
    
                    @Override
                    public void onAdLeftApplication() {
                    }
    
                    @Override
                    public void onAdOpened() {
                    }
    
                    @Override
                    public void onAdLoaded() {
                        adView.setVisibility(View.VISIBLE);
                    }
                });
            }
        }
    
    }
  • 09-02-2019, 07:20:38
    #2
    Hocam selamlar, öncelikle verinin JSON biçiminde geldiği durumlarda önerim okhttp, Serializable ve GSON librarylerini kullanarak veriyi doğru bir biçimde data model içerisine koymanız. Bu şekilde hem daha hızlı çalışacaktır,daha doğru olacaktır.Yaygın kullanım da bahsettiğim şekildedir.
    Eğer yazdığınız şekilde yapmaya devam etmek istiyorsanız PM atın, teamviewer ile diğer classlarınıza da bakıp ücretsiz bir şekilde hatayı çözmeye çalışırım.
    İyi çalışmalar.
  • 09-02-2019, 12:00:58
    #3
    Folloxme adlı üyeden alıntı: mesajı görüntüle
    Hocam selamlar, öncelikle verinin JSON biçiminde geldiği durumlarda önerim okhttp, Serializable ve GSON librarylerini kullanarak veriyi doğru bir biçimde data model içerisine koymanız. Bu şekilde hem daha hızlı çalışacaktır,daha doğru olacaktır.Yaygın kullanım da bahsettiğim şekildedir.
    Eğer yazdığınız şekilde yapmaya devam etmek istiyorsanız PM atın, teamviewer ile diğer classlarınıza da bakıp ücretsiz bir şekilde hatayı çözmeye çalışırım.
    İyi çalışmalar.
    Çok teşekkür ederim tw bilgilerini hemen özelden atıyorum sorunu biraz daha detaylandırdım üç telefonda test ettim General Mobile, Xperia ve Vestel Venüs. General Mobile ve Xperia ile tarif detayları gelmiyorken Vestel Venüs cihazda tarif geliyor programın içinde bir tane webview html görüntüleyici var bunu devre dışı bıraktım mı tüm cihazlarda sorunsuz geliyor lakin bu sefer tarif detayları çok sönük kalıyor html yorumlamada bir problem oluşuyor