mirror of https://github.com/kurisufriend/Clover
parent
39d974f91c
commit
900fdb6ce4
@ -0,0 +1,11 @@ |
|||||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||||
|
<menu xmlns:android="http://schemas.android.com/apk/res/android" > |
||||||
|
|
||||||
|
<item |
||||||
|
android:id="@+id/enable_watch_switch" |
||||||
|
android:title="" |
||||||
|
android:actionViewClass="android.widget.Switch" |
||||||
|
android:showAsAction="always"> |
||||||
|
</item> |
||||||
|
|
||||||
|
</menu> |
@ -1,57 +1,52 @@ |
|||||||
<?xml version="1.0" encoding="utf-8"?> |
<?xml version="1.0" encoding="utf-8"?> |
||||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" > |
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" > |
||||||
<PreferenceCategory |
|
||||||
android:title="@string/preference_general" > |
<Preference |
||||||
|
android:key="watch_settings" |
||||||
<Preference |
android:title="@string/preference_watch_settings" > |
||||||
android:title="@string/board_edit" > |
<intent |
||||||
<intent |
android:action="android.intent.action.VIEW" |
||||||
android:action="android.intent.action.VIEW" |
android:targetClass="org.floens.chan.activity.WatchSettingsActivity" |
||||||
android:targetPackage="org.floens.chan" |
android:targetPackage="org.floens.chan" /> |
||||||
android:targetClass="org.floens.chan.activity.BoardEditor" /> |
</Preference> |
||||||
</Preference> |
<Preference android:title="@string/board_edit" > |
||||||
|
<intent |
||||||
<CheckBoxPreference |
android:action="android.intent.action.VIEW" |
||||||
android:title="@string/preference_open_link_confirmation" |
android:targetClass="org.floens.chan.activity.BoardEditor" |
||||||
android:key="preference_open_link_confirmation" |
android:targetPackage="org.floens.chan" /> |
||||||
android:defaultValue="true" /> |
</Preference> |
||||||
|
|
||||||
<EditTextPreference |
<PreferenceCategory android:title="@string/preference_general" > |
||||||
android:title="@string/preference_default_name" |
<CheckBoxPreference |
||||||
android:key="preference_default_name" /> |
android:defaultValue="true" |
||||||
|
android:key="preference_open_link_confirmation" |
||||||
<EditTextPreference |
android:title="@string/preference_open_link_confirmation" /> |
||||||
android:title="@string/preference_default_email" |
|
||||||
android:key="preference_default_email" /> |
<EditTextPreference |
||||||
|
android:key="preference_default_name" |
||||||
</PreferenceCategory> |
android:title="@string/preference_default_name" /> |
||||||
|
<EditTextPreference |
||||||
<PreferenceCategory |
android:key="preference_default_email" |
||||||
android:title="@string/preference_about" |
android:title="@string/preference_default_email" /> |
||||||
android:key="group_about" > |
</PreferenceCategory> |
||||||
|
<PreferenceCategory |
||||||
|
android:key="group_about" |
||||||
|
android:title="@string/preference_about" > |
||||||
<Preference |
<Preference |
||||||
android:title="@string/preference_licenses" |
android:key="about_licences" |
||||||
android:summary="@string/preference_licences_summary" |
android:summary="@string/preference_licences_summary" |
||||||
android:key="about_licences" /> |
android:title="@string/preference_licenses" /> |
||||||
|
|
||||||
<Preference |
<Preference |
||||||
android:title="Chan" |
android:key="about_version" |
||||||
android:key="about_version" /> |
android:title="Chan" /> |
||||||
|
|
||||||
<Preference |
<Preference |
||||||
android:title="@string/preference_developer" |
android:key="about_developer" |
||||||
android:key="about_developer" > |
android:title="@string/preference_developer" > |
||||||
<intent |
<intent |
||||||
android:action="android.intent.action.VIEW" |
android:action="android.intent.action.VIEW" |
||||||
android:targetPackage="org.floens.chan" |
android:targetClass="org.floens.chan.activity.DeveloperActivity" |
||||||
android:targetClass="org.floens.chan.activity.DeveloperActivity" /> |
android:targetPackage="org.floens.chan" /> |
||||||
</Preference> |
</Preference> |
||||||
|
|
||||||
</PreferenceCategory> |
</PreferenceCategory> |
||||||
</PreferenceScreen> |
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</PreferenceScreen> |
@ -0,0 +1,108 @@ |
|||||||
|
package org.floens.chan.activity; |
||||||
|
|
||||||
|
import org.floens.chan.R; |
||||||
|
import org.floens.chan.utils.ChanPreferences; |
||||||
|
import org.floens.chan.utils.Utils; |
||||||
|
|
||||||
|
import android.app.Activity; |
||||||
|
import android.app.Fragment; |
||||||
|
import android.app.FragmentTransaction; |
||||||
|
import android.os.Bundle; |
||||||
|
import android.os.Handler; |
||||||
|
import android.os.Looper; |
||||||
|
import android.preference.PreferenceFragment; |
||||||
|
import android.view.Gravity; |
||||||
|
import android.view.LayoutInflater; |
||||||
|
import android.view.Menu; |
||||||
|
import android.view.View; |
||||||
|
import android.view.ViewGroup; |
||||||
|
import android.widget.CompoundButton; |
||||||
|
import android.widget.CompoundButton.OnCheckedChangeListener; |
||||||
|
import android.widget.LinearLayout; |
||||||
|
import android.widget.Switch; |
||||||
|
import android.widget.TextView; |
||||||
|
|
||||||
|
public class WatchSettingsActivity extends Activity implements OnCheckedChangeListener { |
||||||
|
private Switch watchSwitch; |
||||||
|
|
||||||
|
@Override |
||||||
|
protected void onCreate(Bundle savedInstanceState) { |
||||||
|
super.onCreate(savedInstanceState); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public boolean onCreateOptionsMenu(Menu menu) { |
||||||
|
getMenuInflater().inflate(R.menu.watch_settings, menu); |
||||||
|
|
||||||
|
watchSwitch = (Switch) menu.findItem(R.id.enable_watch_switch).getActionView(); |
||||||
|
watchSwitch.setOnCheckedChangeListener(this); |
||||||
|
watchSwitch.setPadding(0, 0, Utils.dp(this, 20), 0); |
||||||
|
|
||||||
|
setEnabled(ChanPreferences.getWatchEnabled()); |
||||||
|
|
||||||
|
return true; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { |
||||||
|
setEnabled(isChecked); |
||||||
|
} |
||||||
|
|
||||||
|
private void setEnabled(boolean enabled) { |
||||||
|
if (enabled) { |
||||||
|
FragmentTransaction t = getFragmentManager().beginTransaction(); |
||||||
|
t.replace(android.R.id.content, new WatchSettingsFragment()); |
||||||
|
t.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE); |
||||||
|
t.commit(); |
||||||
|
} else { |
||||||
|
FragmentTransaction t = getFragmentManager().beginTransaction(); |
||||||
|
t.replace(android.R.id.content, TextFragment.newInstance(R.string.watch_info_text)); |
||||||
|
t.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE); |
||||||
|
t.commit(); |
||||||
|
} |
||||||
|
|
||||||
|
watchSwitch.setChecked(enabled); |
||||||
|
|
||||||
|
ChanPreferences.setWatchEnabled(enabled); |
||||||
|
|
||||||
|
watchSwitch.setEnabled(false); |
||||||
|
new Handler(Looper.getMainLooper()).postDelayed(new Runnable() { |
||||||
|
@Override |
||||||
|
public void run() { |
||||||
|
watchSwitch.setEnabled(true); |
||||||
|
} |
||||||
|
}, 500); |
||||||
|
} |
||||||
|
|
||||||
|
public static class TextFragment extends Fragment { |
||||||
|
public static TextFragment newInstance(int textResource) { |
||||||
|
TextFragment f = new TextFragment(); |
||||||
|
Bundle bundle = new Bundle(); |
||||||
|
bundle.putInt("text_resource", textResource); |
||||||
|
f.setArguments(bundle); |
||||||
|
return f; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public View onCreateView(LayoutInflater inflater, ViewGroup group, Bundle savedInstanceState) { |
||||||
|
LinearLayout container = new LinearLayout(inflater.getContext()); |
||||||
|
|
||||||
|
int p = Utils.dp(inflater.getContext(), 20); |
||||||
|
container.setPadding(p, p, p, p); |
||||||
|
|
||||||
|
TextView text = new TextView(inflater.getContext()); |
||||||
|
text.setTextSize(20); |
||||||
|
text.setText(getArguments().getInt("text_resource")); |
||||||
|
|
||||||
|
container.setGravity(Gravity.CENTER); |
||||||
|
container.addView(text); |
||||||
|
|
||||||
|
return container; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public static class WatchSettingsFragment extends PreferenceFragment { |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -1,29 +1,47 @@ |
|||||||
package org.floens.chan.utils; |
package org.floens.chan.utils; |
||||||
|
|
||||||
import org.floens.chan.ChanApplication; |
import org.floens.chan.ChanApplication; |
||||||
|
import org.floens.chan.service.PinnedService; |
||||||
|
|
||||||
public class ChanPreferences { |
public class ChanPreferences { |
||||||
public static boolean getOpenLinkConfirmation() { |
public static boolean getOpenLinkConfirmation() { |
||||||
return ChanApplication.getPreferences().getBoolean("preference_open_link_confirmation", true); |
return ChanApplication.getPreferences().getBoolean("preference_open_link_confirmation", true); |
||||||
} |
} |
||||||
|
|
||||||
public static String getDefaultName() { |
public static String getDefaultName() { |
||||||
return ChanApplication.getPreferences().getString("preference_default_name", ""); |
return ChanApplication.getPreferences().getString("preference_default_name", ""); |
||||||
} |
} |
||||||
|
|
||||||
public static String getDefaultEmail() { |
public static String getDefaultEmail() { |
||||||
return ChanApplication.getPreferences().getString("preference_default_email", ""); |
return ChanApplication.getPreferences().getString("preference_default_email", ""); |
||||||
} |
} |
||||||
|
|
||||||
public static boolean getDeveloper() { |
public static boolean getDeveloper() { |
||||||
return ChanApplication.getPreferences().getBoolean("preference_developer", false); |
return ChanApplication.getPreferences().getBoolean("preference_developer", false); |
||||||
} |
} |
||||||
|
|
||||||
public static void setDeveloper(boolean developer) { |
public static void setDeveloper(boolean developer) { |
||||||
ChanApplication.getPreferences().edit().putBoolean("preference_developer", developer).commit(); |
ChanApplication.getPreferences().edit().putBoolean("preference_developer", developer).commit(); |
||||||
} |
} |
||||||
|
|
||||||
public static String getImageSaveDirectory() { |
public static String getImageSaveDirectory() { |
||||||
return "Chan"; |
return "Chan"; |
||||||
} |
} |
||||||
|
|
||||||
|
public static boolean getWatchEnabled() { |
||||||
|
return ChanApplication.getPreferences().getBoolean("preference_watch_enabled", true); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* This also calls startStopAccordingToSettings on the PinnedService to |
||||||
|
* start/stop the service as needed. |
||||||
|
* |
||||||
|
* @param enabled |
||||||
|
*/ |
||||||
|
public static void setWatchEnabled(boolean enabled) { |
||||||
|
if (getWatchEnabled() != enabled) { |
||||||
|
ChanApplication.getPreferences().edit().putBoolean("preference_watch_enabled", enabled).commit(); |
||||||
|
PinnedService.startStopAccordingToSettings(ChanApplication.getInstance()); |
||||||
|
} |
||||||
|
} |
||||||
} |
} |
||||||
|
Loading…
Reference in new issue