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"?> |
||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" > |
||||
<PreferenceCategory |
||||
android:title="@string/preference_general" > |
||||
|
||||
<Preference |
||||
android:title="@string/board_edit" > |
||||
<intent |
||||
android:action="android.intent.action.VIEW" |
||||
android:targetPackage="org.floens.chan" |
||||
android:targetClass="org.floens.chan.activity.BoardEditor" /> |
||||
</Preference> |
||||
|
||||
<CheckBoxPreference |
||||
android:title="@string/preference_open_link_confirmation" |
||||
android:key="preference_open_link_confirmation" |
||||
android:defaultValue="true" /> |
||||
|
||||
<EditTextPreference |
||||
android:title="@string/preference_default_name" |
||||
android:key="preference_default_name" /> |
||||
|
||||
<EditTextPreference |
||||
android:title="@string/preference_default_email" |
||||
android:key="preference_default_email" /> |
||||
|
||||
</PreferenceCategory> |
||||
|
||||
<Preference |
||||
android:key="watch_settings" |
||||
android:title="@string/preference_watch_settings" > |
||||
<intent |
||||
android:action="android.intent.action.VIEW" |
||||
android:targetClass="org.floens.chan.activity.WatchSettingsActivity" |
||||
android:targetPackage="org.floens.chan" /> |
||||
</Preference> |
||||
<Preference android:title="@string/board_edit" > |
||||
<intent |
||||
android:action="android.intent.action.VIEW" |
||||
android:targetClass="org.floens.chan.activity.BoardEditor" |
||||
android:targetPackage="org.floens.chan" /> |
||||
</Preference> |
||||
|
||||
<PreferenceCategory android:title="@string/preference_general" > |
||||
<CheckBoxPreference |
||||
android:defaultValue="true" |
||||
android:key="preference_open_link_confirmation" |
||||
android:title="@string/preference_open_link_confirmation" /> |
||||
|
||||
<EditTextPreference |
||||
android:key="preference_default_name" |
||||
android:title="@string/preference_default_name" /> |
||||
<EditTextPreference |
||||
android:key="preference_default_email" |
||||
android:title="@string/preference_default_email" /> |
||||
</PreferenceCategory> |
||||
<PreferenceCategory |
||||
android:title="@string/preference_about" |
||||
android:key="group_about" > |
||||
|
||||
android:key="group_about" |
||||
android:title="@string/preference_about" > |
||||
<Preference |
||||
android:title="@string/preference_licenses" |
||||
android:summary="@string/preference_licences_summary" |
||||
android:key="about_licences" /> |
||||
|
||||
android:key="about_licences" |
||||
android:summary="@string/preference_licences_summary" |
||||
android:title="@string/preference_licenses" /> |
||||
<Preference |
||||
android:title="Chan" |
||||
android:key="about_version" /> |
||||
|
||||
android:key="about_version" |
||||
android:title="Chan" /> |
||||
<Preference |
||||
android:title="@string/preference_developer" |
||||
android:key="about_developer" > |
||||
android:key="about_developer" |
||||
android:title="@string/preference_developer" > |
||||
<intent |
||||
android:action="android.intent.action.VIEW" |
||||
android:targetPackage="org.floens.chan" |
||||
android:targetClass="org.floens.chan.activity.DeveloperActivity" /> |
||||
android:action="android.intent.action.VIEW" |
||||
android:targetClass="org.floens.chan.activity.DeveloperActivity" |
||||
android:targetPackage="org.floens.chan" /> |
||||
</Preference> |
||||
|
||||
</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 { |
||||
|
||||
} |
||||
|
||||
} |
Loading…
Reference in new issue