-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
demonstrate more useful situation eg: login logout
- Loading branch information
Showing
26 changed files
with
453 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,32 @@ | ||
apply plugin: 'com.android.application' | ||
|
||
android { | ||
compileSdkVersion 23 | ||
buildToolsVersion "24.0.0 rc1" | ||
compileSdkVersion 24 | ||
buildToolsVersion "24.0.2" | ||
|
||
defaultConfig { | ||
applicationId "com.aspsine.fragmentnavigator.demo" | ||
minSdkVersion 11 | ||
targetSdkVersion 23 | ||
versionCode 2 | ||
versionName "2.0" | ||
targetSdkVersion 24 | ||
versionCode 3 | ||
versionName "3.0" | ||
} | ||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
repositories { | ||
maven { url "https://jitpack.io" } | ||
} | ||
} | ||
|
||
dependencies { | ||
compile fileTree(include: ['*.jar'], dir: 'libs') | ||
testCompile 'junit:junit:4.12' | ||
compile project(':library') | ||
compile 'com.android.support:appcompat-v7:23.3.0' | ||
compile 'com.android.support:support-v4:23.3.0' | ||
// compile 'com.github.Aspsine:FragmentNavigator:1.0.2' | ||
compile 'com.android.support:appcompat-v7:24.2.0' | ||
compile 'com.android.support:design:24.2.0' | ||
testCompile 'junit:junit:4.12' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
app/src/main/java/com/aspsine/fragmentnavigator/demo/Action.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.aspsine.fragmentnavigator.demo; | ||
|
||
/** | ||
* Created by aspsine on 16/9/3. | ||
*/ | ||
|
||
public class Action { | ||
public static final String LOGIN = Action.class.getName() + ".LOGIN"; | ||
public static final String LOGOUT = Action.class.getName() + ".LOGOUT"; | ||
} |
66 changes: 0 additions & 66 deletions
66
app/src/main/java/com/aspsine/fragmentnavigator/demo/MainActivity.java
This file was deleted.
Oops, something went wrong.
40 changes: 40 additions & 0 deletions
40
app/src/main/java/com/aspsine/fragmentnavigator/demo/broadcast/BroadcastManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.aspsine.fragmentnavigator.demo.broadcast; | ||
|
||
import android.content.BroadcastReceiver; | ||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.content.IntentFilter; | ||
import android.support.v4.content.LocalBroadcastManager; | ||
|
||
import com.aspsine.fragmentnavigator.demo.Action; | ||
|
||
/** | ||
* Created by aspsine on 16/9/3. | ||
*/ | ||
|
||
public class BroadcastManager { | ||
|
||
public static void register(Context context, BroadcastReceiver receiver, String... actions){ | ||
IntentFilter filter = new IntentFilter(); | ||
for (String action: actions){ | ||
filter.addAction(action); | ||
} | ||
LocalBroadcastManager.getInstance(context).registerReceiver(receiver, filter); | ||
} | ||
|
||
public static void unregister(Context context, BroadcastReceiver receiver){ | ||
LocalBroadcastManager.getInstance(context).unregisterReceiver(receiver); | ||
} | ||
|
||
public static void sendLoginBroadcast(Context context, int position){ | ||
Intent intent = new Intent(Action.LOGIN); | ||
intent.putExtra("EXTRA_POSITION", position); | ||
LocalBroadcastManager.getInstance(context).sendBroadcast(intent); | ||
} | ||
|
||
public static void sendLogoutBroadcast(Context context, int position){ | ||
Intent intent = new Intent(Action.LOGOUT); | ||
intent.putExtra("EXTRA_POSITION", position); | ||
LocalBroadcastManager.getInstance(context).sendBroadcast(intent); | ||
} | ||
} |
4 changes: 3 additions & 1 deletion
4
...mentnavigator/demo/ExceptionActivity.java → ...r/demo/ui/activity/ExceptionActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
app/src/main/java/com/aspsine/fragmentnavigator/demo/ui/activity/LoginActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package com.aspsine.fragmentnavigator.demo.ui.activity; | ||
|
||
import android.os.Bundle; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.text.TextUtils; | ||
import android.view.View; | ||
import android.widget.Button; | ||
import android.widget.EditText; | ||
|
||
import com.aspsine.fragmentnavigator.demo.R; | ||
import com.aspsine.fragmentnavigator.demo.broadcast.BroadcastManager; | ||
import com.aspsine.fragmentnavigator.demo.utils.SharedPrefUtils; | ||
|
||
public class LoginActivity extends AppCompatActivity implements View.OnClickListener{ | ||
|
||
private EditText etEmail; | ||
private EditText etPassword; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_login); | ||
etEmail = (EditText) findViewById(R.id.et_email); | ||
etPassword = (EditText)findViewById(R.id.et_password); | ||
Button button = (Button) findViewById(R.id.login_in_button); | ||
button.setOnClickListener(this); | ||
} | ||
|
||
@Override | ||
public void onClick(View v) { | ||
if (v.getId() == R.id.login_in_button){ | ||
tryLogin(); | ||
} | ||
} | ||
|
||
void tryLogin(){ | ||
String email = String.valueOf(etEmail.getText()).trim(); | ||
String password = String.valueOf(etPassword.getText()).trim(); | ||
|
||
if(check(email, password)){ | ||
markUserLogin(); | ||
notifyUserLogin(); | ||
finish(); | ||
} | ||
} | ||
|
||
boolean check(String email, String password){ | ||
if (TextUtils.isEmpty(email)){ | ||
etEmail.setError(getString(R.string.error_invalid_email)); | ||
return false; | ||
} | ||
if (TextUtils.isEmpty(password)){ | ||
etPassword.setError(getString(R.string.error_invalid_password)); | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
private void markUserLogin(){ | ||
SharedPrefUtils.login(this); | ||
} | ||
|
||
private void notifyUserLogin(){ | ||
BroadcastManager.sendLoginBroadcast(this, 1); | ||
} | ||
} | ||
|
Oops, something went wrong.