-
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 4 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 |
|---|---|---|
|
|
@@ -6,7 +6,7 @@ | |
| import android.support.v4.app.FragmentManager; | ||
| import android.support.v7.app.AppCompatActivity; | ||
| import android.os.Bundle; | ||
| import android.util.Log; | ||
| import android.view.MotionEvent; | ||
| import android.view.View; | ||
|
|
||
| import com.example.anna.myapplication.R; | ||
|
|
@@ -18,6 +18,7 @@ public class PersonListActivity extends AppCompatActivity { | |
| private Fragment fragment; | ||
| private Fragment newFragment; | ||
| private long personId = -1; | ||
| private float downX, downY; | ||
|
|
||
| @Override | ||
| protected void onCreate(Bundle savedInstanceState) { | ||
|
|
@@ -132,4 +133,45 @@ public void openFragment2 (long personId_) { | |
|
|
||
| findViewById(R.id.fragmentContainer2).setVisibility(View.VISIBLE); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean onTouchEvent(MotionEvent event) { | ||
|
||
| super.onTouchEvent(event); | ||
|
|
||
| switch (event.getAction()) { | ||
| case MotionEvent.ACTION_DOWN: | ||
| downX = event.getX(); | ||
| downY = event.getY(); | ||
| break; | ||
| case MotionEvent.ACTION_UP: | ||
| case MotionEvent.ACTION_CANCEL: | ||
| float upX = event.getX(); | ||
| float upY = event.getY(); | ||
|
|
||
| float deltaX = downX - upX; | ||
| float deltaY = downY - upY; | ||
| if ((Math.abs(deltaY) > Math.abs(deltaX)) && (deltaY < 0)) { | ||
|
|
||
| personId = -1; | ||
|
|
||
| if (findViewById(R.id.fragmentContainer2).getVisibility() == View.VISIBLE) { | ||
|
||
| findViewById(R.id.fragmentContainer2).setVisibility(View.GONE); | ||
|
|
||
| fragment = fragmentManager.findFragmentById(R.id.fragmentContainer1); | ||
| newFragment = new PersonListFragment(); | ||
|
|
||
| if (fragment == null) { | ||
| fragmentManager.beginTransaction() | ||
| .addToBackStack(null) | ||
| .add(R.id.fragmentContainer1, newFragment) | ||
| .commit(); | ||
| } | ||
|
|
||
| findViewById(R.id.fragmentContainer1).setVisibility(View.VISIBLE); | ||
| } | ||
| } | ||
| break; | ||
| } | ||
| 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 лучше