create Camera Preferences - Android Camera

Android examples for Camera:Camera Feature

Description

create Camera Preferences

Demo Code


import java.util.StringTokenizer;
import android.content.Context;
import android.content.SharedPreferences;
import android.hardware.Camera;
import android.preference.PreferenceManager;
import android.widget.Toast;

public class Main{
    private static SharedPreferences mSharedPreferences;
    private static void createCameraPreferences(Camera.Parameters params) {

        SharedPreferences.Editor editor = mSharedPreferences.edit();
        editor.putBoolean("initialized", true);

        StringTokenizer strParams = new StringTokenizer(params.flatten(),
                ";");
        while (strParams.hasMoreTokens()) {
            StringTokenizer entries = new StringTokenizer(
                    strParams.nextToken(), "=");
            String key, values;/*from  ww w. j a va  2s.  co m*/
            if (entries.countTokens() == 2) {
                key = entries.nextToken();
                values = entries.nextToken();
            } else {
                key = entries.nextToken();
                values = "";
            }

            for (int i = 0; i < CameraParameters.SUPPORT_PARAMS.length; i++) {
                if (key.compareTo(CameraParameters.SUPPORT_PARAMS[i]) == 0) {
                    editor.putString(key, values);
                }
            }
        }

        editor.commit();

        // For JPEG Thumbnail size, it requires additional task
        String thumbnailSize = mSharedPreferences.getString(
                "jpeg-thumbnail-width", "")
                + "x"
                + mSharedPreferences.getString("jpeg-thumbnail-height", "");
        editor.putString("thumbnail-size", thumbnailSize);
        editor.commit();
    }
}

Related Tutorials