forked from PhilJay/MPAndroidChart
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainActivity.java
More file actions
209 lines (172 loc) · 7.36 KB
/
MainActivity.java
File metadata and controls
209 lines (172 loc) · 7.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
package com.xxmassdeveloper.mpchartexample.notimportant;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import com.xxmassdeveloper.mpchartexample.BarChartActivity;
import com.xxmassdeveloper.mpchartexample.BarChartActivityMultiDataset;
import com.xxmassdeveloper.mpchartexample.DrawChartActivity;
import com.xxmassdeveloper.mpchartexample.LineChartActivity;
import com.xxmassdeveloper.mpchartexample.ListViewBarChartActivity;
import com.xxmassdeveloper.mpchartexample.ListViewMultiChartActivity;
import com.xxmassdeveloper.mpchartexample.MultiLineChartActivity;
import com.xxmassdeveloper.mpchartexample.PieChartActivity;
import com.xxmassdeveloper.mpchartexample.R;
import com.xxmassdeveloper.mpchartexample.ScatterChartActivity;
import com.xxmassdeveloper.mpchartexample.fragments.SimpleChartDemo;
import java.util.ArrayList;
import java.util.List;
public class MainActivity extends Activity implements OnItemClickListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_main);
ArrayList<ContentItem> objects = new ArrayList<ContentItem>();
objects.add(new ContentItem("Line Chart", "A simple demonstration of the linechart."));
objects.add(new ContentItem("Bar Chart", "A simple demonstration of the bar chart."));
objects.add(new ContentItem("Pie Chart", "A simple demonstration of the pie chart."));
objects.add(new ContentItem("Scatter Chart", "A simple demonstration of the scatter chart."));
objects.add(new ContentItem("Multiple Lines Chart",
"A line chart with multiple DataSet objects. One color per DataSet."));
objects.add(new ContentItem("Multiple Bars Chart",
"A bar chart with multiple DataSet objects. One multiple colors per DataSet."));
objects.add(new ContentItem("Draw Chart",
"Demonstration of drawing values into the chart per touch-gesture. With callbacks."));
objects.add(new ContentItem(
"Charts in Fragments, awesome design.",
"Demonstration of charts inside Fragments. In this example the focus was on the design and look and feel of the chart."));
objects.add(new ContentItem(
"BarChart inside ListView",
"Demonstrates the usage of a BarChart inside a ListView item."));
objects.add(new ContentItem(
"Multiple charts inside ListView",
"Demonstrates the usage of different chart types inside a ListView."));
MyAdapter adapter = new MyAdapter(this, objects);
ListView lv = (ListView) findViewById(R.id.listView1);
lv.setAdapter(adapter);
lv.setOnItemClickListener(this);
}
@Override
public void onItemClick(AdapterView<?> av, View v, int pos, long arg3) {
Intent i;
switch (pos) {
case 0:
i = new Intent(this, LineChartActivity.class);
startActivity(i);
break;
case 1:
i = new Intent(this, BarChartActivity.class);
startActivity(i);
break;
case 2:
i = new Intent(this, PieChartActivity.class);
startActivity(i);
break;
case 3:
i = new Intent(this, ScatterChartActivity.class);
startActivity(i);
break;
case 4:
i = new Intent(this, MultiLineChartActivity.class);
startActivity(i);
break;
case 5:
i = new Intent(this, BarChartActivityMultiDataset.class);
startActivity(i);
break;
case 6:
i = new Intent(this, DrawChartActivity.class);
startActivity(i);
break;
case 7:
i = new Intent(this, SimpleChartDemo.class);
startActivity(i);
break;
case 8:
i = new Intent(this, ListViewBarChartActivity.class);
startActivity(i);
break;
case 9:
i = new Intent(this, ListViewMultiChartActivity.class);
startActivity(i);
break;
}
overridePendingTransition(R.anim.move_right_in_activity, R.anim.move_left_out_activity);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
Intent i = null;
switch (item.getItemId()) {
case R.id.viewGithub:
i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart"));
startActivity(i);
break;
case R.id.report:
i = new Intent(Intent.ACTION_SENDTO, Uri.fromParts(
"mailto", "philjay.librarysup@gmail.com", null));
i.putExtra(Intent.EXTRA_SUBJECT, "MPAndroidChart Issue");
i.putExtra(Intent.EXTRA_TEXT, "Your error report here...");
startActivity(Intent.createChooser(i, "Report Problem"));
break;
case R.id.website:
i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse("http://www.xxmassdeveloper.com"));
startActivity(i);
break;
}
return true;
}
private class ContentItem {
String name;
String desc;
public ContentItem(String n, String d) {
name = n;
desc = d;
}
}
private class MyAdapter extends ArrayAdapter<ContentItem> {
public MyAdapter(Context context, List<ContentItem> objects) {
super(context, 0, objects);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ContentItem c = getItem(position);
ViewHolder holder = null;
if (convertView == null) {
holder = new ViewHolder();
convertView = LayoutInflater.from(getContext()).inflate(R.layout.list_item, null);
holder.tvName = (TextView) convertView.findViewById(R.id.tvName);
holder.tvDesc = (TextView) convertView.findViewById(R.id.tvDesc);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.tvName.setText(c.name);
holder.tvDesc.setText(c.desc);
return convertView;
}
private class ViewHolder {
TextView tvName, tvDesc;
}
}
}