List of usage examples for android.widget LinearLayout VERTICAL
int VERTICAL
To view the source code for android.widget LinearLayout VERTICAL.
Click Source Link
From source file:com.java2s.intents4.IntentsDemo4Activity.java
void addRow(final LinearLayout layout, String label, String hintStr, boolean addRadioGroup) { LinearLayout.LayoutParams rowLayoutParams = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); LinearLayout.LayoutParams editTextLayoutParams = new LinearLayout.LayoutParams(400, LinearLayout.LayoutParams.WRAP_CONTENT, 1); if (addRadioGroup) { editTextLayoutParams = new LinearLayout.LayoutParams(400, LinearLayout.LayoutParams.WRAP_CONTENT, 1); }/* w ww . ja v a 2s. co m*/ LinearLayout.LayoutParams buttonLayoutParams = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT, 0); LinearLayout row = new LinearLayout(this); row.setOrientation(LinearLayout.HORIZONTAL); row.setGravity(Gravity.CENTER_VERTICAL); TextView textView = new TextView(this); textView.setText(label); row.addView(textView); EditText editText = new EditText(this); editText.setTextSize(TypedValue.COMPLEX_UNIT_SP, 12); editText.setHint(hintStr); editText.setLayoutParams(editTextLayoutParams); if (!isFirstTime) { editText.requestFocus(); } row.addView(editText); if (addRadioGroup) { LinearLayout groupLayout = new LinearLayout(this); groupLayout.setOrientation(LinearLayout.VERTICAL); groupLayout.setGravity(Gravity.CENTER_HORIZONTAL); RadioGroup group = new RadioGroup(this); group.setLayoutParams(new RadioGroup.LayoutParams(RadioGroup.LayoutParams.WRAP_CONTENT, RadioGroup.LayoutParams.WRAP_CONTENT)); final Button patternButton = new Button(this); patternButton.setText(pathPatterns[0]); patternButton.setTextSize(8); patternButton.setLayoutParams(buttonLayoutParams); patternButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { String patternButtonText = patternButton.getText().toString().trim(); if (patternButtonText.equals(pathPatterns[0])) { patternButton.setText(pathPatterns[1]); } else if (patternButtonText.equals(pathPatterns[1])) { patternButton.setText(pathPatterns[2]); } else if (patternButtonText.equals(pathPatterns[2])) { patternButton.setText(pathPatterns[0]); } } }); groupLayout.addView(patternButton); row.addView(groupLayout); } Button button = new Button(this); button.setTextSize(10); button.setTypeface(null, Typeface.BOLD); button.setText("X"); button.setTypeface(Typeface.SANS_SERIF, Typeface.BOLD); button.setLayoutParams(buttonLayoutParams); button.setOnClickListener(new OnClickListener() { public void onClick(View view) { layout.removeView((LinearLayout) view.getParent()); } }); row.addView(button); row.setLayoutParams(rowLayoutParams); layout.addView(row); }
From source file:com.superrecycleview.superlibrary.utils.SuperDivider.java
@Override public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) { if (parent.getLayoutManager() == null || parent.getAdapter() == null) { return;/*from w w w . j a va 2s.c om*/ } int childAdapterPosition = parent.getChildAdapterPosition(view); int itemCount = parent.getAdapter().getItemCount(); int realChildAdapterPosition = childAdapterPosition; int realItemCount = itemCount; if (isNeedSkip(childAdapterPosition, realItemCount)) { outRect.set(0, 0, 0, 0); } else { if (mOrientation == LinearLayout.VERTICAL) { getVerticalItemOffsets(outRect); } else { outRect.set(mSize, 0, 0, 0); } } }
From source file:com.mediaexplorer.remote.MexRemoteActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main);/*from w w w . ja v a 2 s . c o m*/ this.setTitle(R.string.app_name); dbg = "MexWebremote"; text_view = (TextView) findViewById(R.id.text); web_view = (WebView) findViewById(R.id.link_view); web_view.getSettings().setJavaScriptEnabled(true);/* /* Future: setOverScrollMode is API level >8 * web_view.setOverScrollMode (OVER_SCROLL_NEVER); */ web_view.setBackgroundColor(0); web_view.setWebViewClient(new WebViewClient() { /* for some reason we only get critical errors so an auth error * is not handled here which is why there is some crack that test * the connection with a special httpclient */ @Override public void onReceivedHttpAuthRequest(final WebView view, final HttpAuthHandler handler, final String host, final String realm) { String[] userpass = new String[2]; userpass = view.getHttpAuthUsernamePassword(host, realm); HttpResponse response = null; HttpGet httpget; DefaultHttpClient httpclient; String target_host; int target_port; target_host = MexRemoteActivity.this.target_host; target_port = MexRemoteActivity.this.target_port; /* We may get null from getHttpAuthUsernamePassword which will * break the setCredentials so junk used instead to keep * it happy. */ Log.d(dbg, "using the set httpauth, testing auth using client"); try { if (userpass == null) { userpass = new String[2]; userpass[0] = "none"; userpass[1] = "none"; } } catch (Exception e) { userpass = new String[2]; userpass[0] = "none"; userpass[1] = "none"; } /* Log.d ("debug", * "trying: GET http://"+userpass[0]+":"+userpass[1]+"@"+target_host+":"+target_port+"/"); */ /* We're going to test the authentication credentials that we * have before using them so that we can act on the response. */ httpclient = new DefaultHttpClient(); httpget = new HttpGet("http://" + target_host + ":" + target_port + "/"); httpclient.getCredentialsProvider().setCredentials(new AuthScope(target_host, target_port), new UsernamePasswordCredentials(userpass[0], userpass[1])); try { response = httpclient.execute(httpget); } catch (IOException e) { Log.d(dbg, "Problem executing the http get"); e.printStackTrace(); } Log.d(dbg, "HTTP reponse:" + Integer.toString(response.getStatusLine().getStatusCode())); if (response.getStatusLine().getStatusCode() == 401) { /* We got Authentication failed (401) so ask user for u/p */ /* login dialog box */ final AlertDialog.Builder logindialog; final EditText user; final EditText pass; LinearLayout layout; LayoutParams params; TextView label_username; TextView label_password; logindialog = new AlertDialog.Builder(MexRemoteActivity.this); logindialog.setTitle("Mex Webremote login"); user = new EditText(MexRemoteActivity.this); pass = new EditText(MexRemoteActivity.this); layout = new LinearLayout(MexRemoteActivity.this); pass.setTransformationMethod(new PasswordTransformationMethod()); layout.setOrientation(LinearLayout.VERTICAL); params = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT); layout.setLayoutParams(params); user.setLayoutParams(params); pass.setLayoutParams(params); label_username = new TextView(MexRemoteActivity.this); label_password = new TextView(MexRemoteActivity.this); label_username.setText("Username:"); label_password.setText("Password:"); layout.addView(label_username); layout.addView(user); layout.addView(label_password); layout.addView(pass); logindialog.setView(layout); logindialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }); logindialog.setPositiveButton("Login", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { String uvalue = user.getText().toString().trim(); String pvalue = pass.getText().toString().trim(); view.setHttpAuthUsernamePassword(host, realm, uvalue, pvalue); handler.proceed(uvalue, pvalue); } }); logindialog.show(); /* End login dialog box */ } else /* We didn't get a 401 */ { handler.proceed(userpass[0], userpass[1]); } } /* End onReceivedHttpAuthRequest */ }); /* End Override */ /* Run mdns to check for service in a "runnable" (async) */ handler.post(new Runnable() { public void run() { startMdns(); } }); dialog = ProgressDialog.show(MexRemoteActivity.this, "", "Searching...", true); /* Let's put something in the webview while we're waiting */ String summary = "<html><head><style>body { background-color: #000000; color: #ffffff; }></style></head><body><p>Searching for the media explorer webservice</p><p>More infomation on <a href=\"http://media-explorer.github.com\" >Media Explorer's home page</a></p></body></html>"; web_view.loadData(summary, "text/html", "utf-8"); }
From source file:jp.mau.twappremover.MainActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); if (id == R.id.action_settings) { ScrollView contents = new ScrollView(this); LinearLayout layout = new LinearLayout(this); layout.setOrientation(LinearLayout.VERTICAL); contents.addView(layout);//from w w w .j a v a2s .c o m AssetManager asm = getResources().getAssets(); String[] filelist = null; try { filelist = asm.list("licenses"); } catch (Exception ex) { ex.printStackTrace(); } if (filelist != null) { for (String file : filelist) { Gen.debug(file); InputStream is = null; BufferedReader br = null; String txt = ""; try { is = getAssets().open("licenses/" + file); br = new BufferedReader(new InputStreamReader(is)); String str; while ((str = br.readLine()) != null) { txt += str + "\n"; } } catch (Exception ex) { ex.printStackTrace(); } finally { try { if (is != null) is.close(); } catch (Exception ex) { } try { if (br != null) br.close(); } catch (Exception ex) { } } TextView tv = new TextView(this); tv.setText(txt); layout.addView(tv); } } // final PopupView dialog = new PopupView(this); dialog.setDialog().setLabels(getString(R.string.activity_main_dlgtitle_oss), "") .setView(contents, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT) .setCancelable(true) .setPositiveBtn(getString(R.string.activity_main_dlgbtn_oss), new OnClickListener() { @Override public void onClick(View v) { dialog.dismiss(); } }).show(); return true; } return super.onOptionsItemSelected(item); }
From source file:com.azure.webapi.LoginManager.java
/** * Creates the UI for the interactive authentication process * /*from w w w . j ava 2s.com*/ * @param provider * The provider used for the authentication process * @param startUrl * The initial URL for the authentication process * @param endUrl * The final URL for the authentication process * @param context * The context used to create the authentication dialog * @param callback * Callback to invoke when the authentication process finishes */ protected void showLoginUI(MobileServiceAuthenticationProvider provider, final String startUrl, final String endUrl, final Context context, LoginUIOperationCallback callback) { if (startUrl == null || startUrl == "") { throw new IllegalArgumentException("startUrl can not be null or empty"); } if (endUrl == null || endUrl == "") { throw new IllegalArgumentException("endUrl can not be null or empty"); } if (context == null) { throw new IllegalArgumentException("context can not be null"); } final LoginUIOperationCallback externalCallback = callback; final AlertDialog.Builder builder = new AlertDialog.Builder(context); // Create the Web View to show the login page final WebView wv = new WebView(context); builder.setTitle("Connecting to a service"); builder.setCancelable(true); builder.setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { if (externalCallback != null) { externalCallback.onCompleted(null, new MobileServiceException("User Canceled")); } } }); // Set cancel button's action builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (externalCallback != null) { externalCallback.onCompleted(null, new MobileServiceException("User Canceled")); } wv.destroy(); } }); wv.getSettings().setJavaScriptEnabled(true); wv.requestFocus(View.FOCUS_DOWN); wv.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View view, MotionEvent event) { int action = event.getAction(); if (action == MotionEvent.ACTION_DOWN || action == MotionEvent.ACTION_UP) { if (!view.hasFocus()) { view.requestFocus(); } } return false; } }); // Create a LinearLayout and add the WebView to the Layout LinearLayout layout = new LinearLayout(context); layout.setOrientation(LinearLayout.VERTICAL); layout.addView(wv); // Add a dummy EditText to the layout as a workaround for a bug // that prevents showing the keyboard for the WebView on some devices EditText dummyEditText = new EditText(context); dummyEditText.setVisibility(View.GONE); layout.addView(dummyEditText); // Add the layout to the dialog builder.setView(layout); final AlertDialog dialog = builder.create(); wv.setWebViewClient(new WebViewClient() { @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { // If the URL of the started page matches with the final URL // format, the login process finished if (isFinalUrl(url)) { if (externalCallback != null) { externalCallback.onCompleted(url, null); } dialog.dismiss(); } super.onPageStarted(view, url, favicon); } // Checks if the given URL matches with the final URL's format private boolean isFinalUrl(String url) { if (url == null) { return false; } return url.startsWith(endUrl); } // Checks if the given URL matches with the start URL's format private boolean isStartUrl(String url) { if (url == null) { return false; } return url.startsWith(startUrl); } @Override public void onPageFinished(WebView view, String url) { if (isStartUrl(url)) { if (externalCallback != null) { externalCallback.onCompleted(null, new MobileServiceException( "Logging in with the selected authentication provider is not enabled")); } dialog.dismiss(); } } }); wv.loadUrl(startUrl); dialog.show(); }
From source file:com.tooltip.Tooltip.java
private View getContentView(Builder builder) { GradientDrawable drawable = new GradientDrawable(); drawable.setColor(builder.mBackgroundColor); drawable.setCornerRadius(builder.mCornerRadius); int padding = (int) builder.mPadding; TextView textView = new TextView(builder.mContext); TextViewCompat.setTextAppearance(textView, builder.mTextAppearance); textView.setText(builder.mText);//from w w w . j ava 2 s . c o m textView.setPadding(padding, padding, padding, padding); textView.setLineSpacing(builder.mLineSpacingExtra, builder.mLineSpacingMultiplier); textView.setTypeface(builder.mTypeface, builder.mTextStyle); if (builder.mTextSize >= 0) { textView.setTextSize(TypedValue.TYPE_NULL, builder.mTextSize); } if (builder.mTextColor != null) { textView.setTextColor(builder.mTextColor); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { textView.setBackground(drawable); } else { //noinspection deprecation textView.setBackgroundDrawable(drawable); } LinearLayout.LayoutParams textViewParams = new LinearLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, 0); textViewParams.gravity = Gravity.CENTER; textView.setLayoutParams(textViewParams); mArrowView = new ImageView(builder.mContext); mArrowView.setImageDrawable(builder.mArrowDrawable); LinearLayout.LayoutParams arrowLayoutParams; if (mGravity == Gravity.TOP || mGravity == Gravity.BOTTOM) { arrowLayoutParams = new LinearLayout.LayoutParams((int) builder.mArrowWidth, (int) builder.mArrowHeight, 0); } else { arrowLayoutParams = new LinearLayout.LayoutParams((int) builder.mArrowHeight, (int) builder.mArrowWidth, 0); } arrowLayoutParams.gravity = Gravity.CENTER; mArrowView.setLayoutParams(arrowLayoutParams); mContentView = new LinearLayout(builder.mContext); mContentView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); mContentView.setOrientation(mGravity == Gravity.START || mGravity == Gravity.END ? LinearLayout.HORIZONTAL : LinearLayout.VERTICAL); padding = (int) Util.dpToPx(5); switch (mGravity) { case Gravity.START: mContentView.setPadding(0, 0, padding, 0); break; case Gravity.TOP: case Gravity.BOTTOM: mContentView.setPadding(padding, 0, padding, 0); break; case Gravity.END: mContentView.setPadding(padding, 0, 0, 0); break; } if (mGravity == Gravity.TOP || mGravity == Gravity.START) { mContentView.addView(textView); mContentView.addView(mArrowView); } else { mContentView.addView(mArrowView); mContentView.addView(textView); } mContentView.setOnClickListener(mClickListener); mContentView.setOnLongClickListener(mLongClickListener); if (builder.isCancelable || builder.isDismissOnClick) { mContentView.setOnTouchListener(mTouchListener); } return mContentView; }
From source file:org.cocos2dx.lib.Cocos2dxEditBoxDialog.java
@Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); getWindow().setBackgroundDrawable(new ColorDrawable(0x80000000)); LinearLayout layout = new LinearLayout(mParentActivity); layout.setOrientation(LinearLayout.VERTICAL); LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT); mTextViewTitle = new TextView(mParentActivity); LinearLayout.LayoutParams textviewParams = new LinearLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); textviewParams.leftMargin = textviewParams.rightMargin = convertDipsToPixels(10); mTextViewTitle.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20); layout.addView(mTextViewTitle, textviewParams); mInputEditText = new EditText(mParentActivity); LinearLayout.LayoutParams editTextParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); editTextParams.leftMargin = editTextParams.rightMargin = convertDipsToPixels(10); layout.addView(mInputEditText, editTextParams); setContentView(layout, layoutParams); getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); mInputMode = mMsg.inputMode;//from w w w . jav a 2s . co m mInputFlag = mMsg.inputFlag; mReturnType = mMsg.returnType; mMaxLength = mMsg.maxLength; mTextViewTitle.setText(mMsg.title); mInputEditText.setText(mMsg.content); int oldImeOptions = mInputEditText.getImeOptions(); mInputEditText.setImeOptions(oldImeOptions | EditorInfo.IME_FLAG_NO_EXTRACT_UI); oldImeOptions = mInputEditText.getImeOptions(); switch (mInputMode) { case kEditBoxInputModeAny: mInputModeContraints = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_MULTI_LINE; break; case kEditBoxInputModeEmailAddr: mInputModeContraints = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS; break; case kEditBoxInputModeNumeric: mInputModeContraints = InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_SIGNED; break; case kEditBoxInputModePhoneNumber: mInputModeContraints = InputType.TYPE_CLASS_PHONE; break; case kEditBoxInputModeUrl: mInputModeContraints = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_URI; break; case kEditBoxInputModeDecimal: mInputModeContraints = InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL | InputType.TYPE_NUMBER_FLAG_SIGNED; break; case kEditBoxInputModeSingleLine: mInputModeContraints = InputType.TYPE_CLASS_TEXT; break; default: break; } if (mIsMultiline) { mInputModeContraints |= InputType.TYPE_TEXT_FLAG_MULTI_LINE; } mInputEditText.setInputType(mInputModeContraints | mInputFlagConstraints); switch (mInputFlag) { case kEditBoxInputFlagPassword: mInputFlagConstraints = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD; break; case kEditBoxInputFlagSensitive: mInputFlagConstraints = InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS; break; case kEditBoxInputFlagInitialCapsWord: mInputFlagConstraints = InputType.TYPE_TEXT_FLAG_CAP_WORDS; break; case kEditBoxInputFlagInitialCapsSentence: mInputFlagConstraints = InputType.TYPE_TEXT_FLAG_CAP_SENTENCES; break; case kEditBoxInputFlagInitialCapsAllCharacters: mInputFlagConstraints = InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS; break; default: break; } mInputEditText.setInputType(mInputFlagConstraints | mInputModeContraints); switch (mReturnType) { case kKeyboardReturnTypeDefault: mInputEditText.setImeOptions(oldImeOptions | EditorInfo.IME_ACTION_NONE); break; case kKeyboardReturnTypeDone: mInputEditText.setImeOptions(oldImeOptions | EditorInfo.IME_ACTION_DONE); break; case kKeyboardReturnTypeSend: mInputEditText.setImeOptions(oldImeOptions | EditorInfo.IME_ACTION_SEND); break; case kKeyboardReturnTypeSearch: mInputEditText.setImeOptions(oldImeOptions | EditorInfo.IME_ACTION_SEARCH); break; case kKeyboardReturnTypeGo: mInputEditText.setImeOptions(oldImeOptions | EditorInfo.IME_ACTION_GO); break; default: mInputEditText.setImeOptions(oldImeOptions | EditorInfo.IME_ACTION_NONE); break; } if (mMaxLength > 0) { mInputEditText.setFilters(new InputFilter[] { new InputFilter.LengthFilter(mMaxLength) }); } Handler initHandler = new Handler(); initHandler.postDelayed(new Runnable() { public void run() { mInputEditText.requestFocus(); mInputEditText.setSelection(mInputEditText.length()); openKeyboard(); } }, 200); mInputEditText.setOnEditorActionListener(new OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { // if user didn't set keyboard type, // this callback will be invoked twice with 'KeyEvent.ACTION_DOWN' and 'KeyEvent.ACTION_UP' if (actionId != EditorInfo.IME_NULL || (actionId == EditorInfo.IME_NULL && event != null && event.getAction() == KeyEvent.ACTION_DOWN)) { //Log.d("EditBox", "actionId: "+actionId +",event: "+event); mParentActivity.setEditBoxResult(mInputEditText.getText().toString()); closeKeyboard(); dismiss(); return true; } return false; } }); }
From source file:com.utils.widget.head.HeaderFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final Activity activity = getActivity(); assert activity != null; mFrameLayout = new FrameLayout(activity); mHeader = onCreateHeaderView(inflater, mFrameLayout); mHeaderHeader = mHeader.findViewById(android.R.id.title); mHeaderBackground = mHeader.findViewById(android.R.id.background); assert mHeader.getLayoutParams() != null; mHeaderHeight = mHeader.getLayoutParams().height; mFakeHeader = new Space(activity); mFakeHeader.setLayoutParams(new ListView.LayoutParams(0, mHeaderHeight)); View content = onCreateContentView(inflater, mFrameLayout); if (content instanceof ListView) { isListViewEmpty = true;//from ww w . ja va 2 s. c o m final ListView listView = (ListView) content; listView.addHeaderView(mFakeHeader); listView.setOnScrollListener(new AbsListView.OnScrollListener() { @Override public void onScrollStateChanged(AbsListView absListView, int scrollState) { if (mOnScrollListener != null) { mOnScrollListener.onScrollStateChanged(absListView, scrollState); } } @Override public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount, int totalItemCount) { if (mOnScrollListener != null) { mOnScrollListener.onScroll(absListView, firstVisibleItem, visibleItemCount, totalItemCount); } if (isListViewEmpty) { scrollHeaderTo(0); } else { final View child = absListView.getChildAt(0); assert child != null; scrollHeaderTo(child == mFakeHeader ? child.getTop() : -mHeaderHeight); } } }); } else { // Merge fake header view and content view. final LinearLayout view = new LinearLayout(activity); view.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); view.setOrientation(LinearLayout.VERTICAL); view.addView(mFakeHeader); view.addView(content); // Put merged content to ScrollView final NotifyingScrollView scrollView = new NotifyingScrollView(activity); scrollView.addView(view); scrollView.setOnScrollChangedListener(new NotifyingScrollView.OnScrollChangedListener() { @Override public void onScrollChanged(ScrollView who, int l, int t, int oldl, int oldt) { scrollHeaderTo(-t); } }); content = scrollView; } mFrameLayout.addView(content); mFrameLayout.addView(mHeader); // Content overlay view always shows at the top of content. if ((mContentOverlay = onCreateContentOverlayView(inflater, mFrameLayout)) != null) { mFrameLayout.addView(mContentOverlay, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); } // Post initial scroll mFrameLayout.post(new Runnable() { @Override public void run() { scrollHeaderTo(0, true); } }); return mFrameLayout; }
From source file:com.infigent.stocksense.MainActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); startService(new Intent(this, BackGround.class)); // setSlidingActionBarEnabled(true); Intent n = getIntent();//w ww .j a v a2s .co m if (getIntent() != null) { Bundle bundle = n.getExtras(); if (bundle != null) { Log.e("ARG", "EXIST"); if (bundle.containsKey("eq")) { Log.e("EQ", "EXIST"); if (bundle.getBoolean("eq")) { Log.e("eq", "true"); Bundle data = new Bundle(); Fragment4 eq = new Fragment4(); mContent = eq; data.putString("q", bundle.getString("q")); data.putString("type", bundle.getString("type")); data.putString("name", bundle.getString("name")); data.putString("f", gId()); eq.setArguments(data); switchContent(eq); } } } } if (savedInstanceState != null) mContent = getSupportFragmentManager().getFragment(savedInstanceState, "mContent"); if (mContent == null) mContent = new Fragment1(); ScrollView scrollView = new ScrollView(this); LinearLayout l = new LinearLayout(this); TextView one = new TextView(this); one.setText(getResources().getString(R.string.intro)); one.setPadding(0, 0, 0, 20); TextView two = new TextView(this); two.setText("Limited License"); two.setTextAppearance(getApplicationContext(), android.R.style.TextAppearance_DeviceDefault_Medium); TextView three = new TextView(this); three.setText(getResources().getString(R.string.l1)); TextView four = new TextView(this); four.setText(getResources().getString(R.string.l2)); four.setPadding(0, 0, 0, 20); TextView five = new TextView(this); five.setText("Disclaimer"); five.setTextAppearance(getApplicationContext(), android.R.style.TextAppearance_DeviceDefault_Medium); TextView six = new TextView(this); six.setText(getResources().getString(R.string.disclaimer1)); TextView seven = new TextView(this); seven.setText(getResources().getString(R.string.disclaimer2)); TextView eight = new TextView(this); eight.setText(getResources().getString(R.string.disclaimer3)); eight.setPadding(0, 0, 0, 20); TextView nine = new TextView(this); nine.setText("Liability For Our Services"); nine.setTextAppearance(getApplicationContext(), android.R.style.TextAppearance_DeviceDefault_Medium); TextView ten = new TextView(this); ten.setText(getResources().getString(R.string.liability1)); TextView eleven = new TextView(this); eleven.setText(getResources().getString(R.string.liability2)); eleven.setPadding(0, 0, 0, 20); TextView twelve = new TextView(this); twelve.setText("Maintenance And Support"); twelve.setTextAppearance(getApplicationContext(), android.R.style.TextAppearance_DeviceDefault_Medium); TextView thirteen = new TextView(this); thirteen.setText(getResources().getString(R.string.ms)); thirteen.setPadding(0, 0, 0, 20); TextView fourteen = new TextView(this); fourteen.setText("Links To Third Party Website"); fourteen.setTextAppearance(getApplicationContext(), android.R.style.TextAppearance_DeviceDefault_Medium); TextView fifteen = new TextView(this); fifteen.setText(getResources().getString(R.string.p3)); l.addView(one); l.addView(two); l.addView(three); l.addView(four); l.addView(five); l.addView(six); l.addView(seven); l.addView(eight); l.addView(nine); l.addView(ten); l.addView(eleven); l.addView(twelve); l.addView(thirteen); l.addView(fourteen); l.addView(fifteen); one.setTextColor(getResources().getColor(R.color.White)); two.setTextColor(getResources().getColor(R.color.White)); three.setTextColor(getResources().getColor(R.color.White)); four.setTextColor(getResources().getColor(R.color.White)); five.setTextColor(getResources().getColor(R.color.White)); six.setTextColor(getResources().getColor(R.color.White)); seven.setTextColor(getResources().getColor(R.color.White)); eight.setTextColor(getResources().getColor(R.color.White)); nine.setTextColor(getResources().getColor(R.color.White)); ten.setTextColor(getResources().getColor(R.color.White)); eleven.setTextColor(getResources().getColor(R.color.White)); twelve.setTextColor(getResources().getColor(R.color.White)); thirteen.setTextColor(getResources().getColor(R.color.White)); fourteen.setTextColor(getResources().getColor(R.color.White)); fifteen.setTextColor(getResources().getColor(R.color.White)); l.setOrientation(LinearLayout.VERTICAL); l.setBackgroundColor(getResources().getColor(R.color.bg)); l.setPadding(10, 10, 10, 10); scrollView.addView(l); boolean firstboot = getSharedPreferences("BOOT_PREF", MODE_PRIVATE).getBoolean("firstboot", true); if (firstboot) { LayoutInflater inflater = getLayoutInflater(); View vvv = inflater.inflate(R.layout.alerttitle, null); AlertDialog.Builder builder = new AlertDialog.Builder(this).setTitle("Terms of Service") .setView(scrollView).setCustomTitle(vvv) .setPositiveButton(android.R.string.ok, new Dialog.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { dialogInterface.dismiss(); getSharedPreferences("BOOT_PREF", MODE_PRIVATE).edit().putBoolean("firstboot", false) .commit(); } }).setNegativeButton(android.R.string.cancel, new Dialog.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // Close the activity as they have declined the EULA MainActivity.this.finish(); } }).setCancelable(false); builder.create().show(); } ime = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); ActionBar actionBar = getSupportActionBar(); getSupportActionBar().setCustomView(R.layout.search); actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM); actionBar.setDisplayUseLogoEnabled(true); actionBar.setDisplayShowTitleEnabled(false); actionBar.setDisplayShowHomeEnabled(true); actionBar.setDisplayHomeAsUpEnabled(true); sb = (ImageButton) actionBar.getCustomView().findViewById(R.id.sb); title = (TextView) actionBar.getCustomView().findViewById(R.id.title); sb.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub // only will trigger it if no physical keyboard is open search.setVisibility(View.VISIBLE); search.requestFocus(); ime.showSoftInput(search, InputMethodManager.SHOW_IMPLICIT); search.setSelection(search.getText().length()); sb.setVisibility(View.GONE); title.setVisibility(View.GONE); } }); search = (AutoCompleteTextView) actionBar.getCustomView().findViewById(R.id.et); search.setThreshold(2); search.setAdapter(new SuggestionsAdapter(this, search.getText().toString())); search.setSelectAllOnFocus(true); search.clearFocus(); search.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View arg1, int pos, long id) { String term = parent.getItemAtPosition(pos).toString(); String[] lines = term.split("\\r?\\n"); String name = lines[0]; String code = lines[1].substring(lines[1].indexOf(":") + 1, lines[1].length()).trim(); String type = lines[1].substring(0, lines[1].indexOf(":")); Log.d("DATA", name + " " + type + ":" + code); search.setText(""); if (isNetworkAvailable()) { if (term.replace(" ", "") != null) { Bundle data = new Bundle(); data.putString("q", code); data.putString("type", type); data.putString("name", name); data.putString("f", gId()); Fragment4 eq = new Fragment4(); eq.setArguments(data); Log.d("C", gId() + " frag"); mContent = eq; getSupportFragmentManager().beginTransaction().replace(R.id.content_frame, eq).commit(); getSlidingMenu().showContent(); search.setVisibility(View.GONE); sb.setVisibility(View.VISIBLE); title.setVisibility(View.VISIBLE); ime.hideSoftInputFromWindow(search.getApplicationWindowToken(), 0); } else { Toast.makeText(getApplicationContext(), "Enter a search term!", Toast.LENGTH_LONG).show(); } } else Toast.makeText(getApplicationContext(), "Internet not available", Toast.LENGTH_LONG).show(); } }); search.setOnEditorActionListener(new OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { return false; } }); // set the Above View setContentView(R.layout.content_frame); getSupportFragmentManager().beginTransaction().replace(R.id.content_frame, mContent).commit(); AdView mAdView; mAdView = (AdView) findViewById(R.id.adView); AdRequest adRequest = new AdRequest.Builder().build(); mAdView.loadAd(adRequest); // set the Behind View setBehindContentView(R.layout.menu_frame); getSupportFragmentManager().beginTransaction().replace(R.id.menu_frame, new SampleListFragment()).commit(); }
From source file:com.sonvp.tooltip.Tooltip.java
private Tooltip(Builder builder) { this.builder = builder; this.anchorView = builder.anchorView; this.gravity = builder.tooltipGravity; if (builder.dismissOutsideTouch) { rootView = (ViewGroup) anchorView.getRootView(); overlay = new View(builder.context); overlay.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); // overlay.setBackgroundColor(builder.context.getResources().getColor(android.R.color.holo_green_light)); overlay.setOnTouchListener(this); rootView.addView(overlay);//from w ww .j a v a 2s . c o m } // TODO container should NOT capture all events container = new LinearLayout(builder.context); container.setOnClickListener(this); int backgroundColor = builder.backgroundColor; viewTooltip = getViewTooltip(builder, backgroundColor); rectAnchorView = getRectView(anchorView); changeGravityToolTip(); if (builder.arrowDrawable == null) { builder.arrowDrawable = new ArrowDrawable(backgroundColor, gravity); } arrow = new ImageView(builder.context); // TODO supports Gravity.NO_GRAVITY switch (gravity) { case Gravity.LEFT: container.setOrientation(LinearLayout.HORIZONTAL); container.addView(viewTooltip, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT)); arrow.setImageDrawable(builder.arrowDrawable); container.addView(arrow, new LinearLayout.LayoutParams((int) builder.arrowWidth, (int) builder.arrowHeight)); break; case Gravity.RIGHT: container.setOrientation(LinearLayout.HORIZONTAL); arrow.setImageDrawable(builder.arrowDrawable); container.addView(arrow, new LinearLayout.LayoutParams((int) builder.arrowWidth, (int) builder.arrowHeight)); container.addView(viewTooltip, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT)); break; case Gravity.TOP: container.setOrientation(LinearLayout.VERTICAL); container.addView(viewTooltip, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT)); arrow.setImageDrawable(builder.arrowDrawable); container.addView(arrow, new LinearLayout.LayoutParams((int) builder.arrowWidth, (int) builder.arrowHeight)); break; case Gravity.BOTTOM: container.setOrientation(LinearLayout.VERTICAL); arrow.setImageDrawable(builder.arrowDrawable); container.addView(arrow, new LinearLayout.LayoutParams((int) builder.arrowWidth, (int) builder.arrowHeight)); container.addView(viewTooltip, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT)); break; } popupWindow = new PopupWindow(container, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); popupWindow.setOnDismissListener(this); popupWindow.setClippingEnabled(false); popupWindow.setAnimationStyle(android.R.style.Animation); // popupWindow.setBackgroundDrawable(builder.context.getResources().getDrawable(android.R.color.holo_blue_bright)); }