List of usage examples for android.widget LinearLayout setLayoutParams
public void setLayoutParams(ViewGroup.LayoutParams params)
From source file:org.apache.cordova.AndroidChromeClient.java
@Override /**//from w ww .j av a2 s . c o m * Ask the host application for a custom progress view to show while * a <video> is loading. * @return View The progress view. */ public View getVideoLoadingProgressView() { if (mVideoProgressView == null) { // Create a new Loading view programmatically. // create the linear layout LinearLayout layout = new LinearLayout(this.appView.getContext()); layout.setOrientation(LinearLayout.VERTICAL); RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); layoutParams.addRule(RelativeLayout.CENTER_IN_PARENT); layout.setLayoutParams(layoutParams); // the proress bar ProgressBar bar = new ProgressBar(this.appView.getContext()); LinearLayout.LayoutParams barLayoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); barLayoutParams.gravity = Gravity.CENTER; bar.setLayoutParams(barLayoutParams); layout.addView(bar); mVideoProgressView = layout; } return mVideoProgressView; }
From source file:fr.cph.chicago.core.adapter.FavoritesAdapter.java
private void handleBikeStation(@NonNull final FavoritesViewHolder holder, @NonNull final BikeStation bikeStation) { holder.stationNameTextView.setText(bikeStation.getName()); holder.favoriteImage.setImageResource(R.drawable.ic_directions_bike_white_24dp); holder.detailsButton.setOnClickListener(v -> { if (!Util.isNetworkAvailable(context)) { Util.showNetworkErrorMessage(activity); } else if (bikeStation.getLatitude() != 0 && bikeStation.getLongitude() != 0) { final Intent intent = new Intent(activity.getApplicationContext(), BikeStationActivity.class); final Bundle extras = new Bundle(); extras.putParcelable(activity.getString(R.string.bundle_bike_station), bikeStation); intent.putExtras(extras);/*from w ww .j ava 2s. c o m*/ activity.startActivity(intent); } else { Util.showMessage(activity, R.string.message_not_ready); } }); holder.mapButton.setText(activity.getString(R.string.favorites_view_station)); holder.mapButton.setOnClickListener( new GoogleMapOnClickListener(bikeStation.getLatitude(), bikeStation.getLongitude())); final LinearLayout.LayoutParams containerParams = getInsideParams(true, true); final LinearLayout container = new LinearLayout(context); container.setOrientation(LinearLayout.VERTICAL); container.setLayoutParams(containerParams); final LinearLayout firstLine = createBikeFirstLine(bikeStation); container.addView(firstLine); final LinearLayout secondLine = createBikeSecondLine(bikeStation); container.addView(secondLine); holder.mainLayout.addView(container); }
From source file:nz.ac.auckland.lablet.script.components.TextComponent.java
@Override public View createView(Context context, Fragment parent) { ScriptTreeNodeSheetBase.Counter counter = this.component.getCounter("QuestionCounter"); // Note: we have to do this programmatically because findViewById would find the wrong child // items if there is more than one text question. LinearLayout layout = new LinearLayout(context); layout.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)); layout.setOrientation(LinearLayout.VERTICAL); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { layout.setBackgroundColor(context.getResources().getColor(R.color.sc_question_background_color, null)); } else {/* w w w. java 2 s . c o m*/ layout.setBackgroundColor(context.getResources().getColor(R.color.sc_question_background_color)); } TextView textView = new TextView(context); textView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT)); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { textView.setTextAppearance(android.R.style.TextAppearance_Medium); } else { textView.setTextAppearance(context, android.R.style.TextAppearance_Medium); } question_num = counter.increaseValue(); textView.setText("Q" + question_num + ": " + text); EditText editText = new EditText(context); editText.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)); editText.setText(answer); editText.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) { } @Override public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) { } @Override public void afterTextChanged(Editable editable) { answer = editable.toString(); update(); } }); layout.addView(textView); layout.addView(editText); return layout; }
From source file:fr.cph.chicago.core.adapter.FavoritesAdapter.java
@NonNull private LinearLayout createBikeLine(@NonNull final BikeStation bikeStation, final boolean firstLine) { final LinearLayout.LayoutParams lineParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);//from w w w .j av a2s . c o m final LinearLayout line = new LinearLayout(context); line.setOrientation(LinearLayout.HORIZONTAL); line.setLayoutParams(lineParams); // Left final LinearLayout.LayoutParams leftParam = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); final RelativeLayout left = new RelativeLayout(context); left.setLayoutParams(leftParam); final RelativeLayout lineIndication = LayoutUtil.createColoredRoundForFavorites(context, TrainLine.NA); int lineId = Util.generateViewId(); lineIndication.setId(lineId); final RelativeLayout.LayoutParams availableParam = new RelativeLayout.LayoutParams( LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); availableParam.addRule(RelativeLayout.RIGHT_OF, lineId); availableParam.setMargins(pixelsHalf, 0, 0, 0); final TextView boundCustomTextView = new TextView(context); boundCustomTextView.setText(activity.getString(R.string.bike_available_docks)); boundCustomTextView.setSingleLine(true); boundCustomTextView.setLayoutParams(availableParam); boundCustomTextView.setTextColor(grey5); int availableId = Util.generateViewId(); boundCustomTextView.setId(availableId); final RelativeLayout.LayoutParams availableValueParam = new RelativeLayout.LayoutParams( LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); availableValueParam.addRule(RelativeLayout.RIGHT_OF, availableId); availableValueParam.setMargins(pixelsHalf, 0, 0, 0); final TextView amountBike = new TextView(context); final String text = firstLine ? activity.getString(R.string.bike_available_bikes) : activity.getString(R.string.bike_available_docks); boundCustomTextView.setText(text); final Integer data = firstLine ? bikeStation.getAvailableBikes() : bikeStation.getAvailableDocks(); if (data == null) { amountBike.setText("?"); amountBike.setTextColor(ContextCompat.getColor(context, R.color.orange)); } else { amountBike.setText(String.valueOf(data)); final int color = data == 0 ? R.color.red : R.color.green; amountBike.setTextColor(ContextCompat.getColor(context, color)); } amountBike.setLayoutParams(availableValueParam); left.addView(lineIndication); left.addView(boundCustomTextView); left.addView(amountBike); line.addView(left); return line; }
From source file:com.klisly.bookbox.widget.draglistview.BoardView.java
public DragItemRecyclerView addColumnList(final DragItemAdapter adapter, final View header, boolean hasFixedItemSize) { final DragItemRecyclerView recyclerView = new DragItemRecyclerView(getContext()); recyclerView.setMotionEventSplittingEnabled(false); recyclerView.setDragItem(mDragItem); recyclerView.setLayoutParams(/* w w w . j a v a2s .c o m*/ new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT)); recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); recyclerView.setHasFixedSize(hasFixedItemSize); recyclerView.setItemAnimator(new DefaultItemAnimator()); recyclerView.setDragItemListener(new DragItemRecyclerView.DragItemListener() { @Override public void onDragStarted(int itemPosition, float x, float y) { mDragStartColumn = getColumnOfList(recyclerView); mDragStartRow = itemPosition; mCurrentRecyclerView = recyclerView; mDragItem.setOffset(((View) mCurrentRecyclerView.getParent()).getX(), mCurrentRecyclerView.getY()); if (mBoardListener != null) { mBoardListener.onItemDragStarted(mDragStartColumn, mDragStartRow); } invalidate(); } @Override public void onDragging(int itemPosition, float x, float y) { } @Override public void onDragEnded(int newItemPosition) { if (mBoardListener != null) { mBoardListener.onItemDragEnded(mDragStartColumn, mDragStartRow, getColumnOfList(recyclerView), newItemPosition); } } }); recyclerView.setAdapter(adapter); recyclerView.setDragEnabled(mDragEnabled); adapter.setDragStartedListener(new DragItemAdapter.DragStartCallback() { @Override public boolean startDrag(View itemView, long itemId) { return recyclerView.startDrag(itemView, itemId, getListTouchX(recyclerView), getListTouchY(recyclerView)); } @Override public boolean isDragging() { return recyclerView.isDragging(); } }); LinearLayout layout = new LinearLayout(getContext()); layout.setOrientation(LinearLayout.VERTICAL); layout.setLayoutParams(new LayoutParams(mColumnWidth, LayoutParams.MATCH_PARENT)); if (header != null) { layout.addView(header); mHeaders.put(mLists.size(), header); } layout.addView(recyclerView); mLists.add(recyclerView); mColumnLayout.addView(layout); return recyclerView; }
From source file:com.mooshim.mooshimeter.main.ScanActivity.java
private void addDevice(final MooshimeterDevice d) { mEmptyMsg.setVisibility(View.GONE); if (mMeterList.contains(d)) { // The meter as already been added Log.e(TAG, "Tried to add the same meter twice"); return;//w w w.j a v a 2 s. c o m } mMeterList.add(d); mMeterDict.put(d.getAddress(), d); final LinearLayout wrapper = new LinearLayout(this); wrapper.setOrientation(LinearLayout.VERTICAL); wrapper.setLayoutParams(mDeviceScrollView.getLayoutParams()); wrapper.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (d.mConnectionState == BluetoothProfile.STATE_CONNECTED || d.mConnectionState == BluetoothProfile.STATE_CONNECTING) { startSingleMeterActivity(d); } else { final Button bv = (Button) view.findViewById(R.id.btnConnect); toggleConnectionState(bv, d); } } }); wrapper.addView(mInflater.inflate(R.layout.element_mm_titlebar, wrapper, false)); //wrapper.setTag(Integer.valueOf(R.layout.element_mm_titlebar)); refreshMeterTile(d, wrapper); mDeviceScrollView.addView(wrapper); mTileList.add(wrapper); if (mMeterList.size() > 1) setStatus(mMeterList.size() + " devices"); else setStatus("1 device"); }
From source file:net.opendasharchive.openarchive.ReviewMediaActivity.java
private void deleteMedia() { final Switch swDeleteLocal = new Switch(this); final Switch swDeleteRemote = new Switch(this); LinearLayout linearLayoutGroup = new LinearLayout(this); linearLayoutGroup.setOrientation(LinearLayout.VERTICAL); linearLayoutGroup.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); swDeleteLocal.setTextOn(getString(R.string.answer_yes)); swDeleteLocal.setTextOff(getString(R.string.answer_no)); TextView tvLocal = new TextView(this); tvLocal.setText(R.string.delete_local); LinearLayout linearLayout = new LinearLayout(this); linearLayout.setOrientation(LinearLayout.HORIZONTAL); linearLayout.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); linearLayout.setGravity(Gravity.CENTER_HORIZONTAL); linearLayout.addView(tvLocal);/*from ww w. ja v a 2s . c om*/ linearLayout.addView(swDeleteLocal); linearLayoutGroup.addView(linearLayout); if (mMedia.getServerUrl() != null) { swDeleteRemote.setTextOn(getString(R.string.answer_yes)); swDeleteRemote.setTextOff(getString(R.string.answer_no)); TextView tvRemote = new TextView(this); tvRemote.setText(R.string.delete_remote); LinearLayout linearLayoutRemote = new LinearLayout(this); linearLayoutRemote.setOrientation(LinearLayout.HORIZONTAL); linearLayoutRemote.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); linearLayoutRemote.setGravity(Gravity.CENTER_HORIZONTAL); linearLayoutRemote.addView(tvRemote); linearLayoutRemote.addView(swDeleteRemote); linearLayoutGroup.addView(linearLayoutRemote); } AlertDialog.Builder build = new AlertDialog.Builder(ReviewMediaActivity.this).setTitle(R.string.menu_delete) .setMessage(R.string.alert_delete_media).setView(linearLayoutGroup).setCancelable(true) .setNegativeButton(R.string.dialog_cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { //do nothing } }) .setPositiveButton(R.string.dialog_ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { deleteMedia(swDeleteLocal.isChecked(), swDeleteRemote.isChecked()); finish(); } }); build.create().show(); }
From source file:oyagev.projects.android.ArduCopter.BluetoothChat.java
private void addControl(String name, String type, int commandValue) { Log.d(TAG, "Adding cmd: " + commandValue); LinearLayout row = new LinearLayout(this); row.setOrientation(LinearLayout.HORIZONTAL); row.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)); View view = new TextView(this); //hidden view for command value TextView cmdView = new TextView(this); cmdView.setLayoutParams(new LinearLayout.LayoutParams(0, 0)); cmdView.setVisibility(View.INVISIBLE); cmdView.setText(String.valueOf(commandValue)); cmdView.setTag("cmd"); //Setup the control if (type.equals("Button")) { view = new Button(this); ((Button) view).setText(name); ((Button) view).setOnClickListener(new OnClickListener() { @Override/*from www .j a v a 2 s. c o m*/ public void onClick(View v) { TextView cmd = (TextView) ((LinearLayout) v.getParent()).findViewWithTag("cmd"); dispatchUserEvent((int) Integer.valueOf(cmd.getText().toString()), new byte[] { 1 }); } }); } else if (type.equals("Edit")) { view = new EditText(this); ((EditText) view).setText(name); } else if (type.equals("Label")) { view = new TextView(this); ((TextView) view).setText(name); } else if (type.equals("Scrollbar")) { view = new LinearLayout(this); TextView text = new TextView(this); text.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT)); text.setText(name); text.setTag("seek_text"); SeekBar bar = new SeekBar(this); bar.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)); ((LinearLayout) view).setOrientation(LinearLayout.VERTICAL); ((LinearLayout) view).addView(text); ((LinearLayout) view).addView(bar); bar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() { @Override public void onStopTrackingTouch(SeekBar seekBar) { // TODO Auto-generated method stub } @Override public void onStartTrackingTouch(SeekBar seekBar) { // TODO Auto-generated method stub } @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { TextView cmd = (TextView) ((LinearLayout) ((LinearLayout) seekBar.getParent()).getParent()) .findViewWithTag("cmd"); ByteBuffer buffer = ByteBuffer.allocate(2); buffer.putShort((short) progress); dispatchUserEvent((int) Integer.valueOf(cmd.getText().toString()), buffer.array()); } }); } else if (type.equals("Input String")) { view = new LinearLayout(this); TextView text = new TextView(this); text.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT)); text.setText(name); text.setTag("inp_text"); TextView inp = new TextView(this); inp.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)); //((LinearLayout)view).setOrientation(LinearLayout.VERTICAL); ((LinearLayout) view).addView(text); ((LinearLayout) view).addView(inp); ycomm.registerCallback((byte) commandValue, new CallbackView(getApplicationContext(), inp) { @Override public void run(byte type, byte command, byte[] data, byte data_langth) { // TODO Auto-generated method stub String str = new String(data); ((TextView) this.view).setText(str); } }); } else { return; } view.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)); row.addView(cmdView); row.addView(view); ((LinearLayout) findViewById(R.id.controls_layout)).addView(row); }
From source file:fr.cph.chicago.activity.StationActivity.java
@SuppressWarnings("unchecked") @Override// w w w . j av a 2s . c o m protected final void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); ChicagoTracker.checkTrainData(this); if (!this.isFinishing()) { // Load data DataHolder dataHolder = DataHolder.getInstance(); this.mTrainData = dataHolder.getTrainData(); mIds = new HashMap<String, Integer>(); // Load right xml setContentView(R.layout.activity_station); // Get station id from bundle extra if (mStationId == null) { mStationId = getIntent().getExtras().getInt("stationId"); } // Get station from station id mStation = mTrainData.getStation(mStationId); MultiMap<String, String> reqParams = new MultiValueMap<String, String>(); reqParams.put("mapid", String.valueOf(mStation.getId())); new LoadData().execute(reqParams); // Call google street api to load image new DisplayGoogleStreetPicture().execute(mStation.getStops().get(0).getPosition()); this.mIsFavorite = isFavorite(); TextView textView = (TextView) findViewById(R.id.activity_bike_station_station_name); textView.setText(mStation.getName().toString()); mStreetViewImage = (ImageView) findViewById(R.id.activity_bike_station_streetview_image); mStreetViewText = (TextView) findViewById(R.id.activity_bike_station_steetview_text); mMapImage = (ImageView) findViewById(R.id.activity_bike_station_map_image); mDirectionImage = (ImageView) findViewById(R.id.activity_bike_station_map_direction); mFavoritesImage = (ImageView) findViewById(R.id.activity_bike_station_favorite_star); if (mIsFavorite) { mFavoritesImage.setImageDrawable(getResources().getDrawable(R.drawable.ic_save_active)); } mFavoritesImage.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { StationActivity.this.switchFavorite(); } }); LinearLayout stopsView = (LinearLayout) findViewById(R.id.activity_bike_station_details); this.mParamsStop = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); Map<TrainLine, List<Stop>> stops = mStation.getStopByLines(); CheckBox checkBox = null; for (Entry<TrainLine, List<Stop>> e : stops.entrySet()) { final TrainLine line = e.getKey(); List<Stop> stopss = e.getValue(); Collections.sort(stopss); LayoutInflater layoutInflater = (LayoutInflater) ChicagoTracker.getAppContext() .getSystemService(Context.LAYOUT_INFLATER_SERVICE); View view = layoutInflater.inflate(R.layout.activity_station_line_title, null); TextView lineTextView = (TextView) view.findViewById(R.id.activity_bus_station_value); lineTextView.setText(line.toStringWithLine()); TextView lineColorTextView = (TextView) view.findViewById(R.id.activity_bus_color); lineColorTextView.setBackgroundColor(line.getColor()); stopsView.addView(view); for (final Stop stop : stopss) { LinearLayout line2 = new LinearLayout(this); line2.setOrientation(LinearLayout.HORIZONTAL); line2.setLayoutParams(mParamsStop); checkBox = new CheckBox(this); checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { Preferences.saveTrainFilter(mStationId, line, stop.getDirection(), isChecked); } }); checkBox.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // Update timing MultiMap<String, String> reqParams = new MultiValueMap<String, String>(); reqParams.put("mapid", String.valueOf(mStation.getId())); new LoadData().execute(reqParams); } }); checkBox.setChecked(Preferences.getTrainFilter(mStationId, line, stop.getDirection())); checkBox.setText(stop.getDirection().toString()); checkBox.setTextColor(getResources().getColor(R.color.grey)); line2.addView(checkBox); stopsView.addView(line2); LinearLayout line3 = new LinearLayout(this); line3.setOrientation(LinearLayout.VERTICAL); line3.setLayoutParams(mParamsStop); int id3 = Util.generateViewId(); line3.setId(id3); mIds.put(line.toString() + "_" + stop.getDirection().toString(), id3); stopsView.addView(line3); } } getActionBar().setDisplayHomeAsUpEnabled(true); Util.trackScreen(this, R.string.analytics_train_details); } }
From source file:com.farmerbb.taskbar.service.DashboardService.java
@SuppressLint("RtlHardcoded") private void drawDashboard() { windowManager = (WindowManager) getSystemService(WINDOW_SERVICE); final WindowManager.LayoutParams params = new WindowManager.LayoutParams( WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.TYPE_PHONE, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM, PixelFormat.TRANSLUCENT);/*w w w .j a v a 2s. c o m*/ // Initialize views layout = new LinearLayout(this); layout.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); layout.setVisibility(View.GONE); layout.setAlpha(0); SharedPreferences pref = U.getSharedPreferences(this); int width = pref.getInt("dashboard_width", getApplicationContext().getResources().getInteger(R.integer.dashboard_width)); int height = pref.getInt("dashboard_height", getApplicationContext().getResources().getInteger(R.integer.dashboard_height)); boolean isPortrait = getApplicationContext().getResources() .getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT; boolean isLandscape = getApplicationContext().getResources() .getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE; if (isPortrait) { columns = height; rows = width; } if (isLandscape) { columns = width; rows = height; } maxSize = columns * rows; int backgroundTint = U.getBackgroundTint(this); int accentColor = U.getAccentColor(this); int accentColorAlt = accentColor; accentColorAlt = ColorUtils.setAlphaComponent(accentColorAlt, Color.alpha(accentColorAlt) / 2); int cellCount = 0; for (int i = 0; i < columns; i++) { LinearLayout layout2 = new LinearLayout(this); layout2.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, 1)); layout2.setOrientation(LinearLayout.VERTICAL); for (int j = 0; j < rows; j++) { DashboardCell cellLayout = (DashboardCell) View.inflate(this, R.layout.dashboard, null); cellLayout.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, 1)); cellLayout.setBackgroundColor(backgroundTint); cellLayout.setOnClickListener(cellOcl); cellLayout.setOnHoverListener(cellOhl); TextView empty = (TextView) cellLayout.findViewById(R.id.empty); empty.setBackgroundColor(accentColorAlt); empty.setTextColor(accentColor); Bundle bundle = new Bundle(); bundle.putInt("cellId", cellCount); cellLayout.setTag(bundle); cells.put(cellCount, cellLayout); cellCount++; layout2.addView(cellLayout); } layout.addView(layout2); } mAppWidgetManager = AppWidgetManager.getInstance(this); mAppWidgetHost = new AppWidgetHost(this, APPWIDGET_HOST_ID); mAppWidgetHost.startListening(); for (int i = 0; i < maxSize; i++) { int appWidgetId = pref.getInt("dashboard_widget_" + Integer.toString(i), -1); if (appWidgetId != -1) addWidget(appWidgetId, i, false); else if (pref.getBoolean("dashboard_widget_" + Integer.toString(i) + "_placeholder", false)) addPlaceholder(i); } mAppWidgetHost.stopListening(); LocalBroadcastManager.getInstance(this).unregisterReceiver(toggleReceiver); LocalBroadcastManager.getInstance(this).unregisterReceiver(addWidgetReceiver); LocalBroadcastManager.getInstance(this).unregisterReceiver(removeWidgetReceiver); LocalBroadcastManager.getInstance(this).unregisterReceiver(hideReceiver); LocalBroadcastManager.getInstance(this).registerReceiver(toggleReceiver, new IntentFilter("com.farmerbb.taskbar.TOGGLE_DASHBOARD")); LocalBroadcastManager.getInstance(this).registerReceiver(addWidgetReceiver, new IntentFilter("com.farmerbb.taskbar.ADD_WIDGET_COMPLETED")); LocalBroadcastManager.getInstance(this).registerReceiver(removeWidgetReceiver, new IntentFilter("com.farmerbb.taskbar.REMOVE_WIDGET_COMPLETED")); LocalBroadcastManager.getInstance(this).registerReceiver(hideReceiver, new IntentFilter("com.farmerbb.taskbar.HIDE_DASHBOARD")); windowManager.addView(layout, params); new Handler().postDelayed(() -> { int paddingSize = getResources().getDimensionPixelSize(R.dimen.icon_size); switch (U.getTaskbarPosition(DashboardService.this)) { case "top_vertical_left": case "bottom_vertical_left": layout.setPadding(paddingSize, 0, 0, 0); break; case "top_left": case "top_right": layout.setPadding(0, paddingSize, 0, 0); break; case "top_vertical_right": case "bottom_vertical_right": layout.setPadding(0, 0, paddingSize, 0); break; case "bottom_left": case "bottom_right": layout.setPadding(0, 0, 0, paddingSize); break; } }, 100); }