Skip to content

Commit

Permalink
提交文件
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaodingfeng committed Apr 22, 2020
1 parent a153d46 commit 033c8f0
Show file tree
Hide file tree
Showing 9 changed files with 166 additions and 3 deletions.
1 change: 1 addition & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/build

1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ android {

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'org.jsoup:jsoup:1.13.1'
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.zhihu.android:matisse:0.5.2-beta4'
implementation 'com.github.bumptech.glide:glide:4.8.0'
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />

<uses-permission android:name="android.permission.INTERNET"/>
<application
android:name=".MyApplication"
android:allowBackup="true"
Expand Down Expand Up @@ -34,7 +34,7 @@
android:name=".ui.NoteActivity"
android:theme="@style/AppTheme.NoActionBar" />
<activity android:name=".ui.AlarmAlertActivity" />

<activity android:name=".ui.Meiwen" />
<receiver android:name=".ui.AlarmReceiver"
android:permission="TODO">
<intent-filter>
Expand Down
43 changes: 43 additions & 0 deletions app/src/main/java/com/example/xiaobai/yynote/bean/Article.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.example.xiaobai.yynote.bean;


public class Article {
private String ArticleTitle; //标题
private String ArticleUrl; //链接地址
private String ArticleWho; //来源
private String Content;

public Article(String ArticleTitle, String ArticleUrl, String ArticleWho,String Content) {
this.ArticleTitle = ArticleTitle;
this.ArticleUrl = ArticleUrl;
this.ArticleWho = ArticleWho;
this.Content=Content;
}


public String getArticleWho() {
return ArticleWho;
}

public void setArticleWho(String newsTime) {
this.ArticleWho = newsTime;
}

public String getArticleTitle() {
return ArticleTitle;
}

public void setArticleTitle(String newsTitle) {
this.ArticleTitle = newsTitle;
}

public String getArticleUrl() {
return ArticleUrl;
}
public String getContents() {
return Content;
}
public void setArticleUrl(String newsUrl) {
this.ArticleUrl = newsUrl;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,9 @@ public boolean onOptionsItemSelected(MenuItem item) {
editor.putString("ShowNotesModel",showNotesModel);
editor.apply(); //editor.commit();
refreshLayoutManager();
}else if(id==R.id.Article){
Intent intent = new Intent(MainActivity.this, Meiwen.class);
startActivity(intent);
}
return super.onOptionsItemSelected(item);
}
Expand Down
86 changes: 86 additions & 0 deletions app/src/main/java/com/example/xiaobai/yynote/ui/Meiwen.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package com.example.xiaobai.yynote.ui;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.widget.TextView;

import com.example.xiaobai.yynote.R;
import com.example.xiaobai.yynote.bean.Article;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;

import java.io.IOException;
import java.util.List;

public class Meiwen extends AppCompatActivity {
private Handler handler;
private List<Article> newsList;
private TextView textView;
private TextView textView1;
@SuppressLint("HandlerLeak")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if(getSupportActionBar() !=null) {

getSupportActionBar().hide();
}
setContentView(R.layout.meiweneveryday);
textView=(TextView)findViewById(R.id.textView2);
textView1=(TextView)findViewById(R.id.textView4);
getNews();
handler = new Handler() {
@SuppressLint("SetTextI18n")
@Override
public void handleMessage(Message msg) {
textView.setText("handleMessage。。。");
textView1.setText("handleMessage。。。");
if (msg.what == 1) {
Article news = newsList.get(0);
textView.setText(news.getArticleTitle()+"\n"+news.getArticleWho());
textView1.setText(news.getContents());
}
else{
textView.setText("加载中。。。");
textView1.setText("加载中。。。");
}
}
};
}

private void getNews(){
new Thread(new Runnable() {
@Override
public void run() {
try{
int i= (int) (Math.random() * 36);
textView.setText("加载中。。。");
textView1.setText("加载中。。。");
Document doc = Jsoup.connect("http://www.xiaole8.com/renshengzheli/page_"+Integer.toString(i)+".html").get();
Elements titleLinks = doc.select("ul.l2"); //解析来获取每条新闻的标题与链接地址
Elements titlelins = titleLinks.get(0).select("li");
int j= (int) (Math.random() * titlelins.size());
String uri = titlelins.get(j).select("a").attr("href");
String title = titlelins.get(j).select("a").text();
Document doc1 = Jsoup.connect(uri).get();
String mainarctile=doc1.select("div.wzcon").select("p").text();
String laiyuan=doc1.select("div.info").text();
mainarctile=mainarctile.replaceAll("<br>","\n");
Article article = new Article(title, uri,laiyuan,mainarctile);
newsList.add(article);
Message msg = new Message();
msg.what = 1;
handler.sendMessage(msg);

}catch (Exception e){
e.printStackTrace();
}
}
}).start();
}
}
24 changes: 24 additions & 0 deletions app/src/main/res/layout/meiweneveryday.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
android:id="@+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAlignment="center"
android:textSize="18sp"
android:text="标题"
android:gravity="center_horizontal" />

<TextView
android:id="@+id/textView4"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/textView2"
android:text="TextView" />


</RelativeLayout>
5 changes: 5 additions & 0 deletions app/src/main/res/menu/main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,9 @@
android:orderInCategory="100"
android:title="@string/grid_model"
app:showAsAction="never" />
<item
android:id="@+id/Article"
android:orderInCategory="100"
android:title="轻阅读"
app:showAsAction="never" />
</menu>
2 changes: 1 addition & 1 deletion gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ goto fail
@rem Get command-line arguments, handling Windows variants

if not "%OS%" == "Windows_NT" goto win9xME_args

:win9xME_args
@rem Slurp the command line arguments.
set CMD_LINE_ARGS=
Expand Down

0 comments on commit 033c8f0

Please sign in to comment.