support landscape layout and new Share intent
- when device is landscape, the log will show on the main screen - Orbot v12 includes a new simple share service for HS based file sharing
This commit is contained in:
parent
7df2acd59c
commit
21c27972d9
|
@ -4,12 +4,15 @@
|
||||||
package org.torproject.android;
|
package org.torproject.android;
|
||||||
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
import java.util.StringTokenizer;
|
||||||
|
|
||||||
import org.torproject.android.service.ITorService;
|
import org.torproject.android.service.ITorService;
|
||||||
import org.torproject.android.service.ITorServiceCallback;
|
import org.torproject.android.service.ITorServiceCallback;
|
||||||
import org.torproject.android.service.TorServiceConstants;
|
import org.torproject.android.service.TorServiceConstants;
|
||||||
import org.torproject.android.settings.ProcessSettingsAsyncTask;
|
import org.torproject.android.settings.ProcessSettingsAsyncTask;
|
||||||
import org.torproject.android.settings.SettingsPreferences;
|
import org.torproject.android.settings.SettingsPreferences;
|
||||||
|
import org.torproject.android.share.ShareItem;
|
||||||
|
import org.torproject.android.share.ShareService;
|
||||||
import org.torproject.android.wizard.ChooseLocaleWizardActivity;
|
import org.torproject.android.wizard.ChooseLocaleWizardActivity;
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
|
@ -71,7 +74,7 @@ public class Orbot extends SherlockActivity implements TorConstants, OnLongClick
|
||||||
/* Tor Service interaction */
|
/* Tor Service interaction */
|
||||||
/* The primary interface we will be calling on the service. */
|
/* The primary interface we will be calling on the service. */
|
||||||
ITorService mService = null;
|
ITorService mService = null;
|
||||||
private boolean autoStartOnBind = false;
|
private boolean autoStartFromIntent = false;
|
||||||
|
|
||||||
SharedPreferences prefs;
|
SharedPreferences prefs;
|
||||||
|
|
||||||
|
@ -109,6 +112,12 @@ public class Orbot extends SherlockActivity implements TorConstants, OnLongClick
|
||||||
|
|
||||||
prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void doLayout ()
|
||||||
|
{
|
||||||
setContentView(R.layout.layout_main);
|
setContentView(R.layout.layout_main);
|
||||||
|
|
||||||
lblStatus = (TextView)findViewById(R.id.lblStatus);
|
lblStatus = (TextView)findViewById(R.id.lblStatus);
|
||||||
|
@ -122,20 +131,23 @@ public class Orbot extends SherlockActivity implements TorConstants, OnLongClick
|
||||||
|
|
||||||
mDrawer = ((SlidingDrawer)findViewById(R.id.SlidingDrawer));
|
mDrawer = ((SlidingDrawer)findViewById(R.id.SlidingDrawer));
|
||||||
Button slideButton = (Button)findViewById(R.id.slideButton);
|
Button slideButton = (Button)findViewById(R.id.slideButton);
|
||||||
slideButton.setOnTouchListener(new OnTouchListener (){
|
if (slideButton != null)
|
||||||
|
{
|
||||||
|
slideButton.setOnTouchListener(new OnTouchListener (){
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onTouch(View v, MotionEvent event) {
|
public boolean onTouch(View v, MotionEvent event) {
|
||||||
|
|
||||||
if (event.equals(MotionEvent.ACTION_DOWN))
|
if (event.equals(MotionEvent.ACTION_DOWN))
|
||||||
{
|
{
|
||||||
mDrawerOpen = !mDrawerOpen;
|
mDrawerOpen = !mDrawerOpen;
|
||||||
mTxtOrbotLog.setEnabled(mDrawerOpen);
|
mTxtOrbotLog.setEnabled(mDrawerOpen);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
ScrollingMovementMethod smm = new ScrollingMovementMethod();
|
ScrollingMovementMethod smm = new ScrollingMovementMethod();
|
||||||
|
|
||||||
|
@ -155,6 +167,7 @@ public class Orbot extends SherlockActivity implements TorConstants, OnLongClick
|
||||||
downloadText.setText(formatCount(0) + " / " + formatTotal(0));
|
downloadText.setText(formatCount(0) + " / " + formatTotal(0));
|
||||||
uploadText.setText(formatCount(0) + " / " + formatTotal(0));
|
uploadText.setText(formatCount(0) + " / " + formatTotal(0));
|
||||||
|
|
||||||
|
//updateStatus("");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void appendLogTextAndScroll(String text)
|
private void appendLogTextAndScroll(String text)
|
||||||
|
@ -297,7 +310,7 @@ public class Orbot extends SherlockActivity implements TorConstants, OnLongClick
|
||||||
stopService(new Intent(ITorService.class.getName()));
|
stopService(new Intent(ITorService.class.getName()));
|
||||||
|
|
||||||
//clears all notifications from the status bar
|
//clears all notifications from the status bar
|
||||||
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
|
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
|
||||||
mNotificationManager.cancelAll();
|
mNotificationManager.cancelAll();
|
||||||
|
|
||||||
|
|
||||||
|
@ -373,6 +386,23 @@ public class Orbot extends SherlockActivity implements TorConstants, OnLongClick
|
||||||
|
|
||||||
String onionHostname = prefs.getString("pref_hs_hostname","");
|
String onionHostname = prefs.getString("pref_hs_hostname","");
|
||||||
|
|
||||||
|
while (onionHostname.length() == 0)
|
||||||
|
{
|
||||||
|
//we need to stop and start Tor
|
||||||
|
try {
|
||||||
|
stopTor();
|
||||||
|
|
||||||
|
Thread.sleep(3000); //wait three seconds
|
||||||
|
|
||||||
|
startTor();
|
||||||
|
} catch (Exception e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
onionHostname = prefs.getString("pref_hs_hostname","");
|
||||||
|
}
|
||||||
|
|
||||||
Intent nResult = new Intent();
|
Intent nResult = new Intent();
|
||||||
nResult.putExtra("hs_host", onionHostname);
|
nResult.putExtra("hs_host", onionHostname);
|
||||||
setResult(RESULT_OK, nResult);
|
setResult(RESULT_OK, nResult);
|
||||||
|
@ -387,10 +417,20 @@ public class Orbot extends SherlockActivity implements TorConstants, OnLongClick
|
||||||
|
|
||||||
bindService();
|
bindService();
|
||||||
|
|
||||||
|
doLayout ();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleIntents ()
|
||||||
|
{
|
||||||
if (getIntent() == null)
|
if (getIntent() == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
String action = getIntent().getAction();
|
// Get intent, action and MIME type
|
||||||
|
Intent intent = getIntent();
|
||||||
|
String action = intent.getAction();
|
||||||
|
String type = intent.getType();
|
||||||
|
|
||||||
|
|
||||||
if (action == null)
|
if (action == null)
|
||||||
return;
|
return;
|
||||||
|
@ -432,7 +472,7 @@ public class Orbot extends SherlockActivity implements TorConstants, OnLongClick
|
||||||
}
|
}
|
||||||
else if (action.equals("org.torproject.android.START_TOR"))
|
else if (action.equals("org.torproject.android.START_TOR"))
|
||||||
{
|
{
|
||||||
autoStartOnBind = true;
|
autoStartFromIntent = true;
|
||||||
|
|
||||||
if (mService == null)
|
if (mService == null)
|
||||||
{
|
{
|
||||||
|
@ -440,7 +480,33 @@ public class Orbot extends SherlockActivity implements TorConstants, OnLongClick
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//already running!
|
try {
|
||||||
|
startTor();
|
||||||
|
} catch (RemoteException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
else if (Intent.ACTION_SEND.equals(action))
|
||||||
|
{
|
||||||
|
Uri dataUri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM);
|
||||||
|
|
||||||
|
try {
|
||||||
|
String shareUrl = mService.addOnionShare(dataUri, type);
|
||||||
|
|
||||||
|
Toast.makeText(this, "Share available at: " + shareUrl, Toast.LENGTH_LONG).show();
|
||||||
|
ClipboardManager cm = (ClipboardManager)getSystemService(Context.CLIPBOARD_SERVICE);
|
||||||
|
cm.setText(shareUrl);
|
||||||
|
|
||||||
|
intent.setAction(null);
|
||||||
|
|
||||||
|
|
||||||
|
} catch (RemoteException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -471,9 +537,14 @@ public class Orbot extends SherlockActivity implements TorConstants, OnLongClick
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onConfigurationChanged(Configuration newConfig) {
|
public void onConfigurationChanged(Configuration newConfig) {
|
||||||
super.onConfigurationChanged(newConfig);
|
super.onConfigurationChanged(newConfig);
|
||||||
|
|
||||||
|
doLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
|
@ -492,7 +563,8 @@ public class Orbot extends SherlockActivity implements TorConstants, OnLongClick
|
||||||
*/
|
*/
|
||||||
private void openBrowser(String url)
|
private void openBrowser(String url)
|
||||||
{
|
{
|
||||||
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
|
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
|
||||||
|
startActivity(intent);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -624,6 +696,12 @@ public class Orbot extends SherlockActivity implements TorConstants, OnLongClick
|
||||||
mItemOnOff.setTitle(R.string.menu_stop);
|
mItemOnOff.setTitle(R.string.menu_stop);
|
||||||
|
|
||||||
|
|
||||||
|
if (autoStartFromIntent)
|
||||||
|
{
|
||||||
|
setResult(RESULT_OK);
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else if (torStatus == TorServiceConstants.STATUS_CONNECTING)
|
else if (torStatus == TorServiceConstants.STATUS_CONNECTING)
|
||||||
{
|
{
|
||||||
|
@ -844,9 +922,6 @@ public class Orbot extends SherlockActivity implements TorConstants, OnLongClick
|
||||||
downloadText.setText(formatCount(datacount.Download) + " / " + formatTotal(totalRead));
|
downloadText.setText(formatCount(datacount.Download) + " / " + formatTotal(totalRead));
|
||||||
uploadText.setText(formatCount(datacount.Upload) + " / " + formatTotal(totalWrite));
|
uploadText.setText(formatCount(datacount.Upload) + " / " + formatTotal(totalWrite));
|
||||||
|
|
||||||
// downloadText.invalidate();
|
|
||||||
// uploadText.invalidate();
|
|
||||||
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
super.handleMessage(msg);
|
super.handleMessage(msg);
|
||||||
|
@ -880,17 +955,17 @@ public class Orbot extends SherlockActivity implements TorConstants, OnLongClick
|
||||||
try {
|
try {
|
||||||
mService.registerCallback(mCallback);
|
mService.registerCallback(mCallback);
|
||||||
|
|
||||||
//again with the update status?!? :P
|
if (autoStartFromIntent)
|
||||||
updateStatus(null);
|
|
||||||
|
|
||||||
if (autoStartOnBind)
|
|
||||||
{
|
{
|
||||||
autoStartOnBind = false;
|
|
||||||
|
|
||||||
startTor();
|
startTor();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handleIntents();
|
||||||
|
|
||||||
|
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
// In this case the service has crashed before we could even
|
// In this case the service has crashed before we could even
|
||||||
// do anything with it; we can count on soon being
|
// do anything with it; we can count on soon being
|
||||||
|
|
Loading…
Reference in New Issue