Beispiel #1
0
 private void setUpNavView() {
   if (navigationDrawer != null) {
     navigationView = (NavigationView) findViewById(R.id.navigation_view);
     TextView name = (TextView) navigationView.getHeaderView(0).findViewById(R.id.account_name);
     name.setText(getPref(App.PREF_USER_NAME));
     TextView email = (TextView) navigationView.getHeaderView(0).findViewById(R.id.account_email);
     email.setText(getPref(App.PREF_USER_EMAIL));
     navigationView.setNavigationItemSelectedListener(
         new NavigationView.OnNavigationItemSelectedListener() {
           @Override
           public boolean onNavigationItemSelected(MenuItem menuItem) {
             menuItem.setChecked(true);
             switch (menuItem.getItemId()) {
               case R.id.navigation_item_1:
                 mCurrentSelectedPosition = 0;
                 navigationDrawer.closeDrawers();
                 return true;
               case R.id.navigation_item_2:
                 mCurrentSelectedPosition = 1;
                 navigationDrawer.closeDrawers();
                 return true;
               default:
                 return true;
             }
           }
         });
   }
 }
  private void findUI() {

    devDialog = new AlertDialog.Builder(ForecastActivity.this, R.style.AppCompatAlertDialogStyle);
    devDialog.setTitle("Печеньку?");
    devDialog.setMessage("К сожалению раздел находится в разработке...");
    devDialog.setPositiveButton(
        "ОК",
        new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialogInterface, int i) {
            dialogInterface.dismiss();
          }
        });

    toolbar = (Toolbar) findViewById(R.id.toolbar);
    drawerLayout = (DrawerLayoutWithViewPager) findViewById(R.id.drawer_layout);
    navigationView = (NavigationView) findViewById(R.id.nav_view);
    b_cities = navigationView.getHeaderView(0).findViewById(R.id.b_cities);
    pagerMaterial = (ViewPager) navigationView.getHeaderView(0).findViewById(R.id.pager_material);
    pagerCity = (ViewPager) navigationView.getHeaderView(0).findViewById(R.id.pager_city);

    topbar = (LinearLayout) drawerLayout.findViewById(R.id.topbar);
    summary_box = (LinearLayout) drawerLayout.findViewById(R.id.summary_box);
    summary_city = (TextView) drawerLayout.findViewById(R.id.city);
    summary_daily = (TextView) drawerLayout.findViewById(R.id.summary);
    // summary_hourly = (TextView) drawerLayout.findViewById(R.id.summary_hourly);
    summary_city.startAnimation(AnimationUtils.loadAnimation(this, R.anim.fadein));
    summary_daily.startAnimation(AnimationUtils.loadAnimation(this, R.anim.fadein));

    scroll = (SwipeRefreshLayout) drawerLayout.findViewById(R.id.scroll);
    scroll.setProgressViewOffset(false, -100, 100);
  }
  private void setupDrawer() {
    View headerLayout = mNavigationView.getHeaderView(0);
    TextView userName = (TextView) headerLayout.findViewById(R.id.user_name_txt);
    TextView userEmail = (TextView) headerLayout.findViewById(R.id.user_email_txt);
    userName.setText(mDataManager.getPreferencesManager().getUserName());
    userEmail.setText(mDataManager.getPreferencesManager().getEmail());

    setRoundedAvatar();

    mNavigationView.setNavigationItemSelectedListener(
        new NavigationView.OnNavigationItemSelectedListener() {
          @Override
          public boolean onNavigationItemSelected(MenuItem item) {
            switch (item.getItemId()) {
              case R.id.team_menu:
                mNavigationDrawer.closeDrawer(GravityCompat.START);
                break;
              case R.id.user_profile_menu:
                Intent profileIntent = new Intent(UserListActivity.this, MainActivity.class);
                startActivity(profileIntent);
                mNavigationDrawer.closeDrawer(GravityCompat.START);
                break;
              case R.id.exit_menu:
                mDataManager.getPreferencesManager().saveAuthToken("");
                Intent exitIntent = new Intent(UserListActivity.this, AuthActivity.class);
                startActivity(exitIntent);
            }
            return true;
          }
        });
  }
Beispiel #4
0
  @Override
  protected void initView() {
    toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View view) {
            Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                .setAction("Action", null)
                .show();
          }
        });

    drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    toggle =
        new ActionBarDrawerToggle(
            this,
            drawer,
            toolbar,
            R.string.navigation_drawer_open,
            R.string.navigation_drawer_close);
    drawer.setDrawerListener(toggle);
    toggle.syncState();

    navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);

    View headerView = navigationView.getHeaderView(0);
    avatar = (ImageView) headerView.findViewById(R.id.imageView);
    avatar.setOnClickListener(this);
    switch2News();
  }
  /**
   * Initializes the activity and the view of the main page
   *
   * @param savedInstanceState
   */
  @Override
  protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    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);

    navHeaderLayout = navigationView.getHeaderView(0);

    // ATTENTION: This was auto-generated to implement the App Indexing API.
    // See https://g.co/AppIndexing/AndroidStudio for more information.
    client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    mUserPreference = new UserPreference(MainActivity.this);

    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);

    View headerView = navigationView.getHeaderView(0);
    TextView txtUsername = (TextView) headerView.findViewById(R.id.txt_username);
    TextView txtEmail = (TextView) headerView.findViewById(R.id.txt_email);

    txtUsername.setText(mUserPreference.getName());
    txtEmail.setText(mUserPreference.getEmail());

    if (mCurrentLocationFragment == null) {
      mCurrentLocationFragment = new CurrentLocationFragment();
    }
    setUpFragment(mCurrentLocationFragment, CurrentLocationFragment.class.getSimpleName());
  }
 private void setRoundedAvatar() {
   View headerLayout = mNavigationView.getHeaderView(0);
   ImageView avatarImg = (ImageView) headerLayout.findViewById(R.id.avatar);
   Bitmap bitmap = BitmapFactory.decodeResource(this.getResources(), R.drawable.avatar);
   RoundedDrawable roundedDrawable = new RoundedDrawable(bitmap);
   avatarImg.setImageDrawable(roundedDrawable);
 }
Beispiel #8
0
  private void setupDrawerContent(final NavigationView navigationView) {
    navigationView
        .getHeaderView(0)
        .findViewById(R.id.nav_weibo)
        .setOnClickListener(
            v -> {
              ClipboardHelper.copy(MainActivity.this, getResources().getString(R.string.weibo));
              ToastUtil.showShortToast("微博地址[http://weibo.com/123466678]已经复制到剪贴板╮(╯_╰)╭");
            });
    navigationView.setNavigationItemSelectedListener(
        menuItem -> {
          switch (menuItem.getItemId()) {
            case R.id.nav_avatar:
            case R.id.nav_weibo:
              break;
            case R.id.nav_all:
              viewPager.setCurrentItem(0);
              drawerLayout.closeDrawers();
              break;
            case R.id.nav_mm:
              viewPager.setCurrentItem(1);
              drawerLayout.closeDrawers();
              break;
            case R.id.nav_android:
              viewPager.setCurrentItem(2);
              drawerLayout.closeDrawers();
              break;
            case R.id.nav_ios:
              viewPager.setCurrentItem(3);
              drawerLayout.closeDrawers();
              break;
            case R.id.nav_github:
              drawerLayout.closeDrawers();
              jump2Url("https://github.com/login");
              break;
            case R.id.nav_trending:
              drawerLayout.closeDrawers();
              jump2Url("https://github.com/trending?l=java");
              break;
            case R.id.nav_about:
              drawerLayout.closeDrawers();
              startActivity(new Intent(this, AboutActivity.class));
              break;

            default:
              return true;
          }
          return true;
        });
  }
Beispiel #9
0
  private void initView() {
    // MainActivity的布局文件中的主要控件初始化
    mToolbar = (Toolbar) this.findViewById(R.id.tool_bar);
    mDrawerLayout = (DrawerLayout) this.findViewById(R.id.drawer_layout);
    mNavigationView = (NavigationView) this.findViewById(R.id.navigation_view);
    headerView = mNavigationView.getHeaderView(0);
    header_userimg = (CricleImageView) headerView.findViewById(R.id.header_userimg);
    header_username = (TextView) headerView.findViewById(R.id.header_username);
    // 初始化ToolBar
    setSupportActionBar(mToolbar);
    ActionBar actionBar = getSupportActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setHomeAsUpIndicator(R.drawable.all);
    // 对NavigationView添加item的监听事件
    mNavigationView.setNavigationItemSelectedListener(naviListener);
    if (SharedPerferencesUtil.getInstance().getIsLogined()) {
      // 已登陆
      // 个人数据加载
      user = JSON.parseObject(SharedPerferencesUtil.getInstance().getUserJson(), Users.class);
      Log.d(TAG, user.toString());
      initNavigationViewData(user);

      header_userimg.setOnClickListener(
          new View.OnClickListener() {
            @Override
            public void onClick(View v) {
              // 获取当前的用户ID,发送请求获取最新资料
              usersService.getUserDetailsByID(user.getID());
            }
          });
    } else
      header_userimg.setOnClickListener(
          new View.OnClickListener() {
            @Override
            public void onClick(View v) {
              startActivity(new Intent(x.app(), LoginActivity.class));
            }
          });
    // 列表
    mRecyclerView.setLayoutManager(new LinearLayoutManager(mRecyclerView.getContext()));
    mRecyclerView.setAdapter(new RecyclerViewAdapter(this));
  }
Beispiel #10
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_friend_list);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    SharedPreferences prefs = getSharedPreferences(getApplication().getPackageName(), MODE_PRIVATE);
    String userEmail = prefs.getString(ListActivity.USER_EMAIL, "");
    userName = userEmail.split("@")[0];
    usersRef = new Firebase(ListActivity.FIREBASE_URI);
    usersRef = usersRef.child("items");

    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);

    // Set user email in nav bar
    TextView drawerEmail =
        (TextView) navigationView.getHeaderView(0).findViewById(R.id.drawer_email);
    drawerEmail.setText(userEmail);

    // If started by intent
    if (getIntent().getExtras() != null) {
      String itemId = getIntent().getExtras().getString(ListActivity.ITEM_ID);
      Firebase itemRef = new Firebase(ListActivity.FIREBASE_URI).child("items").child(itemId);
      itemRef.child("isPublic").setValue(true);
      getIntent().removeExtra(ListActivity.ITEM_ID);
    }
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);

    // Load current user card preferences
    Intent intent = getIntent();
    mIdentity = intent.getStringExtra(ApplicationConstants.Extra.IDENTITY);
    mCardId = intent.getStringExtra(ApplicationConstants.Extra.CARD_ID);

    // Initialize Client Factory
    String accessToken = intent.getStringExtra(ApplicationConstants.Extra.VIRGIL_TOKEN);
    clientFactory = new ClientFactory(accessToken);

    // Configure UI
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    // Configure messages view
    PrivateKey privateKey =
        new PrivateKey(intent.getStringExtra(ApplicationConstants.Extra.PRIVATE_KEY));
    mMessagesAdapter = new MessagesAdapter(mMessages, mCardId, privateKey);

    RecyclerView messagesRecyclerView = (RecyclerView) findViewById(R.id.messagesRecyclerView);
    LinearLayoutManager layoutManager = new LinearLayoutManager(this);
    // for a chat app, show latest at the bottom
    layoutManager.setStackFromEnd(true);
    messagesRecyclerView.setLayoutManager(layoutManager);
    messagesRecyclerView.setAdapter(mMessagesAdapter);

    mWriteMessageEditText = (EditText) findViewById(R.id.writeMessageEditText);
    mSendChatMessageButton = (ImageButton) findViewById(R.id.sendChatMessageButton);
    mSendChatMessageButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View view) {
            if (mCurrentChannel != null) {
              String messageBody = mWriteMessageEditText.getText().toString();

              SendMessageTask sendTask = new SendMessageTask(messageBody);
              sendTask.execute((Void) null);
            }
          }
        });

    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();

    mNavigationView = (NavigationView) findViewById(R.id.nav_view);
    mNavigationView.setNavigationItemSelectedListener(this);

    TextView nicknameTV = (TextView) mNavigationView.getHeaderView(0).findViewById(R.id.nickname);
    nicknameTV.setText(mIdentity);

    // Initialize chat
    mMembers = new ConcurrentHashMap<>();

    String twilioToken = intent.getStringExtra(ApplicationConstants.Extra.TWILIO_TOKEN);
    retrieveAccessTokenFromServer(twilioToken);
  }
  private void load() {
    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);
    View headerLayout = navigationView.getHeaderView(0);
    TextView tv = (TextView) headerLayout.findViewById(R.id.nav_header_username);
    tv.setText(SharedPreferencesHelper.getStringProperty(getApplicationContext(), "username"));

    if (!BaseHelper.isServiceRunning(RetreiveNotificationsService.class, this)) {
      Intent myIntent = new Intent(this, RetreiveNotificationsService.class);
      this.startService(myIntent);
    }

    if (ValidationHelper.isInternetConnected(getApplicationContext())) {
      LinearLayout l = (LinearLayout) findViewById(R.id.contacts_container);
      if (retryButton != null) {
        l.removeView(findViewById(R.id.contactRetry));
      }
      progress = ProgressDialog.show(ContactsActivity.this, "", "Retrieving contacts...", true);
      progress.show();

      PendingRequestsTask pendingRequestsTask = new PendingRequestsTask();
      pendingRequestsTask.execute(
          SharedPreferencesHelper.getStringProperty(getApplicationContext(), "username"));

      ContactsTask contactsTask = new ContactsTask();
      contactsTask.execute(
          SharedPreferencesHelper.getStringProperty(getApplicationContext(), "username"));
    } else {
      LinearLayout l = (LinearLayout) findViewById(R.id.contacts_container);
      if (retryButton != null) {
        l.addView(retryButton);
      } else {
        toast = Toast.makeText(getApplicationContext(), "", Toast.LENGTH_SHORT);
        toast.setText("Could not retrieve contacts. No internet connection.");
        toast.show();

        retryButton = new Button(getApplicationContext());
        int size =
            (int)
                TypedValue.applyDimension(
                    TypedValue.COMPLEX_UNIT_DIP, 30, getResources().getDisplayMetrics());
        LinearLayout.LayoutParams params =
            new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
        params.gravity = Gravity.CENTER_HORIZONTAL;
        retryButton.setLayoutParams(params);
        retryButton.setId(R.id.contactRetry);
        retryButton.setText("Retry");
        retryButton.setBackgroundColor(Color.RED);
        retryButton.setOnClickListener(
            new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                if (ValidationHelper.isInternetConnected(getApplicationContext())) {
                  LinearLayout l = (LinearLayout) findViewById(R.id.contacts_container);
                  l.removeView(findViewById(R.id.contactRetry));
                  progress =
                      ProgressDialog.show(
                          ContactsActivity.this, "", "Retrieving contacts...", true);
                  progress.show();
                  ContactsTask contactsTask = new ContactsTask();
                  contactsTask.execute(
                      SharedPreferencesHelper.getStringProperty(
                          getApplicationContext(), "username"));
                } else {
                  toast = Toast.makeText(getApplicationContext(), "", Toast.LENGTH_SHORT);
                  toast.setText("Could not retrieve contacts. No internet connection.");
                  toast.show();
                }
              }
            });
        l.addView(retryButton);
      }
    }
    LocationUpdateReceiver.SetAlarm(getApplicationContext(), BaseHelper.INTERVAL_ONE_HOUR);
  }
Beispiel #13
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    actionBar = getSupportActionBar();
    assert (actionBar != null);
    actionBar.setDisplayShowTitleEnabled(false);

    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) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);
    navigationView.getMenu().getItem(0).setChecked(true);

    // Sets the name and id in the header bar
    settings = getSharedPreferences(StartActivity.PREFS_NAME, 0);
    View headerLayout = navigationView.getHeaderView(0);
    TextView name = (TextView) headerLayout.findViewById(R.id.student_name);
    TextView id = (TextView) headerLayout.findViewById(R.id.student_id);
    name.setText(settings.getString("name", ""));
    id.setText(settings.getString("id", ""));

    progressBar = (ProgressBar) findViewById(R.id.progressBar);

    datePickerButton = (LinearLayout) findViewById(R.id.date_picker_button);
    UpdateSchedule.datePickerWeek = (TextView) findViewById(R.id.date_picker_week);
    UpdateSchedule.datePickerStudent = (TextView) findViewById(R.id.date_picker_student);
    datePickerButton.setOnClickListener(
        new View.OnClickListener() {

          @Override
          public void onClick(View v) {

            dialog.show(getFragmentManager(), "DatePickerDialog");
          }
        });

    cal = Calendar.getInstance();
    cal.setFirstDayOfWeek(Calendar.MONDAY);
    UpdateSchedule.dayOfWeek = DayPicker.toDayNumber(cal.get(Calendar.DAY_OF_WEEK));

    // TODO: Figure out the colors
    dialog =
        DatePickerDialog.newInstance(
            new DayPicker(),
            cal.get(Calendar.YEAR),
            cal.get(Calendar.MONTH),
            cal.get(Calendar.DAY_OF_MONTH));
    dialog.vibrate(false);

    resources = getResources();
    fragmentManager = getFragmentManager();

    replaceFragment(currentFragment);

    SharedPreferences.Editor editor = settings.edit();

    try {
      if (settings.getInt("version", 0)
          < getPackageManager().getPackageInfo(getPackageName(), 0).versionCode) {

        editor.putInt(
            "version", getPackageManager().getPackageInfo(getPackageName(), 0).versionCode);
        editor.apply();

        MaterialDialog.Builder update =
            new MaterialDialog.Builder(this)
                .title(R.string.update)
                .content(R.string.update_text)
                .positiveText(R.string.ok);
        update.show();
      }
    } catch (PackageManager.NameNotFoundException e) {
      e.printStackTrace();
    }

    if (settings.getInt("tutorial", 0) < StartActivity.TUTORIAL_VERSION) {

      editor.putInt("tutorial", StartActivity.TUTORIAL_VERSION);
      editor.apply();

      MaterialDialog.Builder tutorial =
          new MaterialDialog.Builder(this)
              .title(R.string.tutorial)
              .content(Html.fromHtml(getString(R.string.tutorial_text)))
              .positiveText(R.string.ok);
      tutorial.show();
    }

    if (!settings.getString("friends", "").equals("")) {

      Gson gson = new Gson();
      Type type = new TypeToken<List<FriendInfo>>() {}.getType();

      FriendsFragment.friendArrayList.clear();
      List<FriendInfo> friendList = gson.fromJson(settings.getString("friends", ""), type);

      for (int i = 0; i < friendList.size(); i++) {

        if (friendList.get(i).name != null && friendList.get(i).code != null) {

          FriendsFragment.friendArrayList.add(friendList.get(i));
        } else {
          Log.w("Friends", "Found null entry, skipping!");
        }
      }
    }

    invalidateOptionsMenu();
    editCallback =
        new MaterialDialog.InputCallback() {

          @Override
          public void onInput(@NonNull MaterialDialog materialDialog, CharSequence charSequence) {

            FriendsFragment.friendArrayList.get(editPosition).name = charSequence.toString();
            Collections.sort(FriendsFragment.friendArrayList, MainActivity.nameSorter);
            FriendsFragment.fa.notifyDataSetChanged();

            Gson gson = new Gson();
            String jsonFriends = gson.toJson(FriendsFragment.friendArrayList);

            SharedPreferences settings = getSharedPreferences(StartActivity.PREFS_NAME, 0);
            SharedPreferences.Editor editor = settings.edit();

            editor.putString("friends", jsonFriends);
            editor.apply();
          }
        };
    edit =
        new MaterialDialog.Builder(this)
            .title(getText(R.string.edit))
            .inputType(InputType.TYPE_CLASS_TEXT)
            .neutralText(R.string.cancel)
            .negativeText(R.string.remove)
            .onNegative(
                new MaterialDialog.SingleButtonCallback() {

                  @Override
                  public void onClick(
                      @NonNull MaterialDialog materialDialog, @NonNull DialogAction dialogAction) {

                    FriendsFragment.friendArrayList.remove(editPosition);
                    Collections.sort(FriendsFragment.friendArrayList, MainActivity.nameSorter);
                    FriendsFragment.fa.notifyDataSetChanged();

                    Gson gson = new Gson();
                    String jsonFriends = gson.toJson(FriendsFragment.friendArrayList);

                    SharedPreferences settings = getSharedPreferences(StartActivity.PREFS_NAME, 0);
                    SharedPreferences.Editor editor = settings.edit();

                    editor.putString("friends", jsonFriends);
                    editor.apply();
                  }
                });
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_list);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbar.setTitle("E-care");
    setSupportActionBar(toolbar);

    db = new SQLiteHandler(getApplicationContext());
    session = new SessionManager(getApplicationContext());

    drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    NavigationView view = (NavigationView) findViewById(R.id.navigation_view);
    view.getMenu().getItem(1).setChecked(true);
    view.setNavigationItemSelectedListener(
        new NavigationView.OnNavigationItemSelectedListener() {
          @Override
          public boolean onNavigationItemSelected(MenuItem menuItem) {
            Toast.makeText(
                    ShowAppointmentList.this, menuItem.getItemId() + " pressed", Toast.LENGTH_LONG)
                .show();
            Intent intent = new Intent();
            Log.d(R.id.nav_1 + "", menuItem.getItemId() + " ");
            switch (menuItem.getItemId()) {
              case R.id.nav_1:
                intent.setClass(ShowAppointmentList.this, Case_history_review.class);
                startActivity(intent);
                break;
              case R.id.nav_2:
                intent.setClass(ShowAppointmentList.this, ShowAppointmentList.class);
                // intent .putExtra("name", "Hello B Activity");
                startActivity(intent);
                break;
              case R.id.nav_3:
                intent.setClass(ShowAppointmentList.this, Appointmentcreate.class);
                // intent .putExtra("name", "Hello B Activity");
                startActivity(intent);
                break;
              case R.id.nav_4:
                intent.setClass(ShowAppointmentList.this, AlarmActivity.class);
                // intent .putExtra("name", "Hello B Activity");
                startActivity(intent);
                break;
              case R.id.nav_5:
                intent.setClass(ShowAppointmentList.this, PatientReport.class);
                // intent .putExtra("name", "Hello B Activity");
                startActivity(intent);
                break;
              case R.id.nav_6:
                // logout
                AlertDialog.Builder builder = new AlertDialog.Builder(ShowAppointmentList.this);
                // Uncomment the below code to Set the message and title from the strings.xml file
                // builder.setMessage(R.string.dialog_message) .setTitle(R.string.dialog_title);

                // Setting message manually and performing action on button click
                builder
                    .setMessage("Do you want to close this application ?")
                    .setCancelable(false)
                    .setPositiveButton(
                        "Yes",
                        new DialogInterface.OnClickListener() {
                          public void onClick(DialogInterface dialog, int id) {
                            session.setLogin(false);
                            db.deleteUsers();
                            final Intent intent_logout =
                                new Intent(ShowAppointmentList.this, LoginActivity.class);
                            startActivity(intent_logout);
                            finish();
                          }
                        })
                    .setNegativeButton(
                        "No",
                        new DialogInterface.OnClickListener() {
                          public void onClick(DialogInterface dialog, int id) {
                            //  Action for 'NO' Button
                            dialog.cancel();
                          }
                        });

                // Creating dialog box
                AlertDialog alert = builder.create();
                // Setting the title manually
                alert.setTitle("AlertDialogExample");
                alert.show();

                break;
            }
            menuItem.setChecked(true);
            drawerLayout.closeDrawers();
            return true;
          }
        });

    ActionBarDrawerToggle actionBarDrawerToggle =
        new ActionBarDrawerToggle(
            this, drawerLayout, toolbar, R.string.drawer_open, R.string.drawer_close) {
          @Override
          public void onDrawerClosed(View drawerView) {
            super.onDrawerClosed(drawerView);
          }

          @Override
          public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
          }
        };

    db = new SQLiteHandler(getApplicationContext());
    dbuser = db.getUserDetails();
    View header = view.getHeaderView(0);
    TextView headerName = (TextView) header.findViewById(R.id.drawer_name);
    username = dbuser.get("name");
    uid = dbuser.get("uid");
    headerName.setText(username);
    ImageLoader imageLoader = AppController.getInstance().getImageLoader();
    com.example.yuen.e_carei_doctor.customlistviewvolley.CirculaireNetworkImageView headerphoto =
        (com.example.yuen.e_carei_doctor.customlistviewvolley.CirculaireNetworkImageView)
            header.findViewById(R.id.drawer_thumbnail);
    headerphoto.setImageUrl("http://10.89.133.147/test/" + dbuser.get("image"), imageLoader);
    drawerLayout.setDrawerListener(actionBarDrawerToggle);
    actionBarDrawerToggle.syncState();

    mListView = (SwipeMenuListView) findViewById(R.id.listView);
    swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_refresh_layout);

    swipeRefreshLayout.setOnRefreshListener(this);

    /**
     * Showing Swipe Refresh animation on activity create As animation won't start on onCreate, post
     * runnable is used
     */
    swipeRefreshLayout.post(
        new Runnable() {
          @Override
          public void run() {

            swipeRefreshLayout.setRefreshing(true);
            fetchPatients();
          }
        });

    PD = new ProgressDialog(this);
    // Showing progress dialog before making http request
    PD.setMessage("Loading...");
    PD.show();
    mAdapter = new AppointmentListAdapter(this, appointmentList);
    mListView.setAdapter(mAdapter);
    // fetchPatients();
    // step 1. create a MenuCreator
    SwipeMenuCreator creator =
        new SwipeMenuCreator() {

          @Override
          public void create(SwipeMenu menu) {

            // create "delete" item
            SwipeMenuItem deleteItem = new SwipeMenuItem(getApplicationContext());
            // set item background
            deleteItem.setBackground(new ColorDrawable(Color.rgb(0xF9, 0x3F, 0x25)));
            // set item width
            deleteItem.setWidth(dp2px(90));
            // set a icon
            deleteItem.setIcon(R.drawable.ic_delete);
            // add to menu
            menu.addMenuItem(deleteItem);
          }
        };
    // set creator
    mListView.setMenuCreator(creator);

    // step 2. listener item click event
    mListView.setOnMenuItemClickListener(
        new SwipeMenuListView.OnMenuItemClickListener() {
          @Override
          public boolean onMenuItemClick(int position, SwipeMenu menu, int index) {
            AppointmentList item = appointmentList.get(position);
            switch (index) {
              case 0:
                // delete
                // delete(item);
                final String row_aid = aidlist.get(position).toString();
                AlertDialog.Builder builder = new AlertDialog.Builder(ShowAppointmentList.this);

                // Setting message manually and performing action on button click
                builder
                    .setMessage("Do you want to delete this row ?")
                    .setCancelable(false)
                    .setPositiveButton(
                        "Yes",
                        new DialogInterface.OnClickListener() {
                          public void onClick(DialogInterface dialog, int id) {
                            delete(uid, row_aid);
                            fetchPatients();
                          }
                        })
                    .setNegativeButton(
                        "No",
                        new DialogInterface.OnClickListener() {
                          public void onClick(DialogInterface dialog, int id) {
                            //  Action for 'NO' Button
                            dialog.cancel();
                          }
                        });

                // Creating dialog box
                AlertDialog alert = builder.create();
                // Setting the title manually
                alert.setTitle("AlertDialogExample");
                alert.show();
                break;
            }
            return false;
          }
        });

    // set SwipeListener
    mListView.setOnSwipeListener(
        new SwipeMenuListView.OnSwipeListener() {

          @Override
          public void onSwipeStart(int position) {
            // swipe start
          }

          @Override
          public void onSwipeEnd(int position) {
            // swipe end
          }
        });

    // set MenuStateChangeListener
    mListView.setOnMenuStateChangeListener(
        new SwipeMenuListView.OnMenuStateChangeListener() {
          @Override
          public void onMenuOpen(int position) {}

          @Override
          public void onMenuClose(int position) {}
        });

    // other setting
    //		listView.setCloseInterpolator(new BounceInterpolator());

    // test item long click
    mListView.setOnItemLongClickListener(
        new AdapterView.OnItemLongClickListener() {

          @Override
          public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
            Toast.makeText(getApplicationContext(), position + " long click", Toast.LENGTH_SHORT)
                .show();
            return false;
          }
        });
  }
Beispiel #15
0
  @Override
  protected void initPageView() {
    db = Ioc.getIoc().getDb("/sdcard/MTM/", Constants.APP_DATABASE);
    //
    getSupportActionBar().setTitle("红树林管家");
    initViews();

    // 设置Drawerlayout开关指示器,即Toolbar最左边的那个icon
    ActionBarDrawerToggle toggle =
        new ActionBarDrawerToggle(
            this,
            mDrawerLayout,
            getActionBarToolbar(),
            R.string.navigation_drawer_open,
            R.string.navigation_drawer_close);
    mDrawerLayout.setDrawerListener(toggle);
    //        Resources resource=(Resources)getBaseContext().getResources();
    //        ColorStateList
    // csl=(ColorStateList)resource.getColorStateList(R.color.selector_nav_menu_textcolor);
    //        mNavigationView.setItemTextColor(csl);
    toggle.syncState();
    // 给NavigationView填充顶部区域,也可在xml中使用app:headerLayout="@layout/header_nav"来设置
    headerLayout = mNavigationView.getHeaderView(0);

    // 给NavigationView填充Menu菜单,也可在xml中使用app:menu="@menu/menu_nav"来设置
    //        mNavigationView.inflateMenu(R.menu.menu_nav);
    // 自己写的方法,设置NavigationView中menu的item被选中后要执行的操作
    account_layout = (LinearLayout) headerLayout.findViewById(R.id.account_islogin);
    account_item_name = (TextView) headerLayout.findViewById(R.id.account_item_name);
    account_layout.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            startActivityForResult(
                new Intent(MainActivity.this, PersonalInfoActivity.class)
                    .putExtra("memberInfo", Handler_Json.beanToJson(personEntity)),
                2);
          }
        });
    getMemInfo();

    //        //获取版本号
    //        Properties pro = Handler_Properties.loadConfigAssets("version.properties");
    //        currVersion = pro.get("version").toString();
    //        ajaxVersion();

    hotelCode =
        Handler_SharedPreferences.getValueByName(
            this, "hotel", "hotelcode", Handler_SharedPreferences.STRING);
    Ioc.getIoc().getLogger().e(" OnEventChange hotelCode:" + hotelCode);
    mNavigationView.setNavigationItemSelectedListener(this);
    if (Handler_String.isBlank(hotelCode) || "2".equals(hotelCode)) {
      Handler_SharedPreferences.WriteSharedPreferences(
          getApplicationContext(), "hotel", "hotelcode", "2");
      getActionBarToolbar().setTitle("三亚•三亚湾");
      mNavigationView.setCheckedItem(R.id.nav_menu_sy);
    } else {
      getActionBarToolbar().setTitle("青岛•灵山湾");
      Handler_SharedPreferences.WriteSharedPreferences(
          getApplicationContext(), "hotel", "hotelcode", "3");
      mNavigationView.setCheckedItem(R.id.nav_menu_qd);
    }

    // 根据gps地理位置切换酒店
    citycode = CityCodeUtils.GetCityCode();
    Log.d("CityCode", "citycode=" + citycode);
    switchHotelByLocation(citycode);
    getAppVersionByFir();
  }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);

    prefs = PreferenceManager.getDefaultSharedPreferences(this);
    PreferenceManager.setDefaultValues(this, R.xml.prefs, false);
    prefs.registerOnSharedPreferenceChangeListener(this);

    // set preferred lang to the default lang
    if ("".equals(prefs.getString(PrefsActivity.PREF_LANGUAGE, ""))) {
      prefs
          .edit()
          .putString(PrefsActivity.PREF_LANGUAGE, Locale.getDefault().getLanguage())
          .apply();
    }

    messageContainer = this.findViewById(R.id.home_messages);
    messageText = (TextView) this.findViewById(R.id.home_message);
    messageButton = (Button) this.findViewById(R.id.message_action_button);

    courses = new ArrayList<>();
    courseListAdapter = new CourseListAdapter(this, courses);
    courseList = (ListView) findViewById(R.id.course_list);
    courseList.setAdapter(courseListAdapter);

    // the alternative of registerForContextMenu(courseList);
    CourseContextMenuCustom courseMenu = new CourseContextMenuCustom(this);
    courseMenu.registerForContextMenu(courseList, this);

    courseList.setOnItemClickListener(
        new OnItemClickListener() {

          public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Course selectedCourse = courses.get(position);
            Intent i = new Intent(OppiaMobileActivity.this, CourseIndexActivity.class);
            Bundle tb = new Bundle();
            tb.putSerializable(Course.TAG, selectedCourse);
            i.putExtras(tb);
            startActivity(i);
          }
        });

    llNone = (LinearLayout) this.findViewById(R.id.no_courses);
    initialCourseListPadding = courseList.getPaddingTop();

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    // Initializing Drawer Layout and ActionBarToggle
    final DrawerLayout drawerLayout = (DrawerLayout) findViewById(R.id.drawer);
    navigationView = (NavigationView) findViewById(R.id.navigation_view);
    ((TextView) navigationView.getHeaderView(0).findViewById(R.id.drawer_user_fullname))
        .setText(SessionManager.getUserDisplayName(this));
    ((TextView) navigationView.getHeaderView(0).findViewById(R.id.drawer_username))
        .setText(SessionManager.getUsername(this));
    navigationView.setNavigationItemSelectedListener(
        new NavigationView.OnNavigationItemSelectedListener() {
          @Override
          public boolean onNavigationItemSelected(MenuItem menuItem) {
            boolean result = onOptionsItemSelected(menuItem);
            menuItem.setChecked(false);
            drawerLayout.closeDrawers();
            return result;
          }
        });

    ActionBarDrawerToggle actionBarDrawerToggle =
        new ActionBarDrawerToggle(this, drawerLayout, toolbar, R.string.open, R.string.close) {
          @Override
          public void onDrawerClosed(View drawerView) {
            // Code here will be triggered once the drawer closes as we dont want anything to happen
            // so we leave this blank
            super.onDrawerClosed(drawerView);
          }

          @Override
          public void onDrawerOpened(View drawerView) {
            // Code here will be triggered once the drawer open as we dont want anything to happen
            // so we leave this blank
            super.onDrawerOpened(drawerView);
          }
        };

    // Setting the actionbarToggle to drawer layout
    drawerLayout.setDrawerListener(actionBarDrawerToggle);
    actionBarDrawerToggle.syncState();
  }
Beispiel #17
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    ButterKnife.bind(this);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
    container.setAdapter(mSectionsPagerAdapter);
    tabs.setupWithViewPager(container);

    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View view) {
            Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                .setAction("Action", null)
                .show();
          }
        });

    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);
    //        View headerLayout = LayoutInflater.from(this).inflate(R.layout.nav_header_main, null);
    //        navigationView.addHeaderView(headerLayout);
    //        CircleImageView circleImageView = (CircleImageView)
    // headerLayout.findViewById(R.id.circleImageView);
    //        LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams)
    // circleImageView.getLayoutParams();
    //        layoutParams.width = 250;
    //        layoutParams.height = 250;
    //        layoutParams.topMargin = 80;
    //        circleImageView.setLayoutParams(layoutParams);
    //        circleImageView.setOnClickListener(new View.OnClickListener() {
    //            @Override
    //            public void onClick(View v) {
    //                LogUtil.d("头像点击。。。");
    //            }
    //        });
    View header = navigationView.getHeaderView(0);
    CircleImageView circleImageView = (CircleImageView) header.findViewById(R.id.circleImageView);
    circleImageView.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            LogUtil.d("头像");
          }
        });

    // 模拟数据
    //        for (int i = 0; i < 20; i++) {
    //            Map<String, Object> listItem = new HashMap<>();
    //            listItem.put("img", R.mipmap.ic_launcher);
    //            listItem.put("text", "Item " + i);
    //            mData.add(listItem);
    //        }

  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    volley = VolleyS.getInstance(this);
    fRequestQueue = volley.getRequestQueue();
    setContentView(R.layout.activity_main);
    current = Backendless.UserService.CurrentUser();
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
    StrictMode.setThreadPolicy(policy);
    String appVersion = "v1";
    Backendless.initApp(
        this,
        "F89F55EE-64AD-32BF-FFE1-96C258DA8800",
        "C7F9D9B6-6A7E-6FCF-FF7E-B1D7272E9900",
        appVersion);
    SharedPreferences sharedPreferences = getSharedPreferences("myData", Context.MODE_PRIVATE);
    String name = sharedPreferences.getString("name", "");

    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();
    String urlpost = "http://10.10.3.21:3000/topcandidatos";
    JsonArrayRequest req =
        new JsonArrayRequest(
            urlpost,
            new Response.Listener<JSONArray>() {
              @Override
              public void onResponse(JSONArray response) {
                for (int i = 0; i < response.length(); i++) {
                  Candidato candidato = new Candidato();
                  try {
                    JSONObject jsonObject = response.getJSONObject(i);
                    candidato.setApellidos(jsonObject.getString("can_Apellido"));
                    candidato.setNombres(jsonObject.getString("can_Nombre"));
                    candidato.setId(jsonObject.getInt("can_Codigo"));
                    candidato.setFoto(jsonObject.getString("can_Foto"));
                    candidato.setPopularidad(jsonObject.getDouble("percent"));
                    candidato.setVotos(jsonObject.getInt("Respuestas"));
                    candidatos.add(candidato);
                  } catch (JSONException e) {
                    e.printStackTrace();
                  }
                }
                candidatoAdapter =
                    new CandidatoAdapter(
                        MainActivity.this, R.layout.top_item_candidato, candidatos);
                ListView tablesListView = (ListView) findViewById(R.id.mainList);
                candidatoAdapter.notifyDataSetChanged();
                tablesListView.setAdapter(candidatoAdapter);
                /*try {
                    VolleyLog.v("Response:%n %s", response.toString(4));
                } catch (JSONException e) {
                    e.printStackTrace();
                }*/
              }
            },
            new Response.ErrorListener() {
              @Override
              public void onErrorResponse(VolleyError error) {
                VolleyLog.e("Error: ", error.getMessage());
              }
            });
    addToQueue(req);
    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);
    View header = navigationView.getHeaderView(0);
    ImageView imageView = (ImageView) header.findViewById(R.id.imageView);
    TextView title = (TextView) header.findViewById(R.id.titleHeader);
    TextView email = (TextView) header.findViewById(R.id.email);
    Picasso.with(this)
        .load(
            "https://graph.facebook.com/"
                + current.getProperty("email").toString()
                + "/picture?type=large")
        .resize(110, 110)
        .centerCrop()
        .into(imageView);
    title.setText(current.getProperty("name").toString());
    email.setText(current.getProperty("fb_email").toString());
  }
Beispiel #19
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    session = new UserSessionManager(getApplicationContext());
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    final 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);

    View header = navigationView.getHeaderView(0);
    TextView text = (TextView) header.findViewById(R.id.user);

    if (session.isUserLoggedIn())
      text.setText(session.getUserDetails().get(UserSessionManager.KEY_EMAIL));
    ImageView image = (ImageView) header.findViewById(R.id.imageView);
    TextView textUser = (TextView) header.findViewById(R.id.user);
    if (session.isUserLoggedIn()) {
      navigationView.getMenu().clear();
      navigationView.inflateMenu(R.menu.activity_main_drawer);
      image.setOnClickListener(
          new View.OnClickListener() {
            @Override
            public void onClick(View v) {
              startActivity(new Intent(getApplicationContext(), UserProfile.class));
              drawer.closeDrawer(GravityCompat.START);
            }
          });
      textUser.setOnClickListener(
          new View.OnClickListener() {
            @Override
            public void onClick(View v) {
              startActivity(new Intent(getApplicationContext(), UserProfile.class));
              drawer.closeDrawer(GravityCompat.START);
            }
          });
    } else {
      navigationView.getMenu().clear();
      navigationView.inflateMenu(R.menu.activity_log_drawer);
    }

    ImageButton search = (ImageButton) findViewById(R.id.search);
    search.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            startActivity(new Intent(getApplicationContext(), Search.class));
          }
        });
    ImageButton add = (ImageButton) findViewById(R.id.add);
    add.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            startActivity(new Intent(getApplicationContext(), Add.class));
          }
        });

    // if(session.checkLogin())
    //   finish();

  }
Beispiel #20
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    // how to adjust the height of toolbar
    // http://stackoverflow.com/questions/17439683/how-to-change-action-bar-size
    // zsmth_actionbar_size @ dimen ==> ThemeOverlay.ActionBar @ styles ==> theme @ app_bar_main.xml

    // init floating action button & circular action menu
    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    initCircularActionMenu(fab);

    mDrawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    mToggle =
        new ActionBarDrawerToggle(
            this,
            mDrawer,
            toolbar,
            R.string.navigation_drawer_open,
            R.string.navigation_drawer_close);
    mDrawer.addDrawerListener(mToggle);
    mToggle.syncState();

    mNavigationView = (NavigationView) findViewById(R.id.nav_view);
    mNavigationView.setNavigationItemSelectedListener(this);
    mNavigationView.setCheckedItem(R.id.nav_guidance);

    // http://stackoverflow.com/questions/33161345/android-support-v23-1-0-update-breaks-navigationview-get-find-header
    View headerView = mNavigationView.getHeaderView(0);
    mAvatar = (WrapContentDraweeView) headerView.findViewById(R.id.nav_user_avatar);
    mAvatar.setOnClickListener(this);

    mUsername = (TextView) headerView.findViewById(R.id.nav_user_name);
    mUsername.setOnClickListener(this);

    // http://stackoverflow.com/questions/27097126/marquee-title-in-toolbar-actionbar-in-android-with-lollipop-sdk
    TextView titleTextView = null;
    try {
      Field f = toolbar.getClass().getDeclaredField("mTitleTextView");
      f.setAccessible(true);
      titleTextView = (TextView) f.get(toolbar);
      titleTextView.setEllipsize(TextUtils.TruncateAt.START);
    } catch (NoSuchFieldException e) {
    } catch (IllegalAccessException e) {
    }

    // init all fragments
    initFragments();

    FragmentManager fm = getSupportFragmentManager();
    if (Settings.getInstance().isLaunchHotTopic()) {
      fm.beginTransaction().replace(R.id.content_frame, hotTopicFragment).commit();
    } else {
      fm.beginTransaction().replace(R.id.content_frame, favoriteBoardFragment).commit();
    }

    getSupportFragmentManager()
        .addOnBackStackChangedListener(
            new FragmentManager.OnBackStackChangedListener() {
              public void onBackStackChanged() {
                // Enable Up button only  if there are entries in the back stack
                boolean canback = getSupportFragmentManager().getBackStackEntryCount() > 0;
                if (canback) {
                  mToggle.setDrawerIndicatorEnabled(false);
                  getSupportActionBar().setDisplayShowHomeEnabled(true);
                  getSupportActionBar().setHomeButtonEnabled(true);
                  getSupportActionBar().setDisplayHomeAsUpEnabled(true);
                } else {
                  getSupportActionBar().setDisplayHomeAsUpEnabled(false);
                  mToggle.setDrawerIndicatorEnabled(true);
                  mDrawer.addDrawerListener(mToggle);
                }
              }
            });

    // start service to maintain user status
    setupUserStatusReceiver();
    updateUserStatusNow();
    UpdateNavigationViewHeader();

    // schedule the periodical run
    MaintainUserStatusService.schedule(MainActivity.this, mReceiver);

    if (Settings.getInstance().isFirstRun()) {
      // show info dialog after 5 seconds for the first run
      final Handler handler = new Handler();
      handler.postDelayed(
          new Runnable() {
            @Override
            public void run() {
              showInfoDialog();
            }
          },
          2000);
    }
  }
Beispiel #21
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    Log.d(TAG, "onCreate(" + savedInstanceState + "," + getIntent().getExtras() + ")");
    super.onCreate(savedInstanceState);
    if (savedInstanceState != null) {
      currentFragment = savedInstanceState.getInt(CURRENT_FRAGMENT, R.id.nav_info);
    } else if (getIntent().getExtras() != null) {
      currentFragment = getIntent().getExtras().getInt(CURRENT_FRAGMENT, R.id.nav_info);
    }

    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View view) {
            if (!ecm.isConnected()) {
              connect();
            } else {
              disconnect();
            }
          }
        });

    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.addDrawerListener(toggle);
    toggle.syncState();

    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);

    ((TextView) navigationView.getHeaderView(0).findViewById(R.id.headerTitle))
        .setText(Utils.getAppVersion(this));

    // Bind to our service and setup the connect button
    bindService(
        new Intent(this, EcmDroidService.class), serviceConnection, Context.BIND_AUTO_CREATE);
    startService(new Intent(this, EcmDroidService.class));

    switchToFragment(currentFragment);

    // Install the database
    dbHelper = new DBHelper(this);
    if (!dbHelper.isDbInstalled()) {
      ProgressDialogTask installTask =
          new ProgressDialogTask(this, "Installing Database") {
            @Override
            protected Exception doInBackground(Void... args) {
              try {
                dbHelper.installDB(MainActivity.this);
              } catch (IOException e) {
                Log.e(TAG, "DB Install failed.", e);
                return e;
              }
              return null;
            }

            @Override
            protected void onPostExecute(Exception result) {
              super.onPostExecute(result);
              if (result != null) {
                Toast.makeText(
                        MainActivity.this, "FATAL: DB Installation failed.", Toast.LENGTH_LONG)
                    .show();
                System.exit(0);
              }
            }
          };
      installTask.execute();
    }
  }