Example usage for android.widget LinearLayout findViewById

List of usage examples for android.widget LinearLayout findViewById

Introduction

In this page you can find the example usage for android.widget LinearLayout findViewById.

Prototype

@Nullable
public final <T extends View> T findViewById(@IdRes int id) 

Source Link

Document

Finds the first descendant view with the given ID, the view itself if the ID matches #getId() , or null if the ID is invalid (< 0) or there is no matching view in the hierarchy.

Usage

From source file:com.sentaroh.android.SMBSync2.ActivityMain.java

@SuppressLint("InflateParams")
private void aboutSMBSync() {
    final Dialog dialog = new Dialog(this);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setContentView(R.layout.about_dialog);

    final LinearLayout title_view = (LinearLayout) dialog.findViewById(R.id.about_dialog_title_view);
    final TextView title = (TextView) dialog.findViewById(R.id.about_dialog_title);
    title_view.setBackgroundColor(mGp.themeColorList.dialog_title_background_color);
    title.setTextColor(mGp.themeColorList.text_color_dialog_title);
    title.setText(getString(R.string.msgs_dlg_title_about) + "(Ver " + packageVersionName + ")");

    // get our tabHost from the xml
    final TabHost tab_host = (TabHost) dialog.findViewById(R.id.about_tab_host);
    tab_host.setup();//from w  w  w  . j  a  va2s.co  m

    final TabWidget tab_widget = (TabWidget) dialog.findViewById(android.R.id.tabs);

    if (Build.VERSION.SDK_INT >= 11) {
        tab_widget.setStripEnabled(false);
        tab_widget.setShowDividers(LinearLayout.SHOW_DIVIDER_NONE);
    }

    CustomTabContentView tabViewProf = new CustomTabContentView(this,
            getString(R.string.msgs_about_dlg_func_btn));
    tab_host.addTab(tab_host.newTabSpec("func").setIndicator(tabViewProf).setContent(android.R.id.tabcontent));

    CustomTabContentView tabViewHist = new CustomTabContentView(this,
            getString(R.string.msgs_about_dlg_change_btn));
    tab_host.addTab(
            tab_host.newTabSpec("change").setIndicator(tabViewHist).setContent(android.R.id.tabcontent));

    LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    LinearLayout ll_func = (LinearLayout) vi.inflate(R.layout.about_dialog_func, null);
    LinearLayout ll_change = (LinearLayout) vi.inflate(R.layout.about_dialog_change, null);

    final WebView func_view = (WebView) ll_func.findViewById(R.id.about_dialog_function);
    func_view.loadUrl("file:///android_asset/" + getString(R.string.msgs_dlg_title_about_func_desc));
    func_view.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
    func_view.getSettings().setBuiltInZoomControls(true);

    final WebView change_view = (WebView) ll_change.findViewById(R.id.about_dialog_change_history);
    change_view.loadUrl("file:///android_asset/" + getString(R.string.msgs_dlg_title_about_change_desc));
    change_view.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
    change_view.getSettings().setBuiltInZoomControls(true);

    final CustomViewPagerAdapter mAboutViewPagerAdapter = new CustomViewPagerAdapter(this,
            new WebView[] { func_view, change_view });
    final CustomViewPager mAboutViewPager = (CustomViewPager) dialog.findViewById(R.id.about_view_pager);
    //       mMainViewPager.setBackgroundColor(mThemeColorList.window_color_background);
    mAboutViewPager.setAdapter(mAboutViewPagerAdapter);
    mAboutViewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            //             util.addDebugMsg(2,"I","onPageSelected entered, pos="+position);
            tab_widget.setCurrentTab(position);
            tab_host.setCurrentTab(position);
        }

        @Override
        public void onPageScrollStateChanged(int state) {
            //             util.addDebugMsg(2,"I","onPageScrollStateChanged entered, state="+state);
        }

        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
            //             util.addDebugMsg(2,"I","onPageScrolled entered, pos="+position);
        }
    });

    tab_host.setOnTabChangedListener(new OnTabChangeListener() {
        @Override
        public void onTabChanged(String tabId) {
            util.addDebugMsg(2, "I", "onTabchanged entered. tab=" + tabId);
            mAboutViewPager.setCurrentItem(tab_host.getCurrentTab());
        }
    });

    final Button btnOk = (Button) dialog.findViewById(R.id.about_dialog_btn_ok);

    CommonDialog.setDlgBoxSizeLimit(dialog, true);

    // OK?
    btnOk.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            dialog.dismiss();
        }
    });
    // Cancel?
    dialog.setOnCancelListener(new Dialog.OnCancelListener() {
        @Override
        public void onCancel(DialogInterface arg0) {
            btnOk.performClick();
        }
    });

    dialog.show();
}

From source file:com.nttec.everychan.ui.presentation.BoardFragment.java

/**
 * ? thumbnail view  ?  ?  ?./*from ww w.  j a  v  a2s. c o m*/
 *  ??  thumbnail view   {@link #thumbnailWidth}
 */
private FloatingModel[] measureFloatingModels(LayoutInflater inflater) {
    Point displaySize = AppearanceUtils.getDisplaySize(activity.getWindowManager().getDefaultDisplay());

    LinearLayout view = (LinearLayout) inflater.inflate(R.layout.post_item_layout, (ViewGroup) rootView, false);

    TextView commentView = (TextView) view.findViewById(R.id.post_comment);
    TextPaint textPaint = commentView.getPaint();
    int textLineHeight = Math.max(1, commentView.getLineHeight());
    int rootWidth = (int) (displaySize.x * settings.getRootViewWeight());
    postItemPadding = view.getPaddingLeft() + view.getPaddingRight();
    int textWidth = postItemWidth = rootWidth - postItemPadding;

    View thumbnailView = view.findViewById(R.id.post_thumbnail);
    ViewGroup.MarginLayoutParams thumbnailLayoutParams = (ViewGroup.MarginLayoutParams) thumbnailView
            .getLayoutParams();
    thumbnailMargin = thumbnailLayoutParams.leftMargin + thumbnailLayoutParams.rightMargin;

    View attachmentTypeView = thumbnailView.findViewById(R.id.post_thumbnail_attachment_type);
    FloatingModel[] floatingModels = new FloatingModel[2];

    attachmentTypeView.setVisibility(View.GONE);
    thumbnailView.measure(displaySize.x, displaySize.y);
    Point thumbnailSize = new Point(thumbnailMargin + thumbnailView.getMeasuredWidth(),
            thumbnailView.getMeasuredHeight());
    floatingModels[0] = new FloatingModel(thumbnailSize, textWidth, textPaint);

    attachmentTypeView.setVisibility(View.VISIBLE);
    thumbnailView.measure(displaySize.x, displaySize.y);
    thumbnailSize = new Point(thumbnailMargin + thumbnailView.getMeasuredWidth(),
            thumbnailView.getMeasuredHeight());
    floatingModels[1] = new FloatingModel(thumbnailSize, textWidth, textPaint);

    thumbnailWidth = thumbnailSize.x;
    maxItemLines = divcell(thumbnailSize.y, textLineHeight);

    return floatingModels;
}

From source file:com.sentaroh.android.SMBSync2.SyncTaskUtility.java

private void listDirFilterLocal(SyncTaskItem sti, String prof_master, final ArrayList<String> dir_filter,
        final AdapterFilterList fla, final NotifyEvent p_ntfy) {
    final String cdir = sti.getMasterDirectoryName();
    String localBaseDir_t = mGp.internalRootDirectory;
    if (sti.getMasterFolderType().equals(SyncTaskItem.SYNC_FOLDER_TYPE_SDCARD))
        localBaseDir_t = mGp.sdcardRootDirectory;
    final String localBaseDir = localBaseDir_t;

    //??//from w  w w  .  jav  a2  s. c  o  m
    final Dialog dialog = new Dialog(mContext);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setCanceledOnTouchOutside(false);
    dialog.setContentView(R.layout.item_select_list_dlg);

    LinearLayout ll_dlg_view = (LinearLayout) dialog.findViewById(R.id.item_select_list_dlg_view);
    ll_dlg_view.setBackgroundColor(mGp.themeColorList.dialog_msg_background_color);

    final LinearLayout title_view = (LinearLayout) dialog.findViewById(R.id.item_select_list_dlg_title_view);
    final TextView title = (TextView) dialog.findViewById(R.id.item_select_list_dlg_title);
    final TextView subtitle = (TextView) dialog.findViewById(R.id.item_select_list_dlg_subtitle);
    title_view.setBackgroundColor(mGp.themeColorList.dialog_title_background_color);
    title.setTextColor(mGp.themeColorList.text_color_dialog_title);
    subtitle.setTextColor(mGp.themeColorList.text_color_dialog_title);

    title.setText(mContext.getString(R.string.msgs_filter_list_dlg_add_dir_filter));
    subtitle.setText(mContext.getString(R.string.msgs_current_dir) + " " + localBaseDir + "/" + cdir);
    final TextView dlg_msg = (TextView) dialog.findViewById(R.id.item_select_list_dlg_msg);
    final Button btn_ok = (Button) dialog.findViewById(R.id.item_select_list_dlg_ok_btn);

    final LinearLayout ll_context = (LinearLayout) dialog.findViewById(R.id.context_view_file_select);
    ll_context.setVisibility(LinearLayout.VISIBLE);
    final ImageButton ib_select_all = (ImageButton) ll_context.findViewById(R.id.context_button_select_all);
    final ImageButton ib_unselect_all = (ImageButton) ll_context.findViewById(R.id.context_button_unselect_all);

    dlg_msg.setVisibility(TextView.VISIBLE);

    //        if (rows.size()<=2) 
    //           ((TextView)dialog.findViewById(R.id.item_select_list_dlg_spacer))
    //           .setVisibility(TextView.VISIBLE);

    CommonDialog.setDlgBoxSizeLimit(dialog, true);

    final ListView lv = (ListView) dialog.findViewById(android.R.id.list);
    final TreeFilelistAdapter tfa = new TreeFilelistAdapter(mContext, false, false);
    lv.setAdapter(tfa);
    ArrayList<TreeFilelistItem> tfl = createLocalFilelist(true, localBaseDir, "/" + cdir);
    if (tfl.size() < 1)
        tfl.add(new TreeFilelistItem(mContext.getString(R.string.msgs_dir_empty)));
    tfa.setDataList(tfl);
    lv.setScrollingCacheEnabled(false);
    lv.setScrollbarFadingEnabled(false);

    ib_select_all.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            for (int i = 0; i < tfa.getDataItemCount(); i++) {
                TreeFilelistItem tfli = tfa.getDataItem(i);
                if (!tfli.isHideListItem())
                    tfa.setDataItemIsSelected(i);
            }
            tfa.notifyDataSetChanged();
            btn_ok.setEnabled(true);
        }
    });

    ib_unselect_all.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            for (int i = 0; i < tfa.getDataItemCount(); i++) {
                tfa.setDataItemIsUnselected(i);
            }
            tfa.notifyDataSetChanged();
            btn_ok.setEnabled(false);
        }
    });

    lv.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> items, View view, int idx, long id) {
            final int pos = tfa.getItem(idx);
            final TreeFilelistItem tfi = tfa.getDataItem(pos);
            if (tfi.getName().startsWith("---"))
                return;
            expandHideLocalDirTree(true, localBaseDir, pos, tfi, tfa);
        }
    });
    lv.setOnItemLongClickListener(new OnItemLongClickListener() {
        @Override
        public boolean onItemLongClick(AdapterView<?> arg0, View arg1, final int position, long arg3) {
            final int t_pos = tfa.getItem(position);
            final TreeFilelistItem tfi = tfa.getDataItem(t_pos);
            if (tfi.getName().startsWith("---"))
                return true;
            if (!tfa.getDataItem(t_pos).isChecked()) {
                tfa.setDataItemIsSelected(t_pos);
            }
            return true;
        }
    });

    //OK?
    btn_ok.setEnabled(false);
    NotifyEvent ntfy = new NotifyEvent(mContext);
    //Listen setRemoteShare response 
    ntfy.setListener(new NotifyEventListener() {
        @Override
        public void positiveResponse(Context arg0, Object[] arg1) {
            btn_ok.setEnabled(true);
        }

        @Override
        public void negativeResponse(Context arg0, Object[] arg1) {
            boolean checked = false;
            for (int i = 0; i < tfa.getDataItemCount(); i++) {
                if (tfa.getDataItem(i).isChecked()) {
                    checked = true;
                    break;
                }
            }
            if (checked)
                btn_ok.setEnabled(true);
            else
                btn_ok.setEnabled(false);
        }
    });
    tfa.setCbCheckListener(ntfy);

    btn_ok.setText(mContext.getString(R.string.msgs_filter_list_dlg_add));
    btn_ok.setVisibility(Button.VISIBLE);
    btn_ok.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            if (!addDirFilter(true, tfa, fla, "/" + cdir + "/", dlg_msg))
                return;
            addDirFilter(false, tfa, fla, "/" + cdir + "/", dlg_msg);
            dialog.dismiss();
            p_ntfy.notifyToListener(true, null);
        }
    });

    //CANCEL?
    final Button btn_cancel = (Button) dialog.findViewById(R.id.item_select_list_dlg_cancel_btn);
    btn_cancel.setText(mContext.getString(R.string.msgs_filter_list_dlg_close));
    btn_cancel.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            dialog.dismiss();
            p_ntfy.notifyToListener(true, null);
        }
    });
    // Cancel?
    dialog.setOnCancelListener(new Dialog.OnCancelListener() {
        @Override
        public void onCancel(DialogInterface arg0) {
            btn_cancel.performClick();
        }
    });
    //        dialog.setOnKeyListener(new DialogOnKeyListener(context));
    //        dialog.setCancelable(false);
    dialog.show();

    return;

}

From source file:com.sentaroh.android.SMBSync2.SyncTaskUtility.java

private void listDirFilterSMB(SyncTaskItem sti, String prof_master, final ArrayList<String> dir_filter,
        final AdapterFilterList fla, final NotifyEvent p_ntfy) {
    setSmbUserPass(sti.getMasterRemoteUserID(), sti.getMasterRemotePassword());
    String t_remurl = "";
    if (sti.getMasterRemoteHostname().equals(""))
        t_remurl = sti.getMasterRemoteAddr();
    else//from  w  w w  . ja va  2 s .  co m
        t_remurl = sti.getMasterRemoteHostname();
    String h_port = "";
    if (!sti.getMasterRemotePassword().equals(""))
        h_port = ":" + sti.getMasterRemotePort();
    final String remurl = "smb://" + t_remurl + h_port + "/" + sti.getMasterRemoteSmbShareName();
    final String remdir = "/" + sti.getMasterDirectoryName() + "/";

    NotifyEvent ntfy = new NotifyEvent(mContext);
    // set thread response 
    ntfy.setListener(new NotifyEventListener() {
        @Override
        public void positiveResponse(Context c, Object[] o) {
            final ArrayList<TreeFilelistItem> rows = new ArrayList<TreeFilelistItem>();
            @SuppressWarnings("unchecked")
            ArrayList<TreeFilelistItem> rfl = (ArrayList<TreeFilelistItem>) o[0];

            for (int i = 0; i < rfl.size(); i++) {
                if (rfl.get(i).isDir() && rfl.get(i).canRead())
                    rows.add(rfl.get(i));
            }
            Collections.sort(rows);
            if (rows.size() < 1)
                rows.add(new TreeFilelistItem(mContext.getString(R.string.msgs_dir_empty)));
            //??
            final Dialog dialog = new Dialog(mContext);
            dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
            dialog.setCanceledOnTouchOutside(false);
            dialog.setContentView(R.layout.item_select_list_dlg);

            LinearLayout ll_dlg_view = (LinearLayout) dialog.findViewById(R.id.item_select_list_dlg_view);
            ll_dlg_view.setBackgroundColor(mGp.themeColorList.dialog_msg_background_color);

            final LinearLayout title_view = (LinearLayout) dialog
                    .findViewById(R.id.item_select_list_dlg_title_view);
            final TextView title = (TextView) dialog.findViewById(R.id.item_select_list_dlg_title);
            final TextView subtitle = (TextView) dialog.findViewById(R.id.item_select_list_dlg_subtitle);
            title_view.setBackgroundColor(mGp.themeColorList.dialog_title_background_color);
            title.setTextColor(mGp.themeColorList.text_color_dialog_title);
            subtitle.setTextColor(mGp.themeColorList.text_color_dialog_title);

            title.setText(mContext.getString(R.string.msgs_filter_list_dlg_add_dir_filter));
            subtitle.setText(mContext.getString(R.string.msgs_current_dir) + " " + remurl + remdir);
            final TextView dlg_msg = (TextView) dialog.findViewById(R.id.item_select_list_dlg_msg);
            final LinearLayout ll_context = (LinearLayout) dialog.findViewById(R.id.context_view_file_select);
            ll_context.setVisibility(LinearLayout.VISIBLE);
            final ImageButton ib_select_all = (ImageButton) ll_context
                    .findViewById(R.id.context_button_select_all);
            final ImageButton ib_unselect_all = (ImageButton) ll_context
                    .findViewById(R.id.context_button_unselect_all);
            final Button btn_ok = (Button) dialog.findViewById(R.id.item_select_list_dlg_ok_btn);
            dlg_msg.setVisibility(TextView.VISIBLE);

            //              if (rows.size()<=2) 
            //                 ((TextView)dialog.findViewById(R.id.item_select_list_dlg_spacer))
            //                 .setVisibility(TextView.VISIBLE);

            CommonDialog.setDlgBoxSizeLimit(dialog, true);

            final ListView lv = (ListView) dialog.findViewById(android.R.id.list);
            final TreeFilelistAdapter tfa = new TreeFilelistAdapter(mContext, false, false);
            tfa.setDataList(rows);
            lv.setAdapter(tfa);
            lv.setScrollingCacheEnabled(false);
            lv.setScrollbarFadingEnabled(false);
            //             lv.setFastScrollEnabled(true);

            ib_select_all.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    for (int i = 0; i < tfa.getDataItemCount(); i++) {
                        TreeFilelistItem tfli = tfa.getDataItem(i);
                        if (!tfli.isHideListItem())
                            tfa.setDataItemIsSelected(i);
                    }
                    tfa.notifyDataSetChanged();
                    btn_ok.setEnabled(true);
                }
            });

            ib_unselect_all.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    for (int i = 0; i < tfa.getDataItemCount(); i++) {
                        tfa.setDataItemIsUnselected(i);
                    }
                    tfa.notifyDataSetChanged();
                    btn_ok.setEnabled(false);
                }
            });

            lv.setOnItemClickListener(new OnItemClickListener() {
                public void onItemClick(AdapterView<?> items, View view, int idx, long id) {
                    // ????????
                    final int pos = tfa.getItem(idx);
                    final TreeFilelistItem tfi = tfa.getDataItem(pos);
                    if (tfi.getName().startsWith("---"))
                        return;
                    expandHideRemoteDirTree(remurl, pos, tfi, tfa);
                }
            });

            lv.setOnItemLongClickListener(new OnItemLongClickListener() {
                @Override
                public boolean onItemLongClick(AdapterView<?> arg0, View arg1, final int position, long arg3) {
                    final int t_pos = tfa.getItem(position);
                    final TreeFilelistItem tfi = tfa.getDataItem(t_pos);
                    if (tfi.getName().startsWith("---"))
                        return true;
                    if (!tfa.getDataItem(t_pos).isChecked()) {
                        tfa.setDataItemIsSelected(t_pos);
                    }
                    return true;
                }
            });

            //OK?
            btn_ok.setEnabled(false);
            NotifyEvent ntfy = new NotifyEvent(mContext);
            //Listen setRemoteShare response 
            ntfy.setListener(new NotifyEventListener() {
                @Override
                public void positiveResponse(Context arg0, Object[] arg1) {
                    btn_ok.setEnabled(true);
                }

                @Override
                public void negativeResponse(Context arg0, Object[] arg1) {
                    if (tfa.isDataItemIsSelected())
                        btn_ok.setEnabled(true);
                    else
                        btn_ok.setEnabled(false);
                }
            });
            tfa.setCbCheckListener(ntfy);

            btn_ok.setText(mContext.getString(R.string.msgs_filter_list_dlg_add));
            btn_ok.setVisibility(Button.VISIBLE);
            btn_ok.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    if (!addDirFilter(true, tfa, fla, remdir, dlg_msg))
                        return;
                    addDirFilter(false, tfa, fla, remdir, dlg_msg);
                    dialog.dismiss();
                    p_ntfy.notifyToListener(true, null);
                }
            });
            //CANCEL?
            final Button btn_cancel = (Button) dialog.findViewById(R.id.item_select_list_dlg_cancel_btn);
            btn_cancel.setText(mContext.getString(R.string.msgs_filter_list_dlg_close));
            btn_cancel.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    dialog.dismiss();
                    p_ntfy.notifyToListener(true, null);
                }
            });
            // Cancel?
            dialog.setOnCancelListener(new Dialog.OnCancelListener() {
                @Override
                public void onCancel(DialogInterface arg0) {
                    btn_cancel.performClick();
                }
            });
            //            dialog.setOnKeyListener(new DialogOnKeyListener(context));
            //            dialog.setCancelable(false);
            dialog.show();
        }

        @Override
        public void negativeResponse(Context c, Object[] o) {
            p_ntfy.notifyToListener(false, o);
        }
    });
    createRemoteFileList(remurl, remdir, ntfy, true);
}

From source file:org.tvbrowser.tvbrowser.TvBrowser.java

private void sortChannels() {
    ContentResolver cr = getContentResolver();

    StringBuilder where = new StringBuilder(TvBrowserContentProvider.CHANNEL_KEY_SELECTION);
    where.append("=1");

    LinearLayout main = (LinearLayout) getLayoutInflater().inflate(R.layout.channel_sort_list,
            getParentViewGroup(), false);

    Button sortAlphabetically = (Button) main.findViewById(R.id.channel_sort_alpabetically);

    final DynamicListView channelSort = (DynamicListView) main.findViewById(R.id.channel_sort);

    String[] projection = { TvBrowserContentProvider.KEY_ID, TvBrowserContentProvider.CHANNEL_KEY_NAME,
            TvBrowserContentProvider.CHANNEL_KEY_ORDER_NUMBER, TvBrowserContentProvider.CHANNEL_KEY_SELECTION,
            TvBrowserContentProvider.CHANNEL_KEY_LOGO };

    Cursor channels = cr.query(TvBrowserContentProvider.CONTENT_URI_CHANNELS, projection, where.toString(),
            null, TvBrowserContentProvider.CHANNEL_KEY_ORDER_NUMBER);

    final ArrayList<SortInterface> channelSource = new ArrayList<SortInterface>();

    if (channels.moveToFirst()) {
        do {//from   w  w w  .  ja  va  2s .com
            int key = channels.getInt(0);
            String name = channels.getString(1);

            int order = 0;

            if (!channels.isNull(channels.getColumnIndex(TvBrowserContentProvider.CHANNEL_KEY_ORDER_NUMBER))) {
                order = channels
                        .getInt(channels.getColumnIndex(TvBrowserContentProvider.CHANNEL_KEY_ORDER_NUMBER));
            }

            Bitmap channelLogo = UiUtils.createBitmapFromByteArray(
                    channels.getBlob(channels.getColumnIndex(TvBrowserContentProvider.CHANNEL_KEY_LOGO)));

            if (channelLogo != null) {
                BitmapDrawable l = new BitmapDrawable(getResources(), channelLogo);

                ColorDrawable background = new ColorDrawable(SettingConstants.LOGO_BACKGROUND_COLOR);
                background.setBounds(0, 0, channelLogo.getWidth() + 2, channelLogo.getHeight() + 2);

                LayerDrawable logoDrawable = new LayerDrawable(new Drawable[] { background, l });
                logoDrawable.setBounds(background.getBounds());

                l.setBounds(2, 2, channelLogo.getWidth(), channelLogo.getHeight());

                channelLogo = UiUtils.drawableToBitmap(logoDrawable);
            }

            channelSource.add(new ChannelSort(key, name, order, channelLogo));
        } while (channels.moveToNext());

        channels.close();

        final Comparator<SortInterface> sortComparator = new Comparator<SortInterface>() {
            @Override
            public int compare(SortInterface lhs, SortInterface rhs) {
                if (lhs.getSortNumber() < rhs.getSortNumber()) {
                    return -1;
                } else if (lhs.getSortNumber() > rhs.getSortNumber()) {
                    return 1;
                }

                return 0;
            }
        };

        Collections.sort(channelSource, sortComparator);

        // create default logo for channels without logo
        final Bitmap defaultLogo = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);

        final StableArrayAdapter<SortInterface> aa = new StableArrayAdapter<SortInterface>(TvBrowser.this,
                R.layout.channel_sort_row, channelSource) {
            public View getView(int position, View convertView, ViewGroup parent) {
                ChannelSort value = (ChannelSort) getItem(position);
                ViewHolder holder = null;

                if (convertView == null) {
                    LayoutInflater mInflater = (LayoutInflater) getContext()
                            .getSystemService(Activity.LAYOUT_INFLATER_SERVICE);

                    holder = new ViewHolder();

                    convertView = mInflater.inflate(R.layout.channel_sort_row, getParentViewGroup(), false);

                    holder.mTextView = (TextView) convertView.findViewById(R.id.row_of_channel_sort_text);
                    holder.mSortNumber = (TextView) convertView.findViewById(R.id.row_of_channel_sort_number);
                    holder.mLogo = (ImageView) convertView.findViewById(R.id.row_of_channel_sort_icon);

                    convertView.setTag(holder);

                } else {
                    holder = (ViewHolder) convertView.getTag();
                }

                holder.mTextView.setText(value.getName());

                String sortNumber = String.valueOf(value.getSortNumber());

                if (value.getSortNumber() == 0) {
                    sortNumber = "-";
                }

                sortNumber += ".";

                holder.mSortNumber.setText(sortNumber);

                Bitmap logo = value.getLogo();

                if (logo != null) {
                    holder.mLogo.setImageBitmap(logo);
                } else {
                    holder.mLogo.setImageBitmap(defaultLogo);
                }

                return convertView;
            }
        };
        channelSort.setAdapter(aa);
        channelSort.setArrayList(channelSource);
        channelSort.setSortDropListener(new SortDropListener() {
            @Override
            public void dropped(int originalPosition, int position) {
                int startIndex = originalPosition;
                int endIndex = position;

                int droppedPos = position;

                if (originalPosition > position) {
                    startIndex = position;
                    endIndex = originalPosition;
                }

                int previousNumber = 0;

                if (startIndex > 0) {
                    previousNumber = aa.getItem(startIndex - 1).getSortNumber();
                }

                int firstVisible = channelSort.getFirstVisiblePosition();

                for (int i = startIndex; i <= endIndex; i++) {
                    if (i == droppedPos || aa.getItem(i).getSortNumber() != 0) {
                        aa.getItem(i).setSortNumber(++previousNumber);

                        if (i >= firstVisible) {
                            View line = channelSort.getChildAt(i - firstVisible);

                            if (line != null) {
                                ((TextView) line.findViewById(R.id.row_of_channel_sort_number))
                                        .setText(String.valueOf(previousNumber) + ".");
                            }
                        }
                    }
                }

            }
        });

        channelSort.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(final AdapterView<?> adapterView, final View view, final int position,
                    long id) {
                AlertDialog.Builder builder = new AlertDialog.Builder(TvBrowser.this);

                LinearLayout numberSelection = (LinearLayout) getLayoutInflater()
                        .inflate(R.layout.sort_number_selection, getParentViewGroup(), false);

                mSelectionNumberChanged = false;

                final NumberPicker number = (NumberPicker) numberSelection.findViewById(R.id.sort_picker);
                number.setMinValue(1);
                number.setMaxValue(channelSource.size());
                number.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS);
                number.setOnValueChangedListener(new NumberPicker.OnValueChangeListener() {
                    @Override
                    public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
                        mSelectionNumberChanged = true;
                    }
                });

                final EditText numberAlternative = (EditText) numberSelection
                        .findViewById(R.id.sort_entered_number);

                builder.setView(numberSelection);

                final ChannelSort selection = (ChannelSort) channelSource.get(position);

                TextView name = (TextView) numberSelection.findViewById(R.id.sort_picker_channel_name);
                name.setText(selection.getName());

                if (selection.getSortNumber() > 0) {
                    if (selection.getSortNumber() < channelSource.size() + 1) {
                        number.setValue(selection.getSortNumber());
                    } else {
                        numberAlternative.setText(String.valueOf(selection.getSortNumber()));
                    }
                }

                builder.setPositiveButton(android.R.string.ok, new OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        String test = numberAlternative.getText().toString().trim();

                        if (test.length() == 0 || mSelectionNumberChanged) {
                            selection.setSortNumber(number.getValue());
                        } else {
                            try {
                                selection.setSortNumber(Integer.parseInt(test));
                            } catch (NumberFormatException e1) {
                            }
                        }

                        Collections.sort(channelSource, sortComparator);
                        aa.notifyDataSetChanged();
                    }
                });

                builder.setNegativeButton(android.R.string.cancel, null);

                builder.show();
            }
        });

        sortAlphabetically.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Collections.sort(channelSource, new Comparator<SortInterface>() {
                    @Override
                    public int compare(SortInterface lhs, SortInterface rhs) {
                        return lhs.getName().compareToIgnoreCase(rhs.getName());
                    }
                });

                for (int i = 0; i < channelSource.size(); i++) {
                    channelSource.get(i).setSortNumber(i + 1);
                }

                aa.notifyDataSetChanged();
            }
        });

        AlertDialog.Builder builder = new AlertDialog.Builder(TvBrowser.this);

        builder.setTitle(R.string.action_sort_channels);
        builder.setView(main);

        builder.setPositiveButton(android.R.string.ok, new OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                boolean somethingChanged = false;

                for (SortInterface selection : channelSource) {
                    if (((ChannelSort) selection).wasChanged()) {
                        somethingChanged = true;

                        ContentValues values = new ContentValues();
                        values.put(TvBrowserContentProvider.CHANNEL_KEY_ORDER_NUMBER,
                                selection.getSortNumber());

                        getContentResolver().update(
                                ContentUris.withAppendedId(TvBrowserContentProvider.CONTENT_URI_CHANNELS,
                                        ((ChannelSort) selection).getKey()),
                                values, null, null);
                    }
                }

                if (somethingChanged) {
                    updateProgramListChannelBar();
                }
            }
        });
        builder.setNegativeButton(android.R.string.cancel, new OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {

            }
        });

        builder.show();
    }
}

From source file:org.tvbrowser.tvbrowser.TvBrowser.java

private void updateTvData() {
    if (!TvDataUpdateService.IS_RUNNING) {
        Cursor test = getContentResolver().query(TvBrowserContentProvider.CONTENT_URI_CHANNELS, null,
                TvBrowserContentProvider.CHANNEL_KEY_SELECTION + "=1", null, null);

        if (test.getCount() > 0) {
            AlertDialog.Builder builder = new AlertDialog.Builder(TvBrowser.this);

            RelativeLayout dataDownload = (RelativeLayout) getLayoutInflater()
                    .inflate(R.layout.dialog_data_update_selection, getParentViewGroup(), false);

            final Spinner days = (Spinner) dataDownload
                    .findViewById(R.id.dialog_data_update_selection_download_days);
            final CheckBox pictures = (CheckBox) dataDownload
                    .findViewById(R.id.dialog_data_update_selection_download_picture);

            final Spinner autoUpdate = (Spinner) dataDownload
                    .findViewById(R.id.dialog_data_update_preferences_auto_update_selection_type);
            final Spinner frequency = (Spinner) dataDownload
                    .findViewById(R.id.dialog_data_update_preferences_auto_update_selection_frequency);
            final CheckBox onlyWiFi = (CheckBox) dataDownload
                    .findViewById(R.id.dialog_data_update_preferences_auto_update_selection_type_connection);
            final TextView timeLabel = (TextView) dataDownload
                    .findViewById(R.id.dialog_data_update_preferences_auto_update_selection_time_label);
            final TextView time = (TextView) dataDownload
                    .findViewById(R.id.dialog_data_update_preferences_auto_update_selection_time);
            time.setTextColor(onlyWiFi.getTextColors());

            String currentDownloadDays = PrefUtils.getStringValue(R.string.DAYS_TO_DOWNLOAD,
                    R.string.days_to_download_default);

            final String[] possibleDownloadDays = getResources().getStringArray(R.array.download_days);

            for (int i = 0; i < possibleDownloadDays.length; i++) {
                if (currentDownloadDays.equals(possibleDownloadDays[i])) {
                    days.setSelection(i);
                    break;
                }/*from www  . ja  va2s .  c  om*/
            }

            pictures.setChecked(
                    PrefUtils.getBooleanValue(R.string.LOAD_PICTURE_DATA, R.bool.load_picture_data_default));

            String currentAutoUpdateValue = PrefUtils.getStringValue(R.string.PREF_AUTO_UPDATE_TYPE,
                    R.string.pref_auto_update_type_default);
            String currentAutoUpdateFrequency = PrefUtils.getStringValue(R.string.PREF_AUTO_UPDATE_FREQUENCY,
                    R.string.pref_auto_update_frequency_default);

            if (currentAutoUpdateValue.equals("0")) {
                frequency.setEnabled(false);
                onlyWiFi.setEnabled(false);
                timeLabel.setEnabled(false);
                time.setEnabled(false);
                frequency.setVisibility(View.GONE);
                onlyWiFi.setVisibility(View.GONE);
                timeLabel.setVisibility(View.GONE);
                time.setVisibility(View.GONE);
            } else if (currentAutoUpdateValue.equals("1")) {
                autoUpdate.setSelection(1);
                timeLabel.setEnabled(false);
                time.setEnabled(false);
                timeLabel.setVisibility(View.GONE);
                time.setVisibility(View.GONE);
            } else if (currentAutoUpdateValue.equals("2")) {
                autoUpdate.setSelection(2);
            }

            final String[] autoFrequencyPossibleValues = getResources()
                    .getStringArray(R.array.pref_auto_update_frequency_values);

            for (int i = 0; i < autoFrequencyPossibleValues.length; i++) {
                if (autoFrequencyPossibleValues[i].equals(currentAutoUpdateFrequency)) {
                    frequency.setSelection(i);
                    break;
                }
            }

            onlyWiFi.setChecked(PrefUtils.getBooleanValue(R.string.PREF_AUTO_UPDATE_ONLY_WIFI,
                    R.bool.pref_auto_update_only_wifi_default));

            final AtomicInteger currentAutoUpdateTime = new AtomicInteger(PrefUtils.getIntValue(
                    R.string.PREF_AUTO_UPDATE_START_TIME, R.integer.pref_auto_update_start_time_default));

            Calendar now = Calendar.getInstance();

            now.set(Calendar.HOUR_OF_DAY, currentAutoUpdateTime.get() / 60);
            now.set(Calendar.MINUTE, currentAutoUpdateTime.get() % 60);
            now.set(Calendar.SECOND, 0);
            now.set(Calendar.MILLISECOND, 0);

            time.setText(DateFormat.getTimeFormat(TvBrowser.this).format(now.getTime()));

            autoUpdate.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
                @Override
                public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                    frequency.setEnabled(position != 0);
                    onlyWiFi.setEnabled(position != 0);

                    if (position != 0) {
                        frequency.setVisibility(View.VISIBLE);
                        onlyWiFi.setVisibility(View.VISIBLE);
                    } else {
                        frequency.setVisibility(View.GONE);
                        onlyWiFi.setVisibility(View.GONE);
                    }

                    timeLabel.setEnabled(position == 2);
                    time.setEnabled(position == 2);

                    if (position == 2) {
                        timeLabel.setVisibility(View.VISIBLE);
                        time.setVisibility(View.VISIBLE);
                    } else {
                        timeLabel.setVisibility(View.GONE);
                        time.setVisibility(View.GONE);
                    }
                }

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

                }
            });

            View.OnClickListener onClickListener = new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    AlertDialog.Builder b2 = new AlertDialog.Builder(TvBrowser.this);

                    LinearLayout timeSelection = (LinearLayout) getLayoutInflater().inflate(
                            R.layout.dialog_data_update_selection_auto_update_time, getParentViewGroup(),
                            false);

                    final TimePicker timePick = (TimePicker) timeSelection
                            .findViewById(R.id.dialog_data_update_selection_auto_update_selection_time);
                    timePick.setIs24HourView(DateFormat.is24HourFormat(TvBrowser.this));
                    timePick.setCurrentHour(currentAutoUpdateTime.get() / 60);
                    timePick.setCurrentMinute(currentAutoUpdateTime.get() % 60);

                    b2.setView(timeSelection);

                    b2.setPositiveButton(android.R.string.ok, new OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            currentAutoUpdateTime
                                    .set(timePick.getCurrentHour() * 60 + timePick.getCurrentMinute());

                            Calendar now = Calendar.getInstance();

                            now.set(Calendar.HOUR_OF_DAY, currentAutoUpdateTime.get() / 60);
                            now.set(Calendar.MINUTE, currentAutoUpdateTime.get() % 60);
                            now.set(Calendar.SECOND, 0);
                            now.set(Calendar.MILLISECOND, 0);

                            time.setText(DateFormat.getTimeFormat(TvBrowser.this).format(now.getTime()));
                        }
                    });
                    b2.setNegativeButton(android.R.string.cancel, null);

                    b2.show();
                }
            };

            time.setOnClickListener(onClickListener);
            timeLabel.setOnClickListener(onClickListener);

            builder.setTitle(R.string.download_data);
            builder.setView(dataDownload);

            builder.setPositiveButton(android.R.string.ok, new OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    String value = possibleDownloadDays[days.getSelectedItemPosition()];

                    Editor settings = PreferenceManager.getDefaultSharedPreferences(TvBrowser.this).edit();

                    if (PrefUtils.getStringValueAsInt(R.string.PREF_AUTO_UPDATE_RANGE,
                            R.string.pref_auto_update_range_default) < Integer.parseInt(value)) {
                        settings.putString(getString(R.string.PREF_AUTO_UPDATE_RANGE), value);
                    }

                    settings.putString(getString(R.string.DAYS_TO_DOWNLOAD), value);
                    settings.putBoolean(getString(R.string.LOAD_PICTURE_DATA), pictures.isChecked());
                    settings.putString(getString(R.string.PREF_AUTO_UPDATE_TYPE),
                            String.valueOf(autoUpdate.getSelectedItemPosition()));

                    if (autoUpdate.getSelectedItemPosition() == 1
                            || autoUpdate.getSelectedItemPosition() == 2) {
                        settings.putString(getString(R.string.PREF_AUTO_UPDATE_FREQUENCY),
                                autoFrequencyPossibleValues[frequency.getSelectedItemPosition()]);
                        settings.putBoolean(getString(R.string.PREF_AUTO_UPDATE_ONLY_WIFI),
                                onlyWiFi.isChecked());

                        if (autoUpdate.getSelectedItemPosition() == 2) {
                            settings.putInt(getString(R.string.PREF_AUTO_UPDATE_START_TIME),
                                    currentAutoUpdateTime.get());
                        }
                    }

                    settings.commit();

                    IOUtils.handleDataUpdatePreferences(TvBrowser.this);

                    Intent startDownload = new Intent(TvBrowser.this, TvDataUpdateService.class);
                    startDownload.putExtra(TvDataUpdateService.TYPE, TvDataUpdateService.TV_DATA_TYPE);
                    startDownload.putExtra(getResources().getString(R.string.DAYS_TO_DOWNLOAD),
                            Integer.parseInt(value));

                    startService(startDownload);

                    updateProgressIcon(true);
                }
            });
            builder.setNegativeButton(android.R.string.cancel, null);
            builder.show();
        } else {
            Cursor test2 = getContentResolver().query(TvBrowserContentProvider.CONTENT_URI_CHANNELS, null, null,
                    null, null);

            boolean loadAgain = test2.getCount() < 1;

            test2.close();

            selectChannels(loadAgain);
        }

        test.close();
    }
}

From source file:br.org.funcate.dynamicforms.FragmentDetail.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.details, container, false);
    LinearLayout mainView = (LinearLayout) view.findViewById(R.id.form_linear);
    FragmentDetailActivity fragmentDetailActivity;
    try {/*from ww  w  . j  a  va  2s  . c om*/
        FragmentActivity activity = getActivity();
        if (selectedFormName == null || sectionObject == null) {
            FragmentList fragmentList = (FragmentList) getFragmentManager().findFragmentById(R.id.listFragment);
            if (fragmentList != null) {
                selectedFormName = fragmentList.getSelectedItemName();
                sectionObject = fragmentList.getSectionObject();
                noteId = fragmentList.getNoteId();
            } else {
                if (activity instanceof FragmentDetailActivity) {
                    // case of portrait mode
                    fragmentDetailActivity = (FragmentDetailActivity) activity;
                    selectedFormName = fragmentDetailActivity.getFormName();
                    sectionObject = fragmentDetailActivity.getSectionObject();
                    noteId = fragmentDetailActivity.getNoteId();
                    workingDirectory = fragmentDetailActivity.getWorkingDirectory();
                    existingFeatureData = fragmentDetailActivity.getFeatureData();
                }
            }
        }
        if (selectedFormName != null) {
            JSONObject formObject = TagsManager.getForm4Name(selectedFormName, sectionObject);

            key2WidgetMap.clear();
            requestCodes2WidgetMap.clear();
            int requestCode = 666;
            keyList.clear();
            key2ConstraintsMap.clear();

            if (formObject != null) {// Test to get form configuration to this layer

                JSONArray formItemsArray = TagsManager.getFormItems(formObject);

                int length = ((formItemsArray != null) ? (formItemsArray.length()) : (0));
                for (int i = 0; i < length; i++) {
                    JSONObject jsonObject = formItemsArray.getJSONObject(i);

                    String key = "-"; //$NON-NLS-1$
                    if (jsonObject.has(TAG_KEY))
                        key = jsonObject.getString(TAG_KEY).trim();

                    String label = key;
                    if (jsonObject.has(TAG_LABEL))
                        label = jsonObject.getString(TAG_LABEL).trim();

                    String type = FormUtilities.TYPE_STRING;
                    if (jsonObject.has(TAG_TYPE)) {
                        type = jsonObject.getString(TAG_TYPE).trim();
                    }

                    boolean readonly = false;
                    if (jsonObject.has(TAG_READONLY)) {
                        String readonlyStr = jsonObject.getString(TAG_READONLY).trim();
                        readonly = Boolean.parseBoolean(readonlyStr);
                    }
                    // if attribute has a non printable char, force readonly mode.
                    if (Utilities.existUnprintableCharacters(key)) {
                        readonly = true;
                    }

                    Constraints constraints = new Constraints();
                    FormUtilities.handleConstraints(jsonObject, constraints);
                    key2ConstraintsMap.put(key, constraints);
                    String constraintDescription = constraints.getDescription();

                    Object o;
                    GView addedView = null;
                    if (type.equals(TYPE_STRING)) {
                        o = getValueFromExtras(jsonObject, key);
                        String value = ((String) o).trim();
                        addedView = FormUtilities.addEditText(activity, mainView, label, value, 0, 0,
                                constraintDescription, readonly);
                    } else if (type.equals(TYPE_STRINGAREA)) {
                        o = getValueFromExtras(jsonObject, key);
                        String value = ((String) o).trim();
                        addedView = FormUtilities.addEditText(activity, mainView, label, value, 0, 7,
                                constraintDescription, readonly);
                    } else if (type.equals(TYPE_DOUBLE)) {
                        o = getValueFromExtras(jsonObject, key);
                        String value = ((String) o).trim();
                        addedView = FormUtilities.addEditText(activity, mainView, label, value, 1, 0,
                                constraintDescription, readonly);
                    } else if (type.equals(TYPE_INTEGER)) {
                        o = getValueFromExtras(jsonObject, key);
                        String value = ((String) o).trim();
                        addedView = FormUtilities.addEditText(activity, mainView, label, value, 4, 0,
                                constraintDescription, readonly);
                    } else if (type.equals(TYPE_DATE)) {
                        o = getValueFromExtras(jsonObject, key);
                        String value = ((String) o).trim();
                        addedView = FormUtilities.addDateView(FragmentDetail.this, mainView, label, value,
                                constraintDescription, readonly);
                    } else if (type.equals(TYPE_TIME)) {
                        o = getValueFromExtras(jsonObject, key);
                        String value = ((String) o).trim();
                        addedView = FormUtilities.addTimeView(FragmentDetail.this, mainView, label, value,
                                constraintDescription, readonly);
                    } else if (type.equals(TYPE_LABEL)) {
                        String size = "20"; //$NON-NLS-1$
                        if (jsonObject.has(TAG_SIZE))
                            size = jsonObject.getString(TAG_SIZE);
                        String url = null;
                        if (jsonObject.has(TAG_URL))
                            url = jsonObject.getString(TAG_URL);

                        o = getValueFromExtras(jsonObject, key);
                        String value = ((String) o).trim();
                        addedView = FormUtilities.addTextView(activity, mainView, value, size, false, url);
                    } else if (type.equals(TYPE_LABELWITHLINE)) {
                        String size = "20"; //$NON-NLS-1$
                        if (jsonObject.has(TAG_SIZE))
                            size = jsonObject.getString(TAG_SIZE);
                        String url = null;
                        if (jsonObject.has(TAG_URL))
                            url = jsonObject.getString(TAG_URL);

                        o = getValueFromExtras(jsonObject, key);
                        String value = ((String) o).trim();
                        addedView = FormUtilities.addTextView(activity, mainView, value, size, true, url);
                    } else if (type.equals(TYPE_BOOLEAN)) {
                        o = getValueFromExtras(jsonObject, key);
                        String value = ((String) o).trim();
                        addedView = FormUtilities.addBooleanView(activity, mainView, label, value,
                                constraintDescription, readonly);
                    } else if (type.equals(TYPE_STRINGCOMBO)) {
                        JSONArray comboItems = TagsManager.getComboItems(jsonObject);
                        String[] itemsArray = TagsManager.comboItems2StringArray(comboItems);
                        o = getValueFromExtras(jsonObject, key);
                        String value = ((String) o).trim();
                        addedView = FormUtilities.addComboView(activity, mainView, label, value, itemsArray,
                                constraintDescription);
                    } else if (type.equals(TYPE_CONNECTEDSTRINGCOMBO)) {
                        LinkedHashMap<String, List<String>> valuesMap = TagsManager
                                .extractComboValuesMap(jsonObject);
                        o = getValueFromExtras(jsonObject, key);
                        String value = ((String) o).trim();
                        addedView = FormUtilities.addConnectedComboView(activity, mainView, label, value,
                                valuesMap, constraintDescription);
                    } else if (type.equals(TYPE_STRINGMULTIPLECHOICE)) {
                        JSONArray comboItems = TagsManager.getComboItems(jsonObject);
                        String[] itemsArray = TagsManager.comboItems2StringArray(comboItems);
                        o = getValueFromExtras(jsonObject, key);
                        String value = ((String) o).trim();
                        addedView = FormUtilities.addMultiSelectionView(activity, mainView, label, value,
                                itemsArray, constraintDescription);
                    } else if (type.equals(TYPE_PICTURES)) {

                        o = getValueFromExtras(jsonObject, FormUtilities.IMAGE_MAP);
                        Map<String, Map<String, String>> value = null;
                        String clazz = o.getClass().getSimpleName();
                        if (("bundle").equalsIgnoreCase(clazz)) {
                            Bundle imageMapBundle = (Bundle) o;

                            Bundle imageMapThumbnailBundle = imageMapBundle.getBundle("thumbnail");
                            Bundle imageMapDisplayBundle = imageMapBundle.getBundle("display");

                            if (imageMapThumbnailBundle != null && imageMapDisplayBundle != null) {
                                Set<String> keys = imageMapThumbnailBundle.keySet();
                                Iterator<String> itKeys = keys.iterator();

                                if (keys.size() > 0) {
                                    value = new HashMap<String, Map<String, String>>(keys.size());

                                    while (itKeys.hasNext()) {
                                        String keyMap = itKeys.next();
                                        Map<String, String> imagePaths = new HashMap<String, String>(2);
                                        imagePaths.put("thumbnail",
                                                (String) imageMapThumbnailBundle.get(keyMap));
                                        imagePaths.put("display", (String) imageMapDisplayBundle.get(keyMap));

                                        value.put(keyMap, imagePaths);
                                    }
                                }
                            }
                        }
                        addedView = FormUtilities.addPictureView(this, requestCode, mainView, label, value,
                                constraintDescription);
                    }
                    /*else if (type.equals(TYPE_SKETCH)) {
                    addedView = FormUtilities.addSketchView(noteId, this, requestCode, mainView, label, value, constraintDescription);
                    } */
                    else {
                        Toast.makeText(getActivity().getApplicationContext(),
                                "Type non implemented yet: " + type, Toast.LENGTH_LONG).show();
                    }
                    /*                    } else if (type.equals(TYPE_MAP)) {
                    if (value.length() <= 0) {
                        // need to read image
                        File tempDir = ResourcesManager.getInstance(activity).getTempDir();
                        File tmpImage = new File(tempDir, LibraryConstants.TMPPNGIMAGENAME);
                        if (tmpImage.exists()) {
                            byte[][] imageAndThumbnailFromPath = ImageUtilities.getImageAndThumbnailFromPath(tmpImage.getAbsolutePath(), 1);
                            Date date = new Date();
                            String mapImageName = ImageUtilities.getMapImageName(date);
                            
                            IImagesDbHelper imageHelper = DefaultHelperClasses.getDefaulfImageHelper();
                            long imageId = imageHelper.addImage(longitude, latitude, -1.0, -1.0, date.getTime(), mapImageName, imageAndThumbnailFromPath[0], imageAndThumbnailFromPath[1], noteId);
                            value = "" + imageId;
                        }
                    }
                    addedView = FormUtilities.addMapView(activity, mainView, label, value, constraintDescription);
                                        } else if (type.equals(TYPE_NFCUID)) {
                    addedView = new GNfcUidView(this, null, requestCode, mainView, label, value, constraintDescription);
                                        } else {
                    GPLog.addLogEntry(this, null, null, "Type non implemented yet: " + type);
                                        }*/
                    key2WidgetMap.put(key, addedView);
                    keyList.add(key);
                    requestCodes2WidgetMap.put(requestCode, addedView);
                    requestCode++;
                } // end of the form items loop
            } else {
                String size = "20"; //$NON-NLS-1$
                String url = null;
                String value = getResources().getString(R.string.error_while_loading_form_configuration);
                GView addedView = FormUtilities.addTextView(activity, mainView, value, size, true, url);
                String key = "-"; //$NON-NLS-1$
                key2WidgetMap.put(key, addedView);
                keyList.add(key);
                requestCodes2WidgetMap.put(requestCode, addedView);
            }

            LinearLayout btnLinear = (LinearLayout) mainView.findViewById(R.id.btn_linear);
            if (keyList.size() == 1) {
                Button btnSave = (Button) btnLinear.findViewById(R.id.saveButton);
                btnSave.setEnabled(false);
            }
            mainView.removeView(btnLinear);
            mainView.addView(btnLinear);
        }
    } catch (ParseException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
        Toast.makeText(getActivity().getApplicationContext(), e.getMessage(), Toast.LENGTH_LONG).show();
    }

    return view;
}