From 96d9981e3bd5547974bac5065f5bcfeb03389bea Mon Sep 17 00:00:00 2001 From: antoxa2584 Date: Mon, 9 Oct 2017 00:15:04 +0300 Subject: [PATCH] Code refactor --- mobile/build.gradle | 7 +- .../excuser/ExcuserApplication.java | 15 +- .../excuser/activity/AudioPlayer.java | 8 +- .../excuser/activity/BaseActivity.java | 12 +- .../activity/IncomingCallActivity.java | 99 ++++++------ .../excuser/activity/SplashActivity.java | 10 +- .../activity/home/AddContactDialog.java | 28 ++-- .../excuser/activity/home/ContactAdapter.java | 44 +++--- .../excuser/activity/home/MainActivity.java | 67 ++++---- .../DeviceWearConnectionFragment.java | 144 ++++++++---------- .../onboarding/OnboardingActivity.java | 5 - .../onboarding/WearShakeDemoFragment.java | 7 +- .../WearShakeIntensityFragment.java | 51 +++---- .../activity/settings/SettingsActivity.java | 50 +++--- .../com/squareboat/excuser/model/Contact.java | 9 +- .../service/DataLayerListenerService.java | 4 +- .../excuser/utils/LocalStoreUtils.java | 29 ++-- .../excuser/utils/StatusBarUtil.java | 6 +- .../excuser/widget/SpaceItemDecoration.java | 1 + .../widget/textdrawable/TextDrawable.java | 119 +++++++-------- .../textdrawable/util/ColorGenerator.java | 8 +- settings.gradle | 2 +- utils/.gitignore | 1 + utils/build.gradle | 35 +++++ utils/proguard-rules.pro | 21 +++ utils/src/main/AndroidManifest.xml | 1 + .../src/main/java/com}/utils/Utils.java | 10 +- wear/build.gradle | 3 +- .../squareboat/excuser/MainWearActivity.java | 85 +++++------ .../service/AccelerometerSensorService.java | 49 +++--- .../service/DataLayerListenerService.java | 8 +- .../excuser/utils/LocalStoreUtils.java | 4 +- .../com/squareboat/excuser/utils/Utils.java | 81 ---------- 33 files changed, 458 insertions(+), 565 deletions(-) create mode 100644 utils/.gitignore create mode 100644 utils/build.gradle create mode 100644 utils/proguard-rules.pro create mode 100644 utils/src/main/AndroidManifest.xml rename {mobile/src/main/java/com/squareboat/excuser => utils/src/main/java/com}/utils/Utils.java (94%) mode change 100755 => 100644 delete mode 100755 wear/src/main/java/com/squareboat/excuser/utils/Utils.java diff --git a/mobile/build.gradle b/mobile/build.gradle index 64a4d70..0b44b6b 100644 --- a/mobile/build.gradle +++ b/mobile/build.gradle @@ -76,12 +76,10 @@ 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' @@ -89,13 +87,14 @@ dependencies { 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') } diff --git a/mobile/src/main/java/com/squareboat/excuser/ExcuserApplication.java b/mobile/src/main/java/com/squareboat/excuser/ExcuserApplication.java index c253bfe..0e1da55 100644 --- a/mobile/src/main/java/com/squareboat/excuser/ExcuserApplication.java +++ b/mobile/src/main/java/com/squareboat/excuser/ExcuserApplication.java @@ -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; @@ -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() @@ -49,10 +50,6 @@ public void onCreate() { } } - public static ExcuserApplication getInstance() { - return _instance; - } - public String getAppPackageName() { return getPackageName(); } diff --git a/mobile/src/main/java/com/squareboat/excuser/activity/AudioPlayer.java b/mobile/src/main/java/com/squareboat/excuser/activity/AudioPlayer.java index b7194ce..2521cf3 100644 --- a/mobile/src/main/java/com/squareboat/excuser/activity/AudioPlayer.java +++ b/mobile/src/main/java/com/squareboat/excuser/activity/AudioPlayer.java @@ -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)); @@ -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 @@ -66,7 +66,7 @@ public void stopRingtone() { mPlayer = null; } - if(mVibrator!=null){ + if (mVibrator != null) { mVibrator.cancel(); } } @@ -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; } diff --git a/mobile/src/main/java/com/squareboat/excuser/activity/BaseActivity.java b/mobile/src/main/java/com/squareboat/excuser/activity/BaseActivity.java index 2013321..463af42 100644 --- a/mobile/src/main/java/com/squareboat/excuser/activity/BaseActivity.java +++ b/mobile/src/main/java/com/squareboat/excuser/activity/BaseActivity.java @@ -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) { @@ -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); } @@ -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(); } @@ -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(); } diff --git a/mobile/src/main/java/com/squareboat/excuser/activity/IncomingCallActivity.java b/mobile/src/main/java/com/squareboat/excuser/activity/IncomingCallActivity.java index f45246b..71567e6 100644 --- a/mobile/src/main/java/com/squareboat/excuser/activity/IncomingCallActivity.java +++ b/mobile/src/main/java/com/squareboat/excuser/activity/IncomingCallActivity.java @@ -24,6 +24,7 @@ import butterknife.BindView; import butterknife.ButterKnife; +import butterknife.OnClick; /** * Created by Vipul on 02/05/17. @@ -31,49 +32,32 @@ 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); @@ -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 { @@ -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(); @@ -144,34 +128,32 @@ 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(); @@ -179,11 +161,11 @@ private void onCallAccept(){ mActivityTimeout.cancel(); } - private void onCallReject(){ + private void onCallReject() { } - private void endActivity(){ - if(mAudioPlayer!=null) + private void endActivity() { + if (mAudioPlayer != null) mAudioPlayer.stopRingtone(); mActivityTimeout.cancel(); @@ -191,7 +173,7 @@ private void endActivity(){ 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) { @@ -202,11 +184,10 @@ 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; @@ -214,17 +195,29 @@ private String formatTimespan(long timespan) { } 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(); + } + }); + } + } } diff --git a/mobile/src/main/java/com/squareboat/excuser/activity/SplashActivity.java b/mobile/src/main/java/com/squareboat/excuser/activity/SplashActivity.java index c28f1ba..26f0538 100644 --- a/mobile/src/main/java/com/squareboat/excuser/activity/SplashActivity.java +++ b/mobile/src/main/java/com/squareboat/excuser/activity/SplashActivity.java @@ -35,29 +35,27 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { protected void onResume() { super.onResume(); - if(checkPlayServices()) { + if (checkPlayServices()) { new Handler().postDelayed(new Runnable() { @Override public void run() { - - if(LocalStoreUtils.isOnboardingCompleted(SplashActivity.this)) { + if (LocalStoreUtils.isOnboardingCompleted(SplashActivity.this)) { launchMainActivity(); } else { launchOnboardingActivity(); } - } }, SPLASH_TIME_OUT); } } - private void launchOnboardingActivity(){ + private void launchOnboardingActivity() { startActivity(new Intent(SplashActivity.this, OnboardingActivity.class)); overridePendingTransition(0, R.anim.fade_out); finish(); } - private void launchMainActivity(){ + private void launchMainActivity() { startActivity(new Intent(SplashActivity.this, MainActivity.class)); overridePendingTransition(0, R.anim.fade_out); finish(); diff --git a/mobile/src/main/java/com/squareboat/excuser/activity/home/AddContactDialog.java b/mobile/src/main/java/com/squareboat/excuser/activity/home/AddContactDialog.java index 1f3f75a..636b790 100644 --- a/mobile/src/main/java/com/squareboat/excuser/activity/home/AddContactDialog.java +++ b/mobile/src/main/java/com/squareboat/excuser/activity/home/AddContactDialog.java @@ -20,11 +20,6 @@ public class AddContactDialog extends DialogFragment { - public interface DialogCallback { - void onContactAdded(Contact contact); - void onContactUpdated(Contact contact); - } - private DialogCallback mDialogCallback; private View positiveAction, negativeAction; private TextInputLayout nameInputLayout, mobileInputLayout; @@ -48,10 +43,10 @@ public Dialog onCreateDialog(Bundle savedInstanceState) { this.mContact = getArguments().getParcelable("contact"); materialDialog = new MaterialDialog.Builder(getActivity()) - .title(mContact==null ? "Add Contact" : "Edit Contact") + .title(mContact == null ? "Add Contact" : "Edit Contact") .customView(R.layout.dialog_add_contact, true) .cancelable(false) - .positiveText(mContact==null ? R.string.add : R.string.update) + .positiveText(mContact == null ? R.string.add : R.string.update) .negativeText(android.R.string.cancel) .build(); @@ -62,7 +57,7 @@ public Dialog onCreateDialog(Bundle savedInstanceState) { nameInputLayout = (TextInputLayout) materialDialog.getCustomView().findViewById(R.id.input_layout_name); mobileInputLayout = (TextInputLayout) materialDialog.getCustomView().findViewById(R.id.input_layout_mobile); - if(mContact!=null) { + if (mContact != null) { nameEditText.setText(mContact.getName()); mobileEditText.setText(mContact.getMobile()); } @@ -80,20 +75,19 @@ public void onClick(View v) { String name = nameEditText.getText().toString().trim(); String mobile = mobileEditText.getText().toString().trim(); - if(mobile.isEmpty()){ + if (mobile.isEmpty()) { mobileInputLayout.setError("Please enter mobile"); return; } - if(mDialogCallback!=null) { + if (mDialogCallback != null) { - if(mContact==null) { + if (mContact == null) { mContact = new Contact(); mContact.setName(name); mContact.setMobile(mobile); mDialogCallback.onContactAdded(mContact); - } - else { + } else { mContact.setName(name); mContact.setMobile(mobile); mDialogCallback.onContactUpdated(mContact); @@ -108,8 +102,14 @@ public void onClick(View v) { return materialDialog; } - public void setDialogCallback(DialogCallback dialogCallback){ + public void setDialogCallback(DialogCallback dialogCallback) { this.mDialogCallback = dialogCallback; } + public interface DialogCallback { + void onContactAdded(Contact contact); + + void onContactUpdated(Contact contact); + } + } diff --git a/mobile/src/main/java/com/squareboat/excuser/activity/home/ContactAdapter.java b/mobile/src/main/java/com/squareboat/excuser/activity/home/ContactAdapter.java index ee615f8..61ea653 100755 --- a/mobile/src/main/java/com/squareboat/excuser/activity/home/ContactAdapter.java +++ b/mobile/src/main/java/com/squareboat/excuser/activity/home/ContactAdapter.java @@ -5,7 +5,6 @@ import android.support.v7.widget.PopupMenu; import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; -import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; @@ -24,21 +23,15 @@ public class ContactAdapter extends RecyclerView.Adapter { - public interface Callbacks { - public void onContactClick(Contact contact); - public void onContactDelete(Contact contact); - } - private Callbacks mCallbacks; private Context context; private List mFeedList; - public ContactAdapter(List feedList) { this.mFeedList = feedList; } @Override - public ContactViewHolder onCreateViewHolder (ViewGroup parent, int viewType) { + public ContactViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { context = parent.getContext(); View view = LayoutInflater.from(context).inflate(R.layout.item_contact, parent, false); @@ -49,7 +42,7 @@ public ContactViewHolder onCreateViewHolder (ViewGroup parent, int viewType) { public void onBindViewHolder(final ContactViewHolder holder, final int position) { final Contact contact = mFeedList.get(position); - if(contact.getName().isEmpty()) { + if (contact.getName().isEmpty()) { holder.contactName.setText("Untitled"); holder.contactMobile.setText(contact.getMobile()); } else { @@ -73,16 +66,17 @@ public void onClick(View v) { @Override public boolean onMenuItemClick(MenuItem item) { switch (item.getItemId()) { - case R.id.menu_edit_contact: - { - if(mCallbacks!=null) - mCallbacks.onContactClick(contact); - } break; + case R.id.menu_edit_contact: { + if (mCallbacks != null) + mCallbacks.onContactClick(contact); + } + break; case R.id.menu_delete_contact: { - if(mCallbacks!=null) + if (mCallbacks != null) mCallbacks.onContactDelete(contact); - } break; + } + break; } return true; @@ -98,13 +92,24 @@ public boolean onMenuItemClick(MenuItem item) { @Override public int getItemCount() { - return (mFeedList!=null? mFeedList.size():0); + return (mFeedList != null ? mFeedList.size() : 0); } public void setCallbacks(Callbacks callbacks) { this.mCallbacks = callbacks; } + public void onItemAdded(Contact category) { + mFeedList.add(category); + notifyDataSetChanged(); + } + + public interface Callbacks { + public void onContactClick(Contact contact); + + public void onContactDelete(Contact contact); + } + public class ContactViewHolder extends RecyclerView.ViewHolder { @BindView(R.id.text_contact_name) @@ -125,9 +130,4 @@ public ContactViewHolder(View itemView) { } } - public void onItemAdded(Contact category){ - mFeedList.add(category); - notifyDataSetChanged(); - } - } diff --git a/mobile/src/main/java/com/squareboat/excuser/activity/home/MainActivity.java b/mobile/src/main/java/com/squareboat/excuser/activity/home/MainActivity.java index a3498d7..76395b4 100644 --- a/mobile/src/main/java/com/squareboat/excuser/activity/home/MainActivity.java +++ b/mobile/src/main/java/com/squareboat/excuser/activity/home/MainActivity.java @@ -4,9 +4,7 @@ import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.design.widget.FloatingActionButton; -import android.support.v7.widget.DividerItemDecoration; import android.support.v7.widget.GridLayoutManager; -import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.util.Log; import android.view.Menu; @@ -21,8 +19,8 @@ import com.squareboat.excuser.activity.settings.SettingsActivity; import com.squareboat.excuser.model.Contact; import com.squareboat.excuser.utils.LocalStoreUtils; -import com.squareboat.excuser.utils.Utils; import com.squareboat.excuser.widget.SpaceItemDecoration; +import com.utils.Utils; import java.util.ArrayList; import java.util.List; @@ -46,6 +44,29 @@ public class MainActivity extends BaseActivity implements GoogleApiClient.Connec private GoogleApiClient mGoogleApiClient; private ContactAdapter mContactAdapter; private List mContacts = new ArrayList<>(); + AddContactDialog.DialogCallback mAddContactDialogCallback = new AddContactDialog.DialogCallback() { + + @Override + public void onContactAdded(Contact contact) { + Log.e("onContactAdded", "->"); + if (LocalStoreUtils.getContacts(MainActivity.this) != null) { + int size = LocalStoreUtils.getContacts(MainActivity.this).size(); + contact.setId(size); + } else { + contact.setId(0); + } + + LocalStoreUtils.addContact(contact, MainActivity.this); + refreshData(); + } + + @Override + public void onContactUpdated(Contact contact) { + Log.e("onContactUpdated", "->"); + LocalStoreUtils.updateContact(contact, MainActivity.this); + refreshData(); + } + }; @Override protected void onCreate(Bundle savedInstanceState) { @@ -56,7 +77,7 @@ protected void onCreate(Bundle savedInstanceState) { setupGoogleClient(); } - private void setupGoogleClient(){ + private void setupGoogleClient() { mGoogleApiClient = new GoogleApiClient.Builder(this) .addApi(Wearable.API) .addConnectionCallbacks(this) @@ -64,7 +85,7 @@ private void setupGoogleClient(){ .build(); } - private void initView(){ + private void initView() { int columnCount = getResources().getInteger(R.integer.item_column); final GridLayoutManager gridLayoutManager = new GridLayoutManager(this, columnCount); @@ -85,9 +106,9 @@ public void onClick(View v) { }); } - private void refreshData(){ - if(LocalStoreUtils.getContacts(this)!=null) { - if(LocalStoreUtils.getContacts(this).size()>0) { + private void refreshData() { + if (LocalStoreUtils.getContacts(this) != null) { + if (LocalStoreUtils.getContacts(this).size() > 0) { showNoContent(false); mContacts.clear(); mContacts.addAll(LocalStoreUtils.getContacts(this)); @@ -100,7 +121,7 @@ private void refreshData(){ } } - private void showNoContent(boolean value){ + private void showNoContent(boolean value) { int noContactVisibility = value ? View.VISIBLE : View.GONE; mNoContactsLayout.setVisibility(noContactVisibility); @@ -142,30 +163,6 @@ public void onConnectionFailed(@NonNull ConnectionResult connectionResult) { Log.e(TAG, "onConnectionFailed(): " + connectionResult); } - AddContactDialog.DialogCallback mAddContactDialogCallback = new AddContactDialog.DialogCallback() { - - @Override - public void onContactAdded(Contact contact) { - Log.e("onContactAdded", "->"); - if (LocalStoreUtils.getContacts(MainActivity.this) != null) { - int size = LocalStoreUtils.getContacts(MainActivity.this).size(); - contact.setId(size); - } else { - contact.setId(0); - } - - LocalStoreUtils.addContact(contact, MainActivity.this); - refreshData(); - } - - @Override - public void onContactUpdated(Contact contact) { - Log.e("onContactUpdated", "->"); - LocalStoreUtils.updateContact(contact, MainActivity.this); - refreshData(); - } - }; - @Override public void onContactClick(Contact contact) { AddContactDialog.showDialog(getSupportFragmentManager(), contact, mAddContactDialogCallback); @@ -187,7 +184,9 @@ public boolean onCreateOptionsMenu(Menu menu) { public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { - case R.id.action_settings: SettingsActivity.launchActivity(this); break; + case R.id.action_settings: + SettingsActivity.launchActivity(this); + break; } return super.onOptionsItemSelected(item); diff --git a/mobile/src/main/java/com/squareboat/excuser/activity/onboarding/DeviceWearConnectionFragment.java b/mobile/src/main/java/com/squareboat/excuser/activity/onboarding/DeviceWearConnectionFragment.java index 7be4d43..b294685 100644 --- a/mobile/src/main/java/com/squareboat/excuser/activity/onboarding/DeviceWearConnectionFragment.java +++ b/mobile/src/main/java/com/squareboat/excuser/activity/onboarding/DeviceWearConnectionFragment.java @@ -2,9 +2,7 @@ import android.annotation.SuppressLint; import android.content.Intent; -import android.graphics.drawable.Animatable; import android.graphics.drawable.AnimatedVectorDrawable; -import android.graphics.drawable.Drawable; import android.net.Uri; import android.os.Bundle; import android.os.Handler; @@ -13,9 +11,7 @@ import android.support.annotation.Nullable; import android.support.design.widget.FloatingActionButton; import android.support.design.widget.Snackbar; -import android.support.graphics.drawable.AnimatedVectorDrawableCompat; import android.support.v4.app.Fragment; -import android.support.v4.content.ContextCompat; import android.support.v7.widget.AppCompatButton; import android.support.v7.widget.AppCompatImageView; import android.util.Log; @@ -25,7 +21,6 @@ import android.view.animation.AlphaAnimation; import android.view.animation.Animation; import android.widget.TextView; -import android.widget.Toast; import com.google.android.gms.common.ConnectionResult; import com.google.android.gms.common.api.GoogleApiClient; @@ -46,6 +41,7 @@ import butterknife.BindString; import butterknife.BindView; import butterknife.ButterKnife; +import butterknife.OnClick; /** * Created by Vipul on 19/05/17. @@ -54,57 +50,61 @@ public class DeviceWearConnectionFragment extends Fragment implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener, - CapabilityApi.CapabilityListener{ + CapabilityApi.CapabilityListener { + private static final String CAPABILITY_WEAR_APP = "com_squareboat_excuser_wear_app"; private static final String TAG = "DeviceWearConnectionFragment"; + private final Animation mConnectionMessageAnimation = new AlphaAnimation(1.0f, 0.0f); @BindString(R.string.checking_message) - String CHECKING_MESSAGE; - + protected String CHECKING_MESSAGE; @BindString(R.string.no_devices_linked) - String NO_DEVICES_LINKED; - + protected String NO_DEVICES_LINKED; @BindString(R.string.no_devices) - String NO_DEVICES; - + protected String NO_DEVICES; @BindString(R.string.missing_all_message) - String MISSING_ALL_MESSAGE; - + protected String MISSING_ALL_MESSAGE; @BindString(R.string.installed_some_devices_message) - String INSTALLED_SOME_DEVICES_MESSAGE; - + protected String INSTALLED_SOME_DEVICES_MESSAGE; @BindString(R.string.installed_all_devices_message) - String INSTALLED_ALL_DEVICES_MESSAGE; - + protected String INSTALLED_ALL_DEVICES_MESSAGE; @BindString(R.string.app_playstore_url) - String PLAY_STORE_APP_URI; - - String CAPABILITY_WEAR_APP = "com_squareboat_excuser_wear_app"; + protected String PLAY_STORE_APP_URI; @BindView(R.id.image_device_wear_connection) - AppCompatImageView mDeviceWearConnection; - + protected AppCompatImageView mDeviceWearConnection; @BindView(R.id.text_connection_title) - TextView mConnectionTitle; - + protected TextView mConnectionTitle; @BindView(R.id.text_connection_message) - TextView mConnectionMessage; - + protected TextView mConnectionMessage; @BindView(R.id.button_wear_app) - AppCompatButton mWearAppButton; - + protected AppCompatButton mWearAppButton; @BindView(R.id.button_install_wear_app) - AppCompatButton mInstallAppOnWear; - + protected AppCompatButton mInstallAppOnWear; @BindView(R.id.button_device_next) - FloatingActionButton mButtonNext; + protected FloatingActionButton mButtonNext; + + // Result from sending RemoteIntent to wear device(s) to open app in play/app store. + private final ResultReceiver mResultReceiver = new ResultReceiver(new Handler()) { + @SuppressLint("LongLogTag") + @Override + protected void onReceiveResult(int resultCode, Bundle resultData) { + Log.d(TAG, "onReceiveResult: " + resultCode); + + if (resultCode == RemoteIntent.RESULT_OK) { + showSnackBar(mInstallAppOnWear, R.string.playstore_request_successfull); + + } else if (resultCode == RemoteIntent.RESULT_FAILED) { + showSnackBar(mInstallAppOnWear, R.string.playstore_request_fail); + + } + } + }; private Set mWearNodesWithApp; private List mAllConnectedNodes; private GoogleApiClient mGoogleApiClient; - final Animation mConnectionMessageAnimation = new AlphaAnimation(1.0f, 0.0f); - public static DeviceWearConnectionFragment newInstance() { return new DeviceWearConnectionFragment(); } @@ -122,29 +122,10 @@ public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { ButterKnife.bind(this, view); mButtonNext.hide(); - mButtonNext.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - ((OnboardingActivity)getActivity()).showWearShakeDemoFragment(); - } - }); mWearAppButton.setVisibility(View.GONE); - mWearAppButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=com.google.android.wearable.app")); - startActivity(intent); - } - }); mInstallAppOnWear.setVisibility(View.GONE); - mInstallAppOnWear.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - openPlayStoreOnWearDevicesWithoutApp(); - } - }); setConnectionMessage(CHECKING_MESSAGE); updateDeviceWearConnectionIcon(R.drawable.avd_device_wear_connection); @@ -156,16 +137,33 @@ public void onClick(View v) { mConnectionMessageAnimation.setRepeatMode(Animation.REVERSE); } - private void updateDeviceWearConnectionIcon(int resId){ + @OnClick(R.id.button_wear_app) + public void onButtonWearAppClicked() { + Intent intent = new Intent(Intent.ACTION_VIEW, + Uri.parse("https://play.google.com/store/apps/details?id=com.google.android.wearable.app")); + startActivity(intent); + } + + @OnClick(R.id.button_install_wear_app) + public void onButtonInstallWearAppClicked() { + openPlayStoreOnWearDevicesWithoutApp(); + } + + @OnClick(R.id.button_device_next) + public void onButtonDeviceNextClicked() { + ((OnboardingActivity) getActivity()).showWearShakeDemoFragment(); + } + + private void updateDeviceWearConnectionIcon(int resId) { AnimatedVectorDrawable avd = (AnimatedVectorDrawable) getActivity().getDrawable(resId); - if (mDeviceWearConnection != null && avd != null) { + if (avd != null) { mDeviceWearConnection.setImageDrawable(avd); avd.start(); } } - private void setGoogleApiClient(){ + private void setGoogleApiClient() { mGoogleApiClient = new GoogleApiClient.Builder(getActivity()) .addApi(Wearable.API) .addConnectionCallbacks(this) @@ -230,7 +228,7 @@ public void onConnectionSuspended(int i) { @Override public void onConnectionFailed(@NonNull ConnectionResult connectionResult) { Log.e(TAG, "onConnectionFailed(): " + connectionResult); - if(connectionResult.getErrorCode() == ConnectionResult.API_UNAVAILABLE) { + if (connectionResult.getErrorCode() == ConnectionResult.API_UNAVAILABLE) { mConnectionTitle.setText("Connection Failed"); setConnectionMessage(NO_DEVICES_LINKED); updateDeviceWearConnectionIcon(R.drawable.avd_device_wear_connection_faliure); @@ -265,7 +263,7 @@ public void onResult(@NonNull NodeApi.GetConnectedNodesResult getConnectedNodesR if (getConnectedNodesResult.getStatus().isSuccess()) { mAllConnectedNodes = getConnectedNodesResult.getNodes(); verifyNodeAndUpdateUI(); - Log.e("Connected Nodes", "->"+mAllConnectedNodes.toString()); + Log.e("Connected Nodes", "->" + mAllConnectedNodes.toString()); findWearDevicesWithApp(); } else { @@ -305,7 +303,7 @@ public void onResult(@NonNull CapabilityApi.GetCapabilityResult getCapabilityRes } @SuppressLint("LongLogTag") - private void verifyNodeAndUpdateUI(){ + private void verifyNodeAndUpdateUI() { mWearAppButton.setVisibility(View.GONE); mInstallAppOnWear.setVisibility(View.GONE); @@ -350,7 +348,7 @@ private void verifyNodeAndUpdateUI(){ } } - private void setConnectionMessage(final String message){ + private void setConnectionMessage(final String message) { mConnectionMessageAnimation.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { @@ -388,8 +386,8 @@ private void openPlayStoreOnWearDevicesWithoutApp() { Log.d(TAG, "Number of nodes without app: " + nodesWithoutApp.size()); Intent intent = new Intent(Intent.ACTION_VIEW) - .addCategory(Intent.CATEGORY_BROWSABLE) - .setData(Uri.parse(PLAY_STORE_APP_URI)); + .addCategory(Intent.CATEGORY_BROWSABLE) + .setData(Uri.parse(PLAY_STORE_APP_URI)); for (Node node : nodesWithoutApp) { RemoteIntent.startRemoteActivity(getContext(), intent, mResultReceiver, node.getId()); @@ -397,29 +395,11 @@ private void openPlayStoreOnWearDevicesWithoutApp() { } } - // Result from sending RemoteIntent to wear device(s) to open app in play/app store. - private final ResultReceiver mResultReceiver = new ResultReceiver(new Handler()) { - @SuppressLint("LongLogTag") - @Override - protected void onReceiveResult(int resultCode, Bundle resultData) { - Log.d(TAG, "onReceiveResult: " + resultCode); - - if (resultCode == RemoteIntent.RESULT_OK) { - showSnackBar(mInstallAppOnWear, R.string.playstore_request_successfull); - - } else if (resultCode == RemoteIntent.RESULT_FAILED) { - showSnackBar(mInstallAppOnWear, R.string.playstore_request_fail); - - } - } - }; - - private void showSnackBar(View view, String message){ + private void showSnackBar(View view, String message) { Snackbar.make(view, message, Snackbar.LENGTH_LONG).show(); } - private void showSnackBar(View view, int message){ + private void showSnackBar(View view, int message) { Snackbar.make(view, message, Snackbar.LENGTH_LONG).show(); } - } diff --git a/mobile/src/main/java/com/squareboat/excuser/activity/onboarding/OnboardingActivity.java b/mobile/src/main/java/com/squareboat/excuser/activity/onboarding/OnboardingActivity.java index 04292d1..1f8e19a 100644 --- a/mobile/src/main/java/com/squareboat/excuser/activity/onboarding/OnboardingActivity.java +++ b/mobile/src/main/java/com/squareboat/excuser/activity/onboarding/OnboardingActivity.java @@ -1,18 +1,13 @@ package com.squareboat.excuser.activity.onboarding; import android.os.Bundle; -import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; import android.support.v7.app.AppCompatActivity; -import android.util.Log; import android.view.View; import com.squareboat.excuser.R; -import java.util.List; -import java.util.Set; - import butterknife.BindView; import butterknife.ButterKnife; diff --git a/mobile/src/main/java/com/squareboat/excuser/activity/onboarding/WearShakeDemoFragment.java b/mobile/src/main/java/com/squareboat/excuser/activity/onboarding/WearShakeDemoFragment.java index ccd295f..f3b5ab4 100644 --- a/mobile/src/main/java/com/squareboat/excuser/activity/onboarding/WearShakeDemoFragment.java +++ b/mobile/src/main/java/com/squareboat/excuser/activity/onboarding/WearShakeDemoFragment.java @@ -1,7 +1,5 @@ package com.squareboat.excuser.activity.onboarding; -import android.graphics.drawable.Animatable; -import android.graphics.drawable.Drawable; import android.os.Bundle; import android.support.annotation.Nullable; import android.support.design.widget.FloatingActionButton; @@ -10,10 +8,7 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.view.animation.Animation; -import com.nineoldandroids.animation.ObjectAnimator; -import com.nineoldandroids.animation.ValueAnimator; import com.squareboat.excuser.R; import butterknife.BindView; @@ -50,7 +45,7 @@ public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { mButtonNext.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - ((OnboardingActivity)getActivity()).showWearShakeIntensityFragment(); + ((OnboardingActivity) getActivity()).showWearShakeIntensityFragment(); } }); } diff --git a/mobile/src/main/java/com/squareboat/excuser/activity/onboarding/WearShakeIntensityFragment.java b/mobile/src/main/java/com/squareboat/excuser/activity/onboarding/WearShakeIntensityFragment.java index d2162ec..e6c4661 100644 --- a/mobile/src/main/java/com/squareboat/excuser/activity/onboarding/WearShakeIntensityFragment.java +++ b/mobile/src/main/java/com/squareboat/excuser/activity/onboarding/WearShakeIntensityFragment.java @@ -3,16 +3,12 @@ import android.annotation.SuppressLint; import android.content.Intent; import android.content.SharedPreferences; -import android.graphics.drawable.Animatable; import android.graphics.drawable.AnimatedVectorDrawable; -import android.graphics.drawable.Drawable; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.design.widget.FloatingActionButton; -import android.support.graphics.drawable.AnimatedVectorDrawableCompat; import android.support.v4.app.Fragment; -import android.support.v4.content.ContextCompat; import android.support.v7.preference.PreferenceManager; import android.support.v7.widget.AppCompatImageView; import android.support.v7.widget.AppCompatSeekBar; @@ -22,27 +18,17 @@ import android.view.ViewGroup; import android.widget.SeekBar; import android.widget.TextView; -import android.widget.Toast; import com.google.android.gms.common.ConnectionResult; import com.google.android.gms.common.api.GoogleApiClient; -import com.google.android.gms.common.api.PendingResult; -import com.google.android.gms.common.api.ResultCallback; -import com.google.android.gms.wearable.DataApi; -import com.google.android.gms.wearable.MessageApi; -import com.google.android.gms.wearable.Node; -import com.google.android.gms.wearable.NodeApi; import com.google.android.gms.wearable.PutDataMapRequest; import com.google.android.gms.wearable.PutDataRequest; import com.google.android.gms.wearable.Wearable; -import com.google.android.gms.wearable.WearableStatusCodes; import com.squareboat.excuser.R; -import com.squareboat.excuser.activity.SplashActivity; import com.squareboat.excuser.activity.home.MainActivity; import com.squareboat.excuser.model.Contact; import com.squareboat.excuser.utils.LocalStoreUtils; -import java.nio.charset.Charset; import java.util.ArrayList; import java.util.List; @@ -55,12 +41,10 @@ public class WearShakeIntensityFragment extends Fragment implements GoogleApiClient.ConnectionCallbacks, - GoogleApiClient.OnConnectionFailedListener{ - - private static final String TAG = "WearShakeIntensityFragment"; + GoogleApiClient.OnConnectionFailedListener { public static final String SHAKE_INTENSITY_KEY = "com.squareboat.excuser.shakeintensity"; - + private static final String TAG = "WearShakeIntensityFragment"; @BindView(R.id.button_done) FloatingActionButton mButtonDone; @@ -100,9 +84,18 @@ public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { switch (progress) { - case 0: mIntensityText.setText(getResources().getString(R.string.low)); updateShakeIntensityIcon(R.drawable.avd_wear_shake_intensity); break; - case 1: mIntensityText.setText(getResources().getString(R.string.moderate)); updateShakeIntensityIcon(R.drawable.avd_wear_shake_intensity_moderate); break; - case 2: mIntensityText.setText(getResources().getString(R.string.high)); updateShakeIntensityIcon(R.drawable.avd_wear_shake_intensity_high); break; + case 0: + mIntensityText.setText(getResources().getString(R.string.low)); + updateShakeIntensityIcon(R.drawable.avd_wear_shake_intensity); + break; + case 1: + mIntensityText.setText(getResources().getString(R.string.moderate)); + updateShakeIntensityIcon(R.drawable.avd_wear_shake_intensity_moderate); + break; + case 2: + mIntensityText.setText(getResources().getString(R.string.high)); + updateShakeIntensityIcon(R.drawable.avd_wear_shake_intensity_high); + break; } } @@ -121,7 +114,7 @@ public void onStopTrackingTouch(SeekBar seekBar) { @Override public void onClick(View v) { - String shakeIntensity = String.valueOf(mIntensitySeekBar.getProgress()+1); + String shakeIntensity = String.valueOf(mIntensitySeekBar.getProgress() + 1); sendShakeIntensityToWear(shakeIntensity); @@ -137,7 +130,7 @@ public void onClick(View v) { }); } - private void saveDummyData(){ + private void saveDummyData() { List contacts = new ArrayList<>(); contacts.add(new Contact(1, "9876543210", "Home")); contacts.add(new Contact(2, "9437674662", "Office")); @@ -146,7 +139,7 @@ private void saveDummyData(){ LocalStoreUtils.setContacts(contacts, getActivity()); } - private void updateShakeIntensityIcon(int resId){ + private void updateShakeIntensityIcon(int resId) { AnimatedVectorDrawable avd = (AnimatedVectorDrawable) getActivity().getDrawable(resId); if (mShakeIntensity != null && avd != null) { @@ -155,13 +148,13 @@ private void updateShakeIntensityIcon(int resId){ } } - private void launchMainActivity(){ + private void launchMainActivity() { startActivity(new Intent(getActivity(), MainActivity.class)); getActivity().overridePendingTransition(0, R.anim.fade_out); getActivity().finish(); } - private void setGoogleApiClient(){ + private void setGoogleApiClient() { mGoogleApiClient = new GoogleApiClient.Builder(getActivity()) .addApi(Wearable.API) .addConnectionCallbacks(this) @@ -208,12 +201,12 @@ public void onConnectionFailed(@NonNull ConnectionResult connectionResult) { Log.e(TAG, "onConnectionFailed(): " + connectionResult); } - private void sendShakeIntensityToWear(String shakeIntensity){ + private void sendShakeIntensityToWear(String shakeIntensity) { PutDataMapRequest putDataMapReq = PutDataMapRequest.create("/SHAKEINTENSITY"); putDataMapReq.getDataMap().putString(SHAKE_INTENSITY_KEY, shakeIntensity); PutDataRequest putDataReq = putDataMapReq - .asPutDataRequest() - .setUrgent(); + .asPutDataRequest() + .setUrgent(); Wearable.DataApi.putDataItem(mGoogleApiClient, putDataReq); } diff --git a/mobile/src/main/java/com/squareboat/excuser/activity/settings/SettingsActivity.java b/mobile/src/main/java/com/squareboat/excuser/activity/settings/SettingsActivity.java index 5b26602..8d5dd00 100644 --- a/mobile/src/main/java/com/squareboat/excuser/activity/settings/SettingsActivity.java +++ b/mobile/src/main/java/com/squareboat/excuser/activity/settings/SettingsActivity.java @@ -19,19 +19,12 @@ import com.google.android.gms.common.ConnectionResult; import com.google.android.gms.common.api.GoogleApiClient; -import com.google.android.gms.common.api.PendingResult; -import com.google.android.gms.common.api.ResultCallback; -import com.google.android.gms.wearable.Node; -import com.google.android.gms.wearable.NodeApi; import com.google.android.gms.wearable.PutDataMapRequest; import com.google.android.gms.wearable.PutDataRequest; import com.google.android.gms.wearable.Wearable; import com.squareboat.excuser.R; import com.squareboat.excuser.activity.onboarding.WearShakeIntensityFragment; -import java.nio.charset.Charset; -import java.util.List; - /** * Created by Vipul on 22/05/17. */ @@ -53,11 +46,11 @@ protected void onCreate(Bundle savedInstanceState) { private void setupActionBar() { - ViewGroup rootView = (ViewGroup)findViewById(R.id.action_bar_root); + ViewGroup rootView = findViewById(R.id.action_bar_root); View view = getLayoutInflater().inflate(R.layout.layout_toolbar, rootView, false); rootView.addView(view, 0); - Toolbar toolbar = (Toolbar)findViewById(R.id.toolbar); + Toolbar toolbar = findViewById(R.id.toolbar); setSupportActionBar(toolbar); ActionBar actionBar = getSupportActionBar(); if (actionBar != null) { @@ -79,36 +72,21 @@ public boolean onMenuItemSelected(int featureId, MenuItem item) { public static class MyPreferenceFragment extends PreferenceFragment implements GoogleApiClient.ConnectionCallbacks, - GoogleApiClient.OnConnectionFailedListener{ + GoogleApiClient.OnConnectionFailedListener { private static final String TAG = "MyPreferenceFragment"; private GoogleApiClient mGoogleApiClient; - - @Override - public void onCreate(final Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - addPreferencesFromResource(R.xml.preference_screen); - setGoogleApiClient(); - - Preference preference = findPreference(getResources().getString(R.string.intensity_preference_key)); - preference.setOnPreferenceChangeListener(preferenceChangeListener); - preferenceChangeListener.onPreferenceChange(preference, - PreferenceManager - .getDefaultSharedPreferences(preference.getContext()) - .getString(preference.getKey(), "")); - } - Preference.OnPreferenceChangeListener preferenceChangeListener = new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { String stringValue = newValue.toString(); - Log.e("stringValue", "->"+stringValue); + Log.e("stringValue", "->" + stringValue); if (preference instanceof ListPreference) { ((ListPreference) preference).setValue(stringValue); String currValue = ((ListPreference) preference).getValue(); - Log.e("value", "->"+currValue); + Log.e("value", "->" + currValue); sendShakeIntensityToWear(currValue); } @@ -116,7 +94,21 @@ public boolean onPreferenceChange(Preference preference, Object newValue) { } }; - private void setGoogleApiClient(){ + @Override + public void onCreate(final Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + addPreferencesFromResource(R.xml.preference_screen); + setGoogleApiClient(); + + Preference preference = findPreference(getResources().getString(R.string.intensity_preference_key)); + preference.setOnPreferenceChangeListener(preferenceChangeListener); + preferenceChangeListener.onPreferenceChange(preference, + PreferenceManager + .getDefaultSharedPreferences(preference.getContext()) + .getString(preference.getKey(), "")); + } + + private void setGoogleApiClient() { mGoogleApiClient = new GoogleApiClient.Builder(getActivity()) .addApi(Wearable.API) .addConnectionCallbacks(this) @@ -164,7 +156,7 @@ public void onConnectionFailed(@NonNull ConnectionResult connectionResult) { Log.e(TAG, "onConnectionFailed(): " + connectionResult); } - private void sendShakeIntensityToWear(String shakeIntensity){ + private void sendShakeIntensityToWear(String shakeIntensity) { PutDataMapRequest putDataMapReq = PutDataMapRequest.create("/SHAKEINTENSITY"); putDataMapReq.getDataMap().putString(WearShakeIntensityFragment.SHAKE_INTENSITY_KEY, shakeIntensity); PutDataRequest putDataReq = putDataMapReq diff --git a/mobile/src/main/java/com/squareboat/excuser/model/Contact.java b/mobile/src/main/java/com/squareboat/excuser/model/Contact.java index 8ca761f..ed3593a 100644 --- a/mobile/src/main/java/com/squareboat/excuser/model/Contact.java +++ b/mobile/src/main/java/com/squareboat/excuser/model/Contact.java @@ -1,4 +1,3 @@ - package com.squareboat.excuser.model; import android.os.Parcel; @@ -22,6 +21,9 @@ public Contact(int mId, String mMobile, String mName) { this.mName = mName; } + public Contact() { + } + public int getId() { return mId; } @@ -58,16 +60,13 @@ public void writeToParcel(Parcel dest, int flags) { dest.writeString(this.mName); } - public Contact() { - } - protected Contact(Parcel in) { this.mId = in.readInt(); this.mMobile = in.readString(); this.mName = in.readString(); } - public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { + public static final Creator CREATOR = new Creator() { @Override public Contact createFromParcel(Parcel source) { return new Contact(source); diff --git a/mobile/src/main/java/com/squareboat/excuser/service/DataLayerListenerService.java b/mobile/src/main/java/com/squareboat/excuser/service/DataLayerListenerService.java index cca4c27..8268702 100644 --- a/mobile/src/main/java/com/squareboat/excuser/service/DataLayerListenerService.java +++ b/mobile/src/main/java/com/squareboat/excuser/service/DataLayerListenerService.java @@ -16,9 +16,9 @@ public class DataLayerListenerService extends WearableListenerService { @Override public void onMessageReceived(MessageEvent messageEvent) { super.onMessageReceived(messageEvent); - Log.e("Message Event", "->"+messageEvent.toString()); + Log.e("Message Event", "->" + messageEvent.toString()); - if("/CALL".equals(messageEvent.getPath())) { + if ("/CALL".equals(messageEvent.getPath())) { Intent intent = new Intent(this, IncomingCallActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent); diff --git a/mobile/src/main/java/com/squareboat/excuser/utils/LocalStoreUtils.java b/mobile/src/main/java/com/squareboat/excuser/utils/LocalStoreUtils.java index 4c34792..24fe124 100644 --- a/mobile/src/main/java/com/squareboat/excuser/utils/LocalStoreUtils.java +++ b/mobile/src/main/java/com/squareboat/excuser/utils/LocalStoreUtils.java @@ -19,12 +19,11 @@ */ public class LocalStoreUtils { - private static GsonBuilder gsonBuilder = new GsonBuilder().setDateFormat("yyyy-MM-dd HH:mm:ss"); - private static Gson gson = gsonBuilder.create(); - private static final String PREF_FILE_NAME = "com.squareboat.excuser"; private static final String KEY_ONBOARDING_DATA = "onboarding_data"; private static final String KEY_CONTACT_DATA = "contact_data"; + private static GsonBuilder gsonBuilder = new GsonBuilder().setDateFormat("yyyy-MM-dd HH:mm:ss"); + private static Gson gson = gsonBuilder.create(); public static void setOnboardingCompleted(boolean value, Context context) { try { @@ -50,7 +49,7 @@ public static void setContacts(List states, Context context) { try { SharedPreferences.Editor editor = getSharedEditor(context); Set set = new HashSet(); - if(states!=null) { + if (states != null) { for (Contact state : states) { set.add(gson.toJson(state)); } @@ -62,10 +61,10 @@ public static void setContacts(List states, Context context) { } } - public static void addContact(Contact contact, Context context){ + public static void addContact(Contact contact, Context context) { List contacts = new ArrayList<>(); - if (getContacts(context)!=null) { + if (getContacts(context) != null) { contacts = getContacts(context); } @@ -73,11 +72,11 @@ public static void addContact(Contact contact, Context context){ setContacts(contacts, context); } - public static void updateContact(Contact contact, Context context){ + public static void updateContact(Contact contact, Context context) { List contacts = getContacts(context); - if (contacts!=null) { - for (int i=0;i contacts = getContacts(context); - if (contacts!=null) { - for (int i=0;i getContacts(Context context) { } //sort contacts alphabetically - if (contacts!=null) { + if (contacts != null) { Collections.sort(contacts, new Comparator() { @Override public int compare(Contact contact, Contact contact1) { diff --git a/mobile/src/main/java/com/squareboat/excuser/utils/StatusBarUtil.java b/mobile/src/main/java/com/squareboat/excuser/utils/StatusBarUtil.java index b9800ed..24210b7 100755 --- a/mobile/src/main/java/com/squareboat/excuser/utils/StatusBarUtil.java +++ b/mobile/src/main/java/com/squareboat/excuser/utils/StatusBarUtil.java @@ -83,7 +83,7 @@ public static void setColorDiff(Activity activity, int color) { /** * 使状态栏半透明 - * + *

* 适用于图片作为背景的界面,此时需要图片填充到状态栏 * * @param activity 需要设置的activity @@ -94,7 +94,7 @@ public static void setTranslucent(Activity activity) { /** * 使状态栏半透明 - * + *

* 适用于图片作为背景的界面,此时需要图片填充到状态栏 * * @param activity 需要设置的activity @@ -123,7 +123,7 @@ public static void setTransparent(Activity activity) { /** * 使状态栏透明(5.0以上半透明效果,不建议使用) - * + *

* 适用于图片作为背景的界面,此时需要图片填充到状态栏 * * @param activity 需要设置的activity diff --git a/mobile/src/main/java/com/squareboat/excuser/widget/SpaceItemDecoration.java b/mobile/src/main/java/com/squareboat/excuser/widget/SpaceItemDecoration.java index 52c2e3f..61a23ca 100755 --- a/mobile/src/main/java/com/squareboat/excuser/widget/SpaceItemDecoration.java +++ b/mobile/src/main/java/com/squareboat/excuser/widget/SpaceItemDecoration.java @@ -3,6 +3,7 @@ /** * Created by Vipul on 10/05/17. */ + import android.graphics.Rect; import android.support.v7.widget.RecyclerView; import android.view.View; diff --git a/mobile/src/main/java/com/squareboat/excuser/widget/textdrawable/TextDrawable.java b/mobile/src/main/java/com/squareboat/excuser/widget/textdrawable/TextDrawable.java index 76a3812..bcfb136 100644 --- a/mobile/src/main/java/com/squareboat/excuser/widget/textdrawable/TextDrawable.java +++ b/mobile/src/main/java/com/squareboat/excuser/widget/textdrawable/TextDrawable.java @@ -19,9 +19,9 @@ */ public class TextDrawable extends ShapeDrawable { + private static final float SHADE_FACTOR = 0.9f; private final Paint textPaint; private final Paint borderPaint; - private static final float SHADE_FACTOR = 0.9f; private final String text; private final int color; private final RectShape shape; @@ -68,10 +68,14 @@ private TextDrawable(Builder builder) { } + public static IShapeBuilder builder() { + return new Builder(); + } + private int getDarkerShade(int color) { - return Color.rgb((int)(SHADE_FACTOR * Color.red(color)), - (int)(SHADE_FACTOR * Color.green(color)), - (int)(SHADE_FACTOR * Color.blue(color))); + return Color.rgb((int) (SHADE_FACTOR * Color.red(color)), + (int) (SHADE_FACTOR * Color.green(color)), + (int) (SHADE_FACTOR * Color.blue(color))); } @Override @@ -101,15 +105,13 @@ public void draw(Canvas canvas) { private void drawBorder(Canvas canvas) { RectF rect = new RectF(getBounds()); - rect.inset(borderThickness/2, borderThickness/2); + rect.inset(borderThickness / 2, borderThickness / 2); if (shape instanceof OvalShape) { canvas.drawOval(rect, borderPaint); - } - else if (shape instanceof RoundRectShape) { + } else if (shape instanceof RoundRectShape) { canvas.drawRoundRect(rect, radius, radius, borderPaint); - } - else { + } else { canvas.drawRect(rect, borderPaint); } } @@ -139,35 +141,62 @@ public int getIntrinsicHeight() { return height; } - public static IShapeBuilder builder() { - return new Builder(); - } + public interface IConfigBuilder { + IConfigBuilder width(int width); - public static class Builder implements IConfigBuilder, IShapeBuilder, IBuilder { + IConfigBuilder height(int height); - private String text; + IConfigBuilder textColor(int color); - private int color; + IConfigBuilder withBorder(int thickness); - private int borderThickness; + IConfigBuilder useFont(Typeface font); - private int width; + IConfigBuilder fontSize(int size); - private int height; + IConfigBuilder bold(); - private Typeface font; + IConfigBuilder toUpperCase(); - private RectShape shape; + IShapeBuilder endConfig(); + } - public int textColor; + public interface IBuilder { - private int fontSize; + TextDrawable build(String text, int color); + } - private boolean isBold; + public interface IShapeBuilder { - private boolean toUpperCase; + IConfigBuilder beginConfig(); + + IBuilder rect(); + + IBuilder round(); + + IBuilder roundRect(int radius); + + TextDrawable buildRect(String text, int color); + + TextDrawable buildRoundRect(String text, int color, int radius); + + TextDrawable buildRound(String text, int color); + } + + public static class Builder implements IConfigBuilder, IShapeBuilder, IBuilder { + public int textColor; public float radius; + private String text; + private int color; + private int borderThickness; + private int width; + private int height; + private Typeface font; + private RectShape shape; + private int fontSize; + private boolean isBold; + private boolean toUpperCase; private Builder() { text = ""; @@ -278,46 +307,4 @@ public TextDrawable build(String text, int color) { return new TextDrawable(this); } } - - public interface IConfigBuilder { - public IConfigBuilder width(int width); - - public IConfigBuilder height(int height); - - public IConfigBuilder textColor(int color); - - public IConfigBuilder withBorder(int thickness); - - public IConfigBuilder useFont(Typeface font); - - public IConfigBuilder fontSize(int size); - - public IConfigBuilder bold(); - - public IConfigBuilder toUpperCase(); - - public IShapeBuilder endConfig(); - } - - public static interface IBuilder { - - public TextDrawable build(String text, int color); - } - - public static interface IShapeBuilder { - - public IConfigBuilder beginConfig(); - - public IBuilder rect(); - - public IBuilder round(); - - public IBuilder roundRect(int radius); - - public TextDrawable buildRect(String text, int color); - - public TextDrawable buildRoundRect(String text, int color, int radius); - - public TextDrawable buildRound(String text, int color); - } } \ No newline at end of file diff --git a/mobile/src/main/java/com/squareboat/excuser/widget/textdrawable/util/ColorGenerator.java b/mobile/src/main/java/com/squareboat/excuser/widget/textdrawable/util/ColorGenerator.java index 2a762a6..e370ec3 100644 --- a/mobile/src/main/java/com/squareboat/excuser/widget/textdrawable/util/ColorGenerator.java +++ b/mobile/src/main/java/com/squareboat/excuser/widget/textdrawable/util/ColorGenerator.java @@ -50,15 +50,15 @@ public class ColorGenerator { private final List mColors; private final Random mRandom; - public static ColorGenerator create(List colorList) { - return new ColorGenerator(colorList); - } - private ColorGenerator(List colorList) { mColors = colorList; mRandom = new Random(System.currentTimeMillis()); } + public static ColorGenerator create(List colorList) { + return new ColorGenerator(colorList); + } + public int getRandomColor() { return mColors.get(mRandom.nextInt(mColors.size())); } diff --git a/settings.gradle b/settings.gradle index 871539e..f2985da 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1 +1 @@ -include ':mobile', ':wear' \ No newline at end of file +include ':mobile', ':wear', ':utils' \ No newline at end of file diff --git a/utils/.gitignore b/utils/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/utils/.gitignore @@ -0,0 +1 @@ +/build diff --git a/utils/build.gradle b/utils/build.gradle new file mode 100644 index 0000000..313ed87 --- /dev/null +++ b/utils/build.gradle @@ -0,0 +1,35 @@ +apply plugin: 'com.android.library' + +android { + compileSdkVersion 26 + buildToolsVersion "26.0.2" + + + defaultConfig { + minSdkVersion 15 + targetSdkVersion 26 + versionCode 1 + versionName "1.0" + + testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } + +} + +dependencies { + compile fileTree(dir: 'libs', include: ['*.jar']) + compile 'com.android.support:appcompat-v7:26.1.0' + testCompile 'junit:junit:4.12' + androidTestCompile('com.android.support.test.espresso:espresso-core:3.0.1', { + exclude group: 'com.android.support', module: 'support-annotations' + }) + +} diff --git a/utils/proguard-rules.pro b/utils/proguard-rules.pro new file mode 100644 index 0000000..f1b4245 --- /dev/null +++ b/utils/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile diff --git a/utils/src/main/AndroidManifest.xml b/utils/src/main/AndroidManifest.xml new file mode 100644 index 0000000..591fde4 --- /dev/null +++ b/utils/src/main/AndroidManifest.xml @@ -0,0 +1 @@ + diff --git a/mobile/src/main/java/com/squareboat/excuser/utils/Utils.java b/utils/src/main/java/com/utils/Utils.java old mode 100755 new mode 100644 similarity index 94% rename from mobile/src/main/java/com/squareboat/excuser/utils/Utils.java rename to utils/src/main/java/com/utils/Utils.java index 4edf969..20481ba --- a/mobile/src/main/java/com/squareboat/excuser/utils/Utils.java +++ b/utils/src/main/java/com/utils/Utils.java @@ -1,4 +1,4 @@ -package com.squareboat.excuser.utils; +package com.utils; import android.app.ActivityManager; import android.content.Context; @@ -45,7 +45,7 @@ public static void hideKeyboardFromView(Context context, View view) { imm.hideSoftInputFromWindow(view.getWindowToken(), 0); } - public static void showKeyboard(Context context, View view){ + public static void showKeyboard(Context context, View view) { InputMethodManager imm = (InputMethodManager) context .getSystemService(Context.INPUT_METHOD_SERVICE); imm.showSoftInput(view, InputMethodManager.SHOW_FORCED); @@ -61,14 +61,14 @@ public static boolean isMyServiceRunning(Context context, Class serviceClass) return false; } - public static String getMetaData(Context context, String metaDataName){ + public static String getMetaData(Context context, String metaDataName) { String metaDataValue = null; try { ApplicationInfo ai = context.getPackageManager().getApplicationInfo(context.getPackageName(), PackageManager.GET_META_DATA); Bundle bundle = ai.metaData; - metaDataValue = bundle.getString(metaDataName); + metaDataValue = bundle.getString(metaDataName); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } @@ -78,4 +78,4 @@ public static String getMetaData(Context context, String metaDataName){ else return metaDataValue; } -} +} \ No newline at end of file diff --git a/wear/build.gradle b/wear/build.gradle index a7d02a6..a57dc2a 100644 --- a/wear/build.gradle +++ b/wear/build.gradle @@ -50,9 +50,10 @@ android { } dependencies { - compile fileTree(dir: 'libs', include: ['*.jar']) + compile fileTree(include: ['*.jar'], dir: 'libs') compile 'com.android.support:wear:26.0.0' provided 'com.google.android.wearable:wearable:2.0.4' compile 'com.google.android.support:wearable:2.0.4' compile 'com.google.android.gms:play-services-wearable:11.0.4' + compile project(':utils') } diff --git a/wear/src/main/java/com/squareboat/excuser/MainWearActivity.java b/wear/src/main/java/com/squareboat/excuser/MainWearActivity.java index fbb79d9..93eae11 100644 --- a/wear/src/main/java/com/squareboat/excuser/MainWearActivity.java +++ b/wear/src/main/java/com/squareboat/excuser/MainWearActivity.java @@ -33,7 +33,6 @@ import com.google.android.wearable.playstore.PlayStoreAvailability; import com.squareboat.excuser.service.AccelerometerSensorService; import com.squareboat.excuser.utils.LocalStoreUtils; -import com.squareboat.excuser.utils.Utils; import java.util.Set; @@ -41,14 +40,28 @@ public class MainWearActivity extends Activity implements GoogleApiClient.Connec GoogleApiClient.OnConnectionFailedListener, CapabilityApi.CapabilityListener { private static final String TAG = "MainWearActivity"; + private static final String CAPABILITY_PHONE_APP = "com_squareboat_excuser_phone_app"; + + // Result from sending RemoteIntent to phone to open app in play/app store. + private final ResultReceiver mResultReceiver = new ResultReceiver(new Handler()) { + @Override + protected void onReceiveResult(int resultCode, Bundle resultData) { + + if (resultCode == RemoteIntent.RESULT_OK) { + new ConfirmationOverlay().showOn(MainWearActivity.this); + + } else if (resultCode == RemoteIntent.RESULT_FAILED) { + new ConfirmationOverlay() + .setType(ConfirmationOverlay.FAILURE_ANIMATION) + .showOn(MainWearActivity.this); + } + } + }; + private ImageView mExcuserImage; private TextView mExcuserStatus; - private Button mInstallAppOnPhone; private GoogleApiClient mGoogleApiClient; private BoxInsetLayout mBoxInsetLayout; - - String CAPABILITY_PHONE_APP = "com_squareboat_excuser_phone_app"; - private Node mAndroidPhoneNodeWithApp; @SuppressLint("LongLogTag") @@ -61,8 +74,8 @@ protected void onCreate(Bundle savedInstanceState) { protected void onStart() { super.onStart(); - if(checkPlayServices()) { - if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.N_MR1) { + if (checkPlayServices()) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) { setGoogleApiClient(); showMissingAppOnPhoneView(); } else { @@ -73,7 +86,9 @@ protected void onStart() { private boolean checkPlayServices() { GoogleApiAvailability apiAvailability = GoogleApiAvailability.getInstance(); + int resultCode = apiAvailability.isGooglePlayServicesAvailable(this); + if (resultCode != ConnectionResult.SUCCESS) { if (apiAvailability.isUserResolvableError(resultCode)) { apiAvailability.getErrorDialog(this, resultCode, 9000, new DialogInterface.OnCancelListener() { @@ -91,17 +106,17 @@ public void onCancel(DialogInterface dialog) { return true; } - private void showMainView(){ + private void showMainView() { setContentView(R.layout.activity_main); - mBoxInsetLayout = (BoxInsetLayout) findViewById(R.id.boxInsetLayout); - mExcuserImage = (ImageView) findViewById(R.id.image_excuser); - mExcuserStatus = (TextView) findViewById(R.id.text_excuser_status); + mBoxInsetLayout = findViewById(R.id.boxInsetLayout); + mExcuserImage = findViewById(R.id.image_excuser); + mExcuserStatus = findViewById(R.id.text_excuser_status); //By default start service - if(LocalStoreUtils.getIsFirstTime(this)) { + if (LocalStoreUtils.getIsFirstTime(this)) { startService(new Intent(getApplicationContext(), AccelerometerSensorService.class)); - LocalStoreUtils.setIsFirstTime(false, this); + LocalStoreUtils.setIsFirstTime(this); } updateView(); @@ -109,7 +124,7 @@ private void showMainView(){ mBoxInsetLayout.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - if(!Utils.isMyServiceRunning(MainWearActivity.this, AccelerometerSensorService.class)) { + if (!Utils.isMyServiceRunning(MainWearActivity.this, AccelerometerSensorService.class)) { startService(new Intent(getApplicationContext(), AccelerometerSensorService.class)); } else { stopService(new Intent(getApplicationContext(), AccelerometerSensorService.class)); @@ -120,10 +135,10 @@ public void onClick(View v) { }); } - private void showMissingAppOnPhoneView(){ + private void showMissingAppOnPhoneView() { setContentView(R.layout.activity_main_missing); - mInstallAppOnPhone = (Button) findViewById(R.id.button_install_phone); + Button mInstallAppOnPhone = findViewById(R.id.button_install_phone); mInstallAppOnPhone.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { @@ -132,7 +147,7 @@ public void onClick(View v) { }); } - private void setGoogleApiClient(){ + private void setGoogleApiClient() { mGoogleApiClient = new GoogleApiClient.Builder(this) .addApi(Wearable.API) .addConnectionCallbacks(this) @@ -140,8 +155,8 @@ private void setGoogleApiClient(){ .build(); } - private void updateView(){ - if(Utils.isMyServiceRunning(MainWearActivity.this, AccelerometerSensorService.class)) { + private void updateView() { + if (Utils.isMyServiceRunning(MainWearActivity.this, AccelerometerSensorService.class)) { mBoxInsetLayout.setBackgroundColor(ContextCompat.getColor(this, R.color.colorPrimary)); mExcuserImage.setColorFilter(ContextCompat.getColor(this, R.color.colorWhite)); @@ -158,6 +173,7 @@ private void updateView(){ @Override public void onPause() { Log.d(TAG, "onPause()"); + super.onPause(); if ((mGoogleApiClient != null) && mGoogleApiClient.isConnected()) { @@ -174,7 +190,9 @@ public void onPause() { @Override public void onResume() { Log.d(TAG, "onResume()"); + super.onResume(); + if (mGoogleApiClient != null) { mGoogleApiClient.connect(); } @@ -258,15 +276,11 @@ private void openAppInStoreOnPhone() { case PlayStoreAvailability.PLAY_STORE_ON_PHONE_AVAILABLE: Log.d(TAG, "\tPLAY_STORE_ON_PHONE_AVAILABLE"); - Intent intentAndroid = - new Intent(Intent.ACTION_VIEW) - .addCategory(Intent.CATEGORY_BROWSABLE) - .setData(Uri.parse(getResources().getString(R.string.app_playstore_url))); + Intent intentAndroid = new Intent(Intent.ACTION_VIEW) + .addCategory(Intent.CATEGORY_BROWSABLE) + .setData(Uri.parse(getResources().getString(R.string.app_playstore_url))); - RemoteIntent.startRemoteActivity( - getApplicationContext(), - intentAndroid, - mResultReceiver); + RemoteIntent.startRemoteActivity(getApplicationContext(), intentAndroid, mResultReceiver); break; // iPhone (iOS device) or Android without Play Store (not supported right now). @@ -280,22 +294,6 @@ private void openAppInStoreOnPhone() { } } - // Result from sending RemoteIntent to phone to open app in play/app store. - private final ResultReceiver mResultReceiver = new ResultReceiver(new Handler()) { - @Override - protected void onReceiveResult(int resultCode, Bundle resultData) { - - if (resultCode == RemoteIntent.RESULT_OK) { - new ConfirmationOverlay().showOn(MainWearActivity.this); - - } else if (resultCode == RemoteIntent.RESULT_FAILED) { - new ConfirmationOverlay() - .setType(ConfirmationOverlay.FAILURE_ANIMATION) - .showOn(MainWearActivity.this); - } - } - }; - private Node pickBestNodeId(Set nodes) { Log.d(TAG, "pickBestNodeId(): " + nodes); @@ -304,6 +302,7 @@ private Node pickBestNodeId(Set nodes) { for (Node node : nodes) { bestNodeId = node; } + return bestNodeId; } } diff --git a/wear/src/main/java/com/squareboat/excuser/service/AccelerometerSensorService.java b/wear/src/main/java/com/squareboat/excuser/service/AccelerometerSensorService.java index 3647a87..a710313 100644 --- a/wear/src/main/java/com/squareboat/excuser/service/AccelerometerSensorService.java +++ b/wear/src/main/java/com/squareboat/excuser/service/AccelerometerSensorService.java @@ -19,11 +19,9 @@ import com.google.android.gms.common.api.GoogleApiClient; import com.google.android.gms.common.api.PendingResult; import com.google.android.gms.common.api.ResultCallback; -import com.google.android.gms.wearable.MessageApi; import com.google.android.gms.wearable.Node; import com.google.android.gms.wearable.NodeApi; import com.google.android.gms.wearable.Wearable; -import com.google.android.gms.wearable.WearableStatusCodes; import com.squareboat.excuser.utils.LocalStoreUtils; import java.util.List; @@ -33,31 +31,22 @@ */ public class AccelerometerSensorService extends Service implements SensorEventListener, GoogleApiClient.ConnectionCallbacks, - GoogleApiClient.OnConnectionFailedListener{ + GoogleApiClient.OnConnectionFailedListener { public static final String TAG = "AccelerometerSensorService"; - - private static float SHAKE_THRESHOLD = 1.1f; private static final int SHAKE_WAIT_TIME_MS = 500; - + private static float SHAKE_THRESHOLD = 1.1f; + IBinder mBinder = new LocalBinder(); private SensorManager mSensorManager; private Sensor mSensor; private long mShakeTime = 0; private GoogleApiClient mGoogleApiClient; - IBinder mBinder = new LocalBinder(); - - public class LocalBinder extends Binder { - public AccelerometerSensorService getServerInstance() { - return AccelerometerSensorService.this; - } - } - @SuppressLint("LongLogTag") @Override public void onCreate() { super.onCreate(); - Log.i(TAG,"onCreate()"); + Log.i(TAG, "onCreate()"); mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE); mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); mSensorManager.registerListener(this, mSensor, SensorManager.SENSOR_DELAY_NORMAL); @@ -79,13 +68,13 @@ public IBinder onBind(Intent intent) { @Override public int onStartCommand(Intent intent, int flags, int startId) { - if(mGoogleApiClient.isConnected()) { - Log.i(TAG+" onStartCommand", "GoogleApiClient Connected"); + if (mGoogleApiClient.isConnected()) { + Log.i(TAG + " onStartCommand", "GoogleApiClient Connected"); return START_STICKY; } - if(!mGoogleApiClient.isConnected() || !mGoogleApiClient.isConnecting()){ - Log.i(TAG+" onStartCommand", "GoogleApiClient not Connected"); + if (!mGoogleApiClient.isConnected() || !mGoogleApiClient.isConnecting()) { + Log.i(TAG + " onStartCommand", "GoogleApiClient not Connected"); mGoogleApiClient.connect(); } @@ -99,7 +88,7 @@ public void onSensorChanged(SensorEvent event) { return; } - if(event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) { + if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) { detectShake(event); } } @@ -115,7 +104,7 @@ public void onAccuracyChanged(Sensor sensor, int accuracy) { private void detectShake(SensorEvent event) { long now = System.currentTimeMillis(); - if((now - mShakeTime) > SHAKE_WAIT_TIME_MS) { + if ((now - mShakeTime) > SHAKE_WAIT_TIME_MS) { mShakeTime = now; float gX = event.values[0] / SensorManager.GRAVITY_EARTH; @@ -123,33 +112,33 @@ private void detectShake(SensorEvent event) { float gZ = event.values[2] / SensorManager.GRAVITY_EARTH; // gForce will be close to 1 when there is no movement - float gForce = (float) Math.sqrt(gX*gX + gY*gY + gZ*gZ); + float gForce = (float) Math.sqrt(gX * gX + gY * gY + gZ * gZ); // Change background color if gForce exceeds threshold; // otherwise, reset the color - if(LocalStoreUtils.getShakeIntensity(this).equals("1")) { + if (LocalStoreUtils.getShakeIntensity(this).equals("1")) { SHAKE_THRESHOLD = 1.1f; } else { SHAKE_THRESHOLD = Float.parseFloat(LocalStoreUtils.getShakeIntensity(this)); } - Log.e("SHAKE_THRESHOLD", "->"+SHAKE_THRESHOLD); + Log.e("SHAKE_THRESHOLD", "->" + SHAKE_THRESHOLD); - if(gForce > SHAKE_THRESHOLD) { + if (gForce > SHAKE_THRESHOLD) { sendShakeEventToPhone(); } } } - private void sendShakeEventToPhone(){ + private void sendShakeEventToPhone() { final PendingResult nodes = Wearable.NodeApi.getConnectedNodes(mGoogleApiClient); nodes.setResultCallback(new ResultCallback() { @Override public void onResult(NodeApi.GetConnectedNodesResult result) { final List nodes = result.getNodes(); if (nodes != null) { - for (int i=0; i"+dataMap.getString(SHAKE_INTENSITY_KEY)); + Log.e("Data Event", "value->" + dataMap.getString(SHAKE_INTENSITY_KEY)); LocalStoreUtils.setShakeIntensity(dataMap.getString(SHAKE_INTENSITY_KEY), this); } } diff --git a/wear/src/main/java/com/squareboat/excuser/utils/LocalStoreUtils.java b/wear/src/main/java/com/squareboat/excuser/utils/LocalStoreUtils.java index 0670ede..1adf576 100644 --- a/wear/src/main/java/com/squareboat/excuser/utils/LocalStoreUtils.java +++ b/wear/src/main/java/com/squareboat/excuser/utils/LocalStoreUtils.java @@ -13,10 +13,10 @@ public class LocalStoreUtils { private static final String KEY_IS_FIRST_TIME = "is_first_time"; private static final String KEY_SHAKE_INTENSITY_DATA = "shake_intensity_data"; - public static void setIsFirstTime(boolean value, Context context) { + public static void setIsFirstTime(Context context) { try { SharedPreferences.Editor editor = getSharedEditor(context); - editor.putBoolean(KEY_IS_FIRST_TIME, value); + editor.putBoolean(KEY_IS_FIRST_TIME, false); editor.commit(); } catch (Exception e) { e.printStackTrace(); diff --git a/wear/src/main/java/com/squareboat/excuser/utils/Utils.java b/wear/src/main/java/com/squareboat/excuser/utils/Utils.java deleted file mode 100755 index 4edf969..0000000 --- a/wear/src/main/java/com/squareboat/excuser/utils/Utils.java +++ /dev/null @@ -1,81 +0,0 @@ -package com.squareboat.excuser.utils; - -import android.app.ActivityManager; -import android.content.Context; -import android.content.pm.ApplicationInfo; -import android.content.pm.PackageManager; -import android.content.res.Resources; -import android.os.Bundle; -import android.util.TypedValue; -import android.view.View; -import android.view.inputmethod.InputMethodManager; - -public class Utils { - - public static int dpToPx(float dp, Context context) { - return dpToPx(dp, context.getResources()); - } - - public static int dpToPx(float dp, Resources resources) { - float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, resources.getDisplayMetrics()); - return (int) px; - } - - public static int getRelativeTop(View myView) { - if (myView.getId() == android.R.id.content) - return myView.getTop(); - else - return myView.getTop() + getRelativeTop((View) myView.getParent()); - } - - public static int getRelativeLeft(View myView) { - if (myView.getId() == android.R.id.content) - return myView.getLeft(); - else - return myView.getLeft() + getRelativeLeft((View) myView.getParent()); - } - - public static int getColorFromResource(int resourceId, Context context) { - return context.getResources().getColor(resourceId); - } - - public static void hideKeyboardFromView(Context context, View view) { - InputMethodManager imm = (InputMethodManager) context - .getSystemService(Context.INPUT_METHOD_SERVICE); - imm.hideSoftInputFromWindow(view.getWindowToken(), 0); - } - - public static void showKeyboard(Context context, View view){ - InputMethodManager imm = (InputMethodManager) context - .getSystemService(Context.INPUT_METHOD_SERVICE); - imm.showSoftInput(view, InputMethodManager.SHOW_FORCED); - } - - public static boolean isMyServiceRunning(Context context, Class serviceClass) { - ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); - for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) { - if (serviceClass.getName().equals(service.service.getClassName())) { - return true; - } - } - return false; - } - - public static String getMetaData(Context context, String metaDataName){ - - String metaDataValue = null; - - try { - ApplicationInfo ai = context.getPackageManager().getApplicationInfo(context.getPackageName(), PackageManager.GET_META_DATA); - Bundle bundle = ai.metaData; - metaDataValue = bundle.getString(metaDataName); - } catch (PackageManager.NameNotFoundException e) { - e.printStackTrace(); - } - - if (metaDataValue == null || metaDataValue.isEmpty()) - throw new NullPointerException(metaDataName + " key must not be null. Set your api key as meta data in AndroidManifest.xml file."); - else - return metaDataValue; - } -}