mirror of https://github.com/PurpleI2P/i2pd.git
orignal
7 years ago
committed by
GitHub
6 changed files with 9 additions and 190 deletions
@ -1,27 +0,0 @@ |
|||||||
<LinearLayout android:id="@+id/main_layout" |
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android" |
|
||||||
xmlns:tools="http://schemas.android.com/tools" |
|
||||||
android:layout_width="match_parent" |
|
||||||
android:layout_height="match_parent" |
|
||||||
android:orientation="vertical" |
|
||||||
android:paddingBottom="@dimen/vertical_page_margin" |
|
||||||
android:paddingLeft="@dimen/horizontal_page_margin" |
|
||||||
android:paddingRight="@dimen/horizontal_page_margin" |
|
||||||
android:paddingTop="@dimen/vertical_page_margin" |
|
||||||
tools:context=".I2PDPermsAskerActivity"> |
|
||||||
|
|
||||||
<TextView |
|
||||||
android:id="@+id/textview_retry" |
|
||||||
android:layout_width="wrap_content" |
|
||||||
android:layout_height="wrap_content" |
|
||||||
android:layout_marginBottom="@dimen/horizontal_page_margin" |
|
||||||
android:visibility="gone" |
|
||||||
/> |
|
||||||
|
|
||||||
<Button |
|
||||||
android:id="@+id/button_request_write_ext_storage_perms" |
|
||||||
android:layout_width="wrap_content" |
|
||||||
android:layout_height="wrap_content" |
|
||||||
android:text="Retry requesting the SD card write permissions" |
|
||||||
android:visibility="gone"/> |
|
||||||
</LinearLayout> |
|
@ -1,16 +0,0 @@ |
|||||||
<resources> |
|
||||||
|
|
||||||
<!-- Define standard dimensions to comply with Holo-style grids and rhythm. --> |
|
||||||
|
|
||||||
<dimen name="margin_tiny">4dp</dimen> |
|
||||||
<dimen name="margin_small">8dp</dimen> |
|
||||||
<dimen name="margin_medium">16dp</dimen> |
|
||||||
<dimen name="margin_large">32dp</dimen> |
|
||||||
<dimen name="margin_huge">64dp</dimen> |
|
||||||
|
|
||||||
<!-- Semantic definitions --> |
|
||||||
|
|
||||||
<dimen name="horizontal_page_margin">@dimen/margin_medium</dimen> |
|
||||||
<dimen name="vertical_page_margin">@dimen/margin_medium</dimen> |
|
||||||
|
|
||||||
</resources> |
|
@ -1,121 +0,0 @@ |
|||||||
package org.purplei2p.i2pd; |
|
||||||
|
|
||||||
import android.Manifest; |
|
||||||
import android.app.Activity; |
|
||||||
import android.content.Intent; |
|
||||||
import android.content.pm.PackageManager; |
|
||||||
import android.os.Bundle; |
|
||||||
import android.support.v4.app.ActivityCompat; |
|
||||||
import android.support.design.widget.Snackbar; |
|
||||||
import android.support.v7.app.AppCompatActivity; |
|
||||||
import android.view.View; |
|
||||||
import android.widget.Button; |
|
||||||
import android.widget.TextView; |
|
||||||
|
|
||||||
//dangerous perms, per https://developer.android.com/guide/topics/permissions/normal-permissions.html :
|
|
||||||
//android.permission.WRITE_EXTERNAL_STORAGE
|
|
||||||
public class I2PDPermsAskerActivity extends AppCompatActivity { |
|
||||||
|
|
||||||
private static final int PERMISSION_WRITE_EXTERNAL_STORAGE = 0; |
|
||||||
|
|
||||||
private View mLayout; |
|
||||||
private Button button_request_write_ext_storage_perms; |
|
||||||
private TextView textview_retry; |
|
||||||
|
|
||||||
@Override |
|
||||||
protected void onCreate(Bundle savedInstanceState) { |
|
||||||
super.onCreate(savedInstanceState); |
|
||||||
|
|
||||||
setContentView(R.layout.activity_perms_asker); |
|
||||||
mLayout = findViewById(R.id.main_layout); |
|
||||||
button_request_write_ext_storage_perms = (Button) findViewById(R.id.button_request_write_ext_storage_perms); |
|
||||||
textview_retry = (TextView) findViewById(R.id.textview_retry); |
|
||||||
|
|
||||||
button_request_write_ext_storage_perms.setOnClickListener(new View.OnClickListener() { |
|
||||||
@Override |
|
||||||
public void onClick(View view) { |
|
||||||
request_write_ext_storage_perms(); |
|
||||||
} |
|
||||||
}); |
|
||||||
request_write_ext_storage_perms(); |
|
||||||
} |
|
||||||
|
|
||||||
private void request_write_ext_storage_perms() { |
|
||||||
|
|
||||||
textview_retry.setVisibility(TextView.GONE); |
|
||||||
button_request_write_ext_storage_perms.setVisibility(Button.GONE); |
|
||||||
|
|
||||||
// Here, thisActivity is the current activity
|
|
||||||
if (ActivityCompat.checkSelfPermission(this, |
|
||||||
Manifest.permission.WRITE_EXTERNAL_STORAGE) |
|
||||||
!= PackageManager.PERMISSION_GRANTED) { |
|
||||||
|
|
||||||
// Should we show an explanation?
|
|
||||||
if (ActivityCompat.shouldShowRequestPermissionRationale(this, |
|
||||||
Manifest.permission.WRITE_EXTERNAL_STORAGE)) { |
|
||||||
|
|
||||||
// Show an explanation to the user *asynchronously* -- don't block
|
|
||||||
// this thread waiting for the user's response! After the user
|
|
||||||
// sees the explanation, try again to request the permission.
|
|
||||||
|
|
||||||
Snackbar.make(mLayout, "SD card write access is required to write the keys and other files to the I2PD folder on SD card.", |
|
||||||
Snackbar.LENGTH_INDEFINITE).setAction("OK", new View.OnClickListener() { |
|
||||||
@Override |
|
||||||
public void onClick(View view) { |
|
||||||
// Request the permission
|
|
||||||
ActivityCompat.requestPermissions(I2PDPermsAskerActivity.this, |
|
||||||
new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, |
|
||||||
PERMISSION_WRITE_EXTERNAL_STORAGE); |
|
||||||
} |
|
||||||
}).show(); |
|
||||||
|
|
||||||
} else { |
|
||||||
|
|
||||||
// No explanation needed, we can request the permission.
|
|
||||||
|
|
||||||
ActivityCompat.requestPermissions(this, |
|
||||||
new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, |
|
||||||
PERMISSION_WRITE_EXTERNAL_STORAGE); |
|
||||||
|
|
||||||
// MY_PERMISSIONS_REQUEST_READ_CONTACTS is an
|
|
||||||
// app-defined int constant. The callback method gets the
|
|
||||||
// result of the request.
|
|
||||||
} |
|
||||||
} else startMainActivity(); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void onRequestPermissionsResult(int requestCode, |
|
||||||
String permissions[], int[] grantResults) { |
|
||||||
switch (requestCode) { |
|
||||||
case PERMISSION_WRITE_EXTERNAL_STORAGE: { |
|
||||||
// If request is cancelled, the result arrays are empty.
|
|
||||||
if (grantResults.length > 0 |
|
||||||
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) { |
|
||||||
|
|
||||||
// permission was granted, yay! Do the
|
|
||||||
// contacts-related task you need to do.
|
|
||||||
|
|
||||||
startMainActivity(); |
|
||||||
|
|
||||||
} else { |
|
||||||
|
|
||||||
// permission denied, boo! Disable the
|
|
||||||
// functionality that depends on this permission.
|
|
||||||
textview_retry.setText("SD card write permission denied, you need to allow this to continue"); |
|
||||||
textview_retry.setVisibility(TextView.VISIBLE); |
|
||||||
button_request_write_ext_storage_perms.setVisibility(Button.VISIBLE); |
|
||||||
} |
|
||||||
return; |
|
||||||
} |
|
||||||
|
|
||||||
// other 'case' lines to check for other
|
|
||||||
// permissions this app might request.
|
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
private void startMainActivity() { |
|
||||||
startActivity(new Intent(this, I2PDActivity.class)); |
|
||||||
finish(); |
|
||||||
} |
|
||||||
} |
|
Loading…
Reference in new issue