Great Android Programming Reference

Finds all API level statics/consts among other things.

http://www.kiwidoc.com/java/l/x/android/android/5/p/android.provider/c/Settings.Secure

Advertisements

Boiler Plate Android ListPreference Implementation Example

/values/arrays.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string-array name="pref_capacitive_backlight_entries">        
        <item>Off</item>
        <item>Dim</item>
        <item>Full On (Default)</item>
    </string-array>
    <string-array name="pref_capacitive_backlight_values">        
        <item>0</item>
        <item>2</item>
        <item>20</item>
    </string-array>
</resources>

/xml/misc_prefs.xml

<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen android:key="sense_pref_root"
  xmlns:android="http://schemas.android.com/apk/res/android">
    <PreferenceCategory android:title="Misc Tweaks">
       	<ListPreference android:entries="@array/pref_capacitive_backlight_entries" android:title="Capacitive Backlight" android:key="pref_capacitive_backlight" android:entryValues="@array/pref_capacitive_backlight_values" android:summary="Brightness of backlight behind bottom capacitive buttons" android:defaultValue="20" />
    </PreferenceCategory>
</PreferenceScreen>

MiscActivity.java


package com.roman.tweaks.activities;

import com.roman.tweaks.R;
import com.roman.tweaks.ShellInterface;


import android.content.Context;

import android.os.Bundle;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.PreferenceActivity;
import android.preference.PreferenceScreen;
import android.provider.Settings;
import android.util.Log;

public class MiscActivity extends PreferenceActivity implements OnPreferenceChangeListener {
    String pref;

    Context mContext;

    
    private static final String PREF_CAPACITIVE_BACKLIGHT = "pref_capacitive_backlight";

    
    ListPreference mCapacitiveBacklight;
    
    /** Called when the activity is first created. */
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mContext = this.getApplicationContext();
        addPreferencesFromResource(R.xml.misc_prefs);
        PreferenceScreen prefs = getPreferenceScreen();

   
        mCapacitiveBacklight = (ListPreference) prefs.findPreference(PREF_CAPACITIVE_BACKLIGHT);  
        mCapacitiveBacklight.setOnPreferenceChangeListener(this);          

    }    

    

    public boolean onPreferenceChange(Preference preference, Object newValue) {
        if (preference == mCapacitiveBacklight) {
            int valCapacitiveBacklight = Integer.valueOf((String) newValue);

            Settings.System.putInt(getContentResolver(), "tweaks_capacitive_backlight",
            		valCapacitiveBacklight);
            
            if (ShellInterface.isSuAvailable()) {
				ShellInterface.runCommand("echo '"+valCapacitiveBacklight+"' > /sys/devices/platform/leds-pm8058/leds/button-backlight/currents");
			}     
            
            
            return true;
        } 

        return false;
    }
}

AndroidManifest.xml Additions:

 <activity android:label="Tweaks - Misc Options" android:name=".activities.MiscActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
            </intent-filter>
        </activity>

Boiler Plate Android EditTextPreference Implementation Example

Create a new directory from root of project (xml) and add a new xml file (other_prefs):

<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen android:title="Other Preferences"
	android:key="Other_prefscreen" xmlns:android="http://schemas.android.com/apk/res/android">
	<EditTextPreference android:title="Carrier Caption"
		android:key="pref_lockscreen_caption" android:summary="The text to display at top of the lockscreen"
		android:defaultValue="Warm TwoPointThree" android:dialogTitle="Lockscreen caption" />
</PreferenceScreen>

Create a new Activity under /src (OtherActivity.java)

package com.roman.tweaks.activities;

import com.roman.tweaks.R;
import com.roman.tweaks.ShellInterface;

import android.os.Bundle;
import android.preference.EditTextPreference;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.PreferenceActivity;
import android.preference.PreferenceScreen;
import android.provider.Settings;

public class OtherActivity extends PreferenceActivity implements
		OnPreferenceChangeListener {

	public static final String TAG = "OtherActivity";

	// String keys for preference lookup
	private static final String PREF_CARRIER_CAPTION = "pref_lockscreen_caption";

	private EditTextPreference mLockscreenCaptionPref;

	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		addPreferencesFromResource(R.xml.other_prefs);

		// get UI object references
		PreferenceScreen prefSet = getPreferenceScreen();

		mLockscreenCaptionPref = (EditTextPreference) prefSet
				.findPreference(PREF_CARRIER_CAPTION);

		mLockscreenCaptionPref.setOnPreferenceChangeListener(this);
	}

	
	public boolean onPreferenceChange(Preference preference, Object newValue) {

		if (preference == mLockscreenCaptionPref) {

			String inputCarrierText = String.valueOf((String) newValue);
			Settings.System.putString(getContentResolver(),
					"tweaks_lockscreen_Caption", inputCarrierText);
			
			// Perform functions on preference change
			if (ShellInterface.isSuAvailable()) {
				ShellInterface.runCommand("echo '"+inputCarrierText+"' > /system/customize/lock_carrier.txt");
			}
			return true;

		}

		return false;
	}

}

Used in Warm Tweaks. See LockScreensActivity.java

How-To Access Methods From MasterPage With No CodeBehind File

Create a new MasterPage called “MasterPage1.master” unchecking “Place code in separate file”

At the top of the new MasterPage in the page directive append a ClassName property:

<%@ Master Language="C#" ClassName="MasterPage1" %>

In the script section add your public method:

<%@ Master Language="C#" ClassName="MasterPage1" %>

<%@ Register Src="../uc/footer.ascx" TagName="footer" TagPrefix="uc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
    public void SetMastHeadImage(string ImageUrl, string AlternateText)
    {
        this.imgMastHead.ImageUrl = (string.IsNullOrEmpty(ImageUrl)) ? "" : ImageUrl; ;
        this.imgMastHead.AlternateText = (string.IsNullOrEmpty(AlternateText)) ? "" : AlternateText;
    }
</script>

Create a new Page selecting the Master Page you just created.

Add code to invoke the method you just added:

<%@ Page Title="" Language="C#" MasterPageFile="~/mp/MasterPage1.master" %>

<script runat="server">
    
    
    protected override void OnLoad(EventArgs e)
    {
        // Define mast head image / alt text             
        ((MasterPage1)Master).SetMastHeadImage("../images/aboutus/masthead-AboutUs.jpg", "About Us");

    }
    
</script>