Search in sources :

Example 1 with PreferencesHelper

use of top.wefor.now.PreferencesHelper in project Now by XunMengWinter.

the class WebActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_webview);
    ButterKnife.bind(this);
    mContext = this;
    mUrl = getIntent().getStringExtra(EXTRA_URL);
    mTitle = getIntent().getStringExtra(EXTRA_TITLE);
    picUrl = getIntent().getStringExtra(EXTRA_PIC_URL);
    summary = getIntent().getStringExtra(EXTRA_SUMMARY);
    new Thread() {

        @Override
        public void run() {
            super.run();
            // }
            try {
                Drawable drawable = Glide.with(WebActivity.this).load(picUrl).submit(120, 120).get();
                bitmap = ImageUtil.drawableToBitmap(drawable);
            } catch (InterruptedException | ExecutionException e) {
                e.printStackTrace();
            }
        }
    }.start();
    mWebView.setWebChromeClient(new ChromeClient());
    mWebView.setWebViewClient(new ViewClient());
    WebSettings webSettings = mWebView.getSettings();
    webSettings.setJavaScriptEnabled(new PreferencesHelper(App.getInstance()).isJSEnabled());
    webSettings.setLoadWithOverviewMode(true);
    webSettings.setAppCacheEnabled(true);
    webSettings.setAppCachePath(Constants.WEB_CACHE_DIR);
    if (NowAppUtil.isWifiConnected())
        webSettings.setCacheMode(WebSettings.LOAD_DEFAULT);
    else
        webSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
    mWebView.loadUrl(mUrl);
    mWebView.setOnTouchListener(this);
    setTitle(mTitle);
    mFloatingActionButton.setVisibility(View.GONE);
}
Also used : WebChromeClient(android.webkit.WebChromeClient) WebViewClient(android.webkit.WebViewClient) WebSettings(android.webkit.WebSettings) Drawable(android.graphics.drawable.Drawable) PreferencesHelper(top.wefor.now.PreferencesHelper)

Example 2 with PreferencesHelper

use of top.wefor.now.PreferencesHelper in project Now by XunMengWinter.

the class NGListFragment method getData.

@Override
public void getData() {
    // String nGUrl = "http://photography.nationalgeographic.com/photography/";
    Observable.create((ObservableOnSubscribe<Document>) observableEmitter -> {
        if (!PrefUtil.isNeedRefresh(Constants.KEY_REFRESH_TIME_NG)) {
            observableEmitter.onComplete();
            return;
        }
        try {
            Document document = Jsoup.connect(Urls.NG_BASE_URL).get();
            observableEmitter.onNext(document);
        } catch (IOException e) {
            e.printStackTrace();
            observableEmitter.onComplete();
        }
    }).subscribeOn(Schedulers.io()).observeOn(Schedulers.computation()).doOnNext(document -> {
        mList.clear();
        // Logger.i(document.ownText());
        PrefUtil.setRefreshTime(Constants.KEY_REFRESH_TIME_NG, new Date().getTime());
        Element contents = document.getElementById("ajaxBox");
        Elements list = contents.getElementsByClass("ajax_list");
        for (int i = 0; i < SIZE && i < list.size(); i++) {
            Element element = list.get(i);
            NG nG = new NG();
            Element imageA = element.select("dd").first().select("a").first();
            nG.url = pass(imageA.attr("href"));
            nG.imgUrl = pass(imageA.select("img").first().attr("src"));
            nG.title = pass(imageA.select("img").first().attr("alt"));
            nG.content = pass(element.getElementsByClass("ajax_dd_text").first().ownText());
            Log.i("xyz ", "ngfragment " + nG.content + nG.imgUrl + nG.url + nG.title);
            mList.add(nG);
        }
        if (mList.size() > 0) {
            PreferencesHelper preferencesHelper = new PreferencesHelper(App.getInstance());
            // 设置封面图,set Cover image
            preferencesHelper.setCoverImage(mList.get(0).imgUrl);
            // setHeadImages
            JSONArray jsonArray = new JSONArray();
            for (int i = 0; i < Math.min(mList.size(), 6); i++) jsonArray.add(mList.get(i).imgUrl);
            preferencesHelper.setNgImages(jsonArray.toJSONString());
        }
    }).observeOn(AndroidSchedulers.mainThread()).doOnComplete(this::showList).subscribe(document -> {
        saveData();
        showList();
    });
}
Also used : PrefUtil(top.wefor.now.utils.PrefUtil) Bundle(android.os.Bundle) WebActivity(top.wefor.now.ui.activity.WebActivity) Constants(top.wefor.now.Constants) ObservableOnSubscribe(io.reactivex.ObservableOnSubscribe) Date(java.util.Date) PreferencesHelper(top.wefor.now.PreferencesHelper) NG(top.wefor.now.data.model.entity.NG) Intent(android.content.Intent) NonNull(android.support.annotation.NonNull) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) JSONArray(com.alibaba.fastjson.JSONArray) Urls(top.wefor.now.data.http.Urls) Element(org.jsoup.nodes.Element) BaseListAdapter(top.wefor.now.ui.adapter.BaseListAdapter) Observable(io.reactivex.Observable) Schedulers(io.reactivex.schedulers.Schedulers) RealmNG(top.wefor.now.data.model.realm.RealmNG) Log(android.util.Log) R(top.wefor.now.R) NGAdapter(top.wefor.now.ui.adapter.NGAdapter) IOException(java.io.IOException) List(java.util.List) App(top.wefor.now.App) Document(org.jsoup.nodes.Document) Jsoup(org.jsoup.Jsoup) Elements(org.jsoup.select.Elements) Nullable(android.support.annotation.Nullable) Element(org.jsoup.nodes.Element) JSONArray(com.alibaba.fastjson.JSONArray) NG(top.wefor.now.data.model.entity.NG) RealmNG(top.wefor.now.data.model.realm.RealmNG) IOException(java.io.IOException) Document(org.jsoup.nodes.Document) Elements(org.jsoup.select.Elements) Date(java.util.Date) PreferencesHelper(top.wefor.now.PreferencesHelper)

Example 3 with PreferencesHelper

use of top.wefor.now.PreferencesHelper in project Now by XunMengWinter.

the class GankDailyActivity method initViews.

@Override
protected void initViews(Bundle savedInstanceState) {
    mFragmentPagerAdapter = new FragmentPagerAdapter(getSupportFragmentManager()) {

        @Override
        public Fragment getItem(int position) {
            return mFragments.get(position);
        }

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

        @Override
        public CharSequence getPageTitle(int position) {
            return mTitles.get(position);
        }
    };
    mGankTabLayout.setupWithViewPager(mViewPager);
    mViewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(mGankTabLayout));
    mViewPager.setAdapter(mFragmentPagerAdapter);
    mPreferencesHelper = new PreferencesHelper(this);
    showLastGankImage();
    getTheLatestGank();
}
Also used : FragmentPagerAdapter(android.support.v4.app.FragmentPagerAdapter) TabLayout(android.support.design.widget.TabLayout) Fragment(android.support.v4.app.Fragment) PreferencesHelper(top.wefor.now.PreferencesHelper)

Aggregations

PreferencesHelper (top.wefor.now.PreferencesHelper)3 Intent (android.content.Intent)1 Drawable (android.graphics.drawable.Drawable)1 Bundle (android.os.Bundle)1 NonNull (android.support.annotation.NonNull)1 Nullable (android.support.annotation.Nullable)1 TabLayout (android.support.design.widget.TabLayout)1 Fragment (android.support.v4.app.Fragment)1 FragmentPagerAdapter (android.support.v4.app.FragmentPagerAdapter)1 Log (android.util.Log)1 WebChromeClient (android.webkit.WebChromeClient)1 WebSettings (android.webkit.WebSettings)1 WebViewClient (android.webkit.WebViewClient)1 JSONArray (com.alibaba.fastjson.JSONArray)1 Observable (io.reactivex.Observable)1 ObservableOnSubscribe (io.reactivex.ObservableOnSubscribe)1 AndroidSchedulers (io.reactivex.android.schedulers.AndroidSchedulers)1 Schedulers (io.reactivex.schedulers.Schedulers)1 IOException (java.io.IOException)1 Date (java.util.Date)1