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:
n8fr8 2013-02-12 14:26:38 +07:00
parent 7df2acd59c
commit 21c27972d9
1 changed files with 104 additions and 29 deletions

View File

@ -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)
{
@Override slideButton.setOnTouchListener(new OnTouchListener (){
public boolean onTouch(View v, MotionEvent event) {
@Override
if (event.equals(MotionEvent.ACTION_DOWN)) public boolean onTouch(View v, MotionEvent event) {
{
mDrawerOpen = !mDrawerOpen; if (event.equals(MotionEvent.ACTION_DOWN))
mTxtOrbotLog.setEnabled(mDrawerOpen); {
mDrawerOpen = !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);
@ -386,11 +416,21 @@ public class Orbot extends SherlockActivity implements TorConstants, OnLongClick
super.onResume(); super.onResume();
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);
} }
@ -623,6 +695,12 @@ public class Orbot extends SherlockActivity implements TorConstants, OnLongClick
if (mItemOnOff != null) if (mItemOnOff != null)
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)
@ -843,10 +921,7 @@ 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);
@ -879,17 +954,17 @@ public class Orbot extends SherlockActivity implements TorConstants, OnLongClick
// connected to it. // connected to it.
try { try {
mService.registerCallback(mCallback); mService.registerCallback(mCallback);
//again with the update status?!? :P
updateStatus(null);
if (autoStartOnBind) if (autoStartFromIntent)
{ {
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