Ứng dụng đọc báo với RSS

48 536 1
Ứng dụng đọc báo với RSS

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

TÍCH HỢP MẠNG XÃ HỘI VÀO ỨNG DỤNG ANDROID, ứng dụng đọc báo với RSS, tìm hiểu về HĐH Android, chuẩn RSS, Khảo sát yêu cầu hệ thống, phân tích yêu cầu, đặc tả usecase, thiết kế giao diện ứng dụng, ứng dụng, tích hợp mạng xã hội Facebook.

BAN CƠ YẾU CHÍNH PHỦ HỌC VIỆN KỸ THUẬT MẬT Mà ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯ THỰC TẬP CƠ SỞ TÍCH HỢP MẠNG Xà HỘI VÀO ỨNG DỤNG ANDROID Ngành: Công nghệ thông tin Chun ngành: An tồn thơng tin Hà Nội, 2017 BAN CƠ YẾU CHÍNH PHỦ HỌC VIỆN KỸ THUẬT MẬT Mà ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯ THỰC TẬP CƠ SỞ TÍCH HỢP MẠNG Xà HỘI VÀO ỨNG DỤNG ANDROID Ngành: Công nghệ thông tin Chuyên ngành: An tồn thơng tin Sinh viên thực hiện: Trịnh Thị Mai Lớp: AT10D Người hướng dẫn: GV: Lê Anh Tiến Khoa Công nghệ thông tin – Học viện Kỹ thuật mật mã Hà Nội, 2017 MỤC LỤC Danh mục kí hiệu viết tắt vi Danh mục hình vẽ vii Danh mục bảng viii Lời cảm ơn ix Lời nói đầu .x Chương Giới thiệu chung 1.1 Android gì? 1.2.1 Khái niệm .1 1.2.2 Lịch sử phát triển 1.1.3 Các đặc điểm Android 1.1.4 Kiến trúc Android 1.1.5 Giao diện phiên Android .6 1.2 Chuẩn RSS 17 1.2.1 Khái niệm chuẩn RSS 17 1.2.2 Cấu trúc thẻ RSS 17 1.3 Kết luận chương 18 Chương Phần ứng dụng 20 2.1 Khảo sát yêu cầu hệ thống 20 2.2 Phân tích yêu cầu 20 2.2.1 Sơ đồ nghiệp vụ: 20 2.2.2 Đặc tả chi tiết Usecase .20 2.3 Thiết kế ứng dụng 21 2.3.1 Thiết kế giao diện ứng dụng 21 2.3.2 Thiết kế giao diện chức 23 2.4 Kết luận chương 24 Chương Phần chức 25 3.1 Add SDK 25 3.2 Add Facebook App ID 25 3.3 Kết luận chương 25 Chương 4: Xây dựng ứng dụng thực nghiệm kết 26 4.1 Yêu cầu chương trình 26 4.2 Lựa chọn cơng cụ lập trình .26 4.3 Giới thiệu chương trình 27 4.4 Kết luận chương 29 Kết luận 30 Tài liệu tham khảo .31 Phụ lục 32 i DANH MỤC KÍ HIỆU VÀ VIẾT TẮT NFC Near-Field Communications, công nghệ kết nối không dây phạm vi tầm ngắn SDK Gói phát triển phần mềm UI User Interface, Giao diện người dùng GSM Global System for Mobile Communications EDGE Enhanced Data Rates for GSM Evolution IDEN Mạng số tích hợp nâng cao CDMA Code Division Multiple Access LTE Long Term Evolution JPEG oint Photographic Experts Group PNG Portable Network Graphics GIF Graphics Interchange Format SMS Short Message Services MMS Multimedia Messaging Service HTML HyperText Markup Language XHTML Extensible HyperText Markup Language GPS Global Positioning System ii DANH MỤC HÌNH VẼ Hình 1.1: phiên SDK Android Hình 1.2: Kiến trúc Android Hình 1.3: Android 1.0 Hình 1.4: Android 1.1 Hình 1.5: Android 1.5 Hình 1.6: Android 1.6 Hình 1.7: Android 2.0 Hình 1.8: Android 2.2 10 Hình 1.9: Android 2.3 10 Hình 1.10: Android 3.0 11 Hình 1.11: Android 4.0 12 Hình 1.12: Android 4.3 13 Hình 1.13: Android 4.4 13 Hình 1.14: Android 5.0 14 Hình 1.15: Android 6.0 14 Hình 1.16 :hình ảnh Android 7.0 Samsung Galaxy J7 Prime 15 Hình 1.17: Android 8.0 16 Hình 2.1: Usecase người dùng 20 Hình 4.1: Giao diện ứng dụng .27 Hình 4.2: Hành động Login Logout 28 Hình 4.3: Màn hình đăng nhập 29 iii DANH MỤC BẢNG Bảng Đặc tả chi tiết Usecase đăng nhập 20 iv LỜI CẢM ƠN Trong trình thực thực tập sở này, nhận giúp đỡ tận tình cán hướng dẫn GV Lê Anh Tiến – Khoa Công nghệ thông tin Học viện Kỹ thuật Mật mã,… Xin cảm ơn tất người tạo điều kiện tốt để hoàn thành thực tập sở này! SINH VIÊN THỰC HIỆN Trịnh Thị Mai v LỜI NÓI ĐẦU Ngày nay, mà thiết bị di động nói chung điện thoại di động( Smartphone) nói riêng trở thành vật bất thân hầu hết người sống hàng ngày, lĩnh vực ngành nghề Trong đó, Snmartphone sử dụng hệ điều hành Android chiếm phần lớn tổng số Smartphone tồn giới Theo báo tài q năm 2014, Google cơng bố, có đến 250 triệu thiết bị chạy Android kích haotj có đến 11 tỉ lượt tải ứng dụng từ Android market Điều cho thấy, ứng dụng Android ngày phổ biến đáp ứng gần đầy đủ yêu cầu khách hàng Từ số trên, ta thấy phát triển lập trình ứng dụng Android cơng việc Lập trình viên Android ln ln tìm tòi phát triển nhiều ứng dụng phục vụ người dùng Ngoài ra, mà ứng dụng Android phát triển mạnh mẽ người dùng đòi hỏi chúng tiện lợi, nhanh chóng, dễ chia sẻ kết nối mạng xã hội bùng nổ mạnh mẽ Facebook, Twitter, Google… mà không cần thông qua app thức Chính vậy, chúng tơi phát triển ứng dụng mà tích hợp sẵn mạng xã hội dựa ứng dụng đọc tin tức có hiệu chất lượng Bài báo cáo chia thành Chương: - Chương 1: Giới thiệu chung - Chương 2: Phần ứng dụng - Chương 3: Phần chức - Chương 4: Thực nghiệm SINH VIÊN THỰC HIỆN Trần Văn Tam vi CHƯƠNG GIỚI THIỆU CHUNG 1.1 Android gì? 1.1.1 Khái niệm: Android hệ điều hành mã nguồn mở hệ điều hành dựa Linux cho thiết bị mobile Smartphone máy tính bảng Ban đầu, Android phát triển công ty Android với hỗ trợ tài Google, nhiên sau Google mua lại vào năm 2005 Android đưa phương pháp thống để phát triển ứng dụng cho thiết bị động, nghĩa lập trình viên cần phát triển Android ứng dụng khác chạy thiết bị động khác chạy hệ điều hành Android 1.1.2 Lịch sử phát triển: - 10/2003, Android, Inc, thành lập Palo Alto, Califorlia Andy Rubin, Rich Miners, Nick Sears Chris White - Tháng 7/2005, Google mua lại Android, Inc - 5/11/2007, Open Handset Alliance, liên minh nhà sản xuất thành lập - 12/11/2007, phiên Beta Android Software Development Kit( SDK) công bố Google - 23/9/2008, phiên thương mại Android 1.0 công bố Thiết bị chạy Android HTC Dream - 09/02/2009, phát hành cập nhật Android 1.1 dành riêng cho T-Mobile G1 - 30/04/2009, phát hành cập nhật 1.5 dựa nhân Linux 2.6.27 - 15/09/2009, phát hành SDK dành cho Android 1.6 dựa nhân Linux 2.6.29 - 26/10/2009, phát hành SDK dành cho Android 2.0 dựa nhân Linux 2.6.29 - 03/12/20099, Phát hành SDK Android 2.0.1 - 12/01/2010, phát hành SDK Android 2.1 - 20/05//2010, phát hành SDK dành cho Android 2.2 dựa nhân Linux 2.6.32 - 06/12/2010, phát hành SDK Android 2.2 - 06/12/2010, phát hành SDK Android 2.3 - - 22/02/2011, phát hành SDK Android 2.3.3 22/02/2011, phát hành SDK Android 3.0 dánh cho tablet 10/05/2011, phát hành SDK Android 3.0 18/07/2011, phát hành SDK Android 3.2 Cuối năm 2011, Android 4.0 Ice Cream Sandwich mắt 27/06/2012, Google công bố phiên 4.1 Jelly Bean với mục đích cải thiên giao diện người dung, tính hiệu suất 30/10/2012, Google thức tuyên bố cập nhật hệ điều hành Android hãng lên phiên 4.2 giữ nguyên tên gọi “Jelly Bean” 2013, Android KitKat 4.4 giới thiệu 2014, Android Lolipop 5.0 mắt công chúng 09/2015, Android Marshmallow 6.0 phát hành 06/2016, Android Nougat 7.0 mắt thức 2017, Android Oreo Google phục vụ Hình 1.1: Các Phiên SDK Android CHƯƠNG XÂY DỰNG ỨNG DỤNG THỰC NGHIỆM VÀ KẾT QUẢ 4.1 Yêu cầu chương trình - Lấy tin tức https://vnexpress.net/rss/thoi-su.rss dạng listview - Kết nối đến với Facebook App - Login facebook thành công, trả thông tin người dùng - Share tin tức lên trang cá nhân người dùng thành công 4.2 Lựa chọn công cụ lập trình - Cơng cụ lập trình sử dụng Android studio 2.3.3 với minSDKVersion 15, targetSDKVersion 25, buildToolVersion 25.3.1 - Ngơn ngữ lập trình: Java Android 26 4.3 Giới thiệu chương trình Hình 4.1: Giao diện ứng dụng 27 Hình 4.2: Hành động Login Logout 28 Hình 4.3 : Màn hình đăng nhập Facebook 4.4 Kết luận chương - Hoàn thành thực nghiệm ứng dụng đọc tin tức thời với RSS 29 KẾT LUẬN Bốn chương chuyên đề thể mục tiêu đặt thực chuyên đề đạt Cụ thể: Chương Đã giới thiệu lại tổng quan hệ điều ành Android kiến thức cần thiết chuẩn RSS sử dụng ứng dụng thực nghiệm Chương Đã phân tích yêu cầu cho ứng dụng, thiết kế ứng dụng,từ đáp ứng yêu cầu ứng dụng để tích hợp chức theo yêu cầu đề tài Chương Lần lượt theo bước tích hợp mạng xã hội vào App, hồn thành yêu cầu đăng nhập tài khaonr facebook, có thông tin người dùng chia sẻ tin tức lên trang cá nhân Trong chương 4, đưa ứng dụng thực nghiệm với thiết kế đặt Dù vậy, số vấn đề chưa hoàn thiện như: - Giao diện ứng dụng chưa đáp ứng yêu cầu đẹp thân thiện với người dùng - Ứng dụng đơn giản, đáp ứng đủ yêu cầu thiết kế - Mới tích hợp mạng xác hội Facebook, ngồi mạng xã hội phổ biến khác Twitter, G+,… chưa tích hợp 30 TÀI LIỆU THAM KHẢO [1] https://developers.facebook.com/docs/android [2] https://tinhte.vn/threads/tim-hieu-qua-trinh-phat-trien-cua-android-qua-cacphien-ban.1367201/ [3] http://www.whatisrss.com/ [4] http://www.xml.com/pub/a/2002/12/18/dive-into-xml.html [5] http://blogspace.com/rss [6] http://www.shoutem.com/app/rss-feed 31 PHỤ LỤC Mã chương trình minh họa hoạt động: - MainActivity.java: package com.example.user.app_ttcscn; import import import import import import import import import import import import import import import android.app.ProgressDialog; android.content.Intent; android.content.pm.PackageInfo; android.content.pm.PackageManager; android.content.pm.Signature; android.os.AsyncTask; android.os.Bundle; android.support.v7.app.AppCompatActivity; android.support.v7.widget.LinearLayoutManager; android.support.v7.widget.RecyclerView; android.support.v7.widget.Toolbar; android.util.Base64; android.util.Log; android.view.Menu; android.view.MenuItem; import import import import com.example.user.app_ttcscn.Adapter.FeedAdapter; com.example.user.app_ttcscn.Common.HTTPDataHandler; com.example.user.app_ttcscn.Model.RootObject; com.google.gson.Gson; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; public class MainActivity extends AppCompatActivity { Toolbar toolbar; RecyclerView recyclerView; RootObject rootObject; // RSS String RSS_Link= "https://vnexpress.net/rss/thoi-su.rss"; String RSS_to_Json_API= "https://api.rss2json.com/v1/api.json?rss_url="; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); toolbar= (Toolbar)findViewById(R.id.toolbar); toolbar.setTitle("Thời sự"); setSupportActionBar(toolbar); recyclerView= (RecyclerView)findViewById(R.id.recyclerView); LinearLayoutManager linearLayoutManager= new LinearLayoutManager(getBaseContext(),LinearLayoutManager.VERTICAL, false); recyclerView.setLayoutManager(linearLayoutManager); loadRSS(); try { PackageInfo info = getPackageManager().getPackageInfo( "com.example.user.app_ttcscn", PackageManager.GET_SIGNATURES); for (Signature signature : info.signatures) { MessageDigest md = MessageDigest.getInstance("SHA"); md.update(signature.toByteArray()); Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT)); } 32 } catch (PackageManager.NameNotFoundException e) { } catch (NoSuchAlgorithmException e) { } } private void loadRSS() { AsyncTask loadRSSAsync= new AsyncTask() { ProgressDialog dialog= new ProgressDialog(MainActivity.this); @Override protected void onPreExecute() { dialog.setMessage("Please wait "); dialog.show(); } @Override protected String doInBackground(String params) { String result; HTTPDataHandler http= new HTTPDataHandler(); result= http.GetHTTPData(params[0]); return result; } @Override protected void onPostExecute(String s) { dialog.dismiss(); rootObject= new Gson().fromJson(s,RootObject.class ); FeedAdapter adapter= new FeedAdapter(rootObject, getBaseContext()); recyclerView.setAdapter(adapter); adapter.notifyDataSetChanged(); } }; StringBuilder url_get_data = new StringBuilder((RSS_to_Json_API)); url_get_data.append(RSS_Link); loadRSSAsync.execute(url_get_data.toString()); } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.menu_bar, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { if (item.getItemId()== R.id.refresh) { loadRSS(); }else { if (item.getItemId() == R.id.login) { Intent intent= new Intent(MainActivity.this, Facebook_Login.class); startActivity(intent); } } return true; } } - Facebook_Login.java: 33 - package com.example.user.app_ttcscn; import import import import import import android.content.Intent; android.os.Bundle; android.support.v7.app.AppCompatActivity; android.util.Log; android.view.View; android.widget.TextView; import import import import import import import import import import com.facebook.AccessToken; com.facebook.CallbackManager; com.facebook.FacebookCallback; com.facebook.FacebookException; com.facebook.FacebookSdk; com.facebook.GraphRequest; com.facebook.GraphResponse; com.facebook.login.LoginResult; com.facebook.login.widget.LoginButton; com.facebook.login.widget.ProfilePictureView; import org.json.JSONObject; import java.util.Arrays; public class Facebook_Login extends AppCompatActivity { LoginButton loginButton; ProfilePictureView profilePictureView; TextView txtName, txtEmail, txtFirtName; CallbackManager callbackManager; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); FacebookSdk.sdkInitialize(getApplicationContext()); callbackManager= CallbackManager.Factory.create(); setContentView(R.layout.activity_facebook login); loginButton= (LoginButton)findViewById(R.id.login_button); profilePictureView= (ProfilePictureView)findViewById(R.id.friendProfilePicture); txtName= (TextView)findViewById(R.id.name); txtEmail=(TextView)findViewById(R.id.email); txtFirtName=(TextView)findViewById(R.id.firt_name); txtName.setVisibility(View.INVISIBLE); txtEmail.setVisibility(View.INVISIBLE); txtFirtName.setVisibility(View.INVISIBLE); loginButton.setReadPermissions(Arrays.asList("profile_picture", "email")); setLogin_Button(); } private void setLogin_Button() { loginButton.registerCallback(callbackManager, new FacebookCallback() { @Override public void onSuccess(LoginResult loginResult) { result();// fuction lay thong tin ve loginButton.setVisibility(View.INVISIBLE); txtName.setVisibility(View.VISIBLE); txtEmail.setVisibility(View.VISIBLE); txtFirtName.setVisibility(View.VISIBLE); } @Override public void onCancel() 34 { } @Override public void onError(FacebookException error) { } }); } private void result() { GraphRequest graph= GraphRequest.newMeRequest(AccessToken.getCurrentAccessToken(), new GraphRequest.GraphJSONObjectCallback() { @Override public void onCompleted(JSONObject object, GraphResponse response) { Log.d("json", response.getJSONObject().toString()); } }); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); callbackManager.onActivityResult(requestCode, resultCode, data); } } - Feed.java: - package com.example.user.app_ttcscn.Model; /** * Created by User on 10/15/2017 */ public class Feed { public String public String public String public String public String public String url ; title; link; author; description; image; public String getUrl() { return url; } public void setUrl(String url) { this.url = url; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public String getLink() { return link; } 35 public void setLink(String link) { this.link = link; } public String getAuthor() { return author; } public void setAuthor(String author) { this.author = author; } public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } public String getImage() { return image; } public void setImage(String image) { this.image = image; } public Feed(String url, String title, String link, String author, String description, String image) { this.url = url; this.title = title; this.link = link; this.author = author; this.description = description; this.image = image; } } - Item.java: - package com.example.user.app_ttcscn.Model; import java.util.List; /** * Created by User on 10/15/2017 */ public class Item { public String title; public String pubDate; public String link ; public String guid; public String author; public String thumbnail; public String description; public String content; public List enclosure; public List categories; public Item(String title, String pubDate, String link, String guid, String author, String thumbnail, String description, String content, List enclosure, List categories) { this.title = title; this.pubDate = pubDate; this.link = link; this.guid = guid; 36 this.author = author; this.thumbnail = thumbnail; this.description = description; this.content = content; this.enclosure = enclosure; this.categories = categories; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public String getPubDate() { return pubDate; } public String getLink() { return link; } public String getContent() { return content; } } - RSSObject.java: - package com.example.user.app_ttcscn.Model; import java.util.List; /** * Created by User on 10/15/2017 */ public class RootObject { public String status; public Feed feed; public List items; public RootObject(String status, Feed feed, List items) { this.status = status; this.feed = feed; this.items = items; } - } - HTTPDataHandler.java: - package com.example.user.app_ttcscn.Common; import import import import import import import java.io.BufferedInputStream; java.io.BufferedReader; java.io.InputStream; java.io.InputStreamReader; java.net.HttpURLConnection; java.net.MalformedURLException; java.net.URL; /** * Created by User on 10/15/2017 */ public class HTTPDataHandler { 37 static String stream= null; public HTTPDataHandler() {} public String GetHTTPData(String urlString) { try { URL url= new URL(urlString); HttpURLConnection connection= (HttpURLConnection)url.openConnection(); if (connection.getResponseCode()== HttpURLConnection.HTTP_OK) { InputStream inputStream= new BufferedInputStream(connection.getInputStream()); BufferedReader bufferedReader= new BufferedReader(new InputStreamReader(inputStream)); StringBuilder stringBuilder= new StringBuilder(); String line; while ((line=bufferedReader.readLine())!=null) { stringBuilder.append(line); stream=stringBuilder.toString(); connection.disconnect(); } } } catch (Exception e) { e.printStackTrace(); } return stream; } } - FeedAdapter: - package com.example.user.app_ttcscn.Adapter; import import import import import import import import import android.content.Context; android.content.Intent; android.net.Uri; android.support.v7.widget.RecyclerView; android.text.Html; android.view.LayoutInflater; android.view.View; android.view.ViewGroup; android.widget.TextView; import com.example.user.app_ttcscn.Interface.ItemClickListener; import com.example.user.app_ttcscn.Model.RootObject; import com.example.user.app_ttcscn.R; /** * Created by User on 10/15/2017 */ class FeedViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener { public TextView txtTitle, txtPubDate, txtContent, txtCaption; private ItemClickListener itemClickListener; public FeedViewHolder(View itemView) { super(itemView); 38 txtTitle= (TextView) itemView.findViewById(R.id.txtTitle); txtPubDate= (TextView) itemView.findViewById(R.id.txtPubDate); txtCaption= (TextView) itemView.findViewById(R.id.txtCaption); txtContent= (TextView) itemView.findViewById(R.id.txtContent); //set event itemView.setOnClickListener(this); itemView.setOnLongClickListener(this); } public void setItemClickListener(ItemClickListener itemClickListener) { this.itemClickListener = itemClickListener; } @Override public void onClick(View v) { itemClickListener.onClick(v, getAdapterPosition(), false); } @Override public boolean onLongClick(View v) { itemClickListener.onClick(v, getAdapterPosition(), true); return true; } } public class FeedAdapter extends RecyclerView.Adapter { private RootObject rootObject; private Context context; private LayoutInflater layoutInflater; public FeedAdapter(RootObject rootObject, Context context) { this.rootObject = rootObject; this.context = context; layoutInflater= LayoutInflater.from(context); } @Override public FeedViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { View itemView = layoutInflater.inflate(R.layout.row, parent, false); return new FeedViewHolder(itemView); } @Override public void onBindViewHolder(FeedViewHolder holder, int position) { holder.txtTitle.setText(rootObject.getItems().get(position).getTitle()); holder.txtPubDate.setText(rootObject.getItems().get(position).getPubDate()); holder.txtContent.setText(Html.fromHtml(rootObject.getItems().get(position).get Content())); holder.setItemClickListener(new ItemClickListener() { @Override public void onClick(View view, int position, boolean isLongClick) { if (!isLongClick) { Intent browserIntent= new Intent(Intent.ACTION_VIEW, Uri.parse(rootObject.getItems().get(position).getLink())); browserIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(browserIntent); } 39 } }); } @Override public int getItemCount() { return rootObject.items.size(); } } 40 ... xmlns :android= "http://schemas .android. com/apk/res /android" xmlns:app="http://schemas .android. com/apk/res-auto" xmlns:tools="http://schemas .android. com/tools" android: layout_width="match_parent" android: layout_height="match_parent"... encoding="utf-8"?>

Ngày đăng: 10/12/2017, 18:35

Mục lục

    Danh mục kí hiệu và viết tắt

    Danh mục hình vẽ

    1.1.2. Lịch sử phát triển:

    1.1.3. Các đặc điểm của Android:;

    1.1.5. Giao diện và các phiên bản Android

    1.2.1. Khái niệm chuẩn RSS:

    1.2.2. Cấu trúc các thẻ RSS:

    2.1. Khảo sát yêu cầu hệ thống:

    2.2. Phân tích yêu cầu:

    2.2.1. Sơ đồ nghiệp vụ:

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan