Example usage for android.widget LinearLayout setBackgroundColor

List of usage examples for android.widget LinearLayout setBackgroundColor

Introduction

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

Prototype

@RemotableViewMethod
public void setBackgroundColor(@ColorInt int color) 

Source Link

Document

Sets the background color for this view.

Usage

From source file:de.baumann.thema.RequestActivity.java

@SuppressWarnings("unchecked")
private void populateView(ArrayList arrayListFinal) {
    ArrayList<AppInfo> local_arrayList;
    local_arrayList = arrayListFinal;// www  .  j ava 2s.co  m

    GridView grid = (GridView) findViewById(R.id.appgrid);

    assert grid != null;
    grid.setVerticalSpacing(GridView.AUTO_FIT);
    grid.setHorizontalSpacing(GridView.AUTO_FIT);
    grid.setStretchMode(GridView.STRETCH_COLUMN_WIDTH);
    grid.setFastScrollEnabled(true);
    grid.setFastScrollAlwaysVisible(true);

    if (DEBUG)
        Log.v(TAG, "height: " + getDisplaySize("height") + "; width: " + getDisplaySize("width"));

    AppAdapter appInfoAdapter;
    if (isPortrait()) {
        grid.setNumColumns(numCol_Portrait);

        if (isTablet(context)) {
            grid.setNumColumns(numCol_Portrait); //Here you can change the number of columns for Tablets
            if (DEBUG)
                Log.v(TAG, "isTablet");
        }
        if (isXLargeTablet(context)) {
            grid.setNumColumns(numCol_Portrait); //Here you can change the number of columns for Large Tablets
            if (DEBUG)
                Log.v(TAG, "isXLargeTablet");
        }

        appInfoAdapter = new AppAdapter(this, R.layout.request_item_list, local_arrayList);
    }

    else {
        grid.setNumColumns(numCol_Landscape);

        if (isTablet(context)) {
            grid.setNumColumns(numCol_Landscape); //Here you can change the number of columns for Tablets
            if (DEBUG)
                Log.v(TAG, "isTablet");
        }
        if (isXLargeTablet(context)) {
            grid.setNumColumns(numCol_Landscape); //Here you can change the number of columns for Large Tablets
            if (DEBUG)
                Log.v(TAG, "isXLargeTablet");
        }

        appInfoAdapter = new AppAdapter(this, R.layout.request_item_grid, local_arrayList);
    }

    grid.setAdapter(appInfoAdapter);
    grid.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        public void onItemClick(AdapterView<?> AdapterView, View view, int position, long row) {
            AppInfo appInfo = (AppInfo) AdapterView.getItemAtPosition(position);
            CheckBox checker = (CheckBox) view.findViewById(R.id.CBappSelect);
            ViewSwitcher icon = (ViewSwitcher) view.findViewById(R.id.viewSwitcherChecked);
            LinearLayout localBackground = (LinearLayout) view.findViewById(R.id.card_bg);
            Animation aniIn = AnimationUtils.loadAnimation(context, R.anim.request_flip_in_half_1);
            Animation aniOut = AnimationUtils.loadAnimation(context, R.anim.request_flip_in_half_2);

            checker.toggle();
            appInfo.setSelected(checker.isChecked());

            icon.setInAnimation(aniIn);
            icon.setOutAnimation(aniOut);

            if (appInfo.isSelected()) {
                if (DEBUG)
                    Log.v(TAG, "Selected App: " + appInfo.getName());
                localBackground
                        .setBackgroundColor(ContextCompat.getColor(context, R.color.request_card_pressed));
                if (icon.getDisplayedChild() == 0) {
                    icon.showNext();
                }
            } else {
                if (DEBUG)
                    Log.v(TAG, "Deselected App: " + appInfo.getName());
                localBackground
                        .setBackgroundColor(ContextCompat.getColor(context, R.color.request_card_unpressed));
                if (icon.getDisplayedChild() == 1) {
                    icon.showPrevious();
                }
            }
        }
    });
}

From source file:org.alfresco.mobile.android.application.fragments.signin.AccountServerFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    final LinearLayout backField = (LinearLayout) viewById(R.id.account_action_server_container);
    final Button actionContinue = (Button) viewById(R.id.account_action_server);
    actionContinue.setOnClickListener(new View.OnClickListener() {
        @Override/*from   www.  jav a 2  s .  c o m*/
        public void onClick(View v) {

            String value = createHostnameURL(hostname.getText().toString(), https.isChecked());
            if (value == null) {
                hostname.setError("Your hostname seems invalid");
            } else {
                Operator.with(getActivity())
                        .load(new CheckServerRequest.Builder(https.isChecked(), hostname.getText().toString()));
            }
        }
    });

    https = (CheckBox) viewById(R.id.signing_https);
    https.setVisibility(View.INVISIBLE);

    hostname = (MaterialEditText) viewById(R.id.signing_hostname);
    hostname.requestFocus();
    UIUtils.showKeyboard(getActivity(), hostname);

    if (hostname.getText().length() == 0) {
        actionContinue.setEnabled(false);
        backField.setBackgroundColor(getResources().getColor(R.color.accent_disable));
    }

    hostname.addTextChangedListener(new TextWatcher() {
        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void afterTextChanged(Editable s) {
            if (s.length() == 0) {
                actionContinue.setEnabled(false);
                backField.setBackgroundColor(getResources().getColor(R.color.accent_disable));
            } else {
                actionContinue.setEnabled(true);
                backField.setBackgroundColor(getResources().getColor(R.color.accent));
            }

            hideHTTPS = true;
            switch (s.length()) {
            case 0:
                hideHTTPS = true;
                break;
            case 1:
                hideHTTPS = s.toString().equals("h");
                break;
            case 2:
                hideHTTPS = s.toString().equals("ht");
                break;
            case 3:
                hideHTTPS = s.toString().equals("htt");
                break;
            case 4:
                hideHTTPS = s.toString().equals("http");
                break;
            case 5:
                hideHTTPS = s.toString().equals("http:") || s.toString().equals("https");
                break;
            case 6:
                hideHTTPS = s.toString().equals("http:/") || s.toString().equals("https:");
                break;
            case 7:
                hideHTTPS = s.toString().equals("http://") || s.toString().equals("https:/");
                break;
            case 8:
                hideHTTPS = s.toString().startsWith("http://") || s.toString().equals("https://");
                break;
            default:
                hideHTTPS = s.toString().startsWith("http://") || s.toString().startsWith("https://");
            }

            int shortAnimTime = getResources().getInteger(android.R.integer.config_shortAnimTime);
            if (https.getVisibility() == View.VISIBLE && hideHTTPS
                    || https.getVisibility() == View.INVISIBLE && !hideHTTPS) {
                https.setVisibility(hideHTTPS ? View.INVISIBLE : View.VISIBLE);
                https.animate().setDuration(shortAnimTime).alpha(hideHTTPS ? 0 : 1)
                        .setListener(new AnimatorListenerAdapter() {
                            @Override
                            public void onAnimationEnd(Animator animation) {
                                https.setVisibility(hideHTTPS ? View.INVISIBLE : View.VISIBLE);
                            }
                        });
            } else {
                https.setVisibility(hideHTTPS ? View.INVISIBLE : View.VISIBLE);
            }
        }
    });
}

From source file:com.ibuildapp.romanblack.FanWallPlugin.FanWallPlugin.java

private void initializeUI() {
    setContentView(R.layout.romanblack_fanwall_main);

    mainlLayout = (LinearLayout) findViewById(R.id.romanblack_fanwall_main);
    mainlLayout.setBackgroundColor(Statics.color1);

    // less then android L
    if (android.os.Build.VERSION.SDK_INT <= 20) {
        InputMethodManager im = (InputMethodManager) getSystemService(Service.INPUT_METHOD_SERVICE);
        SoftKeyboard softKeyboard;// w w w  . j  av a  2  s.c  om
        softKeyboard = new SoftKeyboard(mainlLayout, im);
        softKeyboard.setSoftKeyboardCallback(new SoftKeyboard.SoftKeyboardChanged() {

            @Override
            public void onSoftKeyboardHide() {
                Message msg = handler.obtainMessage(HANDLE_TAP_BAR, 1, 0);
                handler.sendMessage(msg);
            }

            @Override
            public void onSoftKeyboardShow() {
                Message msg = handler.obtainMessage(HANDLE_TAP_BAR, 0, 0);
                handler.sendMessage(msg);
            }
        });
    }

    bottomBarHodler = (LinearLayout) findViewById(R.id.romanblack_fanwall_main_bottom_bar);

    TextView noMsgText = (TextView) findViewById(R.id.romanblack_fanwall_nomessages_text);

    // top bar
    setTopBarLeftButtonText(getResources().getString(R.string.common_home_upper), true,
            new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    finish();
                }
            });

    // set title
    if (TextUtils.isEmpty(widget.getTitle()))
        setTopBarTitle(getString(R.string.fanwall_talks));
    else
        setTopBarTitle(widget.getTitle());

    imageHolder = (LinearLayout) findViewById(R.id.fanwall_image_holder);
    userImage = (ImageView) findViewById(R.id.fanwall_user_image);
    closeBtn = (ImageView) findViewById(R.id.fanwall_close_image);
    closeBtn.setOnClickListener(this);

    chooserHolder = (LinearLayout) findViewById(R.id.fanwall_chooser_holder);
    openBottom = (LinearLayout) findViewById(R.id.romanblack_fanwall_open_bottom);
    openBottom.setOnClickListener(this);

    enableGpsCheckbox = (CheckBox) findViewById(R.id.romanblack_fanwall_enable_gps_checkbox);
    enableGpsCheckbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
            if (b) {
                if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
                    final AlertDialog.Builder builder = new AlertDialog.Builder(FanWallPlugin.this);
                    builder.setMessage(getString(R.string.enable_gps_msg)).setCancelable(false)
                            .setPositiveButton(getString(R.string.yes), new DialogInterface.OnClickListener() {
                                public void onClick(@SuppressWarnings("unused") final DialogInterface dialog,
                                        @SuppressWarnings("unused") final int id) {
                                    startActivityForResult(
                                            new Intent(
                                                    android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS),
                                            GPS_SETTINGS_ACTIVITY);
                                }
                            }).setNegativeButton(getString(R.string.no), new DialogInterface.OnClickListener() {
                                public void onClick(final DialogInterface dialog,
                                        @SuppressWarnings("unused") final int id) {
                                    enableGpsCheckbox.setChecked(false);
                                    dialog.dismiss();
                                }
                            });
                    final AlertDialog alert = builder.create();
                    alert.show();
                } else {
                    Prefs.with(FanWallPlugin.this).save(Prefs.KEY_GPS, true);
                }
            } else
                Prefs.with(FanWallPlugin.this).save(Prefs.KEY_GPS, false);

        }
    });
    enableGpsCheckbox.setChecked(Prefs.with(FanWallPlugin.this).getBoolean(Prefs.KEY_GPS, false));

    galleryChooser = (LinearLayout) findViewById(R.id.romanblack_fanwall_gallery);
    galleryChooser.setOnClickListener(this);
    photoChooser = (LinearLayout) findViewById(R.id.romanblack_fanwall_make_photo);
    photoChooser.setOnClickListener(this);

    postMsg = (LinearLayout) findViewById(R.id.romanblack_fanwall_send_post);
    postMsg.setOnClickListener(this);
    editMsg = (EditText) findViewById(R.id.romanblack_fanwall_edit_msg);
    editMsg.addTextChangedListener(FanWallPlugin.this);

    tabHolder = (LinearLayout) findViewById(R.id.romanblack_fanwall_tab_holder);
    tabHolder.setBackgroundColor(res.getColor(R.color.black_50_trans));
    LinearLayout separator = (LinearLayout) findViewById(R.id.romanblack_fanwall_tab_holder_separator);
    separator.setBackgroundColor(res.getColor(R.color.white_30_trans));
    LinearLayout separatorUp = (LinearLayout) findViewById(R.id.romanblack_fanwall_tab_holder_up);
    LinearLayout separatorDown = (LinearLayout) findViewById(R.id.romanblack_fanwall_tab_holder_down);

    tabMapLayout = (LinearLayout) findViewById(R.id.romanblack_fanwall_tab_map_layout);
    tabMapLayout.setOnClickListener(this);

    tabPhotosLayout = (LinearLayout) findViewById(R.id.romanblack_fanwall_tab_photos_layout);
    tabPhotosLayout.setOnClickListener(this);

    if (Statics.isSchemaDark) {
        separatorUp.setBackgroundColor(res.getColor(R.color.white_20_trans));
        separatorDown.setBackgroundColor(res.getColor(R.color.white_20_trans));
        int temp = Color.WHITE & 0x00ffffff;
        int result = temp | 0x80000000;
        noMsgText.setTextColor(result);
    } else {
        separatorUp.setBackgroundColor(res.getColor(R.color.black_20_trans));
        separatorDown.setBackgroundColor(res.getColor(R.color.black_20_trans));
        int temp = Color.BLACK & 0x00ffffff;
        int result = temp | 0x80000000;
        noMsgText.setTextColor(result);
    }

    noMessagesLayout = (LinearLayout) findViewById(R.id.romanblack_fanwall_main_nomessages_layout);

    messageListLayoutRoot = (FrameLayout) findViewById(R.id.romanblack_fanwall_messagelist_list_layout);
    messageList = (PullToRefreshListView) findViewById(R.id.romanblack_fanwall_messagelist_pulltorefresh);
    messageList.setDivider(null);
    messageList.setBackgroundColor(Color.TRANSPARENT);
    messageList.setDrawingCacheBackgroundColor(Color.TRANSPARENT);

    ILoadingLayout loadingLayout = messageList.getLoadingLayoutProxy();
    if (Statics.isSchemaDark) {
        loadingLayout.setHeaderColor(Color.WHITE);
    } else {
        loadingLayout.setHeaderColor(Color.BLACK);
    }

    //messageList.set
    adapter = new MainLayoutMessagesAdapter(FanWallPlugin.this, messageList, messages, widget);
    adapter.setInnerInterface(new MainLayoutMessagesAdapter.onEndReached() {
        @Override
        public void endReached() {
            if (!refreshingBottom)
                refreshBottom();
        }
    });

    messageList.setAdapter(adapter);
    messageList.setOnRefreshListener(new PullToRefreshBase.OnRefreshListener<ListView>() {
        @Override
        public void onRefresh(PullToRefreshBase<ListView> refreshView) {
            refreshTop();
        }
    });

    if (Statics.canEdit.compareToIgnoreCase("all") == 0) {
        bottomBarHodler.setVisibility(View.VISIBLE);
    } else {
        bottomBarHodler.setVisibility(View.GONE);
    }

    // start downloading messages
    // exactly in create() method!!!
    handler.sendEmptyMessage(SHOW_PROGRESS_DIALOG);
    refreshMessages();
}

From source file:com.ezeeideas.wordjam.BaseGameActivity.java

private void honorTheme() {
    //honor theme for common elements
    LinearLayout mainLayout = (LinearLayout) findViewById(R.id.game_main_layout);
    mainLayout.setBackgroundColor(Themes.getColorFor(Themes.COLOR_BACKGROUND));

    View ruleHeader = (View) findViewById(R.id.rule_header);
    ruleHeader.setBackgroundColor(Themes.getColorFor(Themes.COLOR_LINE_HEADING));

    View ruleFooter = (View) findViewById(R.id.rule_footer);
    ruleFooter.setBackgroundColor(Themes.getColorFor(Themes.COLOR_LINE_HEADING));

    View ruleFooter2 = (View) findViewById(R.id.rule_footer2);
    if (ruleFooter2 != null) {
        ruleFooter2.setBackgroundColor(Themes.getColorFor(Themes.COLOR_LINE_HEADING));
    }/*from  ww  w .j  a  v a2s  . com*/

    //honor theme for game specfic elements
    doHonorTheme();
}

From source file:com.sentaroh.android.Utilities.Dialog.SafFileSelectDialogFragment.java

private void initViewWidget() {
    if (mDebugEnable)
        Log.v(APPLICATION_TAG, "initViewWidget");

    if (mDebugEnable)
        Log.v(APPLICATION_TAG, "Create=" + mDialogEnableCreate + ", Title=" + mDialogTitle + ", lurl="
                + mDialogLocalUuid + ", ldir=" + mDialogLocalDir + ", file name=" + mDialogFileName);

    mThemeColorList = ThemeUtil.getThemeColorList(getActivity());

    mDialog.setContentView(R.layout.file_select_edit_dlg);
    LinearLayout title_view = (LinearLayout) mDialog.findViewById(R.id.file_select_edit_dlg_title_view);
    title_view.setBackgroundColor(mThemeColorList.dialog_title_background_color);
    TextView title = (TextView) mDialog.findViewById(R.id.file_select_edit_dlg_title);
    title.setTextColor(mThemeColorList.text_color_dialog_title);
    title.setText(mDialogTitle);//from w  w  w  .  j  a  va  2s.c o m
    final TextView dlg_msg = (TextView) mDialog.findViewById(R.id.file_select_edit_dlg_msg);
    final Button btnHome = (Button) mDialog.findViewById(R.id.file_select_edit_dlg_home_dir_btn);
    btnHome.setTextColor(mThemeColorList.text_color_primary);
    btnHome.setVisibility(Button.VISIBLE);

    final Button btnCreate = (Button) mDialog.findViewById(R.id.file_select_edit_dlg_create_btn);
    btnCreate.setTextColor(mThemeColorList.text_color_primary);
    final Button btnOk = (Button) mDialog.findViewById(R.id.file_select_edit_dlg_ok_btn);
    //      btnOk.setTextColor(mThemeColorList.text_color_primary);
    final Button btnCancel = (Button) mDialog.findViewById(R.id.file_select_edit_dlg_cancel_btn);
    btnCancel.setTextColor(mThemeColorList.text_color_primary);
    final Button btnRefresh = (Button) mDialog.findViewById(R.id.file_select_edit_dlg_refresh_btn);
    btnRefresh.setTextColor(mThemeColorList.text_color_primary);

    LinearLayout ll_dlg_view = (LinearLayout) mDialog.findViewById(R.id.file_select_edit_dlg_view);
    //      LinearLayout ll_dlg_view_filename=(LinearLayout) mDialog.findViewById(R.id.file_select_edit_dlg_view_filename);
    //      LinearLayout ll_dlg_view_create=(LinearLayout) mDialog.findViewById(R.id.file_select_edit_dlg_view_create);
    //      LinearLayout ll_dlg_view_btn=(LinearLayout) mDialog.findViewById(R.id.file_select_edit_dlg_view_btn);
    ll_dlg_view.setBackgroundColor(mThemeColorList.dialog_msg_background_color);
    //      ll_dlg_view_filename.setBackgroundColor(mThemeColorList.dialog_msg_background_color);
    //      ll_dlg_view_create.setBackgroundColor(mThemeColorList.dialog_msg_background_color);
    //      ll_dlg_view_btn.setBackgroundColor(mThemeColorList.dialog_msg_background_color);

    final Activity activity = getActivity();
    final Context context = activity.getApplicationContext();

    if (mDialogEnableCreate) {
        btnCreate.setVisibility(TextView.VISIBLE);
    }

    LinearLayout ll_mp = (LinearLayout) mDialog.findViewById(R.id.file_select_edit_dlg_mp_view);
    ll_mp.setVisibility(LinearLayout.GONE);

    mTreeFileListView = (ListView) mDialog.findViewById(android.R.id.list);
    final EditText filename = (EditText) mDialog.findViewById(R.id.file_select_edit_dlg_file_name);
    final CustomTextView dir_name = (CustomTextView) mDialog.findViewById(R.id.file_select_edit_dlg_dir_name);
    filename.setOnKeyListener(new OnKeyListener() {
        @Override
        public boolean onKey(View arg0, int keyCode, KeyEvent event) {
            if (//event.getAction() == KeyEvent.ACTION_DOWN &&
            keyCode == KeyEvent.KEYCODE_ENTER) {
                return true;
            }
            return false;
        }
    });
    if (!mDialogSingleSelect) {
        filename.setVisibility(EditText.GONE);
    }
    //    if (dirs.size()<=2)   v_spacer.setVisibility(TextView.VISIBLE);

    mTreeFilelistAdapter = new TreeFilelistAdapter(activity, mDialogSingleSelect, true);
    mTreeFileListView.setAdapter(mTreeFilelistAdapter);
    //       if (mDialogFileOnly) {
    //          mTreeFilelistAdapter.setDirectorySelectable(false);
    //          mTreeFilelistAdapter.setFileSelectable(true);
    //       }
    //       if (mDialogDirOnly) {
    //          mTreeFilelistAdapter.setDirectorySelectable(true);
    //          mTreeFilelistAdapter.setFileSelectable(false);
    //       }

    ArrayList<TreeFilelistItem> tfl = createLocalFilelist(mDialogFileOnly, mDialogLocalUuid, "");
    if (tfl.size() == 0) {
        tfl.add(new TreeFilelistItem(context.getString(R.string.msgs_file_select_edit_dir_empty)));
    } else {
        mTreeFilelistAdapter.setDataList(tfl);
        if (!mDialogLocalDir.equals("")) {
            String sel_dir = mDialogLocalDir;
            String n_dir = "", e_dir = "";
            if (sel_dir.startsWith("/"))
                n_dir = sel_dir.substring(1);
            else
                n_dir = sel_dir;
            if (n_dir.endsWith("/"))
                e_dir = n_dir.substring(0, n_dir.length() - 1);
            else
                e_dir = n_dir;
            selectLocalDirTree(e_dir);
        }
        if (!mDialogFileName.equals(""))
            selectLocalDirTreeFile(mDialogFileName);
    }
    mTreeFileListView.setScrollingCacheEnabled(false);
    mTreeFileListView.setScrollbarFadingEnabled(false);

    if (mSavedViewContentsValue != null && mSavedViewContentsValue.mainDialogFilename != null) {
        filename.setText(mSavedViewContentsValue.mainDialogFilename);
        filename.setSelection(mSavedViewContentsValue.mainDialogFilenameSelStart,
                mSavedViewContentsValue.mainDialogFilenameTextSelEnd);
        dir_name.setText(mSavedViewContentsValue.mainDialogDirName);
    } else {
        //          if (mDialogLocalDir.equals("")) filename.setText(mDialogLocalUuid+mDialogFileName);
        //          else filename.setText(mDialogLocalUuid+mDialogLocalDir+"/"+mDialogFileName);
        //         filename.setSelection(filename.getText().toString().length());
        dir_name.setText(mDialogLocalDir + "/");
        filename.setText(mDialogFileName);
    }

    //      CommonDialog.setDlgBoxSizeLimit(mDialog,true);
    //   setDlgBoxSize(dialog,0,0,false);

    if (!mDialogSingleSelect)
        btnOk.setEnabled(false);

    NotifyEvent cb_ntfy = new NotifyEvent(context);
    // set file list thread response listener 
    cb_ntfy.setListener(new NotifyEventListener() {
        @Override
        public void positiveResponse(Context c, Object[] o) {
            int p = (Integer) o[0];
            boolean p_chk = (Boolean) o[1];
            if (mDialogSingleSelect) {
                if (mTreeFilelistAdapter.getDataItem(p).isChecked() && !p_chk) {
                    if (p != -1) {
                        if (mTreeFilelistAdapter.getDataItem(p).isChecked()) {
                            if (mTreeFilelistAdapter.getDataItem(p).isDir()) {
                                dir_name.setText(mTreeFilelistAdapter.getDataItem(p).getPath()
                                        + mTreeFilelistAdapter.getDataItem(p).getName() + "/");
                                //                           filename.setText("");
                            } else {
                                dir_name.setText(mTreeFilelistAdapter.getDataItem(p).getPath());
                                filename.setText(mTreeFilelistAdapter.getDataItem(p).getName());
                            }
                        }
                    }
                }
                if (mDialogFileOnly) {
                    if (filename.getText().length() > 0) {
                        btnOk.setEnabled(true);
                        putDlgMsg(dlg_msg, "");
                    } else {
                        btnOk.setEnabled(false);
                        putDlgMsg(dlg_msg,
                                context.getString(R.string.msgs_file_select_edit_dlg_filename_not_specified));
                    }
                } else {
                    if (mTreeFilelistAdapter.isDataItemIsSelected() || filename.getText().length() > 0) {
                        btnOk.setEnabled(true);
                        putDlgMsg(dlg_msg, "");
                    } else {
                        putDlgMsg(dlg_msg,
                                context.getString(R.string.msgs_file_select_edit_dlg_directory_not_selected));
                        btnOk.setEnabled(false);
                    }
                }
            } else {
                if (mTreeFilelistAdapter.getDataItem(p).isDir()) {
                    dir_name.setText(mTreeFilelistAdapter.getDataItem(p).getPath()
                            + mTreeFilelistAdapter.getDataItem(p).getName() + "/");
                } else {
                    dir_name.setText(mTreeFilelistAdapter.getDataItem(p).getPath());
                    filename.setText(mTreeFilelistAdapter.getDataItem(p).getName());
                }
                putDlgMsg(dlg_msg, "");
                btnOk.setEnabled(true);
            }
        }

        @Override
        public void negativeResponse(Context c, Object[] o) {
            boolean checked = false;
            //         int p=(Integer) o[0];
            boolean p_chk = (Boolean) o[1];
            if (mDialogSingleSelect) {
                if (p_chk) {
                    for (int i = 0; i < mTreeFilelistAdapter.getDataItemCount(); i++) {
                        if (mTreeFilelistAdapter.getDataItem(i).isChecked()) {
                            checked = true;
                            break;
                        }
                    }
                    if (checked)
                        btnOk.setEnabled(true);
                    else
                        btnOk.setEnabled(false);
                }
            } else {
                //               Log.v("","sel="+p_chk);
                btnOk.setEnabled(false);
                for (int i = 0; i < mTreeFilelistAdapter.getDataItemCount(); i++) {
                    if (mTreeFilelistAdapter.getDataItem(i).isChecked()) {
                        btnOk.setEnabled(true);
                        break;
                    }
                }
            }
        }
    });
    mTreeFilelistAdapter.setCbCheckListener(cb_ntfy);

    //      if (mDialogLocalUuid.equals(filename.getText().toString())) btnOk.setEnabled(false);
    filename.addTextChangedListener(new TextWatcher() {
        @Override
        public void afterTextChanged(Editable s) {
            if (mDialogSingleSelect) {
                if (s.length() != 0) {
                    btnOk.setEnabled(true);
                    putDlgMsg(dlg_msg, "");
                } else {
                    btnOk.setEnabled(false);
                    putDlgMsg(dlg_msg,
                            context.getString(R.string.msgs_file_select_edit_dlg_filename_not_specified));
                }
            }
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }
    });

    NotifyEvent ntfy_expand_close = new NotifyEvent(context);
    ntfy_expand_close.setListener(new NotifyEventListener() {
        @Override
        public void positiveResponse(Context c, Object[] o) {
            int idx = (Integer) o[0];
            final int pos = mTreeFilelistAdapter.getItem(idx);
            final TreeFilelistItem tfi = mTreeFilelistAdapter.getDataItem(pos);
            if (tfi.getName().startsWith("---"))
                return;
            if (tfi.isDir())
                processLocalDirTree(mDialogFileOnly, mDialogLocalUuid, pos, tfi, mTreeFilelistAdapter);
            else {
                mTreeFilelistAdapter.setDataItemIsSelected(pos);
                dir_name.setText(mTreeFilelistAdapter.getDataItem(pos).getPath());
                filename.setText(mTreeFilelistAdapter.getDataItem(pos).getName());
                if (mTreeFilelistAdapter.getDataItem(pos).isDir() && mDialogFileOnly)
                    btnOk.setEnabled(false);
                else
                    btnOk.setEnabled(true);
            }
        }

        @Override
        public void negativeResponse(Context c, Object[] o) {
        }
    });
    mTreeFilelistAdapter.setExpandCloseListener(ntfy_expand_close);
    mTreeFileListView.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> items, View view, int idx, long id) {
            final int pos = mTreeFilelistAdapter.getItem(idx);
            final TreeFilelistItem tfi = mTreeFilelistAdapter.getDataItem(pos);
            if (tfi.getName().startsWith("---"))
                return;
            if (tfi.isDir())
                processLocalDirTree(mDialogFileOnly, mDialogLocalUuid, pos, tfi, mTreeFilelistAdapter);
            else {
                mTreeFilelistAdapter.setDataItemIsSelected(pos);
                dir_name.setText(mTreeFilelistAdapter.getDataItem(pos).getPath());
                filename.setText(mTreeFilelistAdapter.getDataItem(pos).getName());
                if (mTreeFilelistAdapter.getDataItem(pos).isDir() && mDialogFileOnly)
                    btnOk.setEnabled(false);
                else
                    btnOk.setEnabled(true);
            }
        }
    });

    mTreeFileListView.setOnItemLongClickListener(new OnItemLongClickListener() {
        @Override
        public boolean onItemLongClick(AdapterView<?> arg0, View arg1, final int position, long arg3) {
            return true;
        }
    });

    btnHome.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            dir_name.setText("/");
        }
    });

    //Create button
    btnCreate.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            NotifyEvent ntfy = new NotifyEvent(context);
            // set file list thread response listener 
            ntfy.setListener(new NotifyEventListener() {
                @Override
                public void positiveResponse(Context c, Object[] o) {
                    //                  btnRefresh.performClick();                  
                }

                @Override
                public void negativeResponse(Context c, Object[] o) {
                }

            });
            //            String mp="";
            //            for(TreeFilelistItem tfi:mTreeFilelistAdapter.getDataList()) {
            //               if (tfi.isChecked()) {
            //                  mp=tfi.getPath()+tfi.getName();
            //                  break;
            //               }
            //            }
            fileSelectEditDialogCreateBtn(activity, context,
                    dir_name.getText().substring(0, dir_name.getText().length() - 1), "", mTreeFilelistAdapter,
                    ntfy, mTreeFileListView);

        }
    });
    //Refresh button
    btnRefresh.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            ArrayList<TreeFilelistItem> tfl = createLocalFilelist(mDialogFileOnly, mDialogLocalUuid, "");//mDialogLocalUuid,"");
            if (tfl.size() < 1)
                tfl.add(new TreeFilelistItem(context.getString(R.string.msgs_file_select_edit_dir_empty)));
            mTreeFilelistAdapter.setDataList(tfl);
        }
    });
    //OK button
    //      btnOk.setEnabled(false);
    btnOk.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            if (mDialogSingleSelect) {
                String[] sl_array = new String[] {
                        dir_name.getText().toString() + filename.getText().toString() };
                if (mNotifyEvent != null)
                    mNotifyEvent.notifyToListener(true, sl_array);
            } else {
                ArrayList<String> sl = new ArrayList<String>();
                ArrayList<TreeFilelistItem> tfl = mTreeFilelistAdapter.getDataList();
                for (TreeFilelistItem li : tfl) {
                    if (li.isChecked()) {
                        if (li.isDir())
                            sl.add(li.getPath() + li.getName());
                        else
                            sl.add(li.getPath() + li.getName());
                    }
                }
                String[] sl_array = new String[sl.size()];
                for (int i = 0; i < sl.size(); i++) {
                    if (mDialogSelectedFilePathWithMountPoint)
                        sl_array[i] = sl.get(i);
                    else
                        sl_array[i] = sl.get(i);
                    //                  Log.v("","sel="+sl_array[i]);
                }
                if (mNotifyEvent != null)
                    mNotifyEvent.notifyToListener(true, sl_array);
            }
            //            mDialog.dismiss();
            mFragment.dismiss();
        }
    });
    // CANCEL?
    btnCancel.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            //            mDialog.dismiss();
            mFragment.dismiss();
            if (mNotifyEvent != null)
                mNotifyEvent.notifyToListener(false, null);
        }
    });

}

From source file:org.anurag.file.quest.FileQuestHD.java

/**
 * /*from  ww  w.j ava2  s .c  o  m*/
 * @param color
 */
private void styleActionBar(int color) {
    // TODO Auto-generated method stub
    toolbar.setBackgroundColor(color);
    top_toolbar.setBackgroundColor(color);
    indicator.setBackgroundColor(color);
    bottom_options.setBackgroundColor(color);
    LinearLayout drawermenu = (LinearLayout) findViewById(R.id.drawer_list);
    drawermenu.setBackgroundColor(color);
}

From source file:com.sentaroh.android.Utilities.Dialog.FileSelectDialogFragment.java

private void initViewWidget() {
    if (mDebugEnable)
        Log.v(APPLICATION_TAG, "initViewWidget");

    if (mDebugEnable)
        Log.v(APPLICATION_TAG, "Create=" + mDialogEnableCreate + ", Title=" + mDialogTitle + ", lurl="
                + mDialogLocalUrl + ", ldir=" + mDialogLocalDir + ", file name=" + mDialogFileName);

    mThemeColorList = ThemeUtil.getThemeColorList(getActivity());

    mDialog.setContentView(R.layout.file_select_edit_dlg);
    LinearLayout title_view = (LinearLayout) mDialog.findViewById(R.id.file_select_edit_dlg_title_view);
    title_view.setBackgroundColor(mThemeColorList.dialog_title_background_color);
    TextView title = (TextView) mDialog.findViewById(R.id.file_select_edit_dlg_title);
    title.setTextColor(mThemeColorList.text_color_dialog_title);
    title.setText(mDialogTitle);/*from   ww w . java 2  s  .c o  m*/
    final TextView dlg_msg = (TextView) mDialog.findViewById(R.id.file_select_edit_dlg_msg);
    final Button btnHome = (Button) mDialog.findViewById(R.id.file_select_edit_dlg_home_dir_btn);
    btnHome.setTextColor(mThemeColorList.text_color_primary);
    btnHome.setVisibility(Button.VISIBLE);
    final Button btnCreate = (Button) mDialog.findViewById(R.id.file_select_edit_dlg_create_btn);
    btnCreate.setTextColor(mThemeColorList.text_color_primary);
    final Button btnOk = (Button) mDialog.findViewById(R.id.file_select_edit_dlg_ok_btn);
    //      btnOk.setTextColor(mThemeColorList.text_color_primary);
    final Button btnCancel = (Button) mDialog.findViewById(R.id.file_select_edit_dlg_cancel_btn);
    btnCancel.setTextColor(mThemeColorList.text_color_primary);
    final Button btnRefresh = (Button) mDialog.findViewById(R.id.file_select_edit_dlg_refresh_btn);
    btnRefresh.setTextColor(mThemeColorList.text_color_primary);

    LinearLayout ll_dlg_view = (LinearLayout) mDialog.findViewById(R.id.file_select_edit_dlg_view);
    ll_dlg_view.setBackgroundColor(mThemeColorList.dialog_msg_background_color);

    final Activity activity = getActivity();
    final Context context = activity.getApplicationContext();

    if (mDialogEnableCreate) {
        btnCreate.setVisibility(TextView.VISIBLE);
    }

    mLocalMountPointSpinner = (Spinner) mDialog.findViewById(R.id.file_select_edit_dlg_rdir);
    setSpinnerBackground(context, mLocalMountPointSpinner, mThemeColorList.theme_is_light);
    mLocalMountPointSpinner.setVisibility(Spinner.VISIBLE);
    //   Root directory spinner
    CustomSpinnerAdapter adapter = new CustomSpinnerAdapter(activity, R.layout.custom_simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    mLocalMountPointSpinner.setPrompt(context.getString(R.string.msgs_file_select_edit_local_mount_point));
    mLocalMountPointSpinner.setAdapter(adapter);

    int a_no = -1;
    ArrayList<String> ml = LocalMountPoint.getLocalMountPointList(context);
    mLocalMountPointSpinner.setOnItemSelectedListener(null);
    if (mDialogMpLimitInternalAndSdcard) {
        adapter.add(Environment.getExternalStorageDirectory().toString());
        File[] fl = ContextCompat.getExternalFilesDirs(context, null);
        for (File item : fl) {
            if (!item.getPath().startsWith(Environment.getExternalStorageDirectory().toString())) {
                adapter.add(item.getPath().substring(0, item.getPath().indexOf("/Android")));
                break;
            }
        }
        mLocalMountPointSpinner.setEnabled(true);
        for (int i = 0; i < adapter.getCount(); i++) {
            if (adapter.getItem(i).equals(mDialogLocalUrl)) {
                a_no = i;
                break;
            }
        }
        mLocalMountPointSpinner.setSelection(a_no);
    } else {
        if (ml.size() == 0) {
            if (mDialogIncludeRoot)
                adapter.add("/");
            adapter.add(mDialogLocalUrl);
            mLocalMountPointSpinner.setEnabled(false);
        } else {
            mLocalMountPointSpinner.setEnabled(true);
            if (mDialogIncludeRoot)
                adapter.add("/");
            for (int i = 0; i < ml.size(); i++)
                adapter.add(ml.get(i));
            for (int i = 0; i < ml.size(); i++) {
                if (mDialogLocalUrl.startsWith(ml.get(i))) {
                    a_no = i;
                    break;
                }
            }
            mLocalMountPointSpinner.setSelection(a_no);
        }
    }
    LinearLayout ll_mp = (LinearLayout) mDialog.findViewById(R.id.file_select_edit_dlg_mp_view);
    if (mDialogHideMp)
        ll_mp.setVisibility(LinearLayout.GONE);
    else
        ll_mp.setVisibility(LinearLayout.VISIBLE);
    //      ll_mp.setVisibility(LinearLayout.GONE);

    //   final TextView v_spacer=(TextView)mDialog.findViewById(R.id.file_select_edit_dlg_spacer);
    mTreeFileListView = (ListView) mDialog.findViewById(android.R.id.list);
    final CustomTextView dir_name = (CustomTextView) mDialog.findViewById(R.id.file_select_edit_dlg_dir_name);
    dir_name.setTextColor(mThemeColorList.text_color_primary);
    final EditText file_name = (EditText) mDialog.findViewById(R.id.file_select_edit_dlg_file_name);
    if (!mDialogSingleSelect)
        file_name.setVisibility(EditText.GONE);
    else
        file_name.setVisibility(EditText.VISIBLE);
    if (mDialogFileOnly) {
        file_name.setVisibility(EditText.VISIBLE);
        file_name.setEnabled(true);
        dir_name.setVisibility(EditText.VISIBLE);
    } else {
        if (mDialogDirectoryOnly) {
            file_name.setVisibility(EditText.GONE);
            file_name.setEnabled(false);
            dir_name.setVisibility(EditText.VISIBLE);
            btnHome.setVisibility(EditText.VISIBLE);
        } else {
            file_name.setVisibility(EditText.VISIBLE);
            file_name.setEnabled(true);
            dir_name.setVisibility(EditText.VISIBLE);
            btnHome.setVisibility(EditText.VISIBLE);
        }
    }
    file_name.setOnKeyListener(new OnKeyListener() {
        @Override
        public boolean onKey(View arg0, int keyCode, KeyEvent event) {
            if (//event.getAction() == KeyEvent.ACTION_DOWN &&
            keyCode == KeyEvent.KEYCODE_ENTER) {
                return true;
            }
            return false;
        }
    });
    //    if (dirs.size()<=2)   v_spacer.setVisibility(TextView.VISIBLE);

    mTreeFilelistAdapter = new TreeFilelistAdapter(activity, mDialogSingleSelect, true);
    mTreeFileListView.setAdapter(mTreeFilelistAdapter);

    if (mDialogLocalUrl.equals(""))
        mDialogLocalUrl = ml.get(0);
    ArrayList<TreeFilelistItem> tfl = createLocalFilelist(mDialogFileOnly, mDialogLocalUrl, "");
    if (tfl.size() == 0) {
        tfl.add(new TreeFilelistItem(context.getString(R.string.msgs_file_select_edit_dir_empty)));
    } else {
        mTreeFilelistAdapter.setDataList(tfl);
        if (!mDialogLocalDir.equals("")) {
            String sel_dir = mDialogLocalDir;
            String n_dir = "", e_dir = "";
            if (sel_dir.startsWith("/"))
                n_dir = sel_dir.substring(1);
            else
                n_dir = sel_dir;
            if (n_dir.endsWith("/"))
                e_dir = n_dir.substring(0, n_dir.length() - 1);
            else
                e_dir = n_dir;
            //              Log.v("","mp="+mDialogLocalUrl+", se;_dir="+sel_dir+", e_dir="+e_dir);
            selectLocalDirTree(e_dir);
        }
        if (!mDialogFileName.equals(""))
            selectLocalDirTreeFile(mDialogFileName);
    }
    mTreeFileListView.setScrollingCacheEnabled(false);
    mTreeFileListView.setScrollbarFadingEnabled(false);

    if (mSavedViewContentsValue != null && mSavedViewContentsValue.mainDialogFilename != null) {
        file_name.setText(mSavedViewContentsValue.mainDialogFilename);
        file_name.setSelection(mSavedViewContentsValue.mainDialogFilenameSelStart,
                mSavedViewContentsValue.mainDialogFilenameTextSelEnd);
        dir_name.setText(mSavedViewContentsValue.mainDialogDirName);
    } else {
        String d_name = mDialogLocalDir.equals("") ? mDialogLocalUrl + "/"
                : mDialogLocalUrl + mDialogLocalDir + "/";
        dir_name.setText(d_name);
        file_name.setText(mDialogFileName);
    }

    if (!mDialogSingleSelect)
        btnOk.setEnabled(false);

    NotifyEvent cb_ntfy = new NotifyEvent(context);
    // set file list thread response listener 
    cb_ntfy.setListener(new NotifyEventListener() {
        @Override
        public void positiveResponse(Context c, Object[] o) {
            int p = (Integer) o[0];
            boolean p_chk = (Boolean) o[1];
            String turl = (String) mLocalMountPointSpinner.getSelectedItem();
            if (mDialogSingleSelect) {
                if (mTreeFilelistAdapter.getDataItem(p).isChecked() && !p_chk) {
                    if (p != -1) {
                        if (mTreeFilelistAdapter.getDataItem(p).isChecked()) {
                            if (mTreeFilelistAdapter.getDataItem(p).isDir()) {
                                dir_name.setText(turl + mTreeFilelistAdapter.getDataItem(p).getPath()
                                        + mTreeFilelistAdapter.getDataItem(p).getName() + "/");
                                //                           file_name.setText("");
                            } else {
                                dir_name.setText(turl + mTreeFilelistAdapter.getDataItem(p).getPath());
                                file_name.setText(mTreeFilelistAdapter.getDataItem(p).getName());
                            }
                        }
                    }
                }
                if (mDialogFileOnly) {
                    if (file_name.getText().length() > 0) {
                        btnOk.setEnabled(true);
                        putDlgMsg(dlg_msg, "");
                    } else {
                        btnOk.setEnabled(false);
                        putDlgMsg(dlg_msg,
                                context.getString(R.string.msgs_file_select_edit_dlg_filename_not_specified));
                    }
                } else {
                    if (mTreeFilelistAdapter.isDataItemIsSelected() || file_name.getText().length() > 0) {
                        btnOk.setEnabled(true);
                        putDlgMsg(dlg_msg, "");
                    } else {
                        putDlgMsg(dlg_msg,
                                context.getString(R.string.msgs_file_select_edit_dlg_directory_not_selected));
                        btnOk.setEnabled(false);
                    }
                }
            } else {
                if (mTreeFilelistAdapter.getDataItem(p).isDir()) {
                    dir_name.setText(turl + mTreeFilelistAdapter.getDataItem(p).getPath()
                            + mTreeFilelistAdapter.getDataItem(p).getName() + "/");
                    //                  file_name.setText("");
                } else {
                    dir_name.setText(turl + mTreeFilelistAdapter.getDataItem(p).getPath());
                    file_name.setText(mTreeFilelistAdapter.getDataItem(p).getName());
                }
                putDlgMsg(dlg_msg, "");
                btnOk.setEnabled(true);
            }
        }

        @Override
        public void negativeResponse(Context c, Object[] o) {
            boolean checked = false;
            //         int p=(Integer) o[0];
            boolean p_chk = (Boolean) o[1];
            if (mDialogSingleSelect) {
                if (p_chk) {
                    for (int i = 0; i < mTreeFilelistAdapter.getDataItemCount(); i++) {
                        if (mTreeFilelistAdapter.getDataItem(i).isChecked()) {
                            checked = true;
                            break;
                        }
                    }
                    if (checked)
                        btnOk.setEnabled(true);
                    else
                        btnOk.setEnabled(false);
                }
            } else {
                //               Log.v("","sel="+p_chk);
                btnOk.setEnabled(false);
                for (int i = 0; i < mTreeFilelistAdapter.getDataItemCount(); i++) {
                    if (mTreeFilelistAdapter.getDataItem(i).isChecked()) {
                        btnOk.setEnabled(true);
                        break;
                    }
                }
            }
        }
    });
    mTreeFilelistAdapter.setCbCheckListener(cb_ntfy);

    if (mDialogLocalUrl.equals(file_name.getText().toString()))
        btnOk.setEnabled(false);
    if (mDialogFileOnly && mDialogFileName.equals("")) {
        btnOk.setEnabled(false);
        putDlgMsg(dlg_msg, context.getString(R.string.msgs_file_select_edit_dlg_filename_not_specified));
    }
    file_name.addTextChangedListener(new TextWatcher() {
        @Override
        public void afterTextChanged(Editable s) {
            if (mDialogSingleSelect) {
                if (s.length() != 0) {
                    btnOk.setEnabled(true);
                    putDlgMsg(dlg_msg, "");
                } else {
                    btnOk.setEnabled(false);
                    putDlgMsg(dlg_msg,
                            context.getString(R.string.msgs_file_select_edit_dlg_filename_not_specified));
                }
            }
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }
    });

    NotifyEvent ntfy_expand_close = new NotifyEvent(context);
    ntfy_expand_close.setListener(new NotifyEventListener() {
        @Override
        public void positiveResponse(Context c, Object[] o) {
            int idx = (Integer) o[0];
            final int pos = mTreeFilelistAdapter.getItem(idx);
            final TreeFilelistItem tfi = mTreeFilelistAdapter.getDataItem(pos);
            if (tfi.getName().startsWith("---"))
                return;
            String turl = (String) mLocalMountPointSpinner.getSelectedItem();
            if (tfi.isDir())
                processLocalDirTree(mDialogFileOnly, turl, pos, tfi, mTreeFilelistAdapter);
            else {
                mTreeFilelistAdapter.setDataItemIsSelected(pos);
                dir_name.setText((turl + mTreeFilelistAdapter.getDataItem(pos).getPath()));
                file_name.setText(mTreeFilelistAdapter.getDataItem(pos).getName());
                if (mTreeFilelistAdapter.getDataItem(pos).isDir() && mDialogFileOnly)
                    btnOk.setEnabled(false);
                else
                    btnOk.setEnabled(true);
            }
        }

        @Override
        public void negativeResponse(Context c, Object[] o) {
        }
    });
    mTreeFilelistAdapter.setExpandCloseListener(ntfy_expand_close);
    mTreeFileListView.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> items, View view, int idx, long id) {
            final int pos = mTreeFilelistAdapter.getItem(idx);
            final TreeFilelistItem tfi = mTreeFilelistAdapter.getDataItem(pos);
            if (tfi.getName().startsWith("---"))
                return;
            String turl = (String) mLocalMountPointSpinner.getSelectedItem();
            if (tfi.isDir())
                processLocalDirTree(mDialogFileOnly, turl, pos, tfi, mTreeFilelistAdapter);
            else {
                mTreeFilelistAdapter.setDataItemIsSelected(pos);
                dir_name.setText((turl + mTreeFilelistAdapter.getDataItem(pos).getPath()));
                file_name.setText(mTreeFilelistAdapter.getDataItem(pos).getName());
                if (mTreeFilelistAdapter.getDataItem(pos).isDir() && mDialogFileOnly)
                    btnOk.setEnabled(false);
                else
                    btnOk.setEnabled(true);
            }
        }
    });

    mTreeFileListView.setOnItemLongClickListener(new OnItemLongClickListener() {
        @Override
        public boolean onItemLongClick(AdapterView<?> arg0, View arg1, final int position, long arg3) {
            return true;
        }
    });

    btnHome.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            dir_name.setText(mLocalMountPointSpinner.getSelectedItem().toString() + "/");
        }
    });

    //Create button
    btnCreate.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            NotifyEvent ntfy = new NotifyEvent(context);
            // set file list thread response listener 
            ntfy.setListener(new NotifyEventListener() {
                @Override
                public void positiveResponse(Context c, Object[] o) {
                    //                  btnRefresh.performClick();                  
                }

                @Override
                public void negativeResponse(Context c, Object[] o) {
                }

            });
            fileSelectEditDialogCreateBtn(activity, context,
                    dir_name.getText().substring(0, dir_name.getText().length() - 1), "",
                    mLocalMountPointSpinner.getSelectedItem().toString(), mTreeFilelistAdapter, ntfy,
                    mTreeFileListView);

        }
    });
    //Refresh button
    btnRefresh.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            String mp = mLocalMountPointSpinner.getSelectedItem().toString();
            ArrayList<TreeFilelistItem> tfl = createLocalFilelist(mDialogFileOnly, mp, "");//mDialogLocalUrl,"");
            if (tfl.size() < 1)
                tfl.add(new TreeFilelistItem(context.getString(R.string.msgs_file_select_edit_dir_empty)));
            mTreeFilelistAdapter.setDataList(tfl);
        }
    });
    //OK button
    //      btnOk.setEnabled(false);
    btnOk.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            if (mDialogSingleSelect) {
                String[] sl_array = new String[] { dir_name.getText() + file_name.getText().toString() };
                if (mNotifyEvent != null)
                    mNotifyEvent.notifyToListener(true, sl_array);
            } else {
                ArrayList<String> sl = new ArrayList<String>();
                ArrayList<TreeFilelistItem> tfl = mTreeFilelistAdapter.getDataList();
                for (TreeFilelistItem li : tfl) {
                    if (li.isChecked()) {
                        if (li.isDir())
                            sl.add(li.getPath() + li.getName());
                        else
                            sl.add(li.getPath() + li.getName());
                    }
                }
                String[] sl_array = new String[sl.size()];
                String mp = mLocalMountPointSpinner.getSelectedItem().toString();
                for (int i = 0; i < sl.size(); i++) {
                    if (mDialogSelectedFilePathWithMountPoint)
                        sl_array[i] = mp + sl.get(i);
                    else
                        sl_array[i] = sl.get(i);
                    //                  Log.v("","sel="+sl_array[i]);
                }
                if (mNotifyEvent != null)
                    mNotifyEvent.notifyToListener(true, sl_array);
            }
            //            mDialog.dismiss();
            mFragment.dismiss();
        }
    });
    // CANCEL?
    btnCancel.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            //            mDialog.dismiss();
            mFragment.dismiss();
            if (mNotifyEvent != null)
                mNotifyEvent.notifyToListener(false, null);
        }
    });

    Handler hndl = new Handler();
    hndl.postDelayed(new Runnable() {
        @Override
        public void run() {
            mLocalMountPointSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
                @Override
                public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                    //                    Log.v("","MP selected="+position);
                    Spinner spinner = (Spinner) parent;
                    String turl = (String) spinner.getSelectedItem();
                    ArrayList<TreeFilelistItem> tfl = createLocalFilelist(mDialogFileOnly, turl, "");
                    if (tfl.size() < 1)
                        tfl.add(new TreeFilelistItem(
                                context.getString(R.string.msgs_file_select_edit_dir_empty)));
                    mTreeFilelistAdapter.setDataList(tfl);
                    mTreeFilelistAdapter.notifyDataSetChanged();
                    if (turl.startsWith(mSafFileMgr.getExternalSdcardPath())) {
                        if (mSafFileMgr.getSdcardSafFile() == null)
                            btnCreate.setEnabled(false);
                        else
                            btnCreate.setEnabled(true);
                    } else
                        btnCreate.setEnabled(true);
                    dir_name.setText(turl + "/");
                    Handler hndl_sel = new Handler();
                    hndl_sel.post(new Runnable() {
                        @Override
                        public void run() {
                            mTreeFileListView.setSelection(0);
                        }
                    });
                }

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

From source file:com.dycody.android.idealnote.ListFragment.java

/**
 * Selects all notes in list/* w w  w.  j  av  a 2 s  .c  om*/
 */
private void selectAllNotes() {
    for (int i = 0; i < list.getChildCount(); i++) {
        LinearLayout v = (LinearLayout) list.getChildAt(i).findViewById(R.id.card_layout);
        // Checks null to avoid the footer
        if (v != null) {
            v.setBackgroundColor(getResources().getColor(R.color.list_bg_selected));
        }
    }
    selectedNotes.clear();
    for (int i = 0; i < listAdapter.getCount(); i++) {
        selectedNotes.add(listAdapter.getItem(i));
        listAdapter.addSelectedItem(i);
    }
    prepareActionModeMenu();
    setCabTitle();
}

From source file:com.dycody.android.idealnote.ListFragment.java

/**
 * Manage check/uncheck of notes in list during multiple selection phase
 *//*from w w w  .j  a v a 2 s.  com*/
private void toggleListViewItem(View view, int position) {
    Note note = listAdapter.getItem(position);
    LinearLayout cardLayout = (LinearLayout) view.findViewById(R.id.card_layout);
    if (!getSelectedNotes().contains(note)) {
        getSelectedNotes().add(note);
        listAdapter.addSelectedItem(position);
        cardLayout.setBackgroundColor(getResources().getColor(R.color.list_bg_selected));
    } else {
        getSelectedNotes().remove(note);
        listAdapter.removeSelectedItem(position);
        listAdapter.restoreDrawable(note, cardLayout);
    }
    prepareActionModeMenu();

    // Close CAB if no items are selected
    if (getSelectedNotes().size() == 0) {
        finishActionMode();
    }

}

From source file:com.money.manager.ex.adapter.AllDataAdapter.java

@SuppressWarnings({})
@Override/* ww  w.j a v a  2 s.co  m*/
public void bindView(View view, Context context, Cursor cursor) {
    // take a pointer of object UI
    LinearLayout linDate = (LinearLayout) view.findViewById(R.id.linearLayoutDate);
    TextView txtDay = (TextView) view.findViewById(R.id.textViewDay);
    TextView txtMonth = (TextView) view.findViewById(R.id.textViewMonth);
    TextView txtYear = (TextView) view.findViewById(R.id.textViewYear);
    TextView txtStatus = (TextView) view.findViewById(R.id.textViewStatus);
    TextView txtAmount = (TextView) view.findViewById(R.id.textViewAmount);
    TextView txtPayee = (TextView) view.findViewById(R.id.textViewPayee);
    TextView txtAccountName = (TextView) view.findViewById(R.id.textViewAccountName);
    TextView txtCategorySub = (TextView) view.findViewById(R.id.textViewCategorySub);
    TextView txtNotes = (TextView) view.findViewById(R.id.textViewNotes);
    TextView txtBalance = (TextView) view.findViewById(R.id.textViewBalance);
    // header index
    if (!mHeadersAccountIndex.containsKey(cursor.getInt(cursor.getColumnIndex(ACCOUNTID)))) {
        mHeadersAccountIndex.put(cursor.getInt(cursor.getColumnIndex(ACCOUNTID)), cursor.getPosition());
    }
    // write status
    txtStatus.setText(mApplication.getStatusAsString(cursor.getString(cursor.getColumnIndex(STATUS))));
    // color status
    int colorBackground = getBackgroundColorFromStatus(cursor.getString(cursor.getColumnIndex(STATUS)));
    linDate.setBackgroundColor(colorBackground);
    txtStatus.setTextColor(Color.GRAY);
    // date group
    try {
        Date date = new SimpleDateFormat("yyyy-MM-dd").parse(cursor.getString(cursor.getColumnIndex(DATE)));
        txtMonth.setText(new SimpleDateFormat("MMM").format(date));
        txtYear.setText(new SimpleDateFormat("yyyy").format(date));
        txtDay.setText(new SimpleDateFormat("dd").format(date));
    } catch (ParseException e) {
        Log.e(AllDataAdapter.class.getSimpleName(), e.getMessage());
    }
    // take transaction amount
    double amount = cursor.getDouble(cursor.getColumnIndex(AMOUNT));
    // set currency id
    setCurrencyId(cursor.getInt(cursor.getColumnIndex(CURRENCYID)));
    // manage transfer and change amount sign
    if ((cursor.getString(cursor.getColumnIndex(TRANSACTIONTYPE)) != null)
            && (Constants.TRANSACTION_TYPE_TRANSFER
                    .equalsIgnoreCase(cursor.getString(cursor.getColumnIndex(TRANSACTIONTYPE))))) {
        if (getAccountId() != cursor.getInt(cursor.getColumnIndex(TOACCOUNTID))) {
            amount = -(amount); // -total
        } else if (getAccountId() == cursor.getInt(cursor.getColumnIndex(TOACCOUNTID))) {
            amount = cursor.getDouble(cursor.getColumnIndex(TOTRANSAMOUNT)); // to account = account
            setCurrencyId(cursor.getInt(cursor.getColumnIndex(TOCURRENCYID)));
        }
    }
    // check amount sign
    CurrencyUtils currencyUtils = new CurrencyUtils(mContext);
    txtAmount.setText(currencyUtils.getCurrencyFormatted(getCurrencyId(), amount));
    // text color amount
    if (Constants.TRANSACTION_TYPE_TRANSFER
            .equalsIgnoreCase(cursor.getString(cursor.getColumnIndex(TRANSACTIONTYPE)))) {
        txtAmount.setTextColor(Color.GRAY);
    } else if (Constants.TRANSACTION_TYPE_DEPOSIT
            .equalsIgnoreCase(cursor.getString(cursor.getColumnIndex(TRANSACTIONTYPE)))) {
        txtAmount.setTextColor(mCore.resolveColorAttribute(R.attr.holo_green_color_theme));
    } else {
        txtAmount.setTextColor(mCore.resolveColorAttribute(R.attr.holo_red_color_theme));
    }
    // compose payee description
    txtPayee.setText(cursor.getString(cursor.getColumnIndex(PAYEE)));
    // compose account name
    if (isShowAccountName()) {
        if (mHeadersAccountIndex.containsValue(cursor.getPosition())) {
            txtAccountName.setText(cursor.getString(cursor.getColumnIndex(ACCOUNTNAME)));
            txtAccountName.setVisibility(View.VISIBLE);
        } else {
            txtAccountName.setVisibility(View.GONE);
        }
    } else {
        txtAccountName.setVisibility(View.GONE);
    }
    // write ToAccountName
    if ((!TextUtils.isEmpty(cursor.getString(cursor.getColumnIndex(TOACCOUNTNAME))))) {
        if (getAccountId() != cursor.getInt(cursor.getColumnIndex(TOACCOUNTID)))
            txtPayee.setText(cursor.getString(cursor.getColumnIndex(TOACCOUNTNAME)));
        else
            txtPayee.setText(cursor.getString(cursor.getColumnIndex(ACCOUNTNAME)));
    }
    // compose category description
    String categorySub = cursor.getString(cursor.getColumnIndex(CATEGORY));
    // check sub category
    if (!(TextUtils.isEmpty(cursor.getString(cursor.getColumnIndex(SUBCATEGORY))))) {
        categorySub += " : <i>" + cursor.getString(cursor.getColumnIndex(SUBCATEGORY)) + "</i>";
    }
    // write category/subcategory format html
    if (!TextUtils.isEmpty(categorySub)) {
        txtCategorySub.setText(Html.fromHtml(categorySub));
    } else {
        txtCategorySub.setText("");
    }
    // notes
    if (!TextUtils.isEmpty(cursor.getString(cursor.getColumnIndex(NOTES)))) {
        txtNotes.setText(
                Html.fromHtml("<small>" + cursor.getString(cursor.getColumnIndex(NOTES)) + "</small>"));
        txtNotes.setVisibility(View.VISIBLE);
    } else {
        txtNotes.setVisibility(View.GONE);
    }
    // check if item is checked
    if (mCheckedPosition.get(cursor.getPosition(), false)) {
        view.setBackgroundResource(R.color.holo_blue_light);
    } else {
        view.setBackgroundResource(android.R.color.transparent);
    }
    // balance account or days left
    if (mTypeCursor == TypeCursor.ALLDATA) {
        if (isShowBalanceAmount() && getDatabase() != null) {
            int transId = cursor.getInt(cursor.getColumnIndex(ID));
            // create thread for calculate balance amount
            BalanceAmount balanceAmount = new BalanceAmount();
            balanceAmount.setAccountId(getAccountId());
            balanceAmount.setDate(cursor.getString(cursor.getColumnIndex(DATE)));
            balanceAmount.setTextView(txtBalance);
            balanceAmount.setContext(mContext);
            balanceAmount.setDatabase(getDatabase());
            balanceAmount.setTransId(transId);
            // execute thread
            balanceAmount.execute();
        } else {
            txtBalance.setVisibility(View.GONE);
        }
    } else {
        int daysLeft = cursor.getInt(cursor.getColumnIndex(QueryBillDeposits.DAYSLEFT));
        if (daysLeft == 0) {
            txtBalance.setText(R.string.inactive);
        } else {
            txtBalance.setText(Integer.toString(Math.abs(daysLeft)) + " "
                    + context.getString(daysLeft > 0 ? R.string.days_remaining : R.string.days_overdue));
        }
        txtBalance.setVisibility(View.VISIBLE);
    }
}