commit ee3e05423abd4f68b146711b21b1053f5742c669 Author: Hashik Donthineni hashikdonthineni@gmail.com Date: Thu Feb 27 21:45:04 2020 +0530
Fixed blank screen when orintation changed in AppIntro --- .../org/torproject/android/OrbotMainActivity.java | 3 - .../android/ui/onboarding/CustomSlideBigText.java | 51 +++++++--- .../android/ui/onboarding/OnboardingActivity.java | 105 +++++++++++++++------ 3 files changed, 113 insertions(+), 46 deletions(-)
diff --git a/app/src/main/java/org/torproject/android/OrbotMainActivity.java b/app/src/main/java/org/torproject/android/OrbotMainActivity.java index 831f55f9..4f4ab222 100644 --- a/app/src/main/java/org/torproject/android/OrbotMainActivity.java +++ b/app/src/main/java/org/torproject/android/OrbotMainActivity.java @@ -194,9 +194,6 @@ public class OrbotMainActivity extends AppCompatActivity
if (showFirstTime) { - Editor pEdit = mPrefs.edit(); - pEdit.putBoolean("connect_first_time", false); - pEdit.commit(); startActivity(new Intent(this,OnboardingActivity.class)); }
diff --git a/app/src/main/java/org/torproject/android/ui/onboarding/CustomSlideBigText.java b/app/src/main/java/org/torproject/android/ui/onboarding/CustomSlideBigText.java index b4f319b2..c010ce0d 100644 --- a/app/src/main/java/org/torproject/android/ui/onboarding/CustomSlideBigText.java +++ b/app/src/main/java/org/torproject/android/ui/onboarding/CustomSlideBigText.java @@ -1,14 +1,17 @@ package org.torproject.android.ui.onboarding;
import android.os.Bundle; + import androidx.annotation.Nullable; import androidx.fragment.app.Fragment; + import android.text.TextUtils; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Button; import android.widget.TextView; + import org.torproject.android.R;
public class CustomSlideBigText extends Fragment { @@ -19,6 +22,8 @@ public class CustomSlideBigText extends Fragment { private String mButtonText; private String mSubTitle; private View.OnClickListener mButtonListener; + TextView tv, title; + Button button;
public static CustomSlideBigText newInstance(int layoutResId) { CustomSlideBigText sampleSlide = new CustomSlideBigText(); @@ -30,15 +35,15 @@ public class CustomSlideBigText extends Fragment { return sampleSlide; }
- public void setTitle (String title) - { + public void setTitle(String title) { mTitle = title; }
- public void setSubTitle(String subTitle) { mSubTitle = subTitle; } + public void setSubTitle(String subTitle) { + mSubTitle = subTitle; + }
- public void showButton (String buttonText, View.OnClickListener buttonListener) - { + public void showButton(String buttonText, View.OnClickListener buttonListener) { mButtonText = buttonText; mButtonListener = buttonListener; } @@ -57,19 +62,17 @@ public class CustomSlideBigText extends Fragment { public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View view = inflater.inflate(layoutResId, container, false); - ((TextView)view.findViewById(R.id.custom_slide_big_text)).setText(mTitle); - + title = ((TextView) view.findViewById(R.id.custom_slide_big_text)); + title.setText(mTitle); + tv = (TextView) view.findViewById(R.id.custom_slide_big_text_sub); if (!TextUtils.isEmpty(mSubTitle)) {
- TextView tv = - (TextView)view.findViewById(R.id.custom_slide_big_text_sub); tv.setText(mSubTitle); tv.setVisibility(View.VISIBLE); }
- if (mButtonText != null) - { - Button button = (Button)view.findViewById(R.id.custom_slide_button); + if (mButtonText != null) { + button = (Button) view.findViewById(R.id.custom_slide_button); button.setVisibility(View.VISIBLE); button.setText(mButtonText); button.setOnClickListener(mButtonListener); @@ -77,4 +80,28 @@ public class CustomSlideBigText extends Fragment { return view;
} + + @Override + public void onActivityCreated(Bundle savedInstanceState) { + super.onActivityCreated(savedInstanceState); + if (savedInstanceState != null) { + savedInstanceState.getString("Title"); + tv.setText(savedInstanceState.getString("SubTitle")); + if (mButtonText != null) { + button.setText(savedInstanceState.getString("ButtonText")); + } + + } + } + + @Override + public void onSaveInstanceState(Bundle outState) { + super.onSaveInstanceState(outState); + outState.putString("Title", mTitle); + outState.putString("SubTitle", mSubTitle); + if (mButtonText != null) { + outState.putString("ButtonText", mButtonText); + } + } + } diff --git a/app/src/main/java/org/torproject/android/ui/onboarding/OnboardingActivity.java b/app/src/main/java/org/torproject/android/ui/onboarding/OnboardingActivity.java index e73a88b8..a732e76d 100644 --- a/app/src/main/java/org/torproject/android/ui/onboarding/OnboardingActivity.java +++ b/app/src/main/java/org/torproject/android/ui/onboarding/OnboardingActivity.java @@ -2,62 +2,80 @@ package org.torproject.android.ui.onboarding;
import android.content.Context; import android.content.Intent; +import android.content.SharedPreferences; import android.os.Bundle; import androidx.annotation.Nullable; import androidx.fragment.app.Fragment; + +import android.util.Log; import android.view.View; import com.github.paolorotolo.appintro.AppIntro; import org.torproject.android.R; +import org.torproject.android.service.util.Prefs; import org.torproject.android.settings.LocaleHelper; import org.torproject.android.ui.AppManagerActivity; import org.torproject.android.ui.VPNEnableActivity; import org.torproject.android.ui.hiddenservices.permissions.PermissionManager;
+import java.util.HashMap; +import java.util.LinkedList; + public class OnboardingActivity extends AppIntro { + CustomSlideBigText welcome, intro2, cs2, cs3;
@Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState);
- // Instead of fragments, you can also use our default slide - // Just set a title, description, background and image. AppIntro will do the rest. - CustomSlideBigText welcome = CustomSlideBigText.newInstance(R.layout.custom_slide_big_text); - welcome.setTitle(getString(R.string.hello)); - welcome.setSubTitle(getString(R.string.welcome)); - addSlide(welcome); - - CustomSlideBigText intro2 = CustomSlideBigText.newInstance(R.layout.custom_slide_big_text); - intro2.setTitle(getString(R.string.browser_the_internet)); - intro2.setSubTitle(getString(R.string.no_tracking)); - addSlide(intro2); - - CustomSlideBigText cs2 = CustomSlideBigText.newInstance(R.layout.custom_slide_big_text); - cs2.setTitle(getString(R.string.bridges_sometimes)); - cs2.showButton(getString(R.string.action_more), new View.OnClickListener() { - @Override - public void onClick(View v) { - startActivity(new Intent(OnboardingActivity.this,BridgeWizardActivity.class)); - } - }); - addSlide(cs2); + if (savedInstanceState != null) { + welcome = (CustomSlideBigText) getSupportFragmentManager().getFragment(savedInstanceState, "welcome"); + intro2 = (CustomSlideBigText) getSupportFragmentManager().getFragment(savedInstanceState, "intro2"); + cs2 = (CustomSlideBigText) getSupportFragmentManager().getFragment(savedInstanceState, "cs2"); + if (PermissionManager.isLollipopOrHigher()) + cs3 = (CustomSlideBigText) getSupportFragmentManager().getFragment(savedInstanceState, "cs3");
- if (PermissionManager.isLollipopOrHigher()) { + }else{ + // Instead of fragments, you can also use our default slide + // Just set a title, description, background and image. AppIntro will do the rest. + welcome = CustomSlideBigText.newInstance(R.layout.custom_slide_big_text); + welcome.setTitle(getString(R.string.hello)); + welcome.setSubTitle(getString(R.string.welcome)); + addSlide(welcome);
- CustomSlideBigText cs3 = CustomSlideBigText.newInstance(R.layout.custom_slide_big_text); - cs3.setTitle(getString(R.string.vpn_setup)); - cs3.setSubTitle(getString(R.string.vpn_setup_sub)); - cs3.showButton(getString(R.string.action_vpn_choose), new View.OnClickListener() { + intro2 = CustomSlideBigText.newInstance(R.layout.custom_slide_big_text); + intro2.setTitle(getString(R.string.browser_the_internet)); + intro2.setSubTitle(getString(R.string.no_tracking)); + addSlide(intro2); + + cs2 = CustomSlideBigText.newInstance(R.layout.custom_slide_big_text); + cs2.setTitle(getString(R.string.bridges_sometimes)); + cs2.showButton(getString(R.string.action_more), new View.OnClickListener() { @Override public void onClick(View v) { - startActivity(new Intent(OnboardingActivity.this, VPNEnableActivity.class)); - startActivityForResult(new Intent(OnboardingActivity.this, AppManagerActivity.class), 9999); - + startActivity(new Intent(OnboardingActivity.this,BridgeWizardActivity.class)); } }); - addSlide(cs3); + addSlide(cs2);
+ if (PermissionManager.isLollipopOrHigher()) { + + cs3 = CustomSlideBigText.newInstance(R.layout.custom_slide_big_text); + cs3.setTitle(getString(R.string.vpn_setup)); + cs3.setSubTitle(getString(R.string.vpn_setup_sub)); + cs3.showButton(getString(R.string.action_vpn_choose), new View.OnClickListener() { + @Override + public void onClick(View v) { + startActivity(new Intent(OnboardingActivity.this, VPNEnableActivity.class)); + startActivityForResult(new Intent(OnboardingActivity.this, AppManagerActivity.class), 9999); + + } + }); + addSlide(cs3); + + } }
+ // OPTIONAL METHODS // Override bar/separator color. setBarColor(getResources().getColor(R.color.dark_purple)); @@ -71,7 +89,11 @@ public class OnboardingActivity extends AppIntro { @Override public void onDonePressed(Fragment currentFragment) { super.onDonePressed(currentFragment); - // Do something when users tap on Done button. + // Setting first time app open flag "connect_firest_time" to false + SharedPreferences.Editor pEdit = Prefs.getSharedPrefs(getApplicationContext()).edit(); + pEdit.putBoolean("connect_first_time", false); + pEdit.apply(); + finish(); }
@@ -79,4 +101,25 @@ public class OnboardingActivity extends AppIntro { protected void attachBaseContext(Context base) { super.attachBaseContext(LocaleHelper.onAttach(base)); } + + @Override + protected void onSaveInstanceState(Bundle outState) { + super.onSaveInstanceState(outState); + + //Save the fragment's instance + int count = 0; + for (Fragment fragment : getSupportFragmentManager().getFragments()) { + count++; + } + + //Should check if the fragment exists in the fragment manager or else it'll flag error + if(count >= 1) + getSupportFragmentManager().putFragment(outState, "welcome", welcome); + if(count >= 2) + getSupportFragmentManager().putFragment(outState, "intro2", intro2); + if(count >=3) + getSupportFragmentManager().putFragment(outState, "cs2", cs2); + if (count >= 4 && PermissionManager.isLollipopOrHigher()) + getSupportFragmentManager().putFragment(outState, "cs3", cs3); + } } \ No newline at end of file
tor-commits@lists.torproject.org