Skip to content

Commit 038dd56

Browse files
committed
Launcher and Shared Prefrences
1 parent db6cbfc commit 038dd56

File tree

7 files changed

+142
-13
lines changed

7 files changed

+142
-13
lines changed

TestAksh/.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

TestAksh/app/src/main/AndroidManifest.xml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,7 @@
2626
<activity
2727
android:name=".example.TecmaxLauncherActivity"
2828
android:configChanges="orientation|keyboardHidden|screenSize"
29-
android:theme="@style/FullscreenTheme">
30-
<intent-filter>
31-
<action android:name="android.intent.action.MAIN" />
32-
33-
<category android:name="android.intent.category.LAUNCHER" />
34-
</intent-filter>
35-
</activity>
29+
android:theme="@style/FullscreenTheme"/>
3630
<activity android:name=".example.LinearExActivity" />
3731
<activity
3832
android:name=".default_templets.BasicActivity"
@@ -84,7 +78,14 @@
8478
<activity
8579
android:name=".example.WhatsTabActivity"
8680
android:label="@string/title_activity_whats_tab"
87-
android:theme="@style/AppTheme.NoActionBar"></activity>
81+
android:theme="@style/AppTheme.NoActionBar" />
82+
<activity android:name=".LauncherActivity">
83+
<intent-filter>
84+
<action android:name="android.intent.action.MAIN" />
85+
86+
<category android:name="android.intent.category.LAUNCHER" />
87+
</intent-filter>
88+
</activity>
8889
</application>
8990

9091
</manifest>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.tecmax.testaksh;
2+
3+
import android.content.Intent;
4+
import android.os.Bundle;
5+
import android.support.v7.app.AppCompatActivity;
6+
7+
import com.tecmax.testaksh.example.TecmaxLauncherActivity;
8+
9+
public class LauncherActivity extends AppCompatActivity {
10+
11+
@Override
12+
protected void onCreate(Bundle savedInstanceState) {
13+
super.onCreate(savedInstanceState);
14+
setContentView(R.layout.activity_launcher);
15+
Thread timerThread = new Thread() {
16+
public void run() {
17+
try {
18+
sleep(3000);
19+
} catch (InterruptedException e) {
20+
e.printStackTrace();
21+
} finally {
22+
finish();
23+
Intent intent = new Intent(LauncherActivity.this,
24+
TecmaxLauncherActivity.class);
25+
startActivity(intent);
26+
}
27+
}
28+
};
29+
timerThread.start();
30+
}
31+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package com.tecmax.testaksh;
2+
3+
import android.content.Context;
4+
import android.content.SharedPreferences;
5+
6+
/**
7+
* Created by Lincoln on 05/05/16.
8+
*/
9+
public class PrefManager {
10+
SharedPreferences pref;
11+
SharedPreferences.Editor editor;
12+
Context _context;
13+
14+
// shared pref mode
15+
int PRIVATE_MODE = 0;
16+
17+
// Shared preferences file name
18+
private static final String PREF_NAME = "androidhive-welcome";
19+
20+
private static final String IS_FIRST_TIME_LAUNCH = "IsFirstTimeLaunch";
21+
private static final String USERNAME = "username";
22+
23+
public PrefManager(Context context) {
24+
this._context = context;
25+
pref = _context.getSharedPreferences(PREF_NAME, PRIVATE_MODE);
26+
editor = pref.edit();
27+
}
28+
29+
public void setRememberMe(boolean isFirstTime) {
30+
editor.putBoolean(IS_FIRST_TIME_LAUNCH, isFirstTime);
31+
editor.apply();
32+
}
33+
34+
public boolean isRememberMe() {
35+
return pref.getBoolean(IS_FIRST_TIME_LAUNCH, true);
36+
}
37+
38+
public void setUserName(String isFirstTime) {
39+
editor.putString(USERNAME, isFirstTime);
40+
editor.apply();
41+
}
42+
43+
public String getUserName() {
44+
return pref.getString(USERNAME, "");
45+
}
46+
47+
}

TestAksh/app/src/main/java/com/tecmax/testaksh/fragments/LoginFragment.java

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,22 @@
66
import android.view.LayoutInflater;
77
import android.view.View;
88
import android.view.ViewGroup;
9+
import android.widget.Button;
10+
import android.widget.CheckBox;
11+
import android.widget.EditText;
912
import android.widget.Toast;
1013

14+
import com.tecmax.testaksh.PrefManager;
1115
import com.tecmax.testaksh.R;
1216

1317
/**
1418
* A simple {@link Fragment} subclass.
1519
*/
1620
public class LoginFragment extends Fragment {
1721

22+
CheckBox rem;
23+
EditText un, pa;
24+
PrefManager manager;
1825

1926
public LoginFragment() {
2027
// Required empty public constructor
@@ -24,11 +31,32 @@ public LoginFragment() {
2431
@Override
2532
public View onCreateView(LayoutInflater inflater, ViewGroup container,
2633
Bundle savedInstanceState) {
27-
// Inflate the layout for this fragment
28-
return inflater.inflate(R.layout.fragment_login, container, false);
34+
View v = inflater.inflate(R.layout.fragment_login, container, false);
35+
rem = v.findViewById(R.id.rem);
36+
un = v.findViewById(R.id.lg);
37+
pa = v.findViewById(R.id.pa);
38+
Button logi = v.findViewById(R.id.lvv);
39+
logi.setOnClickListener(new View.OnClickListener() {
40+
@Override
41+
public void onClick(View view) {
42+
validation(view);
43+
}
44+
});
45+
manager = new PrefManager(getActivity());
46+
47+
if (manager.isRememberMe()) {
48+
un.setText(manager.getUserName());
49+
rem.setChecked(true);
50+
}
51+
return v;
2952
}
3053

3154
public void validation(View v) {
32-
Toast.makeText(getActivity(), "Login Clicked", Toast.LENGTH_SHORT).show();
55+
if (rem.isChecked()) {
56+
manager.setUserName(un.getText().toString());
57+
}
58+
manager.setRememberMe(rem.isChecked());
59+
Toast.makeText(getActivity(),
60+
"Login Clicked", Toast.LENGTH_SHORT).show();
3361
}
3462
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto"
4+
xmlns:tools="http://schemas.android.com/tools"
5+
android:layout_width="match_parent"
6+
android:layout_height="match_parent"
7+
tools:context="com.tecmax.testaksh.LauncherActivity">
8+
9+
</android.support.constraint.ConstraintLayout>

TestAksh/app/src/main/res/layout/fragment_login.xml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,23 @@
1010
android:layout_width="match_parent"
1111
android:layout_height="wrap_content"
1212
android:hint="username" />
13+
1314
<EditText
1415
android:id="@+id/pa"
1516
android:layout_width="match_parent"
1617
android:layout_height="wrap_content"
1718
android:hint="Password" />
1819

20+
<CheckBox
21+
android:id="@+id/rem"
22+
android:layout_width="match_parent"
23+
android:layout_height="wrap_content"
24+
android:text="Remember Me" />
25+
1926
<Button
27+
android:id="@+id/lvv"
2028
android:layout_width="match_parent"
2129
android:layout_height="wrap_content"
22-
android:onClick="validation"
23-
android:text="Login"/>
30+
android:text="Login" />
2431

2532
</LinearLayout>

0 commit comments

Comments
 (0)