导航菜单

页面标题

页面副标题

自健身 v3.3.4 - GymHtmlDetailActivity.java 源代码

正在查看: 自健身 v3.3.4 应用的 GymHtmlDetailActivity.java JAVA 源代码文件

本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。


package com.mu.gymtrain.Activity.MainPackage;

import android.graphics.Bitmap;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageView;
import android.widget.TextView;
import butterknife.BindView;
import butterknife.OnClick;
import com.blankj.utilcode.util.LogUtils;
import com.mu.gymtrain.Base.BaseActivity;
import com.mu.gymtrain.Http.HttpHelper;
import com.mu.gymtrain.R;
import com.mu.gymtrain.Utils.PreferenceUtils;
import com.mu.gymtrain.Utils.UrlConfig;
import com.mu.gymtrain.Utils.ViewUtils;
import java.io.IOException;
import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class GymHtmlDetailActivity extends BaseActivity {

    @BindView(R.id.title_left)
    ImageView titleLeft;

    @BindView(R.id.title_middle)
    TextView titleMiddle;
    private WebSettings webSettings;

    @BindView(R.id.webView)
    WebView webView;

    public int getContentLayout() {
        return R.layout.activity_gymdetail;
    }

    public void initView() {
        this.titleMiddle.setText(getString(R.string.introduce));
        initWebView();
    }

    public void initData() {
        getDetail();
    }

    private void getDetail() {
        String string = PreferenceUtils.getInstance().getString("currentgymid", "");
        ViewUtils.showLoading(this, "加载中...");
        HttpHelper.getInstance().getRetrofitService(this).getGymDetail(UrlConfig.Path.GET_GYMDETAIL + string, getToken()).enqueue(new Callback<ResponseBody>() {
            @Override
            public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
                ViewUtils.hideLoading();
                try {
                    String string2 = ((ResponseBody) response.body()).string();
                    LogUtils.i(new Object[]{string2});
                    GymHtmlDetailActivity.this.webView.loadData(string2.replaceAll("/public/upload", "https://www.zijianshen.com//public/upload"), "text/html;charset=utf-8", "utf-8");
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onFailure(Call<ResponseBody> call, Throwable t) {
                ViewUtils.hideLoading();
            }
        });
    }

    private void initWebView() {
        WebSettings settings = this.webView.getSettings();
        this.webSettings = settings;
        settings.setAllowContentAccess(true);
        this.webSettings.setAppCacheEnabled(false);
        this.webSettings.setBuiltInZoomControls(false);
        this.webSettings.setUseWideViewPort(true);
        this.webSettings.setLoadWithOverviewMode(true);
        this.webSettings.setAppCacheEnabled(true);
        this.webSettings.setDomStorageEnabled(true);
        this.webSettings.setDatabaseEnabled(true);
        this.webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
        this.webView.setSaveEnabled(true);
        this.webView.setKeepScreenOn(true);
        this.webSettings.setCacheMode(1);
        this.webView.setWebViewClient(new WebViewClient() {
            @Override
            public void onPageFinished(final WebView view, final String url) {
                super.onPageFinished(view, url);
            }

            @Override
            public void onPageStarted(WebView view, String url, Bitmap favicon) {
                super.onPageStarted(view, url, favicon);
            }

            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                view.loadUrl(url);
                return true;
            }

            @Override
            public void onLoadResource(WebView webView, String s) {
                super.onLoadResource(webView, s);
            }
        });
    }

    @OnClick({R.id.title_left})
    public void onViewClicked() {
        finish();
    }
}