-
Notifications
You must be signed in to change notification settings - Fork 0
DevAndroidMotionAndRelease #5
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
base: master
Are you sure you want to change the base?
Changes from 6 commits
2eaf6a8
54c7b82
0f50416
8edf0fa
dd2572c
0206917
25a59eb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,3 +8,5 @@ | |
| /captures | ||
| .externalNativeBuild | ||
| /.idea | ||
| /keystores/release.properties | ||
| /keystores/release_keystore.jks | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| package com.example.anna.myapplication.data; | ||
|
|
||
| import java.io.FileInputStream; | ||
| import java.io.FileOutputStream; | ||
|
|
||
| import android.app.IntentService; | ||
| import android.content.Context; | ||
| import android.content.Intent; | ||
| import android.widget.Toast; | ||
|
|
||
| import com.example.anna.myapplication.presentation.MyApplication; | ||
|
|
||
| public class LoadDatabaseIntentService extends IntentService { | ||
|
|
||
| private FileOutputStream fileOutputStream = null; | ||
|
|
||
| public LoadDatabaseIntentService() { | ||
| super("LoadDatabaseIntentService"); | ||
| } | ||
|
|
||
| @Override | ||
| protected void onHandleIntent(Intent intent) { | ||
| if (intent != null) { | ||
| String databaseBackup = MyApplication.getPersonDao().loadAll().toString(); | ||
| String fileName = intent.getStringExtra("fileName"); | ||
| try { | ||
| fileOutputStream = openFileOutput(fileName, Context.MODE_PRIVATE); | ||
| fileOutputStream.write(databaseBackup.getBytes()); | ||
| fileOutputStream.close(); | ||
| } catch (Exception e) { | ||
| Toast toast = Toast.makeText(this, "An error occurred while writing database", Toast.LENGTH_LONG); | ||
| toast.show(); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| package com.example.anna.myapplication.presentation; | ||
|
|
||
| import android.content.Intent; | ||
| import android.support.v7.app.AppCompatActivity; | ||
| import android.os.Bundle; | ||
| import android.widget.Button; | ||
| import android.widget.TextView; | ||
|
|
||
| import com.example.anna.myapplication.R; | ||
|
|
||
| import java.io.FileInputStream; | ||
|
|
||
| public class IntentServiceActivity extends AppCompatActivity { | ||
|
|
||
| private TextView DatabaseTextView; | ||
| private Button DatabaseLoadButton, nextButton, backButton; | ||
|
|
||
|
|
||
| @Override | ||
| protected void onCreate(Bundle savedInstanceState) { | ||
| super.onCreate(savedInstanceState); | ||
| setContentView(R.layout.intent_service); | ||
|
|
||
| DatabaseTextView = (TextView) findViewById(R.id.textView); | ||
|
|
||
| DatabaseLoadButton = (Button) findViewById(R.id.loadDatabaseButton); | ||
| DatabaseLoadButton.setOnClickListener(view -> { | ||
| StringBuilder stringBuilder = new StringBuilder(); | ||
| try{ | ||
| FileInputStream fstream = openFileInput(MyApplication.getFileName()); | ||
| int i; | ||
| while ((i = fstream.read())!= -1){ | ||
| stringBuilder.append((char)i); | ||
| } | ||
| fstream.close(); | ||
| DatabaseTextView.setText(stringBuilder.toString()); | ||
| }catch (Exception e){ | ||
| DatabaseTextView.setText(getResources().getString(R.string.error_load_database)); | ||
| } | ||
|
|
||
| }); | ||
|
|
||
| nextButton = findViewById(R.id.nextScreenButton); | ||
| nextButton.setOnClickListener(view -> { | ||
| Intent startActivity = new Intent(this, TouchActivity.class); | ||
| startActivity(startActivity); | ||
| }); | ||
|
|
||
| backButton = findViewById(R.id.to_first_activity_button); | ||
| backButton.setOnClickListener(view -> { | ||
| Intent startActivity = new Intent(this, MainActivity.class); | ||
| startActivity(startActivity); | ||
| }); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,8 +5,11 @@ | |
| import android.os.AsyncTask; | ||
| import android.os.Bundle; | ||
| import android.support.v4.app.Fragment; | ||
| import android.support.v4.view.GestureDetectorCompat; | ||
| import android.view.GestureDetector; | ||
| import android.view.KeyEvent; | ||
| import android.view.LayoutInflater; | ||
| import android.view.MotionEvent; | ||
| import android.view.View; | ||
| import android.view.ViewGroup; | ||
| import android.widget.EditText; | ||
|
|
@@ -17,14 +20,17 @@ | |
| import com.facebook.drawee.view.SimpleDraweeView; | ||
| import static android.app.Activity.RESULT_OK; | ||
|
|
||
| public class PersonDetailFragment extends Fragment { | ||
| public class PersonDetailFragment extends Fragment implements | ||
| GestureDetector.OnGestureListener, | ||
| GestureDetector.OnDoubleTapListener{ | ||
|
|
||
| private static EditText editText; | ||
| private SimpleDraweeView imageView; | ||
| private TextView birthdayTextView, personTextView; | ||
| private static final String ARG_DESCRIPTION = "description"; | ||
| private static final String ARG_PERSON_ID = "personId"; | ||
| private long personId = -1; | ||
| private GestureDetectorCompat gestureDetectorCompat; | ||
|
|
||
| @Override | ||
| public View onCreateView(LayoutInflater inflater, ViewGroup container, | ||
|
|
@@ -61,6 +67,15 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, | |
| if (savedInstanceState != null) { | ||
| editText.setText(savedInstanceState.getString(ARG_DESCRIPTION)); | ||
| } | ||
|
|
||
| gestureDetectorCompat = new GestureDetectorCompat(getContext(),this); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. вместо того, чтобы имплеметировать все методы, можно подать в аргументы SimpleGestureListener и имплементировать только нужный метод onFling |
||
| gestureDetectorCompat.setOnDoubleTapListener(this); | ||
|
|
||
| view.setOnTouchListener(new View.OnTouchListener() { | ||
| public boolean onTouch(View v, MotionEvent event) { | ||
| return gestureDetectorCompat.onTouchEvent(event); | ||
| } | ||
| }); | ||
| return view; | ||
| } | ||
|
|
||
|
|
@@ -91,12 +106,12 @@ protected Person doInBackground(final String... strings) { | |
| MyApplication.getPersonDao().update(person); | ||
|
|
||
| // SQLite | ||
| /* ContentValues updatedValues = new ContentValues(); | ||
| updatedValues.put(AppSQLiteOpenHelper.Columns.BIRTHDAY, birthday); | ||
| MyApplication.personRepository.update( | ||
| personId, | ||
| updatedValues); | ||
| */ | ||
| /* ContentValues updatedValues = new ContentValues(); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. А почему код закоментирован? Если он не нужен, то надо удалить |
||
| updatedValues.put(AppSQLiteOpenHelper.Columns.BIRTHDAY, birthday); | ||
| MyApplication.personRepository.update( | ||
| personId, | ||
| updatedValues); | ||
| */ | ||
| return person; | ||
| } | ||
|
|
||
|
|
@@ -158,4 +173,51 @@ protected void onPostExecute(final Person person) { | |
| editText.setText(person.getNote()); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public boolean onScroll(MotionEvent event1, MotionEvent event2, float distanceX, float distanceY) { | ||
| return true; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean onDoubleTapEvent(MotionEvent event) { | ||
| return true; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean onSingleTapConfirmed(MotionEvent event) { | ||
| return true; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean onDown(MotionEvent event) { | ||
| return true; | ||
| } | ||
|
|
||
| @Override | ||
| public void onShowPress(MotionEvent event) {} | ||
|
|
||
| @Override | ||
| public void onLongPress(MotionEvent event) {} | ||
|
|
||
| @Override | ||
| public boolean onDoubleTap(MotionEvent event) { | ||
| return true; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean onFling(MotionEvent event1, MotionEvent event2, | ||
| float velocityX, float velocityY) { | ||
| float deltaX = event1.getX() - event2.getX(); | ||
| float deltaY = event1.getY() - event2.getY(); | ||
| if ((Math.abs(deltaY) > Math.abs(deltaX)) && (deltaY < 0)) { | ||
| getActivity().onBackPressed(); | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean onSingleTapUp(MotionEvent event) { | ||
| return true; | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Так неправильно закрывать stream. Используй try with resources лучше