Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.skype;
- import java.io.ByteArrayOutputStream;
- import java.util.ArrayList;
- import java.util.List;
- import android.app.Activity;
- import android.app.AlertDialog;
- import android.app.Service;
- import android.content.Context;
- import android.content.DialogInterface;
- import android.content.Intent;
- import android.content.SharedPreferences;
- import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
- import android.graphics.Bitmap;
- import android.graphics.Bitmap.Config;
- import android.graphics.BitmapFactory;
- import android.graphics.Canvas;
- import android.graphics.Color;
- import android.graphics.ImageFormat;
- import android.graphics.Paint;
- import android.graphics.Rect;
- import android.graphics.YuvImage;
- import android.hardware.Camera;
- import android.hardware.Camera.CameraInfo;
- import android.hardware.Camera.Size;
- import android.media.AudioManager;
- import android.net.Uri;
- import android.os.Bundle;
- import android.preference.CheckBoxPreference;
- import android.preference.EditTextPreference;
- import android.preference.ListPreference;
- import android.preference.Preference;
- import android.preference.PreferenceActivity;
- import android.preference.PreferenceCategory;
- import android.preference.PreferenceScreen;
- import android.preference.Preference.OnPreferenceClickListener;
- import android.preference.RingtonePreference;
- import android.provider.Settings;
- import android.util.Log;
- import android.view.MenuItem;
- import android.widget.Toast;
- public class AdvancedSettings extends PreferenceActivity implements
- OnSharedPreferenceChangeListener {
- private static final String PREFS_NAME = "skypeCustomSettings";
- private static final String buildNo = "v04";
- public static Context context = null;
- public static int lastCamID = -1;
- public static boolean speakerPhoneOn = false;
- public static boolean bluetoothAudioOn = false;
- public static AudioManager am = null;
- SharedPreferences settings = null;
- SharedPreferences.Editor editor = null;
- int numCams = -1;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- PreferenceScreen root = getPreferenceManager().createPreferenceScreen(
- this);
- if (context == null)
- context = this.getApplicationContext();
- settings = context.getSharedPreferences(PREFS_NAME, 0);
- editor = settings.edit();
- PreferenceCategory vidCat = new PreferenceCategory(this);
- vidCat.setKey("cat_vid");
- vidCat.setTitle("Video settings");
- PreferenceCategory resCat = new PreferenceCategory(this);
- resCat.setKey("cat_0camres");
- resCat.setTitle("Camera settings");
- ListPreference cam1 = new ListPreference(this);
- cam1.setTitle("Resolution");
- cam1.setDialogTitle("Resolution");
- cam1.setKey("cam0res");
- ListPreference cam1rotation = new ListPreference(this);
- cam1rotation.setTitle("Rotation");
- cam1rotation.setDialogTitle("Rotation");
- cam1rotation.setKey("cam0rot");
- cam1rotation.setEntries(new String[] { "None", "90 deg", "180 deg",
- "270 deg" });
- cam1rotation.setEntryValues(new String[] { "-1", "90", "180", "270" });
- ListPreference cam1focus = new ListPreference(this);
- cam1focus.setTitle("Focus Mode");
- cam1focus.setDialogTitle("Focus Mode");
- cam1focus.setKey("cam0focus");
- cam1focus.setEntries(new String[] { "Default", "INFINITY", "FIXED",
- "EDOF", "CONTINUOUS_VIDEO" });
- cam1focus.setEntryValues(new String[] { "-1", "infinity", "fixed",
- "edof", "continuous-video" });
- ListPreference cam1colorEffect = new ListPreference(this);
- cam1colorEffect.setTitle("Color Effect");
- cam1colorEffect.setDialogTitle("Color Effect");
- cam1colorEffect.setKey("cam0colorEffect");
- cam1colorEffect.setEntries(new String[] { "Default", "MONO",
- "NEGATIVE", "SOLARIZE", "SEPIA", "POSTERIZE", "WHITEBOARD",
- "BLACKBOARD", "AQUA" });
- cam1colorEffect.setEntryValues(new String[] { "-1", "mono", "negative",
- "solarize", "sepia", "posterize", "whiteboard", "blackboard",
- "aqua" });
- ListPreference cam1sceneMode = new ListPreference(this);
- cam1sceneMode.setTitle("Scene Mode");
- cam1sceneMode.setDialogTitle("Scene Mode");
- cam1sceneMode.setKey("cam0sceneMode");
- cam1sceneMode.setEntries(new String[] { "Default", "AUTO", "ACTION",
- "PORTRAIT", "LANDSCAPE", "NIGHT", "NIGHT_PORTRAIT", "THEATRE",
- "BEACH", "SNOW", "SUNSET", "STEADYPHOTO", "FIREWORKS",
- "SPORTS", "PARTY", "CANDLELIGHT" });
- cam1sceneMode.setEntryValues(new String[] { "-1", "auto", "action",
- "portrait", "landscape", "night", "night-portrait", "theatre",
- "beach", "snow", "sunset", "steadyphoto", "fireworks",
- "sports", "party", "candlelight" });
- ListPreference cam1whiteBalance = new ListPreference(this);
- cam1whiteBalance.setTitle("White Balance");
- cam1whiteBalance.setDialogTitle("White Balance");
- cam1whiteBalance.setKey("cam0whiteBalance");
- cam1whiteBalance.setEntries(new String[] { "Default", "AUTO",
- "INCANDESCENT", "FLUORESCENT", "WARM_FLUORESCENT", "DAYLIGHT",
- "CLOUDY_DAYLIGHT", "TWILIGHT", "SHADE" });
- cam1whiteBalance.setEntryValues(new String[] { "-1", "auto",
- "incandescent", "fluorescent", "warm-fluorescent", "daylight",
- "cloudy-daylight", "twilight", "shade" });
- CheckBoxPreference cam1flip = new CheckBoxPreference(this);
- cam1flip.setTitle("Flip camera preview");
- cam1flip.setSummary("Image you see (not image sent!) will be flipped horizontally (mirrored)");
- cam1flip.setKey("cam0flip");
- cam1flip.setChecked(settings.getBoolean("cam0flip", false));
- CheckBoxPreference cam1flipAll = new CheckBoxPreference(this);
- cam1flipAll.setTitle("Flip camera image");
- cam1flipAll
- .setSummary("Both image you see and image sent will be flipped horizontally (mirrored)");
- cam1flipAll.setKey("cam0flipAll");
- cam1flipAll.setChecked(settings.getBoolean("cam0flipAll", false));
- PreferenceScreen cam0screen = getPreferenceManager()
- .createPreferenceScreen(this);
- cam0screen.setKey("cam0screen");
- ListPreference cam2 = new ListPreference(this);
- cam2.setTitle("Resolution");
- cam2.setDialogTitle("Resolution");
- cam2.setKey("cam1res");
- ListPreference cam2focus = new ListPreference(this);
- cam2focus.setTitle("Focus Mode");
- cam2focus.setDialogTitle("Focus Mode");
- cam2focus.setKey("cam1focus");
- cam2focus.setEntries(new String[] { "Default", "INFINITY", "FIXED",
- "EDOF", "CONTINUOUS_VIDEO" });
- cam2focus.setEntryValues(new String[] { "-1", "infinity", "fixed",
- "edof", "continuous-video" });
- ListPreference cam2colorEffect = new ListPreference(this);
- cam2colorEffect.setTitle("Color Effect");
- cam2colorEffect.setDialogTitle("Color Effect");
- cam2colorEffect.setKey("cam1colorEffect");
- cam2colorEffect.setEntries(new String[] { "Default", "MONO",
- "NEGATIVE", "SOLARIZE", "SEPIA", "POSTERIZE", "WHITEBOARD",
- "BLACKBOARD", "AQUA" });
- cam2colorEffect.setEntryValues(new String[] { "-1", "mono", "negative",
- "solarize", "sepia", "posterize", "whiteboard", "blackboard",
- "aqua" });
- ListPreference cam2sceneMode = new ListPreference(this);
- cam2sceneMode.setTitle("Scene Mode");
- cam2sceneMode.setDialogTitle("Scene Mode");
- cam2sceneMode.setKey("cam1sceneMode");
- cam2sceneMode.setEntries(new String[] { "Default", "AUTO", "ACTION",
- "PORTRAIT", "LANDSCAPE", "NIGHT", "NIGHT_PORTRAIT", "THEATRE",
- "BEACH", "SNOW", "SUNSET", "STEADYPHOTO", "FIREWORKS",
- "SPORTS", "PARTY", "CANDLELIGHT" });
- cam2sceneMode.setEntryValues(new String[] { "-1", "auto", "action",
- "portrait", "landscape", "night", "night-portrait", "theatre",
- "beach", "snow", "sunset", "steadyphoto", "fireworks",
- "sports", "party", "candlelight" });
- ListPreference cam2whiteBalance = new ListPreference(this);
- cam2whiteBalance.setTitle("White Balance");
- cam2whiteBalance.setDialogTitle("White Balance");
- cam2whiteBalance.setKey("cam1whiteBalance");
- cam2whiteBalance.setEntries(new String[] { "Default", "AUTO",
- "INCANDESCENT", "FLUORESCENT", "WARM_FLUORESCENT", "DAYLIGHT",
- "CLOUDY_DAYLIGHT", "TWILIGHT", "SHADE" });
- cam2whiteBalance.setEntryValues(new String[] { "-1", "auto",
- "incandescent", "fluorescent", "warm-fluorescent", "daylight",
- "cloudy-daylight", "twilight", "shade" });
- ListPreference cam2rotation = new ListPreference(this);
- cam2rotation.setTitle("Rotation");
- cam2rotation.setDialogTitle("Rotation");
- cam2rotation.setKey("cam1rot");
- cam2rotation.setEntries(new String[] { "None", "90 deg", "180 deg",
- "270 deg" });
- cam2rotation.setEntryValues(new String[] { "-1", "90", "180", "270" });
- CheckBoxPreference cam2flip = new CheckBoxPreference(this);
- cam2flip.setTitle("Flip camera preview");
- cam2flip.setSummary("Image you see (not image sent!) will be flipped horizontally (mirrored)");
- cam2flip.setKey("cam1flip");
- cam2flip.setChecked(settings.getBoolean("cam1flip", false));
- CheckBoxPreference cam2flipAll = new CheckBoxPreference(this);
- cam2flipAll.setTitle("Flip camera image");
- cam2flipAll
- .setSummary("Both image you see and image sent will be flipped horizontally (mirrored)");
- cam2flipAll.setKey("cam1flipAll");
- cam2flipAll.setChecked(settings.getBoolean("cam1flipAll", false));
- PreferenceScreen cam1screen = getPreferenceManager()
- .createPreferenceScreen(this);
- cam1screen.setKey("cam1screen");
- Preference toastCamInfo = new Preference(this);
- toastCamInfo.setTitle("Number of cameras:");
- toastCamInfo.setKey("camInfoButton");
- toastCamInfo
- .setOnPreferenceClickListener(new OnPreferenceClickListener() {
- @Override
- public boolean onPreferenceClick(Preference preference) {
- AdvancedSettings
- .toastCameraInfo(AdvancedSettings.context);
- return false;
- }
- });
- CheckBoxPreference forceVideo = new CheckBoxPreference(this);
- forceVideo.setTitle("Force-enable video-calling");
- forceVideo.setSummary("Enable video-calling on your device!");
- forceVideo.setKey("forceVideo");
- forceVideo.setChecked(settings.getBoolean("forceVideo", false));
- setPreferenceScreen(root);
- if ((numCams = settings.getInt("numCams", -99)) == -99) {
- numCams = android.hardware.Camera.getNumberOfCameras();
- Toast.makeText(context, "Found " + numCams + " camera(s)!",
- Toast.LENGTH_LONG).show();
- editor.putInt("numCams", numCams);
- editor.commit();
- }
- toastCamInfo.setTitle("Number of cameras: " + numCams);
- // No way it gets in here :P
- if (android.os.Build.VERSION.SDK_INT < 9) {
- Toast.makeText(
- context,
- "You're running Android 2.2 or older, I wonder how you got here..",
- Toast.LENGTH_LONG).show();
- }
- Preference buildInfo = new Preference(this);
- buildInfo.setTitle("Developed by theos0o");
- buildInfo.setSummary("Build " + buildNo);
- buildInfo.setOnPreferenceClickListener(new OnPreferenceClickListener() {
- @Override
- public boolean onPreferenceClick(Preference preference) {
- Intent browserIntent = new Intent(
- Intent.ACTION_VIEW,
- Uri.parse("http://forum.xda-developers.com/showthread.php?t=1148708"));
- startActivity(browserIntent);
- return false;
- }
- });
- PreferenceCategory audioCat = new PreferenceCategory(this);
- audioCat.setKey("cat_audio");
- audioCat.setTitle("Audio settings");
- CheckBoxPreference customRing = new CheckBoxPreference(this);
- customRing.setKey("useCustomRing");
- customRing.setTitle("Custom ringtone");
- customRing.setSummary("Hate Skype's ringtone? :D");
- customRing.setChecked(settings.getBoolean("useCustomRing", false));
- RingtonePreference ringtone = new RingtonePreference(this) {
- @Override
- protected void onSaveRingtone(Uri ringtoneUri) {
- super.onSaveRingtone(ringtoneUri);
- context.getSharedPreferences(PREFS_NAME, 0).edit()
- .putString("ringtoneS", ringtoneUri.toString())
- .commit();
- }
- };
- ringtone.setTitle("Ringtone");
- ringtone.setKey("ringtoneS");
- ringtone.setEnabled(settings.getBoolean("useCustomRing", false));
- ringtone.setShowSilent(false);
- CheckBoxPreference forceSpeakerOff = new CheckBoxPreference(this);
- forceSpeakerOff.setTitle("Force speaker off after calls");
- forceSpeakerOff
- .setSummary("Speaker stuck enabled after skype-calls? Enable this!");
- forceSpeakerOff.setKey("speakerOff");
- forceSpeakerOff.setChecked(settings.getBoolean("speakerOff", false));
- CheckBoxPreference modeInCall = new CheckBoxPreference(this);
- modeInCall.setTitle("Use MODE_IN_CALL");
- modeInCall.setSummary("Audio failing? Try this..");
- modeInCall.setKey("modeInCall");
- modeInCall.setChecked(settings.getBoolean("modeInCall", false));
- PreferenceCategory genCat = new PreferenceCategory(this);
- genCat.setKey("cat_gen");
- genCat.setTitle("General settings");
- CheckBoxPreference disableProximity = new CheckBoxPreference(this);
- disableProximity.setKey("disableProximity");
- disableProximity.setTitle("Keep screen alive");
- disableProximity
- .setSummary("Prevent screen from going off when in audio-call");
- disableProximity.setChecked(settings.getBoolean("disableProximity",
- false));
- CheckBoxPreference forceOneCam = new CheckBoxPreference(this);
- forceOneCam.setKey("forceOneCam");
- forceOneCam.setTitle("Force one camera");
- forceOneCam.setSummary("WTF! I don't have 2 cams dude!");
- forceOneCam.setChecked(settings.getBoolean("forceOneCam", false));
- CheckBoxPreference avoidSetFPS = new CheckBoxPreference(this);
- avoidSetFPS.setKey("avoidSetFPS");
- avoidSetFPS.setTitle("Avoid setFPS");
- avoidSetFPS.setSummary("Black video? Give this a try..");
- avoidSetFPS.setChecked(settings.getBoolean("avoidSetFPS", false));
- CheckBoxPreference avoidProfiling = new CheckBoxPreference(this);
- avoidProfiling.setKey("avoidProfiling");
- avoidProfiling.setTitle("Avoid FPS profiling");
- avoidProfiling
- .setSummary("If video is zooming after some time, enable this!");
- avoidProfiling.setChecked(settings.getBoolean("avoidProfiling", false));
- root.addPreference(buildInfo);
- root.addPreference(genCat);
- root.addPreference(disableProximity);
- root.addPreference(vidCat);
- root.addPreference(toastCamInfo);
- if (numCams >= 1) {
- root.addPreference(forceVideo);
- if (forceVideo() == 1) {
- if (numCams == 2) {
- root.addPreference(forceOneCam);
- }
- root.addPreference(avoidSetFPS);
- root.addPreference(avoidProfiling);
- root.addPreference(resCat);
- root.addPreference(cam0screen);
- cam0screen.addPreference(cam1);
- cam0screen.addPreference(cam1focus);
- if (colorEffectSupported(0)) {
- cam0screen.addPreference(cam1colorEffect);
- }
- if (sceneModeSupported(0)) {
- cam0screen.addPreference(cam1sceneMode);
- }
- if (whiteBalanceSupported(0)) {
- cam0screen.addPreference(cam1whiteBalance);
- }
- cam0screen.addPreference(cam1rotation);
- cam0screen.addPreference(cam1flip);
- cam0screen.addPreference(cam1flipAll);
- initCamValues(0);
- }
- }
- if (numCams >= 2 && forceVideo() == 1) {
- root.addPreference(cam1screen);
- cam1screen.addPreference(cam2);
- cam1screen.addPreference(cam2focus);
- if (colorEffectSupported(1)) {
- cam1screen.addPreference(cam2colorEffect);
- }
- if (sceneModeSupported(1)) {
- cam1screen.addPreference(cam2sceneMode);
- }
- if (whiteBalanceSupported(1)) {
- cam1screen.addPreference(cam2whiteBalance);
- }
- cam1screen.addPreference(cam2rotation);
- cam1screen.addPreference(cam2flip);
- cam1screen.addPreference(cam2flipAll);
- initCamValues(1);
- }
- CheckBoxPreference customNotif = new CheckBoxPreference(this);
- customNotif.setKey("useCustomNotif");
- customNotif.setTitle("Custom notification sound");
- customNotif.setChecked(settings.getBoolean("useCustomNotif", false));
- RingtonePreference notifS = new RingtonePreference(this) {
- @Override
- protected void onSaveRingtone(Uri ringtoneUri) {
- super.onSaveRingtone(ringtoneUri);
- context.getSharedPreferences(PREFS_NAME, 0).edit()
- .putString("notifS", ringtoneUri.toString()).commit();
- }
- };
- notifS.setTitle("Notification sound");
- notifS.setKey("notifS");
- notifS.setEnabled(settings.getBoolean("useCustomNotif", false));
- notifS.setShowSilent(false);
- notifS.setRingtoneType(2);
- root.addPreference(audioCat);
- root.addPreference(customRing);
- root.addPreference(ringtone);
- root.addPreference(customNotif);
- root.addPreference(notifS);
- root.addPreference(forceSpeakerOff);
- root.addPreference(modeInCall);
- for (int i = 0; i < getPreferenceScreen().getPreferenceCount(); i++) {
- initSummary(getPreferenceScreen().getPreference(i));
- }
- }
- @Override
- protected void onResume() {
- super.onResume();
- getPreferenceScreen().getSharedPreferences()
- .registerOnSharedPreferenceChangeListener(this);
- }
- @Override
- protected void onPause() {
- super.onPause();
- getPreferenceScreen().getSharedPreferences()
- .unregisterOnSharedPreferenceChangeListener(this);
- }
- public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
- String key) {
- updatePrefSummary(findPreference(key));
- }
- private void initSummary(Preference p) {
- if (p instanceof PreferenceCategory) {
- PreferenceCategory pCat = (PreferenceCategory) p;
- for (int i = 0; i < pCat.getPreferenceCount(); i++) {
- initSummary(pCat.getPreference(i));
- }
- } else if (p instanceof PreferenceScreen) {
- PreferenceScreen pScreen = (PreferenceScreen) p;
- for (int i = 0; i < pScreen.getPreferenceCount(); i++) {
- initSummary(pScreen.getPreference(i));
- }
- } else {
- if (!(p instanceof CheckBoxPreference))
- updatePrefSummary(p);
- }
- }
- private void updatePrefSummary(Preference p) {
- if (p instanceof ListPreference) {
- ListPreference listPref = (ListPreference) p;
- p.setSummary(listPref.getEntry());
- editor.putString(p.getKey(), ((ListPreference) p).getValue());
- editor.commit();
- } else if (p instanceof EditTextPreference) {
- EditTextPreference editTextPref = (EditTextPreference) p;
- p.setSummary(editTextPref.getText());
- } else if (p instanceof CheckBoxPreference) {
- if (p.getKey().equals("useCustomRing")) {
- findPreference("ringtoneS").setEnabled(
- ((CheckBoxPreference) p).isChecked());
- } else if (p.getKey().equals("useCustomNotif")) {
- findPreference("notifS").setEnabled(
- ((CheckBoxPreference) p).isChecked());
- }
- editor.putBoolean(p.getKey(), ((CheckBoxPreference) p).isChecked());
- editor.commit();
- if (p.getKey().equals("forceVideo")
- || p.getKey().equals("disableProximity")) {
- promptRestartApp();
- }
- }
- }
- public void initCamValues(int camID) {
- ListPreference targetCam = (ListPreference) findPreference("cam"
- + (camID) + "res");
- ArrayList<String> choices = new ArrayList<String>();
- ArrayList<String> values = new ArrayList<String>();
- choices.add("Let Skype decide");
- values.add("-1");
- choices.add("Force 320x240");
- values.add("-2");
- choices.add("Force 176x144");
- values.add("-3");
- for (Size tmp : getSupportedSizes(camID)) {
- choices.add(tmp.width + "x" + tmp.height);
- values.add(tmp.width + "x" + tmp.height);
- }
- targetCam.setEntries(choices.toArray(new CharSequence[choices.size()]));
- targetCam
- .setEntryValues(values.toArray(new CharSequence[values.size()]));
- String index = settings.getString("cam" + (camID) + "res", "-1");
- targetCam.setValue(index);
- targetCam.setSummary(targetCam.getEntry());
- ((PreferenceScreen) findPreference("cam" + camID + "screen"))
- .setTitle((getCameraFacing(camID) == CameraInfo.CAMERA_FACING_BACK ? "Back camera"
- : "Front camera"));
- ListPreference targetRotation = ((ListPreference) findPreference("cam"
- + camID + "rot"));
- index = settings.getString("cam" + (camID) + "rot", "-1");
- targetRotation.setValue(index);
- targetRotation.setSummary(targetRotation.getEntry());
- ListPreference targetFocus = ((ListPreference) findPreference("cam"
- + camID + "focus"));
- index = settings.getString("cam" + (camID) + "focus", "-1");
- targetFocus.setValue(index);
- targetFocus.setSummary(targetFocus.getEntry());
- if (colorEffectSupported(camID)) {
- ListPreference targetColor = ((ListPreference) findPreference("cam"
- + camID + "colorEffect"));
- index = settings.getString("cam" + (camID) + "colorEffect", "-1");
- targetColor.setValue(index);
- targetColor.setSummary(targetColor.getEntry());
- }
- if (sceneModeSupported(camID)) {
- ListPreference targetScene = ((ListPreference) findPreference("cam"
- + camID + "sceneMode"));
- index = settings.getString("cam" + (camID) + "sceneMode", "-1");
- targetScene.setValue(index);
- targetScene.setSummary(targetScene.getEntry());
- }
- if (whiteBalanceSupported(camID)) {
- ListPreference targetBalance = ((ListPreference) findPreference("cam"
- + camID + "whiteBalance"));
- index = settings.getString("cam" + (camID) + "whiteBalance", "-1");
- targetBalance.setValue(index);
- targetBalance.setSummary(targetBalance.getEntry());
- }
- }
- public static List<Size> getSupportedSizes(int camID) {
- if (camID >= Camera.getNumberOfCameras()) {
- throw new IllegalArgumentException("Invalid camera ID (" + camID
- + ")");
- }
- Camera targetCam = Camera.open(camID);
- List<Size> tmp = targetCam.getParameters().getSupportedPreviewSizes();
- targetCam.release();
- return tmp;
- }
- public static void toastCameraInfo(Context context) {
- int i;
- Toast.makeText(context,
- "You're running Android " + android.os.Build.VERSION.RELEASE,
- Toast.LENGTH_LONG).show();
- for (i = 0; i < Camera.getNumberOfCameras(); i++) {
- CameraInfo temp = new CameraInfo();
- Camera.getCameraInfo(i, temp);
- String tmp = "";
- tmp += "CID: "
- + i
- + ", FACING: "
- + (temp.facing == Camera.CameraInfo.CAMERA_FACING_BACK ? "BACK"
- : "FRONT") + ", ORIENTATION: " + temp.orientation;
- Toast.makeText(context, tmp, Toast.LENGTH_LONG).show();
- }
- }
- public static int numberOfCams() {
- if (context.getSharedPreferences(PREFS_NAME, 0).getBoolean(
- "forceOneCam", false)) {
- return 1;
- }
- return Camera.getNumberOfCameras();
- }
- public static int getCameraFacing(int camID) {
- Log.d("getCameraFacing", "Got camID = " + camID);
- if (camID >= Camera.getNumberOfCameras()) {
- throw new IllegalArgumentException("Invalid camera ID (" + camID
- + ")");
- }
- CameraInfo temp = new CameraInfo();
- Camera.getCameraInfo(camID, temp);
- return temp.facing;
- }
- public static int getCamResIndex(int camID) {
- Log.d("getCamResIndex", "Got camID = " + camID);
- if (camID >= Camera.getNumberOfCameras()) {
- throw new IllegalArgumentException("Invalid camera ID (" + camID
- + ")");
- }
- String index = context.getSharedPreferences(PREFS_NAME, 0).getString(
- "cam" + (camID) + "res", "-1");
- try {
- Log.d("getCamResIndex", "Returning " + Integer.parseInt(index));
- return Integer.parseInt(index);
- } catch (NumberFormatException e) {
- Log.d("getCamResIndex", "NumberFormatException (" + index
- + "), returning -99");
- return -99;
- }
- }
- public static int[] getPrefSizeArray(int camID) {
- Log.d("getPrefSizeArray", "Got camID = " + camID);
- String index = context.getSharedPreferences(PREFS_NAME, 0).getString(
- "cam" + (camID) + "res", "-1");
- String[] splitValue = index.split("x");
- int[] rval = { Integer.parseInt(splitValue[0]),
- Integer.parseInt(splitValue[1]) };
- Log.d("getPrefSizeArray",
- "Returning " + Integer.parseInt(splitValue[0]) + "x"
- + Integer.parseInt(splitValue[1]));
- return rval;
- }
- public static int getFlipValue(int camID) {
- Boolean boolval = context.getSharedPreferences(PREFS_NAME, 0)
- .getBoolean("cam" + (camID) + "flip", false);
- if (camID == 0) {
- if (boolval)
- return 1;
- else
- return 0;
- } else {
- if (boolval)
- return 0;
- else
- return 1;
- }
- }
- public static int getRotateValue(int camID) {
- int intval = -1;
- try {
- intval = Integer.parseInt(context.getSharedPreferences(PREFS_NAME,
- 0).getString("cam" + (camID) + "rot", "-1"));
- } catch (NumberFormatException e) {
- intval = -1;
- }
- if (intval != -1)
- return intval;
- else
- return getCameraOrientation(camID);
- }
- private static int getCameraOrientation(int camID) {
- Log.d("getRotation", "Got camID = " + camID);
- if (camID >= Camera.getNumberOfCameras()) {
- throw new IllegalArgumentException("Invalid camera ID (" + camID
- + ")");
- }
- CameraInfo temp = new CameraInfo();
- Camera.getCameraInfo(camID, temp);
- return temp.orientation;
- }
- public static void initContextVar(Context context) {
- AdvancedSettings.context = context;
- }
- public static int forceVideo() {
- return (context.getSharedPreferences(PREFS_NAME, 0).getBoolean(
- "forceVideo", false) ? 1 : 0);
- }
- public static void audioMode(AudioManager am, int close) {
- AdvancedSettings.am = am;
- if (close == 1 && AdvancedSettings.bluetoothAudioOn){
- am.setBluetoothScoOn(false);
- am.stopBluetoothSco();
- am.setMicrophoneMute(false);
- am.setSpeakerphoneOn(false);
- AdvancedSettings.bluetoothAudioOn = false;
- }
- if (context.getSharedPreferences(PREFS_NAME, 0).getBoolean(
- "modeInCall", false)) {
- if (close == 0) {
- am.setMode(AudioManager.MODE_IN_CALL);
- } else {
- am.setMode(AudioManager.MODE_NORMAL);
- }
- }
- }
- public static void forceSpeakerOff(AudioManager am) {
- if (context.getSharedPreferences(PREFS_NAME, 0).getBoolean(
- "speakerOff", false)) {
- am.setSpeakerphoneOn(false);
- }
- }
- public static void setFocus(int camID, Camera.Parameters params) {
- String strval = (context.getSharedPreferences(PREFS_NAME, 0).getString(
- "cam" + camID + "focus", "-1"));
- if (!strval.equals("-1")) {
- params.setFocusMode(strval);
- }
- }
- public static Boolean colorEffectSupported(int camID) {
- if (camID >= Camera.getNumberOfCameras()) {
- throw new IllegalArgumentException("Invalid camera ID (" + camID
- + ")");
- }
- Camera targetCam = Camera.open(camID);
- String tmp = targetCam.getParameters().getColorEffect();
- targetCam.release();
- return (tmp != null);
- }
- public static void setColorEffect(int camID, Camera.Parameters params) {
- String strval = (context.getSharedPreferences(PREFS_NAME, 0).getString(
- "cam" + camID + "colorEffect", "-1"));
- if (!strval.equals("-1")) {
- params.setColorEffect(strval);
- }
- }
- public static Boolean sceneModeSupported(int camID) {
- if (camID >= Camera.getNumberOfCameras()) {
- throw new IllegalArgumentException("Invalid camera ID (" + camID
- + ")");
- }
- Camera targetCam = Camera.open(camID);
- String tmp = targetCam.getParameters().getSceneMode();
- targetCam.release();
- return (tmp != null);
- }
- public static void setSceneMode(int camID, Camera.Parameters params) {
- String strval = (context.getSharedPreferences(PREFS_NAME, 0).getString(
- "cam" + camID + "sceneMode", "-1"));
- if (!strval.equals("-1")) {
- params.setSceneMode(strval);
- }
- }
- public static Boolean whiteBalanceSupported(int camID) {
- if (camID >= Camera.getNumberOfCameras()) {
- throw new IllegalArgumentException("Invalid camera ID (" + camID
- + ")");
- }
- Camera targetCam = Camera.open(camID);
- String tmp = targetCam.getParameters().getWhiteBalance();
- targetCam.release();
- return (tmp != null);
- }
- public static void setWhiteBalance(int camID, Camera.Parameters params) {
- String strval = (context.getSharedPreferences(PREFS_NAME, 0).getString(
- "cam" + camID + "whiteBalance", "-1"));
- if (!strval.equals("-1")) {
- params.setWhiteBalance(strval);
- }
- }
- public static void traceToast() {
- if (context != null)
- Toast.makeText(context, "I am here!", Toast.LENGTH_LONG).show();
- Log.d("traceToast", "I am here!");
- Thread.dumpStack();
- }
- public static void exitButton(Service svc) {
- svc.stopForeground(true);
- svc.stopSelf();
- System.exit(0);
- }
- public void promptRestartApp() {
- AlertDialog.Builder builder = new AlertDialog.Builder(this);
- builder.setMessage(
- "You need to kill and restart Skype for this change to take effect!")
- .setCancelable(false)
- .setPositiveButton("Restart Skype",
- new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int id) {
- killApp();
- }
- })
- .setNegativeButton("Later!",
- new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int id) {
- dialog.cancel();
- }
- });
- AlertDialog alert = builder.create();
- alert.show();
- }
- public void killApp() {
- android.os.Process.killProcess(android.os.Process.myPid());
- }
- public static Uri getRingtoneUri(Uri in) {
- try {
- String[] splitURI = in.toString().split("/");
- String resName = context.getResources().getResourceName(
- Integer.parseInt(splitURI[splitURI.length - 1]));
- if (resName.contains("raw") && resName.contains("incoming_call")) { // raw/incoming_call.wav
- if (context.getSharedPreferences(PREFS_NAME, 0).getBoolean(
- "useCustomRing", false)) {
- return Uri.parse(context
- .getSharedPreferences(PREFS_NAME, 0).getString(
- "ringtoneS",
- Settings.System.DEFAULT_RINGTONE_URI
- .toString()));
- } else {
- return in;
- }
- } else if (resName.contains("raw")
- && resName.contains("message_received")) { // raw/message_received.wav
- if (context.getSharedPreferences(PREFS_NAME, 0).getBoolean(
- "useCustomNotif", false)) {
- return Uri.parse(context
- .getSharedPreferences(PREFS_NAME, 0).getString(
- "notifS",
- Settings.System.DEFAULT_NOTIFICATION_URI
- .toString()));
- } else {
- return in;
- }
- } else {
- return in;
- }
- } catch (NumberFormatException e) {
- return in;
- }
- }
- public static void setParams(int camID, Camera.Parameters params) {
- lastCamID = camID;
- setFocus(camID, params);
- setColorEffect(camID, params);
- setSceneMode(camID, params);
- setWhiteBalance(camID, params);
- }
- public static String disableProximityVal() {
- Boolean boolval = context.getSharedPreferences(PREFS_NAME, 0)
- .getBoolean("disableProximity", false);
- return (boolval ? "WAKE_BIT_SCREEN_BRIGHT"
- : "PROXIMITY_SCREEN_OFF_WAKE_LOCK");
- }
- public static int avoidSetFPS() {
- Boolean boolval = context.getSharedPreferences(PREFS_NAME, 0)
- .getBoolean("avoidSetFPS", false);
- return (boolval ? 1 : 0);
- }
- public static int avoidProfiling() {
- Boolean boolval = context.getSharedPreferences(PREFS_NAME, 0)
- .getBoolean("avoidProfiling", false);
- return (boolval ? 1 : 0);
- }
- public static void showAdvancedSettings(Activity activity) {
- Intent show = new Intent(context, AdvancedSettings.class);
- activity.startActivity(show);
- }
- public static void onPreviewFrame(byte[] data, Camera camera, int camID) {
- int rotation = -1;
- try {
- rotation = Integer.parseInt(context.getSharedPreferences(
- PREFS_NAME, 0).getString("cam" + camID + "rot", "-1"));
- } catch (NumberFormatException e) {
- rotation = -1;
- }
- if (rotation != -1) {
- Size size = camera.getParameters().getPreviewSize();
- YuvImage yuv = new YuvImage(data, ImageFormat.NV21, size.width,
- size.height, null);
- ByteArrayOutputStream stream = new ByteArrayOutputStream();
- yuv.compressToJpeg(new Rect(0, 0, size.width, size.height), 50,
- stream);
- Bitmap bmp = BitmapFactory.decodeByteArray(stream.toByteArray(), 0,
- stream.size());
- Bitmap scaledBitmap;
- scaledBitmap = Bitmap.createBitmap(size.width, size.height,
- Config.RGB_565);
- scaleBitmap(bmp, scaledBitmap, rotation);
- bmp.recycle();
- convertBitmapToNV21(scaledBitmap, data);
- scaledBitmap.recycle();
- }
- }
- public static byte[] convertBitmapToNV21(Bitmap bmp, byte[] yuv) {
- int width = bmp.getWidth();
- int height = bmp.getHeight();
- int[] argb = new int[width * height];
- int yuv_size = width * height
- * ImageFormat.getBitsPerPixel(ImageFormat.NV21);
- yuv_size = (yuv_size / 8) + ((yuv_size % 8) == 0 ? 0 : 1);
- if (yuv == null || yuv.length < yuv_size)
- yuv = new byte[yuv_size];
- bmp.getPixels(argb, 0, width, 0, 0, width, height);
- int vuStart = width * height;
- byte[] yuvColor = new byte[3];
- for (int row = 0; row < height; ++row) {
- for (int col = 0; col < width; ++col) {
- int idx = row * width + col;
- argb2yuv(argb[idx], yuvColor);
- yuv[idx] = yuvColor[0];
- if ((row & 1) == 0 && (col & 1) == 0) {
- int offset = row / 2 * width + col / 2 * 2;
- yuv[vuStart + offset] = yuvColor[2];
- yuv[vuStart + offset + 1] = yuvColor[1];
- }
- }
- }
- return yuv;
- }
- private static final int CSHIFT = 16;
- private static final int CYR = 19595;
- private static final int CYG = 38470;
- private static final int CYB = 7471;
- private static final int CUR = -11059;
- private static final int CUG = -21709;
- private static final int CUB = 32768;
- private static final int CVR = 32768;
- private static final int CVG = -27439;
- private static final int CVB = -5329;
- private static void argb2yuv(int argb, byte[] yuv) {
- int r = Color.red(argb);
- int g = Color.green(argb);
- int b = Color.blue(argb);
- yuv[0] = (byte) ((CYR * r + CYG * g + CYB * b) >> CSHIFT);
- yuv[1] = (byte) (((CUR * r + CUG * g + CUB * b) >> CSHIFT) + 128);
- yuv[2] = (byte) (((CVR * r + CVG * g + CVB * b) >> CSHIFT) + 128);
- }
- public static Bitmap scaleBitmap(Bitmap unscaledBitmap,
- Bitmap scaledBitmap, int degrees) {
- Canvas canvas = new Canvas(scaledBitmap);
- float ratioX, ratioY, offsetX = 0f, offsetY = 0f;
- int dstWidth = scaledBitmap.getWidth(), dstHeight = scaledBitmap
- .getHeight();
- int srcWidth = unscaledBitmap.getWidth(), srcHeight = unscaledBitmap
- .getHeight();
- if (((degrees %= 360) % 180) == 90) {
- int i = srcWidth;
- srcWidth = srcHeight;
- srcHeight = i;
- }
- canvas.drawColor(Color.BLACK);
- ratioX = ratioY = Math.min((float) dstWidth / (float) srcWidth,
- (float) dstHeight / (float) srcHeight);
- offsetX = (((float) srcWidth * ratioX) - (float) dstWidth) / 2f;
- offsetY = (((float) srcHeight * ratioY) - (float) dstHeight) / 2f;
- if (degrees == 0)
- canvas.translate(-offsetX, -offsetY); // for 0
- else if (degrees == 90)
- canvas.translate(dstWidth + offsetX, offsetY); // for 90
- else if (degrees == 180)
- canvas.translate(dstWidth - offsetX, dstHeight - offsetY); // for
- // 180
- else if (degrees == 270)
- canvas.translate(dstWidth / 2 + 2 * offsetX, dstHeight - offsetY); // for
- // 270
- canvas.scale(ratioX, ratioY);
- if (degrees != 0)
- canvas.rotate(degrees);
- canvas.drawBitmap(unscaledBitmap, 0, 0, new Paint(
- Paint.FILTER_BITMAP_FLAG));
- return scaledBitmap;
- }
- public static boolean getFlipAllValue(int camID) {
- boolean rval = context.getSharedPreferences(PREFS_NAME, 0).getBoolean(
- "cam" + camID + "flipAll", false);
- return rval;
- }
- public static boolean btAudio(MenuItem item) {
- if (!item.getTitle().toString().contains("BT Audio"))
- return false;
- if (!android.bluetooth.BluetoothAdapter.getDefaultAdapter().isEnabled()) {
- Toast.makeText(context, "Bluetooth is disabled!", 1).show();
- return true;
- }
- AdvancedSettings.bluetoothAudioOn = !AdvancedSettings.bluetoothAudioOn;
- if (!AdvancedSettings.bluetoothAudioOn) {
- AdvancedSettings.am.setBluetoothScoOn(false);
- AdvancedSettings.am.stopBluetoothSco();
- AdvancedSettings.am.setSpeakerphoneOn(AdvancedSettings.speakerPhoneOn);
- Toast.makeText(context, "Bluetooth audio is OFF!", 1).show();
- } else {
- AdvancedSettings.am.startBluetoothSco();
- AdvancedSettings.am.setBluetoothScoOn(true);
- AdvancedSettings.speakerPhoneOn = am.isSpeakerphoneOn();
- AdvancedSettings.am.setSpeakerphoneOn(false);
- Toast.makeText(context, "Bluetooth audio is ON!", 1).show();
- }
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment