Extract a Instance of specific class RemoteViews which don’t know to how to make.

Extract a Instance of specific class RemoteViews which I don’t know to how to make.


Return instance that i’m looking for.

If type == 0, then return a instance first found.
If type == 1, then return a instance second found.


The problem is, because of tree search, maybe return different value depending on the situation.



ex) find a instance of TextView in RemoteViews.

count is a static variable.


      static public TextView extractTextView(Context context, RemoteViews views, int type) {
           
        Context remotePackageContext ;
        remotePackageContext  = context.getApplicationContext();
        try{
              remotePackageContext = context.createPackageContext(TARGET_PACKAGE, 0);
        }catch(Exception e){;}
       
        LinearLayout ll = new LinearLayout(remotePackageContext );
        View view = views.apply(remotePackageContext, ll);
        count = 0;
       
        LogControl.i(TAG, “msg = ” + searchForTextView(view,2).getText().toString());
        count = 0;
       
        return searchForTextView(view,type);
    }
     
     
    static public TextView searchForTextView(View view, int duration) {
        if (view instanceof TextView) {
              TextView textView = (TextView)view;
              String text = textView.getText().toString();
              count ++;
              LogControl.i(TAG, “tview string = ” + text);
             
              if(textView.getTag() == null && count > duration){
                  
                   return (TextView)view;
              }
        }

        if (view instanceof ViewGroup) {
            ViewGroup viewGroup = (ViewGroup) view;
            for (int i = 0; i < viewGroup.getChildCount(); i++) {
                TextView result = searchForTextView(viewGroup.getChildAt(i), duration);
                if (result != null) {
                     if(count > duration)
                           return result;
                }
            }
        }
        return null;
    }

One thought on “Extract a Instance of specific class RemoteViews which don’t know to how to make.”

  1. I was wondering if you ever thought of changing the structure of your website?
    Its very well written; I love what youve got to say.
    But maybe you could a little more in the way of content so people could connect
    with it better. Youve got an awful lot of text
    for only having 1 or two images. Maybe you could
    space it out better?

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>