SplashActivity 类似微博 引导页

tcxingdechen 2015-09-17



SplashActivity 类似微博 引导页
 
 

 activity_splash.xml

<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"  
    android:background="#0f0">

  

</RelativeLayout>

 SplashActivity .java

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.Window;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.Animation.AnimationListener;

public class SplashActivity extends Activity {
	private boolean first;
	private View view;
	private Context context;
	private Animation animation;
	private static int TIME = 100;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		view = View.inflate(this, R.layout.activity_splash, null);
		setContentView(view);
		context = this;
	}

	@Override
	protected void onResume() {
		super.onResume();
		into();
	}

	private void into() {
		first = SharedPreferencesUtils.getFirstFlag(SplashActivity.this);
		animation = AnimationUtils.loadAnimation(context, R.anim.alpha);
		view.startAnimation(animation);
		animation.setAnimationListener(new AnimationListener() {

			@Override
			public void onAnimationEnd(Animation anim) {
				 new Handler().postDelayed( new Runnable() {

					@Override
					public void run() { 
						Intent intent = null;
                        if ( first || (Boolean)(SharedPreferencesUtils.getMessage(SplashActivity.this).get("checkLogin")) ) {
                        	intent = new Intent( SplashActivity.this,
                    				LoginActivity.class );    
                        }else{
                        	intent = new Intent( SplashActivity.this,
                    			MainActivity.class ); 
                        }
                        startActivity( intent );
                        overridePendingTransition( R.anim.in_from_right,
                                R.anim.out_to_left );
                        SplashActivity.this.finish();
					}
					 
				 }, TIME);
			}

			@Override
			public void onAnimationRepeat(Animation arg0) { 
			}

			@Override
			public void onAnimationStart(Animation arg0) { 
			}

		});
	}

	public void onPause() {
		super.onPause();
	}
}
import java.util.HashMap;
import java.util.Map;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

public class SharedPreferencesUtils {

	private static String APP_IS_FIRST_IN = "APP_IS_FIRST_IN";
	private static String USERINFO ="USERINFO";
	
	 
	//是否是第一次进入app 默认:是 
	public static boolean getFirstFlag(Context context){
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				APP_IS_FIRST_IN,Context.MODE_PRIVATE);
		return   sharedPreferences.getBoolean(APP_IS_FIRST_IN, true);
	} 
	
	//修改是否是第一次进入app 
	public static void changeFirstFlag(Context context ,boolean isFirstIn){
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				APP_IS_FIRST_IN, Context.MODE_PRIVATE ); 
        Editor editor = sharedPreferences.edit();
        editor.putBoolean( APP_IS_FIRST_IN, isFirstIn );
        editor.commit();
	}
	 
	
	// 保存用户登录信息
	public static void saveMessage(Context context,String userName, String password, Boolean checkLogin, Boolean remember) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				USERINFO,Context.MODE_PRIVATE);
		SharedPreferences.Editor editor = sharedPreferences.edit();
		editor.putString("userName", userName);
		editor.putString("password", password);
		editor.putBoolean("checkLogin", checkLogin);
		editor.putBoolean("remember", remember);
		editor.commit();
	}
	
	public static Map<String, Object> getMessage(Context context) {
		Map<String, Object> map = new HashMap<String, Object>();
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				USERINFO,Context.MODE_PRIVATE);
		String name = sharedPreferences.getString("userName", "");
		String pass = sharedPreferences.getString("password", "");
		Boolean checkLogin = sharedPreferences.getBoolean("checkLogin", false);
		Boolean remember = sharedPreferences.getBoolean("remember", true);
		map.put("name", name);
		map.put("pass", pass);
		map.put("checkLogin", checkLogin);
		map.put("remember", remember);
		return map;
	}
	
	
}

res/anim 创建三个动画效果

alpha.xml

<?xml version="1.0" encoding="UTF-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="2000"
    android:fromAlpha="0.3"
    android:toAlpha="1.0" />

  in_from_right.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
    <translate
        android:duration="500"
        android:fromXDelta="100%p"
        android:toXDelta="0%p" />
</set>

 out_to_left.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate
        android:duration="500"
        android:fromXDelta="0%p"
        android:toXDelta="-100%p" />
</set>

 AndroidManifest.xml

<application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:label="@string/app_name"
            android:screenOrientation="portrait"
            android:name="com.curiousby.activity.SplashActivity"  >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
</application>

捐助开发者

在兴趣的驱动下,写一个免费的东西,有欣喜,也还有汗水,希望你喜欢我的作品,同时也能支持一下。 当然,有钱捧个钱场(右上角的爱心标志,支持支付宝和PayPal捐助),没钱捧个人场,谢谢各位。


SplashActivity 类似微博 引导页SplashActivity 类似微博 引导页SplashActivity 类似微博 引导页
 
 
 谢谢您的赞助,我会做的更好!

相关推荐