This repository was archived by the owner on Jun 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathStatsActivity.java
More file actions
134 lines (111 loc) · 5.69 KB
/
Copy pathStatsActivity.java
File metadata and controls
134 lines (111 loc) · 5.69 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
package me.angrybyte.contactsgenerator;
import android.content.ComponentName;
import android.content.Intent;
import android.content.ServiceConnection;
import android.graphics.Color;
import android.os.Bundle;
import android.os.IBinder;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.TextView;
import me.angrybyte.contactsgenerator.api.GeneratorStats;
import me.angrybyte.contactsgenerator.service.GeneratorService;
import me.angrybyte.contactsgenerator.service.GeneratorServiceBinder;
import me.angrybyte.contactsgenerator.service.ServiceApi;
public class StatsActivity extends AppCompatActivity implements ServiceConnection {
private static final String TAG = StatsActivity.class.getSimpleName();
private TextView mCheckDeviceView;
private TextView mRequestedCountView;
private TextView mGeneratedCountView;
private TextView mGeneratedMalesView;
private TextView mGeneratedFemalesView;
private TextView mAverageTimeView;
private TextView mTotalTimeView;
private TextView mShortestContactViewLabel;
private TextView mShortestContactViewValue;
private TextView mLongestContactViewLabel;
private TextView mLongestContactViewValue;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_stats);
mCheckDeviceView = (TextView) findViewById(R.id.stats_check_device);
mRequestedCountView = (TextView) findViewById(R.id.stats_requested_count);
mGeneratedCountView = (TextView) findViewById(R.id.stats_generated_count);
mGeneratedMalesView = (TextView) findViewById(R.id.stats_generated_males);
mGeneratedFemalesView = (TextView) findViewById(R.id.stats_generated_females);
mAverageTimeView = (TextView) findViewById(R.id.stats_generated_average_time_value);
mTotalTimeView = (TextView) findViewById(R.id.stats_generated_total_time_value);
mShortestContactViewLabel = (TextView) findViewById(R.id.stats_shortest_generated_contact_label);
mShortestContactViewValue = (TextView) findViewById(R.id.stats_shortest_generated_contact_value);
mLongestContactViewLabel = (TextView) findViewById(R.id.stats_longest_generated_contact_label);
mLongestContactViewValue = (TextView) findViewById(R.id.stats_longest_generated_contact_value);
// prepare the toolbar with title coloring
Toolbar toolbar = (Toolbar) findViewById(R.id.stats_toolbar);
// noinspection ConstantConditions
toolbar.setTitleTextColor(Color.WHITE);
}
@Override
protected void onStart() {
super.onStart();
Intent binderIntent = new Intent(this, GeneratorService.class);
bindService(binderIntent, this, 0);
}
@Override
protected void onStop() {
super.onStop();
unbindService(this);
}
@Override
public void onBackPressed() {
Intent serviceStopper = new Intent(this, GeneratorService.class);
stopService(serviceStopper);
Intent backToMain = new Intent(this, MainActivity.class);
startActivity(backToMain);
finish();
}
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
Log.d(TAG, "Service connected to " + TAG);
ServiceApi serviceApi = ((GeneratorServiceBinder) service).getService();
GeneratorStats stats = serviceApi.getStats();
if (stats != null) {
if (!serviceApi.isForceStopped() && (stats.requested == 0 || stats.generated < stats.requested)) {
mCheckDeviceView.setVisibility(View.VISIBLE);
} else {
mCheckDeviceView.setVisibility(View.GONE);
}
String requested = String.valueOf(stats.requested);
String generatedTotal = String.valueOf(stats.generated);
String malesGenerated = String.valueOf(stats.males);
String femalesGenerated = String.valueOf(stats.females);
String averageTimePerContact = stats.averageTimePerContact / 1000 + "s";
String totalTimeUsed = stats.totalTime / 1000 + "s";
String shortestTimeForContact = TextUtils.isEmpty(stats.shortestContact) ? "" : stats.shortestContact + " ("
+ stats.shortestContactTime / 1000 + "s)";
String longestTimeForContact = TextUtils.isEmpty(stats.longestContact) ? "" : stats.longestContact + " ("
+ stats.longestContactTime / 1000 + "s)";
mRequestedCountView.setText(requested);
mGeneratedCountView.setText(generatedTotal);
mGeneratedMalesView.setText(malesGenerated);
mGeneratedFemalesView.setText(femalesGenerated);
mAverageTimeView.setText(averageTimePerContact);
mTotalTimeView.setText(totalTimeUsed);
mShortestContactViewValue.setText(shortestTimeForContact);
mLongestContactViewValue.setText(longestTimeForContact);
int shortestFieldsVisibility = shortestTimeForContact.isEmpty() ? View.GONE : View.VISIBLE;
mShortestContactViewLabel.setVisibility(shortestFieldsVisibility);
mShortestContactViewValue.setVisibility(shortestFieldsVisibility);
int longestFieldsVisibility = longestTimeForContact.isEmpty() ? View.GONE : View.VISIBLE;
mLongestContactViewLabel.setVisibility(longestFieldsVisibility);
mLongestContactViewValue.setVisibility(longestFieldsVisibility);
}
}
@Override
public void onServiceDisconnected(ComponentName name) {
Log.d(TAG, "Service disconnected from " + TAG);
}
}