This repository has been archived by the owner on Oct 5, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 371
/
SettingsFragment.java
193 lines (163 loc) · 8.4 KB
/
SettingsFragment.java
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
/*
* Copyright (C) 2015 Willi Ye
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.grarak.kerneladiutor.fragments.other;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import com.grarak.kerneladiutor.MainActivity;
import com.grarak.kerneladiutor.R;
import com.grarak.kerneladiutor.elements.CardViewItem;
import com.grarak.kerneladiutor.elements.DividerCardView;
import com.grarak.kerneladiutor.elements.PopupCardItem;
import com.grarak.kerneladiutor.elements.SwitchCompatCardItem;
import com.grarak.kerneladiutor.fragments.RecyclerViewFragment;
import com.grarak.kerneladiutor.utils.Constants;
import com.grarak.kerneladiutor.utils.Utils;
import com.grarak.kerneladiutor.utils.root.RootUtils;
import java.util.ArrayList;
import java.util.List;
/**
* Created by willi on 09.03.15.
*/
public class SettingsFragment extends RecyclerViewFragment {
@Override
public boolean showApplyOnBoot() {
return false;
}
@Override
public void init(Bundle savedInstanceState) {
super.init(savedInstanceState);
darkthemeInit();
if (!Resources.getSystem().getConfiguration().locale.getLanguage().equals("en"))
forceenglishlanguageInit();
betainfoInit();
applyonbootInit();
debuggingInit();
}
private void darkthemeInit() {
SwitchCompatCardItem.DSwitchCompatCard mDarkthemeCard = new SwitchCompatCardItem.DSwitchCompatCard();
mDarkthemeCard.setDescription(getString(R.string.dark_theme));
mDarkthemeCard.setChecked(Utils.DARKTHEME);
mDarkthemeCard.setOnDSwitchCompatCardListener(new SwitchCompatCardItem.DSwitchCompatCard.OnDSwitchCompatCardListener() {
@Override
public void onChecked(SwitchCompatCardItem.DSwitchCompatCard dSwitchCompatCard, boolean checked) {
Utils.saveBoolean("darktheme", checked, getActivity());
startActivity(new Intent(getActivity(), MainActivity.class));
}
});
addView(mDarkthemeCard);
}
private void forceenglishlanguageInit() {
SwitchCompatCardItem.DSwitchCompatCard mForceEnglishLanguageCard = new SwitchCompatCardItem.DSwitchCompatCard();
mForceEnglishLanguageCard.setDescription(getString(R.string.force_english_language));
mForceEnglishLanguageCard.setChecked(Utils.getBoolean("forceenglish", false, getActivity()));
mForceEnglishLanguageCard.setOnDSwitchCompatCardListener(
new SwitchCompatCardItem.DSwitchCompatCard.OnDSwitchCompatCardListener() {
@Override
public void onChecked(SwitchCompatCardItem.DSwitchCompatCard dSwitchCompatCard, boolean checked) {
Utils.saveBoolean("forceenglish", checked, getActivity());
if (!checked)
Utils.setLocale(Resources.getSystem().getConfiguration().locale.getLanguage(), getActivity());
startActivity(new Intent(getActivity(), MainActivity.class));
}
});
addView(mForceEnglishLanguageCard);
}
private void betainfoInit() {
if (Constants.VERSION_NAME.contains("beta")) {
SwitchCompatCardItem.DSwitchCompatCard mBetaInfoCard = new SwitchCompatCardItem.DSwitchCompatCard();
mBetaInfoCard.setTitle(getString(R.string.beta_info));
mBetaInfoCard.setDescription(getString(R.string.beta_info_summary));
mBetaInfoCard.setChecked(Utils.getBoolean("betainfo", true, getActivity()));
mBetaInfoCard.setOnDSwitchCompatCardListener(
new SwitchCompatCardItem.DSwitchCompatCard.OnDSwitchCompatCardListener() {
@Override
public void onChecked(SwitchCompatCardItem.DSwitchCompatCard dSwitchCompatCard, boolean checked) {
Utils.saveBoolean("betainfo", checked, getActivity());
}
});
addView(mBetaInfoCard);
}
}
private void applyonbootInit() {
DividerCardView.DDividerCard mApplyonBootDividerCard = new DividerCardView.DDividerCard();
mApplyonBootDividerCard.setText(getString(R.string.apply_on_boot));
addView(mApplyonBootDividerCard);
final List<String> list = new ArrayList<>();
for (int i = 15; i < 481; i *= 2)
list.add(i + getString(R.string.sec));
PopupCardItem.DPopupCard mApplyonbootDelayCard = new PopupCardItem.DPopupCard(list);
mApplyonbootDelayCard.setDescription(getString(R.string.delay));
mApplyonbootDelayCard.setItem(Utils.getInt("applyonbootdelay", 15, getActivity()) + getString(R.string.sec));
mApplyonbootDelayCard.setOnDPopupCardListener(new PopupCardItem.DPopupCard.OnDPopupCardListener() {
@Override
public void onItemSelected(PopupCardItem.DPopupCard dPopupCard, int position) {
Utils.saveInt("applyonbootdelay", Utils.stringToInt(list.get(position)
.replace(getString(R.string.sec), "")), getActivity());
}
});
addView(mApplyonbootDelayCard);
SwitchCompatCardItem.DSwitchCompatCard mApplyonbootNotificationCard = new SwitchCompatCardItem.DSwitchCompatCard();
mApplyonbootNotificationCard.setTitle(getString(R.string.notification));
mApplyonbootNotificationCard.setDescription(getString(R.string.notification_summary));
mApplyonbootNotificationCard.setChecked(Utils.getBoolean("applyonbootnotification", true, getActivity()));
mApplyonbootNotificationCard.setOnDSwitchCompatCardListener(
new SwitchCompatCardItem.DSwitchCompatCard.OnDSwitchCompatCardListener() {
@Override
public void onChecked(SwitchCompatCardItem.DSwitchCompatCard dSwitchCompatCard, boolean checked) {
Utils.saveBoolean("applyonbootnotification", checked, getActivity());
}
});
addView(mApplyonbootNotificationCard);
}
private void debuggingInit() {
DividerCardView.DDividerCard mDebuggingDividerCard = new DividerCardView.DDividerCard();
mDebuggingDividerCard.setText(getString(R.string.debugging));
addView(mDebuggingDividerCard);
CardViewItem.DCardView mLogcatCard = new CardViewItem.DCardView();
mLogcatCard.setTitle(getString(R.string.logcat));
mLogcatCard.setDescription(getString(R.string.logcat_summary));
mLogcatCard.setOnDCardListener(new CardViewItem.DCardView.OnDCardListener() {
@Override
public void onClick(CardViewItem.DCardView dCardView) {
RootUtils.runCommand("logcat -d > /sdcard/logcat.txt");
}
});
addView(mLogcatCard);
if (Utils.existFile("/proc/last_kmsg")) {
CardViewItem.DCardView mLastKmsgCard = new CardViewItem.DCardView();
mLastKmsgCard.setTitle(getString(R.string.last_kmsg));
mLastKmsgCard.setDescription(getString(R.string.last_kmsg_summary));
mLastKmsgCard.setOnDCardListener(new CardViewItem.DCardView.OnDCardListener() {
@Override
public void onClick(CardViewItem.DCardView dCardView) {
RootUtils.runCommand("cat /proc/last_kmsg > /sdcard/last_kmsg.txt");
}
});
addView(mLastKmsgCard);
}
CardViewItem.DCardView mDmesgCard = new CardViewItem.DCardView();
mDmesgCard.setTitle(getString(R.string.driver_message));
mDmesgCard.setDescription(getString(R.string.driver_message_summary));
mDmesgCard.setOnDCardListener(new CardViewItem.DCardView.OnDCardListener() {
@Override
public void onClick(CardViewItem.DCardView dCardView) {
RootUtils.runCommand("dmesg > /sdcard/dmesg.txt");
}
});
addView(mDmesgCard);
}
}