Example #1
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    status = (EditText) findViewById(R.id.status);

    Button send = (Button) findViewById(R.id.send);

    send.setOnClickListener(onSend);

    prefs = PreferenceManager.getDefaultSharedPreferences(this);
    prefs.registerOnSharedPreferenceChangeListener(prefListener);

    bindService(new Intent(ITwitterMonitor.class.getName()), svcConn, Context.BIND_AUTO_CREATE);

    adapter = new TimelineAdapter();

    ListView list = (ListView) findViewById(R.id.timeline);

    //		list.addHeaderView(buildHeader());
    list.setAdapter(adapter);
    list.setOnItemClickListener(onStatusClick);
    list.setOnItemSelectedListener(selectionListener);

    TabHost.TabSpec spec = getTabHost().newTabSpec("tag1");

    spec.setContent(R.id.status_tab);
    spec.setIndicator("Status", getResources().getDrawable(R.drawable.status));
    getTabHost().addTab(spec);

    spec = getTabHost().newTabSpec("tag2");
    spec.setContent(R.id.friends);
    spec.setIndicator("Friends", getResources().getDrawable(R.drawable.friends));
    getTabHost().addTab(spec);

    getTabHost().setCurrentTab(0);

    try {
      for (Twitter.User u : getClient().getFriends()) {
        friends.add(u.screenName);
      }
    } catch (Throwable t) {
      Log.e("Patchy", "Exception in JTwitter#getFriends()", t);
      goBlooey(t);
    }

    Collections.sort(friends);

    friendsList = (ListView) findViewById(R.id.friends);

    friendsAdapter =
        new ArrayAdapter<String>(this, android.R.layout.simple_list_item_multiple_choice, friends);
    friendsList.setAdapter(friendsAdapter);
    friendsList.setItemsCanFocus(false);
    friendsList.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);

    locMgr = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    locMgr.requestLocationUpdates(LocationManager.GPS_PROVIDER, 10000, 10000.0f, onLocationChange);
  }
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.fragment_tv_1, container, false);
    mListViewLayout = v.findViewById(R.id.list_layout);
    mGalleryLayout = v.findViewById(R.id.tv_gallery_layout);
    mListCover = v.findViewById(R.id.list_cover);
    mTvLeft = v.findViewById(R.id.tv_left);
    mTvRight = v.findViewById(R.id.tv_right);

    mListView = (ListView) v.findViewById(R.id.tv_list);
    mListViewAdapter = new ListViewAdapter(getActivity());
    mListView.setAdapter(mListViewAdapter);
    mListView.setOnItemSelectedListener(this);
    mListView.setOnItemClickListener(this);

    mGallery = (Gallery) v.findViewById(R.id.tv_gallery);
    mGalleryAdapter = new GalleryAdapter(getActivity());
    mGallery.setAdapter(mGalleryAdapter);

    mProgressBar = (ProgressBar) v.findViewById(R.id.loading);

    setViewsVisiable(View.GONE);

    init();

    return v;
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    lvMain = (ListView) findViewById(R.id.lvMain);

    ArrayAdapter<CharSequence> adapter =
        ArrayAdapter.createFromResource(this, R.array.names, android.R.layout.simple_list_item_1);
    lvMain.setAdapter(adapter);

    lvMain.setOnItemClickListener(
        new AdapterView.OnItemClickListener() {
          public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Log.d(LOG_TAG, "itemClick: position = " + position + ", id = " + id);
          }
        });

    lvMain.setOnItemSelectedListener(
        new AdapterView.OnItemSelectedListener() {
          public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            Log.d(LOG_TAG, "itemSelect: position = " + position + ", id = " + id);
          }

          public void onNothingSelected(AdapterView<?> parent) {
            Log.d(LOG_TAG, "itemSelect: nothing");
          }
        });

    lvMain.setOnScrollListener(
        new AbsListView.OnScrollListener() {
          public void onScrollStateChanged(AbsListView view, int scrollState) {
            Log.d(LOG_TAG, "scrollState = " + scrollState);
          }

          public void onScroll(
              AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
            // Log.d(LOG_TAG, "scroll: firstVisibleItem = " + firstVisibleItem + ",
            // visibleItemCount" + visibleItemCount + ", totalItemCount" + totalItemCount);
          }
        });
  }
Example #4
0
  @Test
  public void testSetSelection_ShouldFireOnItemSelectedListener() throws Exception {
    listView.setAdapter(new CountingAdapter(1));
    ShadowHandler.idleMainLooper();

    listView.setOnItemSelectedListener(
        new AdapterView.OnItemSelectedListener() {
          @Override
          public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            transcript.add("item was selected: " + position);
          }

          @Override
          public void onNothingSelected(AdapterView<?> parent) {}
        });

    listView.setSelection(0);
    ShadowHandler.idleMainLooper();
    transcript.assertEventsSoFar("item was selected: 0");
  }
Example #5
0
  public MVCHelper(IRefreshView refreshView, ILoadView loadView, ILoadMoreView loadMoreView) {
    super();
    this.context = refreshView.getContentView().getContext().getApplicationContext();
    this.autoLoadMore = true;
    this.refreshView = refreshView;
    contentView = refreshView.getContentView();
    contentView.setOverScrollMode(View.OVER_SCROLL_NEVER);
    refreshView.setOnRefreshListener(onRefreshListener);
    if (loadMoreView != null) {
      if (contentView instanceof ListView) {
        final ListView listView = (ListView) contentView;
        listView.setCacheColorHint(Color.TRANSPARENT);
        listView.setOnScrollListener(new ListViewOnScrollListener());
        listView.setOnItemSelectedListener(new ListViewOnItemSelectedListener());
        mLoadMoreView = loadMoreView;
        mLoadMoreView.init(
            new FootViewAdder() {

              @Override
              public View addFootView(int layoutId) {
                View view = LayoutInflater.from(context).inflate(layoutId, listView, false);
                return addFootView(view);
              }

              @Override
              public View addFootView(View view) {
                listView.addFooterView(view);
                return view;
              }
            },
            onClickLoadMoreListener);
      } else if (contentView instanceof RecyclerView) {
        RecyclerView recyclerView = (RecyclerView) contentView;
        recyclerView.setOnScrollListener(new RecyclerViewOnScrollListener());
        mLoadMoreView = loadMoreView;
      }
    }
    mLoadView = loadView;
    mLoadView.init(refreshView.getSwitchView(), onClickRefresListener);
  }
Example #6
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_invite_page);

    contactsListView = (ListView) findViewById(R.id.listView1);

    String[] from = {"name", "number"};
    int[] to = {R.id.textView1, R.id.textView2};

    contacts = fetchWhatsAppContacts();

    SimpleAdapter adapter = new SimpleAdapter(this, contacts, R.layout.activity_contacts, from, to);
    contactsListView.setAdapter(adapter);

    contactsListView.setOnItemSelectedListener(
        new OnItemSelectedListener() {

          @Override
          public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            try {
              Uri uri = Uri.parse("smsto:" + contacts.get(R.id.textView2).get("number").toString());
              Intent i = new Intent(Intent.ACTION_SENDTO, uri);
              i.setPackage("com.whatsapp");
              startActivity(i);
            } catch (ActivityNotFoundException e) {
              Toast.makeText(getApplicationContext(), "no whatsapp!", Toast.LENGTH_SHORT).show();
              Log.e("Intent", e.getMessage());
            }
          }

          @Override
          public void onNothingSelected(AdapterView<?> parent) {
            // TODO Auto-generated method stub

          }
        });
  }
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView =
        inflater.inflate(R.layout.ext_cashila_payments_fragment_pending, container, false);
    ButterKnife.inject(this, rootView);

    mbw = MbwManager.getInstance(this.getActivity());
    cs = ((CashilaPaymentsActivity) getActivity()).getCashilaService();
    eventBus = mbw.getEventBus();

    getBillPays(true);

    lvPending.setOnItemSelectedListener(
        new AdapterView.OnItemSelectedListener() {
          @Override
          public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {}

          @Override
          public void onNothingSelected(AdapterView<?> adapterView) {}
        });

    return rootView;
  }
  private void init(Context context) {
    // LayoutInflater inflater = (LayoutInflater) context
    // .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    LayoutInflater inflater = LayoutInflater.from(context);
    inflater.inflate(R.layout.view_region, this, true);
    regionListView = (ListView) findViewById(R.id.listView);
    plateListView = (ListView) findViewById(R.id.listView2);

    earaListViewAdapter = new TextAdapter(context, groups, R.drawable.choose_item_selected, 0);
    earaListViewAdapter.setSelectedPositionNoNotify(tEaraPosition);
    regionListView.setAdapter(earaListViewAdapter);

    regionListView.setOnItemSelectedListener(
        new OnItemSelectedListener() {

          @Override
          public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
            System.out.println(arg1);
          }

          @Override
          public void onNothingSelected(AdapterView<?> arg0) {}
        });

    earaListViewAdapter.setOnItemClickListener(
        new TextAdapter.OnItemClickListener() {

          @Override
          public void onItemClick(View view, int position) {
            //
            // mOnSelectListener.getValue(showString, parentId,
            // parentId);
            if (position < children.size()) {
              parentId = position;
              childrenItem.clear();
              childrenItem.addAll(children.get(position));
              if (children.get(position).size() == 0) {
                mOnSelectListener.getValue(groups.get(position), parentId, position);
              }
              plateListViewAdapter.notifyDataSetChanged();
            }
          }
        });
    if (tEaraPosition < children.size()) childrenItem.addAll(children.get(tEaraPosition));
    plateListViewAdapter = new TextAdapter(context, childrenItem, 0, 1);
    plateListViewAdapter.setSelectedPositionNoNotify(tBlockPosition);
    plateListView.setAdapter(plateListViewAdapter);
    plateListViewAdapter.setOnItemClickListener(
        new TextAdapter.OnItemClickListener() {

          @Override
          public void onItemClick(View view, final int position) {
            showString = childrenItem.get(position);
            if (mOnSelectListener != null) {
              mOnSelectListener.getValue(showString, parentId, position);
            }
            plateListViewAdapter.notifyDataSetChanged();
          }
        });
    if (tBlockPosition < childrenItem.size()) showString = childrenItem.get(tBlockPosition);
    if (showString.contains("不限")) {
      showString = showString.replace("不限", "");
    }
    setDefaultSelect();
  }
Example #9
0
  @Override
  public View onCreateSubView(LayoutInflater inflater) {
    // TODO Auto-generated method stub
    View contentView = inflater.inflate(R.layout.video, null, false);

    sourceLv = (ListView) contentView.findViewById(R.id.source_lv);
    sourceLv.setAdapter(listAdapter);
    sourceLv.setOnItemClickListener(onItemClickListener);
    sourceLv.setOnItemSelectedListener(onItemSelectedListener);
    sourceLv.requestFocus();

    surfaceContainer = contentView.findViewById(R.id.surface_container);

    surfaceView = (SurfaceView) contentView.findViewById(R.id.video_surface);
    surfaceHolder = surfaceView.getHolder();
    surfaceHolder.addCallback(
        new SurfaceHolder.Callback() {

          @Override
          public void surfaceDestroyed(SurfaceHolder arg0) {
            // TODO Auto-generated method stub
            //				videoInspect.setFullscale();
            LogUtil.d(TAG, "surfaceDestroyed");
          }

          @Override
          public void surfaceCreated(SurfaceHolder arg0) {
            // TODO Auto-generated method stub
            LogUtil.d(TAG, "surfaceCreated");
          }

          @Override
          public void surfaceChanged(SurfaceHolder arg0, int arg1, int arg2, int arg3) {
            // TODO Auto-generated method stub
            LogUtil.d(TAG, "surfaceChanged");
            try {
              PanelProperty pp = PictureManager.getInstance().getPanelWidthHeight();
              LogUtil.d(TAG, "pp width:" + pp.width + " height:" + pp.height);
              DisplayMetrics dm = new DisplayMetrics();
              getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm);
              LogUtil.d(TAG, "dm width:" + dm.widthPixels + " height:" + dm.heightPixels);

              if (pp.width != 0 && dm.widthPixels != 0) {
                xScale = (float) pp.width / (float) (dm.widthPixels);
              }

              if (pp.height != 0 && dm.heightPixels != 0) {
                yScale = (float) (pp.height) / (float) (dm.heightPixels);
              }
              LogUtil.d(TAG, "xScale" + xScale + " yScale:" + yScale);
            } catch (TvCommonException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
            }

            int[] location = new int[2];
            surfaceContainer.getLocationOnScreen(location);
            surfaceContainerX = location[0];
            surfaceContainerY = location[1];

            surfaceContainerW = surfaceContainer.getWidth();
            surfaceContainerH = surfaceContainer.getHeight();

            if (videoInspect != null) {
              LogUtil.d(
                  TAG,
                  "surfaceContainer width:" + surfaceContainerW + " height:" + surfaceContainerH);
              videoInspect.setPipDimens(
                  (int) (surfaceContainerX * xScale),
                  (int) (surfaceContainerY * yScale),
                  (int) (surfaceContainerW * xScale),
                  (int) (surfaceContainerH * yScale));
              videoInspect.setPipscale();
            }
          }
        });

    return contentView;
  }
Example #10
0
  /**
   * Description: <br>
   * 初始化
   */
  private void init() {
    fileView = View.inflate(context, R.layout.listfile, null);
    p = new PopupWindow(fileView, LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
    p.setFocusable(true);
    pathTV = (TextView) fileView.findViewById(R.id.pathTV);
    File file = new File("/");
    currentFile = file;
    filelist = new ArrayList<File>();
    for (File ch : file.listFiles()) {
      filelist.add(ch);
    }
    Collections.sort(filelist);
    filelist.add(0, currentFile);
    list = (ListView) fileView.findViewById(R.id.list);
    ensure = (Button) fileView.findViewById(R.id.ensure_file);
    cancel = (Button) fileView.findViewById(R.id.cancel_select_file);
    if (type == IS_SAVE) {
      ensure.setText("保存");
    } else {
      ensure.setText("选择");
    }
    fa = new FileListAdapter();
    list.setAdapter(fa);
    list.setSelected(true);
    list.setOnItemClickListener(
        new OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            File f = (File) parent.getItemAtPosition(position);
            if (f.equals(selectFile)) {
              if (f.isDirectory()) {
                if (f.equals(currentFile)) {
                  f = (f.getParentFile() == null ? f : f.getParentFile());
                }
                filelist = getFileList(f);
                fa.notifyDataSetChanged();
                currentFile = f;
                pathTV.setText(currentFile.getPath());
                selectFile = null;
              }
              if (f.isFile() && type == IS_OPEN) {
                p.dismiss();
              }
            } else {
              selectFile = f;
              fa.notifyDataSetChanged();
            }
          }
        });
    list.setOnItemSelectedListener(
        new OnItemSelectedListener() {

          @Override
          public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            File f = (File) parent.getItemAtPosition(position);
            selectFile = f;
            fa.notifyDataSetChanged();
          }

          @Override
          public void onNothingSelected(AdapterView<?> parent) {
            // TODO Auto-generated method stub

          }
        });
    ensure.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View v) {
            if (selectFile != null && selectFile.isDirectory() && type == IS_OPEN) {
              if (selectFile.equals(currentFile)) {
                selectFile =
                    (selectFile.getParentFile() == null ? selectFile : selectFile.getParentFile());
              }
              filelist = getFileList(selectFile);
              fa.notifyDataSetChanged();
              currentFile = selectFile;
              pathTV.setText(currentFile.getPath());
              selectFile = null;
            } else if (selectFile != null && selectFile.isFile() && type == IS_OPEN) {
              fsListener.returnFile(selectFile);
              p.dismiss();
            } else if (type == IS_SAVE) {
              fsListener.returnFile(currentFile);
              p.dismiss();
            }
          }
        });
    cancel.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View v) {
            selectFile = null;
            p.dismiss();
          }
        });
  }
Example #11
0
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    /* 清除共享区内的信息 */
    SharedPreferences pf = getSharedPreferences("partition", 0);
    SharedPreferences.Editor editor = pf.edit();
    editor.clear();

    mMedia = new MediaProvider(this);
    mDevices = new DeviceManager(this);
    mHandler = new EventHandler(this, this, mMedia, mDevices);

    mTable = mHandler.new TableRow();
    mMenuListener = mHandler.new MenuItemListener();

    /* 设置信息预览栏内容 */
    mThumb = (LinearLayout) findViewById(R.id.thumb);
    mVideo = (SurfaceView) findViewById(R.id.thumb_movie);
    mImage = (ImageView) findViewById(R.id.thumbnail);

    Drawable bp = getResources().getDrawable(R.drawable.thumbnail_equipment);
    Bitmap m = ((BitmapDrawable) bp).getBitmap();

    mPreview = (TextView) findViewById(R.id.preview);
    mPath = (TextView) findViewById(R.id.path);
    mIndex = (TextView) findViewById(R.id.index);
    mHandler.setViewResource(mVideo, mImage, mPreview, mPath, mIndex);

    /* 把ListView 与 TableRow 绑定,并监听items的被选中事件 */
    list = getListView();
    mHandler.setListAdapter(mTable, list);
    list.setAdapter(mTable);
    list.setOnItemSelectedListener(mHandler);
    list.setOnItemClickListener(mHandler);
    list.setOnItemLongClickListener(mHandler);

    /* 设置监听导航栏的菜单item */
    Button devices = (Button) findViewById(R.id.device_button);
    Button video = (Button) findViewById(R.id.video_button);
    Button picture = (Button) findViewById(R.id.picture_button);
    Button music = (Button) findViewById(R.id.music_button);
    Button file = (Button) findViewById(R.id.file_button);
    devices.setOnClickListener(mHandler);
    video.setOnClickListener(mHandler);
    picture.setOnClickListener(mHandler);
    music.setOnClickListener(mHandler);
    file.setOnClickListener(mHandler);

    /* 读取传进来的参数决定过滤类型  */
    Bundle b = getIntent().getExtras();
    if (b != null) {
      String action = b.getString("media_type");
      if (action != null) {
        if (action.equals("MEDIA_TYPE_MUSIC")) {
          mHandler.setFilterType(mMedia.MUSIC_FILTER);
          music.performClick();
        } else if (action.equals("MEDIA_TYPE_PICTURE")) {
          mHandler.setFilterType(mMedia.PICTURE_FILTER);
          picture.performClick();
        } else if (action.equals("MEDIA_TYPE_VIDEO")) {
          mHandler.setFilterType(mMedia.MOVIE_FILTER);
          video.performClick();
        } else if (action.equals("MEDIA_TYPE_ALL")) {
          mHandler.setFilterType(mMedia.ALLTYPE_FILTER);
          file.performClick();
        } else {
          devices.performClick();
        }
      } else {
        Log.d(TAG, "started by other parames");
        devices.performClick();
      }
    } else {
      devices.performClick();
    }

    /* 设置option菜单栏信息 */
    createMenu();

    /* 增加热插拔功能 */
    mReceiver =
        new BroadcastReceiver() {
          @Override
          public void onReceive(Context context, Intent intent) {
            String tmpstring = intent.getData().getPath();
            Log.d(TAG, "devices path:" + tmpstring);
            if (intent.getAction().equals(intent.ACTION_MEDIA_REMOVED)
                || intent.getAction().equals(intent.ACTION_MEDIA_BAD_REMOVAL)) {
              /* 等待1秒钟再刷新界面,这是因为底层发出卸载信号时,有时实际上还没卸载掉设备 */
              try {
                Thread.currentThread().sleep(500);
              } catch (Exception e) {
              }
              ;
              if (mHandler.currentDir.startsWith(tmpstring) || mHandler.isDeviceList()) {
                showDeviceList();
              }
              if (mDevices.isInterStoragePath(tmpstring)) {
                // DisplayToast(getResources().getString(R.string.flash_out));
              } else if (mDevices.isSdStoragePath(tmpstring)) {
                DisplayToast(getResources().getString(R.string.sdcard_out));
              } else if (mDevices.isUsbStoragePath(tmpstring)) {
                DisplayToast(getResources().getString(R.string.usb_out));
              }

            } else if (intent.getAction().equals(intent.ACTION_MEDIA_MOUNTED)) {
              if (mHandler.isDeviceList()) {
                showDeviceList();
              }
              if (mDevices.isInterStoragePath(tmpstring)) {
                // DisplayToast(getResources().getString(R.string.flash_in));
              } else if (mDevices.isSdStoragePath(tmpstring)) {
                DisplayToast(getResources().getString(R.string.sdcard_in));
              } else if (mDevices.isUsbStoragePath(tmpstring)) {
                DisplayToast(getResources().getString(R.string.usb_in));
              }
            }
          }
        };
    IntentFilter filter = new IntentFilter();
    filter.addAction(Intent.ACTION_MEDIA_MOUNTED);
    filter.addAction(Intent.ACTION_MEDIA_REMOVED);
    filter.addAction(Intent.ACTION_MEDIA_BAD_REMOVAL);
    filter.addDataScheme("file");
    registerReceiver(mReceiver, filter);

    if (getIntent().getAction() != null) {
      if (getIntent().getAction().equals("com.softwinner.action.GET_FILE")) {
        returnFile = true;
      }
    }
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.swipe_layout_listview);
    mListView = (ListView) findViewById(R.id.listview);

    /** The following comment is the sample usage of ArraySwipeAdapter. */
    //        String[] adapterData = new String[]{"Activity", "Service", "Content Provider",
    // "Intent", "BroadcastReceiver", "ADT", "Sqlite3", "HttpClient",
    //                "DDMS", "Android Studio", "Fragment", "Loader", "Activity", "Service",
    // "Content Provider", "Intent",
    //                "BroadcastReceiver", "ADT", "Sqlite3", "HttpClient", "Activity", "Service",
    // "Content Provider", "Intent",
    //                "BroadcastReceiver", "ADT", "Sqlite3", "HttpClient"};
    //        mListView.setAdapter(new ArraySwipeAdapterSample<String>(this, R.layout.listview_item,
    // R.id.position, adapterData));

    mAdapter = new ListViewAdapter(this);
    mListView.setAdapter(mAdapter);
    mAdapter.setMode(SwipeItemMangerImpl.Mode.Single);
    mListView.setOnItemClickListener(
        new AdapterView.OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Toast.makeText(mContext, "Click", Toast.LENGTH_SHORT).show();
          }
        });
    mListView.setOnTouchListener(
        new View.OnTouchListener() {
          @Override
          public boolean onTouch(View v, MotionEvent event) {
            Log.e("ListView", "OnTouch");
            return false;
          }
        });
    mListView.setOnItemLongClickListener(
        new AdapterView.OnItemLongClickListener() {
          @Override
          public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
            Toast.makeText(mContext, "OnItemLongClickListener", Toast.LENGTH_SHORT).show();
            return false;
          }
        });
    mListView.setOnScrollListener(
        new AbsListView.OnScrollListener() {
          @Override
          public void onScrollStateChanged(AbsListView view, int scrollState) {
            Log.e("ListView", "onScrollStateChanged");
          }

          @Override
          public void onScroll(
              AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {}
        });

    mListView.setOnItemSelectedListener(
        new AdapterView.OnItemSelectedListener() {
          @Override
          public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            Log.e("ListView", "onItemSelected:" + position);
          }

          @Override
          public void onNothingSelected(AdapterView<?> parent) {
            Log.e("ListView", "onNothingSelected:");
          }
        });
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    // Get settings provider
    mSettings = SettingsProvider.getInstance(this);

    // Check language
    Log.d(MainActivity.class.getName(), "Set locale in onCreate");
    setLocale();

    // Set flag indicating we are in oncreate
    mOnResumeDirectlyAfterOnCreate = true;

    // Now go on
    super.onCreate(savedInstanceState);
    setContentView(R.layout.mainactivity);

    // Check if observer have to be started
    if (mSettings.getBackgroundObserverEnabled()) {
      // Start foreground service
      Intent startIntent = new Intent(this, ForeGroundService.class);
      startIntent.setAction(ForeGroundService.FOREGROUNDSERVICE_START);
      startService(startIntent);
    }

    // Get base linear layout
    mMainLayout = (LinearLayout) findViewById(R.id.linearLayoutMain);

    // Check if background image have to be set
    WallpaperSelectDialog selectDialog = new WallpaperSelectDialog(this);
    selectDialog.setWallpaper(false);

    // Get linear layout for semi-transparent background
    mSemiTransparentLayout =
        (LinearLayout) findViewById(R.id.linearLayoutSemiTransparentBackground);

    // Get clock and date
    mTextViewClock = (TextView) findViewById(R.id.textViewClock);
    mTextViewDate = (TextView) findViewById(R.id.textViewDate);

    // Get ListView
    mListView = (ListView) findViewById(R.id.listView);

    // Handle item click listener
    mListView.setOnItemClickListener(
        new AdapterView.OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Log.d(
                MainActivity.class.getName(), "OnItemClickListener: clicked position " + position);
            handleLeftBarItemSelection(parent, view, position, id);
          }
        });

    // Handle item selected changes
    mListView.setOnItemSelectedListener(
        new AdapterView.OnItemSelectedListener() {
          @Override
          public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            Log.d(
                MainActivity.class.getName(),
                "OnItemSelectedListener: selected position " + position);
            handleLeftBarItemSelection(parent, view, position, id);
          }

          @Override
          public void onNothingSelected(AdapterView<?> parent) {}
        });

    // Set adapter
    LeftBarItemsListAdapter actAdapter = new LeftBarItemsListAdapter(this);
    mListView.setAdapter(actAdapter);

    // Focus first item
    mListView
        .getViewTreeObserver()
        .addOnGlobalLayoutListener(
            new ViewTreeObserver.OnGlobalLayoutListener() {
              @Override
              public void onGlobalLayout() {
                try {
                  // Remove listener
                  mListView.getViewTreeObserver().removeOnGlobalLayoutListener(this);

                  // Check if first icon have to be selected
                  mListView.requestFocusFromTouch();
                  mListView.setSelection(0);
                } catch (Exception e) {
                  StringWriter errors = new StringWriter();
                  e.printStackTrace(new PrintWriter(errors));
                  String errorReason = errors.toString();
                  Log.d(
                      MainActivity.class.getName(),
                      "Failed to focus first left bar list item: \n" + errorReason);
                }
              }
            });

    // Check if left bar shall be hided
    mLeftBar = (LinearLayout) findViewById(R.id.leftbar);
  }
Example #14
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.ezydine);

    // [FTDriver] setPermissionIntent() before begin()
    mSerial = new FTDriver((UsbManager) getSystemService(Context.USB_SERVICE));

    // [FTDriver] setPermissionIntent() before begin()
    PendingIntent permissionIntent =
        PendingIntent.getBroadcast(this, 0, new Intent(ACTION_USB_PERMISSION), 0);
    mSerial.setPermissionIntent(permissionIntent);

    if (mSerial.begin(SERIAL_BAUDRATE)) {
      //   mainloop();
    }

    // リソースに準備した画像ファイルからBitmapを作成しておく
    image_amber = BitmapFactory.decodeResource(getResources(), R.drawable.amber_32);
    image_black = BitmapFactory.decodeResource(getResources(), R.drawable.black_32);
    image_green = BitmapFactory.decodeResource(getResources(), R.drawable.green_32);
    image_red = BitmapFactory.decodeResource(getResources(), R.drawable.red_32);
    image_white = BitmapFactory.decodeResource(getResources(), R.drawable.white_32);
    image_blue = BitmapFactory.decodeResource(getResources(), R.drawable.blue_32);
    image_gray = BitmapFactory.decodeResource(getResources(), R.drawable.gray_32);

    // データの作成
    List<CustomData> objects = new ArrayList<CustomData>();

    item1 = new CustomData();
    item2 = new CustomData();
    item3 = new CustomData();
    item4 = new CustomData();
    item5 = new CustomData();
    item6 = new CustomData();
    item7 = new CustomData();
    item8 = new CustomData();
    item9 = new CustomData();
    item10 = new CustomData();

    initView();
    objects.add(item1);
    objects.add(item2);
    objects.add(item3);
    objects.add(item4);
    objects.add(item5);
    objects.add(item6);
    objects.add(item7);
    objects.add(item8);
    objects.add(item9);
    objects.add(item10);

    item1.setImagaData(image_green);
    item9.setImagaData(image_blue);
    item1.setTextColor(true);
    item10.setImagaData(image_red);

    CustomAdapter customAdapater = new CustomAdapter(this, 0, objects);

    ListView listView = (ListView) findViewById(R.id.list);
    listView.setAdapter(customAdapater);

    // リスト項目がクリックされた時の処理
    listView.setOnItemClickListener(
        new AdapterView.OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            ListView listView = (ListView) parent;
            Log.d(TAG, "onItemClick: " + position);
            //                String item = (String) listView.getItemAtPosition(position);
            //                Toast.makeText(getApplicationContext(), item + " clicked",
            //                        Toast.LENGTH_LONG).show();
          }
        });

    listView.setOnItemSelectedListener(
        new AdapterView.OnItemSelectedListener() {
          // リスト項目が選択された時の処理
          @Override
          public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            ListView listView = (ListView) parent;
            Log.d(TAG, "onItemSelected: " + position);
            //                String item = (String) listView.getItemAtPosition(position);
            //                Toast.makeText(getApplicationContext(), item + " selected",
            //                        Toast.LENGTH_LONG).show();
          }

          // リスト項目がなにも選択されていない時の処理
          @Override
          public void onNothingSelected(AdapterView<?> parent) {
            Log.d(TAG, "onNothingSelected");
            //                Toast.makeText(getApplicationContext(), "no item selected",
            //                        Toast.LENGTH_LONG).show();
          }
        });

    // リスト項目が長押しされた時の処理
    listView.setOnItemLongClickListener(
        new AdapterView.OnItemLongClickListener() {
          @Override
          public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
            ListView listView = (ListView) parent;
            Log.d(TAG, "onItemLongClick: " + position);
            //                String item = (String) listView.getItemAtPosition(position);
            //                Toast.makeText(getApplicationContext(), item + " long clicked",
            //                        Toast.LENGTH_LONG).show();
            return false;
          }
        });
    mHandler =
        new Handler() {
          // メッセージ受信
          public void handleMessage(Message message) {
            // メッセージの表示
            textView = (TextView) findViewById(R.id.textView);
            textView.setText((String) message.obj);
            Log.d(TAG, "mag: " + (String) message.obj);
            // メッセージの種類に応じてswitch文で制御すれば
            // イベント制御に利用できます
          };
        };
  }