Skip to content

Commit

Permalink
Moved settings fragment to it's own file
Browse files Browse the repository at this point in the history
  • Loading branch information
roeiedri committed Oct 3, 2020
1 parent 872a45d commit 2ef7d47
Show file tree
Hide file tree
Showing 9 changed files with 234 additions and 139 deletions.
2 changes: 2 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ dependencies {

//Room
implementation "androidx.room:room-runtime:2.1.0"
implementation 'androidx.wear:wear:1.0.0'
annotationProcessor "androidx.room:room-compiler:2.1.0"
testImplementation "androidx.room:room-testing:2.1.0"

Expand Down Expand Up @@ -106,4 +107,5 @@ dependencies {
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'org.mockito:mockito-android:2.24.0'
androidTestImplementation 'com.jraska.livedata:testing:1.0.0'
compileOnly 'com.google.android.wearable:wearable:2.5.0'
}
26 changes: 25 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
xmlns:tools="http://schemas.android.com/tools"
package="com.chooloo.www.callmanager">

<uses-permission android:name="android.permission.WAKE_LOCK" />

<uses-feature android:name="android.hardware.type.watch" />

<uses-permission android:name="android.permission.MANAGE_OWN_CALLS" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
Expand All @@ -12,7 +16,6 @@
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Expand All @@ -29,6 +32,21 @@
android:theme="@style/AppTheme.Light"
android:windowSoftInputMode="adjustResize"
tools:ignore="AllowBackup,GoogleAppIndexingWarning">
<uses-library
android:name="com.google.android.wearable"
android:required="true" />

<!--
Set to true if your app is Standalone, that is, it does not require the handheld
app to run.
-->
<meta-data
android:name="com.google.android.wearable.standalone"
android:value="true" />

<activity
android:name=".ui.activity.ContactActivity"
android:label="@string/title_activity_contact"></activity>
<activity
android:name=".ui.activity.MainActivity"
android:label="@string/app_name"
Expand All @@ -38,17 +56,23 @@
<!-- For receiving intents -->
<intent-filter>
<action android:name="android.intent.action.SEND" />

<category android:name="android.intent.category.DEFAULT" />

<data android:mimeType="image/*" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND" />

<category android:name="android.intent.category.DEFAULT" />

<data android:mimeType="text/plain" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND_MULTIPLE" />

<category android:name="android.intent.category.DEFAULT" />

<data android:mimeType="image/*" />
</intent-filter>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.chooloo.www.callmanager.ui.activity;

import android.os.Bundle;
import android.widget.TextView;

import com.chooloo.www.callmanager.R;
import com.chooloo.www.callmanager.util.ThemeUtils;

public class ContactActivity extends AbsThemeActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setThemeType(ThemeUtils.TYPE_NORMAL);
setContentView(R.layout.activity_contact);


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import androidx.preference.SwitchPreference;

import com.chooloo.www.callmanager.R;
import com.chooloo.www.callmanager.ui.fragment.SettingsFragment;
import com.chooloo.www.callmanager.util.PermissionUtils;
import com.chooloo.www.callmanager.util.ThemeUtils;

Expand Down Expand Up @@ -45,142 +46,4 @@ protected void onCreate(Bundle savedInstanceState) {

Objects.requireNonNull(getSupportActionBar()).setDisplayHomeAsUpEnabled(true);
}

public static class SettingsFragment extends PreferenceFragmentCompat {

@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
setPreferencesFromResource(R.xml.preference, rootKey);

//Init preferences
Preference.OnPreferenceChangeListener colorChangeListener = (preference, newValue) -> {
ListPreference listPreference = (ListPreference) preference;
CharSequence[] entries = listPreference.getEntries();
listPreference.setSummary(entries[listPreference.findIndexOfValue((String) newValue)]);

Intent intent = new Intent(getActivity(), MainActivity.class);
startActivity(intent);
return true;
};

Preference.OnPreferenceChangeListener themeChangeListener = (preference, newValue) -> {
ListPreference listPreference = (ListPreference) preference;
CharSequence[] entries = listPreference.getEntries();
listPreference.setSummary(entries[listPreference.findIndexOfValue((String) newValue)]);

Intent intent = new Intent(getActivity(), MainActivity.class);
startActivity(intent);
return true;
};

Preference.OnPreferenceChangeListener excelEnableChangeListener = (preference, newValue) -> {
CheckBoxPreference checkBoxPreference = (CheckBoxPreference) preference;
checkBoxPreference.setSummary(checkBoxPreference.getSummary());

Intent intent = new Intent(getActivity(), MainActivity.class);
startActivity(intent);
return true;
};

Preference.OnPreferenceChangeListener listChangeListener = (preference, newValue) -> {
ListPreference listPreference = (ListPreference) preference;
CharSequence[] entries = listPreference.getEntries();
listPreference.setSummary(entries[listPreference.findIndexOfValue((String) newValue)]);
return true;
};

Preference.OnPreferenceChangeListener switchChangeListener = (preference, newValue) -> {
SwitchPreference switchPreference = (SwitchPreference) preference;
switchPreference.setSummary(switchPreference.getSummary());
return true;
};

// App Color
ListPreference appColorPreference = (ListPreference) findPreference(getString(R.string.pref_app_color_key));
appColorPreference.setOnPreferenceChangeListener(colorChangeListener);
appColorPreference.setSummary(appColorPreference.getEntry());

// App theme
ListPreference appThemePreference = (ListPreference) findPreference(getString(R.string.pref_app_theme_key));
appThemePreference.setOnPreferenceChangeListener(themeChangeListener);
appThemePreference.setSummary(appThemePreference.getEntry());

// End call timer
ListPreference rejectCallTimerPreference = (ListPreference) findPreference(getString(R.string.pref_reject_call_timer_key));
rejectCallTimerPreference.setOnPreferenceChangeListener(listChangeListener);
rejectCallTimerPreference.setSummary(rejectCallTimerPreference.getEntry());

// Answer call timer
ListPreference answerCallTimerPreference = (ListPreference) findPreference(getString(R.string.pref_answer_call_timer_key));
answerCallTimerPreference.setOnPreferenceChangeListener(listChangeListener);
answerCallTimerPreference.setSummary(answerCallTimerPreference.getEntry());

// Default page
ListPreference defaultPagePreference = (ListPreference) findPreference(getString(R.string.pref_default_page_key));
defaultPagePreference.setOnPreferenceChangeListener(listChangeListener);
defaultPagePreference.setSummary(defaultPagePreference.getEntry());

// Excel enable selection
CheckBoxPreference excelEnablePreference = (CheckBoxPreference) findPreference(getString(R.string.pref_excel_enable_key));
excelEnablePreference.setOnPreferenceChangeListener(excelEnableChangeListener);

// SwitchPreference isSilentPreference = (SwitchPreference) findPreference(getString(R.string.pref_is_silent_key));
// isSilentPreference.setOnPreferenceChangeListener(switchChangeListener);
//
// SwitchPreference isNoVibratePreference = (SwitchPreference) findPreference(getString(R.string.pref_is_no_vibrate_key));
// isNoVibratePreference.setOnPreferenceChangeListener(switchChangeListener);

// Biometrics
SwitchPreference isBiometricPreference = (SwitchPreference) findPreference(getString(R.string.pref_is_biometric_key));
isBiometricPreference.setOnPreferenceChangeListener(switchChangeListener);

// Sim selection
ListPreference simSelectionPreference = (ListPreference) findPreference(getString(R.string.pref_sim_select_key));
simSelectionPreference.setOnPreferenceChangeListener(listChangeListener);

PermissionUtils.checkPermissionGranted(getContext(), READ_PHONE_STATE, true);
setupSimSelection();
}

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (requestCode == PermissionUtils.PERMISSION_RC && PermissionUtils.checkPermissionsGranted(grantResults)) {
setupSimSelection();
}
}

private void setupSimSelection() {
if (!PermissionUtils.checkPermissionGranted(getContext(), READ_PHONE_STATE, true)) {
Toast.makeText(getContext(), "No permission, please give permission to read phone state", Toast.LENGTH_LONG).show();
return;
}

ListPreference simSelectionPreference = (ListPreference) findPreference(getString(R.string.pref_sim_select_key));

@SuppressLint("MissingPermission")
List<SubscriptionInfo> subscriptionInfoList = SubscriptionManager.from(getContext()).getActiveSubscriptionInfoList();
int simCount = subscriptionInfoList.size();

if (simCount == 1) {
simSelectionPreference.setSummary(getString(R.string.pref_sim_select_disabled));
simSelectionPreference.setEnabled(false);
} else {
List<CharSequence> simsEntries = new ArrayList<>();

for (int i = 0; i < simCount; i++) {
SubscriptionInfo si = subscriptionInfoList.get(i);
Timber.i("Sim info " + i + " : " + si.getDisplayName());
simsEntries.add(si.getDisplayName());
}

CharSequence[] simsEntriesList = simsEntries.toArray(new CharSequence[simsEntries.size()]);
simSelectionPreference.setEntries(simsEntriesList);
// simsEntries.add(getString(R.string.pref_sim_select_ask_entry));
// CharSequence[] simsEntryValues = {"0", "1", "2"};
CharSequence[] simsEntryValues = {"0", "1"};
simSelectionPreference.setEntryValues(simsEntryValues);
}
}
}
}
Loading

0 comments on commit 2ef7d47

Please sign in to comment.