List of usage examples for android.view LayoutInflater from
public static LayoutInflater from(Context context)
From source file:com.abc.driver.MainActivity.java
public void initFHorders() { mFHorderLv = (PullToRefreshListView) findViewById(R.id.huoyun_lv); mFHorderLv.setMode(Mode.BOTH);//from w ww .ja v a 2s . c om mFHorderMore = (ViewGroup) LayoutInflater.from(MainActivity.this).inflate(R.layout.more_list, null); mFHorderMore.setVisibility(View.GONE); mFHolderMoreTv = (TextView) mFHorderMore.getChildAt(0); // mFHorderLv.addFooterView(mFHorderMore); mFHorderLv.setOnItemClickListener(mFHorderDetailListener); mFHorderLv.setAdapter(mFHorderTypes.nHorderAdapter); // Set a listener to be invoked when the list should be refreshed. mFHorderLv.setOnRefreshListener(new OnRefreshListener2<ListView>() { @Override public void onPullDownToRefresh(PullToRefreshBase<ListView> refreshView) { isForceRefreshFH = true; String label = DateUtils.formatDateTime(getApplicationContext(), System.currentTimeMillis(), DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_ABBREV_ALL); refreshView.getLoadingLayoutProxy().setLastUpdatedLabel(label);// // mHorderTypes[mCurrRadioIdx] = new HorderType(mCurrRadioIdx); mFHorderDownLoadTask = new FHorderDownLoadTask(); mFHorderDownLoadTask.execute(CellSiteConstants.NORMAL_OPERATION); } @Override public void onPullUpToRefresh(PullToRefreshBase<ListView> refreshView) { isForceRefreshFH = true; // mHorderTypes[mCurrRadioIdx] = new HorderType(mCurrRadioIdx); String label = DateUtils.formatDateTime(getApplicationContext(), System.currentTimeMillis(), DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_ABBREV_ALL); refreshView.getLoadingLayoutProxy().setLastUpdatedLabel(label);// mFHorderDownLoadTask = new FHorderDownLoadTask(); mFHorderDownLoadTask.execute(CellSiteConstants.NORMAL_OPERATION); } }); }
From source file:com.ximai.savingsmore.save.activity.AddGoodsAcitivyt.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.add_good_activity); setCenterTitle("?"); setLeftBackMenuVisibility(AddGoodsAcitivyt.this, ""); head_view = (ImageView) findViewById(R.id.head_image); my_name = (TextView) findViewById(R.id.name); MyImageLoader.displayDefaultImage(URLText.img_url + MyUserInfoUtils.getInstance().myUserInfo.PhotoPath, head_view);//from w w w . j a v a2 s . c o m if (null != MyUserInfoUtils.getInstance().myUserInfo.UserExtInfo) { my_name.setText(MyUserInfoUtils.getInstance().myUserInfo.UserExtInfo.StoreName); } cuxiaoshuoming = (TextView) findViewById(R.id.cuxiaoshuoming); shangpingmiaoshu = (TextView) findViewById(R.id.shangpingmiaoshu); horizontalListView = (HorizontalListView) findViewById(R.id.myGridview); yijifenlei = (TextView) findViewById(R.id.one_classity); erjifenlei = (TextView) findViewById(R.id.two_classity); brand = (TextView) findViewById(R.id.brand_name); xingshi_item = (LinearLayout) findViewById(R.id.xingshi_item); xingshi = (TextView) findViewById(R.id.xingshi); yuanyin_item = (LinearLayout) findViewById(R.id.yuanyin_item); yuanyin = (TextView) findViewById(R.id.yuanyin); dizhi_item = (LinearLayout) findViewById(R.id.dizhi_item); dizhi = (TextView) findViewById(R.id.dizhi); satrt_item = (LinearLayout) findViewById(R.id.start_time_item); start = (TextView) findViewById(R.id.start_time); end_item = (LinearLayout) findViewById(R.id.end_time_item); end = (TextView) findViewById(R.id.end_time); danwei_item = (LinearLayout) findViewById(R.id.danwei_item); danwei = (TextView) findViewById(R.id.danwei); bizhong_item = (LinearLayout) findViewById(R.id.bizhong_item); bizhong = (TextView) findViewById(R.id.bizhong); fapiao_item = (LinearLayout) findViewById(R.id.fapiao_item); fapiao = (TextView) findViewById(R.id.fapiao); yuan_price = (EditText) findViewById(R.id.yuan_price); cuxiao_price = (EditText) findViewById(R.id.cuxiao_price); cuxiao_text = (TextView) findViewById(R.id.cuxiao_text); fabu = (TextView) findViewById(R.id.fabu); product_bianhao = (EditText) findViewById(R.id.product_bianhao); product_name = (EditText) findViewById(R.id.product_name); xiangxi_address = (EditText) findViewById(R.id.xiangxi_address); servise = (TextView) findViewById(R.id.servise); servise.setOnClickListener(this); fabu.setOnClickListener(this); yijifenlei.setOnClickListener(this); erjifenlei.setOnClickListener(this); brand.setOnClickListener(this); xingshi_item.setOnClickListener(this); yuanyin_item.setOnClickListener(this); dizhi_item.setOnClickListener(this); satrt_item.setOnClickListener(this); end_item.setOnClickListener(this); danwei_item.setOnClickListener(this); bizhong_item.setOnClickListener(this); fapiao_item.setOnClickListener(this); yuan_price.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } @Override public void afterTextChanged(Editable s) { if (null != xingshi_id) { if (xingshi_id.equals("2") || xingshi_id.equals("3") || xingshi_id.equals("7") || xingshi_id.equals("12")) { cuxiao_price.setText(s.toString()); } } } }); myAdapter = new MyAdapter(); horizontalListView.setAdapter(myAdapter); queryDicNode(); queryDicNode2(); explain = (EditText) findViewById(R.id.explain); descript = (EditText) findViewById(R.id.decript); shuoming_number = explain.getText().length(); miaoshu_number = descript.getText().length(); explain.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { shuoming_number = explain.getText().length(); cuxiaoshuoming.setText("(?" + (200 - shuoming_number) + ")"); } @Override public void afterTextChanged(Editable s) { } }); descript.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { miaoshu_number = descript.getText().length(); shangpingmiaoshu.setText("???(?" + (200 - miaoshu_number) + ")"); } @Override public void afterTextChanged(Editable s) { } }); zidingyi_brand = (TextView) findViewById(R.id.zidingyi_brand); custom_type = (TextView) findViewById(R.id.custom_type); zidingyi_brand.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { classity_dialog = new AlertDialog.Builder(AddGoodsAcitivyt.this).create(); View view = LayoutInflater.from(AddGoodsAcitivyt.this).inflate(R.layout.save_brand, null); final TextView queding, quxiao; final EditText content; queding = (TextView) view.findViewById(R.id.comfirm); quxiao = (TextView) view.findViewById(R.id.cannel); content = (EditText) view.findViewById(R.id.content); queding.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (null != content.getText() && !TextUtils.isEmpty(content.getText())) { save_brand(content.getText().toString()); } } }); quxiao.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { classity_dialog.dismiss(); } }); classity_dialog.setView(view); classity_dialog.show(); } }); custom_type.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (oneId != null && !TextUtils.isEmpty(oneId)) { brand_dialog = new AlertDialog.Builder(AddGoodsAcitivyt.this).create(); View view = LayoutInflater.from(AddGoodsAcitivyt.this).inflate(R.layout.custom_classfy, null); final TextView queding, quxiao; final EditText content; queding = (TextView) view.findViewById(R.id.comfirm); quxiao = (TextView) view.findViewById(R.id.cannel); content = (EditText) view.findViewById(R.id.content); queding.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (null != content.getText() && !TextUtils.isEmpty(content.getText())) { apply_calssity(content.getText().toString(), oneId); } } }); quxiao.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { brand_dialog.dismiss(); } }); brand_dialog.setView(view); brand_dialog.show(); } else { Toast.makeText(AddGoodsAcitivyt.this, "", Toast.LENGTH_SHORT).show(); } } }); cuxiao_price.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (cuxiao_text.getText().equals("N?N")) { bug_dialog = new AlertDialog.Builder(AddGoodsAcitivyt.this).create(); View view = LayoutInflater.from(AddGoodsAcitivyt.this).inflate(R.layout.bug_give, null); final TextView queding, quxiao; final EditText number1, number2; queding = (TextView) view.findViewById(R.id.comfirm); quxiao = (TextView) view.findViewById(R.id.cannel); number1 = (EditText) view.findViewById(R.id.number1); number2 = (EditText) view.findViewById(R.id.number2); queding.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (null != number1.getText() && !TextUtils.isEmpty(number1.getText()) && null != number2.getText() && !TextUtils.isEmpty(number2.getText())) { cuxiao_price.setText("" + number1.getText().toString() + "?" + number2.getText().toString()); bug_dialog.dismiss(); } } }); quxiao.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { bug_dialog.dismiss(); } }); bug_dialog.setView(view); bug_dialog.show(); } } }); myProduct = new MyProduct(); if (null != getIntent().getStringExtra("id")) { Id = getIntent().getStringExtra("id"); getgood_detial(Id); } }
From source file:com.watch.customer.ui.ShopListActivity.java
@SuppressWarnings("deprecation") private void showSectionPop(int width, int height, final int secindex) { layout = (LinearLayout) LayoutInflater.from(ShopListActivity.this).inflate(R.layout.popup_category, null); section_list = (ListView) layout.findViewById(R.id.section_list); section_grid = (GridView) layout.findViewById(R.id.section_grid); section_list.setOnItemClickListener(this); section_grid.setOnItemClickListener(this); if (secindex == 1) {// 2grid section_grid.setVisibility(View.VISIBLE); section_list.setVisibility(View.GONE); secAdapter = new SectionAdapter(ShopListActivity.this, secArr2, selectPos[secindex], secindex); section_grid.setAdapter(secAdapter); } else {// ww w.j a v a 2 s . c o m section_grid.setVisibility(View.GONE); section_list.setVisibility(View.VISIBLE); if (secindex == 0) { secAdapter = new SectionAdapter(ShopListActivity.this, secArr1, selectPos[secindex], secindex); } else { secAdapter = new SectionAdapter(ShopListActivity.this, secArr3, selectPos[secindex], secindex); } section_list.setAdapter(secAdapter); } mPopWin = new PopupWindow(layout, width, LayoutParams.WRAP_CONTENT, true); mPopWin.setOnDismissListener(new OnDismissListener() { @Override public void onDismiss() { // TODO Auto-generated method stub selectSecCheck(4); } }); mPopWin.setBackgroundDrawable(new BitmapDrawable()); mPopWin.showAsDropDown(text1, 0, 0); mPopWin.update(); }
From source file:android.support.v7.app.AppCompatDelegateImplV7.java
private void ensureSubDecor() { if (!mSubDecorInstalled) { final LayoutInflater inflater = LayoutInflater.from(mContext); if (!mWindowNoTitle) { if (mIsFloating) { // If we're floating, inflate the dialog title decor mSubDecor = (ViewGroup) inflater.inflate(R.layout.abc_dialog_title_material, null); } else if (mHasActionBar) { /**/*from w w w .j a v a 2 s. com*/ * This needs some explanation. As we can not use the android:theme attribute * pre-L, we emulate it by manually creating a LayoutInflater using a * ContextThemeWrapper pointing to actionBarTheme. */ TypedValue outValue = new TypedValue(); mContext.getTheme().resolveAttribute(R.attr.actionBarTheme, outValue, true); Context themedContext; if (outValue.resourceId != 0) { themedContext = new ContextThemeWrapper(mContext, outValue.resourceId); } else { themedContext = mContext; } // Now inflate the view using the themed context and set it as the content view mSubDecor = (ViewGroup) LayoutInflater.from(themedContext).inflate(R.layout.abc_screen_toolbar, null); mDecorContentParent = (DecorContentParent) mSubDecor.findViewById(R.id.decor_content_parent); mDecorContentParent.setWindowCallback(getWindowCallback()); /** * Propagate features to DecorContentParent */ if (mOverlayActionBar) { mDecorContentParent.initFeature(FEATURE_ACTION_BAR_OVERLAY); } if (mFeatureProgress) { mDecorContentParent.initFeature(Window.FEATURE_PROGRESS); } if (mFeatureIndeterminateProgress) { mDecorContentParent.initFeature(Window.FEATURE_INDETERMINATE_PROGRESS); } } } else { if (mOverlayActionMode) { mSubDecor = (ViewGroup) inflater.inflate(R.layout.abc_screen_simple_overlay_action_mode, null); } else { mSubDecor = (ViewGroup) inflater.inflate(R.layout.abc_screen_simple, null); } if (Build.VERSION.SDK_INT >= 21) { // If we're running on L or above, we can rely on ViewCompat's // setOnApplyWindowInsetsListener ViewCompat.setOnApplyWindowInsetsListener(mSubDecor, new OnApplyWindowInsetsListener() { @Override public WindowInsetsCompat onApplyWindowInsets(View v, WindowInsetsCompat insets) { final int top = insets.getSystemWindowInsetTop(); final int newTop = updateStatusGuard(top); if (top != newTop) { insets = insets.replaceSystemWindowInsets(insets.getSystemWindowInsetLeft(), newTop, insets.getSystemWindowInsetRight(), insets.getSystemWindowInsetBottom()); } // Now apply the insets on our view return ViewCompat.onApplyWindowInsets(v, insets); } }); } else { // Else, we need to use our own FitWindowsViewGroup handling ((FitWindowsViewGroup) mSubDecor) .setOnFitSystemWindowsListener(new FitWindowsViewGroup.OnFitSystemWindowsListener() { @Override public void onFitSystemWindows(Rect insets) { insets.top = updateStatusGuard(insets.top); } }); } } if (mSubDecor == null) { throw new IllegalArgumentException("AppCompat does not support the current theme features"); } if (mDecorContentParent == null) { mTitleView = (TextView) mSubDecor.findViewById(R.id.title); } // Make the decor optionally fit system windows, like the window's decor ViewUtils.makeOptionalFitsSystemWindows(mSubDecor); final ViewGroup decorContent = (ViewGroup) mWindow.findViewById(android.R.id.content); final ViewGroup abcContent = (ViewGroup) mSubDecor.findViewById(R.id.action_bar_activity_content); // There might be Views already added to the Window's content view so we need to // migrate them to our content view while (decorContent.getChildCount() > 0) { final View child = decorContent.getChildAt(0); decorContent.removeViewAt(0); abcContent.addView(child); } // Now set the Window's content view with the decor mWindow.setContentView(mSubDecor); // Change our content FrameLayout to use the android.R.id.content id. // Useful for fragments. decorContent.setId(View.NO_ID); abcContent.setId(android.R.id.content); // The decorContent may have a foreground drawable set (windowContentOverlay). // Remove this as we handle it ourselves if (decorContent instanceof FrameLayout) { ((FrameLayout) decorContent).setForeground(null); } // If a title was set before we installed the decor, propogate it now CharSequence title = getTitle(); if (!TextUtils.isEmpty(title)) { onTitleChanged(title); } applyFixedSizeWindow(); onSubDecorInstalled(mSubDecor); mSubDecorInstalled = true; // Invalidate if the panel menu hasn't been created before this. // Panel menu invalidation is deferred avoiding application onCreateOptionsMenu // being called in the middle of onCreate or similar. // A pending invalidation will typically be resolved before the posted message // would run normally in order to satisfy instance state restoration. PanelFeatureState st = getPanelState(FEATURE_OPTIONS_PANEL, false); if (!isDestroyed() && (st == null || st.menu == null)) { invalidatePanelMenu(FEATURE_ACTION_BAR); } } }
From source file:com.cypress.cysmart.RDKEmulatorView.MicrophoneEmulatorFragment.java
/** * Method to display a custom alert./*from www .j a v a 2s .co m*/ * Option for entering the google key in the method for voice to * text conversion */ private void showCustumAlert(String storedKey, boolean changeNeeded) { LayoutInflater li = LayoutInflater.from(getActivity()); View promptsView = li.inflate(R.layout.api_key_dialog_alert, null); AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(getActivity()); // set api_key_dialog_alert.xml to alertdialog builder alertDialogBuilder.setView(promptsView); //User input Edittext final EditText userInput = (EditText) promptsView.findViewById(R.id.custom_alert_user_input); if (changeNeeded) { userInput.setText(storedKey); } // set dialog message alertDialogBuilder.setCancelable(false).setPositiveButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // get user input and set it to sharedpreferecne Logger.i("userInput.getText()--->" + userInput.getText()); Utils.setStringSharedPreference(getActivity(), Constants.PREF_GOOGLE_API_KEY, userInput.getText().toString()); } }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); // create alert dialog AlertDialog alertDialog = alertDialogBuilder.create(); // show it alertDialog.show(); }
From source file:app.wz.MainActivity.java
public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); if (id == R.id.menu_run_pause) { if (neuro.halt) { neuro.halt = false;/*www .j a v a 2 s.c om*/ setProgressBarIndeterminateVisibility(true); wakeLock.acquire(); if (prefs.getBoolean("use_server", false)) lock.acquire(); // for the system's orientation sensor registered listeners mSensorManager.registerListener(this, mSensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION), SensorManager.SENSOR_DELAY_GAME); synchronized (neuro) { neuro.notify(); } } else { haltNeuro(); } } else { if (!neuro.halt) { haltNeuro(); } } if (id == R.id.menu_device_connect) { bt.setDeviceTarget(BluetoothState.DEVICE_OTHER); /* if(bt.getServiceState() == BluetoothState.STATE_CONNECTED) bt.disconnect();*/ Intent intent = new Intent(getApplicationContext(), DeviceList.class); startActivityForResult(intent, BluetoothState.REQUEST_CONNECT_DEVICE); } else if (id == R.id.reset_Neuro) { neuro.updatePrefs(true); textRead.append("Reset Neuro \n"); textScroll.fullScroll(View.FOCUS_DOWN); } else if (id == R.id.menu_disconnect) { if (bt.getServiceState() == BluetoothState.STATE_CONNECTED) bt.disconnect(); } else if (id == R.id.remote_control) { if (bt.getServiceState() == BluetoothState.STATE_CONNECTED) { Intent intent = new Intent(this, JoystickActivity.class); startActivity(intent); } else { Toast.makeText(getApplicationContext(), "Not Connected", Toast.LENGTH_SHORT).show(); } return true; } else if (id == R.id.action_settings) { Intent intent = new Intent(this, SettingsActivity.class); startActivity(intent); return true; } else if (id == R.id.help) { LayoutInflater li = LayoutInflater.from(this); View view = li.inflate(R.layout.help, null); AlertDialog.Builder alert = new AlertDialog.Builder(this); alert.setView(view); alert.show(); } return super.onOptionsItemSelected(item); }
From source file:ca.ualberta.cs.unter.view.DriverSearchRequestActivity.java
/** * A dialog that allow user to filter the request *//*w ww .j av a 2 s . co m*/ private void openFilterRequestDialog() { AlertDialog.Builder builder = new AlertDialog.Builder(DriverSearchRequestActivity.this); LayoutInflater layoutInflater = LayoutInflater.from(this); View promptView = layoutInflater.inflate(R.layout.driver_filter_request_dialog, null); RangeBar priceRangeBar = (RangeBar) promptView .findViewById(R.id.rangebar__priceRange_DriverSearchRequestActivity); priceRangeBar.setTickStart(0); priceRangeBar.setTickEnd(300); priceRangeBar.setTickInterval(300 / 100.0f); // Sets the display values of the indices priceRangeBar.setOnRangeBarChangeListener(new RangeBar.OnRangeBarChangeListener() { @Override public void onRangeChangeListener(RangeBar rangeBar, int leftPinIndex, int rightPinIndex, String leftPinValue, String rightPinValue) { // use priceRangeMin, priceRangeMax later for filtering search result priceRangeMin = Float.parseFloat(leftPinValue); priceRangeMax = Float.parseFloat(rightPinValue); } }); RangeBar pricePerKMRangeBar = (RangeBar) promptView .findViewById(R.id.rangebar_priceperkmrange_driversearchrequestactivity); pricePerKMRangeBar.setTickStart(0); pricePerKMRangeBar.setTickEnd(10); pricePerKMRangeBar.setTickInterval(10 / 20.0f); // Sets the display values of the indices pricePerKMRangeBar.setOnRangeBarChangeListener(new RangeBar.OnRangeBarChangeListener() { @Override public void onRangeChangeListener(RangeBar rangeBar, int leftPinIndex, int rightPinIndex, String leftPinValue, String rightPinValue) { // use pricePerKMRangeMin, pricePerKMRangeMin later for filtering search result pricePerKMRangeMin = Float.parseFloat(leftPinValue); pricePerKMRangeMax = Float.parseFloat(rightPinValue); } }); builder.setTitle("Filter Request").setView(promptView) .setPositiveButton(R.string.dialog_ok_button, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { filterRequestList(priceRangeMin, priceRangeMax, pricePerKMRangeMin, pricePerKMRangeMax); } }).setNegativeButton(R.string.dialog_cancel_button, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }); // Create & Show the FilterDialog AlertDialog dialog = builder.create(); dialog.show(); }
From source file:com.actionbarsherlock.internal.app.ActionBarImpl.java
@Override public void setCustomView(int resId) { setCustomView(LayoutInflater.from(getThemedContext()).inflate(resId, mActionView, false)); }
From source file:android.support.v7ox.widget.SearchView.java
public SearchView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); mDrawableManager = AppCompatDrawableManager.get(); final TintTypedArray a = TintTypedArray.obtainStyledAttributes(context, attrs, R.styleable.SearchView, defStyleAttr, 0);// w w w . jav a 2 s . c o m final LayoutInflater inflater = LayoutInflater.from(context); final int layoutResId = a.getResourceId(R.styleable.SearchView_layout, R.layout.abc_search_view); inflater.inflate(layoutResId, this, true); mSearchSrcTextView = (SearchAutoComplete) findViewById(R.id.search_src_text); mSearchSrcTextView.setSearchView(this); mSearchEditFrame = findViewById(R.id.search_edit_frame); mSearchPlate = findViewById(R.id.search_plate); mSubmitArea = findViewById(R.id.submit_area); mSearchButton = (ImageView) findViewById(R.id.search_button); mGoButton = (ImageView) findViewById(R.id.search_go_btn); mCloseButton = (ImageView) findViewById(R.id.search_close_btn); mVoiceButton = (ImageView) findViewById(R.id.search_voice_btn); mCollapsedIcon = (ImageView) findViewById(R.id.search_mag_icon); // Set up icons and backgrounds. mSearchPlate.setBackgroundDrawable(a.getDrawable(R.styleable.SearchView_queryBackground)); mSubmitArea.setBackgroundDrawable(a.getDrawable(R.styleable.SearchView_submitBackground)); mSearchButton.setImageDrawable(a.getDrawable(R.styleable.SearchView_searchIcon)); mGoButton.setImageDrawable(a.getDrawable(R.styleable.SearchView_goIcon)); mCloseButton.setImageDrawable(a.getDrawable(R.styleable.SearchView_closeIcon)); mVoiceButton.setImageDrawable(a.getDrawable(R.styleable.SearchView_voiceIcon)); mCollapsedIcon.setImageDrawable(a.getDrawable(R.styleable.SearchView_searchIcon)); mSearchHintIcon = a.getDrawable(R.styleable.SearchView_searchHintIcon); // Extract dropdown layout resource IDs for later use. mSuggestionRowLayout = a.getResourceId(R.styleable.SearchView_suggestionRowLayout, R.layout.abc_search_dropdown_item_icons_2line); mSuggestionCommitIconResId = a.getResourceId(R.styleable.SearchView_commitIcon, 0); mSearchButton.setOnClickListener(mOnClickListener); mCloseButton.setOnClickListener(mOnClickListener); mGoButton.setOnClickListener(mOnClickListener); mVoiceButton.setOnClickListener(mOnClickListener); mSearchSrcTextView.setOnClickListener(mOnClickListener); mSearchSrcTextView.addTextChangedListener(mTextWatcher); mSearchSrcTextView.setOnEditorActionListener(mOnEditorActionListener); mSearchSrcTextView.setOnItemClickListener(mOnItemClickListener); mSearchSrcTextView.setOnItemSelectedListener(mOnItemSelectedListener); mSearchSrcTextView.setOnKeyListener(mTextKeyListener); // Inform any listener of focus changes mSearchSrcTextView.setOnFocusChangeListener(new OnFocusChangeListener() { public void onFocusChange(View v, boolean hasFocus) { if (mOnQueryTextFocusChangeListener != null) { mOnQueryTextFocusChangeListener.onFocusChange(SearchView.this, hasFocus); } } }); setIconifiedByDefault(a.getBoolean(R.styleable.SearchView_iconifiedByDefault, true)); final int maxWidth = a.getDimensionPixelSize(R.styleable.SearchView_android_maxWidth, -1); if (maxWidth != -1) { setMaxWidth(maxWidth); } mDefaultQueryHint = a.getText(R.styleable.SearchView_defaultQueryHint); mQueryHint = a.getText(R.styleable.SearchView_queryHint); final int imeOptions = a.getInt(R.styleable.SearchView_android_imeOptions, -1); if (imeOptions != -1) { setImeOptions(imeOptions); } final int inputType = a.getInt(R.styleable.SearchView_android_inputType, -1); if (inputType != -1) { setInputType(inputType); } boolean focusable = true; focusable = a.getBoolean(R.styleable.SearchView_android_focusable, focusable); setFocusable(focusable); a.recycle(); // Save voice intent for later queries/launching mVoiceWebSearchIntent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH); mVoiceWebSearchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); mVoiceWebSearchIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_WEB_SEARCH); mVoiceAppSearchIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); mVoiceAppSearchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); mDropDownAnchor = findViewById(mSearchSrcTextView.getDropDownAnchor()); if (mDropDownAnchor != null) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { addOnLayoutChangeListenerToDropDownAnchorSDK11(); } else { addOnLayoutChangeListenerToDropDownAnchorBase(); } } updateViewsVisibility(mIconifiedByDefault); updateQueryHint(); }
From source file:com.code.android.vibevault.SearchScreen.java
private void launchSettingsDialog() { final SeekBar seek; final Spinner sortSpin; final Spinner searchSpin; final TextView seekValue; // Make the settings dialog. AlertDialog.Builder ad = new AlertDialog.Builder(this); ad.setTitle("Search Settings"); View v = LayoutInflater.from(this).inflate(R.layout.scrollable_settings_dialog, null); ad.setPositiveButton("Okay.", new android.content.DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int arg1) { }/*from w w w .jav a 2s . c o m*/ }); // Grab all the GUI widgets. seek = (SeekBar) v.findViewById(R.id.NumResultsSeekBar); seek.setProgress(Integer.valueOf(VibeVault.db.getPref("numResults")) - 10); sortSpin = (Spinner) v.findViewById(R.id.SortSpinner); searchSpin = (Spinner) v.findViewById(R.id.SearchSpinner); seekValue = (TextView) v.findViewById(R.id.SeekBarValue); seekValue.setText(VibeVault.db.getPref("numResults")); // Set the seek bar to its current value, and set up a Listener. seek.setOnSeekBarChangeListener(new OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { seekValue.setText(String.valueOf(progress + 10)); VibeVault.db.updatePref("numResults", String.valueOf(progress + 10)); } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onStopTrackingTouch(SeekBar seekBar) { } }); // Set up the spinner, and set up it's OnItemSelectedListener. ArrayAdapter<String> sortAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, VibeVault.sortChoices); sortAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); sortSpin.setAdapter(sortAdapter); int sortPos = 1; String sortOrder = VibeVault.db.getPref("sortOrder"); for (int i = 0; i < VibeVault.sortChoices.length; i++) { if (VibeVault.sortChoices[i].equals(sortOrder)) sortPos = i; } sortSpin.setSelection(sortPos); sortSpin.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> arg0, View view, int arg2, long arg3) { int selected = arg0.getSelectedItemPosition(); VibeVault.db.updatePref("sortOrder", VibeVault.sortChoices[selected]); } @Override public void onNothingSelected(AdapterView<?> arg0) { } }); ArrayAdapter<String> searchAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, VibeVault.searchChoices); searchAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); searchSpin.setAdapter(searchAdapter); int searchPos = 1; String searchOrder = VibeVault.searchPref; for (int i = 0; i < VibeVault.searchChoices.length; i++) { if (VibeVault.searchChoices[i].equals(searchOrder)) searchPos = i; } searchSpin.setSelection(searchPos); searchSpin.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> arg0, View view, int arg2, long arg3) { int selected = arg0.getSelectedItemPosition(); VibeVault.searchPref = VibeVault.searchChoices[selected]; if (VibeVault.searchPref.equals("Artist") && artistSearchInput.getText().equals("")) { artistSearchInput.setHint("Search Artists..."); } else if (VibeVault.searchPref.equals("Show/Artist Description") && artistSearchInput.getText().equals("")) { artistSearchInput.setHint("Search Descriptions..."); } } @Override public void onNothingSelected(AdapterView<?> arg0) { } }); // Show the settings screen. ad.setView(v); ad.show(); }