└── DialogFragmentFragment ├── .gitignore ├── .idea ├── gradle.xml ├── misc.xml ├── modules.xml └── runConfigurations.xml ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── codingwithmitch │ │ └── com │ │ └── dialogfragmentfragment │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── codingwithmitch │ │ │ └── com │ │ │ └── dialogfragmentfragment │ │ │ ├── MainActivity.java │ │ │ ├── MainFragment.java │ │ │ └── MyCustomDialog.java │ └── res │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable │ │ └── ic_launcher_background.xml │ │ ├── layout │ │ ├── activity_main.xml │ │ ├── dialog_my_custom.xml │ │ └── fragment_main.xml │ │ ├── mipmap-anydpi-v26 │ │ ├── ic_launcher.xml │ │ └── ic_launcher_round.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── codingwithmitch │ └── com │ └── dialogfragmentfragment │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /DialogFragmentFragment/.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | .externalNativeBuild 10 | -------------------------------------------------------------------------------- /DialogFragmentFragment/.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 17 | 18 | -------------------------------------------------------------------------------- /DialogFragmentFragment/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 16 | 26 | 27 | 28 | 29 | 30 | 31 | 33 | -------------------------------------------------------------------------------- /DialogFragmentFragment/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /DialogFragmentFragment/.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /DialogFragmentFragment/app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /DialogFragmentFragment/app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 26 5 | defaultConfig { 6 | applicationId "codingwithmitch.com.dialogfragmentfragment" 7 | minSdkVersion 16 8 | targetSdkVersion 26 9 | versionCode 1 10 | versionName "1.0" 11 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 12 | } 13 | buildTypes { 14 | release { 15 | minifyEnabled false 16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 17 | } 18 | } 19 | } 20 | 21 | dependencies { 22 | implementation fileTree(dir: 'libs', include: ['*.jar']) 23 | implementation 'com.android.support:appcompat-v7:26.1.0' 24 | implementation 'com.android.support.constraint:constraint-layout:1.0.2' 25 | testImplementation 'junit:junit:4.12' 26 | androidTestImplementation 'com.android.support.test:runner:1.0.1' 27 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1' 28 | } 29 | -------------------------------------------------------------------------------- /DialogFragmentFragment/app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /DialogFragmentFragment/app/src/androidTest/java/codingwithmitch/com/dialogfragmentfragment/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package codingwithmitch.com.dialogfragmentfragment; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumented test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("codingwithmitch.com.dialogfragmentfragment", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /DialogFragmentFragment/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /DialogFragmentFragment/app/src/main/java/codingwithmitch/com/dialogfragmentfragment/MainActivity.java: -------------------------------------------------------------------------------- 1 | package codingwithmitch.com.dialogfragmentfragment; 2 | 3 | 4 | import android.app.FragmentTransaction; 5 | import android.support.v7.app.AppCompatActivity; 6 | import android.os.Bundle; 7 | 8 | public class MainActivity extends AppCompatActivity { 9 | 10 | private static final String TAG = "MainActivity"; 11 | 12 | @Override 13 | protected void onCreate(Bundle savedInstanceState) { 14 | super.onCreate(savedInstanceState); 15 | setContentView(R.layout.activity_main); 16 | 17 | MainFragment fragment = new MainFragment(); 18 | 19 | FragmentTransaction transaction = getFragmentManager().beginTransaction(); 20 | transaction.replace(R.id.container, fragment, "MainFragment"); 21 | transaction.commit(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /DialogFragmentFragment/app/src/main/java/codingwithmitch/com/dialogfragmentfragment/MainFragment.java: -------------------------------------------------------------------------------- 1 | package codingwithmitch.com.dialogfragmentfragment; 2 | 3 | import android.app.Fragment; 4 | import android.os.Bundle; 5 | import android.support.annotation.Nullable; 6 | 7 | import android.util.Log; 8 | import android.view.LayoutInflater; 9 | import android.view.View; 10 | import android.view.ViewGroup; 11 | import android.widget.Button; 12 | import android.widget.TextView; 13 | 14 | import org.w3c.dom.Text; 15 | 16 | /** 17 | * Created by User on 12/10/2017. 18 | */ 19 | 20 | public class MainFragment extends Fragment implements MyCustomDialog.OnInputSelected{ 21 | 22 | 23 | private static final String TAG = "MainFragment"; 24 | 25 | @Override 26 | public void sendInput(String input) { 27 | Log.d(TAG, "sendInput: found incoming input: " + input); 28 | 29 | mInputDisplay.setText(input); 30 | } 31 | 32 | private Button mOpenDialog; 33 | public TextView mInputDisplay; 34 | 35 | @Nullable 36 | @Override 37 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 38 | View view = inflater.inflate(R.layout.fragment_main, container, false); 39 | mOpenDialog = view.findViewById(R.id.open_dialog); 40 | mInputDisplay = view.findViewById(R.id.input_display); 41 | 42 | mOpenDialog.setOnClickListener(new View.OnClickListener() { 43 | @Override 44 | public void onClick(View v) { 45 | Log.d(TAG, "onClick: opening dialog"); 46 | 47 | MyCustomDialog dialog = new MyCustomDialog(); 48 | dialog.setTargetFragment(MainFragment.this, 1); 49 | dialog.show(getFragmentManager(), "MyCustomDialog"); 50 | } 51 | }); 52 | 53 | 54 | return view; 55 | } 56 | 57 | 58 | } 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | -------------------------------------------------------------------------------- /DialogFragmentFragment/app/src/main/java/codingwithmitch/com/dialogfragmentfragment/MyCustomDialog.java: -------------------------------------------------------------------------------- 1 | package codingwithmitch.com.dialogfragmentfragment; 2 | 3 | import android.app.DialogFragment; 4 | import android.content.Context; 5 | import android.os.Bundle; 6 | import android.support.annotation.Nullable; 7 | import android.util.Log; 8 | import android.view.LayoutInflater; 9 | import android.view.View; 10 | import android.view.ViewGroup; 11 | import android.widget.EditText; 12 | import android.widget.TextView; 13 | 14 | /** 15 | * Created by User on 12/10/2017. 16 | */ 17 | 18 | public class MyCustomDialog extends DialogFragment { 19 | 20 | private static final String TAG = "MyCustomDialog"; 21 | 22 | public interface OnInputSelected{ 23 | void sendInput(String input); 24 | } 25 | public OnInputSelected mOnInputSelected; 26 | 27 | //widgets 28 | private EditText mInput; 29 | private TextView mActionOk, mActionCancel; 30 | 31 | @Nullable 32 | @Override 33 | public View onCreateView(final LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) { 34 | View view = inflater.inflate(R.layout.dialog_my_custom, container, false); 35 | mActionOk = view.findViewById(R.id.action_ok); 36 | mActionCancel = view.findViewById(R.id.action_cancel); 37 | mInput = view.findViewById(R.id.input); 38 | 39 | mActionCancel.setOnClickListener(new View.OnClickListener() { 40 | @Override 41 | public void onClick(View v) { 42 | Log.d(TAG, "onClick: closing dialog"); 43 | getDialog().dismiss(); 44 | } 45 | }); 46 | 47 | mActionOk.setOnClickListener(new View.OnClickListener() { 48 | @Override 49 | public void onClick(View v) { 50 | Log.d(TAG, "onClick: capturing input."); 51 | 52 | String input = mInput.getText().toString(); 53 | if(!input.equals("")){ 54 | // 55 | // //Easiest way: just set the value. 56 | // MainFragment fragment = (MainFragment) getActivity().getFragmentManager().findFragmentByTag("MainFragment"); 57 | // fragment.mInputDisplay.setText(input); 58 | 59 | mOnInputSelected.sendInput(input); 60 | } 61 | 62 | 63 | getDialog().dismiss(); 64 | } 65 | }); 66 | 67 | return view; 68 | } 69 | 70 | @Override 71 | public void onAttach(Context context) { 72 | super.onAttach(context); 73 | try{ 74 | mOnInputSelected = (OnInputSelected) getTargetFragment(); 75 | }catch (ClassCastException e){ 76 | Log.e(TAG, "onAttach: ClassCastException : " + e.getMessage() ); 77 | } 78 | } 79 | } 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | -------------------------------------------------------------------------------- /DialogFragmentFragment/app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /DialogFragmentFragment/app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 11 | 16 | 21 | 26 | 31 | 36 | 41 | 46 | 51 | 56 | 61 | 66 | 71 | 76 | 81 | 86 | 91 | 96 | 101 | 106 | 111 | 116 | 121 | 126 | 131 | 136 | 141 | 146 | 151 | 156 | 161 | 166 | 171 | 172 | -------------------------------------------------------------------------------- /DialogFragmentFragment/app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 14 | 15 | -------------------------------------------------------------------------------- /DialogFragmentFragment/app/src/main/res/layout/dialog_my_custom.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 15 | 16 | 23 | 24 | 33 | 34 | 44 | 45 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /DialogFragmentFragment/app/src/main/res/layout/fragment_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 18 | 19 |