Initial commit. Version 1.4

Signed-off-by: Carlos Silva <r3pek@r3pek.org>
This commit is contained in:
Carlos Mogas da Silva 2010-04-23 19:26:25 +01:00
commit fd47903476
13 changed files with 375 additions and 0 deletions

7
.classpath Normal file
View file

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry kind="output" path="bin"/>
</classpath>

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
/gen

33
.project Normal file
View file

@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>APNpt</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.android.ide.eclipse.adt.ApkBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View file

@ -0,0 +1,3 @@
#Tue Nov 10 11:01:48 GMT 2009
eclipse.preferences.version=1
encoding/<project>=UTF-8

19
AndroidManifest.xml Normal file
View file

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.r3pek.APNpt" android:versionName="1.4" android:versionCode="7">
<application android:icon="@drawable/icon" android:label="@string/app_name" android:debuggable="false">
<activity android:name=".MainActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion="3" />
<uses-permission android:name="android.permission.WRITE_APN_SETTINGS" />
<supports-screens android:smallScreens="true" android:normalScreens="true" android:anyDensity="true" android:largeScreens="true" android:resizeable="true"></supports-screens>
</manifest>

BIN
bin/APNpt.apk Normal file

Binary file not shown.

BIN
bin/classes.dex Normal file

Binary file not shown.

BIN
bin/resources.ap_ Normal file

Binary file not shown.

13
default.properties Normal file
View file

@ -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

BIN
res/drawable/icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.9 KiB

18
res/layout/main.xml Normal file
View file

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="@+id/LinearLayout01" android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical"><TextView android:id="@+id/TextView01" android:layout_height="wrap_content" android:textStyle="bold" android:layout_width="wrap_content" android:text="APNs:"></TextView>
<CheckBox android:id="@+id/CheckBox01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Vodafone"></CheckBox>
<CheckBox android:id="@+id/CheckBox02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="TMN"></CheckBox>
<CheckBox android:id="@+id/CheckBox03" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Optimus"></CheckBox>
<Button android:id="@+id/Button01" android:layout_height="wrap_content" android:text="Limpar Todos" android:layout_width="wrap_content"></Button>
</LinearLayout>

View file

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">APNpt</string>
</resources>

View 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;
}
}