Java tutorial
/** * * Copyright (c) 2013,2014 RadiusNetworks. All rights reserved. * http://www.radiusnetworks.com * * @author David G. Young * * Licensed to the Attribution Assurance License (AAL) * (adapted from the original BSD license) See the LICENSE file * distributed with this work for additional information * regarding copyright ownership. * */ package it.clipart.swipehtmlpageapp; import android.os.Bundle; import android.support.v4.app.Fragment; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.webkit.WebView; import android.content.Context; /** * This class represents a single page in the Intro as controlled by the IntroActivity * <p/> * Created by dyoung on 3/10/14. */ public class IntroFragment extends Fragment { private static final String TAG = "IntroFragment"; private static final String ARG_OBJECT = "object"; private boolean dontShowAgain = false; private View rootView; private int item; MyWebActivity activity; public IntroFragment(MyWebActivity activity, int page) { // Mentre costruisce e visualizza la pagina corrente carica la prossima pagina. item = page + 1; } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { rootView = inflater.inflate(R.layout.intro_screen, container, false); View controlView = rootView.findViewById(R.id.introFinishControls); /* If we are on the last page of the intro, we show a special controlView that lets the user select if they ever want to see this again, and continue on to the main part of the app. Se si nell'ultima pagina dell'intro, verr mostrato uno speciale controlView che lascia l'utente se vuole vederlo da capo o proseguire nella parte principale. */ if (item == MyWebActivity.NUM_INTRO_PAGES) { /* Se l'ultima pagina rende visibile il layout contenente il controllo che lancia la guida vera e propria - Il fatto che sia l'ultima pagina non viene creato un successivo Fragment e quindi lo swipe non pi attivo. */ controlView.setVisibility(View.VISIBLE); // Controlla la checkBox "Non mostrare pi" rootView.findViewById(R.id.checkBox).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { dontShowAgainTapped(); } }); } // Se si torna indietro ( ad esempio ) rende invisibile il controllo di cui sopra else { controlView.setVisibility(View.INVISIBLE); } WebView webview = (WebView) rootView.findViewById(R.id.webView); android.webkit.WebSettings webSettings = webview.getSettings(); webSettings.setJavaScriptEnabled(true); webview.getSettings().setLoadsImagesAutomatically(true); webview.addJavascriptInterface(new WebAppInterface(this.activity), "Android"); webview.loadUrl("file:///android_asset/intro" + item + ".html"); Log.d(TAG, "Caricata la pagina intro url: " + webview.getUrl()); return rootView; } // Track the state of the checkbox here manually, because we are using a custom ImageButton so // we can make the checkbox have a special look public void dontShowAgainTapped() { dontShowAgain = !dontShowAgain; Log.d(TAG, "NON MOSTRARE PIU' stato toccato. ora: " + dontShowAgain); if (dontShowAgain) { //rootView.findViewById(R.id.checkBox).setBackground(getResources().getDrawable(R.drawable.checkbox_checked )); } else { //rootView.findViewById(R.id.checkBox).setBackground(getResources().getDrawable(R.drawable.checkbox_unchecked )); } } public class WebAppInterface { android.content.Context mContext; /** Instantiate the interface and set the context */ WebAppInterface(android.content.Context c) { mContext = c; } /** Show a toast from the web page */ //@JavascriptInterface public void showToast(String toast) { android.widget.Toast.makeText(mContext, toast, android.widget.Toast.LENGTH_SHORT).show(); } } }