commit fd479034764d279ec7df0ac4c0e33371931750bb Author: Carlos Silva Date: Fri Apr 23 19:26:25 2010 +0100 Initial commit. Version 1.4 Signed-off-by: Carlos Silva diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..6e9239f --- /dev/null +++ b/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8d94b88 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/gen diff --git a/.project b/.project new file mode 100644 index 0000000..63d18c1 --- /dev/null +++ b/.project @@ -0,0 +1,33 @@ + + + APNpt + + + + + + com.android.ide.eclipse.adt.ResourceManagerBuilder + + + + + com.android.ide.eclipse.adt.PreCompilerBuilder + + + + + org.eclipse.jdt.core.javabuilder + + + + + com.android.ide.eclipse.adt.ApkBuilder + + + + + + com.android.ide.eclipse.adt.AndroidNature + org.eclipse.jdt.core.javanature + + diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..b0bbf34 --- /dev/null +++ b/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,3 @@ +#Tue Nov 10 11:01:48 GMT 2009 +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/AndroidManifest.xml b/AndroidManifest.xml new file mode 100644 index 0000000..0e88395 --- /dev/null +++ b/AndroidManifest.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/bin/APNpt.apk b/bin/APNpt.apk new file mode 100644 index 0000000..3f4ba3e Binary files /dev/null and b/bin/APNpt.apk differ diff --git a/bin/classes.dex b/bin/classes.dex new file mode 100644 index 0000000..25e0a78 Binary files /dev/null and b/bin/classes.dex differ diff --git a/bin/resources.ap_ b/bin/resources.ap_ new file mode 100644 index 0000000..ef7cab9 Binary files /dev/null and b/bin/resources.ap_ differ diff --git a/default.properties b/default.properties new file mode 100644 index 0000000..19c9665 --- /dev/null +++ b/default.properties @@ -0,0 +1,13 @@ +# This file is automatically generated by Android Tools. +# Do not modify this file -- YOUR CHANGES WILL BE ERASED! +# +# This file must be checked in Version Control Systems. +# +# To customize properties used by the Ant build system use, +# "build.properties", and override values to adapt the script to your +# project structure. + +# Indicates whether an apk should be generated for each density. +split.density=false +# Project target. +target=android-4 diff --git a/res/drawable/icon.png b/res/drawable/icon.png new file mode 100644 index 0000000..c819520 Binary files /dev/null and b/res/drawable/icon.png differ diff --git a/res/layout/main.xml b/res/layout/main.xml new file mode 100644 index 0000000..03b769d --- /dev/null +++ b/res/layout/main.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + diff --git a/res/values/strings-pt.xml b/res/values/strings-pt.xml new file mode 100644 index 0000000..d53a855 --- /dev/null +++ b/res/values/strings-pt.xml @@ -0,0 +1,5 @@ + + + + APNpt + diff --git a/src/org/r3pek/APNpt/MainActivity.java b/src/org/r3pek/APNpt/MainActivity.java new file mode 100644 index 0000000..f260764 --- /dev/null +++ b/src/org/r3pek/APNpt/MainActivity.java @@ -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 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 getAPNs() { + Cursor c = context.getContentResolver().query(APN_TABLE_URI, new String[]{"name"}, null, null, null); + if (c != null) { + ArrayList result = new ArrayList(); + 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; + } +} \ No newline at end of file