You've already forked android_translation_layer
mirror of
https://gitlab.com/android_translation_layer/android_translation_layer.git
synced 2025-10-27 11:48:10 -07:00
add initial support for fragments
Fragments are not added to the View hierarchy yet. Only the lifecycle callbacks are implemented
This commit is contained in:
@@ -23,6 +23,8 @@ import java.io.InputStream;
|
||||
import java.io.StringReader;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
import org.xmlpull.v1.XmlPullParserFactory;
|
||||
|
||||
@@ -36,6 +38,7 @@ public class Activity extends Context {
|
||||
private int pendingRequestCode;
|
||||
private int pendingResultCode;
|
||||
private Intent pendingData;
|
||||
List<Fragment> fragments = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Helper function to be called from native code to construct main activity
|
||||
@@ -110,6 +113,10 @@ public class Activity extends Context {
|
||||
System.out.println("- onCreate - yay!");
|
||||
new ViewGroup(this).setId(R.id.content);
|
||||
|
||||
for (Fragment fragment : fragments) {
|
||||
fragment.onCreate(savedInstanceState);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -118,6 +125,10 @@ public class Activity extends Context {
|
||||
if (window.contentView != null)
|
||||
window.setContentView(window.contentView);
|
||||
|
||||
for (Fragment fragment : fragments) {
|
||||
fragment.onStart();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -134,24 +145,40 @@ public class Activity extends Context {
|
||||
pendingData = null;
|
||||
}
|
||||
|
||||
for (Fragment fragment : fragments) {
|
||||
fragment.onResume();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
protected void onPause() {
|
||||
System.out.println("- onPause - yay!");
|
||||
|
||||
for (Fragment fragment : fragments) {
|
||||
fragment.onPause();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
protected void onStop() {
|
||||
System.out.println("- onStop - yay!");
|
||||
|
||||
for (Fragment fragment : fragments) {
|
||||
fragment.onStop();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
protected void onDestroy() {
|
||||
System.out.println("- onDestroy - yay!");
|
||||
|
||||
for (Fragment fragment : fragments) {
|
||||
fragment.onDestroy();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -291,7 +318,7 @@ public class Activity extends Context {
|
||||
}
|
||||
|
||||
public FragmentManager getFragmentManager() {
|
||||
return new FragmentManager();
|
||||
return new FragmentManager(this);
|
||||
}
|
||||
|
||||
public LayoutInflater getLayoutInflater() {
|
||||
|
||||
@@ -1,5 +1,31 @@
|
||||
package android.app;
|
||||
|
||||
import android.os.Bundle;
|
||||
|
||||
public class Fragment {
|
||||
|
||||
|
||||
Activity activity;
|
||||
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
}
|
||||
|
||||
public void onStart() {
|
||||
}
|
||||
|
||||
public void onResume() {
|
||||
}
|
||||
|
||||
public void onPause() {
|
||||
}
|
||||
|
||||
public void onStop() {
|
||||
}
|
||||
|
||||
public void onDestroy() {
|
||||
}
|
||||
|
||||
public Activity getActivity() {
|
||||
return activity;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,13 +1,19 @@
|
||||
package android.app;
|
||||
|
||||
public class FragmentManager {
|
||||
|
||||
private Activity activity;
|
||||
|
||||
public FragmentManager(Activity activity) {
|
||||
this.activity = activity;
|
||||
}
|
||||
|
||||
public Fragment findFragmentByTag(String tag) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public FragmentTransaction beginTransaction() {
|
||||
return new FragmentTransaction();
|
||||
return new FragmentTransaction(activity);
|
||||
}
|
||||
|
||||
public boolean executePendingTransactions() {
|
||||
|
||||
@@ -1,8 +1,16 @@
|
||||
package android.app;
|
||||
|
||||
public class FragmentTransaction {
|
||||
|
||||
private Activity activity;
|
||||
|
||||
public FragmentTransaction(Activity activity) {
|
||||
this.activity = activity;
|
||||
}
|
||||
|
||||
public FragmentTransaction add(Fragment fragment, String string) {
|
||||
fragment.activity = activity;
|
||||
activity.fragments.add(fragment);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user