-
Notifications
You must be signed in to change notification settings - Fork 23
/
ProfileFragment.java
842 lines (660 loc) · 33 KB
/
ProfileFragment.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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
package com.aero.control.fragments;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.content.pm.ApplicationInfo;
import android.graphics.Color;
import android.graphics.drawable.AnimationDrawable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Parcelable;
import android.preference.PreferenceFragment;
import android.preference.PreferenceManager;
import android.text.method.ScrollingMovementMethod;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.AnimationUtils;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import com.aero.control.AeroActivity;
import com.aero.control.R;
import com.aero.control.helpers.perAppHelper;
import com.aero.control.helpers.settingsHelper;
import com.cocosw.undobar.UndoBarController;
import com.cocosw.undobar.UndoBarStyle;
import com.espian.showcaseview.ShowcaseView;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import fr.nicolaspomepuy.discreetapprate.AppRate;
/**
* Created by Alexander Christ on 09.12.13.
*/
public class ProfileFragment extends PreferenceFragment implements UndoBarController.AdvancedUndoListener {
private static final String LOG_TAG = PreferenceFragment.class.getName();
private ViewGroup mContainerView;
public ShowcaseView mShowCase;
private SharedPreferences mPrefs;
public ShowcaseView.ConfigOptions mConfigOptions;
private static final String perAppProfileHandler = "perAppProfileHandler";
private String[] mCompleteProfiles;
public static final String FILENAME_PROFILES = "firstrun_profiles";
public static final String FILENAME_PERAPP = "firstrun_perapp";
public static final settingsHelper settings = new settingsHelper();
private ViewGroup mDeletedChild;
private String mDeletedProfile;
private SharedPreferences mPerAppPrefs;
private Context mContext;
private List<ApplicationInfo> mPackages;
private ProgressDialog mProgressDialog;
private boolean mWarning;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setHasOptionsMenu(true);
mContext = getActivity();
mWarning = false;
mPerAppPrefs = mContext.getSharedPreferences(perAppProfileHandler, Context.MODE_PRIVATE);
final View v = inflater.inflate(R.layout.profile_fragment, null);
final TextView empty = (TextView)v.findViewById(android.R.id.empty);
empty.setTypeface(AeroActivity.files.kitkatFont);
mContainerView = (ViewGroup)v.findViewById(R.id.container);
// Load all available profiles;
loadProfiles();
return mContainerView;
}
private final void loadProfiles() {
mCompleteProfiles = AeroActivity.shell.getDirInfo(AeroActivity.files.sharedPrefsPath, true);
for (String s : mCompleteProfiles) {
// Don't take default xml;
if (!(s.equals("com.aero.control_preferences.xml") || s.equals("showcase_internal.xml")
|| s.equals("app_rate_prefs.xml") || s.equals(perAppProfileHandler + ".xml"))) {
// Just for the looks;
s = s.replace(".xml", "");
addProfile(s, false);
mContainerView.findViewById(android.R.id.empty).setVisibility(View.GONE);
mContainerView.findViewById(R.id.empty_image).setVisibility(View.GONE);
}
}
// User has assigned apps, but no service is running;
if (AeroActivity.perAppService == null || !(AeroActivity.perAppService.getState())) {
if (checkAllStates() && !mWarning) {
AppRate.with(getActivity())
.text(R.string.pref_profile_service_not_running)
.fromTop(false)
.delay(1000)
.autoHide(15000)
.allowPlayLink(false)
.forceShow();
mWarning = true;
}
}
}
// Create our options menu;
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
mPrefs = PreferenceManager.getDefaultSharedPreferences(getActivity().getApplicationContext());
String a = mPrefs.getString("app_theme", null);
if (a == null)
a = "";
if (a.equals("red"))
inflater.inflate(R.menu.profiles_menu, menu);
else if (a.equals("light"))
inflater.inflate(R.menu.profiles_menu, menu);
else if (a.equals("dark"))
inflater.inflate(R.menu.profiles_menu_light, menu);
else
inflater.inflate(R.menu.profiles_menu, menu);
super.onCreateOptionsMenu(menu, inflater);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_add_item:
// Check if there are actual changes;
final File defaultFile = new File(AeroActivity.files.sharedPrefsPath + "com.aero.control_preferences.xml");
if (!(defaultFile.exists())) {
Toast.makeText(mContext, R.string.pref_profile_no_changes , Toast.LENGTH_LONG).show();
break;
}
showDialog(new EditText(mContext));
break;
case R.id.action_reload:
showResetDialog();
break;
}
return super.onOptionsItemSelected(item);
}
private void showResetDialog() {
AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
LayoutInflater inflater = getActivity().getLayoutInflater();
View layout = inflater.inflate(R.layout.about_screen, null);
TextView aboutText = (TextView) layout.findViewById(R.id.aboutScreen);
builder.setTitle(R.string.pref_profile_reset);
aboutText.setText(R.string.pref_profile_reset_sum);
builder.setView(layout)
.setPositiveButton(R.string.got_it, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
// Continue with resetting
mPrefs = PreferenceManager.getDefaultSharedPreferences(mContext);
SharedPreferences.Editor editor = mPrefs.edit();
editor.clear();
editor.commit();
Toast.makeText(mContext, R.string.successful , Toast.LENGTH_LONG).show();
}
})
.setNegativeButton(R.string.maybe_later, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
}
});
builder.show();
}
private final void showDialog(final EditText editText) {
mCompleteProfiles = AeroActivity.shell.getDirInfo(AeroActivity.files.sharedPrefsPath, true);
AlertDialog dialog = new AlertDialog.Builder(mContext)
.setTitle(R.string.add_a_name)
.setMessage(R.string.define_a_name)
.setView(editText)
.setPositiveButton(R.string.save, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
String allProfiles = Arrays.asList(mCompleteProfiles).toString();
String profileTitle = editText.getText().toString();
// Add content;
if (profileTitle.equals(""))
Toast.makeText(mContext, R.string.pref_profile_enter_name, Toast.LENGTH_LONG).show();
else if (allProfiles.contains(profileTitle + ".xml"))
Toast.makeText(mContext, R.string.pref_profile_name_exists, Toast.LENGTH_LONG).show();
else {
/* Check here if there are path seperators, but don't interrupt the process */
if (profileTitle.contains("/"))
profileTitle = profileTitle.replace("/", "-");
addProfile(profileTitle, true);
// Set up our file;
int output = 0;
final byte[] buffer = new byte[1024];
try {
FileInputStream fis = mContext.openFileInput(FILENAME_PERAPP);
output = fis.read(buffer);
fis.close();
} catch (IOException e) {
Log.e(LOG_TAG, "Couldn't open File... " + output);
}
// Only show showcase once;
if (output == 0)
DrawFirstStart(R.string.showcase_perapp_profiles, R.string.showcase_perapp_profiles_sum, FILENAME_PERAPP, null);
// Hide the "empty" view since there is now at least one item in the list.
mContainerView.findViewById(android.R.id.empty).setVisibility(View.GONE);
mContainerView.findViewById(R.id.empty_image).setVisibility(View.GONE);
}
}
})
.setNegativeButton(R.string.cancel, null)
.create();
dialog.show();
}
// Adds the object to our "list", s = Name
private void addProfile(final String s, boolean flag) {
mPrefs = PreferenceManager.getDefaultSharedPreferences(mContext);
final SharedPreferences AeroProfile = mContext.getSharedPreferences(s, Context.MODE_PRIVATE);
final File defaultFile = new File(AeroActivity.files.sharedPrefsPath + "com.aero.control_preferences.xml");
// Init the perApp data here, so we can re-use it for each profile
final perAppHelper perApp = new perAppHelper(mContext);
if(!(defaultFile.exists()))
return;
// Flag if we add a profile to the list which already exists as a file;
if (flag) {
// This will save the current profile as a preference and invokes a new scan;
saveNewProfile(AeroProfile);
}
// Instantiate a new "row" view.
final ViewGroup childView = (ViewGroup) LayoutInflater.from(mContext).inflate(
R.layout.profiles_list, mContainerView, false);
// Create TextView, with Content and Listeners;
final TextView txtView = (TextView)childView.findViewById(R.id.profile_text);
final TextView txtViewSummary = (TextView)childView.findViewById(R.id.profile_text_summary);
txtView.setText(s);
/*
* Case 1; We open up our data and check, if the user has checked anything for this profile
* Case 2: We actually map the found data to our objects later on (checked state)
*/
if (checkState(s)) {
// he has checked something!
updateStatus(txtViewSummary, true);
} else {
updateStatus(txtViewSummary, false);
}
txtView.setTypeface(AeroActivity.files.kitkatFont);
createListener(txtView, txtViewSummary);
final UndoBarStyle style = new UndoBarStyle(R.drawable.ic_action_undo, R.string.pref_profile_undo,
R.drawable.undobar_background, 5000).setAnim(AnimationUtils.loadAnimation(mContext,
android.R.anim.fade_in), AnimationUtils.loadAnimation(mContext, android.R.anim.fade_out));
// Remove the complete ViewGroup;
childView.findViewById(R.id.delete_button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
UndoBarController.show(getActivity(), getText(R.string.pref_profile_deleted), ProfileFragment.this, style);
mDeletedProfile = txtView.getText().toString();
mDeletedChild = childView;
mPrefs = mContext.getSharedPreferences(mDeletedProfile, Context.MODE_PRIVATE);
mContainerView.removeView(mDeletedChild);
}
});
// Assign this profile to an app
childView.findViewById(R.id.assign_to_app).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// Handles mapping and calls the dialog builder;
getPersistentData(perApp, s, txtViewSummary);
}
});
mContainerView.addView(childView, 0);
}
/*
* Called to revoke the operations;
*/
@Override
public void onUndo(final Parcelable token) {
Toast.makeText(mContext, R.string.successful, Toast.LENGTH_SHORT).show();
mContainerView.addView(mDeletedChild);
}
/*
* Called to execute the operations;
*/
@Override
public void onHide(final Parcelable token) {
if (deleteProfile(mDeletedProfile)) {
mContainerView.removeView(mDeletedChild);
}
// If there are no rows remaining, show
// the empty view.
if (mContainerView.getChildCount() == 2) {
mContainerView.findViewById(android.R.id.empty).setVisibility(View.VISIBLE);
mContainerView.findViewById(R.id.empty_image).setVisibility(View.VISIBLE);
}
}
// Returns true if any available profile is assigned
private final boolean checkAllStates() {
for (String s : mCompleteProfiles) {
// Don't take default xml;
if (!(s.equals("com.aero.control_preferences.xml") || s.equals("showcase_internal.xml")
|| s.equals("app_rate_prefs.xml") || s.equals(perAppProfileHandler + ".xml"))) {
// Just for the looks;
s = s.replace(".xml", "");
if (checkState(s))
return true;
}
}
return false;
}
// Checks and returns true if the profile is assigned
private final boolean checkState(String name) {
final String profile = mPerAppPrefs.getString(name, null);
// No profile was created anyway, return quickly;
if (profile == null)
return false;
String tmp[];
tmp = profile.replace("+", " ").split(" ");
// If no assigned apps are found, set to false, otherwise update UI
if (tmp == null) {
return false;
} else {
for (final String a : tmp) {
if (a.equals(""))
return false;
}
return true;
}
}
/*
* Maps the persistent data in shared_prefs to our currently
* available objects and also sets up the per app dialog
*/
private final void getPersistentData(final perAppHelper perApp, final String profileName, final TextView txtViewSummary) {
final String savedSelectedProfiles = mPerAppPrefs.getString(profileName, null);
String systemApps = mPerAppPrefs.getString("systemStatus", null);
//Probably a "fresh" profile;
if (systemApps == null)
systemApps = "false";
perApp.setSystemAppStatus(Boolean.valueOf(systemApps));
if (mPackages != null) {
// We are good to go, save time!
perApp.setPackages(mPackages);
// Map data if present
if (savedSelectedProfiles != null) {
String tmp[];
tmp = savedSelectedProfiles.replace("+", " ").split(" ");
// Finds the matches;
perApp.findMatch(tmp);
}
showPerAppDialog(perApp, profileName, txtViewSummary);
} else {
if (mProgressDialog == null) {
mProgressDialog = new ProgressDialog(mContext);
mProgressDialog.setMessage(getText(R.string.pref_profile_loading_app_data));
mProgressDialog.setIndeterminate(true);
mProgressDialog.setIndeterminateDrawable(getResources().getDrawable(R.drawable.spinner_animation));
}
mProgressDialog.show();
// Worst case;
Runnable runnable = new Runnable() {
@Override
public void run() {
/*
* While we are getting the relevant data, we show a spinner
* and continue with our operation afterwards in the UI thread
*/
perApp.getAllApps(perApp.getSystemAppStatus());
mPackages = perApp.getPackages();
// Map data if present
if (savedSelectedProfiles != null) {
String tmp[];
tmp = savedSelectedProfiles.replace("+", " ").split(" ");
// Finds the matches;
perApp.findMatch(tmp);
}
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
mProgressDialog.dismiss();
showPerAppDialog(perApp, profileName, txtViewSummary);
}
});
}
};
new Thread(runnable).start();
}
}
private void updateStatus(TextView txtView, boolean toggle) {
if (toggle) {
txtView.setText(R.string.perAppAssigned);
txtView.setTextColor(Color.parseColor("#1abc9c"));
} else {
txtView.setText(R.string.notperAppAssigned);
txtView.setTextColor(Color.parseColor("#e74c3c"));
}
}
private final void showPerAppDialog(final perAppHelper perApp, final String profileName, final TextView txtViewSummary) {
final AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
dialog.setTitle(R.string.pref_profile_perApp);
dialog.setMultiChoiceItems(perApp.getAllPackageNames(), perApp.getCheckedState(), new DialogInterface.OnMultiChoiceClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i, boolean b) {
if (b) {
perApp.setChecked(true, i);
} else {
perApp.setChecked(false, i);
}
}
})
// Set the action buttons
.setPositiveButton(R.string.save, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
String[] packageNames = perApp.getCurrentSelectedPackages();
String tmp = "";
if (packageNames != null) {
for (String a : packageNames) {
tmp = tmp + a + "+";
}
}
mPerAppPrefs.edit().remove(profileName);
mPerAppPrefs.edit().putString("systemStatus", perApp.getSystemAppStatus() + "").commit();
mPerAppPrefs.edit().putString(profileName, tmp).commit();
if (checkState(profileName)) {
updateStatus(txtViewSummary, true);
} else {
updateStatus(txtViewSummary, false);
}
// User has assigned apps, but no service is running;
if (AeroActivity.perAppService == null || !(AeroActivity.perAppService.getState())) {
if (checkAllStates() && !mWarning) {
AppRate.with(getActivity())
.text(R.string.pref_profile_service_not_running)
.fromTop(false)
.delay(1000)
.autoHide(15000)
.allowPlayLink(false)
.forceShow();
mWarning = true;
}
}
}
})
.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
// Do Nothing
}
})
.setNeutralButton(R.string.pref_profile_showSystem, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
perApp.setSystemAppStatus(!perApp.getSystemAppStatus());
mPerAppPrefs.edit().putString("systemStatus", perApp.getSystemAppStatus() + "").commit();
getPersistentData(perApp, profileName, txtViewSummary);
}
})
;
dialog.create().show();
}
private final boolean deleteProfile(String ProfileName) {
final File prefFile = new File (AeroActivity.files.sharedPrefsPath + ProfileName + ".xml");
mPerAppPrefs.edit().remove(ProfileName).commit();
//Delete it;
prefFile.delete();
// Check if file is gone;
if(!(prefFile.exists())) {
return true;
} else {
// Now we need to try to delete it with fire
Log.e(LOG_TAG, "Whoop, it still exists, something went wrong");
// Delete the file, not just clear the pref;
final String[] cmd = new String[] {
"rm " + "\"" + AeroActivity.files.sharedPrefsPath + ProfileName + ".xml" + "\""
};
AeroActivity.shell.setRootInfo(cmd);
try {
Thread.sleep(350);
} catch (InterruptedException e) {
Log.e(LOG_TAG, "Something interrupted the main Thread, try again.", e);
}
return true;
}
}
private final void saveNewProfile(SharedPreferences AeroProfile) {
// Just to be save, loading default again;
mPrefs = PreferenceManager.getDefaultSharedPreferences(mContext);
SharedPreferences.Editor editor = AeroProfile.edit();
// Get all our preferences;
final Map<String,?> allKeys = mPrefs.getAll();
saveProfile(allKeys, editor);
}
private final void applyProfile(SharedPreferences AeroProfile) {
// Just to be save, loading default again;
SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(mContext).edit();
// Get all our preferences;
final Map<String,?> allKeys = AeroProfile.getAll();
saveProfile(allKeys, editor);
}
private final void saveProfile(Map<String,?> allKeys, SharedPreferences.Editor editor) {
for(Map.Entry<String, ?> entry : allKeys.entrySet()) {
String value = entry.getValue().toString();
String key = entry.getKey().toString();
// We found a boolean, wow!
if (value.equals("true") || value.equals("false")) {
Boolean tmp;
/*
* Somehow getBoolean doesn't work for me here
*/
if (value.equals("false"))
tmp = false;
else if (value.equals("true"))
tmp = true;
else
tmp = false;
editor.putBoolean(key, tmp);
} else {
editor.putString(key, value);
}
}
editor.commit();
}
private final void renameProfile(CharSequence oldName, String newName, TextView txtView, TextView txtViewSummary) {
final File prefFile = new File (AeroActivity.files.sharedPrefsPath + oldName.toString() + ".xml");
newName = newName.replace("/", "-");
prefFile.renameTo(new File (AeroActivity.files.sharedPrefsPath + newName + ".xml"));
prefFile.delete();
if (prefFile.exists()) {
final String[] cmd = new String[] {
"mv " + "\"" + AeroActivity.files.sharedPrefsPath + oldName + ".xml" + "\"" + " " + "\"" + AeroActivity.files.sharedPrefsPath + newName + ".xml" + "\""
};
AeroActivity.shell.setRootInfo(cmd);
}
// We need to delete the "old" preference if there are profiles assigned;
final String valueOld = mPerAppPrefs.getString(oldName.toString(), null);
mPerAppPrefs.edit().remove(oldName.toString()).commit();
mPerAppPrefs.edit().putString(newName, valueOld).commit();
txtView.setText(newName);
}
/*
* Create a onClick Listener for each profile;
*/
private final void createListener(final TextView txtView, final TextView txtViewSummary) {
// Get our relative layout parent view first and set the listener
View v = (View)txtView.getParent();
// Show the actual profile;
v.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
final SharedPreferences AeroProfile = mContext.getSharedPreferences(txtView.getText().toString(), Context.MODE_PRIVATE);
TextView profileText = new TextView(mContext);
String content = "";
String tmp;
// Get all our preferences;
final Map<String,?> allKeys = AeroProfile.getAll();
for(Map.Entry<String, ?> entry : allKeys.entrySet()) {
tmp = entry.getKey();
// For better looking;
if (tmp.contains("/sys/devices/system/cpu/cpufreq/"))
tmp = tmp.replace("/sys/devices/system/cpu/cpufreq/", "");
else if (tmp.contains("/proc/sys/vm/"))
tmp = tmp.replace("/proc/sys/vm/", "");
else if (tmp.contains("/sys/module/msm_kgsl_core/parameters/"))
tmp = tmp.replace("/sys/module/msm_kgsl_core/parameters/", "gpu -> ");
else if (tmp.contains("/sys/kernel/hotplug_control/"))
tmp = tmp.replace("/sys/kernel/hotplug_control/", "hotplug_control -> ");
else if (tmp.contains("/sys/devices/virtual/timed_output/vibrator/"))
tmp = tmp.replace("/sys/devices/virtual/timed_output/vibrator/", "vibrator -> ");
else if (tmp.contains("/sys/module/msm_thermal/parameters/"))
tmp = tmp.replace("/sys/module/msm_thermal/parameters/", "thermal_control -> ");
else if (tmp.contains("/sys/devices/fdb00000.qcom,kgsl-3d0/kgsl/kgsl-3d0/devfreq/"))
tmp = tmp.replace("/sys/devices/fdb00000.qcom,kgsl-3d0/kgsl/kgsl-3d0/devfreq/", "");
content = tmp + " = " + entry.getValue().toString() + "\n" + content;
profileText.setText(content);
}
profileText.setVerticalScrollBarEnabled(true);
profileText.setMovementMethod(new ScrollingMovementMethod());
profileText.setPadding(20, 20, 20, 20);
profileText.setTypeface(AeroActivity.files.kitkatFont);
AlertDialog dialog = new AlertDialog.Builder(mContext)
.setTitle(getText(R.string.slider_overview) + ": " + txtView.getText().toString())
.setView(profileText)
.setPositiveButton(R.string.apply, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
mPrefs = mContext.getSharedPreferences("com.aero.control_preferences", Context.MODE_PRIVATE);
deleteProfile("com.aero.control_preferences");
SharedPreferences AeroProfile = mContext.getSharedPreferences(txtView.getText().toString(), Context.MODE_PRIVATE);
applyProfile(AeroProfile);
settings.setSettings(mContext, null);
}
})
.setNegativeButton(R.string.cancel, null)
.create();
dialog.show();
}
});
// Change the name of the profile;
v.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View view) {
mCompleteProfiles = AeroActivity.shell.getDirInfo(AeroActivity.files.sharedPrefsPath, true);
final EditText editText = new EditText(mContext);
final CharSequence oldName = txtView.getText();
editText.setText(oldName);
AlertDialog dialog = new AlertDialog.Builder(mContext)
.setTitle(R.string.pref_profile_change_name)
.setMessage(R.string.pref_profile_change_name_sum)
.setView(editText)
.setPositiveButton(R.string.save, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
String newName = editText.getText().toString();
String allProfiles = Arrays.asList(mCompleteProfiles).toString();
if (allProfiles.contains(newName + ".xml")) {
Toast.makeText(mContext, R.string.pref_profile_name_exists, Toast.LENGTH_LONG).show();
} else {
txtView.setText(newName);
renameProfile(oldName, newName, txtView, txtViewSummary);
}
}
})
.setNegativeButton(R.string.cancel, null)
.create();
dialog.show();
return true;
}
});
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
// Prepare Showcase;
mConfigOptions = new ShowcaseView.ConfigOptions();
mConfigOptions.hideOnClickOutside = false;
mConfigOptions.shotType = ShowcaseView.TYPE_ONE_SHOT;
// Set up our file;
int output = 0;
final byte[] buffer = new byte[1024];
try {
FileInputStream fis = mContext.openFileInput(FILENAME_PROFILES);
output = fis.read(buffer);
fis.close();
} catch (IOException e) {
Log.e(LOG_TAG, "Couldn't open File... " + output);
}
// Only show showcase once;
if (output == 0)
DrawFirstStart(R.string.showcase_profile_fragment, R.string.showcase_profile_fragment_sum, FILENAME_PROFILES, R.id.action_add_item);
}
public void DrawFirstStart(int header, int content, String filename, Integer id) {
try {
FileOutputStream fos = mContext.openFileOutput(filename, Context.MODE_PRIVATE);
fos.write("1".getBytes());
fos.close();
}
catch (IOException e) {
Log.e(LOG_TAG, "Could not save file. ", e);
}
if (id == null)
mShowCase = ShowcaseView.insertShowcaseView(150, 200, getActivity(), header, content, mConfigOptions);
else
mShowCase = ShowcaseView.insertShowcaseViewWithType(ShowcaseView.ITEM_ACTION_ITEM, id, getActivity(), header, content, mConfigOptions);
}
}