commit 272ca20f2ea2d7f6869da4e4a6f8a66b2f97c8bb Author: Hashik Donthineni HashikDonthineni@gmail.com Date: Sun Jun 28 15:26:42 2020 +0530
Started MainFragment from MainActivity --- .../main/java/org/torproject/snowflake/MainActivity.java | 16 ++++++++++++++++ .../main/java/org/torproject/snowflake/MainFragment.java | 5 +++-- app/src/main/res/layout/activity_main.xml | 6 ++++++ app/src/main/res/layout/fragment_main_fragment.xml | 4 ++-- 4 files changed, 27 insertions(+), 4 deletions(-)
diff --git a/app/src/main/java/org/torproject/snowflake/MainActivity.java b/app/src/main/java/org/torproject/snowflake/MainActivity.java index d412944..642fe21 100644 --- a/app/src/main/java/org/torproject/snowflake/MainActivity.java +++ b/app/src/main/java/org/torproject/snowflake/MainActivity.java @@ -10,6 +10,7 @@ import android.os.Build; import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity; +import androidx.fragment.app.Fragment;
import org.torproject.snowflake.constants.ForegroundServiceConstants; import org.torproject.snowflake.interfaces.MainFragmentCallback; @@ -34,6 +35,21 @@ public class MainActivity extends AppCompatActivity implements MainFragmentCallb //Setting initial run to false. sharedPreferences.edit().putBoolean(getString(R.string.initial_run_boolean), false).apply(); } + + //Starting the MainFragment. + startFragment(MainFragment.newInstance()); + } + + /** + * Used to replace the fragment in the "fragment_container" + * + * @param fragment New Fragment that is to be placed in the container. + */ + private void startFragment(Fragment fragment) { + getSupportFragmentManager() + .beginTransaction() + .replace(R.id.fragment_container, + fragment).commit(); }
/** diff --git a/app/src/main/java/org/torproject/snowflake/MainFragment.java b/app/src/main/java/org/torproject/snowflake/MainFragment.java index f850277..e30923b 100644 --- a/app/src/main/java/org/torproject/snowflake/MainFragment.java +++ b/app/src/main/java/org/torproject/snowflake/MainFragment.java @@ -46,7 +46,8 @@ public class MainFragment extends Fragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - Button startButton = container.findViewById(R.id.start_button); + View rootView = inflater.inflate(R.layout.fragment_main_fragment, container, false); + Button startButton = rootView.findViewById(R.id.start_button); startButton.setOnClickListener(v -> { if (callback.isServiceRunning()) //Toggling the service. callback.serviceToggle(ForegroundServiceConstants.ACTION_STOP); @@ -57,7 +58,7 @@ public class MainFragment extends Fragment { startButton.performClick(); //To perform an automatic click in testing environment.
// Inflate the layout for this fragment - return inflater.inflate(R.layout.fragment_main_fragment, container, false); + return rootView; }
@Override diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index abc7268..c9f27a2 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -38,4 +38,10 @@ android:foreground="?android:attr/selectableItemBackground" /> </RelativeLayout> </androidx.appcompat.widget.Toolbar> + + <FrameLayout + android:layout_width="match_parent" + android:layout_height="match_parent" + android:id="@+id/fragment_container" + app:layout_constraintTop_toBottomOf="@+id/toolbar" /> </androidx.constraintlayout.widget.ConstraintLayout> \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_main_fragment.xml b/app/src/main/res/layout/fragment_main_fragment.xml index 7523126..6e9c225 100644 --- a/app/src/main/res/layout/fragment_main_fragment.xml +++ b/app/src/main/res/layout/fragment_main_fragment.xml @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="utf-8"?> -<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" +<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" @@ -14,4 +14,4 @@ android:foreground="?android:attr/selectableItemBackground" android:text="Service Toggle" />
-</FrameLayout> \ No newline at end of file +</RelativeLayout> \ No newline at end of file
tor-commits@lists.torproject.org