实例介绍
【实例简介】
【实例截图】
【核心代码】
/**
* 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();
}
}
好例子网口号:伸出你的我的手 — 分享!
相关软件
小贴士
感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。
- 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
- 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
- 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
- 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。
关于好例子网
本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明


网友评论
我要评论