Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Hacktoberfest] Code refactor #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions mobile/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -76,26 +76,25 @@ dependencies {
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})

wearApp project(path: ':wear', configuration: 'wear1Release')
compile 'com.google.android.gms:play-services-wearable:11.0.4'
provided 'com.google.android.wearable:wearable:2.0.4'
compile 'com.google.android.support:wearable:2.0.4'

compile 'com.android.support:appcompat-v7:26.0.0'
compile 'com.android.support:design:26.0.0'
compile 'com.android.support:cardview-v7:26.0.0'
compile 'com.android.support:preference-v7:26.0.0'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.jakewharton:butterknife:8.5.1'
compile 'net.frakbot:glowpadbackport:2.1.1'
compile ('com.afollestad.material-dialogs:core:0.9.4.5') {
compile('com.afollestad.material-dialogs:core:0.9.4.5') {
exclude group: 'com.android.support'
}
compile 'com.google.code.gson:gson:2.8.0'
testCompile 'junit:junit:4.12'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.5.1'
compile('com.crashlytics.sdk.android:crashlytics:2.6.8@aar') {
transitive = true;
transitive = true
}
compile project(':utils')
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

import android.app.Application;
import android.os.StrictMode;
import com.crashlytics.android.Crashlytics;

import com.crashlytics.android.answers.Answers;
import com.crashlytics.android.Crashlytics;
import com.crashlytics.android.core.CrashlyticsCore;

import io.fabric.sdk.android.Fabric;
Expand All @@ -15,15 +14,17 @@

public class ExcuserApplication extends Application {

public static final String TAG = ExcuserApplication.class.getSimpleName();
private static ExcuserApplication instance;

private static ExcuserApplication _instance;
public static ExcuserApplication getInstance() {
return instance;
}

@Override
public void onCreate() {
super.onCreate();

_instance = this;
instance = this;

//Crashlytics, disabled for debug builds
Crashlytics crashlytics = new Crashlytics.Builder()
Expand All @@ -49,10 +50,6 @@ public void onCreate() {
}
}

public static ExcuserApplication getInstance() {
return _instance;
}

public String getAppPackageName() {
return getPackageName();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public void playRingtone() {
mPlayer.setAudioStreamType(AudioManager.STREAM_RING);

try {
if(hasSIM())
if (hasSIM())
mPlayer.setDataSource(mContext, RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE));
else
mPlayer.setDataSource(mContext, RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM));
Expand All @@ -47,7 +47,7 @@ public void playRingtone() {
break;
case AudioManager.RINGER_MODE_VIBRATE:
mVibrator = (Vibrator) mContext.getSystemService(Context.VIBRATOR_SERVICE);
if(mVibrator.hasVibrator()) {
if (mVibrator.hasVibrator()) {
long[] pattern = {0, 500, 200};

// The '0' here means to repeat indefinitely
Expand All @@ -66,7 +66,7 @@ public void stopRingtone() {
mPlayer = null;
}

if(mVibrator!=null){
if (mVibrator != null) {
mVibrator.cancel();
}
}
Expand Down Expand Up @@ -98,7 +98,7 @@ public void stopProgressTone() {
}
}

private boolean hasSIM(){
private boolean hasSIM() {
TelephonyManager manager = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
return manager.getPhoneType() != TelephonyManager.PHONE_TYPE_NONE;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
public class BaseActivity extends AppCompatActivity {

@BindView(R.id.toolbar)
Toolbar toolbar;
protected Toolbar toolbar;

@BindView(R.id.coordinatorLayout)
CoordinatorLayout coordinatorLayout;
protected CoordinatorLayout coordinatorLayout;

@Override
public void setContentView(int layoutResID) {
Expand Down Expand Up @@ -92,12 +92,12 @@ protected boolean isDisplayHomeAsUpEnabled() {
}

public void setDisplayHomeAsUpEnabled(boolean value) {
if(getSupportActionBar()!=null)
if (getSupportActionBar() != null)
getSupportActionBar().setDisplayHomeAsUpEnabled(value);
}

public void setHomeAsUpIndicator(Drawable drawable) {
if(getSupportActionBar()!=null)
if (getSupportActionBar() != null)
getSupportActionBar().setHomeAsUpIndicator(drawable);
}

Expand All @@ -115,7 +115,7 @@ public void showSnackBar(String value) {
.make(getCoordinatorLayout(), value, Snackbar.LENGTH_LONG);

View sbView = snackbar.getView();
TextView textView = (TextView) sbView.findViewById(android.support.design.R.id.snackbar_text);
TextView textView = sbView.findViewById(android.support.design.R.id.snackbar_text);
textView.setTextColor(ContextCompat.getColor(this, R.color.colorAccent));
snackbar.show();
}
Expand All @@ -125,7 +125,7 @@ public void showSnackBar(int value) {
.make(getCoordinatorLayout(), value, Snackbar.LENGTH_LONG);

View sbView = snackbar.getView();
TextView textView = (TextView) sbView.findViewById(android.support.design.R.id.snackbar_text);
TextView textView = sbView.findViewById(android.support.design.R.id.snackbar_text);
textView.setTextColor(ContextCompat.getColor(this, R.color.colorAccent));
snackbar.show();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,56 +24,40 @@

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
* Created by Vipul on 02/05/17.
*/

public class IncomingCallActivity extends BaseActivity {

private AudioPlayer mAudioPlayer;

@BindView(R.id.text_caller_name)
TextView mCallerName;

protected TextView mCallerName;
@BindView(R.id.text_caller_phone)
TextView mCallerPhone;

protected TextView mCallerPhone;
@BindView(R.id.text_call_duration)
TextView mCallDuration;

protected TextView mCallDuration;
@BindView(R.id.button_call_end)
FloatingActionButton mCallButton;

protected FloatingActionButton mCallButton;
@BindView(R.id.incomingCallWidget)
GlowPadView mGlowPadView;
protected GlowPadView mGlowPadView;

private AudioPlayer mAudioPlayer;
private Timer mTimer;
private UpdateCallDurationTask mDurationTask;
private CountDownTimer mActivityTimeout;
private long mCallStart = 0;

private class UpdateCallDurationTask extends TimerTask {
@Override
public void run() {
IncomingCallActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
updateCallDuration();
}
});
}
}

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_incoming_call);
StatusBarUtil.setColor(this, ContextCompat.getColor(this, R.color.colorIncomingCallDark));

getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON|
WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD|
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED|
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON |
WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD |
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);

ButterKnife.bind(this);
Expand All @@ -86,19 +70,19 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
startActivityTimeout();
}

private void initView(){
private void initView() {

mCallButton.hide();
initTimer();

if (LocalStoreUtils.getContacts(this)!=null && LocalStoreUtils.getContacts(this).size()>0) {
if (LocalStoreUtils.getContacts(this) != null && LocalStoreUtils.getContacts(this).size() > 0) {

Random r = new Random();
int randomId = r.nextInt(LocalStoreUtils.getContacts(this).size());

Contact contact = LocalStoreUtils.getContacts(this).get(randomId);

if(contact.getName().isEmpty()) {
if (contact.getName().isEmpty()) {
mCallerName.setText(contact.getMobile());
mCallerPhone.setVisibility(View.GONE);
} else {
Expand All @@ -125,9 +109,9 @@ public void onReleased(View v, int handle) {

@Override
public void onTrigger(View v, int target) {
Log.e("target id", "->"+target);
Log.e("target id", "->" + target);

if(target==0) { //accept
if (target == 0) { //accept
onCallAccept();
} else { //decline
endActivity();
Expand All @@ -144,54 +128,52 @@ public void onFinishFinalAnimation() {
// Do nothing
}
});
}

mCallButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
endActivity();
}
});
@OnClick(R.id.button_call_end)
protected void onCallEndClick() {
endActivity();
}

private void initTimer(){
private void initTimer() {
mTimer = new Timer();
mDurationTask = new UpdateCallDurationTask();
}

private void startTimer(){
private void startTimer() {
mCallStart = System.currentTimeMillis();
mTimer.schedule(mDurationTask, 0, 500);
}

private void stopTimer(){
if(mDurationTask!=null)
private void stopTimer() {
if (mDurationTask != null)
mDurationTask.cancel();

if(mTimer!=null)
if (mTimer != null)
mTimer.cancel();
}

private void onCallAccept(){
private void onCallAccept() {
mAudioPlayer.stopRingtone();
mGlowPadView.setVisibility(View.GONE);
mCallButton.show();
startTimer();
mActivityTimeout.cancel();
}

private void onCallReject(){
private void onCallReject() {
}

private void endActivity(){
if(mAudioPlayer!=null)
private void endActivity() {
if (mAudioPlayer != null)
mAudioPlayer.stopRingtone();

mActivityTimeout.cancel();

android.os.Process.killProcess(android.os.Process.myPid()); //completely destroy app instance
}

private void startActivityTimeout(){
private void startActivityTimeout() {
mActivityTimeout = new CountDownTimer(30000, 100) {
@Override
public void onTick(long millisUntilFinished) {
Expand All @@ -202,29 +184,40 @@ public void onTick(long millisUntilFinished) {
public void onFinish() {
endActivity();
}
}
.start();
}.start();
}

private String formatTimespan(long timespan) {
private String formatTimeSpan(long timespan) {
long totalSeconds = timespan / 1000;
long minutes = totalSeconds / 60;
long seconds = totalSeconds % 60;
return String.format(Locale.US, "%02d:%02d", minutes, seconds);
}

private void updateCallDuration() {
if(mCallStart>0) {
mCallDuration.setText(formatTimespan(System.currentTimeMillis() - mCallStart));
if (mCallStart > 0) {
mCallDuration.setText(formatTimeSpan(System.currentTimeMillis() - mCallStart));
}
}

@Override
protected void onStop() {
super.onStop();
if(mAudioPlayer!=null)
if (mAudioPlayer != null)
mAudioPlayer.stopRingtone();

stopTimer();
}

private class UpdateCallDurationTask extends TimerTask {
@Override
public void run() {
IncomingCallActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
updateCallDuration();
}
});
}
}
}
Loading