Android Open Source - LinuxZaSve_mobile Main Activity






From Project

Back to project page LinuxZaSve_mobile.

License

The source code is released under:

Apache License

If you think the Android project LinuxZaSve_mobile 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.linuxzasve.mobile;
// w w w. j  av  a  2s  .c o m
import android.app.ActionBar;
import android.app.Activity;
import android.app.SearchManager;
import android.content.Intent;
import android.os.Bundle;

import com.linuxzasve.mobile.fragments.ArticleDisplayFragment;
import com.linuxzasve.mobile.fragments.ArticleListFragment;
import com.linuxzasve.mobile.fragments.ArticleListFragmentType;
import com.linuxzasve.mobile.fragments.CommentEditFragment;
import com.linuxzasve.mobile.fragments.CommentListFragment;
import com.linuxzasve.mobile.rest.model.Post;

/**
 * Main activity. This activity handles all fragment for this app.
 *
 * @author dperetin
 */
public class MainActivity extends Activity implements
        ArticleListFragment.ArticleFragmentListener,
        ArticleDisplayFragment.ArticleDisplayFragmentListener,
        CommentListFragment.CommentListFragmentListener,
        CommentEditFragment.CommentEditFragmentListener {

    // holds action from intent
    private String intentAction;

    // if activity was started for search, hold term being searched for
    private String searchQuery;

    @Override
    public void onCreate(final Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        Intent intent = getIntent();
        intentAction = intent.getAction();

        if (savedInstanceState == null) {
            ArticleListFragment articleListFragment = new ArticleListFragment();

            Bundle bundle = new Bundle();

            if (Intent.ACTION_SEARCH.equals(intentAction)) {
                searchQuery = intent.getStringExtra(SearchManager.QUERY);
                bundle.putSerializable(ArticleListFragment.ARTICLE_LIST_FRAGMENT_TYPE, ArticleListFragmentType.SEARCH);
            }
            else {
                bundle.putSerializable(ArticleListFragment.ARTICLE_LIST_FRAGMENT_TYPE, ArticleListFragmentType.LIST);
            }

            articleListFragment.setArguments(bundle);

            getFragmentManager()
                .beginTransaction()
                .replace(android.R.id.content, articleListFragment)
                .commit();
        }
    }

    /** article list fragment listeners **/

    @Override
    public void onArticleFragmentUpNavPressed() {
        onBackPressed();
    }

    @Override
    public void setArticleFragmentActionBarTitle() {
        ActionBar actionBar = getActionBar();

        if (actionBar != null) {
            if (Intent.ACTION_SEARCH.equals(intentAction)) {
                actionBar.setSubtitle(getResources().getString(R.string.action_bar_subtitle_article_search,
                        searchQuery));

                actionBar.setHomeButtonEnabled(true);
                actionBar.setDisplayHomeAsUpEnabled(true);
            } else {
                actionBar.setSubtitle(getResources().getString(R.string.action_bar_subtitle_article_list));

                actionBar.setHomeButtonEnabled(false);
                actionBar.setDisplayHomeAsUpEnabled(false);
            }


        }
    }

    @Override
    public void onListItemSelected(Post post) {
        ArticleDisplayFragment articleDisplayFragment = new ArticleDisplayFragment();

        Bundle bundle = new Bundle();
        bundle.putParcelable(ArticleDisplayFragment.BUNDLE_POST, post);

        articleDisplayFragment.setArguments(bundle);

        getFragmentManager()
                .beginTransaction()
                .replace(android.R.id.content, articleDisplayFragment)
                .addToBackStack(null)
                .commit();
    }

    @Override
    public void onSearchButtonPressed() {
        onSearchRequested();
    }

    // article display listeners

    @Override
    public void onArticleDisplayFragmentUpNavPressed() {
        onBackPressed();
    }

    @Override
    public void setUpArticleDisplayFragmentActionBar(String title) {
        ActionBar actionBar = getActionBar();

        if (actionBar != null) {
            actionBar.setSubtitle(title);
            actionBar.setHomeButtonEnabled(true);
            actionBar.setDisplayHomeAsUpEnabled(true);
        }
    }

    @Override
    public void onShareButtonPressed() {

    }

    @Override
    public void onCommentsListButtonPressed(Post post) {
        CommentListFragment fragment = new CommentListFragment();

        Bundle bundle = new Bundle();
        bundle.putParcelable(ArticleDisplayFragment.BUNDLE_POST, post);

        fragment.setArguments(bundle);

        getFragmentManager()
                .beginTransaction()
                .replace(android.R.id.content, fragment)
                .addToBackStack(null)
                .commit();

    }

    @Override
    public void onCommentListFragmentUpNavPressed() {
        onBackPressed();
    }

    @Override
    public void setCommentListFragmentActionBarTitle(String title) {
        ActionBar actionBar = getActionBar();

        if (actionBar != null) {
            actionBar.setSubtitle(title);
            actionBar.setHomeButtonEnabled(true);
            actionBar.setDisplayHomeAsUpEnabled(true);
        }
    }

    @Override
    public void onNewCommentPressed(Post post) {
        CommentEditFragment fragment = new CommentEditFragment();

        Bundle bundle = new Bundle();
        bundle.putParcelable(ArticleDisplayFragment.BUNDLE_POST, post);

        fragment.setArguments(bundle);

        getFragmentManager()
                .beginTransaction()
                .replace(android.R.id.content, fragment)
                .addToBackStack(null)
                .commit();
    }

    @Override
    public void onCommentEditFragmentUpNavPressed() {
        onBackPressed();
    }

    @Override
    public void setCommentEditFragmentActionBarTitle() {
        ActionBar ab = getActionBar();

        if (ab != null) {
            ab.setHomeButtonEnabled(true);
            ab.setDisplayHomeAsUpEnabled(true);
        }
    }

    @Override
    public void onSendCommentButtonPressed() {
        onBackPressed();
    }
}




Java Source Code List

com.linuxzasve.mobile.ActivityHelper.java
com.linuxzasve.mobile.MainActivity.java
com.linuxzasve.mobile.adapters.ArticleListArrayAdapter.java
com.linuxzasve.mobile.adapters.CommentListArrayAdapter.java
com.linuxzasve.mobile.db.Comment.java
com.linuxzasve.mobile.emote.EmoticonDrawables.java
com.linuxzasve.mobile.fragments.ArticleDisplayFragment.java
com.linuxzasve.mobile.fragments.ArticleListFragmentType.java
com.linuxzasve.mobile.fragments.ArticleListFragment.java
com.linuxzasve.mobile.fragments.CommentEditFragment.java
com.linuxzasve.mobile.fragments.CommentListFragment.java
com.linuxzasve.mobile.googl.GooGlService.java
com.linuxzasve.mobile.googl.GoogleUrlShortener.java
com.linuxzasve.mobile.googl.model.GooGlRequest.java
com.linuxzasve.mobile.googl.model.GooGlResponse.java
com.linuxzasve.mobile.rest.LzsRestGateway.java
com.linuxzasve.mobile.rest.LzsRestService.java
com.linuxzasve.mobile.rest.model.Attachment.java
com.linuxzasve.mobile.rest.model.Author.java
com.linuxzasve.mobile.rest.model.Category.java
com.linuxzasve.mobile.rest.model.Comment.java
com.linuxzasve.mobile.rest.model.CustomFields.java
com.linuxzasve.mobile.rest.model.DetailedImage.java
com.linuxzasve.mobile.rest.model.Image.java
com.linuxzasve.mobile.rest.model.LzsRestResponse.java
com.linuxzasve.mobile.rest.model.Post.java
com.linuxzasve.mobile.rest.model.Tag.java
com.linuxzasve.mobile.rest.model.Thumbnail.java
com.linuxzasve.mobile.timthumb.TimThumb.java