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.io.StringReader;
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
import org.xmlpull.v1.XmlPullParser;
|
import org.xmlpull.v1.XmlPullParser;
|
||||||
import org.xmlpull.v1.XmlPullParserFactory;
|
import org.xmlpull.v1.XmlPullParserFactory;
|
||||||
|
|
||||||
@@ -36,6 +38,7 @@ public class Activity extends Context {
|
|||||||
private int pendingRequestCode;
|
private int pendingRequestCode;
|
||||||
private int pendingResultCode;
|
private int pendingResultCode;
|
||||||
private Intent pendingData;
|
private Intent pendingData;
|
||||||
|
List<Fragment> fragments = new ArrayList<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper function to be called from native code to construct main activity
|
* 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!");
|
System.out.println("- onCreate - yay!");
|
||||||
new ViewGroup(this).setId(R.id.content);
|
new ViewGroup(this).setId(R.id.content);
|
||||||
|
|
||||||
|
for (Fragment fragment : fragments) {
|
||||||
|
fragment.onCreate(savedInstanceState);
|
||||||
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -118,6 +125,10 @@ public class Activity extends Context {
|
|||||||
if (window.contentView != null)
|
if (window.contentView != null)
|
||||||
window.setContentView(window.contentView);
|
window.setContentView(window.contentView);
|
||||||
|
|
||||||
|
for (Fragment fragment : fragments) {
|
||||||
|
fragment.onStart();
|
||||||
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -134,24 +145,40 @@ public class Activity extends Context {
|
|||||||
pendingData = null;
|
pendingData = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (Fragment fragment : fragments) {
|
||||||
|
fragment.onResume();
|
||||||
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void onPause() {
|
protected void onPause() {
|
||||||
System.out.println("- onPause - yay!");
|
System.out.println("- onPause - yay!");
|
||||||
|
|
||||||
|
for (Fragment fragment : fragments) {
|
||||||
|
fragment.onPause();
|
||||||
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void onStop() {
|
protected void onStop() {
|
||||||
System.out.println("- onStop - yay!");
|
System.out.println("- onStop - yay!");
|
||||||
|
|
||||||
|
for (Fragment fragment : fragments) {
|
||||||
|
fragment.onStop();
|
||||||
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void onDestroy() {
|
protected void onDestroy() {
|
||||||
System.out.println("- onDestroy - yay!");
|
System.out.println("- onDestroy - yay!");
|
||||||
|
|
||||||
|
for (Fragment fragment : fragments) {
|
||||||
|
fragment.onDestroy();
|
||||||
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -291,7 +318,7 @@ public class Activity extends Context {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public FragmentManager getFragmentManager() {
|
public FragmentManager getFragmentManager() {
|
||||||
return new FragmentManager();
|
return new FragmentManager(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public LayoutInflater getLayoutInflater() {
|
public LayoutInflater getLayoutInflater() {
|
||||||
|
|||||||
@@ -1,5 +1,31 @@
|
|||||||
package android.app;
|
package android.app;
|
||||||
|
|
||||||
|
import android.os.Bundle;
|
||||||
|
|
||||||
public class Fragment {
|
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;
|
package android.app;
|
||||||
|
|
||||||
public class FragmentManager {
|
public class FragmentManager {
|
||||||
|
|
||||||
|
private Activity activity;
|
||||||
|
|
||||||
|
public FragmentManager(Activity activity) {
|
||||||
|
this.activity = activity;
|
||||||
|
}
|
||||||
|
|
||||||
public Fragment findFragmentByTag(String tag) {
|
public Fragment findFragmentByTag(String tag) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public FragmentTransaction beginTransaction() {
|
public FragmentTransaction beginTransaction() {
|
||||||
return new FragmentTransaction();
|
return new FragmentTransaction(activity);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean executePendingTransactions() {
|
public boolean executePendingTransactions() {
|
||||||
|
|||||||
@@ -1,8 +1,16 @@
|
|||||||
package android.app;
|
package android.app;
|
||||||
|
|
||||||
public class FragmentTransaction {
|
public class FragmentTransaction {
|
||||||
|
|
||||||
|
private Activity activity;
|
||||||
|
|
||||||
|
public FragmentTransaction(Activity activity) {
|
||||||
|
this.activity = activity;
|
||||||
|
}
|
||||||
|
|
||||||
public FragmentTransaction add(Fragment fragment, String string) {
|
public FragmentTransaction add(Fragment fragment, String string) {
|
||||||
|
fragment.activity = activity;
|
||||||
|
activity.fragments.add(fragment);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user