List of usage examples for android.widget RelativeLayout addView
public void addView(View child, int index)
From source file:com.nextgis.mobile.MapFragment.java
protected void addMapButtons(RelativeLayout rl) { mivZoomIn = new ImageView(getActivity()); mivZoomIn.setImageResource(R.drawable.ic_plus); //mivZoomIn.setId(R.drawable.ic_plus); mivZoomOut = new ImageView(getActivity()); mivZoomOut.setImageResource(R.drawable.ic_minus); //mivZoomOut.setId(R.drawable.ic_minus); final ImageView ivMark = new ImageView(getActivity()); ivMark.setImageResource(R.drawable.ic_mark); //ivMark.setId(R.drawable.ic_mark); //show zoom level between plus and minus mivZoomLevel = new TextView(getActivity()); //ivZoomLevel.setAlpha(150); mivZoomLevel.setId(R.drawable.ic_zoomlevel); final float scale = getResources().getDisplayMetrics().density; int pixels = (int) (48 * scale + 0.5f); mivZoomLevel.setTextSize(TypedValue.COMPLEX_UNIT_SP, 30); //ivZoomLevel.setTextAppearance(this, android.R.attr.textAppearanceLarge); mivZoomLevel.setWidth(pixels);// ww w. j a v a 2 s . co m mivZoomLevel.setHeight(pixels); mivZoomLevel.setTextColor(Color.DKGRAY); mivZoomLevel.setBackgroundColor(Color.argb(50, 128, 128, 128)); //Color.LTGRAY R.drawable.ic_zoomlevel); mivZoomLevel.setGravity(Gravity.CENTER); mivZoomLevel.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); mivZoomLevel.setText("" + (int) Math.floor(mMap.getZoomLevel())); mivZoomIn.setOnClickListener(new OnClickListener() { public void onClick(View v) { mMap.zoomIn(); } }); mivZoomOut.setOnClickListener(new OnClickListener() { public void onClick(View v) { mMap.zoomOut(); } }); ivMark.setOnClickListener(new OnClickListener() { public void onClick(View v) { //TODO: onMark(); } }); final RelativeLayout.LayoutParams RightParams1 = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); RightParams1.setMargins(mMargings + 5, mMargings - 5, mMargings + 5, mMargings - 5); RightParams1.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); RightParams1.addRule(RelativeLayout.CENTER_IN_PARENT);//ALIGN_PARENT_TOP rl.addView(mivZoomLevel, RightParams1); final RelativeLayout.LayoutParams RightParams4 = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); RightParams4.setMargins(mMargings + 5, mMargings - 5, mMargings + 5, mMargings - 5); RightParams4.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); RightParams4.addRule(RelativeLayout.ABOVE, R.drawable.ic_zoomlevel);//ALIGN_PARENT_TOP rl.addView(mivZoomIn, RightParams4); final RelativeLayout.LayoutParams RightParams3 = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); RightParams3.setMargins(mMargings + 5, mMargings - 5, mMargings + 5, mMargings - 5); RightParams3.addRule(RelativeLayout.ALIGN_PARENT_LEFT); RightParams3.addRule(RelativeLayout.CENTER_IN_PARENT);//ALIGN_PARENT_TOP rl.addView(ivMark, RightParams3); final RelativeLayout.LayoutParams RightParams2 = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); RightParams2.setMargins(mMargings + 5, mMargings - 5, mMargings + 5, mMargings - 5); RightParams2.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); RightParams2.addRule(RelativeLayout.BELOW, R.drawable.ic_zoomlevel);//R.drawable.ic_plus); rl.addView(mivZoomOut, RightParams2); setZoomInEnabled(mMap.canZoomIn()); setZoomOutEnabled(mMap.canZoomOut()); }
From source file:id.co.datascrip.dtswarehousesystem.activity.Form_Scan_Scandid.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); bundle = getIntent().getBundleExtra("bundle"); initScanner();/*ww w .ja v a 2 s . c om*/ RelativeLayout overlayView = mPicker.getOverlayView(); final FloatingActionButton floatingActionButton = new FloatingActionButton(this); floatingActionButton.setImageDrawable(ContextCompat.getDrawable(this, R.drawable.ic_create_white_18dp)); ShitTextView tx_title = new ShitTextView(this); tx_title.setText(bundle.getString("TitleScan")); ShitTextView tx_input_manual = new ShitTextView(this); tx_input_manual.setText(bundle.getString("TitleInput").trim().replace(":", "")); floatingActionButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Dialog_Input_Manual dialog = new Dialog_Input_Manual(Form_Scan_Scandid.this, bundle); dialog.setOnDismissListener(new DialogInterface.OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { if (!Function.isEmpty(no)) { Intent intent = new Intent(); intent.putExtra(getString(R.string.intent_result_scan), no); setResult(RESULT_OK, intent); no = ""; finish(); } } }); } }); RelativeLayout.LayoutParams rParams = new RelativeLayout.LayoutParams( AppBarLayout.LayoutParams.WRAP_CONTENT, AppBarLayout.LayoutParams.WRAP_CONTENT); rParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); rParams.topMargin = 60; rParams.rightMargin = 20; RelativeLayout.LayoutParams infoParam = new RelativeLayout.LayoutParams( AppBarLayout.LayoutParams.WRAP_CONTENT, AppBarLayout.LayoutParams.WRAP_CONTENT); infoParam.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); infoParam.topMargin = 20; infoParam.rightMargin = 10; tx_input_manual.setTextColor(ContextCompat.getColor(this, R.color.GREEN)); tx_title.setTypeface(Typeface.createFromAsset(getAssets(), "fonts/Felbridge-Light.otf")); RelativeLayout.LayoutParams titleParam = new RelativeLayout.LayoutParams( AppBarLayout.LayoutParams.MATCH_PARENT, AppBarLayout.LayoutParams.WRAP_CONTENT); titleParam.topMargin = 300; titleParam.leftMargin = 50; tx_title.setTextSize(24); tx_title.setTextColor(ContextCompat.getColor(this, R.color.GREEN)); tx_title.setTypeface(Typeface.createFromAsset(getAssets(), "fonts/Felbridge-Bold.otf")); overlayView.addView(floatingActionButton, rParams); overlayView.addView(tx_input_manual, infoParam); overlayView.addView(tx_title, titleParam); }
From source file:com.wit.and.dialog.LoginDialog.java
/** * /* w w w. j a va2s . c om*/ */ @Override protected View onCreateBodyView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final Context context = inflater.getContext(); RelativeLayout layout = new RelativeLayout(context); // Apply neutral layout params. layout.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); // Do not allow to apply style to body view. // layout.setId(R.id.Dialog_Layout_Body); // Create layout for loading view. LinearLayout loadingLayout = new LinearLayout(context); loadingLayout.setOrientation(LinearLayout.HORIZONTAL); loadingLayout.setGravity(Gravity.CENTER_VERTICAL); // Allow styling of loading layout as body layout. loadingLayout.setId(R.id.And_Dialog_Layout_Body); // Create text view for message. TextView msgTextView = new TextView(context); msgTextView.setId(R.id.And_Dialog_TextView_Message); // Create circle progress bar. ProgressBar circleProgressBar = new ProgressBar(context); circleProgressBar.setId(R.id.And_Dialog_ProgressBar); // Build loading view. loadingLayout.addView(circleProgressBar, new LinearLayout.LayoutParams( LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT)); loadingLayout.addView(msgTextView, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT)); loadingLayout.setVisibility(View.GONE); // Insert loading layout into main body layout. RelativeLayout.LayoutParams loadingLayoutParams = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); loadingLayoutParams.addRule(RelativeLayout.CENTER_IN_PARENT); layout.addView(loadingLayout, loadingLayoutParams); // Create layout for edit texts. LinearLayout editLayout = new LinearLayout(context); editLayout.setOrientation(LinearLayout.VERTICAL); editLayout.setId(R.id.And_Dialog_Layout_LoginDialog_EditView); // Create edit texts for username and password. EditText userEdit = new EditText(context); userEdit.setId(R.id.And_Dialog_EditText_Username); userEdit.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS); EditText passEdit = new EditText(context); passEdit.setId(R.id.And_Dialog_EditText_Password); passEdit.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD); // Create edit texts divider. DialogDivider divider = new DialogDivider(context); divider.setId(R.id.And_Dialog_Divider_LoginDialog_EditTexts); // Build edit layout. editLayout.addView(userEdit, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)); editLayout.addView(divider, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)); editLayout.addView(passEdit, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)); // Add custom layout. View customView = onCreateCustomView(inflater, editLayout, savedInstanceState); if (customView != null) { editLayout.addView(this.mCustomView = customView); } // Insert edit layout into main body layout. RelativeLayout.LayoutParams editLayoutParams = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); editLayoutParams.addRule(RelativeLayout.CENTER_IN_PARENT); layout.addView(editLayout, editLayoutParams); return layout; }
From source file:com.luseen.spacenavigation.SpaceNavigationView.java
@Override protected void onSizeChanged(int w, int h, int oldw, int oldh) { super.onSizeChanged(w, h, oldw, oldh); /**//from w ww .j a v a 2 s.co m * Restore current item index from savedInstance */ restoreCurrentItem(); /** * Trow exceptions if items size is greater than 4 or lesser than 2 */ if (spaceItems.size() < 2) { throw new NullPointerException("Your space item count must be greater than 1 ," + " your current items count is : " + spaceItems.size()); } if (spaceItems.size() > 4) { throw new IndexOutOfBoundsException( "Your items count maximum can be 4," + " your current items count is : " + spaceItems.size()); } /** * Get left or right content width */ contentWidth = (w - spaceNavigationHeight) / 2; /** * Removing all view for not being duplicated */ removeAllViews(); /** * Views initializations and customizing */ RelativeLayout mainContent = new RelativeLayout(context); RelativeLayout centreBackgroundView = new RelativeLayout(context); LinearLayout leftContent = new LinearLayout(context); LinearLayout rightContent = new LinearLayout(context); BezierView centreContent = buildBezierView(); FloatingActionButton fab = new FloatingActionButton(context); fab.setSize(FloatingActionButton.SIZE_NORMAL); fab.setBackgroundTintList(ColorStateList.valueOf(centreButtonColor)); fab.setImageResource(centreButtonIcon); fab.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { if (spaceOnClickListener != null) spaceOnClickListener.onCentreButtonClick(); } }); /** * Set fab layout params */ LayoutParams fabParams = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); fabParams.addRule(RelativeLayout.CENTER_IN_PARENT); fabParams.setMargins(centreContentMargin, centreContentMargin, centreContentMargin, centreContentMargin); /** * Main content size */ LayoutParams mainContentParams = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, mainContentHeight); mainContentParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); /** * Centre content size */ LayoutParams centreContentParams = new LayoutParams(centreContentWight, spaceNavigationHeight); centreContentParams.addRule(RelativeLayout.CENTER_HORIZONTAL); /** * Centre Background View content size and position */ LayoutParams centreBackgroundViewParams = new LayoutParams(centreContentWight, mainContentHeight); centreBackgroundViewParams.addRule(RelativeLayout.CENTER_HORIZONTAL); centreBackgroundViewParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); /** * Left content size */ LayoutParams leftContentParams = new LayoutParams(contentWidth, ViewGroup.LayoutParams.MATCH_PARENT); leftContentParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT); leftContentParams.addRule(LinearLayout.HORIZONTAL); /** * Right content size */ LayoutParams rightContentParams = new LayoutParams(contentWidth, ViewGroup.LayoutParams.MATCH_PARENT); rightContentParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); rightContentParams.addRule(LinearLayout.HORIZONTAL); /** * Adding views background colors */ leftContent.setBackgroundColor(spaceBackgroundColor); rightContent.setBackgroundColor(spaceBackgroundColor); centreBackgroundView.setBackgroundColor(spaceBackgroundColor); /** * Adding view to centreContent */ centreContent.addView(fab, fabParams); /** * Adding views to mainContent */ mainContent.addView(leftContent, leftContentParams); mainContent.addView(rightContent, rightContentParams); /** * Adding views to mainView */ addView(centreBackgroundView, centreBackgroundViewParams); addView(centreContent, centreContentParams); addView(mainContent, mainContentParams); /** * Adding current space items to left and right content */ addSpaceItems(leftContent, rightContent); /** * Redraw main view to make subviews visible */ Utils.postRequestLayout(this); }
From source file:com.max2idea.android.limbo.main.LimboActivity.java
public void promptVNCAllowExternal(final Activity activity) { final AlertDialog alertDialog; alertDialog = new AlertDialog.Builder(activity).create(); alertDialog.setTitle("Enable VNC server"); TextView textView = new TextView(activity); textView.setVisibility(View.VISIBLE); textView.setId(201012010);//from www. j a v a2 s . com textView.setText("VNC Server: " + this.getLocalIpAddress() + ":" + "5901\n" + "Warning: VNC is not secure make sure you're on a private network!\n"); EditText passwdView = new EditText(activity); passwdView.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD); passwdView.setHint("Password"); passwdView.setEnabled(true); passwdView.setVisibility(View.VISIBLE); passwdView.setId(11111); passwdView.setSingleLine(); RelativeLayout mLayout = new RelativeLayout(this); mLayout.setId(12222); RelativeLayout.LayoutParams textViewParams = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT); textViewParams.addRule(RelativeLayout.ALIGN_PARENT_TOP, mLayout.getId()); mLayout.addView(textView, textViewParams); RelativeLayout.LayoutParams passwordViewParams = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT); passwordViewParams.addRule(RelativeLayout.BELOW, textView.getId()); // passwordViewParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, // mLayout.getId()); mLayout.addView(passwdView, passwordViewParams); alertDialog.setView(mLayout); final Handler handler = this.handler; alertDialog.setButton("Set", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // UIUtils.log("Searching..."); EditText a = (EditText) alertDialog.findViewById(11111); if (a.getText().toString().trim().equals("")) { Toast.makeText(getApplicationContext(), "Password cannot be empty!", Toast.LENGTH_SHORT).show(); vnc_passwd = null; vnc_allow_external = 0; mVNCAllowExternal.setChecked(false); // LimboSettingsManager.setVNCAllowExternal(activity, false); return; } else { sendHandlerMessage(handler, Const.VNC_PASSWORD, "vnc_passwd", "passwd"); vnc_passwd = a.getText().toString(); vnc_allow_external = 1; // LimboSettingsManager.setVNCAllowExternal(activity, true); } } }); alertDialog.setButton2("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { vnc_passwd = null; vnc_allow_external = 0; mVNCAllowExternal.setChecked(false); // LimboSettingsManager.setVNCAllowExternal(activity, false); return; } }); alertDialog.setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { mVNCAllowExternal.setChecked(false); // LimboSettingsManager.setVNCAllowExternal(activity, false); vnc_passwd = null; vnc_allow_external = 0; } }); alertDialog.show(); }
From source file:com.max2idea.android.limbo.main.LimboActivity.java
public void promptImageName(final Activity activity, String hd) { final String hd_string = hd; final AlertDialog alertDialog; alertDialog = new AlertDialog.Builder(activity).create(); alertDialog.setTitle("Image Name"); RelativeLayout mLayout = new RelativeLayout(this); mLayout.setId(12222);// w ww .j a va 2s . co m EditText imageNameView = new EditText(activity); imageNameView.setEnabled(true); imageNameView.setVisibility(View.VISIBLE); imageNameView.setId(201012010); imageNameView.setSingleLine(); RelativeLayout.LayoutParams searchViewParams = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT); mLayout.addView(imageNameView, searchViewParams); final Spinner size = new Spinner(this); RelativeLayout.LayoutParams setPlusParams = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT); size.setId(201012044); String[] arraySpinner = new String[7]; for (int i = 0; i < arraySpinner.length; i++) { if (i < 5) { arraySpinner[i] = (i + 1) + " GB"; } } arraySpinner[5] = "10 GB"; arraySpinner[6] = "20 GB"; ArrayAdapter sizeAdapter = new ArrayAdapter(this, android.R.layout.simple_spinner_item, arraySpinner); sizeAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); size.setAdapter(sizeAdapter); setPlusParams.addRule(RelativeLayout.BELOW, imageNameView.getId()); mLayout.addView(size, setPlusParams); // TODO: Not working for now // final TextView preallocText = new TextView(this); // preallocText.setText("Preallocate? "); // preallocText.setTextSize(15); // RelativeLayout.LayoutParams preallocTParams = new // RelativeLayout.LayoutParams( // RelativeLayout.LayoutParams.WRAP_CONTENT, // RelativeLayout.LayoutParams.WRAP_CONTENT); // preallocTParams.addRule(RelativeLayout.BELOW, size.getId()); // mLayout.addView(preallocText, preallocTParams); // preallocText.setId(64512044); // // final CheckBox prealloc = new CheckBox(this); // RelativeLayout.LayoutParams preallocParams = new // RelativeLayout.LayoutParams( // RelativeLayout.LayoutParams.WRAP_CONTENT, // RelativeLayout.LayoutParams.WRAP_CONTENT); // preallocParams.addRule(RelativeLayout.BELOW, size.getId()); // preallocParams.addRule(RelativeLayout.RIGHT_OF, // preallocText.getId()); // preallocParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, // preallocText.getId()); // mLayout.addView(prealloc, preallocParams); // prealloc.setId(64512344); alertDialog.setView(mLayout); final Handler handler = this.handler; // alertDialog.setMessage(body); alertDialog.setButton("Create", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { int sizeSel = size.getSelectedItemPosition(); String templateImage = "hd1g.qcow2"; if (sizeSel < 5) { templateImage = "hd" + (sizeSel + 1) + "g.qcow2"; } else if (sizeSel == 5) { templateImage = "hd10g.qcow2"; } else if (sizeSel == 6) { templateImage = "hd20g.qcow2"; } // UIUtils.log("Searching..."); EditText a = (EditText) alertDialog.findViewById(201012010); progDialog = ProgressDialog.show(activity, "Please Wait", "Creating HD Image...", true); // CreateImage createImg = new // CreateImage(a.getText().toString(), // hd_string, sizeInt, prealloc.isChecked()); // CreateImage createImg = new CreateImage(a.getText().toString(), // hd_string, sizeInt, false); // createImg.execute(); String image = a.getText().toString(); if (!image.endsWith(".qcow2")) { image += ".qcow2"; } createImg(templateImage, image, hd_string); } }); alertDialog.show(); }
From source file:com.max2idea.android.limbo.main.LimboActivity.java
private void promptImportMachines() { // TODO Auto-generated method stub final AlertDialog alertDialog; alertDialog = new AlertDialog.Builder(activity).create(); alertDialog.setTitle("Import Machines"); RelativeLayout mLayout = new RelativeLayout(this); mLayout.setId(12222);//w w w .j a va 2 s . c o m TextView imageNameView = new TextView(activity); imageNameView.setVisibility(View.VISIBLE); imageNameView.setId(201012010); imageNameView.setText( "Step 1: Place the machine.CSV file you export previously under \"limbo\" directory in your SD card.\n" + "Step 2: WARNING: Any machine with the same name will be replaced!\n" + "Step 3: Press \"OK\".\n"); RelativeLayout.LayoutParams searchViewParams = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT); mLayout.addView(imageNameView, searchViewParams); alertDialog.setView(mLayout); final Handler handler = this.handler; // alertDialog.setMessage(body); alertDialog.setButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // For each line create a Machine progDialog = ProgressDialog.show(activity, "Please Wait", "Importing Machines...", true); ImportMachines importer = new ImportMachines(); importer.execute(); } }); alertDialog.setButton2("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { return; } }); alertDialog.setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { return; } }); alertDialog.show(); }
From source file:processing.core.PApplet.java
/** Called with the activity is first created. */ @Override//from w ww . j a v a2 s . com public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { super.onCreateView(inflater, container, savedInstanceState); // println("PApplet.onCreate()"); if (DEBUG) println("onCreate() happening here: " + Thread.currentThread().getName()); // commented to use fragments /* * Window window = getWindow(); * * // Take up as much area as possible * requestWindowFeature(Window.FEATURE_NO_TITLE); * window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN, * WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN); * * // This does the actual full screen work * window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, * WindowManager.LayoutParams.FLAG_FULLSCREEN); */ DisplayMetrics dm = new DisplayMetrics(); this.getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm); displayWidth = dm.widthPixels; displayHeight = dm.heightPixels; // println("density is " + dm.density); // println("densityDpi is " + dm.densityDpi); if (DEBUG) println("display metrics: " + dm); // println("screen size is " + screenWidth + "x" + screenHeight); // LinearLayout layout = new LinearLayout(this); // layout.setOrientation(LinearLayout.VERTICAL | // LinearLayout.HORIZONTAL); // viewGroup = new ViewGroup(); // surfaceView.setLayoutParams(); // viewGroup.setLayoutParams(LayoutParams.) // RelativeLayout layout = new RelativeLayout(this); // RelativeLayout overallLayout = new RelativeLayout(this); // RelativeLayout.LayoutParams lp = new // RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, // RelativeLayout.LayoutParams.FILL_PARENT); // lp.addRule(RelativeLayout.RIGHT_OF, tv1.getId()); // layout.setGravity(RelativeLayout.CENTER_IN_PARENT); int sw = sketchWidth(); int sh = sketchHeight(); if (sketchRenderer().equals(JAVA2D)) { surfaceView = new SketchSurfaceView(this.getActivity(), sw, sh); } else if (sketchRenderer().equals(P2D) || sketchRenderer().equals(P3D)) { surfaceView = new SketchSurfaceViewGL(this.getActivity(), sw, sh, sketchRenderer().equals(P3D)); } // g = ((SketchSurfaceView) surfaceView).getGraphics(); // surfaceView.setLayoutParams(new LayoutParams(sketchWidth(), // sketchHeight())); // layout.addView(surfaceView); // surfaceView.setVisibility(1); // println("visibility " + surfaceView.getVisibility() + " " + // SurfaceView.VISIBLE); // layout.addView(surfaceView); // AttributeSet as = new AttributeSet(); // RelativeLayout.LayoutParams lp = new // RelativeLayout.LayoutParams(layout, as); // lp.addRule(android.R.styleable.ViewGroup_Layout_layout_height, // layout.add // lp.addRule(, arg1) // layout.addView(surfaceView, sketchWidth(), sketchHeight()); // new // RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, // RelativeLayout.LayoutParams.FILL_PARENT); if (sw == displayWidth && sh == displayHeight) { // If using the full screen, don't embed inside other layouts // window.setContentView(surfaceView); no para fragments } else { // If not using full screen, setup awkward view-inside-a-view so // that // the sketch can be centered on screen. (If anyone has a more // efficient // way to do this, please file an issue on Google Code, otherwise // you // can keep your "talentless hack" comments to yourself. Ahem.) RelativeLayout overallLayout = new RelativeLayout(this.getActivity()); overallLayout.setBackgroundColor(0x00000000); RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); lp.addRule(RelativeLayout.CENTER_IN_PARENT); LinearLayout layout = new LinearLayout(this.getActivity()); layout.setBackgroundColor(0x00000000); layout.addView(surfaceView, sketchWidth(), sketchHeight()); overallLayout.addView(layout, lp); // window.setContentView(overallLayout); no para fragments } /* * // Here we use Honeycomb API (11+) to hide (in reality, just make the * status icons into small dots) // the status bar. Since the core is * still built against API 7 (2.1), we use introspection to get // the * setSystemUiVisibility() method from the view class. Method * visibilityMethod = null; try { visibilityMethod = * surfaceView.getClass().getMethod("setSystemUiVisibility", new Class[] * { int.class}); } catch (NoSuchMethodException e) { // Nothing to do. * This means that we are running with a version of Android previous to * Honeycomb. } if (visibilityMethod != null) { try { // This is * equivalent to calling: * //surfaceView.setSystemUiVisibility(View.STATUS_BAR_HIDDEN); // The * value of View.STATUS_BAR_HIDDEN is 1. * visibilityMethod.invoke(surfaceView, new Object[] { 1 }); } catch * (InvocationTargetException e) { } catch (IllegalAccessException e) { * } } window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, * WindowManager.LayoutParams.FLAG_FULLSCREEN); */ // layout.addView(surfaceView, lp); // surfaceView.setLayoutParams(new LayoutParams(sketchWidth(), // sketchHeight())); // RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams() // layout.addView(surfaceView, new LayoutParams(arg0) // TODO probably don't want to set these here, can't we wait for // surfaceChanged()? // removing this in 0187 // width = screenWidth; // height = screenHeight; // int left = (screenWidth - iwidth) / 2; // int right = screenWidth - (left + iwidth); // int top = (screenHeight - iheight) / 2; // int bottom = screenHeight - (top + iheight); // surfaceView.setPadding(left, top, right, bottom); // android:layout_width // window.setContentView(surfaceView); // set full screen // code below here formerly from init() // millisOffset = System.currentTimeMillis(); // moved to the variable // declaration finished = false; // just for clarity // this will be cleared by draw() if it is not overridden looping = true; redraw = true; // draw this guy once firstMotion = true; // these need to be inited before setup sizeMethods = new RegisteredMethods(); preMethods = new RegisteredMethods(); drawMethods = new RegisteredMethods(); postMethods = new RegisteredMethods(); mouseEventMethods = new RegisteredMethods(); keyEventMethods = new RegisteredMethods(); disposeMethods = new RegisteredMethods(); Context context = this.getActivity().getApplicationContext(); sketchPath = context.getFilesDir().getAbsolutePath(); // Looper.prepare(); handler = new Handler(); // println("calling loop()"); // Looper.loop(); // println("done with loop() call, will continue..."); start(); return surfaceView; }
From source file:com.processing.core.PApplet.java
/** Called with the activity is first created. */ @Override/*from w w w . j a va 2s. c om*/ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // println("PApplet.onCreate()"); if (DEBUG) println("onCreate() happening here: " + Thread.currentThread().getName()); Window window = getWindow(); // Take up as much area as possible requestWindowFeature(Window.FEATURE_NO_TITLE); window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN, WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN); // This does the actual full screen work window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); DisplayMetrics dm = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(dm); displayWidth = dm.widthPixels; displayHeight = dm.heightPixels; // println("density is " + dm.density); // println("densityDpi is " + dm.densityDpi); if (DEBUG) println("display metrics: " + dm); //println("screen size is " + screenWidth + "x" + screenHeight); // LinearLayout layout = new LinearLayout(this); // layout.setOrientation(LinearLayout.VERTICAL | LinearLayout.HORIZONTAL); // viewGroup = new ViewGroup(); // surfaceView.setLayoutParams(); // viewGroup.setLayoutParams(LayoutParams.) // RelativeLayout layout = new RelativeLayout(this); // RelativeLayout overallLayout = new RelativeLayout(this); // RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.FILL_PARENT); //lp.addRule(RelativeLayout.RIGHT_OF, tv1.getId()); // layout.setGravity(RelativeLayout.CENTER_IN_PARENT); int sw = sketchWidth(); int sh = sketchHeight(); if (sketchRenderer().equals(JAVA2D)) { surfaceView = new SketchSurfaceView(this, sw, sh); } else if (sketchRenderer().equals(P2D) || sketchRenderer().equals(P3D)) { surfaceView = new SketchSurfaceViewGL(this, sw, sh, sketchRenderer().equals(P3D)); } // g = ((SketchSurfaceView) surfaceView).getGraphics(); // surfaceView.setLayoutParams(new LayoutParams(sketchWidth(), sketchHeight())); // layout.addView(surfaceView); // surfaceView.setVisibility(1); // println("visibility " + surfaceView.getVisibility() + " " + SurfaceView.VISIBLE); // layout.addView(surfaceView); // AttributeSet as = new AttributeSet(); // RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(layout, as); // lp.addRule(android.R.styleable.ViewGroup_Layout_layout_height, // layout.add //lp.addRule(, arg1) //layout.addView(surfaceView, sketchWidth(), sketchHeight()); // new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, // RelativeLayout.LayoutParams.FILL_PARENT); if (sw == displayWidth && sh == displayHeight) { // If using the full screen, don't embed inside other layouts window.setContentView(surfaceView); } else { // If not using full screen, setup awkward view-inside-a-view so that // the sketch can be centered on screen. (If anyone has a more efficient // way to do this, please file an issue on Google Code, otherwise you // can keep your "talentless hack" comments to yourself. Ahem.) RelativeLayout overallLayout = new RelativeLayout(this); RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); lp.addRule(RelativeLayout.CENTER_IN_PARENT); LinearLayout layout = new LinearLayout(this); layout.addView(surfaceView, sketchWidth(), sketchHeight()); overallLayout.addView(layout, lp); window.setContentView(overallLayout); } /* // Here we use Honeycomb API (11+) to hide (in reality, just make the status icons into small dots) // the status bar. Since the core is still built against API 7 (2.1), we use introspection to get // the setSystemUiVisibility() method from the view class. Method visibilityMethod = null; try { visibilityMethod = surfaceView.getClass().getMethod("setSystemUiVisibility", new Class[] { int.class}); } catch (NoSuchMethodException e) { // Nothing to do. This means that we are running with a version of Android previous to Honeycomb. } if (visibilityMethod != null) { try { // This is equivalent to calling: //surfaceView.setSystemUiVisibility(View.STATUS_BAR_HIDDEN); // The value of View.STATUS_BAR_HIDDEN is 1. visibilityMethod.invoke(surfaceView, new Object[] { 1 }); } catch (InvocationTargetException e) { } catch (IllegalAccessException e) { } } window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); */ // layout.addView(surfaceView, lp); // surfaceView.setLayoutParams(new LayoutParams(sketchWidth(), sketchHeight())); // RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams() // layout.addView(surfaceView, new LayoutParams(arg0) // TODO probably don't want to set these here, can't we wait for surfaceChanged()? // removing this in 0187 // width = screenWidth; // height = screenHeight; // int left = (screenWidth - iwidth) / 2; // int right = screenWidth - (left + iwidth); // int top = (screenHeight - iheight) / 2; // int bottom = screenHeight - (top + iheight); // surfaceView.setPadding(left, top, right, bottom); // android:layout_width // window.setContentView(surfaceView); // set full screen // code below here formerly from init() //millisOffset = System.currentTimeMillis(); // moved to the variable declaration finished = false; // just for clarity // this will be cleared by draw() if it is not overridden looping = true; redraw = true; // draw this guy once // firstMotion = true; Context context = getApplicationContext(); sketchPath = context.getFilesDir().getAbsolutePath(); // Looper.prepare(); handler = new Handler(); // println("calling loop()"); // Looper.loop(); // println("done with loop() call, will continue..."); start(); }
From source file:com.codename1.impl.android.AndroidImplementation.java
@Override public Object showNativePicker(final int type, final Component source, final Object currentValue, final Object data) { if (getActivity() == null) { return null; }//w w w. j a v a2 s . co m final boolean[] canceled = new boolean[1]; final boolean[] dismissed = new boolean[1]; if (editInProgress()) { stopEditing(true); } if (type == Display.PICKER_TYPE_TIME) { class TimePick implements TimePickerDialog.OnTimeSetListener, TimePickerDialog.OnCancelListener, Runnable { int result = ((Integer) currentValue).intValue(); public void onTimeSet(TimePicker tp, int hour, int minute) { result = hour * 60 + minute; dismissed[0] = true; synchronized (this) { notify(); } } public void run() { while (!dismissed[0]) { synchronized (this) { try { wait(50); } catch (InterruptedException er) { } } } } @Override public void onCancel(DialogInterface di) { dismissed[0] = true; canceled[0] = true; synchronized (this) { notify(); } } } final TimePick pickInstance = new TimePick(); getActivity().runOnUiThread(new Runnable() { public void run() { int hour = ((Integer) currentValue).intValue() / 60; int minute = ((Integer) currentValue).intValue() % 60; TimePickerDialog tp = new TimePickerDialog(getActivity(), pickInstance, hour, minute, true) { @Override public void cancel() { super.cancel(); dismissed[0] = true; canceled[0] = true; } @Override public void dismiss() { super.dismiss(); dismissed[0] = true; } }; tp.setOnCancelListener(pickInstance); //DateFormat.is24HourFormat(activity)); tp.show(); } }); Display.getInstance().invokeAndBlock(pickInstance); if (canceled[0]) { return null; } return new Integer(pickInstance.result); } if (type == Display.PICKER_TYPE_DATE) { final java.util.Calendar cl = java.util.Calendar.getInstance(); if (currentValue != null) { cl.setTime((Date) currentValue); } class DatePick implements DatePickerDialog.OnDateSetListener, DatePickerDialog.OnCancelListener, Runnable { Date result = (Date) currentValue; public void onDateSet(DatePicker dp, int year, int month, int day) { java.util.Calendar c = java.util.Calendar.getInstance(); c.set(java.util.Calendar.YEAR, year); c.set(java.util.Calendar.MONTH, month); c.set(java.util.Calendar.DAY_OF_MONTH, day); result = c.getTime(); dismissed[0] = true; synchronized (this) { notify(); } } public void run() { while (!dismissed[0]) { synchronized (this) { try { wait(50); } catch (InterruptedException er) { } } } } public void onCancel(DialogInterface di) { result = null; dismissed[0] = true; canceled[0] = true; synchronized (this) { notify(); } } } final DatePick pickInstance = new DatePick(); getActivity().runOnUiThread(new Runnable() { public void run() { DatePickerDialog tp = new DatePickerDialog(getActivity(), pickInstance, cl.get(java.util.Calendar.YEAR), cl.get(java.util.Calendar.MONTH), cl.get(java.util.Calendar.DAY_OF_MONTH)) { @Override public void cancel() { super.cancel(); dismissed[0] = true; canceled[0] = true; } @Override public void dismiss() { super.dismiss(); dismissed[0] = true; } }; tp.setOnCancelListener(pickInstance); tp.show(); } }); Display.getInstance().invokeAndBlock(pickInstance); return pickInstance.result; } if (type == Display.PICKER_TYPE_STRINGS) { final String[] values = (String[]) data; class StringPick implements Runnable, NumberPicker.OnValueChangeListener { int result = -1; StringPick() { } public void run() { while (!dismissed[0]) { synchronized (this) { try { wait(50); } catch (InterruptedException er) { } } } } public void cancel() { dismissed[0] = true; canceled[0] = true; synchronized (this) { notify(); } } public void ok() { canceled[0] = false; dismissed[0] = true; synchronized (this) { notify(); } } @Override public void onValueChange(NumberPicker np, int oldVal, int newVal) { result = newVal; } } final StringPick pickInstance = new StringPick(); for (int iter = 0; iter < values.length; iter++) { if (values[iter].equals(currentValue)) { pickInstance.result = iter; break; } } if (pickInstance.result == -1 && values.length > 0) { // The picker will default to showing the first element anyways // If we don't set the result to 0, then the user has to first // scroll to a different number, then back to the first option // to pick the first option. pickInstance.result = 0; } getActivity().runOnUiThread(new Runnable() { public void run() { NumberPicker picker = new NumberPicker(getActivity()); if (source.getClientProperty("showKeyboard") == null) { picker.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS); } picker.setMinValue(0); picker.setMaxValue(values.length - 1); picker.setDisplayedValues(values); picker.setOnValueChangedListener(pickInstance); if (pickInstance.result > -1) { picker.setValue(pickInstance.result); } RelativeLayout linearLayout = new RelativeLayout(getActivity()); RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(50, 50); RelativeLayout.LayoutParams numPicerParams = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); numPicerParams.addRule(RelativeLayout.CENTER_HORIZONTAL); linearLayout.setLayoutParams(params); linearLayout.addView(picker, numPicerParams); AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(getActivity()); alertDialogBuilder.setView(linearLayout); alertDialogBuilder.setCancelable(false) .setPositiveButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { pickInstance.ok(); } }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); pickInstance.cancel(); } }); AlertDialog alertDialog = alertDialogBuilder.create(); alertDialog.show(); } }); Display.getInstance().invokeAndBlock(pickInstance); if (canceled[0]) { return null; } if (pickInstance.result < 0) { return null; } return values[pickInstance.result]; } return null; }