如何写一个发微博的页面(包括插入图片,插入表情,插入话题,插入Location) (一)

先上效果图:

先看页面布局:

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

	<RelativeLayout
		android:layout_width="fill_parent"
		android:layout_height="0dp"
		android:layout_weight="1"
		android:background="#f4f4f4" >

		<LinearLayout
			android:id="@+id/btns_bottom"
			android:layout_width="fill_parent"
			android:layout_height="wrap_content"
			android:layout_alignParentBottom="true"
			android:orientation="horizontal">

			<LinearLayout <strong> //这5个是底部的按钮</strong>
				android:layout_width="fill_parent"
				android:layout_height="wrap_content"
				android:layout_weight="1">
				<ImageButton
					android:src="@drawable/btn_insert_save"
					android:layout_width="fill_parent"
					android:layout_height="wrap_content"
					android:layout_weight="1"
					android:background="@drawable/bg_btn"
					android:visibility="gone" />

				<ImageButton
					android:id="@+id/ib_insert_location"
					android:src="@drawable/btn_insert_location"
					android:layout_width="fill_parent"
					android:layout_height="wrap_content"
					android:layout_weight="1"
					android:background="@drawable/bg_btn"/>

				<ImageButton
					android:id="@+id/ib_insert_pic"
					android:src="@drawable/btn_insert_pic"
					android:layout_width="fill_parent"
					android:layout_height="wrap_content"
					android:layout_weight="1"
					android:background="@drawable/bg_btn"/>

				<ImageButton
					android:id="@+id/ib_insert_topic"
					android:src="@drawable/btn_insert_talk"
					android:layout_width="fill_parent"
					android:layout_height="wrap_content"
					android:layout_weight="1"
					android:background="@drawable/bg_btn"/>

				<ImageButton
					android:id="@+id/ib_insert_at"
					android:src="@drawable/btn_insert_at"
					android:layout_width="fill_parent"
					android:layout_height="wrap_content"
					android:layout_weight="1"
					android:background="@drawable/bg_btn"/>

				<ImageButton
					android:id="@+id/ib_face_keyboard"
					android:src="@drawable/btn_insert_face"
					android:layout_width="fill_parent"
					android:layout_height="wrap_content"
					android:layout_weight="1"
					android:background="@drawable/bg_btn"/>
			</LinearLayout>
		</LinearLayout>

		<RelativeLayout <strong> //这一个包括缩略图和location</strong>
			android:id="@+id/marks"
			android:layout_width="fill_parent"
			android:layout_height="50dp"
			android:padding="3dp"
			android:layout_above="@id/btns_bottom" >

			<ImageView
				android:id="@+id/iv_insertpic"
				android:scaleType="centerCrop"
				android:layout_width="50dp"
				android:layout_height="fill_parent"
				android:visibility="gone" />

			<ImageView
				android:id="@+id/iv_location"
				android:src="@drawable/icon_insertlocation"
				android:layout_width="wrap_content"
				android:layout_height="wrap_content"
				android:layout_centerVertical="true"
				android:layout_marginLeft="15dp"
				android:layout_toRightOf="@id/iv_insertpic"
				android:visibility="gone"/>

			<ProgressBar
				android:id="@+id/pg_loadlocation"
				style="@android:style/Widget.ProgressBar.Small.Inverse"
				android:layout_width="wrap_content"
				android:layout_height="wrap_content"
				android:layout_centerVertical="true"
				android:layout_marginLeft="15dp"
				android:layout_toRightOf="@id/iv_insertpic"
				android:visibility="gone" />

			<LinearLayout
				android:id="@+id/ll_text_limit_unit"
				android:layout_width="wrap_content"
				android:layout_height="wrap_content"
				android:layout_centerVertical="true"
				android:layout_alignParentRight="true"
				android:gravity="center"
				android:background="@drawable/bg_delwords"
				android:focusable="true"
				android:clickable="true" android:layout_alignParentBottom="false">

				<TextView
					android:id="@+id/tv_text_limit"
					android:layout_width="wrap_content"
					android:layout_height="wrap_content"
					android:text="140"
					android:layout_marginRight="5px"
					android:textColor="#333"/>

				<ImageView
					android:src="@drawable/icon_delwords"
					android:layout_width="wrap_content"
					android:layout_height="wrap_content" />

			</LinearLayout>

		</RelativeLayout>

		<EditText<strong> //这个是正文</strong>
			android:id="@+id/et_mblog"
			android:layout_width="fill_parent"
			android:layout_height="fill_parent"
			android:layout_above="@id/marks"
			android:background="@null"
			android:capitalize="sentences"
			android:imeOptions="actionDone"
			android:gravity="top|left"
			android:layout_margin="3px" />

	</RelativeLayout>
	<strong>//这个在最外层,整个界面的底部,是表情的界面,用gridview来实现</strong>
	<com.example.weibotest.view.EmotionView
		android:id="@+id/emotion_view"
		android:layout_width="fill_parent"
		android:layout_height="wrap_content"
		android:visibility="gone" />
</LinearLayout>

首先看从手机相册里load image:

private void startToMediaActivity() {
		startActivityForResult(new Intent(Intent.ACTION_PICK,
				android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI),
				WriteBlog.REQUEST_CODE_GALLERY);
	}

private void startToCameraActivity() {
		if (FileUtils.isSdCardAvailable()) {
			final Intent i = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
			final Uri picUri = Uri.fromFile(sdcardTempFile);
			i.putExtra(MediaStore.EXTRA_OUTPUT, picUri);
			startActivityForResult(i, WriteBlog.REQUEST_CODE_CAMERA);
		}
		else {
			Toast.makeText(this, R.string.pls_insert_sdcard, Toast.LENGTH_SHORT)
					.show();
		}
	}
	

一个Image的处理类:

	final class ImageLoadingHelper {

		private File picfile;
		private WriteBlog activity;
		private String defaultTempPath;
		private String defaultDraftPath;

		Bitmap createThumbnail() {
			Options thumbnailOpts = new BitmapFactory.Options();
			if (!hasBitmap()) { throw new IllegalStateException("There is no pic!"); }
			return BitmapFactory.decodeFile(getTempPath(),
					thumbnailOpts);
		}

		synchronized boolean hasBitmap() {
			String picfileName = picfile.getName();
			if(picfileName.matches(".avi")|| picfileName.matches(".rm")||picfileName.matches(".mp4")
					||picfileName.matches(".rmvb")||picfileName.matches(".wmv")||picfileName.matches(".flv"))
				{
				return false;
				}
			else{
				return FileUtils.doesExisted(picfile);
			}

		}

		synchronized void importBitmapFile(Uri uri) {
			if (uri.getScheme().equals("content")) {
				InputStream inputStream = null;
				try {
					inputStream = activity.getContentResolver()
							.openInputStream(uri);
				} catch (FileNotFoundException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				FileUtils.file_put_contents(inputStream,picfile);
			}
		}

		boolean doesDraftExist() {
			return FileUtils.doesExisted(defaultDraftPath);
		}

		String getTempPath() {
			return picfile == null ? "" : picfile.getAbsolutePath();
		}

		void loadDraft() {
			FileUtils.copy(defaultDraftPath, defaultTempPath);
			activity.displayInsertBitmap();

		}

		void saveDraft() {
			FileUtils.copy(defaultTempPath, defaultDraftPath);
		}

		ImageLoadingHelper(WriteBlog activity) {
			this.activity = activity;
			if (FileUtils.isSdCardAvailable()) {
				defaultTempPath = FileUtils.getSDPath() + "/temp/"
						+ System.currentTimeMillis() + ".jpg";
			}
			else {
				defaultTempPath = activity.getFilesDir().getAbsolutePath()
						+ "/pic/" + System.currentTimeMillis() + ".jpg";
			}
			defaultDraftPath = activity.getFilesDir().getAbsolutePath()
					+ "/draft/bitmap_temp.jpg";
			if (FileUtils.doesExisted(defaultTempPath)) {
				defaultTempPath.replace(".jpg", "(1).jpg");
			}
			picfile = new File(defaultTempPath);
		}

	}

选完图片我们会调用onactivityResult:

	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		if ((requestCode == WriteBlog.REQUEST_CODE_CAMERA)
				|| (WriteBlog.REQUEST_CODE_GALLERY == requestCode)) {
			if (resultCode != Activity.RESULT_OK) { return; }
			Uri uri = null;
			if ((requestCode == WriteBlog.REQUEST_CODE_CAMERA)
					&& FileUtils.doesExisted(sdcardTempFile)) {
				uri = Uri.fromFile(sdcardTempFile);
			}
			else if (WriteBlog.REQUEST_CODE_GALLERY == requestCode) {
				uri = data.getData();
			}

			if (uri != null) {
				displayImageUri(uri);
			}
		}
	}

	private void displayImageUri(Uri uri) {
		mImageLoadingHelper.importBitmapFile(uri);
		displayInsertBitmap();
	}

	void displayInsertBitmap() {
		insertPicView.setImageBitmap(mImageLoadingHelper
				.createThumbnail());
		insertPicView.setVisibility(View.VISIBLE);
	}

如何写一个发微博的页面(包括插入图片,插入表情,插入话题,插入Location) (一),布布扣,bubuko.com

时间: 2024-08-08 00:53:01

如何写一个发微博的页面(包括插入图片,插入表情,插入话题,插入Location) (一)的相关文章

【filter 页面重定向循环】写一个过滤器造成的页面重定向循环的问题

今天做一个过滤器,碰上页面重定向循环的情况: 浏览器的访问路径是:http://192.168.16.104:8080/biologyInfo/login/login/login/login/login/login/login/login/login/login/login/login/login/login/login/login/login/login/login/login/login/login/login1.htmls 过滤器的类如下: 1 package com.agen.util;

使用HTML写一个完整的注册页面

在上一篇博客中,我简单地写了怎样通过使用HTML写一个简单的跳转登录页面,but,TMD太丑了,于是突发奇想+天马行空不如写一个完整注册页面和流程,呵呵,不废话直接上代码. 首先是第一个页面testlogin,代码如下: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>登录</title>     <link href="tes

使用jeesite框架写一个树结构的列表页面(一般的数据表结构)

先上图,看一下需要完成的列表页的效果 以区域树结构列表为例子,大致就是要完成这个效果 1.做这个需求之前,我大致阅读了jeesite官方文档( https://jeesite.gitee.io/docs/)关于树表结构的文档(带有树表两个字的都看了看),查看了jeesite框架中自带的页面实例,又查看了项目中一些运用了树结构的页面以及后台代码. 按照文档走,我搞不出来这个东西...,为什么别的页面用得好好的呢???最后发现,我的数据表结构有点问题, jeesite的这个树结构如果要直接使用的话,

用HTML5写一个简单的HTML页面

HTML5的<!doctype>声明 在HTML 4.01中doctype这样写: <!DOCTYPE html PUBLIC "-//W3C/DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd"> 在HTML5中很简单: <!DOCTYPE html> HTML5的<meta>标签 <meta>标签在 HTML 4.01 中这样写: <m

php写一个简洁的登录页面

在学php中,刚刚看完实战演练就写了个登录页面 1.表单解析图 这是我们要写的 先用html写个表单先 <html> <head> <title>login</title> <style> #dog{ text-align:center; } </style> </head> <body> <div id="dog"> <form method="POST&quo

今天写一个关于浮动的页面,页面高度不能设置。用元素将他撑开。

HTML源码 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible&qu

用Python写一个最简单的网络爬虫

什么是网络爬虫?这是百度百科的解释: 网络爬虫(又被称为网页蜘蛛,网络机器人,在FOAF社区中间,更经常的称为网页追逐者),是一种按照一定的规则,自动的抓取万维网信息的程序或者脚本.另外一些不常使用的名字还有蚂蚁,自动索引,模拟程序或者蠕虫. 爬虫可以做什么?爬虫可以帮助我们在茫茫互联网中爬取我们需要的特定数据,这个特定数据可以是任何想获得的数据. 爬虫是一个让人热血的话题,因为当你在写爬虫的时候,你会感觉到自己是在做一件很NB的事,而每当写出一个爬虫,就会在此基础上不断尝试写出更NB的爬虫,有

采用jsp页面与java代码分离的方式写一个简单的二维表

前提:在我们做程序时追求的是高内聚,低耦合,但是如果我们把jsp页面的的代码和java的代码都放在了jsp的代码编写中,使java和jsp高耦合这样的话不仅使jsp代码页面显得很复杂,而且也特别让不利于以后的维护,所以我们有了一个不成文的规范就是分层架构,把javad代码与jsp的代码分离开来,使jsp代码页中更加干净整洁. 下面我将于用jsp和java代码分离的方法做出这样的一个二维表(做一个jsp页面动态显示信息表) 第一步:首先我们需要一个实体类用于存放一个人的一整条信息(根据表格信息有编

3.写一个hello world页面

经过1和2的学习,现在已经可以正常启动Django了,这一节说怎么写一个hello world页面,所有的环境基础就是1和2中搭建的 1.在app模块中添加页面 具体为 hello_django\hello\views.py 中添加如下代码: 2.在setting文件中加入对hello这个app的管理 具体为 hello_django\hello_django\settings.py 中修改如下代码: 3.在urls文件中加入对这个页面的映射关系 具体为 \hello_django\hello_