-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
301 additions
and
50 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
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
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
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
15 changes: 15 additions & 0 deletions
15
app/src/main/java/com/github/weiss/example/entity/UserModel.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,15 @@ | ||
package com.github.weiss.example.entity; | ||
|
||
/** | ||
* author weiss | ||
* email [email protected] | ||
* created 2018/1/30. | ||
*/ | ||
public class UserModel { | ||
|
||
public int id; | ||
|
||
public UserModel(int id) { | ||
this.id = id; | ||
} | ||
} |
128 changes: 128 additions & 0 deletions
128
app/src/main/java/com/github/weiss/example/ui/EasyPermissionsActivity.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,128 @@ | ||
package com.github.weiss.example.ui; | ||
|
||
import android.Manifest; | ||
import android.content.Intent; | ||
import android.os.Bundle; | ||
import android.support.annotation.NonNull; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.util.Log; | ||
|
||
import com.github.weiss.example.BaseActivity; | ||
|
||
import java.util.List; | ||
|
||
import pub.devrel.easypermissions.AfterPermissionGranted; | ||
import pub.devrel.easypermissions.AppSettingsDialog; | ||
import pub.devrel.easypermissions.EasyPermissions; | ||
|
||
public abstract class EasyPermissionsActivity extends BaseActivity implements EasyPermissions.PermissionCallbacks, | ||
EasyPermissions.RationaleCallbacks { | ||
|
||
private static final String TAG = "EasyPermissionsActivity"; | ||
private static final String[] PERMISSION = { | ||
Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.CAMERA | ||
}; | ||
|
||
private static final int RC_PERM = 124; | ||
private boolean isFirst = false; | ||
|
||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
isFirst = true; | ||
} | ||
|
||
@Override | ||
protected void onResume() { | ||
super.onResume(); | ||
if (isFirst) { | ||
//因为要通过一个Fragment来弹出弹出框,所以activity这里的onResume执行了两次,这里进行判断 | ||
isFirst = false; | ||
permissionsTask(); | ||
|
||
} | ||
} | ||
|
||
private boolean hasPermissions() { | ||
return EasyPermissions.hasPermissions(this, PERMISSION); | ||
} | ||
|
||
private boolean hasStoragePermission() { | ||
return EasyPermissions.hasPermissions(this, Manifest.permission.WRITE_EXTERNAL_STORAGE); | ||
} | ||
|
||
|
||
@AfterPermissionGranted(RC_PERM) | ||
public void permissionsTask() { | ||
if (hasPermissions()) { | ||
startMainActivity(); | ||
// Have permissions, do the thing! | ||
} else { | ||
// Ask for both permissions | ||
EasyPermissions.requestPermissions( | ||
this, | ||
"需要获取以下权限,才能正常使用APP", | ||
RC_PERM, | ||
PERMISSION); | ||
} | ||
} | ||
|
||
public abstract void startMainActivity(); | ||
|
||
@Override | ||
public void onRequestPermissionsResult(int requestCode, | ||
@NonNull String[] permissions, | ||
@NonNull int[] grantResults) { | ||
super.onRequestPermissionsResult(requestCode, permissions, grantResults); | ||
|
||
// EasyPermissions handles the request result. | ||
EasyPermissions.onRequestPermissionsResult(requestCode, permissions, grantResults, this); | ||
} | ||
|
||
//接受的权限List | ||
@Override | ||
public void onPermissionsGranted(int requestCode, @NonNull List<String> perms) { | ||
Log.d(TAG, "onPermissionsGranted:" + requestCode + ":" + perms.size()); | ||
} | ||
|
||
//拒绝的权限List | ||
@Override | ||
public void onPermissionsDenied(int requestCode, @NonNull List<String> perms) { | ||
Log.d(TAG, "onPermissionsDenied:" + requestCode + ":" + perms.size()); | ||
// (Optional) Check whether the user denied any permissions and checked "NEVER ASK AGAIN." | ||
// This will display a dialog directing them to enable the permission in app settings. | ||
if (EasyPermissions.somePermissionPermanentlyDenied(this, perms)) { | ||
//这个方法有个前提是,用户点击了“不再询问”后,才判断权限没有被获取到 | ||
new AppSettingsDialog.Builder(this) | ||
.setRationale("没有该权限,此应用程序可能无法正常工作。打开应用设置界面以修改应用权限") | ||
.setTitle("必需权限") | ||
.build() | ||
.show(); | ||
isFirst = true; | ||
} else if (!hasPermissions()) { | ||
//这里响应的是除了AppSettingsDialog这个弹出框,剩下的两个弹出框被拒绝或者取消的效果 | ||
finish(); | ||
} | ||
} | ||
|
||
@Override | ||
public void onActivityResult(int requestCode, int resultCode, Intent data) { | ||
super.onActivityResult(requestCode, resultCode, data); | ||
if (requestCode == AppSettingsDialog.DEFAULT_SETTINGS_REQ_CODE) { | ||
if (!hasPermissions()) { | ||
finish(); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public void onRationaleAccepted(int requestCode) { | ||
Log.d(TAG, "onRationaleAccepted:" + requestCode); | ||
} | ||
|
||
@Override | ||
public void onRationaleDenied(int requestCode) { | ||
Log.d(TAG, "onRationaleDenied:" + requestCode); | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
app/src/main/java/com/github/weiss/example/ui/SplashActivity.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,57 @@ | ||
package com.github.weiss.example.ui; | ||
|
||
import android.content.Intent; | ||
import android.os.Handler; | ||
import android.os.Message; | ||
|
||
import com.flyco.systembar.SystemBarHelper; | ||
import com.github.weiss.example.BaseActivity; | ||
import com.github.weiss.example.R; | ||
|
||
/** | ||
* author weiss | ||
* email [email protected] | ||
* created 2017/12/15. | ||
*/ | ||
public class SplashActivity extends EasyPermissionsActivity { | ||
|
||
@Override | ||
protected int getLayoutId() { | ||
//隐藏标题栏以及状态栏 | ||
/* getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, | ||
WindowManager.LayoutParams.FLAG_FULLSCREEN); | ||
*//**标题是属于View的,所以窗口所有的修饰部分被隐藏后标题依然有效,需要去掉标题**//* | ||
requestWindowFeature(Window.FEATURE_NO_TITLE);*/ | ||
return R.layout.activity_splash; | ||
} | ||
|
||
@Override | ||
protected void initView() { | ||
SystemBarHelper.immersiveStatusBar(this); | ||
} | ||
|
||
@Override | ||
protected void onDestroy() { | ||
handler.removeMessages(0); | ||
super.onDestroy(); | ||
} | ||
|
||
private Handler handler = new Handler() { | ||
@Override | ||
public void handleMessage(Message msg) { | ||
getHome(); | ||
super.handleMessage(msg); | ||
} | ||
}; | ||
|
||
public void getHome() { | ||
Intent intent = new Intent(SplashActivity.this, MainActivity.class); | ||
startActivity(intent); | ||
finish(); | ||
} | ||
|
||
@Override | ||
public void startMainActivity() { | ||
handler.sendEmptyMessageDelayed(0, 1500); | ||
} | ||
} |
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,30 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<android.support.design.widget.CoordinatorLayout | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
<!-- | ||
<android.support.design.widget.AppBarLayout | ||
android:id="@+id/app_bar_layout" | ||
android:layout_height="wrap_content" | ||
android:layout_width="match_parent" | ||
android:theme="@style/AppTheme.AppBarOverlay"> | ||
<android.support.v7.widget.Toolbar | ||
android:id="@+id/toolbar" | ||
android:layout_width="match_parent" | ||
android:layout_height="?attr/actionBarSize" | ||
android:background="?attr/colorPrimary" | ||
app:popupTheme="@style/AppTheme.PopupOverlay" /> | ||
</android.support.design.widget.AppBarLayout> | ||
<uk.co.senab.photoview.PhotoView | ||
android:id="@+id/picture" | ||
android:layout_centerInParent="true" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"/>--> | ||
|
||
</android.support.design.widget.CoordinatorLayout> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Oops, something went wrong.