Android Open Source - friendica-for-android Main Menu Fragment






From Project

Back to project page friendica-for-android.

License

The source code is released under:

This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.

If you think the Android project friendica-for-android 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 de.wikilab.android.friendica01.fragment;
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
import java.util.ArrayList;
/*from   w  w  w  .  j  ava 2  s .  c o m*/
import org.w3c.dom.Document;

import de.wikilab.android.friendica01.FragmentParentListener;
import de.wikilab.android.friendica01.LoginListener;
import de.wikilab.android.friendica01.Max;
import de.wikilab.android.friendica01.R;
import de.wikilab.android.friendica01.TwAjax;
import de.wikilab.android.friendica01.R.id;
import de.wikilab.android.friendica01.R.layout;
import de.wikilab.android.friendica01.R.string;
import de.wikilab.android.friendica01.adapter.HtmlStringArrayAdapter;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;

public class MainMenuFragment extends Fragment implements LoginListener {
  private static final String TAG="Friendica/MainMenuFragment";
  
  
  View mainView;
  
  ListView lvw;

  private int selectedItemIndex=-1;
  
  public final ArrayList<String> MainList = new ArrayList<String>();
  
  
  private void appendNumber(ArrayList<String> listWithNotifications, int index, String number) {
    listWithNotifications.set(index, listWithNotifications.get(index) + " <b>[<font color=red>" + number + "</font>]</b>");
  }
  
  public void UpdateList() {
    
    final TwAjax t = new TwAjax(getActivity(), true, true);
    t.getUrlXmlDocument(Max.getServer(getActivity()) + "/ping", new Runnable() {
    //t.getUrlContent("http://" + server + "/ping", new Runnable() {
      @Override
      public void run() {
        ArrayList<String> listWithNotifications = (ArrayList<String>) MainList.clone();

        Document xd = t.getXmlDocumentResult();
        
        try {
          appendNumber(listWithNotifications, 0, xd.getElementsByTagName("net").item(0).getTextContent());
        //} catch (Exception ingoreException) {}
        
        //try {
          appendNumber(listWithNotifications, 4, xd.getElementsByTagName("intro").item(0).getTextContent() + " intros");
        //} catch (Exception ingoreException) {}
        
        //try {
          appendNumber(listWithNotifications, 2, xd.getElementsByTagName("home").item(0).getTextContent());
        //} catch (Exception ingoreException) {}
        
        //try {
          appendNumber(listWithNotifications, 1, xd.getElementsByTagName("notif").item(0).getAttributes().getNamedItem("count").getNodeValue());
        //} catch (Exception ingoreException) {}
        
        //try {
          lvw.setAdapter(new HtmlStringArrayAdapter(getActivity(), R.layout.mainmenuitem, android.R.id.text1, listWithNotifications));
          if (selectedItemIndex>-1)((HtmlStringArrayAdapter)lvw.getAdapter()).setSelectedItemIndex(selectedItemIndex);
        } catch (Exception ignoreException) {}
      }
    });
    //lvw.setAdapter(new HtmlStringArrayAdapter(this, android.R.layout.simple_list_item_1, android.R.id.text1, MainList));
  }
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (savedInstanceState != null) {
      if (savedInstanceState.containsKey("selectedItemIndex")) {
        selectedItemIndex=savedInstanceState.getInt("selectedItemIndex");
      }
    }
  }

  @Override
  public void onSaveInstanceState(Bundle outState) {
    outState.putInt("selectedItemIndex", selectedItemIndex);
    super.onSaveInstanceState(outState);
  }
  
  @Override
  public void onResume() {
    UpdateList();
    super.onResume();
  }
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    
    mainView = inflater.inflate(R.layout.mainmenu, container);
    
    lvw = (ListView) mainView.findViewById(R.id.listview);
    lvw.setAdapter(new HtmlStringArrayAdapter(getActivity(), R.layout.mainmenuitem, android.R.id.text1, MainList));
    if (selectedItemIndex>-1)((HtmlStringArrayAdapter)lvw.getAdapter()).setSelectedItemIndex(selectedItemIndex);
    
    MainList.add(getString(R.string.mm_timeline));
    MainList.add(getString(R.string.mm_notifications));
    MainList.add(getString(R.string.mm_mywall));
    MainList.add(getString(R.string.mm_myphotoalbums));
    MainList.add(getString(R.string.mm_friends));
    MainList.add(getString(R.string.mm_directmessages));
    MainList.add(getString(R.string.mm_updatemystatus));
    MainList.add(getString(R.string.mm_takephoto));
    MainList.add(getString(R.string.mm_selectphoto));
    MainList.add(getString(R.string.mm_preferences));
    MainList.add(getString(R.string.mm_logout));

    return mainView;
  }


  
  @Override
  public void OnLogin() {
    UpdateList();
    
    lvw.setOnItemClickListener(new AdapterView.OnItemClickListener() {
      @Override public void onItemClick(AdapterView<?> arg0, View arg1, int index, long arg3) {
        ((FragmentParentListener)getActivity()).OnFragmentMessage("Navigate Main Menu", MainList.get(index), null);
        ((HtmlStringArrayAdapter)lvw.getAdapter()).setSelectedItemIndex(index);
        selectedItemIndex=index;
      }
    });
  }
  
  

}




Java Source Code List

com.handmark.pulltorefresh.library.PullToRefreshAdapterViewBase.java
com.handmark.pulltorefresh.library.PullToRefreshBase.java
com.handmark.pulltorefresh.library.PullToRefreshExpandableListView.java
com.handmark.pulltorefresh.library.PullToRefreshGridView.java
com.handmark.pulltorefresh.library.PullToRefreshListView.java
com.handmark.pulltorefresh.library.PullToRefreshWebView.java
com.handmark.pulltorefresh.library.internal.EmptyViewMethodAccessor.java
com.handmark.pulltorefresh.library.internal.IndicatorLayout.java
com.handmark.pulltorefresh.library.internal.LoadingLayout.java
de.wikilab.android.friendica01.FileUploadService.java
de.wikilab.android.friendica01.FragmentParentListener.java
de.wikilab.android.friendica01.GCMIntentService.java
de.wikilab.android.friendica01.HtmlImageHelper.java
de.wikilab.android.friendica01.LoginListener.java
de.wikilab.android.friendica01.Max.java
de.wikilab.android.friendica01.NotificationCheckerService.java
de.wikilab.android.friendica01.Notification.java
de.wikilab.android.friendica01.TwAjax.java
de.wikilab.android.friendica01.ViewServer.java
de.wikilab.android.friendica01.activity.FriendicaImgUploadActivity.java
de.wikilab.android.friendica01.activity.GenericContentActivity.java
de.wikilab.android.friendica01.activity.HomeActivity.java
de.wikilab.android.friendica01.activity.MainScreenActivity.java
de.wikilab.android.friendica01.activity.MessageDetailActivity.java
de.wikilab.android.friendica01.activity.MessagesActivity.java
de.wikilab.android.friendica01.activity.PreferenceContainerActivity.java
de.wikilab.android.friendica01.activity.PreferencesActivity.java
de.wikilab.android.friendica01.activity.UserProfileActivity.java
de.wikilab.android.friendica01.activity.WritePostActivity.java
de.wikilab.android.friendica01.adapter.HtmlStringArrayAdapter.java
de.wikilab.android.friendica01.adapter.MessageContentAdapter.java
de.wikilab.android.friendica01.adapter.MessageListAdapter.java
de.wikilab.android.friendica01.adapter.PhotoGalleryAdapter.java
de.wikilab.android.friendica01.adapter.PostListAdapter.java
de.wikilab.android.friendica01.fragment.ContentFragment.java
de.wikilab.android.friendica01.fragment.FriendListFragment.java
de.wikilab.android.friendica01.fragment.MainMenuFragment.java
de.wikilab.android.friendica01.fragment.MessageViewFragment.java
de.wikilab.android.friendica01.fragment.MessageWriteFragment.java
de.wikilab.android.friendica01.fragment.PhotoGalleryFragment.java
de.wikilab.android.friendica01.fragment.PostDetailFragment.java
de.wikilab.android.friendica01.fragment.PostListFragment.java
de.wikilab.android.friendica01.fragment.WelcomeFragment.java
de.wikilab.android.friendica01.fragment.WritePostFragment.java