Guest User

Untitled

a guest
Oct 20th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.52 KB | None | 0 0
  1. public class Main2Activity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {
  2. private static final int SELECT_PHOTO = 100;
  3. private ImageView chooseImage;
  4.  
  5. @Override
  6. protected void onCreate(Bundle savedInstanceState) {
  7. super.onCreate(savedInstanceState);
  8. setContentView(R.layout.content_main);
  9. Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
  10. setSupportActionBar(toolbar);
  11.  
  12. ActivityCompat.requestPermissions(Main2Activity.this, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, 1);
  13. DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
  14. ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
  15. this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
  16. drawer.setDrawerListener(toggle);
  17. toggle.syncState();
  18.  
  19. NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
  20. navigationView.setNavigationItemSelectedListener(this);
  21.  
  22. ImageView startEmergency = (ImageView) (findViewById(R.id.start_emergency));
  23.  
  24. startEmergency.setOnClickListener(new View.OnClickListener() {
  25. @Override
  26. public void onClick(View view) {
  27. Intent emergencyIntent = new Intent(Main2Activity.this, EmergencyActActivity.class);
  28.  
  29. startActivity(emergencyIntent);
  30. }
  31. });
  32.  
  33. TextView myHealth = (TextView) (findViewById(R.id.myHealth));
  34.  
  35. myHealth.setOnClickListener(new View.OnClickListener() {
  36. @Override
  37. public void onClick(View view) {
  38.  
  39. Intent healthIntent = new Intent(Main2Activity.this, HealthActivity.class);
  40.  
  41. startActivity(healthIntent);
  42. }
  43. });
  44.  
  45. /* TextView browse=(TextView) (findViewById(R.id.browse));
  46.  
  47. browse.setOnClickListener(new View.OnClickListener() {
  48. @Override
  49. public void onClick(View view) {
  50.  
  51. Intent browseIntent=new Intent(MainActivity.this, BrowseActivity.class);
  52.  
  53. startActivity(browseIntent);
  54. }
  55. });*/
  56.  
  57. TextView myAccount = (TextView) (findViewById(R.id.myAccount));
  58.  
  59. myAccount.setOnClickListener(new View.OnClickListener() {
  60. @Override
  61. public void onClick(View view) {
  62. Intent accountIntent = new Intent(Main2Activity.this, AccountActivity.class);
  63. startActivity(accountIntent);
  64. }
  65. });
  66. }
  67.  
  68. public void ChooseImage(View v) {
  69. openGallery();
  70. }
  71.  
  72. private void openGallery() {
  73. Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
  74. photoPickerIntent.setType("image/*");
  75. startActivityForResult(photoPickerIntent, SELECT_PHOTO);
  76. }
  77.  
  78. @Override
  79. protected void onActivityResult(int requestCode, int resultCode, Intent data) {
  80. super.onActivityResult(requestCode, resultCode, data);
  81.  
  82. if (requestCode == SELECT_PHOTO && resultCode == RESULT_OK && null != data) {
  83. Uri selectedImage = data.getData();
  84. String[] filePathColumn = {MediaStore.Images.Media.DATA};
  85.  
  86. Cursor cursor = getContentResolver().query(selectedImage,
  87. filePathColumn, null, null, null);
  88. cursor.moveToFirst();
  89.  
  90. int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
  91. String picturePath = cursor.getString(columnIndex);
  92. cursor.close();
  93.  
  94. ImageView imageView = (ImageView) findViewById(R.id.imageButton);
  95. imageView.setImageBitmap(BitmapFactory.decodeFile(picturePath));
  96. }
  97. }
  98.  
  99. @Override
  100. public boolean dispatchTouchEvent(MotionEvent ev) {
  101. if (ev.getAction() == MotionEvent.ACTION_DOWN) {
  102. View v = getCurrentFocus();
  103. if (v instanceof EditText) {
  104. EditText edit = ((EditText) v);
  105. Rect outR = new Rect();
  106. edit.getGlobalVisibleRect(outR);
  107. Boolean isKeyboardOpen = !outR.contains((int) ev.getRawX(), (int) ev.getRawY());
  108. System.out.print("Is Keyboard? " + isKeyboardOpen);
  109. if (isKeyboardOpen) {
  110. System.out.print("Entro al IF");
  111. edit.clearFocus();
  112. InputMethodManager imm = (InputMethodManager) this.getSystemService(Context.INPUT_METHOD_SERVICE);
  113. imm.hideSoftInputFromWindow(edit.getWindowToken(), 0);
  114. }
  115. edit.setCursorVisible(!isKeyboardOpen);
  116. }
  117. }
  118. return super.dispatchTouchEvent(ev);
  119. }
  120.  
  121. @Override
  122. public boolean onCreateOptionsMenu(Menu menu) {
  123. getMenuInflater().inflate(R.menu.menu, menu);
  124.  
  125. MenuItem searchItem = menu.findItem(R.id.search);
  126. MenuItem searchMenuItem = menu.findItem(R.id.search);
  127. if (searchMenuItem == null) {
  128. return true;
  129. }
  130.  
  131. searchItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
  132. @Override
  133. public boolean onMenuItemClick(MenuItem menuItem) {
  134. // Create a Uri from an intent string. Use the result to create an Intent.
  135. Uri gmmIntentUri = Uri.parse("geo:0,0?q=hospitals");
  136.  
  137. // Create an Intent from gmmIntentUri. Set the action to ACTION_VIEW
  138. Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
  139. // Make the Intent explicit by setting the Google Maps package
  140. mapIntent.setPackage("com.google.android.apps.maps");
  141.  
  142. // Attempt to start an activity that can handle the Intent
  143. startActivity(mapIntent);
  144.  
  145. return true;
  146. }
  147. });
  148.  
  149. return true;
  150. }
  151.  
  152. @Override
  153. public void onBackPressed() {
  154. DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
  155. if (drawer.isDrawerOpen(GravityCompat.START)) {
  156. drawer.closeDrawer(GravityCompat.START);
  157. } else {
  158. super.onBackPressed();
  159. }
  160. }
  161.  
  162. @SuppressWarnings("StatementWithEmptyBody")
  163. @Override
  164. public boolean onNavigationItemSelected(MenuItem item) {
  165. // Handle navigation view item clicks here.
  166. int id = item.getItemId();
  167.  
  168. if (id == R.id.nav_camera) {
  169. Intent intent = new Intent(Main2Activity.this, StepsActivity.class);
  170. startActivity(intent);
  171. } else if (id == R.id.nav_gallery) {
  172. } else if (id == R.id.nav_slideshow) {
  173. } else if (id == R.id.nav_manage) {
  174. } else if (id == R.id.nav_share) {
  175. } else if (id == R.id.nav_send) {
  176. }
  177.  
  178. DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
  179. drawer.closeDrawer(GravityCompat.START);
  180. return true;
  181. }
  182. }
  183.  
  184. public class LoginActivity extends AppCompatActivity {
  185.  
  186. public static int APP_REQUEST_CODE = 1;
  187.  
  188. @Override
  189. protected void onCreate(Bundle savedInstanceState) {
  190. super.onCreate(savedInstanceState);
  191. setContentView(R.layout.activity_login);
  192. FontHelper.setCustomTypeface(findViewById(R.id.view_root));
  193.  
  194. // check for an existing access token
  195. AccessToken accessToken = AccountKit.getCurrentAccessToken();
  196. if (accessToken != null) {
  197. // if previously logged in, proceed to the account activity
  198. launchAccountActivity();
  199. }
  200. }
  201.  
  202. @Override
  203. protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
  204. super.onActivityResult(requestCode, resultCode, data);
  205.  
  206. // confirm that this response matches your request
  207. if (requestCode == APP_REQUEST_CODE) {
  208. AccountKitLoginResult loginResult = data.getParcelableExtra(AccountKitLoginResult.RESULT_KEY);
  209. if (loginResult.getError() != null) {
  210. // display login error
  211. String toastMessage = loginResult.getError().getErrorType().getMessage();
  212. Toast.makeText(this, toastMessage, Toast.LENGTH_LONG).show();
  213. } else if (loginResult.getAccessToken() != null) {
  214. // on successful login, proceed to the account activity
  215. launchAccountActivity();
  216. }
  217. }
  218. }
  219.  
  220. private void onLogin(final LoginType loginType) {
  221. // create intent for the Account Kit activity
  222. final Intent intent = new Intent(this, AccountKitActivity.class);
  223.  
  224. // configure login type and response type
  225. AccountKitConfiguration.AccountKitConfigurationBuilder configurationBuilder =
  226. new AccountKitConfiguration.AccountKitConfigurationBuilder(
  227. loginType,
  228. AccountKitActivity.ResponseType.TOKEN
  229. );
  230. final AccountKitConfiguration configuration = configurationBuilder.build();
  231.  
  232. // launch the Account Kit activity
  233. intent.putExtra(AccountKitActivity.ACCOUNT_KIT_ACTIVITY_CONFIGURATION, configuration);
  234. startActivityForResult(intent, APP_REQUEST_CODE);
  235. }
  236.  
  237. public void onPhoneLogin(View view) {
  238. AppEventsLogger logger = AppEventsLogger.newLogger(this);
  239. logger.logEvent("onPhoneLogin");
  240.  
  241. onLogin(LoginType.PHONE);
  242. }
  243.  
  244. public void onEmailLogin(View view) {
  245. AppEventsLogger logger = AppEventsLogger.newLogger(this);
  246. logger.logEvent("onEmailLogin");
  247.  
  248. onLogin(LoginType.EMAIL);
  249. }
  250.  
  251. private void launchAccountActivity() {
  252. Intent intent = new Intent(LoginActivity.this, Main2Activity.class);
  253. startActivity(intent);
  254. }
  255. }
Add Comment
Please, Sign In to add comment