diff --git a/app/src/main/java/io/github/subhamtyagi/lastlauncher/GuidanceNewCode.java b/app/src/main/java/io/github/subhamtyagi/lastlauncher/GuidanceNewCode.java new file mode 100644 index 00000000..0d94f240 --- /dev/null +++ b/app/src/main/java/io/github/subhamtyagi/lastlauncher/GuidanceNewCode.java @@ -0,0 +1,106 @@ +package io.github.subhamtyagi.lastlauncher; + +import android.app.Activity; +import android.content.SharedPreferences; +import android.util.Log; +import android.view.View; +import android.widget.Button; +import android.widget.TextView; + +/** + * the added code + */ + +public class GuidanceNewCode extends Activity { + /** + * button of tutorial + */ + + private Button guidanceBtn; //NOPMD - suppressed BeanMembersShouldSerialize - should be + + /** + * textview of tutorial + */ + + private TextView guidanceView; //NOPMD - suppressed BeanMembersShouldSerialize - should be + + /** + * the status of tutorial, decide on which guidance text to show + */ + + private int guidanceStatus; //NOPMD - suppressed BeanMembersShouldSerialize - should be + + /** + * debug tag + */ + + private static final String GUIDANCETAG = "guidance"; + + /** + * bind guidanceBtn and guidanceView with .xml file and check the status of app + * If the app runs for the first time, show the guidance + * If not, hide the guidance + */ + + public void initialGuidance() { + + // get guidance button and view by id + guidanceBtn = findViewById(R.id.btn_next); + guidanceView = findViewById(R.id.text_guidance); + + // check whether the user installs the application for the first time + final SharedPreferences storage = getSharedPreferences("store", 0); + final boolean firstGetIn = + storage.getBoolean("firstGetIn", true); //NOPMD - suppressed LawOfDemeter - + + // if true, setup guidance, else hide the guidance + if (firstGetIn) { + Log.i(GUIDANCETAG, "first time!"); + final SharedPreferences.Editor editor = storage.edit(); + editor.putBoolean("firstGetIn", false); //NOPMD - suppressed LawOfDemeter - + editor.commit(); //NOPMD - suppressed LawOfDemeter - + } else { + guidanceBtn.setVisibility(View.GONE); + guidanceView.setVisibility(View.GONE); + } + } + + /** + * add a listener to guidanceBtn + * when the button is clicked, change the text of guidanceView + * (show different steps of guidance) + * reveal the button and textview after user finishing the guidance + * @param view the origin parameter of the button listener, no use in this method + */ + + public void onClickNext(final View view) { + Log.i(GUIDANCETAG, "get in! status: " + guidanceStatus + " " + guidanceView.getText()); + switch (guidanceStatus) { + case 0: + guidanceView.setText(getResources(). //NOPMD - suppressed LawOfDemeter - + getString(R.string.guidance2)); + guidanceView.requestLayout(); + guidanceStatus++; + Log.i(GUIDANCETAG, "First out!" + guidanceView.getText()); + guidanceView.postInvalidate(); + break; + case 1: + guidanceView.setText(getResources(). //NOPMD - suppressed LawOfDemeter - + getString(R.string.guidance3)); + guidanceStatus++; + Log.i(GUIDANCETAG, "Second out!" + guidanceView.getText()); + break; + case 2: + guidanceView.setText(getResources(). //NOPMD - suppressed LawOfDemeter - + getString(R.string.guidance4)); + guidanceStatus++; + guidanceBtn.setText(getResources(). //NOPMD - suppressed LawOfDemeter - + getString(R.string.finish)); + break; + default: + guidanceBtn.setVisibility(View.GONE); + guidanceView.setVisibility(View.GONE); + break; + } + } +}