List of usage examples for android.widget LinearLayout setVisibility
@RemotableViewMethod public void setVisibility(@Visibility int visibility)
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 av a 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); // 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:com.mobicage.rogerthat.util.ui.SendMessageView.java
public void setActive(T activity, MainService mainService, String[] friendRecipients, String initialText, String parentKey, long parentFlags, String repliedToKey, long defaultPriority, boolean defaultSticky) { mMainService = mainService;/*ww w. j a va2s .c o m*/ mMessagingPlugin = mainService.getPlugin(MessagingPlugin.class); mActivity = activity; mFriendRecipients = friendRecipients; mParentKey = parentKey; mParentFlags = parentFlags; mRepliedToKey = repliedToKey; mPriority = defaultPriority; mIsSticky = defaultSticky; mMessage = (EditText) findViewById(R.id.message); if (initialText != null) { mMessage.setText(initialText); } mKey = UUID.randomUUID().toString(); final ImageButton submitButton = (ImageButton) findViewById(R.id.submit); mAttachmentContainer = (FrameLayout) findViewById(R.id.attachment_container); mAttachmentPreview = (ImageView) findViewById(R.id.attachment_preview); findViewById(R.id.attachment_status).setOnClickListener(new SafeViewOnClickListener() { @Override public void safeOnClick(View v) { mAttachmentContainer.setVisibility(View.GONE); mHasImageSelected = false; mHasVideoSelected = false; initImageButtonsNavigation(); } }); mButtonsContainer = (LinearLayout) findViewById(R.id.button_container); submitButton.setOnClickListener(new SafeViewOnClickListener() { @Override public void safeOnClick(View v) { try { if ("".equals(mMessage.getText().toString().trim()) && mButtons.size() == 0 && !mHasImageSelected && !mHasVideoSelected) { UIUtils.showLongToast(mActivity, mActivity.getString(R.string.message_or_buttons_required)); return; } final String me = mMainService.getIdentityStore().getIdentity().getEmail(); sendMessage(me); mMainService.sendBroadcast(new Intent(MessagingPlugin.NEW_MESSAGE_QUEUED_TO_BACKLOG_INTENT), true, true); if (mParentKey != null && !SystemUtils.isFlagEnabled(mParentFlags, MessagingPlugin.FLAG_DYNAMIC_CHAT)) mMessagingPlugin.ackThread(mParentKey); Long[] buttonIds = mButtons.toArray(new Long[mButtons.size()]); for (Long buttonId : buttonIds) { final CannedButton cannedButton = mCannedButtons.getById(buttonId); if (cannedButton != null) { cannedButton.used(); mCannedButtons.setDirty(true); } } if (mCannedButtons.isDirty()) mCannedButtons.sort(); mCannedButtons.save(mMainService.getConfigurationProvider()); if (mRepliedToKey != null) dismissMessageOnReply(mRepliedToKey); if (mFriendRecipients == null) { hideKeyboard(); resetLayout(); } else { mMainService.runOnBIZZHandler(new SafeRunnable() { @Override protected void safeRun() throws Exception { Bundle b = new Bundle(); b.putString(HomeActivity.INTENT_KEY_LAUNCHINFO, HomeActivity.INTENT_VALUE_SHOW_NEW_MESSAGES); b.putString(HomeActivity.INTENT_KEY_MESSAGE, mKey); Intent intent = new Intent(mActivity, MessagingActivity.class); intent.setAction(MainActivity.ACTION_NOTIFICATION_MESSAGE_RECEIVED); intent.putExtra("show_drawer_icon", true); intent.putExtras(b); intent.setFlags(MainActivity.FLAG_NEW_STACK); mActivity.startActivity(intent); } }); } } catch (Exception e) { L.bug(e); } } }); _5_DP_IN_PX = UIUtils.convertDipToPixels(mActivity, 5); _30_DP_IN_PX = UIUtils.convertDipToPixels(mActivity, 30); _60_DP_IN_PX = UIUtils.convertDipToPixels(mActivity, 60); final int displayWidth = UIUtils.getDisplayWidth(mActivity); mMaxImageButtonsOnScreen = displayWidth / _60_DP_IN_PX; L.i("displayWidth: " + displayWidth); L.i("mMaxImageButtonsOnScreen: " + mMaxImageButtonsOnScreen); loadCannedButtons(); final LinearLayout optionButtons = (LinearLayout) findViewById(R.id.imageButtons); if (mFriendRecipients == null) { mMessage.clearFocus(); mMessage.setOnFocusChangeListener(new OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { optionButtons.setVisibility(View.VISIBLE); initImageButtonsNavigation(); mMessage.setOnFocusChangeListener(null); } }); } else { optionButtons.setVisibility(View.VISIBLE); initImageButtonsNavigation(); } }
From source file:com.sentaroh.android.Utilities.LogUtil.CommonLogFileListDialogFragment.java
private void setContextButtonSelecteMode(CommonLogFileListAdapter lfm_adapter) { final TextView dlg_title = (TextView) mDialog.findViewById(R.id.log_file_list_dlg_title); String sel = "" + lfm_adapter.getItemSelectedCount() + "/" + lfm_adapter.getCount(); dlg_title.setText(sel);// ww w. j a v a2 s. c o m final ImageButton dlg_done = (ImageButton) mDialog.findViewById(R.id.log_file_list_dlg_done); dlg_done.setVisibility(ImageButton.VISIBLE); LinearLayout ll_prof = (LinearLayout) mDialog.findViewById(R.id.log_context_view); LinearLayout ll_delete = (LinearLayout) ll_prof.findViewById(R.id.log_context_button_delete_view); LinearLayout ll_share = (LinearLayout) ll_prof.findViewById(R.id.log_context_button_share_view); LinearLayout ll_select_all = (LinearLayout) ll_prof.findViewById(R.id.log_context_button_select_all_view); LinearLayout ll_unselect_all = (LinearLayout) ll_prof .findViewById(R.id.log_context_button_unselect_all_view); boolean deletable_log_selected = false; for (int i = 0; i < lfm_adapter.getCount(); i++) { if (lfm_adapter.getItem(i).isChecked && !lfm_adapter.getItem(i).isCurrentLogFile) { deletable_log_selected = true; break; } } if (deletable_log_selected) ll_delete.setVisibility(LinearLayout.VISIBLE); else ll_delete.setVisibility(LinearLayout.GONE); if (lfm_adapter.getItemSelectedCount() > 0) ll_share.setVisibility(LinearLayout.VISIBLE); else ll_share.setVisibility(LinearLayout.GONE); ll_select_all.setVisibility(LinearLayout.VISIBLE); if (lfm_adapter.isAnyItemSelected()) ll_unselect_all.setVisibility(LinearLayout.VISIBLE); else ll_unselect_all.setVisibility(LinearLayout.GONE); }
From source file:com.intuit.qboecoui.email.SalesFormEmail.java
/** * This method customizes the sales form email form based on the transaction * type and company file preferences. This determines if preferences for * online payment will be displayed or not. */// w w w . j a v a 2s . c o m private void customizeSalesFormEmailForm() { if (mTransactionType == TXN_TYPE.INVOICE) { // We will show the online payment options only if the company file // is a Harmony file. // EInvoicing is enabled and MAS subscription is paid. if (Util.isNeoEnabled()) { LinearLayout onlinePaymentPreferencesContainer = (LinearLayout) findViewById( R.id.pref_online_payment_container); if (onlinePaymentPreferencesContainer != null && SalesFormEmail.ETransactionEnabledStatus_ENABLED .equalsIgnoreCase(mETransactionEnabledStatus) && mETransactionPaymentEnabled) { // Show these preferences onlinePaymentPreferencesContainer.setVisibility(View.VISIBLE); } if (Util.shouldBankTransferOptionBeShown()) { onlinePaymentPreferencesContainer.findViewById(R.id.pref_bank_transfer) .setVisibility(View.VISIBLE); } else { onlinePaymentPreferencesContainer.findViewById(R.id.pref_bank_transfer) .setVisibility(View.GONE); } } } }
From source file:org.linphone.LinphoneActivity.java
private void changeFragmentForTablets(Fragment newFragment, FragmentsAvailable newFragmentType, boolean withoutAnimation) { // if (getResources().getBoolean(R.bool.show_statusbar_only_on_dialer)) { // if (newFragmentType == FragmentsAvailable.DIALER) { // showStatusBar(); // } else { // hideStatusBar(); // }//from ww w .j a v a 2 s. com // } if (statusFragment != null) { statusFragment.closeStatusBar(); } LinearLayout ll = (LinearLayout) findViewById(R.id.fragmentContainer2); FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); if (newFragmentType.shouldAddItselfToTheRightOf(currentFragment)) { ll.setVisibility(View.VISIBLE); transaction.addToBackStack(newFragmentType.toString()); transaction.replace(R.id.fragmentContainer2, newFragment); } else { if (newFragmentType == FragmentsAvailable.DIALER || newFragmentType == FragmentsAvailable.ABOUT || newFragmentType == FragmentsAvailable.ABOUT_INSTEAD_OF_CHAT || newFragmentType == FragmentsAvailable.ABOUT_INSTEAD_OF_SETTINGS || newFragmentType == FragmentsAvailable.SETTINGS || newFragmentType == FragmentsAvailable.ACCOUNT_SETTINGS) { ll.setVisibility(View.GONE); } else { ll.setVisibility(View.INVISIBLE); } if (!withoutAnimation && !isAnimationDisabled && currentFragment.shouldAnimate()) { if (newFragmentType.isRightOf(currentFragment)) { transaction.setCustomAnimations(R.anim.slide_in_right_to_left, R.anim.slide_out_right_to_left, R.anim.slide_in_left_to_right, R.anim.slide_out_left_to_right); } else { transaction.setCustomAnimations(R.anim.slide_in_left_to_right, R.anim.slide_out_left_to_right, R.anim.slide_in_right_to_left, R.anim.slide_out_right_to_left); } } transaction.replace(R.id.fragmentContainer, newFragment); } transaction.commitAllowingStateLoss(); getSupportFragmentManager().executePendingTransactions(); currentFragment = newFragmentType; if (newFragmentType == FragmentsAvailable.DIALER || newFragmentType == FragmentsAvailable.ABOUT_INSTEAD_OF_CHAT || newFragmentType == FragmentsAvailable.ABOUT_INSTEAD_OF_SETTINGS || newFragmentType == FragmentsAvailable.SETTINGS || newFragmentType == FragmentsAvailable.CONTACTS || newFragmentType == FragmentsAvailable.CHATLIST || newFragmentType == FragmentsAvailable.HISTORY) { try { getSupportFragmentManager().popBackStackImmediate(null, FragmentManager.POP_BACK_STACK_INCLUSIVE); } catch (IllegalStateException e) { } } fragmentsHistory.add(currentFragment); }
From source file:org.openhab.habdroid.ui.OpenHABWidgetAdapter.java
@SuppressWarnings("deprecation") @Override/*from ww w.jav a2 s . c om*/ public View getView(int position, View convertView, ViewGroup parent) { /* TODO: This definitely needs some huge refactoring */ final RelativeLayout widgetView; TextView labelTextView; TextView valueTextView; int widgetLayout; String[] splitString; OpenHABWidget openHABWidget = getItem(position); int screenWidth = ((WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE)) .getDefaultDisplay().getWidth(); switch (this.getItemViewType(position)) { case TYPE_FRAME: widgetLayout = R.layout.openhabwidgetlist_frameitem; break; case TYPE_GROUP: widgetLayout = R.layout.openhabwidgetlist_groupitem; break; case TYPE_SECTIONSWITCH: widgetLayout = R.layout.openhabwidgetlist_sectionswitchitem; break; case TYPE_SWITCH: widgetLayout = R.layout.openhabwidgetlist_switchitem; break; case TYPE_ROLLERSHUTTER: widgetLayout = R.layout.openhabwidgetlist_rollershutteritem; break; case TYPE_TEXT: widgetLayout = R.layout.openhabwidgetlist_textitem; break; case TYPE_SLIDER: widgetLayout = R.layout.openhabwidgetlist_slideritem; break; case TYPE_IMAGE: widgetLayout = R.layout.openhabwidgetlist_imageitem; break; case TYPE_SELECTION: widgetLayout = R.layout.openhabwidgetlist_selectionitem; break; case TYPE_SETPOINT: widgetLayout = R.layout.openhabwidgetlist_setpointitem; break; case TYPE_CHART: widgetLayout = R.layout.openhabwidgetlist_chartitem; break; case TYPE_VIDEO: widgetLayout = R.layout.openhabwidgetlist_videoitem; break; case TYPE_VIDEO_MJPEG: widgetLayout = R.layout.openhabwidgetlist_videomjpegitem; break; case TYPE_WEB: widgetLayout = R.layout.openhabwidgetlist_webitem; break; case TYPE_COLOR: widgetLayout = R.layout.openhabwidgetlist_coloritem; break; default: widgetLayout = R.layout.openhabwidgetlist_genericitem; break; } if (convertView == null) { widgetView = new RelativeLayout(getContext()); String inflater = Context.LAYOUT_INFLATER_SERVICE; LayoutInflater vi; vi = (LayoutInflater) getContext().getSystemService(inflater); vi.inflate(widgetLayout, widgetView, true); } else { widgetView = (RelativeLayout) convertView; } // Process the colour attributes Integer iconColor = openHABWidget.getIconColor(); Integer labelColor = openHABWidget.getLabelColor(); Integer valueColor = openHABWidget.getValueColor(); // Process widgets icon image MySmartImageView widgetImage = (MySmartImageView) widgetView.findViewById(R.id.widgetimage); // Some of widgets, for example Frame doesnt' have an icon, so... if (widgetImage != null) { if (openHABWidget.getIcon() != null) { // This is needed to escape possible spaces and everything according to rfc2396 String iconUrl = openHABBaseUrl + "images/" + Uri.encode(openHABWidget.getIcon() + ".png"); // Log.d(TAG, "Will try to load icon from " + iconUrl); // Now set image URL widgetImage.setImageUrl(iconUrl, R.drawable.blank_icon, openHABUsername, openHABPassword); if (iconColor != null) widgetImage.setColorFilter(iconColor); else widgetImage.clearColorFilter(); } } TextView defaultTextView = new TextView(widgetView.getContext()); // Get TextView for widget label and set it's color labelTextView = (TextView) widgetView.findViewById(R.id.widgetlabel); // Change label color only for non-frame widgets if (labelColor != null && labelTextView != null && this.getItemViewType(position) != TYPE_FRAME) { Log.d(TAG, String.format("Setting label color to %d", labelColor)); labelTextView.setTextColor(labelColor); } else if (labelTextView != null && this.getItemViewType(position) != TYPE_FRAME) labelTextView.setTextColor(defaultTextView.getTextColors().getDefaultColor()); // Get TextView for widget value and set it's color valueTextView = (TextView) widgetView.findViewById(R.id.widgetvalue); if (valueColor != null && valueTextView != null) { Log.d(TAG, String.format("Setting value color to %d", valueColor)); valueTextView.setTextColor(valueColor); } else if (valueTextView != null) valueTextView.setTextColor(defaultTextView.getTextColors().getDefaultColor()); defaultTextView = null; switch (getItemViewType(position)) { case TYPE_FRAME: if (labelTextView != null) { labelTextView.setText(openHABWidget.getLabel()); if (valueColor != null) labelTextView.setTextColor(valueColor); } widgetView.setClickable(false); if (openHABWidget.getLabel().length() > 0) { // hide empty frames widgetView.setVisibility(View.VISIBLE); labelTextView.setVisibility(View.VISIBLE); } else { widgetView.setVisibility(View.GONE); labelTextView.setVisibility(View.GONE); } break; case TYPE_GROUP: if (labelTextView != null && valueTextView != null) { splitString = openHABWidget.getLabel().split("\\[|\\]"); labelTextView.setText(splitString[0]); if (splitString.length > 1) { // We have some value valueTextView.setText(splitString[1]); } else { // This is needed to clean up cached TextViews valueTextView.setText(""); } } break; case TYPE_SECTIONSWITCH: splitString = openHABWidget.getLabel().split("\\[|\\]"); if (labelTextView != null) labelTextView.setText(splitString[0]); if (splitString.length > 1 && valueTextView != null) { // We have some value valueTextView.setText(splitString[1]); } else { // This is needed to clean up cached TextViews valueTextView.setText(""); } RadioGroup sectionSwitchRadioGroup = (RadioGroup) widgetView.findViewById(R.id.sectionswitchradiogroup); // As we create buttons in this radio in runtime, we need to remove all // exiting buttons first sectionSwitchRadioGroup.removeAllViews(); sectionSwitchRadioGroup.setTag(openHABWidget); Iterator<OpenHABWidgetMapping> sectionMappingIterator = openHABWidget.getMappings().iterator(); while (sectionMappingIterator.hasNext()) { OpenHABWidgetMapping widgetMapping = sectionMappingIterator.next(); SegmentedControlButton segmentedControlButton = (SegmentedControlButton) LayoutInflater .from(sectionSwitchRadioGroup.getContext()) .inflate(R.layout.openhabwidgetlist_sectionswitchitem_button, sectionSwitchRadioGroup, false); segmentedControlButton.setText(widgetMapping.getLabel()); segmentedControlButton.setTag(widgetMapping.getCommand()); if (openHABWidget.getItem() != null && widgetMapping.getCommand() != null) { if (widgetMapping.getCommand().equals(openHABWidget.getItem().getState())) { segmentedControlButton.setChecked(true); } else { segmentedControlButton.setChecked(false); } } else { segmentedControlButton.setChecked(false); } segmentedControlButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { Log.i(TAG, "Button clicked"); RadioGroup group = (RadioGroup) view.getParent(); if (group.getTag() != null) { OpenHABWidget radioWidget = (OpenHABWidget) group.getTag(); SegmentedControlButton selectedButton = (SegmentedControlButton) view; if (selectedButton.getTag() != null) { sendItemCommand(radioWidget.getItem(), (String) selectedButton.getTag()); } } } }); sectionSwitchRadioGroup.addView(segmentedControlButton); } sectionSwitchRadioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() { public void onCheckedChanged(RadioGroup group, int checkedId) { OpenHABWidget radioWidget = (OpenHABWidget) group.getTag(); SegmentedControlButton selectedButton = (SegmentedControlButton) group.findViewById(checkedId); if (selectedButton != null) { Log.d(TAG, "Selected " + selectedButton.getText()); Log.d(TAG, "Command = " + (String) selectedButton.getTag()); // radioWidget.getItem().sendCommand((String)selectedButton.getTag()); sendItemCommand(radioWidget.getItem(), (String) selectedButton.getTag()); } } }); break; case TYPE_SWITCH: if (labelTextView != null) labelTextView.setText(openHABWidget.getLabel()); SwitchCompat switchSwitch = (SwitchCompat) widgetView.findViewById(R.id.switchswitch); if (openHABWidget.hasItem()) { if (openHABWidget.getItem().getStateAsBoolean()) { switchSwitch.setChecked(true); } else { switchSwitch.setChecked(false); } } switchSwitch.setTag(openHABWidget.getItem()); switchSwitch.setOnTouchListener(new OnTouchListener() { public boolean onTouch(View v, MotionEvent motionEvent) { SwitchCompat switchSwitch = (SwitchCompat) v; OpenHABItem linkedItem = (OpenHABItem) switchSwitch.getTag(); if (motionEvent.getActionMasked() == MotionEvent.ACTION_UP) if (!switchSwitch.isChecked()) { sendItemCommand(linkedItem, "ON"); } else { sendItemCommand(linkedItem, "OFF"); } return false; } }); break; case TYPE_COLOR: if (labelTextView != null) labelTextView.setText(openHABWidget.getLabel()); ImageButton colorUpButton = (ImageButton) widgetView.findViewById(R.id.colorbutton_up); ImageButton colorDownButton = (ImageButton) widgetView.findViewById(R.id.colorbutton_down); ImageButton colorColorButton = (ImageButton) widgetView.findViewById(R.id.colorbutton_color); colorUpButton.setTag(openHABWidget.getItem()); colorDownButton.setTag(openHABWidget.getItem()); colorColorButton.setTag(openHABWidget.getItem()); colorUpButton.setOnTouchListener(new OnTouchListener() { public boolean onTouch(View v, MotionEvent motionEvent) { ImageButton colorButton = (ImageButton) v; OpenHABItem colorItem = (OpenHABItem) colorButton.getTag(); if (motionEvent.getActionMasked() == MotionEvent.ACTION_UP) sendItemCommand(colorItem, "ON"); return false; } }); colorDownButton.setOnTouchListener(new OnTouchListener() { public boolean onTouch(View v, MotionEvent motionEvent) { ImageButton colorButton = (ImageButton) v; OpenHABItem colorItem = (OpenHABItem) colorButton.getTag(); if (motionEvent.getActionMasked() == MotionEvent.ACTION_UP) sendItemCommand(colorItem, "OFF"); return false; } }); colorColorButton.setOnTouchListener(new OnTouchListener() { public boolean onTouch(View v, MotionEvent motionEvent) { ImageButton colorButton = (ImageButton) v; OpenHABItem colorItem = (OpenHABItem) colorButton.getTag(); if (colorItem != null) { if (motionEvent.getActionMasked() == MotionEvent.ACTION_UP) { Log.d(TAG, "Time to launch color picker!"); ColorPickerDialog colorDialog = new ColorPickerDialog(widgetView.getContext(), new OnColorChangedListener() { public void colorChanged(float[] hsv, View v) { Log.d(TAG, "New color HSV = " + hsv[0] + ", " + hsv[1] + ", " + hsv[2]); String newColor = String.valueOf(hsv[0]) + "," + String.valueOf(hsv[1] * 100) + "," + String.valueOf(hsv[2] * 100); OpenHABItem colorItem = (OpenHABItem) v.getTag(); sendItemCommand(colorItem, newColor); } }, colorItem.getStateAsHSV()); colorDialog.setTag(colorItem); colorDialog.show(); } } return false; } }); break; case TYPE_ROLLERSHUTTER: if (labelTextView != null) labelTextView.setText(openHABWidget.getLabel()); ImageButton rollershutterUpButton = (ImageButton) widgetView.findViewById(R.id.rollershutterbutton_up); ImageButton rollershutterStopButton = (ImageButton) widgetView .findViewById(R.id.rollershutterbutton_stop); ImageButton rollershutterDownButton = (ImageButton) widgetView .findViewById(R.id.rollershutterbutton_down); rollershutterUpButton.setTag(openHABWidget.getItem()); rollershutterStopButton.setTag(openHABWidget.getItem()); rollershutterDownButton.setTag(openHABWidget.getItem()); rollershutterUpButton.setOnTouchListener(new OnTouchListener() { public boolean onTouch(View v, MotionEvent motionEvent) { ImageButton rollershutterButton = (ImageButton) v; OpenHABItem rollershutterItem = (OpenHABItem) rollershutterButton.getTag(); if (motionEvent.getActionMasked() == MotionEvent.ACTION_UP) sendItemCommand(rollershutterItem, "UP"); return false; } }); rollershutterStopButton.setOnTouchListener(new OnTouchListener() { public boolean onTouch(View v, MotionEvent motionEvent) { ImageButton rollershutterButton = (ImageButton) v; OpenHABItem rollershutterItem = (OpenHABItem) rollershutterButton.getTag(); if (motionEvent.getActionMasked() == MotionEvent.ACTION_UP) sendItemCommand(rollershutterItem, "STOP"); return false; } }); rollershutterDownButton.setOnTouchListener(new OnTouchListener() { public boolean onTouch(View v, MotionEvent motionEvent) { ImageButton rollershutterButton = (ImageButton) v; OpenHABItem rollershutterItem = (OpenHABItem) rollershutterButton.getTag(); if (motionEvent.getActionMasked() == MotionEvent.ACTION_UP) sendItemCommand(rollershutterItem, "DOWN"); return false; } }); break; case TYPE_TEXT: splitString = openHABWidget.getLabel().split("\\[|\\]"); if (labelTextView != null) if (splitString.length > 0) { labelTextView.setText(splitString[0]); } else { labelTextView.setText(openHABWidget.getLabel()); } if (valueTextView != null) if (splitString.length > 1) { // If value is not empty, show TextView valueTextView.setVisibility(View.VISIBLE); valueTextView.setText(splitString[1]); } else { // If value is empty, hide TextView to fix vertical alignment of label valueTextView.setVisibility(View.GONE); valueTextView.setText(""); } break; case TYPE_SLIDER: splitString = openHABWidget.getLabel().split("\\[|\\]"); if (labelTextView != null) labelTextView.setText(splitString[0]); SeekBar sliderSeekBar = (SeekBar) widgetView.findViewById(R.id.sliderseekbar); if (openHABWidget.hasItem()) { sliderSeekBar.setTag(openHABWidget.getItem()); sliderSeekBar.setProgress(openHABWidget.getItem().getStateAsFloat().intValue()); sliderSeekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() { public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { } public void onStartTrackingTouch(SeekBar seekBar) { Log.d(TAG, "onStartTrackingTouch position = " + seekBar.getProgress()); } public void onStopTrackingTouch(SeekBar seekBar) { Log.d(TAG, "onStopTrackingTouch position = " + seekBar.getProgress()); OpenHABItem sliderItem = (OpenHABItem) seekBar.getTag(); // sliderItem.sendCommand(String.valueOf(seekBar.getProgress())); if (sliderItem != null && seekBar != null) sendItemCommand(sliderItem, String.valueOf(seekBar.getProgress())); } }); if (volumeUpWidget == null) { volumeUpWidget = sliderSeekBar; volumeDownWidget = sliderSeekBar; } } break; case TYPE_IMAGE: MySmartImageView imageImage = (MySmartImageView) widgetView.findViewById(R.id.imageimage); imageImage.setImageUrl(ensureAbsoluteURL(openHABBaseUrl, openHABWidget.getUrl()), false, openHABUsername, openHABPassword); // ViewGroup.LayoutParams imageLayoutParams = imageImage.getLayoutParams(); // float imageRatio = imageImage.getDrawable().getIntrinsicWidth()/imageImage.getDrawable().getIntrinsicHeight(); // imageLayoutParams.height = (int) (screenWidth/imageRatio); // imageImage.setLayoutParams(imageLayoutParams); if (openHABWidget.getRefresh() > 0) { imageImage.setRefreshRate(openHABWidget.getRefresh()); refreshImageList.add(imageImage); } break; case TYPE_CHART: MySmartImageView chartImage = (MySmartImageView) widgetView.findViewById(R.id.chartimage); //Always clear the drawable so no images from recycled views appear chartImage.setImageDrawable(null); OpenHABItem chartItem = openHABWidget.getItem(); Random random = new Random(); String chartUrl = ""; if (chartItem != null) { if (chartItem.getType().equals("GroupItem")) { chartUrl = openHABBaseUrl + "chart?groups=" + chartItem.getName() + "&period=" + openHABWidget.getPeriod() + "&random=" + String.valueOf(random.nextInt()); } else { chartUrl = openHABBaseUrl + "chart?items=" + chartItem.getName() + "&period=" + openHABWidget.getPeriod() + "&random=" + String.valueOf(random.nextInt()); } if (openHABWidget.getService() != null && openHABWidget.getService().length() > 0) { chartUrl += "&service=" + openHABWidget.getService(); } } Log.d(TAG, "Chart url = " + chartUrl); if (chartImage == null) Log.e(TAG, "chartImage == null !!!"); ViewGroup.LayoutParams chartLayoutParams = chartImage.getLayoutParams(); chartLayoutParams.height = (int) (screenWidth / 2); chartImage.setLayoutParams(chartLayoutParams); chartUrl += "&w=" + String.valueOf(screenWidth); chartUrl += "&h=" + String.valueOf(screenWidth / 2); chartImage.setImageUrl(chartUrl, false, openHABUsername, openHABPassword); // TODO: This is quite dirty fix to make charts look full screen width on all displays if (openHABWidget.getRefresh() > 0) { chartImage.setRefreshRate(openHABWidget.getRefresh()); refreshImageList.add(chartImage); } Log.d(TAG, "chart size = " + chartLayoutParams.width + " " + chartLayoutParams.height); break; case TYPE_VIDEO: VideoView videoVideo = (VideoView) widgetView.findViewById(R.id.videovideo); Log.d(TAG, "Opening video at " + openHABWidget.getUrl()); // TODO: This is quite dirty fix to make video look maximum available size on all screens WindowManager wm = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE); ViewGroup.LayoutParams videoLayoutParams = videoVideo.getLayoutParams(); videoLayoutParams.height = (int) (wm.getDefaultDisplay().getWidth() / 1.77); videoVideo.setLayoutParams(videoLayoutParams); // We don't have any event handler to know if the VideoView is on the screen // so we manage an array of all videos to stop them when user leaves the page if (!videoWidgetList.contains(videoVideo)) videoWidgetList.add(videoVideo); // Start video if (!videoVideo.isPlaying()) { videoVideo.setVideoURI(Uri.parse(openHABWidget.getUrl())); videoVideo.start(); } Log.d(TAG, "Video height is " + videoVideo.getHeight()); break; case TYPE_VIDEO_MJPEG: Log.d(TAG, "Video is mjpeg"); ImageView mjpegImage = (ImageView) widgetView.findViewById(R.id.mjpegimage); MjpegStreamer mjpegStreamer = new MjpegStreamer(openHABWidget.getUrl(), this.openHABUsername, this.openHABPassword, this.getContext()); mjpegStreamer.setTargetImageView(mjpegImage); mjpegStreamer.start(); if (!mjpegWidgetList.contains(mjpegStreamer)) mjpegWidgetList.add(mjpegStreamer); break; case TYPE_WEB: WebView webWeb = (WebView) widgetView.findViewById(R.id.webweb); if (openHABWidget.getHeight() > 0) { ViewGroup.LayoutParams webLayoutParams = webWeb.getLayoutParams(); webLayoutParams.height = openHABWidget.getHeight() * 80; webWeb.setLayoutParams(webLayoutParams); } webWeb.setWebViewClient( new AnchorWebViewClient(openHABWidget.getUrl(), this.openHABUsername, this.openHABPassword)); webWeb.getSettings().setJavaScriptEnabled(true); webWeb.loadUrl(openHABWidget.getUrl()); break; case TYPE_SELECTION: int spinnerSelectedIndex = -1; if (labelTextView != null) labelTextView.setText(openHABWidget.getLabel()); final Spinner selectionSpinner = (Spinner) widgetView.findViewById(R.id.selectionspinner); selectionSpinner.setOnItemSelectedListener(null); ArrayList<String> spinnerArray = new ArrayList<String>(); Iterator<OpenHABWidgetMapping> mappingIterator = openHABWidget.getMappings().iterator(); while (mappingIterator.hasNext()) { OpenHABWidgetMapping openHABWidgetMapping = mappingIterator.next(); spinnerArray.add(openHABWidgetMapping.getLabel()); if (openHABWidgetMapping.getCommand() != null && openHABWidget.getItem() != null) if (openHABWidgetMapping.getCommand().equals(openHABWidget.getItem().getState())) { spinnerSelectedIndex = spinnerArray.size() - 1; } } ArrayAdapter<String> spinnerAdapter = new ArrayAdapter<String>(this.getContext(), android.R.layout.simple_spinner_item, spinnerArray); spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); selectionSpinner.setAdapter(spinnerAdapter); selectionSpinner.setTag(openHABWidget); if (spinnerSelectedIndex >= 0) { Log.d(TAG, "Setting spinner selected index to " + String.valueOf(spinnerSelectedIndex)); selectionSpinner.setSelection(spinnerSelectedIndex); } else { Log.d(TAG, "Not setting spinner selected index"); } selectionSpinner.post(new Runnable() { @Override public void run() { selectionSpinner.setOnItemSelectedListener(new OnItemSelectedListener() { public void onItemSelected(AdapterView<?> parent, View view, int index, long id) { Log.d(TAG, "Spinner item click on index " + index); Spinner spinner = (Spinner) parent; String selectedLabel = (String) spinner.getAdapter().getItem(index); Log.d(TAG, "Spinner onItemSelected selected label = " + selectedLabel); OpenHABWidget openHABWidget = (OpenHABWidget) parent.getTag(); if (openHABWidget != null) { Log.d(TAG, "Label selected = " + openHABWidget.getMapping(index).getLabel()); Iterator<OpenHABWidgetMapping> mappingIterator = openHABWidget.getMappings() .iterator(); while (mappingIterator.hasNext()) { OpenHABWidgetMapping openHABWidgetMapping = mappingIterator.next(); if (openHABWidgetMapping.getLabel().equals(selectedLabel)) { Log.d(TAG, "Spinner onItemSelected found match with " + openHABWidgetMapping.getCommand()); if (openHABWidget.getItem() != null && openHABWidget.getItem().getState() != null) { // Only send the command for selection of selected command will change the state if (!openHABWidget.getItem().getState() .equals(openHABWidgetMapping.getCommand())) { Log.d(TAG, "Spinner onItemSelected selected label command != current item state"); sendItemCommand(openHABWidget.getItem(), openHABWidgetMapping.getCommand()); } } else if (openHABWidget.getItem() != null && openHABWidget.getItem().getState() == null) { Log.d(TAG, "Spinner onItemSelected selected label command and state == null"); sendItemCommand(openHABWidget.getItem(), openHABWidgetMapping.getCommand()); } } } } // if (!openHABWidget.getItem().getState().equals(openHABWidget.getMapping(index).getCommand())) // sendItemCommand(openHABWidget.getItem(), // openHABWidget.getMapping(index).getCommand()); } public void onNothingSelected(AdapterView<?> arg0) { } }); } }); break; case TYPE_SETPOINT: splitString = openHABWidget.getLabel().split("\\[|\\]"); if (labelTextView != null) labelTextView.setText(splitString[0]); if (valueTextView != null) if (splitString.length > 1) { // If value is not empty, show TextView valueTextView.setVisibility(View.VISIBLE); valueTextView.setText(splitString[1]); } Button setPointMinusButton = (Button) widgetView.findViewById(R.id.setpointbutton_minus); Button setPointPlusButton = (Button) widgetView.findViewById(R.id.setpointbutton_plus); setPointMinusButton.setTag(openHABWidget); setPointPlusButton.setTag(openHABWidget); setPointMinusButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { Log.d(TAG, "Minus"); OpenHABWidget setPointWidget = (OpenHABWidget) v.getTag(); float currentValue = setPointWidget.getItem().getStateAsFloat(); currentValue = currentValue - setPointWidget.getStep(); if (currentValue < setPointWidget.getMinValue()) currentValue = setPointWidget.getMinValue(); if (currentValue > setPointWidget.getMaxValue()) currentValue = setPointWidget.getMaxValue(); sendItemCommand(setPointWidget.getItem(), String.valueOf(currentValue)); } }); setPointPlusButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { Log.d(TAG, "Plus"); OpenHABWidget setPointWidget = (OpenHABWidget) v.getTag(); float currentValue = setPointWidget.getItem().getStateAsFloat(); currentValue = currentValue + setPointWidget.getStep(); if (currentValue < setPointWidget.getMinValue()) currentValue = setPointWidget.getMinValue(); if (currentValue > setPointWidget.getMaxValue()) currentValue = setPointWidget.getMaxValue(); sendItemCommand(setPointWidget.getItem(), String.valueOf(currentValue)); } }); if (volumeUpWidget == null) { volumeUpWidget = setPointPlusButton; volumeDownWidget = setPointMinusButton; } break; default: if (labelTextView != null) labelTextView.setText(openHABWidget.getLabel()); break; } LinearLayout dividerLayout = (LinearLayout) widgetView.findViewById(R.id.listdivider); if (dividerLayout != null) { if (position < this.getCount() - 1) { if (this.getItemViewType(position + 1) == TYPE_FRAME) { dividerLayout.setVisibility(View.GONE); // hide dividers before frame widgets } else { dividerLayout.setVisibility(View.VISIBLE); // show dividers for all others } } else { // last widget in the list, hide divider dividerLayout.setVisibility(View.GONE); } } return widgetView; }
From source file:com.sim2dial.dialer.InCallActivity.java
private void displayOrHideContactPicture(LinearLayout callView, Uri pictureUri, boolean hide) { ImageView contactPicture = (ImageView) callView.findViewById(R.id.contactPicture); if (pictureUri != null) { LinphoneUtils.setImagePictureFromUri(callView.getContext(), contactPicture, Uri.parse(pictureUri.toString()), R.drawable.ic_contact); }/* w w w .j a v a 2 s .com*/ callView.setVisibility(hide ? View.GONE : View.VISIBLE); }
From source file:org.gateshipone.malp.application.views.NowPlayingView.java
private void setVolumeControlSetting() { SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(getContext()); String volumeControlView = sharedPref.getString(getContext().getString(R.string.pref_volume_controls_key), getContext().getString(R.string.pref_volume_control_view_default)); LinearLayout volLayout = (LinearLayout) findViewById(R.id.volume_control_layout); if (volumeControlView.equals(getContext().getString(R.string.pref_volume_control_view_off_key))) { if (volLayout != null) { volLayout.setVisibility(GONE); }/* ww w. ja v a 2 s .c om*/ mVolumeSeekbarLayout.setVisibility(GONE); mVolumeButtonLayout.setVisibility(GONE); } else if (volumeControlView .equals(getContext().getString(R.string.pref_volume_control_view_seekbar_key))) { if (volLayout != null) { volLayout.setVisibility(VISIBLE); } mVolumeSeekbarLayout.setVisibility(VISIBLE); mVolumeButtonLayout.setVisibility(GONE); } else if (volumeControlView .equals(getContext().getString(R.string.pref_volume_control_view_buttons_key))) { if (volLayout != null) { volLayout.setVisibility(VISIBLE); } mVolumeSeekbarLayout.setVisibility(GONE); mVolumeButtonLayout.setVisibility(VISIBLE); } }
From source file:com.praisehim.koraildelay.SwipeLibrary.SwipeListViewTouchListener.java
/** * Create reveal animation//from w ww .j a v a2 s .c o m * * @param view * affected view * @param swap * If will change state. If "false" returns to the original * position * @param swapRight * If swap is true, this parameter tells if movement is toward * right or left * @param position * list position */ @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) private void generateRevealAnimate(final View view, final boolean swap, final boolean swapRight, final int position) { TrainInfo thisTrain = Data.TRAINLIST.get(position); thisTrain.isOpen = !thisTrain.isOpen; if (thisTrain.isOpen) {////////////////// TextView trainRegistTextView = (TextView) backView.findViewById(R.id.trainRegistTextView); LinearLayout backViewContainer = (LinearLayout) backView.findViewById(R.id.backViewContainer); boolean canInstance = InterestTrain.canInterest(thisTrain); boolean isExist = false; if (canInstance) { Log.e("", " "); isExist = InterestTrain.isExist(thisTrain); if (!isExist) { InterestTrain.addInterest(thisTrain); trainRegistTextView.setText(" \n"); backViewContainer.setVisibility(View.VISIBLE); backView.setBackgroundColor(backView.getResources().getColor(android.R.color.holo_blue_light)); } else { InterestTrain.removeInterest(thisTrain); backViewContainer.setVisibility(View.GONE); backView.setBackgroundColor( backView.getResources().getColor(android.R.color.holo_orange_light)); trainRegistTextView.setText(" \n"); } } else { Log.e("", " "); trainRegistTextView.setText(" \n "); backViewContainer.setVisibility(View.GONE); backView.setBackgroundColor(backView.getResources().getColor(android.R.color.holo_orange_light)); } } //////////// if (Data.INTEREST_LIST != null) Log.e("", "" + Data.INTEREST_LIST.size()); // if(swapRight) // { // backView.setBackgroundColor(backView.getResources().getColor(android.R.color.holo_orange_light)); // } // else // { // backView.setBackgroundColor(backView.getResources().getColor(android.R.color.holo_blue_light)); // } int moveTo = 0; if (opened.get(position)) { if (!swap) { moveTo = openedRight.get(position) ? (int) (viewWidth - rightOffset) : (int) (-viewWidth + leftOffset); } } else { if (swap) { moveTo = swapRight ? (int) (viewWidth - rightOffset) : (int) (-viewWidth + leftOffset); } } animate(frontView).translationX(moveTo) .alpha(Math.max(0.3f, Math.min(1f, 1f - 2f * Math.abs(moveTo) / viewWidth))) .setDuration(animationTime).setListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { frontView.setAlpha(1); swipeListView.resetScrolling(); if (swap) { boolean aux = !opened.get(position); opened.set(position, aux); if (aux) { Log.e("animationTime", String.valueOf(animationTime)); animate(backView).alpha(1).setDuration(400); swipeListView.onOpened(position, swapRight); openedRight.set(position, swapRight); } else { backView.setAlpha(0); swipeListView.onClosed(position, openedRight.get(position)); } } resetCell(position); } }); }
From source file:com.farmerbb.taskbar.service.TaskbarService.java
@SuppressLint("RtlHardcoded") private void drawTaskbar() { IconCache.getInstance(this).clearCache(); // Initialize layout params windowManager = (WindowManager) getSystemService(WINDOW_SERVICE); U.setCachedRotation(windowManager.getDefaultDisplay().getRotation()); final WindowManager.LayoutParams params = new WindowManager.LayoutParams( WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.TYPE_PHONE, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM, PixelFormat.TRANSLUCENT);// w w w . ja v a 2s .c o m // Determine where to show the taskbar on screen switch (U.getTaskbarPosition(this)) { case "bottom_left": layoutId = R.layout.taskbar_left; params.gravity = Gravity.BOTTOM | Gravity.LEFT; positionIsVertical = false; break; case "bottom_vertical_left": layoutId = R.layout.taskbar_vertical; params.gravity = Gravity.BOTTOM | Gravity.LEFT; positionIsVertical = true; break; case "bottom_right": layoutId = R.layout.taskbar_right; params.gravity = Gravity.BOTTOM | Gravity.RIGHT; positionIsVertical = false; break; case "bottom_vertical_right": layoutId = R.layout.taskbar_vertical; params.gravity = Gravity.BOTTOM | Gravity.RIGHT; positionIsVertical = true; break; case "top_left": layoutId = R.layout.taskbar_left; params.gravity = Gravity.TOP | Gravity.LEFT; positionIsVertical = false; break; case "top_vertical_left": layoutId = R.layout.taskbar_top_vertical; params.gravity = Gravity.TOP | Gravity.LEFT; positionIsVertical = true; break; case "top_right": layoutId = R.layout.taskbar_right; params.gravity = Gravity.TOP | Gravity.RIGHT; positionIsVertical = false; break; case "top_vertical_right": layoutId = R.layout.taskbar_top_vertical; params.gravity = Gravity.TOP | Gravity.RIGHT; positionIsVertical = true; break; } // Initialize views int theme = 0; SharedPreferences pref = U.getSharedPreferences(this); switch (pref.getString("theme", "light")) { case "light": theme = R.style.AppTheme; break; case "dark": theme = R.style.AppTheme_Dark; break; } boolean altButtonConfig = pref.getBoolean("alt_button_config", false); ContextThemeWrapper wrapper = new ContextThemeWrapper(this, theme); layout = (LinearLayout) LayoutInflater.from(wrapper).inflate(layoutId, null); taskbar = (LinearLayout) layout.findViewById(R.id.taskbar); scrollView = (FrameLayout) layout.findViewById(R.id.taskbar_scrollview); if (altButtonConfig) { space = (Space) layout.findViewById(R.id.space_alt); layout.findViewById(R.id.space).setVisibility(View.GONE); } else { space = (Space) layout.findViewById(R.id.space); layout.findViewById(R.id.space_alt).setVisibility(View.GONE); } space.setOnClickListener(v -> toggleTaskbar()); startButton = (ImageView) layout.findViewById(R.id.start_button); int padding; if (pref.getBoolean("app_drawer_icon", false)) { startButton.setImageDrawable(ContextCompat.getDrawable(this, R.mipmap.ic_launcher)); padding = getResources().getDimensionPixelSize(R.dimen.app_drawer_icon_padding_alt); } else { startButton.setImageDrawable(ContextCompat.getDrawable(this, R.drawable.all_apps_button_icon)); padding = getResources().getDimensionPixelSize(R.dimen.app_drawer_icon_padding); } startButton.setPadding(padding, padding, padding, padding); startButton.setOnClickListener(ocl); startButton.setOnLongClickListener(view -> { openContextMenu(); return true; }); startButton.setOnGenericMotionListener((view, motionEvent) -> { if (motionEvent.getAction() == MotionEvent.ACTION_BUTTON_PRESS && motionEvent.getButtonState() == MotionEvent.BUTTON_SECONDARY) openContextMenu(); return false; }); refreshInterval = (int) (Float.parseFloat(pref.getString("refresh_frequency", "2")) * 1000); if (refreshInterval == 0) refreshInterval = 100; sortOrder = pref.getString("sort_order", "false"); runningAppsOnly = pref.getString("recents_amount", "past_day").equals("running_apps_only"); switch (pref.getString("recents_amount", "past_day")) { case "past_day": searchInterval = System.currentTimeMillis() - AlarmManager.INTERVAL_DAY; break; case "app_start": long oneDayAgo = System.currentTimeMillis() - AlarmManager.INTERVAL_DAY; long appStartTime = pref.getLong("time_of_service_start", System.currentTimeMillis()); long deviceStartTime = System.currentTimeMillis() - SystemClock.elapsedRealtime(); long startTime = deviceStartTime > appStartTime ? deviceStartTime : appStartTime; searchInterval = startTime > oneDayAgo ? startTime : oneDayAgo; break; } Intent intent = new Intent("com.farmerbb.taskbar.HIDE_START_MENU"); LocalBroadcastManager.getInstance(TaskbarService.this).sendBroadcast(intent); if (altButtonConfig) { button = (Button) layout.findViewById(R.id.hide_taskbar_button_alt); layout.findViewById(R.id.hide_taskbar_button).setVisibility(View.GONE); } else { button = (Button) layout.findViewById(R.id.hide_taskbar_button); layout.findViewById(R.id.hide_taskbar_button_alt).setVisibility(View.GONE); } try { button.setTypeface(Typeface.createFromFile("/system/fonts/Roboto-Regular.ttf")); } catch (RuntimeException e) { /* Gracefully fail */ } updateButton(false); button.setOnClickListener(v -> toggleTaskbar()); LinearLayout buttonLayout = (LinearLayout) layout.findViewById( altButtonConfig ? R.id.hide_taskbar_button_layout_alt : R.id.hide_taskbar_button_layout); if (buttonLayout != null) buttonLayout.setOnClickListener(v -> toggleTaskbar()); LinearLayout buttonLayoutToHide = (LinearLayout) layout.findViewById( altButtonConfig ? R.id.hide_taskbar_button_layout : R.id.hide_taskbar_button_layout_alt); if (buttonLayoutToHide != null) buttonLayoutToHide.setVisibility(View.GONE); int backgroundTint = U.getBackgroundTint(this); int accentColor = U.getAccentColor(this); dashboardButton = (FrameLayout) layout.findViewById(R.id.dashboard_button); navbarButtons = (LinearLayout) layout.findViewById(R.id.navbar_buttons); dashboardEnabled = pref.getBoolean("dashboard", false); if (dashboardEnabled) { layout.findViewById(R.id.square1).setBackgroundColor(accentColor); layout.findViewById(R.id.square2).setBackgroundColor(accentColor); layout.findViewById(R.id.square3).setBackgroundColor(accentColor); layout.findViewById(R.id.square4).setBackgroundColor(accentColor); layout.findViewById(R.id.square5).setBackgroundColor(accentColor); layout.findViewById(R.id.square6).setBackgroundColor(accentColor); dashboardButton.setOnClickListener(v -> LocalBroadcastManager.getInstance(TaskbarService.this) .sendBroadcast(new Intent("com.farmerbb.taskbar.TOGGLE_DASHBOARD"))); } else dashboardButton.setVisibility(View.GONE); if (pref.getBoolean("button_back", false)) { navbarButtonsEnabled = true; ImageView backButton = (ImageView) layout.findViewById(R.id.button_back); backButton.setVisibility(View.VISIBLE); backButton.setOnClickListener(v -> { U.sendAccessibilityAction(this, AccessibilityService.GLOBAL_ACTION_BACK); if (pref.getBoolean("hide_taskbar", true) && !FreeformHackHelper.getInstance().isInFreeformWorkspace()) hideTaskbar(true); }); } if (pref.getBoolean("button_home", false)) { navbarButtonsEnabled = true; ImageView homeButton = (ImageView) layout.findViewById(R.id.button_home); homeButton.setVisibility(View.VISIBLE); homeButton.setOnClickListener(v -> { U.sendAccessibilityAction(this, AccessibilityService.GLOBAL_ACTION_HOME); if (pref.getBoolean("hide_taskbar", true) && !FreeformHackHelper.getInstance().isInFreeformWorkspace()) hideTaskbar(true); }); homeButton.setOnLongClickListener(v -> { Intent voiceSearchIntent = new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE); voiceSearchIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); try { startActivity(voiceSearchIntent); } catch (ActivityNotFoundException e) { /* Gracefully fail */ } if (pref.getBoolean("hide_taskbar", true) && !FreeformHackHelper.getInstance().isInFreeformWorkspace()) hideTaskbar(true); return true; }); homeButton.setOnGenericMotionListener((view13, motionEvent) -> { if (motionEvent.getAction() == MotionEvent.ACTION_BUTTON_PRESS && motionEvent.getButtonState() == MotionEvent.BUTTON_SECONDARY) { Intent voiceSearchIntent = new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE); voiceSearchIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); try { startActivity(voiceSearchIntent); } catch (ActivityNotFoundException e) { /* Gracefully fail */ } if (pref.getBoolean("hide_taskbar", true) && !FreeformHackHelper.getInstance().isInFreeformWorkspace()) hideTaskbar(true); } return true; }); } if (pref.getBoolean("button_recents", false)) { navbarButtonsEnabled = true; ImageView recentsButton = (ImageView) layout.findViewById(R.id.button_recents); recentsButton.setVisibility(View.VISIBLE); recentsButton.setOnClickListener(v -> { U.sendAccessibilityAction(this, AccessibilityService.GLOBAL_ACTION_RECENTS); if (pref.getBoolean("hide_taskbar", true) && !FreeformHackHelper.getInstance().isInFreeformWorkspace()) hideTaskbar(true); }); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { recentsButton.setOnLongClickListener(v -> { U.sendAccessibilityAction(this, AccessibilityService.GLOBAL_ACTION_TOGGLE_SPLIT_SCREEN); if (pref.getBoolean("hide_taskbar", true) && !FreeformHackHelper.getInstance().isInFreeformWorkspace()) hideTaskbar(true); return true; }); recentsButton.setOnGenericMotionListener((view13, motionEvent) -> { if (motionEvent.getAction() == MotionEvent.ACTION_BUTTON_PRESS && motionEvent.getButtonState() == MotionEvent.BUTTON_SECONDARY) { U.sendAccessibilityAction(this, AccessibilityService.GLOBAL_ACTION_TOGGLE_SPLIT_SCREEN); if (pref.getBoolean("hide_taskbar", true) && !FreeformHackHelper.getInstance().isInFreeformWorkspace()) hideTaskbar(true); } return true; }); } } if (!navbarButtonsEnabled) navbarButtons.setVisibility(View.GONE); layout.setBackgroundColor(backgroundTint); layout.findViewById(R.id.divider).setBackgroundColor(accentColor); button.setTextColor(accentColor); if (isFirstStart && FreeformHackHelper.getInstance().isInFreeformWorkspace()) showTaskbar(false); else if (!pref.getBoolean("collapsed", false) && pref.getBoolean("taskbar_active", false)) toggleTaskbar(); LocalBroadcastManager.getInstance(this).unregisterReceiver(showReceiver); LocalBroadcastManager.getInstance(this).unregisterReceiver(hideReceiver); LocalBroadcastManager.getInstance(this).unregisterReceiver(tempShowReceiver); LocalBroadcastManager.getInstance(this).unregisterReceiver(tempHideReceiver); LocalBroadcastManager.getInstance(this).registerReceiver(showReceiver, new IntentFilter("com.farmerbb.taskbar.SHOW_TASKBAR")); LocalBroadcastManager.getInstance(this).registerReceiver(hideReceiver, new IntentFilter("com.farmerbb.taskbar.HIDE_TASKBAR")); LocalBroadcastManager.getInstance(this).registerReceiver(tempShowReceiver, new IntentFilter("com.farmerbb.taskbar.TEMP_SHOW_TASKBAR")); LocalBroadcastManager.getInstance(this).registerReceiver(tempHideReceiver, new IntentFilter("com.farmerbb.taskbar.TEMP_HIDE_TASKBAR")); startRefreshingRecents(); windowManager.addView(layout, params); isFirstStart = false; }