-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: EmergencySignal with blinking background and a sound
fix: delete deprecated refactor: minor changes throughout the code update: gradle with instant start design: colors change
- Loading branch information
1 parent
eee3c80
commit bfb3fe4
Showing
21 changed files
with
353 additions
and
194 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 0 additions & 13 deletions
13
app/src/androidTest/java/com/adkdevelopment/simpleflashlightadfree/ApplicationTest.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
153 changes: 153 additions & 0 deletions
153
app/src/main/java/com/adkdevelopment/simpleflashlightadfree/EmergencyFragment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
package com.adkdevelopment.simpleflashlightadfree; | ||
|
||
import android.content.Intent; | ||
import android.content.res.AssetFileDescriptor; | ||
import android.graphics.Color; | ||
import android.graphics.drawable.AnimationDrawable; | ||
import android.graphics.drawable.ColorDrawable; | ||
import android.media.MediaPlayer; | ||
import android.os.Bundle; | ||
import android.os.Handler; | ||
import android.support.annotation.Nullable; | ||
import android.support.v4.content.ContextCompat; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.ImageView; | ||
import android.widget.LinearLayout; | ||
import android.widget.TextView; | ||
|
||
import butterknife.Bind; | ||
import butterknife.ButterKnife; | ||
|
||
/** | ||
* Created by karataev on 2/22/16. | ||
*/ | ||
public class EmergencyFragment extends android.support.v4.app.Fragment { | ||
|
||
private static final String TAG = EmergencyFragment.class.getSimpleName(); | ||
|
||
private int status; | ||
MediaPlayer mMediaPlayer; | ||
|
||
@Bind(R.id.button_image) ImageView mButtonImage; | ||
@Bind(R.id.flashlight_mode) TextView mStatusText; | ||
@Bind(R.id.layout) LinearLayout mLinearLayout; | ||
|
||
public EmergencyFragment() {} | ||
|
||
@Override | ||
public void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
|
||
if (savedInstanceState != null) { | ||
status = savedInstanceState.getInt(FlashlightService.STATUS); | ||
|
||
if (status != FlashlightService.STATUS_OFF) { | ||
Intent intent = new Intent(getActivity().getApplication(), FlashlightService.class); | ||
intent.putExtra(FlashlightService.STATUS, status); | ||
getActivity().getApplication().startService(intent); | ||
} | ||
} else { | ||
status = FlashlightService.STATUS_OFF; | ||
} | ||
|
||
} | ||
|
||
@Nullable | ||
@Override | ||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { | ||
|
||
View rootView = inflater.inflate(R.layout.fragment_main, container, false); | ||
|
||
ButterKnife.bind(this, rootView); | ||
|
||
// check status and use correct image | ||
Utility.setSwitchColor(mStatusText, mButtonImage, status); | ||
|
||
mButtonImage.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
// Start service on click | ||
if (status == FlashlightService.STATUS_OFF) { | ||
status = FlashlightService.STATUS_BLINK; | ||
} else { | ||
status = FlashlightService.STATUS_OFF; | ||
} | ||
|
||
emergencySignal(); | ||
|
||
Intent intent = new Intent(getActivity().getApplication(), FlashlightService.class); | ||
|
||
// Set button drawable | ||
Utility.setSwitchColor(mStatusText, mButtonImage, status); | ||
|
||
intent.putExtra(FlashlightService.STATUS, status); | ||
getActivity().getApplication().startService(intent); | ||
} | ||
}); | ||
|
||
return rootView; | ||
} | ||
|
||
@Override | ||
public void onDestroy() { | ||
super.onDestroy(); | ||
|
||
|
||
} | ||
|
||
@Override | ||
public void onSaveInstanceState(Bundle outState) { | ||
super.onSaveInstanceState(outState); | ||
|
||
// Save status on rotate, possibly will remove rotation in the future | ||
outState.putInt(FlashlightService.STATUS, status); | ||
} | ||
|
||
/** | ||
* Starts emergency sound from assets | ||
*/ | ||
public void emergencySignal() { | ||
|
||
try { | ||
if (mMediaPlayer != null && mMediaPlayer.isPlaying() && status == FlashlightService.STATUS_OFF) { | ||
mMediaPlayer.stop(); | ||
mMediaPlayer.reset(); | ||
mMediaPlayer.release(); | ||
mMediaPlayer = null; | ||
|
||
mLinearLayout.setBackgroundColor(ContextCompat.getColor(getContext(), R.color.colorBackground)); | ||
} else if (status == FlashlightService.STATUS_BLINK) { | ||
|
||
final AnimationDrawable drawable = new AnimationDrawable(); | ||
final Handler handler = new Handler(); | ||
|
||
drawable.addFrame(new ColorDrawable(Color.RED), 400); | ||
drawable.addFrame(new ColorDrawable(Color.BLUE), 400); | ||
drawable.setOneShot(false); | ||
|
||
mLinearLayout.setBackground(drawable); | ||
handler.postDelayed(new Runnable() { | ||
@Override | ||
public void run() { | ||
drawable.start(); | ||
} | ||
}, 100); | ||
|
||
mMediaPlayer = new MediaPlayer(); | ||
AssetFileDescriptor descriptor = getActivity().getAssets().openFd("sews.mp3"); | ||
mMediaPlayer.setDataSource(descriptor.getFileDescriptor(), descriptor.getStartOffset(), descriptor.getLength()); | ||
descriptor.close(); | ||
|
||
mMediaPlayer.prepare(); | ||
mMediaPlayer.setVolume(1f, 1f); | ||
mMediaPlayer.setLooping(true); | ||
mMediaPlayer.start(); | ||
} | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.