Intelligent housekeeper -- 6. Logic development of home page Jump

  • Next, the flash screen page is implemented. If the program is run for the first time, the flash screen page will jump to the boot page. If not, it will jump to the main activity.

  • Similarly, there is only one TextView in the splash screen page and the guide page, indicating the splash screen page and the guide page.

  • The flash page has a delay effect (2s). Here we use the handler to implement the delay function

  • The handleMessage method needs to be overridden to filter out the msg to be used through switch. If it is a splash screen and it is the first time to run, it will jump to the boot page.

  • Next, judge whether the program runs for the first time

  • Judge after getting the boolean value

  • Delay implementation:

handler.sendEmptyMessageDelayed(StaticClass.SHARE_SPLASH,2000);
  • Set the style of the font, because the method of setting the font may be used in the future, so we encapsulate it into UtilTools

  • Set for textView of the splash screen page

mTextView=(TextView)findViewById(R.id.splash_text);
UtilsTools.setFont(this,mTextView);
  • Disable return key
    Just annotate the method super
//Disable return key
    @Override
    public void onBackPressed() {
       // super.onBackPressed();
    }
  • Achieve full screen
    Because SplashActivity inherits AppCompatActivity, not Activity, we can't set full screen theme directly in Android manifest.xml. We can customize full screen theme in style file

    At the same time, note in Android manifest.xml:

All code of SplashActivity:

public class SplashActivity extends AppCompatActivity {

    private TextView mTextView;

    private Handler handler=new Handler(){
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            switch (msg.what){
                case StaticClass.SHARE_SPLASH:
                    if(isFirst()){
                        startActivity(new Intent(SplashActivity.this,GuideActivity.class));
                    }else{
                        startActivity(new Intent(SplashActivity.this, MainActivity.class));
                    }
                    finish();
                    break;

            }
        }
    };


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);

        initView();
    }

    private void initView() {
        mTextView=(TextView)findViewById(R.id.splash_text);
        handler.sendEmptyMessageDelayed(StaticClass.SHARE_SPLASH,2000);
        UtilsTools.setFont(this,mTextView);
    }

    private boolean isFirst(){
        boolean isFirst= ShareUtils.getBoolean(this,StaticClass.SHARE_IS_FIRST,true);

        //If it is the first run, isFirst is true, and it is set to false, which means whether it is the first run and returns true, otherwise it is not the first run and returns false
        if(isFirst){
            ShareUtils.putBoolean(this,StaticClass.SHARE_IS_FIRST,false);
            return true;
        }else
        {
            return false;
        }
    }

    //Disable return key
    @Override
    public void onBackPressed() {
       // super.onBackPressed();
    }
}

Tags: Android xml

Posted on Mon, 06 Jan 2020 11:56:48 -0800 by sweatje