This repository has been archived by the owner on Aug 9, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #4 -> Support nested fragments
- Loading branch information
Victor
committed
May 6, 2016
1 parent
e64019c
commit 46a5a96
Showing
4 changed files
with
106 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package app; | ||
|
||
/** | ||
* Created by victor on 06/05/16. | ||
*/ | ||
public class HostActivitySampleFragmentNested { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package app; | ||
|
||
import android.app.Activity; | ||
import android.content.Intent; | ||
import android.graphics.Bitmap; | ||
import android.os.Bundle; | ||
import android.provider.MediaStore; | ||
import android.support.annotation.Nullable; | ||
import android.support.v4.app.Fragment; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.ImageView; | ||
import android.widget.Toast; | ||
|
||
import io.victoralbertos.app.R; | ||
import rx_activity_result.RxActivityResult; | ||
|
||
/** | ||
* Created by victor on 06/05/16. | ||
*/ | ||
|
||
public class SampleParentFragmentNested extends Fragment { | ||
|
||
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { | ||
View view = inflater.inflate(R.layout.sample_parent_fragment_nested, container, false); | ||
return view; | ||
} | ||
|
||
@Override public void onActivityCreated(@Nullable Bundle savedInstanceState) { | ||
super.onActivityCreated(savedInstanceState); | ||
|
||
getChildFragmentManager() | ||
.beginTransaction() | ||
.add(R.id.fl_fragment_container, new SampleFragmentNested()) | ||
.commit(); | ||
} | ||
|
||
public static class SampleFragmentNested extends Fragment { | ||
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { | ||
View view = inflater.inflate(R.layout.sample_layout, container, false); | ||
return view; | ||
} | ||
|
||
@Override public void onActivityCreated(Bundle savedInstanceState) { | ||
super.onActivityCreated(savedInstanceState); | ||
getView().findViewById(R.id.bt_camera).setOnClickListener(view -> camera()); | ||
} | ||
|
||
private void camera() { | ||
Intent takePhoto = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); | ||
|
||
RxActivityResult.on(this).startIntent(takePhoto) | ||
.subscribe(result -> { | ||
Intent data = result.data(); | ||
int resultCode = result.resultCode(); | ||
|
||
if (resultCode == Activity.RESULT_OK) { | ||
result.targetUI().showImage(data); | ||
} else { | ||
result.targetUI().printUserCanceled(); | ||
} | ||
}); | ||
} | ||
|
||
private void showImage(Intent data) { | ||
Bitmap imageBitmap = (Bitmap) data.getExtras().get("data"); | ||
((ImageView) getView().findViewById(R.id.iv_thumbnail)).setImageBitmap(imageBitmap); | ||
} | ||
|
||
private void printUserCanceled() { | ||
Toast.makeText(getActivity(), getString(R.string.user_canceled_action), Toast.LENGTH_LONG).show(); | ||
} | ||
} | ||
|
||
|
||
} | ||
|
||
|
14 changes: 14 additions & 0 deletions
14
app/src/main/res/layout/host_activity_sample_fragment_nested.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:orientation="vertical" android:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
|
||
<fragment | ||
android:id="@+id/sample_fragment" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
class="app.SampleFragment" | ||
tools:layout="@layout/sample_layout" /> | ||
|
||
</LinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:orientation="vertical" android:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
|
||
</LinearLayout> |