-
Notifications
You must be signed in to change notification settings - Fork 144
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed callback if DialogFragment called from an other Fragment #39
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="net.rdrei.android.dirchooser.sample"> | ||
package="net.rdrei.android.dirchooser.sample" > | ||
|
||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> | ||
|
||
|
@@ -20,9 +20,13 @@ | |
</activity> | ||
<activity | ||
android:name="net.rdrei.android.dirchooser.sample.DirChooserFragmentSample" | ||
android:configChanges="orientation|screenSize" | ||
android:label="@string/app_name" | ||
android:parentActivityName="net.rdrei.android.dirchooser.sample.DirChooserSample" | ||
android:configChanges="orientation|screenSize" > | ||
android:parentActivityName="net.rdrei.android.dirchooser.sample.DirChooserSample" > | ||
</activity> | ||
<activity | ||
android:name="net.rdrei.android.dirchooser.sample.DirChooserFragmentHolder" | ||
android:label="@string/title_activity_dir_chooser_fragment_holder" > | ||
</activity> | ||
</application> | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you reduce this to the minimum changes necessary? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can make a new push only with changes in the library project. Or the other solution could be to combine all the changes in a one Activity. Because at the moment there is a necessary method call for a Fragment ( mDialog.setTargetFragment(this, REQUEST_CODE); ), so I think the sample will be useful. And what do you think ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's a tough one. I think I'd prefer the way you took here and keep them separate, because I think that keeping the example simple is very important for its usefulness. |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package net.rdrei.android.dirchooser.sample; | ||
|
||
|
||
import android.os.Bundle; | ||
import android.app.Fragment; | ||
import android.support.annotation.NonNull; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.Button; | ||
import android.widget.TextView; | ||
|
||
import net.rdrei.android.dirchooser.DirectoryChooserFragment; | ||
|
||
|
||
public class DirChooserFragment extends Fragment implements DirectoryChooserFragment.OnFragmentInteractionListener { | ||
|
||
private static final int REQUEST_CODE = 0; | ||
|
||
private TextView mDirectoryTextView; | ||
private DirectoryChooserFragment mDialog; | ||
|
||
@Override | ||
public void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
mDialog = DirectoryChooserFragment.newInstance("DialogSample", null); | ||
|
||
// You must set this Fragment to the Dialog for receiving the callback. | ||
mDialog.setTargetFragment(this, REQUEST_CODE); | ||
} | ||
|
||
@Override | ||
public View onCreateView(LayoutInflater inflater, ViewGroup container, | ||
Bundle savedInstanceState) { | ||
// Inflate the layout for this fragment | ||
View view = inflater.inflate(R.layout.fragment_blank, container, false); | ||
mDirectoryTextView = (TextView) view.findViewById(R.id.tvFragmentText); | ||
|
||
view.findViewById(R.id.btnStart).setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View view) { | ||
mDialog.show(getFragmentManager(), null); | ||
} | ||
}); | ||
|
||
return view; | ||
} | ||
|
||
|
||
@Override | ||
public void onSelectDirectory(@NonNull String path) { | ||
mDirectoryTextView.setText(path); | ||
mDialog.dismiss(); | ||
} | ||
|
||
@Override | ||
public void onCancelChooser() { | ||
mDialog.dismiss(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package net.rdrei.android.dirchooser.sample; | ||
|
||
import android.app.Activity; | ||
import android.app.ActionBar; | ||
import android.app.Fragment; | ||
import android.os.Bundle; | ||
import android.view.LayoutInflater; | ||
import android.view.Menu; | ||
import android.view.MenuItem; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.os.Build; | ||
|
||
|
||
|
||
public class DirChooserFragmentHolder extends Activity { | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_dir_chooser_fragment_holder); | ||
if (savedInstanceState == null) { | ||
getFragmentManager().beginTransaction() | ||
.add(R.id.container, new DirChooserFragment()) | ||
.commit(); | ||
} | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:id="@+id/container" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
tools:context="net.rdrei.android.dirchooser.sample.DirChooserFragmentHolder" | ||
tools:ignore="MergeRootFrame" /> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<FrameLayout 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" | ||
android:padding="8dp" | ||
tools:context="net.rdrei.android.dirchooser.sample.DirChooserFragment"> | ||
|
||
<TextView | ||
android:layout_width="fill_parent" | ||
android:layout_height="wrap_content" | ||
android:text="@string/directory_selected_label" | ||
android:textAppearance="?android:attr/textAppearanceMedium"/> | ||
|
||
<TextView | ||
android:id="@+id/tvFragmentText" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:fontFamily="monospace" | ||
android:text="@string/none" | ||
tools:ignore="UnusedAttribute" | ||
android:layout_marginTop="24dp" /> | ||
|
||
<Button | ||
android:id="@+id/btnStart" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_gravity="center" | ||
android:text="@string/title_start_button" /> | ||
|
||
</FrameLayout> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:id="@+id/root" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:paddingLeft="@dimen/activity_horizontal_margin" | ||
android:paddingRight="@dimen/activity_horizontal_margin" | ||
android:paddingTop="@dimen/activity_vertical_margin" | ||
android:paddingBottom="@dimen/activity_vertical_margin" | ||
tools:context="net.rdrei.android.dirchooser.sample.DirChooserFragmentHolder$PlaceholderFragment"> | ||
|
||
</FrameLayout> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<resources> | ||
<!-- Default screen margins, per the Android Design guidelines. --> | ||
<dimen name="activity_horizontal_margin">16dp</dimen> | ||
<dimen name="activity_vertical_margin">16dp</dimen> | ||
</resources> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we now have proper checks in place, we no longer need to catch the ClassCastException
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
^