Browse Source

Merge pull request #1409 from nonlinear-chaos-order-etc/openssl

android - show battery optimiz. os dialog menu item added; translated all battery stuff into Russian
pull/1410/head
orignal 5 years ago committed by GitHub
parent
commit
ab3a4d902e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      android/.gitignore
  2. 25
      android/res/menu/options_main.xml
  3. 7
      android/res/values-ru/strings.xml
  4. 10
      android/res/values/strings.xml
  5. 26
      android/src/org/purplei2p/i2pd/I2PDActivity.java

1
android/.gitignore vendored

@ -13,3 +13,4 @@ build.sh @@ -13,3 +13,4 @@ build.sh
android.iml
build
*.iml
*.local

25
android/res/menu/options_main.xml

@ -3,14 +3,19 @@ @@ -3,14 +3,19 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".I2PDActivity">
<item
android:id="@+id/action_graceful_stop"
android:title="@string/action_graceful_stop"
android:orderInCategory="98"
/>
<item
android:id="@+id/action_stop"
android:title="@string/action_stop"
android:orderInCategory="99"
/>
<group android:id="@+id/group_i2pd_control" >
<item
android:id="@+id/action_stop"
android:orderInCategory="99"
android:title="@string/action_stop" />
<item
android:id="@+id/action_graceful_stop"
android:orderInCategory="98"
android:title="@string/action_graceful_stop" />
</group>
<group android:id="@+id/group_various" >
<item
android:id="@+id/action_battery_otimizations"
android:title="@string/menu_item_battery_optimizations_str" />
</group>
</menu>

7
android/res/values-ru/strings.xml

@ -17,4 +17,11 @@ @@ -17,4 +17,11 @@
<string name="remaining">осталось</string>
<string name="title_activity_i2_pdperms_asker_prompt">Запрос</string>
<string name="permDenied">Права для записи на SD карту отклонены, вам необходимо предоставить их для продолжения</string>
<string name="menu_item_battery_optimizations_str">Оптимизации аккумулятора</string>
<string name="battery_optimizations_enabled">Оптимизации аккумулятора включены</string>
<string name="device_does_not_support_disabling_battery_optimizations">Ваша версия Андроид не поддерживает отключение оптимизаций аккумулятора</string>
<string name="battery_optimizations_enabled_explained">Ваша операционная система осуществляет оптимизации расхода аккумулятора, которые могут приводить к выгрузке I2PD из памяти и прекращению его работы с целью сэкономить заряд аккумулятора.\nРекомендуется отключить эти оптимизации.</string>
<string name="battery_optimizations_enabled_dialog" >Ваша операционная система осуществляет оптимизации расхода аккумулятора, которые могут приводить к выгрузке I2PD из памяти и прекращению его работы с целью сэкономить заряд аккумулятора.\n\nВам сейчас будет предложено разрешить отключение этих оптимизаций.</string>
<string name="continue_str">Продолжить</string>
<string name="os_version_does_not_support_battery_optimizations_show_os_dialog_api">Ваша версия Андроид не поддерживает показ диалога об оптимизациях аккумулятора для приложений.</string>
</resources>

10
android/res/values/strings.xml

@ -18,8 +18,10 @@ @@ -18,8 +18,10 @@
<string name="title_activity_i2_pdperms_asker_prompt">Prompt</string>
<string name="permDenied">SD card write permission denied, you need to allow this to continue</string>
<string name="battery_optimizations_enabled">Battery optimizations enabled</string>
<string name="battery_optimizations_enabled_explained">Your device is doing some heavy battery optimizations on I2PD that might lead to daemon closing with no other reason.\nIt is recommended to disable those battery optimizations.</string>
<string name="battery_optimizations_enabled_dialog">Your device is doing some heavy battery optimizations on I2PD that might lead to daemon closing with no other reason.\n\nYou will now be asked to disable those.</string>
<string name="next">Next</string>
<string name="device_does_not_support_disabling_battery_optimizations">Your device does not support opting out of battery optimizations</string>
<string name="battery_optimizations_enabled_explained">Your Android is doing some heavy battery optimizations on I2PD that might lead to daemon closing with no other reason.\nIt is recommended to allow disabling those battery optimizations.</string>
<string name="battery_optimizations_enabled_dialog" >Your Android is doing some heavy battery optimizations on I2PD that might lead to daemon closing with no other reason.\n\nYou will now be asked to allow to disable those.</string>
<string name="continue_str">Continue</string>
<string name="device_does_not_support_disabling_battery_optimizations">Your Android version does not support opting out of battery optimizations</string>
<string name="menu_item_battery_optimizations_str">Battery Optimizations</string>
<string name="os_version_does_not_support_battery_optimizations_show_os_dialog_api">Your Android OS version does not support showing the dialog for battery optimizations for applications.</string>
</resources>

26
android/src/org/purplei2p/i2pd/I2PDActivity.java

@ -46,6 +46,8 @@ import androidx.core.content.ContextCompat; @@ -46,6 +46,8 @@ import androidx.core.content.ContextCompat;
// For future package update checking
import org.purplei2p.i2pd.BuildConfig;
import static android.provider.Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS;
public class I2PDActivity extends Activity {
private static final String TAG = "i2pdActvt";
private static final int MY_PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE = 1;
@ -229,9 +231,14 @@ public class I2PDActivity extends Activity { @@ -229,9 +231,14 @@ public class I2PDActivity extends Activity {
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.options_main, menu);
menu.findItem(R.id.action_battery_otimizations).setVisible(isBatteryOptimizationsOpenOsDialogApiAvailable());
return true;
}
private boolean isBatteryOptimizationsOpenOsDialogApiAvailable() {
return android.os.Build.VERSION.SDK_INT >= 23;
}
@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
// Handle action bar item clicks here. The action bar will
@ -254,12 +261,26 @@ public class I2PDActivity extends Activity { @@ -254,12 +261,26 @@ public class I2PDActivity extends Activity {
item.setTitle(R.string.action_cancel_graceful_stop);
i2pdGracefulStop();
}
return true;
return true;
case R.id.action_battery_otimizations:
onActionBatteryOptimizations();
return true;
}
return super.onOptionsItemSelected(item);
}
private void onActionBatteryOptimizations() {
if (isBatteryOptimizationsOpenOsDialogApiAvailable()) {
try {
startActivity(new Intent(ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS));
} catch (ActivityNotFoundException e) {
Log.e(TAG,"BATT_OPTIM_DIALOG_ActvtNotFound", e);
Toast.makeText(this, R.string.os_version_does_not_support_battery_optimizations_show_os_dialog_api, Toast.LENGTH_SHORT).show();
}
}
}
private void i2pdStop() {
cancelGracefulStop();
new Thread(() -> {
@ -389,6 +410,7 @@ public class I2PDActivity extends Activity { @@ -389,6 +410,7 @@ public class I2PDActivity extends Activity {
copyAsset(path + "/" + entry);
}
} catch (IOException e) {
Log.e(TAG,"ex ignored", e);
copyFileAsset(path);
}
}
@ -518,7 +540,7 @@ public class I2PDActivity extends Activity { @@ -518,7 +540,7 @@ public class I2PDActivity extends Activity {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.battery_optimizations_enabled);
builder.setMessage(R.string.battery_optimizations_enabled_dialog);
builder.setPositiveButton(R.string.next, (dialog, which) -> {
builder.setPositiveButton(R.string.continue_str, (dialog, which) -> {
try {
startActivity(new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS, Uri.parse(PACKAGE_URI_SCHEME + getPackageName())));
} catch (ActivityNotFoundException e) {

Loading…
Cancel
Save