74 lines
2.5 KiB
Java
74 lines
2.5 KiB
Java
package at.sprinternet.mvnoroaming;
|
|
|
|
import android.os.Bundle;
|
|
import android.app.Activity;
|
|
import android.content.Context;
|
|
import android.content.SharedPreferences;
|
|
import android.util.Log;
|
|
import android.view.View;
|
|
import android.widget.Button;
|
|
import android.widget.CompoundButton;
|
|
import android.widget.EditText;
|
|
import android.widget.Switch;
|
|
import android.widget.Toast;
|
|
|
|
public class MVNORoamingStatusChanger extends Activity {
|
|
|
|
private static final String PROVIDER_KEY = "mvno_provider";
|
|
private static final String REBOOTSERVICE_KEY = "mvno_setonreboot";
|
|
private static final String TAG = "MVNOroaming";
|
|
|
|
private EditText editTextProvider;
|
|
private Button buttonUpdate;
|
|
private Switch switchReboot;
|
|
|
|
private SharedPreferences prefs;
|
|
|
|
@Override
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
super.onCreate(savedInstanceState);
|
|
setContentView(R.layout.activity_mvno);
|
|
|
|
editTextProvider = (EditText) findViewById(R.id.editTextProvider);
|
|
buttonUpdate = (Button) findViewById(R.id.buttonUpdate);
|
|
switchReboot = (Switch) findViewById(R.id.switchReboot);
|
|
prefs = this.getSharedPreferences("at.sprinternet.mvnoroaming", Context.MODE_PRIVATE);
|
|
|
|
//set listeners
|
|
switchReboot.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
|
@Override
|
|
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
|
Log.v(TAG, "Switch State="+isChecked);
|
|
prefs.edit().putBoolean(REBOOTSERVICE_KEY, isChecked).commit();
|
|
}
|
|
|
|
});
|
|
|
|
buttonUpdate.setOnClickListener(new Button.OnClickListener() {
|
|
@Override
|
|
public void onClick(View v) {
|
|
Log.v(TAG, "Button clicked");
|
|
prefs.edit().putString(PROVIDER_KEY, editTextProvider.getText().toString()).commit();
|
|
Boolean done = ExecuteAsRoot.exec("setprop gsm.sim.operator.alpha " + editTextProvider.getText().toString());
|
|
|
|
if(!done) {
|
|
Toast.makeText(getApplicationContext(), "Setting Service-Provider failed!", Toast.LENGTH_LONG).show();
|
|
} else {
|
|
Toast.makeText(getApplicationContext(), "Updated Service-Provider!", Toast.LENGTH_LONG).show();
|
|
}
|
|
}
|
|
});
|
|
|
|
|
|
//init gui
|
|
String currentProvider = "";
|
|
Boolean setOnReboot = true;
|
|
|
|
currentProvider = prefs.getString(PROVIDER_KEY, ""); // default: empty
|
|
setOnReboot = prefs.getBoolean(REBOOTSERVICE_KEY, true);
|
|
|
|
editTextProvider.setText(currentProvider);
|
|
switchReboot.setChecked(setOnReboot);
|
|
}
|
|
}
|