Chat primary

ongbodev
ongbo 6 years ago
parent f0c01cb49d
commit 38ffbdec4f

@ -5,7 +5,7 @@ android {
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "com.example.cmknowledgegraph"
minSdkVersion 15
minSdkVersion 16
targetSdkVersion 29
versionCode 1
versionName "1.0"
@ -22,24 +22,32 @@ android {
targetCompatibility JavaVersion.VERSION_1_8
}
}
repositories {
maven { url 'https://jitpack.io' }
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
api 'com.hankcs:hanlp:portable-1.7.2'
implementation 'com.google.android.material:material:1.0.0'
// implementation 'androidx.appcompat:appcompat:1.1.0'
// implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
// testImplementation 'junit:junit:4.12'
// androidTestImplementation 'androidx.test.ext:junit:1.1.0'
// androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
// api 'com.hankcs:hanlp:portable-1.7.2'
// implementation 'com.google.android.material:material:1.0.0'
// androidTestImplementation 'androidx.test.ext:junit:1.1.1'
// androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
// implementation fileTree(dir: 'libs', include: ['*.aar', '*.jar'], exclude: [])
// boombutton
implementation 'com.nightonke:boommenu:2.1.1'
// tab
// implementation 'devlight.io:navigationtabbar:1.2.5'
// implementation 'com.github.hackware1993:MagicIndicator:1.5.0'
implementation 'com.github.florent37:materialviewpager:1.2.3'
//dependencies
implementation 'com.flaviofaria:kenburnsview:1.0.7'
implementation 'com.jpardogo.materialtabstrip:library:1.1.0'
implementation 'com.github.bumptech.glide:glide:4.0.0'
implementation 'com.github.ibrahimsn98:SmoothBottomBar:1.5'
}

@ -0,0 +1,45 @@
package com.example.ChatContentPkg;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.example.cmknowledgegraph.R;
import com.github.florent37.materialviewpager.header.MaterialViewPagerHeaderDecorator;
import java.util.ArrayList;
import java.util.List;
public class RecyclerViewFragment extends Fragment {
public static Fragment newInstance(){return new RecyclerViewFragment();}
final List<Object> items = new ArrayList<>();
static final int ITEMS = 3;
RecyclerView mRecyclerView;
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_recyclerview, container, false);
}
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
mRecyclerView=view.findViewById(R.id.recyclerView);
for (int i=0;i<ITEMS;i++){
items.add(new Object());
}
mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
mRecyclerView.setHasFixedSize(true);
mRecyclerView.addItemDecoration(new MaterialViewPagerHeaderDecorator());
mRecyclerView.setAdapter(new RecyclerViewPagerAdapter(items));
}
}

@ -0,0 +1,36 @@
package com.example.ChatContentPkg;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.recyclerview.widget.RecyclerView;
import com.example.cmknowledgegraph.R;
import java.util.List;
public class RecyclerViewPagerAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
List<Object> contents;
public RecyclerViewPagerAdapter(List<Object> contents) {
this.contents = contents;
}
public int getItemCount() {
return contents.size();
}
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = null;
view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.content_cardview, parent, false);
return new RecyclerView.ViewHolder(view) {
};
}
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
}
}

@ -0,0 +1,138 @@
package com.example.cmknowledgegraph;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentStatePagerAdapter;
import androidx.viewpager.widget.ViewPager;
import com.example.ChatContentPkg.RecyclerViewFragment;
import com.github.florent37.materialviewpager.MaterialViewPager;
import com.github.florent37.materialviewpager.header.HeaderDesign;
public class ChatContent extends Fragment{
AppCompatActivity appCompatActivity;//获取到Activity
public AppCompatActivity getAppCompatActivity() {
return appCompatActivity;
}
public void setAppCompatActivity(AppCompatActivity appCompatActivity) {
this.appCompatActivity = appCompatActivity;
}
@Override
public void onAttach(@NonNull Context context) {
super.onAttach(context);
}
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
//要加载的layout文件
return inflater.inflate(R.layout.activity_chat, container, false);
}
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
//包装处理逻辑
//得到MaterViewPager实例
MaterialViewPager materialViewPager = (MaterialViewPager) getActivity().findViewById(R.id.materialViewPager);
//为MaterialViewPager添加监听
materialViewPager.setMaterialViewPagerListener(new MaterialViewPager.Listener() {
@Override
//设置转换动画和图片,颜色
public HeaderDesign getHeaderDesign(int page) {
switch (page){
case 0:
return HeaderDesign.fromColorResAndDrawable(
R.color.blue,
getResources().getDrawable(R.drawable.draw5)
);
case 1:
return HeaderDesign.fromColorResAndDrawable(
R.color.green,
getResources().getDrawable(R.drawable.draw6)
);
case 2:
return HeaderDesign.fromColorResAndDrawable(
R.color.cyan,
getResources().getDrawable(R.drawable.draw7)
);
}
return null;
}
});
//设置Toolbar
Toolbar toolbar = materialViewPager.getToolbar();
AppCompatActivity ap = getAppCompatActivity();
if(toolbar!=null){
ap.setSupportActionBar(toolbar);
ActionBar actionBar = ap.getSupportActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayShowHomeEnabled(true);
actionBar.setDisplayShowTitleEnabled(true);
actionBar.setDisplayUseLogoEnabled(false);
actionBar.setHomeButtonEnabled(true);
}
//为Viewpager设置适配器
ViewPager viewPager = materialViewPager.getViewPager();
viewPager.setAdapter(new FragmentStatePagerAdapter(getChildFragmentManager()) {
@NonNull
@Override
public Fragment getItem(int position) {
switch (position % 3){
case 0:
return RecyclerViewFragment.newInstance();
default:
return RecyclerViewFragment.newInstance();
}
}
@Override
public int getCount() {
return 3;
}
@Nullable
@Override
public CharSequence getPageTitle(int position) {
switch (position % 3){
case 0:
return "论坛";
case 1:
return "drug";
case 2:
return "药友";
default:
return "TAPN";
}
}
});
materialViewPager.getViewPager().setOffscreenPageLimit(materialViewPager
.getViewPager().getAdapter().getCount());
materialViewPager.getPagerTitleStrip().setViewPager(materialViewPager.getViewPager());
}
@Override
public void onResume() {
super.onResume();
}
}

@ -22,7 +22,10 @@ public class MainActivity extends AppCompatActivity {
private TextView mTextMessage;
private FragmentTransaction transaction;
private FragmentManager fragmentManager;
AppCompatActivity appCompatActivity;
public final AppCompatActivity getAppCompatActivity(){
return this;
}
private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener
= new BottomNavigationView.OnNavigationItemSelectedListener() {
@ -30,22 +33,32 @@ public class MainActivity extends AppCompatActivity {
public boolean onNavigationItemSelected(MenuItem item) {
fragmentManager = getSupportFragmentManager(); //使用fragmentmanager和transaction来实现切换效果
transaction = fragmentManager.beginTransaction();
transaction = fragmentManager.beginTransaction();//开启事务
/*
* replaceview
* commit
* */
switch (item.getItemId()) {
case R.id.home:
transaction.replace(R.id.content,new MainContent()); //对应的java class
transaction.commit(); //一定不要忘记commit否则不会显示
transaction.commit(); //提交事务
return true;
case R.id.search:
transaction.replace(R.id.content,new SearchContent()); //对应的java class
transaction.commit(); //一定不要忘记commit否则不会显示
transaction.commit(); //提交事务
return true;
case R.id.chat:
ChatContent chatContent = new ChatContent();
chatContent.setAppCompatActivity(getAppCompatActivity());
transaction.replace(R.id.content,chatContent);
transaction.commit();//提交事务
return true;
case R.id.person:
transaction.replace(R.id.content,new PersonContent()); //对应的java class
transaction.commit(); //一定不要忘记commit否则不会显示
transaction.commit(); //提交事务
return true;
}
return false;
@ -55,9 +68,9 @@ public class MainActivity extends AppCompatActivity {
// 设置默认进来是tab 显示的页面
private void setDefaultFragment(){
fragmentManager = getSupportFragmentManager();
transaction = fragmentManager.beginTransaction();
transaction = fragmentManager.beginTransaction();//开始事务
transaction.replace(R.id.content,new MainContent());
transaction.commit();
transaction.commit();//提交事务
}
@Override

Binary file not shown.

After

Width:  |  Height:  |  Size: 543 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 687 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1013 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 297 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 279 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 MiB

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context=".MainActivity"
tools:showIn="@layout/activity_main">
<com.github.florent37.materialviewpager.MaterialViewPager
android:id="@+id/materialViewPager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:viewpager_logo="@layout/header_logo"
app:viewpager_logoMarginTop="100dp"
app:viewpager_color="@color/colorPrimary"
app:viewpager_headerHeight="200dp"
app:viewpager_headerAlpha="1.0"
app:viewpager_hideLogoWithFade="false"
app:viewpager_hideToolbarAndTitle="true"
app:viewpager_enableToolbarElevation="true"
app:viewpager_parallaxHeaderFactor="1.5"
app:viewpager_headerAdditionalHeight="20dp"
app:viewpager_displayToolbarWhenSwipe="true"
app:viewpager_transparentToolbar="true"
app:viewpager_animatedHeaderImage="true"
app:viewpager_disableToolbar="false"
/>
</LinearLayout>

@ -14,6 +14,8 @@
android:layout_weight="1"
tools:ignore="MissingConstraints" />
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/nav_view"
android:layout_width="0dp"
@ -26,4 +28,5 @@
app:layout_constraintRight_toRightOf="parent"
app:menu="@menu/bottom_nav_menu" />
</androidx.constraintlayout.widget.ConstraintLayout>

@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/card_view"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_marginBottom="@dimen/cardMarginVertical"
android:layout_marginLeft="@dimen/cardMarginHorizontal"
android:layout_marginRight="@dimen/cardMarginHorizontal"
android:layout_marginTop="@dimen/cardMarginVertical"
app:cardCornerRadius="2dp"
app:cardElevation="2dp"
app:cardPreventCornerOverlap="false"
android:clickable="true"
app:contentPadding="0dp">
android:foreground="?android:attr/selectableItemBackgroundBorderless"
</androidx.cardview.widget.CardView>
</FrameLayout>

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.recyclerview.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/logo_white"
android:layout_width="wrap_content"
android:layout_height="@dimen/materialviewpager_logoHeight"
android:text="Health is Everything"
android:textSize="30sp"
android:textColor="@android:color/white"/>

@ -1,11 +1,43 @@
<resources>
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<style name="AppBaseTheme" parent="@style/Theme.AppCompat.Light">
</style>
<style name="AppTheme" parent="AppBaseTheme">
<!-- Customize your theme here. -->
<!-- <item name="colorPrimary">@color/colorPrimary</item>-->
<!-- <item name="colorPrimaryDark">@color/colorPrimaryDark</item>-->
<!-- <item name="colorAccent">@color/colorAccent</item>-->
<item name="android:textColorPrimary">@android:color/white</item>
<item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
<item name="android:windowTranslucentStatus" tools:targetApi="21">true</item>
<item name="android:windowContentOverlay">@null</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<!-- Toolbar Theme / Apply white arrow -->
<item name="colorControlNormal">@android:color/white</item>
<item name="actionBarTheme">@style/AppTheme.ActionBarTheme</item>
<!-- Material Theme -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="colorAccent">@color/accent_color</item>
<item name="android:navigationBarColor" tools:targetApi="21">@color/navigationBarColor</item>
<item name="android:windowDrawsSystemBarBackgrounds" tools:targetApi="21">true</item>
</style>
<style name="AppTheme.ActionBarTheme" parent="@style/ThemeOverlay.AppCompat.ActionBar">
<!-- White arrow -->
<item name="colorControlNormal">@android:color/white</item>
</style>
<style name="DrawerArrowStyle" parent="Widget.AppCompat.DrawerArrowToggle">
<item name="spinBars">true</item>
<item name="color">@color/drawerArrowColor</item>
</style>
</resources>

Loading…
Cancel
Save