com.android.projectz.teamrocket.thebusapp.IntroApp.java Source code

Java tutorial

Introduction

Here is the source code for com.android.projectz.teamrocket.thebusapp.IntroApp.java

Source

package com.android.projectz.teamrocket.thebusapp;
/*
 Copyright (C) 2016-2017  TeamRocket
    
 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.
    
 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
    
 You should have received a copy of the GNU General Public License
 along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

import android.Manifest;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.util.Log;

import com.android.projectz.teamrocket.thebusapp.activities.SplashScreenActivity;
import com.android.projectz.teamrocket.thebusapp.util.SharedPreferencesUtils;
import com.github.paolorotolo.appintro.AppIntro;
import com.github.paolorotolo.appintro.AppIntroFragment;

/**
 * IntroActivity:
 * Questa applicazione dovr fungere da "libretto di istruzione"
 * visibile solo all'avvio del programma, viene usato una dependencies
 * esterna di Paolo Rotolo. Ci permette di migliorare la visualizzazione
 * delle pagine e rendere il tutto professionale e pulito
 *
 * @author simone98dm
 * @date 12/11/2016
 */

public class IntroApp extends AppIntro {
    private String[] permissions = { Manifest.permission.INTERNET, Manifest.permission.WRITE_EXTERNAL_STORAGE,
            Manifest.permission.READ_PHONE_STATE, Manifest.permission.GET_ACCOUNTS };
    private int[] confirmedPermission = new int[4];

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // visualizzazione del benvenuto
        addSlide(AppIntroFragment.newInstance(getResources().getString(R.string.appintro_page1),
                getResources().getString(R.string.appintro_page1_description), R.drawable.ic_bus,
                Color.parseColor("#3498db")));

        // visualizza informazioni per l'inserimento dei dati nei box
        addSlide(AppIntroFragment.newInstance(getResources().getString(R.string.appintro_page2),
                getResources().getString(R.string.appintro_page2_description), R.drawable.appintro_lens,
                Color.parseColor("#e67e22")));

        // visualizza informazioni della lettura dei degli orari
        addSlide(AppIntroFragment.newInstance(getResources().getString(R.string.appintro_page3),
                getResources().getString(R.string.appintro_page3_description), R.drawable.appintro_clock,
                Color.parseColor("#1abc9c")));

        // visualizza informazioni sui dettagli che vengono fuori col tap sul tragitto
        addSlide(AppIntroFragment.newInstance(getResources().getString(R.string.appintro_view_detail),
                getResources().getString(R.string.appIntro_view_detail_body), R.drawable.appintro_detail,
                Color.parseColor("#e74c3c")));

        // visualizza informazioni sulla visualizzazione del report
        addSlide(AppIntroFragment.newInstance(getResources().getString(R.string.appintro_report_issue),
                getResources().getString(R.string.appintro_report_issue_description), R.drawable.appintro_bug,
                Color.parseColor("#9b59b6")));

        //se la versione di android  la 6.0 verra visualizzata la schermata per i permessi...altrimenti non ce n bisogno
        if (!permission()) {
            addSlide(AppIntroFragment.newInstance(getResources().getString(R.string.appintro_permission),
                    getResources().getString(R.string.appintro_permission_content), R.drawable.appintro_permission,
                    Color.parseColor("#34495e")));
            askForPermissions(new String[] { Manifest.permission.INTERNET, Manifest.permission.READ_PHONE_STATE,
                    Manifest.permission.GET_ACCOUNTS, Manifest.permission.WRITE_EXTERNAL_STORAGE }, 6);
        }

        // visualizza la conclusione
        addSlide(AppIntroFragment.newInstance(getResources().getString(R.string.appintro_page4),
                getResources().getString(R.string.appintro_page4_description), R.drawable.appintro_team,
                Color.parseColor("#2ecc71")));

        setImmersiveMode(true);
        setColorTransitionsEnabled(true);
        showSkipButton(false);

    }

    /**
     * controllo per i permessi che l'applicazione deve avere
     * per funzionare al meglio
     */
    private boolean permission() {
        boolean permissionGrant = true;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
            for (int i = 0; i < permissions.length; i++) {
                if (getApplicationContext()
                        .checkCallingOrSelfPermission(permissions[i]) == PackageManager.PERMISSION_DENIED) {
                    permissionGrant = false;
                }
            }
        }
        return permissionGrant;
    }

    @Override
    public void onSkipPressed(Fragment currentFragment) {
        super.onSkipPressed(currentFragment);
    }

    @Override
    public void onDonePressed(Fragment currentFragment) {
        super.onDonePressed(currentFragment);
        if (SharedPreferencesUtils.isTheFirstRun(IntroApp.this) != true) {
            finish();
        } else {
            SharedPreferencesUtils.disableFirstRun(IntroApp.this);
            startActivity(new Intent(IntroApp.this, SplashScreenActivity.class));
            finish();
        }

    }

    @Override
    public void onSlideChanged(@Nullable Fragment oldFragment, @Nullable Fragment newFragment) {
        super.onSlideChanged(oldFragment, newFragment);
    }

}