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);
}
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();
});
}
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();
}
Aggregations