0

I have this view pager of webviews and when the pie charts are loaded from the web service I have to zoom out by my fingers to get the result I want, how can I make it zoom out on page finished?

Here is my code:

private class CustomPagerAdapter extends PagerAdapter {

    private Context mContext;
    private LayoutInflater mLayoutInflater;
    private ArrayList<GraphItem> charts = new ArrayList<GraphItem>();
    Typeface type = null;

    public CustomPagerAdapter(Context context, ArrayList<GraphItem> charts) {
        mContext = context;
        mLayoutInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        this.charts = charts;

        if (MyApplication.lang.equals("en"))
            type = MyApplication.opensanregular;
        else
            type = MyApplication.gdenartwomeduim;
    }

    @Override
    public int getCount() {
        return charts.size();
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == ((LinearLayout) object);
    }

    @Override
    public Object instantiateItem(ViewGroup container, final int position) {
        View itemView = mLayoutInflater.inflate(R.layout.bar_item, container, false);
        final WebView chartWebView = (WebView) itemView.findViewById(R.id.chartview);
        final TextView topicTitle = (TextView) itemView.findViewById(R.id.topicTitle);
        final ImageView ivIndicator = (ImageView) itemView.findViewById(R.id.ivIndicator);
        final RelativeLayout titlelayout=(RelativeLayout) itemView.findViewById(R.id.titlelayout);
        if(MyApplication.lang.equals("ar")) {
            titlelayout.setLayoutDirection(View.LAYOUT_DIRECTION_RTL);
            topicTitle.setTypeface(MyApplication.gdenarBold);
        }
        Picasso.with(CountryProfileActivity.this)
                .load(charts.get(position).getMobileIconURL())
                //.placeholder(R.mipmap.icon)
                //.resize(250,200)
                //.rotate(90)
                .into(ivIndicator);
        topicTitle.setVisibility(View.VISIBLE);
        topicTitle.setTypeface(type);
        chartWebView.getSettings().setJavaScriptEnabled(true);
        chartWebView.getSettings().setAllowFileAccess(true);
        chartWebView.getSettings().setAllowContentAccess(true);
        chartWebView.getSettings().setLoadWithOverviewMode(true);
        chartWebView.getSettings().setUseWideViewPort(true);;
        chartWebView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
        //wvReport.addJavascriptInterface(new JavaScriptInterface(this), "Android");

        chartWebView.setWebViewClient(new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                return false;
            }

            @Override
            public void onPageFinished(WebView view, String url) {
                super.onPageFinished(view, url);
                if (MyApplication.lang.equals("ar"))
                    topicTitle.setText(charts.get(position).getTopicTitleAr());
                else
                    topicTitle.setText(charts.get(position).getTopicTitleEn());
            }
        });

        chartWebView.setWebChromeClient(new WebChromeClient() {
            @Override
            public void onProgressChanged(WebView view, int progress) {

            }

            @Override
            public void onReceivedTitle(WebView view, String title) {

            }
        });
        //wvReport.loadUrl(url);

        if (MyApplication.lang.equals("en")) {
            topicTitle.setTypeface(MyApplication.opensansBol);
            chartWebView.loadDataWithBaseURL("file:///android_asset/", "<html><head>\n" +
                    "<style type=\"text/css\">\n" +
                    "@font-face {\n" +
                    "    font-family: MyFont;\n" +
                    "    src: url(\"file:///android_asset/OpenSans-Regular.ttf\")\n" +
                    "}\n" +
                    "body {\n" +
                    "    font-family: MyFont;\n" +
                    "    text-align: justify;\n" +
                    "}\n" +
                    "</style><body>" + charts.get(position).getPieChart() + "</body></html>", "text/html", "UTF-8", "");
        }else{
            chartWebView.loadDataWithBaseURL("file:///android_asset/", "<html><head>\n" +
                    "<style type=\"text/css\">\n" +
                    "@font-face {\n" +
                    "    font-family: MyFont;\n" +
                    "    src: url(\"file:///android_asset/GE_Dinar_Two_Medium.otf\")\n" +
                    "}\n" +
                    "body {\n" +
                    "    font-family: MyFont;\n" +
                    "    text-align: justify;\n" +
                    "}\n" +
                    "</style><body>" + charts.get(position).getPieChart() + "</body></html>", "text/html", "UTF-8", "");
        }


        container.addView(itemView);
        chartWebView.setBackgroundColor(0);

        return itemView;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView((LinearLayout) object);
    }
}

Here is the image without using view port

No port

Here is the image with port (it becomes very small)

With port

And here is with fingers zoom out (the result I want)

enter image description here

halfer
  • 19,824
  • 17
  • 99
  • 186
eshteghel company
  • 471
  • 1
  • 7
  • 22

0 Answers0