CSDN简单安卓client实现

一直是在电脑上面看CSDN的博客、资讯,今天做了个小软件在手机上面查看资讯和博客。

直接上代码:

一、首先是欢迎界面 --  LoadingActivity.java

package com.example.webviewtest;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.Window;

public class LoadingActivity extends Activity{

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.loading);

		new Handler().postDelayed(new Runnable() {
			@Override
			public void run() {

				Intent mainIntent = new Intent(LoadingActivity.this,
						ShowActivity.class);

				startActivity(mainIntent);
				finish();
			}
		}, 2000);
	}

}

其布局文件非常easy--loading.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:src="@drawable/splash" />

</LinearLayout>

二、主页面--ShowActivity.java

package com.example.webviewtest;

import java.util.Timer;
import java.util.TimerTask;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.Window;
import android.webkit.WebSettings.RenderPriority;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Toast;

public class ShowActivity extends Activity {

	private WebView webView;
	private static Boolean isExit = false;
	Timer tExit = new Timer();// 计时器
	TimerTask task;

	@SuppressLint("SetJavaScriptEnabled")
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.activity_main);

		webView = (WebView) findViewById(R.id.web_view);

		webView.getSettings().setBuiltInZoomControls(true);
		webView.getSettings().setJavaScriptEnabled(true);
		webView.getSettings().setRenderPriority(RenderPriority.HIGH);
		// webView.getSettings().setBlockNetworkImage(true);

		webView.setWebViewClient(new WebViewClient() {
			@Override
			public boolean shouldOverrideUrlLoading(WebView view, String url) {
				// 依据传入的參数再去载入新的网页
				view.loadUrl(url);
				// 表示当前WebView能够处理打开新网页的请求,不用借助系统浏览器
				return true;
			}

			@Override
			public void onReceivedError(WebView view, int errorCode,
					String description, String failingUrl) {
				super.onReceivedError(view, errorCode, description, failingUrl);

				Toast.makeText(ShowActivity.this, "呃!载入失败,或许断网了。或者不能訪问!",
						Toast.LENGTH_LONG).show();
			}
		});

		webView.loadUrl("http://www.csdn.net/");
	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_BACK && webView.canGoBack()) {
			webView.goBack();// 返回前一个页面
			return true;
		}
		return super.onKeyDown(keyCode, event);
	}

	@Override
	public void onBackPressed() {
		if (isExit == false) {
			isExit = true;
			Toast.makeText(this, "再按一次返回键回到桌面", Toast.LENGTH_SHORT).show();
			task = new TimerTask() {
				@Override
				public void run() {
					isExit = false;
				}
			};
			tExit.schedule(task, 2000);
		} else {
			finish();
			System.exit(0);
		}
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// TODO Auto-generated method stub

		super.onCreateOptionsMenu(menu);
		// 加入四个菜单项

		menu.add(Menu.NONE, Menu.FIRST + 1, 1, "帮助").setIcon(
				R.drawable.menu_help);

		menu.add(Menu.NONE, Menu.FIRST + 2, 2, "退出").setIcon(
				R.drawable.menu_quit);

		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// TODO Auto-generated method stub
		switch (item.getItemId()) {

		case Menu.FIRST + 1:
			Intent intent = new Intent(ShowActivity.this, HelpActivity.class);
			startActivity(intent);
			return true;

		case Menu.FIRST + 2:
			new AlertDialog.Builder(this)
					.setTitle("退出")
					.setMessage("你确定要退出CSDN吗?")
					.setIcon(android.R.drawable.ic_dialog_info)
					.setPositiveButton(R.string.ok,
							new DialogInterface.OnClickListener() {
								public void onClick(DialogInterface dialog,
										int whichButton) {
									finish();// 退出程序
								}
							}).setNegativeButton(R.string.cancel, null).show();
			return true;
		}
		return false;
	}

}

布局文件--activity_main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <WebView
        android:id="@+id/web_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</LinearLayout>

三、帮助页面--HelpActivity.java

package com.example.webviewtest;

import android.app.Activity;
import android.os.Bundle;
import android.view.Window;

public class HelpActivity extends Activity{

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.help);
	}

}

布局文件--help.xml

<?xml version="1.0" encoding="utf-8"?

>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:stretchColumns="0,1,2" >

    <TableRow>

        <TextView
            android:layout_width="100dp"
            android:layout_height="match_parent"
            android:layout_marginRight="10dp"
            android:text="第一步:"
            android:textSize="23sp" />

        <TextView
            android:layout_width="100dp"
            android:layout_height="match_parent"
            android:layout_marginRight="5dp"
            android:layout_marginLeft="5dp"
            android:text="第二步:"
            android:textSize="23sp" />

        <TextView
            android:layout_width="100dp"
            android:layout_height="match_parent"
            android:layout_marginRight="10dp"
            android:text="第三步:"
            android:textSize="23sp" />
    </TableRow>

    <TableRow
        android:layout_marginTop="20dp">

       <TextView
            android:layout_width="100dp"
            android:layout_height="match_parent"
            android:layout_marginRight="10dp"
            android:text="右上角图标"
            android:textSize="15sp" />

        <TextView
            android:layout_width="100dp"
            android:layout_height="match_parent"
            android:layout_marginRight="5dp"
            android:layout_marginLeft="5dp"
            android:text="点击博客"
            android:textSize="15sp" />

        <TextView
            android:layout_width="100dp"
            android:layout_height="match_parent"
            android:layout_marginRight="10dp"
            android:text="点击登录"
            android:textSize="15sp" />
    </TableRow>

    <TableRow>

        <ImageView
            android:layout_width="100dp"
            android:layout_height="match_parent"
            android:layout_marginRight="10dp"
            android:src="@drawable/first" />

        <ImageView
            android:layout_width="100dp"
            android:layout_height="match_parent"
            android:layout_marginLeft="5dp"
            android:layout_marginRight="5dp"
            android:src="@drawable/second" />

        <ImageView
            android:layout_width="100dp"
            android:layout_height="match_parent"
            android:layout_marginLeft="10dp"
            android:src="@drawable/third" />
    </TableRow>

</TableLayout>

四、最后别忘了在AndroidManifest.xml文件里加入訪问网络的权限

 <uses-permission android:name="android.permission.INTERNET" />

五、Apk下载地址:http://download.csdn.net/detail/xdwyyan/8121301

时间: 2024-07-31 14:15:59

CSDN简单安卓client实现的相关文章

CSDN简单安卓客户端开发

一直是在电脑上面看CSDN的博客.资讯,今天做了个小软件在手机上面查看资讯和博客. 直接上代码: 一.首先是欢迎界面 --  LoadingActivity.java package com.example.webviewtest; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.os.Handler; import android.view.

Oschina 安卓client源代码学习之中的一个

今天主要研究一下两个功能 (1)双击返回键退出程序 (2)接近完美地退出程序 (1) 在非常多应用程序里都有一个功能,就是点击返回键,之后提示你再点击返回键就退出程序. 之前一直非常好奇这是怎么实现的,今天正好把开源中国安卓client源代码扒下来了,所以就在这里研究一下这个非常easy的功能. public class DoubleClickExitHelper { private final Activity mActivity; private boolean isOnKeyBacking

仿知乎安卓client滑动删除撤销ListView

标签(空格分隔): Android 新版的知乎安卓client有一个有趣的功能,就是在一个item里.向右滑动时整个item会越来越透明,滑动到一半时,整个item就不见了.放开手指就是删除.删除后还能够撤销,第一次看见这个功能觉得非常有意思,用了几天业余时间,我仿造里一个.效果例如以下: 那以下就来想想看怎么实现的,大概能够先分解为三部分: 手指滑动删除item 删除item后的撤销功能 滑动时的效果处理 提醒一下假设你对scroller不熟悉.能够先看一下scroller实现原理 先来看最基

Android应用开发-小巫CSDN博客client之嵌入有米广告

Android应用开发-小巫CSDN博客client之嵌入有米广告 上一篇博客给大家介绍怎样集成友盟社会化组件,本篇继续带来干货,教大家怎样嵌入广告到应用中去.小巫自称专业对接30年,熟悉各大渠道SDK的接入和使用,除非渠道提供的SDK非常坑,不然仅仅须要不到半个小时的时间就能够把SDK接入到应用其中.关于广告,是开发人员比較关注的话题,为什么要嵌入广告呢,自然是为了为自己的辛苦劳作得到些许额外的收益,由于在国内除非做IOS付费软件,不然在Android平台下做收费软件是非常难获得收益的,用户仅

《Python Network Programming Cookbook》读书笔记1---套接字, IPv4, 简单的Client/Server程序

这一部分主要介绍python中socket模块的相关内容,socket即套接字. socket是使用TCP/IP协议的应用程序通常采用的应用编程接口,它位于运输层和应用层之间,起源于UNIX,由于遵从UNIX“一切皆文件的”思想故socket可看作一种特殊的文件,对其的操作基本可以视为读写I/O.打开.关闭.关于套接字的基本概念@吴秦的Linux Socket编程(不限Linux)写的很详细,大家可以参考. 在下面列出的各个部分中我将先贴出代码,然后对其进行解释. 通过python3获得本机名和

闰年测试非法输入的处理 简单安卓app 20150406

在软件测试的课上,老师介绍了闰年测试.闰年测试旨在检测某一年份是否为闰年,计算方式为四年一闰,百年不闰,四百年再闰.使用安卓实现这个小程序. 界面代码如下: 1 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 2 xmlns:tools="http://schemas.android.com/tools" 3 android:layout_width=&quo

简单的Client / Server 使用 linux 伯克利 socket实现 编辑

server /* *run command: * g++ server.cpp -o server && ./server */ #ifndef SERVER #define SERVER #include<arpa/inet.h> #include<assert.h> #include<stdio.h> #include<stdlib.h> #include<pthread.h> #include<errno.h>

Android应用开发-小巫CSDN博客client之获取评论列表

Android应用开发-小巫CSDN博客客户端之获取评论列表 上一篇博客介绍了博文具体内容的业务逻辑实现,本篇博客介绍小巫CSDN博客客户端的最后一项功能.获取评论列表,这个功能的实现跟前面获取文章列表和文章具体的内容不一样,CSDN博客获取评论是通过js来请求server载入评论列表的,返回数据为json数据.我们这里要做的事情就是找到这种一个js文件,再找到请求url的拼接字符串.然后依据我们的需求,请求文章的评论列表获取到当前文章的评论json数据,然后进行解析工作.最后展示到我们的界面其

android源码大放送(实战开发必备),免费安卓demo源码,例子大全文件详细列表

免费安卓demo源码,例子大全文件详细列表 本列表源码永久免费下载地址:http://www.jiandaima.com/blog/android-demo 卷 yunpan 的文件夹 PATH 列表 卷序列号为 0000-73EC E:. │ jiandaima.com文件列表生成.bat │ 例子大全说明.txt │ 本例子永久更新地址~.url │ 目录列表2016.03.10更新.txt │ ├─前台界面 │ ├─3D标签云卡片热门 │ │ Android TagCloudView云标签