WIP: language set and validation
This commit is contained in:
parent
bb38d7644b
commit
a0463742fa
|
@ -1,10 +1,46 @@
|
|||
package info.nightscout.androidaps.startupwizard;
|
||||
|
||||
//import org.mozilla.javascript.Context;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.ComponentName;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.IntentSender;
|
||||
import android.content.ServiceConnection;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.res.AssetManager;
|
||||
import android.content.res.Configuration;
|
||||
import android.content.res.Resources;
|
||||
import android.database.DatabaseErrorHandler;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.os.UserHandle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.view.Display;
|
||||
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.plugins.NSClientInternal.NSClientPlugin;
|
||||
import info.nightscout.utils.LocaleHelper;
|
||||
import info.nightscout.utils.SP;
|
||||
|
||||
public class SWDefinition {
|
||||
|
@ -16,7 +52,532 @@ public class SWDefinition {
|
|||
swDefinition = new SWDefinition();
|
||||
return swDefinition;
|
||||
}
|
||||
android.content.Context context = new Context() {
|
||||
@Override
|
||||
public AssetManager getAssets() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Resources getResources() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PackageManager getPackageManager() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ContentResolver getContentResolver() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Looper getMainLooper() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Context getApplicationContext() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTheme(int resid) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Resources.Theme getTheme() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClassLoader getClassLoader() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPackageName() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApplicationInfo getApplicationInfo() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPackageResourcePath() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPackageCodePath() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SharedPreferences getSharedPreferences(String name, int mode) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean moveSharedPreferencesFrom(Context sourceContext, String name) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deleteSharedPreferences(String name) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileInputStream openFileInput(String name) throws FileNotFoundException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileOutputStream openFileOutput(String name, int mode) throws FileNotFoundException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deleteFile(String name) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getFileStreamPath(String name) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getDataDir() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getFilesDir() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getNoBackupFilesDir() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public File getExternalFilesDir(@Nullable String type) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public File[] getExternalFilesDirs(String type) {
|
||||
return new File[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getObbDir() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public File[] getObbDirs() {
|
||||
return new File[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getCacheDir() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getCodeCacheDir() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public File getExternalCacheDir() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public File[] getExternalCacheDirs() {
|
||||
return new File[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public File[] getExternalMediaDirs() {
|
||||
return new File[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] fileList() {
|
||||
return new String[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getDir(String name, int mode) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SQLiteDatabase openOrCreateDatabase(String name, int mode, SQLiteDatabase.CursorFactory factory) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SQLiteDatabase openOrCreateDatabase(String name, int mode, SQLiteDatabase.CursorFactory factory, @Nullable DatabaseErrorHandler errorHandler) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean moveDatabaseFrom(Context sourceContext, String name) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deleteDatabase(String name) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getDatabasePath(String name) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] databaseList() {
|
||||
return new String[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public Drawable getWallpaper() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Drawable peekWallpaper() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWallpaperDesiredMinimumWidth() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWallpaperDesiredMinimumHeight() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setWallpaper(Bitmap bitmap) throws IOException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setWallpaper(InputStream data) throws IOException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearWallpaper() throws IOException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startActivity(Intent intent) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startActivity(Intent intent, @Nullable Bundle options) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startActivities(Intent[] intents) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startActivities(Intent[] intents, Bundle options) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startIntentSender(IntentSender intent, @Nullable Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags) throws IntentSender.SendIntentException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startIntentSender(IntentSender intent, @Nullable Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags, @Nullable Bundle options) throws IntentSender.SendIntentException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendBroadcast(Intent intent) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendBroadcast(Intent intent, @Nullable String receiverPermission) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendOrderedBroadcast(Intent intent, @Nullable String receiverPermission) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendOrderedBroadcast(@NonNull Intent intent, @Nullable String receiverPermission, @Nullable BroadcastReceiver resultReceiver, @Nullable Handler scheduler, int initialCode, @Nullable String initialData, @Nullable Bundle initialExtras) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendBroadcastAsUser(Intent intent, UserHandle user) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendBroadcastAsUser(Intent intent, UserHandle user, @Nullable String receiverPermission) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendOrderedBroadcastAsUser(Intent intent, UserHandle user, @Nullable String receiverPermission, BroadcastReceiver resultReceiver, @Nullable Handler scheduler, int initialCode, @Nullable String initialData, @Nullable Bundle initialExtras) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendStickyBroadcast(Intent intent) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendStickyOrderedBroadcast(Intent intent, BroadcastReceiver resultReceiver, @Nullable Handler scheduler, int initialCode, @Nullable String initialData, @Nullable Bundle initialExtras) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeStickyBroadcast(Intent intent) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendStickyBroadcastAsUser(Intent intent, UserHandle user) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendStickyOrderedBroadcastAsUser(Intent intent, UserHandle user, BroadcastReceiver resultReceiver, @Nullable Handler scheduler, int initialCode, @Nullable String initialData, @Nullable Bundle initialExtras) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeStickyBroadcastAsUser(Intent intent, UserHandle user) {
|
||||
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Intent registerReceiver(@Nullable BroadcastReceiver receiver, IntentFilter filter) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Intent registerReceiver(@Nullable BroadcastReceiver receiver, IntentFilter filter, int flags) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Intent registerReceiver(BroadcastReceiver receiver, IntentFilter filter, @Nullable String broadcastPermission, @Nullable Handler scheduler) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Intent registerReceiver(BroadcastReceiver receiver, IntentFilter filter, @Nullable String broadcastPermission, @Nullable Handler scheduler, int flags) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unregisterReceiver(BroadcastReceiver receiver) {
|
||||
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public ComponentName startService(Intent service) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public ComponentName startForegroundService(Intent service) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean stopService(Intent service) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean bindService(Intent service, @NonNull ServiceConnection conn, int flags) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unbindService(@NonNull ServiceConnection conn) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean startInstrumentation(@NonNull ComponentName className, @Nullable String profileFile, @Nullable Bundle arguments) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Object getSystemService(@NonNull String name) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getSystemServiceName(@NonNull Class<?> serviceClass) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int checkPermission(@NonNull String permission, int pid, int uid) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int checkCallingPermission(@NonNull String permission) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int checkCallingOrSelfPermission(@NonNull String permission) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int checkSelfPermission(@NonNull String permission) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enforcePermission(@NonNull String permission, int pid, int uid, @Nullable String message) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enforceCallingPermission(@NonNull String permission, @Nullable String message) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enforceCallingOrSelfPermission(@NonNull String permission, @Nullable String message) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void grantUriPermission(String toPackage, Uri uri, int modeFlags) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void revokeUriPermission(Uri uri, int modeFlags) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void revokeUriPermission(String toPackage, Uri uri, int modeFlags) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int checkUriPermission(Uri uri, int pid, int uid, int modeFlags) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int checkCallingUriPermission(Uri uri, int modeFlags) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int checkCallingOrSelfUriPermission(Uri uri, int modeFlags) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int checkUriPermission(@Nullable Uri uri, @Nullable String readPermission, @Nullable String writePermission, int pid, int uid, int modeFlags) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enforceUriPermission(Uri uri, int pid, int uid, int modeFlags, String message) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enforceCallingUriPermission(Uri uri, int modeFlags, String message) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enforceCallingOrSelfUriPermission(Uri uri, int modeFlags, String message) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enforceUriPermission(@Nullable Uri uri, @Nullable String readPermission, @Nullable String writePermission, int pid, int uid, int modeFlags, @Nullable String message) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Context createPackageContext(String packageName, int flags) throws PackageManager.NameNotFoundException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Context createContextForSplit(String splitName) throws PackageManager.NameNotFoundException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Context createConfigurationContext(@NonNull Configuration overrideConfiguration) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Context createDisplayContext(@NonNull Display display) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Context createDeviceProtectedStorageContext() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDeviceProtectedStorage() {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
static List<SWScreen> screens = new ArrayList<>();
|
||||
|
||||
public static List<SWScreen> getScreens() {
|
||||
|
@ -44,9 +605,9 @@ public class SWDefinition {
|
|||
)
|
||||
.add(new SWScreen(R.string.language)
|
||||
.skippable(false)
|
||||
.add(new SWRadioButton().option(R.array.languagesArray, R.array.languagesValues).preferenceId(R.string.language).label(R.string.language).comment(R.string.setupwizard_language_prompt))
|
||||
.validator(() -> SP.contains(R.string.language))
|
||||
)
|
||||
.add(new SWRadioButton().option(R.array.languagesArray, R.array.languagesValues).preferenceId(R.string.key_language).label(R.string.language).comment(R.string.setupwizard_language_prompt))
|
||||
.validator(() -> {/*context = context.getApplicationContext(); LocaleHelper.setLocale(context, SP.getString(R.string.key_language, "en")); return*/ return SP.contains(R.string.key_language);}
|
||||
))
|
||||
;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package info.nightscout.androidaps.startupwizard;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
|
@ -49,7 +50,7 @@ public class SWRadioButton extends SWItem {
|
|||
String[] values = context.getResources().getStringArray(valuesArray);
|
||||
// Get if there is already value in SP
|
||||
String previousValue = SP.getString(preferenceId, "unset");
|
||||
|
||||
log.debug("Value for "+view.getContext().getString(preferenceId)+" is "+previousValue);
|
||||
radioGroup = new RadioGroup(context);
|
||||
radioGroup.clearCheck();
|
||||
|
||||
|
@ -71,7 +72,7 @@ public class SWRadioButton extends SWItem {
|
|||
radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(RadioGroup group, int checkedId) {
|
||||
save(getCheckedValue());
|
||||
save();
|
||||
}
|
||||
|
||||
});
|
||||
|
@ -98,7 +99,8 @@ public class SWRadioButton extends SWItem {
|
|||
}
|
||||
|
||||
public void save(){
|
||||
if(getCheckedValue().equals("none")) {
|
||||
if(!getCheckedValue().equals("none")) {
|
||||
log.debug("Saving "+preferenceId+" value "+getCheckedValue());
|
||||
SP.putString(preferenceId, getCheckedValue());
|
||||
MainApp.bus().post(new EventPreferenceChange(preferenceId));
|
||||
}
|
||||
|
|
|
@ -20,16 +20,15 @@ public class SWUrl extends SWItem {
|
|||
super(Type.URL);
|
||||
}
|
||||
|
||||
public void setOptions(List<String> labels, List<String> values){
|
||||
// log.debug("Setting options - labels "+labels.size()+" values - "+values.size());
|
||||
this.labels = labels;
|
||||
this.values = values;
|
||||
}
|
||||
|
||||
public void setName(String name){
|
||||
this.groupName = name;
|
||||
}
|
||||
|
||||
public void setOptions(List<String> labels, List<String> values){
|
||||
this.labels = labels;
|
||||
this.values = values;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void generateDialog(View view, LinearLayout layout) {
|
||||
Context context = view.getContext();
|
||||
|
|
|
@ -1012,4 +1012,5 @@
|
|||
<string name="setupwizard_skip">Skip</string>
|
||||
<string name="setupwizard_finish">FINISH</string>
|
||||
<string name="setupwizard_language_prompt">Select your language</string>
|
||||
<string name="key_language">language</string>
|
||||
</resources>
|
||||
|
|
Loading…
Reference in a new issue