Custom NotificationBar

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

Custom NotificationBar

Postby zitscher » Fri Jan 22, 2010 12:03 am

Hi Guys,
i have a problem with a custom NotificationBar and i'm going nuts! I'm working on it for hours now but haven't found a solution yet. Maybe one of you can help me fix it.

My intention is to create a custom notification with a little picture in it and a progressbar... The notification gets created and it contains the littel picture and the empty bar. So far, so good. But now i tried to test the bar and it won't animate from 0 to 100 :(

Here is a snippet of my code:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. private NotificationManager mNotificationManager;
  3.  
  4. private static final int NOTIFICATION_ID = 1;
  5.  
  6. pivate Notification nf;    
  7.  
  8. private int AKT_PROGRESS = 0;
  9.  
  10. private int MAX_PROGRESS = 100;
  11.  
  12. private RemoteViews rv;
  13.  
  14.  
  15.  
  16. somewhere in the onCreate():
  17.  
  18.  
  19.  
  20.                 //NotificationManager
  21.  
  22.                 String ns = Context.NOTIFICATION_SERVICE;
  23.  
  24.                 mNotificationManager = (NotificationManager) getSystemService(ns);
  25.  
  26.                 nf = new Notification(R.drawable.up,"Uploading Screenshot! Please Wait...",System.currentTimeMillis());        
  27.  
  28.                
  29.  
  30.                 rv = new RemoteViews(this.getPackageName(), R.layout.custom_notificationbar);
  31.  
  32.                 rv.setImageViewResource(R.id.notifyImage, R.drawable.icon);
  33.  
  34.                 rv.setProgressBar(R.id.customProgressBar, 100, AKT_PROGRESS, false);
  35.  
  36. //              rv.setTextViewText(R.id.notifyText, "20%");
  37.  
  38.                 nf.contentView = rv;
  39.  
  40.                                
  41.  
  42.                 Intent notificationIntent = new Intent(this, ShowMap.class);
  43.  
  44.                 PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
  45.  
  46.                 nf.contentIntent = contentIntent;
  47.  
  48.                
  49.  
  50.                 mNotificationManager.notify(NOTIFICATION_ID, nf);
  51.  
  52.                
  53.  
  54.                 for(int z=0; z <=100; z++){
  55.  
  56.                         Message.obtain(uploadProgressBarHandler).sendToTarget();
  57.  
  58.                 }
  59.  
  60.  
  61.  
  62. ....
  63.  
  64.  
  65.  
  66.  
  67.  
  68.     private Handler uploadProgressBarHandler = new Handler() {
  69.  
  70.         @Override
  71.  
  72.         public void handleMessage(Message msg) {
  73.  
  74.             super.handleMessage(msg);
  75.  
  76.             try {
  77.  
  78.                                 Thread.sleep(500);
  79.  
  80.                    
  81.  
  82.                                 if (AKT_PROGRESS >= MAX_PROGRESS) {
  83.  
  84.                                 mNotificationManager.cancel(NOTIFICATION_ID);
  85.  
  86.                                 AKT_PROGRESS = 0;
  87.  
  88.                                 Log.i("UploadProgress", "Finished!");
  89.  
  90.                     } else {
  91.  
  92.                         Log.i("AKT", ""+AKT_PROGRESS);
  93.  
  94.                                 rv.setProgressBar(R.id.customProgressBar, 100, AKT_PROGRESS, false);
  95.  
  96. //                      pb.incrementProgressBy(1);
  97.  
  98. //                      pb.refreshDrawableState();
  99.  
  100. //                      uploadProgressBarHandler.sendEmptyMessageDelayed(0, 100);
  101.  
  102.                         AKT_PROGRESS++;
  103.  
  104.  
  105.  
  106.                     }
  107.  
  108.                        
  109.  
  110.             } catch (InterruptedException e) {
  111.  
  112.                                 // TODO Auto-generated catch block
  113.  
  114.                                 e.printStackTrace();
  115.  
  116.                         }
  117.  
  118.         }
  119.  
  120.     };
  121.  
  122.  
Parsed in 0.039 seconds, using GeSHi 1.0.8.4


And this is the xml to inflate the notification:

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <?xml version="1.0" encoding="utf-8"?>
  2.  
  3. <LinearLayout
  4.  
  5.         xmlns:android="http://schemas.android.com/apk/res/android"
  6.  
  7.         android:id="@+id/custom_notificationbar"
  8.  
  9.         android:layout_width="fill_parent"
  10.  
  11.         android:layout_height="fill_parent"
  12.  
  13.         android:padding="3dp">
  14.  
  15.         <ImageView android:id="@+id/notifyImage"
  16.  
  17.                 android:layout_width="wrap_content"
  18.  
  19.                 android:layout_height="fill_parent"
  20.  
  21.                 android:layout_marginRight="10dp" />
  22.  
  23.         <ProgressBar style="?android:attr/progressBarStyleHorizontal"
  24.  
  25.                 android:id="@+id/customProgressBar"
  26.  
  27.                 android:max="100"
  28.  
  29.                 android:progress="1"
  30.  
  31.                 android:layout_width="fill_parent"
  32.  
  33.                 android:layout_height="wrap_content"
  34.  
  35.                 android:layout_gravity="center_vertical"
  36.  
  37.         />
  38.  
  39.         <TextView android:id="@+id/notifyText"
  40.  
  41.                 android:layout_width="wrap_content"
  42.  
  43.                 android:layout_height="wrap_content"
  44.  
  45.                 android:text="0%"
  46.  
  47.                 android:textColor="#000"        
  48.  
  49.                 android:layout_gravity="center_vertical"
  50.  
  51.         />     
  52.  
  53. </LinearLayout>
Parsed in 0.003 seconds, using GeSHi 1.0.8.4


Thanks a lot!
Greetings from Bremen, Germany
User avatar
zitscher
Freshman
Freshman
 
Posts: 5
Joined: Fri Nov 20, 2009 8:20 pm

Top

Postby zitscher » Fri Jan 22, 2010 11:22 am

Nobody with a clue? :-/
User avatar
zitscher
Freshman
Freshman
 
Posts: 5
Joined: Fri Nov 20, 2009 8:20 pm

Postby zitscher » Fri Jan 22, 2010 6:39 pm

Problem solved: forgot to notify the Notification again -_-

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. mNotificationManager.notify(NOTIFICATION_ID);
  3.  
  4.  
Parsed in 0.030 seconds, using GeSHi 1.0.8.4
User avatar
zitscher
Freshman
Freshman
 
Posts: 5
Joined: Fri Nov 20, 2009 8:20 pm

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 2 guests