Initial commit. Version 1.4
Signed-off-by: Carlos Silva <r3pek@r3pek.org>
This commit is contained in:
commit
fd47903476
13 changed files with 375 additions and 0 deletions
276
src/org/r3pek/APNpt/MainActivity.java
Normal file
276
src/org/r3pek/APNpt/MainActivity.java
Normal file
|
@ -0,0 +1,276 @@
|
|||
package org.r3pek.APNpt;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.widget.Button;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.Toast;
|
||||
import android.widget.CompoundButton.OnCheckedChangeListener;
|
||||
|
||||
public class MainActivity extends Activity {
|
||||
/*
|
||||
* Information of all APNs
|
||||
* Details cans be found in com.android.providers.telephony.TelephonyProvider
|
||||
*/
|
||||
private static final Uri APN_TABLE_URI = Uri.parse("content://telephony/carriers");
|
||||
/*
|
||||
* Information of the preferred APN
|
||||
*/
|
||||
private static final Uri PREFERRED_APN_URI = Uri.parse("content://telephony/carriers/preferapn");
|
||||
|
||||
private static final int DIALOG_CONFIRMATION_ID = 0;
|
||||
|
||||
private Context context;
|
||||
|
||||
/** Called when the activity is first created. */
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.main);
|
||||
context = getApplicationContext();
|
||||
|
||||
Toast.makeText(context, "Se achou que a aplicação lhe foi util, passe por www.r3pek.org e faça um donativo. Obrigado", Toast.LENGTH_LONG).show();
|
||||
|
||||
CheckBox chkVDF = (CheckBox)findViewById(R.id.CheckBox01);
|
||||
CheckBox chkTMN = (CheckBox)findViewById(R.id.CheckBox02);
|
||||
CheckBox chkOPT = (CheckBox)findViewById(R.id.CheckBox03);
|
||||
Button btnClear = (Button)findViewById(R.id.Button01);
|
||||
|
||||
ArrayList<String> apns = getAPNs();
|
||||
chkVDF.setChecked(false);
|
||||
chkTMN.setChecked(false);
|
||||
chkOPT.setChecked(false);
|
||||
if (apns != null)
|
||||
for (int i = 0; i < apns.size(); i++) {
|
||||
if (apns.get(i).contains("vodafone"))
|
||||
chkVDF.setChecked(true);
|
||||
if (apns.get(i).contains("tmn"))
|
||||
chkTMN.setChecked(true);
|
||||
if (apns.get(i).contains("optimus"))
|
||||
chkOPT.setChecked(true);
|
||||
}
|
||||
|
||||
chkVDF.setOnCheckedChangeListener(new OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
if (isChecked) {
|
||||
int id_net = insertAPN("vdf-net");
|
||||
setDefaultAPN(id_net);
|
||||
int id_mms = insertAPN("vdf-mms");
|
||||
if (id_net != -1 && id_mms != -1)
|
||||
Toast.makeText(context, "APNs para a Vodafone inseridos com sucesso", Toast.LENGTH_SHORT).show();
|
||||
else
|
||||
Toast.makeText(context, "Falha a inserir os APNs para a Vodafone", Toast.LENGTH_SHORT).show();
|
||||
} else {
|
||||
removeAPN("vodafone Internet");
|
||||
removeAPN("vodafone MMS");
|
||||
Toast.makeText(context, "APNs da Vodafone apagados", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
chkTMN.setOnCheckedChangeListener(new OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
if (isChecked) {
|
||||
int id_net = insertAPN("tmn-net");
|
||||
setDefaultAPN(id_net);
|
||||
int id_mms = insertAPN("tmn-mms");
|
||||
if (id_net != -1 && id_mms != -1)
|
||||
Toast.makeText(context, "APNs para a TMN inseridos com sucesso", Toast.LENGTH_SHORT).show();
|
||||
else
|
||||
Toast.makeText(context, "Falha a inserir os APNs para a TMN", Toast.LENGTH_SHORT).show();
|
||||
} else {
|
||||
removeAPN("tmn Internet");
|
||||
removeAPN("tmn MMS");
|
||||
Toast.makeText(context, "APNs da TMN apagados", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
chkOPT.setOnCheckedChangeListener(new OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
if (isChecked) {
|
||||
int id_net = insertAPN("opt-net");
|
||||
setDefaultAPN(id_net);
|
||||
int id_mms = insertAPN("opt-mms");
|
||||
if (id_net != -1 && id_mms != -1)
|
||||
Toast.makeText(context, "APNs para a Optimus inseridos com sucesso", Toast.LENGTH_SHORT).show();
|
||||
else
|
||||
Toast.makeText(context, "Falha a inserir os APNs para a Optimus", Toast.LENGTH_SHORT).show();
|
||||
} else {
|
||||
removeAPN("optimus Internet");
|
||||
removeAPN("optimus MMS");
|
||||
Toast.makeText(context, "APNs da Optimus apagados", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
btnClear.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
showDialog(DIALOG_CONFIRMATION_ID);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected Dialog onCreateDialog(int id) {
|
||||
switch (id) {
|
||||
case DIALOG_CONFIRMATION_ID:
|
||||
return showConfirmationDialog();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private Dialog showConfirmationDialog() {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
builder.setMessage("De certeza que quer apagar TODOS os APNs?");
|
||||
builder.setCancelable(false);
|
||||
builder.setPositiveButton("Sim", new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
MainActivity.this.clearAPNs();
|
||||
}
|
||||
});
|
||||
builder.setNegativeButton("Não", new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
dialog.cancel();
|
||||
}
|
||||
});
|
||||
return builder.create();
|
||||
}
|
||||
|
||||
private void clearAPNs() {
|
||||
context.getContentResolver().delete(APN_TABLE_URI, null,null);
|
||||
((CheckBox)findViewById(R.id.CheckBox01)).setChecked(false);
|
||||
((CheckBox)findViewById(R.id.CheckBox02)).setChecked(false);
|
||||
((CheckBox)findViewById(R.id.CheckBox03)).setChecked(false);
|
||||
//Log.d("ClearAPNs", "Apagados " + r + " APN's");
|
||||
}
|
||||
|
||||
private void removeAPN(String name) {
|
||||
context.getContentResolver().delete(APN_TABLE_URI, "name = '" + name + "'", null);
|
||||
}
|
||||
|
||||
private ArrayList<String> getAPNs() {
|
||||
Cursor c = context.getContentResolver().query(APN_TABLE_URI, new String[]{"name"}, null, null, null);
|
||||
if (c != null) {
|
||||
ArrayList<String> result = new ArrayList<String>();
|
||||
while (c.moveToNext()) {
|
||||
result.add(c.getString(0));
|
||||
//Log.d("getAPNS", c.getString(0));
|
||||
}
|
||||
c.close();
|
||||
return result;
|
||||
} else
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean setDefaultAPN(int id) {
|
||||
boolean res = false;
|
||||
ContentResolver resolver = context.getContentResolver();
|
||||
ContentValues values = new ContentValues();
|
||||
|
||||
values.put("apn_id", id);
|
||||
resolver.update(PREFERRED_APN_URI, values, null, null);
|
||||
Cursor c = resolver.query(PREFERRED_APN_URI, new String[]{"name","apn"}, "_id="+id, null, null);
|
||||
if (c != null) {
|
||||
res = true;
|
||||
c.close();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
private int insertAPN(String operator) {
|
||||
int result = -1;
|
||||
ContentResolver resolver = context.getContentResolver();
|
||||
ContentValues values = new ContentValues();
|
||||
if (operator.equals("vdf-net")) {
|
||||
values.put("name", "vodafone Internet");
|
||||
values.put("apn", "net2.vodafone.pt");
|
||||
values.put("server", "*");
|
||||
values.put("mcc", "268");
|
||||
values.put("mnc", "01");
|
||||
values.put("numeric", "26801");
|
||||
values.put("type", "default");
|
||||
} else if (operator.equals("vdf-mms")) {
|
||||
values.put("name", "vodafone MMS");
|
||||
values.put("apn", "vas.vodafone.pt");
|
||||
values.put("user", "vas");
|
||||
values.put("password", "vas");
|
||||
values.put("server", "*");
|
||||
values.put("mmsc", "http://mms/servlets/mms");
|
||||
values.put("mmsproxy", "213.030.027.063");
|
||||
values.put("mmsport", "8799");
|
||||
values.put("mcc", "268");
|
||||
values.put("mnc", "01");
|
||||
values.put("numeric", "26801");
|
||||
values.put("type", "mms");
|
||||
} else if (operator.equals("tmn-net")) {
|
||||
values.put("name", "tmn Internet");
|
||||
values.put("apn", "internet");
|
||||
values.put("server", "*");
|
||||
values.put("mcc", "268");
|
||||
values.put("mnc", "06");
|
||||
values.put("numeric", "26806");
|
||||
values.put("type", "default");
|
||||
} else if (operator.equals("tmn-mms")) {
|
||||
values.put("name", "tmn MMS");
|
||||
values.put("apn", "mmsc.tmn.pt");
|
||||
values.put("user", "tmn");
|
||||
values.put("password", "tmnnet");
|
||||
values.put("server", "*");
|
||||
values.put("mmsc", "http://mmsc");
|
||||
values.put("mmsproxy", "010.111.002.016");
|
||||
values.put("mmsport", "8080");
|
||||
values.put("mcc", "268");
|
||||
values.put("mnc", "06");
|
||||
values.put("numeric", "26806");
|
||||
values.put("type", "mms");
|
||||
} else if (operator.equals("opt-net")) {
|
||||
values.put("name", "optimus Internet");
|
||||
values.put("apn", "umts"); // "internet" ???
|
||||
values.put("server", "*");
|
||||
values.put("mcc", "268");
|
||||
values.put("mnc", "03");
|
||||
values.put("numeric", "26803");
|
||||
values.put("type", "default");
|
||||
} else if (operator.equals("opt-mms")) {
|
||||
values.put("name", "optimus MMS");
|
||||
values.put("apn", "mms");
|
||||
values.put("server", "*");
|
||||
values.put("mmsc", "http://mmsc:10021/mmsc");
|
||||
values.put("mmsproxy", "062.169.066.001"); // era .5
|
||||
values.put("mmsport", "9201"); // tambem pode ser 8799
|
||||
values.put("mcc", "268");
|
||||
values.put("mnc", "03");
|
||||
values.put("numeric", "26803");
|
||||
values.put("type", "mms");
|
||||
}
|
||||
|
||||
Cursor c = null;
|
||||
Uri newRow = resolver.insert(APN_TABLE_URI, values);
|
||||
if (newRow != null) {
|
||||
c = resolver.query(newRow, new String[]{"_id"}, null, null, null);
|
||||
c.moveToNext();
|
||||
result = c.getShort(0);
|
||||
c.close();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue