| | |
| | | package cn.com.basic.face.base; |
| | | |
| | | import android.content.Context; |
| | | import android.content.Intent; |
| | | import android.os.Handler; |
| | | import android.support.design.widget.TabLayout; |
| | | import android.support.v4.app.Fragment; |
| | | import android.support.v4.app.FragmentManager; |
| | |
| | | import android.os.Bundle; |
| | | import android.view.LayoutInflater; |
| | | import android.view.View; |
| | | import android.view.Window; |
| | | import android.view.WindowManager; |
| | | import android.widget.ImageView; |
| | | import android.widget.LinearLayout; |
| | | import android.widget.TextView; |
| | | import android.widget.Toast; |
| | | |
| | | import com.bsk.zhangbo.demoforbsk.R; |
| | | import cn.com.basic.face.fragment.SurveillanceFragment; |
| | |
| | | import cn.com.basic.face.fragment.RegisterFragment; |
| | | import cn.com.basic.face.fragment.VisitFragment; |
| | | |
| | | import java.io.File; |
| | | import java.io.FileOutputStream; |
| | | import java.io.InputStream; |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | |
| | | myFragmentPagerAdapter.addFragment(RegisterFragment.getInstance(), tabNamesList.get(1),tabIcons[1]); |
| | | myFragmentPagerAdapter.addFragment(CheckInFragment.getInstance(), tabNamesList.get(2),tabIcons[2]); |
| | | myFragmentPagerAdapter.addFragment(PhoneCallFragment.getInstance(), tabNamesList.get(3),tabIcons[3]); |
| | | myFragmentPagerAdapter.addFragment(VisitFragment.newInstance(), tabNamesList.get(4),tabIcons[4]); |
| | | myFragmentPagerAdapter.addFragment(AttendanceFragment.newInstance(), tabNamesList.get(5),tabIcons[5]); |
| | | myFragmentPagerAdapter.addFragment(DeviceFragment.newInstance(), tabNamesList.get(6),tabIcons[6]); |
| | | myFragmentPagerAdapter.addFragment(VisitFragment.getInstance(), tabNamesList.get(4),tabIcons[4]); |
| | | myFragmentPagerAdapter.addFragment(AttendanceFragment.getInstance(), tabNamesList.get(5),tabIcons[5]); |
| | | myFragmentPagerAdapter.addFragment(DeviceFragment.getInstance(), tabNamesList.get(6),tabIcons[6]); |
| | | mViewPager.setAdapter(myFragmentPagerAdapter); |
| | | mViewPager.setOffscreenPageLimit(6);//viewpager缓存个数 |
| | | mTabLayout.setupWithViewPager(mViewPager); |
| | | mTabLayout.setTabMode(TabLayout.MODE_FIXED); |
| | | for (int i = 0; i < mTabLayout.getTabCount(); i++) { |
| | | TabLayout.Tab tab = mTabLayout.getTabAt(i); |
| | | tab.setCustomView(myFragmentPagerAdapter.getTabView(i)); |
| | | LinearLayout view = (LinearLayout)myFragmentPagerAdapter.getTabView(i); |
| | | tab.setCustomView(view); |
| | | if (i == 0) { |
| | | tab.getCustomView().setSelected(true); |
| | | } |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | public static MainActivity getInstance() { |
| | |
| | | |
| | | } |
| | | |
| | | boolean doubleBackToExitPressedOnce = false; |
| | | |
| | | @Override |
| | | public void onBackPressed() { |
| | | if (doubleBackToExitPressedOnce) { |
| | | super.onBackPressed(); |
| | | return; |
| | | } |
| | | |
| | | this.doubleBackToExitPressedOnce = true; |
| | | Toast.makeText(this, "请再次按返回键退出", Toast.LENGTH_SHORT).show(); |
| | | |
| | | new Handler().postDelayed(new Runnable() { |
| | | |
| | | @Override |
| | | public void run() { |
| | | doubleBackToExitPressedOnce=false; |
| | | } |
| | | }, 2000); |
| | | } |
| | | |
| | | |
| | | private MyThread myThread; |
| | | class MyThread extends Thread{ |
| | | @Override |
| | | public void run() { |
| | | try { |
| | | setBmpDecodeEnv(); |
| | | Thread.sleep(2000); |
| | | // Intent sendIntent =new Intent("com.xs.identity.over"); |
| | | // sendBroadcast(sendIntent); |
| | | } catch (InterruptedException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | /** |
| | | * 将raw下的文件复制到sdCard |
| | | */ |
| | | public boolean setBmpDecodeEnv() { |
| | | |
| | | String path=getFilesDir().getAbsolutePath(); |
| | | String filename = "base.dat"; |
| | | try{ |
| | | String databaseFilename = path + "/" + filename; |
| | | File dir = new File(path); |
| | | if (!dir.exists()) |
| | | dir.mkdir(); |
| | | if (!(new File(databaseFilename)).exists()){ |
| | | InputStream is = getResources().openRawResource(R.raw.base); |
| | | FileOutputStream fos = new FileOutputStream(databaseFilename); |
| | | byte[] buffer = new byte[8192]; |
| | | int count = 0; |
| | | while ((count = is.read(buffer)) > 0) |
| | | { |
| | | fos.write(buffer, 0, count); |
| | | } |
| | | fos.close(); |
| | | is.close(); |
| | | } |
| | | } |
| | | catch (Exception e){ |
| | | System.out.println(e.getMessage()); |
| | | return false; |
| | | } |
| | | |
| | | String filename1 = "license.lic"; |
| | | try{ |
| | | String databaseFilename = path + "/" + filename1; |
| | | File dir = new File(path); |
| | | if (!dir.exists()) |
| | | dir.mkdir(); |
| | | if (!(new File(databaseFilename)).exists()){ |
| | | InputStream is = getResources().openRawResource(R.raw.license); |
| | | FileOutputStream fos = new FileOutputStream(databaseFilename); |
| | | byte[] buffer = new byte[8192]; |
| | | int count = 0; |
| | | while ((count = is.read(buffer)) > 0) |
| | | { |
| | | fos.write(buffer, 0, count); |
| | | } |
| | | fos.close(); |
| | | is.close(); |
| | | } |
| | | } |
| | | catch (Exception e){ |
| | | System.out.println(e.getMessage()); |
| | | return false; |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | } |