List of usage examples for android.view Gravity CENTER_VERTICAL
int CENTER_VERTICAL
To view the source code for android.view Gravity CENTER_VERTICAL.
Click Source Link
From source file:fr.tvbarthel.attempt.googlyzooapp.MainActivity.java
/** * set up saving button used to save screen capture *//*from w w w. ja v a 2 s . co m*/ private void setUpSavingButton() { mSaveButtonParams = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); mSaveButtonParams.gravity = Gravity.CENTER_VERTICAL | Gravity.LEFT; //set up button mSaveButton = new ImageButton(this); mSaveButton.setImageDrawable(getResources().getDrawable(R.drawable.ic_action_content_save_white)); mSaveButton.setBackgroundResource(R.drawable.rounded_right_corners); mSaveButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { new SaveAsyncTask().execute(); } }); mSaveButton.setVisibility(View.INVISIBLE); }
From source file:org.nla.tarotdroid.lib.ui.TabGameSetActivity.java
/** * Starts the whole Facebook post process. * /*from w w w . j a v a 2 s . c o m*/ * @param session */ private void launchPostProcess(final Session session) { LayoutInflater inflater = getLayoutInflater(); View layout = inflater.inflate(R.layout.toast, (ViewGroup) findViewById(R.id.toast_layout_root)); ImageView image = (ImageView) layout.findViewById(R.id.image); image.setImageResource(R.drawable.icon_facebook_released); TextView text = (TextView) layout.findViewById(R.id.text); text.setText(this.getString(R.string.msgFacebookNotificationInProgress)); Toast toast = new Toast(getApplicationContext()); toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0); toast.setDuration(Toast.LENGTH_LONG); toast.setView(layout); toast.show(); Request request = Request.newMeRequest(session, new Request.GraphUserCallback() { @Override public void onCompleted(GraphUser user, Response response) { if (session == Session.getActiveSession()) { if (user != null) { int notificationId = FacebookHelper.showNotificationStartProgress(TabGameSetActivity.this); AppContext.getApplication().getNotificationIds() .put(TabGameSetActivity.this.gameSet.getUuid(), notificationId); AppContext.getApplication().setLoggedFacebookUser(user); UpSyncGameSetTask task = new UpSyncGameSetTask(TabGameSetActivity.this, progressDialog); task.setCallback(TabGameSetActivity.this.upSyncCallback); task.execute(TabGameSetActivity.this.gameSet); } } if (response.getError() != null) { AuditHelper.auditErrorAsString(ErrorTypes.facebookNewMeRequestFailed, response.getError().toString(), TabGameSetActivity.this); } } }); request.executeAsync(); }
From source file:org.apache.cordova.inappbrowser.InAppBrowser.java
/** * Display a new browser with the specified URL. * * @param url The url to load. * @param jsonObject/* w w w.java2 s .c om*/ */ public String showWebPage(final String url, HashMap<String, Boolean> features) { // Determine if we should hide the location bar. showLocationBar = true; showZoomControls = true; openWindowHidden = false; if (features != null) { Boolean show = features.get(LOCATION); if (show != null) { showLocationBar = show.booleanValue(); } Boolean zoom = features.get(ZOOM); if (zoom != null) { showZoomControls = zoom.booleanValue(); } Boolean hidden = features.get(HIDDEN); if (hidden != null) { openWindowHidden = hidden.booleanValue(); } Boolean hardwareBack = features.get(HARDWARE_BACK_BUTTON); if (hardwareBack != null) { hadwareBackButton = hardwareBack.booleanValue(); } Boolean cache = features.get(CLEAR_ALL_CACHE); if (cache != null) { clearAllCache = cache.booleanValue(); } else { cache = features.get(CLEAR_SESSION_CACHE); if (cache != null) { clearSessionCache = cache.booleanValue(); } } } final CordovaWebView thatWebView = this.webView; // 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; } @SuppressLint("NewApi") public void run() { // Let's create the main dialog dialog = new InAppBrowserDialog(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.setInAppBroswer(getInAppBrowser()); // Main container layout LinearLayout main = new LinearLayout(cordova.getActivity()); main.setOrientation(LinearLayout.VERTICAL); // Toolbar layout RelativeLayout toolbar = new RelativeLayout(cordova.getActivity()); //Please, no more black! toolbar.setBackgroundColor(android.graphics.Color.LTGRAY); toolbar.setLayoutParams( new RelativeLayout.LayoutParams(LayoutParams.MATCH_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 Button back = new Button(cordova.getActivity()); RelativeLayout.LayoutParams backLayoutParams = new RelativeLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); backLayoutParams.addRule(RelativeLayout.ALIGN_LEFT); back.setLayoutParams(backLayoutParams); back.setContentDescription("Back Button"); back.setId(2); Resources activityRes = cordova.getActivity().getResources(); int backResId = activityRes.getIdentifier("ic_action_previous_item", "drawable", cordova.getActivity().getPackageName()); Drawable backIcon = activityRes.getDrawable(backResId); if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) { back.setBackgroundDrawable(backIcon); } else { back.setBackground(backIcon); } back.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { goBack(); } }); // Forward button Button forward = new Button(cordova.getActivity()); RelativeLayout.LayoutParams forwardLayoutParams = new RelativeLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); forwardLayoutParams.addRule(RelativeLayout.RIGHT_OF, 2); forward.setLayoutParams(forwardLayoutParams); forward.setContentDescription("Forward Button"); forward.setId(3); int fwdResId = activityRes.getIdentifier("ic_action_next_item", "drawable", cordova.getActivity().getPackageName()); Drawable fwdIcon = activityRes.getDrawable(fwdResId); if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) { forward.setBackgroundDrawable(fwdIcon); } else { forward.setBackground(fwdIcon); } 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.MATCH_PARENT, LayoutParams.MATCH_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/Done button Button close = new Button(cordova.getActivity()); RelativeLayout.LayoutParams closeLayoutParams = new RelativeLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); closeLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); close.setLayoutParams(closeLayoutParams); forward.setContentDescription("Close Button"); close.setId(5); int closeResId = activityRes.getIdentifier("ic_action_remove", "drawable", cordova.getActivity().getPackageName()); Drawable closeIcon = activityRes.getDrawable(closeResId); if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) { close.setBackgroundDrawable(closeIcon); } else { close.setBackground(closeIcon); } close.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { closeDialog(); } }); // WebView inAppWebView = new WebView(cordova.getActivity()); inAppWebView.setLayoutParams( new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); inAppWebView.setWebChromeClient(new InAppChromeClient(thatWebView)); WebViewClient client = new InAppBrowserClient(thatWebView, edittext); inAppWebView.setWebViewClient(client); WebSettings settings = inAppWebView.getSettings(); settings.setJavaScriptEnabled(true); settings.setJavaScriptCanOpenWindowsAutomatically(true); settings.setBuiltInZoomControls(getShowZoomControls()); settings.setPluginState(android.webkit.WebSettings.PluginState.ON); //Toggle whether this is enabled or not! Bundle appSettings = cordova.getActivity().getIntent().getExtras(); boolean enableDatabase = appSettings == null ? true : appSettings.getBoolean("InAppBrowserStorageEnabled", true); if (enableDatabase) { String databasePath = cordova.getActivity().getApplicationContext() .getDir("inAppBrowserDB", Context.MODE_PRIVATE).getPath(); settings.setDatabasePath(databasePath); settings.setDatabaseEnabled(true); } settings.setDomStorageEnabled(true); if (clearAllCache) { CookieManager.getInstance().removeAllCookie(); } else if (clearSessionCache) { CookieManager.getInstance().removeSessionCookie(); } inAppWebView.loadUrl(url); inAppWebView.setId(6); inAppWebView.getSettings().setLoadWithOverviewMode(true); inAppWebView.getSettings().setUseWideViewPort(true); inAppWebView.requestFocus(); inAppWebView.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(inAppWebView); WindowManager.LayoutParams lp = new WindowManager.LayoutParams(); lp.copyFrom(dialog.getWindow().getAttributes()); lp.width = WindowManager.LayoutParams.MATCH_PARENT; lp.height = WindowManager.LayoutParams.MATCH_PARENT; dialog.setContentView(main); dialog.show(); dialog.getWindow().setAttributes(lp); // the goal of openhidden is to load the url and not display it // Show() needs to be called to cause the URL to be loaded if (openWindowHidden) { dialog.hide(); } } }; this.cordova.getActivity().runOnUiThread(runnable); return ""; }
From source file:com.mixiaoxiao.mxxedgeeffect.widget.MxxPagerTitleStrip.java
void updateTextPositions(int position, float positionOffset, boolean force) { // position??item,currText // onPageScrolledpositionOffset>0.5fposition+1 if (position != mLastKnownCurrentPage) { updateText(position, mPager.getAdapter()); } else if (!force && positionOffset == mLastKnownPositionOffset) { return;//from ww w . j av a2 s .co m } // /////////////// if (positionOffset == 0f) { mPrevText.setTextColor(convertTextColor(0f)); mCurrText.setTextColor(convertTextColor(1f)); mNextText.setTextColor(convertTextColor(0f)); } else { // Log.d(TAG, "position->" + position + " positionOffset->" + positionOffset); float currPercent = positionOffset;// positionOffset=0.6 // currOffset=0.1 // boolean isOffsetAdding = (positionOffset - // mLastKnownPositionOffset)>0f;//offset if (currPercent <= 0.5f) {// mPrevText.setTextColor(convertTextColor(0f)); mCurrText.setTextColor(convertTextColor((1f - currPercent))); // if(isOffsetAdding){ mNextText.setTextColor(convertTextColor(currPercent)); // } } else {// // currPercent -= 0.5f; mPrevText.setTextColor(convertTextColor(1f - currPercent)); mCurrText.setTextColor(convertTextColor(currPercent)); mNextText.setTextColor(convertTextColor(0)); } // if (currPercent > 0.5f) { // currPercent -= 0.5f; // } // mPrevText.setTextColor(convertTextColor(currPercent)); } // mNextText.setTextColor(transparentColor); mUpdatingPositions = true; final int prevWidth = mPrevText.getMeasuredWidth(); final int currWidth = mCurrText.getMeasuredWidth(); final int nextWidth = mNextText.getMeasuredWidth(); final int halfCurrWidth = 0;// currWidth / 2; final int stripWidth = getWidth(); final int stripHeight = getHeight(); final int paddingLeft = getPaddingLeft(); final int paddingRight = getPaddingRight(); final int paddingTop = getPaddingTop(); final int paddingBottom = getPaddingBottom(); // final int textPaddedLeft = paddingLeft + halfCurrWidth; // final int textPaddedRight = paddingRight + halfCurrWidth; // final int contentWidth = prevWidth + currWidth + nextWidth;// stripWidth // - // textPaddedLeft // - // textPaddedRight; float currOffset = positionOffset + 0.5f;// positionOffset=0.6 // currOffset=0.1 if (currOffset > 1.f) { currOffset -= 1.f; } // float currOffset = positionOffset; // if (currOffset > 1.f) { // currOffset -= 1.f; // } final int currCenter = stripWidth / 2 - (int) (currWidth * (currOffset - 0.5f));// stripWidth // - // textPaddedRight // - // (int) // (contentWidth // * // currOffset); final int currLeft = currCenter - currWidth / 2; final int currRight = currLeft + currWidth; final int prevBaseline = mPrevText.getBaseline(); final int currBaseline = mCurrText.getBaseline(); final int nextBaseline = mNextText.getBaseline(); final int maxBaseline = Math.max(Math.max(prevBaseline, currBaseline), nextBaseline); final int prevTopOffset = maxBaseline - prevBaseline; final int currTopOffset = maxBaseline - currBaseline; final int nextTopOffset = maxBaseline - nextBaseline; final int alignedPrevHeight = prevTopOffset + mPrevText.getMeasuredHeight(); final int alignedCurrHeight = currTopOffset + mCurrText.getMeasuredHeight(); final int alignedNextHeight = nextTopOffset + mNextText.getMeasuredHeight(); final int maxTextHeight = Math.max(Math.max(alignedPrevHeight, alignedCurrHeight), alignedNextHeight); final int vgrav = mGravity & Gravity.VERTICAL_GRAVITY_MASK; int prevTop; int currTop; int nextTop; switch (vgrav) { default: case Gravity.TOP: prevTop = paddingTop + prevTopOffset; currTop = paddingTop + currTopOffset; nextTop = paddingTop + nextTopOffset; break; case Gravity.CENTER_VERTICAL: final int paddedHeight = stripHeight - paddingTop - paddingBottom; final int centeredTop = (paddedHeight - maxTextHeight) / 2; prevTop = centeredTop + prevTopOffset; currTop = centeredTop + currTopOffset; nextTop = centeredTop + nextTopOffset; break; case Gravity.BOTTOM: final int bottomGravTop = stripHeight - paddingBottom - maxTextHeight; prevTop = bottomGravTop + prevTopOffset; currTop = bottomGravTop + currTopOffset; nextTop = bottomGravTop + nextTopOffset; break; } mCurrText.layout(currLeft, currTop, currRight, currTop + mCurrText.getMeasuredHeight()); final int prevLeft = currLeft - mScaledTextSpacing - prevWidth;// Math.min(paddingLeft, // currLeft // - // mScaledTextSpacing // - // prevWidth); mPrevText.layout(prevLeft, prevTop, prevLeft + prevWidth, prevTop + mPrevText.getMeasuredHeight()); final int nextLeft = currRight + mScaledTextSpacing;// Math.max(stripWidth // - paddingRight - // nextWidth, // currRight + mScaledTextSpacing); mNextText.layout(nextLeft, nextTop, nextLeft + nextWidth, nextTop + mNextText.getMeasuredHeight()); mLastKnownPositionOffset = positionOffset; mUpdatingPositions = false; }
From source file:com.nbplus.vbroadlauncher.fragment.LauncherFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment View v = inflater.inflate(R.layout.fragment_launcher, container, false); mMainViewLayout = (LinearLayout) v.findViewById(R.id.main_view_layout); // push agent ??. mPushServiceStatus = (ImageView) v.findViewById(R.id.ic_nav_wifi); if (((BaseActivity) getActivity()).isPushServiceConnected()) { mPushServiceStatus.setImageResource(R.drawable.ic_nav_wifi_on); } else {//from w ww . jav a2s .c o m mPushServiceStatus.setImageResource(R.drawable.ic_nav_wifi_off); } mVillageName = (TextView) v.findViewById(R.id.launcher_village_name); mVillageName.setText(LauncherSettings.getInstance(getActivity()).getVillageName()); mApplicationsView = (LinearLayout) v.findViewById(R.id.ic_nav_apps); mApplicationsView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent intent = new Intent(getActivity(), ShowApplicationActivity.class); startActivity(intent); getActivity().overridePendingTransition(R.anim.fade_in, R.anim.fade_out); } }); mServiceTreeMap = (LinearLayout) v.findViewById(R.id.ic_nav_show_map); mServiceTreeMap.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (!NetworkUtils.isConnected(getActivity())) { ((BaseActivity) getActivity()).showNetworkConnectionAlertDialog(); return; } Intent intent = new Intent(getActivity(), BroadcastWebViewActivity.class); ShortcutData data = new ShortcutData(Constants.SHORTCUT_TYPE_WEB_DOCUMENT_SERVER, R.string.btn_show_map, getActivity().getResources().getString(R.string.addr_show_map), R.drawable.ic_menu_04, R.drawable.ic_menu_shortcut_02_selector, 0, null); VBroadcastServer serverInfo = LauncherSettings.getInstance(getActivity()).getServerInformation(); data.setDomain(serverInfo.getDocServer()); intent.putExtra(Constants.EXTRA_NAME_SHORTCUT_DATA, data); startActivity(intent); } }); mOutdoorMode = (LinearLayout) v.findViewById(R.id.ic_nav_outdoor); mOutdoorText = (TextView) v.findViewById(R.id.tv_outdoor); if (LauncherSettings.getInstance(getActivity()).isOutdoorMode()) { mOutdoorText.setTextColor(getResources().getColor(R.color.btn_color_absentia_on)); mOutdoorText.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_nav_absentia_on, 0, 0, 0); } else { mOutdoorText.setTextColor(getResources().getColor(R.color.btn_color_absentia_off)); mOutdoorText.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_nav_absentia_off, 0, 0, 0); } mOutdoorMode.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Toast toast; boolean mode = false; if (LauncherSettings.getInstance(getActivity()).isOutdoorMode()) { LauncherSettings.getInstance(getActivity()).setIsOutdoorMode(false); mOutdoorText.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_nav_absentia_off, 0, 0, 0); mOutdoorText.setTextColor(getResources().getColor(R.color.btn_color_absentia_off)); toast = Toast.makeText(getActivity(), R.string.outdoor_mode_off, Toast.LENGTH_SHORT); toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0); toast.show(); } else { mode = true; LauncherSettings.getInstance(getActivity()).setIsOutdoorMode(true); mOutdoorText.setTextColor(getResources().getColor(R.color.btn_color_absentia_on)); mOutdoorText.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_nav_absentia_on, 0, 0, 0); toast = Toast.makeText(getActivity(), R.string.outdoor_mode_on, Toast.LENGTH_SHORT); toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0); toast.show(); } HomeLauncherApplication application = (HomeLauncherApplication) getActivity() .getApplicationContext(); if (application != null) { application.outdoorModeChanged(mode); } } }); // ?? ? mIoTDataSync = (LinearLayout) v.findViewById(R.id.ic_iot_data_sync); mIoTDataSyncText = (TextView) v.findViewById(R.id.tv_iot_data_sync); mIoTDataSync.setOnClickListener(mIoTSyncClickListener); mIoTDataSync.setClickable(true); mIoTDataSync.setEnabled(true); mTextClock = (TextClock) v.findViewById(R.id.text_clock); if (mTextClock != null) { mTextClock.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { try { Intent intent = new Intent(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_APP_CALENDAR); startActivity(intent); getActivity().overridePendingTransition(R.anim.fade_in, R.anim.fade_out); } catch (ActivityNotFoundException e) { e.printStackTrace(); AlertDialog.Builder alert = new AlertDialog.Builder(getActivity()); alert.setPositiveButton(R.string.alert_ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Intent i = new Intent( android.provider.Settings.ACTION_MANAGE_APPLICATIONS_SETTINGS); i.addCategory(Intent.CATEGORY_DEFAULT); startActivity(i); } }); alert.setMessage(R.string.alert_calendar_not_found); alert.show(); } } }); } mWeatherView = (WeatherView) v.findViewById(R.id.weather_view); mMainViewLeftPanel = (LinearLayout) v.findViewById(R.id.main_view_left_panel); mMainViewRightPanel = (LinearLayout) v.findViewById(R.id.main_view_right_panel); LayoutInflater layoutInflater = (LayoutInflater) getActivity() .getSystemService(Context.LAYOUT_INFLATER_SERVICE); // add main shortcut. ArrayList<ShortcutData> mainShortcutDatas = LauncherSettings.getInstance(getActivity()) .getLauncherMainShortcuts(); mMainShortcutGridLayout = (GridLayout) v.findViewById(R.id.main_shortcut_grid); float dp;// = DisplayUtils.getDimension(getActivity(), R.dimen.launcher_ic_menu_main_shortcut_width); // float widthPx = DisplayUtils.pxFromDp(getActivity(), dp); // // dp = DisplayUtils.getDimension(getActivity(), R.dimen.launcher_ic_menu_main_shortcut_height); // float heightPx = DisplayUtils.pxFromDp(getActivity(), dp); dp = DisplayUtils.getDimension(getActivity(), R.dimen.launcher_ic_menu_main_shortcut_font_size); float mainShortcutFontPx = DisplayUtils.pxFromDp(getActivity(), dp); for (int i = 0; i < mMainShortcutGridLayout.getColumnCount(); i++) { /** * right shortcut panel */ ShortcutData data = mainShortcutDatas.get(i); FrameLayout btnLayout = (FrameLayout) layoutInflater.inflate(R.layout.launcher_menu_top_item, mMainShortcutGridLayout, false);//new Button(getActivity()); mMainShortcutGridLayout.addView(btnLayout); if (data.getPushType() != null && data.getPushType().length > 0) { data.setLauncherButton(btnLayout); mPushNotifiableShorcuts.add(data); } btnLayout.setBackgroundResource(data.getIconBackResId()); // GridLayout.LayoutParams lp = (GridLayout.LayoutParams)btnLayout.getLayoutParams(); // lp.width = (int)widthPx; // lp.height = (int)heightPx; // btnLayout.setLayoutParams(lp); TextView label = (TextView) btnLayout.findViewById(R.id.menu_item_label); label.setText(data.getName()); label.setTextSize(TypedValue.COMPLEX_UNIT_PX, mainShortcutFontPx); label.setTextColor(getResources().getColor(R.color.white)); label.setTypeface(null, Typeface.BOLD); label.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL); ImageView icon = (ImageView) btnLayout.findViewById(R.id.menu_item_image); icon.setImageResource(data.getIconResId()); btnLayout.setTag(data); btnLayout.setOnClickListener(this); } // add other shortcuts. mShorcutGridLayout = (GridLayout) v.findViewById(R.id.shortcut_grid); ArrayList<ShortcutData> shortcutDatas = LauncherSettings.getInstance(getActivity()).getLauncherShortcuts(); int columnNum = mShorcutGridLayout.getColumnCount(); final int MAX_ROW_NUM = 3; int shortcutNum = shortcutDatas.size() > (columnNum * MAX_ROW_NUM) ? (columnNum * MAX_ROW_NUM) : shortcutDatas.size(); dp = DisplayUtils.getDimension(getActivity(), R.dimen.launcher_ic_menu_shortcut_font_size); float btnFontPx = DisplayUtils.pxFromDp(getActivity(), dp); for (int i = 0; i < shortcutNum; i++) { /** * right shortcut panel */ ShortcutData data = shortcutDatas.get(i); FrameLayout btnLayout = (FrameLayout) layoutInflater.inflate(R.layout.launcher_menu_item, mShorcutGridLayout, false);//new Button(getActivity()); mShorcutGridLayout.addView(btnLayout); if (data.getPushType() != null && data.getPushType().length > 0) { data.setLauncherButton(btnLayout); mPushNotifiableShorcuts.add(data); } btnLayout.setBackgroundResource(data.getIconBackResId()); TextView label = (TextView) btnLayout.findViewById(R.id.menu_item_label); label.setText(data.getName()); label.setTextSize(TypedValue.COMPLEX_UNIT_PX, btnFontPx); label.setTextColor(getResources().getColor(R.color.white)); label.setTypeface(null, Typeface.BOLD); label.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL); ImageView icon = (ImageView) btnLayout.findViewById(R.id.menu_item_image); icon.setImageResource(data.getIconResId()); btnLayout.setTag(data); btnLayout.setOnClickListener(this); } setContentViewByOrientation(); return v; }
From source file:com.mobiroller.tools.inappbrowser.MobirollerInAppBrowser.java
/** * Display a new browser with the specified URL. * * @param url The url to load. * @param jsonObject/*from w ww . ja v a 2 s .c o m*/ */ public String showWebPage(final String url, final HashMap<String, Boolean> features) { // Determine if we should hide the location bar. showLocationBar = true; showZoomControls = false; openWindowHidden = false; if (features != null) { Boolean show = features.get(LOCATION); if (show != null) { showLocationBar = show.booleanValue(); } Boolean zoom = features.get(ZOOM); if (zoom != null) { showZoomControls = zoom.booleanValue(); } Boolean hidden = features.get(HIDDEN); if (hidden != null) { openWindowHidden = hidden.booleanValue(); } Boolean hardwareBack = features.get(HARDWARE_BACK_BUTTON); if (hardwareBack != null) { hadwareBackButton = hardwareBack.booleanValue(); } Boolean cache = features.get(CLEAR_ALL_CACHE); if (cache != null) { clearAllCache = cache.booleanValue(); } else { cache = features.get(CLEAR_SESSION_CACHE); if (cache != null) { clearSessionCache = cache.booleanValue(); } } } final CordovaWebView thatWebView = this.webView; // 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; } @SuppressLint("NewApi") public void run() { // Let's create the main dialog dialog = new MobirollerInAppBrowserDialog(cordova.getActivity(), android.R.style.Theme_Translucent_NoTitleBar); dialog.getWindow().getAttributes().windowAnimations = android.R.style.Animation_Dialog; dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setCancelable(true); dialog.setInAppBroswer(getInAppBrowser()); // Main container layout LinearLayout main = new LinearLayout(cordova.getActivity()); main.setBackgroundColor(Color.TRANSPARENT); main.setOrientation(LinearLayout.VERTICAL); // Toolbar layout RelativeLayout toolbar = new RelativeLayout(cordova.getActivity()); //Please, no more black! toolbar.setBackgroundColor(Color.TRANSPARENT); toolbar.setLayoutParams(new RelativeLayout.LayoutParams(WindowManager.LayoutParams.MATCH_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( WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT)); actionButtonContainer.setHorizontalGravity(Gravity.LEFT); actionButtonContainer.setVerticalGravity(Gravity.CENTER_VERTICAL); actionButtonContainer.setId(1); // Back button Button back = new Button(cordova.getActivity()); RelativeLayout.LayoutParams backLayoutParams = new RelativeLayout.LayoutParams( WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.MATCH_PARENT); backLayoutParams.addRule(RelativeLayout.ALIGN_LEFT); back.setLayoutParams(backLayoutParams); back.setContentDescription("Back Button"); back.setId(2); Resources activityRes = cordova.getActivity().getResources(); int backResId = activityRes.getIdentifier("ic_action_previous_item", "drawable", cordova.getActivity().getPackageName()); Drawable backIcon = activityRes.getDrawable(backResId); if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) { back.setBackgroundDrawable(backIcon); } else { back.setBackground(backIcon); } back.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { goBack(); } }); // Forward button Button forward = new Button(cordova.getActivity()); RelativeLayout.LayoutParams forwardLayoutParams = new RelativeLayout.LayoutParams( WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.MATCH_PARENT); forwardLayoutParams.addRule(RelativeLayout.RIGHT_OF, 2); forward.setLayoutParams(forwardLayoutParams); forward.setContentDescription("Forward Button"); forward.setId(3); int fwdResId = activityRes.getIdentifier("ic_action_next_item", "drawable", cordova.getActivity().getPackageName()); Drawable fwdIcon = activityRes.getDrawable(fwdResId); if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) { forward.setBackgroundDrawable(fwdIcon); } else { forward.setBackground(fwdIcon); } 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( WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_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/Done button Button close = new Button(cordova.getActivity()); RelativeLayout.LayoutParams closeLayoutParams = new RelativeLayout.LayoutParams( WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.MATCH_PARENT); closeLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); close.setLayoutParams(closeLayoutParams); forward.setContentDescription("Close Button"); close.setId(5); int closeResId = activityRes.getIdentifier("ic_action_remove", "drawable", cordova.getActivity().getPackageName()); Drawable closeIcon = activityRes.getDrawable(closeResId); if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) { close.setBackgroundDrawable(closeIcon); } else { close.setBackground(closeIcon); } close.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { closeDialog(); } }); // WebView inAppWebView = new WebView(cordova.getActivity()); inAppWebView.setLayoutParams(new LinearLayout.LayoutParams(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT)); inAppWebView.setWebChromeClient(new MobirollerInAppChromeClient(thatWebView)); WebViewClient client = new InAppBrowserClient(thatWebView, edittext); inAppWebView.setWebViewClient(client); WebSettings settings = inAppWebView.getSettings(); settings.setJavaScriptEnabled(true); settings.setJavaScriptCanOpenWindowsAutomatically(true); settings.setBuiltInZoomControls(showZoomControls); settings.setPluginState(android.webkit.WebSettings.PluginState.ON); //Toggle whether this is enabled or not! Bundle appSettings = cordova.getActivity().getIntent().getExtras(); boolean enableDatabase = appSettings == null ? true : appSettings.getBoolean("InAppBrowserStorageEnabled", true); if (enableDatabase) { String databasePath = cordova.getActivity().getApplicationContext() .getDir("inAppBrowserDB", Context.MODE_PRIVATE).getPath(); settings.setDatabasePath(databasePath); settings.setDatabaseEnabled(true); } settings.setDomStorageEnabled(true); if (clearAllCache) { CookieManager.getInstance().removeAllCookie(); } else if (clearSessionCache) { CookieManager.getInstance().removeSessionCookie(); } inAppWebView.loadUrl(url); inAppWebView.setId(6); inAppWebView.getSettings().setLoadWithOverviewMode(true); inAppWebView.getSettings().setUseWideViewPort(true); inAppWebView.requestFocus(); inAppWebView.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(inAppWebView); WindowManager.LayoutParams lp = new WindowManager.LayoutParams(); lp.copyFrom(dialog.getWindow().getAttributes()); lp.width = WindowManager.LayoutParams.MATCH_PARENT; lp.height = WindowManager.LayoutParams.MATCH_PARENT; //Mobiroller Needs DisplayMetrics metrics = cordova.getActivity().getResources().getDisplayMetrics(); Rect windowRect = new Rect(); webView.getView().getWindowVisibleDisplayFrame(windowRect); int bottomGap = 0; if (features.containsKey("hasTabs")) { if (features.get("hasTabs")) { bottomGap += Math.ceil(44 * metrics.density); } } lp.height = (windowRect.bottom - windowRect.top) - (bottomGap); lp.gravity = Gravity.TOP; lp.format = PixelFormat.TRANSPARENT; close.setAlpha(0); //Mobiroller Needs dialog.setContentView(main); dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); dialog.show(); dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); dialog.getWindow().setAttributes(lp); // the goal of openhidden is to load the url and not display it // Show() needs to be called to cause the URL to be loaded if (openWindowHidden) { dialog.hide(); } } }; this.cordova.getActivity().runOnUiThread(runnable); return ""; }
From source file:com.likemag.cordova.inappbrowsercustom.InAppBrowser.java
/** * Display a new browser with the specified URL. * * @param url The url to load. * @param jsonObject/*from ww w . j a v a 2 s . c o m*/ */ public String showWebPage(final String url, HashMap<String, Boolean> features) { // Determine if we should hide the location bar. showLocationBar = true; openWindowHidden = false; if (features != null) { Boolean show = features.get(LOCATION); if (show != null) { showLocationBar = show.booleanValue(); } Boolean hidden = features.get(HIDDEN); if (hidden != null) { openWindowHidden = hidden.booleanValue(); } Boolean cache = features.get(CLEAR_ALL_CACHE); if (cache != null) { clearAllCache = cache.booleanValue(); } else { cache = features.get(CLEAR_SESSION_CACHE); if (cache != null) { clearSessionCache = cache.booleanValue(); } } } final CordovaWebView thatWebView = this.webView; // 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; } @SuppressLint("NewApi") public void run() { // Let's create the main dialog dialog = new InAppBrowserDialog(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.setInAppBroswer(getInAppBrowser()); // Main container layout LinearLayout main = new LinearLayout(cordova.getActivity()); main.setOrientation(LinearLayout.VERTICAL); // Toolbar layout RelativeLayout toolbar = new RelativeLayout(cordova.getActivity()); //Please, no more black! toolbar.setBackgroundColor(android.graphics.Color.WHITE); toolbar.setLayoutParams( new RelativeLayout.LayoutParams(LayoutParams.MATCH_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 Button back = new Button(cordova.getActivity()); RelativeLayout.LayoutParams backLayoutParams = new RelativeLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); backLayoutParams.addRule(RelativeLayout.ALIGN_LEFT); back.setLayoutParams(backLayoutParams); back.setContentDescription("Back Button"); back.setId(2); Resources activityRes = cordova.getActivity().getResources(); int backResId = activityRes.getIdentifier("ic_action_previous_item", "drawable", cordova.getActivity().getPackageName()); Drawable backIcon = activityRes.getDrawable(backResId); if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) { back.setBackgroundDrawable(backIcon); } else { back.setBackground(backIcon); } back.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { goBack(); } }); // Forward button Button forward = new Button(cordova.getActivity()); RelativeLayout.LayoutParams forwardLayoutParams = new RelativeLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); forwardLayoutParams.addRule(RelativeLayout.RIGHT_OF, 2); forward.setLayoutParams(forwardLayoutParams); forward.setContentDescription("Forward Button"); forward.setId(3); int fwdResId = activityRes.getIdentifier("ic_action_next_item", "drawable", cordova.getActivity().getPackageName()); Drawable fwdIcon = activityRes.getDrawable(fwdResId); if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) { forward.setBackgroundDrawable(fwdIcon); } else { forward.setBackground(fwdIcon); } 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.MATCH_PARENT, LayoutParams.MATCH_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/Done button Button close = new Button(cordova.getActivity()); RelativeLayout.LayoutParams closeLayoutParams = new RelativeLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); closeLayoutParams.addRule(RelativeLayout.ALIGN_LEFT); close.setLayoutParams(closeLayoutParams); forward.setContentDescription("Close Button"); close.setText(getPostName()); close.setTextSize(20.0f); close.setTextColor(android.graphics.Color.GRAY); close.setId(5); int closeResId = activityRes.getIdentifier("ic_action_remove", "drawable", cordova.getActivity().getPackageName()); Drawable closeIcon = activityRes.getDrawable(backResId); closeIcon.setBounds(0, 0, 40, 40); close.setPadding(0, 0, 0, 0); close.setBackgroundDrawable(null); close.setCompoundDrawables(closeIcon, null, null, null); if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) { //close.setBackgroundDrawable(closeIcon); } else { //close.setBackground(closeIcon); } close.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { closeDialog(); } }); // WebView inAppWebView = new WebView(cordova.getActivity()); inAppWebView.setLayoutParams( new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); inAppWebView.setWebChromeClient(new InAppChromeClient(thatWebView)); WebViewClient client = new InAppBrowserClient(thatWebView, edittext); inAppWebView.setWebViewClient(client); WebSettings settings = inAppWebView.getSettings(); settings.setJavaScriptEnabled(true); settings.setJavaScriptCanOpenWindowsAutomatically(true); settings.setBuiltInZoomControls(true); settings.setPluginState(android.webkit.WebSettings.PluginState.ON); //Toggle whether this is enabled or not! Bundle appSettings = cordova.getActivity().getIntent().getExtras(); boolean enableDatabase = appSettings == null ? true : appSettings.getBoolean("InAppBrowserStorageEnabled", true); if (enableDatabase) { String databasePath = cordova.getActivity().getApplicationContext() .getDir("inAppBrowserDB", Context.MODE_PRIVATE).getPath(); settings.setDatabasePath(databasePath); settings.setDatabaseEnabled(true); } settings.setDomStorageEnabled(true); if (clearAllCache) { CookieManager.getInstance().removeAllCookie(); } else if (clearSessionCache) { CookieManager.getInstance().removeSessionCookie(); } inAppWebView.loadUrl(url); inAppWebView.setId(6); inAppWebView.getSettings().setLoadWithOverviewMode(true); inAppWebView.getSettings().setUseWideViewPort(true); inAppWebView.requestFocus(); inAppWebView.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(inAppWebView); WindowManager.LayoutParams lp = new WindowManager.LayoutParams(); lp.copyFrom(dialog.getWindow().getAttributes()); lp.width = WindowManager.LayoutParams.MATCH_PARENT; lp.height = WindowManager.LayoutParams.MATCH_PARENT; dialog.setContentView(main); dialog.show(); dialog.getWindow().setAttributes(lp); // the goal of openhidden is to load the url and not display it // Show() needs to be called to cause the URL to be loaded if (openWindowHidden) { dialog.hide(); } } }; this.cordova.getActivity().runOnUiThread(runnable); return ""; }
From source file:com.phonegap.bossbolo.plugin.inappbrowser.InAppBrowser.java
/** * Display a new browser with the specified URL. * * @param url The url to load. * @param jsonObject// w w w . ja v a 2 s . c o m * @param header */ public String showWebPage(final String url, HashMap<String, Boolean> features, final String header) { // Determine if we should hide the location bar. showLocationBar = true; showZoomControls = true; openWindowHidden = false; if (features != null) { Boolean show = features.get(LOCATION); if (show != null) { showLocationBar = show.booleanValue(); } Boolean zoom = features.get(ZOOM); if (zoom != null) { showZoomControls = zoom.booleanValue(); } Boolean hidden = features.get(HIDDEN); if (hidden != null) { openWindowHidden = hidden.booleanValue(); } Boolean hardwareBack = features.get(HARDWARE_BACK_BUTTON); if (hardwareBack != null) { hadwareBackButton = hardwareBack.booleanValue(); } Boolean cache = features.get(CLEAR_ALL_CACHE); if (cache != null) { clearAllCache = cache.booleanValue(); } else { cache = features.get(CLEAR_SESSION_CACHE); if (cache != null) { clearSessionCache = cache.booleanValue(); } } } final CordovaWebView thatWebView = this.webView; // 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; } @SuppressLint("NewApi") public void run() { int backgroundColor = Color.parseColor("#46bff7"); // Let's create the main dialog dialog = new InAppBrowserDialog(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.setInAppBroswer(getInAppBrowser()); // Main container layout LinearLayout main = new LinearLayout(cordova.getActivity()); main.setOrientation(LinearLayout.VERTICAL); // Toolbar layout header RelativeLayout toolbar = new RelativeLayout(cordova.getActivity()); //Please, no more black! toolbar.setBackgroundColor(android.graphics.Color.LTGRAY); toolbar.setLayoutParams( new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, this.dpToPixels(50))); toolbar.setPadding(this.dpToPixels(8), this.dpToPixels(10), this.dpToPixels(8), this.dpToPixels(10)); toolbar.setHorizontalGravity(Gravity.LEFT); toolbar.setVerticalGravity(Gravity.TOP); toolbar.setBackgroundColor(backgroundColor); // 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 Button back = new Button(cordova.getActivity()); RelativeLayout.LayoutParams backLayoutParams = new RelativeLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); backLayoutParams.addRule(RelativeLayout.ALIGN_LEFT); back.setLayoutParams(backLayoutParams); back.setContentDescription("Back Button"); back.setId(2); back.setWidth(this.dpToPixels(34)); back.setHeight(this.dpToPixels(31)); Resources activityRes = cordova.getActivity().getResources(); int backResId = activityRes.getIdentifier("back", "drawable", cordova.getActivity().getPackageName()); Drawable backIcon = activityRes.getDrawable(backResId); if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) { back.setBackgroundDrawable(backIcon); } else { back.setBackground(backIcon); } back.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { closeDialog(); // goBack(); } }); // Edit Text Box titletext = new TextView(cordova.getActivity()); RelativeLayout.LayoutParams textLayoutParams = new RelativeLayout.LayoutParams( LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); textLayoutParams.addRule(RelativeLayout.RIGHT_OF, this.dpToPixels(65)); textLayoutParams.addRule(RelativeLayout.LEFT_OF, this.dpToPixels(10)); titletext.setLayoutParams(textLayoutParams); titletext.setId(3); titletext.setSingleLine(true); titletext.setText(header); titletext.setTextColor(Color.WHITE); titletext.setGravity(Gravity.CENTER); titletext.setTextSize(TypedValue.COMPLEX_UNIT_PX, this.dpToPixels(20)); titletext.setSingleLine(); titletext.setEllipsize(TruncateAt.END); edittext = new EditText(cordova.getActivity()); RelativeLayout.LayoutParams editLayoutParams = new RelativeLayout.LayoutParams( LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); editLayoutParams.addRule(RelativeLayout.RIGHT_OF, 1); editLayoutParams.addRule(RelativeLayout.LEFT_OF, 5); edittext.setLayoutParams(textLayoutParams); edittext.setId(4); edittext.setSingleLine(true); edittext.setText(url); edittext.setVisibility(View.GONE); // Forward button /*Button forward = new Button(cordova.getActivity()); RelativeLayout.LayoutParams forwardLayoutParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); forwardLayoutParams.addRule(RelativeLayout.RIGHT_OF, 2); forward.setLayoutParams(forwardLayoutParams); forward.setContentDescription("Forward Button"); forward.setId(3); int fwdResId = activityRes.getIdentifier("ic_action_next_item", "drawable", cordova.getActivity().getPackageName()); Drawable fwdIcon = activityRes.getDrawable(fwdResId); if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) { forward.setBackgroundDrawable(fwdIcon); } else { forward.setBackground(fwdIcon); } forward.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { goForward(); } }); // Edit Text Box edittext = new TextView(cordova.getActivity()); RelativeLayout.LayoutParams textLayoutParams = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_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/Done button Button close = new Button(cordova.getActivity()); RelativeLayout.LayoutParams closeLayoutParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); closeLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); close.setLayoutParams(closeLayoutParams); forward.setContentDescription("Close Button"); close.setId(5); int closeResId = activityRes.getIdentifier("ic_action_remove", "drawable", cordova.getActivity().getPackageName()); Drawable closeIcon = activityRes.getDrawable(closeResId); if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) { close.setBackgroundDrawable(closeIcon); } else { close.setBackground(closeIcon); } close.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { closeDialog(); } });*/ // WebView inAppWebView = new WebView(cordova.getActivity()); inAppWebView.setLayoutParams( new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); inAppWebView.setWebChromeClient(new InAppChromeClient(thatWebView)); WebViewClient client = new InAppBrowserClient(thatWebView, edittext); inAppWebView.setWebViewClient(client); WebSettings settings = inAppWebView.getSettings(); settings.setJavaScriptEnabled(true); settings.setJavaScriptCanOpenWindowsAutomatically(true); settings.setBuiltInZoomControls(getShowZoomControls()); settings.setPluginState(android.webkit.WebSettings.PluginState.ON); //Toggle whether this is enabled or not! Bundle appSettings = cordova.getActivity().getIntent().getExtras(); boolean enableDatabase = appSettings == null ? true : appSettings.getBoolean("InAppBrowserStorageEnabled", true); if (enableDatabase) { String databasePath = cordova.getActivity().getApplicationContext() .getDir("inAppBrowserDB", Context.MODE_PRIVATE).getPath(); settings.setDatabasePath(databasePath); settings.setDatabaseEnabled(true); } settings.setDomStorageEnabled(true); if (clearAllCache) { CookieManager.getInstance().removeAllCookie(); } else if (clearSessionCache) { CookieManager.getInstance().removeSessionCookie(); } inAppWebView.loadUrl(url); inAppWebView.setId(6); inAppWebView.getSettings().setLoadWithOverviewMode(true); inAppWebView.getSettings().setUseWideViewPort(true); inAppWebView.requestFocus(); inAppWebView.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(titletext); // 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(inAppWebView); WindowManager.LayoutParams lp = new WindowManager.LayoutParams(); lp.copyFrom(dialog.getWindow().getAttributes()); lp.width = WindowManager.LayoutParams.MATCH_PARENT; lp.height = WindowManager.LayoutParams.MATCH_PARENT; dialog.setContentView(main); dialog.show(); dialog.getWindow().setAttributes(lp); // the goal of openhidden is to load the url and not display it // Show() needs to be called to cause the URL to be loaded if (openWindowHidden) { dialog.hide(); } } }; this.cordova.getActivity().runOnUiThread(runnable); return ""; }
From source file:com.adarshahd.indianrailinfo.donate.PNRStat.java
private void showOfflinePNRStatus(String trainDetails, ArrayList<String> passnDetails) { LinearLayout ll = new LinearLayout(mActivity); TextView textViewTrnDtls = new TextView(mActivity); TextView textViewPsnDtls = new TextView(mActivity); TextView tvTrainDetails = new TextView(mActivity); TextView[] tvPassnDetails = new TextView[passnDetails.size()]; textViewTrnDtls.setText("Train Details: " + mPNRNumber); textViewTrnDtls.setFocusable(true);//from w ww . j a v a 2 s .c o m textViewPsnDtls.setText("Passenger Details"); tvTrainDetails.setText(trainDetails); textViewTrnDtls.setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Large); textViewPsnDtls.setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Large); tvTrainDetails.setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Small); textViewTrnDtls.setPadding(10, 10, 10, 10); textViewPsnDtls.setPadding(10, 10, 10, 10); tvTrainDetails.setPadding(10, 10, 10, 10); tvTrainDetails.setBackgroundResource(R.drawable.card_background); textViewTrnDtls.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL); textViewPsnDtls.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL); ll.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); ll.setOrientation(LinearLayout.VERTICAL); ll.addView(textViewTrnDtls); ll.addView(tvTrainDetails); ll.addView(textViewPsnDtls); for (int i = 0; i < passnDetails.size(); ++i) { tvPassnDetails[i] = new TextView(mActivity); tvPassnDetails[i].setText(passnDetails.get(i)); tvPassnDetails[i].setPadding(10, 10, 10, 10); tvPassnDetails[i].setBackgroundResource(R.drawable.card_background); tvPassnDetails[i].setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Medium); ll.addView(tvPassnDetails[i]); } mFrameLayout.removeAllViews(); mFrameLayout.addView(ll); }
From source file:com.android.launcher3.allapps.AllAppsGridAdapter.java
@Override public void onBindViewHolder(ViewHolder holder, int position) { switch (holder.getItemViewType()) { case ICON_VIEW_TYPE: { AppInfo info = mApps.getAdapterItems().get(position).appInfo; BubbleTextView icon = (BubbleTextView) holder.mContent; icon.applyFromApplicationInfo(info); icon.setAccessibilityDelegate(LauncherAppState.getInstance().getAccessibilityDelegate()); break;// w ww . jav a 2 s .com } case PREDICTION_ICON_VIEW_TYPE: { AppInfo info = mApps.getAdapterItems().get(position).appInfo; BubbleTextView icon = (BubbleTextView) holder.mContent; icon.applyFromApplicationInfo(info); icon.setAccessibilityDelegate(LauncherAppState.getInstance().getAccessibilityDelegate()); break; } case EMPTY_SEARCH_VIEW_TYPE: TextView emptyViewText = (TextView) holder.mContent; emptyViewText.setText(mEmptySearchMessage); emptyViewText.setGravity( mApps.hasNoFilteredResults() ? Gravity.CENTER : Gravity.START | Gravity.CENTER_VERTICAL); break; case SEARCH_MARKET_VIEW_TYPE: TextView searchView = (TextView) holder.mContent; if (mMarketSearchIntent != null) { searchView.setVisibility(View.VISIBLE); searchView.setContentDescription(mMarketSearchMessage); searchView.setGravity( mApps.hasNoFilteredResults() ? Gravity.CENTER : Gravity.START | Gravity.CENTER_VERTICAL); searchView.setText(mMarketSearchMessage); } else { searchView.setVisibility(View.GONE); } break; } if (mBindViewCallback != null) { mBindViewCallback.onBindView(holder); } }