RyMiniFramework(3)-欢迎界面

我感觉, 预期的效果应该是在主Activity中调用一个类,传入splash图片和显示时间即可实现欢迎界面的功能。于是封装了一个RmfSplash类,实现了简单的功能。


1、layout/rmf_ly_splash.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/rmf_id_splash_img"
       android:layout_width="fill_parent"          
       android:layout_height="fill_parent"  
       android:scaleType="center" />

</LinearLayout>


 

2、cn.rydiy.rmf.common.RmfSplash.java

package cn.rydiy.rmf.common;

import android.app.Activity;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;

/**
 * Splash Display Class. It will display splash with full screen and then quit full screen.
 * @author Rydiy
 * @version 1.0.0
 * @Date 2012-07-29
 */
public class RmfSplash {
	private Activity 	 mAct;		//MainActivity
	private int		 mTime;		//delay time
	private Handler   	 mHandler;	//message handler
	private int		 mLayoutMain;	//R.layout.main
	private int		 mLayoutSplash; //R.layout.rmf_ly_splash
	private int		 mIdImgView;	//R.id.rmf_id_splash_img
	
	/**
	 * Constructor
	 * @param mainActivity : your object's main activity's instance
	 * @param resrc : a Resources instance for your application's package
	 */
	public RmfSplash(Activity mainActivity, Resources resrc) {
		this.mAct = mainActivity;
		
		//get resources
		String packageName = mAct.getPackageName();	
		//get R.layout.main
		mLayoutMain = resrc.getIdentifier("main", "layout", packageName);
		//get R.layout.rmf_ly_splash
		mLayoutSplash = resrc.getIdentifier("rmf_ly_splash", "layout", packageName);
		//get R.id.rmf_id_splash_img
		mIdImgView = resrc.getIdentifier("rmf_id_splash_img", "id", packageName);
		
		//create Handler
		mHandler = new Handler() {
			@Override
			public void handleMessage(Message msg) {
				if(msg.arg1 == 1) {
					//quit full screen
			        	final WindowManager.LayoutParams attrs = mAct.getWindow().getAttributes();
			       		attrs.flags &= (~WindowManager.LayoutParams.FLAG_FULLSCREEN);
			        	mAct.getWindow().setAttributes(attrs);
			        	mAct.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);							//set main layout
					mAct.setContentView(mLayoutMain);
				}
			}
		};		
	}

	
	/**
	 * Show splash
	 * @param id  : The resource id of the image data
	 * @param time : Delay time (ms)
	 */
	public void show(int id, int time) {
		Log.d("RMF", "RmfSplash show()");
		mTime = time;
		
		//no title
		mAct.requestWindowFeature(Window.FEATURE_NO_TITLE);
		//full screen
		mAct.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
				WindowManager.LayoutParams.FLAG_FULLSCREEN);		
		//set splash layout
		mAct.setContentView(mLayoutSplash);
		
		//load bitmap
        	Bitmap bmp = BitmapFactory.decodeResource(mAct.getResources(), id);
		ImageView img = (ImageView)mAct.findViewById(mIdImgView);
		img.setImageBitmap(bmp);
		
		//delay time
		new Thread() {
			public void run() {
				Message msg = Message.obtain(mHandler);
				msg.arg1 = 1;
				mHandler.sendMessageDelayed(msg, mTime);
			};
		}.start();
	}
}


 

3、使用

        RmfSplash rSplash = new RmfSplash(this, getResources());
        rSplash.show(R.drawable.rmf_img_splash, 3000);   
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值