码迷,mamicode.com
首页 > 其他好文 > 详细

欢迎页,引导页和主页

时间:2016-01-15 17:46:54      阅读:325      评论:0      收藏:0      [点我收藏+]

标签:android   activity   欢迎页   public   引导页   

配置

<application
        android:name="com.shipping.application.ShippingApplication"
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/NormalTheme" >
        <activity
            android:name="com.shipping.activity.WelcomeActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

        <!-- GuideActivity -->
        <activity
            android:name="com.shipping.guide.GuideActivity"
            android:configChanges="keyboardHidden|orientation"
            android:screenOrientation="portrait" >
        </activity>

        <!-- GuideViewPagerActivity -->
        <activity
            android:name="com.shipping.guide.GuideViewPagerActivity"
            android:configChanges="keyboardHidden|orientation"
            android:screenOrientation="portrait" >
        </activity>

        <!-- MainActivity -->
        <activity
            android:name="com.shipping.activity.MainActivity"
            android:configChanges="keyboardHidden|orientation"
            android:screenOrientation="portrait" >
        </activity>
        </application>

欢迎页代码

package com.shipping.activity;

import cn.jpush.android.api.JPushInterface;

import com.shipping.R;
import com.shipping.app.App;
import com.shipping.guide.GuideActivity;
import com.shippingframework.activity.BaseActivity;
import com.shippingframework.services.TokenService;
import com.shippingframework.services.UserService;
import com.shippingframework.sharedpreferences.AppSharedPreferences;

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



public class WelcomeActivity extends ShipBaseActivity{

	private AppSharedPreferences appSP;
	 
	// 延迟1秒
	private static final long SPLASH_DELAY_MILLIS = 1000*2;
	
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		instance=this;
		
		setContentView(R.layout.activity_welcome);
		
		
		new App(instance);
		appSP=new AppSharedPreferences(instance,AppSharedPreferences.APP_SHAREPRE_FILE);
		
	
		ApplicationInit();
		
		// 使用Handler的postDelayed方法,3秒后执行跳转到MainActivity
		new Handler().postDelayed(new Runnable() {
			public void run() {
				goHome();
			}
		}, SPLASH_DELAY_MILLIS);
		  
	}

	private void ApplicationInit(){
		
		//获取token
		TokenService tokenService=new  TokenService(instance);
		tokenService.GetAccessToken();
		
		//系统自动登录
		UserService userService=new UserService(instance);
		userService.AutoLogin();
	}
	
	
	
	private void goHome() {
		
		if (appSP.getAppIsFirstRun()) {
			appSP.setAppIsFirstRun(false);
			Intent intent = new Intent(WelcomeActivity.this,GuideActivity.class);
			WelcomeActivity.this.startActivity(intent);
			WelcomeActivity.this.finish();
		} else {
			Intent intent = new Intent(WelcomeActivity.this, MainActivity.class);
			WelcomeActivity.this.startActivity(intent);
			WelcomeActivity.this.finish();
		}
			
	}
	
	
	@Override
	protected void onResume() {
	super.onResume();
		JPushInterface.onResume(this);
	}

	@Override
	protected void onPause() {
	super.onPause();
		JPushInterface.onPause(this);
	}
	
	
}
activity_welcome.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" >
 
    <ImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/welcome"
        android:scaleType="fitCenter" />
 
</RelativeLayout>

引导页代码

package com.shipping.guide;


import com.shipping.R;

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



public class GuideActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		
		
		setContentView(R.layout.activity_guide);
		new Handler().postDelayed(new Runnable() {
			@Override
			public void run() {
				Intent intent = new Intent(GuideActivity.this,
						GuideViewPagerActivity.class);
				startActivity(intent);
				GuideActivity.this.finish();
			}
		}, 1000);
		
		
	}
       
	
}

activity_guide.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" >
    

</LinearLayout>
package com.shipping.guide;


import java.util.ArrayList;

import com.shipping.R;
import com.shipping.activity.MainActivity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Parcelable;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.view.LayoutInflater;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.TranslateAnimation;
import android.widget.ImageView;


public class GuideViewPagerActivity extends Activity {
	/** Called when the activity is first created. */
	private ViewPager mViewPager;
	// private PagerTitleStrip mPagerTitleStrip;
	private ImageView mPageImg;// 动画图片
	private int currIndex = 0;
	private ImageView mPage0;
	private ImageView mPage1;
	private ImageView mPage2;
	//private ImageView mPage3;

	// private ImageView mPage4;
	// private ImageView mPage5;
	// private ImageView mPage6;
	// private ImageView mPage7;
	// private ImageView mPage8;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_guide_viewpager);
		mViewPager = (ViewPager) findViewById(R.id.guide_viewpager);
		mViewPager.setOnPageChangeListener(new MyOnPageChangeListener());
		// mPagerTitleStrip = (PagerTitleStrip)findViewById(R.id.pagertitle);

		mPageImg = (ImageView) findViewById(R.id.guide_page_now);

		mPage0 = (ImageView) findViewById(R.id.page0);
		mPage1 = (ImageView) findViewById(R.id.page1);
		mPage2 = (ImageView) findViewById(R.id.page2);
		//mPage3 = (ImageView) findViewById(R.id.page3);
		// mPage4 = (ImageView)findViewById(R.id.page4);
		// mPage5 = (ImageView)findViewById(R.id.page5);
		// mPage6 = (ImageView)findViewById(R.id.page6);
		// mPage7 = (ImageView)findViewById(R.id.page7);
		// mPage8 = (ImageView)findViewById(R.id.page8);

		// 将要分页显示的View装入数组中
		LayoutInflater mLi = LayoutInflater.from(this);
		View view1 = mLi.inflate(R.layout.activity_guide_viewpager_1, null);
		View view2 = mLi.inflate(R.layout.activity_guide_viewpager_2, null);
		View view3 = mLi.inflate(R.layout.activity_guide_viewpager_3, null);
		//View view4 = mLi.inflate(R.layout.activity_app_start_viewpager_end,null);
		// View view5 = mLi.inflate(R.layout.activity_app_start_viewpager_1,
		// null);
		// View view6 = mLi.inflate(R.layout.activity_app_start_viewpager_1,
		// null);
		// View view7 = mLi.inflate(R.layout.activity_app_start_viewpager_1,
		// null);
		// View view8 = mLi.inflate(R.layout.activity_app_start_viewpager_1,
		// null);
		// View view9 = mLi.inflate(R.layout.activity_app_start_viewpager_1,
		// null);

		// 每个页面的view数据
		final ArrayList<View> views = new ArrayList<View>();
		views.add(view1);
		views.add(view2);
		views.add(view3);
		//views.add(view4);
		// views.add(view5);
		// views.add(view6);
		// views.add(view7);
		// views.add(view8);
		// views.add(view9);

		final ArrayList<String> titles = new ArrayList<String>();
		titles.add("①");
		titles.add("②");
		titles.add("③");
		//titles.add("④");
		// titles.add("⑤");
		// titles.add("⑥");
		// titles.add("⑦");
		// titles.add("⑧");
		// titles.add(" ");

		// 填充ViewPager的数据适配器
		PagerAdapter mPagerAdapter = new PagerAdapter() {

			@Override
			public boolean isViewFromObject(View arg0, Object arg1) {
				return arg0 == arg1;
			}

			@Override
			public int getCount() {
				return views.size();
			}

			@Override
			public void destroyItem(View container, int position, Object object) {
				((ViewPager) container).removeView(views.get(position));
			}

			@Override
			public CharSequence getPageTitle(int position) {
				return titles.get(position);
			}

			@Override
			public Object instantiateItem(View container, int position) {
				((ViewPager) container).addView(views.get(position));
				return views.get(position);
			}

			@Override
			public void finishUpdate(View arg0) {
				// TODO Auto-generated method stub

			}

			@Override
			public void restoreState(Parcelable arg0, ClassLoader arg1) {
				// TODO Auto-generated method stub

			}

			@Override
			public Parcelable saveState() {
				// TODO Auto-generated method stub
				return null;
			}

			@Override
			public void startUpdate(View arg0) {
				// TODO Auto-generated method stub

			}
		};

		mViewPager.setAdapter(mPagerAdapter);
	}

	public class MyOnPageChangeListener implements OnPageChangeListener {

		// int one = offset * 2 + bmpW;// 页卡1 -> 页卡2 偏移量
		// int two = one * 2;// 页卡1 -> 页卡3 偏移量
		// int move = 20;

		@Override
		public void onPageSelected(int arg0) {
			Animation animation = null;
			switch (arg0) {
			case 0:
				mPage0.setImageDrawable(getResources().getDrawable(
						R.drawable.guide_viewpager_now));
				mPage1.setImageDrawable(getResources().getDrawable(
						R.drawable.guide_viewpager_index));
				if (currIndex == arg0 + 1) {
					animation = new TranslateAnimation(20 * (arg0 + 1),
							20 * arg0, 0, 0);
				} /*
				 * else if (currIndex == 2) { animation = new
				 * TranslateAnimation(20*2, 0, 0, 0); }
				 */
				break;
			case 1:
				mPage1.setImageDrawable(getResources().getDrawable(
						R.drawable.guide_viewpager_now));
				mPage0.setImageDrawable(getResources().getDrawable(
						R.drawable.guide_viewpager_index));
				mPage2.setImageDrawable(getResources().getDrawable(
						R.drawable.guide_viewpager_index));
				if (currIndex == arg0 - 1) {
					animation = new TranslateAnimation(20 * (arg0 - 1),
							20 * arg0, 0, 0);

				} else if (currIndex == arg0 + 1) {
					animation = new TranslateAnimation(20 * (arg0 + 1),
							20 * arg0, 0, 0);
				}
				break;
			case 2:
				mPage2.setImageDrawable(getResources().getDrawable(
						R.drawable.guide_viewpager_now));
				mPage1.setImageDrawable(getResources().getDrawable(
						R.drawable.guide_viewpager_index));
				/*
				mPage3.setImageDrawable(getResources().getDrawable(
						R.drawable.app_start_page_index));
						*/
				if (currIndex == arg0 - 1) {
					animation = new TranslateAnimation(20 * (arg0 - 1),
							20 * arg0, 0, 0);
				} else if (currIndex == arg0 + 1) {
					animation = new TranslateAnimation(20 * (arg0 + 1),
							20 * arg0, 0, 0);
				}
				break;
				/*
			case 3:
				mPage3.setImageDrawable(getResources().getDrawable(
						R.drawable.app_start_page_now));
				// mPage4.setImageDrawable(getResources().getDrawable(R.drawable.app_start_page_index));
				mPage2.setImageDrawable(getResources().getDrawable(
						R.drawable.app_start_page_index));
				if (currIndex == arg0 - 1) {
					animation = new TranslateAnimation(20 * (arg0 - 1),
							20 * arg0, 0, 0);

				} else if (currIndex == arg0 + 1) {
					animation = new TranslateAnimation(20 * (arg0 + 1),
							20 * arg0, 0, 0);
				}
				break;
			case 4:
				// mPage4.setImageDrawable(getResources().getDrawable(R.drawable.app_start_page_now));
				mPage3.setImageDrawable(getResources().getDrawable(
						R.drawable.app_start_page_index));
				// mPage5.setImageDrawable(getResources().getDrawable(R.drawable.app_start_page_index));
				if (currIndex == arg0 - 1) {
					animation = new TranslateAnimation(20 * (arg0 - 1),
							20 * arg0, 0, 0);
				} else if (currIndex == arg0 + 1) {
					animation = new TranslateAnimation(20 * (arg0 + 1),
							20 * arg0, 0, 0);
				}
				break;
			case 5:
				// mPage5.setImageDrawable(getResources().getDrawable(R.drawable.app_start_page_now));
				// mPage4.setImageDrawable(getResources().getDrawable(R.drawable.app_start_page_index));
				// mPage6.setImageDrawable(getResources().getDrawable(R.drawable.app_start_page_index));
				if (currIndex == arg0 - 1) {
					animation = new TranslateAnimation(20 * (arg0 - 1),
							20 * arg0, 0, 0);
				} else if (currIndex == arg0 + 1) {
					animation = new TranslateAnimation(20 * (arg0 + 1),
							20 * arg0, 0, 0);
				}
				break;
			case 6:
				// mPage6.setImageDrawable(getResources().getDrawable(R.drawable.app_start_page_now));
				// mPage5.setImageDrawable(getResources().getDrawable(R.drawable.app_start_page_index));
				// mPage7.setImageDrawable(getResources().getDrawable(R.drawable.app_start_page_index));
				if (currIndex == arg0 - 1) {
					animation = new TranslateAnimation(20 * (arg0 - 1),
							20 * arg0, 0, 0);
				} else if (currIndex == arg0 + 1) {
					animation = new TranslateAnimation(20 * (arg0 + 1),
							20 * arg0, 0, 0);
				}
				break;
			case 7:
				// mPage7.setImageDrawable(getResources().getDrawable(R.drawable.app_start_page_now));
				// mPage8.setImageDrawable(getResources().getDrawable(R.drawable.app_start_page_index));
				// mPage6.setImageDrawable(getResources().getDrawable(R.drawable.app_start_page_index));
				if (currIndex == arg0 - 1) {
					animation = new TranslateAnimation(20 * (arg0 - 1),
							20 * arg0, 0, 0);
				} else if (currIndex == arg0 + 1) {
					animation = new TranslateAnimation(20 * (arg0 + 1),
							20 * arg0, 0, 0);
				}
				break;*/
			case 8:
				// mPage8.setImageDrawable(getResources().getDrawable(R.drawable.app_start_page_now));
				// mPage7.setImageDrawable(getResources().getDrawable(R.drawable.app_start_page_index));
				if (currIndex == arg0 - 1) {
					animation = new TranslateAnimation(20 * (arg0 - 1),
							20 * arg0, 0, 0);
				} /*
				 * else if (currIndex == arg0+1) { animation = new
				 * TranslateAnimation(20*(arg0+1), 20*arg0, 0, 0); }
				 */
				break;
			}
			currIndex = arg0;
			animation.setFillAfter(true);// True:图片停在动画结束位置
			animation.setDuration(300);
			// mPageImg.startAnimation(animation);
		}

		@Override
		public void onPageScrolled(int arg0, float arg1, int arg2) {
		}

		@Override
		public void onPageScrollStateChanged(int arg0) {
		}
	}

	public void startbutton(View v) {
		// 获取启动意图
		Intent _intent = getIntent();
		if (_intent != null) {
			boolean isStartClose = _intent.getBooleanExtra("isStartClose",false);
			if (isStartClose) {
				this.finish();
			} else {
				Intent intent = new Intent(GuideViewPagerActivity.this,MainActivity.class);
				startActivity(intent);
				this.finish();
			}
		}else{
			Intent intent = new Intent();
			intent.setClass(GuideViewPagerActivity.this,MainActivity.class);
			startActivity(intent);
			this.finish();
		}

	}
}

activity_guide_viewpager.xml

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

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >  

 

    <android.support.v4.view.ViewPager
        android:id="@+id/guide_viewpager"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center" > 
        
        
        <android.support.v4.view.PagerTitleStrip
            android:id="@+id/guide_pagertitle"
            android:layout_width="wrap_content"
            android:layout_height="0dp"
            android:layout_gravity="bottom"
            android:background="#0000"
            android:textColor="#ffff" />
    </android.support.v4.view.ViewPager>  
    
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal"
        android:gravity="center_horizontal" >       
        
        <ImageView
            android:id="@+id/page0"
        	android:layout_width="wrap_content"
        	android:layout_height="wrap_content"
        	android:layout_gravity="bottom"
        	android:layout_marginBottom="30dp"        	
        	
        	android:scaleType="matrix"
        	android:src="@drawable/guide_viewpager_now" />
        <ImageView
            android:id="@+id/page1"
        	android:layout_width="wrap_content"
        	android:layout_height="wrap_content"
        	android:layout_gravity="bottom"
        	android:layout_marginBottom="30dp"        	
        	android:layout_marginLeft="10dp"
        	android:scaleType="matrix"
        	android:src="@drawable/guide_viewpager_index" />
        <ImageView
            android:id="@+id/page2"
        	android:layout_width="wrap_content"
        	android:layout_height="wrap_content"
        	android:layout_gravity="bottom"
        	android:layout_marginBottom="30dp"        	
        	android:layout_marginLeft="10dp"
        	android:scaleType="matrix"
        	android:src="@drawable/guide_viewpager_index" />
        <ImageView
            android:id="@+id/page3"
        	android:layout_width="wrap_content"
        	android:layout_height="wrap_content"
        	android:layout_gravity="bottom"
        	android:layout_marginBottom="30dp"        	
        	android:layout_marginLeft="10dp"
        	android:scaleType="matrix"
        	android:src="@drawable/guide_viewpager_index"
        	android:visibility="gone"
        	 />
               
    </LinearLayout>
    
    <LinearLayout                                  
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal" >     
        

        <ImageView
        	android:id="@+id/guide_page_now"
        	android:layout_width="wrap_content"
        	android:layout_height="wrap_content"
        	android:layout_gravity="bottom"
        	android:layout_marginBottom="30dp"        	
        	android:layout_marginLeft="20dp"
        	android:scaleType="matrix"
        	 />
    </LinearLayout>
	
    
        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:orientation="vertical" >
        
            <Button
              android:layout_width="wrap_content"
              android:layout_height="32dp"
              android:layout_marginTop="8dp"
              android:layout_marginLeft="8dp"
              android:text="开始体验》"
              android:textSize="10sp"
              android:textColor="#fff"
                  android:visibility="gone"     
              android:background="@color/transparent"   
			  android:onClick="startbutton"/>
        </LinearLayout>
        
    
</FrameLayout>

<!--    <android.support.v4.view.PagerTitleStrip   -->
<!--            android:id="@+id/pagertitle"      -->
<!--            android:layout_width="wrap_content"  -->
<!--            android:layout_height="wrap_content"  -->
<!--            android:layout_gravity="bottom" />  -->

<!--    </android.support.v4.view.ViewPager>  -->

主页代码

package com.shipping.activity;

import java.util.Set;

import android.app.ActivityGroup;
import android.app.LocalActivityManager;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.view.Window;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import cn.jpush.android.api.JPushInterface;
import cn.jpush.android.api.TagAliasCallback;

import com.shipping.R;
import com.shipping.activity.chat.ChatActivity;
import com.shipping.activity.chat.ChattingActivity;
import com.shipping.activity.ship.MyInquiryPalletDlActivity;
import com.shipping.activity.ship.MyInquiryPalletHzActivity;
import com.shipping.activity.ship.PalletActivity;
import com.shipping.activity.ship.ShipScheduleActivity;
import com.shipping.activity.u.InquiryShipActivity;
import com.shipping.activity.u.uCenterActivity;
import com.shipping.app.App;
import com.shippingframework.sharedpreferences.AppSharedPreferences;
import com.shippingframework.utils.L;
import com.shippingframework.utils.T;

public class MainActivity extends ActivityGroup {

	// main activity
	public static MainActivity instance;

	// LinearLayout
	private LinearLayout mainContainer = null;

	private Intent mainIntent = null;
	private LocalActivityManager localActivityManager = null;
	private TextView appTitle = null;

	// bottom menu layout
	private ImageView btn_boot_pallet_ImageView = null;
	private ImageView btn_boot_shipschedule_ImageView = null;
	private ImageView btn_boot_chat_ImageView = null;
	private ImageView btn_boot_personal_ImageView = null;

	/**
	 * 用户级别的配置文件
	 * */
	private AppSharedPreferences userSP;

	private boolean isSign = false;

	// long
	private long exitTime = 0;

	private int GOTO_LOGIN = 101;

	private String TAG = "";

	private static final int MSG_SET_ALIAS = 1001;
	private static final int MSG_SET_TAGS = 1002;
	
	
	private static final int GOTO_LOGIN_ACTIVITY=20;

	private int UserIntId = 0;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		instance = this;
		// new App(instance);
		// App.Logout();

		// 隐藏标题
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		// 设置视图
		setContentView(R.layout.activity_main);

		InitView();
		InitData();
	}

	@Override
	public void onWindowFocusChanged(boolean hasFocus) {
		// TODO Auto-generated method stub
		super.onWindowFocusChanged(hasFocus);
		if (hasFocus) {

		}
	}

	/**
	 * 初始化UI
	 */
	protected void InitView() {

		localActivityManager = getLocalActivityManager();

		mainContainer = (LinearLayout) findViewById(R.id.main_container);
		appTitle = (TextView) findViewById(R.id.main_tab_top_title);

		InitTab();
		setContainerView("PalletActivity", PalletActivity.class);
		setMenuIcon("pallet");

	}

	/**
	 * 初始化加载数据
	 */
	protected void InitData() {

		// 检查更新
		// new Handler().postDelayed(new Runnable() {
		// @Override
		// public void run() {
		// AppUpdate appUpdate = new
		// AppUpdate(instance,"com.shipping","manager");
		// appUpdate.checkUpdate();
		// }
		// }, 5000);

		// 获得实例对象
		userSP = new AppSharedPreferences(instance,
				AppSharedPreferences.USER_SHAREPRE_FILE);
		UserIntId = userSP.getUserIntId();
		if (UserIntId > 0) {
			resetAliasAndTags();
		}
	}

	protected void GoLogin() {
		Intent intent = new Intent();
		intent.setClass(instance, LoginActivity.class);
		startActivityForResult(intent, GOTO_LOGIN);

	}

	/**
	 * 初始化TAB
	 * */
	protected void InitTab() {

		// pallet
		btn_boot_pallet_ImageView = (ImageView) findViewById(R.id.bottom_tab_pallet_iv);
		btn_boot_pallet_ImageView.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				setMenuIcon("pallet");
				// startActivity(new
				// Intent(MainActivity.this,PalletActivity.class));
				Intent intent = new Intent();
		         intent.setAction("action.palletRefresh");
		         sendBroadcast(intent);
				setContainerView("PalletActivity", PalletActivity.class);
			}
		});

		// ship
		btn_boot_shipschedule_ImageView = (ImageView) findViewById(R.id.bottom_tab_shipschedule_iv);
		btn_boot_shipschedule_ImageView
				.setOnClickListener(new OnClickListener() {
					@Override
					public void onClick(View v) {
						// TODO Auto-generated method stub
						setMenuIcon("ship");
						Intent intent = new Intent();
				         intent.setAction("action.shipRefresh");
				         sendBroadcast(intent);
						setContainerView("ShipScheduleActivity",
								ShipScheduleActivity.class);
					}
				});

		// chat
		btn_boot_chat_ImageView = (ImageView) findViewById(R.id.bottom_tab_chat_iv);
		btn_boot_chat_ImageView.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub

				if (App.UserIsLogin()) {
					setMenuIcon("chat");

//					setContainerView("ChatActivity", ChatActivity.class);
					if (userSP.getUserType().equals("HZ")){
						Intent intent = new Intent();
				         intent.setAction("action.hzRefresh");
				         sendBroadcast(intent);
						setContainerView("MyInquiryPalletHzActivity", MyInquiryPalletHzActivity.class);
					}
					if (userSP.getUserType().equals("DL")){
						Intent intent = new Intent();
				         intent.setAction("action.dlRefresh");
				         sendBroadcast(intent);
						setContainerView("MyInquiryPalletDlActivity", MyInquiryPalletDlActivity.class);
					}
					if(userSP.getUserType().equals("CD")){
						Intent intent = new Intent();
				         intent.setAction("action.refresh");
				         sendBroadcast(intent);
						setContainerView("InquiryShipActivity", InquiryShipActivity.class);
					}
				} else {
					T.show(instance, "您尚未登录,请登录后再操作");
					startActivityForResult(new Intent(instance, LoginActivity.class),GOTO_LOGIN_ACTIVITY);
				}
			}
		});

		// 个人
		btn_boot_personal_ImageView = (ImageView) findViewById(R.id.bottom_tab_personal_iv);
		btn_boot_personal_ImageView.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				setMenuIcon("personal");
				setContainerView("uCenterActivity", uCenterActivity.class);
			}
		});

	}

	protected void setMenuIcon(String tabIndex) {
		if (tabIndex.equals("pallet")) {
			setTitle("货盘");

			btn_boot_pallet_ImageView
					.setImageResource(R.drawable.btn_home_boot_pallet_pressed);
			btn_boot_shipschedule_ImageView
					.setImageResource(R.drawable.btn_home_boot_ship_normal);
			btn_boot_chat_ImageView
					.setImageResource(R.drawable.btn_home_boot_chat_normal);
			btn_boot_personal_ImageView
					.setImageResource(R.drawable.btn_home_boot_personal_normal);
		} else if (tabIndex.equals("ship")) {
			setTitle("船期");
			btn_boot_pallet_ImageView
					.setImageResource(R.drawable.btn_home_boot_pallet_normal);
			btn_boot_shipschedule_ImageView
					.setImageResource(R.drawable.btn_home_boot_ship_pressed);
			btn_boot_chat_ImageView
					.setImageResource(R.drawable.btn_home_boot_chat_normal);
			btn_boot_personal_ImageView
					.setImageResource(R.drawable.btn_home_boot_personal_normal);
		} else if (tabIndex.equals("chat")) {
			setTitle("聊天");
			btn_boot_pallet_ImageView
					.setImageResource(R.drawable.btn_home_boot_pallet_normal);

			btn_boot_shipschedule_ImageView
					.setImageResource(R.drawable.btn_home_boot_ship_normal);
			btn_boot_chat_ImageView
					.setImageResource(R.drawable.btn_home_boot_chat_pressed);
			btn_boot_personal_ImageView
					.setImageResource(R.drawable.btn_home_boot_personal_normal);
		} else if (tabIndex.equals("personal")) {
			setTitle("个人");
			btn_boot_pallet_ImageView
					.setImageResource(R.drawable.btn_home_boot_pallet_normal);
			btn_boot_shipschedule_ImageView
					.setImageResource(R.drawable.btn_home_boot_ship_normal);
			btn_boot_chat_ImageView
					.setImageResource(R.drawable.btn_home_boot_chat_normal);
			btn_boot_personal_ImageView
					.setImageResource(R.drawable.btn_home_boot_personal_pressed);
		}
	}

	/**
	 * 设置标题
	 * */
	public void setTitle(String title) {
		appTitle.setText(title);
	}

	/**
	 * 设置Container
	 * */
	protected void setContainerView(String id, Class<?> activity) {
		mainContainer.removeAllViews();
		mainIntent = new Intent(this, activity);
		mainIntent.putExtra("VisibilityHeader", false);// True是隐藏 false是不隐藏
		mainIntent.putExtra("IsVisibilityHeaderGoBack", true);// True是隐藏 false是不隐藏
		mainContainer.addView(localActivityManager
				.startActivity(id, mainIntent).getDecorView(),
				new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
						ViewGroup.LayoutParams.MATCH_PARENT));
	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		// 在首页时才 开启连续两次返回键退出系统功能
		if (keyCode == KeyEvent.KEYCODE_BACK
				&& event.getAction() == KeyEvent.ACTION_DOWN) {
			if ((System.currentTimeMillis() - exitTime) > 2000) {
				Toast.makeText(getApplicationContext(), "再按一次退出应用",
						Toast.LENGTH_SHORT).show();
				exitTime = System.currentTimeMillis();
			} else {
				finish();
				System.exit(0);
			}
			return true;
		}

		return super.onKeyDown(keyCode, event);
	}

	private void resetAliasAndTags() {
		L.i(TAG, "----------------------------------resetAliasAndTags begin");

		// reset to jpush
		// JPushInterface.setAliasAndTags(ChattingActivity.this, UserIntId+"",
		// null, new TagAliasCallback() {
		//
		// @Override
		// public void gotResult(int code, String alias, Set<String> tags) {
		// L.i(TAG, "[TagAliasCallback], code: " + code);
		// L.i(TAG, "[TagAliasCallback], alias: " + alias);
		// L.i(TAG, "[TagAliasCallback], tags: " + tags);
		// }
		// });

		UserIntId = userSP.getUserIntId();

		L.i(TAG,
				"----------------------------------resetAliasAndTags UserIntId="
						+ UserIntId);

		// 调用JPush API设置Alias
		jpushHandler.sendMessage(jpushHandler.obtainMessage(MSG_SET_ALIAS,
				UserIntId + ""));

		L.i(TAG, "----------------------------------resetAliasAndTags end");
	}

	private final TagAliasCallback mAliasCallback = new TagAliasCallback() {

		@Override
		public void gotResult(int code, String alias, Set<String> tags) {

			L.i(TAG, "[TagAliasCallback], code: " + code);
			L.i(TAG, "[TagAliasCallback], alias: " + alias);
			L.i(TAG, "[TagAliasCallback], tags: " + tags);

			String logs;
			switch (code) {
			case 0:
				logs = "Set tag and alias success";
				L.i(TAG, logs);
				break;

			case 6002:
				logs = "Failed to set alias and tags due to timeout. Try again after 60s.";
				L.i(TAG, logs);

				jpushHandler.sendMessageDelayed(
						jpushHandler.obtainMessage(MSG_SET_ALIAS, alias),
						1000 * 60);

				break;

			default:
				logs = "Failed with errorCode = " + code;
				L.i(TAG, logs);
			}

			// T.show(getApplicationContext(),logs);
		}

	};

	private final Handler jpushHandler = new Handler() {
		@Override
		public void handleMessage(android.os.Message msg) {
			super.handleMessage(msg);
			switch (msg.what) {
			case MSG_SET_ALIAS:
				L.i(TAG, "Set alias in handler.");
				JPushInterface.setAliasAndTags(getApplicationContext(),
						(String) msg.obj, null, mAliasCallback);
				break;

			// case MSG_SET_TAGS:
			// Log.d(TAG, "Set tags in handler.");
			// JPushInterface.setAliasAndTags(getApplicationContext(), null,
			// (Set<String>) msg.obj, mTagsCallback);
			// break;

			default:
				L.i(TAG, "Unhandled msg - " + msg.what);
			}
		}
	};

}

activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/white"
    android:orientation="vertical" >

    <!-- top -->

    <RelativeLayout
        android:id="@+id/main_tab_top"
        android:layout_width="fill_parent"
        android:layout_height="50dp"
        android:background="@drawable/main_header_relativelayout_bg"
        android:orientation="horizontal"
        android:padding="5dp"
        android:paddingLeft="10dip" 
        android:visibility="gone"
        >

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:gravity="center_horizontal|bottom"
            android:visibility="gone" />

        <TextView
            android:id="@+id/main_tab_top_title"
            android:layout_width="100dp"
            android:layout_height="30dp"
            android:layout_centerInParent="true"
            android:layout_gravity="center_vertical|center"
            android:gravity="center_vertical|center"
            android:text="船运在线"
            android:textColor="@color/font_color"
            android:textSize="18dip" />

        <LinearLayout
            android:id="@+id/header_add_linearlayout"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:layout_alignParentRight="true"
            android:layout_marginRight="10dp"
             android:visibility="gone"
             >

            <ImageView
                android:id="@+id/header_add_iv"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical|center"
                android:background="@drawable/header_icon_add"
                android:padding="10dp" />
        </LinearLayout>
    </RelativeLayout>

    <!-- bottom -->

    <LinearLayout
        android:id="@+id/main_tab_bottom"
        android:layout_width="fill_parent"
        android:layout_height="70dp"
        android:layout_alignParentBottom="true"
        android:background="@drawable/main_bottom_linearlayout_bg"
        android:gravity="center"
        android:orientation="horizontal" >

        <ImageView
            android:id="@+id/bottom_tab_pallet_iv"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center_horizontal|bottom"
            android:src="@drawable/btn_home_boot_pallet_normal"
            android:textColor="#000000"
            android:textSize="16dip" />

        <ImageView
            android:id="@+id/bottom_tab_shipschedule_iv"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center_horizontal|bottom"
            android:src="@drawable/btn_home_boot_ship_normal"
            android:textColor="#000000"
            android:textSize="16dip" />

        <ImageView
            android:id="@+id/bottom_tab_chat_iv"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center_horizontal|bottom"
            android:src="@drawable/btn_home_boot_chat_normal"
            android:textColor="#000000"
            android:textSize="16dip" />

        <ImageView
            android:id="@+id/bottom_tab_personal_iv"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center_horizontal|bottom"
            android:src="@drawable/btn_home_boot_personal_normal"
            android:textColor="#000000"
            android:textSize="16dip" />
    </LinearLayout>

    <!-- container -->

    <LinearLayout
        android:id="@+id/main_container"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_above="@id/main_tab_bottom"
        android:layout_below="@id/main_tab_top"
        android:background="#F4F4F4"
        android:orientation="vertical" >
    </LinearLayout>

</RelativeLayout>


欢迎页,引导页和主页

标签:android   activity   欢迎页   public   引导页   

原文地址:http://javaqun.blog.51cto.com/10687700/1735408

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!