Android Open Source - Alfred4Android Floating Dialog






From Project

Back to project page Alfred4Android.

License

The source code is released under:

Apache License

If you think the Android project Alfred4Android 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 com.toraleap.collimator.ui;
/*ww w  . ja v  a2 s .  c  om*/
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.toraleap.collimator.R;

public final class FloatingDialog extends Dialog {

  private AbsListView mView;
  private TextView mTextTitle;
  private FloatingDialogAdapter mAdapter;
  private DialogInterface.OnClickListener mListener;
  private int mLayout;
  private int mSubLayout;
  private int mSelected;
  private String mTitle;

  public FloatingDialog(Context context, int theme, int layout, int sublayout, int title, int itemsResource, int[] icons, int selected, DialogInterface.OnClickListener listener) {
    super(context, theme);
    mLayout = layout;
    mSubLayout = sublayout;
    mTitle = context.getResources().getString(title);
    mAdapter = new FloatingDialogAdapter(getLayoutInflater(), context.getResources().getStringArray(itemsResource), icons);
    mListener = listener;
  }
  
  public FloatingDialog(Context context, int theme, int layout, int sublayout, String title, String[] items, int[] icons, int selected, DialogInterface.OnClickListener listener) {
    super(context, theme);
    mLayout = layout;
    mSubLayout = sublayout;
    mTitle = title;
    mAdapter = new FloatingDialogAdapter(getLayoutInflater(), items, icons);
    mListener = listener;
  }
  
  @Override
  protected void onCreate(Bundle savedInstanceState)
  {
    setContentView(mLayout);
    mTextTitle = (TextView) findViewById(R.id.dialog_title);
    mTextTitle.setText(mTitle);
    mView = (AbsListView) findViewById(R.id.floating_dialog_view);
    mView.setAdapter(mAdapter);
    mView.setSelection(mSelected);
    mView.setOnItemClickListener(new OnItemClickListener());
    mView.setFocusable(true);
  }
  
  public boolean onTouchEvent(MotionEvent event) {
    if (event.getAction() == MotionEvent.ACTION_DOWN) {
      cancel();
      return true;
    }
    return false;
  }
  
  public void show() {
    super.show();
  }
  
  private class OnItemClickListener implements  AdapterView.OnItemClickListener {
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
      mListener.onClick(FloatingDialog.this, position);
    }
  }
  
  public class FloatingDialogAdapter extends BaseAdapter {
    
    LayoutInflater mInflater;
    String[] mItems;
    int[] mIcons;
    
    public FloatingDialogAdapter(LayoutInflater inflater, String[] items, int[] icons) {
      mInflater = inflater;
      mItems = items;
      mIcons = icons;
    }

    public int getCount() {
      return mItems.length;
    }

    public Object getItem(int position) {
      return mItems[position];
    }

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

    public View getView(int position, View convertView, ViewGroup parent) {
      View view;
      ViewHolder holder;
      if (convertView != null && convertView.getId() == mSubLayout) {
        view = convertView;
        holder = (ViewHolder)view.getTag();
      } else {
        view = mInflater.inflate(mSubLayout, parent, false);
        holder = new ViewHolder();
        holder.icon = (ImageView)view.findViewById(R.id.source_icon);
        holder.label = (TextView)view.findViewById(R.id.source_label);
        view.setTag(holder);
      }
      if (mIcons != null) {
        holder.icon.setImageResource(mIcons[position]);
      } else {
        holder.icon.setImageResource(android.R.drawable.ic_menu_slideshow);
      }
      holder.label.setText(mItems[position]);
      return view;
    }
    
  }
  
  public class ViewHolder
    {
           public ImageView icon;
           public TextView label;
    }

}




Java Source Code List

android.media.MediaMetadataRetriever.java
com.toraleap.collimator.AppSearchActivity.java
com.toraleap.collimator.GlobalContext.java
com.toraleap.collimator.HelpActivity.java
com.toraleap.collimator.PrefsActivity.java
com.toraleap.collimator.SearchActivity.java
com.toraleap.collimator.ShortcutActivity.java
com.toraleap.collimator.bll.FileScannerService.java
com.toraleap.collimator.bll.TagGenerator.java
com.toraleap.collimator.dal.DBColumns.java
com.toraleap.collimator.dal.DBHelper.java
com.toraleap.collimator.dal.DBOperation.java
com.toraleap.collimator.data.Expression.java
com.toraleap.collimator.data.IndexData.java
com.toraleap.collimator.data.IndexLoader.java
com.toraleap.collimator.data.Index.java
com.toraleap.collimator.data.Match.java
com.toraleap.collimator.data.Matcher.java
com.toraleap.collimator.data.Sorter.java
com.toraleap.collimator.ext.GlobalProvider.java
com.toraleap.collimator.ext.Playlist.java
com.toraleap.collimator.model.BaseTag.java
com.toraleap.collimator.ui.FloatingDialog.java
com.toraleap.collimator.ui.MatchAdapter.java
com.toraleap.collimator.util.DigestUtil.java
com.toraleap.collimator.util.FileInfo.java
com.toraleap.collimator.util.MimeTypeMap.java
com.toraleap.collimator.util.RecursiveFileObserver.java
com.toraleap.collimator.util.ShortcutHelper.java
com.toraleap.collimator.util.SoftCache.java
com.toraleap.collimator.util.ThumbnailUtil.java
com.toraleap.collimator.util.Unicode2Alpha.java