@ -0,0 +1,99 @@ |
|||||
|
package com.jiangdg.usbcamera.view; |
||||
|
|
||||
|
import android.Manifest; |
||||
|
import android.content.Intent; |
||||
|
import android.content.pm.PackageManager; |
||||
|
import android.os.Build; |
||||
|
import android.os.Bundle; |
||||
|
import android.os.Handler; |
||||
|
import android.support.annotation.NonNull; |
||||
|
import android.support.v4.app.ActivityCompat; |
||||
|
import android.support.v4.content.ContextCompat; |
||||
|
import android.support.v7.app.AppCompatActivity; |
||||
|
import android.view.WindowManager; |
||||
|
import android.widget.Toast; |
||||
|
|
||||
|
import com.jiangdg.usbcamera.R; |
||||
|
|
||||
|
import java.util.ArrayList; |
||||
|
import java.util.List; |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* permission checking |
||||
|
* Created by jiangdongguo on 2019/6/27. |
||||
|
*/ |
||||
|
|
||||
|
public class SplashActivity extends AppCompatActivity { |
||||
|
private static final String[] REQUIRED_PERMISSION_LIST = new String[]{ |
||||
|
Manifest.permission.WRITE_EXTERNAL_STORAGE, |
||||
|
Manifest.permission.RECORD_AUDIO, |
||||
|
}; |
||||
|
private static final int REQUEST_CODE = 1; |
||||
|
private List<String> mMissPermissions = new ArrayList<>(); |
||||
|
|
||||
|
@Override |
||||
|
protected void onCreate(Bundle savedInstanceState) { |
||||
|
super.onCreate(savedInstanceState); |
||||
|
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); |
||||
|
setContentView(R.layout.activity_splash); |
||||
|
|
||||
|
if (isVersionM()) { |
||||
|
checkAndRequestPermissions(); |
||||
|
} else { |
||||
|
startMainActivity(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
private boolean isVersionM() { |
||||
|
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP; |
||||
|
} |
||||
|
|
||||
|
private void checkAndRequestPermissions() { |
||||
|
mMissPermissions.clear(); |
||||
|
for (String permission : REQUIRED_PERMISSION_LIST) { |
||||
|
int result = ContextCompat.checkSelfPermission(this, permission); |
||||
|
if (result != PackageManager.PERMISSION_GRANTED) { |
||||
|
mMissPermissions.add(permission); |
||||
|
} |
||||
|
} |
||||
|
// check permissions has granted
|
||||
|
if (mMissPermissions.isEmpty()) { |
||||
|
startMainActivity(); |
||||
|
} else { |
||||
|
ActivityCompat.requestPermissions(this, |
||||
|
mMissPermissions.toArray(new String[mMissPermissions.size()]), |
||||
|
REQUEST_CODE); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void onRequestPermissionsResult(final int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { |
||||
|
super.onRequestPermissionsResult(requestCode, permissions, grantResults); |
||||
|
if (requestCode == REQUEST_CODE) { |
||||
|
for (int i = grantResults.length - 1; i >= 0; i--) { |
||||
|
if (grantResults[i] == PackageManager.PERMISSION_GRANTED) { |
||||
|
mMissPermissions.remove(permissions[i]); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
// Get permissions success or not
|
||||
|
if (mMissPermissions.isEmpty()) { |
||||
|
startMainActivity(); |
||||
|
} else { |
||||
|
Toast.makeText(SplashActivity.this, "get permissions failed,exiting...",Toast.LENGTH_SHORT).show(); |
||||
|
SplashActivity.this.finish(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
private void startMainActivity() { |
||||
|
new Handler().postDelayed(new Runnable() { |
||||
|
@Override |
||||
|
public void run() { |
||||
|
startActivity(new Intent(SplashActivity.this, USBCameraActivity.class)); |
||||
|
SplashActivity.this.finish(); |
||||
|
} |
||||
|
}, 3000); |
||||
|
} |
||||
|
} |
||||
|
|
@ -0,0 +1,38 @@ |
|||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" |
||||
|
android:orientation="vertical" android:layout_width="match_parent" |
||||
|
android:layout_height="match_parent"> |
||||
|
|
||||
|
<TextView |
||||
|
android:layout_width="410dp" |
||||
|
android:layout_height="0dp" |
||||
|
android:layout_weight="1" |
||||
|
android:gravity="center_horizontal|center_vertical" |
||||
|
android:text="Welcome to use!" |
||||
|
android:textSize="28sp" |
||||
|
android:textStyle="bold" /> |
||||
|
<TextView |
||||
|
android:layout_width="wrap_content" |
||||
|
android:layout_height="wrap_content" |
||||
|
android:layout_gravity="center_horizontal|center_vertical" |
||||
|
android:textSize="14sp" |
||||
|
android:textStyle="italic" |
||||
|
android:text="Author: jiangdongguo"/> |
||||
|
<TextView |
||||
|
android:layout_width="wrap_content" |
||||
|
android:layout_height="wrap_content" |
||||
|
android:layout_gravity="center_horizontal|center_vertical" |
||||
|
android:layout_marginTop="5dp" |
||||
|
android:textStyle="italic" |
||||
|
android:textSize="14sp" |
||||
|
android:text="Email:765067602@qq.com"/> |
||||
|
<TextView |
||||
|
android:layout_width="match_parent" |
||||
|
android:layout_height="0dp" |
||||
|
android:text="last modify 2019.6" |
||||
|
android:textSize="16sp" |
||||
|
android:textStyle="bold" |
||||
|
android:gravity="bottom|center_horizontal" |
||||
|
android:paddingBottom="20dp" |
||||
|
android:layout_weight="1"/> |
||||
|
</LinearLayout> |
Before Width: | Height: | Size: 3.3 KiB After Width: | Height: | Size: 43 KiB |
Before Width: | Height: | Size: 2.2 KiB After Width: | Height: | Size: 43 KiB |
Before Width: | Height: | Size: 4.7 KiB After Width: | Height: | Size: 43 KiB |
Before Width: | Height: | Size: 7.5 KiB After Width: | Height: | Size: 43 KiB |
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 43 KiB |
@ -1,3 +1,3 @@ |
|||||
<resources> |
<resources> |
||||
<string name="app_name">UVCCamera</string> |
<string name="app_name">AndroidUSBCamera</string> |
||||
</resources> |
</resources> |
||||
|