Skip to content

Commit 7e2651d

Browse files
author
Seaflowery
committed
issue26 src and test
1 parent 07abecc commit 7e2651d

File tree

1 file changed

+106
-0
lines changed

1 file changed

+106
-0
lines changed
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
package io.github.subhamtyagi.lastlauncher;
2+
3+
import android.app.Activity;
4+
import android.content.SharedPreferences;
5+
import android.util.Log;
6+
import android.view.View;
7+
import android.widget.Button;
8+
import android.widget.TextView;
9+
10+
/**
11+
* the added code
12+
*/
13+
14+
public class GuidanceNewCode extends Activity {
15+
/**
16+
* button of tutorial
17+
*/
18+
19+
private Button guidanceBtn; //NOPMD - suppressed BeanMembersShouldSerialize - should be
20+
21+
/**
22+
* textview of tutorial
23+
*/
24+
25+
private TextView guidanceView; //NOPMD - suppressed BeanMembersShouldSerialize - should be
26+
27+
/**
28+
* the status of tutorial, decide on which guidance text to show
29+
*/
30+
31+
private int guidanceStatus; //NOPMD - suppressed BeanMembersShouldSerialize - should be
32+
33+
/**
34+
* debug tag
35+
*/
36+
37+
private static final String GUIDANCETAG = "guidance";
38+
39+
/**
40+
* bind guidanceBtn and guidanceView with .xml file and check the status of app
41+
* If the app runs for the first time, show the guidance
42+
* If not, hide the guidance
43+
*/
44+
45+
public void initialGuidance() {
46+
47+
// get guidance button and view by id
48+
guidanceBtn = findViewById(R.id.btn_next);
49+
guidanceView = findViewById(R.id.text_guidance);
50+
51+
// check whether the user installs the application for the first time
52+
final SharedPreferences storage = getSharedPreferences("store", 0);
53+
final boolean firstGetIn =
54+
storage.getBoolean("firstGetIn", true); //NOPMD - suppressed LawOfDemeter -
55+
56+
// if true, setup guidance, else hide the guidance
57+
if (firstGetIn) {
58+
Log.i(GUIDANCETAG, "first time!");
59+
final SharedPreferences.Editor editor = storage.edit();
60+
editor.putBoolean("firstGetIn", false); //NOPMD - suppressed LawOfDemeter -
61+
editor.commit(); //NOPMD - suppressed LawOfDemeter -
62+
} else {
63+
guidanceBtn.setVisibility(View.GONE);
64+
guidanceView.setVisibility(View.GONE);
65+
}
66+
}
67+
68+
/**
69+
* add a listener to guidanceBtn
70+
* when the button is clicked, change the text of guidanceView
71+
* (show different steps of guidance)
72+
* reveal the button and textview after user finishing the guidance
73+
* @param view the origin parameter of the button listener, no use in this method
74+
*/
75+
76+
public void onClickNext(final View view) {
77+
Log.i(GUIDANCETAG, "get in! status: " + guidanceStatus + " " + guidanceView.getText());
78+
switch (guidanceStatus) {
79+
case 0:
80+
guidanceView.setText(getResources(). //NOPMD - suppressed LawOfDemeter -
81+
getString(R.string.guidance2));
82+
guidanceView.requestLayout();
83+
guidanceStatus++;
84+
Log.i(GUIDANCETAG, "First out!" + guidanceView.getText());
85+
guidanceView.postInvalidate();
86+
break;
87+
case 1:
88+
guidanceView.setText(getResources(). //NOPMD - suppressed LawOfDemeter -
89+
getString(R.string.guidance3));
90+
guidanceStatus++;
91+
Log.i(GUIDANCETAG, "Second out!" + guidanceView.getText());
92+
break;
93+
case 2:
94+
guidanceView.setText(getResources(). //NOPMD - suppressed LawOfDemeter -
95+
getString(R.string.guidance4));
96+
guidanceStatus++;
97+
guidanceBtn.setText(getResources(). //NOPMD - suppressed LawOfDemeter -
98+
getString(R.string.finish));
99+
break;
100+
default:
101+
guidanceBtn.setVisibility(View.GONE);
102+
guidanceView.setVisibility(View.GONE);
103+
break;
104+
}
105+
}
106+
}

0 commit comments

Comments
 (0)