change package name + apk && aab
This commit is contained in:
@ -0,0 +1,295 @@
|
||||
package com.safemobile.safedispatch;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
/** fix import */
|
||||
import com.safemobile.adapters.LanguageSpinnerAdapter;
|
||||
import com.safemobile.lib.AppParams;
|
||||
import com.safemobile.lib.SM;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.Configuration;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
public class SetupActivity extends Activity {
|
||||
|
||||
/* Preferences */
|
||||
private SharedPreferences.Editor editor;
|
||||
//private String IP, PORT, AUDIOPORT, COMPORT, LANGUAGE;
|
||||
|
||||
/* Visual Elements */
|
||||
private EditText appServerIP, appServerPort;
|
||||
private LinearLayout layoutPath;
|
||||
private Button btn_save;
|
||||
|
||||
/* Misc */
|
||||
private Context context;
|
||||
private TabLayoutActivity parentTab;
|
||||
|
||||
/* Language */
|
||||
private String[] Languages = {"English", "German", "Turkish", "Romanian", "Russian", "Spanish"};
|
||||
private ImageView imageLanguage;
|
||||
private LinearLayout layoutSpinnerLanguage;
|
||||
private TextView textViewSpinnerLanguage;
|
||||
|
||||
private Bundle savedInstanceState;
|
||||
|
||||
/** Called when the activity is first created. */
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
this.savedInstanceState = savedInstanceState;
|
||||
context = this;
|
||||
|
||||
// get parentTab
|
||||
parentTab = (TabLayoutActivity)getParent();
|
||||
|
||||
// get settings
|
||||
loadSettings();
|
||||
|
||||
Locale locale = new Locale(AppParams.LANGUAGETMP);
|
||||
Locale.setDefault(locale);
|
||||
Configuration config = new Configuration();
|
||||
config.locale = locale;
|
||||
getBaseContext().getResources().updateConfiguration(config,
|
||||
getBaseContext().getResources().getDisplayMetrics());
|
||||
|
||||
Languages = new String[] {getString(R.string.en), getString(R.string.de), getString(R.string.tr), getString(R.string.ro), getString(R.string.ru), getString(R.string.es)};
|
||||
// set contextView
|
||||
setContentView(R.layout.tabsetup);
|
||||
|
||||
|
||||
layoutSpinnerLanguage = (LinearLayout) findViewById(R.id.layoutSpinnerLanguage);
|
||||
layoutSpinnerLanguage.setOnClickListener(LanguageListener);
|
||||
imageLanguage = (ImageView) findViewById(R.id.imageLanguage);
|
||||
textViewSpinnerLanguage = (TextView) findViewById(R.id.textViewSpinnerLanguage);
|
||||
|
||||
// change spinner icon and selected language according to tmpLanguage
|
||||
if (AppParams.LANGUAGETMP.equals("en")){
|
||||
imageLanguage.setImageResource(R.drawable.en);
|
||||
textViewSpinnerLanguage.setText(getString(R.string.en));
|
||||
}
|
||||
else if (AppParams.LANGUAGETMP.equals("de")){
|
||||
imageLanguage.setImageResource(R.drawable.de);
|
||||
textViewSpinnerLanguage.setText(getString(R.string.de));
|
||||
}
|
||||
else if (AppParams.LANGUAGETMP.equals("tr")){
|
||||
imageLanguage.setImageResource(R.drawable.tr);
|
||||
textViewSpinnerLanguage.setText(getString(R.string.tr));
|
||||
}
|
||||
else if (AppParams.LANGUAGETMP.equals("ro")){
|
||||
imageLanguage.setImageResource(R.drawable.ro);
|
||||
textViewSpinnerLanguage.setText(getString(R.string.ro));
|
||||
}
|
||||
else if(AppParams.LANGUAGETMP.equals("es")){
|
||||
imageLanguage.setImageResource(R.drawable.es);
|
||||
textViewSpinnerLanguage.setText(getString(R.string.es));
|
||||
}
|
||||
else if(AppParams.LANGUAGETMP.equals("ru")){
|
||||
imageLanguage.setImageResource(R.drawable.ru);
|
||||
textViewSpinnerLanguage.setText(getString(R.string.ru));
|
||||
}
|
||||
|
||||
// get visual elements
|
||||
appServerIP = (EditText) findViewById(R.id.appServerIP);
|
||||
appServerPort = (EditText) findViewById(R.id.appServerPort);
|
||||
|
||||
// hide path layout used only on Pad/Pod
|
||||
layoutPath = (LinearLayout) findViewById(R.id.layoutPath);
|
||||
layoutPath.setVisibility(View.GONE);
|
||||
btn_save = (Button) findViewById(R.id.btn_save);
|
||||
|
||||
btn_save.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
saveSettings();
|
||||
}
|
||||
});
|
||||
|
||||
// set values
|
||||
if(!AppParams.IP.equals("n/a"))
|
||||
appServerIP.setText(AppParams.IP);
|
||||
if(!AppParams.PORT.equals("n/a"))
|
||||
appServerPort.setText(AppParams.PORT);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onBackPressed()
|
||||
{
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
builder.setMessage(getString(R.string.exit))
|
||||
.setCancelable(false)
|
||||
.setNeutralButton(getString(R.string.logout), new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
parentTab.whenBackPressed(AppParams.ActivityResult.logout);
|
||||
}
|
||||
})
|
||||
.setPositiveButton(getString(R.string.ext), new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
parentTab.whenBackPressed(AppParams.ActivityResult.exit);
|
||||
}
|
||||
})
|
||||
.setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
dialog.cancel();
|
||||
}
|
||||
});
|
||||
AlertDialog alert = builder.create();
|
||||
alert.show();
|
||||
}
|
||||
|
||||
// listener when select language pressed
|
||||
private OnClickListener LanguageListener = new OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
final LanguageSpinnerAdapter adapter = new LanguageSpinnerAdapter(context, android.R.layout.simple_spinner_item, Languages, getLayoutInflater());
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
||||
builder.setTitle(getString(R.string.selLanguage));
|
||||
builder.setAdapter(adapter , new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
textViewSpinnerLanguage.setText(adapter.getItem(which));
|
||||
switch(which)
|
||||
{
|
||||
case 0: imageLanguage.setImageResource(R.drawable.en); AppParams.LANGUAGETMP = "en"; onCreate(savedInstanceState); parentTab.changeLanguage(); break;
|
||||
case 1: imageLanguage.setImageResource(R.drawable.de); AppParams.LANGUAGETMP = "de"; onCreate(savedInstanceState); parentTab.changeLanguage(); break;
|
||||
case 2: imageLanguage.setImageResource(R.drawable.tr); AppParams.LANGUAGETMP = "tr"; onCreate(savedInstanceState); parentTab.changeLanguage(); break;
|
||||
case 3: imageLanguage.setImageResource(R.drawable.ro); AppParams.LANGUAGETMP = "ro"; onCreate(savedInstanceState); parentTab.changeLanguage(); break;
|
||||
case 4: imageLanguage.setImageResource(R.drawable.ru); AppParams.LANGUAGETMP = "ru"; onCreate(savedInstanceState); parentTab.changeLanguage(); break;
|
||||
case 5: imageLanguage.setImageResource(R.drawable.es); AppParams.LANGUAGETMP = "es"; onCreate(savedInstanceState); parentTab.changeLanguage(); break;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
AlertDialog alert = builder.create();
|
||||
alert.show();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// load settings
|
||||
public void loadSettings()
|
||||
{
|
||||
try
|
||||
{
|
||||
// get Preferences for SafeDispatch
|
||||
AppParams.prefs = getSharedPreferences(getPackageName(), MODE_PRIVATE);
|
||||
// get default IP
|
||||
AppParams.IP = AppParams.prefs.getString("ip", "n/a");
|
||||
// get default communication port
|
||||
AppParams.PORT = AppParams.prefs.getString("port", "n/a");
|
||||
// get default audio port
|
||||
//AUDIOPORT = prefs.getString("audioport", "n/a");
|
||||
// get default com port
|
||||
//COMPORT = prefs.getString("comport", "n/a");
|
||||
// get Language
|
||||
AppParams.LANGUAGE = AppParams.prefs.getString("language", parentTab.databaseLanguage);
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Log.e("Exception", "loadSettings exception");
|
||||
}
|
||||
}
|
||||
|
||||
public void saveSettings()
|
||||
{
|
||||
// get editor
|
||||
editor = AppParams.prefs.edit();
|
||||
// save old IP and PORT values
|
||||
String oldIP = AppParams.IP;
|
||||
String oldPort = AppParams.PORT;
|
||||
|
||||
editor.putString("ip", appServerIP.getText().toString());
|
||||
editor.putString("port", appServerPort.getText().toString());
|
||||
editor.putString("language", AppParams.LANGUAGETMP);
|
||||
Boolean result = editor.commit();
|
||||
// saved completed
|
||||
if(result)
|
||||
Toast.makeText(context, "Settings saved successfully.", Toast.LENGTH_LONG).show();
|
||||
else
|
||||
Toast.makeText(context, "Settings failed to complete!", Toast.LENGTH_LONG).show();
|
||||
// if port or IP changed
|
||||
if((!appServerIP.getText().toString().equalsIgnoreCase(AppParams.IP) ||
|
||||
!appServerPort.getText().toString().equalsIgnoreCase(AppParams.PORT)) && !AppParams.DEMO)
|
||||
{
|
||||
SM.Debug("### SETTINGS ###", "IP and/or PORT had been changed");
|
||||
// load new settings
|
||||
parentTab.loadSettings();
|
||||
|
||||
|
||||
parentTab.removeITCPListener();
|
||||
|
||||
// recreateTCP
|
||||
parentTab.stopTCP();
|
||||
parentTab.recreateTCPConnection();
|
||||
|
||||
/*
|
||||
// stop old TCP
|
||||
parentTab.stopTCP();
|
||||
parentTab.stopTCPParser();
|
||||
// recreate TCP with new settings
|
||||
parentTab.loadSettings();
|
||||
parentTab.TCPinit();
|
||||
*/
|
||||
// start thread to add listener
|
||||
/*
|
||||
SM.Debug("##### initTCPRUN");
|
||||
new Thread(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
parentTab.myHandler.post(parentTab.initTCPRUN);
|
||||
}
|
||||
}).start();*/
|
||||
}
|
||||
// show dialog
|
||||
//showDialog(result);
|
||||
}
|
||||
|
||||
public void showDialog(Boolean result)
|
||||
{
|
||||
Dialog dialog = new Dialog(context);
|
||||
if(result)
|
||||
dialog.setTitle("Save Completed");
|
||||
else
|
||||
dialog.setTitle("Save Failed");
|
||||
dialog.setContentView(R.layout.dialog);
|
||||
dialog.setCancelable(true);
|
||||
dialog.setCanceledOnTouchOutside(true);
|
||||
|
||||
TextView text = (TextView) dialog.findViewById(R.id.text);
|
||||
ImageView image = (ImageView) dialog.findViewById(R.id.image);
|
||||
if(result)
|
||||
{
|
||||
image.setImageResource(R.drawable.error);
|
||||
text.setText("Settings saved successfully.");
|
||||
}
|
||||
else
|
||||
{
|
||||
image.setImageResource(R.drawable.error);
|
||||
text.setText("Settings failed to complete!");
|
||||
}
|
||||
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user