Browse Source

show battery optimiz. menu item added; translated all battery stuff into Russian

pull/1409/head
kote 5 years ago
parent
commit
80f632c19a
  1. 25
      android/res/menu/options_main.xml
  2. 7
      android/res/values-ru/strings.xml
  3. 10
      android/res/values/strings.xml
  4. 26
      android/src/org/purplei2p/i2pd/I2PDActivity.java

25
android/res/menu/options_main.xml

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

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

@ -17,4 +17,11 @@
<string name="remaining">осталось</string> <string name="remaining">осталось</string>
<string name="title_activity_i2_pdperms_asker_prompt">Запрос</string> <string name="title_activity_i2_pdperms_asker_prompt">Запрос</string>
<string name="permDenied">Права для записи на SD карту отклонены, вам необходимо предоставить их для продолжения</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> </resources>

10
android/res/values/strings.xml

@ -18,8 +18,10 @@
<string name="title_activity_i2_pdperms_asker_prompt">Prompt</string> <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="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">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_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 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="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="next">Next</string> <string name="continue_str">Continue</string>
<string name="device_does_not_support_disabling_battery_optimizations">Your device does not support opting out of battery optimizations</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> </resources>

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

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

Loading…
Cancel
Save