Android Open Source - friendica-for-android Notification






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;
/* 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.io.File;
import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
//from   ww w  .  j a v  a 2 s .co m
import org.json.JSONException;
import org.json.JSONObject;
import org.w3c.dom.Node;

import android.content.Context;
import android.graphics.Typeface;
import android.net.Uri;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class Notification {
  private static final String TAG="Friendica/Notification";
  
  
  public String href,name,url,photo,date,seen,content;
  public boolean isUnread = false;
  
  public String targetUrl, targetComponent, targetData;
  
  public static Notification fromXmlNode(Node d) {
    Notification n = new Notification();
    
    n.href = d.getAttributes().getNamedItem("href").getNodeValue();
    n.name = d.getAttributes().getNamedItem("name").getNodeValue();
    n.url = d.getAttributes().getNamedItem("url").getNodeValue();
    n.photo = d.getAttributes().getNamedItem("photo").getNodeValue();
    n.date = d.getAttributes().getNamedItem("date").getNodeValue();
    n.seen = d.getAttributes().getNamedItem("seen").getNodeValue();
    
    n.content = d.getTextContent();
    
    if (n.content.startsWith("→")) {
      n.isUnread = true;
      n.content = n.content.substring(6);
    }
    
    return n;
  }
  
  public void resolveTarget(Context ctx, final Runnable done) {
    final TwAjax resT = new TwAjax(ctx, true, true);
    resT.fetchUrlHeader("GET", this.href, "Location", new Runnable() {
      @Override public void run() {
        
        targetUrl = resT.fetchHeaderResult[0].getValue();
        
        if (targetUrl.endsWith("/message/")) {
          targetComponent = "msg:all";
        }
        
        Matcher m = Max.regeximatch(".*/display/.*/([0-9]+)/?", targetUrl);
        if (m.matches()) {
          targetComponent = "conversation:"; targetData = m.group(1);
        }
        
        done.run();
      }
    });
  }
  
  public static class NotificationsListAdapter extends ArrayAdapter<Notification> {
    
    private static final String TAG = "friendica01.PostListAdapter";
    
    public NotificationsListAdapter(Context context, ArrayList<Notification> notifs) {
      super(context, R.layout.pl_listitem, notifs);
      
    }
    
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
      if (convertView == null) {
        LayoutInflater inf = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        
        convertView = inf.inflate(R.layout.pl_listitem, null);
      }
      
      Notification post = (Notification) getItem(position);
      
      final ImageView profileImage = (ImageView) convertView.findViewById(R.id.profileImage);
      profileImage.setImageResource(R.drawable.ic_launcher);
      try {
        String piurl = post.photo;
        Log.i(TAG, "Going to download profile img: " + piurl);
        final TwAjax pidl = new TwAjax(getContext(), true, false);
        
        //OLD: uncached, download every time, annoying when scrolling fast!
        /*pidl.getUrlBitmap(piurl, new Runnable() {
          @Override
          public void run() {
            
            profileImage.setImageBitmap(pidl.getBitmapResult());
          }
        });*/
        
        //NEW: download cached
        final File pifile = new File(Max.IMG_CACHE_DIR + "/pi_" + Max.cleanFilename(piurl));
        if (pifile.isFile()) {
          profileImage.setImageURI(Uri.parse("file://" + pifile.getAbsolutePath()));
        } else {
          pidl.urlDownloadToFile(piurl, pifile.getAbsolutePath(), new Runnable() {
            @Override
            public void run() {
              profileImage.setImageURI(Uri.parse("file://" + pifile.getAbsolutePath()));
            }
          });
        }
      } catch (Exception e) {
      }
  
      TextView userName = (TextView) convertView.findViewById(R.id.userName);
      userName.setText(post.content);
      if (!post.isUnread) userName.setTypeface(Typeface.DEFAULT);
  
      TextView htmlContent = (TextView) convertView.findViewById(R.id.htmlContent);
      htmlContent.setText(post.date);
      
      return convertView;
    }
    
    
  }
}




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