commit fd23da52372729166fcd4c5d59f4b9fe1ff190c8 Author: Hans-Christoph Steiner hans@eds.org Date: Mon Jun 8 15:38:22 2015 -0400
purge troublesome half-disabled Wizard, rename menu to "Get Apps..."
When clicking on "Wizard" from the menu, then clicking back, it gets stuck in a strange back stack purgatory, and then randomly changes the language. So purge the wizard stuff for now, and add back the parts that are still needed once that is all figured out.
This also simplifies the refactoring of the Intent handling. --- AndroidManifest.xml | 3 +- res/layout/layout_promo_apps.xml | 115 +++++++++ res/layout/layout_wizard.xml | 22 -- res/layout/layout_wizard_locale.xml | 57 ----- res/layout/layout_wizard_tips.xml | 115 --------- res/menu/orbot_main.xml | 4 +- res/values/strings.xml | 2 +- src/org/torproject/android/OrbotMainActivity.java | 39 +-- .../torproject/android/ui/PromoAppsActivity.java | 213 +++++++++++++++ .../ui/wizard/ChooseLocaleWizardActivity.java | 108 -------- .../android/ui/wizard/PromoAppsActivity.java | 270 -------------------- 11 files changed, 335 insertions(+), 613 deletions(-)
diff --git a/AndroidManifest.xml b/AndroidManifest.xml index f95ec15..d7912e5 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -81,8 +81,7 @@ /> - <activity android:name="org.torproject.android.ui.wizard.PromoAppsActivity" android:exported="false"/> - <activity android:name="org.torproject.android.ui.wizard.ChooseLocaleWizardActivity" android:exported="false"/> + <activity android:name="org.torproject.android.ui.PromoAppsActivity" android:exported="false"/> <activity android:name=".settings.SettingsPreferences" android:label="@string/app_name"/> diff --git a/res/layout/layout_promo_apps.xml b/res/layout/layout_promo_apps.xml new file mode 100644 index 0000000..83ed2d4 --- /dev/null +++ b/res/layout/layout_promo_apps.xml @@ -0,0 +1,115 @@ +<?xml version="1.0" encoding="utf-8"?> + +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:orientation="vertical" + android:layout_width="fill_parent" + android:layout_height="fill_parent"> + + +<TableLayout android:id="@+id/TableLayout01" android:stretchColumns="*" android:layout_height="fill_parent" android:layout_width="wrap_content"> + +<TableRow android:layout_margin="10dip" android:id="@+id/TableRow01" android:layout_weight="1" android:layout_width="fill_parent" android:layout_height="fill_parent"> + + + <ScrollView android:id="@+id/helpscrollview" + android:orientation="vertical" + android:layout_width="fill_parent" + android:layout_height="fill_parent" + android:layout_span="3"> + +<LinearLayout + android:layout_width="fill_parent" + android:layout_height="fill_parent" + android:background="#575757" + android:orientation="vertical" + android:paddingRight="20dip" > + + <TextView + android:id="@+id/WizardTextBody1" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_weight="0.31" + android:padding="20dip" + android:text="@string/wizard_tips_msg" + android:textColor="#ffffff" + android:textSize="8pt" > + </TextView> + + <Button + android:id="@+id/WizardRootButtonInstallOrweb" + android:layout_width="fill_parent" + android:layout_height="wrap_content" + android:layout_gravity="left" + android:layout_marginTop="10px" + android:drawableLeft="@drawable/icon_orweb" + android:text="@string/wizard_tips_orweb" /> + + <Button + android:id="@+id/WizardRootButtonInstallGibberbot" + android:layout_width="fill_parent" + android:layout_height="wrap_content" + android:layout_gravity="left" + android:layout_marginTop="10px" + android:drawableLeft="@drawable/ic_chatsecure" + android:text="@string/wizard_tips_gibberbot" /> + + + <Button + android:id="@+id/WizardRootButtonInstallDuckgo" + android:layout_width="fill_parent" + android:layout_height="wrap_content" + android:layout_gravity="left" + android:layout_marginTop="10px" + android:drawableLeft="@drawable/ic_duckduckgo" + android:text="@string/wizard_tips_duckgo" /> + + <Button + android:id="@+id/WizardRootButtonInstallTwitter" + android:layout_width="fill_parent" + android:layout_height="wrap_content" + android:layout_gravity="left" + android:layout_marginTop="10px" + android:drawableLeft="@drawable/ic_twitter" + android:text="@string/wizard_tips_twitter" /> + + <Button + android:id="@+id/WizardRootButtonInstallStoryMaker" + android:layout_width="fill_parent" + android:layout_height="wrap_content" + android:layout_gravity="left" + android:layout_marginTop="10px" + android:drawableLeft="@drawable/icon_story_maker" + android:text="@string/wizard_tips_story_maker" /> + + <Button + android:id="@+id/WizardRootButtonInstallMartus" + android:layout_width="fill_parent" + android:layout_height="wrap_content" + android:layout_gravity="left" + android:layout_marginTop="10px" + android:drawableLeft="@drawable/icon_martus" + android:text="@string/wizard_tips_martus" /> + + <Button + android:id="@+id/WizardRootButtonGooglePlay" + android:layout_width="fill_parent" + android:layout_height="wrap_content" + android:layout_gravity="left" + android:layout_marginTop="10px" + android:drawableLeft="@drawable/ic_play" + android:text="@string/wizard_tips_fdroid_org" /> + + +</LinearLayout> + + </ScrollView> + +</TableRow> +<TableRow android:background="#000000" android:layout_marginTop="10dip" android:paddingTop="10dip" android:id="@+id/TableRow02" android:textColor="#00ff00" android:layout_width="fill_parent" android:layout_height="30px"> + <!-- <Button android:text="@string/btn_back" android:id="@+id/btnWizard1" android:layout_weight="1" android:layout_width="fill_parent" android:layout_height="wrap_content"></Button> --> + <Button android:text="@string/btn_okay" android:id="@+id/btnWizard2" android:layout_weight="1" android:layout_width="fill_parent" android:layout_height="wrap_content"></Button> +</TableRow> +</TableLayout> +</LinearLayout> + + diff --git a/res/layout/layout_wizard.xml b/res/layout/layout_wizard.xml deleted file mode 100644 index 848f744..0000000 --- a/res/layout/layout_wizard.xml +++ /dev/null @@ -1,22 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" - android:orientation="vertical" - android:layout_width="fill_parent" - android:layout_height="wrap_content"> - <ScrollView android:id="@+id/helpscrollview" - android:orientation="vertical" - android:layout_width="fill_parent" - android:layout_height="fill_parent"> - <LinearLayout - android:orientation="vertical" - android:layout_width="fill_parent" - android:layout_height="fill_parent"> - <TextView android:text="" - android:layout_width="fill_parent" - android:layout_height="wrap_content" - android:textColor="#ffffff" /> - </LinearLayout> - </ScrollView> -</LinearLayout> - - \ No newline at end of file diff --git a/res/layout/layout_wizard_locale.xml b/res/layout/layout_wizard_locale.xml deleted file mode 100644 index ae3aecb..0000000 --- a/res/layout/layout_wizard_locale.xml +++ /dev/null @@ -1,57 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" - android:layout_width="fill_parent" - android:layout_height="wrap_content" - android:orientation="vertical" > - -<RelativeLayout - android:layout_width="fill_parent" - android:layout_height="wrap_content" - android:id="@+id/relativeLayout1" - android:layout_gravity="center_horizontal" - android:background="#000000"> - <TextView android:textSize="10pt" - android:textColor="#FFFFFF" - android:layout_alignParentTop="true" - android:layout_height="wrap_content" - android:id="@+id/WizardLocaleTitle" - android:layout_width="wrap_content" - android:fadingEdge="vertical" - android:text="@string/wizard_locale_title" - android:singleLine="true" - android:padding="20px" android:layout_centerInParent="true"> - </TextView> - </RelativeLayout> -<TableLayout android:id="@+id/TableLayout01" android:stretchColumns="*" android:layout_height="fill_parent" android:layout_width="wrap_content"> - -<TableRow android:layout_margin="10dip" android:id="@+id/TableRow01" android:layout_weight="1" android:layout_width="fill_parent" android:layout_height="fill_parent"> - - -<LinearLayout - android:background="#575757" - android:orientation="vertical" - android:layout_width="fill_parent" - android:layout_height="fill_parent" - android:layout_weight="1" - android:padding="3px"> -<TextView android:text="@string/wizard_locale_msg" android:layout_width="wrap_content" android:textColor="#ffffff" android:layout_height="wrap_content" android:textSize="8pt" android:id="@+id/WizardTextBody1" android:padding="20dip"></TextView> -<ListView - android:id="@+id/wizard_locale_list" - android:layout_width="fill_parent" - android:layout_height="wrap_content" - android:layout_weight="1" - > -</ListView> - - - </LinearLayout> - -</TableRow> -<TableRow android:background="#000000" android:layout_marginTop="10dip" android:paddingTop="10dip" android:id="@+id/TableRow01" android:textColor="#00ff00" android:layout_width="fill_parent" android:layout_height="30px"> - <Button android:text="@string/btn_next" android:id="@+id/btnWizard2" android:layout_weight="1" android:layout_width="fill_parent" android:layout_height="wrap_content"></Button> -</TableRow> -</TableLayout> -</LinearLayout> - - - diff --git a/res/layout/layout_wizard_tips.xml b/res/layout/layout_wizard_tips.xml deleted file mode 100644 index 83ed2d4..0000000 --- a/res/layout/layout_wizard_tips.xml +++ /dev/null @@ -1,115 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> - -<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" - android:orientation="vertical" - android:layout_width="fill_parent" - android:layout_height="fill_parent"> - - -<TableLayout android:id="@+id/TableLayout01" android:stretchColumns="*" android:layout_height="fill_parent" android:layout_width="wrap_content"> - -<TableRow android:layout_margin="10dip" android:id="@+id/TableRow01" android:layout_weight="1" android:layout_width="fill_parent" android:layout_height="fill_parent"> - - - <ScrollView android:id="@+id/helpscrollview" - android:orientation="vertical" - android:layout_width="fill_parent" - android:layout_height="fill_parent" - android:layout_span="3"> - -<LinearLayout - android:layout_width="fill_parent" - android:layout_height="fill_parent" - android:background="#575757" - android:orientation="vertical" - android:paddingRight="20dip" > - - <TextView - android:id="@+id/WizardTextBody1" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:layout_weight="0.31" - android:padding="20dip" - android:text="@string/wizard_tips_msg" - android:textColor="#ffffff" - android:textSize="8pt" > - </TextView> - - <Button - android:id="@+id/WizardRootButtonInstallOrweb" - android:layout_width="fill_parent" - android:layout_height="wrap_content" - android:layout_gravity="left" - android:layout_marginTop="10px" - android:drawableLeft="@drawable/icon_orweb" - android:text="@string/wizard_tips_orweb" /> - - <Button - android:id="@+id/WizardRootButtonInstallGibberbot" - android:layout_width="fill_parent" - android:layout_height="wrap_content" - android:layout_gravity="left" - android:layout_marginTop="10px" - android:drawableLeft="@drawable/ic_chatsecure" - android:text="@string/wizard_tips_gibberbot" /> - - - <Button - android:id="@+id/WizardRootButtonInstallDuckgo" - android:layout_width="fill_parent" - android:layout_height="wrap_content" - android:layout_gravity="left" - android:layout_marginTop="10px" - android:drawableLeft="@drawable/ic_duckduckgo" - android:text="@string/wizard_tips_duckgo" /> - - <Button - android:id="@+id/WizardRootButtonInstallTwitter" - android:layout_width="fill_parent" - android:layout_height="wrap_content" - android:layout_gravity="left" - android:layout_marginTop="10px" - android:drawableLeft="@drawable/ic_twitter" - android:text="@string/wizard_tips_twitter" /> - - <Button - android:id="@+id/WizardRootButtonInstallStoryMaker" - android:layout_width="fill_parent" - android:layout_height="wrap_content" - android:layout_gravity="left" - android:layout_marginTop="10px" - android:drawableLeft="@drawable/icon_story_maker" - android:text="@string/wizard_tips_story_maker" /> - - <Button - android:id="@+id/WizardRootButtonInstallMartus" - android:layout_width="fill_parent" - android:layout_height="wrap_content" - android:layout_gravity="left" - android:layout_marginTop="10px" - android:drawableLeft="@drawable/icon_martus" - android:text="@string/wizard_tips_martus" /> - - <Button - android:id="@+id/WizardRootButtonGooglePlay" - android:layout_width="fill_parent" - android:layout_height="wrap_content" - android:layout_gravity="left" - android:layout_marginTop="10px" - android:drawableLeft="@drawable/ic_play" - android:text="@string/wizard_tips_fdroid_org" /> - - -</LinearLayout> - - </ScrollView> - -</TableRow> -<TableRow android:background="#000000" android:layout_marginTop="10dip" android:paddingTop="10dip" android:id="@+id/TableRow02" android:textColor="#00ff00" android:layout_width="fill_parent" android:layout_height="30px"> - <!-- <Button android:text="@string/btn_back" android:id="@+id/btnWizard1" android:layout_weight="1" android:layout_width="fill_parent" android:layout_height="wrap_content"></Button> --> - <Button android:text="@string/btn_okay" android:id="@+id/btnWizard2" android:layout_weight="1" android:layout_width="fill_parent" android:layout_height="wrap_content"></Button> -</TableRow> -</TableLayout> -</LinearLayout> - - diff --git a/res/menu/orbot_main.xml b/res/menu/orbot_main.xml index cff67e9..f37373a 100644 --- a/res/menu/orbot_main.xml +++ b/res/menu/orbot_main.xml @@ -57,8 +57,8 @@ -->
- <item android:id="@+id/menu_wizard" - android:title="@string/menu_wizard" + <item android:id="@+id/menu_promo_apps" + android:title="@string/menu_promo_apps" android:icon="@drawable/ic_menu_goto" yourapp:showAsAction="never"
diff --git a/res/values/strings.xml b/res/values/strings.xml index e5b4cd3..7030a37 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -25,7 +25,7 @@ <string name="menu_start">Start</string> <string name="menu_stop">Stop</string> <string name="menu_about">About</string> - <string name="menu_wizard">Wizard</string> + <string name="menu_promo_apps">Get apps…</string> <string name="main_layout_download">Download</string> <string name="main_layout_upload">Upload</string> <string name="button_help">Help</string> diff --git a/src/org/torproject/android/OrbotMainActivity.java b/src/org/torproject/android/OrbotMainActivity.java index e9c9699..15faf31 100644 --- a/src/org/torproject/android/OrbotMainActivity.java +++ b/src/org/torproject/android/OrbotMainActivity.java @@ -14,8 +14,8 @@ import org.torproject.android.service.TorServiceConstants; import org.torproject.android.service.TorServiceUtils; import org.torproject.android.settings.SettingsPreferences; import org.torproject.android.ui.ImageProgressView; +import org.torproject.android.ui.PromoAppsActivity; import org.torproject.android.ui.Rotate3dAnimation; -import org.torproject.android.ui.wizard.PromoAppsActivity;
import android.annotation.TargetApi; import android.app.Activity; @@ -32,7 +32,6 @@ import android.content.SharedPreferences.OnSharedPreferenceChangeListener; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.content.pm.PackageManager.NameNotFoundException; -import android.content.res.Configuration; import android.net.Uri; import android.net.VpnService; import android.os.Build; @@ -392,7 +391,7 @@ public class OrbotMainActivity extends Activity implements OrbotConstants, OnLon Intent intent = new Intent(OrbotMainActivity.this, SettingsPreferences.class); startActivityForResult(intent, REQUEST_SETTINGS); } - else if (item.getItemId() == R.id.menu_wizard) + else if (item.getItemId() == R.id.menu_promo_apps) { startActivity(new Intent(OrbotMainActivity.this, PromoAppsActivity.class));
@@ -653,26 +652,6 @@ public class OrbotMainActivity extends Activity implements OrbotConstants, OnLon } } } - else - { - - showWizard = mPrefs.getBoolean("show_wizard",showWizard); - - //let's not show the wizard now for new users - - if (showWizard) - { - Editor pEdit = mPrefs.edit(); - pEdit.putBoolean("show_wizard",false); - pEdit.commit(); - showWizard = false; - - - showAlert(getString(R.string.app_name),getString(R.string.wizard_final_msg),true); - - } - - } updateStatus(""); @@ -698,19 +677,7 @@ public class OrbotMainActivity extends Activity implements OrbotConstants, OnLon mBtnBridges.setChecked(true); enableBridges(true); - } - - private boolean showWizard = true; - - - @Override - public void onConfigurationChanged(Configuration newConfig) { - super.onConfigurationChanged(newConfig); - - // doLayout(); - //updateStatus(""); - } - + }
/* * Launch the system activity for Uri viewing with the provided url diff --git a/src/org/torproject/android/ui/PromoAppsActivity.java b/src/org/torproject/android/ui/PromoAppsActivity.java new file mode 100644 index 0000000..5d120d3 --- /dev/null +++ b/src/org/torproject/android/ui/PromoAppsActivity.java @@ -0,0 +1,213 @@ +package org.torproject.android.ui; + +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; +import android.util.Log; +import android.view.View; +import android.view.View.OnClickListener; +import android.widget.Button; + +import org.torproject.android.OrbotConstants; +import org.torproject.android.R; +import java.util.List; + +public class PromoAppsActivity extends Activity implements OrbotConstants { + + final static String MARKET_URI = "market://details?id="; + final static String FDROID_APP_URI = "https://f-droid.org/repository/browse/?fdid="; + final static String PLAY_APP_URI = "https://play.google.com/store/apps/details?id="; + final static String FDROID_URI = "https://f-droid.org/repository/browse/?fdfilter=info.guardianproject"; + final static String PLAY_URI = "https://play.google.com/store/apps/developer?id=The+Guardian+Project"; + + private final static String FDROID_PACKAGE_NAME = "org.fdroid.fdroid"; + private final static String PLAY_PACKAGE_NAME = "com.android.vending"; + + @Override + protected void onCreate(Bundle savedInstanceState) + { + super.onCreate(savedInstanceState); + + } + + @Override + protected void onStart() { + + super.onStart(); + setContentView(R.layout.layout_promo_apps); + + stepFive(); + + } + + @Override + protected void onResume() { + super.onResume(); + + + } + + void stepFive(){ + + + String title = getString(R.string.wizard_tips_title); + + setTitle(title); + + Button btnLink = (Button)findViewById(R.id.WizardRootButtonInstallGibberbot); + + btnLink.setOnClickListener(new OnClickListener() { + + @Override + public void onClick(View view) { + finish(); + startActivity(getInstallIntent("info.guardianproject.otr.app.im")); + + } + }); + + btnLink = (Button)findViewById(R.id.WizardRootButtonInstallOrweb); + + btnLink.setOnClickListener(new OnClickListener() { + + @Override + public void onClick(View view) { + finish(); + startActivity(getInstallIntent("info.guardianproject.browser")); + + } + }); + + btnLink = (Button)findViewById(R.id.WizardRootButtonInstallDuckgo); + + btnLink.setOnClickListener(new OnClickListener() { + + @Override + public void onClick(View view) { + + finish(); + startActivity(getInstallIntent("com.duckduckgo.mobile.android")); + + } + }); + + btnLink = (Button)findViewById(R.id.WizardRootButtonInstallTwitter); + + btnLink.setOnClickListener(new OnClickListener() { + + @Override + public void onClick(View view) { + + String url = getString(R.string.twitter_setup_url); + finish(); + startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url))); + + } + }); + + btnLink = (Button)findViewById(R.id.WizardRootButtonInstallStoryMaker); + + btnLink.setOnClickListener(new OnClickListener() { + + @Override + public void onClick(View view) { + finish(); + startActivity(getInstallIntent("info.guardianproject.mrapp")); + + } + }); + + btnLink = (Button)findViewById(R.id.WizardRootButtonInstallMartus); + + btnLink.setOnClickListener(new OnClickListener() { + + @Override + public void onClick(View view) { + finish(); + startActivity(getInstallIntent("org.martus.android")); + + } + }); + + 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() { + + @Override + public void onClick(View view) { + startActivity(intent); + } + }); + + Button next = ((Button)findViewById(R.id.btnWizard2)); + next.setOnClickListener(new View.OnClickListener() { + + public void onClick(View v) { + finish(); + } + }); + + } + + 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)); + + PackageManager pm = getPackageManager(); + List<ResolveInfo> resInfos = pm.queryIntentActivities(intent, 0); + + String foundPackageName = null; + for (ResolveInfo r : resInfos) { + Log.i(TAG, "market: " + r.activityInfo.packageName); + if (TextUtils.equals(r.activityInfo.packageName, FDROID_PACKAGE_NAME) + || TextUtils.equals(r.activityInfo.packageName, PLAY_PACKAGE_NAME)) { + foundPackageName = r.activityInfo.packageName; + break; + } + } + + if (foundPackageName == null) { + intent.setData(Uri.parse(FDROID_APP_URI + packageName)); + } else { + intent.setPackage(foundPackageName); + } + return intent; + } +} diff --git a/src/org/torproject/android/ui/wizard/ChooseLocaleWizardActivity.java b/src/org/torproject/android/ui/wizard/ChooseLocaleWizardActivity.java deleted file mode 100644 index a804f45..0000000 --- a/src/org/torproject/android/ui/wizard/ChooseLocaleWizardActivity.java +++ /dev/null @@ -1,108 +0,0 @@ -package org.torproject.android.ui.wizard; - -import android.app.Activity; -import android.content.Intent; -import android.content.SharedPreferences; -import android.content.SharedPreferences.Editor; -import android.content.res.Configuration; -import android.os.Bundle; -import android.view.KeyEvent; -import android.view.View; -import android.widget.AdapterView; -import android.widget.AdapterView.OnItemClickListener; -import android.widget.ArrayAdapter; -import android.widget.Button; -import android.widget.ListView; -import android.widget.Toast; - -import info.guardianproject.util.Languages; - -import org.torproject.android.OrbotApp; -import org.torproject.android.OrbotConstants; -import org.torproject.android.R; -import org.torproject.android.service.TorServiceUtils; - -import java.util.Locale; - -public class ChooseLocaleWizardActivity extends Activity implements OrbotConstants { - - private ListView listLocales; - private String[] localeValues; - - protected void onCreate(Bundle savedInstanceState) - { - super.onCreate(savedInstanceState); - - setContentView(R.layout.layout_wizard_locale); - - listLocales = (ListView)findViewById(R.id.wizard_locale_list); - Button next = ((Button)findViewById(R.id.btnWizard2)); - // next.setEnabled(false); - - Languages languages = OrbotApp.getLanguages(this); - localeValues = languages.getSupportedLocales(); - ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, - android.R.layout.simple_list_item_1, android.R.id.text1, - languages.getAllNames()); - listLocales.setAdapter(adapter); - - listLocales.setSelection(0); - listLocales.setOnItemClickListener(new OnItemClickListener() { - - @Override - public void onItemClick(AdapterView<?> arg0, View arg1, - int arg2, long arg3) { - - setLocalePref(arg2); - finish(); - startActivity(new Intent(ChooseLocaleWizardActivity.this, PromoAppsActivity.class)); - } - }); - - next.setOnClickListener(new View.OnClickListener() { - - public void onClick(View v) { - setLocalePref(0); - finish(); - startActivity(new Intent(ChooseLocaleWizardActivity.this, PromoAppsActivity.class)); - - } - }); - } - - private void setLocalePref(int selId) - { - SharedPreferences prefs = TorServiceUtils.getSharedPrefs(getApplicationContext()); - - Configuration config = getResources().getConfiguration(); - - String lang = localeValues[selId]; - - Editor pEdit = prefs.edit(); - pEdit.putString(PREF_DEFAULT_LOCALE, lang); - pEdit.commit(); - Locale locale = null; - - if (lang.equals("xx")) - { - locale = Locale.getDefault(); - - } - else - locale = new Locale(lang); - - Locale.setDefault(locale); - config.locale = locale; - getResources().updateConfiguration(config, getResources().getDisplayMetrics()); - } - - //Code to override the back button! - @Override - public boolean onKeyDown(int keyCode, KeyEvent event) { - if(keyCode == KeyEvent.KEYCODE_BACK){ - Toast.makeText(getApplicationContext(), R.string.wizard_exit_at_first_screen_toast, Toast.LENGTH_SHORT).show(); - return true; - } - return false; - } -} \ No newline at end of file diff --git a/src/org/torproject/android/ui/wizard/PromoAppsActivity.java b/src/org/torproject/android/ui/wizard/PromoAppsActivity.java deleted file mode 100644 index 048528f..0000000 --- a/src/org/torproject/android/ui/wizard/PromoAppsActivity.java +++ /dev/null @@ -1,270 +0,0 @@ -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; -import android.util.Log; -import android.view.KeyEvent; -import android.view.View; -import android.view.View.OnClickListener; -import android.widget.Button; - -import org.torproject.android.OrbotConstants; -import org.torproject.android.R; - -import java.util.List; - -public class PromoAppsActivity extends Activity implements OrbotConstants { - - final static String MARKET_URI = "market://details?id="; - final static String FDROID_APP_URI = "https://f-droid.org/repository/browse/?fdid="; - final static String PLAY_APP_URI = "https://play.google.com/store/apps/details?id="; - final static String FDROID_URI = "https://f-droid.org/repository/browse/?fdfilter=info.guardianproject"; - final static String PLAY_URI = "https://play.google.com/store/apps/developer?id=The+Guardian+Project"; - - private final static String FDROID_PACKAGE_NAME = "org.fdroid.fdroid"; - private final static String PLAY_PACKAGE_NAME = "com.android.vending"; - - @Override - protected void onCreate(Bundle savedInstanceState) - { - super.onCreate(savedInstanceState); - - } - - @Override - protected void onStart() { - - super.onStart(); - setContentView(R.layout.layout_wizard_tips); - - stepFive(); - - } - - @Override - protected void onResume() { - super.onResume(); - - - } - - void stepFive(){ - - - String title = getString(R.string.wizard_tips_title); - - setTitle(title); - - Button btnLink = (Button)findViewById(R.id.WizardRootButtonInstallGibberbot); - - btnLink.setOnClickListener(new OnClickListener() { - - @Override - public void onClick(View view) { - finish(); - startActivity(getInstallIntent("info.guardianproject.otr.app.im")); - - } - }); - - btnLink = (Button)findViewById(R.id.WizardRootButtonInstallOrweb); - - btnLink.setOnClickListener(new OnClickListener() { - - @Override - public void onClick(View view) { - finish(); - startActivity(getInstallIntent("info.guardianproject.browser")); - - } - }); - - btnLink = (Button)findViewById(R.id.WizardRootButtonInstallDuckgo); - - btnLink.setOnClickListener(new OnClickListener() { - - @Override - public void onClick(View view) { - - finish(); - startActivity(getInstallIntent("com.duckduckgo.mobile.android")); - - } - }); - - btnLink = (Button)findViewById(R.id.WizardRootButtonInstallTwitter); - - btnLink.setOnClickListener(new OnClickListener() { - - @Override - public void onClick(View view) { - - String url = getString(R.string.twitter_setup_url); - finish(); - startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url))); - - } - }); - - btnLink = (Button)findViewById(R.id.WizardRootButtonInstallStoryMaker); - - btnLink.setOnClickListener(new OnClickListener() { - - @Override - public void onClick(View view) { - finish(); - startActivity(getInstallIntent("info.guardianproject.mrapp")); - - } - }); - - btnLink = (Button)findViewById(R.id.WizardRootButtonInstallMartus); - - btnLink.setOnClickListener(new OnClickListener() { - - @Override - public void onClick(View view) { - finish(); - startActivity(getInstallIntent("org.martus.android")); - - } - }); - - 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() { - - @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) { - if(keyCode == KeyEvent.KEYCODE_BACK){ - finish(); - startActivity(new Intent(getBaseContext(), ChooseLocaleWizardActivity.class)); - return true; - } - 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)); - - PackageManager pm = getPackageManager(); - List<ResolveInfo> resInfos = pm.queryIntentActivities(intent, 0); - - String foundPackageName = null; - for (ResolveInfo r : resInfos) { - Log.i(TAG, "market: " + r.activityInfo.packageName); - if (TextUtils.equals(r.activityInfo.packageName, FDROID_PACKAGE_NAME) - || TextUtils.equals(r.activityInfo.packageName, PLAY_PACKAGE_NAME)) { - foundPackageName = r.activityInfo.packageName; - break; - } - } - - if (foundPackageName == null) { - intent.setData(Uri.parse(FDROID_APP_URI + packageName)); - } else { - intent.setPackage(foundPackageName); - } - return intent; - } - - /* - private void showWizardFinal () - { - 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) - .setPositiveButton(R.string.button_close, ocListener) - .setMessage(msg) - .show(); - }*/ -}
tor-commits@lists.torproject.org