Skip to content

Commit 54e4afa

Browse files
committed
beautified the timeline
1 parent 9efa1e6 commit 54e4afa

4 files changed

Lines changed: 139 additions & 5 deletions

File tree

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package com.cmput301f17t11.cupofjava.Views;
2+
3+
import android.app.Activity;
4+
import android.app.usage.UsageEvents;
5+
import android.content.Context;
6+
import android.view.LayoutInflater;
7+
import android.view.View;
8+
import android.view.ViewGroup;
9+
import android.view.animation.AccelerateInterpolator;
10+
import android.widget.ArrayAdapter;
11+
import android.widget.BaseAdapter;
12+
import android.widget.ImageView;
13+
import android.widget.TextView;
14+
15+
import com.cmput301f17t11.cupofjava.Controllers.EventFilteringHelper;
16+
import com.cmput301f17t11.cupofjava.Models.Habit;
17+
import com.cmput301f17t11.cupofjava.Models.HabitEvent;
18+
import com.cmput301f17t11.cupofjava.R;
19+
20+
import java.util.ArrayList;
21+
22+
/**
23+
* Created by naz_t on 12/4/2017.
24+
*/
25+
26+
public class EventListAdapter extends BaseAdapter {
27+
LayoutInflater inflater = null;
28+
Activity context;
29+
ArrayList<HabitEvent> habitEvents;
30+
31+
public EventListAdapter(Activity context, ArrayList<HabitEvent> events){
32+
this.context = context;
33+
habitEvents = events;
34+
inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
35+
}
36+
37+
@Override
38+
public int getCount(){
39+
return habitEvents.size();
40+
}
41+
42+
@Override
43+
public HabitEvent getItem(int position){
44+
return habitEvents.get(position);
45+
}
46+
47+
@Override
48+
public long getItemId(int position){
49+
return position;
50+
}
51+
52+
@Override
53+
public View getView(int position, View convertView, ViewGroup parent){
54+
View view = convertView;
55+
view = (view == null) ? inflater.inflate(R.layout.fancy_event_list_view, null): view;
56+
57+
TextView textViewHabitWhat = (TextView)view.findViewById(R.id.event_list_which_habit);
58+
TextView textViewHabitWhen = (TextView)view.findViewById(R.id.event_list_date);
59+
TextView textViewHabitComment = (TextView) view.findViewById(R.id.event_list_comment);
60+
ImageView imageView = (ImageView) view.findViewById(R.id.event_list_image_view);
61+
62+
HabitEvent selectedHabit = habitEvents.get(position);
63+
64+
textViewHabitWhat.setText(selectedHabit.getHabitTitle());
65+
textViewHabitWhen.setText(selectedHabit.getDateAsString());
66+
textViewHabitComment.setText(selectedHabit.getComment());
67+
68+
if (selectedHabit.hasImage()){
69+
imageView.setImageBitmap(selectedHabit.getImage());
70+
}
71+
72+
return view;
73+
}
74+
}

app/src/main/java/com/cmput301f17t11/cupofjava/Views/HabitEventTimeLineActivity.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -367,10 +367,11 @@ private void updateTextView(int eventCount){
367367
* @param events Arraylist of type HabitEvent
368368
*/
369369
private void updateListView(ArrayList<HabitEvent> events){
370-
ArrayAdapter<HabitEvent> arrayAdapter = new ArrayAdapter<>(getActivity(),
371-
R.layout.habit_event_list_item, events);
370+
//ArrayAdapter<HabitEvent> arrayAdapter = new ArrayAdapter<>(getActivity(),
371+
// R.layout.habit_event_list_item, events);
372+
EventListAdapter adapter = new EventListAdapter(getActivity(), events);
372373
synchronized (listView){
373-
this.listView.setAdapter(arrayAdapter);
374+
this.listView.setAdapter(adapter);
374375
this.listView.notify();
375376
}
376377
}

app/src/main/res/layout/activity_habit_time_line.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,11 @@
104104
<ListView
105105
android:id="@+id/timeLineListView"
106106
android:layout_width="match_parent"
107-
android:layout_height="400dp"
107+
android:layout_height="366dp"
108108
android:layout_marginLeft="8dp"
109109
android:layout_marginRight="8dp"
110110
android:layout_marginTop="8dp"
111-
android:background="@color/white" />
111+
android:background="@color/white"/>
112112

113113
</LinearLayout>
114114
</RelativeLayout>
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:id="@+id/fancy_event_list_item"
4+
android:layout_height="wrap_content"
5+
android:layout_width="match_parent"
6+
>
7+
8+
<ImageView
9+
android:id="@+id/event_list_image_view"
10+
android:layout_centerVertical="true"
11+
android:layout_alignParentLeft="true"
12+
android:layout_marginLeft="10dp"
13+
android:layout_width="80dp"
14+
android:layout_height="80dp"
15+
android:background="@drawable/ic_launcher"
16+
/>
17+
18+
<TextView
19+
android:id="@+id/event_list_which_habit"
20+
android:layout_width="match_parent"
21+
android:layout_height="wrap_content"
22+
android:fontFamily="sans-serif"
23+
android:paddingTop="20dp"
24+
android:textAlignment="center"
25+
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
26+
android:textColor="@color/black"
27+
android:textSize="16sp"
28+
android:textStyle="bold">
29+
</TextView>
30+
31+
<TextView
32+
android:id="@+id/event_list_date"
33+
android:layout_width="match_parent"
34+
android:layout_height="wrap_content"
35+
android:layout_below="@id/event_list_which_habit"
36+
android:fontFamily="sans-serif"
37+
android:paddingBottom="20dp"
38+
android:textAlignment="textEnd"
39+
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
40+
android:textColor="@color/black"
41+
android:textSize="16sp"
42+
>
43+
</TextView>
44+
45+
<TextView
46+
android:id="@+id/event_list_comment"
47+
android:layout_width="match_parent"
48+
android:layout_height="wrap_content"
49+
android:layout_alignParentStart="true"
50+
android:layout_below="@+id/event_list_date"
51+
android:fontFamily="sans-serif"
52+
android:paddingBottom="20dp"
53+
android:textAlignment="center"
54+
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
55+
android:textColor="@color/black"
56+
android:textSize="16sp">
57+
</TextView>
58+
59+
</RelativeLayout>

0 commit comments

Comments
 (0)