-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
molihuan
committed
Jun 7, 2022
1 parent
0ec00a7
commit 94539b2
Showing
49 changed files
with
1,401 additions
and
560 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 |
---|---|---|
|
@@ -13,3 +13,5 @@ | |
.externalNativeBuild | ||
.cxx | ||
local.properties | ||
gradles | ||
gradle.properties |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
89 changes: 89 additions & 0 deletions
89
app/src/main/java/com/molihuan/demo01/fragments/BaseFragment.java
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,89 @@ | ||
package com.molihuan.demo01.fragments; | ||
|
||
import android.app.Activity; | ||
import android.content.Context; | ||
import android.os.Bundle; | ||
import android.util.Log; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
|
||
import androidx.annotation.LayoutRes; | ||
import androidx.annotation.NonNull; | ||
import androidx.fragment.app.Fragment; | ||
|
||
import com.zlylib.mlhfileselectorlib.interfaces.IActivityAndFragment; | ||
|
||
|
||
public abstract class BaseFragment extends Fragment implements View.OnClickListener { | ||
|
||
private int mFragmentViewId; | ||
private View mFragmentView; | ||
public Activity mActivity; | ||
public IActivityAndFragment mIActivityAndFragment;//定义activity与fragment通信接口 | ||
|
||
public BaseFragment() { | ||
// Required empty public constructor | ||
} | ||
public BaseFragment(@LayoutRes int fragmentViewId) { | ||
mFragmentViewId=fragmentViewId; | ||
} | ||
|
||
|
||
@Override | ||
public void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
|
||
} | ||
|
||
@Override | ||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { | ||
if (mFragmentView==null){ | ||
mFragmentView = inflater.inflate(mFragmentViewId, container, false); | ||
getComponents(mFragmentView);//获取组件 | ||
setListeners(mFragmentView);//设置监听 | ||
initData(mFragmentView);//初始化数据 | ||
} | ||
return mFragmentView; | ||
} | ||
|
||
public abstract void initData(View view); | ||
|
||
public abstract void setListeners(View view); | ||
|
||
public abstract void getComponents(View view); | ||
|
||
@Override | ||
public abstract void onClick(View v); | ||
|
||
|
||
|
||
/** | ||
* 当Activity和Fragment产生关系时调用 | ||
* context可以强转为Activity | ||
* @param context | ||
*/ | ||
@Override | ||
public void onAttach(@NonNull Context context) { | ||
super.onAttach(context); | ||
if (mActivity==null){ | ||
mActivity= getActivity(); | ||
} | ||
|
||
try { | ||
//获取通信接口实例 | ||
mIActivityAndFragment= (IActivityAndFragment) context; | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
Log.e("interfaceError","IActivityAndFragment错误,Activity必须实现IActivityAndFragment接口"); | ||
} | ||
} | ||
|
||
/** | ||
* 当Activity和Fragment脱离时调用 | ||
*/ | ||
@Override | ||
public void onDetach() { | ||
super.onDetach(); | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
app/src/main/java/com/molihuan/demo01/fragments/EmptyFragment.java
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,42 @@ | ||
package com.molihuan.demo01.fragments; | ||
|
||
import android.view.View; | ||
import android.widget.TextView; | ||
|
||
import com.molihuan.demo01.R; | ||
|
||
public class EmptyFragment extends BaseFragment { | ||
|
||
private TextView tv1; | ||
|
||
public EmptyFragment() { | ||
super(R.layout.fragment_empty); | ||
} | ||
|
||
@Override | ||
public void initData(View view) { | ||
|
||
} | ||
|
||
@Override | ||
public void setListeners(View view) { | ||
tv1.setOnClickListener(this); | ||
} | ||
|
||
@Override | ||
public void getComponents(View view) { | ||
tv1=view.findViewById(R.id.tv1); | ||
} | ||
|
||
@Override | ||
public void onClick(View v) { | ||
switch (v.getId()){ | ||
case R.id.tv1: | ||
tv1.setVisibility(View.INVISIBLE); | ||
|
||
break; | ||
} | ||
} | ||
|
||
|
||
} |
9 changes: 9 additions & 0 deletions
9
app/src/main/java/com/molihuan/demo01/interfaces/IActivityAndFragment.java
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,9 @@ | ||
package com.molihuan.demo01.interfaces; | ||
/** | ||
* author: molihuan | ||
* 2022.6.1 | ||
* Activity与Fragment通信接口 | ||
*/ | ||
public interface IActivityAndFragment { | ||
Object invokeFuncAiF(int functionCode); | ||
} |
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
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,15 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<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" | ||
tools:context=".fragments.BaseFragment"> | ||
|
||
<!-- TODO: Update blank fragment layout --> | ||
<TextView | ||
android:id="@+id/tv1" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:text="@string/hello_blank_fragment" /> | ||
|
||
</FrameLayout> |
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
<resources> | ||
<string name="app_name">demo01</string> | ||
<!-- TODO: Remove or change this placeholder text --> | ||
<string name="hello_blank_fragment">Hello blank fragment</string> | ||
</resources> |
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
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
Binary file not shown.
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
Oops, something went wrong.