Android Open Source - logback-android-ui Context Selector






From Project

Back to project page logback-android-ui.

License

The source code is released under:

Copyright (C) 2011-2012 Vanderbilt University Permission is hereby granted, free of charge, to any person obtaining a copy of this data, including any software or models in source or binary form, as ...

If you think the Android project logback-android-ui 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

/*Copyright (C) 2010-2012 Institute for Software Integrated Systems (ISIS)
This software was developed by the Institute for Software Integrated
Systems (ISIS) at Vanderbilt University, Tennessee, USA for the 
Transformative Apps program under DARPA, Contract # HR011-10-C-0175.
The United States Government has unlimited rights to this software. 
The US government has the right to use, modify, reproduce, release, 
perform, display, or disclose computer software or computer software 
documentation in whole or in part, in any manner and for any 
purpose whatsoever, and to have or authorize others to do so.
 *///w ww  . j ava  2 s.com
package edu.vu.isis.logger.ui;

import java.util.ArrayList;
import java.util.List;

import android.app.ListActivity;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.ProviderInfo;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;
import edu.vu.isis.logger.R;

/**
 * Allows the user to select which application's LoggerContext to view and edit.
 * Android is queried for applications running LAUI by finding all applications
 * with Content Providers whose authorities end with "LauiContentProvider"
 * @author Nick King
 * 
 */
public class ContextSelector extends ListActivity {

  private List<AppHolder> mAppList = new ArrayList<AppHolder>();

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.context_selector);
  }

  @Override
  public void onStart() {
    super.onStart();
    findContentProviders();
    setListAdapter(new AppHolderAdapter());
  }

  private void findContentProviders() {
    mAppList.clear();

    final PackageManager pm = getPackageManager();
    final List<PackageInfo> packageList = pm
        .getInstalledPackages(PackageManager.GET_PROVIDERS);

    for (PackageInfo pkg : packageList) {
      if (pkg.applicationInfo == null || pkg.providers == null)
        continue;
      for (ProviderInfo info : pkg.providers) {
        if (info.authority.endsWith("LauiContentProvider")) {
          AppHolder holder = new AppHolder();
          Drawable icon = pkg.applicationInfo.loadIcon(pm);
          CharSequence label = pkg.applicationInfo.loadLabel(pm);

          holder.cpAuthority = info.authority;
          holder.icon = icon;
          holder.label = label;
          mAppList.add(holder);
        }
      }
    }
  }

  public void viewLogcat(View v) {
    Intent intent = new Intent();
    intent.setClass(this, LogcatLogViewer.class);
    startActivity(intent);
  }

  public void refreshList(View v) {
    findContentProviders();
  }

  @Override
  protected void onListItemClick(ListView parent, View row, int position,
      long id) {
    Intent intent = new Intent();
    intent.setClass(this, LoggerEditor.class);
    intent.putExtra(LoggerEditor.EXTRA_NAME,
        mAppList.get(position).cpAuthority);

    startActivity(intent);
  }

  private static class AppHolder {

    private Drawable icon;
    private CharSequence label;
    private String cpAuthority;

  }

  private static class ViewHolder {
    private TextView tv;
  }

  private class AppHolderAdapter extends BaseAdapter {

    @Override
    public int getCount() {
      return mAppList.size();
    }

    @Override
    public Object getItem(int position) {
      return mAppList.get(position);
    }

    @Override
    public long getItemId(int position) {
      return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
      final View row;
      if (convertView == null) {
        LayoutInflater inflater = getLayoutInflater();
        row = inflater.inflate(R.layout.context_selector_row, parent,
            false);
      } else {
        row = convertView;
      }

      TextView tv;
      if (row.getTag() == null) {
        tv = (TextView) row.findViewById(R.id.context_selector_row_tv);
        row.setTag(new ViewHolder().tv = tv);
      } else {
        ViewHolder vHolder = (ViewHolder) row.getTag();
        tv = vHolder.tv;
      }

      AppHolder aHolder = mAppList.get(position);
      tv.setText(aHolder.label);
      tv.setCompoundDrawablesWithIntrinsicBounds(aHolder.icon, null,
          null, null);

      return row;
    }

  }

}




Java Source Code List

edu.vu.isis.logger.lib.AppenderStoreAction.java
edu.vu.isis.logger.lib.AppenderStore.java
edu.vu.isis.logger.lib.LauiContentProvider.java
edu.vu.isis.logger.lib.Loggers.java
edu.vu.isis.logger.lib.Tree.java
edu.vu.isis.logger.provider.LauiContentUri.java
edu.vu.isis.logger.ui.ContextSelector.java
edu.vu.isis.logger.ui.FileLogViewer.java
edu.vu.isis.logger.ui.HintSpinner.java
edu.vu.isis.logger.ui.LogViewerBase.java
edu.vu.isis.logger.ui.LogViewerPreferences.java
edu.vu.isis.logger.ui.LogcatLogViewer.java
edu.vu.isis.logger.ui.LoggerEditor.java
edu.vu.isis.logger.util.ByteBuffers.java
edu.vu.isis.logger.util.FileLogReader.java
edu.vu.isis.logger.util.LogElementAdapter.java
edu.vu.isis.logger.util.LogElement.java
edu.vu.isis.logger.util.LogLevel.java
edu.vu.isis.logger.util.LogReader.java
edu.vu.isis.logger.util.LogcatLogReader.java
edu.vu.isis.logger.util.ScrollingFileReader.java
edu.vu.isis.logger.util.TreeAdapter.java