Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Main2Activity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {
- private static final int SELECT_PHOTO = 100;
- private ImageView chooseImage;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.content_main);
- Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
- setSupportActionBar(toolbar);
- ActivityCompat.requestPermissions(Main2Activity.this, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, 1);
- DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
- ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
- this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
- drawer.setDrawerListener(toggle);
- toggle.syncState();
- NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
- navigationView.setNavigationItemSelectedListener(this);
- ImageView startEmergency = (ImageView) (findViewById(R.id.start_emergency));
- startEmergency.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- Intent emergencyIntent = new Intent(Main2Activity.this, EmergencyActActivity.class);
- startActivity(emergencyIntent);
- }
- });
- TextView myHealth = (TextView) (findViewById(R.id.myHealth));
- myHealth.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- Intent healthIntent = new Intent(Main2Activity.this, HealthActivity.class);
- startActivity(healthIntent);
- }
- });
- /* TextView browse=(TextView) (findViewById(R.id.browse));
- browse.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- Intent browseIntent=new Intent(MainActivity.this, BrowseActivity.class);
- startActivity(browseIntent);
- }
- });*/
- TextView myAccount = (TextView) (findViewById(R.id.myAccount));
- myAccount.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- Intent accountIntent = new Intent(Main2Activity.this, AccountActivity.class);
- startActivity(accountIntent);
- }
- });
- }
- public void ChooseImage(View v) {
- openGallery();
- }
- private void openGallery() {
- Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
- photoPickerIntent.setType("image/*");
- startActivityForResult(photoPickerIntent, SELECT_PHOTO);
- }
- @Override
- protected void onActivityResult(int requestCode, int resultCode, Intent data) {
- super.onActivityResult(requestCode, resultCode, data);
- if (requestCode == SELECT_PHOTO && resultCode == RESULT_OK && null != data) {
- Uri selectedImage = data.getData();
- String[] filePathColumn = {MediaStore.Images.Media.DATA};
- Cursor cursor = getContentResolver().query(selectedImage,
- filePathColumn, null, null, null);
- cursor.moveToFirst();
- int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
- String picturePath = cursor.getString(columnIndex);
- cursor.close();
- ImageView imageView = (ImageView) findViewById(R.id.imageButton);
- imageView.setImageBitmap(BitmapFactory.decodeFile(picturePath));
- }
- }
- @Override
- public boolean dispatchTouchEvent(MotionEvent ev) {
- if (ev.getAction() == MotionEvent.ACTION_DOWN) {
- View v = getCurrentFocus();
- if (v instanceof EditText) {
- EditText edit = ((EditText) v);
- Rect outR = new Rect();
- edit.getGlobalVisibleRect(outR);
- Boolean isKeyboardOpen = !outR.contains((int) ev.getRawX(), (int) ev.getRawY());
- System.out.print("Is Keyboard? " + isKeyboardOpen);
- if (isKeyboardOpen) {
- System.out.print("Entro al IF");
- edit.clearFocus();
- InputMethodManager imm = (InputMethodManager) this.getSystemService(Context.INPUT_METHOD_SERVICE);
- imm.hideSoftInputFromWindow(edit.getWindowToken(), 0);
- }
- edit.setCursorVisible(!isKeyboardOpen);
- }
- }
- return super.dispatchTouchEvent(ev);
- }
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- getMenuInflater().inflate(R.menu.menu, menu);
- MenuItem searchItem = menu.findItem(R.id.search);
- MenuItem searchMenuItem = menu.findItem(R.id.search);
- if (searchMenuItem == null) {
- return true;
- }
- searchItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
- @Override
- public boolean onMenuItemClick(MenuItem menuItem) {
- // Create a Uri from an intent string. Use the result to create an Intent.
- Uri gmmIntentUri = Uri.parse("geo:0,0?q=hospitals");
- // Create an Intent from gmmIntentUri. Set the action to ACTION_VIEW
- Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
- // Make the Intent explicit by setting the Google Maps package
- mapIntent.setPackage("com.google.android.apps.maps");
- // Attempt to start an activity that can handle the Intent
- startActivity(mapIntent);
- return true;
- }
- });
- return true;
- }
- @Override
- public void onBackPressed() {
- DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
- if (drawer.isDrawerOpen(GravityCompat.START)) {
- drawer.closeDrawer(GravityCompat.START);
- } else {
- super.onBackPressed();
- }
- }
- @SuppressWarnings("StatementWithEmptyBody")
- @Override
- public boolean onNavigationItemSelected(MenuItem item) {
- // Handle navigation view item clicks here.
- int id = item.getItemId();
- if (id == R.id.nav_camera) {
- Intent intent = new Intent(Main2Activity.this, StepsActivity.class);
- startActivity(intent);
- } else if (id == R.id.nav_gallery) {
- } else if (id == R.id.nav_slideshow) {
- } else if (id == R.id.nav_manage) {
- } else if (id == R.id.nav_share) {
- } else if (id == R.id.nav_send) {
- }
- DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
- drawer.closeDrawer(GravityCompat.START);
- return true;
- }
- }
- public class LoginActivity extends AppCompatActivity {
- public static int APP_REQUEST_CODE = 1;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_login);
- FontHelper.setCustomTypeface(findViewById(R.id.view_root));
- // check for an existing access token
- AccessToken accessToken = AccountKit.getCurrentAccessToken();
- if (accessToken != null) {
- // if previously logged in, proceed to the account activity
- launchAccountActivity();
- }
- }
- @Override
- protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
- super.onActivityResult(requestCode, resultCode, data);
- // confirm that this response matches your request
- if (requestCode == APP_REQUEST_CODE) {
- AccountKitLoginResult loginResult = data.getParcelableExtra(AccountKitLoginResult.RESULT_KEY);
- if (loginResult.getError() != null) {
- // display login error
- String toastMessage = loginResult.getError().getErrorType().getMessage();
- Toast.makeText(this, toastMessage, Toast.LENGTH_LONG).show();
- } else if (loginResult.getAccessToken() != null) {
- // on successful login, proceed to the account activity
- launchAccountActivity();
- }
- }
- }
- private void onLogin(final LoginType loginType) {
- // create intent for the Account Kit activity
- final Intent intent = new Intent(this, AccountKitActivity.class);
- // configure login type and response type
- AccountKitConfiguration.AccountKitConfigurationBuilder configurationBuilder =
- new AccountKitConfiguration.AccountKitConfigurationBuilder(
- loginType,
- AccountKitActivity.ResponseType.TOKEN
- );
- final AccountKitConfiguration configuration = configurationBuilder.build();
- // launch the Account Kit activity
- intent.putExtra(AccountKitActivity.ACCOUNT_KIT_ACTIVITY_CONFIGURATION, configuration);
- startActivityForResult(intent, APP_REQUEST_CODE);
- }
- public void onPhoneLogin(View view) {
- AppEventsLogger logger = AppEventsLogger.newLogger(this);
- logger.logEvent("onPhoneLogin");
- onLogin(LoginType.PHONE);
- }
- public void onEmailLogin(View view) {
- AppEventsLogger logger = AppEventsLogger.newLogger(this);
- logger.logEvent("onEmailLogin");
- onLogin(LoginType.EMAIL);
- }
- private void launchAccountActivity() {
- Intent intent = new Intent(LoginActivity.this, Main2Activity.class);
- startActivity(intent);
- }
- }
Add Comment
Please, Sign In to add comment