Skip to content

Commit

Permalink
添加fragment
Browse files Browse the repository at this point in the history
  • Loading branch information
yannecer committed Dec 22, 2017
1 parent 6e13c68 commit a2dbbab
Show file tree
Hide file tree
Showing 7 changed files with 155 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
<activity
android:name=".activity.WeekActivity"
android:configChanges="orientation|screenSize|keyboardHidden" />
<activity
android:name=".activity.TestFragmentActivity"
android:configChanges="orientation|screenSize|keyboardHidden" />


</application>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package necer.ncalendardemo.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.TextView;

import necer.ncalendardemo.R;

public class MainActivity extends AppCompatActivity {
Expand All @@ -29,10 +31,14 @@ public void defaultSelect(View v) {
public void notDefaultSelect(View v) {
startActivity(new Intent(this, MonthNotSelectActivity.class));
}

public void week(View v) {
startActivity(new Intent(this, WeekActivity.class));
}

public void fragment(View v) {
startActivity(new Intent(this, TestFragmentActivity.class));
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package necer.ncalendardemo.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;

import necer.ncalendardemo.R;
import necer.ncalendardemo.fragment.TestFragment;

/**
* Created by necer on 2017/12/22.
*/

public class TestFragmentActivity extends AppCompatActivity {


@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test_fragment);


getSupportFragmentManager().beginTransaction().replace(R.id.fl_, new TestFragment()).commit();


}
}
79 changes: 79 additions & 0 deletions app/src/main/java/necer/ncalendardemo/fragment/TestFragment.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package necer.ncalendardemo.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.necer.ncalendar.calendar.NCalendar;
import com.necer.ncalendar.listener.OnCalendarChangedListener;

import org.joda.time.DateTime;

import java.util.ArrayList;
import java.util.List;

import necer.ncalendardemo.R;
import necer.ncalendardemo.adapter.AAAdapter;

/**
* Created by necer on 2017/12/22.
*/

public class TestFragment extends Fragment implements OnCalendarChangedListener {


private NCalendar ncalendar;
private RecyclerView recyclerView;
private TextView tv_month;
private TextView tv_date;

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {


View view = LayoutInflater.from(getContext()).inflate(R.layout.activity_ncalendar, null);



ncalendar = (NCalendar) view.findViewById(R.id.ncalendarrrr);
recyclerView = (RecyclerView) view.findViewById(R.id.recyclerView);
tv_month = (TextView) view.findViewById(R.id.tv_month);
tv_date = (TextView) view.findViewById(R.id.tv_date);
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
AAAdapter aaAdapter = new AAAdapter(getContext());
recyclerView.setAdapter(aaAdapter);
ncalendar.setOnCalendarChangedListener(this);

ncalendar.post(new Runnable() {
@Override
public void run() {

List<String> list = new ArrayList<>();
list.add("2017-09-21");
list.add("2017-10-21");
list.add("2017-10-1");
list.add("2017-10-15");
list.add("2017-10-18");
list.add("2017-10-26");
list.add("2017-11-21");

ncalendar.setPoint(list);
}
});

return view;
}

@Override
public void onCalendarChanged(DateTime dateTime) {
tv_month.setText(dateTime.getMonthOfYear() + "月");
tv_date.setText(dateTime.getYear() + "年" + dateTime.getMonthOfYear() + "月" + dateTime.getDayOfMonth() + "日");
}
}
40 changes: 23 additions & 17 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -1,54 +1,60 @@
<?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">


android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">


<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="仿miui日历"
android:layout_marginTop="20dp"
android:onClick="toMiui"/>
android:onClick="toMiui"
android:text="仿miui日历" />

<Button
android:id="@+id/bt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="默认不选中的月日历"
android:layout_marginTop="20dp"
android:onClick="notDefaultSelect"/>
android:onClick="notDefaultSelect"
android:text="默认不选中的月日历" />


<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="默认选中的月日历"
android:onClick="defaultSelect"/>
android:onClick="defaultSelect"
android:text="默认选中的月日历" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="周日历"
android:onClick="week"/>
android:onClick="week"
android:text="周日历" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="fragment"
android:text="Fragment" />


<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="12sp"
android:layout_margin="15dp"
android:text="注意:1单纯的周日历和月日历使用方法完全相同
2:单个的周日历和月日历可以设置默认不选中(即是点击才选中,不点击不选中),但是月周切换必须每页都有选中日期,这样才能体现出月周切换日期无缝切换的特点, 该日历不支持月周切换的不选中设置"/>
2:单个的周日历和月日历可以设置默认不选中(即是点击才选中,不点击不选中),但是月周切换必须每页都有选中日期,这样才能体现出月周切换日期无缝切换的特点, 该日历不支持月周切换的不选中设置"
android:textSize="12sp" />

<TextView
android:id="@+id/tv_version"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="12sp"
android:layout_margin="15dp"
android:text="版本"/>

android:text="版本"
android:textSize="12sp" />


</LinearLayout>
16 changes: 16 additions & 0 deletions app/src/main/res/layout/activity_test_fragment.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?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">


<FrameLayout
android:id="@+id/fl_"
android:layout_width="match_parent"
android:layout_height="match_parent"></FrameLayout>




</LinearLayout>

0 comments on commit a2dbbab

Please sign in to comment.