fix browser install request

This commit is contained in:
Nathan Freitas 2016-10-24 15:00:47 -04:00
parent 28f1dbf7dd
commit ac037a9dc5
3 changed files with 40 additions and 49 deletions

View File

@ -737,8 +737,12 @@ public class OrbotMainActivity extends AppCompatActivity
private void openBrowser(final String browserLaunchUrl,boolean forceExternal) private void openBrowser(final String browserLaunchUrl,boolean forceExternal)
{ {
boolean isBrowserInstalled = appInstalledOrNot(TorServiceConstants.BROWSER_APP_USERNAME); boolean isBrowserInstalled = appInstalledOrNot(TorServiceConstants.BROWSER_APP_USERNAME);
if (mBtnVPN.isChecked()||forceExternal) if (isBrowserInstalled)
{
startIntent(TorServiceConstants.BROWSER_APP_USERNAME,Intent.ACTION_VIEW,Uri.parse(browserLaunchUrl));
}
else if (mBtnVPN.isChecked()||forceExternal)
{ {
//use the system browser since VPN is on //use the system browser since VPN is on
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(browserLaunchUrl)); Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(browserLaunchUrl));
@ -751,10 +755,6 @@ public class OrbotMainActivity extends AppCompatActivity
intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP|Intent.FLAG_ACTIVITY_NEW_TASK); intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP|Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent); startActivity(intent);
} }
else if (isBrowserInstalled)
{
startIntent(TorServiceConstants.BROWSER_APP_USERNAME,Intent.ACTION_VIEW,Uri.parse(browserLaunchUrl));
}
else else
{ {
AlertDialog aDialog = new AlertDialog.Builder(OrbotMainActivity.this) AlertDialog aDialog = new AlertDialog.Builder(OrbotMainActivity.this)
@ -768,10 +768,13 @@ public class OrbotMainActivity extends AppCompatActivity
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
//prompt to install Orweb //prompt to install Orweb
Intent intent = new Intent(OrbotMainActivity.this,PromoAppsActivity.class); //Intent intent = new Intent(OrbotMainActivity.this,PromoAppsActivity.class);
startActivity(intent); //startActivity(intent);
} startActivity(PromoAppsActivity.getInstallIntent(TorServiceConstants.BROWSER_APP_USERNAME,OrbotMainActivity.this));
}
}) })
.setNegativeButton(R.string.standard_browser, new Dialog.OnClickListener () .setNegativeButton(R.string.standard_browser, new Dialog.OnClickListener ()
@ -1291,7 +1294,6 @@ public class OrbotMainActivity extends AppCompatActivity
if (torStatus == null && newTorStatus != null) //first time status if (torStatus == null && newTorStatus != null) //first time status
{ {
torStatus = newTorStatus; torStatus = newTorStatus;
findViewById(R.id.pbConnecting).setVisibility(View.GONE);
findViewById(R.id.frameMain).setVisibility(View.VISIBLE); findViewById(R.id.frameMain).setVisibility(View.VISIBLE);
updateStatus(log); updateStatus(log);

View File

@ -1,6 +1,7 @@
package org.torproject.android.ui; package org.torproject.android.ui;
import android.app.Activity; import android.app.Activity;
import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException; import android.content.pm.PackageManager.NameNotFoundException;
@ -69,7 +70,7 @@ public class PromoAppsActivity extends Activity implements OrbotConstants {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
finish(); finish();
startActivity(getInstallIntent("info.guardianproject.otr.app.im")); startActivity(getInstallIntent("info.guardianproject.otr.app.im",PromoAppsActivity.this));
} }
}); });
@ -81,7 +82,7 @@ public class PromoAppsActivity extends Activity implements OrbotConstants {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
finish(); finish();
startActivity(getInstallIntent(TorServiceConstants.BROWSER_APP_USERNAME)); startActivity(getInstallIntent(TorServiceConstants.BROWSER_APP_USERNAME,PromoAppsActivity.this));
} }
}); });
@ -94,7 +95,7 @@ public class PromoAppsActivity extends Activity implements OrbotConstants {
public void onClick(View view) { public void onClick(View view) {
finish(); finish();
startActivity(getInstallIntent("com.duckduckgo.mobile.android")); startActivity(getInstallIntent("com.duckduckgo.mobile.android",PromoAppsActivity.this));
} }
}); });
@ -120,7 +121,7 @@ public class PromoAppsActivity extends Activity implements OrbotConstants {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
finish(); finish();
startActivity(getInstallIntent("info.guardianproject.mrapp")); startActivity(getInstallIntent("info.guardianproject.mrapp",PromoAppsActivity.this));
} }
}); });
@ -132,7 +133,7 @@ public class PromoAppsActivity extends Activity implements OrbotConstants {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
finish(); finish();
startActivity(getInstallIntent("org.martus.android")); startActivity(getInstallIntent("org.martus.android",PromoAppsActivity.this));
} }
}); });
@ -179,7 +180,7 @@ public class PromoAppsActivity extends Activity implements OrbotConstants {
} }
boolean isAppInstalled(PackageManager pm, String packageName) { public static boolean isAppInstalled(PackageManager pm, String packageName) {
try { try {
pm.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES); pm.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES);
return true; return true;
@ -188,11 +189,11 @@ public class PromoAppsActivity extends Activity implements OrbotConstants {
} }
} }
Intent getInstallIntent(String packageName) { public static Intent getInstallIntent(String packageName, Context context) {
final Intent intent = new Intent(Intent.ACTION_VIEW); final Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(MARKET_URI + packageName)); intent.setData(Uri.parse(MARKET_URI + packageName));
PackageManager pm = getPackageManager(); PackageManager pm = context.getPackageManager();
List<ResolveInfo> resInfos = pm.queryIntentActivities(intent, 0); List<ResolveInfo> resInfos = pm.queryIntentActivities(intent, 0);
String foundPackageName = null; String foundPackageName = null;

View File

@ -2,7 +2,9 @@
<LinearLayout android:gravity="center_vertical|center_horizontal" <LinearLayout android:gravity="center_vertical|center_horizontal"
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent" xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="@color/dark_purple" android:background="@color/dark_purple"
@ -23,32 +25,16 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:id="@+id/content_frame" android:id="@+id/content_frame"
>
<LinearLayout android:gravity="center_vertical|center_horizontal"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="wrap_content"
>
>
<ProgressBar
android:id="@+id/pbConnecting"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="60dp"
android:visibility="gone"
android:layout_gravity="center_horizontal|center_vertical"/>
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="400dp"
android:id="@+id/frameMain" android:id="@+id/frameMain"
android:visibility="visible" android:visibility="visible"
android:orientation="vertical" android:orientation="vertical"
android:layout_gravity="center_horizontal|center_vertical" android:gravity="center_horizontal|center_vertical"
> >
<org.torproject.android.ui.ImageProgressView <org.torproject.android.ui.ImageProgressView
android:id="@+id/imgStatus" android:id="@+id/imgStatus"
@ -58,7 +44,7 @@ android:layout_gravity="center_horizontal|center_vertical"/>
android:padding="0dp" android:padding="0dp"
android:layout_margin="0dp" android:layout_margin="0dp"
android:src="@drawable/toroff" /> android:src="@drawable/toroff" />
<LinearLayout android:gravity="center_horizontal" <LinearLayout android:gravity="center_horizontal"
@ -88,9 +74,6 @@ android:layout_gravity="center_horizontal|center_vertical"/>
/> />
</LinearLayout> </LinearLayout>
</LinearLayout>
</LinearLayout> </LinearLayout>
<LinearLayout <LinearLayout
@ -116,31 +99,36 @@ android:layout_gravity="center_horizontal|center_vertical"/>
<android.support.v7.widget.SwitchCompat <android.support.v7.widget.SwitchCompat
android:id="@+id/btnVPN" android:id="@+id/btnVPN"
android:layout_width="80dp" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/menu_vpn" android:text="@string/menu_vpn"
android:layout_margin="3dp" android:layout_margin="3dp"
android:ellipsize="end"
android:singleLine="true" android:singleLine="true"
/> app:switchPadding="9dp"
/>
<android.support.v7.widget.SwitchCompat <android.support.v7.widget.SwitchCompat
android:id="@+id/btnBridges" android:id="@+id/btnBridges"
android:layout_width="100dp" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/bridges" android:text="@string/bridges"
android:layout_marginTop="3dp" android:layout_marginTop="3dp"
android:layout_marginLeft="5dp" android:layout_marginLeft="5dp"
android:layout_marginBottom="3dp" android:layout_marginBottom="3dp"
android:ellipsize="end"
android:singleLine="true" android:singleLine="true"
app:switchPadding="9dp"
/> />
<Spinner <Spinner
android:id="@+id/spinnerCountry" android:id="@+id/spinnerCountry"
android:layout_width="140dp" android:layout_width="140dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:layout_weight="1"
android:layout_marginTop="3dp"
android:layout_marginLeft="5dp"
android:layout_marginBottom="3dp"
/> />
</LinearLayout> </LinearLayout>