From e58a15ebd77dc90fcdfc926eb21be0c8e5c11aad Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Wed, 3 Jun 2015 17:36:41 -0400 Subject: [PATCH] Promo Apps: choose "all apps" URL based on which app store is installed Since most people using devices without Google Play will be in China, where Google is generally blocked, instead direct people to f-droid.org unless they have Google Play installed. --- res/layout/layout_wizard_tips.xml | 2 +- res/values-ar/strings.xml | 6 +- res/values-az/strings.xml | 2 +- res/values-bg/strings.xml | 2 +- res/values-ca/strings.xml | 2 +- res/values-cs-rCZ/strings.xml | 2 +- res/values-da/strings.xml | 2 +- res/values-de/strings.xml | 2 +- res/values-el/strings.xml | 2 +- res/values-eo/strings.xml | 2 +- res/values-es/strings.xml | 2 +- res/values-et/strings.xml | 2 +- res/values-eu/strings.xml | 2 +- res/values-fa/strings.xml | 2 +- res/values-fi/strings.xml | 2 +- res/values-fr-rFR/strings.xml | 2 +- res/values-fr/strings.xml | 2 +- res/values-gl/strings.xml | 2 +- res/values-he/strings.xml | 2 +- res/values-hr/strings.xml | 2 +- res/values-hu/strings.xml | 2 +- res/values-id-rID/strings.xml | 2 +- res/values-is/strings.xml | 2 +- res/values-it/strings.xml | 2 +- res/values-ja/strings.xml | 2 +- res/values-ko/strings.xml | 2 +- res/values-lv/strings.xml | 2 +- res/values-mk/strings.xml | 2 +- res/values-ms-rMY/strings.xml | 2 +- res/values-nb/strings.xml | 2 +- res/values-nl/strings.xml | 2 +- res/values-pl/strings.xml | 2 +- res/values-pt-rBR/strings.xml | 2 +- res/values-pt/strings.xml | 2 +- res/values-ro/strings.xml | 2 +- res/values-ru/strings.xml | 2 +- res/values-si-rLK/strings.xml | 2 +- res/values-sr/strings.xml | 2 +- res/values-sv/strings.xml | 2 +- res/values-tl/strings.xml | 2 +- res/values-tr/strings.xml | 2 +- res/values-uk/strings.xml | 2 +- res/values-vi/strings.xml | 2 +- res/values-zh-rTW/strings.xml | 2 +- res/values-zh/strings.xml | 2 +- res/values/strings.xml | 3 +- .../android/ui/wizard/PromoAppsActivity.java | 90 ++++++++++++------- 47 files changed, 108 insertions(+), 79 deletions(-) diff --git a/res/layout/layout_wizard_tips.xml b/res/layout/layout_wizard_tips.xml index 43afc43c..83ed2d44 100644 --- a/res/layout/layout_wizard_tips.xml +++ b/res/layout/layout_wizard_tips.xml @@ -97,7 +97,7 @@ android:layout_gravity="left" android:layout_marginTop="10px" android:drawableLeft="@drawable/ic_play" - android:text="@string/wizard_tips_play" /> + android:text="@string/wizard_tips_fdroid_org" /> diff --git a/res/values-ar/strings.xml b/res/values-ar/strings.xml index 8ace8ba7..28af9d6a 100644 --- a/res/values-ar/strings.xml +++ b/res/values-ar/strings.xml @@ -96,10 +96,8 @@ برامج معدة للعمل مع اوربوت Orweb: متصفح مصمّم للخصوصية و يعمل مع تور يمكنك الحصول علي جميع تطبيقات مشروع الجاردين على جوجل بلاي - https://play.google.com/store/search?q=guardianproject - - diff --git a/res/values-az/strings.xml b/res/values-az/strings.xml index b7c5ae3f..9035a84a 100644 --- a/res/values-az/strings.xml +++ b/res/values-az/strings.xml @@ -100,7 +100,7 @@ Orveb: Tor vasitəsilə işləyən təhlükəsizliyi gücləndirilmiş brauzer Google Play-də bütün Guardian Layihə aplikasiyaları tap - https://play.google.com/store/search?q=guardianproject + Transparent Proxying This allows your apps to automatically run through the Tor network without any configuration. diff --git a/src/org/torproject/android/ui/wizard/PromoAppsActivity.java b/src/org/torproject/android/ui/wizard/PromoAppsActivity.java index a3681650..048528fd 100644 --- a/src/org/torproject/android/ui/wizard/PromoAppsActivity.java +++ b/src/org/torproject/android/ui/wizard/PromoAppsActivity.java @@ -3,7 +3,9 @@ package org.torproject.android.ui.wizard; import android.app.Activity; import android.content.Intent; import android.content.pm.PackageManager; +import android.content.pm.PackageManager.NameNotFoundException; import android.content.pm.ResolveInfo; +import android.graphics.drawable.Drawable; import android.net.Uri; import android.os.Bundle; import android.text.TextUtils; @@ -35,22 +37,22 @@ public class PromoAppsActivity extends Activity implements OrbotConstants { super.onCreate(savedInstanceState); } - + @Override protected void onStart() { - + super.onStart(); setContentView(R.layout.layout_wizard_tips); - + stepFive(); - + } - + @Override protected void onResume() { super.onResume(); - - + + } void stepFive(){ @@ -135,45 +137,64 @@ public class PromoAppsActivity extends Activity implements OrbotConstants { } }); - btnLink = (Button)findViewById(R.id.WizardRootButtonGooglePlay); + PackageManager pm = getPackageManager(); + final Intent intent = new Intent(Intent.ACTION_VIEW); + // change text and icon based on which app store is installed (or not) + try { + if (isAppInstalled(pm, FDROID_PACKAGE_NAME)) { + Drawable icon = pm.getApplicationIcon(FDROID_PACKAGE_NAME); + btnLink.setCompoundDrawablesWithIntrinsicBounds(icon, null, null, null); + btnLink.setText(R.string.wizard_tips_fdroid); + intent.setPackage(FDROID_PACKAGE_NAME); + intent.setData(Uri.parse(FDROID_URI)); + } else if (isAppInstalled(pm, PLAY_PACKAGE_NAME)) { + Drawable icon = pm.getApplicationIcon(PLAY_PACKAGE_NAME); + btnLink.setCompoundDrawablesWithIntrinsicBounds(icon, null, null, null); + btnLink.setText(R.string.wizard_tips_play); + intent.setPackage(PLAY_PACKAGE_NAME); + intent.setData(Uri.parse(PLAY_URI)); + } + } catch (NameNotFoundException e) { + e.printStackTrace(); + btnLink.setText(R.string.wizard_tips_fdroid_org); + intent.setData(Uri.parse(FDROID_URI)); + } btnLink.setOnClickListener(new OnClickListener() { - - public void onClick(View view) { - - String url = getString(R.string.wizard_tips_play_url); - startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url))); + @Override + public void onClick(View view) { + startActivity(intent); } - }); - - + }); + + // Button back = ((Button)findViewById(R.id.btnWizard1)); Button next = ((Button)findViewById(R.id.btnWizard2)); - + /* back.setOnClickListener(new View.OnClickListener() { - + public void onClick(View v) { finish(); startActivityForResult(new Intent(PromoAppsActivity.this, ChooseLocaleWizardActivity.class), 1); } });*/ - + next.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { //showWizardFinal(); - + finish(); } }); - + } - - - + + + //Code to override the back button! @Override public boolean onKeyDown(int keyCode, KeyEvent event) { @@ -185,6 +206,15 @@ public class PromoAppsActivity extends Activity implements OrbotConstants { return false; } + boolean isAppInstalled(PackageManager pm, String packageName) { + try { + pm.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES); + return true; + } catch (PackageManager.NameNotFoundException e) { + return false; + } + } + Intent getInstallIntent(String packageName) { final Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse(MARKET_URI + packageName)); @@ -215,21 +245,21 @@ public class PromoAppsActivity extends Activity implements OrbotConstants { { String title = null; String msg = null; - - + + title = context.getString(R.string.wizard_final); msg = context.getString(R.string.wizard_final_msg); - + DialogInterface.OnClickListener ocListener = new DialogInterface.OnClickListener() { - + @Override public void onClick(DialogInterface dialog, int which) { context.startActivity(new Intent(context, Orbot.class)); } }; - - + + new AlertDialog.Builder(context) .setIcon(R.drawable.icon) .setTitle(title)