List of usage examples for android.widget LinearLayout setOrientation
public void setOrientation(@OrientationMode int orientation)
From source file:com.example.damerap_ver1.IntroVideoActivity.java
/** * Create the view in which the video will be rendered. *//*ww w . ja v a2 s . c om*/ private void setupView() { LinearLayout lLinLayout = new LinearLayout(this); lLinLayout.setId(1); lLinLayout.setOrientation(LinearLayout.VERTICAL); lLinLayout.setGravity(Gravity.CENTER); lLinLayout.setBackgroundColor(Color.BLACK); LayoutParams lLinLayoutParms = new LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT); lLinLayout.setLayoutParams(lLinLayoutParms); this.setContentView(lLinLayout); RelativeLayout lRelLayout = new RelativeLayout(this); lRelLayout.setId(2); lRelLayout.setGravity(Gravity.CENTER); lRelLayout.setBackgroundColor(Color.BLACK); android.widget.RelativeLayout.LayoutParams lRelLayoutParms = new android.widget.RelativeLayout.LayoutParams( ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT); lRelLayout.setLayoutParams(lRelLayoutParms); lLinLayout.addView(lRelLayout); mVideoView = new VideoView(this); mVideoView.setId(3); android.widget.RelativeLayout.LayoutParams lVidViewLayoutParams = new android.widget.RelativeLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); lVidViewLayoutParams.addRule(RelativeLayout.CENTER_IN_PARENT); mVideoView.setLayoutParams(lVidViewLayoutParams); lRelLayout.addView(mVideoView); mProgressBar = new ProgressBar(this); mProgressBar.setId(4); android.widget.RelativeLayout.LayoutParams lProgressBarLayoutParms = new android.widget.RelativeLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); lProgressBarLayoutParms.addRule(RelativeLayout.CENTER_IN_PARENT); mProgressBar.setLayoutParams(lProgressBarLayoutParms); lRelLayout.addView(mProgressBar); mProgressMessage = new TextView(this); mProgressMessage.setId(5); android.widget.RelativeLayout.LayoutParams lProgressMsgLayoutParms = new android.widget.RelativeLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); lProgressMsgLayoutParms.addRule(RelativeLayout.CENTER_HORIZONTAL); lProgressMsgLayoutParms.addRule(RelativeLayout.BELOW, 4); mProgressMessage.setLayoutParams(lProgressMsgLayoutParms); mProgressMessage.setTextColor(Color.LTGRAY); mProgressMessage.setTextSize(TypedValue.COMPLEX_UNIT_PT, 8); mProgressMessage.setText("..."); lRelLayout.addView(mProgressMessage); }
From source file:net.fengg.lib.tabsliding.TabSlidingView.java
private void addTextIconTab(final int position, String title, int resId) { TextView text = new TextView(getContext()); text.setText(title);//from w ww. ja v a2 s . co m text.setGravity(Gravity.CENTER); text.setSingleLine(); ImageButton icon = new ImageButton(getContext()); icon.setImageResource(resId); icon.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { pager.setCurrentItem(position); } }); LinearLayout linearLayout = new LinearLayout(getContext()); linearLayout.setOrientation(titileIconDirection); if (iconAbove) { linearLayout.addView(icon, shouldExpand ? expandedTabLayoutParams : defaultTabLayoutParams); linearLayout.addView(text, shouldExpand ? expandedTabLayoutParams : defaultTabLayoutParams); } else { linearLayout.addView(text, shouldExpand ? expandedTabLayoutParams : defaultTabLayoutParams); linearLayout.addView(icon, shouldExpand ? expandedTabLayoutParams : defaultTabLayoutParams); } addTab(position, linearLayout); }
From source file:com.astuetz.PagerSlidingTabStripPlus.java
private void addTab(final int position, View tab) { tab.setFocusable(true);/* w ww.j a v a2 s .co m*/ tab.setPadding(tabPaddingLeft, tabPaddingTop, tabPaddingRight, tabPaddingBottom); LinearLayout tabLayout = new LinearLayout(getContext()); tabLayout.setOrientation(LinearLayout.VERTICAL); tabLayout.setGravity(Gravity.CENTER); tabLayout.addView(tab, 0, defaultTabLayoutParams); tabLayout.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { pager.setCurrentItem(position); } }); tabsContainer.addView(tabLayout, position, shouldExpand ? expandedTabLayoutParams : defaultTabLayoutParams); }
From source file:com.cloudexplorers.plugins.childBrowser.ChildBrowser.java
/** * Display a new browser with the specified URL. * /* www .j av a2s . c o m*/ * @param url * The url to load. * @param jsonObject */ public String showWebPage(final String url, JSONObject options) { // Determine if we should hide the location bar. if (options != null) { showLocationBar = options.optBoolean("showLocationBar", true); } // Create dialog in new thread Runnable runnable = new Runnable() { /** * Convert our DIP units to Pixels * * @return int */ private int dpToPixels(int dipValue) { int value = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, (float) dipValue, cordova.getActivity().getResources().getDisplayMetrics()); return value; } public void run() { // Let's create the main dialog dialog = new Dialog(cordova.getActivity(), android.R.style.Theme_NoTitleBar); dialog.getWindow().getAttributes().windowAnimations = android.R.style.Animation_Dialog; dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setCancelable(true); dialog.setOnDismissListener(new DialogInterface.OnDismissListener() { public void onDismiss(DialogInterface dialog) { try { JSONObject obj = new JSONObject(); obj.put("type", CLOSE_EVENT); sendUpdate(obj, false); } catch (JSONException e) { Log.d(LOG_TAG, "Should never happen"); } } }); // Main container layout LinearLayout main = new LinearLayout(cordova.getActivity()); main.setOrientation(LinearLayout.VERTICAL); // Toolbar layout RelativeLayout toolbar = new RelativeLayout(cordova.getActivity()); toolbar.setLayoutParams( new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, this.dpToPixels(44))); toolbar.setPadding(this.dpToPixels(2), this.dpToPixels(2), this.dpToPixels(2), this.dpToPixels(2)); toolbar.setHorizontalGravity(Gravity.LEFT); toolbar.setVerticalGravity(Gravity.TOP); // Action Button Container layout RelativeLayout actionButtonContainer = new RelativeLayout(cordova.getActivity()); actionButtonContainer.setLayoutParams( new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); actionButtonContainer.setHorizontalGravity(Gravity.LEFT); actionButtonContainer.setVerticalGravity(Gravity.CENTER_VERTICAL); actionButtonContainer.setId(1); // Back button ImageButton back = new ImageButton(cordova.getActivity()); RelativeLayout.LayoutParams backLayoutParams = new RelativeLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT); backLayoutParams.addRule(RelativeLayout.ALIGN_LEFT); back.setLayoutParams(backLayoutParams); back.setContentDescription("Back Button"); back.setId(2); try { back.setImageBitmap(loadDrawable("www/childbrowser/icon_arrow_left.png")); } catch (IOException e) { Log.e(LOG_TAG, e.getMessage(), e); } back.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { goBack(); } }); // Forward button ImageButton forward = new ImageButton(cordova.getActivity()); RelativeLayout.LayoutParams forwardLayoutParams = new RelativeLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT); forwardLayoutParams.addRule(RelativeLayout.RIGHT_OF, 2); forward.setLayoutParams(forwardLayoutParams); forward.setContentDescription("Forward Button"); forward.setId(3); try { forward.setImageBitmap(loadDrawable("www/childbrowser/icon_arrow_right.png")); } catch (IOException e) { Log.e(LOG_TAG, e.getMessage(), e); } forward.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { goForward(); } }); // Edit Text Box edittext = new EditText(cordova.getActivity()); RelativeLayout.LayoutParams textLayoutParams = new RelativeLayout.LayoutParams( LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT); textLayoutParams.addRule(RelativeLayout.RIGHT_OF, 1); textLayoutParams.addRule(RelativeLayout.LEFT_OF, 5); edittext.setLayoutParams(textLayoutParams); edittext.setId(4); edittext.setSingleLine(true); edittext.setText(url); edittext.setInputType(InputType.TYPE_TEXT_VARIATION_URI); edittext.setImeOptions(EditorInfo.IME_ACTION_GO); edittext.setInputType(InputType.TYPE_NULL); // Will not except input... // Makes the text // NON-EDITABLE edittext.setOnKeyListener(new View.OnKeyListener() { public boolean onKey(View v, int keyCode, KeyEvent event) { // If the event is a key-down event on the "enter" button if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) { navigate(edittext.getText().toString()); return true; } return false; } }); // Close button ImageButton close = new ImageButton(cordova.getActivity()); RelativeLayout.LayoutParams closeLayoutParams = new RelativeLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT); closeLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); close.setLayoutParams(closeLayoutParams); forward.setContentDescription("Close Button"); close.setId(5); try { close.setImageBitmap(loadDrawable("www/childbrowser/icon_close.png")); } catch (IOException e) { Log.e(LOG_TAG, e.getMessage(), e); } close.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { closeDialog(); } }); // WebView webview = new WebView(cordova.getActivity()); webview.setLayoutParams( new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); webview.setWebChromeClient(new WebChromeClient()); WebViewClient client = new ChildBrowserClient(edittext); webview.setWebViewClient(client); WebSettings settings = webview.getSettings(); settings.setJavaScriptEnabled(true); settings.setJavaScriptCanOpenWindowsAutomatically(true); settings.setBuiltInZoomControls(true); settings.setPluginsEnabled(true); settings.setDomStorageEnabled(true); webview.loadUrl(url); webview.setId(6); webview.getSettings().setLoadWithOverviewMode(true); webview.getSettings().setUseWideViewPort(true); webview.getSettings().setJavaScriptEnabled(true); webview.getSettings().setPluginsEnabled(true); webview.requestFocus(); webview.requestFocusFromTouch(); // Add the back and forward buttons to our action button container // layout actionButtonContainer.addView(back); actionButtonContainer.addView(forward); // Add the views to our toolbar toolbar.addView(actionButtonContainer); toolbar.addView(edittext); toolbar.addView(close); // Don't add the toolbar if its been disabled if (getShowLocationBar()) { // Add our toolbar to our main view/layout main.addView(toolbar); } // Add our webview to our main view/layout main.addView(webview); WindowManager.LayoutParams lp = new WindowManager.LayoutParams(); lp.copyFrom(dialog.getWindow().getAttributes()); lp.width = WindowManager.LayoutParams.FILL_PARENT; lp.height = WindowManager.LayoutParams.FILL_PARENT; dialog.setContentView(main); dialog.show(); dialog.getWindow().setAttributes(lp); } private Bitmap loadDrawable(String filename) throws java.io.IOException { InputStream input = cordova.getActivity().getAssets().open(filename); return BitmapFactory.decodeStream(input); } }; this.cordova.getActivity().runOnUiThread(runnable); return ""; }
From source file:com.wallerlab.compcellscope.Image_Gallery.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_image__gallery); counter = 0;// w ww. j av a 2 s . c o m final ImageView currPic = new ImageView(this); DisplayMetrics metrics = this.getResources().getDisplayMetrics(); final int screen_width = metrics.widthPixels; SharedPreferences settings = getSharedPreferences(Folder_Chooser.PREFS_NAME, 0); //SharedPreferences.Editor edit = settings.edit(); String path = settings.getString(Folder_Chooser.location_name, Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).toString()); //Log.d(LOG, " | " + path + " | "); TextView text1 = (TextView) findViewById(R.id.text1); final TextView text2 = (TextView) findViewById(R.id.text2); text1.setText(path); File directory = new File(path); // get all the files from a directory File[] dump_files = directory.listFiles(); Log.d(LOG, dump_files.length + " "); final File[] fList = removeElements(dump_files, "info.json"); Log.d(LOG, "Filtered Length: " + fList.length); Arrays.sort(fList, new Comparator<File>() { @Override public int compare(File file, File file2) { String one = file.toString(); String two = file2.toString(); //Log.d(LOG, "one: " + one); //Log.d(LOG, "two: " + two); int num_one = Integer.parseInt(one.substring(one.lastIndexOf("(") + 1, one.lastIndexOf(")"))); int num_two = Integer.parseInt(two.substring(two.lastIndexOf("(") + 1, two.lastIndexOf(")"))); return num_one - num_two; } }); try { writeJsonFile(fList); } catch (JSONException e) { Log.d(LOG, "JSON WRITE FAILED"); } //List names programattically LinearLayout myLinearLayout = (LinearLayout) findViewById(R.id.linear_table); final LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, screen_width + 4); myLinearLayout.setOrientation(LinearLayout.VERTICAL); if (fList != null) { File cur_pic = fList[0]; BitmapFactory.Options opts = new BitmapFactory.Options(); Log.d(LOG, "\n File Location: " + cur_pic.getAbsolutePath() + " \n" + " Parent: " + cur_pic.getParent().toString() + "\n"); Bitmap myImage = BitmapFactory.decodeFile(cur_pic.getAbsolutePath(), opts); currPic.setLayoutParams(params); currPic.setImageBitmap(myImage); currPic.setId(View.generateViewId()); text2.setText(cur_pic.getName()); } myLinearLayout.addView(currPic); //Seekbar seekBar = (SeekBar) findViewById(R.id.seekBar); seekBar.setEnabled(true); seekBar.setMax(fList.length - 1); seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { int progress = 0; int length = fList.length; @Override public void onProgressChanged(SeekBar seekBar, int i, boolean b) { setCounter(i); if (getCounter() <= fList.length) { File cur_pic = fList[getCounter()]; BitmapFactory.Options opts = new BitmapFactory.Options(); opts.inJustDecodeBounds = true; Bitmap myImage = BitmapFactory.decodeFile(cur_pic.getAbsolutePath(), opts); int image_width = opts.outWidth; int image_height = opts.outHeight; int sampleSize = image_width / screen_width; opts.inSampleSize = sampleSize; text2.setText(cur_pic.getName()); opts.inJustDecodeBounds = false; myImage = BitmapFactory.decodeFile(cur_pic.getAbsolutePath(), opts); currPic.setImageBitmap(myImage); } } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onStopTrackingTouch(SeekBar seekBar) { } }); //Make Button Layout LinearLayout buttonLayout = new LinearLayout(this); buttonLayout.setOrientation(LinearLayout.HORIZONTAL); LinearLayout.LayoutParams LLParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, 1.0f); buttonLayout.setLayoutParams(LLParams); buttonLayout.setId(View.generateViewId()); //Button Layout Params LinearLayout.LayoutParams param_button = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, 1.0f); //Prev Pic Button prevPic = new Button(this); prevPic.setText("Previous"); prevPic.setId(View.generateViewId()); prevPic.setLayoutParams(param_button); prevPic.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (fList != null) { decrementCounter(); if (getCounter() >= 0) { File cur_pic = fList[getCounter()]; BitmapFactory.Options opts = new BitmapFactory.Options(); opts.inJustDecodeBounds = true; Bitmap myImage = BitmapFactory.decodeFile(cur_pic.getAbsolutePath(), opts); int image_width = opts.outWidth; int image_height = opts.outHeight; int sampleSize = image_width / screen_width; opts.inSampleSize = sampleSize; text2.setText(cur_pic.getName()); opts.inJustDecodeBounds = false; myImage = BitmapFactory.decodeFile(cur_pic.getAbsolutePath(), opts); //Log.d(LOG, getCounter() + ""); seekBar.setProgress(getCounter()); currPic.setImageBitmap(myImage); } else { setCounter(0); } } else { Toast.makeText(Image_Gallery.this, "There are no pictures in this folder", Toast.LENGTH_SHORT); setCounter(getCounter() - 1); } } }); buttonLayout.addView(prevPic); // Next Picture Button Button nextPic = new Button(this); nextPic.setText("Next"); nextPic.setId(View.generateViewId()); nextPic.setLayoutParams(param_button); buttonLayout.addView(nextPic); nextPic.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (fList != null) { incrementCounter(); if (getCounter() < fList.length) { File cur_pic = fList[getCounter()]; BitmapFactory.Options opts = new BitmapFactory.Options(); opts.inJustDecodeBounds = true; Bitmap myImage = BitmapFactory.decodeFile(cur_pic.getAbsolutePath(), opts); int image_width = opts.outWidth; int image_height = opts.outHeight; int sampleSize = image_width / screen_width; opts.inSampleSize = sampleSize; text2.setText(cur_pic.getName()); opts.inJustDecodeBounds = false; myImage = BitmapFactory.decodeFile(cur_pic.getAbsolutePath(), opts); //Log.d(LOG, getCounter() + ""); seekBar.setProgress(getCounter()); currPic.setImageBitmap(myImage); } else { setCounter(getCounter() - 1); } } else { Toast.makeText(Image_Gallery.this, "There are no pictures in this folder", Toast.LENGTH_SHORT); setCounter(getCounter() - 1); } } }); myLinearLayout.addView(buttonLayout); }
From source file:fr.cph.chicago.core.adapter.FavoritesAdapter.java
private void handleStation(@NonNull final FavoritesViewHolder holder, @NonNull final Station station) { final int stationId = station.getId(); final Set<TrainLine> trainLines = station.getLines(); holder.favoriteImage.setImageResource(R.drawable.ic_train_white_24dp); holder.stationNameTextView.setText(station.getName()); holder.detailsButton.setOnClickListener(v -> { if (!Util.isNetworkAvailable(context)) { Util.showNetworkErrorMessage(activity); } else {/* w w w .ja va 2s. c o m*/ // Start station activity final Bundle extras = new Bundle(); final Intent intent = new Intent(context, StationActivity.class); extras.putInt(activity.getString(R.string.bundle_train_stationId), stationId); intent.putExtras(extras); activity.startActivity(intent); } }); holder.mapButton.setText(activity.getString(R.string.favorites_view_trains)); holder.mapButton.setOnClickListener(v -> { if (!Util.isNetworkAvailable(context)) { Util.showNetworkErrorMessage(activity); } else { if (trainLines.size() == 1) { startActivity(trainLines.iterator().next()); } else { final List<Integer> colors = new ArrayList<>(); final List<String> values = Stream.of(trainLines).flatMap(line -> { final int color = line != TrainLine.YELLOW ? line.getColor() : ContextCompat.getColor(context, R.color.yellowLine); colors.add(color); return Stream.of(line.toStringWithLine()); }).collect(Collectors.toList()); final PopupFavoritesTrainAdapter ada = new PopupFavoritesTrainAdapter(activity, values, colors); final List<TrainLine> lines = new ArrayList<>(); lines.addAll(trainLines); final AlertDialog.Builder builder = new AlertDialog.Builder(activity); builder.setAdapter(ada, (dialog, position) -> startActivity(lines.get(position))); final int[] screenSize = Util.getScreenSize(context); final AlertDialog dialog = builder.create(); dialog.show(); if (dialog.getWindow() != null) { dialog.getWindow().setLayout((int) (screenSize[0] * 0.7), LayoutParams.WRAP_CONTENT); } } } }); Stream.of(trainLines).forEach(trainLine -> { boolean newLine = true; int i = 0; final Map<String, StringBuilder> etas = favoritesData.getTrainArrivalByLine(stationId, trainLine); for (final Entry<String, StringBuilder> entry : etas.entrySet()) { final LinearLayout.LayoutParams containParam = getInsideParams(newLine, i == etas.size() - 1); final LinearLayout container = new LinearLayout(context); container.setOrientation(LinearLayout.HORIZONTAL); container.setLayoutParams(containParam); // Left final RelativeLayout.LayoutParams leftParam = new RelativeLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); final RelativeLayout left = new RelativeLayout(context); left.setLayoutParams(leftParam); final RelativeLayout lineIndication = LayoutUtil.createColoredRoundForFavorites(context, trainLine); int lineId = Util.generateViewId(); lineIndication.setId(lineId); final RelativeLayout.LayoutParams destinationParams = new RelativeLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); destinationParams.addRule(RelativeLayout.RIGHT_OF, lineId); destinationParams.setMargins(pixelsHalf, 0, 0, 0); final String destination = entry.getKey(); final TextView destinationTextView = new TextView(context); destinationTextView.setTextColor(grey5); destinationTextView.setText(destination); destinationTextView.setLines(1); destinationTextView.setLayoutParams(destinationParams); left.addView(lineIndication); left.addView(destinationTextView); // Right final LinearLayout.LayoutParams rightParams = new LinearLayout.LayoutParams( LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); rightParams.setMargins(marginLeftPixel, 0, 0, 0); final LinearLayout right = new LinearLayout(context); right.setOrientation(LinearLayout.VERTICAL); right.setLayoutParams(rightParams); final StringBuilder currentEtas = entry.getValue(); final TextView arrivalText = new TextView(context); arrivalText.setText(currentEtas); arrivalText.setGravity(Gravity.END); arrivalText.setSingleLine(true); arrivalText.setTextColor(grey5); arrivalText.setEllipsize(TextUtils.TruncateAt.END); right.addView(arrivalText); container.addView(left); container.addView(right); holder.mainLayout.addView(container); newLine = false; i++; } }); }
From source file:fr.cph.chicago.core.adapter.FavoritesAdapter.java
private void handleBusRoute(@NonNull final FavoritesViewHolder holder, @NonNull final BusRoute busRoute) { holder.stationNameTextView.setText(busRoute.getId()); holder.favoriteImage.setImageResource(R.drawable.ic_directions_bus_white_24dp); final List<BusDetailsDTO> busDetailsDTOs = new ArrayList<>(); final Map<String, Map<String, List<BusArrival>>> busArrivals = favoritesData .getBusArrivalsMapped(busRoute.getId()); for (final Entry<String, Map<String, List<BusArrival>>> entry : busArrivals.entrySet()) { // Build data for button outside of the loop final String stopName = entry.getKey(); final String stopNameTrimmed = Util.trimBusStopNameIfNeeded(stopName); final Map<String, List<BusArrival>> value = entry.getValue(); for (final String key2 : value.keySet()) { final BusArrival busArrival = value.get(key2).get(0); final String boundTitle = busArrival.getRouteDirection(); final BusDirection.BusDirectionEnum busDirectionEnum = BusDirection.BusDirectionEnum .fromString(boundTitle); final BusDetailsDTO busDetails = BusDetailsDTO.builder().busRouteId(busArrival.getRouteId()) .bound(busDirectionEnum.getShortUpperCase()).boundTitle(boundTitle) .stopId(Integer.toString(busArrival.getStopId())).routeName(busRoute.getName()) .stopName(stopName).build(); busDetailsDTOs.add(busDetails); }//from w ww .ja va 2s .c om boolean newLine = true; int i = 0; for (final Entry<String, List<BusArrival>> entry2 : value.entrySet()) { final LinearLayout.LayoutParams containParams = getInsideParams(newLine, i == value.size() - 1); final LinearLayout container = new LinearLayout(context); container.setOrientation(LinearLayout.HORIZONTAL); container.setLayoutParams(containParams); // Left final LinearLayout.LayoutParams leftParams = new LinearLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); final RelativeLayout left = new RelativeLayout(context); left.setLayoutParams(leftParams); final RelativeLayout lineIndication = LayoutUtil.createColoredRoundForFavorites(context, TrainLine.NA); int lineId = Util.generateViewId(); lineIndication.setId(lineId); final RelativeLayout.LayoutParams destinationParams = new RelativeLayout.LayoutParams( LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); destinationParams.addRule(RelativeLayout.RIGHT_OF, lineId); destinationParams.setMargins(pixelsHalf, 0, 0, 0); final String bound = BusDirection.BusDirectionEnum.fromString(entry2.getKey()).getShortLowerCase(); final String leftString = stopNameTrimmed + " " + bound; final SpannableString destinationSpannable = new SpannableString(leftString); destinationSpannable.setSpan(new RelativeSizeSpan(0.65f), stopNameTrimmed.length(), leftString.length(), 0); // set size destinationSpannable.setSpan(new ForegroundColorSpan(grey5), 0, leftString.length(), 0); // set color final TextView boundCustomTextView = new TextView(context); boundCustomTextView.setText(destinationSpannable); boundCustomTextView.setSingleLine(true); boundCustomTextView.setLayoutParams(destinationParams); left.addView(lineIndication); left.addView(boundCustomTextView); // Right final LinearLayout.LayoutParams rightParams = new LinearLayout.LayoutParams( LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); rightParams.setMargins(marginLeftPixel, 0, 0, 0); final LinearLayout right = new LinearLayout(context); right.setOrientation(LinearLayout.VERTICAL); right.setLayoutParams(rightParams); final List<BusArrival> buses = entry2.getValue(); final StringBuilder currentEtas = new StringBuilder(); for (final BusArrival arri : buses) { currentEtas.append(" ").append(arri.getTimeLeftDueDelay()); } final TextView arrivalText = new TextView(context); arrivalText.setText(currentEtas); arrivalText.setGravity(Gravity.END); arrivalText.setSingleLine(true); arrivalText.setTextColor(grey5); arrivalText.setEllipsize(TextUtils.TruncateAt.END); right.addView(arrivalText); container.addView(left); container.addView(right); holder.mainLayout.addView(container); newLine = false; i++; } } holder.mapButton.setText(activity.getString(R.string.favorites_view_buses)); holder.detailsButton .setOnClickListener(new BusStopOnClickListener(activity, holder.parent, busDetailsDTOs)); holder.mapButton.setOnClickListener(v -> { if (!Util.isNetworkAvailable(context)) { Util.showNetworkErrorMessage(activity); } else { final Set<String> bounds = Stream.of(busDetailsDTOs).map(BusDetailsDTO::getBound) .collect(Collectors.toSet()); final Intent intent = new Intent(activity.getApplicationContext(), BusMapActivity.class); final Bundle extras = new Bundle(); extras.putString(activity.getString(R.string.bundle_bus_route_id), busRoute.getId()); extras.putStringArray(activity.getString(R.string.bundle_bus_bounds), bounds.toArray(new String[bounds.size()])); intent.putExtras(extras); activity.startActivity(intent); } }); }
From source file:com.nttec.everychan.ui.NewTabFragment.java
private void openChansList() { final ArrayAdapter<ChanModule> chansAdapter = new ArrayAdapter<ChanModule>(activity, 0) { private LayoutInflater inflater = LayoutInflater.from(activity); private int drawablePadding = (int) (resources.getDisplayMetrics().density * 5 + 0.5f); {//from w ww . j a v a2s . co m for (ChanModule chan : MainApplication.getInstance().chanModulesList) add(chan); } @Override public View getView(int position, View convertView, ViewGroup parent) { ChanModule chan = getItem(position); TextView view = (TextView) (convertView == null ? inflater.inflate(android.R.layout.simple_list_item_1, parent, false) : convertView); view.setText(chan.getDisplayingName()); view.setCompoundDrawablesWithIntrinsicBounds(chan.getChanFavicon(), null, null, null); view.setCompoundDrawablePadding(drawablePadding); return view; } }; DialogInterface.OnClickListener onChanSelected = new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { ChanModule chan = chansAdapter.getItem(which); UrlPageModel model = new UrlPageModel(); model.chanName = chan.getChanName(); model.type = UrlPageModel.TYPE_INDEXPAGE; openNewTab(chan.buildUrl(model)); } }; final AlertDialog chansListDialog = new AlertDialog.Builder(activity) .setTitle(R.string.newtab_quickaccess_all_boards).setAdapter(chansAdapter, onChanSelected) .setNegativeButton(android.R.string.cancel, null).create(); chansListDialog.getListView().setOnCreateContextMenuListener(new View.OnCreateContextMenuListener() { @Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { MenuItem.OnMenuItemClickListener contextMenuHandler = new MenuItem.OnMenuItemClickListener() { @SuppressLint("InlinedApi") @Override public boolean onMenuItemClick(MenuItem item) { final ChanModule chan = chansAdapter .getItem(((AdapterView.AdapterContextMenuInfo) item.getMenuInfo()).position); switch (item.getItemId()) { case R.id.context_menu_favorites_from_fragment: if (MainApplication.getInstance().database.isFavorite(chan.getChanName(), null, null, null)) { MainApplication.getInstance().database.removeFavorite(chan.getChanName(), null, null, null); } else { try { UrlPageModel indexPage = new UrlPageModel(); indexPage.chanName = chan.getChanName(); indexPage.type = UrlPageModel.TYPE_INDEXPAGE; MainApplication.getInstance().database.addFavorite(chan.getChanName(), null, null, null, chan.getChanName(), chan.buildUrl(indexPage)); } catch (Exception e) { Logger.e(TAG, e); } } return true; case R.id.context_menu_quickaccess_add: QuickAccess.Entry newEntry = new QuickAccess.Entry(); newEntry.chan = chan; list.add(0, newEntry); adapter.notifyDataSetChanged(); saveQuickAccessToPreferences(); chansListDialog.dismiss(); return true; case R.id.context_menu_quickaccess_custom_board: LinearLayout dialogLayout = new LinearLayout(activity); dialogLayout.setOrientation(LinearLayout.VERTICAL); final EditText boardField = new EditText(activity); final EditText descriptionField = new EditText(activity); boardField.setHint(R.string.newtab_quickaccess_addcustom_boardcode); descriptionField.setHint(R.string.newtab_quickaccess_addcustom_boarddesc); LinearLayout.LayoutParams fieldsParams = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); dialogLayout.addView(boardField, fieldsParams); dialogLayout.addView(descriptionField, fieldsParams); DialogInterface.OnClickListener onOkClicked = new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String boardName = boardField.getText().toString(); for (QuickAccess.Entry entry : list) if (entry.boardName != null && entry.chan != null) if (entry.chan.getChanName().equals(chan.getChanName()) && entry.boardName.equals(boardName)) { Toast.makeText(activity, R.string.newtab_quickaccess_addcustom_already_exists, Toast.LENGTH_LONG).show(); return; } try { if (boardName.trim().length() == 0) throw new Exception(); UrlPageModel boardPageModel = new UrlPageModel(); boardPageModel.type = UrlPageModel.TYPE_BOARDPAGE; boardPageModel.chanName = chan.getChanName(); boardPageModel.boardName = boardName; boardPageModel.boardPage = UrlPageModel.DEFAULT_FIRST_PAGE; chan.buildUrl(boardPageModel); //, ?? ? } catch (Exception e) { Toast.makeText(activity, R.string.newtab_quickaccess_addcustom_incorrect_code, Toast.LENGTH_LONG).show(); return; } QuickAccess.Entry newEntry = new QuickAccess.Entry(); newEntry.chan = chan; newEntry.boardName = boardName; newEntry.boardDescription = descriptionField.getText().toString(); list.add(0, newEntry); adapter.notifyDataSetChanged(); saveQuickAccessToPreferences(); chansListDialog.dismiss(); } }; new AlertDialog.Builder(activity) .setTitle(resources.getString(R.string.newtab_quickaccess_addcustom_title, chan.getChanName())) .setView(dialogLayout).setPositiveButton(android.R.string.ok, onOkClicked) .setNegativeButton(android.R.string.cancel, null).show(); return true; } return false; } }; String thisChanName = chansAdapter.getItem(((AdapterView.AdapterContextMenuInfo) menuInfo).position) .getChanName(); boolean canAddToQuickAccess = true; for (QuickAccess.Entry entry : list) if (entry.boardName == null && entry.chan != null && entry.chan.getChanName().equals(thisChanName)) { canAddToQuickAccess = false; break; } menu.add(Menu.NONE, R.id.context_menu_favorites_from_fragment, 1, MainApplication.getInstance().database.isFavorite(thisChanName, null, null, null) ? R.string.context_menu_remove_favorites : R.string.context_menu_add_favorites) .setOnMenuItemClickListener(contextMenuHandler); menu.add(Menu.NONE, R.id.context_menu_quickaccess_add, 2, R.string.context_menu_quickaccess_add) .setOnMenuItemClickListener(contextMenuHandler).setVisible(canAddToQuickAccess); menu.add(Menu.NONE, R.id.context_menu_quickaccess_custom_board, 3, R.string.context_menu_quickaccess_custom_board) .setOnMenuItemClickListener(contextMenuHandler); if (isSingleboardChan( chansAdapter.getItem(((AdapterView.AdapterContextMenuInfo) menuInfo).position))) menu.findItem(R.id.context_menu_quickaccess_custom_board).setVisible(false); } }); chansListDialog.show(); }
From source file:com.grarak.kerneladiutor.fragments.other.SettingsFragment.java
private void colorDialog(int selection) { LinearLayout linearLayout = new LinearLayout(getActivity()); linearLayout.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); linearLayout.setOrientation(LinearLayout.VERTICAL); int padding = (int) getResources().getDimension(R.dimen.dialog_padding); linearLayout.setPadding(padding, padding, padding, padding); final List<BorderCircleView> circles = new ArrayList<>(); LinearLayout subView = null;/*from ww w . j a v a 2 s. c o m*/ for (int i = 0; i < BorderCircleView.sAccentColors.size(); i++) { if (subView == null || i % 5 == 0) { subView = new LinearLayout(getActivity()); subView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); linearLayout.addView(subView); } BorderCircleView circle = new BorderCircleView(getActivity()); circle.setChecked(i == selection); circle.setBackgroundColor( ContextCompat.getColor(getActivity(), BorderCircleView.sAccentColors.keyAt(i))); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, 1); int margin = (int) getResources().getDimension(R.dimen.color_dialog_margin); params.setMargins(margin, margin, margin, margin); circle.setLayoutParams(params); circle.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { for (BorderCircleView borderCircleView : circles) { if (v == borderCircleView) { borderCircleView.setChecked(true); mColorSelection = circles.indexOf(borderCircleView); } else { borderCircleView.setChecked(false); } } } }); circles.add(circle); subView.addView(circle); } new Dialog(getActivity()).setView(linearLayout) .setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }).setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (mColorSelection >= 0) { Prefs.saveString(KEY_ACCENT_COLOR, BorderCircleView.sAccentColors.valueAt(mColorSelection), getActivity()); } getActivity().finish(); Intent intent = new Intent(getActivity(), MainActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent); } }).setOnDismissListener(new DialogInterface.OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { mColorSelection = -1; } }).show(); }
From source file:com.cairoconfessions.MainActivity.java
public void report(View view) { final EditText edit = new EditText(this); final RadioGroup choices = new RadioGroup(this); edit.setText("I would like to report this confession"); final String[] selectedItem = getResources().getStringArray(R.array.report_choices); for (int i = 0; i < selectedItem.length; i++) { RadioButton choice = new RadioButton(this); choice.setText(selectedItem[i]); choices.addView(choice);//w w w . j a va 2s . co m } choices.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { public void onCheckedChanged(RadioGroup group, int checkedId) { // checkedId is the RadioButton selected edit.setText("I would like to report this confession as " + ((RadioButton) group.findViewById(checkedId)).getText().toString()); } }); LinearLayout ll = new LinearLayout(this); ll.setOrientation(LinearLayout.VERTICAL); ll.addView(choices); ll.addView(edit); AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setMessage("Choose which categories:").setView(ll) .setPositiveButton(R.string.send, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // User clicked OK button reportReceived(); } }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // User clicked Cancel button } }).show(); }