William Zhang

Logo

Mobile App Developer, Competitive Programmer, and Full-Stack Software Engineer

LinkedIn

View My GitHub Profile

Welcome to Timely Fitness

drawing

forthebadge forthebadge forthebadge forthebadge

Welcome to the Timely Fitness project!

Timely Fitness is an Android app that helps you keep good track of your fitness, and occasionally gives you somewhat functional reminders to get moving.

Want to help?

To create this project, I didn’t just need to learn Java. I also had to use:

How does the code behind the app work?

The app works through a central file called MainActivity.java. It contains a crucial method in the code known as the “main” method, which the compiler looks for when it tries to execute the app. Currently, the main function looks something like this:

@Override
    public void onCreate(Bundle savedInstanceState) {

        SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
        String dayNightAuto = SP.getString("dayNightAuto", "2");
        int dayNightAutoValue;
        try {
            dayNightAutoValue = Integer.parseInt(dayNightAuto);
        } catch (NumberFormatException e) {
            dayNightAutoValue = 2;
        }
        if (dayNightAutoValue == getResources().getInteger(R.integer.dark_mode_value)) {
            AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
            SweetAlertDialog.DARK_STYLE = true;
        } else if (dayNightAutoValue == getResources().getInteger(R.integer.light_mode_value)) {
            AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
            SweetAlertDialog.DARK_STYLE = false;
        } else {
            AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM);
            int currentNightMode = getResources().getConfiguration().uiMode
                    & Configuration.UI_MODE_NIGHT_MASK;
            switch (currentNightMode) {
                case Configuration.UI_MODE_NIGHT_YES:
                    SweetAlertDialog.DARK_STYLE = true;
                    break;
                case Configuration.UI_MODE_NIGHT_NO:
                default:
                    SweetAlertDialog.DARK_STYLE = false;
            }
        }

        super.onCreate(savedInstanceState);

        if (ContextCompat.checkSelfPermission(this,
                Manifest.permission.WRITE_EXTERNAL_STORAGE)
                == PackageManager.PERMISSION_GRANTED) {

            File folder = new File(Environment.getExternalStorageDirectory() + "/FastnFitness");
            boolean success = true;
            if (!folder.exists()) {
                success = folder.mkdir();
            }
            if (success) {
                folder = new File(Environment.getExternalStorageDirectory() + "/FastnFitness/crashreport");
                success = folder.mkdir();
            }

            if (folder.exists()) {
                if (!(Thread.getDefaultUncaughtExceptionHandler() instanceof CustomExceptionHandler)) {
                    Thread.setDefaultUncaughtExceptionHandler(new CustomExceptionHandler(
                            Environment.getExternalStorageDirectory() + "/FastnFitness/crashreport"));
                }
            }
        }

        setContentView(R.layout.activity_main);

I’d agree with everyone’s thoughts right now; it looks messy. But the system has to check over a lot of things, like the display size, the status of the device, and some strange abomination that is the light mode/dark mode switcher thingy.

Credits (to all the people whose code and library functions helped make this app just work)

Parts of the library functions for this project were forked from other awesome creations, such as a project by brodeurlv that is called FastNFitness. I found his CSV data parsing functions extremely helpful, and included a folder of some of the functions that he wrote to parse mine. I also used Google Code Snippets, which are folders of functions that the team behind the Android mobile operating system wrote to help developers along, so I need to acknowledge that I used their functional code to help me make this project possible.

Timely Fitness