Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Requested Features Added #2

Merged
merged 3 commits into from

2 participants

@shalinshah1993

The features added :-

  • Brightness Seeker -Random color frequency changer -Random color change stop start by using long click -Widget for flashlight -Added settings icon in action bar for easy access
@friedger friedger merged commit 5babc5c into openintents:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 3, 2013
  1. @shalinshah1993

    Widget added;Brightness Setter added;Color change freq setter added f…

    shalinshah1993 authored
    …or random mode;settings icon in action bar;
Commits on Feb 4, 2013
  1. @shalinshah1993

    Added settings icon

    shalinshah1993 authored
  2. @shalinshah1993
This page is out of date. Refresh to see the latest.
View
1  .gitignore
@@ -3,3 +3,4 @@
*/build-private.properties
*/local.properties
*/release
+lint.xml
View
5 Flashlight/.classpath
@@ -1,10 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
- <classpathentry kind="src" path="src"/>
- <classpathentry kind="src" path="gen"/>
+ <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK/org.openintents.distribution.demo.DistributionDemoActivity"/>
<classpathentry kind="src" path="OI Distribution Library_src"/>
<classpathentry kind="lib" path="libs/hardware09.jar"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="src" path="gen"/>
<classpathentry kind="output" path="bin/classes"/>
</classpath>
View
5 Flashlight/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,5 @@
+#Sun Feb 03 22:11:38 IST 2013
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.source=1.5
View
132 Flashlight/AndroidManifest.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
-<!--
+<!--
* Copyright (C) 2008-2011 OpenIntents.org
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -13,12 +13,15 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
--->
+-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="org.openintents.flashlight"
- android:installLocation="auto"
- android:versionCode="10011" android:versionName="1.1">
- <!-- History:
+ package="org.openintents.flashlight"
+ android:installLocation="auto"
+ android:versionCode="10011"
+ android:versionName="1.1" >
+
+ <!--
+ History:
* * * UPDATE ATRACKDOG METADATA BELOW FOR RELEASE CANDIDATES * * *
1.1 [10011]: 2012-01-01
1.0.7 [10010]: 2011-02-04
@@ -29,54 +32,87 @@
1.0.3 [10003]: 2008-11-19
1.0.2 [10002]: 2008-10-30
1.0.1 [10001]: 2008-10-30
- 1.0.0 [10000]: 2008-10-27 -->
-
- <uses-sdk android:minSdkVersion="2" android:targetSdkVersion="15"/>
-
- <uses-feature android:name="android.hardware.touchscreen" android:required="false"/>
-
- <!-- required to keep the backlight turned on -->
- <uses-permission android:name="android.permission.WAKE_LOCK"/>
-
- <!-- required to adjust the brightness -->
- <!-- <uses-permission android:name="android.permission.WRITE_SETTINGS"/> -->
- <uses-permission android:name="android.permission.HARDWARE_TEST"/>
- <uses-permission android:name="android.permission.FLASHLIGHT"/>
- <uses-permission android:name="android.permission.CAMERA"/>
-
- <!-- Don't require Market users to have camera. This app
- also works without these features: -->
- <uses-feature android:name="android.hardware.camera" android:required="false" />
- <uses-feature android:name="android.hardware.camera.autofocus" android:required="false" />
- <uses-feature android:name="android.hardware.screen.portrait" android:required="false" />
-
- <application android:icon="@drawable/ic_launcher_flashlight" android:label="@string/app_name">
-
+ 1.0.0 [10000]: 2008-10-27
+ -->
+
+ <uses-sdk
+ android:minSdkVersion="2"
+ android:targetSdkVersion="15" />
+
+ <uses-feature
+ android:name="android.hardware.touchscreen"
+ android:required="false" />
+
+ <!-- required to keep the backlight turned on -->
+ <uses-permission android:name="android.permission.WAKE_LOCK" />
+
+ <!-- required to adjust the brightness -->
+ <!-- <uses-permission android:name="android.permission.WRITE_SETTINGS"/> -->
+ <uses-permission android:name="android.permission.HARDWARE_TEST" />
+ <uses-permission android:name="android.permission.FLASHLIGHT" />
+ <uses-permission android:name="android.permission.CAMERA" />
+
+ <!--
+ Don't require Market users to have camera. This app
+ also works without these features:
+ -->
+ <uses-feature
+ android:name="android.hardware.camera"
+ android:required="false" />
+ <uses-feature
+ android:name="android.hardware.camera.autofocus"
+ android:required="false" />
+ <uses-feature
+ android:name="android.hardware.screen.portrait"
+ android:required="false" />
+
+ <application
+ android:icon="@drawable/ic_launcher_flashlight"
+ android:label="@string/app_name" >
+
<!-- aTrackDog metadata -->
- <meta-data android:name="com.a0soft.gphone.aTrackDog.testVersion"
- android:value="10009" />
-
- <meta-data android:name="org.openintents.about"
- android:resource="@xml/about" />
-
- <activity android:name=".Flashlight"
- android:label="@string/app_name"
- android:screenOrientation="portrait">
+ <meta-data
+ android:name="com.a0soft.gphone.aTrackDog.testVersion"
+ android:value="10009" />
+ <meta-data
+ android:name="org.openintents.about"
+ android:resource="@xml/about" />
+
+ <activity
+ android:name=".Flashlight"
+ android:label="@string/app_name"
+ android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
+
<category android:name="android.intent.category.LAUNCHER" />
- </intent-filter>
- <intent-filter>
- <action android:name="org.openintents.action.START_FLASHLIGHT" />
- <category android:name="android.intent.category.DEFAULT" />
</intent-filter>
- </activity>
-
+ <intent-filter>
+ <action android:name="org.openintents.action.START_FLASHLIGHT" />
+
+ <category android:name="android.intent.category.DEFAULT" />
+ </intent-filter>
+ </activity>
<activity android:name="org.openintents.flashlight.FlashlightPrefs" />
-
- <!-- Activities from OI Distribution Library -->
+
+ <!-- Activities from OI Distribution Library -->
<activity android:name="org.openintents.distribution.EulaActivity" />
<activity android:name="org.openintents.distribution.NewVersionActivity" />
-
+
+ <receiver android:name=".Widget" >
+ <intent-filter>
+ <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
+ </intent-filter>
+
+ <meta-data
+ android:name="android.appwidget.provider"
+ android:resource="@xml/widget" />
+ </receiver>
+
+ <service android:name=".WidgetService" >
+ </service>
+
+
</application>
-</manifest>
+
+</manifest>
View
2  Flashlight/project.properties
@@ -9,4 +9,4 @@
android.library.reference.1=../../distribution/DistributionLibrary/
# Project target.
-target=android-15
+target=android-16
View
10 Flashlight/res/layout/main.xml
@@ -46,4 +46,14 @@
android:layout_height="0dip"
android:layout_weight="1"
/>
+ <TextView
+ android:id="@+id/textView1"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="Brightness Setter" />
+
+ <SeekBar android:id="@+id/seekBar1"
+ android:progress="100"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"/>
</LinearLayout>
View
13 Flashlight/res/layout/widget_layout.xml
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:orientation="vertical" >
+
+ <ImageView
+ android:id="@+id/imageView1"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:src="@drawable/ic_launcher_flashlight" />
+
+</LinearLayout>
View
11 Flashlight/res/menu/menu.xml
@@ -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/item1"
+ android:icon="@android:drawable/ic_menu_preferences"
+ android:showAsAction="always"
+ android:title="Preferences">
+ </item>
+
+</menu>
View
5 Flashlight/res/values/strings.xml
@@ -52,5 +52,8 @@
<item >Random Color</item>
<item >White</item>
</string-array>
-
+ <string name="settings_set_time_summary">Select the rate at which the color changes in random mode</string>
+ <string name="settings_set_time_title">Frequency Options</string>
+ <string name="settings_time_dialog_title">Set timeuency</string>
+ <string name="settings_set_time_default">Eg. 40</string>
</resources>
View
13 Flashlight/res/xml/settings.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
-
+<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
android:title="@string/settings_titlebar" >
<CheckBoxPreference
@@ -19,4 +19,13 @@
android:summary="@string/settings_color_options_summary"
android:title="@string/settings_color_options" />
-
+ <EditTextPreference
+ android:dependency="use_camera_flash"
+ android:dialogTitle="@string/settings_time_dialog_title"
+ android:hint="@string/settings_set_time_default"
+ android:key="set_time"
+ android:summary="@string/settings_set_time_summary"
+ android:title="@string/settings_set_time_title" >
+ </EditTextPreference>
+
+</PreferenceScreen>
View
5 Flashlight/res/xml/widget.xml
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android" android:minWidth="72dp" android:minHeight="72dp">
+
+
+</appwidget-provider>
View
349 Flashlight/src/org/openintents/flashlight/Flashlight.java
@@ -39,13 +39,19 @@
import android.support.v2.os.Build;
import android.util.Log;
import android.view.Menu;
+import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
+import android.view.View.OnLongClickListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.LinearLayout;
+import android.widget.SeekBar;
+import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;
+import android.widget.Toast;
+
import java.util.Random;
public class Flashlight extends DistributionLibraryActivity {
@@ -54,10 +60,10 @@
private static final boolean debug = true;
private static final int MENU_COLOR = Menu.FIRST + 1;
- private static final int MENU_SETTINGS = Menu.FIRST + 4;
- private static final int MENU_DISTRIBUTION_START = Menu.FIRST + 100; // MUST BE LAST
-
-
+ private static final int MENU_SETTINGS = Menu.FIRST + 4;
+ private static final int MENU_DISTRIBUTION_START = Menu.FIRST + 100; // MUST
+ // BE
+ // LAST
private static final int REQUEST_CODE_PICK_COLOR = 1;
@@ -65,10 +71,14 @@
private static final int DIALOG_COLORPICKER_DOWNLOAD = 2;
private static final int DIALOG_DISTRIBUTION_START = 100; // MUST BE LAST
-
private LinearLayout mBackground;
private View mIcon;
private TextView mText;
+ private boolean mWait = false;
+ private boolean incR = true, incB = true, incG = true;
+ private String mfreq;
+ private int intFreq;
+ private int i = 1, fRed, fBlue, fGreen;
private PowerManager.WakeLock mWakeLock;
private boolean mWakeLockLocked = false;
@@ -81,6 +91,7 @@
private static int mTimeout = 5000;
private Brightness mBrightness;
+ private SeekBar mSeekBar;
private static boolean mOldClassAvailable;
private static boolean mNewClassAvailable;
@@ -120,7 +131,8 @@ public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.v(TAG, "onCreate Called");
- mDistribution.setFirst(MENU_DISTRIBUTION_START, DIALOG_DISTRIBUTION_START);
+ mDistribution.setFirst(MENU_DISTRIBUTION_START,
+ DIALOG_DISTRIBUTION_START);
// Check whether EULA has been accepted
// or information about new version can be presented.
@@ -129,50 +141,94 @@ public void onCreate(Bundle savedInstanceState) {
}
// Turn off the title bar
- if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB)
- {
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
// Remove title in Android versions without ActionBar.
- // (Starting from HONEYCOMB, keep the title so that
- // the action bar remains accessible.)
+ // (Starting from HONEYCOMB, keep the title so that
+ // the action bar remains accessible.)
requestWindowFeature(Window.FEATURE_NO_TITLE);
}
setContentView(R.layout.main);
-
mBackground = (LinearLayout) findViewById(R.id.background);
mIcon = (View) findViewById(R.id.icon);
mText = (TextView) findViewById(R.id.text);
-
+ mSeekBar = (SeekBar) findViewById(R.id.seekBar1);
+ mSeekBar.setMax(65);
mBackground.setOnTouchListener(new View.OnTouchListener() {
-
public boolean onTouch(View arg0, MotionEvent arg1) {
- if (mUseCameraFlash){
- lightsOnOff();
- } else {
- if (mIcon.getVisibility() == View.VISIBLE) {
- hideIcon();
+ SharedPreferences prefs = PreferenceManager
+ .getDefaultSharedPreferences(Flashlight.this);
+ if (!(prefs.getString(FlashlightPrefs.PREFKEY_COLOR_OPTIONS,
+ FlashlightPrefs.DEFAULT_COLOR_OPTIONS)).equals("1")) {
+
+ if (mUseCameraFlash) {
+ lightsOnOff();
} else {
- showIconForAWhile();
+ if (mIcon.getVisibility() == View.VISIBLE) {
+ hideIcon();
+ } else {
+ showIconForAWhile();
+ }
}
+ } else {
+ mIcon.setVisibility(View.VISIBLE);
+ mText.setVisibility(View.VISIBLE);
}
return false;
}
+ });
+
+ mBackground.setOnLongClickListener(new OnLongClickListener() {
+
+ public boolean onLongClick(View v) {
+ SharedPreferences prefs = PreferenceManager
+ .getDefaultSharedPreferences(Flashlight.this);
+ if ((prefs.getString(FlashlightPrefs.PREFKEY_COLOR_OPTIONS,
+ FlashlightPrefs.DEFAULT_COLOR_OPTIONS)).equals("1")) {
+ if (mWait != true) {
+ mHandler.removeCallbacks(mUpdateBackground);
+ mWait = true;
+ } else {
+ mHandler.removeCallbacks(mUpdateBackground);
+ mHandler.postDelayed(mUpdateBackground, 1000);
+ mWait = false;
+ }
+ }
+ return false;
+ }
});
+ mSeekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
+
+ public void onStopTrackingTouch(SeekBar seekBar) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void onStartTrackingTouch(SeekBar seekBar) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void onProgressChanged(SeekBar seekBar, int progress,
+ boolean fromUser) {
+ mBrightness.setBrightness((float) (progress * 0.015));
+ Toast.makeText(Flashlight.this, ""+progress,
+ Toast.LENGTH_SHORT).show();
+ }
+ });
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
- //mWakeLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK
+ // mWakeLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK
mWakeLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK
| PowerManager.ACQUIRE_CAUSES_WAKEUP
- | PowerManager.ON_AFTER_RELEASE,
- "Flashlight");
-
+ | PowerManager.ON_AFTER_RELEASE, "Flashlight");
- if (mNewClassAvailable) {
+ if (mNewClassAvailable) {
Log.d(TAG, "Using SDK 1.5 brightness adjustment");
mBrightness = new BrightnessNew(this);
} else if (mOldClassAvailable) {
@@ -195,29 +251,39 @@ public boolean onTouch(View arg0, MotionEvent arg1) {
mCameraFlash = new CameraFlash();
}
}
-
- private void resetMainScreen(){
- SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
- if (prefs.getBoolean(FlashlightPrefs.PREFKEY_USE_CAMERA_FLASH, FlashlightPrefs.DEFAULT_USE_CAMERA_FLASH)){
+
+ private void resetMainScreen() {
+ SharedPreferences prefs = PreferenceManager
+ .getDefaultSharedPreferences(this);
+ if (prefs.getBoolean(FlashlightPrefs.PREFKEY_USE_CAMERA_FLASH,
+ FlashlightPrefs.DEFAULT_USE_CAMERA_FLASH)) {
mColor = Color.BLACK;
mUseCameraFlash = true;
Log.v(TAG, "Use Camera!");
} else {
mUseCameraFlash = false;
Log.v(TAG, "Don't use camera!");
- String pref = prefs.getString(FlashlightPrefs.PREFKEY_COLOR_OPTIONS, FlashlightPrefs.DEFAULT_COLOR_OPTIONS);
+ String pref = prefs.getString(
+ FlashlightPrefs.PREFKEY_COLOR_OPTIONS,
+ FlashlightPrefs.DEFAULT_COLOR_OPTIONS);
if (pref.equals("0")) {
- mColor = prefs.getInt(FlashlightPrefs.PREFKEY_SAVED_COLOR, Color.WHITE);
- }
- else if (pref.equals("1")){
+ mColor = prefs.getInt(FlashlightPrefs.PREFKEY_SAVED_COLOR,
+ Color.WHITE);
+ } else if (pref.equals("1")) {
+ mfreq = prefs.getString(FlashlightPrefs.PREF_COLOR_FREQ,
+ FlashlightPrefs.DEFAULT_PREF_COLOR_FREQ);
+ if (!(mfreq.equals("")))
+ intFreq = Integer.parseInt(mfreq);
+ else
+ intFreq = 200;
+
mHandler.removeCallbacks(mUpdateBackground);
- mHandler.postDelayed(mUpdateBackground,1000);
- }
- else if (pref.equals("2")){
+ mHandler.postDelayed(mUpdateBackground, 1000);
+ } else if (pref.equals("2")) {
mColor = Color.WHITE;
}
}
- if (mUseCameraFlash){
+ if (mUseCameraFlash) {
mText.setText(R.string.cameralight_info);
showIcon();
} else {
@@ -225,18 +291,64 @@ else if (pref.equals("2")){
showIconForAWhile();
}
mBackground.setBackgroundColor(mColor);
-
+
}
-
- private Runnable mUpdateBackground = new Runnable(){
+
+ private Runnable mUpdateBackground = new Runnable() {
public void run() {
- int color;
- Random rnd = new Random();
- color = Color.argb(255, rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256));
- mBackground.setBackgroundColor(color);
- mHandler.postDelayed(this,2000);
+ int color;
+ Random rnd = new Random();
+ // Changes the value slowly by deciding whether to increase or
+ // decrease
+ if (fRed < 0) {
+ incR = true;
+ } else if (fRed > 255)
+ incR = false;
+
+ if (incR)
+ fRed = (fRed + rnd.nextInt(10));
+ else
+ fRed = (fRed - rnd.nextInt(10));
+
+ if (fBlue < 0)
+ incB = true;
+ else if (fBlue > 255)
+ incB = false;
+
+ if (incB)
+ fBlue = (fBlue + rnd.nextInt(5));
+ else
+ fBlue = (fBlue - rnd.nextInt(5));
+
+ if (fGreen > 255)
+ incG = false;
+ else if (fGreen < 0) {
+ incG = true;
+ }
+
+ if (incG)
+ fGreen = (fGreen + rnd.nextInt(8));
+ else
+ fGreen = (fGreen - rnd.nextInt(8));
+
+ SharedPreferences sp = PreferenceManager
+ .getDefaultSharedPreferences(Flashlight.this);
+ mfreq = sp.getString(FlashlightPrefs.PREF_COLOR_FREQ,
+ FlashlightPrefs.DEFAULT_PREF_COLOR_FREQ);
+ if (!(mfreq.equals("")))
+ intFreq = Integer.parseInt(mfreq);
+ else
+ intFreq = 200;
+
+ // TransitionDrawable transition = (TransitionDrawable)
+ // mBackground.getBackground();
+ // transition.startTransition(5000);
+ // if(i == 1)
+ color = Color.argb(255, fRed, fGreen, fBlue);
+ mBackground.setBackgroundColor(color);
+ mHandler.postDelayed(this, intFreq);
}
- };
+ };
private void lightsOnOff() {
if (mCameraFlash != null) {
@@ -249,7 +361,7 @@ private void lightsOnOff() {
showIcon();
}
- private void lightsOn(){
+ private void lightsOn() {
if (mCameraFlash != null) {
mCameraFlash.lightsOn();
}
@@ -257,7 +369,7 @@ private void lightsOn(){
mText.setText(R.string.cameralight_stop_info);
}
- private void lightsOff(){
+ private void lightsOff() {
if (mCameraFlash != null) {
mCameraFlash.lightsOff();
}
@@ -265,7 +377,6 @@ private void lightsOff(){
mText.setText(R.string.cameralight_info);
}
-
class FlashlightState {
int mColor;
}
@@ -277,7 +388,6 @@ public Object onRetainNonConfigurationInstance() {
return state;
}
-
@Override
protected void onResume() {
super.onResume();
@@ -296,7 +406,8 @@ protected void onPause() {
protected void onStart() {
super.onStart();
- IntentFilter i = new IntentFilter(FlashlightIntents.ACTION_SET_FLASHLIGHT);
+ IntentFilter i = new IntentFilter(
+ FlashlightIntents.ACTION_SET_FLASHLIGHT);
registerReceiver(mReceiver, i);
}
@@ -307,23 +418,27 @@ protected void onStop() {
unregisterReceiver(mReceiver);
}
- /////////////////////////////////////////////////////
+ // ///////////////////////////////////////////////////
// Menu
-
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
- menu.add(0, MENU_COLOR, 0,R.string.color)
- .setIcon(android.R.drawable.ic_menu_manage).setShortcut('3', 'c');
+ menu.add(0, MENU_COLOR, 0, R.string.color)
+ .setIcon(android.R.drawable.ic_menu_manage)
+ .setShortcut('3', 'c');
- menu.add(0, MENU_SETTINGS, 0,R.string.preferences)
- .setIcon(android.R.drawable.ic_menu_preferences).setShortcut('4', 'p');
+ menu.add(0, MENU_SETTINGS, 0, R.string.preferences)
+ .setIcon(android.R.drawable.ic_menu_preferences)
+ .setShortcut('4', 'p');
// Add distribution menu items last.
mDistribution.onCreateOptionsMenu(menu);
-
+ if (Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB) {
+ MenuInflater mi = getMenuInflater();
+ mi.inflate(R.menu.menu, menu);
+ }
return true;
}
@@ -337,13 +452,17 @@ public boolean onPrepareOptionsMenu(Menu menu) {
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
- case MENU_COLOR:
- pickColor();
- return true;
+ case MENU_COLOR:
+ pickColor();
+ return true;
- case MENU_SETTINGS:
- showSettingsMenu();
- return true;
+ case MENU_SETTINGS:
+ showSettingsMenu();
+ return true;
+
+ case R.id.item1:
+ showSettingsMenu();
+ return true;
}
return super.onOptionsItemSelected(item);
@@ -355,14 +474,13 @@ protected Dialog onCreateDialog(int id) {
Log.d(TAG, "Called onCreateDialog()");
switch (id) {
- case DIALOG_ABOUT:
- return new AboutDialog(this);
- case DIALOG_COLORPICKER_DOWNLOAD:
- return new DownloadAppDialog(this,
- R.string.color_picker_modularization_explanation,
- R.string.color_picker,
- R.string.color_picker_package,
- R.string.color_picker_website);
+ case DIALOG_ABOUT:
+ return new AboutDialog(this);
+ case DIALOG_COLORPICKER_DOWNLOAD:
+ return new DownloadAppDialog(this,
+ R.string.color_picker_modularization_explanation,
+ R.string.color_picker, R.string.color_picker_package,
+ R.string.color_picker_website);
}
return super.onCreateDialog(id);
}
@@ -374,18 +492,16 @@ protected void onPrepareDialog(int id, final Dialog dialog) {
Log.d(TAG, "Called onPrepareDialog()");
switch (id) {
- case DIALOG_COLORPICKER_DOWNLOAD:
- {
- DownloadAppDialog.onPrepareDialog(this, dialog);
- break;
- }
- default:
- break;
+ case DIALOG_COLORPICKER_DOWNLOAD: {
+ DownloadAppDialog.onPrepareDialog(this, dialog);
+ break;
+ }
+ default:
+ break;
}
}
-
- /////////////////////////////////////////////////////
+ // ///////////////////////////////////////////////////
// Other functions
private void wakeLock() {
@@ -394,9 +510,10 @@ private void wakeLock() {
mWakeLock.acquire();
mWakeLockLocked = true;
- //android 1.5 magic number meaning "full brightness"
+ // android 1.5 magic number meaning "full brightness"
mBrightness.setBrightness(1f);
- //Log.d(TAG,"brightness>"+Settings.System.getInt(getContentResolver(), Settings.System.SCREEN_BRIGHTNESS, NOT_VALID));
+ // Log.d(TAG,"brightness>"+Settings.System.getInt(getContentResolver(),
+ // Settings.System.SCREEN_BRIGHTNESS, NOT_VALID));
}
}
@@ -407,7 +524,7 @@ private void wakeUnlock() {
mWakeLock.release();
mWakeLockLocked = false;
- //android 1.5 magic number meaning "default/user brightness"
+ // android 1.5 magic number meaning "default/user brightness"
mBrightness.setBrightness(-1f);
}
}
@@ -423,11 +540,13 @@ private void pickColor() {
if (IntentUtils.isIntentAvailable(this, i)) {
startActivityForResult(i, REQUEST_CODE_PICK_COLOR);
-
+
} else {
showDialog(DIALOG_COLORPICKER_DOWNLOAD);
}
- // IntentUtils.intentLaunchWithMarketFallback(this, i, REQUEST_CODE_PICK_COLOR, FlashlightIntents.PACKAGE_NAME_COLOR_PICKER);
+ // IntentUtils.intentLaunchWithMarketFallback(this, i,
+ // REQUEST_CODE_PICK_COLOR,
+ // FlashlightIntents.PACKAGE_NAME_COLOR_PICKER);
}
/**
@@ -439,48 +558,58 @@ private void pickColor() {
public void onReceive(Context context, Intent intent) {
if (intent != null) {
if (intent.hasExtra(FlashlightIntents.EXTRA_COLOR)) {
- mColor = intent.getIntExtra(FlashlightIntents.EXTRA_COLOR, mColor);
+ mColor = intent.getIntExtra(FlashlightIntents.EXTRA_COLOR,
+ mColor);
mBackground.setBackgroundColor(mColor);
- if (debug) Log.d(TAG, "Receive color " + mColor);
+ if (debug)
+ Log.d(TAG, "Receive color " + mColor);
}
if (intent.hasExtra(FlashlightIntents.EXTRA_BRIGHTNESS)) {
- float brightness = intent.getFloatExtra(FlashlightIntents.EXTRA_BRIGHTNESS, 1f);
+ float brightness = intent.getFloatExtra(
+ FlashlightIntents.EXTRA_BRIGHTNESS, 1f);
mBrightness.setBrightness(brightness);
- if (debug) Log.d(TAG, "Receive brightness " + mBrightness);
+ if (debug)
+ Log.d(TAG, "Receive brightness " + mBrightness);
}
}
}
};
- /////////////////////////////////////////////////////
+ // ///////////////////////////////////////////////////
// Color changed listener:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
- switch(requestCode) {
- case REQUEST_CODE_PICK_COLOR:
- if (resultCode == RESULT_OK) {
- mColor = data.getIntExtra(FlashlightIntents.EXTRA_COLOR, mColor);
-
- SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
- Editor edit = prefs.edit();
- edit.putString("color_options", "0");
- edit.apply();
- String pref = prefs.getString(FlashlightPrefs.PREFKEY_COLOR_OPTIONS, FlashlightPrefs.DEFAULT_COLOR_OPTIONS);
-
- if ( pref.equals("0") ) {
- prefs.edit().putInt(FlashlightPrefs.PREFKEY_SAVED_COLOR, mColor).commit();
- }
- mBackground.setBackgroundColor(mColor);
+ switch (requestCode) {
+ case REQUEST_CODE_PICK_COLOR:
+ if (resultCode == RESULT_OK) {
+ mColor = data
+ .getIntExtra(FlashlightIntents.EXTRA_COLOR, mColor);
+
+ SharedPreferences prefs = PreferenceManager
+ .getDefaultSharedPreferences(this);
+ Editor edit = prefs.edit();
+ edit.putString("color_options", "0");
+ edit.apply();
+ String pref = prefs.getString(
+ FlashlightPrefs.PREFKEY_COLOR_OPTIONS,
+ FlashlightPrefs.DEFAULT_COLOR_OPTIONS);
+
+ if (pref.equals("0")) {
+ prefs.edit()
+ .putInt(FlashlightPrefs.PREFKEY_SAVED_COLOR, mColor)
+ .commit();
}
- break;
+ mBackground.setBackgroundColor(mColor);
+ }
+ break;
}
}
-
- ////////////////////
+
+ // //////////////////
// Handler
Handler mHandler = new Handler() {
@@ -499,13 +628,11 @@ private void hideIcon() {
mIcon.setVisibility(View.GONE);
mText.setVisibility(View.GONE);
-
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
-
- private void showIcon(){
+ private void showIcon() {
mIcon.setVisibility(View.VISIBLE);
mText.setVisibility(View.VISIBLE);
View
14 Flashlight/src/org/openintents/flashlight/FlashlightPrefs.java
@@ -5,15 +5,15 @@
public class FlashlightPrefs extends PreferenceActivity {
- public static final String PREFKEY_SAVED_COLOR = "saved_color";
-
public static final String PREFKEY_USE_CAMERA_FLASH = "use_camera_flash";
- public static final String PREFKEY_COLOR_OPTIONS = "color_options";
+ public static final String PREFKEY_COLOR_OPTIONS = "color_options";
-
- public static final boolean DEFAULT_USE_CAMERA_FLASH = false;
- public static final String DEFAULT_COLOR_OPTIONS = "0";
-
+ public static final String PREF_COLOR_FREQ = "set_time";
+
+ public static final boolean DEFAULT_USE_CAMERA_FLASH = false;
+ public static final String DEFAULT_COLOR_OPTIONS = "0";
+ public static final String DEFAULT_PREF_COLOR_FREQ = "200";
+ public static final String PREFKEY_SAVED_COLOR = "color";
// ========================================================================
@Override
View
32 Flashlight/src/org/openintents/flashlight/Widget.java
@@ -0,0 +1,32 @@
+package org.openintents.flashlight;
+
+import android.app.PendingIntent;
+import android.appwidget.AppWidgetManager;
+import android.appwidget.AppWidgetProvider;
+import android.content.Context;
+import android.content.Intent;
+import android.widget.RemoteViews;
+
+public class Widget extends AppWidgetProvider {
+
+ @Override
+ public void onUpdate(Context context, AppWidgetManager appWidgetManager,
+ int[] appWidgetIds) {
+ // TODO Auto-generated method stub
+ super.onUpdate(context, appWidgetManager, appWidgetIds);
+ for (int i = 0; i < appWidgetIds.length; i++) {
+ int appWidgetId = appWidgetIds[i];
+
+ Intent intent = new Intent(context, WidgetService.class);
+ PendingIntent pendingIntent = PendingIntent.getService(context, 0,
+ intent, 0);
+
+ RemoteViews views = new RemoteViews(context.getPackageName(),
+ R.layout.widget_layout);
+ views.setOnClickPendingIntent(R.id.imageView1, pendingIntent);
+
+ appWidgetManager.updateAppWidget(appWidgetId, views);
+
+ }
+ }
+}
View
55 Flashlight/src/org/openintents/flashlight/WidgetService.java
@@ -0,0 +1,55 @@
+package org.openintents.flashlight;
+
+import android.app.Service;
+import android.content.Intent;
+import android.hardware.Camera;
+import android.os.IBinder;
+import android.widget.Toast;
+
+public class WidgetService extends Service{
+
+ private Camera mCamera;
+ private boolean isOn = false;
+ @Override
+ public void onCreate() {
+ // TODO Auto-generated method stub
+ super.onCreate();
+ Toast.makeText(this, "Created", Toast.LENGTH_SHORT).show();
+ }
+
+ @Override
+ public void onStart(Intent intent, int startId) {
+ // TODO Auto-generated method stub
+ super.onStart(intent, startId);
+ if(!isOn){
+ mCamera = Camera.open();
+ if(mCamera != null){
+ Toast.makeText(this, "Turning On", Toast.LENGTH_SHORT).show();
+ Camera.Parameters params = mCamera.getParameters();
+ params.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
+ mCamera.setParameters(params);
+ isOn = true;
+ }
+ }else{
+ Toast.makeText(this, "Turning off", Toast.LENGTH_SHORT).show();
+ mCamera.release();
+ mCamera = null;
+ isOn = false;
+ stopSelf();
+ }
+ }
+
+ @Override
+ public void onDestroy() {
+ // TODO Auto-generated method stub
+ Toast.makeText(this, "Destroy", Toast.LENGTH_SHORT).show();
+ super.onDestroy();
+ }
+
+ @Override
+ public IBinder onBind(Intent intent) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
Something went wrong with that request. Please try again.