Android Open Source - Stack-Chat Main Activity






From Project

Back to project page Stack-Chat.

License

The source code is released under:

MIT License

If you think the Android project Stack-Chat listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.noahhuppert.stackchat;
/*from w w  w .j  a va 2s  .  c om*/
import android.app.Activity;
import android.app.FragmentManager;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;

import com.noahhuppert.stackchat.controllers.NotificationController;
import com.noahhuppert.stackchat.fragments.RoomFragment;
import com.noahhuppert.stackchat.models.Room;
import com.noahhuppert.stackchat.modules.BaseStackChatModule;
import com.noahhuppert.stackchat.modules.StackChatModule;
import com.noahhuppert.stackchat.tasks.UpdateRoomMessagesTask;

import dagger.ObjectGraph;

/**
 * Main android activity
 */
public class MainActivity extends Activity {
    //Constants
    /**
     * Log Tag
     */
    public static final String LOG_TAG = "Stack Chat Log";

    //Android
    public FragmentManager fragmentManager;

    //Dagger
    /**
     * Main ObjectGraph for Dagger
     */
    public static ObjectGraph objectGraph = ObjectGraph.create(new BaseStackChatModule(), new StackChatModule());
    /**
     * Android notification manager
     */
    public NotificationController notificationController;

    /**
     * Android lifetime method
     * On startup, runs once
     * @param savedInstanceState Saved state from previous life cycle
     */
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        //Android vars
        fragmentManager = getFragmentManager();

        //Dagger
        notificationController = objectGraph.get(NotificationController.class);

        //Set fragment
        RoomFragment roomFragment = new RoomFragment();

        fragmentManager.beginTransaction()
                .replace(R.id.mainFragment, roomFragment)
                .addToBackStack(null)
                .commitAllowingStateLoss();

        /*
        Room room15 = new Room(15);

        room15.addMessage(new Message(0, "message1", 10, 1));
        room15.addMessage(new Message(1, "message2", 10, 1));
        room15.addMessage(new Message(2, "message3", 10, 1));

        messagesRecyclerView = (RecyclerView) getView().findViewById(R.id.messages_recycler_view);
        messagesRecyclerView.setHasFixedSize(true);

        messagesLayoutManager = new LinearLayoutManager(getActivity());
        messagesRecyclerView.setLayoutManager(messagesLayoutManager);

        MessagesRecyclerViewAdapter messagesRecyclerViewAdapter = new MessagesRecyclerViewAdapter(room15.getMessages());
        messagesRecyclerView.setAdapter(messagesRecyclerViewAdapter);
         */
    }


    /**
     * Inflates option menu
     * @param menu The menu to inflate
     * @return ?
     */
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    /**
     * On menu item click
     * @param item Item that is clicked
     * @return ?
     */
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}




Java Source Code List

com.noahhuppert.stackchat.ApplicationTest.java
com.noahhuppert.stackchat.MainActivity.java
com.noahhuppert.stackchat.MessagesRecyclerViewAdapter.java
com.noahhuppert.stackchat.controllers.HeaderBuilder.java
com.noahhuppert.stackchat.controllers.JellyKitNotificationController.java
com.noahhuppert.stackchat.controllers.NotificationController.java
com.noahhuppert.stackchat.controllers.PopNotificationController.java
com.noahhuppert.stackchat.fragments.RoomFragment.java
com.noahhuppert.stackchat.models.KVPair.java
com.noahhuppert.stackchat.models.Message.java
com.noahhuppert.stackchat.models.Room.java
com.noahhuppert.stackchat.models.User.java
com.noahhuppert.stackchat.modules.BaseStackChatModule.java
com.noahhuppert.stackchat.modules.StackChatModule.java
com.noahhuppert.stackchat.modules.StackChatModule.java
com.noahhuppert.stackchat.tasks.GetMessagesTask.java
com.noahhuppert.stackchat.tasks.UpdateRoomMessagesTask.java