コード例 #1
0
ファイル: MainActivity.java プロジェクト: jukov/LANChat
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    setContentView(R.layout.activity_main);
    super.onCreate(savedInstanceState);

    initViews();
    initValues();
    initFragments();
    initAdapters();
    initBroadcastReceiver();
    initService();
  }
コード例 #2
0
ファイル: MainActivity.java プロジェクト: jukov/LANChat
  @Override
  protected void initViews() {
    super.initViews();

    actionBarDrawerToggle =
        new ActionBarDrawerToggle(
            this,
            drawerLayout,
            toolbar,
            R.string.navigation_drawer_open,
            R.string.navigation_drawer_close);
    actionBarDrawerToggle.syncState();

    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) actionBar.setTitle(getString(R.string.global_chat));
  }
コード例 #3
0
ファイル: MainActivity.java プロジェクト: jukov/LANChat
 @Override
 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
   super.onActivityResult(requestCode, resultCode, data);
   if (resultCode == RESULT_OK) {
     switch (requestCode) {
       case REQUEST_CODE_PRIVATE_CHAT:
       case REQUEST_CODE_ROOM_CHAT:
         int id = data.getIntExtra(EXTRA_ID, 0);
         Fragment fragment = fragments.get(id);
         if (fragment instanceof PreferenceFragmentCompat) toolbar.setTitle(R.string.settings);
         else {
           toolbar.setTitle(((BaseFragment) fragment).getTitle());
         }
         getSupportFragmentManager()
             .beginTransaction()
             .replace(R.id.relativeLayoutFragmentContainer, fragments.get(id))
             .commit();
         currentNavigationId = id;
         break;
     }
   }
 }
コード例 #4
0
ファイル: MainActivity.java プロジェクト: jukov/LANChat
 @Override
 protected void onDestroy() {
   super.onDestroy();
   unregisterReceiver(broadcastReceiver);
 }
コード例 #5
0
ファイル: MainActivity.java プロジェクト: jukov/LANChat
 @Override
 protected void initBroadcastReceiver() {
   super.initBroadcastReceiver();
   broadcastReceiver =
       new BroadcastReceiver() {
         @Override
         public void onReceive(Context context, final Intent intent) {
           switch (intent.getAction()) {
             case GLOBAL_MESSAGE_ACTION:
               Log.d(TAG, "Receive global message");
               if (intent.hasExtra(EXTRA_MESSAGE)) {
                 ChatData chatData = intent.getParcelableExtra(EXTRA_MESSAGE);
                 chatAdapter.add(chatData);
               } else if (intent.hasExtra(EXTRA_MESSAGE_BUNDLE)) {
                 Parcelable[] parcelables = intent.getParcelableArrayExtra(EXTRA_MESSAGE_BUNDLE);
                 ChatData[] messages =
                     Arrays.copyOf(parcelables, parcelables.length, ChatData[].class);
                 for (ChatData chatData : messages) {
                   chatAdapter.add(chatData);
                 }
               }
               break;
             case PEOPLE_ACTION:
               PeopleData peopleData = intent.getParcelableExtra(EXTRA_PEOPLE);
               if (peopleData.getEncodedProfilePicture() != null
                   && peopleData.getEncodedProfilePicture().length() > 0)
                 peopleData.setProfilePicture(
                     Base64Converter.getBitmapFromString(peopleData.getEncodedProfilePicture()));
               if (!peopleData.getUid().equals(Utils.getAndroidID(getApplicationContext())))
                 switch (peopleData.getAction()) {
                   case CONNECT:
                     peopleAdapter.add(peopleData);
                     break;
                   case DISCONNECT:
                     peopleAdapter.setOffline(peopleData);
                     break;
                   case CHANGE_PROFILE:
                     peopleAdapter.add(peopleData);
                     break;
                   default:
                     Log.w(getClass().getSimpleName(), "Unexpected action type");
                 }
               break;
             case SEND_ROOM_ACTION:
               Log.d(TAG, "SEND_ROOM_ACTION");
               if (intent.hasExtra(EXTRA_ROOM)) {
                 RoomData roomData = intent.getParcelableExtra(EXTRA_ROOM);
                 roomsAdapter.add(roomData);
               } else if (intent.hasExtra(EXTRA_MESSAGE_BUNDLE)) {
                 Parcelable[] parcelables = intent.getParcelableArrayExtra(EXTRA_MESSAGE_BUNDLE);
                 RoomData[] messages =
                     Arrays.copyOf(parcelables, parcelables.length, RoomData[].class);
                 for (RoomData roomData : messages) {
                   roomsAdapter.add(roomData);
                 }
               }
               break;
             case SET_ALL_OFFLINE_ACTION:
               peopleAdapter.allOffline();
           }
         }
       };
   IntentFilter intentFilter = new IntentFilter();
   intentFilter.addAction(GLOBAL_MESSAGE_ACTION);
   intentFilter.addAction(PEOPLE_ACTION);
   intentFilter.addAction(SET_ALL_OFFLINE_ACTION);
   intentFilter.addAction(SEND_ROOM_ACTION);
   registerReceiver(broadcastReceiver, intentFilter);
 }