List of usage examples for android.widget FrameLayout addView
public void addView(View child)
Adds a child view.
From source file:com.ashlikun.badgeview.BadgeView.java
public void setTargetView(View target) { if (getParent() != null) { ((ViewGroup) getParent()).removeView(this); }//from w w w .j a va 2 s . com if (target == null) { return; } if (target.getParent() instanceof FrameLayout) { ((FrameLayout) target.getParent()).addView(this); } else if (target.getParent() instanceof ViewGroup) { // use a new Framelayout container for adding badge ViewGroup parentContainer = (ViewGroup) target.getParent(); int groupIndex = parentContainer.indexOfChild(target); parentContainer.removeView(target); FrameLayout badgeContainer = new FrameLayout(getContext()); ViewGroup.LayoutParams parentLayoutParams = target.getLayoutParams(); badgeContainer.setLayoutParams(parentLayoutParams); target.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); parentContainer.addView(badgeContainer, groupIndex, parentLayoutParams); badgeContainer.addView(target); badgeContainer.addView(this); } else if (target.getParent() == null) { Log.e(getClass().getSimpleName(), "ParentView is needed"); } }
From source file:io.github.yavski.fabspeeddial.FabSpeedDial.java
@Override protected void onAttachedToWindow() { super.onAttachedToWindow(); LayoutParams layoutParams = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); int coordinatorLayoutOffset = getResources().getDimensionPixelSize(R.dimen.coordinator_layout_offset); if (fabGravity == BOTTOM_END || fabGravity == TOP_END) { layoutParams.setMargins(0, 0, coordinatorLayoutOffset, 0); } else {/*from w ww . j a v a2s. c o m*/ layoutParams.setMargins(coordinatorLayoutOffset, 0, 0, 0); } menuItemsLayout.setLayoutParams(layoutParams); // Set up the client's FAB fab = (FloatingActionButton) findViewById(R.id.fab); fab.setImageDrawable(fabDrawable); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { fab.setImageTintList(fabDrawableTint); } if (fabBackgroundTint != null) { fab.setBackgroundTintList(fabBackgroundTint); } fab.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (isAnimating) return; if (isMenuOpen()) { closeMenu(); } else { openMenu(); } } }); // Needed in order to intercept key events setFocusableInTouchMode(true); if (useTouchGuard) { ViewParent parent = getParent(); touchGuard = new View(getContext()); touchGuard.setOnClickListener(this); touchGuard.setWillNotDraw(true); touchGuard.setVisibility(GONE); if (touchGuardDrawable != null) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { touchGuard.setBackground(touchGuardDrawable); } else { //noinspection deprecation touchGuard.setBackgroundDrawable(touchGuardDrawable); } } if (parent instanceof FrameLayout) { FrameLayout frameLayout = (FrameLayout) parent; frameLayout.addView(touchGuard); bringToFront(); } else if (parent instanceof CoordinatorLayout) { CoordinatorLayout coordinatorLayout = (CoordinatorLayout) parent; coordinatorLayout.addView(touchGuard); bringToFront(); } else if (parent instanceof RelativeLayout) { RelativeLayout relativeLayout = (RelativeLayout) parent; relativeLayout.addView(touchGuard, new RelativeLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); bringToFront(); } else { Log.d(TAG, "touchGuard requires that the parent of this FabSpeedDialer be a FrameLayout or RelativeLayout"); } } setOnClickListener(this); if (shouldOpenMenu) openMenu(); }
From source file:com.radicaldynamic.groupinform.activities.LauncherActivity.java
private void displaySplash() { // Don't show the splash screen if this app appears to be registered if (PreferenceManager.getDefaultSharedPreferences(getApplicationContext()) .getString(InformOnlineState.DEVICE_ID, null) instanceof String) { return;/*from w w w . ja v a2 s .c o m*/ } // Fetch the splash screen Drawable Drawable image = null; try { // Attempt to load the configured default splash screen // The following code only works in 1.6+ // BitmapDrawable bitImage = new BitmapDrawable(getResources(), FileUtils.SPLASH_SCREEN_FILE_PATH); BitmapDrawable bitImage = new BitmapDrawable( FileUtilsExtended.EXTERNAL_FILES + File.separator + FileUtilsExtended.SPLASH_SCREEN_FILE); if (bitImage.getBitmap() != null && bitImage.getIntrinsicHeight() > 0 && bitImage.getIntrinsicWidth() > 0) { image = bitImage; } } catch (Exception e) { // TODO: log exception for debugging? } // TODO: rework if (image == null) { // no splash provided... // if (FileUtils.storageReady() && !((new File(FileUtils.DEFAULT_CONFIG_PATH)).exists())) { // Show the built-in splash image if the config directory // does not exist. Otherwise, suppress the icon. image = getResources().getDrawable(R.drawable.gc_color); // } if (image == null) return; } // Create ImageView to hold the Drawable... ImageView view = new ImageView(getApplicationContext()); // Initialise it with Drawable and full-screen layout parameters view.setImageDrawable(image); int width = getWindowManager().getDefaultDisplay().getWidth(); int height = getWindowManager().getDefaultDisplay().getHeight(); FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(width, height, 0); view.setLayoutParams(lp); view.setScaleType(ScaleType.CENTER); view.setBackgroundColor(Color.WHITE); // And wrap the image view in a frame layout so that the full-screen layout parameters are honoured FrameLayout layout = new FrameLayout(getApplicationContext()); layout.addView(view); // Create the toast and set the view to be that of the FrameLayout mSplashToast = Toast.makeText(getApplicationContext(), "splash screen", Toast.LENGTH_LONG); mSplashToast.setView(layout); mSplashToast.setGravity(Gravity.CENTER, 0, 0); mSplashToast.show(); }
From source file:com.gome.haoyuangong.views.MyViewPageIndicator.java
private void addTab(int index, CharSequence text, int iconResId) { final TabView tabView = new TabView(getContext()); tabView.mIndex = index;/*from w w w . j a v a 2s.c om*/ tabView.setTag("tavView"); tabView.setId(index); // tabView.setFocusable(true); // tabView.setOnClickListener(mTabClickListener); tabView.setText(text); //tabView.setPadding(pointSize, 0, pointSize, 0); tabView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16); tabView.setMaxLines(1); tabView.setGravity(Gravity.CENTER); XmlPullParser xrp = getResources().getXml(R.drawable.tab_button); try { ColorStateList csl = ColorStateList.createFromXml(getResources(), xrp); tabView.setTextColor(csl); } catch (Exception e) { } if (iconResId != 0) { //tabView.setCompoundDrawablesWithIntrinsicBounds(iconResId, 0, 0, 0); } FrameLayout.LayoutParams tabTvL = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); tabView.setLayoutParams(tabTvL); //measureView(tabView); LinearLayout layoutWraper1 = new LinearLayout(getContext()); LinearLayout.LayoutParams lp1 = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, 1); layoutWraper1.setLayoutParams(lp1); layoutWraper1.setGravity(Gravity.CENTER); layoutWraper1.setFocusable(true); layoutWraper1.setOnClickListener(mTabClickListener); layoutWraper1.setPadding(0, 0, 0, 0); layoutWraper1.setBackgroundResource(R.drawable.tab_btn_red); FrameLayout frameLayout = new FrameLayout(getContext()); frameLayout.setTag("framelayout"); // FrameLayout.LayoutParams fl2 = new FrameLayout.LayoutParams(tabView.getMeasuredWidth() + padding, tabView.getMeasuredHeight()+ (int)(padding * 1.5)); FrameLayout.LayoutParams fl2 = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); // frameLayout.setPadding(padding, padding, padding, padding); frameLayout.setLayoutParams(fl2); // frameLayout.addView(tabView); View hasNew = new View(getContext()); FrameLayout.LayoutParams hasNewL = new FrameLayout.LayoutParams(pointSize, pointSize); hasNew.setLayoutParams(hasNewL); hasNewL.gravity = Gravity.TOP | Gravity.RIGHT; hasNew.setBackgroundResource(R.drawable.shape_circle); FrameLayout tabTvframe = new FrameLayout(getContext()); FrameLayout.LayoutParams tabTvframeL = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); tabTvframeL.gravity = Gravity.CENTER; tabTvframe.setLayoutParams(tabTvframeL); tabTvframe.addView(tabView); tabTvframe.addView(hasNew); hasNew.setVisibility(View.GONE); frameLayout.addView(tabTvframe); layoutWraper1.addView(frameLayout); tabView.setTagView(hasNew); mTabLayout.addView(layoutWraper1, new LinearLayout.LayoutParams(0, MATCH_PARENT, 1)); }
From source file:fr.tvbarthel.attempt.googlyzooapp.MainActivity.java
@Override public void onPreviewInitialized(FrameLayout preview) { preview.addView(mRoundedOverlay); preview.addView(mCameraInstructions); preview.addView(mCapturePreview, mCapturePreviewParams); preview.addView(mSaveButton, mSaveButtonParams); preview.addView(mShareButton, mShareButtonParams); preview.setOnTouchListener(MainActivity.this); }
From source file:eu.inmite.apps.smsjizdenka.framework.about.BaseAboutFragment.java
@Override public void onViewCreated(View view, Bundle savedInstanceState) { FrameLayout vCustomPart = (FrameLayout) view.findViewById(R.id.part_custom); ImageView vAppIcon = (ImageView) view.findViewById(R.id.part_app_icon); TextView vVersion = (TextView) view.findViewById(R.id.part_version); TextView vOpensource = (TextView) view.findViewById(R.id.part_opensource); TextView vAppName = (TextView) view.findViewById(R.id.part_app_name); if (isVisible(PART_CUSTOM)) { View customView = getCustomPart(); if (customView != null) { vCustomPart.setVisibility(View.VISIBLE); vCustomPart.addView(customView); }/* w ww. jav a 2s .c om*/ } else { vCustomPart.setVisibility(View.GONE); } if (isVisible(PART_APP_NAME)) { vAppName.setText( getActivity().getApplicationInfo().loadLabel(getActivity().getPackageManager()).toString()); } else { vAppName.setVisibility(View.GONE); } if (isVisible(PART_APP_ICON)) { if (getAppIcon() != 0) { vAppIcon.setImageResource(getAppIcon()); } vAppIcon.setVisibility(View.VISIBLE); vAppIcon.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { IntentUtils.openBrowser(getActivity(), "http://www.avast.com"); } }); } else { vAppIcon.setVisibility(View.GONE); } if (isVisible(PART_VERSION)) { vVersion.setVisibility(View.VISIBLE); setupVersion(vVersion); } else { vVersion.setVisibility(View.GONE); } if (isVisible(PART_OPENSOURCE)) { vOpensource.setVisibility(View.VISIBLE); setupLink(vOpensource, new View.OnClickListener() { @Override public void onClick(View view) { openOpenSourceDialog(); } }); } else { vOpensource.setVisibility(View.GONE); } }
From source file:io.tehtotalpwnage.musicphp_android.NavigationActivity.java
@Override public boolean onNavigationItemSelected(@NonNull MenuItem item) { // Handle navigation view item clicks here. int id = item.getItemId(); if (id == R.id.nav_camera) { // Everything after this point is actually my code. StringRequest req = new StringRequest(Request.Method.GET, UrlGenerator.getServerUrl(this) + "/api/user", new Response.Listener<String>() { @Override// www .j a v a 2s.co m public void onResponse(String response) { TextView view = new TextView(getApplicationContext()); view.setText(response); FrameLayout layout = (FrameLayout) findViewById(R.id.navFrame); layout.removeAllViews(); layout.addView(view); } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { Log.v(TAG, "Connection error"); TextView view = new TextView(getApplicationContext()); view.setText(getResources().getString(R.string.error_connection)); FrameLayout layout = (FrameLayout) findViewById(R.id.navFrame); layout.removeAllViews(); layout.addView(view); NetworkResponse networkResponse = error.networkResponse; if (networkResponse != null && networkResponse.statusCode == HttpURLConnection.HTTP_UNAUTHORIZED) { Log.v(TAG, "Request was unauthorized, meaning that a new token is needed"); AccountManager manager = AccountManager.get(getApplicationContext()); manager.invalidateAuthToken(MusicPhpAccount.ACCOUNT_TYPE, getIntent().getStringExtra(AccountManager.KEY_AUTHTOKEN)); Intent intent = new Intent(NavigationActivity.this, MainActivity.class); startActivity(intent); } } }) { @Override public Map<String, String> getHeaders() throws AuthFailureError { Map<String, String> params = new HashMap<>(); params.put("Accept", "application/json"); params.put("Authorization", "Bearer " + getIntent().getStringExtra(AccountManager.KEY_AUTHTOKEN)); return params; } }; VolleySingleton.getInstance(this).addToRequestQueue(req); } else if (id == R.id.nav_gallery) { final Context context = this; getListing(Item.albums, 0, new VolleyCallback() { @Override public void onSuccess(JSONArray result) { Log.d(TAG, "Volley callback reached"); String albums[][] = new String[result.length()][3]; for (int i = 0; i < result.length(); i++) { try { JSONObject object = result.getJSONObject(i); albums[i][0] = object.getString("name"); albums[i][1] = object.getJSONObject("artist").getString("name"); albums[i][2] = object.getString("id"); } catch (Exception e) { e.printStackTrace(); } } AlbumListingAdapter adapter = new AlbumListingAdapter(context, albums, getIntent().getStringExtra(AccountManager.KEY_AUTHTOKEN)); GridView view = new GridView(context); view.setLayoutParams(new DrawerLayout.LayoutParams(ActionBar.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); view.setNumColumns(GridView.AUTO_FIT); view.setColumnWidth((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 148, getResources().getDisplayMetrics())); view.setStretchMode(GridView.STRETCH_SPACING_UNIFORM); view.setAdapter(adapter); view.setVerticalSpacing((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, getResources().getDisplayMetrics())); FrameLayout layout = (FrameLayout) findViewById(R.id.navFrame); layout.removeAllViews(); layout.addView(view); Log.d(TAG, "Adapter setup complete"); } }); } else if (id == R.id.nav_slideshow) { getListing(Item.artists, 0, new VolleyCallback() { @Override public void onSuccess(JSONArray result) { } }); } else if (id == R.id.nav_manage) { getListing(Item.tracks, 0, new VolleyCallback() { @Override public void onSuccess(JSONArray result) { } }); } else if (id == R.id.nav_share) { Log.d(TAG, "Queue contains " + queue.size() + " items. Displaying queue..."); ListView view = new ListView(this); view.setLayoutParams(new DrawerLayout.LayoutParams(ActionBar.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); String tracks[][] = new String[queue.size()][2]; for (int i = 0; i < queue.size(); i++) { MediaSessionCompat.QueueItem queueItem = queue.get(i); tracks[i][0] = queueItem.getDescription().getMediaId(); tracks[i][1] = (String) queueItem.getDescription().getTitle(); } AlbumAdapter adapter = new AlbumAdapter(this, tracks, getIntent().getStringExtra(AccountManager.KEY_AUTHTOKEN), this); view.setAdapter(adapter); view.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { // String sAddress = getApplicationContext().getSharedPreferences("Prefs", 0).getString("server", null); // Bundle bundle = new Bundle(); // bundle.putString("Authorization", "Bearer " + token); // bundle.putString("Title", tracks[position][1]); // bundle.putString("art", getIntent().getStringExtra("art")); // bundle.putString("ID", tracks[position][0]); // MediaControllerCompat.getMediaController(AlbumActivity.this).getTransportControls().playFromUri(Uri.parse(sAddress + "/api/tracks/" + tracks[position][0] + "/audio"), bundle); } }); FrameLayout layout = (FrameLayout) findViewById(R.id.navFrame); layout.removeAllViews(); layout.addView(view); } else if (id == R.id.nav_send) { String sAddress = getSharedPreferences("Prefs", 0).getString("server", null); StringRequest request = new StringRequest(Request.Method.POST, sAddress + "/api/logout", new Response.Listener<String>() { @Override public void onResponse(String response) { try { JSONObject object = new JSONObject(response); if (object.getString("status").equals("OK")) { Log.v(TAG, "Logged out successfully. Now redirecting to MainActivity..."); AccountManager manager = AccountManager.get(getApplicationContext()); Account accounts[] = manager.getAccountsByType(MusicPhpAccount.ACCOUNT_TYPE); int account = 0; for (int i = 0; i < accounts.length; i++) { if (accounts[i].name.equals( getIntent().getStringExtra(AccountManager.KEY_ACCOUNT_NAME))) { account = i; break; } } final AccountManagerFuture future; if (Build.VERSION.SDK_INT >= 22) { future = manager.removeAccount(accounts[account], NavigationActivity.this, new AccountManagerCallback<Bundle>() { @Override public void run(AccountManagerFuture<Bundle> future) { } }, null); } else { future = manager.removeAccount(accounts[account], new AccountManagerCallback<Boolean>() { @Override public void run(AccountManagerFuture<Boolean> future) { } }, null); } AsyncTask<Void, Void, Void> task = new AsyncTask<Void, Void, Void>() { @Override protected Void doInBackground(Void... params) { try { future.getResult(); Intent intent = new Intent(NavigationActivity.this, MainActivity.class); startActivity(intent); } catch (Exception e) { e.printStackTrace(); } return null; } }; task.execute(); } else { Log.v(TAG, "Issue with logging out..."); } } catch (JSONException e) { Log.e(TAG, "Issue with parsing JSON..."); e.printStackTrace(); } } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { Log.e(TAG, "Error on logging out..."); } }) { @Override public Map<String, String> getHeaders() { Map<String, String> params = new HashMap<>(); params.put("Accept", "application/json"); params.put("Authorization", "Bearer " + getIntent().getStringExtra(AccountManager.KEY_AUTHTOKEN)); return params; } }; VolleySingleton.getInstance(this).addToRequestQueue(request); } DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); drawer.closeDrawer(GravityCompat.START); return true; }
From source file:com.itude.mobile.mobbl.core.view.components.tabbar.MBDefaultActionBarBuilder.java
@Override public synchronized void showProgressIndicatorInTool() { MBToolDefinition refreshToolDef = getRefreshToolDef(); Menu menu = _menu;/* ww w. j av a 2s .c om*/ if (refreshToolDef != null && menu != null) { final MenuItem item = menu.findItem(refreshToolDef.getName().hashCode()); ImageView rotationImage = getRotationImage(); float imageWidth = rotationImage.getDrawable().getIntrinsicWidth(); int framePadding = (int) ((ScreenUtil.convertDimensionPixelsToPixels(_context, 80) - imageWidth) / 2); final FrameLayout frameLayout = new FrameLayout(_context); frameLayout.setLayoutParams( new FrameLayout.LayoutParams(ScreenUtil.convertDimensionPixelsToPixels(_context, 80), LayoutParams.WRAP_CONTENT, Gravity.CENTER)); frameLayout.setPadding(framePadding, 0, framePadding, 0); frameLayout.addView(rotationImage); MBViewManager.getInstance().runOnUiThread(new MBThread() { @Override public void runMethod() { //item.setIcon(null); MenuItemCompat.setActionView(item, frameLayout); getRotationImage().getAnimation().startNow(); } }); } }
From source file:com.example.view.astuetz.PagerSlidingTabStrip.java
@SuppressLint("NewApi") private void addIconTab(int position, int resId, String notification) { FrameLayout tabItemCon = new FrameLayout(getContext()); ImageView tab = new ImageView(getContext()); tab.setImageResource(resId);/*from w ww. j a v a2 s . com*/ tabItemCon.addView(tab); tabIconlist.put(position, tab); ImageView notiSymbol = new ImageView(getContext()); notiSymbol.setImageResource(R.drawable.badge_background); BadgeView noti = new BadgeView(getContext()); noti.setText(notification); tabItemCon.addView(noti); tabItemCon.addView(notiSymbol); if (notification != null && !notification.equals("")) { noti.setVisibility(View.VISIBLE); notiSymbol.setVisibility(View.GONE); } else if (notification != null && notification.equals("")) { noti.setVisibility(View.GONE); notiSymbol.setVisibility(View.VISIBLE); } else { notiSymbol.setVisibility(View.GONE); noti.setVisibility(View.GONE); } int notiSySize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 20, getResources().getDisplayMetrics()); noti.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, Gravity.RIGHT | Gravity.TOP)); notiSymbol.setLayoutParams(new LayoutParams(notiSySize, notiSySize, Gravity.RIGHT | Gravity.TOP)); FrameLayout tabItem = new FrameLayout(getContext()); tabItem.addView(tabItemCon); tabItemCon.setLayoutParams( new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, Gravity.CENTER)); addTab(position, tabItem); }
From source file:com.ultramegasoft.flavordex2.fragment.EntryListFragment.java
@SuppressWarnings("ConstantConditions") @Override//w w w . j av a2 s .c o m public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final View root = inflater.inflate(R.layout.fragment_entry_list, container, false); final FrameLayout list = root.findViewById(R.id.list); list.addView(super.onCreateView(inflater, container, savedInstanceState)); return root; }