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 9e56888 commit 4671b2e
Show file tree
Hide file tree
Showing 3 changed files with 245 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ public class TestFragmentActivity extends AppCompatActivity {
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test_fragment);
getSupportActionBar().hide();


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


}
Expand Down
123 changes: 120 additions & 3 deletions app/src/main/java/necer/ncalendardemo/fragment/TestFragment.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package necer.ncalendardemo.fragment;

import android.content.Context;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
Expand All @@ -8,10 +10,12 @@
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.TextView;

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

import org.joda.time.DateTime;

Expand All @@ -34,12 +38,125 @@ public class TestFragment extends Fragment implements OnCalendarChangedListener
private TextView tv_month;
private TextView tv_date;

@Nullable

public static TestFragment newInstance(String param1, String param2) {
TestFragment fragment = new TestFragment();
Bundle args = new Bundle();

fragment.setArguments(args);
return fragment;
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View rootView = inflater.inflate(R.layout.fragment_leave_shift, container, false);

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
WindowManager.LayoutParams localLayoutParams = getActivity().getWindow().getAttributes();
localLayoutParams.flags = (WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS | localLayoutParams.flags);
}

ncalendar = (NCalendar) rootView.findViewById(R.id.ncalendarrrr);
recyclerView = (RecyclerView) rootView.findViewById(R.id.recyclerView);
tv_month = (TextView) rootView.findViewById(R.id.tv_month);
tv_date = (TextView) rootView.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 rootView;
}

@Override
public void onCalendarChanged(DateTime dateTime) {
tv_month.setText(dateTime.getMonthOfYear() + "月");
tv_date.setText(dateTime.getYear() + "年" + dateTime.getMonthOfYear() + "月" + dateTime.getDayOfMonth() + "日");
MyLog.d("dateTime::" + dateTime);
}


class AAAdapter extends RecyclerView.Adapter<TestFragment.AAAdapter.MyViewHolder> {

private Context context;

public AAAdapter(Context context) {
this.context = context;
}

@Override
public TestFragment.AAAdapter.MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
return new TestFragment.AAAdapter.MyViewHolder(LayoutInflater.from(context).inflate(R.layout.item_, parent,false));
}

@Override
public void onBindViewHolder(TestFragment.AAAdapter.MyViewHolder holder, final int position) {
TextView textView = holder.textView;
textView.setText("-----"+position);

holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
MyLog.d("position:::::" + position);
}
});

}

@Override
public int getItemCount() {
return 50;
}

class MyViewHolder extends RecyclerView.ViewHolder {
TextView textView;
public MyViewHolder(View itemView) {
super(itemView);
textView = (TextView) itemView.findViewById(R.id.tv_);
}
}

}


/*
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);
View view = LayoutInflater.from(getContext()).inflate(R.layout.activity_ncalendar,container, false);
ncalendar = (NCalendar) view.findViewById(R.id.ncalendarrrr);
recyclerView = (RecyclerView) view.findViewById(R.id.recyclerView);
Expand Down Expand Up @@ -74,5 +191,5 @@ public void run() {
public void onCalendarChanged(DateTime dateTime) {
tv_month.setText(dateTime.getMonthOfYear() + "月");
tv_date.setText(dateTime.getYear() + "年" + dateTime.getMonthOfYear() + "月" + dateTime.getDayOfMonth() + "日");
}
}*/
}
123 changes: 123 additions & 0 deletions app/src/main/res/layout/fragment_leave_shift.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">


<RelativeLayout
android:layout_width="match_parent"
android:layout_height="120dp"
android:background="#38AE80">


<TextView
android:id="@+id/tv_month"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="40dp"
android:text=""
android:textColor="#ffffff"
android:textSize="30sp" />

<TextView
android:id="@+id/tv_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="50dp"
android:layout_toRightOf="@id/tv_month"
android:text="2017nian"
android:textColor="#ffffff" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="25dp"
android:layout_alignParentBottom="true"
android:orientation="horizontal">

<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="&#26085;"
android:textColor="#ffffff"
android:textSize="13sp" />

<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="&#19968;"
android:textColor="#ffffff"
android:textSize="13sp" />

<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="&#20108;"
android:textColor="#ffffff"
android:textSize="13sp" />

<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="&#19977;"
android:textColor="#ffffff"
android:textSize="13sp" />

<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="&#22235;"
android:textColor="#ffffff"
android:textSize="13sp" />

<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="&#20116;"
android:textColor="#ffffff"
android:textSize="13sp" />

<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="&#20845;"
android:textColor="#ffffff"
android:textSize="13sp" />
</LinearLayout>

</RelativeLayout>

<com.necer.ncalendar.calendar.NCalendar
android:id="@+id/ncalendarrrr"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:firstDayOfWeek="Sunday"
>

<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white"/>

</com.necer.ncalendar.calendar.NCalendar>


</LinearLayout>

0 comments on commit 4671b2e

Please sign in to comment.