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

RM14476 - Lab level 3. Services #19

Open
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

eteplyakov
Copy link
Owner

@Antor
Copy link
Collaborator

Antor commented Mar 14, 2014

There is no need in showing notification when calculation canceled. Just dismiss Ongoing Notification.

@Antor
Copy link
Collaborator

Antor commented Mar 14, 2014

It shall not be possible to swipe out Ongoing Notification with calculation progress.

@Antor
Copy link
Collaborator

Antor commented Mar 14, 2014

Let's place precision selector and Start/Cancel button in center of screen

return complete.digest();
}

public static String getMD5Checksum(String filename) throws Exception {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Public methods have to be placed before private in class.
Also not a best name for method. It would be better to rename it to calculateMD5ChecksumForFile

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also I think that there is no need in two methods - all code can be put in single method with appropriate comments where required

import java.io.InputStream;
import java.security.MessageDigest;

public class MD5CheckSum {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Such kind of classes with only static helper methods is appropriate to name with postfix ...Utils.
For this class it would be MD5ChecksumUtils or ChecksumUtils

…3_Services

Conflicts:
	CustomView/.classpath
	SMSResponder/.classpath
	SMSResponder/res/values/styles.xml

public class MD5CheckSum {

private static byte[] createChecksum(String filename) throws Exception {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's bad idea in most cases to declare that method just throws Exception
In fact it have to be little bit more detailed throws NoSuchAlgorithmException, IOException
or even throws NoSuchAlgorithmException, FileNotFoundException, IOException
This way code that calling this method will have possibility to handle each type of exception appropriately.

@Antor
Copy link
Collaborator

Antor commented Mar 17, 2014

After first install on device when I'm trying to start calculations app crashes with next stack trace
03-17 16:40:13.530: E/AndroidRuntime(5814): FATAL EXCEPTION: main
03-17 16:40:13.530: E/AndroidRuntime(5814): java.lang.IllegalStateException: Could not execute method of the activity
03-17 16:40:13.530: E/AndroidRuntime(5814): at android.view.View$1.onClick(View.java:3606)
03-17 16:40:13.530: E/AndroidRuntime(5814): at android.view.View.performClick(View.java:4211)
03-17 16:40:13.530: E/AndroidRuntime(5814): at android.view.View$PerformClick.run(View.java:17446)
03-17 16:40:13.530: E/AndroidRuntime(5814): at android.os.Handler.handleCallback(Handler.java:725)
03-17 16:40:13.530: E/AndroidRuntime(5814): at android.os.Handler.dispatchMessage(Handler.java:92)
03-17 16:40:13.530: E/AndroidRuntime(5814): at android.os.Looper.loop(Looper.java:153)
03-17 16:40:13.530: E/AndroidRuntime(5814): at android.app.ActivityThread.main(ActivityThread.java:5299)
03-17 16:40:13.530: E/AndroidRuntime(5814): at java.lang.reflect.Method.invokeNative(Native Method)
03-17 16:40:13.530: E/AndroidRuntime(5814): at java.lang.reflect.Method.invoke(Method.java:511)
03-17 16:40:13.530: E/AndroidRuntime(5814): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
03-17 16:40:13.530: E/AndroidRuntime(5814): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
03-17 16:40:13.530: E/AndroidRuntime(5814): at dalvik.system.NativeStart.main(Native Method)
03-17 16:40:13.530: E/AndroidRuntime(5814): Caused by: java.lang.reflect.InvocationTargetException
03-17 16:40:13.530: E/AndroidRuntime(5814): at java.lang.reflect.Method.invokeNative(Native Method)
03-17 16:40:13.530: E/AndroidRuntime(5814): at java.lang.reflect.Method.invoke(Method.java:511)
03-17 16:40:13.530: E/AndroidRuntime(5814): at android.view.View$1.onClick(View.java:3601)
03-17 16:40:13.530: E/AndroidRuntime(5814): ... 11 more
03-17 16:40:13.530: E/AndroidRuntime(5814): Caused by: java.lang.NullPointerException
03-17 16:40:13.530: E/AndroidRuntime(5814): at com.example.picalculator.MainActivity.onStartClicked(MainActivity.java:158)
03-17 16:40:13.530: E/AndroidRuntime(5814): ... 14 more

import android.widget.Spinner;
import android.widget.TextView;

public class MainActivity extends Activity {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this file there are unused imports which should be deleted (try to use ctrl+O shortcut =)

@Antor
Copy link
Collaborator

Antor commented Mar 18, 2014

All IO operations have to be done asynchronously outside of main thread.
For example com.example.picalculator.MainActivity.readFromFile(String) or com.example.picalculator.MainActivity.isMD5Checked(String)

@Antor
Copy link
Collaborator

Antor commented Mar 18, 2014

Algorithm is still slow. It's about 10 times slower then Super Pi
On Nexus 4[PI with 1M precision]:
Super PI: 17.2 s
Pi calculator: 158 s

Intent intent = new Intent(this, PiCalculateService.class);
intent.putExtra(PiCalculateService.PRECISION_KEY, precisions_.getSelectedItem().toString());
startService(intent);
File dir = new File(Environment.getExternalStorageDirectory().toString() + "/cash_pi");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to store all calculated PI values in Context.getExternalFilesDir("calculated_pi_values"); This folder will be deleted on app uninstall. Read more about it in JavaDocs

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

=) Be careful with typos. Cash means money. You've probably meant cache.

@Antor
Copy link
Collaborator

Antor commented Mar 18, 2014

Please, extract all PI calculation logic into separate class. Also mention algorithm which you're using to calculate PI and link to where you've found it.

result = String.copyValueOf(charString);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do proper Exception handling here. At least show toast to user with appropriate error message.

@Antor
Copy link
Collaborator

Antor commented Mar 18, 2014

Try to use enum for listing all Precisions. In Java enum is fully functional object

@Antor
Copy link
Collaborator

Antor commented Mar 18, 2014

Hash sum check for calculated PI value have to be part of service work, not MainActivity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants