Repository: YarikSOffice/LanguageTest
Branch: master
Commit: db5b3742bfcc
Files: 39
Total size: 48.6 KB
Directory structure:
gitextract_f07za5s_/
├── .gitignore
├── LICENSE
├── README.md
├── app/
│ ├── .gitignore
│ ├── build.gradle
│ ├── proguard-rules.pro
│ └── src/
│ └── main/
│ ├── AndroidManifest.xml
│ ├── java/
│ │ └── com/
│ │ └── yariksoffice/
│ │ └── languagetest/
│ │ ├── App.java
│ │ ├── LocaleManager.java
│ │ ├── TestService.java
│ │ ├── Utility.java
│ │ ├── WebViewLocaleHelper.java
│ │ └── ui/
│ │ ├── BaseActivity.java
│ │ ├── MainActivity.java
│ │ ├── SettingsActivity.java
│ │ ├── TestActivity1.java
│ │ ├── TestActivity2.java
│ │ └── WebViewActivity.java
│ └── res/
│ ├── drawable/
│ │ ├── language_en.xml
│ │ ├── language_ru.xml
│ │ └── language_uk.xml
│ ├── layout/
│ │ ├── locale_info.xml
│ │ ├── main_activity.xml
│ │ ├── settings_activity.xml
│ │ ├── test_activity_1.xml
│ │ ├── test_activity_2.xml
│ │ └── web_view_activity.xml
│ ├── values/
│ │ ├── colors.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ ├── values-ru/
│ │ └── strings.xml
│ └── values-uk/
│ └── strings.xml
├── build.gradle
├── gradle/
│ └── wrapper/
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradle.properties
├── gradlew
├── gradlew.bat
└── settings.gradle
================================================
FILE CONTENTS
================================================
================================================
FILE: .gitignore
================================================
*.iml
.gradle
/local.properties
/.idea*
.DS_Store
/build
/captures
.externalNativeBuild
================================================
FILE: LICENSE
================================================
MIT License
Copyright (c) 2017 Yaroslav Berezanskyi
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
================================================
FILE: README.md
================================================
# Changing the Language in Android Apps
The repository contains 2 approaches for changing a locale in android apps.
`ignore_deprecation` branch is more easier and flexible approach despite using some deprecated API.
Article on Medium:
https://proandroiddev.com/change-language-programmatically-at-runtime-on-android-5e6bc15c758
================================================
FILE: app/.gitignore
================================================
/build
================================================
FILE: app/build.gradle
================================================
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
buildToolsVersion "28.0.3"
defaultConfig {
applicationId "com.yariksoffice.languagetest"
minSdkVersion 15
targetSdkVersion 28
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
incremental true
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
}
================================================
FILE: app/proguard-rules.pro
================================================
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /Users/yari/Library/Android/sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
================================================
FILE: app/src/main/AndroidManifest.xml
================================================
================================================
FILE: app/src/main/java/com/yariksoffice/languagetest/App.java
================================================
package com.yariksoffice.languagetest;
import android.app.Application;
import android.content.Context;
import android.content.res.Configuration;
import android.util.Log;
public class App extends Application {
public static final String TAG = "App";
// for the sake of simplicity. use DI in real apps instead
public static LocaleManager localeManager;
@Override
public void onCreate() {
super.onCreate();
Utility.bypassHiddenApiRestrictions();
}
@Override
protected void attachBaseContext(Context base) {
localeManager = new LocaleManager(base);
super.attachBaseContext(localeManager.setLocale(base));
Log.d(TAG, "attachBaseContext");
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
localeManager.setLocale(this);
Log.d(TAG, "onConfigurationChanged: " + newConfig.locale.getLanguage());
}
}
================================================
FILE: app/src/main/java/com/yariksoffice/languagetest/LocaleManager.java
================================================
package com.yariksoffice.languagetest;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Build;
import android.os.LocaleList;
import android.preference.PreferenceManager;
import java.util.LinkedHashSet;
import java.util.Locale;
import java.util.Set;
import androidx.annotation.RequiresApi;
import static android.os.Build.VERSION_CODES.JELLY_BEAN_MR1;
import static android.os.Build.VERSION_CODES.N;
public class LocaleManager {
public static final String LANGUAGE_ENGLISH = "en";
public static final String LANGUAGE_UKRAINIAN = "uk";
public static final String LANGUAGE_RUSSIAN = "ru";
private static final String LANGUAGE_KEY = "language_key";
private final SharedPreferences prefs;
public LocaleManager(Context context) {
prefs = PreferenceManager.getDefaultSharedPreferences(context);
}
public Context setLocale(Context c) {
return updateResources(c, getLanguage());
}
public Context setNewLocale(Context c, String language) {
persistLanguage(language);
return updateResources(c, language);
}
public String getLanguage() {
return prefs.getString(LANGUAGE_KEY, LANGUAGE_ENGLISH);
}
@SuppressLint("ApplySharedPref")
private void persistLanguage(String language) {
// use commit() instead of apply(), because sometimes we kill the application process
// immediately that prevents apply() from finishing
prefs.edit().putString(LANGUAGE_KEY, language).commit();
}
private Context updateResources(Context context, String language) {
Locale locale = new Locale(language);
Locale.setDefault(locale);
Resources res = context.getResources();
Configuration config = new Configuration(res.getConfiguration());
if (Utility.isAtLeastVersion(N)) {
setLocaleForApi24(config, locale);
context = context.createConfigurationContext(config);
} else if (Utility.isAtLeastVersion(JELLY_BEAN_MR1)) {
config.setLocale(locale);
context = context.createConfigurationContext(config);
} else {
config.locale = locale;
res.updateConfiguration(config, res.getDisplayMetrics());
}
return context;
}
@RequiresApi(api = N)
private void setLocaleForApi24(Configuration config, Locale target) {
Set set = new LinkedHashSet<>();
// bring the target locale to the front of the list
set.add(target);
LocaleList all = LocaleList.getDefault();
for (int i = 0; i < all.size(); i++) {
// append other locales supported by the user
set.add(all.get(i));
}
Locale[] locales = set.toArray(new Locale[0]);
config.setLocales(new LocaleList(locales));
}
public static Locale getLocale(Resources res) {
Configuration config = res.getConfiguration();
return Utility.isAtLeastVersion(N) ? config.getLocales().get(0) : config.locale;
}
}
================================================
FILE: app/src/main/java/com/yariksoffice/languagetest/TestService.java
================================================
package com.yariksoffice.languagetest;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.os.IBinder;
import androidx.annotation.Nullable;
import android.util.Log;
import android.widget.Toast;
import java.util.Locale;
public class TestService extends Service {
private final String TAG = "TestService";
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(App.localeManager.setLocale(base));
Log.d(TAG, "attachBaseContext");
}
@Override
public void onCreate() {
super.onCreate();
Log.d(TAG, "onCreate");
Locale locale = LocaleManager.getLocale(getResources());
String message = locale.getLanguage() + " " + Utility.hexString(getResources());
Toast.makeText(this, message, Toast.LENGTH_LONG).show();
stopSelf();
}
@Nullable
@Override
public IBinder onBind(Intent intent) {
return null;
}
}
================================================
FILE: app/src/main/java/com/yariksoffice/languagetest/Utility.java
================================================
package com.yariksoffice.languagetest;
import android.app.Activity;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.Resources;
import android.os.Build;
import android.util.Log;
import java.lang.ref.WeakReference;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Map;
import java.util.Map.Entry;
import static android.content.pm.PackageManager.GET_META_DATA;
import static android.os.Build.VERSION_CODES.P;
import static com.yariksoffice.languagetest.App.TAG;
public class Utility {
public static String hexString(Resources res) {
Object resImpl = getPrivateField("android.content.res.Resources", "mResourcesImpl", res);
Object o = resImpl != null ? resImpl : res;
return "@" + Integer.toHexString(o.hashCode());
}
public static Object getPrivateField(String className, String fieldName, Object object) {
try {
Class c = Class.forName(className);
Field f = c.getDeclaredField(fieldName);
f.setAccessible(true);
return f.get(object);
} catch (Throwable e) {
e.printStackTrace();
return null;
}
}
public static void bypassHiddenApiRestrictions() {
// http://weishu.me/2019/03/16/another-free-reflection-above-android-p/
if (!isAtLeastVersion(P)) return;
try {
Method forName = Class.class.getDeclaredMethod("forName", String.class);
Method getDeclaredMethod = Class.class.getDeclaredMethod("getDeclaredMethod",
String.class, Class[].class);
Class> vmRuntimeClass = (Class>) forName.invoke(null, "dalvik.system.VMRuntime");
Method getRuntime = (Method) getDeclaredMethod.invoke(vmRuntimeClass, "getRuntime",
null);
Method setHiddenApiExemptions = (Method) getDeclaredMethod.invoke(vmRuntimeClass,
"setHiddenApiExemptions", new Class[]{ String[].class });
Object sVmRuntime = getRuntime.invoke(null);
setHiddenApiExemptions.invoke(sVmRuntime, new Object[]{ new String[]{ "L" } });
} catch (Throwable e) {
Log.e(TAG, "Reflect bootstrap failed:", e);
}
}
public static void resetActivityTitle(Activity a) {
try {
ActivityInfo info = a.getPackageManager().getActivityInfo(a.getComponentName(), GET_META_DATA);
if (info.labelRes != 0) {
a.setTitle(info.labelRes);
}
} catch (NameNotFoundException e) {
e.printStackTrace();
}
}
@SuppressWarnings("unchecked")
public static String getTitleCache() {
try {
Object o = Utility.getPrivateField("android.app.ApplicationPackageManager", "sStringCache", null);
Map, WeakReference> cache = (Map, WeakReference>) o;
if (cache == null) return "";
StringBuilder builder = new StringBuilder("Cache:").append("\n");
for (Entry, WeakReference> e : cache.entrySet()) {
CharSequence title = e.getValue().get();
if (title != null) {
builder.append(title).append("\n");
}
}
return builder.toString();
} catch (Exception e) {
// https://developer.android.com/about/versions/pie/restrictions-non-sdk-interfaces
return "Can't access title cache";
}
}
public static Resources getTopLevelResources(Activity a) {
try {
return a.getPackageManager().getResourcesForApplication(a.getApplicationInfo());
} catch (NameNotFoundException e) {
throw new RuntimeException(e);
}
}
public static boolean isAtLeastVersion(int version) {
return Build.VERSION.SDK_INT >= version;
}
}
================================================
FILE: app/src/main/java/com/yariksoffice/languagetest/WebViewLocaleHelper.java
================================================
package com.yariksoffice.languagetest;
import android.content.Context;
import android.webkit.WebView;
/**
* WebViewLocaleHelper implements a workaround that fixes the unwanted side effect while
* using a WebView introduced in Android N.
*
* For unknown reasons, the very first creation of a WebView (either programmatically
* or via inflation) resets an application locale to the device default.
* More on that: https://issuetracker.google.com/issues/37113860
*/
public class WebViewLocaleHelper {
private boolean requireWorkaround = true;
public void implementWorkaround(Context context) {
if (requireWorkaround) {
requireWorkaround = false;
new WebView(context).destroy();
App.localeManager.setLocale(context);
}
}
}
================================================
FILE: app/src/main/java/com/yariksoffice/languagetest/ui/BaseActivity.java
================================================
package com.yariksoffice.languagetest.ui;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;
import androidx.appcompat.app.AppCompatActivity;
import android.util.Log;
import android.view.MenuItem;
import android.widget.TextView;
import com.yariksoffice.languagetest.App;
import com.yariksoffice.languagetest.LocaleManager;
import com.yariksoffice.languagetest.R;
import com.yariksoffice.languagetest.Utility;
import java.util.Locale;
import static com.yariksoffice.languagetest.LocaleManager.LANGUAGE_ENGLISH;
import static com.yariksoffice.languagetest.LocaleManager.LANGUAGE_RUSSIAN;
import static com.yariksoffice.languagetest.LocaleManager.LANGUAGE_UKRAINIAN;
public abstract class BaseActivity extends AppCompatActivity {
private static final String TAG = "BaseActivity";
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(App.localeManager.setLocale(base));
Log.d(TAG, "attachBaseContext");
}
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.d(TAG, "onCreate");
Utility.resetActivityTitle(this);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == android.R.id.home) {
finish();
return true;
} else {
return super.onOptionsItemSelected(item);
}
}
@Override
protected void onResume() {
super.onResume();
showResourcesInfo();
TextView tv = findViewById(R.id.cache);
tv.setText(Utility.getTitleCache());
}
private void showResourcesInfo() {
Resources topLevelRes = Utility.getTopLevelResources(this);
updateInfo("Top level ", findViewById(R.id.tv1), topLevelRes);
Resources appRes = getApplication().getResources();
updateInfo("Application ", findViewById(R.id.tv2), appRes);
Resources actRes = getResources();
updateInfo("Activity ", findViewById(R.id.tv3), actRes);
TextView tv4 = findViewById(R.id.tv4);
String defLanguage = Locale.getDefault().getLanguage();
tv4.setText(String.format("Locale.getDefault() - %s", defLanguage));
tv4.setCompoundDrawablesWithIntrinsicBounds(null, null, getLanguageDrawable(defLanguage), null);
}
private void updateInfo(String title, TextView tv, Resources res) {
Locale l = LocaleManager.getLocale(res);
tv.setText(title + Utility.hexString(res) + String.format(" - %s", l.getLanguage()));
Drawable icon = getLanguageDrawable(l.getLanguage());
tv.setCompoundDrawablesWithIntrinsicBounds(null, null, icon, null);
}
private Drawable getLanguageDrawable(String language) {
switch (language) {
case LANGUAGE_ENGLISH:
return ContextCompat.getDrawable(this, R.drawable.language_en);
case LANGUAGE_UKRAINIAN:
return ContextCompat.getDrawable(this, R.drawable.language_uk);
case LANGUAGE_RUSSIAN:
return ContextCompat.getDrawable(this, R.drawable.language_ru);
default:
Log.w(TAG, "Unsupported language");
return null;
}
}
}
================================================
FILE: app/src/main/java/com/yariksoffice/languagetest/ui/MainActivity.java
================================================
package com.yariksoffice.languagetest.ui;
import android.content.Intent;
import android.os.Bundle;
import androidx.annotation.Nullable;
import android.widget.TextView;
import com.yariksoffice.languagetest.R;
import com.yariksoffice.languagetest.TestService;
import com.yariksoffice.languagetest.WebViewLocaleHelper;
import java.text.SimpleDateFormat;
import java.util.Date;
public class MainActivity extends BaseActivity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_activity);
WebViewLocaleHelper helper = new WebViewLocaleHelper();
findViewById(R.id.activity_1).setOnClickListener(v -> startActivity(new Intent(this, TestActivity1.class)));
findViewById(R.id.activity_2).setOnClickListener(v -> startActivity(new Intent(this, TestActivity2.class)));
findViewById(R.id.web_view).setOnClickListener(v -> {
helper.implementWorkaround(this);
startActivity(new Intent(this, WebViewActivity.class));
});
findViewById(R.id.service).setOnClickListener(v -> startService(new Intent(this, TestService.class)));
findViewById(R.id.settings).setOnClickListener(v -> startActivity(new Intent(this, SettingsActivity.class)));
TextView tv = findViewById(R.id.hello);
String date = SimpleDateFormat.getDateInstance().format(new Date());
tv.setText(getString(R.string.hello, date));
}
}
================================================
FILE: app/src/main/java/com/yariksoffice/languagetest/ui/SettingsActivity.java
================================================
package com.yariksoffice.languagetest.ui;
import android.content.Intent;
import android.os.Bundle;
import androidx.annotation.Nullable;
import android.widget.Toast;
import com.yariksoffice.languagetest.App;
import com.yariksoffice.languagetest.R;
import static com.yariksoffice.languagetest.LocaleManager.LANGUAGE_ENGLISH;
import static com.yariksoffice.languagetest.LocaleManager.LANGUAGE_RUSSIAN;
import static com.yariksoffice.languagetest.LocaleManager.LANGUAGE_UKRAINIAN;
public class SettingsActivity extends BaseActivity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.settings_activity);
//noinspection ConstantConditions
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
findViewById(R.id.en).setOnClickListener(v -> setNewLocale(LANGUAGE_ENGLISH, false));
findViewById(R.id.en).setOnLongClickListener(v -> setNewLocale(LANGUAGE_ENGLISH, true));
findViewById(R.id.ukr).setOnClickListener(v -> setNewLocale(LANGUAGE_UKRAINIAN, false));
findViewById(R.id.ukr).setOnLongClickListener(v -> setNewLocale(LANGUAGE_UKRAINIAN, true));
findViewById(R.id.ru).setOnClickListener(v -> setNewLocale(LANGUAGE_RUSSIAN, false));
findViewById(R.id.ru).setOnLongClickListener(v -> setNewLocale(LANGUAGE_RUSSIAN, true));
}
private boolean setNewLocale(String language, boolean restartProcess) {
App.localeManager.setNewLocale(this, language);
Intent i = new Intent(this, MainActivity.class);
startActivity(i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK));
if (restartProcess) {
System.exit(0);
} else {
Toast.makeText(this, "Activity restarted", Toast.LENGTH_SHORT).show();
}
return true;
}
}
================================================
FILE: app/src/main/java/com/yariksoffice/languagetest/ui/TestActivity1.java
================================================
package com.yariksoffice.languagetest.ui;
import android.os.Bundle;
import androidx.annotation.Nullable;
import com.yariksoffice.languagetest.R;
public class TestActivity1 extends BaseActivity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.test_activity_1);
//noinspection ConstantConditions
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
}
================================================
FILE: app/src/main/java/com/yariksoffice/languagetest/ui/TestActivity2.java
================================================
package com.yariksoffice.languagetest.ui;
import android.os.Bundle;
import androidx.annotation.Nullable;
import com.yariksoffice.languagetest.R;
public class TestActivity2 extends BaseActivity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.test_activity_2);
//noinspection ConstantConditions
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
}
================================================
FILE: app/src/main/java/com/yariksoffice/languagetest/ui/WebViewActivity.java
================================================
package com.yariksoffice.languagetest.ui;
import android.os.Bundle;
import android.webkit.WebView;
import com.yariksoffice.languagetest.R;
import androidx.annotation.Nullable;
public class WebViewActivity extends BaseActivity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.web_view_activity);
//noinspection ConstantConditions
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
WebView webView = findViewById(R.id.web_view);
webView.loadUrl("https://www.google.com/");
}
}
================================================
FILE: app/src/main/res/drawable/language_en.xml
================================================
================================================
FILE: app/src/main/res/drawable/language_ru.xml
================================================
================================================
FILE: app/src/main/res/drawable/language_uk.xml
================================================
================================================
FILE: app/src/main/res/layout/locale_info.xml
================================================
================================================
FILE: app/src/main/res/layout/main_activity.xml
================================================
================================================
FILE: app/src/main/res/layout/settings_activity.xml
================================================
================================================
FILE: app/src/main/res/layout/test_activity_1.xml
================================================
================================================
FILE: app/src/main/res/layout/test_activity_2.xml
================================================
================================================
FILE: app/src/main/res/layout/web_view_activity.xml
================================================
================================================
FILE: app/src/main/res/values/colors.xml
================================================
#3F51B5#303F9F#FF4081
================================================
FILE: app/src/main/res/values/strings.xml
================================================
Language TestUkrainianEnglishRussianHello\n%sSettingsScreen 1Screen 2WebViewRandom text 1Random text 2Start a serviceClick for activity restart\nLong click for application restart
================================================
FILE: app/src/main/res/values/styles.xml
================================================
================================================
FILE: app/src/main/res/values-ru/strings.xml
================================================
Тест локализацииПривет\n%sУкраинскийАнглийскийРусскийНастройкиЭкран 1Экран 2БраузерКакой-нибудь текст 1Какой-нибудь текст 2Запустить ServiceКлик для перезагрузки activity \nДолгий клик для перезагрузки application
================================================
FILE: app/src/main/res/values-uk/strings.xml
================================================
Тест локалізаціїПривіт\n%sУкраїнськаАнглійськаРосійськаНалаштуванняЕкран 1Екран 2БраузерЯкий-небудь текст 1Який-небудь текст 2Запустити ServiceКлік для перезапуску activity \nДовгий клік для перезапуску application
================================================
FILE: build.gradle
================================================
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
================================================
FILE: gradle/wrapper/gradle-wrapper.properties
================================================
#Thu Nov 15 11:55:15 EET 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
================================================
FILE: gradle.properties
================================================
# Project-wide Gradle settings.
# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.
# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
android.enableJetifier=true
android.useAndroidX=true
org.gradle.jvmargs=-Xmx1536m
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
================================================
FILE: gradlew
================================================
#!/usr/bin/env bash
##############################################################################
##
## Gradle start up script for UN*X
##
##############################################################################
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""
APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
warn ( ) {
echo "$*"
}
die ( ) {
echo
echo "$*"
echo
exit 1
}
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
case "`uname`" in
CYGWIN* )
cygwin=true
;;
Darwin* )
darwin=true
;;
MINGW* )
msys=true
;;
esac
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >/dev/null
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD="java"
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
MAX_FD="$MAX_FD_LIMIT"
fi
ulimit -n $MAX_FD
if [ $? -ne 0 ] ; then
warn "Could not set maximum file descriptor limit: $MAX_FD"
fi
else
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
fi
fi
# For Darwin, add options to specify how the application appears in the dock
if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi
# For Cygwin, switch paths to Windows format before running java
if $cygwin ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`
# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
SEP=""
for dir in $ROOTDIRSRAW ; do
ROOTDIRS="$ROOTDIRS$SEP$dir"
SEP="|"
done
OURCYGPATTERN="(^($ROOTDIRS))"
# Add a user-defined pattern to the cygpath arguments
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
fi
# Now convert the arguments - kludge to limit ourselves to /bin/sh
i=0
for arg in "$@" ; do
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
else
eval `echo args$i`="\"$arg\""
fi
i=$((i+1))
done
case $i in
(0) set -- ;;
(1) set -- "$args0" ;;
(2) set -- "$args0" "$args1" ;;
(3) set -- "$args0" "$args1" "$args2" ;;
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi
# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
function splitJvmOpts() {
JVM_OPTS=("$@")
}
eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
================================================
FILE: gradlew.bat
================================================
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS=
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto init
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:init
@rem Get command-line arguments, handling Windowz variants
if not "%OS%" == "Windows_NT" goto win9xME_args
if "%@eval[2+2]" == "4" goto 4NT_args
:win9xME_args
@rem Slurp the command line arguments.
set CMD_LINE_ARGS=
set _SKIP=2
:win9xME_args_slurp
if "x%~1" == "x" goto execute
set CMD_LINE_ARGS=%*
goto execute
:4NT_args
@rem Get arguments from the 4NT Shell from JP Software
set CMD_LINE_ARGS=%$
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega
================================================
FILE: settings.gradle
================================================
include ':app'