/**
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation; either version 3 of the License, or (at your option) any later
* version.
* You should have received a copy of the GNU General Public License along with
* this program; if not, see <http://www.gnu.org/licenses/>.
* Use this application at your own risk.
*
* Copyright (c) 2009 by Harald Mueller and Sofia Lemons.
*/
package android.tether;
import android.R.drawable;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.app.AlertDialog.Builder;
import android.bluetooth.BluetoothAdapter;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.SubMenu;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.ScaleAnimation;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TableRow;
import android.widget.TextView;
public class MainActivity extends Activity {
private TetherApplication application = null;
private ProgressDialog progressDialog;
private ImageView startBtn = null;
private OnClickListener startBtnListener = null;
private ImageView stopBtn = null;
private OnClickListener stopBtnListener = null;
private CompoundButton lockBtn = null;
private OnCheckedChangeListener lockBtnListener = null;
private TextView radioModeLabel = null;
private ImageView radioModeImage = null;
private TextView progressTitle = null;
private TextView progressText = null;
private ProgressBar progressBar = null;
private RelativeLayout downloadUpdateLayout = null;
private RelativeLayout batteryTemperatureLayout = null;
private CheckBox lockButtonCheckbox = null;
private RelativeLayout trafficRow = null;
private TextView downloadText = null;
private TextView uploadText = null;
private TextView downloadRateText = null;
private TextView uploadRateText = null;
private TextView batteryTemperature = null;
private TableRow startTblRow = null;
private TableRow stopTblRow = null;
private ScaleAnimation animation = null;
private static int ID_DIALOG_STARTING = 0;
private static int ID_DIALOG_STOPPING = 1;
public static final int MESSAGE_CHECK_LOG = 1;
public static final int MESSAGE_CANT_START_TETHER = 2;
public static final int MESSAGE_DOWNLOAD_STARTING = 3;
public static final int MESSAGE_DOWNLOAD_PROGRESS = 4;
public static final int MESSAGE_DOWNLOAD_COMPLETE = 5;
public static final int MESSAGE_DOWNLOAD_BLUETOOTH_COMPLETE = 6;
public static final int MESSAGE_DOWNLOAD_BLUETOOTH_FAILED = 7;
public static final int MESSAGE_TRAFFIC_START = 8;
public static final int MESSAGE_TRAFFIC_COUNT = 9;
public static final int MESSAGE_TRAFFIC_RATE = 10;
public static final int MESSAGE_TRAFFIC_END = 11;
public static final String MSG_TAG = "TETHER -> MainActivity";
public static MainActivity currentInstance = null;
private static void setCurrent(MainActivity current){
MainActivity.currentInstance = current;
}
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
Log.d(MSG_TAG, "Calling onCreate()");
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// Init Application
this.application = (TetherApplication)this.getApplication();
MainActivity.setCurrent(this);
// Init Table-Rows
this.startTblRow = (TableRow)findViewById(R.id.startRow);
this.stopTblRow = (TableRow)findViewById(R.id.stopRow);
this.radioModeImage = (ImageView)findViewById(R.id.radioModeImage);
this.progressBar = (ProgressBar)findViewById(R.id.progressBar);
this.progressText = (TextView)findViewById(R.id.progressText);
this.progressTitle = (TextView)findViewById(R.id.progressTitle);
this.downloadUpdateLayout = (RelativeLayout)findViewById(R.id.layoutDownloadUpdate);
this.batteryTemperatureLayout = (RelativeLayout)findViewById(R.id.layoutBatteryTemp);
this.lockButtonCheckbox = (CheckBox)findViewById(R.id.lockButton);
this.trafficRow = (RelativeLayout)findViewById(R.id.trafficRow);
this.downloadText = (TextView)findViewById(R.id.trafficDown);
this.uploadText = (TextView)findViewById(R.id.trafficUp);
this.downloadRateText = (TextView)findViewById(R.id.trafficDownRate);
this.uploadRateText = (TextView)findViewById(R.id.trafficUpRate);
this.batteryTemperature = (TextView)findViewById(R.id.batteryTempText);
// Define animation
animation = new ScaleAnimation(
0.9f, 1, 0.9f, 1, // From x, to x, from y, to y
ScaleAnimation.RELATIVE_TO_SELF, 0.5f,
ScaleAnimation.RELATIVE_TO_SELF, 0.5f);
animation.setDuration(600);
animation.setFillAfter(true);
animation.setStartOffset(0);
animation.setRepeatCount(1);
animation.setRepeatMode(Animation.REVERSE);
// Startup-Check
if (this.application.startupCheckPerformed == false) {
this.application.startupCheckPerformed = true;
// Check if required kernel-features are enabled
if (!this.application.coretask.isNetfilterSupported()) {
this.openNoNetfilterDialog();
this.application.accessControlSupported = false;
this.application.whitelist.remove();
}
else {
// Check if access-control-feature is supported by kernel
if (!this.application.coretask.isAccessControlSupported()) {
if (this.application.settings.getBoolean("warning_noaccesscontrol_displayed", false) == false) {
this.openNoAccessControlDialog();
this.application.preferenceEditor.putBoolean("warning_noaccesscontrol_displayed", true);
this.application.preferenceEditor.commit();
}
this.application.accessControlSupported = false;
this.application.whitelist.remove();
}
}
// Check root-permission, files
if (!this.application.coretask.hasRootPermission())
this.openNotRootDialog();
// Check if binaries need to be updated
if (this.application.binariesExists() == false || this.application.coretask.filesetOutdated()) {
if (this.application.coretask.hasRootPermission()) {
this.application.installFiles();
}
}
// Open donate-dialog
this.openDonateDialog();
// Check for updates
this.application.checkForUpdate();
}
// Start Button
this.startBtn = (ImageView) findViewById(R.id.startTetherBtn);
this.startBtnListener = new OnClickListener() {
public void onClick(View v) {
Log.d(MSG_TAG, "StartBtn pressed ...");
showDialog(MainActivity.ID_DIALOG_STARTING);
new Thread(new Runnable(){
public void run(){
boolean started = MainActivity.this.application.startTether();
MainActivity.this.dismissDialog(MainActivity.ID_DIALOG_STARTING);
Message message = Message.obtain();
if (started != true) {
message.what = MESSAGE_CANT_START_TETHER;
}
else {
// Make device discoverable if checked
if (Integer.parseInt(Build.VERSION.SDK) >= Build.VERSION_CODES.ECLAIR) {
boolean bluetoothPref = MainActivity.this.application.settings.getBoolean("bluetoothon", false);
if (bluetoothPref) {
boolean bluetoothDiscoverable = MainActivity.this.application.settings.getBoolean("bluetoothdiscoverable", false);
if (bluetoothDiscoverable) {
MainActivity.this.makeDiscoverable();
}
}
}
try {
Thread.sleep(400);
} catch (InterruptedException e) {
// Taking a small nap
}
String wifiStatus = MainActivity.this.application.coretask.getProp("tether.status");
if (wifiStatus.equals("running") == false) {
message.what = MESSAGE_CHECK_LOG;
}
}
MainActivity.this.viewUpdateHandler.sendMessage(message);
}
}).start();
}
};
this.startBtn.setOnClickListener(this.startBtnListener);
// Stop Button
this.stopBtn = (ImageView) findViewById(R.id.stopTetherBtn);
this.stopBtnListener = new OnClickListener() {
public void onClick(View v) {
Log.d(MSG_TAG, "StopBtn pressed ...");
if (MainActivity.this.lockBtn.isChecked()){
Log.d(MSG_TAG, "Tether was locked ...");
MainActivity.this.application.displayToastMessage(getString(R.string.main_activity_locked));
return;
}
showDialog(MainActivity.ID_DIALOG_STOPPING);
new Thread(new Runnable(){
public void run(){
MainActivity.this.application.stopTether();
MainActivity.this.dismissDialog(MainActivity.ID_DIALOG_STOPPING);
MainActivity.this.viewUpdateHandler.sendMessage(new Message());
}
}).start();
}
};
this.stopBtn.setOnClickListener(this.stopBtnListener);
this.lockBtn = (CompoundButton) findViewById(R.id.lockButton);
this.lockBtnListener = new OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
Log.d(MSG_TAG, "LockBtn pressed ...");
}
};
this.lockBtn.setOnCheckedChangeListener(this.lockBtnListener);
// Toggles between start and stop screen
this.toggleStartStop();
}
@Override
public boolean onTrackballEvent(MotionEvent event){
if (event.getAction() == MotionEvent.ACTION_DOWN){
Log.d(MSG_TAG, "Trackball pressed ...");
String tetherStatus = this.application.coretask.getProp("tether.status");
if (!tetherStatus.equals("running")){
new AlertDialog.Builder(this)
.setMessage(getString(R.string.main_activity_trackball_pressed_start))
.setPositiveButton(getString(R.string.main_activity_confirm), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Log.d(MSG_TAG, "Trackball press confirmed ...");
MainActivity.currentInstance.startBtnListener.onClick(MainActivity.currentInstance.startBtn);
}
})
.setNegativeButton(getString(R.string.main_activity_cancel), null)
.show();
}
else{
if (MainActivity.this.lockBtn.isChecked()){
Log.d(MSG_TAG, "Tether was locked ...");
MainActivity.this.application.displayToastMessage(getString(R.string.main_activity_locked));
return false;
}
new AlertDialog.Builder(this)
.setMessage(getString(R.string.main_activity_trackball_pressed_stop))
.setPositiveButton(getString(R.string.main_activity_confirm), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Log.d(MSG_TAG, "Trackball press confirmed ...");
MainActivity.currentInstance.stopBtnListener.onClick(MainActivity.currentInstance.startBtn);
}
})
.setNegativeButton(getString(R.string.main_activity_cancel), null)
.show();
}
}
return true;
}
public void onStop() {
Log.d(MSG_TAG, "Calling onStop()");
super.onStop();
}
public void onDestroy() {
Log.d(MSG_TAG, "Calling onDestroy()");
super.onDestroy();
try {
unregisterReceiver(this.intentReceiver);
} catch (Exception ex) {;}
}
public void onResume() {
Log.d(MSG_TAG, "Calling onResume()");
this.showRadioMode();
super.onResume();
// Check, if the battery-temperatur should be displayed
if(this.application.settings.getString("batterytemppref", "celsius").equals("disabled") == false) {
// create the IntentFilter that will be used to listen
// to battery status broadcasts
this.intentFilter = new IntentFilter();
this.intentFilter.addAction(Intent.ACTION_BATTERY_CHANGED);
registerReceiver(this.intentReceiver, this.intentFilter);
this.batteryTemperatureLayout.setVisibility(View.VISIBLE);
}
else {
try {
unregisterReceiver(this.intentReceiver);
} catch (Exception ex) {;}
this.batteryTemperatureLayout.setVisibility(View.INVISIBLE);
}
// Check, if the lockbutton should be displayed
if (this.stopTblRow.getVisibility() == View.VISIBLE &&
this.application.settings.getBoolean("lockscreenpref", true) == false) {
this.lockButtonCheckbox.setVisibility(View.VISIBLE);
}
else {
this.lockButtonCheckbox.setVisibility(View.GONE);
}
}
private static final int MENU_SETUP = 0;
private static final int MENU_LOG = 1;
private static final int MENU_ABOUT = 2;
private static final int MENU_ACCESS = 3;
@Override
public boolean onCreateOptionsMenu(Menu menu) {
boolean supRetVal = super.onCreateOptionsMenu(menu);
SubMenu setup = menu.addSubMenu(0, MENU_SETUP, 0, getString(R.string.main_activity_settings));
setup.setIcon(drawable.ic_menu_preferences);
if (this.application.accessControlSupported) {
SubMenu accessctr = menu.addSubMenu(0, MENU_ACCESS, 0, getString(R.string.main_activity_accesscontrol));
accessctr.setIcon(drawable.ic_menu_manage);
}
SubMenu log = menu.addSubMenu(0, MENU_LOG, 0, getString(R.string.main_activity_showlog));
log.setIcon(drawable.ic_menu_agenda);
SubMenu about = menu.addSubMenu(0, MENU_ABOUT, 0, getString(R.string.main_activity_about));
about.setIcon(drawable.ic_menu_info_details);
return supRetVal;
}
@Override
public boolean onOptionsItemSelected(MenuItem menuItem) {
boolean supRetVal = super.onOptionsItemSelected(menuItem);
Log.d(MSG_TAG, "Menuitem:getId - " menuItem.getItemId());
switch (menuItem.getItemId()) {
case MENU_SETUP :
startActivityForResult(new Intent(
MainActivity.this, SetupActivity.class), 0);
break;
case MENU_LOG :
startActivityForResult(new Intent(
MainActivity.this, LogActivity.class), 0);
break;
case MENU_ABOUT :
this.openAboutDialog();
break;
case MENU_ACCESS :
startActivityForResult(new Intent(
MainActivity.this, AccessControlActivity.class), 0);
}
return supRetVal;
}
@Override
protected Dialog onCreateDialog(int id) {
if (id == ID_DIALOG_STARTING) {
progressDialog = new ProgressDialog(this);
progressDialog.setTitle(getString(R.string.main_activity_start));
progressDialog.setMessage(getString(R.string.main_activity_start_summary));
progressDialog.setIndeterminate(false);
progressDialog.setCancelable(true);
return progressDialog;
}
else if (id == ID_DIALOG_STOPPING) {
progressDialog = new ProgressDialog(this);
progressDialog.setTitle(getString(R.string.main_activity_stop));
progressDialog.setMessage(getString(R.string.main_activity_stop_summary));
progressDialog.setIndeterminate(false);
progressDialog.setCancelable(true);
return progressDialog;
}
return null;
}
/**
*Listens for intent broadcasts; Needed for the temperature-display
*/
private IntentFilter intentFilter;
private BroadcastReceiver intentReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (action.equals(Intent.ACTION_BATTERY_CHANGED)) {
int temp = (intent.getIntExtra("temperature", 0));
int celsius = (int)((temp 5)/10);
int fahrenheit = (int)(((temp/10)/0.555) 32 0.5);
Log.d(MSG_TAG, "Temp ==> " temp " -- Celsius ==> " celsius " -- Fahrenheit ==> " fahrenheit);
if (MainActivity.this.application.settings.getString("batterytemppref", "celsius").equals("celsius")) {
batteryTemperature.setText("" celsius getString(R.string.main_activity_temperatureunit_celsius));
}
else {
batteryTemperature.setText("" fahrenheit getString(R.string.main_activity_temperatureunit_fahrenheit));
}
}
}
};
public Handler viewUpdateHandler = new Handler(){
public void handleMessage(Message msg) {
switch(msg.what) {
case MESSAGE_CHECK_LOG :
Log.d(MSG_TAG, "Error detected. Check log.");
MainActivity.this.application.displayToastMessage(getString(R.string.main_activity_start_errors));
MainActivity.this.toggleStartStop();
break;
case MESSAGE_CANT_START_TETHER :
Log.d(MSG_TAG, "Unable to start tethering!");
MainActivity.this.application.displayToastMessage(getString(R.string.main_activity_start_unable));
MainActivity.this.toggleStartStop();
break;
case MESSAGE_TRAFFIC_START :
MainActivity.this.trafficRow.setVisibility(View.VISIBLE);
break;
case MESSAGE_TRAFFIC_COUNT :
MainActivity.this.trafficRow.setVisibility(View.VISIBLE);
long uploadTraffic = ((TetherApplication.DataCount)msg.obj).totalUpload;
long downloadTraffic = ((TetherApplication.DataCount)msg.obj).totalDownload;
long uploadRate = ((TetherApplication.DataCount)msg.obj).uploadRate;
long downloadRate = ((TetherApplication.DataCount)msg.obj).downloadRate;
// Set rates to 0 if values are negative
if (uploadRate < 0)
uploadRate = 0;
if (downloadRate < 0)
downloadRate = 0;
MainActivity.this.uploadText.setText(MainActivity.this.formatCount(uploadTraffic, false));
MainActivity.this.downloadText.setText(MainActivity.this.formatCount(downloadTraffic, false));
MainActivity.this.downloadText.invalidate();
MainActivity.this.uploadText.invalidate();
MainActivity.this.uploadRateText.setText(MainActivity.this.formatCount(uploadRate, true));
MainActivity.this.downloadRateText.setText(MainActivity.this.formatCount(downloadRate, true));
MainActivity.this.downloadRateText.invalidate();
MainActivity.this.uploadRateText.invalidate();
break;
case MESSAGE_TRAFFIC_END :
MainActivity.this.trafficRow.setVisibility(View.INVISIBLE);
break;
case MESSAGE_DOWNLOAD_STARTING :
Log.d(MSG_TAG, "Start progress bar");
MainActivity.this.progressBar.setIndeterminate(true);
MainActivity.this.progressTitle.setText((String)msg.obj);
MainActivity.this.progressText.setText("Starting...");
MainActivity.this.downloadUpdateLayout.setVisibility(View.VISIBLE);
break;
case MESSAGE_DOWNLOAD_PROGRESS :
MainActivity.this.progressBar.setIndeterminate(false);
MainActivity.this.progressText.setText(msg.arg1 "k /" msg.arg2 "k");
MainActivity.this.progressBar.setProgress(msg.arg1*100/msg.arg2);
break;
case MESSAGE_DOWNLOAD_COMPLETE :
Log.d(MSG_TAG, "Finished download.");
MainActivity.this.progressText.setText("");
MainActivity.this.progressTitle.setText("");
MainActivity.this.downloadUpdateLayout.setVisibility(View.GONE);
break;
case MESSAGE_DOWNLOAD_BLUETOOTH_COMPLETE :
Log.d(MSG_TAG, "Finished bluetooth download.");
MainActivity.this.startBtn.setClickable(true);
MainActivity.this.radioModeLabel.setText("Bluetooth");
break;
case MESSAGE_DOWNLOAD_BLUETOOTH_FAILED :
Log.d(MSG_TAG, "FAILED bluetooth download.");
MainActivity.this.startBtn.setClickable(true);
MainActivity.this.application.preferenceEditor.putBoolean("bluetoothon", false);
MainActivity.this.application.preferenceEditor.commit();
// TODO: More detailed popup info.
MainActivity.this.application.displayToastMessage("No bluetooth module for your kernel! Please report your kernel version.");
default:
MainActivity.this.toggleStartStop();
}
super.handleMessage(msg);
}
};
private void makeDiscoverable() {
Log.d(MSG_TAG, "Making device discoverable ...");
Intent discoverableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
discoverableIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 120);
startActivity(discoverableIntent);
}
private void toggleStartStop() {
boolean dnsmasqRunning = false;
boolean pandRunning = false;
try {
dnsmasqRunning = this.application.coretask.isProcessRunning("bin/dnsmasq");
} catch (Exception e) {
MainActivity.this.application.displayToastMessage("Unable to check if dnsmasq is currently running!");
}
try {
pandRunning = this.application.coretask.isProcessRunning("bin/pand");
} catch (Exception e) {
MainActivity.this.application.displayToastMessage("Unable to check if pand is currently running!");
}
boolean natEnabled = this.application.coretask.isNatEnabled();
boolean usingBluetooth = this.application.settings.getBoolean("bluetoothon", false);
if ((dnsmasqRunning == true && natEnabled == true) ||
(usingBluetooth == true && pandRunning == true)){
this.startTblRow.setVisibility(View.GONE);
this.stopTblRow.setVisibility(View.VISIBLE);
// Animation
if (this.animation != null)
this.stopBtn.startAnimation(this.animation);
// Checking, if "wired tether" is currently running
String tetherMode = this.application.coretask.getProp("tether.mode");
String tetherStatus = this.application.coretask.getProp("tether.status");
if (tetherStatus.equals("running")) {
if (!(tetherMode.equals("wifi") == true || tetherMode.equals("bt") == true)) {
MainActivity.this.application.displayToastMessage(getString(R.string.main_activity_start_wiredtethering_running));
}
}
// Checking, if cyanogens usb-tether is currently running
tetherStatus = this.application.coretask.getProp("tethering.enabled");
if (tetherStatus.equals("1")) {
MainActivity.this.application.displayToastMessage(getString(R.string.main_activity_start_usbtethering_running));
}
this.application.trafficCounterEnable(true);
this.application.clientConnectEnable(true);
this.application.dnsUpdateEnable(true);
this.application.showStartNotification();
// Check, if the lockbutton should be displayed
if (MainActivity.this.application.settings.getBoolean("lockscreenpref", true) == false) {
MainActivity.this.lockButtonCheckbox.setVisibility(View.VISIBLE);
}
}
else if (dnsmasqRunning == false && natEnabled == false) {
this.startTblRow.setVisibility(View.VISIBLE);
this.stopTblRow.setVisibility(View.GONE);
this.application.trafficCounterEnable(false);
// Animation
if (this.animation != null)
this.startBtn.startAnimation(this.animation);
// Notification
this.application.notificationManager.cancelAll();
// Check, if the lockbutton should be displayed
MainActivity.this.lockButtonCheckbox.setVisibility(View.GONE);
}
else {
this.startTblRow.setVisibility(View.VISIBLE);
this.stopTblRow.setVisibility(View.VISIBLE);
MainActivity.this.application.displayToastMessage(getString(R.string.main_activity_start_unknownstate));
}
this.showRadioMode();
System.gc();
}
private String formatCount(long count, boolean rate) {
// Converts the supplied argument into a string.
// 'rate' indicates whether is a total bytes, or bits per sec.
// Under 2Mb, returns "xxx.xKb"
// Over 2Mb, returns "xxx.xxMb"
if (count < 1e6 * 2)
return ((float)((int)(count*10/1024))/10 (rate ? "kbps" : "kB"));
return ((float)((int)(count*100/1024/1024))/100 (rate ? "mbps" : "MB"));
}
private void openNoNetfilterDialog() {
LayoutInflater li = LayoutInflater.from(this);
View view = li.inflate(R.layout.nonetfilterview, null);
new AlertDialog.Builder(MainActivity.this)
.setTitle(getString(R.string.main_activity_nonetfilter))
.setView(view)
.setNegativeButton(getString(R.string.main_activity_exit), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
Log.d(MSG_TAG, "Close pressed");
MainActivity.this.finish();
}
})
.setNeutralButton(getString(R.string.main_activity_ignore), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
Log.d(MSG_TAG, "Override pressed");
MainActivity.this.application.displayToastMessage("Ignoring, note that this application will NOT work correctly.");
}
})
.show();
}
private void openNoAccessControlDialog() {
LayoutInflater li = LayoutInflater.from(this);
View view = li.inflate(R.layout.noaccesscontrolview, null);
new AlertDialog.Builder(MainActivity.this)
.setTitle(getString(R.string.main_activity_noaccesscontrol))
.setView(view)
.setNeutralButton(getString(R.string.main_activity_ok), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
Log.d(MSG_TAG, "OK pressed");
MainActivity.this.application.displayToastMessage(getString(R.string.main_activity_accesscontrol_disabled));
}
})
.show();
}
private void openNotRootDialog() {
LayoutInflater li = LayoutInflater.from(this);
View view = li.inflate(R.layout.norootview, null);
new AlertDialog.Builder(MainActivity.this)
.setTitle(getString(R.string.main_activity_notroot))
.setView(view)
.setNegativeButton(getString(R.string.main_activity_exit), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
Log.d(MSG_TAG, "Exit pressed");
MainActivity.this.finish();
}
})
.setNeutralButton(getString(R.string.main_activity_ignore), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
Log.d(MSG_TAG, "Ignore pressed");
MainActivity.this.application.installFiles();
MainActivity.this.application.displayToastMessage("Ignoring, note that this application will NOT work correctly.");
}
})
.show();
}
private void openAboutDialog() {
LayoutInflater li = LayoutInflater.from(this);
View view = li.inflate(R.layout.aboutview, null);
TextView versionName = (TextView)view.findViewById(R.id.versionName);
versionName.setText(this.application.getVersionName());
new AlertDialog.Builder(MainActivity.this)
.setTitle(getString(R.string.main_activity_about))
.setView(view)
.setNeutralButton(getString(R.string.main_activity_donate), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
Log.d(MSG_TAG, "Donate pressed");
Uri uri = Uri.parse(getString(R.string.paypalUrl));
startActivity(new Intent(Intent.ACTION_VIEW, uri));
}
})
.setNegativeButton(getString(R.string.main_activity_close), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
Log.d(MSG_TAG, "Close pressed");
}
})
.show();
}
private void openDonateDialog() {
if (this.application.showDonationDialog()) {
// Disable donate-dialog for later startups
this.application.preferenceEditor.putBoolean("donatepref", false);
this.application.preferenceEditor.commit();
// Creating Layout
LayoutInflater li = LayoutInflater.from(this);
View view = li.inflate(R.layout.donateview, null);
new AlertDialog.Builder(MainActivity.this)
.setTitle(getString(R.string.main_activity_donate))
.setView(view)
.setNeutralButton(getString(R.string.main_activity_close), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
Log.d(MSG_TAG, "Close pressed");
}
})
.setNegativeButton(getString(R.string.main_activity_donate), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
Log.d(MSG_TAG, "Donate pressed");
Uri uri = Uri.parse(getString(R.string.paypalUrl));
startActivity(new Intent(Intent.ACTION_VIEW, uri));
}
})
.show();
}
}
private void showRadioMode() {
boolean usingBluetooth = this.application.settings.getBoolean("bluetoothon", false);
if (usingBluetooth) {
this.radioModeImage.setImageResource(R.drawable.bluetooth);
} else {
this.radioModeImage.setImageResource(R.drawable.wifi);
}
}
public void openUpdateDialog(final String downloadFileUrl, final String fileName, final String message,
final String updateTitle) {
LayoutInflater li = LayoutInflater.from(this);
Builder dialog;
View view;
view = li.inflate(R.layout.updateview, null);
TextView messageView = (TextView) view.findViewById(R.id.updateMessage);
TextView updateNowText = (TextView) view.findViewById(R.id.updateNowText);
if (fileName.length() == 0) // No filename, hide 'download now?' string
updateNowText.setVisibility(View.GONE);
messageView.setText(message);
dialog = new AlertDialog.Builder(MainActivity.this)
.setTitle(updateTitle)
.setView(view);
if (fileName.length() > 0) {
// Display Yes/No for if a filename is available.
dialog.setNeutralButton(getString(R.string.main_activity_no), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
Log.d(MSG_TAG, "No pressed");
}
});
dialog.setNegativeButton(getString(R.string.main_activity_yes), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
Log.d(MSG_TAG, "Yes pressed");
MainActivity.this.application.downloadUpdate(downloadFileUrl, fileName);
}
});
} else
dialog.setNeutralButton(getString(R.string.main_activity_ok), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
Log.d(MSG_TAG, "Ok pressed");
}
});
dialog.show();
}
}
资源文件列表
wifi┤½╦═ android/TehterTest.apk , 335039
wifi┤½╦═ android/android_wifi_tether/.classpath , 280
wifi┤½╦═ android/android_wifi_tether/.project , 845
wifi┤½╦═ android/android_wifi_tether/.settings/.svn/all-wcprops , 202
wifi┤½╦═ android/android_wifi_tether/.settings/.svn/entries , 387
wifi┤½╦═ android/android_wifi_tether/.settings/.svn/prop-base/org.eclipse.jdt.core.prefs.svn-base , 39
wifi┤½╦═ android/android_wifi_tether/.settings/.svn/text-base/org.eclipse.jdt.core.prefs.svn-base , 203
wifi┤½╦═ android/android_wifi_tether/.settings/org.eclipse.jdt.core.prefs , 203
wifi┤½╦═ android/android_wifi_tether/.svn/all-wcprops , 605
wifi┤½╦═ android/android_wifi_tether/.svn/dir-prop-base , 77
wifi┤½╦═ android/android_wifi_tether/.svn/entries , 1225
wifi┤½╦═ android/android_wifi_tether/.svn/text-base/.classpath.svn-base , 280
wifi┤½╦═ android/android_wifi_tether/.svn/text-base/.project.svn-base , 845
wifi┤½╦═ android/android_wifi_tether/.svn/text-base/AndroidManifest.xml.svn-base , 2019
wifi┤½╦═ android/android_wifi_tether/.svn/text-base/GPLV3.TXT.svn-base , 35802
wifi┤½╦═ android/android_wifi_tether/.svn/text-base/README.TXT.svn-base , 1037
wifi┤½╦═ android/android_wifi_tether/.svn/text-base/default.properties.svn-base , 469
wifi┤½╦═ android/android_wifi_tether/AndroidManifest.xml , 2019
wifi┤½╦═ android/android_wifi_tether/GPLV3.TXT , 35802
wifi┤½╦═ android/android_wifi_tether/README.TXT , 1037
wifi┤½╦═ android/android_wifi_tether/bin/.svn/all-wcprops , 68
wifi┤½╦═ android/android_wifi_tether/bin/.svn/entries , 237
wifi┤½╦═ android/android_wifi_tether/bin/android/.svn/all-wcprops , 76
wifi┤½╦═ android/android_wifi_tether/bin/android/.svn/entries , 244
wifi┤½╦═ android/android_wifi_tether/bin/android/tether/.svn/all-wcprops , 706
wifi┤½╦═ android/android_wifi_tether/bin/android/tether/.svn/entries , 1067
wifi┤½╦═ android/android_wifi_tether/bin/android/tether/.svn/text-base/AccessControlActivity.java.svn-base , 10691
wifi┤½╦═ android/android_wifi_tether/bin/android/tether/.svn/text-base/LogActivity.java.svn-base , 3460
wifi┤½╦═ android/android_wifi_tether/bin/android/tether/.svn/text-base/MainActivity.java.svn-base , 32995
wifi┤½╦═ android/android_wifi_tether/bin/android/tether/.svn/text-base/SetupActivity.java.svn-base , 27569
wifi┤½╦═ android/android_wifi_tether/bin/android/tether/.svn/text-base/TetherApplication.java.svn-base , 45698
wifi┤½╦═ android/android_wifi_tether/bin/android/tether/AccessControlActivity$1.class , 716
wifi┤½╦═ android/android_wifi_tether/bin/android/tether/AccessControlActivity$2.class , 2537
wifi┤½╦═ android/android_wifi_tether/bin/android/tether/AccessControlActivity$3.class , 1386
wifi┤½╦═ android/android_wifi_tether/bin/android/tether/AccessControlActivity$4.class , 2367
wifi┤½╦═ android/android_wifi_tether/bin/android/tether/AccessControlActivity.class , 8414
wifi┤½╦═ android/android_wifi_tether/bin/android/tether/LogActivity.class , 3543
wifi┤½╦═ android/android_wifi_tether/bin/android/tether/MainActivity$1.class , 2237
wifi┤½╦═ android/android_wifi_tether/bin/android/tether/MainActivity$10.class , 1224
wifi┤½╦═ android/android_wifi_tether/bin/android/tether/MainActivity$11.class , 991
wifi┤½╦═ android/android_wifi_tether/bin/android/tether/MainActivity$12.class , 1268
wifi┤½╦═ android/android_wifi_tether/bin/android/tether/MainActivity$13.class , 1332
wifi┤½╦═ android/android_wifi_tether/bin/android/tether/MainActivity$14.class , 960
wifi┤½╦═ android/android_wifi_tether/bin/android/tether/MainActivity$15.class , 961
wifi┤½╦═ android/android_wifi_tether/bin/android/tether/MainActivity$16.class , 1333
wifi┤½╦═ android/android_wifi_tether/bin/android/tether/MainActivity$17.class , 1036
wifi┤½╦═ android/android_wifi_tether/bin/android/tether/MainActivity$18.class , 1395
wifi┤½╦═ android/android_wifi_tether/bin/android/tether/MainActivity$19.class , 1036
wifi┤½╦═ android/android_wifi_tether/bin/android/tether/MainActivity$2.class , 3984
wifi┤½╦═ android/android_wifi_tether/bin/android/tether/MainActivity$3$1.class , 2344
wifi┤½╦═ android/android_wifi_tether/bin/android/tether/MainActivity$3.class , 1286
wifi┤½╦═ android/android_wifi_tether/bin/android/tether/MainActivity$4$1.class , 1178
wifi┤½╦═ android/android_wifi_tether/bin/android/tether/MainActivity$4.class , 1742
wifi┤½╦═ android/android_wifi_tether/bin/android/tether/MainActivity$5.class , 1001
wifi┤½╦═ android/android_wifi_tether/bin/android/tether/MainActivity$6.class , 1328
wifi┤½╦═ android/android_wifi_tether/bin/android/tether/MainActivity$7.class , 1328
wifi┤½╦═ android/android_wifi_tether/bin/android/tether/MainActivity$8.class , 994
wifi┤½╦═ android/android_wifi_tether/bin/android/tether/MainActivity$9.class , 1233
wifi┤½╦═ android/android_wifi_tether/bin/android/tether/MainActivity.class , 18575
wifi┤½╦═ android/android_wifi_tether/bin/android/tether/R$array.class , 819
wifi┤½╦═ android/android_wifi_tether/bin/android/tether/R$attr.class , 328
wifi┤½╦═ android/android_wifi_tether/bin/android/tether/R$drawable.class , 804
wifi┤½╦═ android/android_wifi_tether/bin/android/tether/R$id.class , 1988
wifi┤½╦═ android/android_wifi_tether/bin/android/tether/R$layout.class , 816
wifi┤½╦═ android/android_wifi_tether/bin/android/tether/R$raw.class , 981
wifi┤½╦═ android/android_wifi_tether/bin/android/tether/R$string.class , 8739
wifi┤½╦═ android/android_wifi_tether/bin/android/tether/R.class , 587
wifi┤½╦═ android/android_wifi_tether/bin/android/tether/SetupActivity$1.class , 869
wifi┤½╦═ android/android_wifi_tether/bin/android/tether/SetupActivity$2.class , 998
wifi┤½╦═ android/android_wifi_tether/bin/android/tether/SetupActivity$3.class , 971
wifi┤½╦═ android/android_wifi_tether/bin/android/tether/SetupActivity$4.class , 1362
wifi┤½╦═ android/android_wifi_tether/bin/android/tether/SetupActivity$5.class , 1475
wifi┤½╦═ android/android_wifi_tether/bin/android/tether/SetupActivity$6.class , 1649
wifi┤½╦═ android/android_wifi_tether/bin/android/tether/SetupActivity$7.class , 1464
wifi┤½╦═ android/android_wifi_tether/bin/android/tether/SetupActivity$8.class , 1594
wifi┤½╦═ android/android_wifi_tether/bin/android/tether/SetupActivity$9$1.class , 1584
wifi┤½╦═ android/android_wifi_tether/bin/android/tether/SetupActivity$9$2.class , 1579
wifi┤½╦═ android/android_wifi_tether/bin/android/tether/SetupActivity$9.class , 8333
wifi┤½╦═ android/android_wifi_tether/bin/android/tether/SetupActivity.class , 11201
wifi┤½╦═ android/android_wifi_tether/bin/android/tether/TetherApplication$1.class , 945
wifi┤½╦═ android/android_wifi_tether/bin/android/tether/TetherApplication$2.class , 847
wifi┤½╦═ android/android_wifi_tether/bin/android/tether/TetherApplication$3.class , 2993
wifi┤½╦═ android/android_wifi_tether/bin/android/tether/TetherApplication$4.class , 2430
wifi┤½╦═ android/android_wifi_tether/bin/android/tether/TetherApplication$5.class , 2139
wifi┤½╦═ android/android_wifi_tether/bin/android/tether/TetherApplication$ClientConnect.class , 5067
wifi┤½╦═ android/android_wifi_tether/bin/android/tether/TetherApplication$DataCount.class , 610
wifi┤½╦═ android/android_wifi_tether/bin/android/tether/TetherApplication$DnsUpdate.class , 1326
wifi┤½╦═ android/android_wifi_tether/bin/android/tether/TetherApplication$TrafficCounter.class , 2435
wifi┤½╦═ android/android_wifi_tether/bin/android/tether/TetherApplication.class , 23549
wifi┤½╦═ android/android_wifi_tether/bin/android/tether/data/.svn/all-wcprops , 334
wifi┤½╦═ android/android_wifi_tether/bin/android/tether/data/.svn/entries , 538
wifi┤½╦═ android/android_wifi_tether/bin/android/tether/data/.svn/text-base/ClientAdapter.java.svn-base , 5218
wifi┤½╦═ android/android_wifi_tether/bin/android/tether/data/.svn/text-base/ClientData.java.svn-base , 1685
wifi┤½╦═ android/android_wifi_tether/bin/android/tether/data/ClientAdapter$1.class , 1028
wifi┤½╦═ android/android_wifi_tether/bin/android/tether/data/ClientAdapter.class , 5483
wifi┤½╦═ android/android_wifi_tether/bin/android/tether/data/ClientData.class , 1646
wifi┤½╦═ android/android_wifi_tether/bin/android/tether/system/.svn/all-wcprops , 1020
wifi┤½╦═ android/android_wifi_tether/bin/android/tether/system/.svn/entries , 1398
wifi┤½╦═ android/android_wifi_tether/bin/android/tether/system/.svn/text-base/BluetoothService.java.svn-base , 1148
wifi┤½╦═ android/android_wifi_tether/bin/android/tether/system/.svn/text-base/BluetoothService_cupcake.java.svn-base , 1798
wifi┤½╦═ android/android_wifi_tether/bin/android/tether/system/.svn/text-base/BluetoothService_eclair.java.svn-base , 1321
wifi┤½╦═ android/android_wifi_tether/bin/android/tether/system/.svn/text-base/Configuration.java.svn-base , 5714
wifi┤½╦═ android/android_wifi_tether/bin/android/tether/system/.svn/text-base/CoreTask.java.svn-base , 22315
wifi┤½╦═ android/android_wifi_tether/bin/android/tether/system/.svn/text-base/NativeTask.java.svn-base , 550
wifi┤½╦═ android/android_wifi_tether/bin/android/tether/system/.svn/text-base/WebserviceTask.java.svn-base , 5786
wifi┤½╦═ android/android_wifi_tether/bin/android/tether/system/BluetoothService.class , 1538
wifi┤½╦═ android/android_wifi_tether/bin/android/tether/system/BluetoothService_cupcake.class , 2053
wifi┤½╦═ android/android_wifi_tether/bin/android/tether/system/BluetoothService_eclair.class , 1273
wifi┤½╦═ android/android_wifi_tether/bin/android/tether/system/Configuration.class , 4326
wifi┤½╦═ android/android_wifi_tether/bin/android/tether/system/CoreTask$1.class , 942
wifi┤½╦═ android/android_wifi_tether/bin/android/tether/system/CoreTask$BluetoothConfig.class , 2626
wifi┤½╦═ android/android_wifi_tether/bin/android/tether/system/CoreTask$DnsmasqConfig.class , 2413
wifi┤½╦═ android/android_wifi_tether/bin/android/tether/system/CoreTask$HostapdConfig.class , 2334
wifi┤½╦═ android/android_wifi_tether/bin/android/tether/system/CoreTask$TetherConfig.class , 2330
wifi┤½╦═ android/android_wifi_tether/bin/android/tether/system/CoreTask$TiWlanConf.class , 3009
wifi┤½╦═ android/android_wifi_tether/bin/android/tether/system/CoreTask$Whitelist.class , 2465
wifi┤½╦═ android/android_wifi_tether/bin/android/tether/system/CoreTask$WpaSupplicant.class , 3205
wifi┤½╦═ android/android_wifi_tether/bin/android/tether/system/CoreTask.class , 12741
wifi┤½╦═ android/android_wifi_tether/bin/android/tether/system/NativeTask.class , 938
wifi┤½╦═ android/android_wifi_tether/bin/android/tether/system/WebserviceTask.class , 5395
wifi┤½╦═ android/android_wifi_tether/bin/android_wifi_tether.apk , 410933
wifi┤½╦═ android/android_wifi_tether/bin/classes.dex , 118852
wifi┤½╦═ android/android_wifi_tether/bin/resources.ap_ , 349432
wifi┤½╦═ android/android_wifi_tether/default.properties , 469
wifi┤½╦═ android/android_wifi_tether/gen/android/tether/R.java , 18438
wifi┤½╦═ android/android_wifi_tether/jni/.svn/all-wcprops , 434
wifi┤½╦═ android/android_wifi_tether/jni/.svn/entries , 755
wifi┤½╦═ android/android_wifi_tether/jni/.svn/text-base/Android.mk.svn-base , 218
wifi┤½╦═ android/android_wifi_tether/jni/.svn/text-base/android_tether_system_NativeTask.c.svn-base , 1469
wifi┤½╦═ android/android_wifi_tether/jni/.svn/text-base/android_tether_system_NativeTask.h.svn-base , 785
wifi┤½╦═ android/android_wifi_tether/jni/Android.mk , 218
wifi┤½╦═ android/android_wifi_tether/jni/android_tether_system_NativeTask.c , 1469
wifi┤½╦═ android/android_wifi_tether/jni/android_tether_system_NativeTask.h , 785
wifi┤½╦═ android/android_wifi_tether/libs/.svn/all-wcprops , 69
wifi┤½╦═ android/android_wifi_tether/libs/.svn/entries , 238
wifi┤½╦═ android/android_wifi_tether/libs/armeabi/.svn/all-wcprops , 188
wifi┤½╦═ android/android_wifi_tether/libs/armeabi/.svn/entries , 410
wifi┤½╦═ android/android_wifi_tether/libs/armeabi/.svn/prop-base/libnativetask.so.svn-base , 53
wifi┤½╦═ android/android_wifi_tether/libs/armeabi/.svn/text-base/libnativetask.so.svn-base , 14300
wifi┤½╦═ android/android_wifi_tether/libs/armeabi/libnativetask.so , 14300
wifi┤½╦═ android/android_wifi_tether/native/.svn/all-wcprops , 71
wifi┤½╦═ android/android_wifi_tether/native/.svn/entries , 260
wifi┤½╦═ android/android_wifi_tether/native/ifconfig/.svn/all-wcprops , 284
wifi┤½╦═ android/android_wifi_tether/native/ifconfig/.svn/entries , 528
wifi┤½╦═ android/android_wifi_tether/native/ifconfig/.svn/text-base/Android.mk.svn-base , 248
wifi┤½╦═ android/android_wifi_tether/native/ifconfig/.svn/text-base/ifconfig.c.svn-base , 4973
wifi┤½╦═ android/android_wifi_tether/native/ifconfig/Android.mk , 248
wifi┤½╦═ android/android_wifi_tether/native/ifconfig/ifconfig.c , 4973
wifi┤½╦═ android/android_wifi_tether/native/tether-edify/.svn/all-wcprops , 602
wifi┤½╦═ android/android_wifi_tether/native/tether-edify/.svn/entries , 984
wifi┤½╦═ android/android_wifi_tether/native/tether-edify/.svn/text-base/Android.mk.svn-base , 381
最多只能显示150条信息!
